blob: 66deb9ecea5fd5abcad873abb9293f9af7b3b8c5 [file] [log] [blame]
Karl Schultz6addd812016-02-02 17:17:23 -07001/*
Mike Weiblen40b160e2017-02-06 19:21:52 -07002 * Copyright (c) 2015-2017 The Khronos Group Inc.
3 * Copyright (c) 2015-2017 Valve Corporation
4 * Copyright (c) 2015-2017 LunarG, Inc.
5 * Copyright (c) 2015-2017 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>
Dave Houlton59a20702017-02-02 17:26:23 -070021 * Author: Dave Houlton <daveh@lunarg.com>
Karl Schultz6addd812016-02-02 17:17:23 -070022 */
Tony Barbour65c48b32015-11-17 10:02:56 -070023
Cody Northrop8e54a402016-03-08 22:25:52 -070024#ifdef ANDROID
25#include "vulkan_wrapper.h"
26#else
David Pinedo9316d3b2015-11-06 12:54:48 -070027#include <vulkan/vulkan.h>
Cody Northrop8e54a402016-03-08 22:25:52 -070028#endif
Cody Northrop1242dfd2016-07-13 17:24:59 -060029
30#if defined(ANDROID) && defined(VALIDATION_APK)
31#include <android/log.h>
32#include <android_native_app_glue.h>
33#endif
34
Jon Ashburn7fa7e222016-02-02 12:08:10 -070035#include "icd-spv.h"
Mark Lobodzinskice751c62016-09-08 10:45:35 -060036#include "test_common.h"
37#include "vk_layer_config.h"
Dave Houlton3c9fca72017-03-27 17:25:54 -060038#include "vk_format_utils.h"
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060039#include "vk_validation_error_messages.h"
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060040#include "vkrenderframework.h"
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070041
42#include <algorithm>
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060043#include <limits.h>
44#include <unordered_set>
Tony Barbour300a6082015-04-07 13:44:53 -060045
Mark Lobodzinski3780e142015-05-14 15:08:13 -050046#define GLM_FORCE_RADIANS
47#include "glm/glm.hpp"
48#include <glm/gtc/matrix_transform.hpp>
49
50//--------------------------------------------------------------------------------------
51// Mesh and VertexFormat Data
52//--------------------------------------------------------------------------------------
Karl Schultz6addd812016-02-02 17:17:23 -070053struct Vertex {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070054 float posX, posY, posZ, posW; // Position data
55 float r, g, b, a; // Color
Mark Lobodzinski3780e142015-05-14 15:08:13 -050056};
57
Karl Schultz6addd812016-02-02 17:17:23 -070058#define XYZ1(_x_, _y_, _z_) (_x_), (_y_), (_z_), 1.f
Mark Lobodzinski3780e142015-05-14 15:08:13 -050059
60typedef enum _BsoFailSelect {
Karl Schultz6addd812016-02-02 17:17:23 -070061 BsoFailNone = 0x00000000,
62 BsoFailLineWidth = 0x00000001,
63 BsoFailDepthBias = 0x00000002,
64 BsoFailViewport = 0x00000004,
65 BsoFailScissor = 0x00000008,
66 BsoFailBlend = 0x00000010,
67 BsoFailDepthBounds = 0x00000020,
68 BsoFailStencilReadMask = 0x00000040,
69 BsoFailStencilWriteMask = 0x00000080,
70 BsoFailStencilReference = 0x00000100,
Mark Muellerd4914412016-06-13 17:52:06 -060071 BsoFailCmdClearAttachments = 0x00000200,
Tobin Ehlis379ba3b2016-07-19 11:22:29 -060072 BsoFailIndexBuffer = 0x00000400,
Mark Lobodzinski3780e142015-05-14 15:08:13 -050073} BsoFailSelect;
74
75struct vktriangle_vs_uniform {
76 // Must start with MVP
Karl Schultz6addd812016-02-02 17:17:23 -070077 float mvp[4][4];
78 float position[3][4];
79 float color[3][4];
Mark Lobodzinski3780e142015-05-14 15:08:13 -050080};
81
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070082static const char bindStateVertShaderText[] =
83 "#version 450\n"
84 "vec2 vertices[3];\n"
85 "out gl_PerVertex {\n"
86 " vec4 gl_Position;\n"
87 "};\n"
88 "void main() {\n"
89 " vertices[0] = vec2(-1.0, -1.0);\n"
90 " vertices[1] = vec2( 1.0, -1.0);\n"
91 " vertices[2] = vec2( 0.0, 1.0);\n"
92 " gl_Position = vec4(vertices[gl_VertexIndex % 3], 0.0, 1.0);\n"
93 "}\n";
Mark Lobodzinski3780e142015-05-14 15:08:13 -050094
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070095static const char bindStateFragShaderText[] =
96 "#version 450\n"
97 "\n"
98 "layout(location = 0) out vec4 uFragColor;\n"
99 "void main(){\n"
100 " uFragColor = vec4(0,1,0,1);\n"
101 "}\n";
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500102
Dave Houlton1d2022c2017-03-29 11:43:58 -0600103// Format search helper
104VkFormat FindSupportedDepthStencilFormat(VkPhysicalDevice phy) {
Dave Houltond7472002017-03-30 09:48:28 -0600105 VkFormat ds_formats[] = {VK_FORMAT_D16_UNORM_S8_UINT, VK_FORMAT_D24_UNORM_S8_UINT, VK_FORMAT_D32_SFLOAT_S8_UINT};
Dave Houlton1d2022c2017-03-29 11:43:58 -0600106 for (uint32_t i = 0; i < sizeof(ds_formats); i++) {
107 VkFormatProperties format_props;
108 vkGetPhysicalDeviceFormatProperties(phy, ds_formats[i], &format_props);
109
110 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
111 return ds_formats[i];
112 }
113 }
114 return (VkFormat)0;
115}
116
117// Validation report callback prototype
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600118static VKAPI_ATTR VkBool32 VKAPI_CALL myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType, uint64_t srcObject,
119 size_t location, int32_t msgCode, const char *pLayerPrefix, const char *pMsg,
120 void *pUserData);
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600121
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600122// ErrorMonitor Usage:
123//
Dave Houltonfbf52152017-01-06 12:55:29 -0700124// Call SetDesiredFailureMsg with a string to be compared against all
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600125// encountered log messages, or a validation error enum identifying
126// desired error message. Passing NULL or VALIDATION_ERROR_MAX_ENUM
127// will match all log messages. logMsg will return true for skipCall
128// only if msg is matched or NULL.
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600129//
Dave Houltonfbf52152017-01-06 12:55:29 -0700130// Call VerifyFound to determine if all desired failure messages
131// were encountered. Call VerifyNotFound to determine if any unexpected
132// failure was encountered.
Tony Barbour300a6082015-04-07 13:44:53 -0600133class ErrorMonitor {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700134 public:
Karl Schultz6addd812016-02-02 17:17:23 -0700135 ErrorMonitor() {
Dave Houltonfbf52152017-01-06 12:55:29 -0700136 test_platform_thread_create_mutex(&mutex_);
137 test_platform_thread_lock_mutex(&mutex_);
138 Reset();
139 test_platform_thread_unlock_mutex(&mutex_);
Tony Barbour300a6082015-04-07 13:44:53 -0600140 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600141
Dave Houltonfbf52152017-01-06 12:55:29 -0700142 ~ErrorMonitor() { test_platform_thread_delete_mutex(&mutex_); }
Dustin Graves48458142016-04-29 16:11:55 -0600143
Dave Houltonfbf52152017-01-06 12:55:29 -0700144 // Set monitor to pristine state
145 void Reset() {
146 message_flags_ = VK_DEBUG_REPORT_ERROR_BIT_EXT;
147 bailout_ = NULL;
148 message_found_ = VK_FALSE;
149 failure_message_strings_.clear();
150 desired_message_strings_.clear();
151 desired_message_ids_.clear();
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700152 ignore_message_strings_.clear();
Dave Houltonfbf52152017-01-06 12:55:29 -0700153 other_messages_.clear();
154 message_outstanding_count_ = 0;
155 }
156
157 // ErrorMonitor will look for an error message containing the specified string(s)
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700158 void SetDesiredFailureMsg(const VkFlags msgFlags, const char *const msgString) {
Dave Houltonfbf52152017-01-06 12:55:29 -0700159 test_platform_thread_lock_mutex(&mutex_);
160 desired_message_strings_.insert(msgString);
161 message_flags_ |= msgFlags;
162 message_outstanding_count_++;
163 test_platform_thread_unlock_mutex(&mutex_);
Tony Barbour300a6082015-04-07 13:44:53 -0600164 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600165
Jeremy Hayesde6d96c2017-02-01 15:22:32 -0700166 // ErrorMonitor will look for an error message containing the specified string(s)
167 template <typename Iter>
168 void SetDesiredFailureMsg(const VkFlags msgFlags, Iter iter, const Iter end) {
169 for (; iter != end; ++iter) {
170 SetDesiredFailureMsg(msgFlags, *iter);
171 }
172 }
173
Dave Houltonfbf52152017-01-06 12:55:29 -0700174 // ErrorMonitor will look for a message ID matching the specified one(s)
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700175 void SetDesiredFailureMsg(const VkFlags msgFlags, const UNIQUE_VALIDATION_ERROR_CODE msg_id) {
Dave Houltonfbf52152017-01-06 12:55:29 -0700176 test_platform_thread_lock_mutex(&mutex_);
177 desired_message_ids_.insert(msg_id);
178 message_flags_ |= msgFlags;
179 message_outstanding_count_++;
180 test_platform_thread_unlock_mutex(&mutex_);
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600181 }
182
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700183 // Set an error that the error monitor will ignore. Do not use this function if you are creating a new test.
184 // TODO: This is stopgap to block new unexpected errors from being introduced. The long-term goal is to remove the use of this
185 // function and its definition.
186 void SetUnexpectedError(const char *const msg) {
187 test_platform_thread_lock_mutex(&mutex_);
188
189 ignore_message_strings_.emplace_back(msg);
190
191 test_platform_thread_unlock_mutex(&mutex_);
192 }
193
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700194 VkBool32 CheckForDesiredMsg(const uint32_t message_code, const char *const msgString) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600195 VkBool32 result = VK_FALSE;
Dave Houltonfbf52152017-01-06 12:55:29 -0700196 test_platform_thread_lock_mutex(&mutex_);
197 if (bailout_ != NULL) {
198 *bailout_ = true;
Mike Stroyanaccf7692015-05-12 16:00:45 -0600199 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600200 string errorString(msgString);
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600201 bool found_expected = false;
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600202
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700203 if (!IgnoreMessage(errorString)) {
204 for (auto desired_msg : desired_message_strings_) {
205 if (desired_msg.length() == 0) {
206 // An empty desired_msg string "" indicates a positive test - not expecting an error.
207 // Return true to avoid calling layers/driver with this error.
208 // And don't erase the "" string, so it remains if another error is found.
209 result = VK_TRUE;
210 found_expected = true;
211 message_found_ = VK_TRUE;
212 failure_message_strings_.insert(errorString);
213 } else if (errorString.find(desired_msg) != string::npos) {
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600214 found_expected = true;
Dave Houltonfbf52152017-01-06 12:55:29 -0700215 message_outstanding_count_--;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700216 failure_message_strings_.insert(errorString);
Dave Houltonfbf52152017-01-06 12:55:29 -0700217 message_found_ = VK_TRUE;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700218 result = VK_TRUE;
219 // We only want one match for each expected error so remove from set here
220 // Since we're about the break the loop it's ok to remove from set we're iterating over
221 desired_message_strings_.erase(desired_msg);
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600222 break;
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600223 }
224 }
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700225 for (auto desired_id : desired_message_ids_) {
226 if (desired_id == VALIDATION_ERROR_MAX_ENUM) {
227 // A message ID set to MAX_ENUM indicates a positive test - not expecting an error.
228 // Return true to avoid calling layers/driver with this error.
229 result = VK_TRUE;
230 } else if (desired_id == message_code) {
231 // Double-check that the string matches the error enum
232 if (errorString.find(validation_error_map[desired_id]) != string::npos) {
233 found_expected = true;
234 message_outstanding_count_--;
235 result = VK_TRUE;
236 message_found_ = VK_TRUE;
237 desired_message_ids_.erase(desired_id);
238 break;
239 } else {
240 // Treat this message as a regular unexpected error, but print a warning jic
241 printf("Message (%s) from MessageID %d does not correspond to expected message from error Database (%s)\n",
242 errorString.c_str(), desired_id, validation_error_map[desired_id]);
243 }
244 }
245 }
246
247 if (!found_expected) {
Jeremy Hayes2a54c012017-03-16 13:32:05 -0600248 printf("Unexpected: %s\n", msgString);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700249 other_messages_.push_back(errorString);
250 }
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600251 }
252
Dave Houltonfbf52152017-01-06 12:55:29 -0700253 test_platform_thread_unlock_mutex(&mutex_);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600254 return result;
Mike Stroyanaccf7692015-05-12 16:00:45 -0600255 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600256
Jeremy Hayes2a54c012017-03-16 13:32:05 -0600257 vector<string> GetOtherFailureMsgs(void) const { return other_messages_; }
258
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700259 VkDebugReportFlagsEXT GetMessageFlags(void) const { return message_flags_; }
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600260
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700261 VkBool32 AnyDesiredMsgFound(void) const { return message_found_; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600262
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700263 VkBool32 AllDesiredMsgsFound(void) const { return (0 == message_outstanding_count_); }
Dave Houltonfbf52152017-01-06 12:55:29 -0700264
265 void SetBailout(bool *bailout) { bailout_ = bailout; }
Tony Barbour300a6082015-04-07 13:44:53 -0600266
Jeremy Hayes2a54c012017-03-16 13:32:05 -0600267 void DumpFailureMsgs(void) const {
268 vector<string> otherMsgs = GetOtherFailureMsgs();
269 if (otherMsgs.size()) {
270 cout << "Other error messages logged for this test were:" << endl;
271 for (auto iter = otherMsgs.begin(); iter != otherMsgs.end(); iter++) {
272 cout << " " << *iter << endl;
Tony Barbour59b42282016-11-03 13:31:28 -0600273 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600274 }
275 }
276
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600277 // Helpers
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200278
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600279 // ExpectSuccess now takes an optional argument allowing a custom combination of debug flags
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700280 void ExpectSuccess(VkDebugReportFlagsEXT const message_flag_mask = VK_DEBUG_REPORT_ERROR_BIT_EXT) {
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600281 // Match ANY message matching specified type
282 SetDesiredFailureMsg(message_flag_mask, "");
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700283 message_flags_ = message_flag_mask; // override mask handling in SetDesired...
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200284 }
285
286 void VerifyFound() {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600287 // Not seeing the desired message is a failure. /Before/ throwing, dump any other messages.
Dave Houltonfbf52152017-01-06 12:55:29 -0700288 if (!AllDesiredMsgsFound()) {
Jeremy Hayes2a54c012017-03-16 13:32:05 -0600289 DumpFailureMsgs();
Dave Houltonfbf52152017-01-06 12:55:29 -0700290 for (auto desired_msg : desired_message_strings_) {
Dave Houltond5507dd2017-01-24 15:29:02 -0700291 ADD_FAILURE() << "Did not receive expected error '" << desired_msg << "'";
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600292 }
Dave Houltonfbf52152017-01-06 12:55:29 -0700293 for (auto desired_id : desired_message_ids_) {
Dave Houltond5507dd2017-01-24 15:29:02 -0700294 ADD_FAILURE() << "Did not receive expected error ENUM '" << desired_id << "'";
Tony Barbour59b42282016-11-03 13:31:28 -0600295 }
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200296 }
Dave Houltonfbf52152017-01-06 12:55:29 -0700297 Reset();
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200298 }
299
300 void VerifyNotFound() {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600301 // ExpectSuccess() configured us to match anything. Any error is a failure.
Dave Houltonfbf52152017-01-06 12:55:29 -0700302 if (AnyDesiredMsgFound()) {
Jeremy Hayes2a54c012017-03-16 13:32:05 -0600303 DumpFailureMsgs();
Dave Houltonfbf52152017-01-06 12:55:29 -0700304 for (auto msg : failure_message_strings_) {
Dave Houltond5507dd2017-01-24 15:29:02 -0700305 ADD_FAILURE() << "Expected to succeed but got error: " << msg;
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600306 }
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200307 }
Dave Houltonfbf52152017-01-06 12:55:29 -0700308 Reset();
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200309 }
310
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700311 private:
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700312 // TODO: This is stopgap to block new unexpected errors from being introduced. The long-term goal is to remove the use of this
313 // function and its definition.
314 bool IgnoreMessage(std::string const &msg) const {
315 if (ignore_message_strings_.empty()) {
316 return false;
317 }
318
319 return std::find_if(ignore_message_strings_.begin(), ignore_message_strings_.end(), [&msg](std::string const &str) {
320 return msg.find(str) != std::string::npos;
321 }) != ignore_message_strings_.end();
322 }
323
Mark Lobodzinski729a8d32017-01-26 12:16:30 -0700324 VkFlags message_flags_;
325 std::unordered_set<uint32_t> desired_message_ids_;
326 std::unordered_set<string> desired_message_strings_;
327 std::unordered_set<string> failure_message_strings_;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700328 std::vector<std::string> ignore_message_strings_;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -0700329 vector<string> other_messages_;
330 test_platform_thread_mutex mutex_;
331 bool *bailout_;
332 VkBool32 message_found_;
333 int message_outstanding_count_;
Tony Barbour300a6082015-04-07 13:44:53 -0600334};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500335
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600336static VKAPI_ATTR VkBool32 VKAPI_CALL myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType, uint64_t srcObject,
337 size_t location, int32_t msgCode, const char *pLayerPrefix, const char *pMsg,
338 void *pUserData) {
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600339 ErrorMonitor *errMonitor = (ErrorMonitor *)pUserData;
340 if (msgFlags & errMonitor->GetMessageFlags()) {
Dave Houltonc85c4a82017-04-25 15:56:45 -0600341#ifdef _DEBUG
342 char embedded_code_string[2048];
343 snprintf(embedded_code_string, 2048, "%s [%05d]", pMsg, msgCode);
344 return errMonitor->CheckForDesiredMsg(msgCode, embedded_code_string);
345#else
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600346 return errMonitor->CheckForDesiredMsg(msgCode, pMsg);
Dave Houltonc85c4a82017-04-25 15:56:45 -0600347#endif
Tony Barbour0b4d9562015-04-09 10:48:04 -0600348 }
Courtney Goeltzenleuchter06640832015-09-04 13:52:24 -0600349 return false;
Tony Barbour300a6082015-04-07 13:44:53 -0600350}
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500351
Karl Schultz6addd812016-02-02 17:17:23 -0700352class VkLayerTest : public VkRenderFramework {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700353 public:
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600354 void VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask);
355 void GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet,
Karl Schultz6addd812016-02-02 17:17:23 -0700356 BsoFailSelect failMask);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600357 void GenericDrawPreparation(VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask) {
358 GenericDrawPreparation(m_commandBuffer, pipelineobj, descriptorSet, failMask);
Karl Schultz6addd812016-02-02 17:17:23 -0700359 }
Tony Barbour300a6082015-04-07 13:44:53 -0600360
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600361 void Draw(uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance) {
362 m_commandBuffer->Draw(vertexCount, instanceCount, firstVertex, firstInstance);
Karl Schultz6addd812016-02-02 17:17:23 -0700363 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600364 void DrawIndexed(uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex, int32_t vertexOffset,
Karl Schultz6addd812016-02-02 17:17:23 -0700365 uint32_t firstInstance) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600366 m_commandBuffer->DrawIndexed(indexCount, instanceCount, firstIndex, vertexOffset, firstInstance);
Karl Schultz6addd812016-02-02 17:17:23 -0700367 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600368 void QueueCommandBuffer(bool checkSuccess = true) { m_commandBuffer->QueueCommandBuffer(checkSuccess); }
369 void QueueCommandBuffer(const VkFence &fence) { m_commandBuffer->QueueCommandBuffer(fence); }
370 void BindVertexBuffer(VkConstantBufferObj *vertexBuffer, VkDeviceSize offset, uint32_t binding) {
Karl Schultz6addd812016-02-02 17:17:23 -0700371 m_commandBuffer->BindVertexBuffer(vertexBuffer, offset, binding);
372 }
373 void BindIndexBuffer(VkIndexBufferObj *indexBuffer, VkDeviceSize offset) {
374 m_commandBuffer->BindIndexBuffer(indexBuffer, offset);
375 }
Tony Barbour1fa09702017-03-16 12:09:08 -0600376 void Init(VkPhysicalDeviceFeatures *features = nullptr, const VkCommandPoolCreateFlags flags = 0) {
377 InitFramework(instance_layer_names, instance_extension_names, device_extension_names, myDbgFunc, m_errorMonitor);
378 InitState(features, flags);
379 }
380
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700381 protected:
Karl Schultz6addd812016-02-02 17:17:23 -0700382 ErrorMonitor *m_errorMonitor;
Ian Elliott2c1daf52016-05-12 09:41:46 -0600383 bool m_enableWSI;
Tony Barbour1fa09702017-03-16 12:09:08 -0600384 std::vector<const char *> instance_layer_names;
385 std::vector<const char *> instance_extension_names;
386 std::vector<const char *> device_extension_names;
Tony Barbour300a6082015-04-07 13:44:53 -0600387
388 virtual void SetUp() {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700389 instance_extension_names.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME);
Courtney Goeltzenleuchterc2b06fe2015-06-16 15:59:11 -0600390 /*
391 * Since CreateDbgMsgCallback is an instance level extension call
392 * any extension / layer that utilizes that feature also needs
393 * to be enabled at create instance time.
394 */
Karl Schultz6addd812016-02-02 17:17:23 -0700395 // Use Threading layer first to protect others from
396 // ThreadCommandBufferCollision test
Courtney Goeltzenleuchter76885322016-02-06 17:11:22 -0700397 instance_layer_names.push_back("VK_LAYER_GOOGLE_threading");
Tobin Ehlis24aab042016-03-24 10:54:18 -0600398 instance_layer_names.push_back("VK_LAYER_LUNARG_parameter_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800399 instance_layer_names.push_back("VK_LAYER_LUNARG_object_tracker");
Tobin Ehlisc96f8062016-03-09 16:12:48 -0700400 instance_layer_names.push_back("VK_LAYER_LUNARG_core_validation");
Ian Elliotte48a1382016-04-28 14:22:58 -0600401 instance_layer_names.push_back("VK_LAYER_LUNARG_swapchain");
Dustin Graveseaa78cd2016-01-26 16:30:22 -0700402 instance_layer_names.push_back("VK_LAYER_GOOGLE_unique_objects");
Courtney Goeltzenleuchterd971b612015-06-17 20:51:59 -0600403
Ian Elliott2c1daf52016-05-12 09:41:46 -0600404 if (m_enableWSI) {
405 instance_extension_names.push_back(VK_KHR_SURFACE_EXTENSION_NAME);
406 device_extension_names.push_back(VK_KHR_SWAPCHAIN_EXTENSION_NAME);
407#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
408#if defined(VK_USE_PLATFORM_ANDROID_KHR)
409 instance_extension_names.push_back(VK_KHR_ANDROID_SURFACE_EXTENSION_NAME);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700410#endif // VK_USE_PLATFORM_ANDROID_KHR
Ian Elliott2c1daf52016-05-12 09:41:46 -0600411#if defined(VK_USE_PLATFORM_MIR_KHR)
412 instance_extension_names.push_back(VK_KHR_MIR_SURFACE_EXTENSION_NAME);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700413#endif // VK_USE_PLATFORM_MIR_KHR
Ian Elliott2c1daf52016-05-12 09:41:46 -0600414#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
415 instance_extension_names.push_back(VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700416#endif // VK_USE_PLATFORM_WAYLAND_KHR
Ian Elliott2c1daf52016-05-12 09:41:46 -0600417#if defined(VK_USE_PLATFORM_WIN32_KHR)
418 instance_extension_names.push_back(VK_KHR_WIN32_SURFACE_EXTENSION_NAME);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700419#endif // VK_USE_PLATFORM_WIN32_KHR
420#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott2c1daf52016-05-12 09:41:46 -0600421#if defined(VK_USE_PLATFORM_XCB_KHR)
422 instance_extension_names.push_back(VK_KHR_XCB_SURFACE_EXTENSION_NAME);
423#elif defined(VK_USE_PLATFORM_XLIB_KHR)
424 instance_extension_names.push_back(VK_KHR_XLIB_SURFACE_EXTENSION_NAME);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700425#endif // VK_USE_PLATFORM_XLIB_KHR
Ian Elliott2c1daf52016-05-12 09:41:46 -0600426 }
427
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600428 this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Tony Barbour300a6082015-04-07 13:44:53 -0600429 this->app_info.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800430 this->app_info.pApplicationName = "layer_tests";
431 this->app_info.applicationVersion = 1;
Tony Barbour300a6082015-04-07 13:44:53 -0600432 this->app_info.pEngineName = "unittest";
433 this->app_info.engineVersion = 1;
Jon Ashburnc5012ff2016-03-22 13:57:46 -0600434 this->app_info.apiVersion = VK_API_VERSION_1_0;
Tony Barbour300a6082015-04-07 13:44:53 -0600435
Tony Barbour15524c32015-04-29 17:34:29 -0600436 m_errorMonitor = new ErrorMonitor;
Tony Barbour300a6082015-04-07 13:44:53 -0600437 }
438
439 virtual void TearDown() {
440 // Clean up resources before we reset
Tony Barbour300a6082015-04-07 13:44:53 -0600441 ShutdownFramework();
Tony Barbour0b4d9562015-04-09 10:48:04 -0600442 delete m_errorMonitor;
Tony Barbour300a6082015-04-07 13:44:53 -0600443 }
Ian Elliott2c1daf52016-05-12 09:41:46 -0600444
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600445 VkLayerTest() { m_enableWSI = false; }
Tony Barbour300a6082015-04-07 13:44:53 -0600446};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500447
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600448void VkLayerTest::VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500449 // Create identity matrix
450 int i;
451 struct vktriangle_vs_uniform data;
452
453 glm::mat4 Projection = glm::mat4(1.0f);
Karl Schultz6addd812016-02-02 17:17:23 -0700454 glm::mat4 View = glm::mat4(1.0f);
455 glm::mat4 Model = glm::mat4(1.0f);
456 glm::mat4 MVP = Projection * View * Model;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500457 const int matrixSize = sizeof(MVP);
Karl Schultz6addd812016-02-02 17:17:23 -0700458 const int bufSize = sizeof(vktriangle_vs_uniform) / sizeof(float);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500459
460 memcpy(&data.mvp, &MVP[0][0], matrixSize);
461
Karl Schultz6addd812016-02-02 17:17:23 -0700462 static const Vertex tri_data[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600463 {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 -0500464 };
465
Karl Schultz6addd812016-02-02 17:17:23 -0700466 for (i = 0; i < 3; i++) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500467 data.position[i][0] = tri_data[i].posX;
468 data.position[i][1] = tri_data[i].posY;
469 data.position[i][2] = tri_data[i].posZ;
470 data.position[i][3] = tri_data[i].posW;
Karl Schultz6addd812016-02-02 17:17:23 -0700471 data.color[i][0] = tri_data[i].r;
472 data.color[i][1] = tri_data[i].g;
473 data.color[i][2] = tri_data[i].b;
474 data.color[i][3] = tri_data[i].a;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500475 }
476
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500477 ASSERT_NO_FATAL_FAILURE(InitViewport());
478
Chris Forbesbcfaadd2016-09-16 14:13:53 +1200479 VkConstantBufferObj constantBuffer(m_device, bufSize * 2, sizeof(float), (const void *)&data,
480 VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500481
Karl Schultz6addd812016-02-02 17:17:23 -0700482 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600483 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500484
485 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +0800486 pipelineobj.AddColorAttachment();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500487 pipelineobj.AddShader(&vs);
488 pipelineobj.AddShader(&ps);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600489 if (failMask & BsoFailLineWidth) {
490 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_LINE_WIDTH);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600491 VkPipelineInputAssemblyStateCreateInfo ia_state = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600492 ia_state.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600493 ia_state.topology = VK_PRIMITIVE_TOPOLOGY_LINE_LIST;
494 pipelineobj.SetInputAssembly(&ia_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600495 }
496 if (failMask & BsoFailDepthBias) {
497 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BIAS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600498 VkPipelineRasterizationStateCreateInfo rs_state = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600499 rs_state.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600500 rs_state.depthBiasEnable = VK_TRUE;
Mark Young7394fdd2016-03-31 14:56:43 -0600501 rs_state.lineWidth = 1.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600502 pipelineobj.SetRasterization(&rs_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600503 }
Rene Lindsayacbf5e62016-12-15 18:47:11 -0700504 // Viewport and scissors must stay in sync or other errors will occur than
Karl Schultz6addd812016-02-02 17:17:23 -0700505 // the ones we want
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600506 if (failMask & BsoFailViewport) {
507 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_VIEWPORT);
508 }
509 if (failMask & BsoFailScissor) {
510 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_SCISSOR);
511 }
512 if (failMask & BsoFailBlend) {
513 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_BLEND_CONSTANTS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600514 VkPipelineColorBlendAttachmentState att_state = {};
515 att_state.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
516 att_state.blendEnable = VK_TRUE;
517 pipelineobj.AddColorAttachment(0, &att_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600518 }
519 if (failMask & BsoFailDepthBounds) {
520 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BOUNDS);
521 }
522 if (failMask & BsoFailStencilReadMask) {
523 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK);
524 }
525 if (failMask & BsoFailStencilWriteMask) {
526 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_WRITE_MASK);
527 }
528 if (failMask & BsoFailStencilReference) {
529 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_REFERENCE);
530 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500531
532 VkDescriptorSetObj descriptorSet(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600533 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, constantBuffer);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500534
535 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour552f6c02016-12-21 14:34:07 -0700536 m_commandBuffer->BeginCommandBuffer();
537 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500538
Tony Barbourfe3351b2015-07-28 10:17:20 -0600539 GenericDrawPreparation(pipelineobj, descriptorSet, failMask);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500540
541 // render triangle
Tobin Ehlis379ba3b2016-07-19 11:22:29 -0600542 if (failMask & BsoFailIndexBuffer) {
543 // Use DrawIndexed w/o an index buffer bound
544 DrawIndexed(3, 1, 0, 0, 0);
545 } else {
546 Draw(3, 1, 0, 0);
547 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500548
Mark Muellerd4914412016-06-13 17:52:06 -0600549 if (failMask & BsoFailCmdClearAttachments) {
550 VkClearAttachment color_attachment = {};
551 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700552 color_attachment.colorAttachment = 1; // Someone who knew what they were doing would use 0 for the index;
Mark Muellerd4914412016-06-13 17:52:06 -0600553 VkClearRect clear_rect = {{{0, 0}, {static_cast<uint32_t>(m_width), static_cast<uint32_t>(m_height)}}, 0, 0};
554
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600555 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Muellerd4914412016-06-13 17:52:06 -0600556 }
557
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500558 // finalize recording of the command buffer
Tony Barbour552f6c02016-12-21 14:34:07 -0700559 m_commandBuffer->EndRenderPass();
560 m_commandBuffer->EndCommandBuffer();
Tony Barbourfe3351b2015-07-28 10:17:20 -0600561 QueueCommandBuffer();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500562}
563
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600564void VkLayerTest::GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj,
565 VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500566 if (m_depthStencil->Initialized()) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600567 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, m_depthStencil);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500568 } else {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600569 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500570 }
571
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800572 commandBuffer->PrepareAttachments();
Karl Schultz6addd812016-02-02 17:17:23 -0700573 // Make sure depthWriteEnable is set so that Depth fail test will work
574 // correctly
575 // Make sure stencilTestEnable is set so that Stencil fail test will work
576 // correctly
Tony Barboureb254902015-07-15 12:50:33 -0600577 VkStencilOpState stencil = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800578 stencil.failOp = VK_STENCIL_OP_KEEP;
579 stencil.passOp = VK_STENCIL_OP_KEEP;
580 stencil.depthFailOp = VK_STENCIL_OP_KEEP;
581 stencil.compareOp = VK_COMPARE_OP_NEVER;
Tony Barboureb254902015-07-15 12:50:33 -0600582
583 VkPipelineDepthStencilStateCreateInfo ds_ci = {};
584 ds_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600585 ds_ci.pNext = NULL;
586 ds_ci.depthTestEnable = VK_FALSE;
587 ds_ci.depthWriteEnable = VK_TRUE;
588 ds_ci.depthCompareOp = VK_COMPARE_OP_NEVER;
589 ds_ci.depthBoundsTestEnable = VK_FALSE;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600590 if (failMask & BsoFailDepthBounds) {
591 ds_ci.depthBoundsTestEnable = VK_TRUE;
Tobin Ehlis21c88352016-05-26 06:15:45 -0600592 ds_ci.maxDepthBounds = 0.0f;
593 ds_ci.minDepthBounds = 0.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600594 }
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600595 ds_ci.stencilTestEnable = VK_TRUE;
596 ds_ci.front = stencil;
597 ds_ci.back = stencil;
Tony Barboureb254902015-07-15 12:50:33 -0600598
Tobin Ehlis4bf96d12015-06-25 11:58:41 -0600599 pipelineobj.SetDepthStencil(&ds_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -0600600 pipelineobj.SetViewport(m_viewports);
601 pipelineobj.SetScissor(m_scissors);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800602 descriptorSet.CreateVKDescriptorSet(commandBuffer);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600603 VkResult err = pipelineobj.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Cody Northrop29a08f22015-08-27 10:20:35 -0600604 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800605 commandBuffer->BindPipeline(pipelineobj);
606 commandBuffer->BindDescriptorSet(descriptorSet);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500607}
608
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600609class VkPositiveLayerTest : public VkLayerTest {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700610 public:
611 protected:
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600612};
613
Ian Elliott2c1daf52016-05-12 09:41:46 -0600614class VkWsiEnabledLayerTest : public VkLayerTest {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700615 public:
616 protected:
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600617 VkWsiEnabledLayerTest() { m_enableWSI = true; }
Ian Elliott2c1daf52016-05-12 09:41:46 -0600618};
619
Mark Muellerdfe37552016-07-07 14:47:42 -0600620class VkBufferTest {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700621 public:
Mark Muellerdfe37552016-07-07 14:47:42 -0600622 enum eTestEnFlags {
623 eDoubleDelete,
624 eInvalidDeviceOffset,
625 eInvalidMemoryOffset,
626 eBindNullBuffer,
627 eFreeInvalidHandle,
Mark Mueller4042b652016-09-05 22:52:21 -0600628 eNone,
Mark Muellerdfe37552016-07-07 14:47:42 -0600629 };
630
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600631 enum eTestConditions { eOffsetAlignment = 1 };
Mark Muellerdfe37552016-07-07 14:47:42 -0600632
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600633 static bool GetTestConditionValid(VkDeviceObj *aVulkanDevice, eTestEnFlags aTestFlag, VkBufferUsageFlags aBufferUsage = 0) {
634 if (eInvalidDeviceOffset != aTestFlag && eInvalidMemoryOffset != aTestFlag) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600635 return true;
636 }
637 VkDeviceSize offset_limit = 0;
638 if (eInvalidMemoryOffset == aTestFlag) {
639 VkBuffer vulkanBuffer;
640 VkBufferCreateInfo buffer_create_info = {};
641 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
642 buffer_create_info.size = 32;
643 buffer_create_info.usage = aBufferUsage;
644
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600645 vkCreateBuffer(aVulkanDevice->device(), &buffer_create_info, nullptr, &vulkanBuffer);
Mark Mueller4042b652016-09-05 22:52:21 -0600646 VkMemoryRequirements memory_reqs = {};
Mark Muellerdfe37552016-07-07 14:47:42 -0600647
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600648 vkGetBufferMemoryRequirements(aVulkanDevice->device(), vulkanBuffer, &memory_reqs);
Mark Muellerdfe37552016-07-07 14:47:42 -0600649 vkDestroyBuffer(aVulkanDevice->device(), vulkanBuffer, nullptr);
650 offset_limit = memory_reqs.alignment;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600651 } else if ((VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT | VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT) & aBufferUsage) {
652 offset_limit = aVulkanDevice->props.limits.minTexelBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600653 } else if (VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT & aBufferUsage) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600654 offset_limit = aVulkanDevice->props.limits.minUniformBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600655 } else if (VK_BUFFER_USAGE_STORAGE_BUFFER_BIT & aBufferUsage) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600656 offset_limit = aVulkanDevice->props.limits.minStorageBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600657 }
658 if (eOffsetAlignment < offset_limit) {
659 return true;
660 }
661 return false;
662 }
663
664 // A constructor which performs validation tests within construction.
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600665 VkBufferTest(VkDeviceObj *aVulkanDevice, VkBufferUsageFlags aBufferUsage, eTestEnFlags aTestFlag = eNone)
666 : AllocateCurrent(false), BoundCurrent(false), CreateCurrent(false), VulkanDevice(aVulkanDevice->device()) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600667 if (eBindNullBuffer == aTestFlag) {
668 VulkanMemory = 0;
669 vkBindBufferMemory(VulkanDevice, VulkanBuffer, VulkanMemory, 0);
670 } else {
671 VkBufferCreateInfo buffer_create_info = {};
672 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
673 buffer_create_info.size = 32;
674 buffer_create_info.usage = aBufferUsage;
675
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600676 vkCreateBuffer(VulkanDevice, &buffer_create_info, nullptr, &VulkanBuffer);
Mark Muellerdfe37552016-07-07 14:47:42 -0600677
678 CreateCurrent = true;
679
680 VkMemoryRequirements memory_requirements;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600681 vkGetBufferMemoryRequirements(VulkanDevice, VulkanBuffer, &memory_requirements);
Mark Muellerdfe37552016-07-07 14:47:42 -0600682
683 VkMemoryAllocateInfo memory_allocate_info = {};
684 memory_allocate_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Cort Stratton77a0d592017-02-17 13:14:13 -0800685 memory_allocate_info.allocationSize = memory_requirements.size + eOffsetAlignment;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600686 bool pass = aVulkanDevice->phy().set_memory_type(memory_requirements.memoryTypeBits, &memory_allocate_info,
687 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Mark Muellerdfe37552016-07-07 14:47:42 -0600688 if (!pass) {
689 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
690 return;
691 }
692
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600693 vkAllocateMemory(VulkanDevice, &memory_allocate_info, NULL, &VulkanMemory);
Mark Muellerdfe37552016-07-07 14:47:42 -0600694 AllocateCurrent = true;
695 // NB: 1 is intentionally an invalid offset value
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600696 const bool offset_en = eInvalidDeviceOffset == aTestFlag || eInvalidMemoryOffset == aTestFlag;
697 vkBindBufferMemory(VulkanDevice, VulkanBuffer, VulkanMemory, offset_en ? eOffsetAlignment : 0);
Mark Muellerdfe37552016-07-07 14:47:42 -0600698 BoundCurrent = true;
699
700 InvalidDeleteEn = (eFreeInvalidHandle == aTestFlag);
701 }
702 }
703
704 ~VkBufferTest() {
705 if (CreateCurrent) {
706 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
707 }
708 if (AllocateCurrent) {
709 if (InvalidDeleteEn) {
710 union {
711 VkDeviceMemory device_memory;
712 unsigned long long index_access;
713 } bad_index;
714
715 bad_index.device_memory = VulkanMemory;
716 bad_index.index_access++;
717
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600718 vkFreeMemory(VulkanDevice, bad_index.device_memory, nullptr);
Mark Muellerdfe37552016-07-07 14:47:42 -0600719 }
720 vkFreeMemory(VulkanDevice, VulkanMemory, nullptr);
721 }
722 }
723
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600724 bool GetBufferCurrent() { return AllocateCurrent && BoundCurrent && CreateCurrent; }
Mark Muellerdfe37552016-07-07 14:47:42 -0600725
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600726 const VkBuffer &GetBuffer() { return VulkanBuffer; }
Mark Muellerdfe37552016-07-07 14:47:42 -0600727
728 void TestDoubleDestroy() {
729 // Destroy the buffer but leave the flag set, which will cause
730 // the buffer to be destroyed again in the destructor.
731 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
732 }
733
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700734 protected:
Mark Muellerdfe37552016-07-07 14:47:42 -0600735 bool AllocateCurrent;
736 bool BoundCurrent;
737 bool CreateCurrent;
738 bool InvalidDeleteEn;
739
740 VkBuffer VulkanBuffer;
741 VkDevice VulkanDevice;
742 VkDeviceMemory VulkanMemory;
Mark Muellerdfe37552016-07-07 14:47:42 -0600743};
744
745class VkVerticesObj {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700746 public:
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600747 VkVerticesObj(VkDeviceObj *aVulkanDevice, unsigned aAttributeCount, unsigned aBindingCount, unsigned aByteStride,
Mark Muellerdfe37552016-07-07 14:47:42 -0600748 VkDeviceSize aVertexCount, const float *aVerticies)
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700749 : BoundCurrent(false),
750 AttributeCount(aAttributeCount),
751 BindingCount(aBindingCount),
752 BindId(BindIdGenerator),
Mark Muellerdfe37552016-07-07 14:47:42 -0600753 PipelineVertexInputStateCreateInfo(),
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600754 VulkanMemoryBuffer(aVulkanDevice, 1, static_cast<int>(aByteStride * aVertexCount),
755 reinterpret_cast<const void *>(aVerticies), VK_BUFFER_USAGE_VERTEX_BUFFER_BIT) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700756 BindIdGenerator++; // NB: This can wrap w/misuse
Mark Muellerdfe37552016-07-07 14:47:42 -0600757
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600758 VertexInputAttributeDescription = new VkVertexInputAttributeDescription[AttributeCount];
759 VertexInputBindingDescription = new VkVertexInputBindingDescription[BindingCount];
Mark Muellerdfe37552016-07-07 14:47:42 -0600760
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600761 PipelineVertexInputStateCreateInfo.pVertexAttributeDescriptions = VertexInputAttributeDescription;
762 PipelineVertexInputStateCreateInfo.vertexAttributeDescriptionCount = AttributeCount;
763 PipelineVertexInputStateCreateInfo.pVertexBindingDescriptions = VertexInputBindingDescription;
764 PipelineVertexInputStateCreateInfo.vertexBindingDescriptionCount = BindingCount;
765 PipelineVertexInputStateCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -0600766
767 unsigned i = 0;
768 do {
769 VertexInputAttributeDescription[i].binding = BindId;
770 VertexInputAttributeDescription[i].location = i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600771 VertexInputAttributeDescription[i].format = VK_FORMAT_R32G32B32_SFLOAT;
772 VertexInputAttributeDescription[i].offset = sizeof(float) * aByteStride;
Mark Muellerdfe37552016-07-07 14:47:42 -0600773 i++;
774 } while (AttributeCount < i);
775
776 i = 0;
777 do {
778 VertexInputBindingDescription[i].binding = BindId;
779 VertexInputBindingDescription[i].stride = aByteStride;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600780 VertexInputBindingDescription[i].inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
Mark Muellerdfe37552016-07-07 14:47:42 -0600781 i++;
782 } while (BindingCount < i);
783 }
784
785 ~VkVerticesObj() {
786 if (VertexInputAttributeDescription) {
787 delete[] VertexInputAttributeDescription;
788 }
789 if (VertexInputBindingDescription) {
790 delete[] VertexInputBindingDescription;
791 }
792 }
793
794 bool AddVertexInputToPipe(VkPipelineObj &aPipelineObj) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600795 aPipelineObj.AddVertexInputAttribs(VertexInputAttributeDescription, AttributeCount);
796 aPipelineObj.AddVertexInputBindings(VertexInputBindingDescription, BindingCount);
Mark Muellerdfe37552016-07-07 14:47:42 -0600797 return true;
798 }
799
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600800 void BindVertexBuffers(VkCommandBuffer aCommandBuffer, unsigned aOffsetCount = 0, VkDeviceSize *aOffsetList = nullptr) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600801 VkDeviceSize *offsetList;
802 unsigned offsetCount;
803
804 if (aOffsetCount) {
805 offsetList = aOffsetList;
806 offsetCount = aOffsetCount;
807 } else {
808 offsetList = new VkDeviceSize[1]();
809 offsetCount = 1;
810 }
811
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600812 vkCmdBindVertexBuffers(aCommandBuffer, BindId, offsetCount, &VulkanMemoryBuffer.handle(), offsetList);
Mark Muellerdfe37552016-07-07 14:47:42 -0600813 BoundCurrent = true;
814
815 if (!aOffsetCount) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600816 delete[] offsetList;
Mark Muellerdfe37552016-07-07 14:47:42 -0600817 }
818 }
819
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700820 protected:
Mark Muellerdfe37552016-07-07 14:47:42 -0600821 static uint32_t BindIdGenerator;
822
823 bool BoundCurrent;
824 unsigned AttributeCount;
825 unsigned BindingCount;
826 uint32_t BindId;
827
828 VkPipelineVertexInputStateCreateInfo PipelineVertexInputStateCreateInfo;
829 VkVertexInputAttributeDescription *VertexInputAttributeDescription;
830 VkVertexInputBindingDescription *VertexInputBindingDescription;
831 VkConstantBufferObj VulkanMemoryBuffer;
832};
833
834uint32_t VkVerticesObj::BindIdGenerator;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500835// ********************************************************************************************************************
836// ********************************************************************************************************************
837// ********************************************************************************************************************
838// ********************************************************************************************************************
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600839TEST_F(VkLayerTest, RequiredParameter) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700840 TEST_DESCRIPTION(
841 "Specify VK_NULL_HANDLE, NULL, and 0 for required handle, "
842 "pointer, array, and array count parameters");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600843
Tony Barbour1fa09702017-03-16 12:09:08 -0600844 ASSERT_NO_FATAL_FAILURE(Init());
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600845
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600846 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pFeatures specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600847 // Specify NULL for a pointer to a handle
848 // Expected to trigger an error with
849 // parameter_validation::validate_required_pointer
850 vkGetPhysicalDeviceFeatures(gpu(), NULL);
851 m_errorMonitor->VerifyFound();
852
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600853 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
854 "required parameter pQueueFamilyPropertyCount specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600855 // Specify NULL for pointer to array count
856 // Expected to trigger an error with parameter_validation::validate_array
Dustin Gravesa4bb8c12016-05-16 17:22:51 -0600857 vkGetPhysicalDeviceQueueFamilyProperties(gpu(), NULL, NULL);
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600858 m_errorMonitor->VerifyFound();
859
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600860 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter viewportCount must be greater than 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600861 // Specify 0 for a required array count
862 // Expected to trigger an error with parameter_validation::validate_array
863 VkViewport view_port = {};
864 m_commandBuffer->SetViewport(0, 0, &view_port);
865 m_errorMonitor->VerifyFound();
866
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600867 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pViewports specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600868 // Specify NULL for a required array
869 // Expected to trigger an error with parameter_validation::validate_array
870 m_commandBuffer->SetViewport(0, 1, NULL);
871 m_errorMonitor->VerifyFound();
872
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600873 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter memory specified as VK_NULL_HANDLE");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600874 // Specify VK_NULL_HANDLE for a required handle
875 // Expected to trigger an error with
876 // parameter_validation::validate_required_handle
877 vkUnmapMemory(device(), VK_NULL_HANDLE);
878 m_errorMonitor->VerifyFound();
879
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600880 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
881 "required parameter pFences[0] specified as VK_NULL_HANDLE");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600882 // Specify VK_NULL_HANDLE for a required handle array entry
883 // Expected to trigger an error with
884 // parameter_validation::validate_required_handle_array
885 VkFence fence = VK_NULL_HANDLE;
886 vkResetFences(device(), 1, &fence);
887 m_errorMonitor->VerifyFound();
888
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600889 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pAllocateInfo specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600890 // Specify NULL for a required struct pointer
891 // Expected to trigger an error with
892 // parameter_validation::validate_struct_type
893 VkDeviceMemory memory = VK_NULL_HANDLE;
894 vkAllocateMemory(device(), NULL, NULL, &memory);
895 m_errorMonitor->VerifyFound();
896
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600897 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "value of faceMask must not be 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600898 // Specify 0 for a required VkFlags parameter
899 // Expected to trigger an error with parameter_validation::validate_flags
900 m_commandBuffer->SetStencilReference(0, 0);
901 m_errorMonitor->VerifyFound();
902
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600903 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 -0600904 // Specify 0 for a required VkFlags array entry
905 // Expected to trigger an error with
906 // parameter_validation::validate_flags_array
907 VkSemaphore semaphore = VK_NULL_HANDLE;
908 VkPipelineStageFlags stageFlags = 0;
909 VkSubmitInfo submitInfo = {};
910 submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
911 submitInfo.waitSemaphoreCount = 1;
912 submitInfo.pWaitSemaphores = &semaphore;
913 submitInfo.pWaitDstStageMask = &stageFlags;
914 vkQueueSubmit(m_device->m_queue, 1, &submitInfo, VK_NULL_HANDLE);
915 m_errorMonitor->VerifyFound();
916}
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600917
Dustin Gravesfce74c02016-05-10 11:42:58 -0600918TEST_F(VkLayerTest, ReservedParameter) {
919 TEST_DESCRIPTION("Specify a non-zero value for a reserved parameter");
920
Tony Barbour1fa09702017-03-16 12:09:08 -0600921 ASSERT_NO_FATAL_FAILURE(Init());
Dustin Gravesfce74c02016-05-10 11:42:58 -0600922
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600923 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " must be 0");
Dustin Gravesfce74c02016-05-10 11:42:58 -0600924 // Specify 0 for a reserved VkFlags parameter
925 // Expected to trigger an error with
926 // parameter_validation::validate_reserved_flags
927 VkEvent event_handle = VK_NULL_HANDLE;
928 VkEventCreateInfo event_info = {};
929 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
930 event_info.flags = 1;
931 vkCreateEvent(device(), &event_info, NULL, &event_handle);
932 m_errorMonitor->VerifyFound();
933}
934
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600935TEST_F(VkLayerTest, InvalidStructSType) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700936 TEST_DESCRIPTION(
937 "Specify an invalid VkStructureType for a Vulkan "
938 "structure's sType field");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600939
Tony Barbour1fa09702017-03-16 12:09:08 -0600940 ASSERT_NO_FATAL_FAILURE(Init());
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600941
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600942 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pAllocateInfo->sType must be");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600943 // Zero struct memory, effectively setting sType to
944 // VK_STRUCTURE_TYPE_APPLICATION_INFO
945 // Expected to trigger an error with
946 // parameter_validation::validate_struct_type
947 VkMemoryAllocateInfo alloc_info = {};
948 VkDeviceMemory memory = VK_NULL_HANDLE;
949 vkAllocateMemory(device(), &alloc_info, NULL, &memory);
950 m_errorMonitor->VerifyFound();
951
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600952 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pSubmits[0].sType must be");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600953 // Zero struct memory, effectively setting sType to
954 // VK_STRUCTURE_TYPE_APPLICATION_INFO
955 // Expected to trigger an error with
956 // parameter_validation::validate_struct_type_array
957 VkSubmitInfo submit_info = {};
958 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
959 m_errorMonitor->VerifyFound();
960}
961
962TEST_F(VkLayerTest, InvalidStructPNext) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600963 TEST_DESCRIPTION("Specify an invalid value for a Vulkan structure's pNext field");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600964
Tony Barbour1fa09702017-03-16 12:09:08 -0600965 ASSERT_NO_FATAL_FAILURE(Init());
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600966
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600967 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "value of pCreateInfo->pNext must be NULL");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600968 // Set VkMemoryAllocateInfo::pNext to a non-NULL value, when pNext must be NULL.
Karl Schultz38b50992016-07-11 16:09:09 -0600969 // Need to pick a function that has no allowed pNext structure types.
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600970 // Expected to trigger an error with parameter_validation::validate_struct_pnext
Karl Schultz38b50992016-07-11 16:09:09 -0600971 VkEvent event = VK_NULL_HANDLE;
Karl Schultz70db3902016-07-11 16:22:10 -0600972 VkEventCreateInfo event_alloc_info = {};
Karl Schultz38b50992016-07-11 16:09:09 -0600973 // Zero-initialization will provide the correct sType
974 VkApplicationInfo app_info = {};
975 event_alloc_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
976 event_alloc_info.pNext = &app_info;
977 vkCreateEvent(device(), &event_alloc_info, NULL, &event);
978 m_errorMonitor->VerifyFound();
979
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600980 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
981 " chain includes a structure with unexpected VkStructureType ");
Karl Schultz38b50992016-07-11 16:09:09 -0600982 // Set VkMemoryAllocateInfo::pNext to a non-NULL value, but use
983 // a function that has allowed pNext structure types and specify
984 // a structure type that is not allowed.
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600985 // Expected to trigger an error with parameter_validation::validate_struct_pnext
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600986 VkDeviceMemory memory = VK_NULL_HANDLE;
Dustin Graves47b6cba2016-05-10 17:34:38 -0600987 VkMemoryAllocateInfo memory_alloc_info = {};
988 memory_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
989 memory_alloc_info.pNext = &app_info;
990 vkAllocateMemory(device(), &memory_alloc_info, NULL, &memory);
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600991 m_errorMonitor->VerifyFound();
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600992}
Dustin Graves5d33d532016-05-09 16:21:12 -0600993
Chris Forbes93c08962017-05-19 11:25:59 -0700994TEST_F(VkLayerTest, UnrecognizedValueOutOfRange) {
Tony Barbour1fa09702017-03-16 12:09:08 -0600995 ASSERT_NO_FATAL_FAILURE(Init());
Dustin Graves5d33d532016-05-09 16:21:12 -0600996
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700997 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
998 "does not fall within the begin..end "
999 "range of the core VkFormat "
1000 "enumeration tokens");
Dustin Graves5d33d532016-05-09 16:21:12 -06001001 // Specify an invalid VkFormat value
1002 // Expected to trigger an error with
1003 // parameter_validation::validate_ranged_enum
1004 VkFormatProperties format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001005 vkGetPhysicalDeviceFormatProperties(gpu(), static_cast<VkFormat>(8000), &format_properties);
Dustin Graves5d33d532016-05-09 16:21:12 -06001006 m_errorMonitor->VerifyFound();
Chris Forbes93c08962017-05-19 11:25:59 -07001007}
1008
1009TEST_F(VkLayerTest, UnrecognizedValueBadMask) {
1010 ASSERT_NO_FATAL_FAILURE(Init());
Dustin Graves5d33d532016-05-09 16:21:12 -06001011
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001012 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 -06001013 // Specify an invalid VkFlags bitmask value
1014 // Expected to trigger an error with parameter_validation::validate_flags
1015 VkImageFormatProperties image_format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001016 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
1017 static_cast<VkImageUsageFlags>(1 << 25), 0, &image_format_properties);
Dustin Graves5d33d532016-05-09 16:21:12 -06001018 m_errorMonitor->VerifyFound();
Chris Forbes93c08962017-05-19 11:25:59 -07001019}
1020
1021TEST_F(VkLayerTest, UnrecognizedValueBadFlag) {
1022 ASSERT_NO_FATAL_FAILURE(Init());
Dustin Graves5d33d532016-05-09 16:21:12 -06001023
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001024 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 -06001025 // Specify an invalid VkFlags array entry
1026 // Expected to trigger an error with
1027 // parameter_validation::validate_flags_array
1028 VkSemaphore semaphore = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001029 VkPipelineStageFlags stage_flags = static_cast<VkPipelineStageFlags>(1 << 25);
Dustin Graves5d33d532016-05-09 16:21:12 -06001030 VkSubmitInfo submit_info = {};
1031 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1032 submit_info.waitSemaphoreCount = 1;
1033 submit_info.pWaitSemaphores = &semaphore;
1034 submit_info.pWaitDstStageMask = &stage_flags;
1035 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
1036 m_errorMonitor->VerifyFound();
Chris Forbes93c08962017-05-19 11:25:59 -07001037}
1038
1039TEST_F(VkLayerTest, UnrecognizedValueBadBool) {
1040 ASSERT_NO_FATAL_FAILURE(Init());
Dustin Graves5d33d532016-05-09 16:21:12 -06001041
Cort Strattonedbe9b82017-05-16 07:38:35 -07001042 // Sneak in a test to make sure using VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE
1043 // doesn't trigger a false positive.
1044 uint32_t extension_count = 0;
1045 bool supports_mirror_clamp = false;
1046 VkResult err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, nullptr);
1047 ASSERT_VK_SUCCESS(err);
1048 if (extension_count > 0) {
1049 std::vector<VkExtensionProperties> available_extensions(extension_count);
1050
1051 err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, &available_extensions[0]);
1052 ASSERT_VK_SUCCESS(err);
1053 for (const auto &extension_props : available_extensions) {
1054 if (strcmp(extension_props.extensionName, VK_KHR_SAMPLER_MIRROR_CLAMP_TO_EDGE_EXTENSION_NAME) == 0) {
1055 supports_mirror_clamp = true;
1056 }
1057 }
1058 }
1059 VkSamplerAddressMode address_mode = VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE;
1060 if (!supports_mirror_clamp) {
1061 printf(" mirror_clamp_to_edge Extension not supported, skipping tests\n");
1062 address_mode = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
Cort Strattonedbe9b82017-05-16 07:38:35 -07001063 }
1064
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001065 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "is neither VK_TRUE nor VK_FALSE");
Dustin Graves5d33d532016-05-09 16:21:12 -06001066 // Specify an invalid VkBool32 value
1067 // Expected to trigger a warning with
1068 // parameter_validation::validate_bool32
1069 VkSampler sampler = VK_NULL_HANDLE;
1070 VkSamplerCreateInfo sampler_info = {};
1071 sampler_info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
1072 sampler_info.pNext = NULL;
1073 sampler_info.magFilter = VK_FILTER_NEAREST;
1074 sampler_info.minFilter = VK_FILTER_NEAREST;
1075 sampler_info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
Cort Strattonedbe9b82017-05-16 07:38:35 -07001076 sampler_info.addressModeU = address_mode;
1077 sampler_info.addressModeV = address_mode;
1078 sampler_info.addressModeW = address_mode;
Dustin Graves5d33d532016-05-09 16:21:12 -06001079 sampler_info.mipLodBias = 1.0;
1080 sampler_info.maxAnisotropy = 1;
1081 sampler_info.compareEnable = VK_FALSE;
1082 sampler_info.compareOp = VK_COMPARE_OP_NEVER;
1083 sampler_info.minLod = 1.0;
1084 sampler_info.maxLod = 1.0;
1085 sampler_info.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
1086 sampler_info.unnormalizedCoordinates = VK_FALSE;
1087 // Not VK_TRUE or VK_FALSE
1088 sampler_info.anisotropyEnable = 3;
1089 vkCreateSampler(m_device->device(), &sampler_info, NULL, &sampler);
1090 m_errorMonitor->VerifyFound();
Chris Forbes93c08962017-05-19 11:25:59 -07001091}
1092
1093#if 0
1094TEST_F(VkLayerTest, UnrecognizedValueMaxEnum) {
1095 ASSERT_NO_FATAL_FAILURE(Init());
Cort Strattonedbe9b82017-05-16 07:38:35 -07001096
1097 // Specify MAX_ENUM
1098 VkDescriptorSetLayoutBinding binding = {};
1099 binding.binding = 0;
1100 binding.descriptorType = VK_DESCRIPTOR_TYPE_MAX_ENUM;
1101 binding.descriptorCount = 1;
1102 binding.stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
1103 VkDescriptorSetLayoutCreateInfo layout_ci = {};
1104 layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1105 layout_ci.bindingCount = 1;
1106 layout_ci.pBindings = &binding;
1107 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "does not fall within the begin..end range");
1108 VkDescriptorSetLayout layout = VK_NULL_HANDLE;
1109 vkCreateDescriptorSetLayout(device(), &layout_ci, NULL, &layout);
1110 m_errorMonitor->VerifyFound();
1111 if (layout != VK_NULL_HANDLE) {
1112 vkDestroyDescriptorSetLayout(device(), layout, NULL);
1113 }
Dustin Graves5d33d532016-05-09 16:21:12 -06001114}
Chris Forbes93c08962017-05-19 11:25:59 -07001115#endif
Dustin Gravesfce74c02016-05-10 11:42:58 -06001116
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001117TEST_F(VkLayerTest, UpdateBufferAlignment) {
1118 TEST_DESCRIPTION("Check alignment parameters for vkCmdUpdateBuffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001119 uint32_t updateData[] = {1, 2, 3, 4, 5, 6, 7, 8};
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001120
Tony Barbour1fa09702017-03-16 12:09:08 -06001121 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001122
1123 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1124 vk_testing::Buffer buffer;
1125 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
1126
Tony Barbour552f6c02016-12-21 14:34:07 -07001127 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001128 // Introduce failure by using dstOffset that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001129 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001130 m_commandBuffer->UpdateBuffer(buffer.handle(), 1, 4, updateData);
1131 m_errorMonitor->VerifyFound();
1132
1133 // Introduce failure by using dataSize that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001134 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001135 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 6, updateData);
1136 m_errorMonitor->VerifyFound();
1137
1138 // Introduce failure by using dataSize that is < 0
1139 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001140 "must be greater than zero and less than or equal to 65536");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001141 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, -44, updateData);
1142 m_errorMonitor->VerifyFound();
1143
1144 // Introduce failure by using dataSize that is > 65536
1145 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001146 "must be greater than zero and less than or equal to 65536");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001147 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 80000, updateData);
1148 m_errorMonitor->VerifyFound();
1149
Tony Barbour552f6c02016-12-21 14:34:07 -07001150 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001151}
1152
1153TEST_F(VkLayerTest, FillBufferAlignment) {
1154 TEST_DESCRIPTION("Check alignment parameters for vkCmdFillBuffer");
1155
Tony Barbour1fa09702017-03-16 12:09:08 -06001156 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001157
1158 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1159 vk_testing::Buffer buffer;
1160 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
1161
Tony Barbour552f6c02016-12-21 14:34:07 -07001162 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001163
1164 // Introduce failure by using dstOffset that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001165 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001166 m_commandBuffer->FillBuffer(buffer.handle(), 1, 4, 0x11111111);
1167 m_errorMonitor->VerifyFound();
1168
1169 // Introduce failure by using size that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001170 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001171 m_commandBuffer->FillBuffer(buffer.handle(), 0, 6, 0x11111111);
1172 m_errorMonitor->VerifyFound();
1173
1174 // Introduce failure by using size that is zero
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001175 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must be greater than zero");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001176 m_commandBuffer->FillBuffer(buffer.handle(), 0, 0, 0x11111111);
1177 m_errorMonitor->VerifyFound();
1178
Tony Barbour552f6c02016-12-21 14:34:07 -07001179 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001180}
Dustin Graves40f35822016-06-23 11:12:53 -06001181
Cortd889ff92016-07-27 09:51:27 -07001182TEST_F(VkLayerTest, PSOPolygonModeInvalid) {
1183 VkResult err;
1184
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001185 TEST_DESCRIPTION(
1186 "Attempt to use a non-solid polygon fill mode in a "
1187 "pipeline when this feature is not enabled.");
Cortd889ff92016-07-27 09:51:27 -07001188
Tony Barbour1fa09702017-03-16 12:09:08 -06001189 ASSERT_NO_FATAL_FAILURE(Init());
Cortd889ff92016-07-27 09:51:27 -07001190 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1191
1192 std::vector<const char *> device_extension_names;
1193 auto features = m_device->phy().features();
1194 // Artificially disable support for non-solid fill modes
Chris Forbes05054022017-05-17 16:29:06 -07001195 features.fillModeNonSolid = VK_FALSE;
Cortd889ff92016-07-27 09:51:27 -07001196 // The sacrificial device object
1197 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
1198
1199 VkRenderpassObj render_pass(&test_device);
1200
1201 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1202 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1203 pipeline_layout_ci.setLayoutCount = 0;
1204 pipeline_layout_ci.pSetLayouts = NULL;
1205
1206 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001207 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Cortd889ff92016-07-27 09:51:27 -07001208 ASSERT_VK_SUCCESS(err);
1209
1210 VkPipelineRasterizationStateCreateInfo rs_ci = {};
1211 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
1212 rs_ci.pNext = nullptr;
1213 rs_ci.lineWidth = 1.0f;
Chris Forbes05054022017-05-17 16:29:06 -07001214 rs_ci.rasterizerDiscardEnable = VK_TRUE;
Cortd889ff92016-07-27 09:51:27 -07001215
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001216 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
1217 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Cortd889ff92016-07-27 09:51:27 -07001218
Mark Lobodzinski5e644732016-08-15 16:51:19 -06001219 // Set polygonMode to unsupported value POINT, should fail
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001220 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1221 "polygonMode cannot be VK_POLYGON_MODE_POINT or VK_POLYGON_MODE_LINE");
Cortd889ff92016-07-27 09:51:27 -07001222 {
1223 VkPipelineObj pipe(&test_device);
1224 pipe.AddShader(&vs);
1225 pipe.AddShader(&fs);
1226 pipe.AddColorAttachment();
1227 // Introduce failure by setting unsupported polygon mode
1228 rs_ci.polygonMode = VK_POLYGON_MODE_POINT;
1229 pipe.SetRasterization(&rs_ci);
1230 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
1231 }
1232 m_errorMonitor->VerifyFound();
1233
1234 // Try again with polygonMode=LINE, should fail
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001235 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1236 "polygonMode cannot be VK_POLYGON_MODE_POINT or VK_POLYGON_MODE_LINE");
Cortd889ff92016-07-27 09:51:27 -07001237 {
1238 VkPipelineObj pipe(&test_device);
1239 pipe.AddShader(&vs);
1240 pipe.AddShader(&fs);
1241 pipe.AddColorAttachment();
1242 // Introduce failure by setting unsupported polygon mode
1243 rs_ci.polygonMode = VK_POLYGON_MODE_LINE;
1244 pipe.SetRasterization(&rs_ci);
1245 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
1246 }
1247 m_errorMonitor->VerifyFound();
1248
Cortd889ff92016-07-27 09:51:27 -07001249 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
1250}
1251
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001252#if 0
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001253TEST_F(VkLayerTest, CallResetCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001254{
1255 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001256 VkFenceCreateInfo fenceInfo = {};
1257 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1258 fenceInfo.pNext = NULL;
1259 fenceInfo.flags = 0;
1260
Mike Weiblencce7ec72016-10-17 19:33:05 -06001261 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Resetting command buffer");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001262
Tony Barbour1fa09702017-03-16 12:09:08 -06001263 ASSERT_NO_FATAL_FAILURE(Init());
Tony Barbourc1eb1a52015-07-20 13:00:10 -06001264
1265 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1266 vk_testing::Buffer buffer;
1267 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001268
Tony Barbourfe3351b2015-07-28 10:17:20 -06001269 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001270 m_commandBuffer->FillBuffer(buffer.handle(), 0, 4, 0x11111111);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001271 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001272
1273 testFence.init(*m_device, fenceInfo);
1274
1275 // Bypass framework since it does the waits automatically
1276 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001277 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001278 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1279 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001280 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001281 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001282 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001283 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001284 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001285 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001286 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001287
1288 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001289 ASSERT_VK_SUCCESS( err );
1290
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001291 // Introduce failure by calling begin again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001292 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001293
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001294 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001295}
1296
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001297TEST_F(VkLayerTest, CallBeginCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001298{
1299 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001300 VkFenceCreateInfo fenceInfo = {};
1301 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1302 fenceInfo.pNext = NULL;
1303 fenceInfo.flags = 0;
1304
Mike Weiblencce7ec72016-10-17 19:33:05 -06001305 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Calling vkBeginCommandBuffer() on active command buffer");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001306
Tony Barbour1fa09702017-03-16 12:09:08 -06001307 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001308 ASSERT_NO_FATAL_FAILURE(InitViewport());
1309 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1310
Tony Barbourfe3351b2015-07-28 10:17:20 -06001311 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001312 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001313 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001314
1315 testFence.init(*m_device, fenceInfo);
1316
1317 // Bypass framework since it does the waits automatically
1318 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001319 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001320 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1321 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001322 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001323 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001324 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001325 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001326 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001327 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001328 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001329
1330 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001331 ASSERT_VK_SUCCESS( err );
1332
Jon Ashburnf19916e2016-01-11 13:12:43 -07001333 VkCommandBufferInheritanceInfo hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001334 VkCommandBufferBeginInfo info = {};
1335 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
1336 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001337 info.renderPass = VK_NULL_HANDLE;
1338 info.subpass = 0;
1339 info.framebuffer = VK_NULL_HANDLE;
Chia-I Wub8d47ae2015-11-11 10:18:12 +08001340 info.occlusionQueryEnable = VK_FALSE;
1341 info.queryFlags = 0;
1342 info.pipelineStatistics = 0;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001343
1344 // Introduce failure by calling BCB again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001345 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001346
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001347 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001348}
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001349#endif
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001350
Mark Lobodzinski833bb552016-12-15 07:41:13 -07001351TEST_F(VkLayerTest, SparseBindingImageBufferCreate) {
1352 TEST_DESCRIPTION("Create buffer/image with sparse attributes but without the sparse_binding bit set");
1353
Tony Barbour1fa09702017-03-16 12:09:08 -06001354 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski833bb552016-12-15 07:41:13 -07001355
1356 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00669);
1357 VkBuffer buffer;
1358 VkBufferCreateInfo buf_info = {};
1359 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1360 buf_info.pNext = NULL;
1361 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
1362 buf_info.size = 2048;
1363 buf_info.queueFamilyIndexCount = 0;
1364 buf_info.pQueueFamilyIndices = NULL;
1365 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1366 buf_info.flags = VK_BUFFER_CREATE_SPARSE_RESIDENCY_BIT;
1367 vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1368 m_errorMonitor->VerifyFound();
1369
1370 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02160);
1371 VkImage image;
1372 VkImageCreateInfo image_create_info = {};
1373 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1374 image_create_info.pNext = NULL;
1375 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1376 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1377 image_create_info.extent.width = 512;
1378 image_create_info.extent.height = 64;
1379 image_create_info.extent.depth = 1;
1380 image_create_info.mipLevels = 1;
1381 image_create_info.arrayLayers = 1;
1382 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1383 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
1384 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1385 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1386 image_create_info.queueFamilyIndexCount = 0;
1387 image_create_info.pQueueFamilyIndices = NULL;
1388 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1389 image_create_info.flags = VK_BUFFER_CREATE_SPARSE_ALIASED_BIT;
1390 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1391 m_errorMonitor->VerifyFound();
1392}
1393
Dave Houlton829c0d82017-01-24 15:09:17 -07001394TEST_F(VkLayerTest, SparseResidencyImageCreateUnsupportedTypes) {
1395 TEST_DESCRIPTION("Create images with sparse residency with unsupported types");
1396
1397 // Determine which device feature are available
Dave Houlton0ba0fdf2017-03-29 12:05:26 -06001398 VkPhysicalDeviceFeatures device_features = {};
Dave Houlton8e0fe7a2017-03-30 10:32:10 -06001399 ASSERT_NO_FATAL_FAILURE(
1400 InitFramework(instance_layer_names, instance_extension_names, device_extension_names, myDbgFunc, m_errorMonitor));
Dave Houlton0ba0fdf2017-03-29 12:05:26 -06001401 ASSERT_NO_FATAL_FAILURE(GetPhysicalDeviceFeatures(&device_features));
Dave Houlton829c0d82017-01-24 15:09:17 -07001402
Dave Houlton8e0fe7a2017-03-30 10:32:10 -06001403 // Mask out device features we don't want and initialize device state
Dave Houlton0ba0fdf2017-03-29 12:05:26 -06001404 device_features.sparseResidencyImage2D = VK_FALSE;
1405 device_features.sparseResidencyImage3D = VK_FALSE;
Dave Houlton8e0fe7a2017-03-30 10:32:10 -06001406 ASSERT_NO_FATAL_FAILURE(InitState(&device_features));
Dave Houlton829c0d82017-01-24 15:09:17 -07001407
1408 VkImage image = VK_NULL_HANDLE;
1409 VkResult result = VK_RESULT_MAX_ENUM;
1410 VkImageCreateInfo image_create_info = {};
1411 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1412 image_create_info.pNext = NULL;
1413 image_create_info.imageType = VK_IMAGE_TYPE_1D;
1414 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1415 image_create_info.extent.width = 512;
1416 image_create_info.extent.height = 1;
1417 image_create_info.extent.depth = 1;
1418 image_create_info.mipLevels = 1;
1419 image_create_info.arrayLayers = 1;
1420 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1421 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
1422 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1423 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1424 image_create_info.queueFamilyIndexCount = 0;
1425 image_create_info.pQueueFamilyIndices = NULL;
1426 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1427 image_create_info.flags = VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT | VK_BUFFER_CREATE_SPARSE_BINDING_BIT;
1428
1429 // 1D image w/ sparse residency is an error
1430 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02352);
1431 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1432 m_errorMonitor->VerifyFound();
1433 if (VK_SUCCESS == result) {
1434 vkDestroyImage(m_device->device(), image, NULL);
1435 image = VK_NULL_HANDLE;
1436 }
1437
1438 // 2D image w/ sparse residency when feature isn't available
1439 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1440 image_create_info.extent.height = 64;
1441 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02144);
1442 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1443 m_errorMonitor->VerifyFound();
1444 if (VK_SUCCESS == result) {
1445 vkDestroyImage(m_device->device(), image, NULL);
1446 image = VK_NULL_HANDLE;
1447 }
1448
1449 // 3D image w/ sparse residency when feature isn't available
1450 image_create_info.imageType = VK_IMAGE_TYPE_3D;
1451 image_create_info.extent.depth = 8;
1452 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02145);
1453 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1454 m_errorMonitor->VerifyFound();
1455 if (VK_SUCCESS == result) {
1456 vkDestroyImage(m_device->device(), image, NULL);
1457 image = VK_NULL_HANDLE;
1458 }
1459}
1460
1461TEST_F(VkLayerTest, SparseResidencyImageCreateUnsupportedSamples) {
1462 TEST_DESCRIPTION("Create images with sparse residency with unsupported tiling or sample counts");
1463
1464 // Determine which device feature are available
Dave Houlton0ba0fdf2017-03-29 12:05:26 -06001465 VkPhysicalDeviceFeatures device_features = {};
Dave Houlton8e0fe7a2017-03-30 10:32:10 -06001466 ASSERT_NO_FATAL_FAILURE(
1467 InitFramework(instance_layer_names, instance_extension_names, device_extension_names, myDbgFunc, m_errorMonitor));
Dave Houlton0ba0fdf2017-03-29 12:05:26 -06001468 ASSERT_NO_FATAL_FAILURE(GetPhysicalDeviceFeatures(&device_features));
Dave Houlton829c0d82017-01-24 15:09:17 -07001469
Dave Houlton0ba0fdf2017-03-29 12:05:26 -06001470 // These tests require that the device support sparse residency for 2D images
1471 if (VK_TRUE != device_features.sparseResidencyImage2D) {
1472 printf(" Test requires unsupported SparseResidencyImage2D feature. Skipped.\n");
Dave Houlton829c0d82017-01-24 15:09:17 -07001473 return;
1474 }
1475
Dave Houlton8e0fe7a2017-03-30 10:32:10 -06001476 // Mask out device features we don't want and initialize device state
Dave Houlton0ba0fdf2017-03-29 12:05:26 -06001477 device_features.sparseResidency2Samples = VK_FALSE;
1478 device_features.sparseResidency4Samples = VK_FALSE;
1479 device_features.sparseResidency8Samples = VK_FALSE;
1480 device_features.sparseResidency16Samples = VK_FALSE;
Dave Houlton8e0fe7a2017-03-30 10:32:10 -06001481 ASSERT_NO_FATAL_FAILURE(InitState(&device_features));
Dave Houlton829c0d82017-01-24 15:09:17 -07001482
1483 VkImage image = VK_NULL_HANDLE;
1484 VkResult result = VK_RESULT_MAX_ENUM;
1485 VkImageCreateInfo image_create_info = {};
1486 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1487 image_create_info.pNext = NULL;
1488 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1489 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1490 image_create_info.extent.width = 64;
1491 image_create_info.extent.height = 64;
1492 image_create_info.extent.depth = 1;
1493 image_create_info.mipLevels = 1;
1494 image_create_info.arrayLayers = 1;
1495 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1496 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1497 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1498 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1499 image_create_info.queueFamilyIndexCount = 0;
1500 image_create_info.pQueueFamilyIndices = NULL;
1501 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1502 image_create_info.flags = VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT | VK_BUFFER_CREATE_SPARSE_BINDING_BIT;
1503
1504 // 2D image w/ sparse residency and linear tiling is an error
1505 m_errorMonitor->SetDesiredFailureMsg(
1506 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1507 "VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT then image tiling of VK_IMAGE_TILING_LINEAR is not supported");
1508 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1509 m_errorMonitor->VerifyFound();
1510 if (VK_SUCCESS == result) {
1511 vkDestroyImage(m_device->device(), image, NULL);
1512 image = VK_NULL_HANDLE;
1513 }
1514 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
1515
1516 // Multi-sample image w/ sparse residency when feature isn't available (4 flavors)
1517 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
1518 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02146);
1519 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1520 m_errorMonitor->VerifyFound();
1521 if (VK_SUCCESS == result) {
1522 vkDestroyImage(m_device->device(), image, NULL);
1523 image = VK_NULL_HANDLE;
1524 }
1525
1526 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
1527 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02147);
1528 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1529 m_errorMonitor->VerifyFound();
1530 if (VK_SUCCESS == result) {
1531 vkDestroyImage(m_device->device(), image, NULL);
1532 image = VK_NULL_HANDLE;
1533 }
1534
1535 image_create_info.samples = VK_SAMPLE_COUNT_8_BIT;
1536 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02148);
1537 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1538 m_errorMonitor->VerifyFound();
1539 if (VK_SUCCESS == result) {
1540 vkDestroyImage(m_device->device(), image, NULL);
1541 image = VK_NULL_HANDLE;
1542 }
1543
1544 image_create_info.samples = VK_SAMPLE_COUNT_16_BIT;
1545 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02149);
1546 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1547 m_errorMonitor->VerifyFound();
1548 if (VK_SUCCESS == result) {
1549 vkDestroyImage(m_device->device(), image, NULL);
1550 image = VK_NULL_HANDLE;
1551 }
1552}
1553
Tobin Ehlisf11be982016-05-11 13:52:53 -06001554TEST_F(VkLayerTest, InvalidMemoryAliasing) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001555 TEST_DESCRIPTION(
1556 "Create a buffer and image, allocate memory, and bind the "
1557 "buffer and image to memory such that they will alias.");
Tobin Ehlisf11be982016-05-11 13:52:53 -06001558 VkResult err;
1559 bool pass;
Tony Barbour1fa09702017-03-16 12:09:08 -06001560 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisf11be982016-05-11 13:52:53 -06001561
Tobin Ehlis077ded32016-05-12 17:39:13 -06001562 VkBuffer buffer, buffer2;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001563 VkImage image;
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001564 VkImage image2;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001565 VkDeviceMemory mem; // buffer will be bound first
1566 VkDeviceMemory mem_img; // image bound first
Tobin Ehlis077ded32016-05-12 17:39:13 -06001567 VkMemoryRequirements buff_mem_reqs, img_mem_reqs;
Rene Lindsayd14f5572016-12-16 14:57:18 -07001568 VkMemoryRequirements buff_mem_reqs2, img_mem_reqs2;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001569
1570 VkBufferCreateInfo buf_info = {};
1571 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1572 buf_info.pNext = NULL;
1573 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1574 buf_info.size = 256;
1575 buf_info.queueFamilyIndexCount = 0;
1576 buf_info.pQueueFamilyIndices = NULL;
1577 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1578 buf_info.flags = 0;
1579 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1580 ASSERT_VK_SUCCESS(err);
1581
Tobin Ehlis077ded32016-05-12 17:39:13 -06001582 vkGetBufferMemoryRequirements(m_device->device(), buffer, &buff_mem_reqs);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001583
1584 VkImageCreateInfo image_create_info = {};
1585 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1586 image_create_info.pNext = NULL;
1587 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1588 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1589 image_create_info.extent.width = 64;
1590 image_create_info.extent.height = 64;
1591 image_create_info.extent.depth = 1;
1592 image_create_info.mipLevels = 1;
1593 image_create_info.arrayLayers = 1;
1594 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis12a4b5e2016-08-08 12:33:11 -06001595 // Image tiling must be optimal to trigger error when aliasing linear buffer
1596 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001597 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1598 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1599 image_create_info.queueFamilyIndexCount = 0;
1600 image_create_info.pQueueFamilyIndices = NULL;
1601 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1602 image_create_info.flags = 0;
1603
Tobin Ehlisf11be982016-05-11 13:52:53 -06001604 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1605 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001606 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
1607 ASSERT_VK_SUCCESS(err);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001608
Tobin Ehlis077ded32016-05-12 17:39:13 -06001609 vkGetImageMemoryRequirements(m_device->device(), image, &img_mem_reqs);
1610
1611 VkMemoryAllocateInfo alloc_info = {};
1612 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1613 alloc_info.pNext = NULL;
1614 alloc_info.memoryTypeIndex = 0;
1615 // Ensure memory is big enough for both bindings
1616 alloc_info.allocationSize = buff_mem_reqs.size + img_mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001617 pass = m_device->phy().set_memory_type(buff_mem_reqs.memoryTypeBits & img_mem_reqs.memoryTypeBits, &alloc_info,
1618 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001619 if (!pass) {
Tobin Ehlis077ded32016-05-12 17:39:13 -06001620 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001621 vkDestroyImage(m_device->device(), image, NULL);
Mark Lobodzinskid2d2d4c2017-02-16 11:51:58 -07001622 vkDestroyImage(m_device->device(), image2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001623 return;
1624 }
Tobin Ehlis077ded32016-05-12 17:39:13 -06001625 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1626 ASSERT_VK_SUCCESS(err);
1627 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
1628 ASSERT_VK_SUCCESS(err);
1629
Rene Lindsayd14f5572016-12-16 14:57:18 -07001630 vkGetImageMemoryRequirements(m_device->device(), image2, &img_mem_reqs2);
1631
Tobin Ehlis32b2bbc2016-12-13 17:33:41 -07001632 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " is aliased with linear buffer 0x");
Tobin Ehlis077ded32016-05-12 17:39:13 -06001633 // VALIDATION FAILURE due to image mapping overlapping buffer mapping
Tobin Ehlisf11be982016-05-11 13:52:53 -06001634 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1635 m_errorMonitor->VerifyFound();
1636
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001637 // Now correctly bind image2 to second mem allocation before incorrectly
Tobin Ehlis077ded32016-05-12 17:39:13 -06001638 // aliasing buffer2
1639 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer2);
1640 ASSERT_VK_SUCCESS(err);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001641 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem_img);
1642 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001643 err = vkBindImageMemory(m_device->device(), image2, mem_img, 0);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001644 ASSERT_VK_SUCCESS(err);
Tobin Ehlis32b2bbc2016-12-13 17:33:41 -07001645 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "is aliased with non-linear image 0x");
Rene Lindsayd14f5572016-12-16 14:57:18 -07001646 vkGetBufferMemoryRequirements(m_device->device(), buffer2, &buff_mem_reqs2);
Tobin Ehlis077ded32016-05-12 17:39:13 -06001647 err = vkBindBufferMemory(m_device->device(), buffer2, mem_img, 0);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001648 m_errorMonitor->VerifyFound();
1649
1650 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlis077ded32016-05-12 17:39:13 -06001651 vkDestroyBuffer(m_device->device(), buffer2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001652 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001653 vkDestroyImage(m_device->device(), image2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001654 vkFreeMemory(m_device->device(), mem, NULL);
1655 vkFreeMemory(m_device->device(), mem_img, NULL);
1656}
1657
Tobin Ehlis35372522016-05-12 08:32:31 -06001658TEST_F(VkLayerTest, InvalidMemoryMapping) {
1659 TEST_DESCRIPTION("Attempt to map memory in a number of incorrect ways");
1660 VkResult err;
1661 bool pass;
Tony Barbour1fa09702017-03-16 12:09:08 -06001662 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis35372522016-05-12 08:32:31 -06001663
1664 VkBuffer buffer;
1665 VkDeviceMemory mem;
1666 VkMemoryRequirements mem_reqs;
1667
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001668 const VkDeviceSize atom_size = m_device->props.limits.nonCoherentAtomSize;
1669
Tobin Ehlis35372522016-05-12 08:32:31 -06001670 VkBufferCreateInfo buf_info = {};
1671 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1672 buf_info.pNext = NULL;
1673 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1674 buf_info.size = 256;
1675 buf_info.queueFamilyIndexCount = 0;
1676 buf_info.pQueueFamilyIndices = NULL;
1677 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1678 buf_info.flags = 0;
1679 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1680 ASSERT_VK_SUCCESS(err);
1681
1682 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
1683 VkMemoryAllocateInfo alloc_info = {};
1684 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1685 alloc_info.pNext = NULL;
1686 alloc_info.memoryTypeIndex = 0;
1687
1688 // Ensure memory is big enough for both bindings
1689 static const VkDeviceSize allocation_size = 0x10000;
1690 alloc_info.allocationSize = allocation_size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001691 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 -06001692 if (!pass) {
1693 vkDestroyBuffer(m_device->device(), buffer, NULL);
1694 return;
1695 }
1696 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1697 ASSERT_VK_SUCCESS(err);
1698
1699 uint8_t *pData;
1700 // Attempt to map memory size 0 is invalid
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001701 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 -06001702 err = vkMapMemory(m_device->device(), mem, 0, 0, 0, (void **)&pData);
1703 m_errorMonitor->VerifyFound();
1704 // Map memory twice
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001705 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001706 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001707 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1708 "VkMapMemory: Attempting to map memory on an already-mapped object ");
1709 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001710 m_errorMonitor->VerifyFound();
1711
1712 // Unmap the memory to avoid re-map error
1713 vkUnmapMemory(m_device->device(), mem);
1714 // overstep allocation with VK_WHOLE_SIZE
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001715 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1716 " with size of VK_WHOLE_SIZE oversteps total array size 0x");
1717 err = vkMapMemory(m_device->device(), mem, allocation_size + 1, VK_WHOLE_SIZE, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001718 m_errorMonitor->VerifyFound();
1719 // overstep allocation w/o VK_WHOLE_SIZE
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001720 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " oversteps total array size 0x");
1721 err = vkMapMemory(m_device->device(), mem, 1, allocation_size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001722 m_errorMonitor->VerifyFound();
1723 // Now error due to unmapping memory that's not mapped
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001724 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Unmapping Memory without memory being mapped: ");
Tobin Ehlis35372522016-05-12 08:32:31 -06001725 vkUnmapMemory(m_device->device(), mem);
1726 m_errorMonitor->VerifyFound();
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001727
Tobin Ehlis35372522016-05-12 08:32:31 -06001728 // Now map memory and cause errors due to flushing invalid ranges
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001729 err = vkMapMemory(m_device->device(), mem, 4 * atom_size, VK_WHOLE_SIZE, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001730 ASSERT_VK_SUCCESS(err);
1731 VkMappedMemoryRange mmr = {};
Chris Forbes3aec0892016-06-13 10:29:26 +12001732 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
Tobin Ehlis35372522016-05-12 08:32:31 -06001733 mmr.memory = mem;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001734 mmr.offset = atom_size; // Error b/c offset less than offset of mapped mem
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001735 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00642);
Tobin Ehlis35372522016-05-12 08:32:31 -06001736 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1737 m_errorMonitor->VerifyFound();
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001738
Tobin Ehlis35372522016-05-12 08:32:31 -06001739 // Now flush range that oversteps mapped range
1740 vkUnmapMemory(m_device->device(), mem);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001741 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001742 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001743 mmr.offset = atom_size;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001744 mmr.size = 4 * atom_size; // Flushing bounds exceed mapped bounds
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001745 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00642);
1746 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1747 m_errorMonitor->VerifyFound();
1748
1749 // Now flush range with VK_WHOLE_SIZE that oversteps offset
1750 vkUnmapMemory(m_device->device(), mem);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001751 err = vkMapMemory(m_device->device(), mem, 2 * atom_size, 4 * atom_size, 0, (void **)&pData);
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001752 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001753 mmr.offset = atom_size;
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001754 mmr.size = VK_WHOLE_SIZE;
1755 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00643);
Tobin Ehlis35372522016-05-12 08:32:31 -06001756 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1757 m_errorMonitor->VerifyFound();
1758
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001759#if 0 // Planning discussion with working group on this validation check.
Mark Lobodzinski3826a4f2016-11-15 09:38:51 -07001760 // Some platforms have an atomsize of 1 which makes the test meaningless
1761 if (atom_size > 3) {
1762 // Now with an offset NOT a multiple of the device limit
1763 vkUnmapMemory(m_device->device(), mem);
1764 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
1765 ASSERT_VK_SUCCESS(err);
1766 mmr.offset = 3; // Not a multiple of atom_size
1767 mmr.size = VK_WHOLE_SIZE;
1768 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00644);
1769 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1770 m_errorMonitor->VerifyFound();
1771
1772 // Now with a size NOT a multiple of the device limit
1773 vkUnmapMemory(m_device->device(), mem);
1774 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
1775 ASSERT_VK_SUCCESS(err);
1776 mmr.offset = atom_size;
1777 mmr.size = 2 * atom_size + 1; // Not a multiple of atom_size
1778 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00645);
1779 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1780 m_errorMonitor->VerifyFound();
1781 }
Tony Barboure3975eb2016-12-15 14:52:44 -07001782#endif
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001783 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
1784 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Tobin Ehlis35372522016-05-12 08:32:31 -06001785 if (!pass) {
1786 vkFreeMemory(m_device->device(), mem, NULL);
1787 vkDestroyBuffer(m_device->device(), buffer, NULL);
1788 return;
1789 }
1790 // TODO : If we can get HOST_VISIBLE w/o HOST_COHERENT we can test cases of
1791 // MEMTRACK_INVALID_MAP in validateAndCopyNoncoherentMemoryToDriver()
1792
1793 vkDestroyBuffer(m_device->device(), buffer, NULL);
1794 vkFreeMemory(m_device->device(), mem, NULL);
1795}
1796
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001797#if 0 // disabled until PV gets real extension enable checks
Ian Elliott1c32c772016-04-28 14:47:13 -06001798TEST_F(VkLayerTest, EnableWsiBeforeUse) {
1799 VkResult err;
1800 bool pass;
1801
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001802 // FIXME: After we turn on this code for non-Linux platforms, uncomment the
1803 // following declaration (which is temporarily being moved below):
1804 // VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott1c32c772016-04-28 14:47:13 -06001805 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001806 VkSwapchainCreateInfoKHR swapchain_create_info = {VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR};
Ian Elliott1c32c772016-04-28 14:47:13 -06001807 uint32_t swapchain_image_count = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001808 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
Ian Elliott1c32c772016-04-28 14:47:13 -06001809 uint32_t image_index = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001810 // VkPresentInfoKHR present_info = {};
Ian Elliott1c32c772016-04-28 14:47:13 -06001811
Tony Barbour1fa09702017-03-16 12:09:08 -06001812 ASSERT_NO_FATAL_FAILURE(Init());
Ian Elliott1c32c772016-04-28 14:47:13 -06001813
Ian Elliott3f06ce52016-04-29 14:46:21 -06001814#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
1815#if defined(VK_USE_PLATFORM_ANDROID_KHR)
1816 // Use the functions from the VK_KHR_android_surface extension without
1817 // enabling that extension:
1818
1819 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001820 VkAndroidSurfaceCreateInfoKHR android_create_info = {VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001821 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1822 err = vkCreateAndroidSurfaceKHR(instance(), &android_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001823 pass = (err != VK_SUCCESS);
1824 ASSERT_TRUE(pass);
1825 m_errorMonitor->VerifyFound();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001826#endif // VK_USE_PLATFORM_ANDROID_KHR
Ian Elliott3f06ce52016-04-29 14:46:21 -06001827
Ian Elliott3f06ce52016-04-29 14:46:21 -06001828#if defined(VK_USE_PLATFORM_MIR_KHR)
1829 // Use the functions from the VK_KHR_mir_surface extension without enabling
1830 // that extension:
1831
1832 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001833 VkMirSurfaceCreateInfoKHR mir_create_info = {VK_STRUCTURE_TYPE_MIR_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001834 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott3f06ce52016-04-29 14:46:21 -06001835 err = vkCreateMirSurfaceKHR(instance(), &mir_create_info, NULL, &surface);
1836 pass = (err != VK_SUCCESS);
1837 ASSERT_TRUE(pass);
1838 m_errorMonitor->VerifyFound();
1839
1840 // Tell whether an mir_connection supports presentation:
1841 MirConnection *mir_connection = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001842 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1843 vkGetPhysicalDeviceMirPresentationSupportKHR(gpu(), 0, mir_connection, visual_id);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001844 m_errorMonitor->VerifyFound();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001845#endif // VK_USE_PLATFORM_MIR_KHR
Ian Elliott3f06ce52016-04-29 14:46:21 -06001846
Ian Elliott3f06ce52016-04-29 14:46:21 -06001847#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
1848 // Use the functions from the VK_KHR_wayland_surface extension without
1849 // enabling that extension:
1850
1851 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001852 VkWaylandSurfaceCreateInfoKHR wayland_create_info = {VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001853 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1854 err = vkCreateWaylandSurfaceKHR(instance(), &wayland_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001855 pass = (err != VK_SUCCESS);
1856 ASSERT_TRUE(pass);
1857 m_errorMonitor->VerifyFound();
1858
1859 // Tell whether an wayland_display supports presentation:
1860 struct wl_display wayland_display = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001861 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1862 vkGetPhysicalDeviceWaylandPresentationSupportKHR(gpu(), 0, &wayland_display);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001863 m_errorMonitor->VerifyFound();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001864#endif // VK_USE_PLATFORM_WAYLAND_KHR
1865#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott3f06ce52016-04-29 14:46:21 -06001866
Ian Elliott3f06ce52016-04-29 14:46:21 -06001867#if defined(VK_USE_PLATFORM_WIN32_KHR)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001868 // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1869 // TO NON-LINUX PLATFORMS:
1870 VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott3f06ce52016-04-29 14:46:21 -06001871 // Use the functions from the VK_KHR_win32_surface extension without
1872 // enabling that extension:
1873
1874 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001875 VkWin32SurfaceCreateInfoKHR win32_create_info = {VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001876 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1877 err = vkCreateWin32SurfaceKHR(instance(), &win32_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001878 pass = (err != VK_SUCCESS);
1879 ASSERT_TRUE(pass);
1880 m_errorMonitor->VerifyFound();
1881
1882 // Tell whether win32 supports presentation:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001883 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott489eec02016-05-05 14:12:44 -06001884 vkGetPhysicalDeviceWin32PresentationSupportKHR(gpu(), 0);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001885 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001886// Set this (for now, until all platforms are supported and tested):
1887#define NEED_TO_TEST_THIS_ON_PLATFORM
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001888#endif // VK_USE_PLATFORM_WIN32_KHR
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07001889#if defined(VK_USE_PLATFORM_XCB_KHR) || defined(VK_USE_PLATFORM_XLIB_KHR)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001890 // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1891 // TO NON-LINUX PLATFORMS:
1892 VkSurfaceKHR surface = VK_NULL_HANDLE;
Tony Barbour2e7bd402016-11-14 14:46:33 -07001893#endif
1894#if defined(VK_USE_PLATFORM_XCB_KHR)
Ian Elliott1c32c772016-04-28 14:47:13 -06001895 // Use the functions from the VK_KHR_xcb_surface extension without enabling
1896 // that extension:
1897
1898 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001899 VkXcbSurfaceCreateInfoKHR xcb_create_info = {VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001900 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001901 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
1902 pass = (err != VK_SUCCESS);
1903 ASSERT_TRUE(pass);
1904 m_errorMonitor->VerifyFound();
1905
1906 // Tell whether an xcb_visualid_t supports presentation:
Ian Elliott3f06ce52016-04-29 14:46:21 -06001907 xcb_connection_t *xcb_connection = NULL;
Ian Elliott1c32c772016-04-28 14:47:13 -06001908 xcb_visualid_t visual_id = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001909 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1910 vkGetPhysicalDeviceXcbPresentationSupportKHR(gpu(), 0, xcb_connection, visual_id);
Ian Elliott1c32c772016-04-28 14:47:13 -06001911 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001912// Set this (for now, until all platforms are supported and tested):
1913#define NEED_TO_TEST_THIS_ON_PLATFORM
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001914#endif // VK_USE_PLATFORM_XCB_KHR
Ian Elliott1c32c772016-04-28 14:47:13 -06001915
Ian Elliott12630812016-04-29 14:35:43 -06001916#if defined(VK_USE_PLATFORM_XLIB_KHR)
1917 // Use the functions from the VK_KHR_xlib_surface extension without enabling
1918 // that extension:
1919
1920 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001921 VkXlibSurfaceCreateInfoKHR xlib_create_info = {VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001922 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06001923 err = vkCreateXlibSurfaceKHR(instance(), &xlib_create_info, NULL, &surface);
1924 pass = (err != VK_SUCCESS);
1925 ASSERT_TRUE(pass);
1926 m_errorMonitor->VerifyFound();
1927
1928 // Tell whether an Xlib VisualID supports presentation:
1929 Display *dpy = NULL;
1930 VisualID visual = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001931 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06001932 vkGetPhysicalDeviceXlibPresentationSupportKHR(gpu(), 0, dpy, visual);
1933 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001934// Set this (for now, until all platforms are supported and tested):
1935#define NEED_TO_TEST_THIS_ON_PLATFORM
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001936#endif // VK_USE_PLATFORM_XLIB_KHR
Ian Elliott12630812016-04-29 14:35:43 -06001937
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001938// Use the functions from the VK_KHR_surface extension without enabling
1939// that extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06001940
Ian Elliott489eec02016-05-05 14:12:44 -06001941#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001942 // Destroy a surface:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001943 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001944 vkDestroySurfaceKHR(instance(), surface, NULL);
1945 m_errorMonitor->VerifyFound();
1946
1947 // Check if surface supports presentation:
1948 VkBool32 supported = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001949 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001950 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
1951 pass = (err != VK_SUCCESS);
1952 ASSERT_TRUE(pass);
1953 m_errorMonitor->VerifyFound();
1954
1955 // Check surface capabilities:
1956 VkSurfaceCapabilitiesKHR capabilities = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001957 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1958 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &capabilities);
Ian Elliott1c32c772016-04-28 14:47:13 -06001959 pass = (err != VK_SUCCESS);
1960 ASSERT_TRUE(pass);
1961 m_errorMonitor->VerifyFound();
1962
1963 // Check surface formats:
1964 uint32_t format_count = 0;
1965 VkSurfaceFormatKHR *formats = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001966 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1967 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &format_count, formats);
Ian Elliott1c32c772016-04-28 14:47:13 -06001968 pass = (err != VK_SUCCESS);
1969 ASSERT_TRUE(pass);
1970 m_errorMonitor->VerifyFound();
1971
1972 // Check surface present modes:
1973 uint32_t present_mode_count = 0;
1974 VkSurfaceFormatKHR *present_modes = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001975 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1976 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &present_mode_count, present_modes);
Ian Elliott1c32c772016-04-28 14:47:13 -06001977 pass = (err != VK_SUCCESS);
1978 ASSERT_TRUE(pass);
1979 m_errorMonitor->VerifyFound();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001980#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001981
Ian Elliott1c32c772016-04-28 14:47:13 -06001982 // Use the functions from the VK_KHR_swapchain extension without enabling
1983 // that extension:
1984
1985 // Create a swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001986 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001987 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
1988 swapchain_create_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001989 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
Ian Elliott1c32c772016-04-28 14:47:13 -06001990 pass = (err != VK_SUCCESS);
1991 ASSERT_TRUE(pass);
1992 m_errorMonitor->VerifyFound();
1993
1994 // Get the images from the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001995 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1996 err = vkGetSwapchainImagesKHR(m_device->device(), swapchain, &swapchain_image_count, NULL);
Ian Elliott1c32c772016-04-28 14:47:13 -06001997 pass = (err != VK_SUCCESS);
1998 ASSERT_TRUE(pass);
1999 m_errorMonitor->VerifyFound();
2000
Chris Forbeseb7d5502016-09-13 18:19:21 +12002001 // Add a fence to avoid (justifiable) error about not providing fence OR semaphore
2002 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
2003 VkFence fence;
2004 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
2005
Ian Elliott1c32c772016-04-28 14:47:13 -06002006 // Try to acquire an image:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002007 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Chris Forbeseb7d5502016-09-13 18:19:21 +12002008 err = vkAcquireNextImageKHR(m_device->device(), swapchain, 0, VK_NULL_HANDLE, fence, &image_index);
Ian Elliott1c32c772016-04-28 14:47:13 -06002009 pass = (err != VK_SUCCESS);
2010 ASSERT_TRUE(pass);
2011 m_errorMonitor->VerifyFound();
2012
Chris Forbeseb7d5502016-09-13 18:19:21 +12002013 vkDestroyFence(m_device->device(), fence, nullptr);
2014
Ian Elliott1c32c772016-04-28 14:47:13 -06002015 // Try to present an image:
Ian Elliott2c1daf52016-05-12 09:41:46 -06002016 //
2017 // NOTE: Currently can't test this because a real swapchain is needed (as
2018 // opposed to the fake one we created) in order for the layer to lookup the
2019 // VkDevice used to enable the extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06002020
2021 // Destroy the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002022 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06002023 vkDestroySwapchainKHR(m_device->device(), swapchain, NULL);
2024 m_errorMonitor->VerifyFound();
2025}
Chris Forbes09368e42016-10-13 11:59:22 +13002026#endif
Ian Elliott1c32c772016-04-28 14:47:13 -06002027
Karl Schultz6addd812016-02-02 17:17:23 -07002028TEST_F(VkLayerTest, MapMemWithoutHostVisibleBit) {
2029 VkResult err;
2030 bool pass;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002031
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002032 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2033 "Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002034
Tony Barbour1fa09702017-03-16 12:09:08 -06002035 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002036
2037 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07002038 VkImage image;
2039 VkDeviceMemory mem;
2040 VkMemoryRequirements mem_reqs;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002041
Karl Schultz6addd812016-02-02 17:17:23 -07002042 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2043 const int32_t tex_width = 32;
2044 const int32_t tex_height = 32;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002045
Tony Barboureb254902015-07-15 12:50:33 -06002046 VkImageCreateInfo image_create_info = {};
2047 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07002048 image_create_info.pNext = NULL;
2049 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2050 image_create_info.format = tex_format;
2051 image_create_info.extent.width = tex_width;
2052 image_create_info.extent.height = tex_height;
2053 image_create_info.extent.depth = 1;
2054 image_create_info.mipLevels = 1;
2055 image_create_info.arrayLayers = 1;
2056 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2057 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2058 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2059 image_create_info.flags = 0;
Chris Forbese65e4d02016-09-13 17:39:18 +12002060 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002061
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002062 VkMemoryAllocateInfo mem_alloc = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002063 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07002064 mem_alloc.pNext = NULL;
2065 mem_alloc.allocationSize = 0;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002066
Chia-I Wuf7458c52015-10-26 21:10:41 +08002067 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002068 ASSERT_VK_SUCCESS(err);
2069
Karl Schultz6addd812016-02-02 17:17:23 -07002070 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002071
Mark Lobodzinski23065352015-05-29 09:32:35 -05002072 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002073
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002074 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002075 if (!pass) { // If we can't find any unmappable memory this test doesn't
2076 // make sense
Chia-I Wuf7458c52015-10-26 21:10:41 +08002077 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbour02fdc7d2015-08-04 16:13:01 -06002078 return;
Mike Stroyand1c84a52015-08-18 14:40:24 -06002079 }
Mike Stroyan713b2d72015-08-04 10:49:29 -06002080
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002081 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002082 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002083 ASSERT_VK_SUCCESS(err);
2084
2085 // Try to bind free memory that has been freed
Tony Barbour67e99152015-07-10 14:10:27 -06002086 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002087 ASSERT_VK_SUCCESS(err);
2088
2089 // Map memory as if to initialize the image
2090 void *mappedAddress = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002091 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, &mappedAddress);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002092
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002093 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002094
Chia-I Wuf7458c52015-10-26 21:10:41 +08002095 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06002096 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002097}
2098
Karl Schultz6addd812016-02-02 17:17:23 -07002099TEST_F(VkLayerTest, RebindMemory) {
2100 VkResult err;
2101 bool pass;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002102
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002103 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which has already been bound to mem object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002104
Tony Barbour1fa09702017-03-16 12:09:08 -06002105 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002106
2107 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07002108 VkImage image;
2109 VkDeviceMemory mem1;
2110 VkDeviceMemory mem2;
2111 VkMemoryRequirements mem_reqs;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002112
Karl Schultz6addd812016-02-02 17:17:23 -07002113 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2114 const int32_t tex_width = 32;
2115 const int32_t tex_height = 32;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002116
Tony Barboureb254902015-07-15 12:50:33 -06002117 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002118 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2119 image_create_info.pNext = NULL;
2120 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2121 image_create_info.format = tex_format;
2122 image_create_info.extent.width = tex_width;
2123 image_create_info.extent.height = tex_height;
2124 image_create_info.extent.depth = 1;
2125 image_create_info.mipLevels = 1;
2126 image_create_info.arrayLayers = 1;
2127 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2128 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2129 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2130 image_create_info.flags = 0;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002131
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002132 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002133 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2134 mem_alloc.pNext = NULL;
2135 mem_alloc.allocationSize = 0;
2136 mem_alloc.memoryTypeIndex = 0;
Tony Barboureb254902015-07-15 12:50:33 -06002137
Karl Schultz6addd812016-02-02 17:17:23 -07002138 // Introduce failure, do NOT set memProps to
2139 // VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
Tony Barboureb254902015-07-15 12:50:33 -06002140 mem_alloc.memoryTypeIndex = 1;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002141 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002142 ASSERT_VK_SUCCESS(err);
2143
Karl Schultz6addd812016-02-02 17:17:23 -07002144 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002145
2146 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002147 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002148 ASSERT_TRUE(pass);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002149
2150 // allocate 2 memory objects
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002151 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem1);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002152 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002153 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem2);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002154 ASSERT_VK_SUCCESS(err);
2155
2156 // Bind first memory object to Image object
Tony Barbour67e99152015-07-10 14:10:27 -06002157 err = vkBindImageMemory(m_device->device(), image, mem1, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002158 ASSERT_VK_SUCCESS(err);
2159
Karl Schultz6addd812016-02-02 17:17:23 -07002160 // Introduce validation failure, try to bind a different memory object to
2161 // the same image object
Tony Barbour67e99152015-07-10 14:10:27 -06002162 err = vkBindImageMemory(m_device->device(), image, mem2, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002163
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002164 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002165
Chia-I Wuf7458c52015-10-26 21:10:41 +08002166 vkDestroyImage(m_device->device(), image, NULL);
2167 vkFreeMemory(m_device->device(), mem1, NULL);
2168 vkFreeMemory(m_device->device(), mem2, NULL);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002169}
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002170
Karl Schultz6addd812016-02-02 17:17:23 -07002171TEST_F(VkLayerTest, SubmitSignaledFence) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002172 vk_testing::Fence testFence;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002173
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002174 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2175 "submitted in SIGNALED state. Fences "
2176 "must be reset before being submitted");
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002177
2178 VkFenceCreateInfo fenceInfo = {};
Tony Barbour0b4d9562015-04-09 10:48:04 -06002179 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2180 fenceInfo.pNext = NULL;
2181 fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
Tony Barbour300a6082015-04-07 13:44:53 -06002182
Tony Barbour1fa09702017-03-16 12:09:08 -06002183 ASSERT_NO_FATAL_FAILURE(Init());
Tony Barbour300a6082015-04-07 13:44:53 -06002184 ASSERT_NO_FATAL_FAILURE(InitViewport());
2185 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2186
Tony Barbour552f6c02016-12-21 14:34:07 -07002187 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002188 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbour552f6c02016-12-21 14:34:07 -07002189 m_commandBuffer->EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -06002190
2191 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002192
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002193 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08002194 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2195 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002196 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002197 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07002198 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002199 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002200 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08002201 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002202 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06002203
2204 vkQueueSubmit(m_device->m_queue, 1, &submit_info, testFence.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07002205 vkQueueWaitIdle(m_device->m_queue);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002206
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002207 m_errorMonitor->VerifyFound();
Tony Barbour0b4d9562015-04-09 10:48:04 -06002208}
Chris Forbes4e44c912016-06-16 10:20:00 +12002209
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002210TEST_F(VkLayerTest, InvalidUsageBits) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002211 TEST_DESCRIPTION(
2212 "Specify wrong usage for image then create conflicting view of image "
2213 "Initialize buffer with wrong usage then perform copy expecting errors "
2214 "from both the image and the buffer (2 calls)");
Mark Lobodzinski33826372017-04-13 11:10:11 -06002215 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid usage flag for Image ");
Tobin Ehlis41376e12015-07-03 08:45:14 -06002216
Tony Barbour1fa09702017-03-16 12:09:08 -06002217 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -06002218 auto format = FindSupportedDepthStencilFormat(gpu());
Tony Barbourf887b162017-03-09 10:06:46 -07002219 if (!format) {
2220 printf(" No Depth + Stencil format found. Skipped.\n");
2221 return;
2222 }
Chris Forbesd2b5fe42016-11-28 18:00:00 +13002223
Tony Barbourf92621a2016-05-02 14:28:12 -06002224 VkImageObj image(m_device);
Tony Barbour75d79f02016-08-30 09:39:07 -06002225 // Initialize image with USAGE_TRANSIENT_ATTACHMENT
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06002226 image.Init(128, 128, 1, format, VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Karl Schultzb5bc11e2016-05-04 08:36:08 -06002227 ASSERT_TRUE(image.initialized());
Tobin Ehlis41376e12015-07-03 08:45:14 -06002228
Tony Barbourf92621a2016-05-02 14:28:12 -06002229 VkImageView dsv;
2230 VkImageViewCreateInfo dsvci = {};
2231 dsvci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
2232 dsvci.image = image.handle();
2233 dsvci.viewType = VK_IMAGE_VIEW_TYPE_2D;
Chris Forbesd2b5fe42016-11-28 18:00:00 +13002234 dsvci.format = format;
Tony Barbourf92621a2016-05-02 14:28:12 -06002235 dsvci.subresourceRange.layerCount = 1;
2236 dsvci.subresourceRange.baseMipLevel = 0;
2237 dsvci.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002238 dsvci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis41376e12015-07-03 08:45:14 -06002239
Tony Barbourf92621a2016-05-02 14:28:12 -06002240 // Create a view with depth / stencil aspect for image with different usage
2241 vkCreateImageView(m_device->device(), &dsvci, NULL, &dsv);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002242
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002243 m_errorMonitor->VerifyFound();
Tony Barbourf92621a2016-05-02 14:28:12 -06002244
2245 // Initialize buffer with TRANSFER_DST usage
2246 vk_testing::Buffer buffer;
2247 VkMemoryPropertyFlags reqs = 0;
2248 buffer.init_as_dst(*m_device, 128 * 128, reqs);
2249 VkBufferImageCopy region = {};
2250 region.bufferRowLength = 128;
2251 region.bufferImageHeight = 128;
Mark Lobodzinski80871462017-02-16 10:37:27 -07002252 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Tony Barbourf92621a2016-05-02 14:28:12 -06002253 region.imageSubresource.layerCount = 1;
2254 region.imageExtent.height = 16;
2255 region.imageExtent.width = 16;
2256 region.imageExtent.depth = 1;
2257
Mark Lobodzinski80871462017-02-16 10:37:27 -07002258 // Buffer usage not set to TRANSFER_SRC and image usage not set to TRANSFER_DST
Tony Barbour552f6c02016-12-21 14:34:07 -07002259 m_commandBuffer->BeginCommandBuffer();
Tony Barbourf92621a2016-05-02 14:28:12 -06002260
Chris Forbesda581202016-10-06 18:25:26 +13002261 // two separate errors from this call:
Mark Lobodzinski33826372017-04-13 11:10:11 -06002262 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image should have VK_IMAGE_USAGE_TRANSFER_DST_BIT");
2263 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Buffer should have VK_BUFFER_USAGE_TRANSFER_SRC_BIT");
Chris Forbesda581202016-10-06 18:25:26 +13002264
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002265 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
2266 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourf92621a2016-05-02 14:28:12 -06002267 m_errorMonitor->VerifyFound();
Tobin Ehlis41376e12015-07-03 08:45:14 -06002268}
Tony Barbour75d79f02016-08-30 09:39:07 -06002269
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002270TEST_F(VkLayerTest, LeakAnObject) {
2271 VkResult err;
2272
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002273 TEST_DESCRIPTION("Create a fence and destroy its device without first destroying the fence.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002274
2275 // Note that we have to create a new device since destroying the
2276 // framework's device causes Teardown() to fail and just calling Teardown
2277 // will destroy the errorMonitor.
2278
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002279 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "has not been destroyed.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002280
Tony Barbour1fa09702017-03-16 12:09:08 -06002281 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002282
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002283 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002284 std::vector<VkDeviceQueueCreateInfo> queue_info;
2285 queue_info.reserve(queue_props.size());
2286 std::vector<std::vector<float>> queue_priorities;
2287 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
2288 VkDeviceQueueCreateInfo qi = {};
2289 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
2290 qi.pNext = NULL;
2291 qi.queueFamilyIndex = i;
2292 qi.queueCount = queue_props[i].queueCount;
2293 queue_priorities.emplace_back(qi.queueCount, 0.0f);
2294 qi.pQueuePriorities = queue_priorities[i].data();
2295 queue_info.push_back(qi);
2296 }
2297
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002298 std::vector<const char *> device_extension_names;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002299
2300 // The sacrificial device object
2301 VkDevice testDevice;
2302 VkDeviceCreateInfo device_create_info = {};
2303 auto features = m_device->phy().features();
2304 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
2305 device_create_info.pNext = NULL;
2306 device_create_info.queueCreateInfoCount = queue_info.size();
2307 device_create_info.pQueueCreateInfos = queue_info.data();
Tony Barbour4c70d102016-08-08 16:06:56 -06002308 device_create_info.enabledLayerCount = 0;
2309 device_create_info.ppEnabledLayerNames = NULL;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002310 device_create_info.pEnabledFeatures = &features;
2311 err = vkCreateDevice(gpu(), &device_create_info, NULL, &testDevice);
2312 ASSERT_VK_SUCCESS(err);
2313
2314 VkFence fence;
2315 VkFenceCreateInfo fence_create_info = {};
2316 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2317 fence_create_info.pNext = NULL;
2318 fence_create_info.flags = 0;
2319 err = vkCreateFence(testDevice, &fence_create_info, NULL, &fence);
2320 ASSERT_VK_SUCCESS(err);
2321
2322 // Induce failure by not calling vkDestroyFence
2323 vkDestroyDevice(testDevice, NULL);
2324 m_errorMonitor->VerifyFound();
2325}
2326
2327TEST_F(VkLayerTest, InvalidCommandPoolConsistency) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002328 TEST_DESCRIPTION(
2329 "Allocate command buffers from one command pool and "
2330 "attempt to delete them from another.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002331
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002332 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeCommandBuffers is attempting to free Command Buffer");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002333
Tony Barbour1fa09702017-03-16 12:09:08 -06002334 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002335 VkCommandPool command_pool_one;
2336 VkCommandPool command_pool_two;
2337
2338 VkCommandPoolCreateInfo pool_create_info{};
2339 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
2340 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
2341 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
2342
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002343 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002344
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002345 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002346
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002347 VkCommandBuffer cb;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002348 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002349 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002350 command_buffer_allocate_info.commandPool = command_pool_one;
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002351 command_buffer_allocate_info.commandBufferCount = 1;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002352 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002353 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &cb);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002354
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002355 vkFreeCommandBuffers(m_device->device(), command_pool_two, 1, &cb);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002356
2357 m_errorMonitor->VerifyFound();
2358
2359 vkDestroyCommandPool(m_device->device(), command_pool_one, NULL);
2360 vkDestroyCommandPool(m_device->device(), command_pool_two, NULL);
2361}
2362
2363TEST_F(VkLayerTest, InvalidDescriptorPoolConsistency) {
2364 VkResult err;
2365
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002366 TEST_DESCRIPTION(
2367 "Allocate descriptor sets from one DS pool and "
2368 "attempt to delete them from another.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002369
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002370 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeDescriptorSets is attempting to free descriptorSet");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002371
Tony Barbour1fa09702017-03-16 12:09:08 -06002372 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002373 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2374
2375 VkDescriptorPoolSize ds_type_count = {};
2376 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
2377 ds_type_count.descriptorCount = 1;
2378
2379 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2380 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2381 ds_pool_ci.pNext = NULL;
2382 ds_pool_ci.flags = 0;
2383 ds_pool_ci.maxSets = 1;
2384 ds_pool_ci.poolSizeCount = 1;
2385 ds_pool_ci.pPoolSizes = &ds_type_count;
2386
2387 VkDescriptorPool ds_pool_one;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002388 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002389 ASSERT_VK_SUCCESS(err);
2390
2391 // Create a second descriptor pool
2392 VkDescriptorPool ds_pool_two;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002393 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002394 ASSERT_VK_SUCCESS(err);
2395
2396 VkDescriptorSetLayoutBinding dsl_binding = {};
2397 dsl_binding.binding = 0;
2398 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
2399 dsl_binding.descriptorCount = 1;
2400 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2401 dsl_binding.pImmutableSamplers = NULL;
2402
2403 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2404 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2405 ds_layout_ci.pNext = NULL;
2406 ds_layout_ci.bindingCount = 1;
2407 ds_layout_ci.pBindings = &dsl_binding;
2408
2409 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002410 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002411 ASSERT_VK_SUCCESS(err);
2412
2413 VkDescriptorSet descriptorSet;
2414 VkDescriptorSetAllocateInfo alloc_info = {};
2415 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
2416 alloc_info.descriptorSetCount = 1;
2417 alloc_info.descriptorPool = ds_pool_one;
2418 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002419 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002420 ASSERT_VK_SUCCESS(err);
2421
2422 err = vkFreeDescriptorSets(m_device->device(), ds_pool_two, 1, &descriptorSet);
2423
2424 m_errorMonitor->VerifyFound();
2425
2426 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2427 vkDestroyDescriptorPool(m_device->device(), ds_pool_one, NULL);
2428 vkDestroyDescriptorPool(m_device->device(), ds_pool_two, NULL);
2429}
2430
2431TEST_F(VkLayerTest, CreateUnknownObject) {
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002432 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00788);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002433
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002434 TEST_DESCRIPTION("Pass an invalid image object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002435
Tony Barbour1fa09702017-03-16 12:09:08 -06002436 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002437
2438 // Pass bogus handle into GetImageMemoryRequirements
2439 VkMemoryRequirements mem_reqs;
2440 uint64_t fakeImageHandle = 0xCADECADE;
2441 VkImage fauxImage = reinterpret_cast<VkImage &>(fakeImageHandle);
2442
2443 vkGetImageMemoryRequirements(m_device->device(), fauxImage, &mem_reqs);
2444
2445 m_errorMonitor->VerifyFound();
2446}
2447
Mike Schuchardt17838902017-02-21 09:48:06 -07002448TEST_F(VkLayerTest, UseObjectWithWrongDevice) {
2449 TEST_DESCRIPTION(
2450 "Try to destroy a render pass object using a device other than the one it was created on. "
2451 "This should generate a distinct error from the invalid handle error.");
2452 // Create first device and renderpass
Tony Barbour1fa09702017-03-16 12:09:08 -06002453 ASSERT_NO_FATAL_FAILURE(Init());
Mike Schuchardt17838902017-02-21 09:48:06 -07002454 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2455
2456 // Create second device
2457 float priorities[] = {1.0f};
2458 VkDeviceQueueCreateInfo queue_info{};
2459 queue_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
2460 queue_info.pNext = NULL;
2461 queue_info.flags = 0;
2462 queue_info.queueFamilyIndex = 0;
2463 queue_info.queueCount = 1;
2464 queue_info.pQueuePriorities = &priorities[0];
2465
2466 VkDeviceCreateInfo device_create_info = {};
2467 auto features = m_device->phy().features();
2468 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
2469 device_create_info.pNext = NULL;
2470 device_create_info.queueCreateInfoCount = 1;
2471 device_create_info.pQueueCreateInfos = &queue_info;
2472 device_create_info.enabledLayerCount = 0;
2473 device_create_info.ppEnabledLayerNames = NULL;
2474 device_create_info.pEnabledFeatures = &features;
2475
2476 VkDevice second_device;
2477 ASSERT_VK_SUCCESS(vkCreateDevice(gpu(), &device_create_info, NULL, &second_device));
2478
2479 // Try to destroy the renderpass from the first device using the second device
2480 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00399);
2481 vkDestroyRenderPass(second_device, m_renderPass, NULL);
2482 m_errorMonitor->VerifyFound();
2483
2484 vkDestroyDevice(second_device, NULL);
2485}
2486
Karl Schultz6addd812016-02-02 17:17:23 -07002487TEST_F(VkLayerTest, PipelineNotBound) {
2488 VkResult err;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002489
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002490 TEST_DESCRIPTION("Pass in an invalid pipeline object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002491
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002492 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00601);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002493
Tony Barbour1fa09702017-03-16 12:09:08 -06002494 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002495 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002496
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002497 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002498 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2499 ds_type_count.descriptorCount = 1;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002500
2501 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002502 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2503 ds_pool_ci.pNext = NULL;
2504 ds_pool_ci.maxSets = 1;
2505 ds_pool_ci.poolSizeCount = 1;
2506 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002507
2508 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002509 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002510 ASSERT_VK_SUCCESS(err);
2511
2512 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002513 dsl_binding.binding = 0;
2514 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2515 dsl_binding.descriptorCount = 1;
2516 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2517 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002518
2519 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002520 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2521 ds_layout_ci.pNext = NULL;
2522 ds_layout_ci.bindingCount = 1;
2523 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002524
2525 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002526 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002527 ASSERT_VK_SUCCESS(err);
2528
2529 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002530 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002531 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07002532 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002533 alloc_info.descriptorPool = ds_pool;
2534 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002535 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002536 ASSERT_VK_SUCCESS(err);
2537
2538 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002539 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2540 pipeline_layout_ci.pNext = NULL;
2541 pipeline_layout_ci.setLayoutCount = 1;
2542 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002543
2544 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002545 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002546 ASSERT_VK_SUCCESS(err);
2547
Mark Youngad779052016-01-06 14:26:04 -07002548 VkPipeline badPipeline = (VkPipeline)((size_t)0xbaadb1be);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002549
Tony Barbour552f6c02016-12-21 14:34:07 -07002550 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002551 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002552
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002553 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002554
Chia-I Wuf7458c52015-10-26 21:10:41 +08002555 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2556 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2557 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002558}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002559
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002560TEST_F(VkLayerTest, BindImageInvalidMemoryType) {
2561 VkResult err;
2562
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002563 TEST_DESCRIPTION(
2564 "Test validation check for an invalid memory type index "
2565 "during bind[Buffer|Image]Memory time");
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002566
Tony Barbour1fa09702017-03-16 12:09:08 -06002567 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002568
2569 // Create an image, allocate memory, set a bad typeIndex and then try to
2570 // bind it
2571 VkImage image;
2572 VkDeviceMemory mem;
2573 VkMemoryRequirements mem_reqs;
2574 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2575 const int32_t tex_width = 32;
2576 const int32_t tex_height = 32;
2577
2578 VkImageCreateInfo image_create_info = {};
2579 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2580 image_create_info.pNext = NULL;
2581 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2582 image_create_info.format = tex_format;
2583 image_create_info.extent.width = tex_width;
2584 image_create_info.extent.height = tex_height;
2585 image_create_info.extent.depth = 1;
2586 image_create_info.mipLevels = 1;
2587 image_create_info.arrayLayers = 1;
2588 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2589 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2590 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2591 image_create_info.flags = 0;
2592
2593 VkMemoryAllocateInfo mem_alloc = {};
2594 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2595 mem_alloc.pNext = NULL;
2596 mem_alloc.allocationSize = 0;
2597 mem_alloc.memoryTypeIndex = 0;
2598
2599 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
2600 ASSERT_VK_SUCCESS(err);
2601
2602 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
2603 mem_alloc.allocationSize = mem_reqs.size;
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002604
2605 // Introduce Failure, select invalid TypeIndex
2606 VkPhysicalDeviceMemoryProperties memory_info;
2607
2608 vkGetPhysicalDeviceMemoryProperties(gpu(), &memory_info);
2609 unsigned int i;
2610 for (i = 0; i < memory_info.memoryTypeCount; i++) {
2611 if ((mem_reqs.memoryTypeBits & (1 << i)) == 0) {
2612 mem_alloc.memoryTypeIndex = i;
2613 break;
2614 }
2615 }
2616 if (i >= memory_info.memoryTypeCount) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07002617 printf(" No invalid memory type index could be found; skipped.\n");
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002618 vkDestroyImage(m_device->device(), image, NULL);
2619 return;
2620 }
2621
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002622 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 -06002623
2624 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
2625 ASSERT_VK_SUCCESS(err);
2626
2627 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2628 (void)err;
2629
2630 m_errorMonitor->VerifyFound();
2631
2632 vkDestroyImage(m_device->device(), image, NULL);
2633 vkFreeMemory(m_device->device(), mem, NULL);
2634}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002635
Karl Schultz6addd812016-02-02 17:17:23 -07002636TEST_F(VkLayerTest, BindInvalidMemory) {
2637 VkResult err;
2638 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002639
Tony Barbour1fa09702017-03-16 12:09:08 -06002640 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisec598302015-09-15 15:02:17 -06002641
Cortf801b982017-01-17 18:10:21 -08002642 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
Cort Strattonde748202017-02-17 12:50:01 -08002643 const int32_t tex_width = 256;
2644 const int32_t tex_height = 256;
Tobin Ehlisec598302015-09-15 15:02:17 -06002645
2646 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002647 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2648 image_create_info.pNext = NULL;
2649 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2650 image_create_info.format = tex_format;
2651 image_create_info.extent.width = tex_width;
2652 image_create_info.extent.height = tex_height;
2653 image_create_info.extent.depth = 1;
2654 image_create_info.mipLevels = 1;
2655 image_create_info.arrayLayers = 1;
2656 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Cort Strattonf1d8a4a2017-01-28 14:17:04 -08002657 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Karl Schultz6addd812016-02-02 17:17:23 -07002658 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2659 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002660
Cortf801b982017-01-17 18:10:21 -08002661 VkBufferCreateInfo buffer_create_info = {};
2662 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
2663 buffer_create_info.pNext = NULL;
2664 buffer_create_info.flags = 0;
Cort Strattonde748202017-02-17 12:50:01 -08002665 buffer_create_info.size = 4 * 1024 * 1024;
2666 buffer_create_info.usage = VK_BUFFER_USAGE_VERTEX_BUFFER_BIT;
Cortf801b982017-01-17 18:10:21 -08002667 buffer_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
Tobin Ehlisec598302015-09-15 15:02:17 -06002668
Cortf801b982017-01-17 18:10:21 -08002669 // Create an image/buffer, allocate memory, free it, and then try to bind it
2670 {
2671 VkImage image = VK_NULL_HANDLE;
2672 VkBuffer buffer = VK_NULL_HANDLE;
2673 err = vkCreateImage(device(), &image_create_info, NULL, &image);
2674 ASSERT_VK_SUCCESS(err);
2675 err = vkCreateBuffer(device(), &buffer_create_info, NULL, &buffer);
2676 ASSERT_VK_SUCCESS(err);
2677 VkMemoryRequirements image_mem_reqs = {}, buffer_mem_reqs = {};
2678 vkGetImageMemoryRequirements(device(), image, &image_mem_reqs);
2679 vkGetBufferMemoryRequirements(device(), buffer, &buffer_mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002680
Cortf801b982017-01-17 18:10:21 -08002681 VkMemoryAllocateInfo image_mem_alloc = {}, buffer_mem_alloc = {};
2682 image_mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2683 image_mem_alloc.allocationSize = image_mem_reqs.size;
2684 pass = m_device->phy().set_memory_type(image_mem_reqs.memoryTypeBits, &image_mem_alloc, 0);
2685 ASSERT_TRUE(pass);
2686 buffer_mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2687 buffer_mem_alloc.allocationSize = buffer_mem_reqs.size;
2688 pass = m_device->phy().set_memory_type(buffer_mem_reqs.memoryTypeBits, &buffer_mem_alloc, 0);
2689 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002690
Cortf801b982017-01-17 18:10:21 -08002691 VkDeviceMemory image_mem = VK_NULL_HANDLE, buffer_mem = VK_NULL_HANDLE;
2692 err = vkAllocateMemory(device(), &image_mem_alloc, NULL, &image_mem);
2693 ASSERT_VK_SUCCESS(err);
2694 err = vkAllocateMemory(device(), &buffer_mem_alloc, NULL, &buffer_mem);
2695 ASSERT_VK_SUCCESS(err);
Tobin Ehlisec598302015-09-15 15:02:17 -06002696
Cortf801b982017-01-17 18:10:21 -08002697 vkFreeMemory(device(), image_mem, NULL);
2698 vkFreeMemory(device(), buffer_mem, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002699
Cortf801b982017-01-17 18:10:21 -08002700 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00809);
2701 err = vkBindImageMemory(device(), image, image_mem, 0);
2702 (void)err; // This may very well return an error.
2703 m_errorMonitor->VerifyFound();
Tobin Ehlisec598302015-09-15 15:02:17 -06002704
Cortf801b982017-01-17 18:10:21 -08002705 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00800);
2706 err = vkBindBufferMemory(device(), buffer, buffer_mem, 0);
2707 (void)err; // This may very well return an error.
2708 m_errorMonitor->VerifyFound();
Tobin Ehlisec598302015-09-15 15:02:17 -06002709
Cortf801b982017-01-17 18:10:21 -08002710 vkDestroyImage(m_device->device(), image, NULL);
2711 vkDestroyBuffer(m_device->device(), buffer, NULL);
2712 }
Cort Strattonc21601b2017-01-28 14:16:16 -08002713
2714 // Try to bind memory to an object that already has a memory binding
2715 {
2716 VkImage image = VK_NULL_HANDLE;
2717 err = vkCreateImage(device(), &image_create_info, NULL, &image);
2718 ASSERT_VK_SUCCESS(err);
2719 VkBuffer buffer = VK_NULL_HANDLE;
2720 err = vkCreateBuffer(device(), &buffer_create_info, NULL, &buffer);
2721 ASSERT_VK_SUCCESS(err);
2722 VkMemoryRequirements image_mem_reqs = {}, buffer_mem_reqs = {};
2723 vkGetImageMemoryRequirements(device(), image, &image_mem_reqs);
2724 vkGetBufferMemoryRequirements(device(), buffer, &buffer_mem_reqs);
2725 VkMemoryAllocateInfo image_alloc_info = {}, buffer_alloc_info = {};
2726 image_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2727 image_alloc_info.allocationSize = image_mem_reqs.size;
2728 buffer_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2729 buffer_alloc_info.allocationSize = buffer_mem_reqs.size;
2730 pass = m_device->phy().set_memory_type(image_mem_reqs.memoryTypeBits, &image_alloc_info, 0);
2731 ASSERT_TRUE(pass);
2732 pass = m_device->phy().set_memory_type(buffer_mem_reqs.memoryTypeBits, &buffer_alloc_info, 0);
2733 ASSERT_TRUE(pass);
2734 VkDeviceMemory image_mem, buffer_mem;
2735 err = vkAllocateMemory(device(), &image_alloc_info, NULL, &image_mem);
2736 ASSERT_VK_SUCCESS(err);
2737 err = vkAllocateMemory(device(), &buffer_alloc_info, NULL, &buffer_mem);
2738 ASSERT_VK_SUCCESS(err);
2739
2740 err = vkBindImageMemory(device(), image, image_mem, 0);
2741 ASSERT_VK_SUCCESS(err);
2742 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00803);
2743 err = vkBindImageMemory(device(), image, image_mem, 0);
2744 (void)err; // This may very well return an error.
2745 m_errorMonitor->VerifyFound();
2746
2747 err = vkBindBufferMemory(device(), buffer, buffer_mem, 0);
2748 ASSERT_VK_SUCCESS(err);
2749 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00791);
2750 err = vkBindBufferMemory(device(), buffer, buffer_mem, 0);
2751 (void)err; // This may very well return an error.
2752 m_errorMonitor->VerifyFound();
2753
2754 vkFreeMemory(device(), image_mem, NULL);
2755 vkFreeMemory(device(), buffer_mem, NULL);
2756 vkDestroyImage(device(), image, NULL);
2757 vkDestroyBuffer(device(), buffer, NULL);
2758 }
Cort Strattonf1d8a4a2017-01-28 14:17:04 -08002759
Cort Strattonde748202017-02-17 12:50:01 -08002760 // Try to bind memory to an object with an invalid memoryOffset
Cort6c7dff72017-01-27 18:34:50 -08002761 {
2762 VkImage image = VK_NULL_HANDLE;
2763 err = vkCreateImage(device(), &image_create_info, NULL, &image);
2764 ASSERT_VK_SUCCESS(err);
2765 VkBuffer buffer = VK_NULL_HANDLE;
2766 err = vkCreateBuffer(device(), &buffer_create_info, NULL, &buffer);
2767 ASSERT_VK_SUCCESS(err);
2768 VkMemoryRequirements image_mem_reqs = {}, buffer_mem_reqs = {};
2769 vkGetImageMemoryRequirements(device(), image, &image_mem_reqs);
2770 vkGetBufferMemoryRequirements(device(), buffer, &buffer_mem_reqs);
2771 VkMemoryAllocateInfo image_alloc_info = {}, buffer_alloc_info = {};
2772 image_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Cort Strattonde748202017-02-17 12:50:01 -08002773 // Leave some extra space for alignment wiggle room
2774 image_alloc_info.allocationSize = image_mem_reqs.size + image_mem_reqs.alignment;
Cort6c7dff72017-01-27 18:34:50 -08002775 buffer_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Cort Strattonde748202017-02-17 12:50:01 -08002776 buffer_alloc_info.allocationSize = buffer_mem_reqs.size + buffer_mem_reqs.alignment;
Cort6c7dff72017-01-27 18:34:50 -08002777 pass = m_device->phy().set_memory_type(image_mem_reqs.memoryTypeBits, &image_alloc_info, 0);
2778 ASSERT_TRUE(pass);
2779 pass = m_device->phy().set_memory_type(buffer_mem_reqs.memoryTypeBits, &buffer_alloc_info, 0);
2780 ASSERT_TRUE(pass);
2781 VkDeviceMemory image_mem, buffer_mem;
2782 err = vkAllocateMemory(device(), &image_alloc_info, NULL, &image_mem);
2783 ASSERT_VK_SUCCESS(err);
2784 err = vkAllocateMemory(device(), &buffer_alloc_info, NULL, &buffer_mem);
2785 ASSERT_VK_SUCCESS(err);
2786
Cort Strattonde748202017-02-17 12:50:01 -08002787 // Test unaligned memory offset
2788 {
2789 if (image_mem_reqs.alignment > 1) {
2790 VkDeviceSize image_offset = 1;
2791 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02178);
2792 err = vkBindImageMemory(device(), image, image_mem, image_offset);
2793 (void)err; // This may very well return an error.
2794 m_errorMonitor->VerifyFound();
2795 }
Cort6c7dff72017-01-27 18:34:50 -08002796
Cort Strattonde748202017-02-17 12:50:01 -08002797 if (buffer_mem_reqs.alignment > 1) {
2798 VkDeviceSize buffer_offset = 1;
2799 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02174);
2800 err = vkBindBufferMemory(device(), buffer, buffer_mem, buffer_offset);
2801 (void)err; // This may very well return an error.
2802 m_errorMonitor->VerifyFound();
2803 }
2804 }
2805
2806 // Test memory offsets outside the memory allocation
2807 {
2808 VkDeviceSize image_offset =
2809 (image_alloc_info.allocationSize + image_mem_reqs.alignment) & ~(image_mem_reqs.alignment - 1);
2810 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00805);
2811 err = vkBindImageMemory(device(), image, image_mem, image_offset);
2812 (void)err; // This may very well return an error.
2813 m_errorMonitor->VerifyFound();
2814
2815 VkDeviceSize buffer_offset =
2816 (buffer_alloc_info.allocationSize + buffer_mem_reqs.alignment) & ~(buffer_mem_reqs.alignment - 1);
2817 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00793);
2818 err = vkBindBufferMemory(device(), buffer, buffer_mem, buffer_offset);
2819 (void)err; // This may very well return an error.
2820 m_errorMonitor->VerifyFound();
2821 }
2822
2823 // Test memory offsets within the memory allocation, but which leave too little memory for
2824 // the resource.
2825 {
2826 VkDeviceSize image_offset = (image_mem_reqs.size - 1) & ~(image_mem_reqs.alignment - 1);
Tony Barbour02d08552017-03-24 16:36:01 -06002827 if ((image_offset > 0) && (image_mem_reqs.size < (image_alloc_info.allocationSize - image_mem_reqs.alignment))) {
Cort Strattonde748202017-02-17 12:50:01 -08002828 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02179);
2829 err = vkBindImageMemory(device(), image, image_mem, image_offset);
2830 (void)err; // This may very well return an error.
2831 m_errorMonitor->VerifyFound();
2832 }
2833
2834 VkDeviceSize buffer_offset = (buffer_mem_reqs.size - 1) & ~(buffer_mem_reqs.alignment - 1);
2835 if (buffer_offset > 0) {
2836 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02175);
2837 err = vkBindBufferMemory(device(), buffer, buffer_mem, buffer_offset);
2838 (void)err; // This may very well return an error.
2839 m_errorMonitor->VerifyFound();
2840 }
2841 }
Cort6c7dff72017-01-27 18:34:50 -08002842
2843 vkFreeMemory(device(), image_mem, NULL);
2844 vkFreeMemory(device(), buffer_mem, NULL);
2845 vkDestroyImage(device(), image, NULL);
2846 vkDestroyBuffer(device(), buffer, NULL);
2847 }
2848
Cort Stratton4c38bb52017-01-28 13:33:10 -08002849 // Try to bind memory to an object with an invalid memory type
2850 {
2851 VkImage image = VK_NULL_HANDLE;
2852 err = vkCreateImage(device(), &image_create_info, NULL, &image);
2853 ASSERT_VK_SUCCESS(err);
2854 VkBuffer buffer = VK_NULL_HANDLE;
2855 err = vkCreateBuffer(device(), &buffer_create_info, NULL, &buffer);
2856 ASSERT_VK_SUCCESS(err);
2857 VkMemoryRequirements image_mem_reqs = {}, buffer_mem_reqs = {};
2858 vkGetImageMemoryRequirements(device(), image, &image_mem_reqs);
2859 vkGetBufferMemoryRequirements(device(), buffer, &buffer_mem_reqs);
2860 VkMemoryAllocateInfo image_alloc_info = {}, buffer_alloc_info = {};
2861 image_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2862 image_alloc_info.allocationSize = image_mem_reqs.size;
2863 buffer_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2864 buffer_alloc_info.allocationSize = buffer_mem_reqs.size;
Cort Strattonccc90e32017-02-04 13:47:42 -08002865 // Create a mask of available memory types *not* supported by these resources,
2866 // and try to use one of them.
Cort Stratton4c38bb52017-01-28 13:33:10 -08002867 VkPhysicalDeviceMemoryProperties memory_properties = {};
2868 vkGetPhysicalDeviceMemoryProperties(m_device->phy().handle(), &memory_properties);
Cort Strattonccc90e32017-02-04 13:47:42 -08002869 VkDeviceMemory image_mem, buffer_mem;
2870
Cort Stratton4c38bb52017-01-28 13:33:10 -08002871 uint32_t image_unsupported_mem_type_bits = ((1 << memory_properties.memoryTypeCount) - 1) & ~image_mem_reqs.memoryTypeBits;
Cort Strattonccc90e32017-02-04 13:47:42 -08002872 if (image_unsupported_mem_type_bits != 0) {
Dave Houlton584d51e2017-02-16 12:52:54 -07002873 pass = m_device->phy().set_memory_type(image_unsupported_mem_type_bits, &image_alloc_info, 0);
2874 ASSERT_TRUE(pass);
2875 err = vkAllocateMemory(device(), &image_alloc_info, NULL, &image_mem);
2876 ASSERT_VK_SUCCESS(err);
2877 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00806);
2878 err = vkBindImageMemory(device(), image, image_mem, 0);
2879 (void)err; // This may very well return an error.
2880 m_errorMonitor->VerifyFound();
2881 vkFreeMemory(device(), image_mem, NULL);
Cort Strattonccc90e32017-02-04 13:47:42 -08002882 }
2883
Cort Stratton4c38bb52017-01-28 13:33:10 -08002884 uint32_t buffer_unsupported_mem_type_bits =
2885 ((1 << memory_properties.memoryTypeCount) - 1) & ~buffer_mem_reqs.memoryTypeBits;
Cort Strattonccc90e32017-02-04 13:47:42 -08002886 if (buffer_unsupported_mem_type_bits != 0) {
Dave Houlton584d51e2017-02-16 12:52:54 -07002887 pass = m_device->phy().set_memory_type(buffer_unsupported_mem_type_bits, &buffer_alloc_info, 0);
2888 ASSERT_TRUE(pass);
2889 err = vkAllocateMemory(device(), &buffer_alloc_info, NULL, &buffer_mem);
2890 ASSERT_VK_SUCCESS(err);
2891 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00797);
2892 err = vkBindBufferMemory(device(), buffer, buffer_mem, 0);
2893 (void)err; // This may very well return an error.
2894 m_errorMonitor->VerifyFound();
2895 vkFreeMemory(device(), buffer_mem, NULL);
Cort Strattonccc90e32017-02-04 13:47:42 -08002896 }
Cort Stratton4c38bb52017-01-28 13:33:10 -08002897
Cort Stratton4c38bb52017-01-28 13:33:10 -08002898 vkDestroyImage(device(), image, NULL);
2899 vkDestroyBuffer(device(), buffer, NULL);
2900 }
2901
Cort Strattonf1d8a4a2017-01-28 14:17:04 -08002902 // Try to bind memory to an image created with sparse memory flags
2903 {
2904 VkImageCreateInfo sparse_image_create_info = image_create_info;
2905 sparse_image_create_info.flags |= VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
2906 VkImageFormatProperties image_format_properties = {};
2907 err = vkGetPhysicalDeviceImageFormatProperties(m_device->phy().handle(), sparse_image_create_info.format,
2908 sparse_image_create_info.imageType, sparse_image_create_info.tiling,
2909 sparse_image_create_info.usage, sparse_image_create_info.flags,
2910 &image_format_properties);
2911 if (!m_device->phy().features().sparseResidencyImage2D || err == VK_ERROR_FORMAT_NOT_SUPPORTED) {
2912 // most likely means sparse formats aren't supported here; skip this test.
2913 } else {
2914 ASSERT_VK_SUCCESS(err);
2915 if (image_format_properties.maxExtent.width == 0) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07002916 printf(" Sparse image format not supported; skipped.\n");
Cort Strattonf1d8a4a2017-01-28 14:17:04 -08002917 return;
2918 } else {
2919 VkImage sparse_image = VK_NULL_HANDLE;
2920 err = vkCreateImage(m_device->device(), &sparse_image_create_info, NULL, &sparse_image);
2921 ASSERT_VK_SUCCESS(err);
2922 VkMemoryRequirements sparse_mem_reqs = {};
2923 vkGetImageMemoryRequirements(m_device->device(), sparse_image, &sparse_mem_reqs);
2924 if (sparse_mem_reqs.memoryTypeBits != 0) {
2925 VkMemoryAllocateInfo sparse_mem_alloc = {};
2926 sparse_mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2927 sparse_mem_alloc.pNext = NULL;
2928 sparse_mem_alloc.allocationSize = sparse_mem_reqs.size;
2929 sparse_mem_alloc.memoryTypeIndex = 0;
2930 pass = m_device->phy().set_memory_type(sparse_mem_reqs.memoryTypeBits, &sparse_mem_alloc, 0);
2931 ASSERT_TRUE(pass);
2932 VkDeviceMemory sparse_mem = VK_NULL_HANDLE;
2933 err = vkAllocateMemory(m_device->device(), &sparse_mem_alloc, NULL, &sparse_mem);
2934 ASSERT_VK_SUCCESS(err);
2935 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00804);
2936 err = vkBindImageMemory(m_device->device(), sparse_image, sparse_mem, 0);
2937 // This may very well return an error.
2938 (void)err;
2939 m_errorMonitor->VerifyFound();
2940 vkFreeMemory(m_device->device(), sparse_mem, NULL);
2941 }
2942 vkDestroyImage(m_device->device(), sparse_image, NULL);
2943 }
2944 }
2945 }
2946
2947 // Try to bind memory to a buffer created with sparse memory flags
2948 {
2949 VkBufferCreateInfo sparse_buffer_create_info = buffer_create_info;
2950 sparse_buffer_create_info.flags |= VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
2951 if (!m_device->phy().features().sparseResidencyBuffer) {
2952 // most likely means sparse formats aren't supported here; skip this test.
2953 } else {
2954 VkBuffer sparse_buffer = VK_NULL_HANDLE;
2955 err = vkCreateBuffer(m_device->device(), &sparse_buffer_create_info, NULL, &sparse_buffer);
2956 ASSERT_VK_SUCCESS(err);
2957 VkMemoryRequirements sparse_mem_reqs = {};
2958 vkGetBufferMemoryRequirements(m_device->device(), sparse_buffer, &sparse_mem_reqs);
2959 if (sparse_mem_reqs.memoryTypeBits != 0) {
2960 VkMemoryAllocateInfo sparse_mem_alloc = {};
2961 sparse_mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2962 sparse_mem_alloc.pNext = NULL;
2963 sparse_mem_alloc.allocationSize = sparse_mem_reqs.size;
2964 sparse_mem_alloc.memoryTypeIndex = 0;
2965 pass = m_device->phy().set_memory_type(sparse_mem_reqs.memoryTypeBits, &sparse_mem_alloc, 0);
2966 ASSERT_TRUE(pass);
2967 VkDeviceMemory sparse_mem = VK_NULL_HANDLE;
2968 err = vkAllocateMemory(m_device->device(), &sparse_mem_alloc, NULL, &sparse_mem);
2969 ASSERT_VK_SUCCESS(err);
2970 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00792);
2971 err = vkBindBufferMemory(m_device->device(), sparse_buffer, sparse_mem, 0);
2972 // This may very well return an error.
2973 (void)err;
2974 m_errorMonitor->VerifyFound();
2975 vkFreeMemory(m_device->device(), sparse_mem, NULL);
2976 }
2977 vkDestroyBuffer(m_device->device(), sparse_buffer, NULL);
2978 }
2979 }
Tobin Ehlisec598302015-09-15 15:02:17 -06002980}
2981
Karl Schultz6addd812016-02-02 17:17:23 -07002982TEST_F(VkLayerTest, BindMemoryToDestroyedObject) {
2983 VkResult err;
2984 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002985
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002986 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00808);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002987
Tony Barbour1fa09702017-03-16 12:09:08 -06002988 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisec598302015-09-15 15:02:17 -06002989
Karl Schultz6addd812016-02-02 17:17:23 -07002990 // Create an image object, allocate memory, destroy the object and then try
2991 // to bind it
2992 VkImage image;
2993 VkDeviceMemory mem;
2994 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06002995
Karl Schultz6addd812016-02-02 17:17:23 -07002996 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2997 const int32_t tex_width = 32;
2998 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06002999
3000 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003001 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3002 image_create_info.pNext = NULL;
3003 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3004 image_create_info.format = tex_format;
3005 image_create_info.extent.width = tex_width;
3006 image_create_info.extent.height = tex_height;
3007 image_create_info.extent.depth = 1;
3008 image_create_info.mipLevels = 1;
3009 image_create_info.arrayLayers = 1;
3010 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
3011 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
3012 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
3013 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06003014
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003015 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003016 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
3017 mem_alloc.pNext = NULL;
3018 mem_alloc.allocationSize = 0;
3019 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06003020
Chia-I Wuf7458c52015-10-26 21:10:41 +08003021 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06003022 ASSERT_VK_SUCCESS(err);
3023
Karl Schultz6addd812016-02-02 17:17:23 -07003024 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06003025
3026 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003027 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06003028 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06003029
3030 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003031 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06003032 ASSERT_VK_SUCCESS(err);
3033
3034 // Introduce validation failure, destroy Image object before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08003035 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06003036 ASSERT_VK_SUCCESS(err);
3037
3038 // Now Try to bind memory to this destroyed object
3039 err = vkBindImageMemory(m_device->device(), image, mem, 0);
3040 // This may very well return an error.
Karl Schultz6addd812016-02-02 17:17:23 -07003041 (void)err;
Tobin Ehlisec598302015-09-15 15:02:17 -06003042
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003043 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06003044
Chia-I Wuf7458c52015-10-26 21:10:41 +08003045 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003046}
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003047
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -07003048TEST_F(VkLayerTest, CreatePipelineBadVertexAttributeFormat) {
3049 TEST_DESCRIPTION("Test that pipeline validation catches invalid vertex attribute formats");
3050
Tony Barbour1fa09702017-03-16 12:09:08 -06003051 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -07003052 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3053
3054 VkVertexInputBindingDescription input_binding;
3055 memset(&input_binding, 0, sizeof(input_binding));
3056
3057 VkVertexInputAttributeDescription input_attribs;
3058 memset(&input_attribs, 0, sizeof(input_attribs));
3059
3060 // Pick a really bad format for this purpose and make sure it should fail
3061 input_attribs.format = VK_FORMAT_BC2_UNORM_BLOCK;
3062 VkFormatProperties format_props = m_device->format_properties(input_attribs.format);
3063 if ((format_props.bufferFeatures & VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT) != 0) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07003064 printf(" Format unsuitable for test; skipped.\n");
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -07003065 return;
3066 }
3067
3068 input_attribs.location = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003069 char const *vsSource =
3070 "#version 450\n"
3071 "\n"
3072 "out gl_PerVertex {\n"
3073 " vec4 gl_Position;\n"
3074 "};\n"
3075 "void main(){\n"
3076 " gl_Position = vec4(1);\n"
3077 "}\n";
3078 char const *fsSource =
3079 "#version 450\n"
3080 "\n"
3081 "layout(location=0) out vec4 color;\n"
3082 "void main(){\n"
3083 " color = vec4(1);\n"
3084 "}\n";
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -07003085
3086 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01413);
3087 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
3088 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
3089
3090 VkPipelineObj pipe(m_device);
3091 pipe.AddColorAttachment();
3092 pipe.AddShader(&vs);
3093 pipe.AddShader(&fs);
3094
3095 pipe.AddVertexInputBindings(&input_binding, 1);
3096 pipe.AddVertexInputAttribs(&input_attribs, 1);
3097
3098 VkDescriptorSetObj descriptorSet(m_device);
3099 descriptorSet.AppendDummy();
3100 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
3101
3102 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
3103
3104 m_errorMonitor->VerifyFound();
3105}
3106
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003107TEST_F(VkLayerTest, ImageSampleCounts) {
Jeremy Hayes0d104082017-02-21 10:24:16 -07003108 TEST_DESCRIPTION("Use bad sample counts in image transfer calls to trigger validation errors.");
Tony Barbour1fa09702017-03-16 12:09:08 -06003109 ASSERT_NO_FATAL_FAILURE(Init(nullptr, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT));
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003110
3111 VkMemoryPropertyFlags reqs = 0;
3112 VkImageCreateInfo image_create_info = {};
3113 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3114 image_create_info.pNext = NULL;
3115 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3116 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
3117 image_create_info.extent.width = 256;
3118 image_create_info.extent.height = 256;
3119 image_create_info.extent.depth = 1;
3120 image_create_info.mipLevels = 1;
3121 image_create_info.arrayLayers = 1;
3122 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
3123 image_create_info.flags = 0;
3124
3125 VkImageBlit blit_region = {};
3126 blit_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3127 blit_region.srcSubresource.baseArrayLayer = 0;
3128 blit_region.srcSubresource.layerCount = 1;
3129 blit_region.srcSubresource.mipLevel = 0;
3130 blit_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3131 blit_region.dstSubresource.baseArrayLayer = 0;
3132 blit_region.dstSubresource.layerCount = 1;
3133 blit_region.dstSubresource.mipLevel = 0;
3134
3135 // Create two images, the source with sampleCount = 2, and attempt to blit
3136 // between them
3137 {
3138 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003139 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003140 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003141 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003142 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003143 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003144 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003145 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003146 m_commandBuffer->BeginCommandBuffer();
Jeremy Hayes0d104082017-02-21 10:24:16 -07003147 m_errorMonitor->SetDesiredFailureMsg(
3148 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3149 "was created with a sample count of VK_SAMPLE_COUNT_2_BIT but must be VK_SAMPLE_COUNT_1_BIT");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003150 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3151 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003152 m_errorMonitor->VerifyFound();
3153 m_commandBuffer->EndCommandBuffer();
3154 }
3155
3156 // Create two images, the dest with sampleCount = 4, and attempt to blit
3157 // between them
3158 {
3159 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003160 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003161 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003162 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003163 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003164 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003165 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003166 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003167 m_commandBuffer->BeginCommandBuffer();
Jeremy Hayes0d104082017-02-21 10:24:16 -07003168 m_errorMonitor->SetDesiredFailureMsg(
3169 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3170 "was created with a sample count of VK_SAMPLE_COUNT_4_BIT but must be VK_SAMPLE_COUNT_1_BIT");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003171 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3172 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003173 m_errorMonitor->VerifyFound();
3174 m_commandBuffer->EndCommandBuffer();
3175 }
3176
3177 VkBufferImageCopy copy_region = {};
3178 copy_region.bufferRowLength = 128;
3179 copy_region.bufferImageHeight = 128;
3180 copy_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3181 copy_region.imageSubresource.layerCount = 1;
3182 copy_region.imageExtent.height = 64;
3183 copy_region.imageExtent.width = 64;
3184 copy_region.imageExtent.depth = 1;
3185
3186 // Create src buffer and dst image with sampleCount = 4 and attempt to copy
3187 // buffer to image
3188 {
3189 vk_testing::Buffer src_buffer;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003190 src_buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
3191 image_create_info.samples = VK_SAMPLE_COUNT_8_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003192 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003193 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003194 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003195 m_commandBuffer->BeginCommandBuffer();
Jeremy Hayes0d104082017-02-21 10:24:16 -07003196 m_errorMonitor->SetDesiredFailureMsg(
3197 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3198 "was created with a sample count of VK_SAMPLE_COUNT_8_BIT but must be VK_SAMPLE_COUNT_1_BIT");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003199 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), src_buffer.handle(), dst_image.handle(),
3200 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &copy_region);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003201 m_errorMonitor->VerifyFound();
3202 m_commandBuffer->EndCommandBuffer();
3203 }
3204
3205 // Create dst buffer and src image with sampleCount = 2 and attempt to copy
3206 // image to buffer
3207 {
3208 vk_testing::Buffer dst_buffer;
3209 dst_buffer.init_as_dst(*m_device, 128 * 128 * 4, reqs);
3210 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003211 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003212 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003213 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003214 m_commandBuffer->BeginCommandBuffer();
Jeremy Hayes0d104082017-02-21 10:24:16 -07003215 m_errorMonitor->SetDesiredFailureMsg(
3216 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3217 "was created with a sample count of VK_SAMPLE_COUNT_2_BIT but must be VK_SAMPLE_COUNT_1_BIT");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003218 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003219 dst_buffer.handle(), 1, &copy_region);
3220 m_errorMonitor->VerifyFound();
3221 m_commandBuffer->EndCommandBuffer();
3222 }
3223}
3224
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003225TEST_F(VkLayerTest, BlitImageFormats) {
Tony Barbour1fa09702017-03-16 12:09:08 -06003226 ASSERT_NO_FATAL_FAILURE(Init());
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003227
3228 VkImageObj src_image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06003229 src_image.Init(64, 64, 1, VK_FORMAT_A2B10G10R10_UINT_PACK32, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003230 VkImageObj dst_image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06003231 dst_image.Init(64, 64, 1, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003232 VkImageObj dst_image2(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06003233 dst_image2.Init(64, 64, 1, VK_FORMAT_R8G8B8A8_SINT, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003234
3235 VkImageBlit blitRegion = {};
3236 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3237 blitRegion.srcSubresource.baseArrayLayer = 0;
3238 blitRegion.srcSubresource.layerCount = 1;
3239 blitRegion.srcSubresource.mipLevel = 0;
3240 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3241 blitRegion.dstSubresource.baseArrayLayer = 0;
3242 blitRegion.dstSubresource.layerCount = 1;
3243 blitRegion.dstSubresource.mipLevel = 0;
3244
Dave Houlton34df4cb2016-12-01 16:43:06 -07003245 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02191);
3246
3247 // TODO: there are 9 permutations of signed, unsigned, & other for source and dest
3248 // this test is only checking 2 of them at the moment
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003249
3250 // Unsigned int vs not an int
Tony Barbour552f6c02016-12-21 14:34:07 -07003251 m_commandBuffer->BeginCommandBuffer();
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06003252 vkCmdBlitImage(m_commandBuffer->handle(), src_image.image(), src_image.Layout(), dst_image.image(), dst_image.Layout(), 1,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003253 &blitRegion, VK_FILTER_NEAREST);
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003254
3255 m_errorMonitor->VerifyFound();
3256
Dave Houlton34df4cb2016-12-01 16:43:06 -07003257 // Test should generate 2 VU failures
3258 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02190);
3259 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02191);
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003260
3261 // Unsigned int vs signed int
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06003262 vkCmdBlitImage(m_commandBuffer->handle(), src_image.image(), src_image.Layout(), dst_image2.image(), dst_image2.Layout(), 1,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003263 &blitRegion, VK_FILTER_NEAREST);
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003264
Dave Houlton34df4cb2016-12-01 16:43:06 -07003265 // TODO: Note that this only verifies that at least one of the VU enums was found
3266 // Also, if any were not seen, they'll remain in the target list (Soln TBD, JIRA task: VL-72)
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003267 m_errorMonitor->VerifyFound();
3268
Tony Barbour552f6c02016-12-21 14:34:07 -07003269 m_commandBuffer->EndCommandBuffer();
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003270}
3271
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003272TEST_F(VkLayerTest, DSImageTransferGranularityTests) {
3273 VkResult err;
3274 bool pass;
3275
3276 TEST_DESCRIPTION("Tests for validaiton of Queue Family property minImageTransferGranularity.");
Tony Barbour1fa09702017-03-16 12:09:08 -06003277 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003278
3279 // If w/d/h granularity is 1, test is not meaningful
3280 // TODO: When virtual device limits are available, create a set of limits for this test that
3281 // will always have a granularity of > 1 for w, h, and d
3282 auto index = m_device->graphics_queue_node_index_;
3283 auto queue_family_properties = m_device->phy().queue_properties();
3284
3285 if ((queue_family_properties[index].minImageTransferGranularity.depth < 4) ||
3286 (queue_family_properties[index].minImageTransferGranularity.width < 4) ||
3287 (queue_family_properties[index].minImageTransferGranularity.height < 4)) {
3288 return;
3289 }
3290
3291 // Create two images of different types and try to copy between them
3292 VkImage srcImage;
3293 VkImage dstImage;
3294 VkDeviceMemory srcMem;
3295 VkDeviceMemory destMem;
3296 VkMemoryRequirements memReqs;
3297
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003298 VkImageCreateInfo image_create_info = {};
3299 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3300 image_create_info.pNext = NULL;
3301 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3302 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
3303 image_create_info.extent.width = 32;
3304 image_create_info.extent.height = 32;
3305 image_create_info.extent.depth = 1;
3306 image_create_info.mipLevels = 1;
3307 image_create_info.arrayLayers = 4;
3308 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
3309 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
3310 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
3311 image_create_info.flags = 0;
3312
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003313 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003314 ASSERT_VK_SUCCESS(err);
3315
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003316 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003317 ASSERT_VK_SUCCESS(err);
3318
3319 // Allocate memory
3320 VkMemoryAllocateInfo memAlloc = {};
3321 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
3322 memAlloc.pNext = NULL;
3323 memAlloc.allocationSize = 0;
3324 memAlloc.memoryTypeIndex = 0;
3325
3326 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
3327 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003328 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003329 ASSERT_TRUE(pass);
3330 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
3331 ASSERT_VK_SUCCESS(err);
3332
3333 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
3334 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003335 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003336 ASSERT_VK_SUCCESS(err);
3337 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
3338 ASSERT_VK_SUCCESS(err);
3339
3340 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
3341 ASSERT_VK_SUCCESS(err);
3342 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
3343 ASSERT_VK_SUCCESS(err);
3344
Tony Barbour552f6c02016-12-21 14:34:07 -07003345 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003346 VkImageCopy copyRegion;
3347 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3348 copyRegion.srcSubresource.mipLevel = 0;
3349 copyRegion.srcSubresource.baseArrayLayer = 0;
3350 copyRegion.srcSubresource.layerCount = 1;
3351 copyRegion.srcOffset.x = 0;
3352 copyRegion.srcOffset.y = 0;
3353 copyRegion.srcOffset.z = 0;
3354 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3355 copyRegion.dstSubresource.mipLevel = 0;
3356 copyRegion.dstSubresource.baseArrayLayer = 0;
3357 copyRegion.dstSubresource.layerCount = 1;
3358 copyRegion.dstOffset.x = 0;
3359 copyRegion.dstOffset.y = 0;
3360 copyRegion.dstOffset.z = 0;
3361 copyRegion.extent.width = 1;
3362 copyRegion.extent.height = 1;
3363 copyRegion.extent.depth = 1;
3364
3365 // Introduce failure by setting srcOffset to a bad granularity value
3366 copyRegion.srcOffset.y = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003367 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3368 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003369 m_errorMonitor->VerifyFound();
3370
3371 // Introduce failure by setting extent to a bad granularity value
3372 copyRegion.srcOffset.y = 0;
3373 copyRegion.extent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003374 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3375 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003376 m_errorMonitor->VerifyFound();
3377
3378 // Now do some buffer/image copies
3379 vk_testing::Buffer buffer;
3380 VkMemoryPropertyFlags reqs = 0;
3381 buffer.init_as_dst(*m_device, 128 * 128, reqs);
3382 VkBufferImageCopy region = {};
3383 region.bufferOffset = 0;
3384 region.bufferRowLength = 3;
3385 region.bufferImageHeight = 128;
3386 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3387 region.imageSubresource.layerCount = 1;
3388 region.imageExtent.height = 16;
3389 region.imageExtent.width = 16;
3390 region.imageExtent.depth = 1;
3391 region.imageOffset.x = 0;
3392 region.imageOffset.y = 0;
3393 region.imageOffset.z = 0;
3394
3395 // Introduce failure by setting bufferRowLength to a bad granularity value
3396 region.bufferRowLength = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003397 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3398 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
3399 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003400 m_errorMonitor->VerifyFound();
3401 region.bufferRowLength = 128;
3402
3403 // Introduce failure by setting bufferOffset to a bad granularity value
3404 region.bufferOffset = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003405 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3406 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
3407 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003408 m_errorMonitor->VerifyFound();
3409 region.bufferOffset = 0;
3410
3411 // Introduce failure by setting bufferImageHeight to a bad granularity value
3412 region.bufferImageHeight = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003413 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3414 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
3415 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003416 m_errorMonitor->VerifyFound();
3417 region.bufferImageHeight = 128;
3418
3419 // Introduce failure by setting imageExtent to a bad granularity value
3420 region.imageExtent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003421 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3422 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
3423 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003424 m_errorMonitor->VerifyFound();
3425 region.imageExtent.width = 16;
3426
3427 // Introduce failure by setting imageOffset to a bad granularity value
3428 region.imageOffset.z = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003429 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3430 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
3431 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003432 m_errorMonitor->VerifyFound();
3433
Tony Barbour552f6c02016-12-21 14:34:07 -07003434 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003435
3436 vkDestroyImage(m_device->device(), srcImage, NULL);
3437 vkDestroyImage(m_device->device(), dstImage, NULL);
3438 vkFreeMemory(m_device->device(), srcMem, NULL);
3439 vkFreeMemory(m_device->device(), destMem, NULL);
3440}
3441
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003442TEST_F(VkLayerTest, MismatchedQueueFamiliesOnSubmit) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003443 TEST_DESCRIPTION(
3444 "Submit command buffer created using one queue family and "
3445 "attempt to submit them on a queue created in a different "
3446 "queue family.");
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003447
Tony Barbour1fa09702017-03-16 12:09:08 -06003448 ASSERT_NO_FATAL_FAILURE(Init());
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07003449
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003450 // This test is meaningless unless we have multiple queue families
3451 auto queue_family_properties = m_device->phy().queue_properties();
3452 if (queue_family_properties.size() < 2) {
3453 return;
3454 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003455 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is being submitted on queue ");
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003456 // Get safe index of another queue family
3457 uint32_t other_queue_family = (m_device->graphics_queue_node_index_ == 0) ? 1 : 0;
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003458 VkQueue other_queue;
3459 vkGetDeviceQueue(m_device->device(), other_queue_family, 0, &other_queue);
3460
3461 // Record an empty cmd buffer
3462 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
3463 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3464 vkBeginCommandBuffer(m_commandBuffer->handle(), &cmdBufBeginDesc);
3465 vkEndCommandBuffer(m_commandBuffer->handle());
3466
3467 // And submit on the wrong queue
3468 VkSubmitInfo submit_info = {};
3469 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3470 submit_info.commandBufferCount = 1;
3471 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Tobin Ehlisfd213ea2016-08-10 17:10:46 -06003472 vkQueueSubmit(other_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003473
3474 m_errorMonitor->VerifyFound();
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003475}
3476
Chris Forbes4c24a922016-11-16 08:59:10 +13003477TEST_F(VkLayerTest, RenderPassAttachmentIndexOutOfRange) {
Tony Barbour1fa09702017-03-16 12:09:08 -06003478 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes4c24a922016-11-16 08:59:10 +13003479
Chris Forbes2d9b2a82016-11-21 10:45:39 +13003480 // There are no attachments, but refer to attachment 0.
3481 VkAttachmentReference ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbes4c24a922016-11-16 08:59:10 +13003482 VkSubpassDescription subpasses[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003483 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &ref, nullptr, nullptr, 0, nullptr},
Chris Forbes4c24a922016-11-16 08:59:10 +13003484 };
3485
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003486 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 1, subpasses, 0, nullptr};
Chris Forbes4c24a922016-11-16 08:59:10 +13003487 VkRenderPass rp;
3488
Chris Forbes2d9b2a82016-11-21 10:45:39 +13003489 // "... must be less than the total number of attachments ..."
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003490 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00325);
Chris Forbes4c24a922016-11-16 08:59:10 +13003491 vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3492 m_errorMonitor->VerifyFound();
3493}
3494
Chris Forbesa58c4522016-09-28 15:19:39 +13003495TEST_F(VkLayerTest, RenderPassPipelineSubpassMismatch) {
3496 TEST_DESCRIPTION("Use a pipeline for the wrong subpass in a render pass instance");
Tony Barbour1fa09702017-03-16 12:09:08 -06003497 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbesa58c4522016-09-28 15:19:39 +13003498
3499 // A renderpass with two subpasses, both writing the same attachment.
3500 VkAttachmentDescription attach[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003501 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3502 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_UNDEFINED,
3503 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesa58c4522016-09-28 15:19:39 +13003504 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003505 VkAttachmentReference ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbesa58c4522016-09-28 15:19:39 +13003506 VkSubpassDescription subpasses[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003507 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &ref, nullptr, nullptr, 0, nullptr},
3508 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &ref, nullptr, nullptr, 0, nullptr},
Chris Forbesa58c4522016-09-28 15:19:39 +13003509 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003510 VkSubpassDependency dep = {0,
3511 1,
3512 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
3513 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
3514 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
3515 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
3516 VK_DEPENDENCY_BY_REGION_BIT};
3517 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, attach, 2, subpasses, 1, &dep};
Chris Forbesa58c4522016-09-28 15:19:39 +13003518 VkRenderPass rp;
3519 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3520 ASSERT_VK_SUCCESS(err);
3521
3522 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06003523 image.InitNoLayout(32, 32, 1, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Chris Forbesa58c4522016-09-28 15:19:39 +13003524 VkImageView imageView = image.targetView(VK_FORMAT_R8G8B8A8_UNORM);
3525
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003526 VkFramebufferCreateInfo fbci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &imageView, 32, 32, 1};
Chris Forbesa58c4522016-09-28 15:19:39 +13003527 VkFramebuffer fb;
3528 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
3529 ASSERT_VK_SUCCESS(err);
3530
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003531 char const *vsSource =
3532 "#version 450\n"
3533 "void main() { gl_Position = vec4(1); }\n";
3534 char const *fsSource =
3535 "#version 450\n"
3536 "layout(location=0) out vec4 color;\n"
3537 "void main() { color = vec4(1); }\n";
Chris Forbesa58c4522016-09-28 15:19:39 +13003538
3539 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
3540 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
3541 VkPipelineObj pipe(m_device);
3542 pipe.AddColorAttachment();
3543 pipe.AddShader(&vs);
3544 pipe.AddShader(&fs);
3545 VkViewport view_port = {};
3546 m_viewports.push_back(view_port);
3547 pipe.SetViewport(m_viewports);
3548 VkRect2D rect = {};
3549 m_scissors.push_back(rect);
3550 pipe.SetScissor(m_scissors);
3551
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003552 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 0, nullptr, 0, nullptr};
Chris Forbesa58c4522016-09-28 15:19:39 +13003553 VkPipelineLayout pl;
3554 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
3555 ASSERT_VK_SUCCESS(err);
3556 pipe.CreateVKPipeline(pl, rp);
3557
Tony Barbour552f6c02016-12-21 14:34:07 -07003558 m_commandBuffer->BeginCommandBuffer();
Chris Forbesa58c4522016-09-28 15:19:39 +13003559
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003560 VkRenderPassBeginInfo rpbi = {VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO,
3561 nullptr,
3562 rp,
3563 fb,
3564 {{
3565 0, 0,
3566 },
3567 {32, 32}},
3568 0,
3569 nullptr};
Chris Forbesa58c4522016-09-28 15:19:39 +13003570
3571 // subtest 1: bind in the wrong subpass
3572 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
3573 vkCmdNextSubpass(m_commandBuffer->handle(), VK_SUBPASS_CONTENTS_INLINE);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003574 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "built for subpass 0 but used in subpass 1");
Chris Forbesa58c4522016-09-28 15:19:39 +13003575 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
3576 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
3577 m_errorMonitor->VerifyFound();
3578
3579 vkCmdEndRenderPass(m_commandBuffer->handle());
3580
3581 // subtest 2: bind in correct subpass, then transition to next subpass
3582 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
3583 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
3584 vkCmdNextSubpass(m_commandBuffer->handle(), VK_SUBPASS_CONTENTS_INLINE);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003585 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "built for subpass 0 but used in subpass 1");
Chris Forbesa58c4522016-09-28 15:19:39 +13003586 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
3587 m_errorMonitor->VerifyFound();
3588
3589 vkCmdEndRenderPass(m_commandBuffer->handle());
3590
Tony Barbour552f6c02016-12-21 14:34:07 -07003591 m_commandBuffer->EndCommandBuffer();
Chris Forbesa58c4522016-09-28 15:19:39 +13003592
3593 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
3594 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
3595 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3596}
3597
Tony Barbour4e919972016-08-09 13:27:40 -06003598TEST_F(VkLayerTest, RenderPassInvalidRenderArea) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003599 TEST_DESCRIPTION(
3600 "Generate INVALID_RENDER_AREA error by beginning renderpass"
3601 "with extent outside of framebuffer");
Tony Barbour1fa09702017-03-16 12:09:08 -06003602 ASSERT_NO_FATAL_FAILURE(Init());
Tony Barbour4e919972016-08-09 13:27:40 -06003603 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3604
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003605 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3606 "Cannot execute a render pass with renderArea "
3607 "not within the bound of the framebuffer.");
Tony Barbour4e919972016-08-09 13:27:40 -06003608
3609 // Framebuffer for render target is 256x256, exceed that for INVALID_RENDER_AREA
3610 m_renderPassBeginInfo.renderArea.extent.width = 257;
3611 m_renderPassBeginInfo.renderArea.extent.height = 257;
Tony Barbour552f6c02016-12-21 14:34:07 -07003612 m_commandBuffer->BeginCommandBuffer();
3613 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tony Barbour4e919972016-08-09 13:27:40 -06003614 m_errorMonitor->VerifyFound();
3615}
3616
3617TEST_F(VkLayerTest, DisabledIndependentBlend) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003618 TEST_DESCRIPTION(
3619 "Generate INDEPENDENT_BLEND by disabling independent "
3620 "blend and then specifying different blend states for two "
3621 "attachements");
Cody Northrop5703cc72016-08-19 09:57:10 -06003622 VkPhysicalDeviceFeatures features = {};
3623 features.independentBlend = VK_FALSE;
Tony Barbour1fa09702017-03-16 12:09:08 -06003624 ASSERT_NO_FATAL_FAILURE(Init(&features));
Tony Barbour4e919972016-08-09 13:27:40 -06003625
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003626 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3627 "Invalid Pipeline CreateInfo: If independent blend feature not "
3628 "enabled, all elements of pAttachments must be identical");
Tony Barbour4e919972016-08-09 13:27:40 -06003629
Cody Northropc31a84f2016-08-22 10:41:47 -06003630 VkDescriptorSetObj descriptorSet(m_device);
3631 descriptorSet.AppendDummy();
3632 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Tony Barbour4e919972016-08-09 13:27:40 -06003633
Cody Northropc31a84f2016-08-22 10:41:47 -06003634 VkPipelineObj pipeline(m_device);
Tony Barbour0ace59a2017-02-06 13:38:36 -07003635 // Create a renderPass with two color attachments
3636 VkAttachmentReference attachments[2] = {};
3637 attachments[0].layout = VK_IMAGE_LAYOUT_GENERAL;
Tony Barbourffd60bd2017-03-09 12:04:55 -07003638 attachments[1].attachment = 1;
Tony Barbour0ace59a2017-02-06 13:38:36 -07003639 attachments[1].layout = VK_IMAGE_LAYOUT_GENERAL;
3640
3641 VkSubpassDescription subpass = {};
3642 subpass.pColorAttachments = attachments;
3643 subpass.colorAttachmentCount = 2;
3644
3645 VkRenderPassCreateInfo rpci = {};
3646 rpci.subpassCount = 1;
3647 rpci.pSubpasses = &subpass;
Tony Barbourffd60bd2017-03-09 12:04:55 -07003648 rpci.attachmentCount = 2;
Tony Barbour0ace59a2017-02-06 13:38:36 -07003649
Tony Barbourffd60bd2017-03-09 12:04:55 -07003650 VkAttachmentDescription attach_desc[2] = {};
3651 attach_desc[0].format = VK_FORMAT_B8G8R8A8_UNORM;
3652 attach_desc[0].samples = VK_SAMPLE_COUNT_1_BIT;
3653 attach_desc[0].initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
3654 attach_desc[0].finalLayout = VK_IMAGE_LAYOUT_GENERAL;
3655 attach_desc[1].format = VK_FORMAT_B8G8R8A8_UNORM;
3656 attach_desc[1].samples = VK_SAMPLE_COUNT_1_BIT;
3657 attach_desc[1].initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
3658 attach_desc[1].finalLayout = VK_IMAGE_LAYOUT_GENERAL;
Tony Barbour0ace59a2017-02-06 13:38:36 -07003659
Tony Barbourffd60bd2017-03-09 12:04:55 -07003660 rpci.pAttachments = attach_desc;
Tony Barbour0ace59a2017-02-06 13:38:36 -07003661 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3662
3663 VkRenderPass renderpass;
3664 vkCreateRenderPass(m_device->device(), &rpci, NULL, &renderpass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003665 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Cody Northropc31a84f2016-08-22 10:41:47 -06003666 pipeline.AddShader(&vs);
Cody Northrop5703cc72016-08-19 09:57:10 -06003667
Cody Northropc31a84f2016-08-22 10:41:47 -06003668 VkPipelineColorBlendAttachmentState att_state1 = {}, att_state2 = {};
3669 att_state1.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3670 att_state1.blendEnable = VK_TRUE;
3671 att_state2.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3672 att_state2.blendEnable = VK_FALSE;
3673 pipeline.AddColorAttachment(0, &att_state1);
3674 pipeline.AddColorAttachment(1, &att_state2);
Tony Barbour0ace59a2017-02-06 13:38:36 -07003675 pipeline.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderpass);
Cody Northropc31a84f2016-08-22 10:41:47 -06003676 m_errorMonitor->VerifyFound();
Tony Barbour0ace59a2017-02-06 13:38:36 -07003677 vkDestroyRenderPass(m_device->device(), renderpass, NULL);
Tony Barbour4e919972016-08-09 13:27:40 -06003678}
3679
Mike Weiblen40b160e2017-02-06 19:21:52 -07003680// Is the Pipeline compatible with the expectations of the Renderpass/subpasses?
3681TEST_F(VkLayerTest, PipelineRenderpassCompatibility) {
3682 TEST_DESCRIPTION(
3683 "Create a graphics pipeline that is incompatible with the requirements "
3684 "of its contained Renderpass/subpasses.");
Tony Barbour1fa09702017-03-16 12:09:08 -06003685 ASSERT_NO_FATAL_FAILURE(Init());
Mike Weiblen40b160e2017-02-06 19:21:52 -07003686
3687 VkDescriptorSetObj ds_obj(m_device);
3688 ds_obj.AppendDummy();
3689 ds_obj.CreateVKDescriptorSet(m_commandBuffer);
3690
3691 VkShaderObj vs_obj(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
3692
3693 VkPipelineColorBlendAttachmentState att_state1 = {};
3694 att_state1.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3695 att_state1.blendEnable = VK_TRUE;
3696
3697 VkRenderpassObj rp_obj(m_device);
3698
3699 {
3700 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02116);
3701 VkPipelineObj pipeline(m_device);
3702 pipeline.AddShader(&vs_obj);
3703 pipeline.AddColorAttachment(0, &att_state1);
3704
3705 VkGraphicsPipelineCreateInfo info = {};
3706 pipeline.InitGraphicsPipelineCreateInfo(&info);
3707 info.pColorBlendState = nullptr;
3708
3709 pipeline.CreateVKPipeline(ds_obj.GetPipelineLayout(), rp_obj.handle(), &info);
3710 m_errorMonitor->VerifyFound();
3711 }
3712}
3713
Cort Stratton7547f772017-05-04 15:18:52 -07003714TEST_F(VkLayerTest, CreateRenderPassAttachments) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003715 TEST_DESCRIPTION(
Cort Stratton7547f772017-05-04 15:18:52 -07003716 "Ensure that CreateRenderPass produces the expected validation errors "
3717 "when a subpass's attachments violate the valid usage conditions.");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003718
Tony Barbour1fa09702017-03-16 12:09:08 -06003719 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003720
Cort Stratton7547f772017-05-04 15:18:52 -07003721 std::vector<VkAttachmentDescription> attachments = {
3722 // input attachments
3723 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3724 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_GENERAL,
3725 VK_IMAGE_LAYOUT_GENERAL},
3726 // color attachments
3727 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3728 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3729 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3730 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3731 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3732 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3733 // depth attachment
3734 {0, VK_FORMAT_D24_UNORM_S8_UINT, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3735 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
3736 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL},
3737 // resolve attachment
3738 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3739 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3740 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3741 // preserve attachments
3742 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3743 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3744 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3745 };
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003746
Cort Stratton7547f772017-05-04 15:18:52 -07003747 std::vector<VkAttachmentReference> input = {
3748 {0, VK_IMAGE_LAYOUT_GENERAL},
3749 };
3750 std::vector<VkAttachmentReference> color = {
3751 {1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL}, {2, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3752 };
3753 VkAttachmentReference depth = {3, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
3754 std::vector<VkAttachmentReference> resolve = {
3755 {4, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL}, {VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3756 };
3757 std::vector<uint32_t> preserve = {5};
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003758
Cort Stratton7547f772017-05-04 15:18:52 -07003759 VkSubpassDescription subpass = {0,
3760 VK_PIPELINE_BIND_POINT_GRAPHICS,
3761 (uint32_t)input.size(),
3762 input.data(),
3763 (uint32_t)color.size(),
3764 color.data(),
3765 resolve.data(),
3766 &depth,
3767 (uint32_t)preserve.size(),
3768 preserve.data()};
3769
3770 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO,
3771 nullptr,
3772 0,
3773 (uint32_t)attachments.size(),
3774 attachments.data(),
3775 1,
3776 &subpass,
3777 0,
3778 nullptr};
3779
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003780 VkRenderPass rp;
Cort Stratton7547f772017-05-04 15:18:52 -07003781 VkResult err;
3782 // Test too many color attachments
3783 {
3784 std::vector<VkAttachmentReference> too_many_colors(m_device->props.limits.maxColorAttachments + 1, color[0]);
3785 subpass.colorAttachmentCount = (uint32_t)too_many_colors.size();
3786 subpass.pColorAttachments = too_many_colors.data();
3787 subpass.pResolveAttachments = NULL;
3788 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00348);
3789 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3790 m_errorMonitor->VerifyFound();
3791 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
3792 subpass.colorAttachmentCount = (uint32_t)color.size();
3793 subpass.pColorAttachments = color.data();
3794 subpass.pResolveAttachments = resolve.data();
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003795 }
Cort Stratton7547f772017-05-04 15:18:52 -07003796 // Test sample count mismatch between color buffers
3797 attachments[subpass.pColorAttachments[1].attachment].samples = VK_SAMPLE_COUNT_8_BIT;
3798 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00337);
3799 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
Chris Forbesc5389742016-06-29 11:49:23 +12003800 m_errorMonitor->VerifyFound();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003801 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
Cort Stratton7547f772017-05-04 15:18:52 -07003802 attachments[subpass.pColorAttachments[1].attachment].samples = attachments[subpass.pColorAttachments[0].attachment].samples;
3803 // Test sample count mismatch between color buffers and depth buffer
3804 attachments[subpass.pDepthStencilAttachment->attachment].samples = VK_SAMPLE_COUNT_8_BIT;
3805 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00337);
3806 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
Chris Forbesc5389742016-06-29 11:49:23 +12003807 m_errorMonitor->VerifyFound();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003808 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
Cort Stratton7547f772017-05-04 15:18:52 -07003809 attachments[subpass.pDepthStencilAttachment->attachment].samples = attachments[subpass.pColorAttachments[0].attachment].samples;
3810 // Test resolve attachment with UNUSED color attachment
3811 color[0].attachment = VK_ATTACHMENT_UNUSED;
3812 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00350);
3813 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
Chris Forbes3f128ef2016-06-29 14:58:53 +12003814 m_errorMonitor->VerifyFound();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003815 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
Cort Stratton7547f772017-05-04 15:18:52 -07003816 color[0].attachment = 1;
3817 // Test resolve from a single-sampled color attachment
3818 attachments[subpass.pColorAttachments[0].attachment].samples = VK_SAMPLE_COUNT_1_BIT;
3819 attachments[subpass.pColorAttachments[1].attachment].samples = VK_SAMPLE_COUNT_1_BIT; // avoid mismatch (00337)
3820 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00351);
3821 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3822 m_errorMonitor->VerifyFound();
3823 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
3824 attachments[subpass.pColorAttachments[0].attachment].samples = VK_SAMPLE_COUNT_4_BIT;
3825 attachments[subpass.pColorAttachments[1].attachment].samples = VK_SAMPLE_COUNT_4_BIT;
3826 // Test resolve to a multi-sampled resolve attachment
3827 attachments[subpass.pResolveAttachments[0].attachment].samples = VK_SAMPLE_COUNT_4_BIT;
3828 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00352);
3829 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3830 m_errorMonitor->VerifyFound();
3831 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
3832 attachments[subpass.pResolveAttachments[0].attachment].samples = VK_SAMPLE_COUNT_1_BIT;
3833 // Test with color/resolve format mismatch
3834 attachments[subpass.pColorAttachments[0].attachment].format = VK_FORMAT_R8G8B8A8_SRGB;
3835 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00353);
3836 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3837 m_errorMonitor->VerifyFound();
3838 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
3839 attachments[subpass.pColorAttachments[0].attachment].format = attachments[subpass.pResolveAttachments[0].attachment].format;
3840 // Test for UNUSED preserve attachments
3841 preserve[0] = VK_ATTACHMENT_UNUSED;
3842 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00356);
3843 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3844 m_errorMonitor->VerifyFound();
3845 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
3846 preserve[0] = 5;
3847 // Test for preserve attachments used elsewhere in the subpass
3848 color[0].attachment = preserve[0];
3849 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00357);
3850 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3851 m_errorMonitor->VerifyFound();
3852 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
3853 color[0].attachment = 1;
3854 // test for layout mismatch between input attachment and color attachment
3855 input[0].attachment = color[0].attachment;
3856 input[0].layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
3857 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00358);
3858 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3859 m_errorMonitor->VerifyFound();
3860 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
3861 input[0].attachment = 0;
3862 input[0].layout = VK_IMAGE_LAYOUT_GENERAL;
3863 // test for layout mismatch between input attachment and depth attachment
3864 input[0].attachment = depth.attachment;
3865 input[0].layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
3866 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00358);
3867 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3868 m_errorMonitor->VerifyFound();
3869 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
3870 input[0].attachment = 0;
3871 input[0].layout = VK_IMAGE_LAYOUT_GENERAL;
3872 // Test for attachment used first as input with loadOp=CLEAR
3873 {
3874 std::vector<VkSubpassDescription> subpasses = {subpass, subpass, subpass};
3875 subpasses[0].inputAttachmentCount = 0;
3876 subpasses[1].inputAttachmentCount = 0;
3877 attachments[input[0].attachment].loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
3878 VkRenderPassCreateInfo rpci_multipass = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO,
3879 nullptr,
3880 0,
3881 (uint32_t)attachments.size(),
3882 attachments.data(),
3883 (uint32_t)subpasses.size(),
3884 subpasses.data(),
3885 0,
3886 nullptr};
3887 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00349);
3888 err = vkCreateRenderPass(m_device->device(), &rpci_multipass, nullptr, &rp);
3889 m_errorMonitor->VerifyFound();
3890 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
3891 attachments[input[0].attachment].loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
3892 }
Chris Forbes3f128ef2016-06-29 14:58:53 +12003893}
3894
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003895TEST_F(VkLayerTest, FramebufferCreateErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003896 TEST_DESCRIPTION(
3897 "Hit errors when attempting to create a framebuffer :\n"
3898 " 1. Mismatch between framebuffer & renderPass attachmentCount\n"
3899 " 2. Use a color image as depthStencil attachment\n"
3900 " 3. Mismatch framebuffer & renderPass attachment formats\n"
3901 " 4. Mismatch framebuffer & renderPass attachment #samples\n"
3902 " 5. Framebuffer attachment w/ non-1 mip-levels\n"
3903 " 6. Framebuffer attachment where dimensions don't match\n"
Cort Stratton8133ec22017-04-27 16:25:03 +02003904 " 7. Framebuffer attachment where dimensions don't match\n"
3905 " 8. Framebuffer attachment w/o identity swizzle\n"
3906 " 9. framebuffer dimensions exceed physical device limits\n");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003907
Tony Barbour1fa09702017-03-16 12:09:08 -06003908 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003909 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3910
Cort Stratton8133ec22017-04-27 16:25:03 +02003911 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00404);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003912
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003913 // Create a renderPass with a single color attachment
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003914 VkAttachmentReference attach = {};
3915 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
3916 VkSubpassDescription subpass = {};
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003917 subpass.pColorAttachments = &attach;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003918 VkRenderPassCreateInfo rpci = {};
3919 rpci.subpassCount = 1;
3920 rpci.pSubpasses = &subpass;
3921 rpci.attachmentCount = 1;
3922 VkAttachmentDescription attach_desc = {};
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003923 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003924 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003925 rpci.pAttachments = &attach_desc;
3926 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3927 VkRenderPass rp;
3928 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3929 ASSERT_VK_SUCCESS(err);
3930
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003931 VkImageView ivs[2];
3932 ivs[0] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
3933 ivs[1] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003934 VkFramebufferCreateInfo fb_info = {};
3935 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
3936 fb_info.pNext = NULL;
3937 fb_info.renderPass = rp;
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003938 // Set mis-matching attachmentCount
3939 fb_info.attachmentCount = 2;
3940 fb_info.pAttachments = ivs;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003941 fb_info.width = 100;
3942 fb_info.height = 100;
3943 fb_info.layers = 1;
3944
3945 VkFramebuffer fb;
3946 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3947
3948 m_errorMonitor->VerifyFound();
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003949 if (err == VK_SUCCESS) {
3950 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3951 }
3952 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003953
3954 // Create a renderPass with a depth-stencil attachment created with
3955 // IMAGE_USAGE_COLOR_ATTACHMENT
3956 // Add our color attachment to pDepthStencilAttachment
3957 subpass.pDepthStencilAttachment = &attach;
3958 subpass.pColorAttachments = NULL;
3959 VkRenderPass rp_ds;
3960 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp_ds);
3961 ASSERT_VK_SUCCESS(err);
3962 // Set correct attachment count, but attachment has COLOR usage bit set
3963 fb_info.attachmentCount = 1;
3964 fb_info.renderPass = rp_ds;
3965
Cort Stratton8133ec22017-04-27 16:25:03 +02003966 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00406);
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003967 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3968
3969 m_errorMonitor->VerifyFound();
3970 if (err == VK_SUCCESS) {
3971 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3972 }
3973 vkDestroyRenderPass(m_device->device(), rp_ds, NULL);
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003974
3975 // Create new renderpass with alternate attachment format from fb
3976 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
3977 subpass.pDepthStencilAttachment = NULL;
3978 subpass.pColorAttachments = &attach;
3979 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3980 ASSERT_VK_SUCCESS(err);
3981
3982 // Cause error due to mis-matched formats between rp & fb
3983 // rp attachment 0 now has RGBA8 but corresponding fb attach is BGRA8
3984 fb_info.renderPass = rp;
Cort Stratton8133ec22017-04-27 16:25:03 +02003985 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00408);
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003986 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3987
3988 m_errorMonitor->VerifyFound();
3989 if (err == VK_SUCCESS) {
3990 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3991 }
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003992 vkDestroyRenderPass(m_device->device(), rp, NULL);
3993
3994 // Create new renderpass with alternate sample count from fb
3995 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
3996 attach_desc.samples = VK_SAMPLE_COUNT_4_BIT;
3997 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3998 ASSERT_VK_SUCCESS(err);
3999
4000 // Cause error due to mis-matched sample count between rp & fb
4001 fb_info.renderPass = rp;
Cort Stratton8133ec22017-04-27 16:25:03 +02004002 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00409);
Tobin Ehlis77d717c2016-06-22 14:19:19 -06004003 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4004
4005 m_errorMonitor->VerifyFound();
4006 if (err == VK_SUCCESS) {
4007 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4008 }
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06004009
4010 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis6cfda642016-06-22 16:12:58 -06004011
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06004012 {
4013 // Create an image with 2 mip levels.
4014 VkImageObj image(m_device);
4015 image.Init(128, 128, 2, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
4016 ASSERT_TRUE(image.initialized());
Tobin Ehlis6cfda642016-06-22 16:12:58 -06004017
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06004018 // Create a image view with two mip levels.
4019 VkImageView view;
4020 VkImageViewCreateInfo ivci = {};
4021 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
4022 ivci.image = image.handle();
4023 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
4024 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
4025 ivci.subresourceRange.layerCount = 1;
4026 ivci.subresourceRange.baseMipLevel = 0;
4027 // Set level count to 2 (only 1 is allowed for FB attachment)
4028 ivci.subresourceRange.levelCount = 2;
4029 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4030 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
4031 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6cfda642016-06-22 16:12:58 -06004032
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06004033 // Re-create renderpass to have matching sample count
4034 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
4035 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
4036 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6cfda642016-06-22 16:12:58 -06004037
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06004038 fb_info.renderPass = rp;
4039 fb_info.pAttachments = &view;
Cort Stratton8133ec22017-04-27 16:25:03 +02004040 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00411);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06004041 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4042
4043 m_errorMonitor->VerifyFound();
4044 if (err == VK_SUCCESS) {
4045 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4046 }
4047 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis6cfda642016-06-22 16:12:58 -06004048 }
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06004049
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06004050 // Update view to original color buffer and grow FB dimensions too big
4051 fb_info.pAttachments = ivs;
4052 fb_info.height = 1024;
4053 fb_info.width = 1024;
4054 fb_info.layers = 2;
Cort Stratton8133ec22017-04-27 16:25:03 +02004055 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00410);
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06004056 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4057
4058 m_errorMonitor->VerifyFound();
4059 if (err == VK_SUCCESS) {
4060 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4061 }
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06004062
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06004063 {
4064 // Create an image with one mip level.
4065 VkImageObj image(m_device);
4066 image.Init(128, 128, 1, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
4067 ASSERT_TRUE(image.initialized());
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06004068
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06004069 // Create view attachment with non-identity swizzle
4070 VkImageView view;
4071 VkImageViewCreateInfo ivci = {};
4072 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
4073 ivci.image = image.handle();
4074 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
4075 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
4076 ivci.subresourceRange.layerCount = 1;
4077 ivci.subresourceRange.baseMipLevel = 0;
4078 ivci.subresourceRange.levelCount = 1;
4079 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4080 ivci.components.r = VK_COMPONENT_SWIZZLE_G;
4081 ivci.components.g = VK_COMPONENT_SWIZZLE_R;
4082 ivci.components.b = VK_COMPONENT_SWIZZLE_A;
4083 ivci.components.a = VK_COMPONENT_SWIZZLE_B;
4084 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
4085 ASSERT_VK_SUCCESS(err);
4086
4087 fb_info.pAttachments = &view;
4088 fb_info.height = 100;
4089 fb_info.width = 100;
4090 fb_info.layers = 1;
4091
Cort Stratton8133ec22017-04-27 16:25:03 +02004092 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00412);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06004093 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4094
4095 m_errorMonitor->VerifyFound();
4096 if (err == VK_SUCCESS) {
4097 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4098 }
4099 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06004100 }
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06004101
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004102 // reset attachment to color attachment
4103 fb_info.pAttachments = ivs;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004104
4105 // Request fb that exceeds max width
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004106 fb_info.width = m_device->props.limits.maxFramebufferWidth + 1;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004107 fb_info.height = 100;
4108 fb_info.layers = 1;
4109 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00413);
Cort Stratton8133ec22017-04-27 16:25:03 +02004110 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00410);
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004111 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
Cort Stratton8133ec22017-04-27 16:25:03 +02004112 m_errorMonitor->VerifyFound();
4113 if (err == VK_SUCCESS) {
4114 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4115 }
4116 // and width=0
4117 fb_info.width = 0;
4118 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02806);
4119 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004120 m_errorMonitor->VerifyFound();
4121 if (err == VK_SUCCESS) {
4122 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4123 }
4124
4125 // Request fb that exceeds max height
4126 fb_info.width = 100;
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004127 fb_info.height = m_device->props.limits.maxFramebufferHeight + 1;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004128 fb_info.layers = 1;
4129 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00414);
Cort Stratton8133ec22017-04-27 16:25:03 +02004130 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00410);
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004131 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
Cort Stratton8133ec22017-04-27 16:25:03 +02004132 m_errorMonitor->VerifyFound();
4133 if (err == VK_SUCCESS) {
4134 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4135 }
4136 // and height=0
4137 fb_info.height = 0;
4138 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02807);
4139 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004140 m_errorMonitor->VerifyFound();
4141 if (err == VK_SUCCESS) {
4142 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4143 }
4144
4145 // Request fb that exceeds max layers
4146 fb_info.width = 100;
4147 fb_info.height = 100;
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004148 fb_info.layers = m_device->props.limits.maxFramebufferLayers + 1;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004149 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00415);
Cort Stratton8133ec22017-04-27 16:25:03 +02004150 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00410);
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004151 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
Cort Stratton8133ec22017-04-27 16:25:03 +02004152 m_errorMonitor->VerifyFound();
4153 if (err == VK_SUCCESS) {
4154 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4155 }
4156 // and layers=0
4157 fb_info.layers = 0;
4158 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02808);
4159 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004160 m_errorMonitor->VerifyFound();
4161 if (err == VK_SUCCESS) {
4162 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4163 }
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06004164
Tobin Ehlis6cfda642016-06-22 16:12:58 -06004165 vkDestroyRenderPass(m_device->device(), rp, NULL);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004166}
4167
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004168TEST_F(VkLayerTest, DynamicDepthBiasNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004169 TEST_DESCRIPTION(
4170 "Run a simple draw calls to validate failure when Depth Bias dynamic "
4171 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004172
Tony Barbour1fa09702017-03-16 12:09:08 -06004173 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004174 // Dynamic depth bias
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004175 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic depth bias state not set for this command buffer");
4176 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBias);
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004177 m_errorMonitor->VerifyFound();
4178}
4179
4180TEST_F(VkLayerTest, DynamicLineWidthNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004181 TEST_DESCRIPTION(
4182 "Run a simple draw calls to validate failure when Line Width dynamic "
4183 "state is required but not correctly bound.");
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004184
Tony Barbour1fa09702017-03-16 12:09:08 -06004185 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004186 // Dynamic line width
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004187 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic line width state not set for this command buffer");
4188 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailLineWidth);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004189 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004190}
4191
4192TEST_F(VkLayerTest, DynamicViewportNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004193 TEST_DESCRIPTION(
4194 "Run a simple draw calls to validate failure when Viewport dynamic "
4195 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004196
Tony Barbour1fa09702017-03-16 12:09:08 -06004197 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004198 // Dynamic viewport state
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07004199 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4200 "Dynamic viewport(s) 0 are used by pipeline state object, but were not provided");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004201 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailViewport);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004202 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004203}
4204
4205TEST_F(VkLayerTest, DynamicScissorNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004206 TEST_DESCRIPTION(
4207 "Run a simple draw calls to validate failure when Scissor dynamic "
4208 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004209
Tony Barbour1fa09702017-03-16 12:09:08 -06004210 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004211 // Dynamic scissor state
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07004212 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4213 "Dynamic scissor(s) 0 are used by pipeline state object, but were not provided");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004214 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailScissor);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004215 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004216}
4217
Cortd713fe82016-07-27 09:51:27 -07004218TEST_F(VkLayerTest, DynamicBlendConstantsNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004219 TEST_DESCRIPTION(
4220 "Run a simple draw calls to validate failure when Blend Constants "
4221 "dynamic state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004222
Tony Barbour1fa09702017-03-16 12:09:08 -06004223 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis21c88352016-05-26 06:15:45 -06004224 // Dynamic blend constant state
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004225 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4226 "Dynamic blend constants state not set for this command buffer");
4227 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailBlend);
Tobin Ehlis21c88352016-05-26 06:15:45 -06004228 m_errorMonitor->VerifyFound();
4229}
4230
4231TEST_F(VkLayerTest, DynamicDepthBoundsNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004232 TEST_DESCRIPTION(
4233 "Run a simple draw calls to validate failure when Depth Bounds dynamic "
4234 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004235
Tony Barbour1fa09702017-03-16 12:09:08 -06004236 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis21c88352016-05-26 06:15:45 -06004237 if (!m_device->phy().features().depthBounds) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07004238 printf(" Device does not support depthBounds test; skipped.\n");
Tobin Ehlis21c88352016-05-26 06:15:45 -06004239 return;
4240 }
4241 // Dynamic depth bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004242 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4243 "Dynamic depth bounds state not set for this command buffer");
4244 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBounds);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004245 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004246}
4247
4248TEST_F(VkLayerTest, DynamicStencilReadNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004249 TEST_DESCRIPTION(
4250 "Run a simple draw calls to validate failure when Stencil Read dynamic "
4251 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004252
Tony Barbour1fa09702017-03-16 12:09:08 -06004253 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004254 // Dynamic stencil read mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004255 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4256 "Dynamic stencil read mask state not set for this command buffer");
4257 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReadMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004258 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004259}
4260
4261TEST_F(VkLayerTest, DynamicStencilWriteNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004262 TEST_DESCRIPTION(
4263 "Run a simple draw calls to validate failure when Stencil Write dynamic"
4264 " state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004265
Tony Barbour1fa09702017-03-16 12:09:08 -06004266 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004267 // Dynamic stencil write mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004268 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4269 "Dynamic stencil write mask state not set for this command buffer");
4270 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilWriteMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004271 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004272}
4273
4274TEST_F(VkLayerTest, DynamicStencilRefNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004275 TEST_DESCRIPTION(
4276 "Run a simple draw calls to validate failure when Stencil Ref dynamic "
4277 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004278
Tony Barbour1fa09702017-03-16 12:09:08 -06004279 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004280 // Dynamic stencil reference
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004281 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4282 "Dynamic stencil reference state not set for this command buffer");
4283 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReference);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004284 m_errorMonitor->VerifyFound();
Tobin Ehlis963a4042015-09-29 08:18:34 -06004285}
4286
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06004287TEST_F(VkLayerTest, IndexBufferNotBound) {
4288 TEST_DESCRIPTION("Run an indexed draw call without an index buffer bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004289
Tony Barbour1fa09702017-03-16 12:09:08 -06004290 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004291 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4292 "Index buffer object not bound to this command buffer when Indexed ");
4293 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailIndexBuffer);
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06004294 m_errorMonitor->VerifyFound();
4295}
4296
Karl Schultz6addd812016-02-02 17:17:23 -07004297TEST_F(VkLayerTest, CommandBufferTwoSubmits) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004298 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4299 "was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has "
4300 "been submitted");
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004301
Tony Barbour1fa09702017-03-16 12:09:08 -06004302 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004303 ASSERT_NO_FATAL_FAILURE(InitViewport());
4304 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4305
Karl Schultz6addd812016-02-02 17:17:23 -07004306 // We luck out b/c by default the framework creates CB w/ the
4307 // VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set
Tony Barbour552f6c02016-12-21 14:34:07 -07004308 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004309 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbour552f6c02016-12-21 14:34:07 -07004310 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004311
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004312 // Bypass framework since it does the waits automatically
4313 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06004314 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08004315 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4316 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004317 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06004318 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07004319 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004320 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004321 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08004322 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06004323 submit_info.pSignalSemaphores = NULL;
4324
Chris Forbes40028e22016-06-13 09:59:34 +12004325 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Karl Schultz6addd812016-02-02 17:17:23 -07004326 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski89cad1a2016-11-11 15:51:31 -07004327 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004328
Karl Schultz6addd812016-02-02 17:17:23 -07004329 // Cause validation error by re-submitting cmd buffer that should only be
4330 // submitted once
Chris Forbes40028e22016-06-13 09:59:34 +12004331 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski89cad1a2016-11-11 15:51:31 -07004332 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004333
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004334 m_errorMonitor->VerifyFound();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004335}
4336
Karl Schultz6addd812016-02-02 17:17:23 -07004337TEST_F(VkLayerTest, AllocDescriptorFromEmptyPool) {
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004338 TEST_DESCRIPTION("Attempt to allocate more sets and descriptors than descriptor pool has available.");
Karl Schultz6addd812016-02-02 17:17:23 -07004339 VkResult err;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004340
Tony Barbour1fa09702017-03-16 12:09:08 -06004341 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004342 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004343
Karl Schultz6addd812016-02-02 17:17:23 -07004344 // Create Pool w/ 1 Sampler descriptor, but try to alloc Uniform Buffer
4345 // descriptor from it
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004346 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004347 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004348 ds_type_count.descriptorCount = 2;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004349
4350 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004351 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4352 ds_pool_ci.pNext = NULL;
4353 ds_pool_ci.flags = 0;
4354 ds_pool_ci.maxSets = 1;
4355 ds_pool_ci.poolSizeCount = 1;
4356 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004357
4358 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004359 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004360 ASSERT_VK_SUCCESS(err);
4361
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004362 VkDescriptorSetLayoutBinding dsl_binding_samp = {};
4363 dsl_binding_samp.binding = 0;
4364 dsl_binding_samp.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
4365 dsl_binding_samp.descriptorCount = 1;
4366 dsl_binding_samp.stageFlags = VK_SHADER_STAGE_ALL;
4367 dsl_binding_samp.pImmutableSamplers = NULL;
4368
4369 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4370 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4371 ds_layout_ci.pNext = NULL;
4372 ds_layout_ci.bindingCount = 1;
4373 ds_layout_ci.pBindings = &dsl_binding_samp;
4374
4375 VkDescriptorSetLayout ds_layout_samp;
4376 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_samp);
4377 ASSERT_VK_SUCCESS(err);
4378
4379 // Try to allocate 2 sets when pool only has 1 set
4380 VkDescriptorSet descriptor_sets[2];
4381 VkDescriptorSetLayout set_layouts[2] = {ds_layout_samp, ds_layout_samp};
4382 VkDescriptorSetAllocateInfo alloc_info = {};
4383 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4384 alloc_info.descriptorSetCount = 2;
4385 alloc_info.descriptorPool = ds_pool;
4386 alloc_info.pSetLayouts = set_layouts;
4387 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00911);
4388 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
4389 m_errorMonitor->VerifyFound();
4390
4391 alloc_info.descriptorSetCount = 1;
4392 // Create layout w/ descriptor type not available in pool
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004393 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004394 dsl_binding.binding = 0;
4395 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4396 dsl_binding.descriptorCount = 1;
4397 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4398 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004399
Karl Schultz6addd812016-02-02 17:17:23 -07004400 ds_layout_ci.bindingCount = 1;
4401 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004402
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004403 VkDescriptorSetLayout ds_layout_ub;
4404 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_ub);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004405 ASSERT_VK_SUCCESS(err);
4406
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004407 VkDescriptorSet descriptor_set;
Jon Ashburnf19916e2016-01-11 13:12:43 -07004408 alloc_info.descriptorSetCount = 1;
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004409 alloc_info.pSetLayouts = &ds_layout_ub;
4410 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00912);
4411 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004412
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004413 m_errorMonitor->VerifyFound();
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004414
Karl Schultz2825ab92016-12-02 08:23:14 -07004415 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_samp, NULL);
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004416 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_ub, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +08004417 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004418}
4419
Karl Schultz6addd812016-02-02 17:17:23 -07004420TEST_F(VkLayerTest, FreeDescriptorFromOneShotPool) {
4421 VkResult err;
Tobin Ehlise735c692015-10-08 13:13:50 -06004422
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07004423 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00922);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004424
Tony Barbour1fa09702017-03-16 12:09:08 -06004425 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlise735c692015-10-08 13:13:50 -06004426 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise735c692015-10-08 13:13:50 -06004427
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004428 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004429 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4430 ds_type_count.descriptorCount = 1;
Tobin Ehlise735c692015-10-08 13:13:50 -06004431
4432 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004433 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4434 ds_pool_ci.pNext = NULL;
4435 ds_pool_ci.maxSets = 1;
4436 ds_pool_ci.poolSizeCount = 1;
4437 ds_pool_ci.flags = 0;
4438 // Not specifying VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT means
4439 // app can only call vkResetDescriptorPool on this pool.;
4440 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise735c692015-10-08 13:13:50 -06004441
4442 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004443 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise735c692015-10-08 13:13:50 -06004444 ASSERT_VK_SUCCESS(err);
4445
4446 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004447 dsl_binding.binding = 0;
4448 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4449 dsl_binding.descriptorCount = 1;
4450 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4451 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise735c692015-10-08 13:13:50 -06004452
4453 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004454 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4455 ds_layout_ci.pNext = NULL;
4456 ds_layout_ci.bindingCount = 1;
4457 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise735c692015-10-08 13:13:50 -06004458
4459 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004460 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise735c692015-10-08 13:13:50 -06004461 ASSERT_VK_SUCCESS(err);
4462
4463 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004464 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08004465 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07004466 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06004467 alloc_info.descriptorPool = ds_pool;
4468 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004469 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise735c692015-10-08 13:13:50 -06004470 ASSERT_VK_SUCCESS(err);
4471
4472 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004473 m_errorMonitor->VerifyFound();
Tobin Ehlise735c692015-10-08 13:13:50 -06004474
Chia-I Wuf7458c52015-10-26 21:10:41 +08004475 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4476 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise735c692015-10-08 13:13:50 -06004477}
4478
Karl Schultz6addd812016-02-02 17:17:23 -07004479TEST_F(VkLayerTest, InvalidDescriptorPool) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004480 // Attempt to clear Descriptor Pool with bad object.
4481 // ObjectTracker should catch this.
Cody Northropc31a84f2016-08-22 10:41:47 -06004482
Tony Barbour1fa09702017-03-16 12:09:08 -06004483 ASSERT_NO_FATAL_FAILURE(Init());
Karl Schultzf78bcdd2016-11-30 12:36:01 -07004484 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00930);
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004485 uint64_t fake_pool_handle = 0xbaad6001;
4486 VkDescriptorPool bad_pool = reinterpret_cast<VkDescriptorPool &>(fake_pool_handle);
4487 vkResetDescriptorPool(device(), bad_pool, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -06004488 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004489}
4490
Karl Schultzf78bcdd2016-11-30 12:36:01 -07004491TEST_F(VkLayerTest, InvalidDescriptorSet) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004492 // Attempt to bind an invalid Descriptor Set to a valid Command Buffer
4493 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004494 // Create a valid cmd buffer
Karl Schultzbdb75952016-04-19 11:36:49 -06004495 // call vkCmdBindDescriptorSets w/ false Descriptor Set
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004496
4497 uint64_t fake_set_handle = 0xbaad6001;
4498 VkDescriptorSet bad_set = reinterpret_cast<VkDescriptorSet &>(fake_set_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06004499 VkResult err;
Karl Schultzf78bcdd2016-11-30 12:36:01 -07004500 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00982);
Karl Schultzbdb75952016-04-19 11:36:49 -06004501
Tony Barbour1fa09702017-03-16 12:09:08 -06004502 ASSERT_NO_FATAL_FAILURE(Init());
Karl Schultzbdb75952016-04-19 11:36:49 -06004503
4504 VkDescriptorSetLayoutBinding layout_bindings[1] = {};
4505 layout_bindings[0].binding = 0;
4506 layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4507 layout_bindings[0].descriptorCount = 1;
4508 layout_bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
4509 layout_bindings[0].pImmutableSamplers = NULL;
4510
4511 VkDescriptorSetLayout descriptor_set_layout;
4512 VkDescriptorSetLayoutCreateInfo dslci = {};
4513 dslci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4514 dslci.pNext = NULL;
4515 dslci.bindingCount = 1;
4516 dslci.pBindings = layout_bindings;
4517 err = vkCreateDescriptorSetLayout(device(), &dslci, NULL, &descriptor_set_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06004518 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06004519
4520 VkPipelineLayout pipeline_layout;
4521 VkPipelineLayoutCreateInfo plci = {};
4522 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4523 plci.pNext = NULL;
4524 plci.setLayoutCount = 1;
4525 plci.pSetLayouts = &descriptor_set_layout;
4526 err = vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06004527 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06004528
Tony Barbour552f6c02016-12-21 14:34:07 -07004529 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004530 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &bad_set, 0,
4531 NULL);
Karl Schultzbdb75952016-04-19 11:36:49 -06004532 m_errorMonitor->VerifyFound();
Tony Barbour552f6c02016-12-21 14:34:07 -07004533 m_commandBuffer->EndCommandBuffer();
Karl Schultzbdb75952016-04-19 11:36:49 -06004534 vkDestroyPipelineLayout(device(), pipeline_layout, NULL);
4535 vkDestroyDescriptorSetLayout(device(), descriptor_set_layout, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004536}
4537
Karl Schultz6addd812016-02-02 17:17:23 -07004538TEST_F(VkLayerTest, InvalidDescriptorSetLayout) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004539 // Attempt to create a Pipeline Layout with an invalid Descriptor Set Layout.
4540 // ObjectTracker should catch this.
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004541 uint64_t fake_layout_handle = 0xbaad6001;
4542 VkDescriptorSetLayout bad_layout = reinterpret_cast<VkDescriptorSetLayout &>(fake_layout_handle);
Karl Schultzf78bcdd2016-11-30 12:36:01 -07004543 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00875);
Tony Barbour1fa09702017-03-16 12:09:08 -06004544 ASSERT_NO_FATAL_FAILURE(Init());
Karl Schultzbdb75952016-04-19 11:36:49 -06004545 VkPipelineLayout pipeline_layout;
4546 VkPipelineLayoutCreateInfo plci = {};
4547 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4548 plci.pNext = NULL;
4549 plci.setLayoutCount = 1;
4550 plci.pSetLayouts = &bad_layout;
4551 vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
4552
4553 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004554}
4555
Mark Muellerd4914412016-06-13 17:52:06 -06004556TEST_F(VkLayerTest, WriteDescriptorSetIntegrityCheck) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004557 TEST_DESCRIPTION(
4558 "This test verifies some requirements of chapter 13.2.3 of the Vulkan Spec "
4559 "1) A uniform buffer update must have a valid buffer index."
4560 "2) When using an array of descriptors in a single WriteDescriptor,"
4561 " the descriptor types and stageflags must all be the same."
4562 "3) Immutable Sampler state must match across descriptors");
Mark Muellerd4914412016-06-13 17:52:06 -06004563
Mike Weiblena6666382017-01-05 15:16:11 -07004564 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00941);
Mark Muellerd4914412016-06-13 17:52:06 -06004565
Tony Barbour1fa09702017-03-16 12:09:08 -06004566 ASSERT_NO_FATAL_FAILURE(Init());
Mark Muellerd4914412016-06-13 17:52:06 -06004567 VkDescriptorPoolSize ds_type_count[4] = {};
4568 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4569 ds_type_count[0].descriptorCount = 1;
Tony Barboure132c5f2016-12-12 11:50:20 -07004570 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Muellerd4914412016-06-13 17:52:06 -06004571 ds_type_count[1].descriptorCount = 1;
Tony Barboure132c5f2016-12-12 11:50:20 -07004572 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Muellerd4914412016-06-13 17:52:06 -06004573 ds_type_count[2].descriptorCount = 1;
4574 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
4575 ds_type_count[3].descriptorCount = 1;
4576
4577 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4578 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4579 ds_pool_ci.maxSets = 1;
4580 ds_pool_ci.poolSizeCount = sizeof(ds_type_count) / sizeof(VkDescriptorPoolSize);
4581 ds_pool_ci.pPoolSizes = ds_type_count;
4582
4583 VkDescriptorPool ds_pool;
4584 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
4585 ASSERT_VK_SUCCESS(err);
4586
Mark Muellerb9896722016-06-16 09:54:29 -06004587 VkDescriptorSetLayoutBinding layout_binding[3] = {};
Mark Muellerd4914412016-06-13 17:52:06 -06004588 layout_binding[0].binding = 0;
4589 layout_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4590 layout_binding[0].descriptorCount = 1;
4591 layout_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
4592 layout_binding[0].pImmutableSamplers = NULL;
4593
4594 layout_binding[1].binding = 1;
4595 layout_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
4596 layout_binding[1].descriptorCount = 1;
4597 layout_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4598 layout_binding[1].pImmutableSamplers = NULL;
4599
4600 VkSamplerCreateInfo sampler_ci = {};
4601 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
4602 sampler_ci.pNext = NULL;
4603 sampler_ci.magFilter = VK_FILTER_NEAREST;
4604 sampler_ci.minFilter = VK_FILTER_NEAREST;
4605 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
4606 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4607 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4608 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4609 sampler_ci.mipLodBias = 1.0;
4610 sampler_ci.anisotropyEnable = VK_FALSE;
4611 sampler_ci.maxAnisotropy = 1;
4612 sampler_ci.compareEnable = VK_FALSE;
4613 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
4614 sampler_ci.minLod = 1.0;
4615 sampler_ci.maxLod = 1.0;
4616 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
4617 sampler_ci.unnormalizedCoordinates = VK_FALSE;
4618 VkSampler sampler;
4619
4620 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
4621 ASSERT_VK_SUCCESS(err);
4622
4623 layout_binding[2].binding = 2;
4624 layout_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
4625 layout_binding[2].descriptorCount = 1;
4626 layout_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4627 layout_binding[2].pImmutableSamplers = static_cast<VkSampler *>(&sampler);
4628
Mark Muellerd4914412016-06-13 17:52:06 -06004629 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4630 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4631 ds_layout_ci.bindingCount = sizeof(layout_binding) / sizeof(VkDescriptorSetLayoutBinding);
4632 ds_layout_ci.pBindings = layout_binding;
4633 VkDescriptorSetLayout ds_layout;
4634 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
4635 ASSERT_VK_SUCCESS(err);
4636
4637 VkDescriptorSetAllocateInfo alloc_info = {};
4638 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4639 alloc_info.descriptorSetCount = 1;
4640 alloc_info.descriptorPool = ds_pool;
4641 alloc_info.pSetLayouts = &ds_layout;
4642 VkDescriptorSet descriptorSet;
4643 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
4644 ASSERT_VK_SUCCESS(err);
4645
4646 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4647 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4648 pipeline_layout_ci.pNext = NULL;
4649 pipeline_layout_ci.setLayoutCount = 1;
4650 pipeline_layout_ci.pSetLayouts = &ds_layout;
4651
4652 VkPipelineLayout pipeline_layout;
4653 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4654 ASSERT_VK_SUCCESS(err);
4655
Mark Mueller5c838ce2016-06-16 09:54:29 -06004656 VkWriteDescriptorSet descriptor_write = {};
Mark Muellerd4914412016-06-13 17:52:06 -06004657 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4658 descriptor_write.dstSet = descriptorSet;
4659 descriptor_write.dstBinding = 0;
4660 descriptor_write.descriptorCount = 1;
4661 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4662
Mark Mueller5c838ce2016-06-16 09:54:29 -06004663 // 1) The uniform buffer is intentionally invalid here
Mark Muellerd4914412016-06-13 17:52:06 -06004664 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4665 m_errorMonitor->VerifyFound();
4666
4667 // Create a buffer to update the descriptor with
4668 uint32_t qfi = 0;
4669 VkBufferCreateInfo buffCI = {};
4670 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4671 buffCI.size = 1024;
4672 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
4673 buffCI.queueFamilyIndexCount = 1;
4674 buffCI.pQueueFamilyIndices = &qfi;
4675
4676 VkBuffer dyub;
4677 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
4678 ASSERT_VK_SUCCESS(err);
Mark Muellerd4914412016-06-13 17:52:06 -06004679
Tony Barboure132c5f2016-12-12 11:50:20 -07004680 VkDeviceMemory mem;
4681 VkMemoryRequirements mem_reqs;
4682 vkGetBufferMemoryRequirements(m_device->device(), dyub, &mem_reqs);
4683
4684 VkMemoryAllocateInfo mem_alloc_info = {};
4685 mem_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4686 mem_alloc_info.allocationSize = mem_reqs.size;
4687 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
4688 err = vkAllocateMemory(m_device->device(), &mem_alloc_info, NULL, &mem);
4689 ASSERT_VK_SUCCESS(err);
4690
4691 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
4692 ASSERT_VK_SUCCESS(err);
4693
4694 VkDescriptorBufferInfo buffInfo[2] = {};
4695 buffInfo[0].buffer = dyub;
4696 buffInfo[0].offset = 0;
4697 buffInfo[0].range = 1024;
4698 buffInfo[1].buffer = dyub;
4699 buffInfo[1].offset = 0;
4700 buffInfo[1].range = 1024;
4701 descriptor_write.pBufferInfo = buffInfo;
Mark Muellerd4914412016-06-13 17:52:06 -06004702 descriptor_write.descriptorCount = 2;
4703
Mark Mueller5c838ce2016-06-16 09:54:29 -06004704 // 2) The stateFlags don't match between the first and second descriptor
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07004705 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00938);
Mark Muellerd4914412016-06-13 17:52:06 -06004706 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4707 m_errorMonitor->VerifyFound();
4708
Mark Mueller5c838ce2016-06-16 09:54:29 -06004709 // 3) The second descriptor has a null_ptr pImmutableSamplers and
4710 // the third descriptor contains an immutable sampler
Mark Muellerd4914412016-06-13 17:52:06 -06004711 descriptor_write.dstBinding = 1;
4712 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Mueller5c838ce2016-06-16 09:54:29 -06004713
Mark Mueller5c838ce2016-06-16 09:54:29 -06004714 // Make pImageInfo index non-null to avoid complaints of it missing
4715 VkDescriptorImageInfo imageInfo = {};
4716 imageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
4717 descriptor_write.pImageInfo = &imageInfo;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07004718 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00938);
Mark Muellerd4914412016-06-13 17:52:06 -06004719 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4720 m_errorMonitor->VerifyFound();
4721
Mark Muellerd4914412016-06-13 17:52:06 -06004722 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tony Barboure132c5f2016-12-12 11:50:20 -07004723 vkFreeMemory(m_device->device(), mem, NULL);
Mark Muellerd4914412016-06-13 17:52:06 -06004724 vkDestroySampler(m_device->device(), sampler, NULL);
4725 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4726 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4727 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4728}
4729
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004730TEST_F(VkLayerTest, InvalidCmdBufferBufferDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004731 TEST_DESCRIPTION(
4732 "Attempt to draw with a command buffer that is invalid "
4733 "due to a buffer dependency being destroyed.");
Tony Barbour1fa09702017-03-16 12:09:08 -06004734 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004735
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004736 VkBuffer buffer;
4737 VkDeviceMemory mem;
4738 VkMemoryRequirements mem_reqs;
4739
4740 VkBufferCreateInfo buf_info = {};
4741 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes3d5882f2016-09-16 17:37:17 +12004742 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004743 buf_info.size = 256;
4744 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
4745 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
4746 ASSERT_VK_SUCCESS(err);
4747
4748 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
4749
4750 VkMemoryAllocateInfo alloc_info = {};
4751 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4752 alloc_info.allocationSize = 256;
4753 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004754 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 -06004755 if (!pass) {
4756 vkDestroyBuffer(m_device->device(), buffer, NULL);
4757 return;
4758 }
4759 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
4760 ASSERT_VK_SUCCESS(err);
4761
4762 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
4763 ASSERT_VK_SUCCESS(err);
4764
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004765 m_commandBuffer->BeginCommandBuffer();
Chris Forbes3d5882f2016-09-16 17:37:17 +12004766 vkCmdFillBuffer(m_commandBuffer->GetBufferHandle(), buffer, 0, VK_WHOLE_SIZE, 0);
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004767 m_commandBuffer->EndCommandBuffer();
4768
Mark Lobodzinski33826372017-04-13 11:10:11 -06004769 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound Buffer ");
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004770 // Destroy buffer dependency prior to submit to cause ERROR
4771 vkDestroyBuffer(m_device->device(), buffer, NULL);
4772
4773 VkSubmitInfo submit_info = {};
4774 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4775 submit_info.commandBufferCount = 1;
4776 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4777 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4778
4779 m_errorMonitor->VerifyFound();
Rene Lindsayab6c5cd2016-12-20 14:05:37 -07004780 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004781 vkFreeMemory(m_device->handle(), mem, NULL);
4782}
4783
Tobin Ehlisea413442016-09-28 10:23:59 -06004784TEST_F(VkLayerTest, InvalidCmdBufferBufferViewDestroyed) {
4785 TEST_DESCRIPTION("Delete bufferView bound to cmd buffer, then attempt to submit cmd buffer.");
4786
Tony Barbour1fa09702017-03-16 12:09:08 -06004787 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisea413442016-09-28 10:23:59 -06004788 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4789
4790 VkDescriptorPoolSize ds_type_count;
4791 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4792 ds_type_count.descriptorCount = 1;
4793
4794 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4795 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4796 ds_pool_ci.maxSets = 1;
4797 ds_pool_ci.poolSizeCount = 1;
4798 ds_pool_ci.pPoolSizes = &ds_type_count;
4799
4800 VkDescriptorPool ds_pool;
4801 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
4802 ASSERT_VK_SUCCESS(err);
4803
4804 VkDescriptorSetLayoutBinding layout_binding;
4805 layout_binding.binding = 0;
4806 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4807 layout_binding.descriptorCount = 1;
4808 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4809 layout_binding.pImmutableSamplers = NULL;
4810
4811 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4812 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4813 ds_layout_ci.bindingCount = 1;
4814 ds_layout_ci.pBindings = &layout_binding;
4815 VkDescriptorSetLayout ds_layout;
4816 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
4817 ASSERT_VK_SUCCESS(err);
4818
4819 VkDescriptorSetAllocateInfo alloc_info = {};
4820 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4821 alloc_info.descriptorSetCount = 1;
4822 alloc_info.descriptorPool = ds_pool;
4823 alloc_info.pSetLayouts = &ds_layout;
4824 VkDescriptorSet descriptor_set;
4825 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
4826 ASSERT_VK_SUCCESS(err);
4827
4828 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4829 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4830 pipeline_layout_ci.pNext = NULL;
4831 pipeline_layout_ci.setLayoutCount = 1;
4832 pipeline_layout_ci.pSetLayouts = &ds_layout;
4833
4834 VkPipelineLayout pipeline_layout;
4835 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4836 ASSERT_VK_SUCCESS(err);
4837
4838 VkBuffer buffer;
4839 uint32_t queue_family_index = 0;
4840 VkBufferCreateInfo buffer_create_info = {};
4841 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4842 buffer_create_info.size = 1024;
4843 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
4844 buffer_create_info.queueFamilyIndexCount = 1;
4845 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
4846
4847 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
4848 ASSERT_VK_SUCCESS(err);
4849
4850 VkMemoryRequirements memory_reqs;
4851 VkDeviceMemory buffer_memory;
4852
4853 VkMemoryAllocateInfo memory_info = {};
4854 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4855 memory_info.allocationSize = 0;
4856 memory_info.memoryTypeIndex = 0;
4857
4858 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
4859 memory_info.allocationSize = memory_reqs.size;
4860 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
4861 ASSERT_TRUE(pass);
4862
4863 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
4864 ASSERT_VK_SUCCESS(err);
4865 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
4866 ASSERT_VK_SUCCESS(err);
4867
4868 VkBufferView view;
4869 VkBufferViewCreateInfo bvci = {};
4870 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
4871 bvci.buffer = buffer;
Tobin Ehliscc980e12017-05-19 12:05:49 -06004872 bvci.format = VK_FORMAT_R32_SFLOAT;
Tobin Ehlisea413442016-09-28 10:23:59 -06004873 bvci.range = VK_WHOLE_SIZE;
4874
4875 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
4876 ASSERT_VK_SUCCESS(err);
4877
4878 VkWriteDescriptorSet descriptor_write = {};
4879 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4880 descriptor_write.dstSet = descriptor_set;
4881 descriptor_write.dstBinding = 0;
4882 descriptor_write.descriptorCount = 1;
4883 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4884 descriptor_write.pTexelBufferView = &view;
4885
4886 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4887
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004888 char const *vsSource =
4889 "#version 450\n"
4890 "\n"
4891 "out gl_PerVertex { \n"
4892 " vec4 gl_Position;\n"
4893 "};\n"
4894 "void main(){\n"
4895 " gl_Position = vec4(1);\n"
4896 "}\n";
4897 char const *fsSource =
4898 "#version 450\n"
4899 "\n"
Tobin Ehliscc980e12017-05-19 12:05:49 -06004900 "layout(set=0, binding=0, r32f) uniform imageBuffer s;\n"
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004901 "layout(location=0) out vec4 x;\n"
4902 "void main(){\n"
4903 " x = imageLoad(s, 0);\n"
4904 "}\n";
Tobin Ehlisea413442016-09-28 10:23:59 -06004905 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4906 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
4907 VkPipelineObj pipe(m_device);
4908 pipe.AddShader(&vs);
4909 pipe.AddShader(&fs);
4910 pipe.AddColorAttachment();
4911 pipe.CreateVKPipeline(pipeline_layout, renderPass());
4912
Mark Lobodzinski33826372017-04-13 11:10:11 -06004913 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound BufferView ");
Tobin Ehlisea413442016-09-28 10:23:59 -06004914
Tony Barbour552f6c02016-12-21 14:34:07 -07004915 m_commandBuffer->BeginCommandBuffer();
4916 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
4917
Tobin Ehlisea413442016-09-28 10:23:59 -06004918 VkViewport viewport = {0, 0, 16, 16, 0, 1};
4919 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
4920 VkRect2D scissor = {{0, 0}, {16, 16}};
4921 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
4922 // Bind pipeline to cmd buffer
4923 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
4924 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
4925 &descriptor_set, 0, nullptr);
4926 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07004927 m_commandBuffer->EndRenderPass();
4928 m_commandBuffer->EndCommandBuffer();
Tobin Ehlisea413442016-09-28 10:23:59 -06004929
4930 // Delete BufferView in order to invalidate cmd buffer
4931 vkDestroyBufferView(m_device->device(), view, NULL);
4932 // Now attempt submit of cmd buffer
4933 VkSubmitInfo submit_info = {};
4934 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4935 submit_info.commandBufferCount = 1;
4936 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4937 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4938 m_errorMonitor->VerifyFound();
4939
4940 // Clean-up
4941 vkDestroyBuffer(m_device->device(), buffer, NULL);
4942 vkFreeMemory(m_device->device(), buffer_memory, NULL);
4943 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4944 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4945 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4946}
4947
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004948TEST_F(VkLayerTest, InvalidCmdBufferImageDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004949 TEST_DESCRIPTION(
4950 "Attempt to draw with a command buffer that is invalid "
4951 "due to an image dependency being destroyed.");
Tony Barbour1fa09702017-03-16 12:09:08 -06004952 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004953
4954 VkImage image;
4955 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4956 VkImageCreateInfo image_create_info = {};
4957 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4958 image_create_info.pNext = NULL;
4959 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4960 image_create_info.format = tex_format;
4961 image_create_info.extent.width = 32;
4962 image_create_info.extent.height = 32;
4963 image_create_info.extent.depth = 1;
4964 image_create_info.mipLevels = 1;
4965 image_create_info.arrayLayers = 1;
4966 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
4967 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004968 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004969 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004970 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004971 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004972 // Have to bind memory to image before recording cmd in cmd buffer using it
4973 VkMemoryRequirements mem_reqs;
4974 VkDeviceMemory image_mem;
4975 bool pass;
4976 VkMemoryAllocateInfo mem_alloc = {};
4977 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4978 mem_alloc.pNext = NULL;
4979 mem_alloc.memoryTypeIndex = 0;
4980 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
4981 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004982 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004983 ASSERT_TRUE(pass);
4984 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
4985 ASSERT_VK_SUCCESS(err);
4986 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
4987 ASSERT_VK_SUCCESS(err);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004988
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004989 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis764d7072016-07-01 12:54:29 -06004990 VkClearColorValue ccv;
4991 ccv.float32[0] = 1.0f;
4992 ccv.float32[1] = 1.0f;
4993 ccv.float32[2] = 1.0f;
4994 ccv.float32[3] = 1.0f;
4995 VkImageSubresourceRange isr = {};
4996 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004997 isr.baseArrayLayer = 0;
4998 isr.baseMipLevel = 0;
Tobin Ehlis764d7072016-07-01 12:54:29 -06004999 isr.layerCount = 1;
5000 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005001 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06005002 m_commandBuffer->EndCommandBuffer();
5003
Mark Lobodzinski33826372017-04-13 11:10:11 -06005004 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound Image ");
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06005005 // Destroy image dependency prior to submit to cause ERROR
5006 vkDestroyImage(m_device->device(), image, NULL);
5007
5008 VkSubmitInfo submit_info = {};
5009 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5010 submit_info.commandBufferCount = 1;
5011 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5012 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5013
5014 m_errorMonitor->VerifyFound();
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06005015 vkFreeMemory(m_device->device(), image_mem, nullptr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06005016}
5017
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005018TEST_F(VkLayerTest, InvalidCmdBufferFramebufferImageDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005019 TEST_DESCRIPTION(
5020 "Attempt to draw with a command buffer that is invalid "
5021 "due to a framebuffer image dependency being destroyed.");
Tony Barbour1fa09702017-03-16 12:09:08 -06005022 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005023 VkFormatProperties format_properties;
5024 VkResult err = VK_SUCCESS;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005025 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
5026 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005027 return;
5028 }
5029
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005030 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5031
5032 VkImageCreateInfo image_ci = {};
5033 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5034 image_ci.pNext = NULL;
5035 image_ci.imageType = VK_IMAGE_TYPE_2D;
5036 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
5037 image_ci.extent.width = 32;
5038 image_ci.extent.height = 32;
5039 image_ci.extent.depth = 1;
5040 image_ci.mipLevels = 1;
5041 image_ci.arrayLayers = 1;
5042 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
5043 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005044 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT;
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005045 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
5046 image_ci.flags = 0;
5047 VkImage image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005048 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005049
5050 VkMemoryRequirements memory_reqs;
5051 VkDeviceMemory image_memory;
5052 bool pass;
5053 VkMemoryAllocateInfo memory_info = {};
5054 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5055 memory_info.pNext = NULL;
5056 memory_info.allocationSize = 0;
5057 memory_info.memoryTypeIndex = 0;
5058 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5059 memory_info.allocationSize = memory_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005060 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005061 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005062 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005063 ASSERT_VK_SUCCESS(err);
5064 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5065 ASSERT_VK_SUCCESS(err);
5066
5067 VkImageViewCreateInfo ivci = {
5068 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
5069 nullptr,
5070 0,
5071 image,
5072 VK_IMAGE_VIEW_TYPE_2D,
5073 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005074 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005075 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
5076 };
5077 VkImageView view;
5078 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
5079 ASSERT_VK_SUCCESS(err);
5080
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005081 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 32, 32, 1};
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005082 VkFramebuffer fb;
5083 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
5084 ASSERT_VK_SUCCESS(err);
5085
5086 // Just use default renderpass with our framebuffer
5087 m_renderPassBeginInfo.framebuffer = fb;
Jeremy Hayesba817e12017-03-03 15:51:11 -07005088 m_renderPassBeginInfo.renderArea.extent.width = 32;
5089 m_renderPassBeginInfo.renderArea.extent.height = 32;
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005090 // Create Null cmd buffer for submit
Tony Barbour552f6c02016-12-21 14:34:07 -07005091 m_commandBuffer->BeginCommandBuffer();
5092 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
5093 m_commandBuffer->EndRenderPass();
5094 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005095 // Destroy image attached to framebuffer to invalidate cmd buffer
5096 vkDestroyImage(m_device->device(), image, NULL);
5097 // Now attempt to submit cmd buffer and verify error
Mark Lobodzinski33826372017-04-13 11:10:11 -06005098 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound Image ");
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005099 QueueCommandBuffer(false);
5100 m_errorMonitor->VerifyFound();
5101
5102 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
5103 vkDestroyImageView(m_device->device(), view, nullptr);
5104 vkFreeMemory(m_device->device(), image_memory, nullptr);
5105}
5106
Tobin Ehlisb329f992016-10-12 13:20:29 -06005107TEST_F(VkLayerTest, FramebufferInUseDestroyedSignaled) {
5108 TEST_DESCRIPTION("Delete in-use framebuffer.");
Tony Barbour1fa09702017-03-16 12:09:08 -06005109 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisb329f992016-10-12 13:20:29 -06005110 VkFormatProperties format_properties;
5111 VkResult err = VK_SUCCESS;
5112 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
5113
Tobin Ehlisb329f992016-10-12 13:20:29 -06005114 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5115
5116 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06005117 image.Init(256, 256, 1, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Tobin Ehlisb329f992016-10-12 13:20:29 -06005118 ASSERT_TRUE(image.initialized());
5119 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
5120
5121 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
5122 VkFramebuffer fb;
5123 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
5124 ASSERT_VK_SUCCESS(err);
5125
5126 // Just use default renderpass with our framebuffer
5127 m_renderPassBeginInfo.framebuffer = fb;
5128 // Create Null cmd buffer for submit
Tony Barbour552f6c02016-12-21 14:34:07 -07005129 m_commandBuffer->BeginCommandBuffer();
5130 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
5131 m_commandBuffer->EndRenderPass();
5132 m_commandBuffer->EndCommandBuffer();
Tobin Ehlisb329f992016-10-12 13:20:29 -06005133 // Submit cmd buffer to put it in-flight
5134 VkSubmitInfo submit_info = {};
5135 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5136 submit_info.commandBufferCount = 1;
5137 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5138 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5139 // Destroy framebuffer while in-flight
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07005140 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00422);
Tobin Ehlisb329f992016-10-12 13:20:29 -06005141 vkDestroyFramebuffer(m_device->device(), fb, NULL);
5142 m_errorMonitor->VerifyFound();
5143 // Wait for queue to complete so we can safely destroy everything
5144 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005145 m_errorMonitor->SetUnexpectedError("If framebuffer is not VK_NULL_HANDLE, framebuffer must be a valid VkFramebuffer handle");
5146 m_errorMonitor->SetUnexpectedError("Unable to remove Framebuffer obj");
Tobin Ehlisb329f992016-10-12 13:20:29 -06005147 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
5148}
5149
Tobin Ehlis88becd72016-09-21 14:33:41 -06005150TEST_F(VkLayerTest, FramebufferImageInUseDestroyedSignaled) {
5151 TEST_DESCRIPTION("Delete in-use image that's child of framebuffer.");
Tony Barbour1fa09702017-03-16 12:09:08 -06005152 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis88becd72016-09-21 14:33:41 -06005153 VkFormatProperties format_properties;
5154 VkResult err = VK_SUCCESS;
5155 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
Tobin Ehlis88becd72016-09-21 14:33:41 -06005156
Tobin Ehlis88becd72016-09-21 14:33:41 -06005157 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5158
5159 VkImageCreateInfo image_ci = {};
5160 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5161 image_ci.pNext = NULL;
5162 image_ci.imageType = VK_IMAGE_TYPE_2D;
5163 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
5164 image_ci.extent.width = 256;
5165 image_ci.extent.height = 256;
5166 image_ci.extent.depth = 1;
5167 image_ci.mipLevels = 1;
5168 image_ci.arrayLayers = 1;
5169 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
5170 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisc8ca0312016-09-22 07:30:05 -06005171 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Tobin Ehlis88becd72016-09-21 14:33:41 -06005172 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
5173 image_ci.flags = 0;
5174 VkImage image;
5175 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
5176
5177 VkMemoryRequirements memory_reqs;
5178 VkDeviceMemory image_memory;
5179 bool pass;
5180 VkMemoryAllocateInfo memory_info = {};
5181 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5182 memory_info.pNext = NULL;
5183 memory_info.allocationSize = 0;
5184 memory_info.memoryTypeIndex = 0;
5185 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5186 memory_info.allocationSize = memory_reqs.size;
5187 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
5188 ASSERT_TRUE(pass);
5189 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
5190 ASSERT_VK_SUCCESS(err);
5191 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5192 ASSERT_VK_SUCCESS(err);
5193
5194 VkImageViewCreateInfo ivci = {
5195 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
5196 nullptr,
5197 0,
5198 image,
5199 VK_IMAGE_VIEW_TYPE_2D,
5200 VK_FORMAT_B8G8R8A8_UNORM,
5201 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
5202 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
5203 };
5204 VkImageView view;
5205 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
5206 ASSERT_VK_SUCCESS(err);
5207
5208 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
5209 VkFramebuffer fb;
5210 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
5211 ASSERT_VK_SUCCESS(err);
5212
5213 // Just use default renderpass with our framebuffer
5214 m_renderPassBeginInfo.framebuffer = fb;
5215 // Create Null cmd buffer for submit
Tony Barbour552f6c02016-12-21 14:34:07 -07005216 m_commandBuffer->BeginCommandBuffer();
5217 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
5218 m_commandBuffer->EndRenderPass();
5219 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis88becd72016-09-21 14:33:41 -06005220 // Submit cmd buffer to put it (and attached imageView) in-flight
5221 VkSubmitInfo submit_info = {};
5222 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5223 submit_info.commandBufferCount = 1;
5224 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5225 // Submit cmd buffer to put framebuffer and children in-flight
5226 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5227 // Destroy image attached to framebuffer while in-flight
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07005228 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00743);
Tobin Ehlis88becd72016-09-21 14:33:41 -06005229 vkDestroyImage(m_device->device(), image, NULL);
5230 m_errorMonitor->VerifyFound();
5231 // Wait for queue to complete so we can safely destroy image and other objects
5232 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005233 m_errorMonitor->SetUnexpectedError("If image is not VK_NULL_HANDLE, image must be a valid VkImage handle");
5234 m_errorMonitor->SetUnexpectedError("Unable to remove Image obj");
Tobin Ehlis88becd72016-09-21 14:33:41 -06005235 vkDestroyImage(m_device->device(), image, NULL);
5236 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
5237 vkDestroyImageView(m_device->device(), view, nullptr);
5238 vkFreeMemory(m_device->device(), image_memory, nullptr);
5239}
5240
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005241TEST_F(VkLayerTest, RenderPassInUseDestroyedSignaled) {
5242 TEST_DESCRIPTION("Delete in-use renderPass.");
5243
Tony Barbour1fa09702017-03-16 12:09:08 -06005244 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005245 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5246
5247 // Create simple renderpass
5248 VkAttachmentReference attach = {};
5249 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
5250 VkSubpassDescription subpass = {};
Dave Houlton756e6742017-03-23 14:33:22 -06005251 subpass.colorAttachmentCount = 1;
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005252 subpass.pColorAttachments = &attach;
5253 VkRenderPassCreateInfo rpci = {};
5254 rpci.subpassCount = 1;
5255 rpci.pSubpasses = &subpass;
5256 rpci.attachmentCount = 1;
5257 VkAttachmentDescription attach_desc = {};
5258 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
5259 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
5260 rpci.pAttachments = &attach_desc;
5261 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
5262 VkRenderPass rp;
5263 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
5264 ASSERT_VK_SUCCESS(err);
5265
5266 // Create a pipeline that uses the given renderpass
5267 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5268 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5269
5270 VkPipelineLayout pipeline_layout;
5271 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
5272 ASSERT_VK_SUCCESS(err);
5273
5274 VkPipelineViewportStateCreateInfo vp_state_ci = {};
5275 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
5276 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005277 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005278 vp_state_ci.pViewports = &vp;
5279 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005280 VkRect2D scissors = {}; // Dummy scissors to point to
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005281 vp_state_ci.pScissors = &scissors;
5282
5283 VkPipelineShaderStageCreateInfo shaderStages[2];
5284 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
5285
5286 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005287 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005288 // but add it to be able to run on more devices
5289 shaderStages[0] = vs.GetStageCreateInfo();
5290 shaderStages[1] = fs.GetStageCreateInfo();
5291
5292 VkPipelineVertexInputStateCreateInfo vi_ci = {};
5293 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
5294
5295 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
5296 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
5297 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
5298
5299 VkPipelineRasterizationStateCreateInfo rs_ci = {};
5300 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
5301 rs_ci.rasterizerDiscardEnable = true;
5302 rs_ci.lineWidth = 1.0f;
5303
5304 VkPipelineColorBlendAttachmentState att = {};
5305 att.blendEnable = VK_FALSE;
5306 att.colorWriteMask = 0xf;
5307
5308 VkPipelineColorBlendStateCreateInfo cb_ci = {};
5309 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
5310 cb_ci.attachmentCount = 1;
5311 cb_ci.pAttachments = &att;
5312
5313 VkGraphicsPipelineCreateInfo gp_ci = {};
5314 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
5315 gp_ci.stageCount = 2;
5316 gp_ci.pStages = shaderStages;
5317 gp_ci.pVertexInputState = &vi_ci;
5318 gp_ci.pInputAssemblyState = &ia_ci;
5319 gp_ci.pViewportState = &vp_state_ci;
5320 gp_ci.pRasterizationState = &rs_ci;
5321 gp_ci.pColorBlendState = &cb_ci;
5322 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
5323 gp_ci.layout = pipeline_layout;
5324 gp_ci.renderPass = rp;
5325
5326 VkPipelineCacheCreateInfo pc_ci = {};
5327 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
5328
Dave Houlton756e6742017-03-23 14:33:22 -06005329 m_errorMonitor->ExpectSuccess();
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005330 VkPipeline pipeline;
5331 VkPipelineCache pipe_cache;
5332 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipe_cache);
5333 ASSERT_VK_SUCCESS(err);
5334
5335 err = vkCreateGraphicsPipelines(m_device->device(), pipe_cache, 1, &gp_ci, NULL, &pipeline);
5336 ASSERT_VK_SUCCESS(err);
Dave Houlton756e6742017-03-23 14:33:22 -06005337
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005338 // Bind pipeline to cmd buffer, will also bind renderpass
5339 m_commandBuffer->BeginCommandBuffer();
5340 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
5341 m_commandBuffer->EndCommandBuffer();
5342
5343 VkSubmitInfo submit_info = {};
5344 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5345 submit_info.commandBufferCount = 1;
5346 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5347 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Dave Houlton756e6742017-03-23 14:33:22 -06005348 m_errorMonitor->VerifyNotFound();
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005349
5350 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00393);
5351 vkDestroyRenderPass(m_device->device(), rp, nullptr);
5352 m_errorMonitor->VerifyFound();
5353
5354 // Wait for queue to complete so we can safely destroy everything
5355 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005356 m_errorMonitor->SetUnexpectedError("If renderPass is not VK_NULL_HANDLE, renderPass must be a valid VkRenderPass handle");
Mark Lobodzinski74597792017-04-11 15:43:49 -06005357 m_errorMonitor->SetUnexpectedError("Unable to remove RenderPass obj");
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005358 vkDestroyRenderPass(m_device->device(), rp, nullptr);
5359 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
5360 vkDestroyPipelineCache(m_device->device(), pipe_cache, nullptr);
5361 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
5362}
5363
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005364TEST_F(VkLayerTest, ImageMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005365 TEST_DESCRIPTION("Attempt to draw with an image which has not had memory bound to it.");
Tony Barbour1fa09702017-03-16 12:09:08 -06005366 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005367
5368 VkImage image;
5369 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5370 VkImageCreateInfo image_create_info = {};
5371 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5372 image_create_info.pNext = NULL;
5373 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5374 image_create_info.format = tex_format;
5375 image_create_info.extent.width = 32;
5376 image_create_info.extent.height = 32;
5377 image_create_info.extent.depth = 1;
5378 image_create_info.mipLevels = 1;
5379 image_create_info.arrayLayers = 1;
5380 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5381 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005382 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005383 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005384 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005385 ASSERT_VK_SUCCESS(err);
5386 // Have to bind memory to image before recording cmd in cmd buffer using it
5387 VkMemoryRequirements mem_reqs;
5388 VkDeviceMemory image_mem;
5389 bool pass;
5390 VkMemoryAllocateInfo mem_alloc = {};
5391 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5392 mem_alloc.pNext = NULL;
5393 mem_alloc.memoryTypeIndex = 0;
5394 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
5395 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005396 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005397 ASSERT_TRUE(pass);
5398 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
5399 ASSERT_VK_SUCCESS(err);
5400
Tobin Ehlisfed999f2016-09-21 15:09:45 -06005401 // Introduce error, do not call vkBindImageMemory(m_device->device(), image, image_mem, 0);
5402 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005403 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005404
5405 m_commandBuffer->BeginCommandBuffer();
5406 VkClearColorValue ccv;
5407 ccv.float32[0] = 1.0f;
5408 ccv.float32[1] = 1.0f;
5409 ccv.float32[2] = 1.0f;
5410 ccv.float32[3] = 1.0f;
5411 VkImageSubresourceRange isr = {};
5412 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
5413 isr.baseArrayLayer = 0;
5414 isr.baseMipLevel = 0;
5415 isr.layerCount = 1;
5416 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005417 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005418 m_commandBuffer->EndCommandBuffer();
5419
5420 m_errorMonitor->VerifyFound();
5421 vkDestroyImage(m_device->device(), image, NULL);
5422 vkFreeMemory(m_device->device(), image_mem, nullptr);
5423}
5424
5425TEST_F(VkLayerTest, BufferMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005426 TEST_DESCRIPTION("Attempt to copy from a buffer which has not had memory bound to it.");
Tony Barbour1fa09702017-03-16 12:09:08 -06005427 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005428
5429 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06005430 image.Init(128, 128, 1, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005431 VK_IMAGE_TILING_OPTIMAL, 0);
5432 ASSERT_TRUE(image.initialized());
5433
5434 VkBuffer buffer;
5435 VkDeviceMemory mem;
5436 VkMemoryRequirements mem_reqs;
5437
5438 VkBufferCreateInfo buf_info = {};
5439 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes8d260dd2016-09-16 17:42:42 +12005440 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski80871462017-02-16 10:37:27 -07005441 buf_info.size = 1024;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005442 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
5443 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
5444 ASSERT_VK_SUCCESS(err);
5445
5446 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
5447
5448 VkMemoryAllocateInfo alloc_info = {};
5449 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Mark Lobodzinski80871462017-02-16 10:37:27 -07005450 alloc_info.allocationSize = 1024;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005451 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005452 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 -06005453 if (!pass) {
5454 vkDestroyBuffer(m_device->device(), buffer, NULL);
5455 return;
5456 }
5457 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
5458 ASSERT_VK_SUCCESS(err);
5459
Tobin Ehlisfed999f2016-09-21 15:09:45 -06005460 // Introduce failure by not calling vkBindBufferMemory(m_device->device(), buffer, mem, 0);
5461 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005462 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005463 VkBufferImageCopy region = {};
Mark Lobodzinski80871462017-02-16 10:37:27 -07005464 region.bufferRowLength = 16;
5465 region.bufferImageHeight = 16;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005466 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
5467
5468 region.imageSubresource.layerCount = 1;
5469 region.imageExtent.height = 4;
5470 region.imageExtent.width = 4;
5471 region.imageExtent.depth = 1;
5472 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005473 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer, image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
5474 &region);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005475 m_commandBuffer->EndCommandBuffer();
5476
5477 m_errorMonitor->VerifyFound();
5478
5479 vkDestroyBuffer(m_device->device(), buffer, NULL);
5480 vkFreeMemory(m_device->handle(), mem, NULL);
5481}
5482
Tobin Ehlis85940f52016-07-07 16:57:21 -06005483TEST_F(VkLayerTest, InvalidCmdBufferEventDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005484 TEST_DESCRIPTION(
5485 "Attempt to draw with a command buffer that is invalid "
5486 "due to an event dependency being destroyed.");
Tony Barbour1fa09702017-03-16 12:09:08 -06005487 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis85940f52016-07-07 16:57:21 -06005488
5489 VkEvent event;
5490 VkEventCreateInfo evci = {};
5491 evci.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
5492 VkResult result = vkCreateEvent(m_device->device(), &evci, NULL, &event);
5493 ASSERT_VK_SUCCESS(result);
5494
5495 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005496 vkCmdSetEvent(m_commandBuffer->GetBufferHandle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Tobin Ehlis85940f52016-07-07 16:57:21 -06005497 m_commandBuffer->EndCommandBuffer();
5498
Mark Lobodzinski33826372017-04-13 11:10:11 -06005499 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound Event ");
Tobin Ehlis85940f52016-07-07 16:57:21 -06005500 // Destroy event dependency prior to submit to cause ERROR
5501 vkDestroyEvent(m_device->device(), event, NULL);
5502
5503 VkSubmitInfo submit_info = {};
5504 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5505 submit_info.commandBufferCount = 1;
5506 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5507 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5508
5509 m_errorMonitor->VerifyFound();
5510}
5511
Tobin Ehlisdbea7552016-07-08 14:33:31 -06005512TEST_F(VkLayerTest, InvalidCmdBufferQueryPoolDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005513 TEST_DESCRIPTION(
5514 "Attempt to draw with a command buffer that is invalid "
5515 "due to a query pool dependency being destroyed.");
Tony Barbour1fa09702017-03-16 12:09:08 -06005516 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisdbea7552016-07-08 14:33:31 -06005517
5518 VkQueryPool query_pool;
5519 VkQueryPoolCreateInfo qpci{};
5520 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
5521 qpci.queryType = VK_QUERY_TYPE_TIMESTAMP;
5522 qpci.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005523 VkResult result = vkCreateQueryPool(m_device->device(), &qpci, nullptr, &query_pool);
Tobin Ehlisdbea7552016-07-08 14:33:31 -06005524 ASSERT_VK_SUCCESS(result);
5525
5526 m_commandBuffer->BeginCommandBuffer();
5527 vkCmdResetQueryPool(m_commandBuffer->GetBufferHandle(), query_pool, 0, 1);
5528 m_commandBuffer->EndCommandBuffer();
5529
Mark Lobodzinski33826372017-04-13 11:10:11 -06005530 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound QueryPool ");
Tobin Ehlisdbea7552016-07-08 14:33:31 -06005531 // Destroy query pool dependency prior to submit to cause ERROR
5532 vkDestroyQueryPool(m_device->device(), query_pool, NULL);
5533
5534 VkSubmitInfo submit_info = {};
5535 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5536 submit_info.commandBufferCount = 1;
5537 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5538 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5539
5540 m_errorMonitor->VerifyFound();
5541}
5542
Tobin Ehlis24130d92016-07-08 15:50:53 -06005543TEST_F(VkLayerTest, InvalidCmdBufferPipelineDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005544 TEST_DESCRIPTION(
5545 "Attempt to draw with a command buffer that is invalid "
5546 "due to a pipeline dependency being destroyed.");
Tony Barbour1fa09702017-03-16 12:09:08 -06005547 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis24130d92016-07-08 15:50:53 -06005548 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5549
5550 VkResult err;
5551
5552 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5553 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5554
5555 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005556 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis24130d92016-07-08 15:50:53 -06005557 ASSERT_VK_SUCCESS(err);
5558
5559 VkPipelineViewportStateCreateInfo vp_state_ci = {};
5560 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
5561 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005562 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -06005563 vp_state_ci.pViewports = &vp;
Tobin Ehlis24130d92016-07-08 15:50:53 -06005564 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005565 VkRect2D scissors = {}; // Dummy scissors to point to
Tobin Ehlis24130d92016-07-08 15:50:53 -06005566 vp_state_ci.pScissors = &scissors;
Tobin Ehlis24130d92016-07-08 15:50:53 -06005567
5568 VkPipelineShaderStageCreateInfo shaderStages[2];
5569 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
5570
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005571 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005572 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005573 // but add it to be able to run on more devices
Tobin Ehlis24130d92016-07-08 15:50:53 -06005574 shaderStages[0] = vs.GetStageCreateInfo();
5575 shaderStages[1] = fs.GetStageCreateInfo();
5576
5577 VkPipelineVertexInputStateCreateInfo vi_ci = {};
5578 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
5579
5580 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
5581 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
5582 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
5583
5584 VkPipelineRasterizationStateCreateInfo rs_ci = {};
5585 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbese06ba252016-09-16 17:48:53 +12005586 rs_ci.rasterizerDiscardEnable = true;
5587 rs_ci.lineWidth = 1.0f;
Tobin Ehlis24130d92016-07-08 15:50:53 -06005588
5589 VkPipelineColorBlendAttachmentState att = {};
5590 att.blendEnable = VK_FALSE;
5591 att.colorWriteMask = 0xf;
5592
5593 VkPipelineColorBlendStateCreateInfo cb_ci = {};
5594 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
5595 cb_ci.attachmentCount = 1;
5596 cb_ci.pAttachments = &att;
5597
5598 VkGraphicsPipelineCreateInfo gp_ci = {};
5599 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
5600 gp_ci.stageCount = 2;
5601 gp_ci.pStages = shaderStages;
5602 gp_ci.pVertexInputState = &vi_ci;
5603 gp_ci.pInputAssemblyState = &ia_ci;
5604 gp_ci.pViewportState = &vp_state_ci;
5605 gp_ci.pRasterizationState = &rs_ci;
5606 gp_ci.pColorBlendState = &cb_ci;
Tobin Ehlis24130d92016-07-08 15:50:53 -06005607 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
5608 gp_ci.layout = pipeline_layout;
5609 gp_ci.renderPass = renderPass();
5610
5611 VkPipelineCacheCreateInfo pc_ci = {};
5612 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
5613
5614 VkPipeline pipeline;
5615 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005616 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis24130d92016-07-08 15:50:53 -06005617 ASSERT_VK_SUCCESS(err);
5618
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005619 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06005620 ASSERT_VK_SUCCESS(err);
5621
5622 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005623 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06005624 m_commandBuffer->EndCommandBuffer();
5625 // Now destroy pipeline in order to cause error when submitting
5626 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
5627
Mark Lobodzinski33826372017-04-13 11:10:11 -06005628 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound Pipeline ");
Tobin Ehlis24130d92016-07-08 15:50:53 -06005629
5630 VkSubmitInfo submit_info = {};
5631 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5632 submit_info.commandBufferCount = 1;
5633 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5634 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5635
5636 m_errorMonitor->VerifyFound();
5637 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
5638 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5639}
5640
Tobin Ehlis31289162016-08-17 14:57:58 -06005641TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetBufferDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005642 TEST_DESCRIPTION(
5643 "Attempt to draw with a command buffer that is invalid "
5644 "due to a bound descriptor set with a buffer dependency "
5645 "being destroyed.");
Tony Barbour1fa09702017-03-16 12:09:08 -06005646 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis31289162016-08-17 14:57:58 -06005647 ASSERT_NO_FATAL_FAILURE(InitViewport());
5648 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5649
5650 VkDescriptorPoolSize ds_type_count = {};
5651 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5652 ds_type_count.descriptorCount = 1;
5653
5654 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5655 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5656 ds_pool_ci.pNext = NULL;
5657 ds_pool_ci.maxSets = 1;
5658 ds_pool_ci.poolSizeCount = 1;
5659 ds_pool_ci.pPoolSizes = &ds_type_count;
5660
5661 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005662 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis31289162016-08-17 14:57:58 -06005663 ASSERT_VK_SUCCESS(err);
5664
5665 VkDescriptorSetLayoutBinding dsl_binding = {};
5666 dsl_binding.binding = 0;
5667 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5668 dsl_binding.descriptorCount = 1;
5669 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5670 dsl_binding.pImmutableSamplers = NULL;
5671
5672 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5673 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5674 ds_layout_ci.pNext = NULL;
5675 ds_layout_ci.bindingCount = 1;
5676 ds_layout_ci.pBindings = &dsl_binding;
5677 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005678 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06005679 ASSERT_VK_SUCCESS(err);
5680
5681 VkDescriptorSet descriptorSet;
5682 VkDescriptorSetAllocateInfo alloc_info = {};
5683 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5684 alloc_info.descriptorSetCount = 1;
5685 alloc_info.descriptorPool = ds_pool;
5686 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005687 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis31289162016-08-17 14:57:58 -06005688 ASSERT_VK_SUCCESS(err);
5689
5690 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5691 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5692 pipeline_layout_ci.pNext = NULL;
5693 pipeline_layout_ci.setLayoutCount = 1;
5694 pipeline_layout_ci.pSetLayouts = &ds_layout;
5695
5696 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005697 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06005698 ASSERT_VK_SUCCESS(err);
5699
5700 // Create a buffer to update the descriptor with
5701 uint32_t qfi = 0;
5702 VkBufferCreateInfo buffCI = {};
5703 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
5704 buffCI.size = 1024;
5705 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
5706 buffCI.queueFamilyIndexCount = 1;
5707 buffCI.pQueueFamilyIndices = &qfi;
5708
5709 VkBuffer buffer;
5710 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &buffer);
5711 ASSERT_VK_SUCCESS(err);
5712 // Allocate memory and bind to buffer so we can make it to the appropriate
5713 // error
5714 VkMemoryAllocateInfo mem_alloc = {};
5715 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5716 mem_alloc.pNext = NULL;
5717 mem_alloc.allocationSize = 1024;
5718 mem_alloc.memoryTypeIndex = 0;
5719
5720 VkMemoryRequirements memReqs;
5721 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005722 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis31289162016-08-17 14:57:58 -06005723 if (!pass) {
5724 vkDestroyBuffer(m_device->device(), buffer, NULL);
5725 return;
5726 }
5727
5728 VkDeviceMemory mem;
5729 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
5730 ASSERT_VK_SUCCESS(err);
5731 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
5732 ASSERT_VK_SUCCESS(err);
5733 // Correctly update descriptor to avoid "NOT_UPDATED" error
5734 VkDescriptorBufferInfo buffInfo = {};
5735 buffInfo.buffer = buffer;
5736 buffInfo.offset = 0;
5737 buffInfo.range = 1024;
5738
5739 VkWriteDescriptorSet descriptor_write;
5740 memset(&descriptor_write, 0, sizeof(descriptor_write));
5741 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5742 descriptor_write.dstSet = descriptorSet;
5743 descriptor_write.dstBinding = 0;
5744 descriptor_write.descriptorCount = 1;
5745 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5746 descriptor_write.pBufferInfo = &buffInfo;
5747
5748 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5749
5750 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005751 char const *vsSource =
5752 "#version 450\n"
5753 "\n"
5754 "out gl_PerVertex { \n"
5755 " vec4 gl_Position;\n"
5756 "};\n"
5757 "void main(){\n"
5758 " gl_Position = vec4(1);\n"
5759 "}\n";
5760 char const *fsSource =
5761 "#version 450\n"
5762 "\n"
5763 "layout(location=0) out vec4 x;\n"
5764 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
5765 "void main(){\n"
5766 " x = vec4(bar.y);\n"
5767 "}\n";
Tobin Ehlis31289162016-08-17 14:57:58 -06005768 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5769 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5770 VkPipelineObj pipe(m_device);
5771 pipe.AddShader(&vs);
5772 pipe.AddShader(&fs);
5773 pipe.AddColorAttachment();
5774 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5775
Tony Barbour552f6c02016-12-21 14:34:07 -07005776 m_commandBuffer->BeginCommandBuffer();
5777 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005778 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5779 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5780 &descriptorSet, 0, NULL);
Rene Lindsay0583ac92017-01-16 14:29:10 -07005781
5782 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &m_viewports[0]);
5783 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &m_scissors[0]);
5784
Tobin Ehlis31289162016-08-17 14:57:58 -06005785 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005786 m_commandBuffer->EndRenderPass();
5787 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski33826372017-04-13 11:10:11 -06005788 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound Buffer ");
Tobin Ehlis31289162016-08-17 14:57:58 -06005789 // Destroy buffer should invalidate the cmd buffer, causing error on submit
5790 vkDestroyBuffer(m_device->device(), buffer, NULL);
5791 // Attempt to submit cmd buffer
5792 VkSubmitInfo submit_info = {};
5793 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5794 submit_info.commandBufferCount = 1;
5795 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5796 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5797 m_errorMonitor->VerifyFound();
5798 // Cleanup
5799 vkFreeMemory(m_device->device(), mem, NULL);
5800
5801 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5802 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5803 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5804}
5805
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005806TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetImageSamplerDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005807 TEST_DESCRIPTION(
5808 "Attempt to draw with a command buffer that is invalid "
5809 "due to a bound descriptor sets with a combined image "
5810 "sampler having their image, sampler, and descriptor set "
5811 "each respectively destroyed and then attempting to "
5812 "submit associated cmd buffers. Attempt to destroy a "
5813 "DescriptorSet that is in use.");
Tony Barbour1fa09702017-03-16 12:09:08 -06005814 ASSERT_NO_FATAL_FAILURE(Init(nullptr, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT));
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005815 ASSERT_NO_FATAL_FAILURE(InitViewport());
5816 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5817
5818 VkDescriptorPoolSize ds_type_count = {};
5819 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5820 ds_type_count.descriptorCount = 1;
5821
5822 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5823 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5824 ds_pool_ci.pNext = NULL;
Rene Lindsayed88b732017-01-27 15:55:29 -07005825 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005826 ds_pool_ci.maxSets = 1;
5827 ds_pool_ci.poolSizeCount = 1;
5828 ds_pool_ci.pPoolSizes = &ds_type_count;
5829
5830 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005831 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005832 ASSERT_VK_SUCCESS(err);
5833
5834 VkDescriptorSetLayoutBinding dsl_binding = {};
5835 dsl_binding.binding = 0;
5836 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5837 dsl_binding.descriptorCount = 1;
5838 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5839 dsl_binding.pImmutableSamplers = NULL;
5840
5841 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5842 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5843 ds_layout_ci.pNext = NULL;
5844 ds_layout_ci.bindingCount = 1;
5845 ds_layout_ci.pBindings = &dsl_binding;
5846 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005847 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005848 ASSERT_VK_SUCCESS(err);
5849
5850 VkDescriptorSet descriptorSet;
5851 VkDescriptorSetAllocateInfo alloc_info = {};
5852 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5853 alloc_info.descriptorSetCount = 1;
5854 alloc_info.descriptorPool = ds_pool;
5855 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005856 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005857 ASSERT_VK_SUCCESS(err);
5858
5859 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5860 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5861 pipeline_layout_ci.pNext = NULL;
5862 pipeline_layout_ci.setLayoutCount = 1;
5863 pipeline_layout_ci.pSetLayouts = &ds_layout;
5864
5865 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005866 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005867 ASSERT_VK_SUCCESS(err);
5868
5869 // Create images to update the descriptor with
5870 VkImage image;
5871 VkImage image2;
5872 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5873 const int32_t tex_width = 32;
5874 const int32_t tex_height = 32;
5875 VkImageCreateInfo image_create_info = {};
5876 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5877 image_create_info.pNext = NULL;
5878 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5879 image_create_info.format = tex_format;
5880 image_create_info.extent.width = tex_width;
5881 image_create_info.extent.height = tex_height;
5882 image_create_info.extent.depth = 1;
5883 image_create_info.mipLevels = 1;
5884 image_create_info.arrayLayers = 1;
5885 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5886 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
5887 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5888 image_create_info.flags = 0;
5889 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
5890 ASSERT_VK_SUCCESS(err);
5891 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
5892 ASSERT_VK_SUCCESS(err);
5893
5894 VkMemoryRequirements memory_reqs;
5895 VkDeviceMemory image_memory;
5896 bool pass;
5897 VkMemoryAllocateInfo memory_info = {};
5898 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5899 memory_info.pNext = NULL;
5900 memory_info.allocationSize = 0;
5901 memory_info.memoryTypeIndex = 0;
5902 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5903 // Allocate enough memory for both images
5904 memory_info.allocationSize = memory_reqs.size * 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005905 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005906 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005907 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005908 ASSERT_VK_SUCCESS(err);
5909 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5910 ASSERT_VK_SUCCESS(err);
5911 // Bind second image to memory right after first image
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005912 err = vkBindImageMemory(m_device->device(), image2, image_memory, memory_reqs.size);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005913 ASSERT_VK_SUCCESS(err);
5914
5915 VkImageViewCreateInfo image_view_create_info = {};
5916 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5917 image_view_create_info.image = image;
5918 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5919 image_view_create_info.format = tex_format;
5920 image_view_create_info.subresourceRange.layerCount = 1;
5921 image_view_create_info.subresourceRange.baseMipLevel = 0;
5922 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005923 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005924
5925 VkImageView view;
5926 VkImageView view2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005927 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005928 ASSERT_VK_SUCCESS(err);
5929 image_view_create_info.image = image2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005930 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view2);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005931 ASSERT_VK_SUCCESS(err);
5932 // Create Samplers
5933 VkSamplerCreateInfo sampler_ci = {};
5934 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5935 sampler_ci.pNext = NULL;
5936 sampler_ci.magFilter = VK_FILTER_NEAREST;
5937 sampler_ci.minFilter = VK_FILTER_NEAREST;
5938 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5939 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5940 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5941 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5942 sampler_ci.mipLodBias = 1.0;
5943 sampler_ci.anisotropyEnable = VK_FALSE;
5944 sampler_ci.maxAnisotropy = 1;
5945 sampler_ci.compareEnable = VK_FALSE;
5946 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5947 sampler_ci.minLod = 1.0;
5948 sampler_ci.maxLod = 1.0;
5949 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5950 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5951 VkSampler sampler;
5952 VkSampler sampler2;
5953 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5954 ASSERT_VK_SUCCESS(err);
5955 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler2);
5956 ASSERT_VK_SUCCESS(err);
5957 // Update descriptor with image and sampler
5958 VkDescriptorImageInfo img_info = {};
5959 img_info.sampler = sampler;
5960 img_info.imageView = view;
5961 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5962
5963 VkWriteDescriptorSet descriptor_write;
5964 memset(&descriptor_write, 0, sizeof(descriptor_write));
5965 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5966 descriptor_write.dstSet = descriptorSet;
5967 descriptor_write.dstBinding = 0;
5968 descriptor_write.descriptorCount = 1;
5969 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5970 descriptor_write.pImageInfo = &img_info;
5971
5972 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5973
5974 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005975 char const *vsSource =
5976 "#version 450\n"
5977 "\n"
5978 "out gl_PerVertex { \n"
5979 " vec4 gl_Position;\n"
5980 "};\n"
5981 "void main(){\n"
5982 " gl_Position = vec4(1);\n"
5983 "}\n";
5984 char const *fsSource =
5985 "#version 450\n"
5986 "\n"
5987 "layout(set=0, binding=0) uniform sampler2D s;\n"
5988 "layout(location=0) out vec4 x;\n"
5989 "void main(){\n"
5990 " x = texture(s, vec2(1));\n"
5991 "}\n";
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005992 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5993 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5994 VkPipelineObj pipe(m_device);
5995 pipe.AddShader(&vs);
5996 pipe.AddShader(&fs);
5997 pipe.AddColorAttachment();
5998 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5999
6000 // First error case is destroying sampler prior to cmd buffer submission
Mark Lobodzinski33826372017-04-13 11:10:11 -06006001 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is invalid because bound Sampler");
Tony Barbour552f6c02016-12-21 14:34:07 -07006002 m_commandBuffer->BeginCommandBuffer();
6003 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006004 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
6005 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6006 &descriptorSet, 0, NULL);
Rene Lindsaya31285f2017-01-11 16:35:53 -07006007 VkViewport viewport = {0, 0, 16, 16, 0, 1};
6008 VkRect2D scissor = {{0, 0}, {16, 16}};
6009 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
6010 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06006011 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07006012 m_commandBuffer->EndRenderPass();
6013 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06006014 // Destroy sampler invalidates the cmd buffer, causing error on submit
6015 vkDestroySampler(m_device->device(), sampler, NULL);
6016 // Attempt to submit cmd buffer
6017 VkSubmitInfo submit_info = {};
6018 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6019 submit_info.commandBufferCount = 1;
6020 submit_info.pCommandBuffers = &m_commandBuffer->handle();
6021 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
6022 m_errorMonitor->VerifyFound();
Rene Lindsaya31285f2017-01-11 16:35:53 -07006023
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06006024 // Now re-update descriptor with valid sampler and delete image
6025 img_info.sampler = sampler2;
6026 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Rene Lindsayed88b732017-01-27 15:55:29 -07006027
6028 VkCommandBufferBeginInfo info = {};
6029 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
6030 info.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
6031
Mark Lobodzinski33826372017-04-13 11:10:11 -06006032 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound Image ");
Rene Lindsayed88b732017-01-27 15:55:29 -07006033 m_commandBuffer->BeginCommandBuffer(&info);
Tony Barbour552f6c02016-12-21 14:34:07 -07006034 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006035 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
6036 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6037 &descriptorSet, 0, NULL);
Rene Lindsaya31285f2017-01-11 16:35:53 -07006038 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
6039 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06006040 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07006041 m_commandBuffer->EndRenderPass();
6042 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06006043 // Destroy image invalidates the cmd buffer, causing error on submit
6044 vkDestroyImage(m_device->device(), image, NULL);
6045 // Attempt to submit cmd buffer
6046 submit_info = {};
6047 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6048 submit_info.commandBufferCount = 1;
6049 submit_info.pCommandBuffers = &m_commandBuffer->handle();
6050 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
6051 m_errorMonitor->VerifyFound();
6052 // Now update descriptor to be valid, but then free descriptor
6053 img_info.imageView = view2;
6054 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Rene Lindsayed88b732017-01-27 15:55:29 -07006055 m_commandBuffer->BeginCommandBuffer(&info);
Tony Barbour552f6c02016-12-21 14:34:07 -07006056 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006057 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
6058 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6059 &descriptorSet, 0, NULL);
Rene Lindsaya31285f2017-01-11 16:35:53 -07006060 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
6061 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06006062 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07006063 m_commandBuffer->EndRenderPass();
6064 m_commandBuffer->EndCommandBuffer();
Tony Barbourc373c012017-01-26 10:53:28 -07006065 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Dave Houltonfbf52152017-01-06 12:55:29 -07006066
6067 // Immediately try to destroy the descriptor set in the active command buffer - failure expected
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006068 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call vkFreeDescriptorSets() on descriptor set 0x");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06006069 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Mark Mueller917f6bc2016-08-30 10:57:19 -06006070 m_errorMonitor->VerifyFound();
Dave Houltonfbf52152017-01-06 12:55:29 -07006071
6072 // Try again once the queue is idle - should succeed w/o error
Dave Houltond5507dd2017-01-24 15:29:02 -07006073 // TODO - though the particular error above doesn't re-occur, there are other 'unexpecteds' still to clean up
Dave Houltonfbf52152017-01-06 12:55:29 -07006074 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07006075 m_errorMonitor->SetUnexpectedError(
6076 "pDescriptorSets must be a pointer to an array of descriptorSetCount VkDescriptorSet handles, each element of which must "
6077 "either be a valid handle or VK_NULL_HANDLE");
Mark Lobodzinski74597792017-04-11 15:43:49 -06006078 m_errorMonitor->SetUnexpectedError("Unable to remove DescriptorSet obj");
Dave Houltonfbf52152017-01-06 12:55:29 -07006079 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
6080
6081 // Attempt to submit cmd buffer containing the freed descriptor set
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06006082 submit_info = {};
6083 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6084 submit_info.commandBufferCount = 1;
6085 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Lobodzinski33826372017-04-13 11:10:11 -06006086 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound DescriptorSet ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06006087 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
6088 m_errorMonitor->VerifyFound();
Dave Houltonfbf52152017-01-06 12:55:29 -07006089
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06006090 // Cleanup
6091 vkFreeMemory(m_device->device(), image_memory, NULL);
6092 vkDestroySampler(m_device->device(), sampler2, NULL);
6093 vkDestroyImage(m_device->device(), image2, NULL);
6094 vkDestroyImageView(m_device->device(), view, NULL);
6095 vkDestroyImageView(m_device->device(), view2, NULL);
6096 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6097 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6098 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6099}
6100
Tobin Ehlisaabbcd02017-04-13 14:15:21 -06006101TEST_F(VkLayerTest, ImageDescriptorLayoutMismatch) {
6102 TEST_DESCRIPTION("Update an image sampler with a layout that doesn't match the actual image layout at the image is used.");
6103 ASSERT_NO_FATAL_FAILURE(Init(nullptr, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT));
6104 ASSERT_NO_FATAL_FAILURE(InitViewport());
6105 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6106
6107 VkDescriptorPoolSize ds_type_count = {};
6108 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6109 ds_type_count.descriptorCount = 1;
6110
6111 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6112 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6113 ds_pool_ci.pNext = NULL;
6114 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
6115 ds_pool_ci.maxSets = 1;
6116 ds_pool_ci.poolSizeCount = 1;
6117 ds_pool_ci.pPoolSizes = &ds_type_count;
6118
6119 VkDescriptorPool ds_pool;
6120 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
6121 ASSERT_VK_SUCCESS(err);
6122
6123 VkDescriptorSetLayoutBinding dsl_binding = {};
6124 dsl_binding.binding = 0;
6125 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6126 dsl_binding.descriptorCount = 1;
6127 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6128 dsl_binding.pImmutableSamplers = NULL;
6129
6130 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6131 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6132 ds_layout_ci.pNext = NULL;
6133 ds_layout_ci.bindingCount = 1;
6134 ds_layout_ci.pBindings = &dsl_binding;
6135 VkDescriptorSetLayout ds_layout;
6136 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
6137 ASSERT_VK_SUCCESS(err);
6138
6139 VkDescriptorSet descriptorSet;
6140 VkDescriptorSetAllocateInfo alloc_info = {};
6141 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6142 alloc_info.descriptorSetCount = 1;
6143 alloc_info.descriptorPool = ds_pool;
6144 alloc_info.pSetLayouts = &ds_layout;
6145 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
6146 ASSERT_VK_SUCCESS(err);
6147
6148 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6149 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6150 pipeline_layout_ci.pNext = NULL;
6151 pipeline_layout_ci.setLayoutCount = 1;
6152 pipeline_layout_ci.pSetLayouts = &ds_layout;
6153
6154 VkPipelineLayout pipeline_layout;
6155 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
6156 ASSERT_VK_SUCCESS(err);
6157
6158 // Create images to update the descriptor with
6159 const VkFormat format = VK_FORMAT_B8G8R8A8_UNORM;
6160 VkImageObj image(m_device);
6161 image.Init(32, 32, 1, format, VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VK_IMAGE_TILING_OPTIMAL,
6162 0);
6163 ASSERT_TRUE(image.initialized());
6164
6165 VkImageViewCreateInfo image_view_create_info = {};
6166 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
6167 image_view_create_info.image = image.handle();
6168 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
6169 image_view_create_info.format = format;
6170 image_view_create_info.subresourceRange.layerCount = 1;
6171 image_view_create_info.subresourceRange.baseMipLevel = 0;
6172 image_view_create_info.subresourceRange.levelCount = 1;
6173 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
6174
6175 VkImageView view;
6176 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
6177 ASSERT_VK_SUCCESS(err);
6178 // Create Sampler
6179 VkSamplerCreateInfo sampler_ci = {};
6180 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
6181 sampler_ci.pNext = NULL;
6182 sampler_ci.magFilter = VK_FILTER_NEAREST;
6183 sampler_ci.minFilter = VK_FILTER_NEAREST;
6184 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
6185 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6186 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6187 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6188 sampler_ci.mipLodBias = 1.0;
6189 sampler_ci.anisotropyEnable = VK_FALSE;
6190 sampler_ci.maxAnisotropy = 1;
6191 sampler_ci.compareEnable = VK_FALSE;
6192 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
6193 sampler_ci.minLod = 1.0;
6194 sampler_ci.maxLod = 1.0;
6195 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
6196 sampler_ci.unnormalizedCoordinates = VK_FALSE;
6197 VkSampler sampler;
6198 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
6199 ASSERT_VK_SUCCESS(err);
6200 // Update descriptor with image and sampler
6201 VkDescriptorImageInfo img_info = {};
6202 img_info.sampler = sampler;
6203 img_info.imageView = view;
6204 // This should cause a mis-match. Actual layout at use time is SHADER_RO
6205 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
6206
6207 VkWriteDescriptorSet descriptor_write;
6208 memset(&descriptor_write, 0, sizeof(descriptor_write));
6209 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6210 descriptor_write.dstSet = descriptorSet;
6211 descriptor_write.dstBinding = 0;
6212 descriptor_write.descriptorCount = 1;
6213 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6214 descriptor_write.pImageInfo = &img_info;
6215
6216 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6217
6218 // Create PSO to be used for draw-time errors below
6219 char const *vsSource =
6220 "#version 450\n"
6221 "\n"
6222 "out gl_PerVertex { \n"
6223 " vec4 gl_Position;\n"
6224 "};\n"
6225 "void main(){\n"
6226 " gl_Position = vec4(1);\n"
6227 "}\n";
6228 char const *fsSource =
6229 "#version 450\n"
6230 "\n"
6231 "layout(set=0, binding=0) uniform sampler2D s;\n"
6232 "layout(location=0) out vec4 x;\n"
6233 "void main(){\n"
6234 " x = texture(s, vec2(1));\n"
6235 "}\n";
6236 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6237 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
6238 VkPipelineObj pipe(m_device);
6239 pipe.AddShader(&vs);
6240 pipe.AddShader(&fs);
6241 pipe.AddColorAttachment();
6242 pipe.CreateVKPipeline(pipeline_layout, renderPass());
6243
6244 VkCommandBufferObj cmd_buf(m_device, m_commandPool);
6245 cmd_buf.BeginCommandBuffer();
Tobin Ehlisaabbcd02017-04-13 14:15:21 -06006246 // record layout different than actual descriptor layout of SHADER_RO
6247 image.SetLayout(&cmd_buf, VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL);
Mark Lobodzinski95512b72017-05-10 12:21:30 -06006248 cmd_buf.BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlisaabbcd02017-04-13 14:15:21 -06006249 vkCmdBindPipeline(cmd_buf.handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
6250 vkCmdBindDescriptorSets(cmd_buf.handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &descriptorSet, 0, NULL);
6251 VkViewport viewport = {0, 0, 16, 16, 0, 1};
6252 VkRect2D scissor = {{0, 0}, {16, 16}};
6253 vkCmdSetViewport(cmd_buf.handle(), 0, 1, &viewport);
6254 vkCmdSetScissor(cmd_buf.handle(), 0, 1, &scissor);
6255 // At draw time the update layout will mis-match the actual layout
6256 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6257 " with specific layout VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL that doesn't match the "
6258 "actual current layout VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL.");
6259 m_errorMonitor->SetDesiredFailureMsg(
6260 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6261 " Image layout specified at vkUpdateDescriptorSets() time doesn't match actual image layout at time descriptor is used.");
6262 cmd_buf.Draw(1, 0, 0, 0);
6263 m_errorMonitor->VerifyFound();
6264 cmd_buf.EndRenderPass();
6265 cmd_buf.EndCommandBuffer();
6266 // Submit cmd buffer
6267 VkSubmitInfo submit_info = {};
6268 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6269 submit_info.commandBufferCount = 1;
6270 submit_info.pCommandBuffers = &cmd_buf.handle();
6271 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
6272 vkQueueWaitIdle(m_device->m_queue);
6273 // Cleanup
6274 vkDestroySampler(m_device->device(), sampler, NULL);
6275 vkDestroyImageView(m_device->device(), view, NULL);
6276 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6277 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6278 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6279}
6280
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006281TEST_F(VkLayerTest, DescriptorPoolInUseDestroyedSignaled) {
6282 TEST_DESCRIPTION("Delete a DescriptorPool with a DescriptorSet that is in use.");
Tony Barbour1fa09702017-03-16 12:09:08 -06006283 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006284 ASSERT_NO_FATAL_FAILURE(InitViewport());
6285 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6286
6287 VkDescriptorPoolSize ds_type_count = {};
6288 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6289 ds_type_count.descriptorCount = 1;
6290
6291 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6292 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6293 ds_pool_ci.pNext = NULL;
6294 ds_pool_ci.maxSets = 1;
6295 ds_pool_ci.poolSizeCount = 1;
6296 ds_pool_ci.pPoolSizes = &ds_type_count;
6297
6298 VkDescriptorPool ds_pool;
6299 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
6300 ASSERT_VK_SUCCESS(err);
6301
6302 VkDescriptorSetLayoutBinding dsl_binding = {};
6303 dsl_binding.binding = 0;
6304 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6305 dsl_binding.descriptorCount = 1;
6306 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6307 dsl_binding.pImmutableSamplers = NULL;
6308
6309 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6310 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6311 ds_layout_ci.pNext = NULL;
6312 ds_layout_ci.bindingCount = 1;
6313 ds_layout_ci.pBindings = &dsl_binding;
6314 VkDescriptorSetLayout ds_layout;
6315 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
6316 ASSERT_VK_SUCCESS(err);
6317
6318 VkDescriptorSet descriptor_set;
6319 VkDescriptorSetAllocateInfo alloc_info = {};
6320 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6321 alloc_info.descriptorSetCount = 1;
6322 alloc_info.descriptorPool = ds_pool;
6323 alloc_info.pSetLayouts = &ds_layout;
6324 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
6325 ASSERT_VK_SUCCESS(err);
6326
6327 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6328 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6329 pipeline_layout_ci.pNext = NULL;
6330 pipeline_layout_ci.setLayoutCount = 1;
6331 pipeline_layout_ci.pSetLayouts = &ds_layout;
6332
6333 VkPipelineLayout pipeline_layout;
6334 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
6335 ASSERT_VK_SUCCESS(err);
6336
6337 // Create image to update the descriptor with
6338 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06006339 image.Init(32, 32, 1, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006340 ASSERT_TRUE(image.initialized());
6341
6342 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
6343 // Create Sampler
6344 VkSamplerCreateInfo sampler_ci = {};
6345 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
6346 sampler_ci.pNext = NULL;
6347 sampler_ci.magFilter = VK_FILTER_NEAREST;
6348 sampler_ci.minFilter = VK_FILTER_NEAREST;
6349 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
6350 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6351 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6352 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6353 sampler_ci.mipLodBias = 1.0;
6354 sampler_ci.anisotropyEnable = VK_FALSE;
6355 sampler_ci.maxAnisotropy = 1;
6356 sampler_ci.compareEnable = VK_FALSE;
6357 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
6358 sampler_ci.minLod = 1.0;
6359 sampler_ci.maxLod = 1.0;
6360 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
6361 sampler_ci.unnormalizedCoordinates = VK_FALSE;
6362 VkSampler sampler;
6363 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
6364 ASSERT_VK_SUCCESS(err);
6365 // Update descriptor with image and sampler
6366 VkDescriptorImageInfo img_info = {};
6367 img_info.sampler = sampler;
6368 img_info.imageView = view;
6369 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
6370
6371 VkWriteDescriptorSet descriptor_write;
6372 memset(&descriptor_write, 0, sizeof(descriptor_write));
6373 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6374 descriptor_write.dstSet = descriptor_set;
6375 descriptor_write.dstBinding = 0;
6376 descriptor_write.descriptorCount = 1;
6377 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6378 descriptor_write.pImageInfo = &img_info;
6379
6380 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6381
6382 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006383 char const *vsSource =
6384 "#version 450\n"
6385 "\n"
6386 "out gl_PerVertex { \n"
6387 " vec4 gl_Position;\n"
6388 "};\n"
6389 "void main(){\n"
6390 " gl_Position = vec4(1);\n"
6391 "}\n";
6392 char const *fsSource =
6393 "#version 450\n"
6394 "\n"
6395 "layout(set=0, binding=0) uniform sampler2D s;\n"
6396 "layout(location=0) out vec4 x;\n"
6397 "void main(){\n"
6398 " x = texture(s, vec2(1));\n"
6399 "}\n";
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006400 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6401 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
6402 VkPipelineObj pipe(m_device);
6403 pipe.AddShader(&vs);
6404 pipe.AddShader(&fs);
6405 pipe.AddColorAttachment();
6406 pipe.CreateVKPipeline(pipeline_layout, renderPass());
6407
Tony Barbour552f6c02016-12-21 14:34:07 -07006408 m_commandBuffer->BeginCommandBuffer();
6409 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006410 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
6411 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6412 &descriptor_set, 0, NULL);
Rene Lindsaye353a072017-01-16 11:07:28 -07006413
6414 VkViewport viewport = {0, 0, 16, 16, 0, 1};
6415 VkRect2D scissor = {{0, 0}, {16, 16}};
6416 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
6417 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
6418
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006419 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07006420 m_commandBuffer->EndRenderPass();
6421 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006422 // Submit cmd buffer to put pool in-flight
6423 VkSubmitInfo submit_info = {};
6424 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6425 submit_info.commandBufferCount = 1;
6426 submit_info.pCommandBuffers = &m_commandBuffer->handle();
6427 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
6428 // Destroy pool while in-flight, causing error
Mark Lobodzinski33826372017-04-13 11:10:11 -06006429 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete DescriptorPool ");
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006430 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6431 m_errorMonitor->VerifyFound();
6432 vkQueueWaitIdle(m_device->m_queue);
6433 // Cleanup
6434 vkDestroySampler(m_device->device(), sampler, NULL);
6435 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6436 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07006437 m_errorMonitor->SetUnexpectedError(
6438 "If descriptorPool is not VK_NULL_HANDLE, descriptorPool must be a valid VkDescriptorPool handle");
Mark Lobodzinski74597792017-04-11 15:43:49 -06006439 m_errorMonitor->SetUnexpectedError("Unable to remove DescriptorPool obj");
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006440 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Rene Lindsaye353a072017-01-16 11:07:28 -07006441 // TODO : It seems Validation layers think ds_pool was already destroyed, even though it wasn't?
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006442}
6443
Tobin Ehlis50a095d2016-09-21 17:32:49 -06006444TEST_F(VkLayerTest, DescriptorImageUpdateNoMemoryBound) {
6445 TEST_DESCRIPTION("Attempt an image descriptor set update where image's bound memory has been freed.");
Tony Barbour1fa09702017-03-16 12:09:08 -06006446 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis50a095d2016-09-21 17:32:49 -06006447 ASSERT_NO_FATAL_FAILURE(InitViewport());
6448 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6449
6450 VkDescriptorPoolSize ds_type_count = {};
6451 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6452 ds_type_count.descriptorCount = 1;
6453
6454 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6455 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6456 ds_pool_ci.pNext = NULL;
6457 ds_pool_ci.maxSets = 1;
6458 ds_pool_ci.poolSizeCount = 1;
6459 ds_pool_ci.pPoolSizes = &ds_type_count;
6460
6461 VkDescriptorPool ds_pool;
6462 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
6463 ASSERT_VK_SUCCESS(err);
6464
6465 VkDescriptorSetLayoutBinding dsl_binding = {};
6466 dsl_binding.binding = 0;
6467 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6468 dsl_binding.descriptorCount = 1;
6469 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6470 dsl_binding.pImmutableSamplers = NULL;
6471
6472 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6473 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6474 ds_layout_ci.pNext = NULL;
6475 ds_layout_ci.bindingCount = 1;
6476 ds_layout_ci.pBindings = &dsl_binding;
6477 VkDescriptorSetLayout ds_layout;
6478 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
6479 ASSERT_VK_SUCCESS(err);
6480
6481 VkDescriptorSet descriptorSet;
6482 VkDescriptorSetAllocateInfo alloc_info = {};
6483 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6484 alloc_info.descriptorSetCount = 1;
6485 alloc_info.descriptorPool = ds_pool;
6486 alloc_info.pSetLayouts = &ds_layout;
6487 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
6488 ASSERT_VK_SUCCESS(err);
6489
6490 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6491 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6492 pipeline_layout_ci.pNext = NULL;
6493 pipeline_layout_ci.setLayoutCount = 1;
6494 pipeline_layout_ci.pSetLayouts = &ds_layout;
6495
6496 VkPipelineLayout pipeline_layout;
6497 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
6498 ASSERT_VK_SUCCESS(err);
6499
6500 // Create images to update the descriptor with
6501 VkImage image;
6502 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
6503 const int32_t tex_width = 32;
6504 const int32_t tex_height = 32;
6505 VkImageCreateInfo image_create_info = {};
6506 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6507 image_create_info.pNext = NULL;
6508 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6509 image_create_info.format = tex_format;
6510 image_create_info.extent.width = tex_width;
6511 image_create_info.extent.height = tex_height;
6512 image_create_info.extent.depth = 1;
6513 image_create_info.mipLevels = 1;
6514 image_create_info.arrayLayers = 1;
6515 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
6516 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
6517 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
6518 image_create_info.flags = 0;
6519 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
6520 ASSERT_VK_SUCCESS(err);
6521 // Initially bind memory to avoid error at bind view time. We'll break binding before update.
6522 VkMemoryRequirements memory_reqs;
6523 VkDeviceMemory image_memory;
6524 bool pass;
6525 VkMemoryAllocateInfo memory_info = {};
6526 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6527 memory_info.pNext = NULL;
6528 memory_info.allocationSize = 0;
6529 memory_info.memoryTypeIndex = 0;
6530 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
6531 // Allocate enough memory for image
6532 memory_info.allocationSize = memory_reqs.size;
6533 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
6534 ASSERT_TRUE(pass);
6535 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
6536 ASSERT_VK_SUCCESS(err);
6537 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
6538 ASSERT_VK_SUCCESS(err);
6539
6540 VkImageViewCreateInfo image_view_create_info = {};
6541 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
6542 image_view_create_info.image = image;
6543 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
6544 image_view_create_info.format = tex_format;
6545 image_view_create_info.subresourceRange.layerCount = 1;
6546 image_view_create_info.subresourceRange.baseMipLevel = 0;
6547 image_view_create_info.subresourceRange.levelCount = 1;
6548 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
6549
6550 VkImageView view;
6551 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
6552 ASSERT_VK_SUCCESS(err);
6553 // Create Samplers
6554 VkSamplerCreateInfo sampler_ci = {};
6555 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
6556 sampler_ci.pNext = NULL;
6557 sampler_ci.magFilter = VK_FILTER_NEAREST;
6558 sampler_ci.minFilter = VK_FILTER_NEAREST;
6559 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
6560 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6561 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6562 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6563 sampler_ci.mipLodBias = 1.0;
6564 sampler_ci.anisotropyEnable = VK_FALSE;
6565 sampler_ci.maxAnisotropy = 1;
6566 sampler_ci.compareEnable = VK_FALSE;
6567 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
6568 sampler_ci.minLod = 1.0;
6569 sampler_ci.maxLod = 1.0;
6570 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
6571 sampler_ci.unnormalizedCoordinates = VK_FALSE;
6572 VkSampler sampler;
6573 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
6574 ASSERT_VK_SUCCESS(err);
6575 // Update descriptor with image and sampler
6576 VkDescriptorImageInfo img_info = {};
6577 img_info.sampler = sampler;
6578 img_info.imageView = view;
6579 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
6580
6581 VkWriteDescriptorSet descriptor_write;
6582 memset(&descriptor_write, 0, sizeof(descriptor_write));
6583 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6584 descriptor_write.dstSet = descriptorSet;
6585 descriptor_write.dstBinding = 0;
6586 descriptor_write.descriptorCount = 1;
6587 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6588 descriptor_write.pImageInfo = &img_info;
6589 // Break memory binding and attempt update
6590 vkFreeMemory(m_device->device(), image_memory, nullptr);
6591 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006592 " previously bound memory was freed. Memory must not be freed prior to this operation.");
Tobin Ehlis50a095d2016-09-21 17:32:49 -06006593 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6594 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
6595 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6596 m_errorMonitor->VerifyFound();
6597 // Cleanup
6598 vkDestroyImage(m_device->device(), image, NULL);
6599 vkDestroySampler(m_device->device(), sampler, NULL);
6600 vkDestroyImageView(m_device->device(), view, NULL);
6601 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6602 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6603 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6604}
6605
Karl Schultz6addd812016-02-02 17:17:23 -07006606TEST_F(VkLayerTest, InvalidPipeline) {
Karl Schultzbdb75952016-04-19 11:36:49 -06006607 // Attempt to bind an invalid Pipeline to a valid Command Buffer
6608 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06006609 // Create a valid cmd buffer
6610 // call vkCmdBindPipeline w/ false Pipeline
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06006611 uint64_t fake_pipeline_handle = 0xbaad6001;
6612 VkPipeline bad_pipeline = reinterpret_cast<VkPipeline &>(fake_pipeline_handle);
Tony Barbour1fa09702017-03-16 12:09:08 -06006613 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes4dbf70f2016-09-16 17:58:00 +12006614 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6615
Karl Schultzf78bcdd2016-11-30 12:36:01 -07006616 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00601);
Tony Barbour552f6c02016-12-21 14:34:07 -07006617 m_commandBuffer->BeginCommandBuffer();
6618 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006619 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, bad_pipeline);
Karl Schultzbdb75952016-04-19 11:36:49 -06006620 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12006621
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06006622 // Now issue a draw call with no pipeline bound
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006623 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 -06006624 Draw(1, 0, 0, 0);
6625 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12006626
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06006627 // Finally same check once more but with Dispatch/Compute
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006628 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "At Draw/Dispatch time no valid VkPipeline is bound!");
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006629 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); // must be outside renderpass
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06006630 vkCmdDispatch(m_commandBuffer->GetBufferHandle(), 0, 0, 0);
6631 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06006632}
6633
Karl Schultz6addd812016-02-02 17:17:23 -07006634TEST_F(VkLayerTest, DescriptorSetNotUpdated) {
Tobin Ehlis5a5f5ef2016-08-17 13:56:55 -06006635 TEST_DESCRIPTION("Bind a descriptor set that hasn't been updated.");
Karl Schultz6addd812016-02-02 17:17:23 -07006636 VkResult err;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006637
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006638 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " bound but it was never updated. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006639
Tony Barbour1fa09702017-03-16 12:09:08 -06006640 ASSERT_NO_FATAL_FAILURE(Init());
Mike Stroyan713b2d72015-08-04 10:49:29 -06006641 ASSERT_NO_FATAL_FAILURE(InitViewport());
6642 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006643 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006644 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6645 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06006646
6647 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006648 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6649 ds_pool_ci.pNext = NULL;
6650 ds_pool_ci.maxSets = 1;
6651 ds_pool_ci.poolSizeCount = 1;
6652 ds_pool_ci.pPoolSizes = &ds_type_count;
Mike Stroyan713b2d72015-08-04 10:49:29 -06006653
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006654 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006655 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006656 ASSERT_VK_SUCCESS(err);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006657
Tony Barboureb254902015-07-15 12:50:33 -06006658 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006659 dsl_binding.binding = 0;
6660 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6661 dsl_binding.descriptorCount = 1;
6662 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6663 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006664
Tony Barboureb254902015-07-15 12:50:33 -06006665 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006666 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6667 ds_layout_ci.pNext = NULL;
6668 ds_layout_ci.bindingCount = 1;
6669 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006670 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006671 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006672 ASSERT_VK_SUCCESS(err);
6673
6674 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006675 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006676 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006677 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006678 alloc_info.descriptorPool = ds_pool;
6679 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006680 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006681 ASSERT_VK_SUCCESS(err);
6682
Tony Barboureb254902015-07-15 12:50:33 -06006683 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006684 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6685 pipeline_layout_ci.pNext = NULL;
6686 pipeline_layout_ci.setLayoutCount = 1;
6687 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006688
6689 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006690 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006691 ASSERT_VK_SUCCESS(err);
6692
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006693 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06006694 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07006695 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006696 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006697
Tony Barbourc95e4ac2015-08-04 17:05:26 -06006698 VkPipelineObj pipe(m_device);
6699 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06006700 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06006701 pipe.AddColorAttachment();
Tony Barbourc95e4ac2015-08-04 17:05:26 -06006702 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06006703
Tony Barbour552f6c02016-12-21 14:34:07 -07006704 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006705 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
6706 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6707 &descriptorSet, 0, NULL);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006708
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006709 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06006710
Chia-I Wuf7458c52015-10-26 21:10:41 +08006711 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6712 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6713 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006714}
6715
Karl Schultz6addd812016-02-02 17:17:23 -07006716TEST_F(VkLayerTest, InvalidBufferViewObject) {
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006717 // Create a single TEXEL_BUFFER descriptor and send it an invalid bufferView
Karl Schultz6addd812016-02-02 17:17:23 -07006718 VkResult err;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006719
Karl Schultzf78bcdd2016-11-30 12:36:01 -07006720 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00940);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006721
Tony Barbour1fa09702017-03-16 12:09:08 -06006722 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006723 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006724 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
6725 ds_type_count.descriptorCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006726
6727 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006728 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6729 ds_pool_ci.pNext = NULL;
6730 ds_pool_ci.maxSets = 1;
6731 ds_pool_ci.poolSizeCount = 1;
6732 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006733
6734 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006735 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006736 ASSERT_VK_SUCCESS(err);
6737
6738 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006739 dsl_binding.binding = 0;
6740 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
6741 dsl_binding.descriptorCount = 1;
6742 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6743 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006744
6745 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006746 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6747 ds_layout_ci.pNext = NULL;
6748 ds_layout_ci.bindingCount = 1;
6749 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006750 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006751 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006752 ASSERT_VK_SUCCESS(err);
6753
6754 VkDescriptorSet descriptorSet;
6755 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006756 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006757 alloc_info.descriptorSetCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006758 alloc_info.descriptorPool = ds_pool;
6759 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006760 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006761 ASSERT_VK_SUCCESS(err);
6762
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006763 VkBufferView view = (VkBufferView)((size_t)0xbaadbeef); // invalid bufferView object
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006764 VkWriteDescriptorSet descriptor_write;
6765 memset(&descriptor_write, 0, sizeof(descriptor_write));
6766 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6767 descriptor_write.dstSet = descriptorSet;
6768 descriptor_write.dstBinding = 0;
6769 descriptor_write.descriptorCount = 1;
6770 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
6771 descriptor_write.pTexelBufferView = &view;
6772
6773 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6774
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006775 m_errorMonitor->VerifyFound();
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006776
6777 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6778 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6779}
6780
Mark Youngd339ba32016-05-30 13:28:35 -06006781TEST_F(VkLayerTest, CreateBufferViewNoMemoryBoundToBuffer) {
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006782 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 -06006783
6784 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06006785 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006786 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -06006787
Tony Barbour1fa09702017-03-16 12:09:08 -06006788 ASSERT_NO_FATAL_FAILURE(Init());
Mark Youngd339ba32016-05-30 13:28:35 -06006789
6790 // Create a buffer with no bound memory and then attempt to create
6791 // a buffer view.
6792 VkBufferCreateInfo buff_ci = {};
6793 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes4538d242016-09-13 18:13:58 +12006794 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -06006795 buff_ci.size = 256;
6796 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
6797 VkBuffer buffer;
6798 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
6799 ASSERT_VK_SUCCESS(err);
6800
6801 VkBufferViewCreateInfo buff_view_ci = {};
6802 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
6803 buff_view_ci.buffer = buffer;
6804 buff_view_ci.format = VK_FORMAT_R8_UNORM;
6805 buff_view_ci.range = VK_WHOLE_SIZE;
6806 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006807 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Mark Youngd339ba32016-05-30 13:28:35 -06006808
6809 m_errorMonitor->VerifyFound();
6810 vkDestroyBuffer(m_device->device(), buffer, NULL);
6811 // If last error is success, it still created the view, so delete it.
6812 if (err == VK_SUCCESS) {
6813 vkDestroyBufferView(m_device->device(), buff_view, NULL);
6814 }
6815}
6816
Karl Schultz6addd812016-02-02 17:17:23 -07006817TEST_F(VkLayerTest, InvalidDynamicOffsetCases) {
6818 // Create a descriptorSet w/ dynamic descriptor and then hit 3 offset error
6819 // cases:
Tobin Ehlisf6585052015-12-17 11:48:42 -07006820 // 1. No dynamicOffset supplied
6821 // 2. Too many dynamicOffsets supplied
6822 // 3. Dynamic offset oversteps buffer being updated
Karl Schultz6addd812016-02-02 17:17:23 -07006823 VkResult err;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006824 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6825 " requires 1 dynamicOffsets, but only "
6826 "0 dynamicOffsets are left in "
6827 "pDynamicOffsets ");
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006828
Tony Barbour1fa09702017-03-16 12:09:08 -06006829 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006830 ASSERT_NO_FATAL_FAILURE(InitViewport());
6831 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6832
6833 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006834 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6835 ds_type_count.descriptorCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006836
6837 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006838 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6839 ds_pool_ci.pNext = NULL;
6840 ds_pool_ci.maxSets = 1;
6841 ds_pool_ci.poolSizeCount = 1;
6842 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006843
6844 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006845 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006846 ASSERT_VK_SUCCESS(err);
6847
6848 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006849 dsl_binding.binding = 0;
6850 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6851 dsl_binding.descriptorCount = 1;
6852 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6853 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006854
6855 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006856 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6857 ds_layout_ci.pNext = NULL;
6858 ds_layout_ci.bindingCount = 1;
6859 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006860 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006861 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006862 ASSERT_VK_SUCCESS(err);
6863
6864 VkDescriptorSet descriptorSet;
6865 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006866 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006867 alloc_info.descriptorSetCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006868 alloc_info.descriptorPool = ds_pool;
6869 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006870 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006871 ASSERT_VK_SUCCESS(err);
6872
6873 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006874 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6875 pipeline_layout_ci.pNext = NULL;
6876 pipeline_layout_ci.setLayoutCount = 1;
6877 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006878
6879 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006880 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006881 ASSERT_VK_SUCCESS(err);
6882
6883 // Create a buffer to update the descriptor with
6884 uint32_t qfi = 0;
6885 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006886 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6887 buffCI.size = 1024;
6888 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6889 buffCI.queueFamilyIndexCount = 1;
6890 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006891
6892 VkBuffer dyub;
6893 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6894 ASSERT_VK_SUCCESS(err);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006895 // Allocate memory and bind to buffer so we can make it to the appropriate
6896 // error
6897 VkMemoryAllocateInfo mem_alloc = {};
6898 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6899 mem_alloc.pNext = NULL;
6900 mem_alloc.allocationSize = 1024;
Chris Forbesb6116cc2016-05-08 11:39:59 +12006901 mem_alloc.memoryTypeIndex = 0;
6902
6903 VkMemoryRequirements memReqs;
6904 vkGetBufferMemoryRequirements(m_device->device(), dyub, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006905 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Chris Forbesb6116cc2016-05-08 11:39:59 +12006906 if (!pass) {
6907 vkDestroyBuffer(m_device->device(), dyub, NULL);
6908 return;
6909 }
6910
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006911 VkDeviceMemory mem;
6912 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
6913 ASSERT_VK_SUCCESS(err);
6914 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
6915 ASSERT_VK_SUCCESS(err);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006916 // Correctly update descriptor to avoid "NOT_UPDATED" error
6917 VkDescriptorBufferInfo buffInfo = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006918 buffInfo.buffer = dyub;
6919 buffInfo.offset = 0;
6920 buffInfo.range = 1024;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006921
6922 VkWriteDescriptorSet descriptor_write;
6923 memset(&descriptor_write, 0, sizeof(descriptor_write));
6924 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6925 descriptor_write.dstSet = descriptorSet;
6926 descriptor_write.dstBinding = 0;
6927 descriptor_write.descriptorCount = 1;
6928 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6929 descriptor_write.pBufferInfo = &buffInfo;
6930
6931 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6932
Tony Barbour552f6c02016-12-21 14:34:07 -07006933 m_commandBuffer->BeginCommandBuffer();
6934 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006935 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6936 &descriptorSet, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006937 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07006938 uint32_t pDynOff[2] = {512, 756};
6939 // Now cause error b/c too many dynOffsets in array for # of dyn descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006940 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6941 "Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but ");
6942 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6943 &descriptorSet, 2, pDynOff);
Chris Forbes7b342802016-04-07 13:20:10 +12006944 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07006945 // Finally cause error due to dynamicOffset being too big
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006946 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6947 " dynamic offset 512 combined with "
6948 "offset 0 and range 1024 that "
6949 "oversteps the buffer size of 1024");
Tobin Ehlisf6585052015-12-17 11:48:42 -07006950 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006951 char const *vsSource =
6952 "#version 450\n"
6953 "\n"
6954 "out gl_PerVertex { \n"
6955 " vec4 gl_Position;\n"
6956 "};\n"
6957 "void main(){\n"
6958 " gl_Position = vec4(1);\n"
6959 "}\n";
6960 char const *fsSource =
6961 "#version 450\n"
6962 "\n"
6963 "layout(location=0) out vec4 x;\n"
6964 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
6965 "void main(){\n"
6966 " x = vec4(bar.y);\n"
6967 "}\n";
Tobin Ehlisf6585052015-12-17 11:48:42 -07006968 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6969 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
6970 VkPipelineObj pipe(m_device);
6971 pipe.AddShader(&vs);
6972 pipe.AddShader(&fs);
6973 pipe.AddColorAttachment();
6974 pipe.CreateVKPipeline(pipeline_layout, renderPass());
6975
Rene Lindsayacbf5e62016-12-15 18:47:11 -07006976 VkViewport viewport = {0, 0, 16, 16, 0, 1};
6977 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
6978 VkRect2D scissor = {{0, 0}, {16, 16}};
6979 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
6980
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006981 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07006982 // This update should succeed, but offset size of 512 will overstep buffer
6983 // /w range 1024 & size 1024
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006984 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6985 &descriptorSet, 1, pDynOff);
Tobin Ehlisf6585052015-12-17 11:48:42 -07006986 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006987 m_errorMonitor->VerifyFound();
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006988
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006989 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis512098e2016-05-05 09:06:12 -06006990 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006991
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006992 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06006993 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006994 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6995}
6996
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006997TEST_F(VkLayerTest, DescriptorBufferUpdateNoMemoryBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006998 TEST_DESCRIPTION(
6999 "Attempt to update a descriptor with a non-sparse buffer "
7000 "that doesn't have memory bound");
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06007001 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06007002 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06007003 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Tobin Ehlisfed999f2016-09-21 15:09:45 -06007004 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7005 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06007006
Tony Barbour1fa09702017-03-16 12:09:08 -06007007 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06007008 ASSERT_NO_FATAL_FAILURE(InitViewport());
7009 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7010
7011 VkDescriptorPoolSize ds_type_count = {};
7012 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
7013 ds_type_count.descriptorCount = 1;
7014
7015 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7016 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7017 ds_pool_ci.pNext = NULL;
7018 ds_pool_ci.maxSets = 1;
7019 ds_pool_ci.poolSizeCount = 1;
7020 ds_pool_ci.pPoolSizes = &ds_type_count;
7021
7022 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007023 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06007024 ASSERT_VK_SUCCESS(err);
7025
7026 VkDescriptorSetLayoutBinding dsl_binding = {};
7027 dsl_binding.binding = 0;
7028 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
7029 dsl_binding.descriptorCount = 1;
7030 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7031 dsl_binding.pImmutableSamplers = NULL;
7032
7033 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7034 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7035 ds_layout_ci.pNext = NULL;
7036 ds_layout_ci.bindingCount = 1;
7037 ds_layout_ci.pBindings = &dsl_binding;
7038 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007039 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06007040 ASSERT_VK_SUCCESS(err);
7041
7042 VkDescriptorSet descriptorSet;
7043 VkDescriptorSetAllocateInfo alloc_info = {};
7044 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7045 alloc_info.descriptorSetCount = 1;
7046 alloc_info.descriptorPool = ds_pool;
7047 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007048 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06007049 ASSERT_VK_SUCCESS(err);
7050
7051 // Create a buffer to update the descriptor with
7052 uint32_t qfi = 0;
7053 VkBufferCreateInfo buffCI = {};
7054 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
7055 buffCI.size = 1024;
7056 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
7057 buffCI.queueFamilyIndexCount = 1;
7058 buffCI.pQueueFamilyIndices = &qfi;
7059
7060 VkBuffer dyub;
7061 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
7062 ASSERT_VK_SUCCESS(err);
7063
7064 // Attempt to update descriptor without binding memory to it
7065 VkDescriptorBufferInfo buffInfo = {};
7066 buffInfo.buffer = dyub;
7067 buffInfo.offset = 0;
7068 buffInfo.range = 1024;
7069
7070 VkWriteDescriptorSet descriptor_write;
7071 memset(&descriptor_write, 0, sizeof(descriptor_write));
7072 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
7073 descriptor_write.dstSet = descriptorSet;
7074 descriptor_write.dstBinding = 0;
7075 descriptor_write.descriptorCount = 1;
7076 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
7077 descriptor_write.pBufferInfo = &buffInfo;
7078
7079 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
7080 m_errorMonitor->VerifyFound();
7081
7082 vkDestroyBuffer(m_device->device(), dyub, NULL);
7083 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7084 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
7085}
7086
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07007087TEST_F(VkLayerTest, InvalidPushConstants) {
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07007088 VkResult err;
Tony Barbour1fa09702017-03-16 12:09:08 -06007089 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07007090 ASSERT_NO_FATAL_FAILURE(InitViewport());
7091 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7092
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007093 VkPipelineLayout pipeline_layout;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07007094 VkPushConstantRange pc_range = {};
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07007095 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7096 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7097 pipeline_layout_ci.pushConstantRangeCount = 1;
7098 pipeline_layout_ci.pPushConstantRanges = &pc_range;
7099
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007100 //
7101 // Check for invalid push constant ranges in pipeline layouts.
7102 //
7103 struct PipelineLayoutTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06007104 VkPushConstantRange const range;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007105 char const *msg;
7106 };
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07007107
Karl Schultzc81037d2016-05-12 08:11:23 -06007108 const uint32_t too_big = m_device->props.limits.maxPushConstantsSize + 0x4;
7109 const std::array<PipelineLayoutTestCase, 10> range_tests = {{
7110 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0},
7111 "vkCreatePipelineLayout() call has push constants index 0 with "
7112 "size 0."},
7113 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
7114 "vkCreatePipelineLayout() call has push constants index 0 with "
7115 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06007116 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Karl Schultzc81037d2016-05-12 08:11:23 -06007117 "vkCreatePipelineLayout() call has push constants index 0 with "
7118 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06007119 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 0},
Karl Schultzc81037d2016-05-12 08:11:23 -06007120 "vkCreatePipelineLayout() call has push constants index 0 with "
7121 "size 0."},
7122 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
7123 "vkCreatePipelineLayout() call has push constants index 0 with "
7124 "offset 1. Offset must"},
7125 {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big},
7126 "vkCreatePipelineLayout() call has push constants index 0 "
7127 "with offset "},
7128 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big},
7129 "vkCreatePipelineLayout() call has push constants "
7130 "index 0 with offset "},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06007131 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06007132 "vkCreatePipelineLayout() call has push constants index 0 "
7133 "with offset "},
7134 {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020},
7135 "vkCreatePipelineLayout() call has push "
7136 "constants index 0 with offset "},
7137 {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0},
7138 "vkCreatePipelineLayout() call has push "
7139 "constants index 0 with offset "},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007140 }};
7141
7142 // Check for invalid offset and size
Karl Schultzc81037d2016-05-12 08:11:23 -06007143 for (const auto &iter : range_tests) {
7144 pc_range = iter.range;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007145 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
7146 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007147 m_errorMonitor->VerifyFound();
7148 if (VK_SUCCESS == err) {
7149 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7150 }
7151 }
7152
7153 // Check for invalid stage flag
7154 pc_range.offset = 0;
7155 pc_range.size = 16;
7156 pc_range.stageFlags = 0;
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06007157 m_errorMonitor->SetDesiredFailureMsg(
7158 VK_DEBUG_REPORT_ERROR_BIT_EXT,
7159 "vkCreatePipelineLayout: value of pCreateInfo->pPushConstantRanges[0].stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007160 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007161 m_errorMonitor->VerifyFound();
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007162 if (VK_SUCCESS == err) {
7163 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7164 }
7165
Karl Schultzc59b72d2017-02-24 15:45:05 -07007166 // Check for duplicate stage flags in a list of push constant ranges.
7167 // A shader can only have one push constant block and that block is mapped
7168 // to the push constant range that has that shader's stage flag set.
7169 // The shader's stage flag can only appear once in all the ranges, so the
7170 // implementation can find the one and only range to map it to.
Karl Schultzc81037d2016-05-12 08:11:23 -06007171 const uint32_t ranges_per_test = 5;
Karl Schultzc59b72d2017-02-24 15:45:05 -07007172 struct DuplicateStageFlagsTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06007173 VkPushConstantRange const ranges[ranges_per_test];
Jeremy Hayesde6d96c2017-02-01 15:22:32 -07007174 std::vector<char const *> const msg;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007175 };
Karl Schultzc59b72d2017-02-24 15:45:05 -07007176 // Overlapping ranges are OK, but a stage flag can appear only once.
7177 const std::array<DuplicateStageFlagsTestCase, 3> duplicate_stageFlags_tests = {
7178 {
7179 {{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
7180 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
7181 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
7182 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007183 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzc59b72d2017-02-24 15:45:05 -07007184 {
7185 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 0 and 1.",
7186 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 0 and 2.",
7187 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 0 and 3.",
7188 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 0 and 4.",
7189 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 1 and 2.",
7190 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 1 and 3.",
7191 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 1 and 4.",
7192 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 2 and 3.",
7193 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 2 and 4.",
7194 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 3 and 4.",
7195 }},
7196 {{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
7197 {VK_SHADER_STAGE_GEOMETRY_BIT, 0, 4},
7198 {VK_SHADER_STAGE_FRAGMENT_BIT, 0, 4},
7199 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
7200 {VK_SHADER_STAGE_GEOMETRY_BIT, 0, 4}},
7201 {
7202 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 0 and 3.",
7203 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 1 and 4.",
7204 }},
7205 {{{VK_SHADER_STAGE_FRAGMENT_BIT, 0, 4},
7206 {VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 4},
7207 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
7208 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
7209 {VK_SHADER_STAGE_GEOMETRY_BIT, 0, 4}},
7210 {
7211 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 2 and 3.",
7212 }},
7213 },
7214 };
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007215
Karl Schultzc59b72d2017-02-24 15:45:05 -07007216 for (const auto &iter : duplicate_stageFlags_tests) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007217 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
Karl Schultzc81037d2016-05-12 08:11:23 -06007218 pipeline_layout_ci.pushConstantRangeCount = ranges_per_test;
Karl Schultzc59b72d2017-02-24 15:45:05 -07007219 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg.begin(), iter.msg.end());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007220 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007221 m_errorMonitor->VerifyFound();
7222 if (VK_SUCCESS == err) {
7223 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7224 }
7225 }
7226
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007227 //
7228 // CmdPushConstants tests
7229 //
7230
Karl Schultzc59b72d2017-02-24 15:45:05 -07007231 // Setup a pipeline layout with ranges: [0,16) [64,80)
Karl Schultzc81037d2016-05-12 08:11:23 -06007232 const VkPushConstantRange pc_range2[] = {
Karl Schultzc59b72d2017-02-24 15:45:05 -07007233 {VK_SHADER_STAGE_VERTEX_BIT, 64, 16}, {VK_SHADER_STAGE_FRAGMENT_BIT, 0, 16},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007234 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007235 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range2) / sizeof(VkPushConstantRange);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007236 pipeline_layout_ci.pPushConstantRanges = pc_range2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007237 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07007238 ASSERT_VK_SUCCESS(err);
Karl Schultzc59b72d2017-02-24 15:45:05 -07007239
7240 const uint8_t dummy_values[100] = {};
7241
7242 m_commandBuffer->BeginCommandBuffer();
7243 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007244
7245 // Check for invalid stage flag
Karl Schultzc59b72d2017-02-24 15:45:05 -07007246 // Note that VU 00996 isn't reached due to parameter validation
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06007247 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdPushConstants: value of stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007248 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, 0, 0, 16, dummy_values);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007249 m_errorMonitor->VerifyFound();
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007250
Karl Schultzc59b72d2017-02-24 15:45:05 -07007251 m_errorMonitor->ExpectSuccess();
7252 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, VK_SHADER_STAGE_FRAGMENT_BIT, 0, 16, dummy_values);
7253 m_errorMonitor->VerifyNotFound();
7254 m_errorMonitor->ExpectSuccess();
7255 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, VK_SHADER_STAGE_VERTEX_BIT, 64, 16, dummy_values);
7256 m_errorMonitor->VerifyNotFound();
7257 const std::array<VkPushConstantRange, 6> cmd_range_tests = {{
7258 {VK_SHADER_STAGE_FRAGMENT_BIT, 64, 16},
7259 {VK_SHADER_STAGE_VERTEX_BIT, 0, 16},
7260 {VK_SHADER_STAGE_GEOMETRY_BIT, 0, 16},
7261 {VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT, 0, 16},
7262 {VK_SHADER_STAGE_VERTEX_BIT, 24, 16},
7263 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06007264 }};
Karl Schultzc59b72d2017-02-24 15:45:05 -07007265 for (const auto &iter : cmd_range_tests) {
7266 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00988);
7267 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.stageFlags, iter.offset, iter.size,
7268 dummy_values);
Karl Schultzc81037d2016-05-12 08:11:23 -06007269 m_errorMonitor->VerifyFound();
7270 }
Karl Schultzc81037d2016-05-12 08:11:23 -06007271
Tony Barbour552f6c02016-12-21 14:34:07 -07007272 m_commandBuffer->EndRenderPass();
7273 m_commandBuffer->EndCommandBuffer();
Karl Schultzc59b72d2017-02-24 15:45:05 -07007274 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07007275}
7276
Karl Schultz6addd812016-02-02 17:17:23 -07007277TEST_F(VkLayerTest, DescriptorSetCompatibility) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07007278 // Test various desriptorSet errors with bad binding combinations
Karl Schultz6addd812016-02-02 17:17:23 -07007279 VkResult err;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007280
Tony Barbour1fa09702017-03-16 12:09:08 -06007281 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis559c6382015-11-05 09:52:49 -07007282 ASSERT_NO_FATAL_FAILURE(InitViewport());
7283 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7284
7285 static const uint32_t NUM_DESCRIPTOR_TYPES = 5;
7286 VkDescriptorPoolSize ds_type_count[NUM_DESCRIPTOR_TYPES] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007287 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7288 ds_type_count[0].descriptorCount = 10;
7289 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
7290 ds_type_count[1].descriptorCount = 2;
7291 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
7292 ds_type_count[2].descriptorCount = 2;
7293 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_SAMPLER;
7294 ds_type_count[3].descriptorCount = 5;
7295 // TODO : LunarG ILO driver currently asserts in desc.c w/ INPUT_ATTACHMENT
7296 // type
7297 // ds_type_count[4].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
7298 ds_type_count[4].type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
7299 ds_type_count[4].descriptorCount = 2;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007300
7301 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007302 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7303 ds_pool_ci.pNext = NULL;
7304 ds_pool_ci.maxSets = 5;
7305 ds_pool_ci.poolSizeCount = NUM_DESCRIPTOR_TYPES;
7306 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007307
7308 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007309 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007310 ASSERT_VK_SUCCESS(err);
7311
7312 static const uint32_t MAX_DS_TYPES_IN_LAYOUT = 2;
7313 VkDescriptorSetLayoutBinding dsl_binding[MAX_DS_TYPES_IN_LAYOUT] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007314 dsl_binding[0].binding = 0;
7315 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7316 dsl_binding[0].descriptorCount = 5;
7317 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
7318 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007319
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007320 // Create layout identical to set0 layout but w/ different stageFlags
7321 VkDescriptorSetLayoutBinding dsl_fs_stage_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007322 dsl_fs_stage_only.binding = 0;
7323 dsl_fs_stage_only.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7324 dsl_fs_stage_only.descriptorCount = 5;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007325 dsl_fs_stage_only.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; // Different stageFlags to cause error at
7326 // bind time
Karl Schultz6addd812016-02-02 17:17:23 -07007327 dsl_fs_stage_only.pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007328 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007329 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7330 ds_layout_ci.pNext = NULL;
7331 ds_layout_ci.bindingCount = 1;
7332 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007333 static const uint32_t NUM_LAYOUTS = 4;
7334 VkDescriptorSetLayout ds_layout[NUM_LAYOUTS] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007335 VkDescriptorSetLayout ds_layout_fs_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007336 // Create 4 unique layouts for full pipelineLayout, and 1 special fs-only
7337 // layout for error case
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007338 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[0]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007339 ASSERT_VK_SUCCESS(err);
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07007340 ds_layout_ci.pBindings = &dsl_fs_stage_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007341 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007342 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007343 dsl_binding[0].binding = 0;
7344 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007345 dsl_binding[0].descriptorCount = 2;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07007346 dsl_binding[1].binding = 1;
7347 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
7348 dsl_binding[1].descriptorCount = 2;
7349 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
7350 dsl_binding[1].pImmutableSamplers = NULL;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07007351 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007352 ds_layout_ci.bindingCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007353 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[1]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007354 ASSERT_VK_SUCCESS(err);
7355 dsl_binding[0].binding = 0;
7356 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007357 dsl_binding[0].descriptorCount = 5;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007358 ds_layout_ci.bindingCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007359 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[2]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007360 ASSERT_VK_SUCCESS(err);
7361 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007362 dsl_binding[0].descriptorCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007363 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[3]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007364 ASSERT_VK_SUCCESS(err);
7365
7366 static const uint32_t NUM_SETS = 4;
7367 VkDescriptorSet descriptorSet[NUM_SETS] = {};
7368 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007369 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007370 alloc_info.descriptorSetCount = NUM_LAYOUTS;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007371 alloc_info.descriptorPool = ds_pool;
7372 alloc_info.pSetLayouts = ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007373 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptorSet);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007374 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007375 VkDescriptorSet ds0_fs_only = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07007376 alloc_info.descriptorSetCount = 1;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007377 alloc_info.pSetLayouts = &ds_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007378 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &ds0_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007379 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007380
7381 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007382 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7383 pipeline_layout_ci.pNext = NULL;
7384 pipeline_layout_ci.setLayoutCount = NUM_LAYOUTS;
7385 pipeline_layout_ci.pSetLayouts = ds_layout;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007386
7387 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007388 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007389 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007390 // Create pipelineLayout with only one setLayout
7391 pipeline_layout_ci.setLayoutCount = 1;
7392 VkPipelineLayout single_pipe_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007393 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &single_pipe_layout);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007394 ASSERT_VK_SUCCESS(err);
7395 // Create pipelineLayout with 2 descriptor setLayout at index 0
7396 pipeline_layout_ci.pSetLayouts = &ds_layout[3];
7397 VkPipelineLayout pipe_layout_one_desc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007398 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_one_desc);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007399 ASSERT_VK_SUCCESS(err);
7400 // Create pipelineLayout with 5 SAMPLER descriptor setLayout at index 0
7401 pipeline_layout_ci.pSetLayouts = &ds_layout[2];
7402 VkPipelineLayout pipe_layout_five_samp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007403 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_five_samp);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007404 ASSERT_VK_SUCCESS(err);
7405 // Create pipelineLayout with UB type, but stageFlags for FS only
7406 pipeline_layout_ci.pSetLayouts = &ds_layout_fs_only;
7407 VkPipelineLayout pipe_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007408 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007409 ASSERT_VK_SUCCESS(err);
7410 // Create pipelineLayout w/ incompatible set0 layout, but set1 is fine
7411 VkDescriptorSetLayout pl_bad_s0[2] = {};
7412 pl_bad_s0[0] = ds_layout_fs_only;
7413 pl_bad_s0[1] = ds_layout[1];
7414 pipeline_layout_ci.setLayoutCount = 2;
7415 pipeline_layout_ci.pSetLayouts = pl_bad_s0;
7416 VkPipelineLayout pipe_layout_bad_set0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007417 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_bad_set0);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007418 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007419
Tobin Ehlis88452832015-12-03 09:40:56 -07007420 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007421 char const *vsSource =
7422 "#version 450\n"
7423 "\n"
7424 "out gl_PerVertex {\n"
7425 " vec4 gl_Position;\n"
7426 "};\n"
7427 "void main(){\n"
7428 " gl_Position = vec4(1);\n"
7429 "}\n";
7430 char const *fsSource =
7431 "#version 450\n"
7432 "\n"
7433 "layout(location=0) out vec4 x;\n"
7434 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
7435 "void main(){\n"
7436 " x = vec4(bar.y);\n"
7437 "}\n";
Tobin Ehlis88452832015-12-03 09:40:56 -07007438 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
7439 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007440 VkPipelineObj pipe(m_device);
7441 pipe.AddShader(&vs);
7442 pipe.AddShader(&fs);
Tobin Ehlis88452832015-12-03 09:40:56 -07007443 pipe.AddColorAttachment();
7444 pipe.CreateVKPipeline(pipe_layout_fs_only, renderPass());
Tobin Ehlis559c6382015-11-05 09:52:49 -07007445
Tony Barbour552f6c02016-12-21 14:34:07 -07007446 m_commandBuffer->BeginCommandBuffer();
7447 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis88452832015-12-03 09:40:56 -07007448
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007449 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07007450 // NOTE : I believe LunarG ilo driver has bug (LX#189) that requires binding
7451 // of PSO
7452 // here before binding DSs. Otherwise we assert in cmd_copy_dset_data() of
7453 // cmd_pipeline.c
7454 // due to the fact that cmd_alloc_dset_data() has not been called in
7455 // cmd_bind_graphics_pipeline()
7456 // TODO : Want to cause various binding incompatibility issues here to test
7457 // DrawState
Tobin Ehlis559c6382015-11-05 09:52:49 -07007458 // First cause various verify_layout_compatibility() fails
7459 // Second disturb early and late sets and verify INFO msgs
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007460 // verify_set_layout_compatibility fail cases:
7461 // 1. invalid VkPipelineLayout (layout) passed into vkCmdBindDescriptorSets
Karl Schultzf78bcdd2016-11-30 12:36:01 -07007462 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00981);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007463 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
7464 (VkPipelineLayout)((size_t)0xbaadb1be), 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007465 m_errorMonitor->VerifyFound();
7466
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007467 // 2. layoutIndex exceeds # of layouts in layout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007468 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempting to bind set to index 1");
7469 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, single_pipe_layout, 0, 2,
7470 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007471 m_errorMonitor->VerifyFound();
7472
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007473 vkDestroyPipelineLayout(m_device->device(), single_pipe_layout, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07007474 // 3. Pipeline setLayout[0] has 2 descriptors, but set being bound has 5
7475 // descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007476 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has 2 descriptors, but DescriptorSetLayout ");
7477 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_one_desc, 0, 1,
7478 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007479 m_errorMonitor->VerifyFound();
7480
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007481 vkDestroyPipelineLayout(m_device->device(), pipe_layout_one_desc, NULL);
7482 // 4. same # of descriptors but mismatch in type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007483 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is type 'VK_DESCRIPTOR_TYPE_SAMPLER' but binding ");
7484 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_five_samp, 0, 1,
7485 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007486 m_errorMonitor->VerifyFound();
7487
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007488 vkDestroyPipelineLayout(m_device->device(), pipe_layout_five_samp, NULL);
7489 // 5. same # of descriptors but mismatch in stageFlags
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007490 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7491 " has stageFlags 16 but binding 0 for DescriptorSetLayout ");
7492 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
7493 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007494 m_errorMonitor->VerifyFound();
7495
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007496 // Cause INFO messages due to disturbing previously bound Sets
7497 // First bind sets 0 & 1
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007498 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
7499 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007500 // 1. Disturb bound set0 by re-binding set1 w/ updated pipelineLayout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007501 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " previously bound as set #0 was disturbed ");
7502 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
7503 &descriptorSet[1], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007504 m_errorMonitor->VerifyFound();
7505
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007506 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
7507 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007508 // 2. Disturb set after last bound set
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007509 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
7510 " newly bound as set #0 so set #1 and "
7511 "any subsequent sets were disturbed ");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007512 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
7513 &ds0_fs_only, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007514 m_errorMonitor->VerifyFound();
7515
Tobin Ehlis10fad692016-07-07 12:00:36 -06007516 // Now that we're done actively using the pipelineLayout that gfx pipeline
7517 // was created with, we should be able to delete it. Do that now to verify
7518 // that validation obeys pipelineLayout lifetime
7519 vkDestroyPipelineLayout(m_device->device(), pipe_layout_fs_only, NULL);
7520
Tobin Ehlis88452832015-12-03 09:40:56 -07007521 // Cause draw-time errors due to PSO incompatibilities
Karl Schultz6addd812016-02-02 17:17:23 -07007522 // 1. Error due to not binding required set (we actually use same code as
7523 // above to disturb set0)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007524 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
7525 &descriptorSet[0], 0, NULL);
7526 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
7527 &descriptorSet[1], 0, NULL);
7528 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " uses set #0 but that set is not bound.");
Rene Lindsay9f228e42017-01-16 13:57:45 -07007529
7530 VkViewport viewport = {0, 0, 16, 16, 0, 1};
7531 VkRect2D scissor = {{0, 0}, {16, 16}};
7532 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
7533 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
7534
Tobin Ehlis88452832015-12-03 09:40:56 -07007535 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007536 m_errorMonitor->VerifyFound();
7537
Tobin Ehlis991d45a2016-01-06 08:48:41 -07007538 vkDestroyPipelineLayout(m_device->device(), pipe_layout_bad_set0, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07007539 // 2. Error due to bound set not being compatible with PSO's
7540 // VkPipelineLayout (diff stageFlags in this case)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007541 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
7542 &descriptorSet[0], 0, NULL);
7543 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " bound as set #0 is not compatible with ");
Tobin Ehlis88452832015-12-03 09:40:56 -07007544 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007545 m_errorMonitor->VerifyFound();
7546
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007547 // Remaining clean-up
Karl Schultz6addd812016-02-02 17:17:23 -07007548 for (uint32_t i = 0; i < NUM_LAYOUTS; ++i) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007549 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout[i], NULL);
7550 }
7551 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_fs_only, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007552 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7553 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
7554}
Tobin Ehlis559c6382015-11-05 09:52:49 -07007555
Karl Schultz6addd812016-02-02 17:17:23 -07007556TEST_F(VkLayerTest, NoBeginCommandBuffer) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007557 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7558 "You must call vkBeginCommandBuffer() before this call to ");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007559
Tony Barbour1fa09702017-03-16 12:09:08 -06007560 ASSERT_NO_FATAL_FAILURE(Init());
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007561 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007562 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007563 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007564
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007565 m_errorMonitor->VerifyFound();
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007566}
7567
Karl Schultz6addd812016-02-02 17:17:23 -07007568TEST_F(VkLayerTest, SecondaryCommandBufferNullRenderpass) {
7569 VkResult err;
7570 VkCommandBuffer draw_cmd;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007571
Karl Schultzf78bcdd2016-11-30 12:36:01 -07007572 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00110);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007573
Tony Barbour1fa09702017-03-16 12:09:08 -06007574 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06007575
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007576 VkCommandBufferAllocateInfo cmd = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007577 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06007578 cmd.pNext = NULL;
Mike Schuchardt06304c22017-03-01 17:09:09 -07007579 cmd.commandPool = m_commandPool->handle();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007580 cmd.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007581 cmd.commandBufferCount = 1;
Cody Northropb4569702015-08-04 17:35:57 -06007582
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007583 err = vkAllocateCommandBuffers(m_device->device(), &cmd, &draw_cmd);
Mike Stroyand1c84a52015-08-18 14:40:24 -06007584 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06007585
7586 // Force the failure by not setting the Renderpass and Framebuffer fields
Jon Ashburnf19916e2016-01-11 13:12:43 -07007587 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Rene Lindsay65072a92017-01-23 11:38:10 -07007588 cmd_buf_hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
7589
7590 VkCommandBufferBeginInfo cmd_buf_info = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007591 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06007592 cmd_buf_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007593 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 -07007594 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06007595
7596 // The error should be caught by validation of the BeginCommandBuffer call
7597 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
7598
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007599 m_errorMonitor->VerifyFound();
Mike Schuchardt06304c22017-03-01 17:09:09 -07007600 vkFreeCommandBuffers(m_device->device(), m_commandPool->handle(), 1, &draw_cmd);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06007601}
7602
Chris Forbes5b3725e2017-05-18 16:01:20 -07007603TEST_F(VkLayerTest, SecondaryCommandBufferRerecordedExplicitReset) {
Chris Forbes9480ae92017-05-17 17:14:34 -07007604 ASSERT_NO_FATAL_FAILURE(Init());
7605
Chris Forbes5b3725e2017-05-18 16:01:20 -07007606 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was destroyed or rerecorded");
Chris Forbes9480ae92017-05-17 17:14:34 -07007607
7608 // A pool we can reset in.
7609 VkCommandPoolObj pool(m_device, m_device->graphics_queue_node_index_,
7610 VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT);
7611 VkCommandBufferObj secondary(m_device, &pool,
7612 VK_COMMAND_BUFFER_LEVEL_SECONDARY);
7613
7614 secondary.begin();
7615 secondary.end();
7616
7617 m_commandBuffer->begin();
7618 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary.handle());
7619
7620 // rerecording of secondary
Chris Forbes5b3725e2017-05-18 16:01:20 -07007621 secondary.reset(); // explicit reset here.
Chris Forbes9480ae92017-05-17 17:14:34 -07007622 secondary.begin();
7623 secondary.end();
7624
7625 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary.handle());
Chris Forbes5b3725e2017-05-18 16:01:20 -07007626 m_errorMonitor->VerifyFound();
7627}
Chris Forbes9480ae92017-05-17 17:14:34 -07007628
Chris Forbes5b3725e2017-05-18 16:01:20 -07007629TEST_F(VkLayerTest, SecondaryCommandBufferRerecordedNoReset) {
7630 ASSERT_NO_FATAL_FAILURE(Init());
7631
7632 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was destroyed or rerecorded");
7633
7634 // A pool we can reset in.
7635 VkCommandPoolObj pool(m_device, m_device->graphics_queue_node_index_,
7636 VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT);
7637 VkCommandBufferObj secondary(m_device, &pool,
7638 VK_COMMAND_BUFFER_LEVEL_SECONDARY);
7639
7640 secondary.begin();
7641 secondary.end();
7642
7643 m_commandBuffer->begin();
7644 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary.handle());
7645
7646 // rerecording of secondary
7647 secondary.begin(); // implicit reset in begin
7648 secondary.end();
7649
7650 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary.handle());
Chris Forbes9480ae92017-05-17 17:14:34 -07007651 m_errorMonitor->VerifyFound();
7652}
7653
Chris Forbes42bbfe22017-05-18 16:20:53 -07007654TEST_F(VkLayerTest, CascadedInvalidation) {
7655 ASSERT_NO_FATAL_FAILURE(Init());
7656
7657 VkEventCreateInfo eci = { VK_STRUCTURE_TYPE_EVENT_CREATE_INFO, nullptr, 0 };
7658 VkEvent event;
7659 vkCreateEvent(m_device->device(), &eci, nullptr, &event);
7660
7661 VkCommandBufferObj secondary(m_device, m_commandPool, VK_COMMAND_BUFFER_LEVEL_SECONDARY);
7662 secondary.begin();
7663 vkCmdSetEvent(secondary.handle(), event, VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT);
7664 secondary.end();
7665
7666 m_commandBuffer->begin();
7667 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary.handle());
7668 m_commandBuffer->end();
7669
7670 // destroying the event should invalidate both primary and secondary CB
7671 vkDestroyEvent(m_device->device(), event, nullptr);
7672
7673 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "invalid because bound Event");
7674 m_commandBuffer->QueueCommandBuffer(false);
7675 m_errorMonitor->VerifyFound();
7676}
7677
Karl Schultz6addd812016-02-02 17:17:23 -07007678TEST_F(VkLayerTest, CommandBufferResetErrors) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007679 // Cause error due to Begin while recording CB
7680 // Then cause 2 errors for attempting to reset CB w/o having
7681 // VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT set for the pool from
7682 // which CBs were allocated. Note that this bit is off by default.
Mike Weiblencce7ec72016-10-17 19:33:05 -06007683 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call Begin on command buffer");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007684
Tony Barbour1fa09702017-03-16 12:09:08 -06007685 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007686
7687 // Calls AllocateCommandBuffers
7688 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
7689
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07007690 // Force the failure by setting the Renderpass and Framebuffer fields with (fake) data
Jon Ashburnf19916e2016-01-11 13:12:43 -07007691 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07007692 cmd_buf_hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
7693 VkCommandBufferBeginInfo cmd_buf_info = {};
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007694 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
7695 cmd_buf_info.pNext = NULL;
7696 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007697 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007698
7699 // Begin CB to transition to recording state
7700 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
7701 // Can't re-begin. This should trigger error
7702 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007703 m_errorMonitor->VerifyFound();
7704
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07007705 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00093);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007706 VkCommandBufferResetFlags flags = 0; // Don't care about flags for this test
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007707 // Reset attempt will trigger error due to incorrect CommandPool state
7708 vkResetCommandBuffer(commandBuffer.GetBufferHandle(), flags);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007709 m_errorMonitor->VerifyFound();
7710
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07007711 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00105);
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007712 // Transition CB to RECORDED state
7713 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
7714 // Now attempting to Begin will implicitly reset, which triggers error
7715 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007716 m_errorMonitor->VerifyFound();
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007717}
7718
Karl Schultz6addd812016-02-02 17:17:23 -07007719TEST_F(VkLayerTest, InvalidPipelineCreateState) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007720 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07007721 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007722
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07007723 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7724 "Invalid Pipeline CreateInfo State: Vertex Shader required");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007725
Tony Barbour1fa09702017-03-16 12:09:08 -06007726 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06007727 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06007728
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007729 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007730 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7731 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06007732
7733 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007734 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7735 ds_pool_ci.pNext = NULL;
7736 ds_pool_ci.maxSets = 1;
7737 ds_pool_ci.poolSizeCount = 1;
7738 ds_pool_ci.pPoolSizes = &ds_type_count;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06007739
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007740 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007741 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007742 ASSERT_VK_SUCCESS(err);
7743
Tony Barboureb254902015-07-15 12:50:33 -06007744 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007745 dsl_binding.binding = 0;
7746 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7747 dsl_binding.descriptorCount = 1;
7748 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7749 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007750
Tony Barboureb254902015-07-15 12:50:33 -06007751 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007752 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7753 ds_layout_ci.pNext = NULL;
7754 ds_layout_ci.bindingCount = 1;
7755 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06007756
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007757 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007758 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007759 ASSERT_VK_SUCCESS(err);
7760
7761 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007762 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007763 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007764 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007765 alloc_info.descriptorPool = ds_pool;
7766 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007767 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007768 ASSERT_VK_SUCCESS(err);
7769
Tony Barboureb254902015-07-15 12:50:33 -06007770 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007771 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7772 pipeline_layout_ci.setLayoutCount = 1;
7773 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007774
7775 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007776 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007777 ASSERT_VK_SUCCESS(err);
7778
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007779 VkViewport vp = {}; // Just need dummy vp to point to
7780 VkRect2D sc = {}; // dummy scissor to point to
Tobin Ehlise68360f2015-10-01 11:15:13 -06007781
7782 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007783 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7784 vp_state_ci.scissorCount = 1;
7785 vp_state_ci.pScissors = &sc;
7786 vp_state_ci.viewportCount = 1;
7787 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007788
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007789 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7790 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7791 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7792 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7793 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7794 rs_state_ci.depthClampEnable = VK_FALSE;
Rene Lindsayae4977b2017-01-23 14:55:54 -07007795 rs_state_ci.rasterizerDiscardEnable = VK_TRUE;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007796 rs_state_ci.depthBiasEnable = VK_FALSE;
Rene Lindsayae4977b2017-01-23 14:55:54 -07007797 rs_state_ci.lineWidth = 1.0f;
7798
7799 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7800 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7801 vi_ci.pNext = nullptr;
7802 vi_ci.vertexBindingDescriptionCount = 0;
7803 vi_ci.pVertexBindingDescriptions = nullptr;
7804 vi_ci.vertexAttributeDescriptionCount = 0;
7805 vi_ci.pVertexAttributeDescriptions = nullptr;
7806
7807 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7808 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7809 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7810
7811 VkPipelineShaderStageCreateInfo shaderStages[2];
7812 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7813
7814 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7815 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Dave Houlton59a20702017-02-02 17:26:23 -07007816 shaderStages[0] = fs.GetStageCreateInfo(); // should be: vs.GetStageCreateInfo();
Rene Lindsayae4977b2017-01-23 14:55:54 -07007817 shaderStages[1] = fs.GetStageCreateInfo();
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007818
Tony Barboureb254902015-07-15 12:50:33 -06007819 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007820 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7821 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007822 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007823 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7824 gp_ci.layout = pipeline_layout;
7825 gp_ci.renderPass = renderPass();
Rene Lindsayae4977b2017-01-23 14:55:54 -07007826 gp_ci.pVertexInputState = &vi_ci;
7827 gp_ci.pInputAssemblyState = &ia_ci;
7828
7829 gp_ci.stageCount = 1;
7830 gp_ci.pStages = shaderStages;
Tony Barboureb254902015-07-15 12:50:33 -06007831
7832 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007833 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7834 pc_ci.initialDataSize = 0;
7835 pc_ci.pInitialData = 0;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007836
7837 VkPipeline pipeline;
Jon Ashburnc669cc62015-07-09 15:02:25 -06007838 VkPipelineCache pipelineCache;
7839
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007840 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Jon Ashburnc669cc62015-07-09 15:02:25 -06007841 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007842 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007843 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007844
Chia-I Wuf7458c52015-10-26 21:10:41 +08007845 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7846 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7847 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7848 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007849}
Rene Lindsayae4977b2017-01-23 14:55:54 -07007850
Tobin Ehlis912df022015-09-17 08:46:18 -06007851/*// TODO : This test should be good, but needs Tess support in compiler to run
7852TEST_F(VkLayerTest, InvalidPatchControlPoints)
7853{
7854 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis912df022015-09-17 08:46:18 -06007855 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007856
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07007857 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07007858 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH
7859primitive ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007860
Tony Barbour1fa09702017-03-16 12:09:08 -06007861 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis912df022015-09-17 08:46:18 -06007862 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis912df022015-09-17 08:46:18 -06007863
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007864 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis912df022015-09-17 08:46:18 -06007865 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007866 ds_type_count.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007867
7868 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7869 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7870 ds_pool_ci.pNext = NULL;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007871 ds_pool_ci.poolSizeCount = 1;
7872 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis912df022015-09-17 08:46:18 -06007873
7874 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07007875 err = vkCreateDescriptorPool(m_device->device(),
7876VK_DESCRIPTOR_POOL_USAGE_NON_FREE, 1, &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis912df022015-09-17 08:46:18 -06007877 ASSERT_VK_SUCCESS(err);
7878
7879 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08007880 dsl_binding.binding = 0;
Tobin Ehlis912df022015-09-17 08:46:18 -06007881 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08007882 dsl_binding.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007883 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7884 dsl_binding.pImmutableSamplers = NULL;
7885
7886 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007887 ds_layout_ci.sType =
7888VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06007889 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007890 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07007891 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis912df022015-09-17 08:46:18 -06007892
7893 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007894 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
7895&ds_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06007896 ASSERT_VK_SUCCESS(err);
7897
7898 VkDescriptorSet descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07007899 err = vkAllocateDescriptorSets(m_device->device(), ds_pool,
7900VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet);
Tobin Ehlis912df022015-09-17 08:46:18 -06007901 ASSERT_VK_SUCCESS(err);
7902
7903 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007904 pipeline_layout_ci.sType =
7905VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06007906 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007907 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007908 pipeline_layout_ci.pSetLayouts = &ds_layout;
7909
7910 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007911 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
7912&pipeline_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06007913 ASSERT_VK_SUCCESS(err);
7914
7915 VkPipelineShaderStageCreateInfo shaderStages[3];
7916 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
7917
Karl Schultz6addd812016-02-02 17:17:23 -07007918 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT,
7919this);
Tobin Ehlis912df022015-09-17 08:46:18 -06007920 // Just using VS txt for Tess shaders as we don't care about functionality
Karl Schultz6addd812016-02-02 17:17:23 -07007921 VkShaderObj
7922tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
7923this);
7924 VkShaderObj
7925te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT,
7926this);
Tobin Ehlis912df022015-09-17 08:46:18 -06007927
Karl Schultz6addd812016-02-02 17:17:23 -07007928 shaderStages[0].sType =
7929VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007930 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007931 shaderStages[0].shader = vs.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07007932 shaderStages[1].sType =
7933VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007934 shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007935 shaderStages[1].shader = tc.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07007936 shaderStages[2].sType =
7937VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007938 shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007939 shaderStages[2].shader = te.handle();
7940
7941 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007942 iaCI.sType =
7943VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Chia-I Wu515eb8f2015-10-31 00:31:16 +08007944 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST;
Tobin Ehlis912df022015-09-17 08:46:18 -06007945
7946 VkPipelineTessellationStateCreateInfo tsCI = {};
7947 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
7948 tsCI.patchControlPoints = 0; // This will cause an error
7949
7950 VkGraphicsPipelineCreateInfo gp_ci = {};
7951 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7952 gp_ci.pNext = NULL;
7953 gp_ci.stageCount = 3;
7954 gp_ci.pStages = shaderStages;
7955 gp_ci.pVertexInputState = NULL;
7956 gp_ci.pInputAssemblyState = &iaCI;
7957 gp_ci.pTessellationState = &tsCI;
7958 gp_ci.pViewportState = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007959 gp_ci.pRasterizationState = NULL;
Tobin Ehlis912df022015-09-17 08:46:18 -06007960 gp_ci.pMultisampleState = NULL;
7961 gp_ci.pDepthStencilState = NULL;
7962 gp_ci.pColorBlendState = NULL;
7963 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7964 gp_ci.layout = pipeline_layout;
7965 gp_ci.renderPass = renderPass();
7966
7967 VkPipelineCacheCreateInfo pc_ci = {};
7968 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7969 pc_ci.pNext = NULL;
7970 pc_ci.initialSize = 0;
7971 pc_ci.initialData = 0;
7972 pc_ci.maxSize = 0;
7973
7974 VkPipeline pipeline;
7975 VkPipelineCache pipelineCache;
7976
Karl Schultz6addd812016-02-02 17:17:23 -07007977 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL,
7978&pipelineCache);
Tobin Ehlis912df022015-09-17 08:46:18 -06007979 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07007980 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
7981&gp_ci, NULL, &pipeline);
Tobin Ehlis912df022015-09-17 08:46:18 -06007982
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007983 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007984
Chia-I Wuf7458c52015-10-26 21:10:41 +08007985 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7986 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7987 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7988 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis912df022015-09-17 08:46:18 -06007989}
7990*/
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007991
Mark Lobodzinski510aa5c2016-12-19 07:59:10 -07007992TEST_F(VkLayerTest, PSOViewportScissorCountTests) {
Karl Schultz6addd812016-02-02 17:17:23 -07007993 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007994
Mark Lobodzinski510aa5c2016-12-19 07:59:10 -07007995 TEST_DESCRIPTION("Test various cases of viewport and scissor count validation");
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007996
Tony Barbour1fa09702017-03-16 12:09:08 -06007997 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007998 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007999
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008000 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008001 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8002 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008003
8004 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008005 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8006 ds_pool_ci.maxSets = 1;
8007 ds_pool_ci.poolSizeCount = 1;
8008 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008009
8010 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008011 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008012 ASSERT_VK_SUCCESS(err);
8013
8014 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008015 dsl_binding.binding = 0;
8016 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8017 dsl_binding.descriptorCount = 1;
8018 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008019
8020 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008021 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8022 ds_layout_ci.bindingCount = 1;
8023 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008024
8025 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008026 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008027 ASSERT_VK_SUCCESS(err);
8028
8029 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008030 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008031 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008032 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008033 alloc_info.descriptorPool = ds_pool;
8034 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008035 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008036 ASSERT_VK_SUCCESS(err);
8037
8038 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008039 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8040 pipeline_layout_ci.setLayoutCount = 1;
8041 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008042
8043 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008044 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008045 ASSERT_VK_SUCCESS(err);
8046
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07008047 VkViewport vp = {};
Tobin Ehlise68360f2015-10-01 11:15:13 -06008048 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008049 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
Mark Lobodzinski510aa5c2016-12-19 07:59:10 -07008050 vp_state_ci.scissorCount = 1;
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07008051 vp_state_ci.viewportCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -07008052 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008053
Karl Schultzdfdb8d42016-03-08 10:30:21 -07008054 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
8055 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
8056 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
8057 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
8058 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
8059 rs_state_ci.depthClampEnable = VK_FALSE;
8060 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
8061 rs_state_ci.depthBiasEnable = VK_FALSE;
8062
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07008063 VkPipelineVertexInputStateCreateInfo vi_ci = {};
8064 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
8065 vi_ci.pNext = nullptr;
8066 vi_ci.vertexBindingDescriptionCount = 0;
8067 vi_ci.pVertexBindingDescriptions = nullptr;
8068 vi_ci.vertexAttributeDescriptionCount = 0;
8069 vi_ci.pVertexAttributeDescriptions = nullptr;
8070
8071 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
8072 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
8073 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
8074
8075 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
8076 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
8077 pipe_ms_state_ci.pNext = NULL;
8078 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
8079 pipe_ms_state_ci.sampleShadingEnable = 0;
8080 pipe_ms_state_ci.minSampleShading = 1.0;
8081 pipe_ms_state_ci.pSampleMask = NULL;
8082
Cody Northropeb3a6c12015-10-05 14:44:45 -06008083 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07008084 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06008085
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008086 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07008087 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chia-I Wu28e06912015-10-31 00:31:16 +08008088 shaderStages[0] = vs.GetStageCreateInfo();
8089 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06008090
8091 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008092 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8093 gp_ci.stageCount = 2;
8094 gp_ci.pStages = shaderStages;
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07008095 gp_ci.pVertexInputState = &vi_ci;
8096 gp_ci.pInputAssemblyState = &ia_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07008097 gp_ci.pViewportState = &vp_state_ci;
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07008098 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07008099 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07008100 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
8101 gp_ci.layout = pipeline_layout;
8102 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06008103
8104 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008105 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008106
8107 VkPipeline pipeline;
8108 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008109 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008110 ASSERT_VK_SUCCESS(err);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008111
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07008112 if (!m_device->phy().features().multiViewport) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07008113 printf(" MultiViewport feature is disabled -- skipping enabled-state checks.\n");
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07008114
8115 // Check case where multiViewport is disabled and viewport count is not 1
8116 // We check scissor/viewport simultaneously since separating them would trigger the mismatch error, 1434.
8117 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01430);
8118 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01431);
8119 vp_state_ci.scissorCount = 0;
8120 vp_state_ci.viewportCount = 0;
8121 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
8122 m_errorMonitor->VerifyFound();
8123 } else {
8124 if (m_device->props.limits.maxViewports == 1) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07008125 printf(" Device limit maxViewports is 1, skipping tests that require higher limits.\n");
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07008126 } else {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07008127 printf(" MultiViewport feature is enabled -- skipping disabled-state checks.\n");
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07008128
8129 // Check is that viewportcount and scissorcount match
8130 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01434);
8131 vp_state_ci.scissorCount = 1;
8132 vp_state_ci.viewportCount = m_device->props.limits.maxViewports;
8133 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
8134 m_errorMonitor->VerifyFound();
8135
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07008136 // Check case where multiViewport is enabled and viewport count is greater than max
8137 // We check scissor/viewport simultaneously since separating them would trigger the mismatch error, 1434.
8138 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01432);
8139 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01433);
8140 vp_state_ci.scissorCount = m_device->props.limits.maxViewports + 1;
8141 vp_state_ci.viewportCount = m_device->props.limits.maxViewports + 1;
8142 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
8143 m_errorMonitor->VerifyFound();
8144 }
8145 }
Tobin Ehlise68360f2015-10-01 11:15:13 -06008146
Chia-I Wuf7458c52015-10-26 21:10:41 +08008147 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
8148 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8149 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8150 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008151}
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07008152
8153// Don't set viewport state in PSO. This is an error b/c we always need this state for the counts even if the data is going to be
8154// set dynamically.
Karl Schultz6addd812016-02-02 17:17:23 -07008155TEST_F(VkLayerTest, PSOViewportStateNotSet) {
Karl Schultz6addd812016-02-02 17:17:23 -07008156 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008157
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07008158 TEST_DESCRIPTION("Create a graphics pipeline with rasterization enabled but no viewport state.");
8159
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07008160 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02113);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008161
Tony Barbour1fa09702017-03-16 12:09:08 -06008162 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlise68360f2015-10-01 11:15:13 -06008163 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06008164
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008165 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008166 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8167 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008168
8169 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008170 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8171 ds_pool_ci.maxSets = 1;
8172 ds_pool_ci.poolSizeCount = 1;
8173 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008174
8175 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008176 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008177 ASSERT_VK_SUCCESS(err);
8178
8179 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008180 dsl_binding.binding = 0;
8181 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8182 dsl_binding.descriptorCount = 1;
8183 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008184
8185 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008186 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8187 ds_layout_ci.bindingCount = 1;
8188 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008189
8190 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008191 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008192 ASSERT_VK_SUCCESS(err);
8193
8194 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008195 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008196 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008197 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008198 alloc_info.descriptorPool = ds_pool;
8199 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008200 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008201 ASSERT_VK_SUCCESS(err);
8202
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07008203 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
8204 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
8205 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
8206
8207 VkPipelineVertexInputStateCreateInfo vi_ci = {};
8208 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
8209 vi_ci.pNext = nullptr;
8210 vi_ci.vertexBindingDescriptionCount = 0;
8211 vi_ci.pVertexBindingDescriptions = nullptr;
8212 vi_ci.vertexAttributeDescriptionCount = 0;
8213 vi_ci.pVertexAttributeDescriptions = nullptr;
8214
8215 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
8216 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
8217 pipe_ms_state_ci.pNext = NULL;
8218 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
8219 pipe_ms_state_ci.sampleShadingEnable = 0;
8220 pipe_ms_state_ci.minSampleShading = 1.0;
8221 pipe_ms_state_ci.pSampleMask = NULL;
8222
Tobin Ehlise68360f2015-10-01 11:15:13 -06008223 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008224 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8225 pipeline_layout_ci.setLayoutCount = 1;
8226 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008227
8228 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008229 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008230 ASSERT_VK_SUCCESS(err);
8231
8232 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
8233 // Set scissor as dynamic to avoid second error
8234 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008235 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
8236 dyn_state_ci.dynamicStateCount = 1;
8237 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008238
Cody Northropeb3a6c12015-10-05 14:44:45 -06008239 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07008240 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06008241
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008242 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07008243 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
8244 // We shouldn't need a fragment shader but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08008245 shaderStages[0] = vs.GetStageCreateInfo();
8246 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06008247
Karl Schultzdfdb8d42016-03-08 10:30:21 -07008248 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
8249 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
8250 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
8251 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
8252 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
8253 rs_state_ci.depthClampEnable = VK_FALSE;
8254 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
8255 rs_state_ci.depthBiasEnable = VK_FALSE;
8256
Tobin Ehlise68360f2015-10-01 11:15:13 -06008257 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008258 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8259 gp_ci.stageCount = 2;
8260 gp_ci.pStages = shaderStages;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07008261 gp_ci.pRasterizationState = &rs_state_ci;
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07008262 // Not setting VP state w/o dynamic vp state should cause validation error
8263 gp_ci.pViewportState = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -07008264 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07008265 gp_ci.pVertexInputState = &vi_ci;
8266 gp_ci.pInputAssemblyState = &ia_ci;
8267 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07008268 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
8269 gp_ci.layout = pipeline_layout;
8270 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06008271
8272 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008273 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008274
8275 VkPipeline pipeline;
8276 VkPipelineCache pipelineCache;
8277
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008278 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008279 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008280 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008281
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008282 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06008283
Chia-I Wuf7458c52015-10-26 21:10:41 +08008284 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
8285 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8286 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8287 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008288}
Mark Lobodzinski73169e22016-12-16 14:01:17 -07008289
8290// Create PSO w/o non-zero viewportCount but no viewport data, then run second test where dynamic scissor count doesn't match PSO
8291// scissor count
Karl Schultz6addd812016-02-02 17:17:23 -07008292TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch) {
8293 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008294
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07008295 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02110);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008296
Tony Barbour1fa09702017-03-16 12:09:08 -06008297 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12008298
8299 if (!m_device->phy().features().multiViewport) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07008300 printf(" Device does not support multiple viewports/scissors; skipped.\n");
Chris Forbesc08a6ca2016-07-28 14:14:07 +12008301 return;
8302 }
8303
Tobin Ehlise68360f2015-10-01 11:15:13 -06008304 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06008305
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008306 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008307 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8308 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008309
8310 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008311 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8312 ds_pool_ci.maxSets = 1;
8313 ds_pool_ci.poolSizeCount = 1;
8314 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008315
8316 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008317 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008318 ASSERT_VK_SUCCESS(err);
8319
8320 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008321 dsl_binding.binding = 0;
8322 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8323 dsl_binding.descriptorCount = 1;
8324 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008325
8326 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008327 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8328 ds_layout_ci.bindingCount = 1;
8329 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008330
8331 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008332 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008333 ASSERT_VK_SUCCESS(err);
8334
8335 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008336 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008337 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008338 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008339 alloc_info.descriptorPool = ds_pool;
8340 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008341 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008342 ASSERT_VK_SUCCESS(err);
8343
8344 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008345 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8346 pipeline_layout_ci.setLayoutCount = 1;
8347 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008348
8349 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008350 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008351 ASSERT_VK_SUCCESS(err);
8352
8353 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008354 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
8355 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008356 vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error
Karl Schultz6addd812016-02-02 17:17:23 -07008357 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008358 vp_state_ci.pScissors = NULL; // Scissor is dynamic (below) so this won't cause error
Tobin Ehlise68360f2015-10-01 11:15:13 -06008359
8360 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
8361 // Set scissor as dynamic to avoid that error
8362 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008363 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
8364 dyn_state_ci.dynamicStateCount = 1;
8365 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008366
Mark Lobodzinski73169e22016-12-16 14:01:17 -07008367 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
8368 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
8369 pipe_ms_state_ci.pNext = NULL;
8370 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
8371 pipe_ms_state_ci.sampleShadingEnable = 0;
8372 pipe_ms_state_ci.minSampleShading = 1.0;
8373 pipe_ms_state_ci.pSampleMask = NULL;
8374
Cody Northropeb3a6c12015-10-05 14:44:45 -06008375 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07008376 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06008377
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008378 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski73169e22016-12-16 14:01:17 -07008379 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
8380 // We shouldn't need a fragment shader but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08008381 shaderStages[0] = vs.GetStageCreateInfo();
8382 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06008383
Cody Northropf6622dc2015-10-06 10:33:21 -06008384 VkPipelineVertexInputStateCreateInfo vi_ci = {};
8385 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
8386 vi_ci.pNext = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008387 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06008388 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008389 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06008390 vi_ci.pVertexAttributeDescriptions = nullptr;
8391
8392 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
8393 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
8394 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
8395
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008396 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008397 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Mark Lobodzinski73169e22016-12-16 14:01:17 -07008398 rs_ci.lineWidth = m_device->props.limits.lineWidthRange[0];
Cody Northropf6622dc2015-10-06 10:33:21 -06008399 rs_ci.pNext = nullptr;
8400
Mark Youngc89c6312016-03-31 16:03:20 -06008401 VkPipelineColorBlendAttachmentState att = {};
8402 att.blendEnable = VK_FALSE;
8403 att.colorWriteMask = 0xf;
8404
Cody Northropf6622dc2015-10-06 10:33:21 -06008405 VkPipelineColorBlendStateCreateInfo cb_ci = {};
8406 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
8407 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06008408 cb_ci.attachmentCount = 1;
8409 cb_ci.pAttachments = &att;
Cody Northropf6622dc2015-10-06 10:33:21 -06008410
Tobin Ehlise68360f2015-10-01 11:15:13 -06008411 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008412 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8413 gp_ci.stageCount = 2;
8414 gp_ci.pStages = shaderStages;
8415 gp_ci.pVertexInputState = &vi_ci;
8416 gp_ci.pInputAssemblyState = &ia_ci;
8417 gp_ci.pViewportState = &vp_state_ci;
8418 gp_ci.pRasterizationState = &rs_ci;
8419 gp_ci.pColorBlendState = &cb_ci;
8420 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski73169e22016-12-16 14:01:17 -07008421 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07008422 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
8423 gp_ci.layout = pipeline_layout;
8424 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06008425
8426 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008427 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008428
8429 VkPipeline pipeline;
8430 VkPipelineCache pipelineCache;
8431
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008432 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008433 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008434 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008435
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008436 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008437
Tobin Ehlisd332f282015-10-02 11:00:56 -06008438 // Now hit second fail case where we set scissor w/ different count than PSO
Karl Schultz6addd812016-02-02 17:17:23 -07008439 // First need to successfully create the PSO from above by setting
8440 // pViewports
Mike Weiblen95dd0f92016-10-19 12:28:27 -06008441 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 -07008442
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008443 VkViewport vp = {}; // Just need dummy vp to point to
Karl Schultz6addd812016-02-02 17:17:23 -07008444 vp_state_ci.pViewports = &vp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008445 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07008446 ASSERT_VK_SUCCESS(err);
Tony Barbour552f6c02016-12-21 14:34:07 -07008447 m_commandBuffer->BeginCommandBuffer();
8448 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008449 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008450 VkRect2D scissors[1] = {}; // don't care about data
Karl Schultz6addd812016-02-02 17:17:23 -07008451 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12008452 vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 1, 1, scissors);
Karl Schultz6addd812016-02-02 17:17:23 -07008453 Draw(1, 0, 0, 0);
8454
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008455 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07008456
8457 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
8458 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8459 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8460 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008461 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07008462}
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008463
8464// Create PSO w/o non-zero scissorCount but no scissor data, then run second test where dynamic viewportCount doesn't match PSO
Karl Schultz6addd812016-02-02 17:17:23 -07008465// viewportCount
8466TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch) {
8467 VkResult err;
8468
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07008469 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02111);
Karl Schultz6addd812016-02-02 17:17:23 -07008470
Tony Barbour1fa09702017-03-16 12:09:08 -06008471 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12008472
8473 if (!m_device->phy().features().multiViewport) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07008474 printf(" Device does not support multiple viewports/scissors; skipped.\n");
Chris Forbesc08a6ca2016-07-28 14:14:07 +12008475 return;
8476 }
8477
Karl Schultz6addd812016-02-02 17:17:23 -07008478 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8479
8480 VkDescriptorPoolSize ds_type_count = {};
8481 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8482 ds_type_count.descriptorCount = 1;
8483
8484 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8485 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8486 ds_pool_ci.maxSets = 1;
8487 ds_pool_ci.poolSizeCount = 1;
8488 ds_pool_ci.pPoolSizes = &ds_type_count;
8489
8490 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008491 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Karl Schultz6addd812016-02-02 17:17:23 -07008492 ASSERT_VK_SUCCESS(err);
8493
8494 VkDescriptorSetLayoutBinding dsl_binding = {};
8495 dsl_binding.binding = 0;
8496 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8497 dsl_binding.descriptorCount = 1;
8498 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8499
8500 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8501 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8502 ds_layout_ci.bindingCount = 1;
8503 ds_layout_ci.pBindings = &dsl_binding;
8504
8505 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008506 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07008507 ASSERT_VK_SUCCESS(err);
8508
8509 VkDescriptorSet descriptorSet;
8510 VkDescriptorSetAllocateInfo alloc_info = {};
8511 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8512 alloc_info.descriptorSetCount = 1;
8513 alloc_info.descriptorPool = ds_pool;
8514 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008515 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Karl Schultz6addd812016-02-02 17:17:23 -07008516 ASSERT_VK_SUCCESS(err);
8517
8518 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
8519 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8520 pipeline_layout_ci.setLayoutCount = 1;
8521 pipeline_layout_ci.pSetLayouts = &ds_layout;
8522
8523 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008524 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07008525 ASSERT_VK_SUCCESS(err);
8526
8527 VkPipelineViewportStateCreateInfo vp_state_ci = {};
8528 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
8529 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008530 vp_state_ci.pScissors = NULL; // Null scissor w/ count of 1 should cause error
Karl Schultz6addd812016-02-02 17:17:23 -07008531 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008532 vp_state_ci.pViewports = NULL; // vp is dynamic (below) so this won't cause error
Karl Schultz6addd812016-02-02 17:17:23 -07008533
8534 VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT;
8535 // Set scissor as dynamic to avoid that error
8536 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
8537 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
8538 dyn_state_ci.dynamicStateCount = 1;
8539 dyn_state_ci.pDynamicStates = &vp_state;
8540
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008541 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
8542 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
8543 pipe_ms_state_ci.pNext = NULL;
8544 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
8545 pipe_ms_state_ci.sampleShadingEnable = 0;
8546 pipe_ms_state_ci.minSampleShading = 1.0;
8547 pipe_ms_state_ci.pSampleMask = NULL;
8548
Karl Schultz6addd812016-02-02 17:17:23 -07008549 VkPipelineShaderStageCreateInfo shaderStages[2];
8550 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
8551
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008552 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008553 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
8554 // We shouldn't need a fragment shader but add it to be able to run on more devices
Karl Schultz6addd812016-02-02 17:17:23 -07008555 shaderStages[0] = vs.GetStageCreateInfo();
8556 shaderStages[1] = fs.GetStageCreateInfo();
8557
8558 VkPipelineVertexInputStateCreateInfo vi_ci = {};
8559 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
8560 vi_ci.pNext = nullptr;
8561 vi_ci.vertexBindingDescriptionCount = 0;
8562 vi_ci.pVertexBindingDescriptions = nullptr;
8563 vi_ci.vertexAttributeDescriptionCount = 0;
8564 vi_ci.pVertexAttributeDescriptions = nullptr;
8565
8566 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
8567 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
8568 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
8569
8570 VkPipelineRasterizationStateCreateInfo rs_ci = {};
8571 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008572 rs_ci.lineWidth = m_device->props.limits.lineWidthRange[0];
Karl Schultz6addd812016-02-02 17:17:23 -07008573 rs_ci.pNext = nullptr;
8574
Mark Youngc89c6312016-03-31 16:03:20 -06008575 VkPipelineColorBlendAttachmentState att = {};
8576 att.blendEnable = VK_FALSE;
8577 att.colorWriteMask = 0xf;
8578
Karl Schultz6addd812016-02-02 17:17:23 -07008579 VkPipelineColorBlendStateCreateInfo cb_ci = {};
8580 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
8581 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06008582 cb_ci.attachmentCount = 1;
8583 cb_ci.pAttachments = &att;
Karl Schultz6addd812016-02-02 17:17:23 -07008584
8585 VkGraphicsPipelineCreateInfo gp_ci = {};
8586 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8587 gp_ci.stageCount = 2;
8588 gp_ci.pStages = shaderStages;
8589 gp_ci.pVertexInputState = &vi_ci;
8590 gp_ci.pInputAssemblyState = &ia_ci;
8591 gp_ci.pViewportState = &vp_state_ci;
8592 gp_ci.pRasterizationState = &rs_ci;
8593 gp_ci.pColorBlendState = &cb_ci;
8594 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008595 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07008596 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
8597 gp_ci.layout = pipeline_layout;
8598 gp_ci.renderPass = renderPass();
8599
8600 VkPipelineCacheCreateInfo pc_ci = {};
8601 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
8602
8603 VkPipeline pipeline;
8604 VkPipelineCache pipelineCache;
8605
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008606 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Karl Schultz6addd812016-02-02 17:17:23 -07008607 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008608 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07008609
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008610 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07008611
8612 // Now hit second fail case where we set scissor w/ different count than PSO
8613 // First need to successfully create the PSO from above by setting
8614 // pViewports
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07008615 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8616 "Dynamic viewport(s) 0 are used by pipeline state object, ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008617
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008618 VkRect2D sc = {}; // Just need dummy vp to point to
Tobin Ehlisd332f282015-10-02 11:00:56 -06008619 vp_state_ci.pScissors = &sc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008620 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06008621 ASSERT_VK_SUCCESS(err);
Tony Barbour552f6c02016-12-21 14:34:07 -07008622 m_commandBuffer->BeginCommandBuffer();
8623 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008624 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008625 VkViewport viewports[1] = {};
8626 viewports[0].width = 8;
8627 viewports[0].height = 8;
Tobin Ehlisd332f282015-10-02 11:00:56 -06008628 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12008629 vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 1, 1, viewports);
Tobin Ehlisd332f282015-10-02 11:00:56 -06008630 Draw(1, 0, 0, 0);
8631
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008632 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06008633
Chia-I Wuf7458c52015-10-26 21:10:41 +08008634 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
8635 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8636 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8637 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008638 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008639}
8640
Mark Young7394fdd2016-03-31 14:56:43 -06008641TEST_F(VkLayerTest, PSOLineWidthInvalid) {
8642 VkResult err;
8643
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008644 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06008645
Tony Barbour1fa09702017-03-16 12:09:08 -06008646 ASSERT_NO_FATAL_FAILURE(Init());
Mark Young7394fdd2016-03-31 14:56:43 -06008647 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8648
8649 VkDescriptorPoolSize ds_type_count = {};
8650 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8651 ds_type_count.descriptorCount = 1;
8652
8653 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8654 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8655 ds_pool_ci.maxSets = 1;
8656 ds_pool_ci.poolSizeCount = 1;
8657 ds_pool_ci.pPoolSizes = &ds_type_count;
8658
8659 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008660 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Young7394fdd2016-03-31 14:56:43 -06008661 ASSERT_VK_SUCCESS(err);
8662
8663 VkDescriptorSetLayoutBinding dsl_binding = {};
8664 dsl_binding.binding = 0;
8665 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8666 dsl_binding.descriptorCount = 1;
8667 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8668
8669 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8670 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8671 ds_layout_ci.bindingCount = 1;
8672 ds_layout_ci.pBindings = &dsl_binding;
8673
8674 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008675 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06008676 ASSERT_VK_SUCCESS(err);
8677
8678 VkDescriptorSet descriptorSet;
8679 VkDescriptorSetAllocateInfo alloc_info = {};
8680 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8681 alloc_info.descriptorSetCount = 1;
8682 alloc_info.descriptorPool = ds_pool;
8683 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008684 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Young7394fdd2016-03-31 14:56:43 -06008685 ASSERT_VK_SUCCESS(err);
8686
8687 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
8688 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8689 pipeline_layout_ci.setLayoutCount = 1;
8690 pipeline_layout_ci.pSetLayouts = &ds_layout;
8691
8692 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008693 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06008694 ASSERT_VK_SUCCESS(err);
8695
8696 VkPipelineViewportStateCreateInfo vp_state_ci = {};
8697 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
8698 vp_state_ci.scissorCount = 1;
8699 vp_state_ci.pScissors = NULL;
8700 vp_state_ci.viewportCount = 1;
8701 vp_state_ci.pViewports = NULL;
8702
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008703 VkDynamicState dynamic_states[3] = {VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR, VK_DYNAMIC_STATE_LINE_WIDTH};
Mark Young7394fdd2016-03-31 14:56:43 -06008704 // Set scissor as dynamic to avoid that error
8705 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
8706 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
8707 dyn_state_ci.dynamicStateCount = 2;
8708 dyn_state_ci.pDynamicStates = dynamic_states;
8709
8710 VkPipelineShaderStageCreateInfo shaderStages[2];
8711 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
8712
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008713 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
8714 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT,
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008715 this); // TODO - We shouldn't need a fragment shader
8716 // but add it to be able to run on more devices
Mark Young7394fdd2016-03-31 14:56:43 -06008717 shaderStages[0] = vs.GetStageCreateInfo();
8718 shaderStages[1] = fs.GetStageCreateInfo();
8719
8720 VkPipelineVertexInputStateCreateInfo vi_ci = {};
8721 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
8722 vi_ci.pNext = nullptr;
8723 vi_ci.vertexBindingDescriptionCount = 0;
8724 vi_ci.pVertexBindingDescriptions = nullptr;
8725 vi_ci.vertexAttributeDescriptionCount = 0;
8726 vi_ci.pVertexAttributeDescriptions = nullptr;
8727
8728 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
8729 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
8730 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
8731
8732 VkPipelineRasterizationStateCreateInfo rs_ci = {};
8733 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
8734 rs_ci.pNext = nullptr;
Rene Lindsay144e4842017-01-20 14:27:15 -07008735 rs_ci.rasterizerDiscardEnable = VK_TRUE;
Mark Young7394fdd2016-03-31 14:56:43 -06008736
Mark Young47107952016-05-02 15:59:55 -06008737 // Check too low (line width of -1.0f).
8738 rs_ci.lineWidth = -1.0f;
Mark Young7394fdd2016-03-31 14:56:43 -06008739
8740 VkPipelineColorBlendAttachmentState att = {};
8741 att.blendEnable = VK_FALSE;
8742 att.colorWriteMask = 0xf;
8743
8744 VkPipelineColorBlendStateCreateInfo cb_ci = {};
8745 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
8746 cb_ci.pNext = nullptr;
8747 cb_ci.attachmentCount = 1;
8748 cb_ci.pAttachments = &att;
8749
8750 VkGraphicsPipelineCreateInfo gp_ci = {};
8751 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8752 gp_ci.stageCount = 2;
8753 gp_ci.pStages = shaderStages;
8754 gp_ci.pVertexInputState = &vi_ci;
8755 gp_ci.pInputAssemblyState = &ia_ci;
8756 gp_ci.pViewportState = &vp_state_ci;
8757 gp_ci.pRasterizationState = &rs_ci;
8758 gp_ci.pColorBlendState = &cb_ci;
8759 gp_ci.pDynamicState = &dyn_state_ci;
8760 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
8761 gp_ci.layout = pipeline_layout;
8762 gp_ci.renderPass = renderPass();
8763
8764 VkPipelineCacheCreateInfo pc_ci = {};
8765 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
8766
8767 VkPipeline pipeline;
8768 VkPipelineCache pipelineCache;
8769
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008770 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06008771 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008772 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06008773
8774 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06008775 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06008776
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008777 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06008778
8779 // Check too high (line width of 65536.0f).
8780 rs_ci.lineWidth = 65536.0f;
8781
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008782 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06008783 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008784 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06008785
8786 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06008787 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06008788
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008789 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06008790
8791 dyn_state_ci.dynamicStateCount = 3;
8792
8793 rs_ci.lineWidth = 1.0f;
8794
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008795 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06008796 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008797 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tony Barbour552f6c02016-12-21 14:34:07 -07008798 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008799 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06008800
8801 // Check too low with dynamic setting.
Mark Young47107952016-05-02 15:59:55 -06008802 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), -1.0f);
Mark Young7394fdd2016-03-31 14:56:43 -06008803 m_errorMonitor->VerifyFound();
8804
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008805 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06008806
8807 // Check too high with dynamic setting.
8808 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), 65536.0f);
8809 m_errorMonitor->VerifyFound();
Tony Barbour552f6c02016-12-21 14:34:07 -07008810 m_commandBuffer->EndCommandBuffer();
Mark Young7394fdd2016-03-31 14:56:43 -06008811
8812 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
8813 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8814 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8815 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008816 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06008817}
8818
Jeremy Hayes37f0cdd2017-05-04 18:08:49 -06008819TEST_F(VkLayerTest, VALIDATION_ERROR_01407) {
8820 TEST_DESCRIPTION("Test VALIDATION_ERROR_01407: binding must be less than VkPhysicalDeviceLimits::maxVertexInputBindings");
8821
8822 ASSERT_NO_FATAL_FAILURE(Init());
8823 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8824
8825 VkPipelineCache pipeline_cache;
8826 {
8827 VkPipelineCacheCreateInfo create_info{};
8828 create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
8829
8830 VkResult err = vkCreatePipelineCache(m_device->device(), &create_info, nullptr, &pipeline_cache);
8831 ASSERT_VK_SUCCESS(err);
8832 }
8833
8834 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
8835 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
8836
8837 VkPipelineShaderStageCreateInfo stages[2]{{}};
8838 stages[0] = vs.GetStageCreateInfo();
8839 stages[1] = fs.GetStageCreateInfo();
8840
8841 // Test when binding is greater than or equal to VkPhysicalDeviceLimits::maxVertexInputBindings.
8842 VkVertexInputBindingDescription vertex_input_binding_description{};
8843 vertex_input_binding_description.binding = m_device->props.limits.maxVertexInputBindings;
8844
8845 VkPipelineVertexInputStateCreateInfo vertex_input_state{};
8846 vertex_input_state.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
8847 vertex_input_state.pNext = nullptr;
8848 vertex_input_state.vertexBindingDescriptionCount = 1;
8849 vertex_input_state.pVertexBindingDescriptions = &vertex_input_binding_description;
8850 vertex_input_state.vertexAttributeDescriptionCount = 0;
8851 vertex_input_state.pVertexAttributeDescriptions = nullptr;
8852
8853 VkPipelineInputAssemblyStateCreateInfo input_assembly_state{};
8854 input_assembly_state.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
8855 input_assembly_state.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
8856
8857 VkViewport viewport{};
8858 VkPipelineViewportStateCreateInfo viewport_state{};
8859 viewport_state.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
8860 viewport_state.scissorCount = 1;
8861 viewport_state.viewportCount = 1;
8862 viewport_state.pViewports = &viewport;
8863
8864 VkPipelineMultisampleStateCreateInfo multisample_state{};
8865 multisample_state.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
8866 multisample_state.pNext = nullptr;
8867 multisample_state.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
8868 multisample_state.sampleShadingEnable = 0;
8869 multisample_state.minSampleShading = 1.0;
8870 multisample_state.pSampleMask = nullptr;
8871
8872 VkPipelineRasterizationStateCreateInfo rasterization_state{};
8873 rasterization_state.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
8874 rasterization_state.polygonMode = VK_POLYGON_MODE_FILL;
8875 rasterization_state.cullMode = VK_CULL_MODE_BACK_BIT;
8876 rasterization_state.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
8877 rasterization_state.depthClampEnable = VK_FALSE;
8878 rasterization_state.rasterizerDiscardEnable = VK_FALSE;
8879 rasterization_state.depthBiasEnable = VK_FALSE;
8880
8881 VkPipelineLayout pipeline_layout;
8882 {
8883 VkPipelineLayoutCreateInfo create_info{};
8884 create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8885 create_info.setLayoutCount = 0;
8886 create_info.pSetLayouts = nullptr;
8887
8888 VkResult err = vkCreatePipelineLayout(m_device->device(), &create_info, nullptr, &pipeline_layout);
8889 ASSERT_VK_SUCCESS(err);
8890 }
8891
8892 {
8893 VkGraphicsPipelineCreateInfo create_info{};
8894 create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8895 create_info.stageCount = 2;
8896 create_info.pStages = stages;
8897 create_info.pVertexInputState = &vertex_input_state;
8898 create_info.pInputAssemblyState = &input_assembly_state;
8899 create_info.pViewportState = &viewport_state;
8900 create_info.pMultisampleState = &multisample_state;
8901 create_info.pRasterizationState = &rasterization_state;
8902 create_info.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
8903 create_info.layout = pipeline_layout;
8904 create_info.renderPass = renderPass();
8905
8906 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01407);
8907 VkPipeline pipeline;
8908 vkCreateGraphicsPipelines(m_device->device(), pipeline_cache, 1, &create_info, nullptr, &pipeline);
8909 m_errorMonitor->VerifyFound();
8910 }
8911
8912 vkDestroyPipelineCache(m_device->device(), pipeline_cache, nullptr);
8913 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
8914}
8915
8916TEST_F(VkLayerTest, VALIDATION_ERROR_01408) {
8917 TEST_DESCRIPTION(
8918 "Test VALIDATION_ERROR_01408: stride must be less than or equal to VkPhysicalDeviceLimits::maxVertexInputBindingStride");
8919
8920 ASSERT_NO_FATAL_FAILURE(Init());
8921 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8922
8923 VkPipelineCache pipeline_cache;
8924 {
8925 VkPipelineCacheCreateInfo create_info{};
8926 create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
8927
8928 VkResult err = vkCreatePipelineCache(m_device->device(), &create_info, nullptr, &pipeline_cache);
8929 ASSERT_VK_SUCCESS(err);
8930 }
8931
8932 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
8933 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
8934
8935 VkPipelineShaderStageCreateInfo stages[2]{{}};
8936 stages[0] = vs.GetStageCreateInfo();
8937 stages[1] = fs.GetStageCreateInfo();
8938
8939 // Test when stride is greater than VkPhysicalDeviceLimits::maxVertexInputBindingStride.
8940 VkVertexInputBindingDescription vertex_input_binding_description{};
8941 vertex_input_binding_description.stride = m_device->props.limits.maxVertexInputBindingStride + 1;
8942
8943 VkPipelineVertexInputStateCreateInfo vertex_input_state{};
8944 vertex_input_state.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
8945 vertex_input_state.pNext = nullptr;
8946 vertex_input_state.vertexBindingDescriptionCount = 1;
8947 vertex_input_state.pVertexBindingDescriptions = &vertex_input_binding_description;
8948 vertex_input_state.vertexAttributeDescriptionCount = 0;
8949 vertex_input_state.pVertexAttributeDescriptions = nullptr;
8950
8951 VkPipelineInputAssemblyStateCreateInfo input_assembly_state{};
8952 input_assembly_state.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
8953 input_assembly_state.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
8954
8955 VkViewport viewport{};
8956 VkPipelineViewportStateCreateInfo viewport_state{};
8957 viewport_state.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
8958 viewport_state.scissorCount = 1;
8959 viewport_state.viewportCount = 1;
8960 viewport_state.pViewports = &viewport;
8961
8962 VkPipelineMultisampleStateCreateInfo multisample_state{};
8963 multisample_state.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
8964 multisample_state.pNext = nullptr;
8965 multisample_state.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
8966 multisample_state.sampleShadingEnable = 0;
8967 multisample_state.minSampleShading = 1.0;
8968 multisample_state.pSampleMask = nullptr;
8969
8970 VkPipelineRasterizationStateCreateInfo rasterization_state{};
8971 rasterization_state.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
8972 rasterization_state.polygonMode = VK_POLYGON_MODE_FILL;
8973 rasterization_state.cullMode = VK_CULL_MODE_BACK_BIT;
8974 rasterization_state.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
8975 rasterization_state.depthClampEnable = VK_FALSE;
8976 rasterization_state.rasterizerDiscardEnable = VK_FALSE;
8977 rasterization_state.depthBiasEnable = VK_FALSE;
8978
8979 VkPipelineLayout pipeline_layout;
8980 {
8981 VkPipelineLayoutCreateInfo create_info{};
8982 create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8983 create_info.setLayoutCount = 0;
8984 create_info.pSetLayouts = nullptr;
8985
8986 VkResult err = vkCreatePipelineLayout(m_device->device(), &create_info, nullptr, &pipeline_layout);
8987 ASSERT_VK_SUCCESS(err);
8988 }
8989
8990 {
8991 VkGraphicsPipelineCreateInfo create_info{};
8992 create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8993 create_info.stageCount = 2;
8994 create_info.pStages = stages;
8995 create_info.pVertexInputState = &vertex_input_state;
8996 create_info.pInputAssemblyState = &input_assembly_state;
8997 create_info.pViewportState = &viewport_state;
8998 create_info.pMultisampleState = &multisample_state;
8999 create_info.pRasterizationState = &rasterization_state;
9000 create_info.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
9001 create_info.layout = pipeline_layout;
9002 create_info.renderPass = renderPass();
9003
9004 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01408);
9005 VkPipeline pipeline;
9006 vkCreateGraphicsPipelines(m_device->device(), pipeline_cache, 1, &create_info, nullptr, &pipeline);
9007 m_errorMonitor->VerifyFound();
9008 }
9009
9010 vkDestroyPipelineCache(m_device->device(), pipeline_cache, nullptr);
9011 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
9012}
9013
Jeremy Hayes091e1ab2017-05-04 18:10:28 -06009014TEST_F(VkLayerTest, VALIDATION_ERROR_01410) {
9015 TEST_DESCRIPTION("Test VALIDATION_ERROR_01410: location must be less than VkPhysicalDeviceLimits::maxVertexInputAttributes");
9016
9017 ASSERT_NO_FATAL_FAILURE(Init());
9018 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9019
9020 VkPipelineCache pipeline_cache;
9021 {
9022 VkPipelineCacheCreateInfo create_info{};
9023 create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
9024
9025 VkResult err = vkCreatePipelineCache(m_device->device(), &create_info, nullptr, &pipeline_cache);
9026 ASSERT_VK_SUCCESS(err);
9027 }
9028
9029 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9030 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
9031
9032 VkPipelineShaderStageCreateInfo stages[2]{{}};
9033 stages[0] = vs.GetStageCreateInfo();
9034 stages[1] = fs.GetStageCreateInfo();
9035
9036 // Test when location is greater than or equal to VkPhysicalDeviceLimits::maxVertexInputAttributes.
9037 VkVertexInputAttributeDescription vertex_input_attribute_description{};
9038 vertex_input_attribute_description.location = m_device->props.limits.maxVertexInputAttributes;
9039
9040 VkPipelineVertexInputStateCreateInfo vertex_input_state{};
9041 vertex_input_state.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
9042 vertex_input_state.pNext = nullptr;
9043 vertex_input_state.vertexBindingDescriptionCount = 0;
9044 vertex_input_state.pVertexBindingDescriptions = nullptr;
9045 vertex_input_state.vertexAttributeDescriptionCount = 1;
9046 vertex_input_state.pVertexAttributeDescriptions = &vertex_input_attribute_description;
9047
9048 VkPipelineInputAssemblyStateCreateInfo input_assembly_state{};
9049 input_assembly_state.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
9050 input_assembly_state.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
9051
9052 VkViewport viewport{};
9053 VkPipelineViewportStateCreateInfo viewport_state{};
9054 viewport_state.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
9055 viewport_state.scissorCount = 1;
9056 viewport_state.viewportCount = 1;
9057 viewport_state.pViewports = &viewport;
9058
9059 VkPipelineMultisampleStateCreateInfo multisample_state{};
9060 multisample_state.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
9061 multisample_state.pNext = nullptr;
9062 multisample_state.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
9063 multisample_state.sampleShadingEnable = 0;
9064 multisample_state.minSampleShading = 1.0;
9065 multisample_state.pSampleMask = nullptr;
9066
9067 VkPipelineRasterizationStateCreateInfo rasterization_state{};
9068 rasterization_state.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
9069 rasterization_state.polygonMode = VK_POLYGON_MODE_FILL;
9070 rasterization_state.cullMode = VK_CULL_MODE_BACK_BIT;
9071 rasterization_state.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
9072 rasterization_state.depthClampEnable = VK_FALSE;
9073 rasterization_state.rasterizerDiscardEnable = VK_FALSE;
9074 rasterization_state.depthBiasEnable = VK_FALSE;
9075
9076 VkPipelineLayout pipeline_layout;
9077 {
9078 VkPipelineLayoutCreateInfo create_info{};
9079 create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9080 create_info.setLayoutCount = 0;
9081 create_info.pSetLayouts = nullptr;
9082
9083 VkResult err = vkCreatePipelineLayout(m_device->device(), &create_info, nullptr, &pipeline_layout);
9084 ASSERT_VK_SUCCESS(err);
9085 }
9086
9087 {
9088 VkGraphicsPipelineCreateInfo create_info{};
9089 create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
9090 create_info.stageCount = 2;
9091 create_info.pStages = stages;
9092 create_info.pVertexInputState = &vertex_input_state;
9093 create_info.pInputAssemblyState = &input_assembly_state;
9094 create_info.pViewportState = &viewport_state;
9095 create_info.pMultisampleState = &multisample_state;
9096 create_info.pRasterizationState = &rasterization_state;
9097 create_info.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
9098 create_info.layout = pipeline_layout;
9099 create_info.renderPass = renderPass();
9100
9101 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01410);
9102 VkPipeline pipeline;
9103 vkCreateGraphicsPipelines(m_device->device(), pipeline_cache, 1, &create_info, nullptr, &pipeline);
9104 m_errorMonitor->VerifyFound();
9105 }
9106
9107 vkDestroyPipelineCache(m_device->device(), pipeline_cache, nullptr);
9108 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
9109}
9110
9111TEST_F(VkLayerTest, VALIDATION_ERROR_01411) {
9112 TEST_DESCRIPTION("Test VALIDATION_ERROR_01411: binding must be less than VkPhysicalDeviceLimits::maxVertexInputBindings");
9113
9114 ASSERT_NO_FATAL_FAILURE(Init());
9115 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9116
9117 VkPipelineCache pipeline_cache;
9118 {
9119 VkPipelineCacheCreateInfo create_info{};
9120 create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
9121
9122 VkResult err = vkCreatePipelineCache(m_device->device(), &create_info, nullptr, &pipeline_cache);
9123 ASSERT_VK_SUCCESS(err);
9124 }
9125
9126 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9127 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
9128
9129 VkPipelineShaderStageCreateInfo stages[2]{{}};
9130 stages[0] = vs.GetStageCreateInfo();
9131 stages[1] = fs.GetStageCreateInfo();
9132
9133 // Test when binding is greater than or equal to VkPhysicalDeviceLimits::maxVertexInputBindings.
9134 VkVertexInputAttributeDescription vertex_input_attribute_description{};
9135 vertex_input_attribute_description.binding = m_device->props.limits.maxVertexInputBindings;
9136
9137 VkPipelineVertexInputStateCreateInfo vertex_input_state{};
9138 vertex_input_state.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
9139 vertex_input_state.pNext = nullptr;
9140 vertex_input_state.vertexBindingDescriptionCount = 0;
9141 vertex_input_state.pVertexBindingDescriptions = nullptr;
9142 vertex_input_state.vertexAttributeDescriptionCount = 1;
9143 vertex_input_state.pVertexAttributeDescriptions = &vertex_input_attribute_description;
9144
9145 VkPipelineInputAssemblyStateCreateInfo input_assembly_state{};
9146 input_assembly_state.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
9147 input_assembly_state.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
9148
9149 VkViewport viewport{};
9150 VkPipelineViewportStateCreateInfo viewport_state{};
9151 viewport_state.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
9152 viewport_state.scissorCount = 1;
9153 viewport_state.viewportCount = 1;
9154 viewport_state.pViewports = &viewport;
9155
9156 VkPipelineMultisampleStateCreateInfo multisample_state{};
9157 multisample_state.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
9158 multisample_state.pNext = nullptr;
9159 multisample_state.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
9160 multisample_state.sampleShadingEnable = 0;
9161 multisample_state.minSampleShading = 1.0;
9162 multisample_state.pSampleMask = nullptr;
9163
9164 VkPipelineRasterizationStateCreateInfo rasterization_state{};
9165 rasterization_state.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
9166 rasterization_state.polygonMode = VK_POLYGON_MODE_FILL;
9167 rasterization_state.cullMode = VK_CULL_MODE_BACK_BIT;
9168 rasterization_state.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
9169 rasterization_state.depthClampEnable = VK_FALSE;
9170 rasterization_state.rasterizerDiscardEnable = VK_FALSE;
9171 rasterization_state.depthBiasEnable = VK_FALSE;
9172
9173 VkPipelineLayout pipeline_layout;
9174 {
9175 VkPipelineLayoutCreateInfo create_info{};
9176 create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9177 create_info.setLayoutCount = 0;
9178 create_info.pSetLayouts = nullptr;
9179
9180 VkResult err = vkCreatePipelineLayout(m_device->device(), &create_info, nullptr, &pipeline_layout);
9181 ASSERT_VK_SUCCESS(err);
9182 }
9183
9184 {
9185 VkGraphicsPipelineCreateInfo create_info{};
9186 create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
9187 create_info.stageCount = 2;
9188 create_info.pStages = stages;
9189 create_info.pVertexInputState = &vertex_input_state;
9190 create_info.pInputAssemblyState = &input_assembly_state;
9191 create_info.pViewportState = &viewport_state;
9192 create_info.pMultisampleState = &multisample_state;
9193 create_info.pRasterizationState = &rasterization_state;
9194 create_info.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
9195 create_info.layout = pipeline_layout;
9196 create_info.renderPass = renderPass();
9197
9198 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01411);
9199 VkPipeline pipeline;
9200 vkCreateGraphicsPipelines(m_device->device(), pipeline_cache, 1, &create_info, nullptr, &pipeline);
9201 m_errorMonitor->VerifyFound();
9202 }
9203
9204 vkDestroyPipelineCache(m_device->device(), pipeline_cache, nullptr);
9205 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
9206}
9207
9208TEST_F(VkLayerTest, VALIDATION_ERROR_01412) {
9209 TEST_DESCRIPTION(
9210 "Test VALIDATION_ERROR_01412: offset must be less than or equal to VkPhysicalDeviceLimits::maxVertexInputAttributeOffset");
9211
9212 ASSERT_NO_FATAL_FAILURE(Init());
9213 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9214
9215 VkPipelineCache pipeline_cache;
9216 {
9217 VkPipelineCacheCreateInfo create_info{};
9218 create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
9219
9220 VkResult err = vkCreatePipelineCache(m_device->device(), &create_info, nullptr, &pipeline_cache);
9221 ASSERT_VK_SUCCESS(err);
9222 }
9223
9224 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9225 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
9226
9227 VkPipelineShaderStageCreateInfo stages[2]{{}};
9228 stages[0] = vs.GetStageCreateInfo();
9229 stages[1] = fs.GetStageCreateInfo();
9230
9231 // Test when offset is greater than maximum.
9232 VkVertexInputAttributeDescription vertex_input_attribute_description{};
9233 vertex_input_attribute_description.offset = m_device->props.limits.maxVertexInputAttributeOffset + 1;
9234
9235 VkPipelineVertexInputStateCreateInfo vertex_input_state{};
9236 vertex_input_state.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
9237 vertex_input_state.pNext = nullptr;
9238 vertex_input_state.vertexBindingDescriptionCount = 0;
9239 vertex_input_state.pVertexBindingDescriptions = nullptr;
9240 vertex_input_state.vertexAttributeDescriptionCount = 1;
9241 vertex_input_state.pVertexAttributeDescriptions = &vertex_input_attribute_description;
9242
9243 VkPipelineInputAssemblyStateCreateInfo input_assembly_state{};
9244 input_assembly_state.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
9245 input_assembly_state.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
9246
9247 VkViewport viewport{};
9248 VkPipelineViewportStateCreateInfo viewport_state{};
9249 viewport_state.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
9250 viewport_state.scissorCount = 1;
9251 viewport_state.viewportCount = 1;
9252 viewport_state.pViewports = &viewport;
9253
9254 VkPipelineMultisampleStateCreateInfo multisample_state{};
9255 multisample_state.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
9256 multisample_state.pNext = nullptr;
9257 multisample_state.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
9258 multisample_state.sampleShadingEnable = 0;
9259 multisample_state.minSampleShading = 1.0;
9260 multisample_state.pSampleMask = nullptr;
9261
9262 VkPipelineRasterizationStateCreateInfo rasterization_state{};
9263 rasterization_state.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
9264 rasterization_state.polygonMode = VK_POLYGON_MODE_FILL;
9265 rasterization_state.cullMode = VK_CULL_MODE_BACK_BIT;
9266 rasterization_state.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
9267 rasterization_state.depthClampEnable = VK_FALSE;
9268 rasterization_state.rasterizerDiscardEnable = VK_FALSE;
9269 rasterization_state.depthBiasEnable = VK_FALSE;
9270
9271 VkPipelineLayout pipeline_layout;
9272 {
9273 VkPipelineLayoutCreateInfo create_info{};
9274 create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9275 create_info.setLayoutCount = 0;
9276 create_info.pSetLayouts = nullptr;
9277
9278 VkResult err = vkCreatePipelineLayout(m_device->device(), &create_info, nullptr, &pipeline_layout);
9279 ASSERT_VK_SUCCESS(err);
9280 }
9281
9282 {
9283 VkGraphicsPipelineCreateInfo create_info{};
9284 create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
9285 create_info.stageCount = 2;
9286 create_info.pStages = stages;
9287 create_info.pVertexInputState = &vertex_input_state;
9288 create_info.pInputAssemblyState = &input_assembly_state;
9289 create_info.pViewportState = &viewport_state;
9290 create_info.pMultisampleState = &multisample_state;
9291 create_info.pRasterizationState = &rasterization_state;
9292 create_info.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
9293 create_info.layout = pipeline_layout;
9294 create_info.renderPass = renderPass();
9295
9296 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01412);
9297 VkPipeline pipeline;
9298 vkCreateGraphicsPipelines(m_device->device(), pipeline_cache, 1, &create_info, nullptr, &pipeline);
9299 m_errorMonitor->VerifyFound();
9300 }
9301
9302 vkDestroyPipelineCache(m_device->device(), pipeline_cache, nullptr);
9303 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
9304}
9305
Karl Schultz6addd812016-02-02 17:17:23 -07009306TEST_F(VkLayerTest, NullRenderPass) {
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06009307 // Bind a NULL RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009308 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mike Schuchardt0b1f2f82016-12-28 15:11:20 -07009309 "vkCmdBeginRenderPass: required parameter pRenderPassBegin specified as NULL");
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06009310
Tony Barbour1fa09702017-03-16 12:09:08 -06009311 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06009312 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06009313
Tony Barbour552f6c02016-12-21 14:34:07 -07009314 m_commandBuffer->BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07009315 // Don't care about RenderPass handle b/c error should be flagged before
9316 // that
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009317 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06009318
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009319 m_errorMonitor->VerifyFound();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06009320}
9321
Karl Schultz6addd812016-02-02 17:17:23 -07009322TEST_F(VkLayerTest, RenderPassWithinRenderPass) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009323 // Bind a BeginRenderPass within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009324 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9325 "It is invalid to issue this call inside an active render pass");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009326
Tony Barbour1fa09702017-03-16 12:09:08 -06009327 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009328 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009329
Tony Barbour552f6c02016-12-21 14:34:07 -07009330 m_commandBuffer->BeginCommandBuffer();
9331 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Karl Schultz6addd812016-02-02 17:17:23 -07009332 // Just create a dummy Renderpass that's non-NULL so we can get to the
9333 // proper error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009334 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009335
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009336 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009337}
9338
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06009339TEST_F(VkLayerTest, RenderPassClearOpMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009340 TEST_DESCRIPTION(
9341 "Begin a renderPass where clearValueCount is less than"
9342 "the number of renderPass attachments that use loadOp"
9343 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06009344
Tony Barbour1fa09702017-03-16 12:09:08 -06009345 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06009346 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9347
9348 // Create a renderPass with a single attachment that uses loadOp CLEAR
9349 VkAttachmentReference attach = {};
9350 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
9351 VkSubpassDescription subpass = {};
Cort Stratton7547f772017-05-04 15:18:52 -07009352 subpass.colorAttachmentCount = 1;
9353 subpass.pColorAttachments = &attach;
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06009354 VkRenderPassCreateInfo rpci = {};
9355 rpci.subpassCount = 1;
9356 rpci.pSubpasses = &subpass;
9357 rpci.attachmentCount = 1;
9358 VkAttachmentDescription attach_desc = {};
Rene Lindsay4bf0e4c2017-01-31 14:20:34 -07009359 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06009360 // Set loadOp to CLEAR
9361 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
9362 rpci.pAttachments = &attach_desc;
9363 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
9364 VkRenderPass rp;
9365 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
9366
9367 VkCommandBufferInheritanceInfo hinfo = {};
9368 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
9369 hinfo.renderPass = VK_NULL_HANDLE;
9370 hinfo.subpass = 0;
9371 hinfo.framebuffer = VK_NULL_HANDLE;
9372 hinfo.occlusionQueryEnable = VK_FALSE;
9373 hinfo.queryFlags = 0;
9374 hinfo.pipelineStatistics = 0;
9375 VkCommandBufferBeginInfo info = {};
9376 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
9377 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
9378 info.pInheritanceInfo = &hinfo;
9379
9380 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
9381 VkRenderPassBeginInfo rp_begin = {};
9382 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
9383 rp_begin.pNext = NULL;
9384 rp_begin.renderPass = renderPass();
9385 rp_begin.framebuffer = framebuffer();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009386 rp_begin.clearValueCount = 0; // Should be 1
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06009387
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07009388 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00442);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06009389
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009390 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06009391
9392 m_errorMonitor->VerifyFound();
Mark Lobodzinski5c70ebd2016-06-09 13:45:00 -06009393
9394 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06009395}
9396
Cody Northrop3bb4d962016-05-09 16:15:57 -06009397TEST_F(VkLayerTest, EndCommandBufferWithinRenderPass) {
Cody Northrop3bb4d962016-05-09 16:15:57 -06009398 TEST_DESCRIPTION("End a command buffer with an active render pass");
9399
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009400 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9401 "It is invalid to issue this call inside an active render pass");
Cody Northrop3bb4d962016-05-09 16:15:57 -06009402
Tony Barbour1fa09702017-03-16 12:09:08 -06009403 ASSERT_NO_FATAL_FAILURE(Init());
Cody Northrop3bb4d962016-05-09 16:15:57 -06009404 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9405
Tony Barbour552f6c02016-12-21 14:34:07 -07009406 m_commandBuffer->BeginCommandBuffer();
9407 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
9408 vkEndCommandBuffer(m_commandBuffer->handle());
Cody Northrop3bb4d962016-05-09 16:15:57 -06009409
9410 m_errorMonitor->VerifyFound();
9411
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009412 // TODO: Add test for VK_COMMAND_BUFFER_LEVEL_SECONDARY
9413 // TODO: Add test for VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT
Cody Northrop3bb4d962016-05-09 16:15:57 -06009414}
9415
Karl Schultz6addd812016-02-02 17:17:23 -07009416TEST_F(VkLayerTest, FillBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009417 // Call CmdFillBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009418 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9419 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009420
Tony Barbour1fa09702017-03-16 12:09:08 -06009421 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009422 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009423
Tony Barbour552f6c02016-12-21 14:34:07 -07009424 m_commandBuffer->BeginCommandBuffer();
9425 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009426
9427 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009428 vk_testing::Buffer dstBuffer;
9429 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009430
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009431 m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009432
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009433 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009434}
9435
Karl Schultz6addd812016-02-02 17:17:23 -07009436TEST_F(VkLayerTest, UpdateBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009437 // Call CmdUpdateBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009438 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9439 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009440
Tony Barbour1fa09702017-03-16 12:09:08 -06009441 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009442 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009443
Tony Barbour552f6c02016-12-21 14:34:07 -07009444 m_commandBuffer->BeginCommandBuffer();
9445 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009446
9447 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009448 vk_testing::Buffer dstBuffer;
9449 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009450
Karl Schultz6addd812016-02-02 17:17:23 -07009451 VkDeviceSize dstOffset = 0;
Rene Lindsay32d26902017-02-02 16:49:24 -07009452 uint32_t Data[] = {1, 2, 3, 4, 5, 6, 7, 8};
9453 VkDeviceSize dataSize = sizeof(Data) / sizeof(uint32_t);
9454 vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(), dstOffset, dataSize, &Data);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009455
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009456 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009457}
9458
Petr Kraus4d718682017-05-18 03:38:41 +02009459TEST_F(VkLayerTest, ClearColorImageWithBadRange) {
9460 TEST_DESCRIPTION("Record clear color with an invalid VkImageSubresourceRange");
9461
9462 ASSERT_NO_FATAL_FAILURE(Init());
9463 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9464
9465 VkImageObj image(m_device);
9466 image.Init(32, 32, 1, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_OPTIMAL);
9467 ASSERT_TRUE(image.create_info().arrayLayers == 1);
9468 ASSERT_TRUE(image.initialized());
9469 image.SetLayout(VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
9470
9471 const VkClearColorValue clear_color = {{0.0f, 0.0f, 0.0f, 1.0f}};
9472
9473 m_commandBuffer->BeginCommandBuffer();
9474 const auto cb_handle = m_commandBuffer->GetBufferHandle();
9475
9476 // Try levelCount = 0
9477 {
9478 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
9479 const VkImageSubresourceRange range = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 0, 1};
9480 vkCmdClearColorImage(cb_handle, image.handle(), image.Layout(), &clear_color, 1, &range);
9481 m_errorMonitor->VerifyFound();
9482 }
9483
9484 // Try baseLevel + levelCount > image.mipLevels
9485 {
9486 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
9487 const VkImageSubresourceRange range = {VK_IMAGE_ASPECT_COLOR_BIT, 1, 1, 0, 1};
9488 vkCmdClearColorImage(cb_handle, image.handle(), image.Layout(), &clear_color, 1, &range);
9489 m_errorMonitor->VerifyFound();
9490 }
9491
9492 // Try baseLevel >= image.mipLevels with VK_REMAINING_MIP_LEVELS
9493 {
9494 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9495 "vkCmdClearColorImage: pRanges[0].baseMipLevel (= 1) is greater or equal to the mip "
9496 "level count of the image (i.e. greater or equal to 1).");
9497 const VkImageSubresourceRange range = {VK_IMAGE_ASPECT_COLOR_BIT, 1, VK_REMAINING_MIP_LEVELS, 0, 1};
9498 vkCmdClearColorImage(cb_handle, image.handle(), image.Layout(), &clear_color, 1, &range);
9499 m_errorMonitor->VerifyFound();
9500 }
9501
9502 // Try layerCount = 0
9503 {
9504 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02931);
9505 const VkImageSubresourceRange range = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 0};
9506 vkCmdClearColorImage(cb_handle, image.handle(), image.Layout(), &clear_color, 1, &range);
9507 m_errorMonitor->VerifyFound();
9508 }
9509
9510 // Try baseLayer + layerCount > image.arrayLayers
9511 {
9512 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02931);
9513 const VkImageSubresourceRange range = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 1, 1};
9514 vkCmdClearColorImage(cb_handle, image.handle(), image.Layout(), &clear_color, 1, &range);
9515 m_errorMonitor->VerifyFound();
9516 }
9517
9518 // Try baseLevel >= image.mipLevels with VK_REMAINING_ARRAY_LAYERS
9519 {
9520 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9521 "vkCmdClearColorImage: pRanges[0].baseArrayLayer (= 1) is greater or equal to the "
9522 "arrayLayers of the image when it was created (i.e. greater or equal to 1).");
9523 const VkImageSubresourceRange range = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 1, VK_REMAINING_ARRAY_LAYERS};
9524 vkCmdClearColorImage(cb_handle, image.handle(), image.Layout(), &clear_color, 1, &range);
9525 m_errorMonitor->VerifyFound();
9526 }
9527}
9528
9529TEST_F(VkLayerTest, ClearDepthStencilWithBadRange) {
9530 TEST_DESCRIPTION("Record clear depth with an invalid VkImageSubresourceRange");
9531
9532 ASSERT_NO_FATAL_FAILURE(Init());
9533 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9534
9535 const auto depth_format = FindSupportedDepthStencilFormat(gpu());
9536 if (!depth_format) {
9537 printf(" No Depth + Stencil format found. Skipped.\n");
9538 return;
9539 }
9540
9541 VkImageObj image(m_device);
9542 image.Init(32, 32, 1, depth_format, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_OPTIMAL);
9543 ASSERT_TRUE(image.create_info().arrayLayers == 1);
9544 ASSERT_TRUE(image.initialized());
9545 const VkImageAspectFlags ds_aspect = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
9546 image.SetLayout(ds_aspect, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
9547
9548 const VkClearDepthStencilValue clear_value = {};
9549
9550 m_commandBuffer->BeginCommandBuffer();
9551 const auto cb_handle = m_commandBuffer->GetBufferHandle();
9552
9553 // Try levelCount = 0
9554 {
9555 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
9556 const VkImageSubresourceRange range = {ds_aspect, 0, 0, 0, 1};
9557 vkCmdClearDepthStencilImage(cb_handle, image.handle(), image.Layout(), &clear_value, 1, &range);
9558 m_errorMonitor->VerifyFound();
9559 }
9560
9561 // Try baseLevel + levelCount > image.mipLevels
9562 {
9563 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
9564 const VkImageSubresourceRange range = {ds_aspect, 1, 1, 0, 1};
9565 vkCmdClearDepthStencilImage(cb_handle, image.handle(), image.Layout(), &clear_value, 1, &range);
9566 m_errorMonitor->VerifyFound();
9567 }
9568
9569 // Try baseLevel >= image.mipLevels with VK_REMAINING_MIP_LEVELS
9570 {
9571 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9572 "vkCmdClearDepthStencilImage: pRanges[0].baseMipLevel (= 1) is greater or equal to "
9573 "the mip level count of the image (i.e. greater or equal to 1).");
9574 const VkImageSubresourceRange range = {ds_aspect, 1, VK_REMAINING_MIP_LEVELS, 0, 1};
9575 vkCmdClearDepthStencilImage(cb_handle, image.handle(), image.Layout(), &clear_value, 1, &range);
9576 m_errorMonitor->VerifyFound();
9577 }
9578
9579 // Try layerCount = 0
9580 {
9581 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02931);
9582 const VkImageSubresourceRange range = {ds_aspect, 0, 1, 0, 0};
9583 vkCmdClearDepthStencilImage(cb_handle, image.handle(), image.Layout(), &clear_value, 1, &range);
9584 m_errorMonitor->VerifyFound();
9585 }
9586
9587 // Try baseLayer + layerCount > image.arrayLayers
9588 {
9589 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02931);
9590 const VkImageSubresourceRange range = {ds_aspect, 0, 1, 1, 1};
9591 vkCmdClearDepthStencilImage(cb_handle, image.handle(), image.Layout(), &clear_value, 1, &range);
9592 m_errorMonitor->VerifyFound();
9593 }
9594
9595 // Try baseLevel >= image.mipLevels with VK_REMAINING_ARRAY_LAYERS
9596 {
9597 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9598 "vkCmdClearDepthStencilImage: pRanges[0].baseArrayLayer (= 1) is greater or equal to "
9599 "the arrayLayers of the image when it was created (i.e. greater or equal to 1).");
9600 const VkImageSubresourceRange range = {ds_aspect, 0, 1, 1, VK_REMAINING_ARRAY_LAYERS};
9601 vkCmdClearDepthStencilImage(cb_handle, image.handle(), image.Layout(), &clear_value, 1, &range);
9602 m_errorMonitor->VerifyFound();
9603 }
9604}
9605
Karl Schultz6addd812016-02-02 17:17:23 -07009606TEST_F(VkLayerTest, ClearColorImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009607 // Call CmdClearColorImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009608 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9609 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009610
Tony Barbour1fa09702017-03-16 12:09:08 -06009611 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009612 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009613
Tony Barbour552f6c02016-12-21 14:34:07 -07009614 m_commandBuffer->BeginCommandBuffer();
9615 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009616
Michael Lentine0a369f62016-02-03 16:51:46 -06009617 VkClearColorValue clear_color;
9618 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
Karl Schultz6addd812016-02-02 17:17:23 -07009619 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
9620 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
9621 const int32_t tex_width = 32;
9622 const int32_t tex_height = 32;
9623 VkImageCreateInfo image_create_info = {};
9624 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
9625 image_create_info.pNext = NULL;
9626 image_create_info.imageType = VK_IMAGE_TYPE_2D;
9627 image_create_info.format = tex_format;
9628 image_create_info.extent.width = tex_width;
9629 image_create_info.extent.height = tex_height;
9630 image_create_info.extent.depth = 1;
9631 image_create_info.mipLevels = 1;
9632 image_create_info.arrayLayers = 1;
9633 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
9634 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
Jeremy Hayesa3d5c7b2017-03-07 16:01:52 -07009635 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009636
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009637 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009638 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009639
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009640 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009641
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009642 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009643
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009644 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009645}
9646
Karl Schultz6addd812016-02-02 17:17:23 -07009647TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009648 // Call CmdClearDepthStencilImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009649 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9650 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009651
Tony Barbour1fa09702017-03-16 12:09:08 -06009652 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009653 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009654
Dave Houlton1d2022c2017-03-29 11:43:58 -06009655 auto depth_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbourf887b162017-03-09 10:06:46 -07009656 if (!depth_format) {
9657 printf(" No Depth + Stencil format found. Skipped.\n");
9658 return;
9659 }
9660
Tony Barbour552f6c02016-12-21 14:34:07 -07009661 m_commandBuffer->BeginCommandBuffer();
9662 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009663
9664 VkClearDepthStencilValue clear_value = {0};
Dustin Gravesa2e5c942016-02-11 18:28:06 -07009665 VkMemoryPropertyFlags reqs = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07009666 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
9667 image_create_info.imageType = VK_IMAGE_TYPE_2D;
Tony Barbourf887b162017-03-09 10:06:46 -07009668 image_create_info.format = depth_format;
Karl Schultz6addd812016-02-02 17:17:23 -07009669 image_create_info.extent.width = 64;
9670 image_create_info.extent.height = 64;
9671 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
9672 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009673
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009674 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009675 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009676
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009677 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009678
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07009679 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_value, 1,
9680 &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009681
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009682 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009683}
9684
Karl Schultz6addd812016-02-02 17:17:23 -07009685TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass) {
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06009686 // Call CmdClearAttachmentss outside of an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07009687 VkResult err;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009688
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009689 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9690 "vkCmdClearAttachments(): This call "
9691 "must be issued inside an active "
9692 "render pass");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009693
Tony Barbour1fa09702017-03-16 12:09:08 -06009694 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009695 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009696
9697 // Start no RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009698 err = m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009699 ASSERT_VK_SUCCESS(err);
9700
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06009701 VkClearAttachment color_attachment;
9702 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9703 color_attachment.clearValue.color.float32[0] = 0;
9704 color_attachment.clearValue.color.float32[1] = 0;
9705 color_attachment.clearValue.color.float32[2] = 0;
9706 color_attachment.clearValue.color.float32[3] = 0;
9707 color_attachment.colorAttachment = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07009708 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009709 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009710
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009711 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009712}
9713
Chris Forbes3b97e932016-09-07 11:29:24 +12009714TEST_F(VkLayerTest, RenderPassExcessiveNextSubpass) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009715 TEST_DESCRIPTION(
9716 "Test that an error is produced when CmdNextSubpass is "
9717 "called too many times in a renderpass instance");
Chris Forbes3b97e932016-09-07 11:29:24 +12009718
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009719 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9720 "vkCmdNextSubpass(): Attempted to advance "
9721 "beyond final subpass");
Chris Forbes3b97e932016-09-07 11:29:24 +12009722
Tony Barbour1fa09702017-03-16 12:09:08 -06009723 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes3b97e932016-09-07 11:29:24 +12009724 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9725
Tony Barbour552f6c02016-12-21 14:34:07 -07009726 m_commandBuffer->BeginCommandBuffer();
9727 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes3b97e932016-09-07 11:29:24 +12009728
9729 // error here.
9730 vkCmdNextSubpass(m_commandBuffer->GetBufferHandle(), VK_SUBPASS_CONTENTS_INLINE);
9731 m_errorMonitor->VerifyFound();
9732
Tony Barbour552f6c02016-12-21 14:34:07 -07009733 m_commandBuffer->EndRenderPass();
9734 m_commandBuffer->EndCommandBuffer();
Chris Forbes3b97e932016-09-07 11:29:24 +12009735}
9736
Chris Forbes6d624702016-09-07 13:57:05 +12009737TEST_F(VkLayerTest, RenderPassEndedBeforeFinalSubpass) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009738 TEST_DESCRIPTION(
9739 "Test that an error is produced when CmdEndRenderPass is "
9740 "called before the final subpass has been reached");
Chris Forbes6d624702016-09-07 13:57:05 +12009741
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009742 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9743 "vkCmdEndRenderPass(): Called before reaching "
9744 "final subpass");
Chris Forbes6d624702016-09-07 13:57:05 +12009745
Tony Barbour1fa09702017-03-16 12:09:08 -06009746 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009747 VkSubpassDescription sd[2] = {{0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr},
9748 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr}};
Chris Forbes6d624702016-09-07 13:57:05 +12009749
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009750 VkRenderPassCreateInfo rcpi = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 2, sd, 0, nullptr};
Chris Forbes6d624702016-09-07 13:57:05 +12009751
9752 VkRenderPass rp;
9753 VkResult err = vkCreateRenderPass(m_device->device(), &rcpi, nullptr, &rp);
9754 ASSERT_VK_SUCCESS(err);
9755
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009756 VkFramebufferCreateInfo fbci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 16, 16, 1};
Chris Forbes6d624702016-09-07 13:57:05 +12009757
9758 VkFramebuffer fb;
9759 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
9760 ASSERT_VK_SUCCESS(err);
9761
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009762 m_commandBuffer->BeginCommandBuffer(); // no implicit RP begin
Chris Forbes6d624702016-09-07 13:57:05 +12009763
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009764 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 +12009765
9766 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
9767
9768 // Error here.
9769 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
9770 m_errorMonitor->VerifyFound();
9771
9772 // Clean up.
9773 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
9774 vkDestroyRenderPass(m_device->device(), rp, nullptr);
9775}
9776
Karl Schultz9e66a292016-04-21 15:57:51 -06009777TEST_F(VkLayerTest, BufferMemoryBarrierNoBuffer) {
9778 // Try to add a buffer memory barrier with no buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009779 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9780 "required parameter pBufferMemoryBarriers[0].buffer specified as VK_NULL_HANDLE");
Karl Schultz9e66a292016-04-21 15:57:51 -06009781
Tony Barbour1fa09702017-03-16 12:09:08 -06009782 ASSERT_NO_FATAL_FAILURE(Init());
Tony Barbour552f6c02016-12-21 14:34:07 -07009783 m_commandBuffer->BeginCommandBuffer();
Karl Schultz9e66a292016-04-21 15:57:51 -06009784
9785 VkBufferMemoryBarrier buf_barrier = {};
9786 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
9787 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
9788 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
9789 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
9790 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
9791 buf_barrier.buffer = VK_NULL_HANDLE;
9792 buf_barrier.offset = 0;
9793 buf_barrier.size = VK_WHOLE_SIZE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009794 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9795 nullptr, 1, &buf_barrier, 0, nullptr);
Karl Schultz9e66a292016-04-21 15:57:51 -06009796
9797 m_errorMonitor->VerifyFound();
9798}
9799
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009800TEST_F(VkLayerTest, InvalidBarriers) {
9801 TEST_DESCRIPTION("A variety of ways to get VK_INVALID_BARRIER ");
9802
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009803 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Barriers cannot be set during subpass");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009804
Tony Barbour1fa09702017-03-16 12:09:08 -06009805 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -06009806 auto depth_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbourf887b162017-03-09 10:06:46 -07009807 if (!depth_format) {
9808 printf(" No Depth + Stencil format found. Skipped.\n");
9809 return;
9810 }
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009811 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9812
9813 VkMemoryBarrier mem_barrier = {};
9814 mem_barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER;
9815 mem_barrier.pNext = NULL;
9816 mem_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
9817 mem_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
Tony Barbour552f6c02016-12-21 14:34:07 -07009818 m_commandBuffer->BeginCommandBuffer();
9819 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009820 // BeginCommandBuffer() starts a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009821 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 1,
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009822 &mem_barrier, 0, nullptr, 0, nullptr);
9823 m_errorMonitor->VerifyFound();
9824
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009825 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image Layout cannot be transitioned to UNDEFINED");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009826 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06009827 image.Init(128, 128, 1, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009828 ASSERT_TRUE(image.initialized());
9829 VkImageMemoryBarrier img_barrier = {};
9830 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
9831 img_barrier.pNext = NULL;
9832 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
9833 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
Mark Lobodzinski95512b72017-05-10 12:21:30 -06009834 img_barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009835 // New layout can't be UNDEFINED
9836 img_barrier.newLayout = VK_IMAGE_LAYOUT_UNDEFINED;
9837 img_barrier.image = image.handle();
9838 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
9839 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
9840 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9841 img_barrier.subresourceRange.baseArrayLayer = 0;
9842 img_barrier.subresourceRange.baseMipLevel = 0;
9843 img_barrier.subresourceRange.layerCount = 1;
9844 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009845 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9846 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009847 m_errorMonitor->VerifyFound();
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009848
Mark Lobodzinski95512b72017-05-10 12:21:30 -06009849 // Transition image to color attachment optimal
9850 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
9851 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
9852 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9853 nullptr, 0, nullptr, 1, &img_barrier);
9854 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinski95512b72017-05-10 12:21:30 -06009855
Mark Lobodzinski45daf6e2017-05-10 13:19:02 -06009856 // Try to change layout in a renderpass
9857 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02080);
9858 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9859 nullptr, 0, nullptr, 1, &img_barrier);
9860 m_errorMonitor->VerifyFound();
9861
9862 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
Petr Kraus4d718682017-05-18 03:38:41 +02009863 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02931);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009864 // baseArrayLayer + layerCount must be <= image's arrayLayers
9865 img_barrier.subresourceRange.baseArrayLayer = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009866 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9867 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009868 m_errorMonitor->VerifyFound();
9869 img_barrier.subresourceRange.baseArrayLayer = 0;
9870
Petr Kraus4d718682017-05-18 03:38:41 +02009871 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009872 // baseMipLevel + levelCount must be <= image's mipLevels
9873 img_barrier.subresourceRange.baseMipLevel = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009874 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9875 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009876 m_errorMonitor->VerifyFound();
9877 img_barrier.subresourceRange.baseMipLevel = 0;
9878
Mike Weiblen7053aa32017-01-25 15:21:10 -07009879 // levelCount must be non-zero.
9880 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
9881 img_barrier.subresourceRange.levelCount = 0;
9882 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9883 nullptr, 0, nullptr, 1, &img_barrier);
9884 m_errorMonitor->VerifyFound();
9885 img_barrier.subresourceRange.levelCount = 1;
9886
9887 // layerCount must be non-zero.
Petr Kraus4d718682017-05-18 03:38:41 +02009888 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02931);
Mike Weiblen7053aa32017-01-25 15:21:10 -07009889 img_barrier.subresourceRange.layerCount = 0;
9890 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9891 nullptr, 0, nullptr, 1, &img_barrier);
9892 m_errorMonitor->VerifyFound();
9893 img_barrier.subresourceRange.layerCount = 1;
9894
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009895 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 -06009896 vk_testing::Buffer buffer;
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07009897 VkMemoryPropertyFlags mem_reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
9898 buffer.init_as_src_and_dst(*m_device, 256, mem_reqs);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009899 VkBufferMemoryBarrier buf_barrier = {};
9900 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
9901 buf_barrier.pNext = NULL;
9902 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
9903 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
9904 buf_barrier.buffer = buffer.handle();
9905 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
9906 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
9907 buf_barrier.offset = 0;
9908 buf_barrier.size = VK_WHOLE_SIZE;
9909 // Can't send buffer barrier during a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009910 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9911 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009912 m_errorMonitor->VerifyFound();
9913 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
9914
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009915 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which is not less than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009916 buf_barrier.offset = 257;
9917 // Offset greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009918 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9919 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009920 m_errorMonitor->VerifyFound();
9921 buf_barrier.offset = 0;
9922
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009923 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "whose sum is greater than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009924 buf_barrier.size = 257;
9925 // Size greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009926 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9927 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009928 m_errorMonitor->VerifyFound();
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009929
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009930 // Now exercise barrier aspect bit errors, first DS
Tobin Ehlis99ab0d22017-04-26 16:53:52 -06009931 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00741);
9932 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00302);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009933 VkDepthStencilObj ds_image(m_device);
Tony Barbourf887b162017-03-09 10:06:46 -07009934 ds_image.Init(m_device, 128, 128, depth_format);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009935 ASSERT_TRUE(ds_image.initialized());
Tobin Ehlis15684a02016-07-21 14:55:26 -06009936 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
9937 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009938 img_barrier.image = ds_image.handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07009939
9940 // Not having DEPTH or STENCIL set is an error
Rene Lindsay4834cba2017-02-02 17:18:56 -07009941 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009942 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9943 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009944 m_errorMonitor->VerifyFound();
Dave Houltonfbf52152017-01-06 12:55:29 -07009945
Tobin Ehlis99ab0d22017-04-26 16:53:52 -06009946 // Having only one of depth or stencil set for DS image is an error
9947 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00302);
9948 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT;
9949 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9950 nullptr, 0, nullptr, 1, &img_barrier);
9951 m_errorMonitor->VerifyFound();
9952
9953 // Having anything other than DEPTH and STENCIL is an error
9954 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00741);
Dave Houltonfbf52152017-01-06 12:55:29 -07009955 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT | VK_IMAGE_ASPECT_COLOR_BIT;
9956 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9957 nullptr, 0, nullptr, 1, &img_barrier);
9958 m_errorMonitor->VerifyFound();
9959
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009960 // Now test depth-only
9961 VkFormatProperties format_props;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009962 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D16_UNORM, &format_props);
9963 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009964 VkDepthStencilObj d_image(m_device);
9965 d_image.Init(m_device, 128, 128, VK_FORMAT_D16_UNORM);
9966 ASSERT_TRUE(d_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009967 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06009968 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009969 img_barrier.image = d_image.handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07009970
9971 // DEPTH bit must be set
9972 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9973 "Depth-only image formats must have the VK_IMAGE_ASPECT_DEPTH_BIT set.");
Rene Lindsay4834cba2017-02-02 17:18:56 -07009974 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Dave Houltonfbf52152017-01-06 12:55:29 -07009975 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
9976 0, nullptr, 0, nullptr, 1, &img_barrier);
9977 m_errorMonitor->VerifyFound();
9978
9979 // No bits other than DEPTH may be set
9980 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9981 "Depth-only image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT set.");
9982 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009983 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
9984 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009985 m_errorMonitor->VerifyFound();
9986 }
Dave Houltonfbf52152017-01-06 12:55:29 -07009987
9988 // Now test stencil-only
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009989 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_S8_UINT, &format_props);
9990 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009991 VkDepthStencilObj s_image(m_device);
9992 s_image.Init(m_device, 128, 128, VK_FORMAT_S8_UINT);
9993 ASSERT_TRUE(s_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009994 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06009995 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009996 img_barrier.image = s_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06009997 // Use of COLOR aspect on depth image is error
Dave Houltonf3229d52017-02-21 15:59:08 -07009998 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9999 "Stencil-only image formats must have the VK_IMAGE_ASPECT_STENCIL_BIT set.");
Tobin Ehlis15684a02016-07-21 14:55:26 -060010000 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010001 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
10002 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010003 m_errorMonitor->VerifyFound();
10004 }
Dave Houltonfbf52152017-01-06 12:55:29 -070010005
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010006 // Finally test color
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010007 VkImageObj c_image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060010008 c_image.Init(128, 128, 1, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010009 ASSERT_TRUE(c_image.initialized());
10010 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10011 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
10012 img_barrier.image = c_image.handle();
Dave Houltonfbf52152017-01-06 12:55:29 -070010013
10014 // COLOR bit must be set
10015 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10016 "Color image formats must have the VK_IMAGE_ASPECT_COLOR_BIT set.");
Rene Lindsay4834cba2017-02-02 17:18:56 -070010017 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Dave Houltonfbf52152017-01-06 12:55:29 -070010018 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10019 nullptr, 0, nullptr, 1, &img_barrier);
10020 m_errorMonitor->VerifyFound();
10021
10022 // No bits other than COLOR may be set
10023 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10024 "Color image formats must have ONLY the VK_IMAGE_ASPECT_COLOR_BIT set.");
10025 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010026 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10027 nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010028 m_errorMonitor->VerifyFound();
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -070010029
Mike Weiblene6e01172017-03-07 22:18:40 -070010030 // A barrier's new and old VkImageLayout must be compatible with an image's VkImageUsageFlags.
10031 {
10032 VkImageObj img_color(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060010033 img_color.Init(128, 128, 1, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL);
Mike Weiblene6e01172017-03-07 22:18:40 -070010034 ASSERT_TRUE(img_color.initialized());
10035
10036 VkImageObj img_ds(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060010037 img_ds.Init(128, 128, 1, depth_format, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL);
Mike Weiblene6e01172017-03-07 22:18:40 -070010038 ASSERT_TRUE(img_ds.initialized());
10039
10040 VkImageObj img_xfer_src(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060010041 img_xfer_src.Init(128, 128, 1, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_OPTIMAL);
Mike Weiblene6e01172017-03-07 22:18:40 -070010042 ASSERT_TRUE(img_xfer_src.initialized());
10043
10044 VkImageObj img_xfer_dst(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060010045 img_xfer_dst.Init(128, 128, 1, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_OPTIMAL);
Mike Weiblene6e01172017-03-07 22:18:40 -070010046 ASSERT_TRUE(img_xfer_dst.initialized());
10047
10048 VkImageObj img_sampled(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060010049 img_sampled.Init(32, 32, 1, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL);
Mike Weiblene6e01172017-03-07 22:18:40 -070010050 ASSERT_TRUE(img_sampled.initialized());
10051
10052 VkImageObj img_input(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060010053 img_input.Init(128, 128, 1, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL);
Mike Weiblene6e01172017-03-07 22:18:40 -070010054 ASSERT_TRUE(img_input.initialized());
10055
10056 const struct {
10057 VkImageObj &image_obj;
10058 VkImageLayout bad_layout;
10059 UNIQUE_VALIDATION_ERROR_CODE msg_code;
10060 } bad_buffer_layouts[] = {
10061 // clang-format off
10062 // images _without_ VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT
10063 {img_ds, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VALIDATION_ERROR_00303},
10064 {img_xfer_src, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VALIDATION_ERROR_00303},
10065 {img_xfer_dst, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VALIDATION_ERROR_00303},
10066 {img_sampled, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VALIDATION_ERROR_00303},
10067 {img_input, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VALIDATION_ERROR_00303},
10068 // images _without_ VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT
10069 {img_color, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, VALIDATION_ERROR_00304},
10070 {img_xfer_src, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, VALIDATION_ERROR_00304},
10071 {img_xfer_dst, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, VALIDATION_ERROR_00304},
10072 {img_sampled, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, VALIDATION_ERROR_00304},
10073 {img_input, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, VALIDATION_ERROR_00304},
10074 {img_color, VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL, VALIDATION_ERROR_00305},
10075 {img_xfer_src, VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL, VALIDATION_ERROR_00305},
10076 {img_xfer_dst, VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL, VALIDATION_ERROR_00305},
10077 {img_sampled, VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL, VALIDATION_ERROR_00305},
10078 {img_input, VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL, VALIDATION_ERROR_00305},
10079 // images _without_ VK_IMAGE_USAGE_SAMPLED_BIT or VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT
10080 {img_color, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VALIDATION_ERROR_00306},
10081 {img_ds, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VALIDATION_ERROR_00306},
10082 {img_xfer_src, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VALIDATION_ERROR_00306},
10083 {img_xfer_dst, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VALIDATION_ERROR_00306},
10084 // images _without_ VK_IMAGE_USAGE_TRANSFER_SRC_BIT
10085 {img_color, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VALIDATION_ERROR_00307},
10086 {img_ds, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VALIDATION_ERROR_00307},
10087 {img_xfer_dst, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VALIDATION_ERROR_00307},
10088 {img_sampled, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VALIDATION_ERROR_00307},
10089 {img_input, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VALIDATION_ERROR_00307},
10090 // images _without_ VK_IMAGE_USAGE_TRANSFER_DST_BIT
10091 {img_color, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VALIDATION_ERROR_00308},
10092 {img_ds, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VALIDATION_ERROR_00308},
10093 {img_xfer_src, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VALIDATION_ERROR_00308},
10094 {img_sampled, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VALIDATION_ERROR_00308},
10095 {img_input, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VALIDATION_ERROR_00308},
10096 // clang-format on
10097 };
10098 const uint32_t layout_count = sizeof(bad_buffer_layouts) / sizeof(bad_buffer_layouts[0]);
10099
10100 for (uint32_t i = 0; i < layout_count; ++i) {
10101 img_barrier.image = bad_buffer_layouts[i].image_obj.handle();
10102 const VkImageUsageFlags usage = bad_buffer_layouts[i].image_obj.usage();
10103 img_barrier.subresourceRange.aspectMask = (usage == VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT)
10104 ? (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)
10105 : VK_IMAGE_ASPECT_COLOR_BIT;
10106
10107 img_barrier.oldLayout = bad_buffer_layouts[i].bad_layout;
10108 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
10109 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_buffer_layouts[i].msg_code);
10110 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT,
10111 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0, nullptr, 1, &img_barrier);
10112 m_errorMonitor->VerifyFound();
10113
10114 img_barrier.oldLayout = VK_IMAGE_LAYOUT_GENERAL;
10115 img_barrier.newLayout = bad_buffer_layouts[i].bad_layout;
10116 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_buffer_layouts[i].msg_code);
10117 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT,
10118 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0, nullptr, 1, &img_barrier);
10119 m_errorMonitor->VerifyFound();
10120 }
10121
10122 img_barrier.oldLayout = VK_IMAGE_LAYOUT_GENERAL;
10123 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
10124 }
10125
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -070010126 // Attempt to mismatch barriers/waitEvents calls with incompatible queues
10127
10128 // Create command pool with incompatible queueflags
10129 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
Mike Schuchardt06304c22017-03-01 17:09:09 -070010130 uint32_t queue_family_index = m_device->QueueFamilyWithoutCapabilities(VK_QUEUE_COMPUTE_BIT);
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -070010131 if (queue_family_index == UINT32_MAX) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070010132 printf(" No non-compute queue found; skipped.\n");
Mike Weiblene6e01172017-03-07 22:18:40 -070010133 return; // NOTE: this exits the test function!
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -070010134 }
10135 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02513);
10136
10137 VkCommandPool command_pool;
10138 VkCommandPoolCreateInfo pool_create_info{};
10139 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
10140 pool_create_info.queueFamilyIndex = queue_family_index;
10141 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
10142 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
10143
10144 // Allocate a command buffer
10145 VkCommandBuffer bad_command_buffer;
10146 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
10147 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
10148 command_buffer_allocate_info.commandPool = command_pool;
10149 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
10150 command_buffer_allocate_info.commandBufferCount = 1;
10151 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &bad_command_buffer));
10152
10153 VkCommandBufferBeginInfo cbbi = {};
10154 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
10155 vkBeginCommandBuffer(bad_command_buffer, &cbbi);
10156 buf_barrier.offset = 0;
10157 buf_barrier.size = VK_WHOLE_SIZE;
10158 vkCmdPipelineBarrier(bad_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1,
10159 &buf_barrier, 0, nullptr);
10160 m_errorMonitor->VerifyFound();
10161
10162 if ((queue_props[queue_family_index].queueFlags & VK_QUEUE_GRAPHICS_BIT) == 0) {
10163 vkEndCommandBuffer(bad_command_buffer);
10164 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070010165 printf(" The non-compute queue does not support graphics; skipped.\n");
Mike Weiblene6e01172017-03-07 22:18:40 -070010166 return; // NOTE: this exits the test function!
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -070010167 }
10168 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02510);
10169 VkEvent event;
10170 VkEventCreateInfo event_create_info{};
10171 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
10172 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
10173 vkCmdWaitEvents(bad_command_buffer, 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, nullptr, 0,
10174 nullptr, 0, nullptr);
10175 m_errorMonitor->VerifyFound();
10176
10177 vkEndCommandBuffer(bad_command_buffer);
10178 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010179}
10180
Chris Forbes50223732017-05-01 09:43:35 -070010181TEST_F(VkPositiveLayerTest, LayoutFromPresentWithoutAccessMemoryRead) {
10182 // Transition an image away from PRESENT_SRC_KHR without ACCESS_MEMORY_READ
10183 // in srcAccessMask.
Tony Barbour18ba25c2016-09-29 13:42:40 -060010184
Chris Forbes50223732017-05-01 09:43:35 -070010185 // The required behavior here was a bit unclear in earlier versions of the
10186 // spec, but there is no memory dependency required here, so this should
10187 // work without warnings.
10188
10189 m_errorMonitor->ExpectSuccess();
Tony Barbour1fa09702017-03-16 12:09:08 -060010190 ASSERT_NO_FATAL_FAILURE(Init());
Tony Barbour18ba25c2016-09-29 13:42:40 -060010191 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060010192 image.Init(128, 128, 1, VK_FORMAT_B8G8R8A8_UNORM, (VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT),
Mike Weiblen62d08a32017-03-07 22:18:27 -070010193 VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbour18ba25c2016-09-29 13:42:40 -060010194 ASSERT_TRUE(image.initialized());
10195
10196 VkImageMemoryBarrier barrier = {};
10197 VkImageSubresourceRange range;
10198 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
Tony Barbour18ba25c2016-09-29 13:42:40 -060010199 barrier.srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
Chris Forbes50223732017-05-01 09:43:35 -070010200 barrier.dstAccessMask = 0;
Tony Barbour18ba25c2016-09-29 13:42:40 -060010201 barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10202 barrier.newLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
10203 barrier.image = image.handle();
10204 range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10205 range.baseMipLevel = 0;
10206 range.levelCount = 1;
10207 range.baseArrayLayer = 0;
10208 range.layerCount = 1;
10209 barrier.subresourceRange = range;
10210 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
10211 cmdbuf.BeginCommandBuffer();
10212 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
10213 &barrier);
10214 barrier.oldLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
10215 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
10216 barrier.srcAccessMask = 0;
10217 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
10218 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
10219 &barrier);
10220
Chris Forbes50223732017-05-01 09:43:35 -070010221 m_errorMonitor->VerifyNotFound();
Tony Barbour18ba25c2016-09-29 13:42:40 -060010222}
10223
Karl Schultz6addd812016-02-02 17:17:23 -070010224TEST_F(VkLayerTest, IdxBufferAlignmentError) {
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010225 // Bind a BeginRenderPass within an active RenderPass
Tony Barbour1fa09702017-03-16 12:09:08 -060010226 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010227 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010228
Jeremy Hayes483d95d2017-03-08 11:03:01 -070010229 uint32_t const indices[] = {0};
10230 VkBufferCreateInfo buf_info = {};
10231 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
10232 buf_info.size = 1024;
10233 buf_info.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
10234 buf_info.queueFamilyIndexCount = 1;
10235 buf_info.pQueueFamilyIndices = indices;
10236
10237 VkBuffer buffer;
10238 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
10239 ASSERT_VK_SUCCESS(err);
10240
10241 VkMemoryRequirements requirements;
10242 vkGetBufferMemoryRequirements(m_device->device(), buffer, &requirements);
10243
10244 VkMemoryAllocateInfo alloc_info{};
10245 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10246 alloc_info.pNext = NULL;
10247 alloc_info.memoryTypeIndex = 0;
10248 alloc_info.allocationSize = requirements.size;
10249 bool pass = m_device->phy().set_memory_type(requirements.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
10250 ASSERT_TRUE(pass);
10251
10252 VkDeviceMemory memory;
10253 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &memory);
10254 ASSERT_VK_SUCCESS(err);
10255
10256 err = vkBindBufferMemory(m_device->device(), buffer, memory, 0);
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010257 ASSERT_VK_SUCCESS(err);
10258
Tony Barbour552f6c02016-12-21 14:34:07 -070010259 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010260 ASSERT_VK_SUCCESS(err);
Jeremy Hayes483d95d2017-03-08 11:03:01 -070010261
Karl Schultz6addd812016-02-02 17:17:23 -070010262 // vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
10263 // VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010264 // Should error before calling to driver so don't care about actual data
Jeremy Hayes483d95d2017-03-08 11:03:01 -070010265 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdBindIndexBuffer() offset (0x7) does not fall on ");
10266 vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), buffer, 7, VK_INDEX_TYPE_UINT16);
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010267 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010268
Jeremy Hayes483d95d2017-03-08 11:03:01 -070010269 vkFreeMemory(m_device->device(), memory, NULL);
10270 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010271}
10272
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -070010273TEST_F(VkLayerTest, InvalidQueueFamilyIndex) {
10274 // Create an out-of-range queueFamilyIndex
Tony Barbour1fa09702017-03-16 12:09:08 -060010275 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -070010276 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10277 VkBufferCreateInfo buffCI = {};
10278 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
10279 buffCI.size = 1024;
Mark Lobodzinski4761d212017-02-28 13:12:44 -070010280 buffCI.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
Jeremy Hayes8a43a0d2017-03-09 11:27:52 -070010281 buffCI.queueFamilyIndexCount = 2;
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -070010282 // Introduce failure by specifying invalid queue_family_index
Mark Lobodzinski4761d212017-02-28 13:12:44 -070010283 uint32_t qfi[2];
10284 qfi[0] = 777;
Jeremy Hayes8a43a0d2017-03-09 11:27:52 -070010285 qfi[1] = 0;
Mark Lobodzinski4761d212017-02-28 13:12:44 -070010286
10287 buffCI.pQueueFamilyIndices = qfi;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010288 buffCI.sharingMode = VK_SHARING_MODE_CONCURRENT; // qfi only matters in CONCURRENT mode
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -070010289
10290 VkBuffer ib;
Jeremy Hayes8a43a0d2017-03-09 11:27:52 -070010291 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Petr Kraus97291752017-05-11 01:05:16 +020010292 "vkCreateBuffer: pCreateInfo->pQueueFamilyIndices[0] (= 777) is not one of the queue "
10293 "families given via VkDeviceQueueCreateInfo structures when the device was created.");
Mark Lobodzinski1f9ebb72017-05-11 15:25:51 -060010294 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010295 m_errorMonitor->VerifyFound();
Mark Lobodzinski4761d212017-02-28 13:12:44 -070010296
10297 if (m_device->queue_props.size() > 2) {
Tony Barbour75db7402017-03-09 14:51:36 -070010298 VkBuffer ib2;
Mark Lobodzinski4761d212017-02-28 13:12:44 -070010299 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which was not created allowing concurrent");
10300
10301 // Create buffer shared to queue families 1 and 2, but submitted on queue family 0
10302 buffCI.queueFamilyIndexCount = 2;
10303 qfi[0] = 1;
10304 qfi[1] = 2;
Tony Barbour75db7402017-03-09 14:51:36 -070010305 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib2);
Mark Lobodzinski4761d212017-02-28 13:12:44 -070010306 VkDeviceMemory mem;
10307 VkMemoryRequirements mem_reqs;
Tony Barbour75db7402017-03-09 14:51:36 -070010308 vkGetBufferMemoryRequirements(m_device->device(), ib2, &mem_reqs);
Mark Lobodzinski4761d212017-02-28 13:12:44 -070010309
10310 VkMemoryAllocateInfo alloc_info = {};
10311 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10312 alloc_info.allocationSize = 1024;
10313 bool pass = false;
10314 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
10315 if (!pass) {
Tony Barbour75db7402017-03-09 14:51:36 -070010316 vkDestroyBuffer(m_device->device(), ib2, NULL);
Mark Lobodzinski4761d212017-02-28 13:12:44 -070010317 return;
10318 }
10319 vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
Tony Barbour75db7402017-03-09 14:51:36 -070010320 vkBindBufferMemory(m_device->device(), ib2, mem, 0);
Mark Lobodzinski4761d212017-02-28 13:12:44 -070010321
10322 m_commandBuffer->begin();
Tony Barbour75db7402017-03-09 14:51:36 -070010323 vkCmdFillBuffer(m_commandBuffer->handle(), ib2, 0, 16, 5);
Mark Lobodzinski4761d212017-02-28 13:12:44 -070010324 m_commandBuffer->end();
10325 QueueCommandBuffer(false);
10326 m_errorMonitor->VerifyFound();
Tony Barbour75db7402017-03-09 14:51:36 -070010327 vkDestroyBuffer(m_device->device(), ib2, NULL);
10328 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski4761d212017-02-28 13:12:44 -070010329 }
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -070010330}
10331
Karl Schultz6addd812016-02-02 17:17:23 -070010332TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010333 TEST_DESCRIPTION(
10334 "Attempt vkCmdExecuteCommands with a primary command buffer"
10335 " (should only be secondary)");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010336
Tony Barbour1fa09702017-03-16 12:09:08 -060010337 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -060010338 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -060010339
Chris Forbesf29a84f2016-10-06 18:39:28 +130010340 // An empty primary command buffer
10341 VkCommandBufferObj cb(m_device, m_commandPool);
10342 cb.BeginCommandBuffer();
10343 cb.EndCommandBuffer();
Tobin Ehlis0c94db02016-07-19 10:49:32 -060010344
Chris Forbesf29a84f2016-10-06 18:39:28 +130010345 m_commandBuffer->BeginCommandBuffer();
10346 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
10347 VkCommandBuffer handle = cb.handle();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -060010348
Chris Forbesf29a84f2016-10-06 18:39:28 +130010349 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdExecuteCommands() called w/ Primary Cmd Buffer ");
10350 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &handle);
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010351 m_errorMonitor->VerifyFound();
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070010352
Tobin Ehlis6d4d1d52017-04-05 12:06:10 -060010353 m_errorMonitor->SetUnexpectedError("All elements of pCommandBuffers must not be in the pending state");
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -060010354}
10355
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010356TEST_F(VkLayerTest, DSUsageBitsErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010357 TEST_DESCRIPTION(
10358 "Attempt to update descriptor sets for images and buffers "
10359 "that do not have correct usage bits sets.");
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010360 VkResult err;
10361
Tony Barbour1fa09702017-03-16 12:09:08 -060010362 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010363 VkDescriptorPoolSize ds_type_count[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
10364 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
10365 ds_type_count[i].type = VkDescriptorType(i);
10366 ds_type_count[i].descriptorCount = 1;
10367 }
10368 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10369 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10370 ds_pool_ci.pNext = NULL;
10371 ds_pool_ci.maxSets = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
10372 ds_pool_ci.poolSizeCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
10373 ds_pool_ci.pPoolSizes = ds_type_count;
10374
10375 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010376 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010377 ASSERT_VK_SUCCESS(err);
10378
10379 // Create 10 layouts where each has a single descriptor of different type
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010380 VkDescriptorSetLayoutBinding dsl_binding[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010381 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
10382 dsl_binding[i].binding = 0;
10383 dsl_binding[i].descriptorType = VkDescriptorType(i);
10384 dsl_binding[i].descriptorCount = 1;
10385 dsl_binding[i].stageFlags = VK_SHADER_STAGE_ALL;
10386 dsl_binding[i].pImmutableSamplers = NULL;
10387 }
10388
10389 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10390 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10391 ds_layout_ci.pNext = NULL;
10392 ds_layout_ci.bindingCount = 1;
10393 VkDescriptorSetLayout ds_layouts[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
10394 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
10395 ds_layout_ci.pBindings = dsl_binding + i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010396 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, ds_layouts + i);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010397 ASSERT_VK_SUCCESS(err);
10398 }
10399 VkDescriptorSet descriptor_sets[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
10400 VkDescriptorSetAllocateInfo alloc_info = {};
10401 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10402 alloc_info.descriptorSetCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
10403 alloc_info.descriptorPool = ds_pool;
10404 alloc_info.pSetLayouts = ds_layouts;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010405 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010406 ASSERT_VK_SUCCESS(err);
10407
10408 // Create a buffer & bufferView to be used for invalid updates
10409 VkBufferCreateInfo buff_ci = {};
10410 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Tony Barbour415497c2017-01-24 10:06:09 -070010411 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010412 buff_ci.size = 256;
10413 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
Tony Barbour415497c2017-01-24 10:06:09 -070010414 VkBuffer buffer, storage_texel_buffer;
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010415 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
10416 ASSERT_VK_SUCCESS(err);
Tony Barbour415497c2017-01-24 10:06:09 -070010417
10418 // Create another buffer to use in testing the UNIFORM_TEXEL_BUFFER case
10419 buff_ci.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
10420 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &storage_texel_buffer);
10421 ASSERT_VK_SUCCESS(err);
10422
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -070010423 VkMemoryRequirements mem_reqs;
10424 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
10425 VkMemoryAllocateInfo mem_alloc_info = {};
10426 mem_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10427 mem_alloc_info.pNext = NULL;
10428 mem_alloc_info.memoryTypeIndex = 0;
10429 mem_alloc_info.allocationSize = mem_reqs.size;
10430 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc_info, 0);
10431 if (!pass) {
10432 vkDestroyBuffer(m_device->device(), buffer, NULL);
10433 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10434 return;
10435 }
10436 VkDeviceMemory mem;
10437 err = vkAllocateMemory(m_device->device(), &mem_alloc_info, NULL, &mem);
10438 ASSERT_VK_SUCCESS(err);
10439 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
10440 ASSERT_VK_SUCCESS(err);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010441
10442 VkBufferViewCreateInfo buff_view_ci = {};
10443 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
10444 buff_view_ci.buffer = buffer;
10445 buff_view_ci.format = VK_FORMAT_R8_UNORM;
10446 buff_view_ci.range = VK_WHOLE_SIZE;
10447 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010448 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010449 ASSERT_VK_SUCCESS(err);
10450
Tony Barbour415497c2017-01-24 10:06:09 -070010451 // Now get resources / view for storage_texel_buffer
10452 vkGetBufferMemoryRequirements(m_device->device(), storage_texel_buffer, &mem_reqs);
10453 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc_info, 0);
10454 if (!pass) {
10455 vkDestroyBuffer(m_device->device(), buffer, NULL);
10456 vkDestroyBufferView(m_device->device(), buff_view, NULL);
10457 vkFreeMemory(m_device->device(), mem, NULL);
10458 vkDestroyBuffer(m_device->device(), storage_texel_buffer, NULL);
10459 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10460 return;
10461 }
10462 VkDeviceMemory storage_texel_buffer_mem;
10463 VkBufferView storage_texel_buffer_view;
10464 err = vkAllocateMemory(m_device->device(), &mem_alloc_info, NULL, &storage_texel_buffer_mem);
10465 ASSERT_VK_SUCCESS(err);
10466 err = vkBindBufferMemory(m_device->device(), storage_texel_buffer, storage_texel_buffer_mem, 0);
10467 ASSERT_VK_SUCCESS(err);
10468 buff_view_ci.buffer = storage_texel_buffer;
10469 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &storage_texel_buffer_view);
10470 ASSERT_VK_SUCCESS(err);
10471
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010472 // Create an image to be used for invalid updates
Tony Barbour4b4a4222017-01-24 11:46:34 -070010473 // Find a format / tiling for COLOR_ATTACHMENT
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010474 VkImageCreateInfo image_ci = {};
Tony Barbour4b4a4222017-01-24 11:46:34 -070010475 image_ci.format = VK_FORMAT_UNDEFINED;
10476 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
10477 VkFormat format = static_cast<VkFormat>(f);
10478 VkFormatProperties fProps = m_device->format_properties(format);
10479 if (fProps.linearTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) {
10480 image_ci.format = format;
10481 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
10482 break;
10483 } else if (fProps.optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) {
10484 image_ci.format = format;
10485 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
10486 break;
10487 }
10488 }
10489 if (image_ci.format == VK_FORMAT_UNDEFINED) {
10490 return;
10491 }
10492
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010493 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10494 image_ci.imageType = VK_IMAGE_TYPE_2D;
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010495 image_ci.extent.width = 64;
10496 image_ci.extent.height = 64;
10497 image_ci.extent.depth = 1;
10498 image_ci.mipLevels = 1;
10499 image_ci.arrayLayers = 1;
10500 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010501 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
Tony Barbour4b4a4222017-01-24 11:46:34 -070010502 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010503 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
10504 VkImage image;
10505 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
10506 ASSERT_VK_SUCCESS(err);
10507 // Bind memory to image
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010508 VkDeviceMemory image_mem;
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -070010509
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010510 VkMemoryAllocateInfo mem_alloc = {};
10511 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10512 mem_alloc.pNext = NULL;
10513 mem_alloc.allocationSize = 0;
10514 mem_alloc.memoryTypeIndex = 0;
10515 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
10516 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010517 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010518 ASSERT_TRUE(pass);
10519 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
10520 ASSERT_VK_SUCCESS(err);
10521 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
10522 ASSERT_VK_SUCCESS(err);
10523 // Now create view for image
10524 VkImageViewCreateInfo image_view_ci = {};
10525 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
10526 image_view_ci.image = image;
Tony Barbour4b4a4222017-01-24 11:46:34 -070010527 image_view_ci.format = image_ci.format;
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010528 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
10529 image_view_ci.subresourceRange.layerCount = 1;
10530 image_view_ci.subresourceRange.baseArrayLayer = 0;
10531 image_view_ci.subresourceRange.levelCount = 1;
10532 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10533 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010534 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010535 ASSERT_VK_SUCCESS(err);
10536
10537 VkDescriptorBufferInfo buff_info = {};
10538 buff_info.buffer = buffer;
10539 VkDescriptorImageInfo img_info = {};
10540 img_info.imageView = image_view;
10541 VkWriteDescriptorSet descriptor_write = {};
10542 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10543 descriptor_write.dstBinding = 0;
10544 descriptor_write.descriptorCount = 1;
10545 descriptor_write.pTexelBufferView = &buff_view;
10546 descriptor_write.pBufferInfo = &buff_info;
10547 descriptor_write.pImageInfo = &img_info;
10548
10549 // These error messages align with VkDescriptorType struct
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -070010550 UNIQUE_VALIDATION_ERROR_CODE error_codes[] = {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010551 VALIDATION_ERROR_00943, // placeholder, no error for SAMPLER descriptor
10552 VALIDATION_ERROR_00943, // COMBINED_IMAGE_SAMPLER
10553 VALIDATION_ERROR_00943, // SAMPLED_IMAGE
10554 VALIDATION_ERROR_00943, // STORAGE_IMAGE
10555 VALIDATION_ERROR_00950, // UNIFORM_TEXEL_BUFFER
10556 VALIDATION_ERROR_00951, // STORAGE_TEXEL_BUFFER
10557 VALIDATION_ERROR_00946, // UNIFORM_BUFFER
10558 VALIDATION_ERROR_00947, // STORAGE_BUFFER
10559 VALIDATION_ERROR_00946, // UNIFORM_BUFFER_DYNAMIC
10560 VALIDATION_ERROR_00947, // STORAGE_BUFFER_DYNAMIC
10561 VALIDATION_ERROR_00943 // INPUT_ATTACHMENT
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -070010562 };
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010563 // Start loop at 1 as SAMPLER desc type has no usage bit error
10564 for (uint32_t i = 1; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
Tony Barbour415497c2017-01-24 10:06:09 -070010565 if (VkDescriptorType(i) == VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER) {
10566 // Now check for UNIFORM_TEXEL_BUFFER using storage_texel_buffer_view
10567 descriptor_write.pTexelBufferView = &storage_texel_buffer_view;
10568 }
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010569 descriptor_write.descriptorType = VkDescriptorType(i);
10570 descriptor_write.dstSet = descriptor_sets[i];
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -070010571 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_codes[i]);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010572
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010573 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010574
10575 m_errorMonitor->VerifyFound();
10576 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[i], NULL);
Tony Barbour415497c2017-01-24 10:06:09 -070010577 if (VkDescriptorType(i) == VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER) {
10578 descriptor_write.pTexelBufferView = &buff_view;
10579 }
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010580 }
Tony Barbour415497c2017-01-24 10:06:09 -070010581
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010582 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[0], NULL);
10583 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -060010584 vkFreeMemory(m_device->device(), image_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010585 vkDestroyImageView(m_device->device(), image_view, NULL);
10586 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tony Barbour415497c2017-01-24 10:06:09 -070010587 vkDestroyBuffer(m_device->device(), storage_texel_buffer, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010588 vkDestroyBufferView(m_device->device(), buff_view, NULL);
Tony Barbour415497c2017-01-24 10:06:09 -070010589 vkDestroyBufferView(m_device->device(), storage_texel_buffer_view, NULL);
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -070010590 vkFreeMemory(m_device->device(), mem, NULL);
Tony Barbour415497c2017-01-24 10:06:09 -070010591 vkFreeMemory(m_device->device(), storage_texel_buffer_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010592 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10593}
10594
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010595TEST_F(VkLayerTest, DSBufferInfoErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010596 TEST_DESCRIPTION(
10597 "Attempt to update buffer descriptor set that has incorrect "
10598 "parameters in VkDescriptorBufferInfo struct. This includes:\n"
Jeremy Hayesd1a6a822017-03-09 14:39:45 -070010599 "1. offset value greater than or equal to buffer size\n"
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010600 "2. range value of 0\n"
10601 "3. range value greater than buffer (size - offset)");
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010602 VkResult err;
10603
Tony Barbour1fa09702017-03-16 12:09:08 -060010604 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010605 VkDescriptorPoolSize ds_type_count = {};
10606 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10607 ds_type_count.descriptorCount = 1;
10608
10609 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10610 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10611 ds_pool_ci.pNext = NULL;
Jeremy Hayesd1a6a822017-03-09 14:39:45 -070010612 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010613 ds_pool_ci.maxSets = 1;
10614 ds_pool_ci.poolSizeCount = 1;
10615 ds_pool_ci.pPoolSizes = &ds_type_count;
10616
10617 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010618 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010619 ASSERT_VK_SUCCESS(err);
10620
10621 // Create layout with single uniform buffer descriptor
10622 VkDescriptorSetLayoutBinding dsl_binding = {};
10623 dsl_binding.binding = 0;
10624 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10625 dsl_binding.descriptorCount = 1;
10626 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10627 dsl_binding.pImmutableSamplers = NULL;
10628
10629 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10630 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10631 ds_layout_ci.pNext = NULL;
10632 ds_layout_ci.bindingCount = 1;
10633 ds_layout_ci.pBindings = &dsl_binding;
10634 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010635 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010636 ASSERT_VK_SUCCESS(err);
10637
10638 VkDescriptorSet descriptor_set = {};
10639 VkDescriptorSetAllocateInfo alloc_info = {};
10640 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10641 alloc_info.descriptorSetCount = 1;
10642 alloc_info.descriptorPool = ds_pool;
10643 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010644 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010645 ASSERT_VK_SUCCESS(err);
10646
10647 // Create a buffer to be used for invalid updates
10648 VkBufferCreateInfo buff_ci = {};
10649 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
10650 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
Jeremy Hayesd1a6a822017-03-09 14:39:45 -070010651 buff_ci.size = m_device->props.limits.minUniformBufferOffsetAlignment;
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010652 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
10653 VkBuffer buffer;
10654 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
10655 ASSERT_VK_SUCCESS(err);
Jeremy Hayesd1a6a822017-03-09 14:39:45 -070010656
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010657 // Have to bind memory to buffer before descriptor update
10658 VkMemoryAllocateInfo mem_alloc = {};
10659 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10660 mem_alloc.pNext = NULL;
Jeremy Hayesd1a6a822017-03-09 14:39:45 -070010661 mem_alloc.allocationSize = buff_ci.size;
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010662 mem_alloc.memoryTypeIndex = 0;
10663
10664 VkMemoryRequirements mem_reqs;
10665 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010666 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010667 if (!pass) {
10668 vkDestroyBuffer(m_device->device(), buffer, NULL);
10669 return;
10670 }
10671
10672 VkDeviceMemory mem;
10673 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
10674 ASSERT_VK_SUCCESS(err);
10675 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
10676 ASSERT_VK_SUCCESS(err);
10677
10678 VkDescriptorBufferInfo buff_info = {};
10679 buff_info.buffer = buffer;
Jeremy Hayesd1a6a822017-03-09 14:39:45 -070010680 // Cause error due to offset out of range
10681 buff_info.offset = buff_ci.size;
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010682 buff_info.range = VK_WHOLE_SIZE;
10683 VkWriteDescriptorSet descriptor_write = {};
10684 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10685 descriptor_write.dstBinding = 0;
10686 descriptor_write.descriptorCount = 1;
10687 descriptor_write.pTexelBufferView = nullptr;
10688 descriptor_write.pBufferInfo = &buff_info;
10689 descriptor_write.pImageInfo = nullptr;
10690
10691 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10692 descriptor_write.dstSet = descriptor_set;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070010693 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00959);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010694
10695 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10696
10697 m_errorMonitor->VerifyFound();
10698 // Now cause error due to range of 0
10699 buff_info.offset = 0;
10700 buff_info.range = 0;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070010701 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00960);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010702
10703 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10704
10705 m_errorMonitor->VerifyFound();
10706 // Now cause error due to range exceeding buffer size - offset
Jeremy Hayesd1a6a822017-03-09 14:39:45 -070010707 buff_info.offset = 0;
10708 buff_info.range = buff_ci.size + 1;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070010709 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00961);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010710
10711 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10712
10713 m_errorMonitor->VerifyFound();
Mark Lobodzinski4bb54092016-07-06 14:27:19 -060010714 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010715 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10716 vkDestroyBuffer(m_device->device(), buffer, NULL);
10717 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
10718 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10719}
10720
Tobin Ehlis845887e2017-02-02 19:01:44 -070010721TEST_F(VkLayerTest, DSBufferLimitErrors) {
10722 TEST_DESCRIPTION(
10723 "Attempt to update buffer descriptor set that has VkDescriptorBufferInfo values that violate device limits.\n"
10724 "Test cases include:\n"
10725 "1. range of uniform buffer update exceeds maxUniformBufferRange\n"
10726 "2. offset of uniform buffer update is not multiple of minUniformBufferOffsetAlignment\n"
10727 "3. range of storage buffer update exceeds maxStorageBufferRange\n"
10728 "4. offset of storage buffer update is not multiple of minStorageBufferOffsetAlignment");
10729 VkResult err;
10730
Tony Barbour1fa09702017-03-16 12:09:08 -060010731 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis845887e2017-02-02 19:01:44 -070010732 VkDescriptorPoolSize ds_type_count[2] = {};
10733 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10734 ds_type_count[0].descriptorCount = 1;
10735 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
10736 ds_type_count[1].descriptorCount = 1;
10737
10738 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10739 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10740 ds_pool_ci.pNext = NULL;
10741 ds_pool_ci.maxSets = 1;
10742 ds_pool_ci.poolSizeCount = 2;
10743 ds_pool_ci.pPoolSizes = ds_type_count;
10744
10745 VkDescriptorPool ds_pool;
10746 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
10747 ASSERT_VK_SUCCESS(err);
10748
10749 // Create layout with single uniform buffer & single storage buffer descriptor
10750 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
10751 dsl_binding[0].binding = 0;
10752 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10753 dsl_binding[0].descriptorCount = 1;
10754 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
10755 dsl_binding[0].pImmutableSamplers = NULL;
10756 dsl_binding[1].binding = 1;
10757 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
10758 dsl_binding[1].descriptorCount = 1;
10759 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
10760 dsl_binding[1].pImmutableSamplers = NULL;
10761
10762 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10763 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10764 ds_layout_ci.pNext = NULL;
10765 ds_layout_ci.bindingCount = 2;
10766 ds_layout_ci.pBindings = dsl_binding;
10767 VkDescriptorSetLayout ds_layout;
10768 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
10769 ASSERT_VK_SUCCESS(err);
10770
10771 VkDescriptorSet descriptor_set = {};
10772 VkDescriptorSetAllocateInfo alloc_info = {};
10773 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10774 alloc_info.descriptorSetCount = 1;
10775 alloc_info.descriptorPool = ds_pool;
10776 alloc_info.pSetLayouts = &ds_layout;
10777 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
10778 ASSERT_VK_SUCCESS(err);
10779
10780 // Create a buffer to be used for invalid updates
10781 auto max_ub_range = m_device->props.limits.maxUniformBufferRange;
10782 auto min_ub_align = m_device->props.limits.minUniformBufferOffsetAlignment;
10783 auto max_sb_range = m_device->props.limits.maxStorageBufferRange;
10784 auto min_sb_align = m_device->props.limits.minStorageBufferOffsetAlignment;
10785 VkBufferCreateInfo ub_ci = {};
10786 ub_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
10787 ub_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
10788 ub_ci.size = max_ub_range + 128; // Make buffer bigger than range limit
10789 ub_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
10790 VkBuffer uniform_buffer;
10791 err = vkCreateBuffer(m_device->device(), &ub_ci, NULL, &uniform_buffer);
10792 ASSERT_VK_SUCCESS(err);
10793 VkBufferCreateInfo sb_ci = {};
10794 sb_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
10795 sb_ci.usage = VK_BUFFER_USAGE_STORAGE_BUFFER_BIT;
10796 sb_ci.size = max_sb_range + 128; // Make buffer bigger than range limit
10797 sb_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
10798 VkBuffer storage_buffer;
10799 err = vkCreateBuffer(m_device->device(), &sb_ci, NULL, &storage_buffer);
10800 ASSERT_VK_SUCCESS(err);
10801 // Have to bind memory to buffer before descriptor update
10802 VkMemoryAllocateInfo mem_alloc = {};
10803 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10804 mem_alloc.pNext = NULL;
10805 mem_alloc.allocationSize = ub_ci.size + sb_ci.size + 1024; // additional buffer for offset
10806 mem_alloc.memoryTypeIndex = 0;
10807
Cort Stratton77a0d592017-02-17 13:14:13 -080010808 VkMemoryRequirements ub_mem_reqs, sb_mem_reqs;
10809 vkGetBufferMemoryRequirements(m_device->device(), uniform_buffer, &ub_mem_reqs);
10810 bool pass = m_device->phy().set_memory_type(ub_mem_reqs.memoryTypeBits, &mem_alloc, 0);
10811 vkGetBufferMemoryRequirements(m_device->device(), storage_buffer, &sb_mem_reqs);
10812 pass &= m_device->phy().set_memory_type(sb_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis845887e2017-02-02 19:01:44 -070010813 if (!pass) {
Tobin Ehlis15c83792017-02-07 10:09:33 -070010814 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Tobin Ehlis845887e2017-02-02 19:01:44 -070010815 vkDestroyBuffer(m_device->device(), uniform_buffer, NULL);
Tobin Ehlis15c83792017-02-07 10:09:33 -070010816 vkDestroyBuffer(m_device->device(), storage_buffer, NULL);
10817 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis845887e2017-02-02 19:01:44 -070010818 return;
10819 }
10820
10821 VkDeviceMemory mem;
10822 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlis15c83792017-02-07 10:09:33 -070010823 if (VK_SUCCESS != err) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070010824 printf(" Failed to allocate memory in DSBufferLimitErrors; skipped.\n");
Tobin Ehlis15c83792017-02-07 10:09:33 -070010825 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10826 vkDestroyBuffer(m_device->device(), uniform_buffer, NULL);
10827 vkDestroyBuffer(m_device->device(), storage_buffer, NULL);
10828 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10829 return;
10830 }
Tobin Ehlis845887e2017-02-02 19:01:44 -070010831 ASSERT_VK_SUCCESS(err);
10832 err = vkBindBufferMemory(m_device->device(), uniform_buffer, mem, 0);
10833 ASSERT_VK_SUCCESS(err);
Cort Stratton77a0d592017-02-17 13:14:13 -080010834 auto sb_offset = (ub_ci.size + sb_mem_reqs.alignment - 1) & ~(sb_mem_reqs.alignment - 1);
Tobin Ehlis845887e2017-02-02 19:01:44 -070010835 err = vkBindBufferMemory(m_device->device(), storage_buffer, mem, sb_offset);
10836 ASSERT_VK_SUCCESS(err);
10837
10838 VkDescriptorBufferInfo buff_info = {};
10839 buff_info.buffer = uniform_buffer;
10840 buff_info.range = ub_ci.size; // This will exceed limit
10841 VkWriteDescriptorSet descriptor_write = {};
10842 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10843 descriptor_write.dstBinding = 0;
10844 descriptor_write.descriptorCount = 1;
10845 descriptor_write.pTexelBufferView = nullptr;
10846 descriptor_write.pBufferInfo = &buff_info;
10847 descriptor_write.pImageInfo = nullptr;
10848
10849 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10850 descriptor_write.dstSet = descriptor_set;
Tony Barbour02d08552017-03-24 16:36:01 -060010851 if (max_ub_range != UINT32_MAX) {
10852 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00948);
10853 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10854 m_errorMonitor->VerifyFound();
10855 }
Tobin Ehlis845887e2017-02-02 19:01:44 -070010856 // Reduce size of range to acceptable limit & cause offset error
10857 buff_info.range = max_ub_range;
10858 buff_info.offset = min_ub_align - 1;
10859 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00944);
10860 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10861 m_errorMonitor->VerifyFound();
10862
10863 // Now break storage updates
10864 buff_info.buffer = storage_buffer;
10865 buff_info.range = sb_ci.size; // This will exceed limit
10866 buff_info.offset = 0; // Reset offset for this update
10867
10868 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
10869 descriptor_write.dstBinding = 1;
Tony Barbour02d08552017-03-24 16:36:01 -060010870 if (max_ub_range != UINT32_MAX) {
10871 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00949);
10872 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10873 m_errorMonitor->VerifyFound();
10874 }
Tobin Ehlis845887e2017-02-02 19:01:44 -070010875
10876 // Reduce size of range to acceptable limit & cause offset error
10877 buff_info.range = max_sb_range;
10878 buff_info.offset = min_sb_align - 1;
10879 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00945);
10880 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10881 m_errorMonitor->VerifyFound();
10882
10883 vkFreeMemory(m_device->device(), mem, NULL);
10884 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10885 vkDestroyBuffer(m_device->device(), uniform_buffer, NULL);
10886 vkDestroyBuffer(m_device->device(), storage_buffer, NULL);
10887 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10888}
10889
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010890TEST_F(VkLayerTest, DSAspectBitsErrors) {
10891 // TODO : Initially only catching case where DEPTH & STENCIL aspect bits
10892 // are set, but could expand this test to hit more cases.
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010893 TEST_DESCRIPTION(
10894 "Attempt to update descriptor sets for images "
10895 "that do not have correct aspect bits sets.");
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010896 VkResult err;
10897
Tony Barbour1fa09702017-03-16 12:09:08 -060010898 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -060010899 auto depth_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbourf887b162017-03-09 10:06:46 -070010900 if (!depth_format) {
10901 printf(" No Depth + Stencil format found. Skipped.\n");
10902 return;
10903 }
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010904 VkDescriptorPoolSize ds_type_count = {};
10905 ds_type_count.type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
10906 ds_type_count.descriptorCount = 1;
10907
10908 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10909 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10910 ds_pool_ci.pNext = NULL;
Jeremy Hayes293c7ed2017-03-09 14:47:07 -070010911 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010912 ds_pool_ci.maxSets = 5;
10913 ds_pool_ci.poolSizeCount = 1;
10914 ds_pool_ci.pPoolSizes = &ds_type_count;
10915
10916 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010917 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010918 ASSERT_VK_SUCCESS(err);
10919
10920 VkDescriptorSetLayoutBinding dsl_binding = {};
10921 dsl_binding.binding = 0;
10922 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
10923 dsl_binding.descriptorCount = 1;
10924 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10925 dsl_binding.pImmutableSamplers = NULL;
10926
10927 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10928 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10929 ds_layout_ci.pNext = NULL;
10930 ds_layout_ci.bindingCount = 1;
10931 ds_layout_ci.pBindings = &dsl_binding;
10932 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010933 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010934 ASSERT_VK_SUCCESS(err);
10935
10936 VkDescriptorSet descriptor_set = {};
10937 VkDescriptorSetAllocateInfo alloc_info = {};
10938 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10939 alloc_info.descriptorSetCount = 1;
10940 alloc_info.descriptorPool = ds_pool;
10941 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010942 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010943 ASSERT_VK_SUCCESS(err);
10944
10945 // Create an image to be used for invalid updates
10946 VkImageCreateInfo image_ci = {};
10947 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10948 image_ci.imageType = VK_IMAGE_TYPE_2D;
Tony Barbourf887b162017-03-09 10:06:46 -070010949 image_ci.format = depth_format;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010950 image_ci.extent.width = 64;
10951 image_ci.extent.height = 64;
10952 image_ci.extent.depth = 1;
10953 image_ci.mipLevels = 1;
10954 image_ci.arrayLayers = 1;
10955 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Young2d1fa302017-03-02 10:13:09 -070010956 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010957 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
10958 image_ci.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
10959 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
10960 VkImage image;
10961 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
10962 ASSERT_VK_SUCCESS(err);
10963 // Bind memory to image
10964 VkMemoryRequirements mem_reqs;
10965 VkDeviceMemory image_mem;
10966 bool pass;
10967 VkMemoryAllocateInfo mem_alloc = {};
10968 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10969 mem_alloc.pNext = NULL;
10970 mem_alloc.allocationSize = 0;
10971 mem_alloc.memoryTypeIndex = 0;
10972 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
10973 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010974 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010975 ASSERT_TRUE(pass);
10976 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
10977 ASSERT_VK_SUCCESS(err);
10978 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
10979 ASSERT_VK_SUCCESS(err);
10980 // Now create view for image
10981 VkImageViewCreateInfo image_view_ci = {};
10982 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
10983 image_view_ci.image = image;
Tony Barbourf887b162017-03-09 10:06:46 -070010984 image_view_ci.format = depth_format;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010985 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
10986 image_view_ci.subresourceRange.layerCount = 1;
10987 image_view_ci.subresourceRange.baseArrayLayer = 0;
10988 image_view_ci.subresourceRange.levelCount = 1;
10989 // Setting both depth & stencil aspect bits is illegal for descriptor
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010990 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010991
10992 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010993 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010994 ASSERT_VK_SUCCESS(err);
10995
10996 VkDescriptorImageInfo img_info = {};
10997 img_info.imageView = image_view;
10998 VkWriteDescriptorSet descriptor_write = {};
10999 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11000 descriptor_write.dstBinding = 0;
11001 descriptor_write.descriptorCount = 1;
11002 descriptor_write.pTexelBufferView = NULL;
11003 descriptor_write.pBufferInfo = NULL;
11004 descriptor_write.pImageInfo = &img_info;
11005 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
11006 descriptor_write.dstSet = descriptor_set;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011007 const char *error_msg =
11008 " please only set either VK_IMAGE_ASPECT_DEPTH_BIT "
11009 "or VK_IMAGE_ASPECT_STENCIL_BIT ";
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011010 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msg);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060011011
11012 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11013
11014 m_errorMonitor->VerifyFound();
11015 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11016 vkDestroyImage(m_device->device(), image, NULL);
11017 vkFreeMemory(m_device->device(), image_mem, NULL);
11018 vkDestroyImageView(m_device->device(), image_view, NULL);
11019 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
11020 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11021}
11022
Karl Schultz6addd812016-02-02 17:17:23 -070011023TEST_F(VkLayerTest, DSTypeMismatch) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060011024 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Karl Schultz6addd812016-02-02 17:17:23 -070011025 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011026
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011027 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11028 " binding #0 with type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER but update "
11029 "type is VK_DESCRIPTOR_TYPE_SAMPLER");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011030
Tony Barbour1fa09702017-03-16 12:09:08 -060011031 ASSERT_NO_FATAL_FAILURE(Init());
Karl Schultz6addd812016-02-02 17:17:23 -070011032 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011033 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011034 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11035 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011036
11037 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011038 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11039 ds_pool_ci.pNext = NULL;
11040 ds_pool_ci.maxSets = 1;
11041 ds_pool_ci.poolSizeCount = 1;
11042 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060011043
Tobin Ehlis3b780662015-05-28 12:11:26 -060011044 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011045 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011046 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -060011047 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011048 dsl_binding.binding = 0;
11049 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11050 dsl_binding.descriptorCount = 1;
11051 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11052 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011053
Tony Barboureb254902015-07-15 12:50:33 -060011054 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011055 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11056 ds_layout_ci.pNext = NULL;
11057 ds_layout_ci.bindingCount = 1;
11058 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060011059
Tobin Ehlis3b780662015-05-28 12:11:26 -060011060 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011061 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011062 ASSERT_VK_SUCCESS(err);
11063
11064 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011065 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011066 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011067 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011068 alloc_info.descriptorPool = ds_pool;
11069 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011070 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011071 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011072
Tobin Ehlis30db8f82016-05-05 08:19:48 -060011073 VkSamplerCreateInfo sampler_ci = {};
11074 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11075 sampler_ci.pNext = NULL;
11076 sampler_ci.magFilter = VK_FILTER_NEAREST;
11077 sampler_ci.minFilter = VK_FILTER_NEAREST;
11078 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11079 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11080 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11081 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11082 sampler_ci.mipLodBias = 1.0;
11083 sampler_ci.anisotropyEnable = VK_FALSE;
11084 sampler_ci.maxAnisotropy = 1;
11085 sampler_ci.compareEnable = VK_FALSE;
11086 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11087 sampler_ci.minLod = 1.0;
11088 sampler_ci.maxLod = 1.0;
11089 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11090 sampler_ci.unnormalizedCoordinates = VK_FALSE;
11091 VkSampler sampler;
11092 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
11093 ASSERT_VK_SUCCESS(err);
11094
11095 VkDescriptorImageInfo info = {};
11096 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011097
11098 VkWriteDescriptorSet descriptor_write;
11099 memset(&descriptor_write, 0, sizeof(descriptor_write));
11100 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011101 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011102 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011103 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011104 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060011105 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011106
11107 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11108
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011109 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011110
Chia-I Wuf7458c52015-10-26 21:10:41 +080011111 vkDestroySampler(m_device->device(), sampler, NULL);
11112 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11113 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060011114}
11115
Karl Schultz6addd812016-02-02 17:17:23 -070011116TEST_F(VkLayerTest, DSUpdateOutOfBounds) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060011117 // For overlapping Update, have arrayIndex exceed that of layout
Karl Schultz6addd812016-02-02 17:17:23 -070011118 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011119
Tobin Ehlisf922ef82016-11-30 10:19:14 -070011120 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00938);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011121
Tony Barbour1fa09702017-03-16 12:09:08 -060011122 ASSERT_NO_FATAL_FAILURE(Init());
Karl Schultz6addd812016-02-02 17:17:23 -070011123 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011124 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011125 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11126 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011127
11128 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011129 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11130 ds_pool_ci.pNext = NULL;
11131 ds_pool_ci.maxSets = 1;
11132 ds_pool_ci.poolSizeCount = 1;
11133 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060011134
Tobin Ehlis3b780662015-05-28 12:11:26 -060011135 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011136 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011137 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011138
Tony Barboureb254902015-07-15 12:50:33 -060011139 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011140 dsl_binding.binding = 0;
11141 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11142 dsl_binding.descriptorCount = 1;
11143 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11144 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -060011145
11146 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011147 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11148 ds_layout_ci.pNext = NULL;
11149 ds_layout_ci.bindingCount = 1;
11150 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060011151
Tobin Ehlis3b780662015-05-28 12:11:26 -060011152 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011153 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011154 ASSERT_VK_SUCCESS(err);
11155
11156 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011157 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011158 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011159 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011160 alloc_info.descriptorPool = ds_pool;
11161 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011162 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011163 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011164
Jeremy Hayesd5b95db2017-03-09 15:24:24 -070011165 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
11166
Tobin Ehlis30db8f82016-05-05 08:19:48 -060011167 // Correctly update descriptor to avoid "NOT_UPDATED" error
11168 VkDescriptorBufferInfo buff_info = {};
Jeremy Hayesd5b95db2017-03-09 15:24:24 -070011169 buff_info.buffer = buffer_test.GetBuffer();
Tobin Ehlis30db8f82016-05-05 08:19:48 -060011170 buff_info.offset = 0;
11171 buff_info.range = 1024;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011172
11173 VkWriteDescriptorSet descriptor_write;
11174 memset(&descriptor_write, 0, sizeof(descriptor_write));
11175 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011176 descriptor_write.dstSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011177 descriptor_write.dstArrayElement = 1; /* This index out of bounds for the update */
Chia-I Wud50a7d72015-10-26 20:48:51 +080011178 descriptor_write.descriptorCount = 1;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -060011179 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11180 descriptor_write.pBufferInfo = &buff_info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011181
11182 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11183
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011184 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011185
Chia-I Wuf7458c52015-10-26 21:10:41 +080011186 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11187 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060011188}
11189
Karl Schultz6addd812016-02-02 17:17:23 -070011190TEST_F(VkLayerTest, InvalidDSUpdateIndex) {
Tobin Ehlisc8d352d2016-11-21 10:33:40 -070011191 // Create layout w/ count of 1 and attempt update to that layout w/ binding index 2
Karl Schultz6addd812016-02-02 17:17:23 -070011192 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011193
Tobin Ehlisc8d352d2016-11-21 10:33:40 -070011194 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00936);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011195
Tony Barbour1fa09702017-03-16 12:09:08 -060011196 ASSERT_NO_FATAL_FAILURE(Init());
Karl Schultz6addd812016-02-02 17:17:23 -070011197 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011198 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011199 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11200 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011201
11202 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011203 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11204 ds_pool_ci.pNext = NULL;
11205 ds_pool_ci.maxSets = 1;
11206 ds_pool_ci.poolSizeCount = 1;
11207 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060011208
Tobin Ehlis3b780662015-05-28 12:11:26 -060011209 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011210 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011211 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011212
Tony Barboureb254902015-07-15 12:50:33 -060011213 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011214 dsl_binding.binding = 0;
11215 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11216 dsl_binding.descriptorCount = 1;
11217 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11218 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -060011219
11220 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011221 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11222 ds_layout_ci.pNext = NULL;
11223 ds_layout_ci.bindingCount = 1;
11224 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011225 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011226 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011227 ASSERT_VK_SUCCESS(err);
11228
11229 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011230 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011231 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011232 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011233 alloc_info.descriptorPool = ds_pool;
11234 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011235 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011236 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011237
Tony Barboureb254902015-07-15 12:50:33 -060011238 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011239 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11240 sampler_ci.pNext = NULL;
11241 sampler_ci.magFilter = VK_FILTER_NEAREST;
11242 sampler_ci.minFilter = VK_FILTER_NEAREST;
11243 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11244 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11245 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11246 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11247 sampler_ci.mipLodBias = 1.0;
11248 sampler_ci.anisotropyEnable = VK_FALSE;
11249 sampler_ci.maxAnisotropy = 1;
11250 sampler_ci.compareEnable = VK_FALSE;
11251 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11252 sampler_ci.minLod = 1.0;
11253 sampler_ci.maxLod = 1.0;
11254 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11255 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -060011256
Tobin Ehlis3b780662015-05-28 12:11:26 -060011257 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011258 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011259 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011260
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060011261 VkDescriptorImageInfo info = {};
11262 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011263
11264 VkWriteDescriptorSet descriptor_write;
11265 memset(&descriptor_write, 0, sizeof(descriptor_write));
11266 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011267 descriptor_write.dstSet = descriptorSet;
11268 descriptor_write.dstBinding = 2;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011269 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011270 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011271 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060011272 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011273
11274 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11275
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011276 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011277
Chia-I Wuf7458c52015-10-26 21:10:41 +080011278 vkDestroySampler(m_device->device(), sampler, NULL);
11279 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11280 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060011281}
11282
Tobin Ehlise202b2d2016-11-21 10:36:16 -070011283TEST_F(VkLayerTest, DSUpdateEmptyBinding) {
11284 // Create layout w/ empty binding and attempt to update it
11285 VkResult err;
11286
Tony Barbour1fa09702017-03-16 12:09:08 -060011287 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlise202b2d2016-11-21 10:36:16 -070011288
11289 VkDescriptorPoolSize ds_type_count = {};
11290 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
11291 ds_type_count.descriptorCount = 1;
11292
11293 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11294 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11295 ds_pool_ci.pNext = NULL;
11296 ds_pool_ci.maxSets = 1;
11297 ds_pool_ci.poolSizeCount = 1;
11298 ds_pool_ci.pPoolSizes = &ds_type_count;
11299
11300 VkDescriptorPool ds_pool;
11301 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
11302 ASSERT_VK_SUCCESS(err);
11303
11304 VkDescriptorSetLayoutBinding dsl_binding = {};
11305 dsl_binding.binding = 0;
11306 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
11307 dsl_binding.descriptorCount = 0;
11308 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11309 dsl_binding.pImmutableSamplers = NULL;
11310
11311 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11312 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11313 ds_layout_ci.pNext = NULL;
11314 ds_layout_ci.bindingCount = 1;
11315 ds_layout_ci.pBindings = &dsl_binding;
11316 VkDescriptorSetLayout ds_layout;
11317 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
11318 ASSERT_VK_SUCCESS(err);
11319
11320 VkDescriptorSet descriptor_set;
11321 VkDescriptorSetAllocateInfo alloc_info = {};
11322 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11323 alloc_info.descriptorSetCount = 1;
11324 alloc_info.descriptorPool = ds_pool;
11325 alloc_info.pSetLayouts = &ds_layout;
11326 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
11327 ASSERT_VK_SUCCESS(err);
11328
11329 VkSamplerCreateInfo sampler_ci = {};
11330 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11331 sampler_ci.magFilter = VK_FILTER_NEAREST;
11332 sampler_ci.minFilter = VK_FILTER_NEAREST;
11333 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11334 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11335 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11336 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11337 sampler_ci.mipLodBias = 1.0;
11338 sampler_ci.maxAnisotropy = 1;
11339 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11340 sampler_ci.minLod = 1.0;
11341 sampler_ci.maxLod = 1.0;
11342 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11343
11344 VkSampler sampler;
11345 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
11346 ASSERT_VK_SUCCESS(err);
11347
11348 VkDescriptorImageInfo info = {};
11349 info.sampler = sampler;
11350
11351 VkWriteDescriptorSet descriptor_write;
11352 memset(&descriptor_write, 0, sizeof(descriptor_write));
11353 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11354 descriptor_write.dstSet = descriptor_set;
11355 descriptor_write.dstBinding = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011356 descriptor_write.descriptorCount = 1; // Lie here to avoid parameter_validation error
Tobin Ehlise202b2d2016-11-21 10:36:16 -070011357 // This is the wrong type, but empty binding error will be flagged first
11358 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
11359 descriptor_write.pImageInfo = &info;
11360
11361 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02348);
11362 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11363 m_errorMonitor->VerifyFound();
11364
11365 vkDestroySampler(m_device->device(), sampler, NULL);
11366 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11367 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11368}
11369
Karl Schultz6addd812016-02-02 17:17:23 -070011370TEST_F(VkLayerTest, InvalidDSUpdateStruct) {
11371 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_*
11372 // types
11373 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011374
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011375 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 -060011376
Tony Barbour1fa09702017-03-16 12:09:08 -060011377 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011378
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011379 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011380 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11381 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011382
11383 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011384 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11385 ds_pool_ci.pNext = NULL;
11386 ds_pool_ci.maxSets = 1;
11387 ds_pool_ci.poolSizeCount = 1;
11388 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060011389
Tobin Ehlis3b780662015-05-28 12:11:26 -060011390 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011391 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011392 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -060011393 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011394 dsl_binding.binding = 0;
11395 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11396 dsl_binding.descriptorCount = 1;
11397 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11398 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011399
Tony Barboureb254902015-07-15 12:50:33 -060011400 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011401 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11402 ds_layout_ci.pNext = NULL;
11403 ds_layout_ci.bindingCount = 1;
11404 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060011405
Tobin Ehlis3b780662015-05-28 12:11:26 -060011406 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011407 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011408 ASSERT_VK_SUCCESS(err);
11409
11410 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011411 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011412 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011413 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011414 alloc_info.descriptorPool = ds_pool;
11415 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011416 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011417 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011418
Tony Barboureb254902015-07-15 12:50:33 -060011419 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011420 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11421 sampler_ci.pNext = NULL;
11422 sampler_ci.magFilter = VK_FILTER_NEAREST;
11423 sampler_ci.minFilter = VK_FILTER_NEAREST;
11424 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11425 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11426 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11427 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11428 sampler_ci.mipLodBias = 1.0;
11429 sampler_ci.anisotropyEnable = VK_FALSE;
11430 sampler_ci.maxAnisotropy = 1;
11431 sampler_ci.compareEnable = VK_FALSE;
11432 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11433 sampler_ci.minLod = 1.0;
11434 sampler_ci.maxLod = 1.0;
11435 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11436 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011437 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011438 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011439 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011440
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060011441 VkDescriptorImageInfo info = {};
11442 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011443
11444 VkWriteDescriptorSet descriptor_write;
11445 memset(&descriptor_write, 0, sizeof(descriptor_write));
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011446 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011447 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011448 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011449 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011450 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060011451 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011452
11453 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11454
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011455 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011456
Chia-I Wuf7458c52015-10-26 21:10:41 +080011457 vkDestroySampler(m_device->device(), sampler, NULL);
11458 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11459 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060011460}
11461
Karl Schultz6addd812016-02-02 17:17:23 -070011462TEST_F(VkLayerTest, SampleDescriptorUpdateError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011463 // Create a single Sampler descriptor and send it an invalid Sampler
Karl Schultz6addd812016-02-02 17:17:23 -070011464 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011465
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070011466 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00942);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011467
Tony Barbour1fa09702017-03-16 12:09:08 -060011468 ASSERT_NO_FATAL_FAILURE(Init());
Karl Schultz6addd812016-02-02 17:17:23 -070011469 // TODO : Farm Descriptor setup code to helper function(s) to reduce copied
11470 // code
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011471 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011472 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
11473 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011474
11475 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011476 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11477 ds_pool_ci.pNext = NULL;
11478 ds_pool_ci.maxSets = 1;
11479 ds_pool_ci.poolSizeCount = 1;
11480 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011481
11482 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011483 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011484 ASSERT_VK_SUCCESS(err);
11485
11486 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011487 dsl_binding.binding = 0;
11488 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
11489 dsl_binding.descriptorCount = 1;
11490 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11491 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011492
11493 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011494 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11495 ds_layout_ci.pNext = NULL;
11496 ds_layout_ci.bindingCount = 1;
11497 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011498 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011499 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011500 ASSERT_VK_SUCCESS(err);
11501
11502 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011503 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011504 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011505 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011506 alloc_info.descriptorPool = ds_pool;
11507 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011508 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011509 ASSERT_VK_SUCCESS(err);
11510
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011511 VkSampler sampler = (VkSampler)((size_t)0xbaadbeef); // Sampler with invalid handle
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011512
11513 VkDescriptorImageInfo descriptor_info;
11514 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
11515 descriptor_info.sampler = sampler;
11516
11517 VkWriteDescriptorSet descriptor_write;
11518 memset(&descriptor_write, 0, sizeof(descriptor_write));
11519 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011520 descriptor_write.dstSet = descriptorSet;
11521 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011522 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011523 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
11524 descriptor_write.pImageInfo = &descriptor_info;
11525
11526 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11527
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011528 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011529
Chia-I Wuf7458c52015-10-26 21:10:41 +080011530 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11531 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011532}
11533
Karl Schultz6addd812016-02-02 17:17:23 -070011534TEST_F(VkLayerTest, ImageViewDescriptorUpdateError) {
11535 // Create a single combined Image/Sampler descriptor and send it an invalid
11536 // imageView
11537 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011538
Karl Schultzf78bcdd2016-11-30 12:36:01 -070011539 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00943);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011540
Tony Barbour1fa09702017-03-16 12:09:08 -060011541 ASSERT_NO_FATAL_FAILURE(Init());
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011542 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011543 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11544 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011545
11546 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011547 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11548 ds_pool_ci.pNext = NULL;
11549 ds_pool_ci.maxSets = 1;
11550 ds_pool_ci.poolSizeCount = 1;
11551 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011552
11553 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011554 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011555 ASSERT_VK_SUCCESS(err);
11556
11557 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011558 dsl_binding.binding = 0;
11559 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11560 dsl_binding.descriptorCount = 1;
11561 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11562 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011563
11564 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011565 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11566 ds_layout_ci.pNext = NULL;
11567 ds_layout_ci.bindingCount = 1;
11568 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011569 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011570 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011571 ASSERT_VK_SUCCESS(err);
11572
11573 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011574 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011575 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011576 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011577 alloc_info.descriptorPool = ds_pool;
11578 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011579 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011580 ASSERT_VK_SUCCESS(err);
11581
11582 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011583 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11584 sampler_ci.pNext = NULL;
11585 sampler_ci.magFilter = VK_FILTER_NEAREST;
11586 sampler_ci.minFilter = VK_FILTER_NEAREST;
11587 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11588 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11589 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11590 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11591 sampler_ci.mipLodBias = 1.0;
11592 sampler_ci.anisotropyEnable = VK_FALSE;
11593 sampler_ci.maxAnisotropy = 1;
11594 sampler_ci.compareEnable = VK_FALSE;
11595 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11596 sampler_ci.minLod = 1.0;
11597 sampler_ci.maxLod = 1.0;
11598 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11599 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011600
11601 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011602 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011603 ASSERT_VK_SUCCESS(err);
11604
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011605 VkImageView view = (VkImageView)((size_t)0xbaadbeef); // invalid imageView object
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011606
11607 VkDescriptorImageInfo descriptor_info;
11608 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
11609 descriptor_info.sampler = sampler;
11610 descriptor_info.imageView = view;
11611
11612 VkWriteDescriptorSet descriptor_write;
11613 memset(&descriptor_write, 0, sizeof(descriptor_write));
11614 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011615 descriptor_write.dstSet = descriptorSet;
11616 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011617 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011618 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11619 descriptor_write.pImageInfo = &descriptor_info;
11620
11621 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11622
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011623 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011624
Chia-I Wuf7458c52015-10-26 21:10:41 +080011625 vkDestroySampler(m_device->device(), sampler, NULL);
11626 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11627 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011628}
11629
Karl Schultz6addd812016-02-02 17:17:23 -070011630TEST_F(VkLayerTest, CopyDescriptorUpdateErrors) {
11631 // Create DS w/ layout of 2 types, write update 1 and attempt to copy-update
11632 // into the other
11633 VkResult err;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011634
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011635 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11636 " binding #1 with type "
11637 "VK_DESCRIPTOR_TYPE_SAMPLER. Types do "
11638 "not match.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011639
Tony Barbour1fa09702017-03-16 12:09:08 -060011640 ASSERT_NO_FATAL_FAILURE(Init());
Karl Schultz6addd812016-02-02 17:17:23 -070011641 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011642 VkDescriptorPoolSize ds_type_count[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011643 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11644 ds_type_count[0].descriptorCount = 1;
11645 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
11646 ds_type_count[1].descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011647
11648 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011649 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11650 ds_pool_ci.pNext = NULL;
11651 ds_pool_ci.maxSets = 1;
11652 ds_pool_ci.poolSizeCount = 2;
11653 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011654
11655 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011656 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis04356f92015-10-27 16:35:27 -060011657 ASSERT_VK_SUCCESS(err);
11658 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011659 dsl_binding[0].binding = 0;
11660 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11661 dsl_binding[0].descriptorCount = 1;
11662 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
11663 dsl_binding[0].pImmutableSamplers = NULL;
11664 dsl_binding[1].binding = 1;
11665 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
11666 dsl_binding[1].descriptorCount = 1;
11667 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
11668 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011669
11670 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011671 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11672 ds_layout_ci.pNext = NULL;
11673 ds_layout_ci.bindingCount = 2;
11674 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011675
11676 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011677 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis04356f92015-10-27 16:35:27 -060011678 ASSERT_VK_SUCCESS(err);
11679
11680 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011681 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011682 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011683 alloc_info.descriptorSetCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011684 alloc_info.descriptorPool = ds_pool;
11685 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011686 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis04356f92015-10-27 16:35:27 -060011687 ASSERT_VK_SUCCESS(err);
11688
11689 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011690 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11691 sampler_ci.pNext = NULL;
11692 sampler_ci.magFilter = VK_FILTER_NEAREST;
11693 sampler_ci.minFilter = VK_FILTER_NEAREST;
11694 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11695 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11696 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11697 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11698 sampler_ci.mipLodBias = 1.0;
11699 sampler_ci.anisotropyEnable = VK_FALSE;
11700 sampler_ci.maxAnisotropy = 1;
11701 sampler_ci.compareEnable = VK_FALSE;
11702 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11703 sampler_ci.minLod = 1.0;
11704 sampler_ci.maxLod = 1.0;
11705 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11706 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011707
11708 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011709 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis04356f92015-10-27 16:35:27 -060011710 ASSERT_VK_SUCCESS(err);
11711
11712 VkDescriptorImageInfo info = {};
11713 info.sampler = sampler;
11714
11715 VkWriteDescriptorSet descriptor_write;
11716 memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet));
11717 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011718 descriptor_write.dstSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011719 descriptor_write.dstBinding = 1; // SAMPLER binding from layout above
Chia-I Wud50a7d72015-10-26 20:48:51 +080011720 descriptor_write.descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011721 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
11722 descriptor_write.pImageInfo = &info;
11723 // This write update should succeed
11724 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11725 // Now perform a copy update that fails due to type mismatch
11726 VkCopyDescriptorSet copy_ds_update;
11727 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
11728 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
11729 copy_ds_update.srcSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011730 copy_ds_update.srcBinding = 1; // Copy from SAMPLER binding
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011731 copy_ds_update.dstSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011732 copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding
11733 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -060011734 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
11735
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011736 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -060011737 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011738 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 -060011739 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
11740 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
11741 copy_ds_update.srcSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011742 copy_ds_update.srcBinding = 3; // ERROR : Invalid binding for matching layout
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011743 copy_ds_update.dstSet = descriptorSet;
11744 copy_ds_update.dstBinding = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011745 copy_ds_update.descriptorCount = 1; // Copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -060011746 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
11747
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011748 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011749
Tobin Ehlis04356f92015-10-27 16:35:27 -060011750 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011751 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11752 " binding#1 with offset index of 1 plus "
11753 "update array offset of 0 and update of "
11754 "5 descriptors oversteps total number "
11755 "of descriptors in set: 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011756
Tobin Ehlis04356f92015-10-27 16:35:27 -060011757 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
11758 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
11759 copy_ds_update.srcSet = descriptorSet;
11760 copy_ds_update.srcBinding = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011761 copy_ds_update.dstSet = descriptorSet;
11762 copy_ds_update.dstBinding = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011763 copy_ds_update.descriptorCount = 5; // ERROR copy 5 descriptors (out of bounds for layout)
Tobin Ehlis04356f92015-10-27 16:35:27 -060011764 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
11765
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011766 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -060011767
Chia-I Wuf7458c52015-10-26 21:10:41 +080011768 vkDestroySampler(m_device->device(), sampler, NULL);
11769 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11770 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis04356f92015-10-27 16:35:27 -060011771}
11772
Karl Schultz6addd812016-02-02 17:17:23 -070011773TEST_F(VkLayerTest, NumSamplesMismatch) {
11774 // Create CommandBuffer where MSAA samples doesn't match RenderPass
11775 // sampleCount
11776 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011777
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011778 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Num samples mismatch! ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011779
Tony Barbour1fa09702017-03-16 12:09:08 -060011780 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis3b780662015-05-28 12:11:26 -060011781 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011782 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -060011783 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011784 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011785
11786 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011787 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11788 ds_pool_ci.pNext = NULL;
11789 ds_pool_ci.maxSets = 1;
11790 ds_pool_ci.poolSizeCount = 1;
11791 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060011792
Tobin Ehlis3b780662015-05-28 12:11:26 -060011793 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011794 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011795 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011796
Tony Barboureb254902015-07-15 12:50:33 -060011797 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +080011798 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -060011799 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +080011800 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011801 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11802 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011803
Tony Barboureb254902015-07-15 12:50:33 -060011804 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11805 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11806 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011807 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -070011808 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060011809
Tobin Ehlis3b780662015-05-28 12:11:26 -060011810 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011811 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011812 ASSERT_VK_SUCCESS(err);
11813
11814 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011815 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011816 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011817 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011818 alloc_info.descriptorPool = ds_pool;
11819 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011820 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011821 ASSERT_VK_SUCCESS(err);
11822
Tony Barboureb254902015-07-15 12:50:33 -060011823 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011824 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070011825 pipe_ms_state_ci.pNext = NULL;
11826 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
11827 pipe_ms_state_ci.sampleShadingEnable = 0;
11828 pipe_ms_state_ci.minSampleShading = 1.0;
11829 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011830
Tony Barboureb254902015-07-15 12:50:33 -060011831 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011832 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11833 pipeline_layout_ci.pNext = NULL;
11834 pipeline_layout_ci.setLayoutCount = 1;
11835 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011836
11837 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011838 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011839 ASSERT_VK_SUCCESS(err);
11840
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011841 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011842 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011843 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011844 VkPipelineObj pipe(m_device);
11845 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060011846 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -060011847 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011848 pipe.SetMSAA(&pipe_ms_state_ci);
11849 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis3b780662015-05-28 12:11:26 -060011850
Tony Barbour552f6c02016-12-21 14:34:07 -070011851 m_commandBuffer->BeginCommandBuffer();
11852 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011853 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis3b780662015-05-28 12:11:26 -060011854
Rene Lindsay3bdc7a42017-01-06 13:20:15 -070011855 VkViewport viewport = {0, 0, 16, 16, 0, 1};
11856 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
11857 VkRect2D scissor = {{0, 0}, {16, 16}};
11858 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
11859
Mark Young29927482016-05-04 14:38:51 -060011860 // Render triangle (the error should trigger on the attempt to draw).
11861 Draw(3, 1, 0, 0);
11862
11863 // Finalize recording of the command buffer
Tony Barbour552f6c02016-12-21 14:34:07 -070011864 m_commandBuffer->EndRenderPass();
11865 m_commandBuffer->EndCommandBuffer();
Mark Young29927482016-05-04 14:38:51 -060011866
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011867 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011868
Chia-I Wuf7458c52015-10-26 21:10:41 +080011869 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11870 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11871 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060011872}
Mark Young29927482016-05-04 14:38:51 -060011873
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011874TEST_F(VkLayerTest, RenderPassIncompatible) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011875 TEST_DESCRIPTION(
11876 "Hit RenderPass incompatible cases. "
11877 "Initial case is drawing with an active renderpass that's "
11878 "not compatible with the bound pipeline state object's creation renderpass");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011879 VkResult err;
11880
Tony Barbour1fa09702017-03-16 12:09:08 -060011881 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011882 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11883
11884 VkDescriptorSetLayoutBinding dsl_binding = {};
11885 dsl_binding.binding = 0;
11886 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11887 dsl_binding.descriptorCount = 1;
11888 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11889 dsl_binding.pImmutableSamplers = NULL;
11890
11891 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11892 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11893 ds_layout_ci.pNext = NULL;
11894 ds_layout_ci.bindingCount = 1;
11895 ds_layout_ci.pBindings = &dsl_binding;
11896
11897 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011898 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011899 ASSERT_VK_SUCCESS(err);
11900
11901 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11902 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11903 pipeline_layout_ci.pNext = NULL;
11904 pipeline_layout_ci.setLayoutCount = 1;
11905 pipeline_layout_ci.pSetLayouts = &ds_layout;
11906
11907 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011908 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011909 ASSERT_VK_SUCCESS(err);
11910
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011911 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011912 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011913 // but add it to be able to run on more devices
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011914 // Create a renderpass that will be incompatible with default renderpass
11915 VkAttachmentReference attach = {};
Cort Stratton7547f772017-05-04 15:18:52 -070011916 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011917 VkAttachmentReference color_att = {};
Cort Stratton7547f772017-05-04 15:18:52 -070011918 color_att.layout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011919 VkSubpassDescription subpass = {};
11920 subpass.inputAttachmentCount = 1;
11921 subpass.pInputAttachments = &attach;
11922 subpass.colorAttachmentCount = 1;
11923 subpass.pColorAttachments = &color_att;
11924 VkRenderPassCreateInfo rpci = {};
11925 rpci.subpassCount = 1;
11926 rpci.pSubpasses = &subpass;
11927 rpci.attachmentCount = 1;
11928 VkAttachmentDescription attach_desc = {};
11929 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Cody Northropbd16af12016-06-21 09:25:48 -060011930 // Format incompatible with PSO RP color attach format B8G8R8A8_UNORM
11931 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011932 rpci.pAttachments = &attach_desc;
11933 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
11934 VkRenderPass rp;
11935 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11936 VkPipelineObj pipe(m_device);
11937 pipe.AddShader(&vs);
11938 pipe.AddShader(&fs);
11939 pipe.AddColorAttachment();
11940 VkViewport view_port = {};
11941 m_viewports.push_back(view_port);
11942 pipe.SetViewport(m_viewports);
11943 VkRect2D rect = {};
11944 m_scissors.push_back(rect);
11945 pipe.SetScissor(m_scissors);
11946 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11947
11948 VkCommandBufferInheritanceInfo cbii = {};
11949 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
11950 cbii.renderPass = rp;
11951 cbii.subpass = 0;
11952 VkCommandBufferBeginInfo cbbi = {};
11953 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
11954 cbbi.pInheritanceInfo = &cbii;
11955 vkBeginCommandBuffer(m_commandBuffer->handle(), &cbbi);
11956 VkRenderPassBeginInfo rpbi = {};
11957 rpbi.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
11958 rpbi.framebuffer = m_framebuffer;
11959 rpbi.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011960 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
11961 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011962
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011963 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is incompatible w/ gfx pipeline ");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011964 // Render triangle (the error should trigger on the attempt to draw).
11965 Draw(3, 1, 0, 0);
11966
11967 // Finalize recording of the command buffer
Tony Barbour552f6c02016-12-21 14:34:07 -070011968 m_commandBuffer->EndRenderPass();
11969 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011970
11971 m_errorMonitor->VerifyFound();
11972
11973 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11974 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11975 vkDestroyRenderPass(m_device->device(), rp, NULL);
11976}
11977
Mark Youngc89c6312016-03-31 16:03:20 -060011978TEST_F(VkLayerTest, NumBlendAttachMismatch) {
11979 // Create Pipeline where the number of blend attachments doesn't match the
11980 // number of color attachments. In this case, we don't add any color
11981 // blend attachments even though we have a color attachment.
11982 VkResult err;
11983
Tobin Ehlis974c0d92017-02-01 13:31:22 -070011984 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02109);
Mark Youngc89c6312016-03-31 16:03:20 -060011985
Tony Barbour1fa09702017-03-16 12:09:08 -060011986 ASSERT_NO_FATAL_FAILURE(Init());
Mark Youngc89c6312016-03-31 16:03:20 -060011987 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11988 VkDescriptorPoolSize ds_type_count = {};
11989 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11990 ds_type_count.descriptorCount = 1;
11991
11992 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11993 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11994 ds_pool_ci.pNext = NULL;
11995 ds_pool_ci.maxSets = 1;
11996 ds_pool_ci.poolSizeCount = 1;
11997 ds_pool_ci.pPoolSizes = &ds_type_count;
11998
11999 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012000 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Youngc89c6312016-03-31 16:03:20 -060012001 ASSERT_VK_SUCCESS(err);
12002
12003 VkDescriptorSetLayoutBinding dsl_binding = {};
12004 dsl_binding.binding = 0;
12005 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12006 dsl_binding.descriptorCount = 1;
12007 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
12008 dsl_binding.pImmutableSamplers = NULL;
12009
12010 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
12011 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12012 ds_layout_ci.pNext = NULL;
12013 ds_layout_ci.bindingCount = 1;
12014 ds_layout_ci.pBindings = &dsl_binding;
12015
12016 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012017 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Youngc89c6312016-03-31 16:03:20 -060012018 ASSERT_VK_SUCCESS(err);
12019
12020 VkDescriptorSet descriptorSet;
12021 VkDescriptorSetAllocateInfo alloc_info = {};
12022 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12023 alloc_info.descriptorSetCount = 1;
12024 alloc_info.descriptorPool = ds_pool;
12025 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012026 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Youngc89c6312016-03-31 16:03:20 -060012027 ASSERT_VK_SUCCESS(err);
12028
12029 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012030 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Youngc89c6312016-03-31 16:03:20 -060012031 pipe_ms_state_ci.pNext = NULL;
12032 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
12033 pipe_ms_state_ci.sampleShadingEnable = 0;
12034 pipe_ms_state_ci.minSampleShading = 1.0;
12035 pipe_ms_state_ci.pSampleMask = NULL;
12036
12037 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12038 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12039 pipeline_layout_ci.pNext = NULL;
12040 pipeline_layout_ci.setLayoutCount = 1;
12041 pipeline_layout_ci.pSetLayouts = &ds_layout;
12042
12043 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012044 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Youngc89c6312016-03-31 16:03:20 -060012045 ASSERT_VK_SUCCESS(err);
12046
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012047 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012048 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012049 // but add it to be able to run on more devices
Mark Youngc89c6312016-03-31 16:03:20 -060012050 VkPipelineObj pipe(m_device);
12051 pipe.AddShader(&vs);
12052 pipe.AddShader(&fs);
12053 pipe.SetMSAA(&pipe_ms_state_ci);
12054 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012055 m_errorMonitor->VerifyFound();
Mark Youngc89c6312016-03-31 16:03:20 -060012056
12057 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12058 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12059 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
12060}
Mark Young29927482016-05-04 14:38:51 -060012061
Mark Muellerd4914412016-06-13 17:52:06 -060012062TEST_F(VkLayerTest, MissingClearAttachment) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012063 TEST_DESCRIPTION(
12064 "Points to a wrong colorAttachment index in a VkClearAttachment "
12065 "structure passed to vkCmdClearAttachments");
Tony Barbour1fa09702017-03-16 12:09:08 -060012066 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012067 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01114);
Mark Muellerd4914412016-06-13 17:52:06 -060012068
12069 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailCmdClearAttachments);
12070 m_errorMonitor->VerifyFound();
12071}
12072
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070012073TEST_F(VkLayerTest, CmdClearAttachmentTests) {
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070012074 TEST_DESCRIPTION("Various tests for validating usage of vkCmdClearAttachments");
12075 VkResult err;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012076
Tony Barbour1fa09702017-03-16 12:09:08 -060012077 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis53eddda2015-07-01 16:46:13 -060012078 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060012079
Chia-I Wu1b99bb22015-10-27 19:25:11 +080012080 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012081 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12082 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060012083
12084 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012085 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12086 ds_pool_ci.pNext = NULL;
12087 ds_pool_ci.maxSets = 1;
12088 ds_pool_ci.poolSizeCount = 1;
12089 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060012090
Tobin Ehlis53eddda2015-07-01 16:46:13 -060012091 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012092 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060012093 ASSERT_VK_SUCCESS(err);
12094
Tony Barboureb254902015-07-15 12:50:33 -060012095 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012096 dsl_binding.binding = 0;
12097 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12098 dsl_binding.descriptorCount = 1;
12099 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
12100 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060012101
Tony Barboureb254902015-07-15 12:50:33 -060012102 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012103 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12104 ds_layout_ci.pNext = NULL;
12105 ds_layout_ci.bindingCount = 1;
12106 ds_layout_ci.pBindings = &dsl_binding;
Mark Lobodzinski209b5292015-09-17 09:44:05 -060012107
Tobin Ehlis53eddda2015-07-01 16:46:13 -060012108 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012109 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060012110 ASSERT_VK_SUCCESS(err);
12111
12112 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012113 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080012114 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070012115 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060012116 alloc_info.descriptorPool = ds_pool;
12117 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012118 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060012119 ASSERT_VK_SUCCESS(err);
12120
Tony Barboureb254902015-07-15 12:50:33 -060012121 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012122 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070012123 pipe_ms_state_ci.pNext = NULL;
12124 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
12125 pipe_ms_state_ci.sampleShadingEnable = 0;
12126 pipe_ms_state_ci.minSampleShading = 1.0;
12127 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060012128
Tony Barboureb254902015-07-15 12:50:33 -060012129 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012130 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12131 pipeline_layout_ci.pNext = NULL;
12132 pipeline_layout_ci.setLayoutCount = 1;
12133 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060012134
12135 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012136 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060012137 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski209b5292015-09-17 09:44:05 -060012138
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012139 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -060012140 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -070012141 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012142 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012143
Tony Barbour62e1a5b2015-08-06 10:16:07 -060012144 VkPipelineObj pipe(m_device);
12145 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060012146 pipe.AddShader(&fs);
Jeremy Hayes7332f342017-03-09 15:54:12 -070012147 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060012148 pipe.SetMSAA(&pipe_ms_state_ci);
12149 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060012150
Tony Barbour552f6c02016-12-21 14:34:07 -070012151 m_commandBuffer->BeginCommandBuffer();
12152 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060012153
Karl Schultz6addd812016-02-02 17:17:23 -070012154 // Main thing we care about for this test is that the VkImage obj we're
12155 // clearing matches Color Attachment of FB
Tobin Ehlis53eddda2015-07-01 16:46:13 -060012156 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -060012157 VkClearAttachment color_attachment;
12158 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12159 color_attachment.clearValue.color.float32[0] = 1.0;
12160 color_attachment.clearValue.color.float32[1] = 1.0;
12161 color_attachment.clearValue.color.float32[2] = 1.0;
12162 color_attachment.clearValue.color.float32[3] = 1.0;
12163 color_attachment.colorAttachment = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012164 VkClearRect clear_rect = {{{0, 0}, {(uint32_t)m_width, (uint32_t)m_height}}};
Tobin Ehlis53eddda2015-07-01 16:46:13 -060012165
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070012166 // Call for full-sized FB Color attachment prior to issuing a Draw
12167 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070012168 "vkCmdClearAttachments() issued on command buffer object ");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012169 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070012170 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012171
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070012172 clear_rect.rect.extent.width = renderPassBeginInfo().renderArea.extent.width + 4;
12173 clear_rect.rect.extent.height = clear_rect.rect.extent.height / 2;
12174 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01115);
12175 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
12176 m_errorMonitor->VerifyFound();
12177
12178 clear_rect.rect.extent.width = (uint32_t)m_width / 2;
12179 clear_rect.layerCount = 2;
12180 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01116);
12181 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012182 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060012183
Chia-I Wuf7458c52015-10-26 21:10:41 +080012184 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12185 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12186 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060012187}
12188
Karl Schultz6addd812016-02-02 17:17:23 -070012189TEST_F(VkLayerTest, VtxBufferBadIndex) {
12190 VkResult err;
Tobin Ehlis502480b2015-06-24 15:53:07 -060012191
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012192 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
12193 "but no vertex buffers are attached to this Pipeline State Object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012194
Tony Barbour1fa09702017-03-16 12:09:08 -060012195 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisd332f282015-10-02 11:00:56 -060012196 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlis502480b2015-06-24 15:53:07 -060012197 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060012198
Chia-I Wu1b99bb22015-10-27 19:25:11 +080012199 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012200 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12201 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060012202
12203 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012204 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12205 ds_pool_ci.pNext = NULL;
12206 ds_pool_ci.maxSets = 1;
12207 ds_pool_ci.poolSizeCount = 1;
12208 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060012209
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060012210 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012211 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis502480b2015-06-24 15:53:07 -060012212 ASSERT_VK_SUCCESS(err);
12213
Tony Barboureb254902015-07-15 12:50:33 -060012214 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012215 dsl_binding.binding = 0;
12216 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12217 dsl_binding.descriptorCount = 1;
12218 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
12219 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060012220
Tony Barboureb254902015-07-15 12:50:33 -060012221 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012222 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12223 ds_layout_ci.pNext = NULL;
12224 ds_layout_ci.bindingCount = 1;
12225 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060012226
Tobin Ehlis502480b2015-06-24 15:53:07 -060012227 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012228 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060012229 ASSERT_VK_SUCCESS(err);
12230
12231 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012232 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080012233 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070012234 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060012235 alloc_info.descriptorPool = ds_pool;
12236 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012237 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis502480b2015-06-24 15:53:07 -060012238 ASSERT_VK_SUCCESS(err);
12239
Tony Barboureb254902015-07-15 12:50:33 -060012240 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012241 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070012242 pipe_ms_state_ci.pNext = NULL;
12243 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
12244 pipe_ms_state_ci.sampleShadingEnable = 0;
12245 pipe_ms_state_ci.minSampleShading = 1.0;
12246 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060012247
Tony Barboureb254902015-07-15 12:50:33 -060012248 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012249 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12250 pipeline_layout_ci.pNext = NULL;
12251 pipeline_layout_ci.setLayoutCount = 1;
12252 pipeline_layout_ci.pSetLayouts = &ds_layout;
12253 VkPipelineLayout pipeline_layout;
Tobin Ehlis502480b2015-06-24 15:53:07 -060012254
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012255 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060012256 ASSERT_VK_SUCCESS(err);
12257
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012258 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012259 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012260 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -060012261 VkPipelineObj pipe(m_device);
12262 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060012263 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -060012264 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060012265 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -060012266 pipe.SetViewport(m_viewports);
12267 pipe.SetScissor(m_scissors);
Tony Barbour62e1a5b2015-08-06 10:16:07 -060012268 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060012269
Tony Barbour552f6c02016-12-21 14:34:07 -070012270 m_commandBuffer->BeginCommandBuffer();
12271 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012272 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisf7bf4502015-09-09 15:12:35 -060012273 // Don't care about actual data, just need to get to draw to flag error
12274 static const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012275 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), (const void *)&vbo_data);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012276 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -060012277 Draw(1, 0, 0, 0);
Tobin Ehlis502480b2015-06-24 15:53:07 -060012278
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012279 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060012280
Chia-I Wuf7458c52015-10-26 21:10:41 +080012281 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12282 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12283 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis502480b2015-06-24 15:53:07 -060012284}
Mark Muellerdfe37552016-07-07 14:47:42 -060012285
Mark Mueller2ee294f2016-08-04 12:59:48 -060012286TEST_F(VkLayerTest, MismatchCountQueueCreateRequestedFeature) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012287 TEST_DESCRIPTION(
12288 "Use an invalid count in a vkEnumeratePhysicalDevices call."
12289 "Use invalid Queue Family Index in vkCreateDevice");
Tony Barbour1fa09702017-03-16 12:09:08 -060012290 ASSERT_NO_FATAL_FAILURE(Init());
Mark Mueller2ee294f2016-08-04 12:59:48 -060012291
Mark Mueller880fce52016-08-17 15:23:23 -060012292 // The following test fails with recent NVidia drivers.
12293 // By the time core_validation is reached, the NVidia
12294 // driver has sanitized the invalid condition and core_validation
12295 // is not introduced to the failure condition. This is not the case
12296 // with AMD and Mesa drivers. Futher investigation is required
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012297 // uint32_t count = static_cast<uint32_t>(~0);
12298 // VkPhysicalDevice physical_device;
12299 // vkEnumeratePhysicalDevices(instance(), &count, &physical_device);
12300 // m_errorMonitor->VerifyFound();
Mark Mueller2ee294f2016-08-04 12:59:48 -060012301
Mark Mueller2ee294f2016-08-04 12:59:48 -060012302 float queue_priority = 0.0;
Mark Mueller2ee294f2016-08-04 12:59:48 -060012303 VkDeviceQueueCreateInfo queue_create_info = {};
12304 queue_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
12305 queue_create_info.queueCount = 1;
12306 queue_create_info.pQueuePriorities = &queue_priority;
12307 queue_create_info.queueFamilyIndex = static_cast<uint32_t>(~0);
12308
12309 VkPhysicalDeviceFeatures features = m_device->phy().features();
12310 VkDevice testDevice;
12311 VkDeviceCreateInfo device_create_info = {};
12312 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
12313 device_create_info.queueCreateInfoCount = 1;
12314 device_create_info.pQueueCreateInfos = &queue_create_info;
12315 device_create_info.pEnabledFeatures = &features;
Jeremy Hayesb26fd042017-03-10 09:13:22 -070012316
Petr Kraus56ed9192017-05-08 23:45:36 +020012317 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00054);
Jeremy Hayes17fd3662017-03-17 11:51:11 -060012318 // The following unexpected error is coming from the LunarG loader. Do not make it a desired message because platforms that do
12319 // not use the LunarG loader (e.g. Android) will not see the message and the test will fail.
12320 m_errorMonitor->SetUnexpectedError("Failed to create device chain.");
Mark Mueller2ee294f2016-08-04 12:59:48 -060012321 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
12322 m_errorMonitor->VerifyFound();
12323
12324 queue_create_info.queueFamilyIndex = 1;
Tobin Ehliscc980e12017-05-19 12:05:49 -060012325 if (m_device->phy().queue_properties().size() < 2) {
12326 queue_create_info.queueFamilyIndex = 0;
12327 }
Mark Mueller2ee294f2016-08-04 12:59:48 -060012328
12329 unsigned feature_count = sizeof(VkPhysicalDeviceFeatures) / sizeof(VkBool32);
12330 VkBool32 *feature_array = reinterpret_cast<VkBool32 *>(&features);
12331 for (unsigned i = 0; i < feature_count; i++) {
12332 if (VK_FALSE == feature_array[i]) {
12333 feature_array[i] = VK_TRUE;
Mark Mueller2ee294f2016-08-04 12:59:48 -060012334 device_create_info.pEnabledFeatures = &features;
Jeremy Hayesb26fd042017-03-10 09:13:22 -070012335 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12336 "While calling vkCreateDevice(), requesting feature #");
Jeremy Hayes17fd3662017-03-17 11:51:11 -060012337 // The following unexpected error is coming from the LunarG loader. Do not make it a desired message because platforms
12338 // that do not use the LunarG loader (e.g. Android) will not see the message and the test will fail.
12339 m_errorMonitor->SetUnexpectedError("Failed to create device chain.");
Jeremy Hayesb26fd042017-03-10 09:13:22 -070012340 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12341 "You requested features that are unavailable on this device. You should first "
12342 "query feature availability by calling vkGetPhysicalDeviceFeatures().");
Mark Mueller2ee294f2016-08-04 12:59:48 -060012343 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
12344 m_errorMonitor->VerifyFound();
12345 break;
12346 }
12347 }
12348}
12349
Tobin Ehlis16edf082016-11-21 12:33:49 -070012350TEST_F(VkLayerTest, InvalidQueryPoolCreate) {
12351 TEST_DESCRIPTION("Attempt to create a query pool for PIPELINE_STATISTICS without enabling pipeline stats for the device.");
12352
Tony Barbour1fa09702017-03-16 12:09:08 -060012353 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis16edf082016-11-21 12:33:49 -070012354
12355 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
12356 std::vector<VkDeviceQueueCreateInfo> queue_info;
12357 queue_info.reserve(queue_props.size());
12358 std::vector<std::vector<float>> queue_priorities;
12359 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
12360 VkDeviceQueueCreateInfo qi{};
12361 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
12362 qi.queueFamilyIndex = i;
12363 qi.queueCount = queue_props[i].queueCount;
12364 queue_priorities.emplace_back(qi.queueCount, 0.0f);
12365 qi.pQueuePriorities = queue_priorities[i].data();
12366 queue_info.push_back(qi);
12367 }
12368
12369 std::vector<const char *> device_extension_names;
12370
12371 VkDevice local_device;
12372 VkDeviceCreateInfo device_create_info = {};
12373 auto features = m_device->phy().features();
12374 // Intentionally disable pipeline stats
12375 features.pipelineStatisticsQuery = VK_FALSE;
12376 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
12377 device_create_info.pNext = NULL;
12378 device_create_info.queueCreateInfoCount = queue_info.size();
12379 device_create_info.pQueueCreateInfos = queue_info.data();
12380 device_create_info.enabledLayerCount = 0;
12381 device_create_info.ppEnabledLayerNames = NULL;
12382 device_create_info.pEnabledFeatures = &features;
12383 VkResult err = vkCreateDevice(gpu(), &device_create_info, nullptr, &local_device);
12384 ASSERT_VK_SUCCESS(err);
12385
12386 VkQueryPoolCreateInfo qpci{};
12387 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
12388 qpci.queryType = VK_QUERY_TYPE_PIPELINE_STATISTICS;
12389 qpci.queryCount = 1;
12390 VkQueryPool query_pool;
12391
12392 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01006);
12393 vkCreateQueryPool(local_device, &qpci, nullptr, &query_pool);
12394 m_errorMonitor->VerifyFound();
12395
12396 vkDestroyDevice(local_device, nullptr);
12397}
12398
Mark Mueller2ee294f2016-08-04 12:59:48 -060012399TEST_F(VkLayerTest, InvalidQueueIndexInvalidQuery) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012400 TEST_DESCRIPTION(
12401 "Use an invalid queue index in a vkCmdWaitEvents call."
12402 "End a command buffer with a query still in progress.");
Mark Mueller2ee294f2016-08-04 12:59:48 -060012403
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012404 const char *invalid_queue_index =
12405 "was created with sharingMode of VK_SHARING_MODE_EXCLUSIVE. If one "
12406 "of src- or dstQueueFamilyIndex is VK_QUEUE_FAMILY_IGNORED, both "
12407 "must be.";
Mark Mueller2ee294f2016-08-04 12:59:48 -060012408
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012409 const char *invalid_query = "Ending command buffer with in progress query: queryPool 0x";
Mark Mueller2ee294f2016-08-04 12:59:48 -060012410
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012411 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queue_index);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012412
Tony Barbour1fa09702017-03-16 12:09:08 -060012413 ASSERT_NO_FATAL_FAILURE(Init());
Mark Mueller2ee294f2016-08-04 12:59:48 -060012414
12415 VkEvent event;
12416 VkEventCreateInfo event_create_info{};
12417 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
12418 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
12419
Mark Mueller2ee294f2016-08-04 12:59:48 -060012420 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012421 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012422
Tony Barbour552f6c02016-12-21 14:34:07 -070012423 m_commandBuffer->BeginCommandBuffer();
Mark Mueller2ee294f2016-08-04 12:59:48 -060012424
12425 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060012426 image.Init(128, 128, 1, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012427 ASSERT_TRUE(image.initialized());
12428 VkImageMemoryBarrier img_barrier = {};
12429 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
12430 img_barrier.pNext = NULL;
12431 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
12432 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
12433 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
12434 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
12435 img_barrier.image = image.handle();
12436 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
Mark Lobodzinski2a74c5c2016-08-17 13:26:28 -060012437
12438 // QueueFamilyIndex must be VK_QUEUE_FAMILY_IGNORED, this verifies
12439 // that layer validation catches the case when it is not.
12440 img_barrier.dstQueueFamilyIndex = 0;
Mark Mueller2ee294f2016-08-04 12:59:48 -060012441 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12442 img_barrier.subresourceRange.baseArrayLayer = 0;
12443 img_barrier.subresourceRange.baseMipLevel = 0;
12444 img_barrier.subresourceRange.layerCount = 1;
12445 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012446 vkCmdWaitEvents(m_commandBuffer->handle(), 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0,
12447 nullptr, 0, nullptr, 1, &img_barrier);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012448 m_errorMonitor->VerifyFound();
12449
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012450 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_query);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012451
12452 VkQueryPool query_pool;
12453 VkQueryPoolCreateInfo query_pool_create_info = {};
12454 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
12455 query_pool_create_info.queryType = VK_QUERY_TYPE_OCCLUSION;
12456 query_pool_create_info.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012457 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012458
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012459 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0 /*startQuery*/, 1 /*queryCount*/);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012460 vkCmdBeginQuery(m_commandBuffer->handle(), query_pool, 0, 0);
12461
12462 vkEndCommandBuffer(m_commandBuffer->handle());
12463 m_errorMonitor->VerifyFound();
12464
12465 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
12466 vkDestroyEvent(m_device->device(), event, nullptr);
12467}
12468
Mark Muellerdfe37552016-07-07 14:47:42 -060012469TEST_F(VkLayerTest, VertexBufferInvalid) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012470 TEST_DESCRIPTION(
12471 "Submit a command buffer using deleted vertex buffer, "
12472 "delete a buffer twice, use an invalid offset for each "
12473 "buffer type, and attempt to bind a null buffer");
Mark Muellerdfe37552016-07-07 14:47:42 -060012474
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012475 const char *deleted_buffer_in_command_buffer =
12476 "Cannot submit cmd buffer "
12477 "using deleted buffer ";
12478 const char *invalid_offset_message =
12479 "vkBindBufferMemory(): "
12480 "memoryOffset is 0x";
12481 const char *invalid_storage_buffer_offset_message =
12482 "vkBindBufferMemory(): "
12483 "storage memoryOffset "
12484 "is 0x";
12485 const char *invalid_texel_buffer_offset_message =
12486 "vkBindBufferMemory(): "
12487 "texel memoryOffset "
12488 "is 0x";
12489 const char *invalid_uniform_buffer_offset_message =
12490 "vkBindBufferMemory(): "
12491 "uniform memoryOffset "
12492 "is 0x";
Mark Muellerdfe37552016-07-07 14:47:42 -060012493
Tony Barbour1fa09702017-03-16 12:09:08 -060012494 ASSERT_NO_FATAL_FAILURE(Init());
Mark Muellerdfe37552016-07-07 14:47:42 -060012495 ASSERT_NO_FATAL_FAILURE(InitViewport());
12496 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12497
12498 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012499 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -060012500 pipe_ms_state_ci.pNext = NULL;
12501 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
12502 pipe_ms_state_ci.sampleShadingEnable = 0;
12503 pipe_ms_state_ci.minSampleShading = 1.0;
12504 pipe_ms_state_ci.pSampleMask = nullptr;
12505
12506 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12507 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12508 VkPipelineLayout pipeline_layout;
12509
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012510 VkResult err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, nullptr, &pipeline_layout);
Mark Muellerdfe37552016-07-07 14:47:42 -060012511 ASSERT_VK_SUCCESS(err);
12512
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012513 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
12514 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Muellerdfe37552016-07-07 14:47:42 -060012515 VkPipelineObj pipe(m_device);
12516 pipe.AddShader(&vs);
12517 pipe.AddShader(&fs);
12518 pipe.AddColorAttachment();
12519 pipe.SetMSAA(&pipe_ms_state_ci);
12520 pipe.SetViewport(m_viewports);
12521 pipe.SetScissor(m_scissors);
12522 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12523
Tony Barbour552f6c02016-12-21 14:34:07 -070012524 m_commandBuffer->BeginCommandBuffer();
12525 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012526 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Muellerdfe37552016-07-07 14:47:42 -060012527
12528 {
12529 // Create and bind a vertex buffer in a reduced scope, which will cause
12530 // it to be deleted upon leaving this scope
12531 const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012532 VkVerticesObj draw_verticies(m_device, 1, 1, sizeof(vbo_data), 3, vbo_data);
Mark Muellerdfe37552016-07-07 14:47:42 -060012533 draw_verticies.BindVertexBuffers(m_commandBuffer->handle());
12534 draw_verticies.AddVertexInputToPipe(pipe);
12535 }
12536
12537 Draw(1, 0, 0, 0);
12538
Tony Barbour552f6c02016-12-21 14:34:07 -070012539 m_commandBuffer->EndRenderPass();
12540 m_commandBuffer->EndCommandBuffer();
Mark Muellerdfe37552016-07-07 14:47:42 -060012541
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012542 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, deleted_buffer_in_command_buffer);
Mark Muellerdfe37552016-07-07 14:47:42 -060012543 QueueCommandBuffer(false);
12544 m_errorMonitor->VerifyFound();
12545
12546 {
12547 // Create and bind a vertex buffer in a reduced scope, and delete it
12548 // twice, the second through the destructor
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012549 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eDoubleDelete);
Karl Schultzf78bcdd2016-11-30 12:36:01 -070012550 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00680);
Mark Muellerdfe37552016-07-07 14:47:42 -060012551 buffer_test.TestDoubleDestroy();
12552 }
12553 m_errorMonitor->VerifyFound();
12554
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012555 m_errorMonitor->SetUnexpectedError("value of pCreateInfo->usage must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012556 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidMemoryOffset)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060012557 // Create and bind a memory buffer with an invalid offset.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012558 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_offset_message);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012559 m_errorMonitor->SetUnexpectedError(
12560 "If buffer was created with the VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT or VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT, "
12561 "memoryOffset must be a multiple of VkPhysicalDeviceLimits::minTexelBufferOffsetAlignment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012562 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidMemoryOffset);
12563 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012564 m_errorMonitor->VerifyFound();
12565 }
12566
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012567 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset,
12568 VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060012569 // Create and bind a memory buffer with an invalid offset again,
12570 // but look for a texel buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012571 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_texel_buffer_offset_message);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012572 m_errorMonitor->SetUnexpectedError(
12573 "memoryOffset must be an integer multiple of the alignment member of the VkMemoryRequirements structure returned from "
12574 "a call to vkGetBufferMemoryRequirements with buffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012575 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
12576 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012577 m_errorMonitor->VerifyFound();
12578 }
12579
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012580 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060012581 // Create and bind a memory buffer with an invalid offset again, but
12582 // look for a uniform buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012583 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_uniform_buffer_offset_message);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012584 m_errorMonitor->SetUnexpectedError(
12585 "memoryOffset must be an integer multiple of the alignment member of the VkMemoryRequirements structure returned from "
12586 "a call to vkGetBufferMemoryRequirements with buffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012587 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
12588 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012589 m_errorMonitor->VerifyFound();
12590 }
12591
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012592 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060012593 // Create and bind a memory buffer with an invalid offset again, but
12594 // look for a storage buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012595 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_storage_buffer_offset_message);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012596 m_errorMonitor->SetUnexpectedError(
12597 "memoryOffset must be an integer multiple of the alignment member of the VkMemoryRequirements structure returned from "
12598 "a call to vkGetBufferMemoryRequirements with buffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012599 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
12600 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012601 m_errorMonitor->VerifyFound();
12602 }
12603
12604 {
12605 // Attempt to bind a null buffer.
Karl Schultzf78bcdd2016-11-30 12:36:01 -070012606 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00799);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012607 m_errorMonitor->SetUnexpectedError("required parameter memory specified as VK_NULL_HANDLE");
12608 m_errorMonitor->SetUnexpectedError("memory must be a valid VkDeviceMemory handle");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012609 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eBindNullBuffer);
12610 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012611 m_errorMonitor->VerifyFound();
12612 }
12613
12614 {
12615 // Attempt to use an invalid handle to delete a buffer.
Karl Schultzf78bcdd2016-11-30 12:36:01 -070012616 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00622);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012617 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eFreeInvalidHandle);
12618 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012619 }
12620 m_errorMonitor->VerifyFound();
12621
12622 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12623}
12624
Tony Barbourff1351e2017-05-10 11:14:03 -060012625TEST_F(VkLayerTest, BadVertexBufferOffset) {
12626 TEST_DESCRIPTION("Submit an offset past the end of a vertex buffer");
12627
12628 ASSERT_NO_FATAL_FAILURE(Init());
12629 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12630 static const float vbo_data[3] = {1.f, 0.f, 1.f};
Tony Barboure94224e2017-05-11 15:22:43 -060012631 VkConstantBufferObj vbo(m_device, 3, sizeof(float), (const void *)&vbo_data);
Tony Barbourff1351e2017-05-10 11:14:03 -060012632 m_commandBuffer->BeginCommandBuffer();
12633 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
12634 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01417);
Tony Barboure94224e2017-05-11 15:22:43 -060012635 BindVertexBuffer(&vbo, (VkDeviceSize)(3 * sizeof(float)), 1); // Offset at the end of the buffer
Tony Barbourff1351e2017-05-10 11:14:03 -060012636 m_errorMonitor->VerifyFound();
12637}
12638
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012639// INVALID_IMAGE_LAYOUT tests (one other case is hit by MapMemWithoutHostVisibleBit and not here)
12640TEST_F(VkLayerTest, InvalidImageLayout) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012641 TEST_DESCRIPTION(
12642 "Hit all possible validation checks associated with the "
12643 "DRAWSTATE_INVALID_IMAGE_LAYOUT enum. Generally these involve having"
12644 "images in the wrong layout when they're copied or transitioned.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012645 // 3 in ValidateCmdBufImageLayouts
12646 // * -1 Attempt to submit cmd buf w/ deleted image
12647 // * -2 Cmd buf submit of image w/ layout not matching first use w/ subresource
12648 // * -3 Cmd buf submit of image w/ layout not matching first use w/o subresource
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012649
Tony Barbour1fa09702017-03-16 12:09:08 -060012650 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -060012651 auto depth_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbourf887b162017-03-09 10:06:46 -070012652 if (!depth_format) {
12653 printf(" No Depth + Stencil format found. Skipped.\n");
12654 return;
12655 }
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012656 // Create src & dst images to use for copy operations
12657 VkImage src_image;
12658 VkImage dst_image;
Cort3b021012016-12-07 12:00:57 -080012659 VkImage depth_image;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012660
12661 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
12662 const int32_t tex_width = 32;
12663 const int32_t tex_height = 32;
12664
12665 VkImageCreateInfo image_create_info = {};
12666 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
12667 image_create_info.pNext = NULL;
12668 image_create_info.imageType = VK_IMAGE_TYPE_2D;
12669 image_create_info.format = tex_format;
12670 image_create_info.extent.width = tex_width;
12671 image_create_info.extent.height = tex_height;
12672 image_create_info.extent.depth = 1;
12673 image_create_info.mipLevels = 1;
12674 image_create_info.arrayLayers = 4;
12675 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
12676 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
12677 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Cort3b021012016-12-07 12:00:57 -080012678 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012679 image_create_info.flags = 0;
12680
12681 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &src_image);
12682 ASSERT_VK_SUCCESS(err);
Cort3b021012016-12-07 12:00:57 -080012683 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012684 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dst_image);
12685 ASSERT_VK_SUCCESS(err);
Cort3b021012016-12-07 12:00:57 -080012686 image_create_info.format = VK_FORMAT_D32_SFLOAT;
12687 image_create_info.usage |= VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
12688 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &depth_image);
12689 ASSERT_VK_SUCCESS(err);
12690
12691 // Allocate memory
12692 VkMemoryRequirements img_mem_reqs = {};
Cort530cf382016-12-08 09:59:47 -080012693 VkMemoryAllocateInfo mem_alloc = {};
Cort3b021012016-12-07 12:00:57 -080012694 VkDeviceMemory src_image_mem, dst_image_mem, depth_image_mem;
Cort530cf382016-12-08 09:59:47 -080012695 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
12696 mem_alloc.pNext = NULL;
12697 mem_alloc.allocationSize = 0;
12698 mem_alloc.memoryTypeIndex = 0;
Cort3b021012016-12-07 12:00:57 -080012699
12700 vkGetImageMemoryRequirements(m_device->device(), src_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080012701 mem_alloc.allocationSize = img_mem_reqs.size;
12702 bool pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080012703 ASSERT_TRUE(pass);
Cort530cf382016-12-08 09:59:47 -080012704 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &src_image_mem);
Cort3b021012016-12-07 12:00:57 -080012705 ASSERT_VK_SUCCESS(err);
12706
12707 vkGetImageMemoryRequirements(m_device->device(), dst_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080012708 mem_alloc.allocationSize = img_mem_reqs.size;
12709 pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080012710 ASSERT_VK_SUCCESS(err);
Cort530cf382016-12-08 09:59:47 -080012711 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &dst_image_mem);
Cort3b021012016-12-07 12:00:57 -080012712 ASSERT_VK_SUCCESS(err);
12713
12714 vkGetImageMemoryRequirements(m_device->device(), depth_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080012715 mem_alloc.allocationSize = img_mem_reqs.size;
12716 pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080012717 ASSERT_VK_SUCCESS(err);
Cort530cf382016-12-08 09:59:47 -080012718 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &depth_image_mem);
Cort3b021012016-12-07 12:00:57 -080012719 ASSERT_VK_SUCCESS(err);
12720
12721 err = vkBindImageMemory(m_device->device(), src_image, src_image_mem, 0);
12722 ASSERT_VK_SUCCESS(err);
12723 err = vkBindImageMemory(m_device->device(), dst_image, dst_image_mem, 0);
12724 ASSERT_VK_SUCCESS(err);
12725 err = vkBindImageMemory(m_device->device(), depth_image, depth_image_mem, 0);
12726 ASSERT_VK_SUCCESS(err);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012727
Tony Barbour552f6c02016-12-21 14:34:07 -070012728 m_commandBuffer->BeginCommandBuffer();
Cort530cf382016-12-08 09:59:47 -080012729 VkImageCopy copy_region;
12730 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12731 copy_region.srcSubresource.mipLevel = 0;
12732 copy_region.srcSubresource.baseArrayLayer = 0;
12733 copy_region.srcSubresource.layerCount = 1;
12734 copy_region.srcOffset.x = 0;
12735 copy_region.srcOffset.y = 0;
12736 copy_region.srcOffset.z = 0;
12737 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12738 copy_region.dstSubresource.mipLevel = 0;
12739 copy_region.dstSubresource.baseArrayLayer = 0;
12740 copy_region.dstSubresource.layerCount = 1;
12741 copy_region.dstOffset.x = 0;
12742 copy_region.dstOffset.y = 0;
12743 copy_region.dstOffset.z = 0;
12744 copy_region.extent.width = 1;
12745 copy_region.extent.height = 1;
12746 copy_region.extent.depth = 1;
12747
Mark Lobodzinski91c28262017-03-22 13:06:12 -060012748 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
12749 "layout should be VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL instead of GENERAL.");
12750 m_errorMonitor->SetUnexpectedError("layout should be VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL instead of GENERAL.");
Tobin Ehlis74cc6822017-03-14 16:16:51 -060012751
Cort530cf382016-12-08 09:59:47 -080012752 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copy_region);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012753 m_errorMonitor->VerifyFound();
Tobin Ehlise35b66a2017-03-15 12:18:31 -060012754 // The first call hits the expected WARNING and skips the call down the chain, so call a second time to call down chain and
12755 // update layer state
Mark Lobodzinski91c28262017-03-22 13:06:12 -060012756 m_errorMonitor->SetUnexpectedError("layout should be VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL instead of GENERAL.");
12757 m_errorMonitor->SetUnexpectedError("layout should be VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL instead of GENERAL.");
Tobin Ehlise35b66a2017-03-15 12:18:31 -060012758 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copy_region);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012759 // Now cause error due to src image layout changing
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012760 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski91c28262017-03-22 13:06:12 -060012761 "with specific layout VK_IMAGE_LAYOUT_UNDEFINED that "
12762 "doesn't match the actual current layout VK_IMAGE_LAYOUT_GENERAL.");
Mark Lobodzinskic61e1da2017-05-15 16:18:13 -060012763 m_errorMonitor->SetUnexpectedError("is VK_IMAGE_LAYOUT_UNDEFINED but can only be VK_IMAGE_LAYOUT");
Cort530cf382016-12-08 09:59:47 -080012764 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copy_region);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012765 m_errorMonitor->VerifyFound();
12766 // Final src error is due to bad layout type
Tobin Ehlis74cc6822017-03-14 16:16:51 -060012767 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski91c28262017-03-22 13:06:12 -060012768 "is VK_IMAGE_LAYOUT_UNDEFINED but can only be "
Tobin Ehlis74cc6822017-03-14 16:16:51 -060012769 "VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL or VK_IMAGE_LAYOUT_GENERAL.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012770 m_errorMonitor->SetUnexpectedError(
Mark Lobodzinski91c28262017-03-22 13:06:12 -060012771 "with specific layout VK_IMAGE_LAYOUT_UNDEFINED that doesn't match the actual current layout VK_IMAGE_LAYOUT_GENERAL.");
Cort530cf382016-12-08 09:59:47 -080012772 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copy_region);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012773 m_errorMonitor->VerifyFound();
12774 // Now verify same checks for dst
Mark Lobodzinski91c28262017-03-22 13:06:12 -060012775 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
12776 "layout should be VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL instead of GENERAL.");
12777 m_errorMonitor->SetUnexpectedError("layout should be VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL instead of GENERAL.");
Cort530cf382016-12-08 09:59:47 -080012778 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copy_region);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012779 m_errorMonitor->VerifyFound();
12780 // Now cause error due to src image layout changing
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012781 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski91c28262017-03-22 13:06:12 -060012782 "with specific layout VK_IMAGE_LAYOUT_UNDEFINED that doesn't match "
Tobin Ehlis74cc6822017-03-14 16:16:51 -060012783 "the actual current layout VK_IMAGE_LAYOUT_GENERAL.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012784 m_errorMonitor->SetUnexpectedError(
Mark Lobodzinski91c28262017-03-22 13:06:12 -060012785 "is VK_IMAGE_LAYOUT_UNDEFINED but can only be VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL or VK_IMAGE_LAYOUT_GENERAL.");
Cort530cf382016-12-08 09:59:47 -080012786 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, &copy_region);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012787 m_errorMonitor->VerifyFound();
Tobin Ehlis74cc6822017-03-14 16:16:51 -060012788 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski91c28262017-03-22 13:06:12 -060012789 "is VK_IMAGE_LAYOUT_UNDEFINED but can only be VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL "
12790 "or VK_IMAGE_LAYOUT_GENERAL.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012791 m_errorMonitor->SetUnexpectedError(
Mark Lobodzinski91c28262017-03-22 13:06:12 -060012792 "with specific layout VK_IMAGE_LAYOUT_UNDEFINED that doesn't match the actual current layout VK_IMAGE_LAYOUT_GENERAL.");
Cort530cf382016-12-08 09:59:47 -080012793 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, &copy_region);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012794 m_errorMonitor->VerifyFound();
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010012795
Cort3b021012016-12-07 12:00:57 -080012796 // Convert dst and depth images to TRANSFER_DST for subsequent tests
12797 VkImageMemoryBarrier transfer_dst_image_barrier[1] = {};
12798 transfer_dst_image_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
12799 transfer_dst_image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
12800 transfer_dst_image_barrier[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
12801 transfer_dst_image_barrier[0].srcAccessMask = 0;
12802 transfer_dst_image_barrier[0].dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
12803 transfer_dst_image_barrier[0].image = dst_image;
12804 transfer_dst_image_barrier[0].subresourceRange.layerCount = image_create_info.arrayLayers;
12805 transfer_dst_image_barrier[0].subresourceRange.levelCount = image_create_info.mipLevels;
12806 transfer_dst_image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12807 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
12808 NULL, 0, NULL, 1, transfer_dst_image_barrier);
12809 transfer_dst_image_barrier[0].image = depth_image;
12810 transfer_dst_image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
12811 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
12812 NULL, 0, NULL, 1, transfer_dst_image_barrier);
12813
12814 // Cause errors due to clearing with invalid image layouts
Cort530cf382016-12-08 09:59:47 -080012815 VkClearColorValue color_clear_value = {};
12816 VkImageSubresourceRange clear_range;
12817 clear_range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12818 clear_range.baseMipLevel = 0;
12819 clear_range.baseArrayLayer = 0;
12820 clear_range.layerCount = 1;
12821 clear_range.levelCount = 1;
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010012822
Cort3b021012016-12-07 12:00:57 -080012823 // Fail due to explicitly prohibited layout for color clear (only GENERAL and TRANSFER_DST are permitted).
12824 // Since the image is currently not in UNDEFINED layout, this will emit two errors.
12825 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01086);
12826 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01085);
Cort530cf382016-12-08 09:59:47 -080012827 m_commandBuffer->ClearColorImage(dst_image, VK_IMAGE_LAYOUT_UNDEFINED, &color_clear_value, 1, &clear_range);
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010012828 m_errorMonitor->VerifyFound();
Cort3b021012016-12-07 12:00:57 -080012829 // Fail due to provided layout not matching actual current layout for color clear.
12830 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01085);
Cort530cf382016-12-08 09:59:47 -080012831 m_commandBuffer->ClearColorImage(dst_image, VK_IMAGE_LAYOUT_GENERAL, &color_clear_value, 1, &clear_range);
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010012832 m_errorMonitor->VerifyFound();
Cort3b021012016-12-07 12:00:57 -080012833
Cort530cf382016-12-08 09:59:47 -080012834 VkClearDepthStencilValue depth_clear_value = {};
12835 clear_range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Cort3b021012016-12-07 12:00:57 -080012836
12837 // Fail due to explicitly prohibited layout for depth clear (only GENERAL and TRANSFER_DST are permitted).
12838 // Since the image is currently not in UNDEFINED layout, this will emit two errors.
12839 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01101);
12840 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01100);
Cort530cf382016-12-08 09:59:47 -080012841 m_commandBuffer->ClearDepthStencilImage(depth_image, VK_IMAGE_LAYOUT_UNDEFINED, &depth_clear_value, 1, &clear_range);
Cort3b021012016-12-07 12:00:57 -080012842 m_errorMonitor->VerifyFound();
12843 // Fail due to provided layout not matching actual current layout for depth clear.
12844 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01100);
Cort530cf382016-12-08 09:59:47 -080012845 m_commandBuffer->ClearDepthStencilImage(depth_image, VK_IMAGE_LAYOUT_GENERAL, &depth_clear_value, 1, &clear_range);
Cort3b021012016-12-07 12:00:57 -080012846 m_errorMonitor->VerifyFound();
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010012847
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012848 // Now cause error due to bad image layout transition in PipelineBarrier
12849 VkImageMemoryBarrier image_barrier[1] = {};
Cort3b021012016-12-07 12:00:57 -080012850 image_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012851 image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
Cort3b021012016-12-07 12:00:57 -080012852 image_barrier[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012853 image_barrier[0].image = src_image;
Cort3b021012016-12-07 12:00:57 -080012854 image_barrier[0].subresourceRange.layerCount = image_create_info.arrayLayers;
12855 image_barrier[0].subresourceRange.levelCount = image_create_info.mipLevels;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012856 image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012857 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski91c28262017-03-22 13:06:12 -060012858 "you cannot transition the layout of aspect 1 from "
12859 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL when current layout is "
12860 "VK_IMAGE_LAYOUT_GENERAL.");
Mike Weiblen62d08a32017-03-07 22:18:27 -070012861 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00305);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012862 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
12863 NULL, 0, NULL, 1, image_barrier);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012864 m_errorMonitor->VerifyFound();
12865
12866 // Finally some layout errors at RenderPass create time
12867 // Just hacking in specific state to get to the errors we want so don't copy this unless you know what you're doing.
12868 VkAttachmentReference attach = {};
12869 // perf warning for GENERAL layout w/ non-DS input attachment
12870 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
12871 VkSubpassDescription subpass = {};
12872 subpass.inputAttachmentCount = 1;
12873 subpass.pInputAttachments = &attach;
12874 VkRenderPassCreateInfo rpci = {};
12875 rpci.subpassCount = 1;
12876 rpci.pSubpasses = &subpass;
12877 rpci.attachmentCount = 1;
12878 VkAttachmentDescription attach_desc = {};
12879 attach_desc.format = VK_FORMAT_UNDEFINED;
12880 rpci.pAttachments = &attach_desc;
Tobin Ehlis1efce022016-05-11 10:40:34 -060012881 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012882 VkRenderPass rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012883 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
12884 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012885 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12886 m_errorMonitor->VerifyFound();
12887 // error w/ non-general layout
12888 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
12889
12890 m_errorMonitor->SetDesiredFailureMsg(
12891 VK_DEBUG_REPORT_ERROR_BIT_EXT,
12892 "Layout for input attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be READ_ONLY_OPTIMAL or GENERAL.");
12893 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12894 m_errorMonitor->VerifyFound();
12895 subpass.inputAttachmentCount = 0;
12896 subpass.colorAttachmentCount = 1;
12897 subpass.pColorAttachments = &attach;
12898 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
12899 // perf warning for GENERAL layout on color attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012900 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
12901 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012902 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12903 m_errorMonitor->VerifyFound();
12904 // error w/ non-color opt or GENERAL layout for color attachment
12905 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
12906 m_errorMonitor->SetDesiredFailureMsg(
12907 VK_DEBUG_REPORT_ERROR_BIT_EXT,
12908 "Layout for color attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.");
12909 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12910 m_errorMonitor->VerifyFound();
12911 subpass.colorAttachmentCount = 0;
12912 subpass.pDepthStencilAttachment = &attach;
12913 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
12914 // perf warning for GENERAL layout on DS attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012915 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
12916 "GENERAL layout for depth attachment may not give optimal performance.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012917 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12918 m_errorMonitor->VerifyFound();
12919 // error w/ non-ds opt or GENERAL layout for color attachment
12920 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012921 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12922 "Layout for depth attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be "
12923 "DEPTH_STENCIL_ATTACHMENT_OPTIMAL, DEPTH_STENCIL_READ_ONLY_OPTIMAL or GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012924 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12925 m_errorMonitor->VerifyFound();
Tobin Ehlis1efce022016-05-11 10:40:34 -060012926 // For this error we need a valid renderpass so create default one
12927 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
12928 attach.attachment = 0;
Tony Barbourf887b162017-03-09 10:06:46 -070012929 attach_desc.format = depth_format;
Tobin Ehlis1efce022016-05-11 10:40:34 -060012930 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
12931 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
12932 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
12933 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
12934 // Can't do a CLEAR load on READ_ONLY initialLayout
12935 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
12936 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
12937 attach_desc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012938 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski91c28262017-03-22 13:06:12 -060012939 "with invalid first layout VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL");
Tobin Ehlis1efce022016-05-11 10:40:34 -060012940 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12941 m_errorMonitor->VerifyFound();
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012942
Cort3b021012016-12-07 12:00:57 -080012943 vkFreeMemory(m_device->device(), src_image_mem, NULL);
12944 vkFreeMemory(m_device->device(), dst_image_mem, NULL);
12945 vkFreeMemory(m_device->device(), depth_image_mem, NULL);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012946 vkDestroyImage(m_device->device(), src_image, NULL);
12947 vkDestroyImage(m_device->device(), dst_image, NULL);
Cort3b021012016-12-07 12:00:57 -080012948 vkDestroyImage(m_device->device(), depth_image, NULL);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012949}
Tobin Ehlisd8d89182016-07-18 20:13:11 -060012950
Tobin Ehlise0936662016-10-11 08:10:51 -060012951TEST_F(VkLayerTest, InvalidStorageImageLayout) {
12952 TEST_DESCRIPTION("Attempt to update a STORAGE_IMAGE descriptor w/o GENERAL layout.");
12953 VkResult err;
12954
Tony Barbour1fa09702017-03-16 12:09:08 -060012955 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlise0936662016-10-11 08:10:51 -060012956
12957 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
12958 VkImageTiling tiling;
12959 VkFormatProperties format_properties;
12960 vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties);
12961 if (format_properties.linearTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
12962 tiling = VK_IMAGE_TILING_LINEAR;
12963 } else if (format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
12964 tiling = VK_IMAGE_TILING_OPTIMAL;
12965 } else {
Dave Houlton584d51e2017-02-16 12:52:54 -070012966 printf(" Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; skipped.\n");
Tobin Ehlise0936662016-10-11 08:10:51 -060012967 return;
12968 }
12969
12970 VkDescriptorPoolSize ds_type = {};
12971 ds_type.type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
12972 ds_type.descriptorCount = 1;
12973
12974 VkDescriptorPoolCreateInfo ds_pool_ci = {};
12975 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12976 ds_pool_ci.maxSets = 1;
12977 ds_pool_ci.poolSizeCount = 1;
12978 ds_pool_ci.pPoolSizes = &ds_type;
12979 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
12980
12981 VkDescriptorPool ds_pool;
12982 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
12983 ASSERT_VK_SUCCESS(err);
12984
12985 VkDescriptorSetLayoutBinding dsl_binding = {};
12986 dsl_binding.binding = 0;
12987 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
12988 dsl_binding.descriptorCount = 1;
12989 dsl_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12990 dsl_binding.pImmutableSamplers = NULL;
12991
12992 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
12993 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12994 ds_layout_ci.pNext = NULL;
12995 ds_layout_ci.bindingCount = 1;
12996 ds_layout_ci.pBindings = &dsl_binding;
12997
12998 VkDescriptorSetLayout ds_layout;
12999 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
13000 ASSERT_VK_SUCCESS(err);
13001
13002 VkDescriptorSetAllocateInfo alloc_info = {};
13003 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
13004 alloc_info.descriptorSetCount = 1;
13005 alloc_info.descriptorPool = ds_pool;
13006 alloc_info.pSetLayouts = &ds_layout;
13007 VkDescriptorSet descriptor_set;
13008 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
13009 ASSERT_VK_SUCCESS(err);
13010
13011 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
13012 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13013 pipeline_layout_ci.pNext = NULL;
13014 pipeline_layout_ci.setLayoutCount = 1;
13015 pipeline_layout_ci.pSetLayouts = &ds_layout;
13016 VkPipelineLayout pipeline_layout;
13017 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
13018 ASSERT_VK_SUCCESS(err);
13019
13020 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060013021 image.Init(32, 32, 1, tex_format, VK_IMAGE_USAGE_STORAGE_BIT, tiling, 0);
Tobin Ehlise0936662016-10-11 08:10:51 -060013022 ASSERT_TRUE(image.initialized());
13023 VkImageView view = image.targetView(tex_format);
13024
13025 VkDescriptorImageInfo image_info = {};
13026 image_info.imageView = view;
13027 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
13028
13029 VkWriteDescriptorSet descriptor_write = {};
13030 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
13031 descriptor_write.dstSet = descriptor_set;
13032 descriptor_write.dstBinding = 0;
13033 descriptor_write.descriptorCount = 1;
13034 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
13035 descriptor_write.pImageInfo = &image_info;
13036
13037 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13038 " of VK_DESCRIPTOR_TYPE_STORAGE_IMAGE type is being updated with layout "
13039 "VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL but according to spec ");
13040 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
13041 m_errorMonitor->VerifyFound();
13042
13043 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
13044 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
13045 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
13046 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
13047}
13048
Chris Forbes3fa68552017-05-18 14:34:05 -070013049TEST_F(VkLayerTest, NonSimultaneousSecondaryMarksPrimary) {
Tony Barbour1fa09702017-03-16 12:09:08 -060013050 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes3fa68552017-05-18 14:34:05 -070013051 const char *simultaneous_use_message =
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013052 "does not have VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set and "
13053 "will cause primary command buffer";
Mark Mueller93b938f2016-08-18 10:27:40 -060013054
Chris Forbes3fa68552017-05-18 14:34:05 -070013055 VkCommandBufferObj secondary(m_device, m_commandPool, VK_COMMAND_BUFFER_LEVEL_SECONDARY);
Mark Mueller93b938f2016-08-18 10:27:40 -060013056
Chris Forbes3fa68552017-05-18 14:34:05 -070013057 secondary.begin();
13058 secondary.end();
Rene Lindsay24cf6c52017-01-04 12:06:59 -070013059
Chris Forbes3fa68552017-05-18 14:34:05 -070013060 VkCommandBufferBeginInfo cbbi = {
13061 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
13062 VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT, nullptr,
13063 };
Mark Mueller93b938f2016-08-18 10:27:40 -060013064
Chris Forbes3fa68552017-05-18 14:34:05 -070013065 m_commandBuffer->begin(&cbbi);
13066 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, simultaneous_use_message);
13067 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary.handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060013068 m_errorMonitor->VerifyFound();
Chris Forbes3fa68552017-05-18 14:34:05 -070013069 m_commandBuffer->end();
13070}
Mark Mueller93b938f2016-08-18 10:27:40 -060013071
Chris Forbes3fa68552017-05-18 14:34:05 -070013072TEST_F(VkLayerTest, SimultaneousUseSecondaryTwoExecutes) {
13073 ASSERT_NO_FATAL_FAILURE(Init());
Mark Mueller93b938f2016-08-18 10:27:40 -060013074
Chris Forbes3fa68552017-05-18 14:34:05 -070013075 const char *simultaneous_use_message = "without VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set!";
Mark Mueller4042b652016-09-05 22:52:21 -060013076
Chris Forbes3fa68552017-05-18 14:34:05 -070013077 VkCommandBufferObj secondary(m_device, m_commandPool, VK_COMMAND_BUFFER_LEVEL_SECONDARY);
13078
13079 VkCommandBufferInheritanceInfo inh = {
13080 VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO, nullptr,
13081 };
13082 VkCommandBufferBeginInfo cbbi = {
13083 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
13084 0, &inh
13085 };
13086
13087 secondary.begin(&cbbi);
13088 secondary.end();
13089
13090 m_commandBuffer->begin();
13091 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary.handle());
13092 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, simultaneous_use_message);
13093 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary.handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060013094 m_errorMonitor->VerifyFound();
Chris Forbes3fa68552017-05-18 14:34:05 -070013095 m_commandBuffer->end();
13096}
Rene Lindsay24cf6c52017-01-04 12:06:59 -070013097
Chris Forbes3fa68552017-05-18 14:34:05 -070013098TEST_F(VkLayerTest, SimultaneousUseSecondarySingleExecute) {
13099 ASSERT_NO_FATAL_FAILURE(Init());
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070013100
Chris Forbes3fa68552017-05-18 14:34:05 -070013101 // variation on previous test executing the same CB twice in the same
13102 // CmdExecuteCommands call
13103
13104 const char *simultaneous_use_message = "without VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set!";
13105
13106 VkCommandBufferObj secondary(m_device, m_commandPool, VK_COMMAND_BUFFER_LEVEL_SECONDARY);
13107
13108 VkCommandBufferInheritanceInfo inh = {
13109 VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO, nullptr,
13110 };
13111 VkCommandBufferBeginInfo cbbi = {
13112 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
13113 0, &inh
13114 };
13115
13116 secondary.begin(&cbbi);
13117 secondary.end();
13118
13119 m_commandBuffer->begin();
13120 VkCommandBuffer cbs[] = { secondary.handle(), secondary.handle() };
13121 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, simultaneous_use_message);
13122 vkCmdExecuteCommands(m_commandBuffer->handle(), 2, cbs);
13123 m_errorMonitor->VerifyFound();
13124 m_commandBuffer->end();
Mark Mueller93b938f2016-08-18 10:27:40 -060013125}
13126
Tony Barbour626994c2017-02-08 15:29:37 -070013127TEST_F(VkLayerTest, SimultaneousUseOneShot) {
13128 TEST_DESCRIPTION(
13129 "Submit the same command buffer twice in one submit looking for simultaneous use and one time submit"
13130 "errors");
13131 const char *simultaneous_use_message = "is already in use and is not marked for simultaneous use";
13132 const char *one_shot_message = "VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has been submitted";
Tony Barbour1fa09702017-03-16 12:09:08 -060013133 ASSERT_NO_FATAL_FAILURE(Init());
Tony Barbour626994c2017-02-08 15:29:37 -070013134
13135 VkCommandBuffer cmd_bufs[2];
13136 VkCommandBufferAllocateInfo alloc_info;
13137 alloc_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
13138 alloc_info.pNext = NULL;
13139 alloc_info.commandBufferCount = 2;
Mike Schuchardt06304c22017-03-01 17:09:09 -070013140 alloc_info.commandPool = m_commandPool->handle();
Tony Barbour626994c2017-02-08 15:29:37 -070013141 alloc_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
13142 vkAllocateCommandBuffers(m_device->device(), &alloc_info, cmd_bufs);
13143
13144 VkCommandBufferBeginInfo cb_binfo;
13145 cb_binfo.pNext = NULL;
13146 cb_binfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
13147 cb_binfo.pInheritanceInfo = VK_NULL_HANDLE;
13148 cb_binfo.flags = 0;
13149 vkBeginCommandBuffer(cmd_bufs[0], &cb_binfo);
13150 VkViewport viewport = {0, 0, 16, 16, 0, 1};
13151 vkCmdSetViewport(cmd_bufs[0], 0, 1, &viewport);
13152 vkEndCommandBuffer(cmd_bufs[0]);
13153 VkCommandBuffer duplicates[2] = {cmd_bufs[0], cmd_bufs[0]};
13154
13155 VkSubmitInfo submit_info = {};
13156 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
13157 submit_info.commandBufferCount = 2;
13158 submit_info.pCommandBuffers = duplicates;
13159 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, simultaneous_use_message);
13160 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
13161 m_errorMonitor->VerifyFound();
13162 vkQueueWaitIdle(m_device->m_queue);
13163
13164 // Set one time use and now look for one time submit
13165 duplicates[0] = duplicates[1] = cmd_bufs[1];
13166 cb_binfo.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT | VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
13167 vkBeginCommandBuffer(cmd_bufs[1], &cb_binfo);
13168 vkCmdSetViewport(cmd_bufs[1], 0, 1, &viewport);
13169 vkEndCommandBuffer(cmd_bufs[1]);
13170 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, one_shot_message);
13171 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
13172 m_errorMonitor->VerifyFound();
13173 vkQueueWaitIdle(m_device->m_queue);
13174}
13175
Tobin Ehlisb093da82017-01-19 12:05:27 -070013176TEST_F(VkLayerTest, StageMaskGsTsEnabled) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013177 TEST_DESCRIPTION(
13178 "Attempt to use a stageMask w/ geometry shader and tesselation shader bits enabled when those features are "
13179 "disabled on the device.");
Tobin Ehlisb093da82017-01-19 12:05:27 -070013180
Tony Barbour1fa09702017-03-16 12:09:08 -060013181 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisb093da82017-01-19 12:05:27 -070013182 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13183
13184 std::vector<const char *> device_extension_names;
13185 auto features = m_device->phy().features();
13186 // Make sure gs & ts are disabled
13187 features.geometryShader = false;
13188 features.tessellationShader = false;
13189 // The sacrificial device object
13190 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
13191
13192 VkCommandPoolCreateInfo pool_create_info{};
13193 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
13194 pool_create_info.queueFamilyIndex = test_device.graphics_queue_node_index_;
13195
13196 VkCommandPool command_pool;
13197 vkCreateCommandPool(test_device.handle(), &pool_create_info, nullptr, &command_pool);
13198
13199 VkCommandBufferAllocateInfo cmd = {};
13200 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
13201 cmd.pNext = NULL;
13202 cmd.commandPool = command_pool;
13203 cmd.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
13204 cmd.commandBufferCount = 1;
13205
13206 VkCommandBuffer cmd_buffer;
13207 VkResult err = vkAllocateCommandBuffers(test_device.handle(), &cmd, &cmd_buffer);
13208 ASSERT_VK_SUCCESS(err);
13209
13210 VkEvent event;
13211 VkEventCreateInfo evci = {};
13212 evci.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
13213 VkResult result = vkCreateEvent(test_device.handle(), &evci, NULL, &event);
13214 ASSERT_VK_SUCCESS(result);
13215
13216 VkCommandBufferBeginInfo cbbi = {};
13217 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
13218 vkBeginCommandBuffer(cmd_buffer, &cbbi);
13219 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00230);
13220 vkCmdSetEvent(cmd_buffer, event, VK_PIPELINE_STAGE_GEOMETRY_SHADER_BIT);
13221 m_errorMonitor->VerifyFound();
13222
13223 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00231);
13224 vkCmdSetEvent(cmd_buffer, event, VK_PIPELINE_STAGE_TESSELLATION_CONTROL_SHADER_BIT);
13225 m_errorMonitor->VerifyFound();
13226
13227 vkDestroyEvent(test_device.handle(), event, NULL);
13228 vkDestroyCommandPool(test_device.handle(), command_pool, NULL);
13229}
13230
Chris Forbesd70103a2017-04-13 11:34:09 -070013231TEST_F(VkLayerTest, EventInUseDestroyedSignaled) {
Tony Barbour1fa09702017-03-16 12:09:08 -060013232 ASSERT_NO_FATAL_FAILURE(Init());
Mark Mueller917f6bc2016-08-30 10:57:19 -060013233 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13234
Tony Barbour552f6c02016-12-21 14:34:07 -070013235 m_commandBuffer->BeginCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060013236
13237 VkEvent event;
13238 VkEventCreateInfo event_create_info = {};
13239 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
13240 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013241 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Mueller917f6bc2016-08-30 10:57:19 -060013242
Tony Barbour552f6c02016-12-21 14:34:07 -070013243 m_commandBuffer->EndCommandBuffer();
Mark Muellerc8d441e2016-08-23 17:36:00 -060013244 vkDestroyEvent(m_device->device(), event, nullptr);
13245
13246 VkSubmitInfo submit_info = {};
13247 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
13248 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013249 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Lobodzinskife4be302017-02-14 13:08:15 -070013250 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is invalid because bound");
Mark Muellerc8d441e2016-08-23 17:36:00 -060013251 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
13252 m_errorMonitor->VerifyFound();
Chris Forbesd70103a2017-04-13 11:34:09 -070013253}
Mark Muellerc8d441e2016-08-23 17:36:00 -060013254
Chris Forbesd70103a2017-04-13 11:34:09 -070013255TEST_F(VkLayerTest, InUseDestroyedSignaled) {
13256 TEST_DESCRIPTION(
13257 "Use vkCmdExecuteCommands with invalid state "
13258 "in primary and secondary command buffers. "
13259 "Delete objects that are inuse. Call VkQueueSubmit "
13260 "with an event that has been deleted.");
Mark Muellerc8d441e2016-08-23 17:36:00 -060013261
Chris Forbesd70103a2017-04-13 11:34:09 -070013262 ASSERT_NO_FATAL_FAILURE(Init());
13263 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13264
13265 m_errorMonitor->ExpectSuccess();
Mark Muellerc8d441e2016-08-23 17:36:00 -060013266
Mark Mueller917f6bc2016-08-30 10:57:19 -060013267 VkSemaphoreCreateInfo semaphore_create_info = {};
13268 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
13269 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013270 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller917f6bc2016-08-30 10:57:19 -060013271 VkFenceCreateInfo fence_create_info = {};
13272 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
13273 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013274 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller917f6bc2016-08-30 10:57:19 -060013275
13276 VkDescriptorPoolSize descriptor_pool_type_count = {};
Mark Mueller4042b652016-09-05 22:52:21 -060013277 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060013278 descriptor_pool_type_count.descriptorCount = 1;
13279
13280 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
13281 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
13282 descriptor_pool_create_info.maxSets = 1;
13283 descriptor_pool_create_info.poolSizeCount = 1;
13284 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013285 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Mark Mueller917f6bc2016-08-30 10:57:19 -060013286
13287 VkDescriptorPool descriptorset_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013288 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
Mark Mueller917f6bc2016-08-30 10:57:19 -060013289
13290 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
Mark Mueller4042b652016-09-05 22:52:21 -060013291 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060013292 descriptorset_layout_binding.descriptorCount = 1;
13293 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
13294
13295 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013296 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060013297 descriptorset_layout_create_info.bindingCount = 1;
13298 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
13299
13300 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013301 ASSERT_VK_SUCCESS(
13302 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060013303
13304 VkDescriptorSet descriptorset;
13305 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013306 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060013307 descriptorset_allocate_info.descriptorSetCount = 1;
13308 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
13309 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013310 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
Mark Mueller917f6bc2016-08-30 10:57:19 -060013311
Mark Mueller4042b652016-09-05 22:52:21 -060013312 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
13313
13314 VkDescriptorBufferInfo buffer_info = {};
13315 buffer_info.buffer = buffer_test.GetBuffer();
13316 buffer_info.offset = 0;
13317 buffer_info.range = 1024;
13318
13319 VkWriteDescriptorSet write_descriptor_set = {};
13320 write_descriptor_set.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
13321 write_descriptor_set.dstSet = descriptorset;
13322 write_descriptor_set.descriptorCount = 1;
13323 write_descriptor_set.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
13324 write_descriptor_set.pBufferInfo = &buffer_info;
13325
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013326 vkUpdateDescriptorSets(m_device->device(), 1, &write_descriptor_set, 0, nullptr);
Mark Mueller4042b652016-09-05 22:52:21 -060013327
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013328 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
13329 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Mueller917f6bc2016-08-30 10:57:19 -060013330
13331 VkPipelineObj pipe(m_device);
13332 pipe.AddColorAttachment();
13333 pipe.AddShader(&vs);
13334 pipe.AddShader(&fs);
13335
13336 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013337 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060013338 pipeline_layout_create_info.setLayoutCount = 1;
13339 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
13340
13341 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013342 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060013343
13344 pipe.CreateVKPipeline(pipeline_layout, m_renderPass);
13345
Chris Forbesd70103a2017-04-13 11:34:09 -070013346 VkEvent event;
13347 VkEventCreateInfo event_create_info = {};
13348 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
13349 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
13350
Tony Barbour552f6c02016-12-21 14:34:07 -070013351 m_commandBuffer->BeginCommandBuffer();
Chris Forbesd70103a2017-04-13 11:34:09 -070013352
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013353 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Muellerc8d441e2016-08-23 17:36:00 -060013354
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013355 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
13356 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
13357 &descriptorset, 0, NULL);
Mark Mueller917f6bc2016-08-30 10:57:19 -060013358
Tony Barbour552f6c02016-12-21 14:34:07 -070013359 m_commandBuffer->EndCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060013360
Chris Forbesd70103a2017-04-13 11:34:09 -070013361 VkSubmitInfo submit_info = {};
13362 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
13363 submit_info.commandBufferCount = 1;
13364 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller917f6bc2016-08-30 10:57:19 -060013365 submit_info.signalSemaphoreCount = 1;
13366 submit_info.pSignalSemaphores = &semaphore;
13367 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013368 m_errorMonitor->Reset(); // resume logmsg processing
Mark Muellerc8d441e2016-08-23 17:36:00 -060013369
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070013370 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00213);
Mark Mueller917f6bc2016-08-30 10:57:19 -060013371 vkDestroyEvent(m_device->device(), event, nullptr);
13372 m_errorMonitor->VerifyFound();
13373
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070013374 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00199);
Mark Mueller917f6bc2016-08-30 10:57:19 -060013375 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
13376 m_errorMonitor->VerifyFound();
13377
Jeremy Hayes08369882017-02-02 10:31:06 -070013378 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Fence 0x");
Mark Mueller917f6bc2016-08-30 10:57:19 -060013379 vkDestroyFence(m_device->device(), fence, nullptr);
13380 m_errorMonitor->VerifyFound();
13381
Tobin Ehlis122207b2016-09-01 08:50:06 -070013382 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070013383 m_errorMonitor->SetUnexpectedError("If semaphore is not VK_NULL_HANDLE, semaphore must be a valid VkSemaphore handle");
13384 m_errorMonitor->SetUnexpectedError("Unable to remove Semaphore obj");
Mark Mueller917f6bc2016-08-30 10:57:19 -060013385 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070013386 m_errorMonitor->SetUnexpectedError("If fence is not VK_NULL_HANDLE, fence must be a valid VkFence handle");
13387 m_errorMonitor->SetUnexpectedError("Unable to remove Fence obj");
Mark Mueller917f6bc2016-08-30 10:57:19 -060013388 vkDestroyFence(m_device->device(), fence, nullptr);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070013389 m_errorMonitor->SetUnexpectedError("If event is not VK_NULL_HANDLE, event must be a valid VkEvent handle");
13390 m_errorMonitor->SetUnexpectedError("Unable to remove Event obj");
Mark Mueller917f6bc2016-08-30 10:57:19 -060013391 vkDestroyEvent(m_device->device(), event, nullptr);
13392 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013393 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
Mark Mueller917f6bc2016-08-30 10:57:19 -060013394 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13395}
13396
Tobin Ehlis2adda372016-09-01 08:51:06 -070013397TEST_F(VkLayerTest, QueryPoolInUseDestroyedSignaled) {
13398 TEST_DESCRIPTION("Delete in-use query pool.");
13399
Tony Barbour1fa09702017-03-16 12:09:08 -060013400 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis2adda372016-09-01 08:51:06 -070013401 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13402
13403 VkQueryPool query_pool;
13404 VkQueryPoolCreateInfo query_pool_ci{};
13405 query_pool_ci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
13406 query_pool_ci.queryType = VK_QUERY_TYPE_TIMESTAMP;
13407 query_pool_ci.queryCount = 1;
13408 vkCreateQueryPool(m_device->device(), &query_pool_ci, nullptr, &query_pool);
Tony Barbour552f6c02016-12-21 14:34:07 -070013409 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis2adda372016-09-01 08:51:06 -070013410 // Reset query pool to create binding with cmd buffer
13411 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0, 1);
13412
Tony Barbour552f6c02016-12-21 14:34:07 -070013413 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis2adda372016-09-01 08:51:06 -070013414
13415 VkSubmitInfo submit_info = {};
13416 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
13417 submit_info.commandBufferCount = 1;
13418 submit_info.pCommandBuffers = &m_commandBuffer->handle();
13419 // Submit cmd buffer and then destroy query pool while in-flight
13420 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
13421
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070013422 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01012);
Tobin Ehlis2adda372016-09-01 08:51:06 -070013423 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
13424 m_errorMonitor->VerifyFound();
13425
13426 vkQueueWaitIdle(m_device->m_queue);
13427 // Now that cmd buffer done we can safely destroy query_pool
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070013428 m_errorMonitor->SetUnexpectedError("If queryPool is not VK_NULL_HANDLE, queryPool must be a valid VkQueryPool handle");
Mark Lobodzinski74597792017-04-11 15:43:49 -060013429 m_errorMonitor->SetUnexpectedError("Unable to remove QueryPool obj");
Tobin Ehlis2adda372016-09-01 08:51:06 -070013430 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
13431}
13432
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060013433TEST_F(VkLayerTest, PipelineInUseDestroyedSignaled) {
13434 TEST_DESCRIPTION("Delete in-use pipeline.");
13435
Tony Barbour1fa09702017-03-16 12:09:08 -060013436 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060013437 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13438
13439 // Empty pipeline layout used for binding PSO
13440 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
13441 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13442 pipeline_layout_ci.setLayoutCount = 0;
13443 pipeline_layout_ci.pSetLayouts = NULL;
13444
13445 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013446 VkResult err = vkCreatePipelineLayout(m_device->handle(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060013447 ASSERT_VK_SUCCESS(err);
13448
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070013449 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00555);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060013450 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013451 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
13452 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060013453 // Store pipeline handle so we can actually delete it before test finishes
13454 VkPipeline delete_this_pipeline;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013455 { // Scope pipeline so it will be auto-deleted
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060013456 VkPipelineObj pipe(m_device);
13457 pipe.AddShader(&vs);
13458 pipe.AddShader(&fs);
13459 pipe.AddColorAttachment();
13460 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13461 delete_this_pipeline = pipe.handle();
13462
Tony Barbour552f6c02016-12-21 14:34:07 -070013463 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060013464 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013465 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060013466
Tony Barbour552f6c02016-12-21 14:34:07 -070013467 m_commandBuffer->EndCommandBuffer();
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060013468
13469 VkSubmitInfo submit_info = {};
13470 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
13471 submit_info.commandBufferCount = 1;
13472 submit_info.pCommandBuffers = &m_commandBuffer->handle();
13473 // Submit cmd buffer and then pipeline destroyed while in-flight
13474 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013475 } // Pipeline deletion triggered here
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060013476 m_errorMonitor->VerifyFound();
13477 // Make sure queue finished and then actually delete pipeline
13478 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070013479 m_errorMonitor->SetUnexpectedError("If pipeline is not VK_NULL_HANDLE, pipeline must be a valid VkPipeline handle");
13480 m_errorMonitor->SetUnexpectedError("Unable to remove Pipeline obj");
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060013481 vkDestroyPipeline(m_device->handle(), delete_this_pipeline, nullptr);
13482 vkDestroyPipelineLayout(m_device->handle(), pipeline_layout, nullptr);
13483}
13484
Tobin Ehlis7d965da2016-09-19 16:15:45 -060013485TEST_F(VkLayerTest, ImageViewInUseDestroyedSignaled) {
13486 TEST_DESCRIPTION("Delete in-use imageView.");
13487
Tony Barbour1fa09702017-03-16 12:09:08 -060013488 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis7d965da2016-09-19 16:15:45 -060013489 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13490
13491 VkDescriptorPoolSize ds_type_count;
13492 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
13493 ds_type_count.descriptorCount = 1;
13494
13495 VkDescriptorPoolCreateInfo ds_pool_ci = {};
13496 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
13497 ds_pool_ci.maxSets = 1;
13498 ds_pool_ci.poolSizeCount = 1;
13499 ds_pool_ci.pPoolSizes = &ds_type_count;
13500
13501 VkDescriptorPool ds_pool;
13502 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
13503 ASSERT_VK_SUCCESS(err);
13504
13505 VkSamplerCreateInfo sampler_ci = {};
13506 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
13507 sampler_ci.pNext = NULL;
13508 sampler_ci.magFilter = VK_FILTER_NEAREST;
13509 sampler_ci.minFilter = VK_FILTER_NEAREST;
13510 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
13511 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
13512 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
13513 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
13514 sampler_ci.mipLodBias = 1.0;
13515 sampler_ci.anisotropyEnable = VK_FALSE;
13516 sampler_ci.maxAnisotropy = 1;
13517 sampler_ci.compareEnable = VK_FALSE;
13518 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
13519 sampler_ci.minLod = 1.0;
13520 sampler_ci.maxLod = 1.0;
13521 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
13522 sampler_ci.unnormalizedCoordinates = VK_FALSE;
13523 VkSampler sampler;
13524
13525 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
13526 ASSERT_VK_SUCCESS(err);
13527
13528 VkDescriptorSetLayoutBinding layout_binding;
13529 layout_binding.binding = 0;
13530 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
13531 layout_binding.descriptorCount = 1;
13532 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
13533 layout_binding.pImmutableSamplers = NULL;
13534
13535 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
13536 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
13537 ds_layout_ci.bindingCount = 1;
13538 ds_layout_ci.pBindings = &layout_binding;
13539 VkDescriptorSetLayout ds_layout;
13540 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
13541 ASSERT_VK_SUCCESS(err);
13542
13543 VkDescriptorSetAllocateInfo alloc_info = {};
13544 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
13545 alloc_info.descriptorSetCount = 1;
13546 alloc_info.descriptorPool = ds_pool;
13547 alloc_info.pSetLayouts = &ds_layout;
13548 VkDescriptorSet descriptor_set;
13549 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
13550 ASSERT_VK_SUCCESS(err);
13551
13552 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
13553 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13554 pipeline_layout_ci.pNext = NULL;
13555 pipeline_layout_ci.setLayoutCount = 1;
13556 pipeline_layout_ci.pSetLayouts = &ds_layout;
13557
13558 VkPipelineLayout pipeline_layout;
13559 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
13560 ASSERT_VK_SUCCESS(err);
13561
13562 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060013563 image.Init(128, 128, 1, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Tobin Ehlis7d965da2016-09-19 16:15:45 -060013564 ASSERT_TRUE(image.initialized());
13565
13566 VkImageView view;
13567 VkImageViewCreateInfo ivci = {};
13568 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
13569 ivci.image = image.handle();
13570 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
13571 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
13572 ivci.subresourceRange.layerCount = 1;
13573 ivci.subresourceRange.baseMipLevel = 0;
13574 ivci.subresourceRange.levelCount = 1;
13575 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
13576
13577 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
13578 ASSERT_VK_SUCCESS(err);
13579
13580 VkDescriptorImageInfo image_info{};
13581 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
13582 image_info.imageView = view;
13583 image_info.sampler = sampler;
13584
13585 VkWriteDescriptorSet descriptor_write = {};
13586 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
13587 descriptor_write.dstSet = descriptor_set;
13588 descriptor_write.dstBinding = 0;
13589 descriptor_write.descriptorCount = 1;
13590 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
13591 descriptor_write.pImageInfo = &image_info;
13592
13593 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
13594
13595 // Create PSO to use the sampler
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013596 char const *vsSource =
13597 "#version 450\n"
13598 "\n"
13599 "out gl_PerVertex { \n"
13600 " vec4 gl_Position;\n"
13601 "};\n"
13602 "void main(){\n"
13603 " gl_Position = vec4(1);\n"
13604 "}\n";
13605 char const *fsSource =
13606 "#version 450\n"
13607 "\n"
13608 "layout(set=0, binding=0) uniform sampler2D s;\n"
13609 "layout(location=0) out vec4 x;\n"
13610 "void main(){\n"
13611 " x = texture(s, vec2(1));\n"
13612 "}\n";
Tobin Ehlis7d965da2016-09-19 16:15:45 -060013613 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13614 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13615 VkPipelineObj pipe(m_device);
13616 pipe.AddShader(&vs);
13617 pipe.AddShader(&fs);
13618 pipe.AddColorAttachment();
13619 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13620
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070013621 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00776);
Tobin Ehlis7d965da2016-09-19 16:15:45 -060013622
Tony Barbour552f6c02016-12-21 14:34:07 -070013623 m_commandBuffer->BeginCommandBuffer();
13624 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis7d965da2016-09-19 16:15:45 -060013625 // Bind pipeline to cmd buffer
13626 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
13627 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
13628 &descriptor_set, 0, nullptr);
Rene Lindsaya8880622017-01-18 13:12:59 -070013629
13630 VkViewport viewport = {0, 0, 16, 16, 0, 1};
13631 VkRect2D scissor = {{0, 0}, {16, 16}};
13632 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
13633 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
13634
Tobin Ehlis7d965da2016-09-19 16:15:45 -060013635 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070013636 m_commandBuffer->EndRenderPass();
13637 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis7d965da2016-09-19 16:15:45 -060013638 // Submit cmd buffer then destroy sampler
13639 VkSubmitInfo submit_info = {};
13640 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
13641 submit_info.commandBufferCount = 1;
13642 submit_info.pCommandBuffers = &m_commandBuffer->handle();
13643 // Submit cmd buffer and then destroy imageView while in-flight
13644 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
13645
13646 vkDestroyImageView(m_device->device(), view, nullptr);
13647 m_errorMonitor->VerifyFound();
13648 vkQueueWaitIdle(m_device->m_queue);
13649 // Now we can actually destroy imageView
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070013650 m_errorMonitor->SetUnexpectedError("If imageView is not VK_NULL_HANDLE, imageView must be a valid VkImageView handle");
Mark Lobodzinski74597792017-04-11 15:43:49 -060013651 m_errorMonitor->SetUnexpectedError("Unable to remove ImageView obj");
Tobin Ehlis7d965da2016-09-19 16:15:45 -060013652 vkDestroyImageView(m_device->device(), view, NULL);
13653 vkDestroySampler(m_device->device(), sampler, nullptr);
13654 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
13655 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
13656 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
13657}
13658
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060013659TEST_F(VkLayerTest, BufferViewInUseDestroyedSignaled) {
13660 TEST_DESCRIPTION("Delete in-use bufferView.");
13661
Tony Barbour1fa09702017-03-16 12:09:08 -060013662 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060013663 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13664
13665 VkDescriptorPoolSize ds_type_count;
13666 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
13667 ds_type_count.descriptorCount = 1;
13668
13669 VkDescriptorPoolCreateInfo ds_pool_ci = {};
13670 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
13671 ds_pool_ci.maxSets = 1;
13672 ds_pool_ci.poolSizeCount = 1;
13673 ds_pool_ci.pPoolSizes = &ds_type_count;
13674
13675 VkDescriptorPool ds_pool;
13676 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
13677 ASSERT_VK_SUCCESS(err);
13678
13679 VkDescriptorSetLayoutBinding layout_binding;
13680 layout_binding.binding = 0;
13681 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
13682 layout_binding.descriptorCount = 1;
13683 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
13684 layout_binding.pImmutableSamplers = NULL;
13685
13686 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
13687 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
13688 ds_layout_ci.bindingCount = 1;
13689 ds_layout_ci.pBindings = &layout_binding;
13690 VkDescriptorSetLayout ds_layout;
13691 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
13692 ASSERT_VK_SUCCESS(err);
13693
13694 VkDescriptorSetAllocateInfo alloc_info = {};
13695 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
13696 alloc_info.descriptorSetCount = 1;
13697 alloc_info.descriptorPool = ds_pool;
13698 alloc_info.pSetLayouts = &ds_layout;
13699 VkDescriptorSet descriptor_set;
13700 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
13701 ASSERT_VK_SUCCESS(err);
13702
13703 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
13704 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13705 pipeline_layout_ci.pNext = NULL;
13706 pipeline_layout_ci.setLayoutCount = 1;
13707 pipeline_layout_ci.pSetLayouts = &ds_layout;
13708
13709 VkPipelineLayout pipeline_layout;
13710 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
13711 ASSERT_VK_SUCCESS(err);
13712
13713 VkBuffer buffer;
13714 uint32_t queue_family_index = 0;
13715 VkBufferCreateInfo buffer_create_info = {};
13716 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
13717 buffer_create_info.size = 1024;
13718 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
13719 buffer_create_info.queueFamilyIndexCount = 1;
13720 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
13721
13722 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
13723 ASSERT_VK_SUCCESS(err);
13724
13725 VkMemoryRequirements memory_reqs;
13726 VkDeviceMemory buffer_memory;
13727
13728 VkMemoryAllocateInfo memory_info = {};
13729 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
13730 memory_info.allocationSize = 0;
13731 memory_info.memoryTypeIndex = 0;
13732
13733 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
13734 memory_info.allocationSize = memory_reqs.size;
13735 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
13736 ASSERT_TRUE(pass);
13737
13738 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
13739 ASSERT_VK_SUCCESS(err);
13740 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
13741 ASSERT_VK_SUCCESS(err);
13742
13743 VkBufferView view;
13744 VkBufferViewCreateInfo bvci = {};
13745 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
13746 bvci.buffer = buffer;
Tobin Ehliscc980e12017-05-19 12:05:49 -060013747 bvci.format = VK_FORMAT_R32_SFLOAT;
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060013748 bvci.range = VK_WHOLE_SIZE;
13749
13750 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
13751 ASSERT_VK_SUCCESS(err);
13752
13753 VkWriteDescriptorSet descriptor_write = {};
13754 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
13755 descriptor_write.dstSet = descriptor_set;
13756 descriptor_write.dstBinding = 0;
13757 descriptor_write.descriptorCount = 1;
13758 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
13759 descriptor_write.pTexelBufferView = &view;
13760
13761 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
13762
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013763 char const *vsSource =
13764 "#version 450\n"
13765 "\n"
13766 "out gl_PerVertex { \n"
13767 " vec4 gl_Position;\n"
13768 "};\n"
13769 "void main(){\n"
13770 " gl_Position = vec4(1);\n"
13771 "}\n";
13772 char const *fsSource =
13773 "#version 450\n"
13774 "\n"
Tobin Ehliscc980e12017-05-19 12:05:49 -060013775 "layout(set=0, binding=0, r32f) uniform imageBuffer s;\n"
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013776 "layout(location=0) out vec4 x;\n"
13777 "void main(){\n"
13778 " x = imageLoad(s, 0);\n"
13779 "}\n";
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060013780 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13781 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13782 VkPipelineObj pipe(m_device);
13783 pipe.AddShader(&vs);
13784 pipe.AddShader(&fs);
13785 pipe.AddColorAttachment();
13786 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13787
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070013788 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00701);
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060013789
Tony Barbour552f6c02016-12-21 14:34:07 -070013790 m_commandBuffer->BeginCommandBuffer();
13791 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060013792 VkViewport viewport = {0, 0, 16, 16, 0, 1};
13793 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
13794 VkRect2D scissor = {{0, 0}, {16, 16}};
13795 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
13796 // Bind pipeline to cmd buffer
13797 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
13798 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
13799 &descriptor_set, 0, nullptr);
13800 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070013801 m_commandBuffer->EndRenderPass();
13802 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060013803
13804 VkSubmitInfo submit_info = {};
13805 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
13806 submit_info.commandBufferCount = 1;
13807 submit_info.pCommandBuffers = &m_commandBuffer->handle();
13808 // Submit cmd buffer and then destroy bufferView while in-flight
13809 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
13810
13811 vkDestroyBufferView(m_device->device(), view, nullptr);
13812 m_errorMonitor->VerifyFound();
13813 vkQueueWaitIdle(m_device->m_queue);
13814 // Now we can actually destroy bufferView
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070013815 m_errorMonitor->SetUnexpectedError("If bufferView is not VK_NULL_HANDLE, bufferView must be a valid VkBufferView handle");
Mark Lobodzinski74597792017-04-11 15:43:49 -060013816 m_errorMonitor->SetUnexpectedError("Unable to remove BufferView obj");
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060013817 vkDestroyBufferView(m_device->device(), view, NULL);
13818 vkDestroyBuffer(m_device->device(), buffer, NULL);
13819 vkFreeMemory(m_device->device(), buffer_memory, NULL);
13820 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
13821 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
13822 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
13823}
13824
Tobin Ehlis209532e2016-09-07 13:52:18 -060013825TEST_F(VkLayerTest, SamplerInUseDestroyedSignaled) {
13826 TEST_DESCRIPTION("Delete in-use sampler.");
13827
Tony Barbour1fa09702017-03-16 12:09:08 -060013828 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis209532e2016-09-07 13:52:18 -060013829 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13830
13831 VkDescriptorPoolSize ds_type_count;
13832 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
13833 ds_type_count.descriptorCount = 1;
13834
13835 VkDescriptorPoolCreateInfo ds_pool_ci = {};
13836 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
13837 ds_pool_ci.maxSets = 1;
13838 ds_pool_ci.poolSizeCount = 1;
13839 ds_pool_ci.pPoolSizes = &ds_type_count;
13840
13841 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013842 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis209532e2016-09-07 13:52:18 -060013843 ASSERT_VK_SUCCESS(err);
13844
13845 VkSamplerCreateInfo sampler_ci = {};
13846 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
13847 sampler_ci.pNext = NULL;
13848 sampler_ci.magFilter = VK_FILTER_NEAREST;
13849 sampler_ci.minFilter = VK_FILTER_NEAREST;
13850 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
13851 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
13852 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
13853 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
13854 sampler_ci.mipLodBias = 1.0;
13855 sampler_ci.anisotropyEnable = VK_FALSE;
13856 sampler_ci.maxAnisotropy = 1;
13857 sampler_ci.compareEnable = VK_FALSE;
13858 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
13859 sampler_ci.minLod = 1.0;
13860 sampler_ci.maxLod = 1.0;
13861 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
13862 sampler_ci.unnormalizedCoordinates = VK_FALSE;
13863 VkSampler sampler;
13864
13865 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
13866 ASSERT_VK_SUCCESS(err);
13867
13868 VkDescriptorSetLayoutBinding layout_binding;
13869 layout_binding.binding = 0;
Tobin Ehlis94fc0ad2016-09-19 16:23:01 -060013870 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
Tobin Ehlis209532e2016-09-07 13:52:18 -060013871 layout_binding.descriptorCount = 1;
13872 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
13873 layout_binding.pImmutableSamplers = NULL;
13874
13875 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
13876 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
13877 ds_layout_ci.bindingCount = 1;
13878 ds_layout_ci.pBindings = &layout_binding;
13879 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013880 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060013881 ASSERT_VK_SUCCESS(err);
13882
13883 VkDescriptorSetAllocateInfo alloc_info = {};
13884 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
13885 alloc_info.descriptorSetCount = 1;
13886 alloc_info.descriptorPool = ds_pool;
13887 alloc_info.pSetLayouts = &ds_layout;
13888 VkDescriptorSet descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013889 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis209532e2016-09-07 13:52:18 -060013890 ASSERT_VK_SUCCESS(err);
13891
13892 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
13893 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13894 pipeline_layout_ci.pNext = NULL;
13895 pipeline_layout_ci.setLayoutCount = 1;
13896 pipeline_layout_ci.pSetLayouts = &ds_layout;
13897
13898 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013899 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060013900 ASSERT_VK_SUCCESS(err);
13901
13902 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060013903 image.Init(128, 128, 1, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Tobin Ehlis209532e2016-09-07 13:52:18 -060013904 ASSERT_TRUE(image.initialized());
13905
13906 VkImageView view;
13907 VkImageViewCreateInfo ivci = {};
13908 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
13909 ivci.image = image.handle();
13910 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
13911 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
13912 ivci.subresourceRange.layerCount = 1;
13913 ivci.subresourceRange.baseMipLevel = 0;
13914 ivci.subresourceRange.levelCount = 1;
13915 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
13916
13917 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
13918 ASSERT_VK_SUCCESS(err);
13919
13920 VkDescriptorImageInfo image_info{};
13921 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
13922 image_info.imageView = view;
13923 image_info.sampler = sampler;
13924
13925 VkWriteDescriptorSet descriptor_write = {};
13926 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
13927 descriptor_write.dstSet = descriptor_set;
13928 descriptor_write.dstBinding = 0;
13929 descriptor_write.descriptorCount = 1;
13930 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
13931 descriptor_write.pImageInfo = &image_info;
13932
13933 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
13934
13935 // Create PSO to use the sampler
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013936 char const *vsSource =
13937 "#version 450\n"
13938 "\n"
13939 "out gl_PerVertex { \n"
13940 " vec4 gl_Position;\n"
13941 "};\n"
13942 "void main(){\n"
13943 " gl_Position = vec4(1);\n"
13944 "}\n";
13945 char const *fsSource =
13946 "#version 450\n"
13947 "\n"
13948 "layout(set=0, binding=0) uniform sampler2D s;\n"
13949 "layout(location=0) out vec4 x;\n"
13950 "void main(){\n"
13951 " x = texture(s, vec2(1));\n"
13952 "}\n";
Tobin Ehlis209532e2016-09-07 13:52:18 -060013953 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13954 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13955 VkPipelineObj pipe(m_device);
13956 pipe.AddShader(&vs);
13957 pipe.AddShader(&fs);
13958 pipe.AddColorAttachment();
13959 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13960
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070013961 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00837);
Tobin Ehlis209532e2016-09-07 13:52:18 -060013962
Tony Barbour552f6c02016-12-21 14:34:07 -070013963 m_commandBuffer->BeginCommandBuffer();
13964 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis209532e2016-09-07 13:52:18 -060013965 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013966 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
13967 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
13968 &descriptor_set, 0, nullptr);
Rene Lindsay4da11732017-01-13 14:42:10 -070013969
13970 VkViewport viewport = {0, 0, 16, 16, 0, 1};
13971 VkRect2D scissor = {{0, 0}, {16, 16}};
13972 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
13973 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
13974
Tobin Ehlis209532e2016-09-07 13:52:18 -060013975 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070013976 m_commandBuffer->EndRenderPass();
13977 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis209532e2016-09-07 13:52:18 -060013978 // Submit cmd buffer then destroy sampler
13979 VkSubmitInfo submit_info = {};
13980 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
13981 submit_info.commandBufferCount = 1;
13982 submit_info.pCommandBuffers = &m_commandBuffer->handle();
13983 // Submit cmd buffer and then destroy sampler while in-flight
13984 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
13985
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013986 vkDestroySampler(m_device->device(), sampler, nullptr); // Destroyed too soon
Tobin Ehlis209532e2016-09-07 13:52:18 -060013987 m_errorMonitor->VerifyFound();
13988 vkQueueWaitIdle(m_device->m_queue);
Rene Lindsay4da11732017-01-13 14:42:10 -070013989
Tobin Ehlis209532e2016-09-07 13:52:18 -060013990 // Now we can actually destroy sampler
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070013991 m_errorMonitor->SetUnexpectedError("If sampler is not VK_NULL_HANDLE, sampler must be a valid VkSampler handle");
13992 m_errorMonitor->SetUnexpectedError("Unable to remove Sampler obj");
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013993 vkDestroySampler(m_device->device(), sampler, NULL); // Destroyed for real
Tobin Ehlis209532e2016-09-07 13:52:18 -060013994 vkDestroyImageView(m_device->device(), view, NULL);
13995 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
13996 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
13997 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
13998}
13999
Mark Mueller1cd9f412016-08-25 13:23:52 -060014000TEST_F(VkLayerTest, QueueForwardProgressFenceWait) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014001 TEST_DESCRIPTION(
14002 "Call VkQueueSubmit with a semaphore that is already "
14003 "signaled but not waited on by the queue. Wait on a "
14004 "fence that has not yet been submitted to a queue.");
Mark Mueller96a56d52016-08-24 10:28:05 -060014005
Tony Barbour1fa09702017-03-16 12:09:08 -060014006 ASSERT_NO_FATAL_FAILURE(Init());
Mark Mueller96a56d52016-08-24 10:28:05 -060014007 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14008
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014009 const char *queue_forward_progress_message = " that has already been signaled but not waited on by queue 0x";
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014010 const char *invalid_fence_wait_message =
14011 " which has not been submitted on a Queue or during "
14012 "acquire next image.";
Mark Mueller96a56d52016-08-24 10:28:05 -060014013
Chris Forbese98aec12017-05-18 12:50:14 -070014014 VkCommandBufferObj cb1(m_device, m_commandPool);
14015 cb1.begin();
14016 cb1.end();
Mark Mueller96a56d52016-08-24 10:28:05 -060014017
14018 VkSemaphoreCreateInfo semaphore_create_info = {};
14019 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
14020 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014021 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller96a56d52016-08-24 10:28:05 -060014022 VkSubmitInfo submit_info = {};
14023 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
14024 submit_info.commandBufferCount = 1;
Chris Forbese98aec12017-05-18 12:50:14 -070014025 submit_info.pCommandBuffers = &cb1.handle();
Mark Mueller96a56d52016-08-24 10:28:05 -060014026 submit_info.signalSemaphoreCount = 1;
14027 submit_info.pSignalSemaphores = &semaphore;
14028 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Chris Forbese98aec12017-05-18 12:50:14 -070014029
Tony Barbour552f6c02016-12-21 14:34:07 -070014030 m_commandBuffer->BeginCommandBuffer();
14031 m_commandBuffer->EndCommandBuffer();
Chris Forbese98aec12017-05-18 12:50:14 -070014032 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014033 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, queue_forward_progress_message);
Mark Mueller96a56d52016-08-24 10:28:05 -060014034 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
14035 m_errorMonitor->VerifyFound();
14036
Mark Mueller1cd9f412016-08-25 13:23:52 -060014037 VkFenceCreateInfo fence_create_info = {};
14038 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
14039 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014040 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller1cd9f412016-08-25 13:23:52 -060014041
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014042 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, invalid_fence_wait_message);
Mark Mueller1cd9f412016-08-25 13:23:52 -060014043 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
14044 m_errorMonitor->VerifyFound();
14045
Mark Mueller4042b652016-09-05 22:52:21 -060014046 vkDeviceWaitIdle(m_device->device());
Mark Mueller1cd9f412016-08-25 13:23:52 -060014047 vkDestroyFence(m_device->device(), fence, nullptr);
Mark Mueller96a56d52016-08-24 10:28:05 -060014048 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
14049}
14050
Tobin Ehlis4af23302016-07-19 10:50:30 -060014051TEST_F(VkLayerTest, FramebufferIncompatible) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014052 TEST_DESCRIPTION(
14053 "Bind a secondary command buffer with with a framebuffer "
14054 "that does not match the framebuffer for the active "
14055 "renderpass.");
Tony Barbour1fa09702017-03-16 12:09:08 -060014056 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis4af23302016-07-19 10:50:30 -060014057 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14058
14059 // A renderpass with one color attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014060 VkAttachmentDescription attachment = {0,
14061 VK_FORMAT_B8G8R8A8_UNORM,
14062 VK_SAMPLE_COUNT_1_BIT,
14063 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
14064 VK_ATTACHMENT_STORE_OP_STORE,
14065 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
14066 VK_ATTACHMENT_STORE_OP_DONT_CARE,
14067 VK_IMAGE_LAYOUT_UNDEFINED,
14068 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060014069
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014070 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060014071
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014072 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060014073
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014074 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060014075
14076 VkRenderPass rp;
14077 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
14078 ASSERT_VK_SUCCESS(err);
14079
14080 // A compatible framebuffer.
14081 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060014082 image.Init(32, 32, 1, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Tobin Ehlis4af23302016-07-19 10:50:30 -060014083 ASSERT_TRUE(image.initialized());
14084
14085 VkImageViewCreateInfo ivci = {
14086 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
14087 nullptr,
14088 0,
14089 image.handle(),
14090 VK_IMAGE_VIEW_TYPE_2D,
14091 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014092 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
14093 VK_COMPONENT_SWIZZLE_IDENTITY},
Tobin Ehlis4af23302016-07-19 10:50:30 -060014094 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
14095 };
14096 VkImageView view;
14097 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
14098 ASSERT_VK_SUCCESS(err);
14099
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014100 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Tobin Ehlis4af23302016-07-19 10:50:30 -060014101 VkFramebuffer fb;
14102 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
14103 ASSERT_VK_SUCCESS(err);
14104
14105 VkCommandBufferAllocateInfo cbai = {};
14106 cbai.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mike Schuchardt06304c22017-03-01 17:09:09 -070014107 cbai.commandPool = m_commandPool->handle();
Tobin Ehlis4af23302016-07-19 10:50:30 -060014108 cbai.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
14109 cbai.commandBufferCount = 1;
14110
14111 VkCommandBuffer sec_cb;
14112 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &sec_cb);
14113 ASSERT_VK_SUCCESS(err);
14114 VkCommandBufferBeginInfo cbbi = {};
14115 VkCommandBufferInheritanceInfo cbii = {};
Chris Forbes98420382016-11-28 17:56:51 +130014116 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Tobin Ehlis4af23302016-07-19 10:50:30 -060014117 cbii.renderPass = renderPass();
14118 cbii.framebuffer = fb;
14119 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
14120 cbbi.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014121 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 -060014122 cbbi.pInheritanceInfo = &cbii;
14123 vkBeginCommandBuffer(sec_cb, &cbbi);
14124 vkEndCommandBuffer(sec_cb);
14125
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014126 VkCommandBufferBeginInfo cbbi2 = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, 0, nullptr};
Chris Forbes3400bc52016-09-13 18:10:34 +120014127 vkBeginCommandBuffer(m_commandBuffer->GetBufferHandle(), &cbbi2);
14128 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Tobin Ehlis4af23302016-07-19 10:50:30 -060014129
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014130 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060014131 " that is not the same as the primary command buffer's current active framebuffer ");
Tobin Ehlis4af23302016-07-19 10:50:30 -060014132 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &sec_cb);
14133 m_errorMonitor->VerifyFound();
14134 // Cleanup
14135 vkDestroyImageView(m_device->device(), view, NULL);
14136 vkDestroyRenderPass(m_device->device(), rp, NULL);
14137 vkDestroyFramebuffer(m_device->device(), fb, NULL);
14138}
Tobin Ehlis52b504f2016-07-19 13:25:12 -060014139
14140TEST_F(VkLayerTest, ColorBlendLogicOpTests) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014141 TEST_DESCRIPTION(
14142 "If logicOp is available on the device, set it to an "
14143 "invalid value. If logicOp is not available, attempt to "
14144 "use it and verify that we see the correct error.");
Tony Barbour1fa09702017-03-16 12:09:08 -060014145 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis52b504f2016-07-19 13:25:12 -060014146 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14147
14148 auto features = m_device->phy().features();
14149 // Set the expected error depending on whether or not logicOp available
14150 if (VK_FALSE == features.logicOp) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014151 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14152 "If logic operations feature not "
14153 "enabled, logicOpEnable must be "
14154 "VK_FALSE");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060014155 } else {
Chris Forbes34797bc2016-10-03 15:28:49 +130014156 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "pColorBlendState->logicOp (16)");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060014157 }
14158 // Create a pipeline using logicOp
14159 VkResult err;
14160
14161 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
14162 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
14163
14164 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014165 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060014166 ASSERT_VK_SUCCESS(err);
14167
14168 VkPipelineViewportStateCreateInfo vp_state_ci = {};
14169 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
14170 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014171 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060014172 vp_state_ci.pViewports = &vp;
14173 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014174 VkRect2D scissors = {}; // Dummy scissors to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060014175 vp_state_ci.pScissors = &scissors;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060014176
14177 VkPipelineShaderStageCreateInfo shaderStages[2];
14178 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
14179
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014180 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
14181 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060014182 shaderStages[0] = vs.GetStageCreateInfo();
14183 shaderStages[1] = fs.GetStageCreateInfo();
14184
14185 VkPipelineVertexInputStateCreateInfo vi_ci = {};
14186 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
14187
14188 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
14189 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
14190 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
14191
14192 VkPipelineRasterizationStateCreateInfo rs_ci = {};
14193 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbes14088512016-10-03 14:28:00 +130014194 rs_ci.lineWidth = 1.0f;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060014195
14196 VkPipelineColorBlendAttachmentState att = {};
14197 att.blendEnable = VK_FALSE;
14198 att.colorWriteMask = 0xf;
14199
14200 VkPipelineColorBlendStateCreateInfo cb_ci = {};
14201 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
14202 // Enable logicOp & set logicOp to value 1 beyond allowed entries
14203 cb_ci.logicOpEnable = VK_TRUE;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014204 cb_ci.logicOp = VK_LOGIC_OP_RANGE_SIZE; // This should cause an error
Tobin Ehlis52b504f2016-07-19 13:25:12 -060014205 cb_ci.attachmentCount = 1;
14206 cb_ci.pAttachments = &att;
14207
Chris Forbes8aeacbf2016-10-03 14:25:08 +130014208 VkPipelineMultisampleStateCreateInfo ms_ci = {};
14209 ms_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
14210 ms_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
14211
Tobin Ehlis52b504f2016-07-19 13:25:12 -060014212 VkGraphicsPipelineCreateInfo gp_ci = {};
14213 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
14214 gp_ci.stageCount = 2;
14215 gp_ci.pStages = shaderStages;
14216 gp_ci.pVertexInputState = &vi_ci;
14217 gp_ci.pInputAssemblyState = &ia_ci;
14218 gp_ci.pViewportState = &vp_state_ci;
14219 gp_ci.pRasterizationState = &rs_ci;
14220 gp_ci.pColorBlendState = &cb_ci;
Chris Forbes8aeacbf2016-10-03 14:25:08 +130014221 gp_ci.pMultisampleState = &ms_ci;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060014222 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
14223 gp_ci.layout = pipeline_layout;
14224 gp_ci.renderPass = renderPass();
14225
14226 VkPipelineCacheCreateInfo pc_ci = {};
14227 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
14228
14229 VkPipeline pipeline;
14230 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014231 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060014232 ASSERT_VK_SUCCESS(err);
14233
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014234 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060014235 m_errorMonitor->VerifyFound();
14236 if (VK_SUCCESS == err) {
14237 vkDestroyPipeline(m_device->device(), pipeline, NULL);
14238 }
Tobin Ehlis52b504f2016-07-19 13:25:12 -060014239 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
14240 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
14241}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060014242
Mike Stroyanaccf7692015-05-12 16:00:45 -060014243#if GTEST_IS_THREADSAFE
14244struct thread_data_struct {
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014245 VkCommandBuffer commandBuffer;
Mike Stroyanca855662017-05-02 11:06:27 -060014246 VkDevice device;
Mike Stroyanaccf7692015-05-12 16:00:45 -060014247 VkEvent event;
14248 bool bailout;
14249};
14250
Karl Schultz6addd812016-02-02 17:17:23 -070014251extern "C" void *AddToCommandBuffer(void *arg) {
14252 struct thread_data_struct *data = (struct thread_data_struct *)arg;
Mike Stroyanaccf7692015-05-12 16:00:45 -060014253
Mike Stroyana6d14942016-07-13 15:10:05 -060014254 for (int i = 0; i < 80000; i++) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014255 vkCmdSetEvent(data->commandBuffer, data->event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mike Stroyanaccf7692015-05-12 16:00:45 -060014256 if (data->bailout) {
14257 break;
14258 }
14259 }
14260 return NULL;
14261}
14262
Karl Schultz6addd812016-02-02 17:17:23 -070014263TEST_F(VkLayerTest, ThreadCommandBufferCollision) {
Mike Stroyan4268d1f2015-07-13 14:45:35 -060014264 test_platform_thread thread;
Mike Stroyanaccf7692015-05-12 16:00:45 -060014265
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014266 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "THREADING ERROR");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014267
Tony Barbour1fa09702017-03-16 12:09:08 -060014268 ASSERT_NO_FATAL_FAILURE(Init());
Mike Stroyanaccf7692015-05-12 16:00:45 -060014269 ASSERT_NO_FATAL_FAILURE(InitViewport());
14270 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14271
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014272 // Calls AllocateCommandBuffers
14273 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060014274
14275 // Avoid creating RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014276 commandBuffer.BeginCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060014277
14278 VkEventCreateInfo event_info;
14279 VkEvent event;
Mike Stroyanaccf7692015-05-12 16:00:45 -060014280 VkResult err;
14281
14282 memset(&event_info, 0, sizeof(event_info));
14283 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
14284
Chia-I Wuf7458c52015-10-26 21:10:41 +080014285 err = vkCreateEvent(device(), &event_info, NULL, &event);
Mike Stroyanaccf7692015-05-12 16:00:45 -060014286 ASSERT_VK_SUCCESS(err);
14287
Mike Stroyanaccf7692015-05-12 16:00:45 -060014288 err = vkResetEvent(device(), event);
14289 ASSERT_VK_SUCCESS(err);
14290
14291 struct thread_data_struct data;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014292 data.commandBuffer = commandBuffer.GetBufferHandle();
Mike Stroyanaccf7692015-05-12 16:00:45 -060014293 data.event = event;
14294 data.bailout = false;
14295 m_errorMonitor->SetBailout(&data.bailout);
Mike Stroyana6d14942016-07-13 15:10:05 -060014296
14297 // First do some correct operations using multiple threads.
14298 // Add many entries to command buffer from another thread.
14299 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
14300 // Make non-conflicting calls from this thread at the same time.
14301 for (int i = 0; i < 80000; i++) {
Mike Stroyand6343902016-07-14 08:56:16 -060014302 uint32_t count;
14303 vkEnumeratePhysicalDevices(instance(), &count, NULL);
Mike Stroyana6d14942016-07-13 15:10:05 -060014304 }
14305 test_platform_thread_join(thread, NULL);
14306
14307 // Then do some incorrect operations using multiple threads.
Mike Stroyanaccf7692015-05-12 16:00:45 -060014308 // Add many entries to command buffer from another thread.
Mike Stroyan4268d1f2015-07-13 14:45:35 -060014309 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyanaccf7692015-05-12 16:00:45 -060014310 // Add many entries to command buffer from this thread at the same time.
14311 AddToCommandBuffer(&data);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060014312
Mike Stroyan4268d1f2015-07-13 14:45:35 -060014313 test_platform_thread_join(thread, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014314 commandBuffer.EndCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060014315
Mike Stroyan10b8cb72016-01-22 15:22:03 -070014316 m_errorMonitor->SetBailout(NULL);
14317
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014318 m_errorMonitor->VerifyFound();
Mike Stroyanaccf7692015-05-12 16:00:45 -060014319
Chia-I Wuf7458c52015-10-26 21:10:41 +080014320 vkDestroyEvent(device(), event, NULL);
Mike Stroyanaccf7692015-05-12 16:00:45 -060014321}
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014322#endif // GTEST_IS_THREADSAFE
Mark Lobodzinski209b5292015-09-17 09:44:05 -060014323
Karl Schultz6addd812016-02-02 17:17:23 -070014324TEST_F(VkLayerTest, InvalidSPIRVCodeSize) {
Mark Lobodzinskid742b312017-05-09 16:26:27 -060014325 TEST_DESCRIPTION("Test that errors are produced for a spirv modules with invalid code sizes");
Chris Forbes1cc79542016-07-20 11:13:44 +120014326
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014327 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014328
Tony Barbour1fa09702017-03-16 12:09:08 -060014329 ASSERT_NO_FATAL_FAILURE(Init());
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014330 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14331
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014332 VkShaderModule module;
14333 VkShaderModuleCreateInfo moduleCreateInfo;
14334 struct icd_spv_header spv;
14335
14336 spv.magic = ICD_SPV_MAGIC;
14337 spv.version = ICD_SPV_VERSION;
14338 spv.gen_magic = 0;
14339
14340 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
14341 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070014342 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014343 moduleCreateInfo.codeSize = 4;
14344 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080014345 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014346
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014347 m_errorMonitor->VerifyFound();
Mark Lobodzinskid742b312017-05-09 16:26:27 -060014348
14349 char const *vsSource =
14350 "#version 450\n"
14351 "\n"
14352 "layout(location=0) out float x;\n"
14353 "out gl_PerVertex {\n"
14354 " vec4 gl_Position;\n"
14355 "};\n"
14356 "void main(){\n"
14357 " gl_Position = vec4(1);\n"
14358 " x = 0;\n"
14359 "}\n";
14360
14361 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02816);
14362 std::vector<unsigned int> shader;
14363 VkShaderModuleCreateInfo module_create_info;
14364 VkShaderModule shader_module;
14365 module_create_info.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
14366 module_create_info.pNext = NULL;
14367 this->GLSLtoSPV(VK_SHADER_STAGE_VERTEX_BIT, vsSource, shader);
14368 module_create_info.pCode = shader.data();
14369 // Introduce failure by making codeSize a non-multiple of 4
14370 module_create_info.codeSize = shader.size() * sizeof(unsigned int) - 1;
14371 module_create_info.flags = 0;
14372 vkCreateShaderModule(m_device->handle(), &module_create_info, NULL, &shader_module);
14373
14374 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014375}
14376
Karl Schultz6addd812016-02-02 17:17:23 -070014377TEST_F(VkLayerTest, InvalidSPIRVMagic) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014378 TEST_DESCRIPTION(
14379 "Test that an error is produced for a spirv module "
14380 "with a bad magic number");
Chris Forbes1cc79542016-07-20 11:13:44 +120014381
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014382 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V magic number");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014383
Tony Barbour1fa09702017-03-16 12:09:08 -060014384 ASSERT_NO_FATAL_FAILURE(Init());
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014385 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14386
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014387 VkShaderModule module;
14388 VkShaderModuleCreateInfo moduleCreateInfo;
14389 struct icd_spv_header spv;
14390
14391 spv.magic = ~ICD_SPV_MAGIC;
14392 spv.version = ICD_SPV_VERSION;
14393 spv.gen_magic = 0;
14394
14395 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
14396 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070014397 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Mark Lobodzinskid742b312017-05-09 16:26:27 -060014398 moduleCreateInfo.codeSize = sizeof(spv) + 16;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014399 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080014400 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014401
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014402 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014403}
14404
Chris Forbesb4afd0f2016-04-04 10:48:35 +120014405#if 0
14406// Not currently covered by SPIRV-Tools validator
Karl Schultz6addd812016-02-02 17:17:23 -070014407TEST_F(VkLayerTest, InvalidSPIRVVersion) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070014408 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +120014409 "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014410
Tony Barbour1fa09702017-03-16 12:09:08 -060014411 ASSERT_NO_FATAL_FAILURE(Init());
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014412 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14413
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014414 VkShaderModule module;
14415 VkShaderModuleCreateInfo moduleCreateInfo;
14416 struct icd_spv_header spv;
14417
14418 spv.magic = ICD_SPV_MAGIC;
14419 spv.version = ~ICD_SPV_VERSION;
14420 spv.gen_magic = 0;
14421
14422 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
14423 moduleCreateInfo.pNext = NULL;
14424
Karl Schultz6addd812016-02-02 17:17:23 -070014425 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014426 moduleCreateInfo.codeSize = sizeof(spv) + 10;
14427 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080014428 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014429
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014430 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014431}
Chris Forbesb4afd0f2016-04-04 10:48:35 +120014432#endif
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014433
Karl Schultz6addd812016-02-02 17:17:23 -070014434TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014435 TEST_DESCRIPTION(
14436 "Test that a warning is produced for a vertex output that "
14437 "is not consumed by the fragment stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014438 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "not consumed by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014439
Tony Barbour1fa09702017-03-16 12:09:08 -060014440 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014441 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes9f7ff632015-05-25 11:13:08 +120014442
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014443 char const *vsSource =
14444 "#version 450\n"
14445 "\n"
14446 "layout(location=0) out float x;\n"
14447 "out gl_PerVertex {\n"
14448 " vec4 gl_Position;\n"
14449 "};\n"
14450 "void main(){\n"
14451 " gl_Position = vec4(1);\n"
14452 " x = 0;\n"
14453 "}\n";
14454 char const *fsSource =
14455 "#version 450\n"
14456 "\n"
14457 "layout(location=0) out vec4 color;\n"
14458 "void main(){\n"
14459 " color = vec4(1);\n"
14460 "}\n";
Chris Forbes9f7ff632015-05-25 11:13:08 +120014461
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014462 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14463 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes9f7ff632015-05-25 11:13:08 +120014464
14465 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014466 pipe.AddColorAttachment();
Chris Forbes9f7ff632015-05-25 11:13:08 +120014467 pipe.AddShader(&vs);
14468 pipe.AddShader(&fs);
14469
Chris Forbes9f7ff632015-05-25 11:13:08 +120014470 VkDescriptorSetObj descriptorSet(m_device);
14471 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014472 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes9f7ff632015-05-25 11:13:08 +120014473
Tony Barbour5781e8f2015-08-04 16:23:11 -060014474 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes9f7ff632015-05-25 11:13:08 +120014475
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014476 m_errorMonitor->VerifyFound();
Chris Forbes9f7ff632015-05-25 11:13:08 +120014477}
Chris Forbes9f7ff632015-05-25 11:13:08 +120014478
Mark Mueller098c9cb2016-09-08 09:01:57 -060014479TEST_F(VkLayerTest, CreatePipelineCheckShaderBadSpecialization) {
14480 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
14481
Tony Barbour1fa09702017-03-16 12:09:08 -060014482 ASSERT_NO_FATAL_FAILURE(Init());
Mark Mueller098c9cb2016-09-08 09:01:57 -060014483 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14484
14485 const char *bad_specialization_message =
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014486 "Specialization entry 0 (for constant id 0) references memory outside provided specialization data ";
Mark Mueller098c9cb2016-09-08 09:01:57 -060014487
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014488 char const *vsSource =
14489 "#version 450\n"
14490 "\n"
14491 "out gl_PerVertex {\n"
14492 " vec4 gl_Position;\n"
14493 "};\n"
14494 "void main(){\n"
14495 " gl_Position = vec4(1);\n"
14496 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060014497
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014498 char const *fsSource =
14499 "#version 450\n"
14500 "\n"
14501 "layout (constant_id = 0) const float r = 0.0f;\n"
14502 "layout(location = 0) out vec4 uFragColor;\n"
14503 "void main(){\n"
14504 " uFragColor = vec4(r,1,0,1);\n"
14505 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060014506
14507 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14508 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14509
14510 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
14511 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
14512
14513 VkPipelineLayout pipeline_layout;
14514 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
14515
14516 VkPipelineViewportStateCreateInfo vp_state_create_info = {};
14517 vp_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
14518 vp_state_create_info.viewportCount = 1;
14519 VkViewport viewport = {};
14520 vp_state_create_info.pViewports = &viewport;
14521 vp_state_create_info.scissorCount = 1;
14522 VkRect2D scissors = {};
14523 vp_state_create_info.pScissors = &scissors;
14524
14525 VkDynamicState scissor_state = VK_DYNAMIC_STATE_SCISSOR;
14526
14527 VkPipelineDynamicStateCreateInfo pipeline_dynamic_state_create_info = {};
14528 pipeline_dynamic_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
14529 pipeline_dynamic_state_create_info.dynamicStateCount = 1;
14530 pipeline_dynamic_state_create_info.pDynamicStates = &scissor_state;
14531
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014532 VkPipelineShaderStageCreateInfo shader_stage_create_info[2] = {vs.GetStageCreateInfo(), fs.GetStageCreateInfo()};
Mark Mueller098c9cb2016-09-08 09:01:57 -060014533
14534 VkPipelineVertexInputStateCreateInfo vertex_input_create_info = {};
14535 vertex_input_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
14536
14537 VkPipelineInputAssemblyStateCreateInfo input_assembly_create_info = {};
14538 input_assembly_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
14539 input_assembly_create_info.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
14540
14541 VkPipelineRasterizationStateCreateInfo rasterization_state_create_info = {};
14542 rasterization_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
14543 rasterization_state_create_info.pNext = nullptr;
14544 rasterization_state_create_info.lineWidth = 1.0f;
14545 rasterization_state_create_info.rasterizerDiscardEnable = true;
14546
14547 VkPipelineColorBlendAttachmentState color_blend_attachment_state = {};
14548 color_blend_attachment_state.blendEnable = VK_FALSE;
14549 color_blend_attachment_state.colorWriteMask = 0xf;
14550
14551 VkPipelineColorBlendStateCreateInfo color_blend_state_create_info = {};
14552 color_blend_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
14553 color_blend_state_create_info.attachmentCount = 1;
14554 color_blend_state_create_info.pAttachments = &color_blend_attachment_state;
14555
14556 VkGraphicsPipelineCreateInfo graphicspipe_create_info = {};
14557 graphicspipe_create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
14558 graphicspipe_create_info.stageCount = 2;
14559 graphicspipe_create_info.pStages = shader_stage_create_info;
14560 graphicspipe_create_info.pVertexInputState = &vertex_input_create_info;
14561 graphicspipe_create_info.pInputAssemblyState = &input_assembly_create_info;
14562 graphicspipe_create_info.pViewportState = &vp_state_create_info;
14563 graphicspipe_create_info.pRasterizationState = &rasterization_state_create_info;
14564 graphicspipe_create_info.pColorBlendState = &color_blend_state_create_info;
14565 graphicspipe_create_info.pDynamicState = &pipeline_dynamic_state_create_info;
14566 graphicspipe_create_info.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
14567 graphicspipe_create_info.layout = pipeline_layout;
14568 graphicspipe_create_info.renderPass = renderPass();
14569
14570 VkPipelineCacheCreateInfo pipeline_cache_create_info = {};
14571 pipeline_cache_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
14572
14573 VkPipelineCache pipelineCache;
14574 ASSERT_VK_SUCCESS(vkCreatePipelineCache(m_device->device(), &pipeline_cache_create_info, nullptr, &pipelineCache));
14575
14576 // This structure maps constant ids to data locations.
14577 const VkSpecializationMapEntry entry =
14578 // id, offset, size
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014579 {0, 4, sizeof(uint32_t)}; // Challenge core validation by using a bogus offset.
Mark Mueller098c9cb2016-09-08 09:01:57 -060014580
14581 uint32_t data = 1;
14582
14583 // Set up the info describing spec map and data
14584 const VkSpecializationInfo specialization_info = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014585 1, &entry, 1 * sizeof(float), &data,
Mark Mueller098c9cb2016-09-08 09:01:57 -060014586 };
14587 shader_stage_create_info[0].pSpecializationInfo = &specialization_info;
14588
14589 VkPipeline pipeline;
14590 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_specialization_message);
14591 vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &graphicspipe_create_info, nullptr, &pipeline);
14592 m_errorMonitor->VerifyFound();
14593
14594 vkDestroyPipelineCache(m_device->device(), pipelineCache, nullptr);
14595 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
14596}
14597
14598TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorTypeMismatch) {
14599 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
14600
Tony Barbour1fa09702017-03-16 12:09:08 -060014601 ASSERT_NO_FATAL_FAILURE(Init());
Mark Mueller098c9cb2016-09-08 09:01:57 -060014602 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14603
14604 const char *descriptor_type_mismatch_message = "Type mismatch on descriptor slot 0.0 (used as type ";
14605
14606 VkDescriptorPoolSize descriptor_pool_type_count[2] = {};
14607 descriptor_pool_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
14608 descriptor_pool_type_count[0].descriptorCount = 1;
14609 descriptor_pool_type_count[1].type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
14610 descriptor_pool_type_count[1].descriptorCount = 1;
14611
14612 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
14613 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
14614 descriptor_pool_create_info.maxSets = 1;
14615 descriptor_pool_create_info.poolSizeCount = 2;
14616 descriptor_pool_create_info.pPoolSizes = descriptor_pool_type_count;
14617 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
14618
14619 VkDescriptorPool descriptorset_pool;
14620 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
14621
14622 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
14623 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
14624 descriptorset_layout_binding.descriptorCount = 1;
14625 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
Cody Northropa6484fd2017-03-10 14:13:49 -070014626 descriptorset_layout_binding.pImmutableSamplers = nullptr;
Mark Mueller098c9cb2016-09-08 09:01:57 -060014627
14628 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
14629 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
14630 descriptorset_layout_create_info.bindingCount = 1;
14631 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
14632
14633 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014634 ASSERT_VK_SUCCESS(
14635 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller098c9cb2016-09-08 09:01:57 -060014636
14637 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
14638 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
14639 descriptorset_allocate_info.descriptorSetCount = 1;
14640 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
14641 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
14642 VkDescriptorSet descriptorset;
14643 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
14644
14645 // Challenge core_validation with a non uniform buffer type.
14646 VkBufferTest storage_buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT);
14647
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014648 char const *vsSource =
14649 "#version 450\n"
14650 "\n"
14651 "layout (std140, set = 0, binding = 0) uniform buf {\n"
14652 " mat4 mvp;\n"
14653 "} ubuf;\n"
14654 "out gl_PerVertex {\n"
14655 " vec4 gl_Position;\n"
14656 "};\n"
14657 "void main(){\n"
14658 " gl_Position = ubuf.mvp * vec4(1);\n"
14659 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060014660
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014661 char const *fsSource =
14662 "#version 450\n"
14663 "\n"
14664 "layout(location = 0) out vec4 uFragColor;\n"
14665 "void main(){\n"
14666 " uFragColor = vec4(0,1,0,1);\n"
14667 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060014668
14669 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14670 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14671
14672 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
14673 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
14674 pipeline_layout_create_info.setLayoutCount = 1;
14675 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
14676
14677 VkPipelineLayout pipeline_layout;
14678 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
14679
14680 VkPipelineObj pipe(m_device);
14681 pipe.AddColorAttachment();
14682 pipe.AddShader(&vs);
14683 pipe.AddShader(&fs);
14684
14685 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_type_mismatch_message);
14686 pipe.CreateVKPipeline(pipeline_layout, renderPass());
14687 m_errorMonitor->VerifyFound();
14688
14689 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
14690 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
14691 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
14692}
14693
14694TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorNotAccessible) {
14695 TEST_DESCRIPTION(
14696 "Create a pipeline in which a descriptor used by a shader stage does not include that stage in its stageFlags.");
14697
Tony Barbour1fa09702017-03-16 12:09:08 -060014698 ASSERT_NO_FATAL_FAILURE(Init());
Mark Mueller098c9cb2016-09-08 09:01:57 -060014699 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14700
14701 const char *descriptor_not_accessible_message = "Shader uses descriptor slot 0.0 (used as type ";
14702
14703 VkDescriptorPoolSize descriptor_pool_type_count = {};
14704 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
14705 descriptor_pool_type_count.descriptorCount = 1;
14706
14707 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
14708 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
14709 descriptor_pool_create_info.maxSets = 1;
14710 descriptor_pool_create_info.poolSizeCount = 1;
14711 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
14712 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
14713
14714 VkDescriptorPool descriptorset_pool;
14715 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
14716
14717 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
14718 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
14719 descriptorset_layout_binding.descriptorCount = 1;
14720 // Intentionally make the uniform buffer inaccessible to the vertex shader to challenge core_validation
14721 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
Cody Northropa6484fd2017-03-10 14:13:49 -070014722 descriptorset_layout_binding.pImmutableSamplers = nullptr;
Mark Mueller098c9cb2016-09-08 09:01:57 -060014723
14724 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
14725 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
14726 descriptorset_layout_create_info.bindingCount = 1;
14727 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
14728
14729 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014730 ASSERT_VK_SUCCESS(
14731 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller098c9cb2016-09-08 09:01:57 -060014732
14733 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
14734 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
14735 descriptorset_allocate_info.descriptorSetCount = 1;
14736 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
14737 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
14738 VkDescriptorSet descriptorset;
14739 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
14740
14741 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
14742
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014743 char const *vsSource =
14744 "#version 450\n"
14745 "\n"
14746 "layout (std140, set = 0, binding = 0) uniform buf {\n"
14747 " mat4 mvp;\n"
14748 "} ubuf;\n"
14749 "out gl_PerVertex {\n"
14750 " vec4 gl_Position;\n"
14751 "};\n"
14752 "void main(){\n"
14753 " gl_Position = ubuf.mvp * vec4(1);\n"
14754 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060014755
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014756 char const *fsSource =
14757 "#version 450\n"
14758 "\n"
14759 "layout(location = 0) out vec4 uFragColor;\n"
14760 "void main(){\n"
14761 " uFragColor = vec4(0,1,0,1);\n"
14762 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060014763
14764 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14765 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14766
14767 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
14768 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
14769 pipeline_layout_create_info.setLayoutCount = 1;
14770 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
14771
14772 VkPipelineLayout pipeline_layout;
14773 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
14774
14775 VkPipelineObj pipe(m_device);
14776 pipe.AddColorAttachment();
14777 pipe.AddShader(&vs);
14778 pipe.AddShader(&fs);
14779
14780 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_not_accessible_message);
14781 pipe.CreateVKPipeline(pipeline_layout, renderPass());
14782 m_errorMonitor->VerifyFound();
14783
14784 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
14785 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
14786 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
14787}
14788
14789TEST_F(VkLayerTest, CreatePipelineCheckShaderPushConstantNotAccessible) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014790 TEST_DESCRIPTION(
14791 "Create a graphics pipleine in which a push constant range containing a push constant block member is not "
14792 "accessible from the current shader stage.");
Mark Mueller098c9cb2016-09-08 09:01:57 -060014793
Tony Barbour1fa09702017-03-16 12:09:08 -060014794 ASSERT_NO_FATAL_FAILURE(Init());
Mark Mueller098c9cb2016-09-08 09:01:57 -060014795 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14796
14797 const char *push_constant_not_accessible_message =
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014798 "Push constant range covering variable starting at offset 0 not accessible from stage VK_SHADER_STAGE_VERTEX_BIT";
Mark Mueller098c9cb2016-09-08 09:01:57 -060014799
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014800 char const *vsSource =
14801 "#version 450\n"
14802 "\n"
14803 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
14804 "out gl_PerVertex {\n"
14805 " vec4 gl_Position;\n"
14806 "};\n"
14807 "void main(){\n"
14808 " gl_Position = vec4(consts.x);\n"
14809 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060014810
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014811 char const *fsSource =
14812 "#version 450\n"
14813 "\n"
14814 "layout(location = 0) out vec4 uFragColor;\n"
14815 "void main(){\n"
14816 " uFragColor = vec4(0,1,0,1);\n"
14817 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060014818
14819 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14820 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14821
14822 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
14823 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
14824
14825 // Set up a push constant range
14826 VkPushConstantRange push_constant_ranges = {};
14827 // Set to the wrong stage to challenge core_validation
14828 push_constant_ranges.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
14829 push_constant_ranges.size = 4;
14830
14831 pipeline_layout_create_info.pPushConstantRanges = &push_constant_ranges;
14832 pipeline_layout_create_info.pushConstantRangeCount = 1;
14833
14834 VkPipelineLayout pipeline_layout;
14835 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
14836
14837 VkPipelineObj pipe(m_device);
14838 pipe.AddColorAttachment();
14839 pipe.AddShader(&vs);
14840 pipe.AddShader(&fs);
14841
14842 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, push_constant_not_accessible_message);
14843 pipe.CreateVKPipeline(pipeline_layout, renderPass());
14844 m_errorMonitor->VerifyFound();
14845
14846 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
14847}
14848
14849TEST_F(VkLayerTest, CreatePipelineCheckShaderNotEnabled) {
14850 TEST_DESCRIPTION(
14851 "Create a graphics pipeline in which a capability declared by the shader requires a feature not enabled on the device.");
14852
Tony Barbour1fa09702017-03-16 12:09:08 -060014853 ASSERT_NO_FATAL_FAILURE(Init());
Mark Mueller098c9cb2016-09-08 09:01:57 -060014854 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14855
14856 const char *feature_not_enabled_message =
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014857 "Shader requires VkPhysicalDeviceFeatures::shaderFloat64 but is not enabled on the device";
Mark Mueller098c9cb2016-09-08 09:01:57 -060014858
14859 // Some awkward steps are required to test with custom device features.
14860 std::vector<const char *> device_extension_names;
14861 auto features = m_device->phy().features();
14862 // Disable support for 64 bit floats
14863 features.shaderFloat64 = false;
14864 // The sacrificial device object
14865 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
14866
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014867 char const *vsSource =
14868 "#version 450\n"
14869 "\n"
14870 "out gl_PerVertex {\n"
14871 " vec4 gl_Position;\n"
14872 "};\n"
14873 "void main(){\n"
14874 " gl_Position = vec4(1);\n"
14875 "}\n";
14876 char const *fsSource =
14877 "#version 450\n"
14878 "\n"
14879 "layout(location=0) out vec4 color;\n"
14880 "void main(){\n"
14881 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
14882 " color = vec4(green);\n"
14883 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060014884
14885 VkShaderObj vs(&test_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14886 VkShaderObj fs(&test_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14887
14888 VkRenderpassObj render_pass(&test_device);
Mark Mueller098c9cb2016-09-08 09:01:57 -060014889
14890 VkPipelineObj pipe(&test_device);
14891 pipe.AddColorAttachment();
14892 pipe.AddShader(&vs);
14893 pipe.AddShader(&fs);
14894
14895 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
14896 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
14897 VkPipelineLayout pipeline_layout;
14898 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(test_device.device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
14899
14900 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, feature_not_enabled_message);
14901 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
14902 m_errorMonitor->VerifyFound();
14903
14904 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, nullptr);
14905}
14906
Mark Lobodzinski20832822017-03-24 14:49:45 -060014907TEST_F(VkLayerTest, CreateShaderModuleCheckBadCapability) {
14908 TEST_DESCRIPTION("Create a shader in which a capability declared by the shader is not supported.");
14909 // Note that this failure message comes from spirv-tools, specifically the validator.
Mark Mueller098c9cb2016-09-08 09:01:57 -060014910
Tony Barbour1fa09702017-03-16 12:09:08 -060014911 ASSERT_NO_FATAL_FAILURE(Init());
Mark Mueller098c9cb2016-09-08 09:01:57 -060014912 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14913
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014914 char const *vsSource =
14915 "#version 450\n"
14916 "\n"
14917 "out gl_PerVertex {\n"
14918 " vec4 gl_Position;\n"
14919 "};\n"
14920 "layout(xfb_buffer = 1) out;"
14921 "void main(){\n"
14922 " gl_Position = vec4(1);\n"
14923 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060014924
Mark Lobodzinski20832822017-03-24 14:49:45 -060014925 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Capability value 53 is not allowed by Vulkan");
Mark Mueller098c9cb2016-09-08 09:01:57 -060014926
Mark Lobodzinski20832822017-03-24 14:49:45 -060014927 std::vector<unsigned int> spv;
14928 VkShaderModuleCreateInfo module_create_info;
14929 VkShaderModule shader_module;
14930 module_create_info.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
14931 module_create_info.pNext = NULL;
14932 this->GLSLtoSPV(VK_SHADER_STAGE_VERTEX_BIT, vsSource, spv);
14933 module_create_info.pCode = spv.data();
14934 module_create_info.codeSize = spv.size() * sizeof(unsigned int);
14935 module_create_info.flags = 0;
Mark Mueller098c9cb2016-09-08 09:01:57 -060014936
Mark Lobodzinski20832822017-03-24 14:49:45 -060014937 vkCreateShaderModule(m_device->handle(), &module_create_info, NULL, &shader_module);
Mark Mueller098c9cb2016-09-08 09:01:57 -060014938
Mark Lobodzinski20832822017-03-24 14:49:45 -060014939 m_errorMonitor->VerifyFound();
Mark Mueller098c9cb2016-09-08 09:01:57 -060014940}
14941
Karl Schultz6addd812016-02-02 17:17:23 -070014942TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014943 TEST_DESCRIPTION(
14944 "Test that an error is produced for a fragment shader input "
14945 "which is not present in the outputs of the previous stage");
Chris Forbes1cc79542016-07-20 11:13:44 +120014946
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014947 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014948
Tony Barbour1fa09702017-03-16 12:09:08 -060014949 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014950 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes59cb88d2015-05-25 11:13:13 +120014951
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014952 char const *vsSource =
14953 "#version 450\n"
14954 "\n"
14955 "out gl_PerVertex {\n"
14956 " vec4 gl_Position;\n"
14957 "};\n"
14958 "void main(){\n"
14959 " gl_Position = vec4(1);\n"
14960 "}\n";
14961 char const *fsSource =
14962 "#version 450\n"
14963 "\n"
14964 "layout(location=0) in float x;\n"
14965 "layout(location=0) out vec4 color;\n"
14966 "void main(){\n"
14967 " color = vec4(x);\n"
14968 "}\n";
Chris Forbes59cb88d2015-05-25 11:13:13 +120014969
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014970 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14971 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes59cb88d2015-05-25 11:13:13 +120014972
14973 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014974 pipe.AddColorAttachment();
Chris Forbes59cb88d2015-05-25 11:13:13 +120014975 pipe.AddShader(&vs);
14976 pipe.AddShader(&fs);
14977
Chris Forbes59cb88d2015-05-25 11:13:13 +120014978 VkDescriptorSetObj descriptorSet(m_device);
14979 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014980 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes59cb88d2015-05-25 11:13:13 +120014981
Tony Barbour5781e8f2015-08-04 16:23:11 -060014982 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes59cb88d2015-05-25 11:13:13 +120014983
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014984 m_errorMonitor->VerifyFound();
Chris Forbes59cb88d2015-05-25 11:13:13 +120014985}
14986
Karl Schultz6addd812016-02-02 17:17:23 -070014987TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvidedInBlock) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014988 TEST_DESCRIPTION(
14989 "Test that an error is produced for a fragment shader input "
14990 "within an interace block, which is not present in the outputs "
14991 "of the previous stage.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014992 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Chris Forbesa3e85f62016-01-15 14:53:11 +130014993
Tony Barbour1fa09702017-03-16 12:09:08 -060014994 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbesa3e85f62016-01-15 14:53:11 +130014995 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14996
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014997 char const *vsSource =
14998 "#version 450\n"
14999 "\n"
15000 "out gl_PerVertex {\n"
15001 " vec4 gl_Position;\n"
15002 "};\n"
15003 "void main(){\n"
15004 " gl_Position = vec4(1);\n"
15005 "}\n";
15006 char const *fsSource =
15007 "#version 450\n"
15008 "\n"
15009 "in block { layout(location=0) float x; } ins;\n"
15010 "layout(location=0) out vec4 color;\n"
15011 "void main(){\n"
15012 " color = vec4(ins.x);\n"
15013 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130015014
15015 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15016 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15017
15018 VkPipelineObj pipe(m_device);
15019 pipe.AddColorAttachment();
15020 pipe.AddShader(&vs);
15021 pipe.AddShader(&fs);
15022
15023 VkDescriptorSetObj descriptorSet(m_device);
15024 descriptorSet.AppendDummy();
15025 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15026
15027 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15028
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015029 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130015030}
15031
Karl Schultz6addd812016-02-02 17:17:23 -070015032TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchArraySize) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015033 TEST_DESCRIPTION(
15034 "Test that an error is produced for mismatched array sizes "
15035 "across the vertex->fragment shader interface");
15036 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15037 "Type mismatch on location 0.0: 'ptr to "
15038 "output arr[2] of float32' vs 'ptr to "
15039 "input arr[1] of float32'");
Chris Forbes0036fd12016-01-26 14:19:49 +130015040
Tony Barbour1fa09702017-03-16 12:09:08 -060015041 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes0036fd12016-01-26 14:19:49 +130015042 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15043
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015044 char const *vsSource =
15045 "#version 450\n"
15046 "\n"
15047 "layout(location=0) out float x[2];\n"
15048 "out gl_PerVertex {\n"
15049 " vec4 gl_Position;\n"
15050 "};\n"
15051 "void main(){\n"
15052 " x[0] = 0; x[1] = 0;\n"
15053 " gl_Position = vec4(1);\n"
15054 "}\n";
15055 char const *fsSource =
15056 "#version 450\n"
15057 "\n"
15058 "layout(location=0) in float x[1];\n"
15059 "layout(location=0) out vec4 color;\n"
15060 "void main(){\n"
15061 " color = vec4(x[0]);\n"
15062 "}\n";
Chris Forbes0036fd12016-01-26 14:19:49 +130015063
15064 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15065 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15066
15067 VkPipelineObj pipe(m_device);
15068 pipe.AddColorAttachment();
15069 pipe.AddShader(&vs);
15070 pipe.AddShader(&fs);
15071
15072 VkDescriptorSetObj descriptorSet(m_device);
15073 descriptorSet.AppendDummy();
15074 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15075
15076 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15077
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015078 m_errorMonitor->VerifyFound();
Chris Forbes0036fd12016-01-26 14:19:49 +130015079}
15080
Karl Schultz6addd812016-02-02 17:17:23 -070015081TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015082 TEST_DESCRIPTION(
15083 "Test that an error is produced for mismatched types across "
15084 "the vertex->fragment shader interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015085 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015086
Tony Barbour1fa09702017-03-16 12:09:08 -060015087 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060015088 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesb56af562015-05-25 11:13:17 +120015089
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015090 char const *vsSource =
15091 "#version 450\n"
15092 "\n"
15093 "layout(location=0) out int x;\n"
15094 "out gl_PerVertex {\n"
15095 " vec4 gl_Position;\n"
15096 "};\n"
15097 "void main(){\n"
15098 " x = 0;\n"
15099 " gl_Position = vec4(1);\n"
15100 "}\n";
15101 char const *fsSource =
15102 "#version 450\n"
15103 "\n"
15104 "layout(location=0) in float x;\n" /* VS writes int */
15105 "layout(location=0) out vec4 color;\n"
15106 "void main(){\n"
15107 " color = vec4(x);\n"
15108 "}\n";
Chris Forbesb56af562015-05-25 11:13:17 +120015109
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060015110 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15111 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesb56af562015-05-25 11:13:17 +120015112
15113 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080015114 pipe.AddColorAttachment();
Chris Forbesb56af562015-05-25 11:13:17 +120015115 pipe.AddShader(&vs);
15116 pipe.AddShader(&fs);
15117
Chris Forbesb56af562015-05-25 11:13:17 +120015118 VkDescriptorSetObj descriptorSet(m_device);
15119 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015120 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesb56af562015-05-25 11:13:17 +120015121
Tony Barbour5781e8f2015-08-04 16:23:11 -060015122 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesb56af562015-05-25 11:13:17 +120015123
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015124 m_errorMonitor->VerifyFound();
Chris Forbesb56af562015-05-25 11:13:17 +120015125}
15126
Karl Schultz6addd812016-02-02 17:17:23 -070015127TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchInBlock) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015128 TEST_DESCRIPTION(
15129 "Test that an error is produced for mismatched types across "
15130 "the vertex->fragment shader interface, when the variable is contained within "
15131 "an interface block");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015132 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Chris Forbesa3e85f62016-01-15 14:53:11 +130015133
Tony Barbour1fa09702017-03-16 12:09:08 -060015134 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbesa3e85f62016-01-15 14:53:11 +130015135 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15136
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015137 char const *vsSource =
15138 "#version 450\n"
15139 "\n"
15140 "out block { layout(location=0) int x; } outs;\n"
15141 "out gl_PerVertex {\n"
15142 " vec4 gl_Position;\n"
15143 "};\n"
15144 "void main(){\n"
15145 " outs.x = 0;\n"
15146 " gl_Position = vec4(1);\n"
15147 "}\n";
15148 char const *fsSource =
15149 "#version 450\n"
15150 "\n"
15151 "in block { layout(location=0) float x; } ins;\n" /* VS writes int */
15152 "layout(location=0) out vec4 color;\n"
15153 "void main(){\n"
15154 " color = vec4(ins.x);\n"
15155 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130015156
15157 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15158 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15159
15160 VkPipelineObj pipe(m_device);
15161 pipe.AddColorAttachment();
15162 pipe.AddShader(&vs);
15163 pipe.AddShader(&fs);
15164
15165 VkDescriptorSetObj descriptorSet(m_device);
15166 descriptorSet.AppendDummy();
15167 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15168
15169 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15170
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015171 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130015172}
15173
15174TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByLocation) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015175 TEST_DESCRIPTION(
15176 "Test that an error is produced for location mismatches across "
15177 "the vertex->fragment shader interface; This should manifest as a not-written/not-consumed "
15178 "pair, but flushes out broken walking of the interfaces");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015179 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 +130015180
Tony Barbour1fa09702017-03-16 12:09:08 -060015181 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbese9928822016-02-17 14:44:52 +130015182 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15183
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015184 char const *vsSource =
15185 "#version 450\n"
15186 "\n"
15187 "out block { layout(location=1) float x; } outs;\n"
15188 "out gl_PerVertex {\n"
15189 " vec4 gl_Position;\n"
15190 "};\n"
15191 "void main(){\n"
15192 " outs.x = 0;\n"
15193 " gl_Position = vec4(1);\n"
15194 "}\n";
15195 char const *fsSource =
15196 "#version 450\n"
15197 "\n"
15198 "in block { layout(location=0) float x; } ins;\n"
15199 "layout(location=0) out vec4 color;\n"
15200 "void main(){\n"
15201 " color = vec4(ins.x);\n"
15202 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130015203
15204 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15205 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15206
15207 VkPipelineObj pipe(m_device);
15208 pipe.AddColorAttachment();
15209 pipe.AddShader(&vs);
15210 pipe.AddShader(&fs);
15211
15212 VkDescriptorSetObj descriptorSet(m_device);
15213 descriptorSet.AppendDummy();
15214 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15215
15216 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15217
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015218 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130015219}
15220
15221TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByComponent) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015222 TEST_DESCRIPTION(
15223 "Test that an error is produced for component mismatches across the "
15224 "vertex->fragment shader interface. It's not enough to have the same set of locations in "
15225 "use; matching is defined in terms of spirv variables.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015226 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 +130015227
Tony Barbour1fa09702017-03-16 12:09:08 -060015228 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbese9928822016-02-17 14:44:52 +130015229 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15230
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015231 char const *vsSource =
15232 "#version 450\n"
15233 "\n"
15234 "out block { layout(location=0, component=0) float x; } outs;\n"
15235 "out gl_PerVertex {\n"
15236 " vec4 gl_Position;\n"
15237 "};\n"
15238 "void main(){\n"
15239 " outs.x = 0;\n"
15240 " gl_Position = vec4(1);\n"
15241 "}\n";
15242 char const *fsSource =
15243 "#version 450\n"
15244 "\n"
15245 "in block { layout(location=0, component=1) float x; } ins;\n"
15246 "layout(location=0) out vec4 color;\n"
15247 "void main(){\n"
15248 " color = vec4(ins.x);\n"
15249 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130015250
15251 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15252 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15253
15254 VkPipelineObj pipe(m_device);
15255 pipe.AddColorAttachment();
15256 pipe.AddShader(&vs);
15257 pipe.AddShader(&fs);
15258
15259 VkDescriptorSetObj descriptorSet(m_device);
15260 descriptorSet.AppendDummy();
15261 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15262
15263 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15264
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015265 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130015266}
15267
Chris Forbes1f3b0152016-11-30 12:48:40 +130015268TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByPrecision) {
15269 TEST_DESCRIPTION("Test that the RelaxedPrecision decoration is validated to match");
15270
Tony Barbour1fa09702017-03-16 12:09:08 -060015271 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes1f3b0152016-11-30 12:48:40 +130015272 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15273
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015274 char const *vsSource =
15275 "#version 450\n"
15276 "layout(location=0) out mediump float x;\n"
15277 "void main() { gl_Position = vec4(0); x = 1.0; }\n";
15278 char const *fsSource =
15279 "#version 450\n"
15280 "layout(location=0) in highp float x;\n"
15281 "layout(location=0) out vec4 color;\n"
15282 "void main() { color = vec4(x); }\n";
Chris Forbes1f3b0152016-11-30 12:48:40 +130015283
15284 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15285 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15286
15287 VkPipelineObj pipe(m_device);
15288 pipe.AddColorAttachment();
15289 pipe.AddShader(&vs);
15290 pipe.AddShader(&fs);
15291
15292 VkDescriptorSetObj descriptorSet(m_device);
15293 descriptorSet.AppendDummy();
15294 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15295
15296 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "differ in precision");
15297
15298 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15299
15300 m_errorMonitor->VerifyFound();
15301}
15302
Chris Forbes870a39e2016-11-30 12:55:56 +130015303TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByPrecisionBlock) {
15304 TEST_DESCRIPTION("Test that the RelaxedPrecision decoration is validated to match");
15305
Tony Barbour1fa09702017-03-16 12:09:08 -060015306 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes870a39e2016-11-30 12:55:56 +130015307 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15308
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015309 char const *vsSource =
15310 "#version 450\n"
15311 "out block { layout(location=0) mediump float x; };\n"
15312 "void main() { gl_Position = vec4(0); x = 1.0; }\n";
15313 char const *fsSource =
15314 "#version 450\n"
15315 "in block { layout(location=0) highp float x; };\n"
15316 "layout(location=0) out vec4 color;\n"
15317 "void main() { color = vec4(x); }\n";
Chris Forbes870a39e2016-11-30 12:55:56 +130015318
15319 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15320 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15321
15322 VkPipelineObj pipe(m_device);
15323 pipe.AddColorAttachment();
15324 pipe.AddShader(&vs);
15325 pipe.AddShader(&fs);
15326
15327 VkDescriptorSetObj descriptorSet(m_device);
15328 descriptorSet.AppendDummy();
15329 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15330
15331 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "differ in precision");
15332
15333 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15334
15335 m_errorMonitor->VerifyFound();
15336}
15337
Karl Schultz6addd812016-02-02 17:17:23 -070015338TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015339 TEST_DESCRIPTION(
15340 "Test that a warning is produced for a vertex attribute which is "
15341 "not consumed by the vertex shader");
Mike Weiblencce7ec72016-10-17 19:33:05 -060015342 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015343
Tony Barbour1fa09702017-03-16 12:09:08 -060015344 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060015345 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesde136e02015-05-25 11:13:28 +120015346
15347 VkVertexInputBindingDescription input_binding;
15348 memset(&input_binding, 0, sizeof(input_binding));
15349
15350 VkVertexInputAttributeDescription input_attrib;
15351 memset(&input_attrib, 0, sizeof(input_attrib));
15352 input_attrib.format = VK_FORMAT_R32_SFLOAT;
15353
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015354 char const *vsSource =
15355 "#version 450\n"
15356 "\n"
15357 "out gl_PerVertex {\n"
15358 " vec4 gl_Position;\n"
15359 "};\n"
15360 "void main(){\n"
15361 " gl_Position = vec4(1);\n"
15362 "}\n";
15363 char const *fsSource =
15364 "#version 450\n"
15365 "\n"
15366 "layout(location=0) out vec4 color;\n"
15367 "void main(){\n"
15368 " color = vec4(1);\n"
15369 "}\n";
Chris Forbesde136e02015-05-25 11:13:28 +120015370
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060015371 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15372 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesde136e02015-05-25 11:13:28 +120015373
15374 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080015375 pipe.AddColorAttachment();
Chris Forbesde136e02015-05-25 11:13:28 +120015376 pipe.AddShader(&vs);
15377 pipe.AddShader(&fs);
15378
15379 pipe.AddVertexInputBindings(&input_binding, 1);
15380 pipe.AddVertexInputAttribs(&input_attrib, 1);
15381
Chris Forbesde136e02015-05-25 11:13:28 +120015382 VkDescriptorSetObj descriptorSet(m_device);
15383 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015384 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesde136e02015-05-25 11:13:28 +120015385
Tony Barbour5781e8f2015-08-04 16:23:11 -060015386 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesde136e02015-05-25 11:13:28 +120015387
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015388 m_errorMonitor->VerifyFound();
Chris Forbesde136e02015-05-25 11:13:28 +120015389}
15390
Karl Schultz6addd812016-02-02 17:17:23 -070015391TEST_F(VkLayerTest, CreatePipelineAttribLocationMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015392 TEST_DESCRIPTION(
15393 "Test that a warning is produced for a location mismatch on "
15394 "vertex attributes. This flushes out bad behavior in the interface walker");
Mike Weiblencce7ec72016-10-17 19:33:05 -060015395 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Chris Forbes7d83cd52016-01-15 11:32:03 +130015396
Tony Barbour1fa09702017-03-16 12:09:08 -060015397 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes7d83cd52016-01-15 11:32:03 +130015398 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15399
15400 VkVertexInputBindingDescription input_binding;
15401 memset(&input_binding, 0, sizeof(input_binding));
15402
15403 VkVertexInputAttributeDescription input_attrib;
15404 memset(&input_attrib, 0, sizeof(input_attrib));
15405 input_attrib.format = VK_FORMAT_R32_SFLOAT;
15406
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015407 char const *vsSource =
15408 "#version 450\n"
15409 "\n"
15410 "layout(location=1) in float x;\n"
15411 "out gl_PerVertex {\n"
15412 " vec4 gl_Position;\n"
15413 "};\n"
15414 "void main(){\n"
15415 " gl_Position = vec4(x);\n"
15416 "}\n";
15417 char const *fsSource =
15418 "#version 450\n"
15419 "\n"
15420 "layout(location=0) out vec4 color;\n"
15421 "void main(){\n"
15422 " color = vec4(1);\n"
15423 "}\n";
Chris Forbes7d83cd52016-01-15 11:32:03 +130015424
15425 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15426 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15427
15428 VkPipelineObj pipe(m_device);
15429 pipe.AddColorAttachment();
15430 pipe.AddShader(&vs);
15431 pipe.AddShader(&fs);
15432
15433 pipe.AddVertexInputBindings(&input_binding, 1);
15434 pipe.AddVertexInputAttribs(&input_attrib, 1);
15435
15436 VkDescriptorSetObj descriptorSet(m_device);
15437 descriptorSet.AppendDummy();
15438 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15439
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070015440 m_errorMonitor->SetUnexpectedError("Vertex shader consumes input at location 1 but not provided");
Chris Forbes7d83cd52016-01-15 11:32:03 +130015441 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15442
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015443 m_errorMonitor->VerifyFound();
Chris Forbes7d83cd52016-01-15 11:32:03 +130015444}
15445
Karl Schultz6addd812016-02-02 17:17:23 -070015446TEST_F(VkLayerTest, CreatePipelineAttribNotProvided) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015447 TEST_DESCRIPTION(
15448 "Test that an error is produced for a vertex shader input which is not "
15449 "provided by a vertex attribute");
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070015450 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15451 "Vertex shader consumes input at location 0 but not provided");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015452
Tony Barbour1fa09702017-03-16 12:09:08 -060015453 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060015454 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes62e8e502015-05-25 11:13:29 +120015455
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015456 char const *vsSource =
15457 "#version 450\n"
15458 "\n"
15459 "layout(location=0) in vec4 x;\n" /* not provided */
15460 "out gl_PerVertex {\n"
15461 " vec4 gl_Position;\n"
15462 "};\n"
15463 "void main(){\n"
15464 " gl_Position = x;\n"
15465 "}\n";
15466 char const *fsSource =
15467 "#version 450\n"
15468 "\n"
15469 "layout(location=0) out vec4 color;\n"
15470 "void main(){\n"
15471 " color = vec4(1);\n"
15472 "}\n";
Chris Forbes62e8e502015-05-25 11:13:29 +120015473
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060015474 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15475 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes62e8e502015-05-25 11:13:29 +120015476
15477 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080015478 pipe.AddColorAttachment();
Chris Forbes62e8e502015-05-25 11:13:29 +120015479 pipe.AddShader(&vs);
15480 pipe.AddShader(&fs);
15481
Chris Forbes62e8e502015-05-25 11:13:29 +120015482 VkDescriptorSetObj descriptorSet(m_device);
15483 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015484 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes62e8e502015-05-25 11:13:29 +120015485
Tony Barbour5781e8f2015-08-04 16:23:11 -060015486 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes62e8e502015-05-25 11:13:29 +120015487
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015488 m_errorMonitor->VerifyFound();
Chris Forbes62e8e502015-05-25 11:13:29 +120015489}
15490
Karl Schultz6addd812016-02-02 17:17:23 -070015491TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015492 TEST_DESCRIPTION(
15493 "Test that an error is produced for a mismatch between the "
15494 "fundamental type (float/int/uint) of an attribute and the "
15495 "vertex shader input that consumes it");
Mike Weiblen15bd38e2016-10-03 19:19:41 -060015496 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 -060015497
Tony Barbour1fa09702017-03-16 12:09:08 -060015498 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060015499 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc97d98e2015-05-25 11:13:31 +120015500
15501 VkVertexInputBindingDescription input_binding;
15502 memset(&input_binding, 0, sizeof(input_binding));
15503
15504 VkVertexInputAttributeDescription input_attrib;
15505 memset(&input_attrib, 0, sizeof(input_attrib));
15506 input_attrib.format = VK_FORMAT_R32_SFLOAT;
15507
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015508 char const *vsSource =
15509 "#version 450\n"
15510 "\n"
15511 "layout(location=0) in int x;\n" /* attrib provided float */
15512 "out gl_PerVertex {\n"
15513 " vec4 gl_Position;\n"
15514 "};\n"
15515 "void main(){\n"
15516 " gl_Position = vec4(x);\n"
15517 "}\n";
15518 char const *fsSource =
15519 "#version 450\n"
15520 "\n"
15521 "layout(location=0) out vec4 color;\n"
15522 "void main(){\n"
15523 " color = vec4(1);\n"
15524 "}\n";
Chris Forbesc97d98e2015-05-25 11:13:31 +120015525
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060015526 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15527 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc97d98e2015-05-25 11:13:31 +120015528
15529 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080015530 pipe.AddColorAttachment();
Chris Forbesc97d98e2015-05-25 11:13:31 +120015531 pipe.AddShader(&vs);
15532 pipe.AddShader(&fs);
15533
15534 pipe.AddVertexInputBindings(&input_binding, 1);
15535 pipe.AddVertexInputAttribs(&input_attrib, 1);
15536
Chris Forbesc97d98e2015-05-25 11:13:31 +120015537 VkDescriptorSetObj descriptorSet(m_device);
15538 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015539 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesc97d98e2015-05-25 11:13:31 +120015540
Tony Barbour5781e8f2015-08-04 16:23:11 -060015541 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc97d98e2015-05-25 11:13:31 +120015542
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015543 m_errorMonitor->VerifyFound();
Chris Forbesc97d98e2015-05-25 11:13:31 +120015544}
15545
Chris Forbesc68b43c2016-04-06 11:18:47 +120015546TEST_F(VkLayerTest, CreatePipelineDuplicateStage) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015547 TEST_DESCRIPTION(
15548 "Test that an error is produced for a pipeline containing multiple "
15549 "shaders for the same stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015550 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15551 "Multiple shaders provided for stage VK_SHADER_STAGE_VERTEX_BIT");
Chris Forbesc68b43c2016-04-06 11:18:47 +120015552
Tony Barbour1fa09702017-03-16 12:09:08 -060015553 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbesc68b43c2016-04-06 11:18:47 +120015554 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15555
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015556 char const *vsSource =
15557 "#version 450\n"
15558 "\n"
15559 "out gl_PerVertex {\n"
15560 " vec4 gl_Position;\n"
15561 "};\n"
15562 "void main(){\n"
15563 " gl_Position = vec4(1);\n"
15564 "}\n";
15565 char const *fsSource =
15566 "#version 450\n"
15567 "\n"
15568 "layout(location=0) out vec4 color;\n"
15569 "void main(){\n"
15570 " color = vec4(1);\n"
15571 "}\n";
Chris Forbesc68b43c2016-04-06 11:18:47 +120015572
15573 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15574 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15575
15576 VkPipelineObj pipe(m_device);
15577 pipe.AddColorAttachment();
15578 pipe.AddShader(&vs);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015579 pipe.AddShader(&vs); // intentionally duplicate vertex shader attachment
Chris Forbesc68b43c2016-04-06 11:18:47 +120015580 pipe.AddShader(&fs);
15581
15582 VkDescriptorSetObj descriptorSet(m_device);
15583 descriptorSet.AppendDummy();
15584 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15585
15586 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15587
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015588 m_errorMonitor->VerifyFound();
Chris Forbesc68b43c2016-04-06 11:18:47 +120015589}
15590
Chris Forbes82ff92a2016-09-09 10:50:24 +120015591TEST_F(VkLayerTest, CreatePipelineMissingEntrypoint) {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070015592 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "No entrypoint found named `foo`");
Chris Forbes82ff92a2016-09-09 10:50:24 +120015593
Tony Barbour1fa09702017-03-16 12:09:08 -060015594 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes82ff92a2016-09-09 10:50:24 +120015595 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15596
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015597 char const *vsSource =
15598 "#version 450\n"
15599 "out gl_PerVertex {\n"
15600 " vec4 gl_Position;\n"
15601 "};\n"
15602 "void main(){\n"
15603 " gl_Position = vec4(0);\n"
15604 "}\n";
15605 char const *fsSource =
15606 "#version 450\n"
15607 "\n"
15608 "layout(location=0) out vec4 color;\n"
15609 "void main(){\n"
15610 " color = vec4(1);\n"
15611 "}\n";
Chris Forbes82ff92a2016-09-09 10:50:24 +120015612
15613 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15614 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this, "foo");
15615
15616 VkPipelineObj pipe(m_device);
15617 pipe.AddColorAttachment();
15618 pipe.AddShader(&vs);
15619 pipe.AddShader(&fs);
15620
15621 VkDescriptorSetObj descriptorSet(m_device);
15622 descriptorSet.AppendDummy();
15623 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15624
15625 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15626
15627 m_errorMonitor->VerifyFound();
15628}
15629
Chris Forbesae9d8cd2016-09-13 16:32:57 +120015630TEST_F(VkLayerTest, CreatePipelineDepthStencilRequired) {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070015631 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15632 "pDepthStencilState is NULL when rasterization is enabled and subpass "
15633 "uses a depth/stencil attachment");
Chris Forbesae9d8cd2016-09-13 16:32:57 +120015634
Tony Barbour1fa09702017-03-16 12:09:08 -060015635 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbesae9d8cd2016-09-13 16:32:57 +120015636 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15637
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015638 char const *vsSource =
15639 "#version 450\n"
15640 "void main(){ gl_Position = vec4(0); }\n";
15641 char const *fsSource =
15642 "#version 450\n"
15643 "\n"
15644 "layout(location=0) out vec4 color;\n"
15645 "void main(){\n"
15646 " color = vec4(1);\n"
15647 "}\n";
Chris Forbesae9d8cd2016-09-13 16:32:57 +120015648
15649 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15650 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15651
15652 VkPipelineObj pipe(m_device);
15653 pipe.AddColorAttachment();
15654 pipe.AddShader(&vs);
15655 pipe.AddShader(&fs);
15656
15657 VkDescriptorSetObj descriptorSet(m_device);
15658 descriptorSet.AppendDummy();
15659 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15660
15661 VkAttachmentDescription attachments[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070015662 {
15663 0, VK_FORMAT_B8G8R8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
15664 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_UNDEFINED,
15665 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
Chris Forbesae9d8cd2016-09-13 16:32:57 +120015666 },
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070015667 {
15668 0, VK_FORMAT_D16_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
15669 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_UNDEFINED,
15670 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
Chris Forbesae9d8cd2016-09-13 16:32:57 +120015671 },
15672 };
15673 VkAttachmentReference refs[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070015674 {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL}, {1, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL},
Chris Forbesae9d8cd2016-09-13 16:32:57 +120015675 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070015676 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &refs[0], nullptr, &refs[1], 0, nullptr};
15677 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesae9d8cd2016-09-13 16:32:57 +120015678 VkRenderPass rp;
15679 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
15680 ASSERT_VK_SUCCESS(err);
15681
15682 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), rp);
15683
15684 m_errorMonitor->VerifyFound();
15685
15686 vkDestroyRenderPass(m_device->device(), rp, nullptr);
15687}
15688
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015689TEST_F(VkLayerTest, CreatePipelineTessPatchDecorationMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015690 TEST_DESCRIPTION(
15691 "Test that an error is produced for a variable output from "
15692 "the TCS without the patch decoration, but consumed in the TES "
15693 "with the decoration.");
15694 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15695 "is per-vertex in tessellation control shader stage "
15696 "but per-patch in tessellation evaluation shader stage");
Chris Forbesa0193bc2016-04-04 19:19:47 +120015697
Tony Barbour1fa09702017-03-16 12:09:08 -060015698 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbesa0193bc2016-04-04 19:19:47 +120015699 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15700
Chris Forbesc1e852d2016-04-04 19:26:42 +120015701 if (!m_device->phy().features().tessellationShader) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070015702 printf(" Device does not support tessellation shaders; skipped.\n");
Chris Forbesc1e852d2016-04-04 19:26:42 +120015703 return;
15704 }
15705
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015706 char const *vsSource =
15707 "#version 450\n"
15708 "void main(){}\n";
15709 char const *tcsSource =
15710 "#version 450\n"
15711 "layout(location=0) out int x[];\n"
15712 "layout(vertices=3) out;\n"
15713 "void main(){\n"
15714 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
15715 " gl_TessLevelInner[0] = 1;\n"
15716 " x[gl_InvocationID] = gl_InvocationID;\n"
15717 "}\n";
15718 char const *tesSource =
15719 "#version 450\n"
15720 "layout(triangles, equal_spacing, cw) in;\n"
15721 "layout(location=0) patch in int x;\n"
15722 "out gl_PerVertex { vec4 gl_Position; };\n"
15723 "void main(){\n"
15724 " gl_Position.xyz = gl_TessCoord;\n"
15725 " gl_Position.w = x;\n"
15726 "}\n";
15727 char const *fsSource =
15728 "#version 450\n"
15729 "layout(location=0) out vec4 color;\n"
15730 "void main(){\n"
15731 " color = vec4(1);\n"
15732 "}\n";
Chris Forbesa0193bc2016-04-04 19:19:47 +120015733
15734 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15735 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
15736 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
15737 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15738
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015739 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
15740 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Chris Forbesa0193bc2016-04-04 19:19:47 +120015741
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015742 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Chris Forbesa0193bc2016-04-04 19:19:47 +120015743
15744 VkPipelineObj pipe(m_device);
15745 pipe.SetInputAssembly(&iasci);
15746 pipe.SetTessellation(&tsci);
15747 pipe.AddColorAttachment();
15748 pipe.AddShader(&vs);
15749 pipe.AddShader(&tcs);
15750 pipe.AddShader(&tes);
15751 pipe.AddShader(&fs);
15752
15753 VkDescriptorSetObj descriptorSet(m_device);
15754 descriptorSet.AppendDummy();
15755 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15756
15757 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15758
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015759 m_errorMonitor->VerifyFound();
Chris Forbesa0193bc2016-04-04 19:19:47 +120015760}
15761
Cort Stratton2bcca1b2017-05-05 16:02:35 -070015762TEST_F(VkLayerTest, CreatePipelineTessErrors) {
15763 TEST_DESCRIPTION("Test various errors when creating a graphics pipeline with tessellation stages active.");
15764
15765 ASSERT_NO_FATAL_FAILURE(Init());
15766 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15767
15768 if (!m_device->phy().features().tessellationShader) {
15769 printf(" Device does not support tessellation shaders; skipped.\n");
15770 return;
15771 }
15772
15773 char const *vsSource =
15774 "#version 450\n"
15775 "void main(){}\n";
15776 char const *tcsSource =
15777 "#version 450\n"
15778 "layout(vertices=3) out;\n"
15779 "void main(){\n"
15780 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
15781 " gl_TessLevelInner[0] = 1;\n"
15782 "}\n";
15783 char const *tesSource =
15784 "#version 450\n"
15785 "layout(triangles, equal_spacing, cw) in;\n"
15786 "out gl_PerVertex { vec4 gl_Position; };\n"
15787 "void main(){\n"
15788 " gl_Position.xyz = gl_TessCoord;\n"
15789 " gl_Position.w = 0;\n"
15790 "}\n";
15791 char const *fsSource =
15792 "#version 450\n"
15793 "layout(location=0) out vec4 color;\n"
15794 "void main(){\n"
15795 " color = vec4(1);\n"
15796 "}\n";
15797
15798 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15799 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
15800 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
15801 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15802
15803 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
15804 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
15805
15806 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
15807
15808 VkDescriptorSetObj descriptorSet(m_device);
15809 descriptorSet.AppendDummy();
15810 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15811
15812 {
15813 VkPipelineObj pipe(m_device);
15814 VkPipelineInputAssemblyStateCreateInfo iasci_bad = iasci;
15815 iasci_bad.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST; // otherwise we get a failure about invalid topology
15816 pipe.SetInputAssembly(&iasci_bad);
15817 pipe.AddColorAttachment();
15818 pipe.AddShader(&vs);
15819 pipe.AddShader(&fs);
15820
15821 // Pass a tess control shader without a tess eval shader
15822 pipe.AddShader(&tcs);
15823 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00534);
15824 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15825 m_errorMonitor->VerifyFound();
15826 }
15827
15828 {
15829 VkPipelineObj pipe(m_device);
15830 VkPipelineInputAssemblyStateCreateInfo iasci_bad = iasci;
15831 iasci_bad.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST; // otherwise we get a failure about invalid topology
15832 pipe.SetInputAssembly(&iasci_bad);
15833 pipe.AddColorAttachment();
15834 pipe.AddShader(&vs);
15835 pipe.AddShader(&fs);
15836
15837 // Pass a tess eval shader without a tess control shader
15838 pipe.AddShader(&tes);
15839 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00535);
15840 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15841 m_errorMonitor->VerifyFound();
15842 }
15843
15844 {
15845 VkPipelineObj pipe(m_device);
15846 pipe.SetInputAssembly(&iasci);
15847 pipe.AddColorAttachment();
15848 pipe.AddShader(&vs);
15849 pipe.AddShader(&fs);
15850
15851 // Pass patch topology without tessellation shaders
15852 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02100);
15853 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15854 m_errorMonitor->VerifyFound();
15855
15856 pipe.AddShader(&tcs);
15857 pipe.AddShader(&tes);
15858 // Pass a NULL pTessellationState (with active tessellation shader stages)
15859 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00536);
15860 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15861 m_errorMonitor->VerifyFound();
15862
15863 // Pass an invalid pTessellationState (bad sType)
15864 VkPipelineTessellationStateCreateInfo tsci_bad = tsci;
15865 tsci_bad.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
15866 pipe.SetTessellation(&tsci_bad);
15867 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01427);
15868 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15869 m_errorMonitor->VerifyFound();
15870 // Pass out-of-range patchControlPoints
15871 tsci_bad = tsci;
15872 tsci_bad.patchControlPoints = 0;
15873 pipe.SetTessellation(&tsci);
15874 pipe.SetTessellation(&tsci_bad);
15875 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01426);
15876 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15877 m_errorMonitor->VerifyFound();
15878 tsci_bad.patchControlPoints = m_device->props.limits.maxTessellationPatchSize + 1;
15879 pipe.SetTessellation(&tsci_bad);
15880 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01426);
15881 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15882 m_errorMonitor->VerifyFound();
15883 pipe.SetTessellation(&tsci);
15884
15885 // Pass an invalid primitive topology
15886 VkPipelineInputAssemblyStateCreateInfo iasci_bad = iasci;
15887 iasci_bad.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
15888 pipe.SetInputAssembly(&iasci_bad);
15889 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02099);
15890 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15891 m_errorMonitor->VerifyFound();
15892 pipe.SetInputAssembly(&iasci);
15893 }
15894}
15895
Karl Schultz6addd812016-02-02 17:17:23 -070015896TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015897 TEST_DESCRIPTION(
15898 "Test that an error is produced for a vertex attribute setup where multiple "
15899 "bindings provide the same location");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015900 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15901 "Duplicate vertex input binding descriptions for binding 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015902
Tony Barbour1fa09702017-03-16 12:09:08 -060015903 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060015904 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes280ba2c2015-06-12 11:16:41 +120015905
15906 /* Two binding descriptions for binding 0 */
15907 VkVertexInputBindingDescription input_bindings[2];
15908 memset(input_bindings, 0, sizeof(input_bindings));
15909
15910 VkVertexInputAttributeDescription input_attrib;
15911 memset(&input_attrib, 0, sizeof(input_attrib));
15912 input_attrib.format = VK_FORMAT_R32_SFLOAT;
15913
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015914 char const *vsSource =
15915 "#version 450\n"
15916 "\n"
15917 "layout(location=0) in float x;\n" /* attrib provided float */
15918 "out gl_PerVertex {\n"
15919 " vec4 gl_Position;\n"
15920 "};\n"
15921 "void main(){\n"
15922 " gl_Position = vec4(x);\n"
15923 "}\n";
15924 char const *fsSource =
15925 "#version 450\n"
15926 "\n"
15927 "layout(location=0) out vec4 color;\n"
15928 "void main(){\n"
15929 " color = vec4(1);\n"
15930 "}\n";
Chris Forbes280ba2c2015-06-12 11:16:41 +120015931
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060015932 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15933 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes280ba2c2015-06-12 11:16:41 +120015934
15935 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080015936 pipe.AddColorAttachment();
Chris Forbes280ba2c2015-06-12 11:16:41 +120015937 pipe.AddShader(&vs);
15938 pipe.AddShader(&fs);
15939
15940 pipe.AddVertexInputBindings(input_bindings, 2);
15941 pipe.AddVertexInputAttribs(&input_attrib, 1);
15942
Chris Forbes280ba2c2015-06-12 11:16:41 +120015943 VkDescriptorSetObj descriptorSet(m_device);
15944 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015945 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes280ba2c2015-06-12 11:16:41 +120015946
Tony Barbour5781e8f2015-08-04 16:23:11 -060015947 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes280ba2c2015-06-12 11:16:41 +120015948
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015949 m_errorMonitor->VerifyFound();
Chris Forbes280ba2c2015-06-12 11:16:41 +120015950}
Chris Forbes8f68b562015-05-25 11:13:32 +120015951
Karl Schultz6addd812016-02-02 17:17:23 -070015952TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015953 TEST_DESCRIPTION(
15954 "Test that an error is produced for a fragment shader which does not "
15955 "provide an output for one of the pipeline's color attachments");
Mike Weiblencce7ec72016-10-17 19:33:05 -060015956 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attachment 0 not written by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015957
Tony Barbour1fa09702017-03-16 12:09:08 -060015958 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120015959
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015960 char const *vsSource =
15961 "#version 450\n"
15962 "\n"
15963 "out gl_PerVertex {\n"
15964 " vec4 gl_Position;\n"
15965 "};\n"
15966 "void main(){\n"
15967 " gl_Position = vec4(1);\n"
15968 "}\n";
15969 char const *fsSource =
15970 "#version 450\n"
15971 "\n"
15972 "void main(){\n"
15973 "}\n";
Chris Forbes4d6d1e52015-05-25 11:13:40 +120015974
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060015975 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15976 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120015977
15978 VkPipelineObj pipe(m_device);
15979 pipe.AddShader(&vs);
15980 pipe.AddShader(&fs);
15981
Chia-I Wu08accc62015-07-07 11:50:03 +080015982 /* set up CB 0, not written */
15983 pipe.AddColorAttachment();
15984 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120015985
Chris Forbes4d6d1e52015-05-25 11:13:40 +120015986 VkDescriptorSetObj descriptorSet(m_device);
15987 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015988 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120015989
Tony Barbour5781e8f2015-08-04 16:23:11 -060015990 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120015991
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015992 m_errorMonitor->VerifyFound();
Chris Forbes4d6d1e52015-05-25 11:13:40 +120015993}
15994
Karl Schultz6addd812016-02-02 17:17:23 -070015995TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015996 TEST_DESCRIPTION(
15997 "Test that a warning is produced for a fragment shader which provides a spurious "
15998 "output with no matching attachment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015999 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060016000 "fragment shader writes to output location 1 with no matching attachment");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016001
Tony Barbour1fa09702017-03-16 12:09:08 -060016002 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120016003
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016004 char const *vsSource =
16005 "#version 450\n"
16006 "\n"
16007 "out gl_PerVertex {\n"
16008 " vec4 gl_Position;\n"
16009 "};\n"
16010 "void main(){\n"
16011 " gl_Position = vec4(1);\n"
16012 "}\n";
16013 char const *fsSource =
16014 "#version 450\n"
16015 "\n"
16016 "layout(location=0) out vec4 x;\n"
16017 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
16018 "void main(){\n"
16019 " x = vec4(1);\n"
16020 " y = vec4(1);\n"
16021 "}\n";
Chris Forbesf3fffaa2015-05-25 11:13:43 +120016022
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060016023 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
16024 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120016025
16026 VkPipelineObj pipe(m_device);
16027 pipe.AddShader(&vs);
16028 pipe.AddShader(&fs);
16029
Chia-I Wu08accc62015-07-07 11:50:03 +080016030 /* set up CB 0, not written */
16031 pipe.AddColorAttachment();
16032 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120016033 /* FS writes CB 1, but we don't configure it */
16034
Chris Forbesf3fffaa2015-05-25 11:13:43 +120016035 VkDescriptorSetObj descriptorSet(m_device);
16036 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016037 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120016038
Tony Barbour5781e8f2015-08-04 16:23:11 -060016039 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120016040
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016041 m_errorMonitor->VerifyFound();
Chris Forbesf3fffaa2015-05-25 11:13:43 +120016042}
16043
Karl Schultz6addd812016-02-02 17:17:23 -070016044TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016045 TEST_DESCRIPTION(
16046 "Test that an error is produced for a mismatch between the fundamental "
16047 "type of an fragment shader output variable, and the format of the corresponding attachment");
Mike Weiblencce7ec72016-10-17 19:33:05 -060016048 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "does not match fragment shader output type");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016049
Tony Barbour1fa09702017-03-16 12:09:08 -060016050 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbesa36d69e2015-05-25 11:13:44 +120016051
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016052 char const *vsSource =
16053 "#version 450\n"
16054 "\n"
16055 "out gl_PerVertex {\n"
16056 " vec4 gl_Position;\n"
16057 "};\n"
16058 "void main(){\n"
16059 " gl_Position = vec4(1);\n"
16060 "}\n";
16061 char const *fsSource =
16062 "#version 450\n"
16063 "\n"
16064 "layout(location=0) out ivec4 x;\n" /* not UNORM */
16065 "void main(){\n"
16066 " x = ivec4(1);\n"
16067 "}\n";
Chris Forbesa36d69e2015-05-25 11:13:44 +120016068
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060016069 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
16070 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa36d69e2015-05-25 11:13:44 +120016071
16072 VkPipelineObj pipe(m_device);
16073 pipe.AddShader(&vs);
16074 pipe.AddShader(&fs);
16075
Chia-I Wu08accc62015-07-07 11:50:03 +080016076 /* set up CB 0; type is UNORM by default */
16077 pipe.AddColorAttachment();
16078 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa36d69e2015-05-25 11:13:44 +120016079
Chris Forbesa36d69e2015-05-25 11:13:44 +120016080 VkDescriptorSetObj descriptorSet(m_device);
16081 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016082 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesa36d69e2015-05-25 11:13:44 +120016083
Tony Barbour5781e8f2015-08-04 16:23:11 -060016084 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa36d69e2015-05-25 11:13:44 +120016085
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016086 m_errorMonitor->VerifyFound();
Chris Forbesa36d69e2015-05-25 11:13:44 +120016087}
Chris Forbes7b1b8932015-06-05 14:43:36 +120016088
Karl Schultz6addd812016-02-02 17:17:23 -070016089TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016090 TEST_DESCRIPTION(
16091 "Test that an error is produced for a shader consuming a uniform "
16092 "block which has no corresponding binding in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016093 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in pipeline layout");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016094
Tony Barbour1fa09702017-03-16 12:09:08 -060016095 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes556c76c2015-08-14 12:04:59 +120016096
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016097 char const *vsSource =
16098 "#version 450\n"
16099 "\n"
16100 "out gl_PerVertex {\n"
16101 " vec4 gl_Position;\n"
16102 "};\n"
16103 "void main(){\n"
16104 " gl_Position = vec4(1);\n"
16105 "}\n";
16106 char const *fsSource =
16107 "#version 450\n"
16108 "\n"
16109 "layout(location=0) out vec4 x;\n"
16110 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
16111 "void main(){\n"
16112 " x = vec4(bar.y);\n"
16113 "}\n";
Chris Forbes556c76c2015-08-14 12:04:59 +120016114
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060016115 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
16116 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes556c76c2015-08-14 12:04:59 +120016117
Chris Forbes556c76c2015-08-14 12:04:59 +120016118 VkPipelineObj pipe(m_device);
16119 pipe.AddShader(&vs);
16120 pipe.AddShader(&fs);
16121
16122 /* set up CB 0; type is UNORM by default */
16123 pipe.AddColorAttachment();
16124 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16125
16126 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016127 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes556c76c2015-08-14 12:04:59 +120016128
16129 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
16130
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016131 m_errorMonitor->VerifyFound();
Chris Forbes556c76c2015-08-14 12:04:59 +120016132}
16133
Chris Forbes5c59e902016-02-26 16:56:09 +130016134TEST_F(VkLayerTest, CreatePipelinePushConstantsNotInLayout) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016135 TEST_DESCRIPTION(
16136 "Test that an error is produced for a shader consuming push constants "
16137 "which are not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016138 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in layout");
Chris Forbes5c59e902016-02-26 16:56:09 +130016139
Tony Barbour1fa09702017-03-16 12:09:08 -060016140 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes5c59e902016-02-26 16:56:09 +130016141
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016142 char const *vsSource =
16143 "#version 450\n"
16144 "\n"
16145 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
16146 "out gl_PerVertex {\n"
16147 " vec4 gl_Position;\n"
16148 "};\n"
16149 "void main(){\n"
16150 " gl_Position = vec4(consts.x);\n"
16151 "}\n";
16152 char const *fsSource =
16153 "#version 450\n"
16154 "\n"
16155 "layout(location=0) out vec4 x;\n"
16156 "void main(){\n"
16157 " x = vec4(1);\n"
16158 "}\n";
Chris Forbes5c59e902016-02-26 16:56:09 +130016159
16160 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
16161 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
16162
16163 VkPipelineObj pipe(m_device);
16164 pipe.AddShader(&vs);
16165 pipe.AddShader(&fs);
16166
16167 /* set up CB 0; type is UNORM by default */
16168 pipe.AddColorAttachment();
16169 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16170
16171 VkDescriptorSetObj descriptorSet(m_device);
16172 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
16173
16174 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
16175
16176 /* should have generated an error -- no push constant ranges provided! */
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016177 m_errorMonitor->VerifyFound();
Chris Forbes5c59e902016-02-26 16:56:09 +130016178}
16179
Chris Forbes3fb17902016-08-22 14:57:55 +120016180TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissing) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016181 TEST_DESCRIPTION(
16182 "Test that an error is produced for a shader consuming an input attachment "
16183 "which is not included in the subpass description");
Chris Forbes3fb17902016-08-22 14:57:55 +120016184 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16185 "consumes input attachment index 0 but not provided in subpass");
16186
Tony Barbour1fa09702017-03-16 12:09:08 -060016187 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes3fb17902016-08-22 14:57:55 +120016188
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016189 char const *vsSource =
16190 "#version 450\n"
16191 "\n"
16192 "out gl_PerVertex {\n"
16193 " vec4 gl_Position;\n"
16194 "};\n"
16195 "void main(){\n"
16196 " gl_Position = vec4(1);\n"
16197 "}\n";
16198 char const *fsSource =
16199 "#version 450\n"
16200 "\n"
16201 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
16202 "layout(location=0) out vec4 color;\n"
16203 "void main() {\n"
16204 " color = subpassLoad(x);\n"
16205 "}\n";
Chris Forbes3fb17902016-08-22 14:57:55 +120016206
16207 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
16208 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
16209
16210 VkPipelineObj pipe(m_device);
16211 pipe.AddShader(&vs);
16212 pipe.AddShader(&fs);
16213 pipe.AddColorAttachment();
16214 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16215
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016216 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
16217 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes3fb17902016-08-22 14:57:55 +120016218 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016219 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes3fb17902016-08-22 14:57:55 +120016220 ASSERT_VK_SUCCESS(err);
16221
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016222 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes3fb17902016-08-22 14:57:55 +120016223 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016224 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes3fb17902016-08-22 14:57:55 +120016225 ASSERT_VK_SUCCESS(err);
16226
16227 // error here.
16228 pipe.CreateVKPipeline(pl, renderPass());
16229
16230 m_errorMonitor->VerifyFound();
16231
16232 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
16233 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
16234}
16235
Chris Forbes5a9a0472016-08-22 16:02:09 +120016236TEST_F(VkLayerTest, CreatePipelineInputAttachmentTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016237 TEST_DESCRIPTION(
16238 "Test that an error is produced for a shader consuming an input attachment "
16239 "with a format having a different fundamental type");
Chris Forbes5a9a0472016-08-22 16:02:09 +120016240 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16241 "input attachment 0 format of VK_FORMAT_R8G8B8A8_UINT does not match");
16242
Tony Barbour1fa09702017-03-16 12:09:08 -060016243 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes5a9a0472016-08-22 16:02:09 +120016244
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016245 char const *vsSource =
16246 "#version 450\n"
16247 "\n"
16248 "out gl_PerVertex {\n"
16249 " vec4 gl_Position;\n"
16250 "};\n"
16251 "void main(){\n"
16252 " gl_Position = vec4(1);\n"
16253 "}\n";
16254 char const *fsSource =
16255 "#version 450\n"
16256 "\n"
16257 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
16258 "layout(location=0) out vec4 color;\n"
16259 "void main() {\n"
16260 " color = subpassLoad(x);\n"
16261 "}\n";
Chris Forbes5a9a0472016-08-22 16:02:09 +120016262
16263 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
16264 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
16265
16266 VkPipelineObj pipe(m_device);
16267 pipe.AddShader(&vs);
16268 pipe.AddShader(&fs);
16269 pipe.AddColorAttachment();
16270 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16271
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016272 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
16273 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes5a9a0472016-08-22 16:02:09 +120016274 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016275 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120016276 ASSERT_VK_SUCCESS(err);
16277
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016278 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120016279 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016280 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120016281 ASSERT_VK_SUCCESS(err);
16282
16283 VkAttachmentDescription descs[2] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016284 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
16285 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
16286 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
16287 {0, VK_FORMAT_R8G8B8A8_UINT, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
16288 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 +120016289 };
16290 VkAttachmentReference color = {
16291 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
16292 };
16293 VkAttachmentReference input = {
16294 1, VK_IMAGE_LAYOUT_GENERAL,
16295 };
16296
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016297 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120016298
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016299 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120016300 VkRenderPass rp;
16301 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
16302 ASSERT_VK_SUCCESS(err);
16303
16304 // error here.
16305 pipe.CreateVKPipeline(pl, rp);
16306
16307 m_errorMonitor->VerifyFound();
16308
16309 vkDestroyRenderPass(m_device->device(), rp, nullptr);
16310 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
16311 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
16312}
16313
Chris Forbes541f7b02016-08-22 15:30:27 +120016314TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissingArray) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016315 TEST_DESCRIPTION(
16316 "Test that an error is produced for a shader consuming an input attachment "
16317 "which is not included in the subpass description -- array case");
Chris Forbes541f7b02016-08-22 15:30:27 +120016318 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Rene Lindsay07b60af2017-01-10 15:57:55 -070016319 "consumes input attachment index 0 but not provided in subpass");
Chris Forbes541f7b02016-08-22 15:30:27 +120016320
Tony Barbour1fa09702017-03-16 12:09:08 -060016321 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes541f7b02016-08-22 15:30:27 +120016322
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016323 char const *vsSource =
16324 "#version 450\n"
16325 "\n"
16326 "out gl_PerVertex {\n"
16327 " vec4 gl_Position;\n"
16328 "};\n"
16329 "void main(){\n"
16330 " gl_Position = vec4(1);\n"
16331 "}\n";
16332 char const *fsSource =
16333 "#version 450\n"
16334 "\n"
16335 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput xs[1];\n"
16336 "layout(location=0) out vec4 color;\n"
16337 "void main() {\n"
16338 " color = subpassLoad(xs[0]);\n"
16339 "}\n";
Chris Forbes541f7b02016-08-22 15:30:27 +120016340
16341 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
16342 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
16343
16344 VkPipelineObj pipe(m_device);
16345 pipe.AddShader(&vs);
16346 pipe.AddShader(&fs);
16347 pipe.AddColorAttachment();
16348 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16349
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016350 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 2, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
16351 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes541f7b02016-08-22 15:30:27 +120016352 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016353 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes541f7b02016-08-22 15:30:27 +120016354 ASSERT_VK_SUCCESS(err);
16355
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016356 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes541f7b02016-08-22 15:30:27 +120016357 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016358 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes541f7b02016-08-22 15:30:27 +120016359 ASSERT_VK_SUCCESS(err);
16360
16361 // error here.
16362 pipe.CreateVKPipeline(pl, renderPass());
16363
16364 m_errorMonitor->VerifyFound();
16365
16366 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
16367 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
16368}
16369
Chris Forbes10eb9ae2016-05-31 16:09:42 +120016370TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptor) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016371 TEST_DESCRIPTION(
16372 "Test that an error is produced for a compute pipeline consuming a "
16373 "descriptor which is not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016374 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Shader uses descriptor slot 0.0");
Chris Forbes10eb9ae2016-05-31 16:09:42 +120016375
Tony Barbour1fa09702017-03-16 12:09:08 -060016376 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes10eb9ae2016-05-31 16:09:42 +120016377
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016378 char const *csSource =
16379 "#version 450\n"
16380 "\n"
16381 "layout(local_size_x=1) in;\n"
16382 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
16383 "void main(){\n"
16384 " x = vec4(1);\n"
16385 "}\n";
Chris Forbes10eb9ae2016-05-31 16:09:42 +120016386
16387 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
16388
16389 VkDescriptorSetObj descriptorSet(m_device);
16390 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
16391
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016392 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
16393 nullptr,
16394 0,
16395 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
16396 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
16397 descriptorSet.GetPipelineLayout(),
16398 VK_NULL_HANDLE,
16399 -1};
Chris Forbes10eb9ae2016-05-31 16:09:42 +120016400
16401 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016402 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes10eb9ae2016-05-31 16:09:42 +120016403
16404 m_errorMonitor->VerifyFound();
16405
16406 if (err == VK_SUCCESS) {
16407 vkDestroyPipeline(m_device->device(), pipe, nullptr);
16408 }
16409}
16410
Chris Forbes22a9b092016-07-19 14:34:05 +120016411TEST_F(VkLayerTest, CreateComputePipelineDescriptorTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016412 TEST_DESCRIPTION(
16413 "Test that an error is produced for a pipeline consuming a "
16414 "descriptor-backed resource of a mismatched type");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016415 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16416 "but descriptor of type VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER");
Chris Forbes22a9b092016-07-19 14:34:05 +120016417
Tony Barbour1fa09702017-03-16 12:09:08 -060016418 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes22a9b092016-07-19 14:34:05 +120016419
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016420 VkDescriptorSetLayoutBinding binding = {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr};
16421 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &binding};
Chris Forbes22a9b092016-07-19 14:34:05 +120016422 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016423 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes22a9b092016-07-19 14:34:05 +120016424 ASSERT_VK_SUCCESS(err);
16425
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016426 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes22a9b092016-07-19 14:34:05 +120016427 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016428 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes22a9b092016-07-19 14:34:05 +120016429 ASSERT_VK_SUCCESS(err);
16430
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016431 char const *csSource =
16432 "#version 450\n"
16433 "\n"
16434 "layout(local_size_x=1) in;\n"
16435 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
16436 "void main() {\n"
16437 " x.x = 1.0f;\n"
16438 "}\n";
Chris Forbes22a9b092016-07-19 14:34:05 +120016439 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
16440
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016441 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
16442 nullptr,
16443 0,
16444 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
16445 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
16446 pl,
16447 VK_NULL_HANDLE,
16448 -1};
Chris Forbes22a9b092016-07-19 14:34:05 +120016449
16450 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016451 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes22a9b092016-07-19 14:34:05 +120016452
16453 m_errorMonitor->VerifyFound();
16454
16455 if (err == VK_SUCCESS) {
16456 vkDestroyPipeline(m_device->device(), pipe, nullptr);
16457 }
16458
16459 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
16460 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
16461}
16462
Chris Forbes50020592016-07-27 13:52:41 +120016463TEST_F(VkLayerTest, DrawTimeImageViewTypeMismatchWithPipeline) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016464 TEST_DESCRIPTION(
16465 "Test that an error is produced when an image view type "
16466 "does not match the dimensionality declared in the shader");
Chris Forbes50020592016-07-27 13:52:41 +120016467
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016468 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 +120016469
Tony Barbour1fa09702017-03-16 12:09:08 -060016470 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes50020592016-07-27 13:52:41 +120016471 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16472
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016473 char const *vsSource =
16474 "#version 450\n"
16475 "\n"
16476 "out gl_PerVertex { vec4 gl_Position; };\n"
16477 "void main() { gl_Position = vec4(0); }\n";
16478 char const *fsSource =
16479 "#version 450\n"
16480 "\n"
16481 "layout(set=0, binding=0) uniform sampler3D s;\n"
16482 "layout(location=0) out vec4 color;\n"
16483 "void main() {\n"
16484 " color = texture(s, vec3(0));\n"
16485 "}\n";
Chris Forbes50020592016-07-27 13:52:41 +120016486 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
16487 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
16488
16489 VkPipelineObj pipe(m_device);
16490 pipe.AddShader(&vs);
16491 pipe.AddShader(&fs);
16492 pipe.AddColorAttachment();
16493
16494 VkTextureObj texture(m_device, nullptr);
16495 VkSamplerObj sampler(m_device);
16496
16497 VkDescriptorSetObj descriptorSet(m_device);
16498 descriptorSet.AppendSamplerTexture(&sampler, &texture);
16499 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
16500
16501 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
16502 ASSERT_VK_SUCCESS(err);
16503
Tony Barbour552f6c02016-12-21 14:34:07 -070016504 m_commandBuffer->BeginCommandBuffer();
16505 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes50020592016-07-27 13:52:41 +120016506
16507 m_commandBuffer->BindPipeline(pipe);
16508 m_commandBuffer->BindDescriptorSet(descriptorSet);
16509
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016510 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes50020592016-07-27 13:52:41 +120016511 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016512 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes50020592016-07-27 13:52:41 +120016513 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16514
16515 // error produced here.
16516 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
16517
16518 m_errorMonitor->VerifyFound();
16519
Tony Barbour552f6c02016-12-21 14:34:07 -070016520 m_commandBuffer->EndRenderPass();
16521 m_commandBuffer->EndCommandBuffer();
Chris Forbes50020592016-07-27 13:52:41 +120016522}
16523
Chris Forbes5533bfc2016-07-27 14:12:34 +120016524TEST_F(VkLayerTest, DrawTimeImageMultisampleMismatchWithPipeline) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016525 TEST_DESCRIPTION(
16526 "Test that an error is produced when a multisampled images "
16527 "are consumed via singlesample images types in the shader, or vice versa.");
Chris Forbes5533bfc2016-07-27 14:12:34 +120016528
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016529 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "requires bound image to have multiple samples");
Chris Forbes5533bfc2016-07-27 14:12:34 +120016530
Tony Barbour1fa09702017-03-16 12:09:08 -060016531 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes5533bfc2016-07-27 14:12:34 +120016532 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16533
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016534 char const *vsSource =
16535 "#version 450\n"
16536 "\n"
16537 "out gl_PerVertex { vec4 gl_Position; };\n"
16538 "void main() { gl_Position = vec4(0); }\n";
16539 char const *fsSource =
16540 "#version 450\n"
16541 "\n"
16542 "layout(set=0, binding=0) uniform sampler2DMS s;\n"
16543 "layout(location=0) out vec4 color;\n"
16544 "void main() {\n"
16545 " color = texelFetch(s, ivec2(0), 0);\n"
16546 "}\n";
Chris Forbes5533bfc2016-07-27 14:12:34 +120016547 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
16548 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
16549
16550 VkPipelineObj pipe(m_device);
16551 pipe.AddShader(&vs);
16552 pipe.AddShader(&fs);
16553 pipe.AddColorAttachment();
16554
16555 VkTextureObj texture(m_device, nullptr);
16556 VkSamplerObj sampler(m_device);
16557
16558 VkDescriptorSetObj descriptorSet(m_device);
16559 descriptorSet.AppendSamplerTexture(&sampler, &texture);
16560 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
16561
16562 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
16563 ASSERT_VK_SUCCESS(err);
16564
Tony Barbour552f6c02016-12-21 14:34:07 -070016565 m_commandBuffer->BeginCommandBuffer();
16566 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes5533bfc2016-07-27 14:12:34 +120016567
16568 m_commandBuffer->BindPipeline(pipe);
16569 m_commandBuffer->BindDescriptorSet(descriptorSet);
16570
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016571 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes5533bfc2016-07-27 14:12:34 +120016572 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016573 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes5533bfc2016-07-27 14:12:34 +120016574 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16575
16576 // error produced here.
16577 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
16578
16579 m_errorMonitor->VerifyFound();
16580
Tony Barbour552f6c02016-12-21 14:34:07 -070016581 m_commandBuffer->EndRenderPass();
16582 m_commandBuffer->EndCommandBuffer();
Chris Forbes5533bfc2016-07-27 14:12:34 +120016583}
16584
Mark Youngc48c4c12016-04-11 14:26:49 -060016585TEST_F(VkLayerTest, CreateImageLimitsViolationMaxWidth) {
Tony Barbour1fa09702017-03-16 12:09:08 -060016586 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060016587
Jeremy Hayesbb63cc12017-03-20 15:33:01 -060016588 VkFormat const format = VK_FORMAT_B8G8R8A8_UNORM;
16589 {
16590 VkFormatProperties properties;
16591 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), format, &properties);
16592 if (properties.optimalTilingFeatures == 0) {
16593 printf(" Image format not supported; skipped.\n");
16594 return;
16595 }
16596 }
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060016597
Jeremy Hayesbb63cc12017-03-20 15:33:01 -060016598 VkImageCreateInfo info = {};
16599 info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16600 info.pNext = NULL;
16601 info.imageType = VK_IMAGE_TYPE_2D;
16602 info.format = format;
16603 info.extent.height = 32;
16604 info.extent.depth = 1;
16605 info.mipLevels = 1;
16606 info.arrayLayers = 1;
16607 info.samples = VK_SAMPLE_COUNT_1_BIT;
16608 info.tiling = VK_IMAGE_TILING_OPTIMAL;
16609 info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
16610 info.flags = 0;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060016611
16612 // Introduce error by sending down a bogus width extent
Jeremy Hayesbb63cc12017-03-20 15:33:01 -060016613 {
16614 VkImageFormatProperties properties;
16615 auto const result = vkGetPhysicalDeviceImageFormatProperties(m_device->phy().handle(), info.format, info.imageType,
16616 info.tiling, info.usage, info.flags, &properties);
16617 ASSERT_VK_SUCCESS(result);
16618 info.extent.width = properties.maxExtent.width + 1;
16619 }
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060016620
Jeremy Hayesbb63cc12017-03-20 15:33:01 -060016621 VkImage image;
16622 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
16623 vkCreateImage(m_device->device(), &info, NULL, &image);
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016624 m_errorMonitor->VerifyFound();
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060016625}
16626
Mark Youngc48c4c12016-04-11 14:26:49 -060016627TEST_F(VkLayerTest, CreateImageLimitsViolationMinWidth) {
Tony Barbour1fa09702017-03-16 12:09:08 -060016628 ASSERT_NO_FATAL_FAILURE(Init());
Mark Youngc48c4c12016-04-11 14:26:49 -060016629
Jeremy Hayesbb63cc12017-03-20 15:33:01 -060016630 VkFormat const format = VK_FORMAT_B8G8R8A8_UNORM;
16631 {
16632 VkFormatProperties properties;
16633 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), format, &properties);
16634 if (properties.optimalTilingFeatures == 0) {
16635 printf(" Image format not supported; skipped.\n");
16636 return;
16637 }
16638 }
Mark Youngc48c4c12016-04-11 14:26:49 -060016639
Jeremy Hayesbb63cc12017-03-20 15:33:01 -060016640 VkImageCreateInfo info = {};
16641 info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16642 info.pNext = NULL;
16643 info.imageType = VK_IMAGE_TYPE_2D;
16644 info.format = format;
16645 info.extent.height = 32;
16646 info.extent.depth = 1;
16647 info.mipLevels = 1;
16648 info.arrayLayers = 1;
16649 info.samples = VK_SAMPLE_COUNT_1_BIT;
16650 info.tiling = VK_IMAGE_TILING_OPTIMAL;
16651 info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
16652 info.flags = 0;
Mark Youngc48c4c12016-04-11 14:26:49 -060016653
16654 // Introduce error by sending down a bogus width extent
Jeremy Hayesbb63cc12017-03-20 15:33:01 -060016655 info.extent.width = 0;
Mark Youngc48c4c12016-04-11 14:26:49 -060016656
Jeremy Hayesbb63cc12017-03-20 15:33:01 -060016657 VkImage image;
Tobin Ehlisa55b1d42017-04-04 12:23:48 -060016658 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02917);
Jeremy Hayesbb63cc12017-03-20 15:33:01 -060016659 m_errorMonitor->SetUnexpectedError("parameter pCreateInfo->extent.width must be greater than 0");
16660 vkCreateImage(m_device->device(), &info, NULL, &image);
Mark Youngc48c4c12016-04-11 14:26:49 -060016661 m_errorMonitor->VerifyFound();
16662}
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -070016663
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060016664TEST_F(VkLayerTest, AttachmentDescriptionUndefinedFormat) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016665 TEST_DESCRIPTION(
16666 "Create a render pass with an attachment description "
16667 "format set to VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060016668
Tony Barbour1fa09702017-03-16 12:09:08 -060016669 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060016670 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16671
Jeremy Hayes632e0ab2017-02-09 13:32:28 -070016672 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "format is VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060016673
16674 VkAttachmentReference color_attach = {};
16675 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
16676 color_attach.attachment = 0;
16677 VkSubpassDescription subpass = {};
16678 subpass.colorAttachmentCount = 1;
16679 subpass.pColorAttachments = &color_attach;
16680
16681 VkRenderPassCreateInfo rpci = {};
16682 rpci.subpassCount = 1;
16683 rpci.pSubpasses = &subpass;
16684 rpci.attachmentCount = 1;
16685 VkAttachmentDescription attach_desc = {};
16686 attach_desc.format = VK_FORMAT_UNDEFINED;
16687 rpci.pAttachments = &attach_desc;
16688 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
16689 VkRenderPass rp;
16690 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
16691
16692 m_errorMonitor->VerifyFound();
16693
16694 if (result == VK_SUCCESS) {
16695 vkDestroyRenderPass(m_device->device(), rp, NULL);
16696 }
16697}
16698
Mark Youngd339ba32016-05-30 13:28:35 -060016699TEST_F(VkLayerTest, CreateImageViewNoMemoryBoundToImage) {
16700 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -060016701 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -060016702 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -060016703
Tony Barbour1fa09702017-03-16 12:09:08 -060016704 ASSERT_NO_FATAL_FAILURE(Init());
Mark Youngd339ba32016-05-30 13:28:35 -060016705
16706 // Create an image and try to create a view with no memory backing the image
16707 VkImage image;
16708
16709 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
16710 const int32_t tex_width = 32;
16711 const int32_t tex_height = 32;
16712
16713 VkImageCreateInfo image_create_info = {};
16714 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16715 image_create_info.pNext = NULL;
16716 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16717 image_create_info.format = tex_format;
16718 image_create_info.extent.width = tex_width;
16719 image_create_info.extent.height = tex_height;
16720 image_create_info.extent.depth = 1;
16721 image_create_info.mipLevels = 1;
16722 image_create_info.arrayLayers = 1;
16723 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16724 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16725 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
16726 image_create_info.flags = 0;
16727
16728 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
16729 ASSERT_VK_SUCCESS(err);
16730
16731 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130016732 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Mark Youngd339ba32016-05-30 13:28:35 -060016733 image_view_create_info.image = image;
16734 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
16735 image_view_create_info.format = tex_format;
16736 image_view_create_info.subresourceRange.layerCount = 1;
16737 image_view_create_info.subresourceRange.baseMipLevel = 0;
16738 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016739 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -060016740
16741 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016742 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Youngd339ba32016-05-30 13:28:35 -060016743
16744 m_errorMonitor->VerifyFound();
16745 vkDestroyImage(m_device->device(), image, NULL);
16746 // If last error is success, it still created the view, so delete it.
16747 if (err == VK_SUCCESS) {
16748 vkDestroyImageView(m_device->device(), view, NULL);
16749 }
Mark Youngd339ba32016-05-30 13:28:35 -060016750}
16751
Karl Schultz6addd812016-02-02 17:17:23 -070016752TEST_F(VkLayerTest, InvalidImageViewAspect) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016753 TEST_DESCRIPTION("Create an image and try to create a view with an invalid aspectMask");
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070016754 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00741);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016755
Tony Barbour1fa09702017-03-16 12:09:08 -060016756 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060016757
Karl Schultz6addd812016-02-02 17:17:23 -070016758 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060016759 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060016760 image.Init(32, 32, 1, tex_format, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_LINEAR, 0);
Tobin Ehlis1f567a22016-05-25 16:15:18 -060016761 ASSERT_TRUE(image.initialized());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060016762
16763 VkImageViewCreateInfo image_view_create_info = {};
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060016764 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060016765 image_view_create_info.image = image.handle();
Karl Schultz6addd812016-02-02 17:17:23 -070016766 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
16767 image_view_create_info.format = tex_format;
16768 image_view_create_info.subresourceRange.baseMipLevel = 0;
16769 image_view_create_info.subresourceRange.levelCount = 1;
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060016770 image_view_create_info.subresourceRange.layerCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070016771 // Cause an error by setting an invalid image aspect
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016772 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060016773
16774 VkImageView view;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060016775 vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060016776
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016777 m_errorMonitor->VerifyFound();
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060016778}
16779
Mike Weiblena1e13f42017-02-09 21:25:59 -070016780TEST_F(VkLayerTest, ExerciseGetImageSubresourceLayout) {
16781 TEST_DESCRIPTION("Test vkGetImageSubresourceLayout() valid usages");
16782
Tony Barbour1fa09702017-03-16 12:09:08 -060016783 ASSERT_NO_FATAL_FAILURE(Init());
Mike Weiblena1e13f42017-02-09 21:25:59 -070016784 VkSubresourceLayout subres_layout = {};
16785
16786 // VU 00732: image must have been created with tiling equal to VK_IMAGE_TILING_LINEAR
16787 {
16788 const VkImageTiling tiling = VK_IMAGE_TILING_OPTIMAL; // ERROR: violates VU 00732
16789 VkImageObj img(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060016790 img.InitNoLayout(32, 32, 1, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, tiling);
Mike Weiblena1e13f42017-02-09 21:25:59 -070016791 ASSERT_TRUE(img.initialized());
16792
16793 VkImageSubresource subres = {};
16794 subres.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16795 subres.mipLevel = 0;
16796 subres.arrayLayer = 0;
16797
16798 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00732);
16799 vkGetImageSubresourceLayout(m_device->device(), img.image(), &subres, &subres_layout);
16800 m_errorMonitor->VerifyFound();
16801 }
16802
16803 // VU 00733: The aspectMask member of pSubresource must only have a single bit set
16804 {
16805 VkImageObj img(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060016806 img.InitNoLayout(32, 32, 1, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
Mike Weiblena1e13f42017-02-09 21:25:59 -070016807 ASSERT_TRUE(img.initialized());
16808
16809 VkImageSubresource subres = {};
16810 subres.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_METADATA_BIT; // ERROR: triggers VU 00733
16811 subres.mipLevel = 0;
16812 subres.arrayLayer = 0;
16813
16814 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00733);
16815 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00741);
16816 vkGetImageSubresourceLayout(m_device->device(), img.image(), &subres, &subres_layout);
16817 m_errorMonitor->VerifyFound();
16818 }
16819
16820 // 00739 mipLevel must be less than the mipLevels specified in VkImageCreateInfo when the image was created
16821 {
16822 VkImageObj img(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060016823 img.InitNoLayout(32, 32, 1, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
Mike Weiblena1e13f42017-02-09 21:25:59 -070016824 ASSERT_TRUE(img.initialized());
16825
16826 VkImageSubresource subres = {};
16827 subres.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16828 subres.mipLevel = 1; // ERROR: triggers VU 00739
16829 subres.arrayLayer = 0;
16830
16831 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00739);
16832 vkGetImageSubresourceLayout(m_device->device(), img.image(), &subres, &subres_layout);
16833 m_errorMonitor->VerifyFound();
16834 }
16835
16836 // 00740 arrayLayer must be less than the arrayLayers specified in VkImageCreateInfo when the image was created
16837 {
16838 VkImageObj img(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060016839 img.InitNoLayout(32, 32, 1, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
Mike Weiblena1e13f42017-02-09 21:25:59 -070016840 ASSERT_TRUE(img.initialized());
16841
16842 VkImageSubresource subres = {};
16843 subres.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16844 subres.mipLevel = 0;
16845 subres.arrayLayer = 1; // ERROR: triggers VU 00740
16846
16847 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00740);
16848 vkGetImageSubresourceLayout(m_device->device(), img.image(), &subres, &subres_layout);
16849 m_errorMonitor->VerifyFound();
16850 }
16851}
16852
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016853TEST_F(VkLayerTest, CopyImageLayerCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -070016854 VkResult err;
16855 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016856
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070016857 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01198);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016858
Tony Barbour1fa09702017-03-16 12:09:08 -060016859 ASSERT_NO_FATAL_FAILURE(Init());
Mike Stroyana3082432015-09-25 13:39:21 -060016860
16861 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070016862 VkImage srcImage;
16863 VkImage dstImage;
16864 VkDeviceMemory srcMem;
16865 VkDeviceMemory destMem;
16866 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016867
16868 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016869 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16870 image_create_info.pNext = NULL;
16871 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16872 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16873 image_create_info.extent.width = 32;
16874 image_create_info.extent.height = 32;
16875 image_create_info.extent.depth = 1;
16876 image_create_info.mipLevels = 1;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016877 image_create_info.arrayLayers = 4;
Karl Schultz6addd812016-02-02 17:17:23 -070016878 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16879 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16880 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16881 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016882
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016883 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016884 ASSERT_VK_SUCCESS(err);
16885
Mark Lobodzinski867787a2016-10-14 11:49:55 -060016886 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016887 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016888 ASSERT_VK_SUCCESS(err);
16889
16890 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016891 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016892 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16893 memAlloc.pNext = NULL;
16894 memAlloc.allocationSize = 0;
16895 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016896
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060016897 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016898 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016899 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016900 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016901 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016902 ASSERT_VK_SUCCESS(err);
16903
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016904 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016905 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016906 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016907 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016908 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016909 ASSERT_VK_SUCCESS(err);
16910
16911 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16912 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016913 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016914 ASSERT_VK_SUCCESS(err);
16915
Tony Barbour552f6c02016-12-21 14:34:07 -070016916 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060016917 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016918 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016919 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060016920 copyRegion.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016921 copyRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060016922 copyRegion.srcOffset.x = 0;
16923 copyRegion.srcOffset.y = 0;
16924 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016925 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016926 copyRegion.dstSubresource.mipLevel = 0;
16927 copyRegion.dstSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016928 // Introduce failure by forcing the dst layerCount to differ from src
16929 copyRegion.dstSubresource.layerCount = 3;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016930 copyRegion.dstOffset.x = 0;
16931 copyRegion.dstOffset.y = 0;
16932 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016933 copyRegion.extent.width = 1;
16934 copyRegion.extent.height = 1;
16935 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016936 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070016937 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060016938
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016939 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060016940
Chia-I Wuf7458c52015-10-26 21:10:41 +080016941 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016942 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016943 vkFreeMemory(m_device->device(), srcMem, NULL);
16944 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016945}
16946
Tony Barbourd6673642016-05-05 14:46:39 -060016947TEST_F(VkLayerTest, ImageLayerUnsupportedFormat) {
Tony Barbourd6673642016-05-05 14:46:39 -060016948 TEST_DESCRIPTION("Creating images with unsuported formats ");
16949
Tony Barbour1fa09702017-03-16 12:09:08 -060016950 ASSERT_NO_FATAL_FAILURE(Init());
Tony Barbourd6673642016-05-05 14:46:39 -060016951 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourd6673642016-05-05 14:46:39 -060016952
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060016953 // Create image with unsupported format - Expect FORMAT_UNSUPPORTED
Chris Forbesf4d8e332016-11-28 17:51:10 +130016954 VkImageCreateInfo image_create_info = {};
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060016955 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060016956 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16957 image_create_info.format = VK_FORMAT_UNDEFINED;
16958 image_create_info.extent.width = 32;
16959 image_create_info.extent.height = 32;
16960 image_create_info.extent.depth = 1;
16961 image_create_info.mipLevels = 1;
16962 image_create_info.arrayLayers = 1;
16963 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16964 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16965 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060016966
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016967 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16968 "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED");
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060016969
Jeremy Hayes96dcd812017-03-14 14:04:19 -060016970 VkImage image;
16971 vkCreateImage(m_device->handle(), &image_create_info, NULL, &image);
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060016972 m_errorMonitor->VerifyFound();
16973
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060016974 // Look for a format that is COMPLETELY unsupported with this hardware
Jeremy Hayes96dcd812017-03-14 14:04:19 -060016975 VkFormat unsupported = VK_FORMAT_UNDEFINED;
Tony Barbourd6673642016-05-05 14:46:39 -060016976 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
16977 VkFormat format = static_cast<VkFormat>(f);
16978 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016979 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Tony Barbourd6673642016-05-05 14:46:39 -060016980 unsupported = format;
16981 break;
16982 }
16983 }
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060016984
Tony Barbourd6673642016-05-05 14:46:39 -060016985 if (unsupported != VK_FORMAT_UNDEFINED) {
Tony Barbourd6673642016-05-05 14:46:39 -060016986 image_create_info.format = unsupported;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016987 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is an unsupported format");
Tony Barbourd6673642016-05-05 14:46:39 -060016988
Jeremy Hayes96dcd812017-03-14 14:04:19 -060016989 vkCreateImage(m_device->handle(), &image_create_info, NULL, &image);
Tony Barbourd6673642016-05-05 14:46:39 -060016990 m_errorMonitor->VerifyFound();
16991 }
16992}
16993
16994TEST_F(VkLayerTest, ImageLayerViewTests) {
Tony Barbourd6673642016-05-05 14:46:39 -060016995 TEST_DESCRIPTION("Passing bad parameters to CreateImageView");
16996
Tony Barbour1fa09702017-03-16 12:09:08 -060016997 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -060016998 auto depth_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbourf887b162017-03-09 10:06:46 -070016999 if (!depth_format) {
17000 return;
17001 }
Tony Barbourd6673642016-05-05 14:46:39 -060017002
17003 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017004 image.Init(128, 128, 1, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
Tony Barbourd6673642016-05-05 14:46:39 -060017005 VK_IMAGE_TILING_OPTIMAL, 0);
17006 ASSERT_TRUE(image.initialized());
17007
17008 VkImageView imgView;
17009 VkImageViewCreateInfo imgViewInfo = {};
17010 imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
17011 imgViewInfo.image = image.handle();
17012 imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
17013 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
17014 imgViewInfo.subresourceRange.layerCount = 1;
17015 imgViewInfo.subresourceRange.baseMipLevel = 0;
17016 imgViewInfo.subresourceRange.levelCount = 1;
17017 imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17018
Tony Barbourd6673642016-05-05 14:46:39 -060017019
Tony Barbourd6673642016-05-05 14:46:39 -060017020 // Can't use depth format for view into color image - Expect INVALID_FORMAT
Tony Barbourf887b162017-03-09 10:06:46 -070017021 imgViewInfo.format = depth_format;
Jeremy Hayes2ffbaa72017-03-14 17:05:50 -060017022 m_errorMonitor->SetDesiredFailureMsg(
17023 VK_DEBUG_REPORT_ERROR_BIT_EXT,
17024 "Formats MUST be IDENTICAL unless VK_IMAGE_CREATE_MUTABLE_FORMAT BIT was set on image creation.");
Tony Barbourd6673642016-05-05 14:46:39 -060017025 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
17026 m_errorMonitor->VerifyFound();
17027 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
17028
Tony Barbourd6673642016-05-05 14:46:39 -060017029 // Same compatibility class but no MUTABLE_FORMAT bit - Expect
17030 // VIEW_CREATE_ERROR
17031 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UINT;
Jeremy Hayes2ffbaa72017-03-14 17:05:50 -060017032 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02172);
Tony Barbourd6673642016-05-05 14:46:39 -060017033 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
17034 m_errorMonitor->VerifyFound();
17035 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
17036
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060017037 // TODO: Update framework to easily passing mutable flag into ImageObj init
17038 // For now just allowing image for this one test to not have memory bound
Jeremy Hayes5a7cf2e2017-01-06 15:23:27 -070017039 // TODO: The following line is preventing the intended validation from occurring because of the way the error monitor works.
17040 // m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17041 // " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Tony Barbourd6673642016-05-05 14:46:39 -060017042 // Have MUTABLE_FORMAT bit but not in same compatibility class - Expect
17043 // VIEW_CREATE_ERROR
17044 VkImageCreateInfo mutImgInfo = image.create_info();
17045 VkImage mutImage;
17046 mutImgInfo.format = VK_FORMAT_R8_UINT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017047 assert(m_device->format_properties(VK_FORMAT_R8_UINT).optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
Tony Barbourd6673642016-05-05 14:46:39 -060017048 mutImgInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
17049 mutImgInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Jeremy Hayes2ffbaa72017-03-14 17:05:50 -060017050 VkResult ret = vkCreateImage(m_device->handle(), &mutImgInfo, NULL, &mutImage);
Tony Barbourd6673642016-05-05 14:46:39 -060017051 ASSERT_VK_SUCCESS(ret);
Jeremy Hayes2ffbaa72017-03-14 17:05:50 -060017052
17053 VkMemoryRequirements requirements;
17054 vkGetImageMemoryRequirements(m_device->device(), mutImage, &requirements);
17055
17056 VkMemoryAllocateInfo alloc_info{};
17057 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17058 alloc_info.pNext = NULL;
17059 alloc_info.memoryTypeIndex = 0;
17060 alloc_info.allocationSize = requirements.size;
17061 bool pass = m_device->phy().set_memory_type(requirements.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
17062 ASSERT_TRUE(pass);
17063
17064 VkDeviceMemory memory;
17065 ret = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &memory);
17066 ASSERT_VK_SUCCESS(ret);
17067
17068 ret = vkBindImageMemory(m_device->device(), mutImage, memory, 0);
17069 ASSERT_VK_SUCCESS(ret);
17070
Tony Barbourd6673642016-05-05 14:46:39 -060017071 imgViewInfo.image = mutImage;
Jeremy Hayes2ffbaa72017-03-14 17:05:50 -060017072 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02171);
Tony Barbourd6673642016-05-05 14:46:39 -060017073 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
17074 m_errorMonitor->VerifyFound();
17075 imgViewInfo.image = image.handle();
Jeremy Hayes2ffbaa72017-03-14 17:05:50 -060017076
17077 vkFreeMemory(m_device->device(), memory, NULL);
Tony Barbourd6673642016-05-05 14:46:39 -060017078 vkDestroyImage(m_device->handle(), mutImage, NULL);
17079}
17080
Petr Kraus4d718682017-05-18 03:38:41 +020017081TEST_F(VkLayerTest, ImageViewSubresourceRangeTests) {
17082 TEST_DESCRIPTION("Passing bad image subrange to CreateImageView");
17083
17084 ASSERT_NO_FATAL_FAILURE(Init());
17085 auto depth_format = FindSupportedDepthStencilFormat(gpu());
17086 if (!depth_format) {
17087 return;
17088 }
17089
17090 VkImageObj image(m_device);
17091 image.Init(128, 128, 1, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
17092 VK_IMAGE_TILING_OPTIMAL, 0);
17093 ASSERT_TRUE(image.initialized());
17094
17095 VkImageView imgView;
17096 VkImageViewCreateInfo imgViewInfo = {};
17097 imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
17098 imgViewInfo.image = image.handle();
17099 imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
17100 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
17101 imgViewInfo.subresourceRange.layerCount = 1;
17102 imgViewInfo.subresourceRange.baseMipLevel = 0;
17103 imgViewInfo.subresourceRange.levelCount = 1;
17104 imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17105
17106 // View's levelCount can't be 0
17107 imgViewInfo.subresourceRange.levelCount = 0;
17108 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
17109 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
17110 m_errorMonitor->VerifyFound();
17111 imgViewInfo.subresourceRange.levelCount = 1;
17112
17113 // View can't have baseMipLevel >= image's mipLevels
17114 imgViewInfo.subresourceRange.baseMipLevel = 1;
17115 imgViewInfo.subresourceRange.levelCount = VK_REMAINING_MIP_LEVELS;
17116 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17117 "vkCreateImageView: pCreateInfo->subresourceRange.baseMipLevel (= 1) is greater or equal "
17118 "to the mip level count of the image (i.e. greater or equal to 1).");
17119 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
17120 m_errorMonitor->VerifyFound();
17121 imgViewInfo.subresourceRange.baseMipLevel = 0;
17122 imgViewInfo.subresourceRange.levelCount = 1;
17123
17124 // View can't have baseMipLevel >= image's mipLevels
17125 imgViewInfo.subresourceRange.baseMipLevel = 1;
17126 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
17127 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
17128 m_errorMonitor->VerifyFound();
17129 imgViewInfo.subresourceRange.baseMipLevel = 0;
17130
17131 // View's baseMipLevel + levelCount can't be > image's mipLevels
17132 imgViewInfo.subresourceRange.levelCount = 2;
17133 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
17134 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
17135 m_errorMonitor->VerifyFound();
17136 imgViewInfo.subresourceRange.levelCount = 1;
17137
17138 // View's layerCount can't be 0
17139 imgViewInfo.subresourceRange.layerCount = 0;
17140 m_errorMonitor->SetDesiredFailureMsg(
17141 VK_DEBUG_REPORT_ERROR_BIT_EXT,
17142 "if pCreateInfo->viewType is VK_IMAGE_TYPE_2D, pCreateInfo->subresourceRange.layerCount must be 1");
17143 // m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02931); // overlap with param_validation
17144 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
17145 m_errorMonitor->VerifyFound();
17146 imgViewInfo.subresourceRange.layerCount = 1;
17147
17148 // View can't have baseArrayLayer >= image's arraySize
17149 imgViewInfo.subresourceRange.baseArrayLayer = 1;
17150 imgViewInfo.subresourceRange.layerCount = VK_REMAINING_ARRAY_LAYERS;
17151 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17152 "vkCreateImageView: pCreateInfo->subresourceRange.baseArrayLayer (= 1) is greater or "
17153 "equal to the arrayLayers of the image when it was created (i.e. greater or equal to 1).");
17154 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
17155 m_errorMonitor->VerifyFound();
17156 imgViewInfo.subresourceRange.baseArrayLayer = 0;
17157 imgViewInfo.subresourceRange.layerCount = 1;
17158
17159 // View can't have baseArrayLayer >= image's arraySize
17160 imgViewInfo.subresourceRange.baseArrayLayer = 1;
17161 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02931);
17162 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
17163 m_errorMonitor->VerifyFound();
17164 imgViewInfo.subresourceRange.baseArrayLayer = 0;
17165
17166 // View's baseArrayLayer + layerCount can't be > image's arrayLayers
17167 imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D_ARRAY;
17168 imgViewInfo.subresourceRange.layerCount = 2;
17169 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02931);
17170 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
17171 m_errorMonitor->VerifyFound();
17172 imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
17173 imgViewInfo.subresourceRange.layerCount = 1;
17174
17175 // View's layerCount of 2D view has to be 1
17176 imgViewInfo.subresourceRange.layerCount = 2;
17177 m_errorMonitor->SetDesiredFailureMsg(
17178 VK_DEBUG_REPORT_ERROR_BIT_EXT,
17179 "if pCreateInfo->viewType is VK_IMAGE_TYPE_2D, pCreateInfo->subresourceRange.layerCount must be 1");
17180 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
17181 m_errorMonitor->VerifyFound();
17182 imgViewInfo.subresourceRange.layerCount = 1;
17183
17184 // TODO: should test maitenance1 3D -> 2D array view feature
17185}
17186
Dave Houlton75967fc2017-03-06 17:21:16 -070017187TEST_F(VkLayerTest, CompressedImageMipCopyTests) {
17188 TEST_DESCRIPTION("Image/Buffer copies for higher mip levels");
17189
Tony Barbour1fa09702017-03-16 12:09:08 -060017190 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton75967fc2017-03-06 17:21:16 -070017191
Jamie Madill35127872017-03-15 16:17:46 -040017192 VkPhysicalDeviceFeatures device_features = {};
Dave Houlton75967fc2017-03-06 17:21:16 -070017193 ASSERT_NO_FATAL_FAILURE(GetPhysicalDeviceFeatures(&device_features));
17194 VkFormat compressed_format = VK_FORMAT_UNDEFINED;
17195 if (device_features.textureCompressionBC) {
17196 compressed_format = VK_FORMAT_BC3_SRGB_BLOCK;
17197 } else if (device_features.textureCompressionETC2) {
17198 compressed_format = VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK;
17199 } else if (device_features.textureCompressionASTC_LDR) {
17200 compressed_format = VK_FORMAT_ASTC_4x4_UNORM_BLOCK;
17201 } else {
17202 printf(" No compressed formats supported - CompressedImageMipCopyTests skipped.\n");
17203 return;
17204 }
17205
17206 VkImageCreateInfo ci;
17207 ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17208 ci.pNext = NULL;
17209 ci.flags = 0;
17210 ci.imageType = VK_IMAGE_TYPE_2D;
17211 ci.format = compressed_format;
17212 ci.extent = {32, 32, 1};
17213 ci.mipLevels = 6;
17214 ci.arrayLayers = 1;
17215 ci.samples = VK_SAMPLE_COUNT_1_BIT;
17216 ci.tiling = VK_IMAGE_TILING_OPTIMAL;
17217 ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
17218 ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
17219 ci.queueFamilyIndexCount = 0;
17220 ci.pQueueFamilyIndices = NULL;
17221 ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
17222
17223 VkImageObj image(m_device);
17224 image.init(&ci);
17225 ASSERT_TRUE(image.initialized());
17226
17227 VkImageObj odd_image(m_device);
17228 ci.extent = {31, 32, 1}; // Mips are [31,32] [15,16] [7,8] [3,4], [1,2] [1,1]
17229 odd_image.init(&ci);
17230 ASSERT_TRUE(odd_image.initialized());
17231
17232 // Allocate buffers
17233 VkMemoryPropertyFlags reqs = 0;
17234 vk_testing::Buffer buffer_1024, buffer_64, buffer_16, buffer_8;
17235 buffer_1024.init_as_src_and_dst(*m_device, 1024, reqs);
17236 buffer_64.init_as_src_and_dst(*m_device, 64, reqs);
17237 buffer_16.init_as_src_and_dst(*m_device, 16, reqs);
17238 buffer_8.init_as_src_and_dst(*m_device, 8, reqs);
17239
17240 VkBufferImageCopy region = {};
17241 region.bufferRowLength = 0;
17242 region.bufferImageHeight = 0;
17243 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17244 region.imageSubresource.layerCount = 1;
17245 region.imageOffset = {0, 0, 0};
17246 region.bufferOffset = 0;
17247
17248 // start recording
17249 m_commandBuffer->BeginCommandBuffer();
17250
17251 // Mip level copies that work - 5 levels
17252 m_errorMonitor->ExpectSuccess();
17253
17254 // Mip 0 should fit in 1k buffer - 1k texels @ 1b each
17255 region.imageExtent = {32, 32, 1};
17256 region.imageSubresource.mipLevel = 0;
17257 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_1024.handle(), 1,
17258 &region);
17259 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_1024.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17260 &region);
17261
17262 // Mip 2 should fit in 64b buffer - 64 texels @ 1b each
17263 region.imageExtent = {8, 8, 1};
17264 region.imageSubresource.mipLevel = 2;
17265 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_64.handle(), 1,
17266 &region);
17267 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17268 &region);
17269
17270 // Mip 3 should fit in 16b buffer - 16 texels @ 1b each
17271 region.imageExtent = {4, 4, 1};
17272 region.imageSubresource.mipLevel = 3;
17273 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
17274 &region);
17275 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17276 &region);
17277
17278 // Mip 4&5 should fit in 16b buffer with no complaint - 4 & 1 texels @ 1b each
17279 region.imageExtent = {2, 2, 1};
17280 region.imageSubresource.mipLevel = 4;
17281 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
17282 &region);
17283 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17284 &region);
17285
17286 region.imageExtent = {1, 1, 1};
17287 region.imageSubresource.mipLevel = 5;
17288 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
17289 &region);
17290 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17291 &region);
17292 m_errorMonitor->VerifyNotFound();
17293
17294 // Buffer must accomodate a full compressed block, regardless of texel count
17295 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01246);
17296 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_8.handle(), 1,
17297 &region);
17298 m_errorMonitor->VerifyFound();
17299 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01227);
17300 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_8.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17301 &region);
17302 m_errorMonitor->VerifyFound();
17303
17304 // Copy width < compressed block size, but not the full mip width
17305 region.imageExtent = {1, 2, 1};
17306 region.imageSubresource.mipLevel = 4;
17307 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01275);
17308 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
17309 &region);
17310 m_errorMonitor->VerifyFound();
17311 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01275);
17312 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17313 &region);
17314 m_errorMonitor->VerifyFound();
17315
17316 // Copy height < compressed block size but not the full mip height
17317 region.imageExtent = {2, 1, 1};
17318 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01276);
17319 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
17320 &region);
17321 m_errorMonitor->VerifyFound();
17322 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01276);
17323 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17324 &region);
17325 m_errorMonitor->VerifyFound();
17326
17327 // Offsets must be multiple of compressed block size
17328 region.imageOffset = {1, 1, 0};
17329 region.imageExtent = {1, 1, 1};
17330 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01273);
17331 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
17332 &region);
17333 m_errorMonitor->VerifyFound();
17334 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01273);
17335 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17336 &region);
17337 m_errorMonitor->VerifyFound();
17338
17339 // Offset + extent width = mip width - should succeed
17340 region.imageOffset = {4, 4, 0};
17341 region.imageExtent = {3, 4, 1};
17342 region.imageSubresource.mipLevel = 2;
17343 m_errorMonitor->ExpectSuccess();
17344 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), odd_image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
17345 &region);
17346 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), odd_image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17347 &region);
17348 m_errorMonitor->VerifyNotFound();
17349
17350 // Offset + extent width > mip width, but still within the final compressed block - should succeed
17351 region.imageExtent = {4, 4, 1};
17352 m_errorMonitor->ExpectSuccess();
17353 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), odd_image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
17354 &region);
17355 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), odd_image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17356 &region);
17357 m_errorMonitor->VerifyNotFound();
17358
17359 // Offset + extent width < mip width and not a multiple of block width - should fail
17360 region.imageExtent = {3, 3, 1};
17361 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01276);
17362 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), odd_image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
17363 &region);
17364 m_errorMonitor->VerifyFound();
17365 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01276);
17366 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), odd_image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17367 &region);
17368 m_errorMonitor->VerifyFound();
17369}
17370
Dave Houlton59a20702017-02-02 17:26:23 -070017371TEST_F(VkLayerTest, ImageBufferCopyTests) {
17372 TEST_DESCRIPTION("Image to buffer and buffer to image tests");
17373
Tony Barbour1fa09702017-03-16 12:09:08 -060017374 ASSERT_NO_FATAL_FAILURE(Init());
Tony Barbourf887b162017-03-09 10:06:46 -070017375 VkFormatProperties format_props = m_device->format_properties(VK_FORMAT_D24_UNORM_S8_UINT);
17376 if (!(format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT)) {
17377 printf(" VK_FORMAT_D24_UNORM_S8_UINT not supported. Skipped.\n");
17378 return;
17379 }
Dave Houlton584d51e2017-02-16 12:52:54 -070017380
17381 // Bail if any dimension of transfer granularity is 0.
17382 auto index = m_device->graphics_queue_node_index_;
17383 auto queue_family_properties = m_device->phy().queue_properties();
17384 if ((queue_family_properties[index].minImageTransferGranularity.depth == 0) ||
17385 (queue_family_properties[index].minImageTransferGranularity.width == 0) ||
17386 (queue_family_properties[index].minImageTransferGranularity.height == 0)) {
17387 printf(" Subresource copies are disallowed when xfer granularity (x|y|z) is 0. Skipped.\n");
17388 return;
17389 }
17390
Dave Houlton59a20702017-02-02 17:26:23 -070017391 VkImageObj image_64k(m_device); // 128^2 texels, 64k
17392 VkImageObj image_16k(m_device); // 64^2 texels, 16k
17393 VkImageObj image_16k_depth(m_device); // 64^2 texels, depth, 16k
Dave Houltonf3229d52017-02-21 15:59:08 -070017394 VkImageObj ds_image_4D_1S(m_device); // 256^2 texels, 512kb (256k depth, 64k stencil, 192k pack)
17395 VkImageObj ds_image_3D_1S(m_device); // 256^2 texels, 256kb (192k depth, 64k stencil)
17396 VkImageObj ds_image_2D(m_device); // 256^2 texels, 128k (128k depth)
17397 VkImageObj ds_image_1S(m_device); // 256^2 texels, 64k (64k stencil)
17398
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017399 image_64k.Init(128, 128, 1, VK_FORMAT_R8G8B8A8_UINT,
Dave Houlton59a20702017-02-02 17:26:23 -070017400 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
17401 VK_IMAGE_TILING_OPTIMAL, 0);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017402 image_16k.Init(64, 64, 1, VK_FORMAT_R8G8B8A8_UINT,
Dave Houlton59a20702017-02-02 17:26:23 -070017403 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
17404 VK_IMAGE_TILING_OPTIMAL, 0);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017405 image_16k_depth.Init(64, 64, 1, VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
Dave Houlton59a20702017-02-02 17:26:23 -070017406 VK_IMAGE_TILING_OPTIMAL, 0);
Dave Houlton59a20702017-02-02 17:26:23 -070017407 ASSERT_TRUE(image_64k.initialized());
17408 ASSERT_TRUE(image_16k.initialized());
17409 ASSERT_TRUE(image_16k_depth.initialized());
Dave Houlton59a20702017-02-02 17:26:23 -070017410
Dave Houltonf3229d52017-02-21 15:59:08 -070017411 // Verify all needed Depth/Stencil formats are supported
17412 bool missing_ds_support = false;
17413 VkFormatProperties props = {0, 0, 0};
17414 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D32_SFLOAT_S8_UINT, &props);
17415 missing_ds_support |= (props.bufferFeatures == 0 && props.linearTilingFeatures == 0 && props.optimalTilingFeatures == 0);
17416 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D24_UNORM_S8_UINT, &props);
17417 missing_ds_support |= (props.bufferFeatures == 0 && props.linearTilingFeatures == 0 && props.optimalTilingFeatures == 0);
17418 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D16_UNORM, &props);
17419 missing_ds_support |= (props.bufferFeatures == 0 && props.linearTilingFeatures == 0 && props.optimalTilingFeatures == 0);
17420 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_S8_UINT, &props);
17421 missing_ds_support |= (props.bufferFeatures == 0 && props.linearTilingFeatures == 0 && props.optimalTilingFeatures == 0);
17422
17423 if (!missing_ds_support) {
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017424 ds_image_4D_1S.Init(
17425 256, 256, 1, VK_FORMAT_D32_SFLOAT_S8_UINT,
Dave Houltonf3229d52017-02-21 15:59:08 -070017426 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
17427 VK_IMAGE_TILING_OPTIMAL, 0);
17428 ASSERT_TRUE(ds_image_4D_1S.initialized());
17429
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017430 ds_image_3D_1S.Init(
17431 256, 256, 1, VK_FORMAT_D24_UNORM_S8_UINT,
Dave Houltonf3229d52017-02-21 15:59:08 -070017432 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
17433 VK_IMAGE_TILING_OPTIMAL, 0);
17434 ASSERT_TRUE(ds_image_3D_1S.initialized());
17435
Dave Houlton11dcd5e2017-04-25 16:00:10 -060017436 ds_image_2D.Init(
17437 256, 256, 1, VK_FORMAT_D16_UNORM,
17438 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
17439 VK_IMAGE_TILING_OPTIMAL, 0);
Dave Houltonf3229d52017-02-21 15:59:08 -070017440 ASSERT_TRUE(ds_image_2D.initialized());
17441
Dave Houlton11dcd5e2017-04-25 16:00:10 -060017442 ds_image_1S.Init(
17443 256, 256, 1, VK_FORMAT_S8_UINT,
17444 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
17445 VK_IMAGE_TILING_OPTIMAL, 0);
Dave Houltonf3229d52017-02-21 15:59:08 -070017446 ASSERT_TRUE(ds_image_1S.initialized());
17447 }
17448
17449 // Allocate buffers
17450 vk_testing::Buffer buffer_256k, buffer_128k, buffer_64k, buffer_16k;
Dave Houlton59a20702017-02-02 17:26:23 -070017451 VkMemoryPropertyFlags reqs = 0;
Dave Houltonf3229d52017-02-21 15:59:08 -070017452 buffer_256k.init_as_src_and_dst(*m_device, 262144, reqs); // 256k
17453 buffer_128k.init_as_src_and_dst(*m_device, 131072, reqs); // 128k
17454 buffer_64k.init_as_src_and_dst(*m_device, 65536, reqs); // 64k
17455 buffer_16k.init_as_src_and_dst(*m_device, 16384, reqs); // 16k
Dave Houlton59a20702017-02-02 17:26:23 -070017456
17457 VkBufferImageCopy region = {};
17458 region.bufferRowLength = 0;
17459 region.bufferImageHeight = 0;
17460 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17461 region.imageSubresource.layerCount = 1;
17462 region.imageOffset = {0, 0, 0};
17463 region.imageExtent = {64, 64, 1};
17464 region.bufferOffset = 0;
17465
17466 // attempt copies before putting command buffer in recording state
17467 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01240);
17468 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64k.handle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17469 &region);
17470 m_errorMonitor->VerifyFound();
17471
17472 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01258);
17473 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_64k.handle(), 1,
17474 &region);
17475 m_errorMonitor->VerifyFound();
17476
17477 // start recording
17478 m_commandBuffer->BeginCommandBuffer();
17479
17480 // successful copies
17481 m_errorMonitor->ExpectSuccess();
17482 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
17483 &region);
17484 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16k.handle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17485 &region);
17486 region.imageOffset.x = 16; // 16k copy, offset requires larger image
17487 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
17488 &region);
17489 region.imageExtent.height = 78; // > 16k copy requires larger buffer & image
17490 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64k.handle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17491 &region);
17492 region.imageOffset.x = 0;
17493 region.imageExtent.height = 64;
17494 region.bufferOffset = 256; // 16k copy with buffer offset, requires larger buffer
17495 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_64k.handle(), 1,
17496 &region);
17497 m_errorMonitor->VerifyNotFound();
17498
Dave Houlton9dae7ec2017-03-01 16:23:25 -070017499 // image/buffer too small (extent too large) on copy to image
Dave Houlton59a20702017-02-02 17:26:23 -070017500 region.imageExtent = {65, 64, 1};
17501 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01227); // buffer too small
17502 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16k.handle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17503 &region);
17504 m_errorMonitor->VerifyFound();
17505
17506 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01228); // image too small
17507 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64k.handle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17508 &region);
17509 m_errorMonitor->VerifyFound();
17510
17511 // image/buffer too small (offset) on copy to image
17512 region.imageExtent = {64, 64, 1};
17513 region.imageOffset = {0, 4, 0};
17514 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01227); // buffer too small
17515 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16k.handle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17516 &region);
17517 m_errorMonitor->VerifyFound();
17518
17519 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01228); // image too small
17520 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64k.handle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17521 &region);
17522 m_errorMonitor->VerifyFound();
17523
17524 // image/buffer too small on copy to buffer
17525 region.imageExtent = {64, 64, 1};
17526 region.imageOffset = {0, 0, 0};
Mark Lobodzinski80871462017-02-16 10:37:27 -070017527 region.bufferOffset = 4;
Dave Houlton59a20702017-02-02 17:26:23 -070017528 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01246); // buffer too small
17529 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
17530 &region);
17531 m_errorMonitor->VerifyFound();
17532
17533 region.imageExtent = {64, 65, 1};
17534 region.bufferOffset = 0;
17535 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01245); // image too small
17536 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_64k.handle(), 1,
17537 &region);
17538 m_errorMonitor->VerifyFound();
17539
17540 // buffer size ok but rowlength causes loose packing
17541 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01246);
17542 region.imageExtent = {64, 64, 1};
17543 region.bufferRowLength = 68;
17544 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
17545 &region);
17546 m_errorMonitor->VerifyFound();
17547
Dave Houlton9dae7ec2017-03-01 16:23:25 -070017548 // An extent with zero area should produce a warning, but no error
17549 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT | VK_DEBUG_REPORT_ERROR_BIT_EXT, "} has zero area");
17550 region.imageExtent.width = 0;
17551 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
17552 &region);
17553 m_errorMonitor->VerifyFound();
17554
Dave Houlton59a20702017-02-02 17:26:23 -070017555 // aspect bits
17556 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01280); // more than 1 aspect bit set
17557 region.imageExtent = {64, 64, 1};
17558 region.bufferRowLength = 0;
17559 region.bufferImageHeight = 0;
17560 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
17561 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_depth.handle(), VK_IMAGE_LAYOUT_GENERAL,
17562 buffer_16k.handle(), 1, &region);
17563 m_errorMonitor->VerifyFound();
17564
17565 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01279); // mis-matched aspect
17566 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
17567 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
17568 &region);
17569 m_errorMonitor->VerifyFound();
17570
17571 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01279); // different mis-matched aspect
17572 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17573 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_depth.handle(), VK_IMAGE_LAYOUT_GENERAL,
17574 buffer_16k.handle(), 1, &region);
17575 m_errorMonitor->VerifyFound();
17576
Dave Houltonf3229d52017-02-21 15:59:08 -070017577 // Test Depth/Stencil copies
17578 if (missing_ds_support) {
17579 printf(" Depth / Stencil formats unsupported - skipping D/S tests.\n");
17580 } else {
17581 VkBufferImageCopy ds_region = {};
17582 ds_region.bufferOffset = 0;
17583 ds_region.bufferRowLength = 0;
17584 ds_region.bufferImageHeight = 0;
17585 ds_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
17586 ds_region.imageSubresource.mipLevel = 0;
17587 ds_region.imageSubresource.baseArrayLayer = 0;
17588 ds_region.imageSubresource.layerCount = 1;
17589 ds_region.imageOffset = {0, 0, 0};
17590 ds_region.imageExtent = {256, 256, 1};
17591
17592 // Depth copies that should succeed
17593 m_errorMonitor->ExpectSuccess(); // Extract 4b depth per texel, pack into 256k buffer
17594 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_4D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
17595 buffer_256k.handle(), 1, &ds_region);
17596 m_errorMonitor->VerifyNotFound();
17597
17598 m_errorMonitor->ExpectSuccess(); // Extract 3b depth per texel, pack (loose) into 256k buffer
17599 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_3D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
17600 buffer_256k.handle(), 1, &ds_region);
17601 m_errorMonitor->VerifyNotFound();
17602
17603 m_errorMonitor->ExpectSuccess(); // Copy 2b depth per texel, into 128k buffer
17604 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_2D.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
17605 buffer_128k.handle(), 1, &ds_region);
17606 m_errorMonitor->VerifyNotFound();
17607
17608 // Depth copies that should fail
17609 ds_region.bufferOffset = 4;
17610 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17611 VALIDATION_ERROR_01246); // Extract 4b depth per texel, pack into 256k buffer
17612 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_4D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
17613 buffer_256k.handle(), 1, &ds_region);
17614 m_errorMonitor->VerifyFound();
17615
17616 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17617 VALIDATION_ERROR_01246); // Extract 3b depth per texel, pack (loose) into 256k buffer
17618 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_3D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
17619 buffer_256k.handle(), 1, &ds_region);
17620 m_errorMonitor->VerifyFound();
17621
17622 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17623 VALIDATION_ERROR_01246); // Copy 2b depth per texel, into 128k buffer
17624 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_2D.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
17625 buffer_128k.handle(), 1, &ds_region);
17626 m_errorMonitor->VerifyFound();
17627
17628 // Stencil copies that should succeed
17629 ds_region.bufferOffset = 0;
17630 ds_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT;
17631 m_errorMonitor->ExpectSuccess(); // Extract 1b stencil per texel, pack into 64k buffer
17632 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_4D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
17633 buffer_64k.handle(), 1, &ds_region);
17634 m_errorMonitor->VerifyNotFound();
17635
17636 m_errorMonitor->ExpectSuccess(); // Extract 1b stencil per texel, pack into 64k buffer
17637 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_3D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
17638 buffer_64k.handle(), 1, &ds_region);
17639 m_errorMonitor->VerifyNotFound();
17640
17641 m_errorMonitor->ExpectSuccess(); // Copy 1b depth per texel, into 64k buffer
17642 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
17643 buffer_64k.handle(), 1, &ds_region);
17644 m_errorMonitor->VerifyNotFound();
17645
17646 // Stencil copies that should fail
17647 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17648 VALIDATION_ERROR_01246); // Extract 1b stencil per texel, pack into 64k buffer
17649 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_4D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
17650 buffer_16k.handle(), 1, &ds_region);
17651 m_errorMonitor->VerifyFound();
17652
17653 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17654 VALIDATION_ERROR_01246); // Extract 1b stencil per texel, pack into 64k buffer
17655 ds_region.bufferRowLength = 260;
17656 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_3D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
17657 buffer_64k.handle(), 1, &ds_region);
17658 m_errorMonitor->VerifyFound();
17659
17660 ds_region.bufferRowLength = 0;
17661 ds_region.bufferOffset = 4;
17662 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17663 VALIDATION_ERROR_01246); // Copy 1b depth per texel, into 64k buffer
17664 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
17665 buffer_64k.handle(), 1, &ds_region);
17666 m_errorMonitor->VerifyFound();
17667 }
17668
Dave Houlton584d51e2017-02-16 12:52:54 -070017669 // Test compressed formats, if supported
Jamie Madill35127872017-03-15 16:17:46 -040017670 VkPhysicalDeviceFeatures device_features = {};
Dave Houlton584d51e2017-02-16 12:52:54 -070017671 ASSERT_NO_FATAL_FAILURE(GetPhysicalDeviceFeatures(&device_features));
Dave Houltonf3229d52017-02-21 15:59:08 -070017672 if (!(device_features.textureCompressionBC || device_features.textureCompressionETC2 ||
17673 device_features.textureCompressionASTC_LDR)) {
17674 printf(" No compressed formats supported - block compression tests skipped.\n");
17675 } else {
Dave Houlton67e9b532017-03-02 17:00:10 -070017676 VkImageObj image_16k_4x4comp(m_device); // 128^2 texels as 32^2 compressed (4x4) blocks, 16k
17677 VkImageObj image_NPOT_4x4comp(m_device); // 130^2 texels as 33^2 compressed (4x4) blocks
Dave Houlton584d51e2017-02-16 12:52:54 -070017678 if (device_features.textureCompressionBC) {
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017679 image_16k_4x4comp.Init(128, 128, 1, VK_FORMAT_BC3_SRGB_BLOCK, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_OPTIMAL,
17680 0);
17681 image_NPOT_4x4comp.Init(130, 130, 1, VK_FORMAT_BC3_SRGB_BLOCK, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_OPTIMAL,
Dave Houlton67e9b532017-03-02 17:00:10 -070017682 0);
Dave Houlton584d51e2017-02-16 12:52:54 -070017683 } else if (device_features.textureCompressionETC2) {
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017684 image_16k_4x4comp.Init(128, 128, 1, VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK, VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
Dave Houlton584d51e2017-02-16 12:52:54 -070017685 VK_IMAGE_TILING_OPTIMAL, 0);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017686 image_NPOT_4x4comp.Init(130, 130, 1, VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK, VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
Dave Houlton67e9b532017-03-02 17:00:10 -070017687 VK_IMAGE_TILING_OPTIMAL, 0);
Dave Houlton584d51e2017-02-16 12:52:54 -070017688 } else {
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017689 image_16k_4x4comp.Init(128, 128, 1, VK_FORMAT_ASTC_4x4_UNORM_BLOCK, VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
Dave Houlton9dae7ec2017-03-01 16:23:25 -070017690 VK_IMAGE_TILING_OPTIMAL, 0);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017691 image_NPOT_4x4comp.Init(130, 130, 1, VK_FORMAT_ASTC_4x4_UNORM_BLOCK, VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
Dave Houlton67e9b532017-03-02 17:00:10 -070017692 VK_IMAGE_TILING_OPTIMAL, 0);
Dave Houlton584d51e2017-02-16 12:52:54 -070017693 }
17694 ASSERT_TRUE(image_16k_4x4comp.initialized());
Dave Houlton59a20702017-02-02 17:26:23 -070017695
Dave Houlton584d51e2017-02-16 12:52:54 -070017696 // Just fits
17697 m_errorMonitor->ExpectSuccess();
17698 region.imageExtent = {128, 128, 1};
17699 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
17700 buffer_16k.handle(), 1, &region);
17701 m_errorMonitor->VerifyNotFound();
Dave Houlton59a20702017-02-02 17:26:23 -070017702
Dave Houlton584d51e2017-02-16 12:52:54 -070017703 // with offset, too big for buffer
17704 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01246);
17705 region.bufferOffset = 16;
17706 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
17707 buffer_16k.handle(), 1, &region);
17708 m_errorMonitor->VerifyFound();
Dave Houlton67e9b532017-03-02 17:00:10 -070017709 region.bufferOffset = 0;
Dave Houlton59a20702017-02-02 17:26:23 -070017710
Dave Houlton67e9b532017-03-02 17:00:10 -070017711 // extents that are not a multiple of compressed block size
17712 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01275);
17713 region.imageExtent.width = 66;
17714 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_NPOT_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
17715 buffer_16k.handle(), 1, &region);
17716 m_errorMonitor->VerifyFound();
17717 region.imageExtent.width = 128;
17718
17719 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01276);
Dave Houlton9dae7ec2017-03-01 16:23:25 -070017720 region.imageExtent.height = 2;
Dave Houlton67e9b532017-03-02 17:00:10 -070017721 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_NPOT_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
17722 buffer_16k.handle(), 1, &region);
17723 m_errorMonitor->VerifyFound();
17724 region.imageExtent.height = 128;
17725
17726 // TODO: All available compressed formats are 2D, with block depth of 1. Unable to provoke VU_01277.
17727
17728 // non-multiple extents are allowed if at the far edge of a non-block-multiple image - these should pass
17729 m_errorMonitor->ExpectSuccess();
17730 region.imageExtent.width = 66;
17731 region.imageOffset.x = 64;
17732 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_NPOT_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
17733 buffer_16k.handle(), 1, &region);
17734 region.imageExtent.width = 16;
17735 region.imageOffset.x = 0;
17736 region.imageExtent.height = 2;
17737 region.imageOffset.y = 128;
17738 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_NPOT_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
Dave Houlton9dae7ec2017-03-01 16:23:25 -070017739 buffer_16k.handle(), 1, &region);
17740 m_errorMonitor->VerifyNotFound();
Dave Houlton67e9b532017-03-02 17:00:10 -070017741 region.imageOffset = {0, 0, 0};
Dave Houlton9dae7ec2017-03-01 16:23:25 -070017742
Dave Houlton584d51e2017-02-16 12:52:54 -070017743 // buffer offset must be a multiple of texel block size (16)
17744 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01274);
17745 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01263);
17746 region.imageExtent = {64, 64, 1};
17747 region.bufferOffset = 24;
17748 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
17749 buffer_16k.handle(), 1, &region);
17750 m_errorMonitor->VerifyFound();
Dave Houlton59a20702017-02-02 17:26:23 -070017751
Dave Houlton584d51e2017-02-16 12:52:54 -070017752 // rowlength not a multiple of block width (4)
17753 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01271);
17754 region.bufferOffset = 0;
17755 region.bufferRowLength = 130;
17756 region.bufferImageHeight = 0;
17757 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
17758 buffer_64k.handle(), 1, &region);
17759 m_errorMonitor->VerifyFound();
Dave Houlton59a20702017-02-02 17:26:23 -070017760
Dave Houlton584d51e2017-02-16 12:52:54 -070017761 // imageheight not a multiple of block height (4)
17762 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01272);
17763 region.bufferRowLength = 0;
17764 region.bufferImageHeight = 130;
17765 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
17766 buffer_64k.handle(), 1, &region);
17767 m_errorMonitor->VerifyFound();
Dave Houlton584d51e2017-02-16 12:52:54 -070017768 }
Dave Houlton59a20702017-02-02 17:26:23 -070017769}
17770
Tony Barbourd6673642016-05-05 14:46:39 -060017771TEST_F(VkLayerTest, MiscImageLayerTests) {
Mark Lobodzinskie6911292017-02-15 14:38:51 -070017772 TEST_DESCRIPTION("Image-related tests that don't belong elsewhare");
Tony Barbourd6673642016-05-05 14:46:39 -060017773
Tony Barbour1fa09702017-03-16 12:09:08 -060017774 ASSERT_NO_FATAL_FAILURE(Init());
Tony Barbourd6673642016-05-05 14:46:39 -060017775
Rene Lindsay135204f2016-12-22 17:11:09 -070017776 // TODO: Ideally we should check if a format is supported, before using it.
Tony Barbourd6673642016-05-05 14:46:39 -060017777 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017778 image.Init(128, 128, 1, VK_FORMAT_R16G16B16A16_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017779 VK_IMAGE_TILING_OPTIMAL, 0); // 64bpp
Tony Barbourd6673642016-05-05 14:46:39 -060017780 ASSERT_TRUE(image.initialized());
Tony Barbourd6673642016-05-05 14:46:39 -060017781 vk_testing::Buffer buffer;
17782 VkMemoryPropertyFlags reqs = 0;
Rene Lindsay135204f2016-12-22 17:11:09 -070017783 buffer.init_as_src(*m_device, 128 * 128 * 8, reqs);
Tony Barbourd6673642016-05-05 14:46:39 -060017784 VkBufferImageCopy region = {};
17785 region.bufferRowLength = 128;
17786 region.bufferImageHeight = 128;
17787 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17788 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
Mark Lobodzinski3702e932016-11-22 11:40:48 -070017789 region.imageSubresource.layerCount = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060017790 region.imageExtent.height = 4;
17791 region.imageExtent.width = 4;
17792 region.imageExtent.depth = 1;
Rene Lindsay135204f2016-12-22 17:11:09 -070017793
17794 VkImageObj image2(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017795 image2.Init(128, 128, 1, VK_FORMAT_R8G8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017796 VK_IMAGE_TILING_OPTIMAL, 0); // 16bpp
Rene Lindsay135204f2016-12-22 17:11:09 -070017797 ASSERT_TRUE(image2.initialized());
17798 vk_testing::Buffer buffer2;
17799 VkMemoryPropertyFlags reqs2 = 0;
17800 buffer2.init_as_src(*m_device, 128 * 128 * 2, reqs2);
17801 VkBufferImageCopy region2 = {};
17802 region2.bufferRowLength = 128;
17803 region2.bufferImageHeight = 128;
17804 region2.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17805 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
17806 region2.imageSubresource.layerCount = 1;
17807 region2.imageExtent.height = 4;
17808 region2.imageExtent.width = 4;
17809 region2.imageExtent.depth = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060017810 m_commandBuffer->BeginCommandBuffer();
Tony Barbourd6673642016-05-05 14:46:39 -060017811
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070017812 // Image must have offset.z of 0 and extent.depth of 1
17813 // Introduce failure by setting imageExtent.depth to 0
17814 region.imageExtent.depth = 0;
Dave Houlton59a20702017-02-02 17:26:23 -070017815 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01747);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070017816 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017817 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070017818 m_errorMonitor->VerifyFound();
17819
17820 region.imageExtent.depth = 1;
17821
17822 // Image must have offset.z of 0 and extent.depth of 1
17823 // Introduce failure by setting imageOffset.z to 4
Dave Houlton9dae7ec2017-03-01 16:23:25 -070017824 // Note: Also (unavoidably) triggers 'region exceeds image' #1228
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070017825 region.imageOffset.z = 4;
Dave Houlton59a20702017-02-02 17:26:23 -070017826 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01747);
Dave Houlton9dae7ec2017-03-01 16:23:25 -070017827 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01228);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070017828 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017829 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070017830 m_errorMonitor->VerifyFound();
17831
17832 region.imageOffset.z = 0;
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060017833 // BufferOffset must be a multiple of the calling command's VkImage parameter's texel size
17834 // Introduce failure by setting bufferOffset to 1 and 1/2 texels
Rene Lindsay135204f2016-12-22 17:11:09 -070017835 region.bufferOffset = 4;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070017836 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01263);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017837 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
17838 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060017839 m_errorMonitor->VerifyFound();
17840
17841 // BufferOffset must be a multiple of 4
17842 // Introduce failure by setting bufferOffset to a value not divisible by 4
Rene Lindsay135204f2016-12-22 17:11:09 -070017843 region2.bufferOffset = 6;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070017844 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01264);
Rene Lindsay135204f2016-12-22 17:11:09 -070017845 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer2.handle(), image2.handle(),
17846 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region2);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060017847 m_errorMonitor->VerifyFound();
17848
17849 // BufferRowLength must be 0, or greater than or equal to the width member of imageExtent
17850 region.bufferOffset = 0;
17851 region.imageExtent.height = 128;
17852 region.imageExtent.width = 128;
17853 // Introduce failure by setting bufferRowLength > 0 but less than width
17854 region.bufferRowLength = 64;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070017855 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01265);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017856 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
17857 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060017858 m_errorMonitor->VerifyFound();
17859
17860 // BufferImageHeight must be 0, or greater than or equal to the height member of imageExtent
17861 region.bufferRowLength = 128;
17862 // Introduce failure by setting bufferRowHeight > 0 but less than height
17863 region.bufferImageHeight = 64;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070017864 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01266);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017865 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
17866 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060017867 m_errorMonitor->VerifyFound();
17868
17869 region.bufferImageHeight = 128;
Tony Barbourd6673642016-05-05 14:46:39 -060017870 VkImageObj intImage1(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017871 intImage1.Init(128, 128, 1, VK_FORMAT_R8_UINT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
Rene Lindsaya35e1cb2016-12-26 10:30:05 -070017872 VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbourd6673642016-05-05 14:46:39 -060017873 VkImageObj intImage2(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017874 intImage2.Init(128, 128, 1, VK_FORMAT_R8_UINT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
Rene Lindsaya35e1cb2016-12-26 10:30:05 -070017875 VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbourd6673642016-05-05 14:46:39 -060017876 VkImageBlit blitRegion = {};
17877 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17878 blitRegion.srcSubresource.baseArrayLayer = 0;
17879 blitRegion.srcSubresource.layerCount = 1;
17880 blitRegion.srcSubresource.mipLevel = 0;
17881 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17882 blitRegion.dstSubresource.baseArrayLayer = 0;
17883 blitRegion.dstSubresource.layerCount = 1;
17884 blitRegion.dstSubresource.mipLevel = 0;
17885
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060017886 // Look for NULL-blit warning
Jeremy Hayesf8e749f2017-03-15 09:40:27 -060017887 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
17888 "vkCmdBlitImage: pRegions[0].srcOffsets specify a zero-volume area.");
17889 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
17890 "vkCmdBlitImage: pRegions[0].dstOffsets specify a zero-volume area.");
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017891 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.Layout(), intImage2.handle(),
17892 intImage2.Layout(), 1, &blitRegion, VK_FILTER_LINEAR);
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060017893 m_errorMonitor->VerifyFound();
17894
Petr Kraus4d718682017-05-18 03:38:41 +020017895 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02931);
Tony Barbourd6673642016-05-05 14:46:39 -060017896 VkImageMemoryBarrier img_barrier;
17897 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
17898 img_barrier.pNext = NULL;
17899 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
17900 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
17901 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
17902 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
17903 img_barrier.image = image.handle();
17904 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
17905 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
17906 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17907 img_barrier.subresourceRange.baseArrayLayer = 0;
17908 img_barrier.subresourceRange.baseMipLevel = 0;
Tony Barbourd6673642016-05-05 14:46:39 -060017909 img_barrier.subresourceRange.layerCount = 0;
17910 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017911 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
17912 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbourd6673642016-05-05 14:46:39 -060017913 m_errorMonitor->VerifyFound();
17914 img_barrier.subresourceRange.layerCount = 1;
17915}
17916
17917TEST_F(VkLayerTest, ImageFormatLimits) {
Tony Barbourd6673642016-05-05 14:46:39 -060017918 TEST_DESCRIPTION("Exceed the limits of image format ");
17919
Tony Barbour1fa09702017-03-16 12:09:08 -060017920 ASSERT_NO_FATAL_FAILURE(Init());
Jeremy Hayesbb63cc12017-03-20 15:33:01 -060017921
17922 VkFormat const format = VK_FORMAT_B8G8R8A8_UNORM;
17923 {
17924 VkFormatProperties properties;
17925 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), format, &properties);
17926 if (properties.linearTilingFeatures == 0) {
17927 printf(" Image format not supported; skipped.\n");
17928 return;
17929 }
17930 }
17931
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017932 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Tony Barbourd6673642016-05-05 14:46:39 -060017933 VkImageCreateInfo image_create_info = {};
17934 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17935 image_create_info.pNext = NULL;
17936 image_create_info.imageType = VK_IMAGE_TYPE_2D;
Jeremy Hayesbb63cc12017-03-20 15:33:01 -060017937 image_create_info.format = format;
Tony Barbourd6673642016-05-05 14:46:39 -060017938 image_create_info.extent.width = 32;
17939 image_create_info.extent.height = 32;
17940 image_create_info.extent.depth = 1;
17941 image_create_info.mipLevels = 1;
17942 image_create_info.arrayLayers = 1;
17943 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
17944 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
17945 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
17946 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
17947 image_create_info.flags = 0;
17948
17949 VkImage nullImg;
17950 VkImageFormatProperties imgFmtProps;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017951 vkGetPhysicalDeviceImageFormatProperties(gpu(), image_create_info.format, image_create_info.imageType, image_create_info.tiling,
17952 image_create_info.usage, image_create_info.flags, &imgFmtProps);
Rene Lindsayef5bc012017-01-06 15:38:00 -070017953 image_create_info.extent.width = imgFmtProps.maxExtent.width + 1;
Tony Barbourd6673642016-05-05 14:46:39 -060017954 // Expect INVALID_FORMAT_LIMITS_VIOLATION
17955 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
17956 m_errorMonitor->VerifyFound();
Rene Lindsayef5bc012017-01-06 15:38:00 -070017957 image_create_info.extent.width = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060017958
Tony Barbour0907e362017-03-09 15:05:30 -070017959 uint32_t maxDim =
17960 std::max(std::max(image_create_info.extent.width, image_create_info.extent.height), image_create_info.extent.depth);
17961 // If max mip levels exceeds image extents, skip the max mip levels test
17962 if ((imgFmtProps.maxMipLevels + 1) <= (floor(log2(maxDim)) + 1)) {
17963 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
17964 image_create_info.mipLevels = imgFmtProps.maxMipLevels + 1;
17965 // Expect INVALID_FORMAT_LIMITS_VIOLATION
17966 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
17967 m_errorMonitor->VerifyFound();
17968 image_create_info.mipLevels = 1;
17969 }
Tony Barbourd6673642016-05-05 14:46:39 -060017970
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017971 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060017972 image_create_info.arrayLayers = imgFmtProps.maxArrayLayers + 1;
17973 // Expect INVALID_FORMAT_LIMITS_VIOLATION
17974 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
17975 m_errorMonitor->VerifyFound();
17976 image_create_info.arrayLayers = 1;
17977
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017978 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is not supported by format");
Tony Barbourd6673642016-05-05 14:46:39 -060017979 int samples = imgFmtProps.sampleCounts >> 1;
17980 image_create_info.samples = (VkSampleCountFlagBits)samples;
17981 // Expect INVALID_FORMAT_LIMITS_VIOLATION
17982 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
17983 m_errorMonitor->VerifyFound();
17984 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
17985
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017986 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17987 "pCreateInfo->initialLayout, must be "
17988 "VK_IMAGE_LAYOUT_UNDEFINED or "
17989 "VK_IMAGE_LAYOUT_PREINITIALIZED");
Tony Barbourd6673642016-05-05 14:46:39 -060017990 image_create_info.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
17991 // Expect INVALID_LAYOUT
17992 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
17993 m_errorMonitor->VerifyFound();
17994 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
17995}
17996
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017997TEST_F(VkLayerTest, CopyImageSrcSizeExceeded) {
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017998 // Image copy with source region specified greater than src image size
Tony Barbour1fa09702017-03-16 12:09:08 -060017999 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskicea14992016-10-14 10:59:42 -060018000
Dave Houltonfc1a4052017-04-27 14:32:45 -060018001 // Create images with full mip chain
18002 VkImageCreateInfo ci;
18003 ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
18004 ci.pNext = NULL;
18005 ci.flags = 0;
18006 ci.imageType = VK_IMAGE_TYPE_3D;
18007 ci.format = VK_FORMAT_R8G8B8A8_UNORM;
18008 ci.extent = {32, 32, 8};
18009 ci.mipLevels = 6;
18010 ci.arrayLayers = 1;
18011 ci.samples = VK_SAMPLE_COUNT_1_BIT;
18012 ci.tiling = VK_IMAGE_TILING_OPTIMAL;
18013 ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
18014 ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
18015 ci.queueFamilyIndexCount = 0;
18016 ci.pQueueFamilyIndices = NULL;
18017 ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
18018
Mark Lobodzinskicea14992016-10-14 10:59:42 -060018019 VkImageObj src_image(m_device);
Dave Houltonfc1a4052017-04-27 14:32:45 -060018020 src_image.init(&ci);
18021 ASSERT_TRUE(src_image.initialized());
18022
18023 // Dest image with one more mip level
18024 ci.extent = {64, 64, 16};
18025 ci.mipLevels = 7;
18026 ci.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskicea14992016-10-14 10:59:42 -060018027 VkImageObj dst_image(m_device);
Dave Houltonfc1a4052017-04-27 14:32:45 -060018028 dst_image.init(&ci);
18029 ASSERT_TRUE(dst_image.initialized());
Mark Lobodzinskicea14992016-10-14 10:59:42 -060018030
Tony Barbour552f6c02016-12-21 14:34:07 -070018031 m_commandBuffer->BeginCommandBuffer();
Dave Houltonfc1a4052017-04-27 14:32:45 -060018032
Mark Lobodzinskicea14992016-10-14 10:59:42 -060018033 VkImageCopy copy_region;
Dave Houltonfc1a4052017-04-27 14:32:45 -060018034 copy_region.extent = {32, 32, 8};
Mark Lobodzinskicea14992016-10-14 10:59:42 -060018035 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskicea14992016-10-14 10:59:42 -060018036 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Dave Houltoncee81d02017-05-02 11:00:10 -060018037 copy_region.srcSubresource.mipLevel = 0;
18038 copy_region.dstSubresource.mipLevel = 0;
Dave Houltonfc1a4052017-04-27 14:32:45 -060018039 copy_region.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinskicea14992016-10-14 10:59:42 -060018040 copy_region.dstSubresource.baseArrayLayer = 0;
Dave Houltonfc1a4052017-04-27 14:32:45 -060018041 copy_region.srcSubresource.layerCount = 1;
18042 copy_region.dstSubresource.layerCount = 1;
18043 copy_region.srcOffset = {0, 0, 0};
18044 copy_region.dstOffset = {0, 0, 0};
18045
18046 m_errorMonitor->ExpectSuccess();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060018047 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
18048 &copy_region);
Dave Houltonfc1a4052017-04-27 14:32:45 -060018049 m_errorMonitor->VerifyNotFound();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060018050
Dave Houltonfc1a4052017-04-27 14:32:45 -060018051 // Source exceeded in x-dim, VU 01202
18052 copy_region.srcOffset.x = 4;
18053 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01175); // General "contained within" VU
18054 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01202);
18055 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
18056 &copy_region);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060018057 m_errorMonitor->VerifyFound();
Dave Houltonfc1a4052017-04-27 14:32:45 -060018058
18059 // Source exceeded in y-dim, VU 01203
18060 copy_region.srcOffset.x = 0;
18061 copy_region.extent.height = 48;
18062 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01175);
18063 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01203);
18064 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
18065 &copy_region);
18066 m_errorMonitor->VerifyFound();
18067
18068 // Source exceeded in z-dim, VU 01204
18069 copy_region.extent = {4, 4, 4};
18070 copy_region.srcSubresource.mipLevel = 2;
18071 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01175);
18072 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01204);
18073 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
18074 &copy_region);
18075 m_errorMonitor->VerifyFound();
18076
18077 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060018078}
18079
18080TEST_F(VkLayerTest, CopyImageDstSizeExceeded) {
Mark Lobodzinskicea14992016-10-14 10:59:42 -060018081 // Image copy with dest region specified greater than dest image size
Tony Barbour1fa09702017-03-16 12:09:08 -060018082 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskicea14992016-10-14 10:59:42 -060018083
Dave Houltonfc1a4052017-04-27 14:32:45 -060018084 // Create images with full mip chain
18085 VkImageCreateInfo ci;
18086 ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
18087 ci.pNext = NULL;
18088 ci.flags = 0;
18089 ci.imageType = VK_IMAGE_TYPE_3D;
18090 ci.format = VK_FORMAT_R8G8B8A8_UNORM;
18091 ci.extent = {32, 32, 8};
18092 ci.mipLevels = 6;
18093 ci.arrayLayers = 1;
18094 ci.samples = VK_SAMPLE_COUNT_1_BIT;
18095 ci.tiling = VK_IMAGE_TILING_OPTIMAL;
18096 ci.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
18097 ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
18098 ci.queueFamilyIndexCount = 0;
18099 ci.pQueueFamilyIndices = NULL;
18100 ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
18101
Mark Lobodzinskicea14992016-10-14 10:59:42 -060018102 VkImageObj dst_image(m_device);
Dave Houltonfc1a4052017-04-27 14:32:45 -060018103 dst_image.init(&ci);
18104 ASSERT_TRUE(dst_image.initialized());
18105
18106 // Src image with one more mip level
18107 ci.extent = {64, 64, 16};
18108 ci.mipLevels = 7;
18109 ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
18110 VkImageObj src_image(m_device);
18111 src_image.init(&ci);
18112 ASSERT_TRUE(src_image.initialized());
Mark Lobodzinskicea14992016-10-14 10:59:42 -060018113
Tony Barbour552f6c02016-12-21 14:34:07 -070018114 m_commandBuffer->BeginCommandBuffer();
Dave Houltonfc1a4052017-04-27 14:32:45 -060018115
Mark Lobodzinskicea14992016-10-14 10:59:42 -060018116 VkImageCopy copy_region;
Dave Houltonfc1a4052017-04-27 14:32:45 -060018117 copy_region.extent = {32, 32, 8};
Mark Lobodzinskicea14992016-10-14 10:59:42 -060018118 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskicea14992016-10-14 10:59:42 -060018119 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Dave Houltoncee81d02017-05-02 11:00:10 -060018120 copy_region.srcSubresource.mipLevel = 0;
18121 copy_region.dstSubresource.mipLevel = 0;
Dave Houltonfc1a4052017-04-27 14:32:45 -060018122 copy_region.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinskicea14992016-10-14 10:59:42 -060018123 copy_region.dstSubresource.baseArrayLayer = 0;
Dave Houltonfc1a4052017-04-27 14:32:45 -060018124 copy_region.srcSubresource.layerCount = 1;
18125 copy_region.dstSubresource.layerCount = 1;
18126 copy_region.srcOffset = {0, 0, 0};
18127 copy_region.dstOffset = {0, 0, 0};
18128
18129 m_errorMonitor->ExpectSuccess();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060018130 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
18131 &copy_region);
Dave Houltonfc1a4052017-04-27 14:32:45 -060018132 m_errorMonitor->VerifyNotFound();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060018133
Dave Houltonfc1a4052017-04-27 14:32:45 -060018134 // Dest exceeded in x-dim, VU 01205
18135 copy_region.dstOffset.x = 4;
18136 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01176); // General "contained within" VU
18137 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01205);
18138 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
18139 &copy_region);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060018140 m_errorMonitor->VerifyFound();
Dave Houltonfc1a4052017-04-27 14:32:45 -060018141
18142 // Dest exceeded in y-dim, VU 01206
18143 copy_region.dstOffset.x = 0;
18144 copy_region.extent.height = 48;
18145 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01176);
18146 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01206);
18147 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
18148 &copy_region);
18149 m_errorMonitor->VerifyFound();
18150
18151 // Dest exceeded in z-dim, VU 01207
18152 copy_region.extent = {4, 4, 4};
18153 copy_region.dstSubresource.mipLevel = 2;
18154 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01176);
18155 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01207);
18156 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
18157 &copy_region);
18158 m_errorMonitor->VerifyFound();
18159
18160 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060018161}
18162
Karl Schultz6addd812016-02-02 17:17:23 -070018163TEST_F(VkLayerTest, CopyImageFormatSizeMismatch) {
Karl Schultzbdb75952016-04-19 11:36:49 -060018164 VkResult err;
18165 bool pass;
18166
18167 // Create color images with different format sizes and try to copy between them
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070018168 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01184);
Karl Schultzbdb75952016-04-19 11:36:49 -060018169
Tony Barbour1fa09702017-03-16 12:09:08 -060018170 ASSERT_NO_FATAL_FAILURE(Init());
Karl Schultzbdb75952016-04-19 11:36:49 -060018171
18172 // Create two images of different types and try to copy between them
18173 VkImage srcImage;
18174 VkImage dstImage;
18175 VkDeviceMemory srcMem;
18176 VkDeviceMemory destMem;
18177 VkMemoryRequirements memReqs;
18178
18179 VkImageCreateInfo image_create_info = {};
18180 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
18181 image_create_info.pNext = NULL;
18182 image_create_info.imageType = VK_IMAGE_TYPE_2D;
18183 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
18184 image_create_info.extent.width = 32;
18185 image_create_info.extent.height = 32;
18186 image_create_info.extent.depth = 1;
18187 image_create_info.mipLevels = 1;
18188 image_create_info.arrayLayers = 1;
18189 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
18190 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
18191 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
18192 image_create_info.flags = 0;
18193
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018194 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060018195 ASSERT_VK_SUCCESS(err);
18196
18197 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
18198 // Introduce failure by creating second image with a different-sized format.
18199 image_create_info.format = VK_FORMAT_R5G5B5A1_UNORM_PACK16;
Tobin Ehlis6d4d1d52017-04-05 12:06:10 -060018200 VkFormatProperties properties;
18201 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), image_create_info.format, &properties);
18202 if (properties.optimalTilingFeatures == 0) {
Tobin Ehliscc980e12017-05-19 12:05:49 -060018203 vkDestroyImage(m_device->device(), srcImage, NULL);
Tobin Ehlis6d4d1d52017-04-05 12:06:10 -060018204 printf(" Image format not supported; skipped.\n");
18205 return;
18206 }
Karl Schultzbdb75952016-04-19 11:36:49 -060018207
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018208 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060018209 ASSERT_VK_SUCCESS(err);
18210
18211 // Allocate memory
18212 VkMemoryAllocateInfo memAlloc = {};
18213 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18214 memAlloc.pNext = NULL;
18215 memAlloc.allocationSize = 0;
18216 memAlloc.memoryTypeIndex = 0;
18217
18218 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
18219 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018220 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060018221 ASSERT_TRUE(pass);
18222 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
18223 ASSERT_VK_SUCCESS(err);
18224
18225 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
18226 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018227 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060018228 ASSERT_TRUE(pass);
18229 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
18230 ASSERT_VK_SUCCESS(err);
18231
18232 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
18233 ASSERT_VK_SUCCESS(err);
18234 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
18235 ASSERT_VK_SUCCESS(err);
18236
Tony Barbour552f6c02016-12-21 14:34:07 -070018237 m_commandBuffer->BeginCommandBuffer();
Karl Schultzbdb75952016-04-19 11:36:49 -060018238 VkImageCopy copyRegion;
18239 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
18240 copyRegion.srcSubresource.mipLevel = 0;
18241 copyRegion.srcSubresource.baseArrayLayer = 0;
18242 copyRegion.srcSubresource.layerCount = 0;
18243 copyRegion.srcOffset.x = 0;
18244 copyRegion.srcOffset.y = 0;
18245 copyRegion.srcOffset.z = 0;
18246 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
18247 copyRegion.dstSubresource.mipLevel = 0;
18248 copyRegion.dstSubresource.baseArrayLayer = 0;
18249 copyRegion.dstSubresource.layerCount = 0;
18250 copyRegion.dstOffset.x = 0;
18251 copyRegion.dstOffset.y = 0;
18252 copyRegion.dstOffset.z = 0;
18253 copyRegion.extent.width = 1;
18254 copyRegion.extent.height = 1;
18255 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018256 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070018257 m_commandBuffer->EndCommandBuffer();
Karl Schultzbdb75952016-04-19 11:36:49 -060018258
18259 m_errorMonitor->VerifyFound();
18260
18261 vkDestroyImage(m_device->device(), srcImage, NULL);
18262 vkDestroyImage(m_device->device(), dstImage, NULL);
18263 vkFreeMemory(m_device->device(), srcMem, NULL);
18264 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060018265}
18266
Karl Schultz6addd812016-02-02 17:17:23 -070018267TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch) {
18268 VkResult err;
18269 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060018270
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018271 // Create a depth image and a depth/stencil image and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018272 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
18273 "vkCmdCopyImage called with unmatched source and dest image depth");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060018274
Tony Barbour1fa09702017-03-16 12:09:08 -060018275 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -060018276 auto depth_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbourf887b162017-03-09 10:06:46 -070018277 if (!depth_format) {
18278 return;
18279 }
Mike Stroyana3082432015-09-25 13:39:21 -060018280
18281 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070018282 VkImage srcImage;
18283 VkImage dstImage;
18284 VkDeviceMemory srcMem;
18285 VkDeviceMemory destMem;
18286 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060018287
18288 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070018289 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
18290 image_create_info.pNext = NULL;
18291 image_create_info.imageType = VK_IMAGE_TYPE_2D;
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018292 image_create_info.format = VK_FORMAT_D32_SFLOAT;
Karl Schultz6addd812016-02-02 17:17:23 -070018293 image_create_info.extent.width = 32;
18294 image_create_info.extent.height = 32;
18295 image_create_info.extent.depth = 1;
18296 image_create_info.mipLevels = 1;
18297 image_create_info.arrayLayers = 1;
18298 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Youngad61f4b2017-04-07 08:59:56 -060018299 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Karl Schultz6addd812016-02-02 17:17:23 -070018300 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
18301 image_create_info.flags = 0;
Tobin Ehlis6d4d1d52017-04-05 12:06:10 -060018302 VkFormatProperties properties;
18303 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), image_create_info.format, &properties);
18304 if (properties.optimalTilingFeatures == 0) {
18305 printf(" Image format not supported; skipped.\n");
18306 return;
18307 }
Mike Stroyana3082432015-09-25 13:39:21 -060018308
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018309 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060018310 ASSERT_VK_SUCCESS(err);
18311
Karl Schultzbdb75952016-04-19 11:36:49 -060018312 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
18313
Mark Lobodzinskidb117632016-03-31 10:45:56 -060018314 // Introduce failure by creating second image with a depth/stencil format
Karl Schultz6addd812016-02-02 17:17:23 -070018315 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Tony Barbourf887b162017-03-09 10:06:46 -070018316 image_create_info.format = depth_format;
Mark Lobodzinski867787a2016-10-14 11:49:55 -060018317 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060018318
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018319 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060018320 ASSERT_VK_SUCCESS(err);
18321
18322 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018323 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070018324 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18325 memAlloc.pNext = NULL;
18326 memAlloc.allocationSize = 0;
18327 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018328
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060018329 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060018330 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018331 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060018332 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018333 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060018334 ASSERT_VK_SUCCESS(err);
18335
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018336 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060018337 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018338 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060018339 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018340 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060018341 ASSERT_VK_SUCCESS(err);
18342
18343 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
18344 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018345 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060018346 ASSERT_VK_SUCCESS(err);
18347
Tony Barbour552f6c02016-12-21 14:34:07 -070018348 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060018349 VkImageCopy copyRegion;
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018350 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060018351 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060018352 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018353 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018354 copyRegion.srcOffset.x = 0;
18355 copyRegion.srcOffset.y = 0;
18356 copyRegion.srcOffset.z = 0;
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018357 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018358 copyRegion.dstSubresource.mipLevel = 0;
18359 copyRegion.dstSubresource.baseArrayLayer = 0;
18360 copyRegion.dstSubresource.layerCount = 0;
18361 copyRegion.dstOffset.x = 0;
18362 copyRegion.dstOffset.y = 0;
18363 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018364 copyRegion.extent.width = 1;
18365 copyRegion.extent.height = 1;
18366 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018367 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070018368 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060018369
Chris Forbes8f36a8a2016-04-07 13:21:07 +120018370 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060018371
Chia-I Wuf7458c52015-10-26 21:10:41 +080018372 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018373 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080018374 vkFreeMemory(m_device->device(), srcMem, NULL);
18375 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060018376}
18377
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018378TEST_F(VkLayerTest, CopyImageSampleCountMismatch) {
18379 TEST_DESCRIPTION("Image copies with sample count mis-matches");
Dave Houlton33c22b72017-02-28 13:16:02 -070018380
Mark Lobodzinski77e590c2017-03-17 12:05:16 -060018381 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton33c22b72017-02-28 13:16:02 -070018382
18383 VkImageFormatProperties image_format_properties;
18384 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
18385 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT, 0,
18386 &image_format_properties);
18387
18388 if ((0 == (VK_SAMPLE_COUNT_2_BIT & image_format_properties.sampleCounts)) ||
18389 (0 == (VK_SAMPLE_COUNT_4_BIT & image_format_properties.sampleCounts))) {
18390 printf(" Image multi-sample support not found; skipped.\n");
18391 return;
18392 }
18393
18394 VkImageCreateInfo ci;
18395 ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
18396 ci.pNext = NULL;
18397 ci.flags = 0;
18398 ci.imageType = VK_IMAGE_TYPE_2D;
18399 ci.format = VK_FORMAT_R8G8B8A8_UNORM;
18400 ci.extent = {128, 128, 1};
18401 ci.mipLevels = 1;
18402 ci.arrayLayers = 1;
18403 ci.samples = VK_SAMPLE_COUNT_1_BIT;
18404 ci.tiling = VK_IMAGE_TILING_OPTIMAL;
18405 ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
18406 ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
18407 ci.queueFamilyIndexCount = 0;
18408 ci.pQueueFamilyIndices = NULL;
18409 ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
18410
18411 VkImageObj image1(m_device);
18412 image1.init(&ci);
18413 ASSERT_TRUE(image1.initialized());
18414
18415 ci.samples = VK_SAMPLE_COUNT_2_BIT;
18416 VkImageObj image2(m_device);
18417 image2.init(&ci);
18418 ASSERT_TRUE(image2.initialized());
18419
18420 ci.samples = VK_SAMPLE_COUNT_4_BIT;
18421 VkImageObj image4(m_device);
18422 image4.init(&ci);
18423 ASSERT_TRUE(image4.initialized());
18424
18425 m_commandBuffer->BeginCommandBuffer();
18426
18427 VkImageCopy copyRegion;
18428 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
18429 copyRegion.srcSubresource.mipLevel = 0;
18430 copyRegion.srcSubresource.baseArrayLayer = 0;
18431 copyRegion.srcSubresource.layerCount = 1;
18432 copyRegion.srcOffset = {0, 0, 0};
18433 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
18434 copyRegion.dstSubresource.mipLevel = 0;
18435 copyRegion.dstSubresource.baseArrayLayer = 0;
18436 copyRegion.dstSubresource.layerCount = 1;
18437 copyRegion.dstOffset = {0, 0, 0};
18438 copyRegion.extent = {128, 128, 1};
18439
18440 // Copy a single sample image to/from a multi-sample image
18441 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01185);
18442 vkCmdCopyImage(m_commandBuffer->GetBufferHandle(), image1.handle(), VK_IMAGE_LAYOUT_GENERAL, image4.handle(),
18443 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
18444 m_errorMonitor->VerifyFound();
18445
18446 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01185);
18447 vkCmdCopyImage(m_commandBuffer->GetBufferHandle(), image2.handle(), VK_IMAGE_LAYOUT_GENERAL, image1.handle(),
18448 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
18449 m_errorMonitor->VerifyFound();
18450
18451 // Copy between multi-sample images with different sample counts
18452 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01185);
18453 vkCmdCopyImage(m_commandBuffer->GetBufferHandle(), image2.handle(), VK_IMAGE_LAYOUT_GENERAL, image4.handle(),
18454 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
18455 m_errorMonitor->VerifyFound();
18456
18457 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01185);
18458 vkCmdCopyImage(m_commandBuffer->GetBufferHandle(), image4.handle(), VK_IMAGE_LAYOUT_GENERAL, image2.handle(),
18459 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
18460 m_errorMonitor->VerifyFound();
18461
18462 m_commandBuffer->EndCommandBuffer();
18463}
18464
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018465TEST_F(VkLayerTest, CopyImageAspectMismatch) {
18466 TEST_DESCRIPTION("Image copies with aspect mask errors");
Mark Lobodzinski77e590c2017-03-17 12:05:16 -060018467 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -060018468 auto ds_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbour9357d542017-03-24 15:42:21 -060018469 if (!ds_format) {
18470 return;
18471 }
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018472
Tobin Ehlis6d4d1d52017-04-05 12:06:10 -060018473 VkFormatProperties properties;
18474 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D32_SFLOAT, &properties);
18475 if (properties.optimalTilingFeatures == 0) {
18476 printf(" Image format VK_FORMAT_D32_SFLOAT not supported; skipped.\n");
18477 return;
18478 }
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018479 VkImageObj color_image(m_device), ds_image(m_device), depth_image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060018480 color_image.Init(128, 128, 1, VK_FORMAT_R32_SFLOAT, VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT);
Mark Youngad61f4b2017-04-07 08:59:56 -060018481 depth_image.Init(128, 128, 1, VK_FORMAT_D32_SFLOAT, VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
Dave Houlton11dcd5e2017-04-25 16:00:10 -060018482 VK_IMAGE_TILING_OPTIMAL, 0);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060018483 ds_image.Init(128, 128, 1, ds_format, VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
18484 VK_IMAGE_TILING_OPTIMAL, 0);
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018485 ASSERT_TRUE(color_image.initialized());
18486 ASSERT_TRUE(depth_image.initialized());
18487 ASSERT_TRUE(ds_image.initialized());
18488
18489 VkImageCopy copyRegion;
18490 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
18491 copyRegion.srcSubresource.mipLevel = 0;
18492 copyRegion.srcSubresource.baseArrayLayer = 0;
18493 copyRegion.srcSubresource.layerCount = 1;
18494 copyRegion.srcOffset = {0, 0, 0};
18495 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
18496 copyRegion.dstSubresource.mipLevel = 0;
18497 copyRegion.dstSubresource.baseArrayLayer = 0;
18498 copyRegion.dstSubresource.layerCount = 1;
18499 copyRegion.dstOffset = {64, 0, 0};
18500 copyRegion.extent = {64, 128, 1};
18501
18502 // Submitting command before command buffer is in recording state
Dave Houlton3c9fca72017-03-27 17:25:54 -060018503 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
18504 "You must call vkBeginCommandBuffer"); // VALIDATION_ERROR_01192);
18505 vkCmdCopyImage(m_commandBuffer->GetBufferHandle(), depth_image.handle(), VK_IMAGE_LAYOUT_GENERAL, depth_image.handle(),
18506 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018507 m_errorMonitor->VerifyFound();
18508
18509 m_commandBuffer->BeginCommandBuffer();
18510
18511 // Src and dest aspect masks don't match
18512 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT;
18513 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01197);
Dave Houlton3c9fca72017-03-27 17:25:54 -060018514 vkCmdCopyImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, ds_image.handle(),
18515 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018516 m_errorMonitor->VerifyFound();
18517 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
18518
18519 // Illegal combinations of aspect bits - VU 01221
Dave Houlton3c9fca72017-03-27 17:25:54 -060018520 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT; // color must be alone
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018521 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT;
18522 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01221);
18523 // These aspect/format mismatches are redundant but unavoidable here
18524 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01200);
18525 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01201);
Dave Houlton3c9fca72017-03-27 17:25:54 -060018526 vkCmdCopyImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_GENERAL, color_image.handle(),
18527 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018528 m_errorMonitor->VerifyFound();
18529 // Metadata aspect is illegal - VU 01222
18530 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
18531 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
18532 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01222);
18533 // These aspect/format mismatches are redundant but unavoidable here
Dave Houlton3c9fca72017-03-27 17:25:54 -060018534 vkCmdCopyImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_GENERAL, color_image.handle(),
18535 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018536 m_errorMonitor->VerifyFound();
18537
18538 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
18539 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
18540
18541 // Aspect mask doesn't match source image format - VU 01200
18542 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01200);
18543 // Again redundant but unavoidable when provoking vu01200 w/o vu01201
18544 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "unmatched source and dest image depth/stencil formats");
18545 vkCmdCopyImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_GENERAL, depth_image.handle(),
18546 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
18547 m_errorMonitor->VerifyFound();
18548
18549 // Aspect mask doesn't match dest image format - VU 01201
18550 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
18551 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
18552 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01201);
18553 // Again redundant but unavoidable when provoking vu01201 w/o vu01200
18554 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "unmatched source and dest image depth/stencil formats");
18555 vkCmdCopyImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_GENERAL, depth_image.handle(),
18556 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
18557 m_errorMonitor->VerifyFound();
18558
18559 m_commandBuffer->EndCommandBuffer();
18560}
18561
Karl Schultz6addd812016-02-02 17:17:23 -070018562TEST_F(VkLayerTest, ResolveImageLowSampleCount) {
18563 VkResult err;
18564 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060018565
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018566 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
18567 "vkCmdResolveImage called with source sample count less than 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060018568
Tony Barbour1fa09702017-03-16 12:09:08 -060018569 ASSERT_NO_FATAL_FAILURE(Init());
Mike Stroyana3082432015-09-25 13:39:21 -060018570
18571 // Create two images of sample count 1 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070018572 VkImage srcImage;
18573 VkImage dstImage;
18574 VkDeviceMemory srcMem;
18575 VkDeviceMemory destMem;
18576 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060018577
18578 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070018579 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
18580 image_create_info.pNext = NULL;
18581 image_create_info.imageType = VK_IMAGE_TYPE_2D;
18582 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
18583 image_create_info.extent.width = 32;
18584 image_create_info.extent.height = 1;
18585 image_create_info.extent.depth = 1;
18586 image_create_info.mipLevels = 1;
18587 image_create_info.arrayLayers = 1;
18588 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
18589 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
18590 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
18591 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018592
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018593 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060018594 ASSERT_VK_SUCCESS(err);
18595
Karl Schultz6addd812016-02-02 17:17:23 -070018596 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060018597
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018598 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060018599 ASSERT_VK_SUCCESS(err);
18600
18601 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018602 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070018603 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18604 memAlloc.pNext = NULL;
18605 memAlloc.allocationSize = 0;
18606 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018607
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060018608 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060018609 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018610 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060018611 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018612 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060018613 ASSERT_VK_SUCCESS(err);
18614
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018615 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060018616 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018617 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060018618 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018619 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060018620 ASSERT_VK_SUCCESS(err);
18621
18622 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
18623 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018624 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060018625 ASSERT_VK_SUCCESS(err);
18626
Tony Barbour552f6c02016-12-21 14:34:07 -070018627 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060018628 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070018629 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
18630 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060018631 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080018632 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060018633 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060018634 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130018635 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060018636 resolveRegion.srcOffset.x = 0;
18637 resolveRegion.srcOffset.y = 0;
18638 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080018639 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018640 resolveRegion.dstSubresource.mipLevel = 0;
18641 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130018642 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018643 resolveRegion.dstOffset.x = 0;
18644 resolveRegion.dstOffset.y = 0;
18645 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018646 resolveRegion.extent.width = 1;
18647 resolveRegion.extent.height = 1;
18648 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018649 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070018650 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060018651
Chris Forbes8f36a8a2016-04-07 13:21:07 +120018652 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060018653
Chia-I Wuf7458c52015-10-26 21:10:41 +080018654 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018655 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080018656 vkFreeMemory(m_device->device(), srcMem, NULL);
18657 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060018658}
18659
Karl Schultz6addd812016-02-02 17:17:23 -070018660TEST_F(VkLayerTest, ResolveImageHighSampleCount) {
18661 VkResult err;
18662 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060018663
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018664 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
18665 "vkCmdResolveImage called with dest sample count greater than 1.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060018666
Tony Barbour1fa09702017-03-16 12:09:08 -060018667 ASSERT_NO_FATAL_FAILURE(Init());
Mike Stroyana3082432015-09-25 13:39:21 -060018668
Chris Forbesa7530692016-05-08 12:35:39 +120018669 // Create two images of sample count 4 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070018670 VkImage srcImage;
18671 VkImage dstImage;
18672 VkDeviceMemory srcMem;
18673 VkDeviceMemory destMem;
18674 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060018675
18676 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070018677 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
18678 image_create_info.pNext = NULL;
18679 image_create_info.imageType = VK_IMAGE_TYPE_2D;
18680 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
18681 image_create_info.extent.width = 32;
18682 image_create_info.extent.height = 1;
18683 image_create_info.extent.depth = 1;
18684 image_create_info.mipLevels = 1;
18685 image_create_info.arrayLayers = 1;
Chris Forbesa7530692016-05-08 12:35:39 +120018686 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070018687 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
18688 // Note: Some implementations expect color attachment usage for any
18689 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018690 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070018691 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018692
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018693 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060018694 ASSERT_VK_SUCCESS(err);
18695
Karl Schultz6addd812016-02-02 17:17:23 -070018696 // Note: Some implementations expect color attachment usage for any
18697 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018698 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060018699
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018700 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060018701 ASSERT_VK_SUCCESS(err);
18702
18703 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018704 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070018705 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18706 memAlloc.pNext = NULL;
18707 memAlloc.allocationSize = 0;
18708 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018709
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060018710 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060018711 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018712 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060018713 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018714 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060018715 ASSERT_VK_SUCCESS(err);
18716
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018717 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060018718 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018719 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060018720 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018721 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060018722 ASSERT_VK_SUCCESS(err);
18723
18724 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
18725 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018726 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060018727 ASSERT_VK_SUCCESS(err);
18728
Tony Barbour552f6c02016-12-21 14:34:07 -070018729 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060018730 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070018731 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
18732 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060018733 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080018734 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060018735 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060018736 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130018737 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060018738 resolveRegion.srcOffset.x = 0;
18739 resolveRegion.srcOffset.y = 0;
18740 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080018741 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018742 resolveRegion.dstSubresource.mipLevel = 0;
18743 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130018744 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018745 resolveRegion.dstOffset.x = 0;
18746 resolveRegion.dstOffset.y = 0;
18747 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018748 resolveRegion.extent.width = 1;
18749 resolveRegion.extent.height = 1;
18750 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018751 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070018752 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060018753
Chris Forbes8f36a8a2016-04-07 13:21:07 +120018754 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060018755
Chia-I Wuf7458c52015-10-26 21:10:41 +080018756 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018757 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080018758 vkFreeMemory(m_device->device(), srcMem, NULL);
18759 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060018760}
18761
Karl Schultz6addd812016-02-02 17:17:23 -070018762TEST_F(VkLayerTest, ResolveImageFormatMismatch) {
18763 VkResult err;
18764 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060018765
Mark Lobodzinski50fbef12017-02-06 15:31:33 -070018766 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018767 "vkCmdResolveImage called with unmatched source and dest formats.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060018768
Tony Barbour1fa09702017-03-16 12:09:08 -060018769 ASSERT_NO_FATAL_FAILURE(Init());
Mike Stroyana3082432015-09-25 13:39:21 -060018770
18771 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070018772 VkImage srcImage;
18773 VkImage dstImage;
18774 VkDeviceMemory srcMem;
18775 VkDeviceMemory destMem;
18776 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060018777
18778 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070018779 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
18780 image_create_info.pNext = NULL;
18781 image_create_info.imageType = VK_IMAGE_TYPE_2D;
18782 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
18783 image_create_info.extent.width = 32;
18784 image_create_info.extent.height = 1;
18785 image_create_info.extent.depth = 1;
18786 image_create_info.mipLevels = 1;
18787 image_create_info.arrayLayers = 1;
18788 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
18789 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
18790 // Note: Some implementations expect color attachment usage for any
18791 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018792 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070018793 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018794
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018795 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060018796 ASSERT_VK_SUCCESS(err);
18797
Karl Schultz6addd812016-02-02 17:17:23 -070018798 // Set format to something other than source image
18799 image_create_info.format = VK_FORMAT_R32_SFLOAT;
18800 // Note: Some implementations expect color attachment usage for any
18801 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018802 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070018803 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060018804
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018805 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060018806 ASSERT_VK_SUCCESS(err);
18807
18808 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018809 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070018810 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18811 memAlloc.pNext = NULL;
18812 memAlloc.allocationSize = 0;
18813 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018814
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060018815 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060018816 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018817 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060018818 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018819 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060018820 ASSERT_VK_SUCCESS(err);
18821
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018822 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060018823 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018824 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060018825 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018826 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060018827 ASSERT_VK_SUCCESS(err);
18828
18829 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
18830 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018831 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060018832 ASSERT_VK_SUCCESS(err);
18833
Tony Barbour552f6c02016-12-21 14:34:07 -070018834 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060018835 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070018836 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
18837 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060018838 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080018839 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060018840 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060018841 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130018842 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060018843 resolveRegion.srcOffset.x = 0;
18844 resolveRegion.srcOffset.y = 0;
18845 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080018846 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018847 resolveRegion.dstSubresource.mipLevel = 0;
18848 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130018849 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018850 resolveRegion.dstOffset.x = 0;
18851 resolveRegion.dstOffset.y = 0;
18852 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018853 resolveRegion.extent.width = 1;
18854 resolveRegion.extent.height = 1;
18855 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018856 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070018857 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060018858
Chris Forbes8f36a8a2016-04-07 13:21:07 +120018859 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060018860
Chia-I Wuf7458c52015-10-26 21:10:41 +080018861 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018862 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080018863 vkFreeMemory(m_device->device(), srcMem, NULL);
18864 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060018865}
18866
Karl Schultz6addd812016-02-02 17:17:23 -070018867TEST_F(VkLayerTest, ResolveImageTypeMismatch) {
18868 VkResult err;
18869 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060018870
Mark Lobodzinski50fbef12017-02-06 15:31:33 -070018871 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018872 "vkCmdResolveImage called with unmatched source and dest image types.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060018873
Tony Barbour1fa09702017-03-16 12:09:08 -060018874 ASSERT_NO_FATAL_FAILURE(Init());
Mike Stroyana3082432015-09-25 13:39:21 -060018875
18876 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070018877 VkImage srcImage;
18878 VkImage dstImage;
18879 VkDeviceMemory srcMem;
18880 VkDeviceMemory destMem;
18881 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060018882
18883 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070018884 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
18885 image_create_info.pNext = NULL;
18886 image_create_info.imageType = VK_IMAGE_TYPE_2D;
18887 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
18888 image_create_info.extent.width = 32;
18889 image_create_info.extent.height = 1;
18890 image_create_info.extent.depth = 1;
18891 image_create_info.mipLevels = 1;
18892 image_create_info.arrayLayers = 1;
18893 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
18894 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
18895 // Note: Some implementations expect color attachment usage for any
18896 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018897 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070018898 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018899
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018900 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060018901 ASSERT_VK_SUCCESS(err);
18902
Karl Schultz6addd812016-02-02 17:17:23 -070018903 image_create_info.imageType = VK_IMAGE_TYPE_1D;
18904 // Note: Some implementations expect color attachment usage for any
18905 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018906 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070018907 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060018908
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018909 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060018910 ASSERT_VK_SUCCESS(err);
18911
18912 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018913 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070018914 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18915 memAlloc.pNext = NULL;
18916 memAlloc.allocationSize = 0;
18917 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018918
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060018919 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060018920 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018921 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060018922 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018923 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060018924 ASSERT_VK_SUCCESS(err);
18925
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018926 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060018927 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018928 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060018929 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018930 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060018931 ASSERT_VK_SUCCESS(err);
18932
18933 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
18934 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018935 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060018936 ASSERT_VK_SUCCESS(err);
18937
Tony Barbour552f6c02016-12-21 14:34:07 -070018938 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060018939 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070018940 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
18941 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060018942 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080018943 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060018944 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060018945 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130018946 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060018947 resolveRegion.srcOffset.x = 0;
18948 resolveRegion.srcOffset.y = 0;
18949 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080018950 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018951 resolveRegion.dstSubresource.mipLevel = 0;
18952 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130018953 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018954 resolveRegion.dstOffset.x = 0;
18955 resolveRegion.dstOffset.y = 0;
18956 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018957 resolveRegion.extent.width = 1;
18958 resolveRegion.extent.height = 1;
18959 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018960 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070018961 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060018962
Chris Forbes8f36a8a2016-04-07 13:21:07 +120018963 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060018964
Chia-I Wuf7458c52015-10-26 21:10:41 +080018965 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018966 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080018967 vkFreeMemory(m_device->device(), srcMem, NULL);
18968 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060018969}
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018970
Karl Schultz6addd812016-02-02 17:17:23 -070018971TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018972 // Create a single Image descriptor and cause it to first hit an error due
Karl Schultz6addd812016-02-02 17:17:23 -070018973 // to using a DS format, then cause it to hit error due to COLOR_BIT not
18974 // set in aspect
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018975 // The image format check comes 2nd in validation so we trigger it first,
18976 // then when we cause aspect fail next, bad format check will be preempted
Karl Schultz6addd812016-02-02 17:17:23 -070018977 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018978
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018979 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
18980 "Combination depth/stencil image formats can have only the ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060018981
Tony Barbour1fa09702017-03-16 12:09:08 -060018982 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -060018983 auto depth_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbourf887b162017-03-09 10:06:46 -070018984 if (!depth_format) {
18985 return;
18986 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060018987
Chia-I Wu1b99bb22015-10-27 19:25:11 +080018988 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070018989 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
18990 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018991
18992 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070018993 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
18994 ds_pool_ci.pNext = NULL;
18995 ds_pool_ci.maxSets = 1;
18996 ds_pool_ci.poolSizeCount = 1;
18997 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018998
18999 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019000 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060019001 ASSERT_VK_SUCCESS(err);
19002
19003 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070019004 dsl_binding.binding = 0;
19005 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
19006 dsl_binding.descriptorCount = 1;
19007 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
19008 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060019009
19010 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070019011 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
19012 ds_layout_ci.pNext = NULL;
19013 ds_layout_ci.bindingCount = 1;
19014 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060019015 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019016 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060019017 ASSERT_VK_SUCCESS(err);
19018
19019 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080019020 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080019021 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070019022 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060019023 alloc_info.descriptorPool = ds_pool;
19024 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019025 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060019026 ASSERT_VK_SUCCESS(err);
19027
Karl Schultz6addd812016-02-02 17:17:23 -070019028 VkImage image_bad;
19029 VkImage image_good;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060019030 // One bad format and one good format for Color attachment
Tony Barbourf887b162017-03-09 10:06:46 -070019031 const VkFormat tex_format_bad = depth_format;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060019032 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
Karl Schultz6addd812016-02-02 17:17:23 -070019033 const int32_t tex_width = 32;
19034 const int32_t tex_height = 32;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060019035
19036 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070019037 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
19038 image_create_info.pNext = NULL;
19039 image_create_info.imageType = VK_IMAGE_TYPE_2D;
19040 image_create_info.format = tex_format_bad;
19041 image_create_info.extent.width = tex_width;
19042 image_create_info.extent.height = tex_height;
19043 image_create_info.extent.depth = 1;
19044 image_create_info.mipLevels = 1;
19045 image_create_info.arrayLayers = 1;
19046 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
19047 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019048 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070019049 image_create_info.flags = 0;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060019050
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019051 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060019052 ASSERT_VK_SUCCESS(err);
19053 image_create_info.format = tex_format_good;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019054 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
19055 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_good);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060019056 ASSERT_VK_SUCCESS(err);
19057
Rene Lindsayf1e89c82016-12-28 13:18:31 -070019058 // ---Bind image memory---
19059 VkMemoryRequirements img_mem_reqs;
19060 vkGetImageMemoryRequirements(m_device->device(), image_bad, &img_mem_reqs);
19061 VkMemoryAllocateInfo image_alloc_info = {};
19062 image_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
19063 image_alloc_info.pNext = NULL;
19064 image_alloc_info.memoryTypeIndex = 0;
19065 image_alloc_info.allocationSize = img_mem_reqs.size;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019066 bool pass =
19067 m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &image_alloc_info, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
Rene Lindsayf1e89c82016-12-28 13:18:31 -070019068 ASSERT_TRUE(pass);
19069 VkDeviceMemory mem;
19070 err = vkAllocateMemory(m_device->device(), &image_alloc_info, NULL, &mem);
19071 ASSERT_VK_SUCCESS(err);
19072 err = vkBindImageMemory(m_device->device(), image_bad, mem, 0);
19073 ASSERT_VK_SUCCESS(err);
19074 // -----------------------
19075
Tobin Ehlisa1c28562015-10-23 16:00:08 -060019076 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130019077 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070019078 image_view_create_info.image = image_bad;
19079 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
19080 image_view_create_info.format = tex_format_bad;
19081 image_view_create_info.subresourceRange.baseArrayLayer = 0;
19082 image_view_create_info.subresourceRange.baseMipLevel = 0;
19083 image_view_create_info.subresourceRange.layerCount = 1;
19084 image_view_create_info.subresourceRange.levelCount = 1;
Rene Lindsayf1e89c82016-12-28 13:18:31 -070019085 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060019086
19087 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019088 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060019089
Chris Forbes8f36a8a2016-04-07 13:21:07 +120019090 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060019091
Chia-I Wuf7458c52015-10-26 21:10:41 +080019092 vkDestroyImage(m_device->device(), image_bad, NULL);
19093 vkDestroyImage(m_device->device(), image_good, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080019094 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
19095 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Rene Lindsayf1e89c82016-12-28 13:18:31 -070019096
19097 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060019098}
Tobin Ehlis6e23d772016-05-19 11:08:34 -060019099
19100TEST_F(VkLayerTest, ClearImageErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019101 TEST_DESCRIPTION(
19102 "Call ClearColorImage w/ a depth|stencil image and "
19103 "ClearDepthStencilImage with a color image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060019104
Tony Barbour1fa09702017-03-16 12:09:08 -060019105 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -060019106 auto depth_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbourf887b162017-03-09 10:06:46 -070019107 if (!depth_format) {
19108 return;
19109 }
Tobin Ehlis6e23d772016-05-19 11:08:34 -060019110 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19111
Tony Barbour552f6c02016-12-21 14:34:07 -070019112 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis6e23d772016-05-19 11:08:34 -060019113
19114 // Color image
19115 VkClearColorValue clear_color;
19116 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
19117 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
19118 const VkFormat color_format = VK_FORMAT_B8G8R8A8_UNORM;
19119 const int32_t img_width = 32;
19120 const int32_t img_height = 32;
19121 VkImageCreateInfo image_create_info = {};
19122 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
19123 image_create_info.pNext = NULL;
19124 image_create_info.imageType = VK_IMAGE_TYPE_2D;
19125 image_create_info.format = color_format;
19126 image_create_info.extent.width = img_width;
19127 image_create_info.extent.height = img_height;
19128 image_create_info.extent.depth = 1;
19129 image_create_info.mipLevels = 1;
19130 image_create_info.arrayLayers = 1;
19131 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
19132 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
19133 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
19134
19135 vk_testing::Image color_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019136 color_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060019137
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019138 const VkImageSubresourceRange color_range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060019139
19140 // Depth/Stencil image
19141 VkClearDepthStencilValue clear_value = {0};
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019142 reqs = 0; // don't need HOST_VISIBLE DS image
Tobin Ehlis6e23d772016-05-19 11:08:34 -060019143 VkImageCreateInfo ds_image_create_info = vk_testing::Image::create_info();
19144 ds_image_create_info.imageType = VK_IMAGE_TYPE_2D;
Tony Barbourf887b162017-03-09 10:06:46 -070019145 ds_image_create_info.format = depth_format;
Tobin Ehlis6e23d772016-05-19 11:08:34 -060019146 ds_image_create_info.extent.width = 64;
19147 ds_image_create_info.extent.height = 64;
19148 ds_image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Rene Lindsaya1fc64a2016-12-27 15:18:54 -070019149 ds_image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis6e23d772016-05-19 11:08:34 -060019150
19151 vk_testing::Image ds_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019152 ds_image.init(*m_device, (const VkImageCreateInfo &)ds_image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060019153
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019154 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 -060019155
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019156 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060019157
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019158 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tobin Ehlis6e23d772016-05-19 11:08:34 -060019159 &color_range);
19160
19161 m_errorMonitor->VerifyFound();
19162
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019163 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
19164 "vkCmdClearColorImage called with "
19165 "image created without "
19166 "VK_IMAGE_USAGE_TRANSFER_DST_BIT");
Tony Barbour26434b92016-06-02 09:43:50 -060019167
Rene Lindsaya1fc64a2016-12-27 15:18:54 -070019168 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tony Barbour26434b92016-06-02 09:43:50 -060019169 &color_range);
19170
19171 m_errorMonitor->VerifyFound();
19172
Tobin Ehlis6e23d772016-05-19 11:08:34 -060019173 // Call CmdClearDepthStencilImage with color image
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019174 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
19175 "vkCmdClearDepthStencilImage called without a depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060019176
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019177 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
19178 &clear_value, 1, &ds_range);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060019179
19180 m_errorMonitor->VerifyFound();
19181}
Tobin Ehliscde08892015-09-22 10:11:37 -060019182
Mike Schuchardt35fece12017-03-07 14:40:28 -070019183TEST_F(VkLayerTest, CommandQueueFlags) {
19184 TEST_DESCRIPTION(
19185 "Allocate a command buffer on a queue that does not support graphics and try to issue a "
19186 "graphics-only command");
19187
19188 ASSERT_NO_FATAL_FAILURE(Init());
19189
19190 uint32_t queueFamilyIndex = m_device->QueueFamilyWithoutCapabilities(VK_QUEUE_GRAPHICS_BIT);
Dave Houlton3c9fca72017-03-27 17:25:54 -060019191 if (queueFamilyIndex == UINT32_MAX) {
Mike Schuchardt35fece12017-03-07 14:40:28 -070019192 printf(" Non-graphics queue family not found; skipped.\n");
19193 return;
19194 } else {
19195 // Create command pool on a non-graphics queue
19196 VkCommandPoolObj command_pool(m_device, queueFamilyIndex);
19197
19198 // Setup command buffer on pool
19199 VkCommandBufferObj command_buffer(m_device, &command_pool);
19200 command_buffer.BeginCommandBuffer();
19201
19202 // Issue a graphics only command
19203 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01446);
19204 VkViewport viewport = {0, 0, 16, 16, 0, 1};
19205 command_buffer.SetViewport(0, 1, &viewport);
19206 m_errorMonitor->VerifyFound();
19207 }
19208}
19209
Mark Lobodzinskib8359282017-05-16 09:17:51 -060019210TEST_F(VkLayerTest, ExecuteUnrecordedCBs) {
19211 TEST_DESCRIPTION(
19212 "Attempt vkCmdExecuteCommands and then QueueSubmit with an unrecorded secondary and primary command buffer, respectively");
19213
19214 ASSERT_NO_FATAL_FAILURE(Init());
19215 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19216 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00155);
19217 // Allocate a secondary command buffer
19218 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
19219 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19220 command_buffer_allocate_info.commandPool = m_commandPool->handle();
19221 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
19222 command_buffer_allocate_info.commandBufferCount = 1;
19223 VkCommandBuffer secondary_command_buffer;
19224 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
19225 VkCommandBufferBeginInfo command_buffer_begin_info = {};
19226 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19227 command_buffer_begin_info.flags =
19228 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
19229 command_buffer_begin_info.pInheritanceInfo = nullptr;
19230
19231 // Now update primary cmd buffer to execute unrecorded secondary
19232 VkResult err = vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
19233 ASSERT_VK_SUCCESS(err);
19234 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
19235 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
19236 vkCmdEndRenderPass(m_commandBuffer->handle());
19237 err = vkEndCommandBuffer(m_commandBuffer->handle());
19238 ASSERT_VK_SUCCESS(err);
19239 m_errorMonitor->VerifyFound();
19240
19241 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00134);
19242 // Allocate a primary command buffer
19243 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19244 command_buffer_allocate_info.commandBufferCount = 1;
19245 VkCommandBuffer primary_command_buffer;
19246 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &primary_command_buffer));
19247
19248 // And submit the unrecorded command buffer
19249 VkSubmitInfo submit_info = {};
19250 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19251 submit_info.commandBufferCount = 1;
19252 submit_info.pCommandBuffers = &primary_command_buffer;
19253 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
19254 m_errorMonitor->VerifyFound();
19255}
19256
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019257// WSI Enabled Tests
19258//
Chris Forbes09368e42016-10-13 11:59:22 +130019259#if 0
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019260TEST_F(VkWsiEnabledLayerTest, TestEnabledWsi) {
19261
19262#if defined(VK_USE_PLATFORM_XCB_KHR)
19263 VkSurfaceKHR surface = VK_NULL_HANDLE;
19264
19265 VkResult err;
19266 bool pass;
19267 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
19268 VkSwapchainCreateInfoKHR swapchain_create_info = {};
19269 // uint32_t swapchain_image_count = 0;
19270 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
19271 // uint32_t image_index = 0;
19272 // VkPresentInfoKHR present_info = {};
19273
Tony Barbour1fa09702017-03-16 12:09:08 -060019274 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019275
19276 // Use the create function from one of the VK_KHR_*_surface extension in
19277 // order to create a surface, testing all known errors in the process,
19278 // before successfully creating a surface:
19279 // First, try to create a surface without a VkXcbSurfaceCreateInfoKHR:
19280 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo specified as NULL");
19281 err = vkCreateXcbSurfaceKHR(instance(), NULL, NULL, &surface);
19282 pass = (err != VK_SUCCESS);
19283 ASSERT_TRUE(pass);
19284 m_errorMonitor->VerifyFound();
19285
19286 // Next, try to create a surface with the wrong
19287 // VkXcbSurfaceCreateInfoKHR::sType:
19288 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
19289 xcb_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
19290 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
19291 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
19292 pass = (err != VK_SUCCESS);
19293 ASSERT_TRUE(pass);
19294 m_errorMonitor->VerifyFound();
19295
19296 // Create a native window, and then correctly create a surface:
19297 xcb_connection_t *connection;
19298 xcb_screen_t *screen;
19299 xcb_window_t xcb_window;
19300 xcb_intern_atom_reply_t *atom_wm_delete_window;
19301
19302 const xcb_setup_t *setup;
19303 xcb_screen_iterator_t iter;
19304 int scr;
19305 uint32_t value_mask, value_list[32];
19306 int width = 1;
19307 int height = 1;
19308
19309 connection = xcb_connect(NULL, &scr);
19310 ASSERT_TRUE(connection != NULL);
19311 setup = xcb_get_setup(connection);
19312 iter = xcb_setup_roots_iterator(setup);
19313 while (scr-- > 0)
19314 xcb_screen_next(&iter);
19315 screen = iter.data;
19316
19317 xcb_window = xcb_generate_id(connection);
19318
19319 value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
19320 value_list[0] = screen->black_pixel;
19321 value_list[1] = XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_STRUCTURE_NOTIFY;
19322
19323 xcb_create_window(connection, XCB_COPY_FROM_PARENT, xcb_window, screen->root, 0, 0, width, height, 0,
19324 XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual, value_mask, value_list);
19325
19326 /* Magic code that will send notification when window is destroyed */
19327 xcb_intern_atom_cookie_t cookie = xcb_intern_atom(connection, 1, 12, "WM_PROTOCOLS");
19328 xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply(connection, cookie, 0);
19329
19330 xcb_intern_atom_cookie_t cookie2 = xcb_intern_atom(connection, 0, 16, "WM_DELETE_WINDOW");
19331 atom_wm_delete_window = xcb_intern_atom_reply(connection, cookie2, 0);
19332 xcb_change_property(connection, XCB_PROP_MODE_REPLACE, xcb_window, (*reply).atom, 4, 32, 1, &(*atom_wm_delete_window).atom);
19333 free(reply);
19334
19335 xcb_map_window(connection, xcb_window);
19336
19337 // Force the x/y coordinates to 100,100 results are identical in consecutive
19338 // runs
19339 const uint32_t coords[] = { 100, 100 };
19340 xcb_configure_window(connection, xcb_window, XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, coords);
19341
19342 // Finally, try to correctly create a surface:
19343 xcb_create_info.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
19344 xcb_create_info.pNext = NULL;
19345 xcb_create_info.flags = 0;
19346 xcb_create_info.connection = connection;
19347 xcb_create_info.window = xcb_window;
19348 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
19349 pass = (err == VK_SUCCESS);
19350 ASSERT_TRUE(pass);
19351
19352 // Check if surface supports presentation:
19353
19354 // 1st, do so without having queried the queue families:
19355 VkBool32 supported = false;
19356 // TODO: Get the following error to come out:
19357 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
19358 "called before calling the vkGetPhysicalDeviceQueueFamilyProperties "
19359 "function");
19360 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
19361 pass = (err != VK_SUCCESS);
19362 // ASSERT_TRUE(pass);
19363 // m_errorMonitor->VerifyFound();
19364
19365 // Next, query a queue family index that's too large:
19366 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
19367 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 100000, surface, &supported);
19368 pass = (err != VK_SUCCESS);
19369 ASSERT_TRUE(pass);
19370 m_errorMonitor->VerifyFound();
19371
19372 // Finally, do so correctly:
19373 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
19374 // SUPPORTED
19375 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
19376 pass = (err == VK_SUCCESS);
19377 ASSERT_TRUE(pass);
19378
19379 // Before proceeding, try to create a swapchain without having called
19380 // vkGetPhysicalDeviceSurfaceCapabilitiesKHR():
19381 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
19382 swapchain_create_info.pNext = NULL;
19383 swapchain_create_info.flags = 0;
19384 swapchain_create_info.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
19385 swapchain_create_info.surface = surface;
19386 swapchain_create_info.imageArrayLayers = 1;
19387 swapchain_create_info.preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
19388 swapchain_create_info.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
19389 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
19390 "called before calling vkGetPhysicalDeviceSurfaceCapabilitiesKHR().");
19391 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
19392 pass = (err != VK_SUCCESS);
19393 ASSERT_TRUE(pass);
19394 m_errorMonitor->VerifyFound();
19395
19396 // Get the surface capabilities:
19397 VkSurfaceCapabilitiesKHR surface_capabilities;
19398
19399 // Do so correctly (only error logged by this entrypoint is if the
19400 // extension isn't enabled):
19401 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &surface_capabilities);
19402 pass = (err == VK_SUCCESS);
19403 ASSERT_TRUE(pass);
19404
19405 // Get the surface formats:
19406 uint32_t surface_format_count;
19407
19408 // First, try without a pointer to surface_format_count:
19409 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSurfaceFormatCount "
19410 "specified as NULL");
19411 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, NULL, NULL);
19412 pass = (err == VK_SUCCESS);
19413 ASSERT_TRUE(pass);
19414 m_errorMonitor->VerifyFound();
19415
19416 // Next, call with a non-NULL pSurfaceFormats, even though we haven't
19417 // correctly done a 1st try (to get the count):
19418 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
19419 surface_format_count = 0;
19420 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, (VkSurfaceFormatKHR *)&surface_format_count);
19421 pass = (err == VK_SUCCESS);
19422 ASSERT_TRUE(pass);
19423 m_errorMonitor->VerifyFound();
19424
19425 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
19426 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
19427 pass = (err == VK_SUCCESS);
19428 ASSERT_TRUE(pass);
19429
19430 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
19431 VkSurfaceFormatKHR *surface_formats = (VkSurfaceFormatKHR *)malloc(surface_format_count * sizeof(VkSurfaceFormatKHR));
19432
19433 // Next, do a 2nd try with surface_format_count being set too high:
19434 surface_format_count += 5;
19435 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
19436 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
19437 pass = (err == VK_SUCCESS);
19438 ASSERT_TRUE(pass);
19439 m_errorMonitor->VerifyFound();
19440
19441 // Finally, do a correct 1st and 2nd try:
19442 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
19443 pass = (err == VK_SUCCESS);
19444 ASSERT_TRUE(pass);
19445 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
19446 pass = (err == VK_SUCCESS);
19447 ASSERT_TRUE(pass);
19448
19449 // Get the surface present modes:
19450 uint32_t surface_present_mode_count;
19451
19452 // First, try without a pointer to surface_format_count:
19453 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pPresentModeCount "
19454 "specified as NULL");
19455
19456 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, NULL, NULL);
19457 pass = (err == VK_SUCCESS);
19458 ASSERT_TRUE(pass);
19459 m_errorMonitor->VerifyFound();
19460
19461 // Next, call with a non-NULL VkPresentModeKHR, even though we haven't
19462 // correctly done a 1st try (to get the count):
19463 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
19464 surface_present_mode_count = 0;
19465 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count,
19466 (VkPresentModeKHR *)&surface_present_mode_count);
19467 pass = (err == VK_SUCCESS);
19468 ASSERT_TRUE(pass);
19469 m_errorMonitor->VerifyFound();
19470
19471 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
19472 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
19473 pass = (err == VK_SUCCESS);
19474 ASSERT_TRUE(pass);
19475
19476 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
19477 VkPresentModeKHR *surface_present_modes = (VkPresentModeKHR *)malloc(surface_present_mode_count * sizeof(VkPresentModeKHR));
19478
19479 // Next, do a 2nd try with surface_format_count being set too high:
19480 surface_present_mode_count += 5;
19481 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
19482 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
19483 pass = (err == VK_SUCCESS);
19484 ASSERT_TRUE(pass);
19485 m_errorMonitor->VerifyFound();
19486
19487 // Finally, do a correct 1st and 2nd try:
19488 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
19489 pass = (err == VK_SUCCESS);
19490 ASSERT_TRUE(pass);
19491 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
19492 pass = (err == VK_SUCCESS);
19493 ASSERT_TRUE(pass);
19494
19495 // Create a swapchain:
19496
19497 // First, try without a pointer to swapchain_create_info:
19498 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo "
19499 "specified as NULL");
19500
19501 err = vkCreateSwapchainKHR(m_device->device(), NULL, NULL, &swapchain);
19502 pass = (err != VK_SUCCESS);
19503 ASSERT_TRUE(pass);
19504 m_errorMonitor->VerifyFound();
19505
19506 // Next, call with a non-NULL swapchain_create_info, that has the wrong
19507 // sType:
19508 swapchain_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
19509 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
19510
19511 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
19512 pass = (err != VK_SUCCESS);
19513 ASSERT_TRUE(pass);
19514 m_errorMonitor->VerifyFound();
19515
19516 // Next, call with a NULL swapchain pointer:
19517 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
19518 swapchain_create_info.pNext = NULL;
19519 swapchain_create_info.flags = 0;
19520 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSwapchain "
19521 "specified as NULL");
19522
19523 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, NULL);
19524 pass = (err != VK_SUCCESS);
19525 ASSERT_TRUE(pass);
19526 m_errorMonitor->VerifyFound();
19527
19528 // TODO: Enhance swapchain layer so that
19529 // swapchain_create_info.queueFamilyIndexCount is checked against something?
19530
19531 // Next, call with a queue family index that's too large:
19532 uint32_t queueFamilyIndex[2] = { 100000, 0 };
19533 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
19534 swapchain_create_info.queueFamilyIndexCount = 2;
19535 swapchain_create_info.pQueueFamilyIndices = queueFamilyIndex;
19536 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
19537 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
19538 pass = (err != VK_SUCCESS);
19539 ASSERT_TRUE(pass);
19540 m_errorMonitor->VerifyFound();
19541
19542 // Next, call a queueFamilyIndexCount that's too small for CONCURRENT:
19543 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
19544 swapchain_create_info.queueFamilyIndexCount = 1;
19545 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
19546 "but with a bad value(s) for pCreateInfo->queueFamilyIndexCount or "
19547 "pCreateInfo->pQueueFamilyIndices).");
19548 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
19549 pass = (err != VK_SUCCESS);
19550 ASSERT_TRUE(pass);
19551 m_errorMonitor->VerifyFound();
19552
19553 // Next, call with an invalid imageSharingMode:
19554 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_MAX_ENUM;
19555 swapchain_create_info.queueFamilyIndexCount = 1;
19556 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
19557 "called with a non-supported pCreateInfo->imageSharingMode (i.e.");
19558 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
19559 pass = (err != VK_SUCCESS);
19560 ASSERT_TRUE(pass);
19561 m_errorMonitor->VerifyFound();
19562 // Fix for the future:
19563 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
19564 // SUPPORTED
19565 swapchain_create_info.queueFamilyIndexCount = 0;
19566 queueFamilyIndex[0] = 0;
19567 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
19568
19569 // TODO: CONTINUE TESTING VALIDATION OF vkCreateSwapchainKHR() ...
19570 // Get the images from a swapchain:
19571 // Acquire an image from a swapchain:
19572 // Present an image to a swapchain:
19573 // Destroy the swapchain:
19574
19575 // TODOs:
19576 //
19577 // - Try destroying the device without first destroying the swapchain
19578 //
19579 // - Try destroying the device without first destroying the surface
19580 //
19581 // - Try destroying the surface without first destroying the swapchain
19582
19583 // Destroy the surface:
19584 vkDestroySurfaceKHR(instance(), surface, NULL);
19585
19586 // Tear down the window:
19587 xcb_destroy_window(connection, xcb_window);
19588 xcb_disconnect(connection);
19589
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019590#else // VK_USE_PLATFORM_XCB_KHR
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019591 return;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019592#endif // VK_USE_PLATFORM_XCB_KHR
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019593}
Chris Forbes09368e42016-10-13 11:59:22 +130019594#endif
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019595
19596//
19597// POSITIVE VALIDATION TESTS
19598//
19599// These tests do not expect to encounter ANY validation errors pass only if this is true
19600
Mark Lobodzinski781aeb52017-02-22 10:57:53 -070019601TEST_F(VkPositiveLayerTest, SecondaryCommandBufferClearColorAttachments) {
19602 TEST_DESCRIPTION("Create a secondary command buffer and record a CmdClearAttachments call into it");
Tony Barbour1fa09702017-03-16 12:09:08 -060019603 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski781aeb52017-02-22 10:57:53 -070019604 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19605
19606 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
19607 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mike Schuchardt06304c22017-03-01 17:09:09 -070019608 command_buffer_allocate_info.commandPool = m_commandPool->handle();
Mark Lobodzinski781aeb52017-02-22 10:57:53 -070019609 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
19610 command_buffer_allocate_info.commandBufferCount = 1;
19611
19612 VkCommandBuffer secondary_command_buffer;
19613 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
19614 VkCommandBufferBeginInfo command_buffer_begin_info = {};
19615 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
19616 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
19617 command_buffer_inheritance_info.renderPass = m_renderPass;
19618 command_buffer_inheritance_info.framebuffer = m_framebuffer;
19619
19620 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19621 command_buffer_begin_info.flags =
19622 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
19623 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
19624
19625 vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
19626 VkClearAttachment color_attachment;
19627 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
19628 color_attachment.clearValue.color.float32[0] = 0;
19629 color_attachment.clearValue.color.float32[1] = 0;
19630 color_attachment.clearValue.color.float32[2] = 0;
19631 color_attachment.clearValue.color.float32[3] = 0;
19632 color_attachment.colorAttachment = 0;
19633 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
19634 vkCmdClearAttachments(secondary_command_buffer, 1, &color_attachment, 1, &clear_rect);
19635}
19636
Tobin Ehlise0006882016-11-03 10:14:28 -060019637TEST_F(VkPositiveLayerTest, SecondaryCommandBufferImageLayoutTransitions) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019638 TEST_DESCRIPTION(
19639 "Perform an image layout transition in a secondary command buffer followed "
19640 "by a transition in the primary.");
Tobin Ehlise0006882016-11-03 10:14:28 -060019641 VkResult err;
19642 m_errorMonitor->ExpectSuccess();
Tony Barbour1fa09702017-03-16 12:09:08 -060019643 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -060019644 auto depth_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbourf887b162017-03-09 10:06:46 -070019645 if (!depth_format) {
19646 return;
19647 }
Tobin Ehlise0006882016-11-03 10:14:28 -060019648 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19649 // Allocate a secondary and primary cmd buffer
19650 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
19651 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mike Schuchardt06304c22017-03-01 17:09:09 -070019652 command_buffer_allocate_info.commandPool = m_commandPool->handle();
Tobin Ehlise0006882016-11-03 10:14:28 -060019653 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
19654 command_buffer_allocate_info.commandBufferCount = 1;
19655
19656 VkCommandBuffer secondary_command_buffer;
19657 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
19658 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19659 VkCommandBuffer primary_command_buffer;
19660 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &primary_command_buffer));
19661 VkCommandBufferBeginInfo command_buffer_begin_info = {};
19662 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
19663 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
19664 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19665 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
19666 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
19667
19668 err = vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
19669 ASSERT_VK_SUCCESS(err);
19670 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060019671 image.Init(128, 128, 1, depth_format, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Tobin Ehlise0006882016-11-03 10:14:28 -060019672 ASSERT_TRUE(image.initialized());
19673 VkImageMemoryBarrier img_barrier = {};
19674 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
19675 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
19676 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
19677 img_barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
19678 img_barrier.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19679 img_barrier.image = image.handle();
19680 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
19681 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
19682 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
19683 img_barrier.subresourceRange.baseArrayLayer = 0;
19684 img_barrier.subresourceRange.baseMipLevel = 0;
19685 img_barrier.subresourceRange.layerCount = 1;
19686 img_barrier.subresourceRange.levelCount = 1;
19687 vkCmdPipelineBarrier(secondary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr,
19688 0, nullptr, 1, &img_barrier);
19689 err = vkEndCommandBuffer(secondary_command_buffer);
19690 ASSERT_VK_SUCCESS(err);
19691
19692 // Now update primary cmd buffer to execute secondary and transitions image
19693 command_buffer_begin_info.pInheritanceInfo = nullptr;
19694 err = vkBeginCommandBuffer(primary_command_buffer, &command_buffer_begin_info);
19695 ASSERT_VK_SUCCESS(err);
19696 vkCmdExecuteCommands(primary_command_buffer, 1, &secondary_command_buffer);
19697 VkImageMemoryBarrier img_barrier2 = {};
19698 img_barrier2.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
19699 img_barrier2.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
19700 img_barrier2.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
19701 img_barrier2.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19702 img_barrier2.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19703 img_barrier2.image = image.handle();
19704 img_barrier2.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
19705 img_barrier2.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
19706 img_barrier2.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
19707 img_barrier2.subresourceRange.baseArrayLayer = 0;
19708 img_barrier2.subresourceRange.baseMipLevel = 0;
19709 img_barrier2.subresourceRange.layerCount = 1;
19710 img_barrier2.subresourceRange.levelCount = 1;
19711 vkCmdPipelineBarrier(primary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
19712 nullptr, 1, &img_barrier2);
19713 err = vkEndCommandBuffer(primary_command_buffer);
19714 ASSERT_VK_SUCCESS(err);
19715 VkSubmitInfo submit_info = {};
19716 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19717 submit_info.commandBufferCount = 1;
19718 submit_info.pCommandBuffers = &primary_command_buffer;
19719 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
19720 ASSERT_VK_SUCCESS(err);
19721 m_errorMonitor->VerifyNotFound();
19722 err = vkDeviceWaitIdle(m_device->device());
19723 ASSERT_VK_SUCCESS(err);
Mike Schuchardt06304c22017-03-01 17:09:09 -070019724 vkFreeCommandBuffers(m_device->device(), m_commandPool->handle(), 1, &secondary_command_buffer);
19725 vkFreeCommandBuffers(m_device->device(), m_commandPool->handle(), 1, &primary_command_buffer);
Tobin Ehlise0006882016-11-03 10:14:28 -060019726}
19727
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019728// This is a positive test. No failures are expected.
19729TEST_F(VkPositiveLayerTest, IgnoreUnrelatedDescriptor) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019730 TEST_DESCRIPTION(
19731 "Ensure that the vkUpdateDescriptorSets validation code "
19732 "is ignoring VkWriteDescriptorSet members that are not "
19733 "related to the descriptor type specified by "
19734 "VkWriteDescriptorSet::descriptorType. Correct "
19735 "validation behavior will result in the test running to "
19736 "completion without validation errors.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019737
19738 const uintptr_t invalid_ptr = 0xcdcdcdcd;
19739
Tony Barbour1fa09702017-03-16 12:09:08 -060019740 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019741
19742 // Image Case
19743 {
19744 m_errorMonitor->ExpectSuccess();
19745
19746 VkImage image;
19747 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
19748 const int32_t tex_width = 32;
19749 const int32_t tex_height = 32;
19750 VkImageCreateInfo image_create_info = {};
19751 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
19752 image_create_info.pNext = NULL;
19753 image_create_info.imageType = VK_IMAGE_TYPE_2D;
19754 image_create_info.format = tex_format;
19755 image_create_info.extent.width = tex_width;
19756 image_create_info.extent.height = tex_height;
19757 image_create_info.extent.depth = 1;
19758 image_create_info.mipLevels = 1;
19759 image_create_info.arrayLayers = 1;
19760 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
19761 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
19762 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
19763 image_create_info.flags = 0;
19764 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
19765 ASSERT_VK_SUCCESS(err);
19766
19767 VkMemoryRequirements memory_reqs;
19768 VkDeviceMemory image_memory;
19769 bool pass;
19770 VkMemoryAllocateInfo memory_info = {};
19771 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
19772 memory_info.pNext = NULL;
19773 memory_info.allocationSize = 0;
19774 memory_info.memoryTypeIndex = 0;
19775 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
19776 memory_info.allocationSize = memory_reqs.size;
19777 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
19778 ASSERT_TRUE(pass);
19779 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
19780 ASSERT_VK_SUCCESS(err);
19781 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
19782 ASSERT_VK_SUCCESS(err);
19783
19784 VkImageViewCreateInfo image_view_create_info = {};
19785 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
19786 image_view_create_info.image = image;
19787 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
19788 image_view_create_info.format = tex_format;
19789 image_view_create_info.subresourceRange.layerCount = 1;
19790 image_view_create_info.subresourceRange.baseMipLevel = 0;
19791 image_view_create_info.subresourceRange.levelCount = 1;
19792 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
19793
19794 VkImageView view;
19795 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
19796 ASSERT_VK_SUCCESS(err);
19797
19798 VkDescriptorPoolSize ds_type_count = {};
19799 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
19800 ds_type_count.descriptorCount = 1;
19801
19802 VkDescriptorPoolCreateInfo ds_pool_ci = {};
19803 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
19804 ds_pool_ci.pNext = NULL;
19805 ds_pool_ci.maxSets = 1;
19806 ds_pool_ci.poolSizeCount = 1;
19807 ds_pool_ci.pPoolSizes = &ds_type_count;
19808
19809 VkDescriptorPool ds_pool;
19810 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
19811 ASSERT_VK_SUCCESS(err);
19812
19813 VkDescriptorSetLayoutBinding dsl_binding = {};
19814 dsl_binding.binding = 0;
19815 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
19816 dsl_binding.descriptorCount = 1;
19817 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
19818 dsl_binding.pImmutableSamplers = NULL;
19819
19820 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
19821 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
19822 ds_layout_ci.pNext = NULL;
19823 ds_layout_ci.bindingCount = 1;
19824 ds_layout_ci.pBindings = &dsl_binding;
19825 VkDescriptorSetLayout ds_layout;
19826 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
19827 ASSERT_VK_SUCCESS(err);
19828
19829 VkDescriptorSet descriptor_set;
19830 VkDescriptorSetAllocateInfo alloc_info = {};
19831 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
19832 alloc_info.descriptorSetCount = 1;
19833 alloc_info.descriptorPool = ds_pool;
19834 alloc_info.pSetLayouts = &ds_layout;
19835 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
19836 ASSERT_VK_SUCCESS(err);
19837
19838 VkDescriptorImageInfo image_info = {};
19839 image_info.imageView = view;
19840 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
19841
19842 VkWriteDescriptorSet descriptor_write;
19843 memset(&descriptor_write, 0, sizeof(descriptor_write));
19844 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
19845 descriptor_write.dstSet = descriptor_set;
19846 descriptor_write.dstBinding = 0;
19847 descriptor_write.descriptorCount = 1;
19848 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
19849 descriptor_write.pImageInfo = &image_info;
19850
19851 // Set pBufferInfo and pTexelBufferView to invalid values, which should
19852 // be
19853 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE.
19854 // This will most likely produce a crash if the parameter_validation
19855 // layer
19856 // does not correctly ignore pBufferInfo.
19857 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
19858 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
19859
19860 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
19861
19862 m_errorMonitor->VerifyNotFound();
19863
19864 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
19865 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
19866 vkDestroyImageView(m_device->device(), view, NULL);
19867 vkDestroyImage(m_device->device(), image, NULL);
19868 vkFreeMemory(m_device->device(), image_memory, NULL);
19869 }
19870
19871 // Buffer Case
19872 {
19873 m_errorMonitor->ExpectSuccess();
19874
19875 VkBuffer buffer;
19876 uint32_t queue_family_index = 0;
19877 VkBufferCreateInfo buffer_create_info = {};
19878 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
19879 buffer_create_info.size = 1024;
19880 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
19881 buffer_create_info.queueFamilyIndexCount = 1;
19882 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
19883
19884 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
19885 ASSERT_VK_SUCCESS(err);
19886
19887 VkMemoryRequirements memory_reqs;
19888 VkDeviceMemory buffer_memory;
19889 bool pass;
19890 VkMemoryAllocateInfo memory_info = {};
19891 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
19892 memory_info.pNext = NULL;
19893 memory_info.allocationSize = 0;
19894 memory_info.memoryTypeIndex = 0;
19895
19896 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
19897 memory_info.allocationSize = memory_reqs.size;
19898 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
19899 ASSERT_TRUE(pass);
19900
19901 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
19902 ASSERT_VK_SUCCESS(err);
19903 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
19904 ASSERT_VK_SUCCESS(err);
19905
19906 VkDescriptorPoolSize ds_type_count = {};
19907 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
19908 ds_type_count.descriptorCount = 1;
19909
19910 VkDescriptorPoolCreateInfo ds_pool_ci = {};
19911 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
19912 ds_pool_ci.pNext = NULL;
19913 ds_pool_ci.maxSets = 1;
19914 ds_pool_ci.poolSizeCount = 1;
19915 ds_pool_ci.pPoolSizes = &ds_type_count;
19916
19917 VkDescriptorPool ds_pool;
19918 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
19919 ASSERT_VK_SUCCESS(err);
19920
19921 VkDescriptorSetLayoutBinding dsl_binding = {};
19922 dsl_binding.binding = 0;
19923 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
19924 dsl_binding.descriptorCount = 1;
19925 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
19926 dsl_binding.pImmutableSamplers = NULL;
19927
19928 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
19929 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
19930 ds_layout_ci.pNext = NULL;
19931 ds_layout_ci.bindingCount = 1;
19932 ds_layout_ci.pBindings = &dsl_binding;
19933 VkDescriptorSetLayout ds_layout;
19934 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
19935 ASSERT_VK_SUCCESS(err);
19936
19937 VkDescriptorSet descriptor_set;
19938 VkDescriptorSetAllocateInfo alloc_info = {};
19939 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
19940 alloc_info.descriptorSetCount = 1;
19941 alloc_info.descriptorPool = ds_pool;
19942 alloc_info.pSetLayouts = &ds_layout;
19943 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
19944 ASSERT_VK_SUCCESS(err);
19945
19946 VkDescriptorBufferInfo buffer_info = {};
19947 buffer_info.buffer = buffer;
19948 buffer_info.offset = 0;
19949 buffer_info.range = 1024;
19950
19951 VkWriteDescriptorSet descriptor_write;
19952 memset(&descriptor_write, 0, sizeof(descriptor_write));
19953 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
19954 descriptor_write.dstSet = descriptor_set;
19955 descriptor_write.dstBinding = 0;
19956 descriptor_write.descriptorCount = 1;
19957 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
19958 descriptor_write.pBufferInfo = &buffer_info;
19959
19960 // Set pImageInfo and pTexelBufferView to invalid values, which should
19961 // be
19962 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER.
19963 // This will most likely produce a crash if the parameter_validation
19964 // layer
19965 // does not correctly ignore pImageInfo.
19966 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
19967 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
19968
19969 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
19970
19971 m_errorMonitor->VerifyNotFound();
19972
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019973 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
19974 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
19975 vkDestroyBuffer(m_device->device(), buffer, NULL);
19976 vkFreeMemory(m_device->device(), buffer_memory, NULL);
19977 }
19978
19979 // Texel Buffer Case
19980 {
19981 m_errorMonitor->ExpectSuccess();
19982
19983 VkBuffer buffer;
19984 uint32_t queue_family_index = 0;
19985 VkBufferCreateInfo buffer_create_info = {};
19986 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
19987 buffer_create_info.size = 1024;
19988 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
19989 buffer_create_info.queueFamilyIndexCount = 1;
19990 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
19991
19992 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
19993 ASSERT_VK_SUCCESS(err);
19994
19995 VkMemoryRequirements memory_reqs;
19996 VkDeviceMemory buffer_memory;
19997 bool pass;
19998 VkMemoryAllocateInfo memory_info = {};
19999 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
20000 memory_info.pNext = NULL;
20001 memory_info.allocationSize = 0;
20002 memory_info.memoryTypeIndex = 0;
20003
20004 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
20005 memory_info.allocationSize = memory_reqs.size;
20006 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
20007 ASSERT_TRUE(pass);
20008
20009 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
20010 ASSERT_VK_SUCCESS(err);
20011 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
20012 ASSERT_VK_SUCCESS(err);
20013
20014 VkBufferViewCreateInfo buff_view_ci = {};
20015 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
20016 buff_view_ci.buffer = buffer;
20017 buff_view_ci.format = VK_FORMAT_R8_UNORM;
20018 buff_view_ci.range = VK_WHOLE_SIZE;
20019 VkBufferView buffer_view;
20020 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buffer_view);
20021
20022 VkDescriptorPoolSize ds_type_count = {};
20023 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
20024 ds_type_count.descriptorCount = 1;
20025
20026 VkDescriptorPoolCreateInfo ds_pool_ci = {};
20027 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
20028 ds_pool_ci.pNext = NULL;
20029 ds_pool_ci.maxSets = 1;
20030 ds_pool_ci.poolSizeCount = 1;
20031 ds_pool_ci.pPoolSizes = &ds_type_count;
20032
20033 VkDescriptorPool ds_pool;
20034 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
20035 ASSERT_VK_SUCCESS(err);
20036
20037 VkDescriptorSetLayoutBinding dsl_binding = {};
20038 dsl_binding.binding = 0;
20039 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
20040 dsl_binding.descriptorCount = 1;
20041 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
20042 dsl_binding.pImmutableSamplers = NULL;
20043
20044 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
20045 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
20046 ds_layout_ci.pNext = NULL;
20047 ds_layout_ci.bindingCount = 1;
20048 ds_layout_ci.pBindings = &dsl_binding;
20049 VkDescriptorSetLayout ds_layout;
20050 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
20051 ASSERT_VK_SUCCESS(err);
20052
20053 VkDescriptorSet descriptor_set;
20054 VkDescriptorSetAllocateInfo alloc_info = {};
20055 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
20056 alloc_info.descriptorSetCount = 1;
20057 alloc_info.descriptorPool = ds_pool;
20058 alloc_info.pSetLayouts = &ds_layout;
20059 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
20060 ASSERT_VK_SUCCESS(err);
20061
20062 VkWriteDescriptorSet descriptor_write;
20063 memset(&descriptor_write, 0, sizeof(descriptor_write));
20064 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
20065 descriptor_write.dstSet = descriptor_set;
20066 descriptor_write.dstBinding = 0;
20067 descriptor_write.descriptorCount = 1;
20068 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
20069 descriptor_write.pTexelBufferView = &buffer_view;
20070
20071 // Set pImageInfo and pBufferInfo to invalid values, which should be
20072 // ignored for descriptorType ==
20073 // VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER.
20074 // This will most likely produce a crash if the parameter_validation
20075 // layer
20076 // does not correctly ignore pImageInfo and pBufferInfo.
20077 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
20078 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
20079
20080 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
20081
20082 m_errorMonitor->VerifyNotFound();
20083
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020084 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
20085 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
20086 vkDestroyBufferView(m_device->device(), buffer_view, NULL);
20087 vkDestroyBuffer(m_device->device(), buffer, NULL);
20088 vkFreeMemory(m_device->device(), buffer_memory, NULL);
20089 }
20090}
20091
Tobin Ehlis8893af82017-05-08 12:52:25 -060020092TEST_F(VkPositiveLayerTest, ImmutableSamplerOnlyDescriptor) {
20093 TEST_DESCRIPTION(
20094 "Bind a DescriptorSet with only an immutable sampler"
20095 "and make sure that we don't warn for no update.");
20096
20097 ASSERT_NO_FATAL_FAILURE(Init());
20098 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20099
20100 VkDescriptorPoolSize ds_type_count = {};
20101 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
20102 ds_type_count.descriptorCount = 1;
20103
20104 VkDescriptorPoolCreateInfo ds_pool_ci = {};
20105 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
20106 ds_pool_ci.maxSets = 1;
20107 ds_pool_ci.poolSizeCount = 1;
20108 ds_pool_ci.pPoolSizes = &ds_type_count;
20109
20110 VkDescriptorPool ds_pool;
20111 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
20112 ASSERT_VK_SUCCESS(err);
20113
20114 VkSamplerCreateInfo sampler_ci = {};
20115 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
20116 sampler_ci.pNext = NULL;
20117 sampler_ci.magFilter = VK_FILTER_NEAREST;
20118 sampler_ci.minFilter = VK_FILTER_NEAREST;
20119 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
20120 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
20121 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
20122 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
20123 sampler_ci.mipLodBias = 1.0;
20124 sampler_ci.anisotropyEnable = VK_FALSE;
20125 sampler_ci.maxAnisotropy = 1;
20126 sampler_ci.compareEnable = VK_FALSE;
20127 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
20128 sampler_ci.minLod = 1.0;
20129 sampler_ci.maxLod = 1.0;
20130 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
20131 sampler_ci.unnormalizedCoordinates = VK_FALSE;
20132 VkSampler sampler;
20133
20134 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
20135 ASSERT_VK_SUCCESS(err);
20136
20137 VkDescriptorSetLayoutBinding layout_binding = {};
20138 layout_binding.binding = 0;
20139 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
20140 layout_binding.descriptorCount = 1;
20141 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
20142 layout_binding.pImmutableSamplers = static_cast<VkSampler *>(&sampler);
20143
20144 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
20145 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
20146 ds_layout_ci.bindingCount = 1;
20147 ds_layout_ci.pBindings = &layout_binding;
20148 VkDescriptorSetLayout ds_layout;
20149 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
20150 ASSERT_VK_SUCCESS(err);
20151
20152 VkDescriptorSetAllocateInfo alloc_info = {};
20153 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
20154 alloc_info.descriptorSetCount = 1;
20155 alloc_info.descriptorPool = ds_pool;
20156 alloc_info.pSetLayouts = &ds_layout;
20157 VkDescriptorSet descriptor_set;
20158 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
20159 ASSERT_VK_SUCCESS(err);
20160
20161 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
20162 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
20163 pipeline_layout_ci.pNext = NULL;
20164 pipeline_layout_ci.setLayoutCount = 1;
20165 pipeline_layout_ci.pSetLayouts = &ds_layout;
20166
20167 VkPipelineLayout pipeline_layout;
20168 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
20169 ASSERT_VK_SUCCESS(err);
20170
20171 m_errorMonitor->ExpectSuccess();
20172 m_commandBuffer->BeginCommandBuffer();
20173 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
20174
20175 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
20176 &descriptor_set, 0, nullptr);
20177 m_errorMonitor->VerifyNotFound();
20178
20179 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
20180 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
20181 vkDestroySampler(m_device->device(), sampler, NULL);
20182 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
20183}
20184
Tobin Ehlisf7428442016-10-25 07:58:24 -060020185TEST_F(VkLayerTest, DuplicateDescriptorBinding) {
20186 TEST_DESCRIPTION("Create a descriptor set layout with a duplicate binding number.");
20187
Tony Barbour1fa09702017-03-16 12:09:08 -060020188 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisf7428442016-10-25 07:58:24 -060020189 // Create layout where two binding #s are "1"
20190 static const uint32_t NUM_BINDINGS = 3;
20191 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
20192 dsl_binding[0].binding = 1;
20193 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
20194 dsl_binding[0].descriptorCount = 1;
20195 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
20196 dsl_binding[0].pImmutableSamplers = NULL;
20197 dsl_binding[1].binding = 0;
20198 dsl_binding[1].descriptorCount = 1;
20199 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
20200 dsl_binding[1].descriptorCount = 1;
20201 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
20202 dsl_binding[1].pImmutableSamplers = NULL;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020203 dsl_binding[2].binding = 1; // Duplicate binding should cause error
Tobin Ehlisf7428442016-10-25 07:58:24 -060020204 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
20205 dsl_binding[2].descriptorCount = 1;
20206 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
20207 dsl_binding[2].pImmutableSamplers = NULL;
20208
20209 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
20210 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
20211 ds_layout_ci.pNext = NULL;
20212 ds_layout_ci.bindingCount = NUM_BINDINGS;
20213 ds_layout_ci.pBindings = dsl_binding;
20214 VkDescriptorSetLayout ds_layout;
20215 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02345);
20216 vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
20217 m_errorMonitor->VerifyFound();
20218}
20219
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060020220TEST_F(VkLayerTest, ViewportAndScissorBoundsChecking) {
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060020221 TEST_DESCRIPTION("Verify errors are detected on misuse of SetViewport and SetScissor.");
20222
Tony Barbour1fa09702017-03-16 12:09:08 -060020223 ASSERT_NO_FATAL_FAILURE(Init());
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060020224
Tony Barbour552f6c02016-12-21 14:34:07 -070020225 m_commandBuffer->BeginCommandBuffer();
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060020226
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060020227 const VkPhysicalDeviceLimits &limits = m_device->props.limits;
20228
20229 {
20230 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01448);
20231 VkViewport viewport = {0, 0, static_cast<float>(limits.maxViewportDimensions[0] + 1), 16, 0, 1};
20232 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
20233 m_errorMonitor->VerifyFound();
20234 }
20235
20236 {
20237 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01449);
20238 VkViewport viewport = {0, 0, 16, static_cast<float>(limits.maxViewportDimensions[1] + 1), 0, 1};
20239 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
20240 m_errorMonitor->VerifyFound();
20241 }
20242
20243 {
20244 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
20245 VkViewport viewport = {limits.viewportBoundsRange[0] - 1, 0, 16, 16, 0, 1};
20246 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
20247 m_errorMonitor->VerifyFound();
20248 }
20249
20250 {
20251 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
20252 VkViewport viewport = {0, limits.viewportBoundsRange[0] - 1, 16, 16, 0, 1};
20253 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
20254 m_errorMonitor->VerifyFound();
20255 }
20256
20257 {
20258 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01451);
20259 VkViewport viewport = {limits.viewportBoundsRange[1], 0, 16, 16, 0, 1};
20260 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
20261 m_errorMonitor->VerifyFound();
20262 }
20263
20264 {
20265 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01452);
20266 VkViewport viewport = {0, limits.viewportBoundsRange[1], 16, 16, 0, 1};
20267 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
20268 m_errorMonitor->VerifyFound();
20269 }
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060020270
20271 {
20272 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
20273 VkRect2D scissor = {{-1, 0}, {16, 16}};
20274 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
20275 m_errorMonitor->VerifyFound();
20276 }
20277
20278 {
20279 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
20280 VkRect2D scissor = {{0, -2}, {16, 16}};
20281 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
20282 m_errorMonitor->VerifyFound();
20283 }
20284
20285 {
20286 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01490);
20287 VkRect2D scissor = {{100, 100}, {INT_MAX, 16}};
20288 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
20289 m_errorMonitor->VerifyFound();
20290 }
20291
20292 {
20293 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01491);
20294 VkRect2D scissor = {{100, 100}, {16, INT_MAX}};
20295 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
20296 m_errorMonitor->VerifyFound();
20297 }
20298
Tony Barbour552f6c02016-12-21 14:34:07 -070020299 m_commandBuffer->EndCommandBuffer();
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060020300}
20301
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020302// This is a positive test. No failures are expected.
20303TEST_F(VkPositiveLayerTest, EmptyDescriptorUpdateTest) {
20304 TEST_DESCRIPTION("Update last descriptor in a set that includes an empty binding");
20305 VkResult err;
20306
Tony Barbour1fa09702017-03-16 12:09:08 -060020307 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020308 m_errorMonitor->ExpectSuccess();
20309 VkDescriptorPoolSize ds_type_count = {};
20310 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
20311 ds_type_count.descriptorCount = 2;
20312
20313 VkDescriptorPoolCreateInfo ds_pool_ci = {};
20314 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
20315 ds_pool_ci.pNext = NULL;
20316 ds_pool_ci.maxSets = 1;
20317 ds_pool_ci.poolSizeCount = 1;
20318 ds_pool_ci.pPoolSizes = &ds_type_count;
20319
20320 VkDescriptorPool ds_pool;
20321 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
20322 ASSERT_VK_SUCCESS(err);
20323
20324 // Create layout with two uniform buffer descriptors w/ empty binding between them
20325 static const uint32_t NUM_BINDINGS = 3;
20326 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
20327 dsl_binding[0].binding = 0;
20328 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
20329 dsl_binding[0].descriptorCount = 1;
20330 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
20331 dsl_binding[0].pImmutableSamplers = NULL;
20332 dsl_binding[1].binding = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020333 dsl_binding[1].descriptorCount = 0; // empty binding
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020334 dsl_binding[2].binding = 2;
20335 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
20336 dsl_binding[2].descriptorCount = 1;
20337 dsl_binding[2].stageFlags = VK_SHADER_STAGE_ALL;
20338 dsl_binding[2].pImmutableSamplers = NULL;
20339
20340 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
20341 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
20342 ds_layout_ci.pNext = NULL;
20343 ds_layout_ci.bindingCount = NUM_BINDINGS;
20344 ds_layout_ci.pBindings = dsl_binding;
20345 VkDescriptorSetLayout ds_layout;
20346 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
20347 ASSERT_VK_SUCCESS(err);
20348
20349 VkDescriptorSet descriptor_set = {};
20350 VkDescriptorSetAllocateInfo alloc_info = {};
20351 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
20352 alloc_info.descriptorSetCount = 1;
20353 alloc_info.descriptorPool = ds_pool;
20354 alloc_info.pSetLayouts = &ds_layout;
20355 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
20356 ASSERT_VK_SUCCESS(err);
20357
20358 // Create a buffer to be used for update
20359 VkBufferCreateInfo buff_ci = {};
20360 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
20361 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
20362 buff_ci.size = 256;
20363 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
20364 VkBuffer buffer;
20365 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
20366 ASSERT_VK_SUCCESS(err);
20367 // Have to bind memory to buffer before descriptor update
20368 VkMemoryAllocateInfo mem_alloc = {};
20369 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
20370 mem_alloc.pNext = NULL;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020371 mem_alloc.allocationSize = 512; // one allocation for both buffers
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020372 mem_alloc.memoryTypeIndex = 0;
20373
20374 VkMemoryRequirements mem_reqs;
20375 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
20376 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
20377 if (!pass) {
20378 vkDestroyBuffer(m_device->device(), buffer, NULL);
20379 return;
20380 }
20381
20382 VkDeviceMemory mem;
20383 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
20384 ASSERT_VK_SUCCESS(err);
20385 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
20386 ASSERT_VK_SUCCESS(err);
20387
20388 // Only update the descriptor at binding 2
20389 VkDescriptorBufferInfo buff_info = {};
20390 buff_info.buffer = buffer;
20391 buff_info.offset = 0;
20392 buff_info.range = VK_WHOLE_SIZE;
20393 VkWriteDescriptorSet descriptor_write = {};
20394 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
20395 descriptor_write.dstBinding = 2;
20396 descriptor_write.descriptorCount = 1;
20397 descriptor_write.pTexelBufferView = nullptr;
20398 descriptor_write.pBufferInfo = &buff_info;
20399 descriptor_write.pImageInfo = nullptr;
20400 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
20401 descriptor_write.dstSet = descriptor_set;
20402
20403 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
20404
20405 m_errorMonitor->VerifyNotFound();
20406 // Cleanup
20407 vkFreeMemory(m_device->device(), mem, NULL);
20408 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
20409 vkDestroyBuffer(m_device->device(), buffer, NULL);
20410 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
20411}
20412
20413// This is a positive test. No failures are expected.
20414TEST_F(VkPositiveLayerTest, TestAliasedMemoryTracking) {
20415 VkResult err;
20416 bool pass;
20417
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020418 TEST_DESCRIPTION(
20419 "Create a buffer, allocate memory, bind memory, destroy "
20420 "the buffer, create an image, and bind the same memory to "
20421 "it");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020422
20423 m_errorMonitor->ExpectSuccess();
20424
Tony Barbour1fa09702017-03-16 12:09:08 -060020425 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020426
20427 VkBuffer buffer;
20428 VkImage image;
20429 VkDeviceMemory mem;
20430 VkMemoryRequirements mem_reqs;
20431
20432 VkBufferCreateInfo buf_info = {};
20433 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
20434 buf_info.pNext = NULL;
20435 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
20436 buf_info.size = 256;
20437 buf_info.queueFamilyIndexCount = 0;
20438 buf_info.pQueueFamilyIndices = NULL;
20439 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
20440 buf_info.flags = 0;
20441 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
20442 ASSERT_VK_SUCCESS(err);
20443
20444 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
20445
20446 VkMemoryAllocateInfo alloc_info = {};
20447 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
20448 alloc_info.pNext = NULL;
20449 alloc_info.memoryTypeIndex = 0;
Dave Houlton9dae7ec2017-03-01 16:23:25 -070020450
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020451 // Ensure memory is big enough for both bindings
20452 alloc_info.allocationSize = 0x10000;
20453
20454 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
20455 if (!pass) {
20456 vkDestroyBuffer(m_device->device(), buffer, NULL);
20457 return;
20458 }
20459
20460 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
20461 ASSERT_VK_SUCCESS(err);
20462
20463 uint8_t *pData;
20464 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
20465 ASSERT_VK_SUCCESS(err);
20466
20467 memset(pData, 0xCADECADE, static_cast<size_t>(mem_reqs.size));
20468
20469 vkUnmapMemory(m_device->device(), mem);
20470
20471 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
20472 ASSERT_VK_SUCCESS(err);
20473
20474 // NOW, destroy the buffer. Obviously, the resource no longer occupies this
20475 // memory. In fact, it was never used by the GPU.
20476 // Just be be sure, wait for idle.
20477 vkDestroyBuffer(m_device->device(), buffer, NULL);
20478 vkDeviceWaitIdle(m_device->device());
20479
Tobin Ehlis6a005702016-12-28 15:25:56 -070020480 // Use optimal as some platforms report linear support but then fail image creation
20481 VkImageTiling image_tiling = VK_IMAGE_TILING_OPTIMAL;
20482 VkImageFormatProperties image_format_properties;
20483 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D, image_tiling,
20484 VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0, &image_format_properties);
20485 if (image_format_properties.maxExtent.width == 0) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070020486 printf(" Image format not supported; skipped.\n");
Tobin Ehlis6a005702016-12-28 15:25:56 -070020487 vkFreeMemory(m_device->device(), mem, NULL);
20488 return;
20489 }
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020490 VkImageCreateInfo image_create_info = {};
20491 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
20492 image_create_info.pNext = NULL;
20493 image_create_info.imageType = VK_IMAGE_TYPE_2D;
20494 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
20495 image_create_info.extent.width = 64;
20496 image_create_info.extent.height = 64;
20497 image_create_info.extent.depth = 1;
20498 image_create_info.mipLevels = 1;
20499 image_create_info.arrayLayers = 1;
20500 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis6a005702016-12-28 15:25:56 -070020501 image_create_info.tiling = image_tiling;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020502 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
20503 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
20504 image_create_info.queueFamilyIndexCount = 0;
20505 image_create_info.pQueueFamilyIndices = NULL;
20506 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
20507 image_create_info.flags = 0;
20508
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020509 /* Create a mappable image. It will be the texture if linear images are ok
Dave Houlton9dae7ec2017-03-01 16:23:25 -070020510 * to be textures or it will be the staging image if they are not.
20511 */
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020512 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
20513 ASSERT_VK_SUCCESS(err);
20514
20515 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
20516
Tobin Ehlis6a005702016-12-28 15:25:56 -070020517 VkMemoryAllocateInfo mem_alloc = {};
20518 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
20519 mem_alloc.pNext = NULL;
20520 mem_alloc.allocationSize = 0;
20521 mem_alloc.memoryTypeIndex = 0;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020522 mem_alloc.allocationSize = mem_reqs.size;
20523
20524 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
20525 if (!pass) {
Tobin Ehlis6a005702016-12-28 15:25:56 -070020526 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020527 vkDestroyImage(m_device->device(), image, NULL);
20528 return;
20529 }
20530
20531 // VALIDATION FAILURE:
20532 err = vkBindImageMemory(m_device->device(), image, mem, 0);
20533 ASSERT_VK_SUCCESS(err);
20534
20535 m_errorMonitor->VerifyNotFound();
20536
20537 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020538 vkDestroyImage(m_device->device(), image, NULL);
20539}
20540
Tony Barbourab713912017-02-02 14:17:35 -070020541// This is a positive test. No failures are expected.
20542TEST_F(VkPositiveLayerTest, TestDestroyFreeNullHandles) {
20543 VkResult err;
20544
20545 TEST_DESCRIPTION(
20546 "Call all applicable destroy and free routines with NULL"
20547 "handles, expecting no validation errors");
20548
20549 m_errorMonitor->ExpectSuccess();
20550
Tony Barbour1fa09702017-03-16 12:09:08 -060020551 ASSERT_NO_FATAL_FAILURE(Init());
Tony Barbourab713912017-02-02 14:17:35 -070020552 vkDestroyBuffer(m_device->device(), VK_NULL_HANDLE, NULL);
20553 vkDestroyBufferView(m_device->device(), VK_NULL_HANDLE, NULL);
20554 vkDestroyCommandPool(m_device->device(), VK_NULL_HANDLE, NULL);
20555 vkDestroyDescriptorPool(m_device->device(), VK_NULL_HANDLE, NULL);
20556 vkDestroyDescriptorSetLayout(m_device->device(), VK_NULL_HANDLE, NULL);
20557 vkDestroyDevice(VK_NULL_HANDLE, NULL);
20558 vkDestroyEvent(m_device->device(), VK_NULL_HANDLE, NULL);
20559 vkDestroyFence(m_device->device(), VK_NULL_HANDLE, NULL);
20560 vkDestroyFramebuffer(m_device->device(), VK_NULL_HANDLE, NULL);
20561 vkDestroyImage(m_device->device(), VK_NULL_HANDLE, NULL);
20562 vkDestroyImageView(m_device->device(), VK_NULL_HANDLE, NULL);
20563 vkDestroyInstance(VK_NULL_HANDLE, NULL);
20564 vkDestroyPipeline(m_device->device(), VK_NULL_HANDLE, NULL);
20565 vkDestroyPipelineCache(m_device->device(), VK_NULL_HANDLE, NULL);
20566 vkDestroyPipelineLayout(m_device->device(), VK_NULL_HANDLE, NULL);
20567 vkDestroyQueryPool(m_device->device(), VK_NULL_HANDLE, NULL);
20568 vkDestroyRenderPass(m_device->device(), VK_NULL_HANDLE, NULL);
20569 vkDestroySampler(m_device->device(), VK_NULL_HANDLE, NULL);
20570 vkDestroySemaphore(m_device->device(), VK_NULL_HANDLE, NULL);
20571 vkDestroyShaderModule(m_device->device(), VK_NULL_HANDLE, NULL);
20572
20573 VkCommandPool command_pool;
20574 VkCommandPoolCreateInfo pool_create_info{};
20575 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20576 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20577 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20578 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20579 VkCommandBuffer command_buffers[3] = {};
20580 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20581 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20582 command_buffer_allocate_info.commandPool = command_pool;
20583 command_buffer_allocate_info.commandBufferCount = 1;
20584 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20585 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffers[1]);
20586 vkFreeCommandBuffers(m_device->device(), command_pool, 3, command_buffers);
20587 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20588
20589 VkDescriptorPoolSize ds_type_count = {};
20590 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
20591 ds_type_count.descriptorCount = 1;
20592
20593 VkDescriptorPoolCreateInfo ds_pool_ci = {};
20594 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
20595 ds_pool_ci.pNext = NULL;
20596 ds_pool_ci.maxSets = 1;
20597 ds_pool_ci.poolSizeCount = 1;
20598 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
20599 ds_pool_ci.pPoolSizes = &ds_type_count;
20600
20601 VkDescriptorPool ds_pool;
20602 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
20603 ASSERT_VK_SUCCESS(err);
20604
20605 VkDescriptorSetLayoutBinding dsl_binding = {};
20606 dsl_binding.binding = 2;
20607 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
20608 dsl_binding.descriptorCount = 1;
20609 dsl_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
20610 dsl_binding.pImmutableSamplers = NULL;
20611 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
20612 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
20613 ds_layout_ci.pNext = NULL;
20614 ds_layout_ci.bindingCount = 1;
20615 ds_layout_ci.pBindings = &dsl_binding;
20616 VkDescriptorSetLayout ds_layout;
20617 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
20618 ASSERT_VK_SUCCESS(err);
20619
20620 VkDescriptorSet descriptor_sets[3] = {};
20621 VkDescriptorSetAllocateInfo alloc_info = {};
20622 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
20623 alloc_info.descriptorSetCount = 1;
20624 alloc_info.descriptorPool = ds_pool;
20625 alloc_info.pSetLayouts = &ds_layout;
20626 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_sets[1]);
20627 ASSERT_VK_SUCCESS(err);
20628 vkFreeDescriptorSets(m_device->device(), ds_pool, 3, descriptor_sets);
20629 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
20630 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
20631
20632 vkFreeMemory(m_device->device(), VK_NULL_HANDLE, NULL);
20633
20634 m_errorMonitor->VerifyNotFound();
20635}
20636
Tony Barbour626994c2017-02-08 15:29:37 -070020637TEST_F(VkPositiveLayerTest, QueueSubmitSemaphoresAndLayoutTracking) {
Tony Barboure0c5cc92017-02-08 13:53:39 -070020638 TEST_DESCRIPTION("Submit multiple command buffers with chained semaphore signals and layout transitions");
Tony Barbour626994c2017-02-08 15:29:37 -070020639
20640 m_errorMonitor->ExpectSuccess();
20641
Tony Barbour1fa09702017-03-16 12:09:08 -060020642 ASSERT_NO_FATAL_FAILURE(Init());
Tony Barbour626994c2017-02-08 15:29:37 -070020643 VkCommandBuffer cmd_bufs[4];
20644 VkCommandBufferAllocateInfo alloc_info;
20645 alloc_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20646 alloc_info.pNext = NULL;
20647 alloc_info.commandBufferCount = 4;
Mike Schuchardt06304c22017-03-01 17:09:09 -070020648 alloc_info.commandPool = m_commandPool->handle();
Tony Barbour626994c2017-02-08 15:29:37 -070020649 alloc_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20650 vkAllocateCommandBuffers(m_device->device(), &alloc_info, cmd_bufs);
20651 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060020652 image.Init(128, 128, 1, VK_FORMAT_B8G8R8A8_UNORM,
Mike Weiblen62d08a32017-03-07 22:18:27 -070020653 (VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT),
20654 VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbour626994c2017-02-08 15:29:37 -070020655 ASSERT_TRUE(image.initialized());
20656 VkCommandBufferBeginInfo cb_binfo;
20657 cb_binfo.pNext = NULL;
20658 cb_binfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20659 cb_binfo.pInheritanceInfo = VK_NULL_HANDLE;
20660 cb_binfo.flags = 0;
20661 // Use 4 command buffers, each with an image layout transition, ColorAO->General->ColorAO->TransferSrc->TransferDst
20662 vkBeginCommandBuffer(cmd_bufs[0], &cb_binfo);
20663 VkImageMemoryBarrier img_barrier = {};
20664 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
20665 img_barrier.pNext = NULL;
20666 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
20667 img_barrier.dstAccessMask = VK_ACCESS_HOST_WRITE_BIT;
20668 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
20669 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
20670 img_barrier.image = image.handle();
20671 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
20672 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
20673 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
20674 img_barrier.subresourceRange.baseArrayLayer = 0;
20675 img_barrier.subresourceRange.baseMipLevel = 0;
20676 img_barrier.subresourceRange.layerCount = 1;
20677 img_barrier.subresourceRange.levelCount = 1;
20678 vkCmdPipelineBarrier(cmd_bufs[0], VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 0, nullptr, 0, nullptr, 1,
20679 &img_barrier);
20680 vkEndCommandBuffer(cmd_bufs[0]);
20681 vkBeginCommandBuffer(cmd_bufs[1], &cb_binfo);
20682 img_barrier.oldLayout = VK_IMAGE_LAYOUT_GENERAL;
20683 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
20684 vkCmdPipelineBarrier(cmd_bufs[1], VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 0, nullptr, 0, nullptr, 1,
20685 &img_barrier);
20686 vkEndCommandBuffer(cmd_bufs[1]);
20687 vkBeginCommandBuffer(cmd_bufs[2], &cb_binfo);
20688 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
20689 img_barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
20690 vkCmdPipelineBarrier(cmd_bufs[2], VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 0, nullptr, 0, nullptr, 1,
20691 &img_barrier);
20692 vkEndCommandBuffer(cmd_bufs[2]);
20693 vkBeginCommandBuffer(cmd_bufs[3], &cb_binfo);
20694 img_barrier.oldLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
20695 img_barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
20696 vkCmdPipelineBarrier(cmd_bufs[3], VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 0, nullptr, 0, nullptr, 1,
20697 &img_barrier);
20698 vkEndCommandBuffer(cmd_bufs[3]);
20699
20700 // Submit 4 command buffers in 3 submits, with submits 2 and 3 waiting for semaphores from submits 1 and 2
20701 VkSemaphore semaphore1, semaphore2;
20702 VkSemaphoreCreateInfo semaphore_create_info{};
20703 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
20704 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore1);
20705 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore2);
20706 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
20707 VkSubmitInfo submit_info[3];
20708 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20709 submit_info[0].pNext = nullptr;
20710 submit_info[0].commandBufferCount = 1;
20711 submit_info[0].pCommandBuffers = &cmd_bufs[0];
20712 submit_info[0].signalSemaphoreCount = 1;
20713 submit_info[0].pSignalSemaphores = &semaphore1;
20714 submit_info[0].waitSemaphoreCount = 0;
20715 submit_info[0].pWaitDstStageMask = nullptr;
20716 submit_info[0].pWaitDstStageMask = flags;
20717 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20718 submit_info[1].pNext = nullptr;
20719 submit_info[1].commandBufferCount = 1;
20720 submit_info[1].pCommandBuffers = &cmd_bufs[1];
20721 submit_info[1].waitSemaphoreCount = 1;
20722 submit_info[1].pWaitSemaphores = &semaphore1;
20723 submit_info[1].signalSemaphoreCount = 1;
20724 submit_info[1].pSignalSemaphores = &semaphore2;
20725 submit_info[1].pWaitDstStageMask = flags;
20726 submit_info[2].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20727 submit_info[2].pNext = nullptr;
20728 submit_info[2].commandBufferCount = 2;
20729 submit_info[2].pCommandBuffers = &cmd_bufs[2];
20730 submit_info[2].waitSemaphoreCount = 1;
20731 submit_info[2].pWaitSemaphores = &semaphore2;
20732 submit_info[2].signalSemaphoreCount = 0;
20733 submit_info[2].pSignalSemaphores = nullptr;
20734 submit_info[2].pWaitDstStageMask = flags;
20735 vkQueueSubmit(m_device->m_queue, 3, submit_info, VK_NULL_HANDLE);
20736 vkQueueWaitIdle(m_device->m_queue);
20737
20738 vkDestroySemaphore(m_device->device(), semaphore1, NULL);
20739 vkDestroySemaphore(m_device->device(), semaphore2, NULL);
20740 m_errorMonitor->VerifyNotFound();
20741}
20742
Tobin Ehlis953e8392016-11-17 10:54:13 -070020743TEST_F(VkPositiveLayerTest, DynamicOffsetWithInactiveBinding) {
20744 // Create a descriptorSet w/ dynamic descriptors where 1 binding is inactive
20745 // We previously had a bug where dynamic offset of inactive bindings was still being used
20746 VkResult err;
20747 m_errorMonitor->ExpectSuccess();
20748
Tony Barbour1fa09702017-03-16 12:09:08 -060020749 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis953e8392016-11-17 10:54:13 -070020750 ASSERT_NO_FATAL_FAILURE(InitViewport());
20751 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20752
20753 VkDescriptorPoolSize ds_type_count = {};
20754 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
20755 ds_type_count.descriptorCount = 3;
20756
20757 VkDescriptorPoolCreateInfo ds_pool_ci = {};
20758 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
20759 ds_pool_ci.pNext = NULL;
20760 ds_pool_ci.maxSets = 1;
20761 ds_pool_ci.poolSizeCount = 1;
20762 ds_pool_ci.pPoolSizes = &ds_type_count;
20763
20764 VkDescriptorPool ds_pool;
20765 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
20766 ASSERT_VK_SUCCESS(err);
20767
20768 const uint32_t BINDING_COUNT = 3;
20769 VkDescriptorSetLayoutBinding dsl_binding[BINDING_COUNT] = {};
Tobin Ehlis0050fba2016-11-30 10:22:02 -070020770 dsl_binding[0].binding = 2;
Tobin Ehlis953e8392016-11-17 10:54:13 -070020771 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
20772 dsl_binding[0].descriptorCount = 1;
20773 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
20774 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis0050fba2016-11-30 10:22:02 -070020775 dsl_binding[1].binding = 0;
Tobin Ehlis953e8392016-11-17 10:54:13 -070020776 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
20777 dsl_binding[1].descriptorCount = 1;
20778 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
20779 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis0050fba2016-11-30 10:22:02 -070020780 dsl_binding[2].binding = 1;
Tobin Ehlis953e8392016-11-17 10:54:13 -070020781 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
20782 dsl_binding[2].descriptorCount = 1;
20783 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
20784 dsl_binding[2].pImmutableSamplers = NULL;
20785
20786 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
20787 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
20788 ds_layout_ci.pNext = NULL;
20789 ds_layout_ci.bindingCount = BINDING_COUNT;
20790 ds_layout_ci.pBindings = dsl_binding;
20791 VkDescriptorSetLayout ds_layout;
20792 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
20793 ASSERT_VK_SUCCESS(err);
20794
20795 VkDescriptorSet descriptor_set;
20796 VkDescriptorSetAllocateInfo alloc_info = {};
20797 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
20798 alloc_info.descriptorSetCount = 1;
20799 alloc_info.descriptorPool = ds_pool;
20800 alloc_info.pSetLayouts = &ds_layout;
20801 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
20802 ASSERT_VK_SUCCESS(err);
20803
20804 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
20805 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
20806 pipeline_layout_ci.pNext = NULL;
20807 pipeline_layout_ci.setLayoutCount = 1;
20808 pipeline_layout_ci.pSetLayouts = &ds_layout;
20809
20810 VkPipelineLayout pipeline_layout;
20811 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
20812 ASSERT_VK_SUCCESS(err);
20813
20814 // Create two buffers to update the descriptors with
20815 // The first will be 2k and used for bindings 0 & 1, the second is 1k for binding 2
20816 uint32_t qfi = 0;
20817 VkBufferCreateInfo buffCI = {};
20818 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
20819 buffCI.size = 2048;
20820 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
20821 buffCI.queueFamilyIndexCount = 1;
20822 buffCI.pQueueFamilyIndices = &qfi;
20823
20824 VkBuffer dyub1;
20825 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub1);
20826 ASSERT_VK_SUCCESS(err);
20827 // buffer2
20828 buffCI.size = 1024;
20829 VkBuffer dyub2;
20830 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub2);
20831 ASSERT_VK_SUCCESS(err);
20832 // Allocate memory and bind to buffers
20833 VkMemoryAllocateInfo mem_alloc[2] = {};
20834 mem_alloc[0].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
20835 mem_alloc[0].pNext = NULL;
20836 mem_alloc[0].memoryTypeIndex = 0;
20837 mem_alloc[1].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
20838 mem_alloc[1].pNext = NULL;
20839 mem_alloc[1].memoryTypeIndex = 0;
20840
20841 VkMemoryRequirements mem_reqs1;
20842 vkGetBufferMemoryRequirements(m_device->device(), dyub1, &mem_reqs1);
20843 VkMemoryRequirements mem_reqs2;
20844 vkGetBufferMemoryRequirements(m_device->device(), dyub2, &mem_reqs2);
20845 mem_alloc[0].allocationSize = mem_reqs1.size;
20846 bool pass = m_device->phy().set_memory_type(mem_reqs1.memoryTypeBits, &mem_alloc[0], 0);
20847 mem_alloc[1].allocationSize = mem_reqs2.size;
20848 pass &= m_device->phy().set_memory_type(mem_reqs2.memoryTypeBits, &mem_alloc[1], 0);
20849 if (!pass) {
20850 vkDestroyBuffer(m_device->device(), dyub1, NULL);
20851 vkDestroyBuffer(m_device->device(), dyub2, NULL);
20852 return;
20853 }
20854
20855 VkDeviceMemory mem1;
20856 err = vkAllocateMemory(m_device->device(), &mem_alloc[0], NULL, &mem1);
20857 ASSERT_VK_SUCCESS(err);
20858 err = vkBindBufferMemory(m_device->device(), dyub1, mem1, 0);
20859 ASSERT_VK_SUCCESS(err);
20860 VkDeviceMemory mem2;
20861 err = vkAllocateMemory(m_device->device(), &mem_alloc[1], NULL, &mem2);
20862 ASSERT_VK_SUCCESS(err);
20863 err = vkBindBufferMemory(m_device->device(), dyub2, mem2, 0);
20864 ASSERT_VK_SUCCESS(err);
20865 // Update descriptors
20866 VkDescriptorBufferInfo buff_info[BINDING_COUNT] = {};
20867 buff_info[0].buffer = dyub1;
20868 buff_info[0].offset = 0;
20869 buff_info[0].range = 256;
20870 buff_info[1].buffer = dyub1;
20871 buff_info[1].offset = 256;
20872 buff_info[1].range = 512;
20873 buff_info[2].buffer = dyub2;
20874 buff_info[2].offset = 0;
20875 buff_info[2].range = 512;
20876
20877 VkWriteDescriptorSet descriptor_write;
20878 memset(&descriptor_write, 0, sizeof(descriptor_write));
20879 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
20880 descriptor_write.dstSet = descriptor_set;
20881 descriptor_write.dstBinding = 0;
20882 descriptor_write.descriptorCount = BINDING_COUNT;
20883 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
20884 descriptor_write.pBufferInfo = buff_info;
20885
20886 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
20887
Tony Barbour552f6c02016-12-21 14:34:07 -070020888 m_commandBuffer->BeginCommandBuffer();
20889 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis953e8392016-11-17 10:54:13 -070020890
20891 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020892 char const *vsSource =
20893 "#version 450\n"
20894 "\n"
20895 "out gl_PerVertex { \n"
20896 " vec4 gl_Position;\n"
20897 "};\n"
20898 "void main(){\n"
20899 " gl_Position = vec4(1);\n"
20900 "}\n";
20901 char const *fsSource =
20902 "#version 450\n"
20903 "\n"
20904 "layout(location=0) out vec4 x;\n"
20905 "layout(set=0) layout(binding=0) uniform foo1 { int x; int y; } bar1;\n"
20906 "layout(set=0) layout(binding=2) uniform foo2 { int x; int y; } bar2;\n"
20907 "void main(){\n"
20908 " x = vec4(bar1.y) + vec4(bar2.y);\n"
20909 "}\n";
Tobin Ehlis953e8392016-11-17 10:54:13 -070020910 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
20911 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
20912 VkPipelineObj pipe(m_device);
20913 pipe.SetViewport(m_viewports);
20914 pipe.SetScissor(m_scissors);
20915 pipe.AddShader(&vs);
20916 pipe.AddShader(&fs);
20917 pipe.AddColorAttachment();
20918 pipe.CreateVKPipeline(pipeline_layout, renderPass());
20919
20920 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
20921 // This update should succeed, but offset of inactive binding 1 oversteps binding 2 buffer size
20922 // we used to have a bug in this case.
20923 uint32_t dyn_off[BINDING_COUNT] = {0, 1024, 256};
20924 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
20925 &descriptor_set, BINDING_COUNT, dyn_off);
20926 Draw(1, 0, 0, 0);
20927 m_errorMonitor->VerifyNotFound();
20928
20929 vkDestroyBuffer(m_device->device(), dyub1, NULL);
20930 vkDestroyBuffer(m_device->device(), dyub2, NULL);
20931 vkFreeMemory(m_device->device(), mem1, NULL);
20932 vkFreeMemory(m_device->device(), mem2, NULL);
20933
20934 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
20935 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
20936 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
20937}
20938
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020939TEST_F(VkPositiveLayerTest, NonCoherentMemoryMapping) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020940 TEST_DESCRIPTION(
20941 "Ensure that validations handling of non-coherent memory "
20942 "mapping while using VK_WHOLE_SIZE does not cause access "
20943 "violations");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020944 VkResult err;
20945 uint8_t *pData;
Tony Barbour1fa09702017-03-16 12:09:08 -060020946 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020947
20948 VkDeviceMemory mem;
20949 VkMemoryRequirements mem_reqs;
20950 mem_reqs.memoryTypeBits = 0xFFFFFFFF;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070020951 const VkDeviceSize atom_size = m_device->props.limits.nonCoherentAtomSize;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020952 VkMemoryAllocateInfo alloc_info = {};
20953 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
20954 alloc_info.pNext = NULL;
20955 alloc_info.memoryTypeIndex = 0;
20956
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070020957 static const VkDeviceSize allocation_size = 32 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020958 alloc_info.allocationSize = allocation_size;
20959
20960 // Find a memory configurations WITHOUT a COHERENT bit, otherwise exit
20961 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020962 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020963 if (!pass) {
20964 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020965 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
20966 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020967 if (!pass) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020968 pass = m_device->phy().set_memory_type(
20969 mem_reqs.memoryTypeBits, &alloc_info,
20970 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT | VK_MEMORY_PROPERTY_HOST_CACHED_BIT,
20971 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020972 if (!pass) {
20973 return;
20974 }
20975 }
20976 }
20977
20978 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
20979 ASSERT_VK_SUCCESS(err);
20980
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070020981 // Map/Flush/Invalidate using WHOLE_SIZE and zero offsets and entire mapped range
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020982 m_errorMonitor->ExpectSuccess();
20983 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
20984 ASSERT_VK_SUCCESS(err);
20985 VkMappedMemoryRange mmr = {};
20986 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
20987 mmr.memory = mem;
20988 mmr.offset = 0;
20989 mmr.size = VK_WHOLE_SIZE;
20990 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
20991 ASSERT_VK_SUCCESS(err);
20992 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
20993 ASSERT_VK_SUCCESS(err);
20994 m_errorMonitor->VerifyNotFound();
20995 vkUnmapMemory(m_device->device(), mem);
20996
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070020997 // Map/Flush/Invalidate using WHOLE_SIZE and an offset and entire mapped range
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020998 m_errorMonitor->ExpectSuccess();
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070020999 err = vkMapMemory(m_device->device(), mem, 5 * atom_size, VK_WHOLE_SIZE, 0, (void **)&pData);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021000 ASSERT_VK_SUCCESS(err);
21001 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
21002 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070021003 mmr.offset = 6 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021004 mmr.size = VK_WHOLE_SIZE;
21005 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
21006 ASSERT_VK_SUCCESS(err);
21007 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
21008 ASSERT_VK_SUCCESS(err);
21009 m_errorMonitor->VerifyNotFound();
21010 vkUnmapMemory(m_device->device(), mem);
21011
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070021012 // Map with offset and size
21013 // Flush/Invalidate subrange of mapped area with offset and size
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021014 m_errorMonitor->ExpectSuccess();
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070021015 err = vkMapMemory(m_device->device(), mem, 3 * atom_size, 9 * atom_size, 0, (void **)&pData);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021016 ASSERT_VK_SUCCESS(err);
21017 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
21018 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070021019 mmr.offset = 4 * atom_size;
21020 mmr.size = 2 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021021 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
21022 ASSERT_VK_SUCCESS(err);
21023 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
21024 ASSERT_VK_SUCCESS(err);
21025 m_errorMonitor->VerifyNotFound();
21026 vkUnmapMemory(m_device->device(), mem);
21027
21028 // Map without offset and flush WHOLE_SIZE with two separate offsets
21029 m_errorMonitor->ExpectSuccess();
21030 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
21031 ASSERT_VK_SUCCESS(err);
21032 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
21033 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070021034 mmr.offset = allocation_size - (4 * atom_size);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021035 mmr.size = VK_WHOLE_SIZE;
21036 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
21037 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070021038 mmr.offset = allocation_size - (6 * atom_size);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021039 mmr.size = VK_WHOLE_SIZE;
21040 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
21041 ASSERT_VK_SUCCESS(err);
21042 m_errorMonitor->VerifyNotFound();
21043 vkUnmapMemory(m_device->device(), mem);
21044
21045 vkFreeMemory(m_device->device(), mem, NULL);
21046}
21047
21048// This is a positive test. We used to expect error in this case but spec now allows it
21049TEST_F(VkPositiveLayerTest, ResetUnsignaledFence) {
21050 m_errorMonitor->ExpectSuccess();
21051 vk_testing::Fence testFence;
21052 VkFenceCreateInfo fenceInfo = {};
21053 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
21054 fenceInfo.pNext = NULL;
21055
Tony Barbour1fa09702017-03-16 12:09:08 -060021056 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021057 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021058 VkFence fences[1] = {testFence.handle()};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021059 VkResult result = vkResetFences(m_device->device(), 1, fences);
21060 ASSERT_VK_SUCCESS(result);
21061
21062 m_errorMonitor->VerifyNotFound();
21063}
21064
21065TEST_F(VkPositiveLayerTest, CommandBufferSimultaneousUseSync) {
21066 m_errorMonitor->ExpectSuccess();
21067
Tony Barbour1fa09702017-03-16 12:09:08 -060021068 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021069 VkResult err;
21070
21071 // Record (empty!) command buffer that can be submitted multiple times
21072 // simultaneously.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021073 VkCommandBufferBeginInfo cbbi = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
21074 VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021075 m_commandBuffer->BeginCommandBuffer(&cbbi);
21076 m_commandBuffer->EndCommandBuffer();
21077
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021078 VkFenceCreateInfo fci = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021079 VkFence fence;
21080 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
21081 ASSERT_VK_SUCCESS(err);
21082
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021083 VkSemaphoreCreateInfo sci = {VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021084 VkSemaphore s1, s2;
21085 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s1);
21086 ASSERT_VK_SUCCESS(err);
21087 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s2);
21088 ASSERT_VK_SUCCESS(err);
21089
21090 // Submit CB once signaling s1, with fence so we can roll forward to its retirement.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021091 VkSubmitInfo si = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &m_commandBuffer->handle(), 1, &s1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021092 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
21093 ASSERT_VK_SUCCESS(err);
21094
21095 // Submit CB again, signaling s2.
21096 si.pSignalSemaphores = &s2;
21097 err = vkQueueSubmit(m_device->m_queue, 1, &si, VK_NULL_HANDLE);
21098 ASSERT_VK_SUCCESS(err);
21099
21100 // Wait for fence.
21101 err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
21102 ASSERT_VK_SUCCESS(err);
21103
21104 // CB is still in flight from second submission, but semaphore s1 is no
21105 // longer in flight. delete it.
21106 vkDestroySemaphore(m_device->device(), s1, nullptr);
21107
21108 m_errorMonitor->VerifyNotFound();
21109
21110 // Force device idle and clean up remaining objects
21111 vkDeviceWaitIdle(m_device->device());
21112 vkDestroySemaphore(m_device->device(), s2, nullptr);
21113 vkDestroyFence(m_device->device(), fence, nullptr);
21114}
21115
21116TEST_F(VkPositiveLayerTest, FenceCreateSignaledWaitHandling) {
21117 m_errorMonitor->ExpectSuccess();
21118
Tony Barbour1fa09702017-03-16 12:09:08 -060021119 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021120 VkResult err;
21121
21122 // A fence created signaled
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021123 VkFenceCreateInfo fci1 = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, VK_FENCE_CREATE_SIGNALED_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021124 VkFence f1;
21125 err = vkCreateFence(m_device->device(), &fci1, nullptr, &f1);
21126 ASSERT_VK_SUCCESS(err);
21127
21128 // A fence created not
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021129 VkFenceCreateInfo fci2 = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021130 VkFence f2;
21131 err = vkCreateFence(m_device->device(), &fci2, nullptr, &f2);
21132 ASSERT_VK_SUCCESS(err);
21133
21134 // Submit the unsignaled fence
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021135 VkSubmitInfo si = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 0, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021136 err = vkQueueSubmit(m_device->m_queue, 1, &si, f2);
21137
21138 // Wait on both fences, with signaled first.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021139 VkFence fences[] = {f1, f2};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021140 vkWaitForFences(m_device->device(), 2, fences, VK_TRUE, UINT64_MAX);
21141
21142 // Should have both retired!
21143 vkDestroyFence(m_device->device(), f1, nullptr);
21144 vkDestroyFence(m_device->device(), f2, nullptr);
21145
21146 m_errorMonitor->VerifyNotFound();
21147}
21148
21149TEST_F(VkPositiveLayerTest, ValidUsage) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021150 TEST_DESCRIPTION(
21151 "Verify that creating an image view from an image with valid usage "
21152 "doesn't generate validation errors");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021153
Tony Barbour1fa09702017-03-16 12:09:08 -060021154 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021155
21156 m_errorMonitor->ExpectSuccess();
21157 // Verify that we can create a view with usage INPUT_ATTACHMENT
21158 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060021159 image.Init(128, 128, 1, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021160 ASSERT_TRUE(image.initialized());
21161 VkImageView imageView;
21162 VkImageViewCreateInfo ivci = {};
21163 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
21164 ivci.image = image.handle();
21165 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
21166 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
21167 ivci.subresourceRange.layerCount = 1;
21168 ivci.subresourceRange.baseMipLevel = 0;
21169 ivci.subresourceRange.levelCount = 1;
21170 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
21171
21172 vkCreateImageView(m_device->device(), &ivci, NULL, &imageView);
21173 m_errorMonitor->VerifyNotFound();
21174 vkDestroyImageView(m_device->device(), imageView, NULL);
21175}
21176
21177// This is a positive test. No failures are expected.
21178TEST_F(VkPositiveLayerTest, BindSparse) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021179 TEST_DESCRIPTION(
21180 "Bind 2 memory ranges to one image using vkQueueBindSparse, destroy the image"
21181 "and then free the memory");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021182
Tony Barbour1fa09702017-03-16 12:09:08 -060021183 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021184
21185 auto index = m_device->graphics_queue_node_index_;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021186 if (!(m_device->queue_props[index].queueFlags & VK_QUEUE_SPARSE_BINDING_BIT)) return;
Tony Barbour623721f2017-03-24 15:00:21 -060021187 if (!m_device->phy().features().sparseBinding) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021188
21189 m_errorMonitor->ExpectSuccess();
21190
21191 VkImage image;
21192 VkImageCreateInfo image_create_info = {};
21193 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
21194 image_create_info.pNext = NULL;
21195 image_create_info.imageType = VK_IMAGE_TYPE_2D;
21196 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
21197 image_create_info.extent.width = 64;
21198 image_create_info.extent.height = 64;
21199 image_create_info.extent.depth = 1;
21200 image_create_info.mipLevels = 1;
21201 image_create_info.arrayLayers = 1;
21202 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
21203 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
21204 image_create_info.usage = VK_IMAGE_USAGE_STORAGE_BIT;
21205 image_create_info.flags = VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
21206 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
21207 ASSERT_VK_SUCCESS(err);
21208
21209 VkMemoryRequirements memory_reqs;
21210 VkDeviceMemory memory_one, memory_two;
21211 bool pass;
21212 VkMemoryAllocateInfo memory_info = {};
21213 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
21214 memory_info.pNext = NULL;
21215 memory_info.allocationSize = 0;
21216 memory_info.memoryTypeIndex = 0;
21217 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
21218 // Find an image big enough to allow sparse mapping of 2 memory regions
21219 // Increase the image size until it is at least twice the
21220 // size of the required alignment, to ensure we can bind both
21221 // allocated memory blocks to the image on aligned offsets.
21222 while (memory_reqs.size < (memory_reqs.alignment * 2)) {
21223 vkDestroyImage(m_device->device(), image, nullptr);
21224 image_create_info.extent.width *= 2;
21225 image_create_info.extent.height *= 2;
21226 err = vkCreateImage(m_device->device(), &image_create_info, nullptr, &image);
21227 ASSERT_VK_SUCCESS(err);
21228 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
21229 }
21230 // Allocate 2 memory regions of minimum alignment size, bind one at 0, the other
21231 // at the end of the first
21232 memory_info.allocationSize = memory_reqs.alignment;
21233 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
21234 ASSERT_TRUE(pass);
21235 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_one);
21236 ASSERT_VK_SUCCESS(err);
21237 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_two);
21238 ASSERT_VK_SUCCESS(err);
21239 VkSparseMemoryBind binds[2];
21240 binds[0].flags = 0;
21241 binds[0].memory = memory_one;
21242 binds[0].memoryOffset = 0;
21243 binds[0].resourceOffset = 0;
21244 binds[0].size = memory_info.allocationSize;
21245 binds[1].flags = 0;
21246 binds[1].memory = memory_two;
21247 binds[1].memoryOffset = 0;
21248 binds[1].resourceOffset = memory_info.allocationSize;
21249 binds[1].size = memory_info.allocationSize;
21250
21251 VkSparseImageOpaqueMemoryBindInfo opaqueBindInfo;
21252 opaqueBindInfo.image = image;
21253 opaqueBindInfo.bindCount = 2;
21254 opaqueBindInfo.pBinds = binds;
21255
21256 VkFence fence = VK_NULL_HANDLE;
21257 VkBindSparseInfo bindSparseInfo = {};
21258 bindSparseInfo.sType = VK_STRUCTURE_TYPE_BIND_SPARSE_INFO;
21259 bindSparseInfo.imageOpaqueBindCount = 1;
21260 bindSparseInfo.pImageOpaqueBinds = &opaqueBindInfo;
21261
21262 vkQueueBindSparse(m_device->m_queue, 1, &bindSparseInfo, fence);
21263 vkQueueWaitIdle(m_device->m_queue);
21264 vkDestroyImage(m_device->device(), image, NULL);
21265 vkFreeMemory(m_device->device(), memory_one, NULL);
21266 vkFreeMemory(m_device->device(), memory_two, NULL);
21267 m_errorMonitor->VerifyNotFound();
21268}
21269
21270TEST_F(VkPositiveLayerTest, RenderPassInitialLayoutUndefined) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021271 TEST_DESCRIPTION(
21272 "Ensure that CmdBeginRenderPass with an attachment's "
21273 "initialLayout of VK_IMAGE_LAYOUT_UNDEFINED works when "
21274 "the command buffer has prior knowledge of that "
21275 "attachment's layout.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021276
21277 m_errorMonitor->ExpectSuccess();
21278
Tony Barbour1fa09702017-03-16 12:09:08 -060021279 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021280
21281 // A renderpass with one color attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021282 VkAttachmentDescription attachment = {0,
21283 VK_FORMAT_R8G8B8A8_UNORM,
21284 VK_SAMPLE_COUNT_1_BIT,
21285 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
21286 VK_ATTACHMENT_STORE_OP_STORE,
21287 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
21288 VK_ATTACHMENT_STORE_OP_DONT_CARE,
21289 VK_IMAGE_LAYOUT_UNDEFINED,
21290 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021291
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021292 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021293
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021294 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021295
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021296 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021297
21298 VkRenderPass rp;
21299 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
21300 ASSERT_VK_SUCCESS(err);
21301
21302 // A compatible framebuffer.
21303 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060021304 image.Init(32, 32, 1, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021305 ASSERT_TRUE(image.initialized());
21306
21307 VkImageViewCreateInfo ivci = {
21308 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
21309 nullptr,
21310 0,
21311 image.handle(),
21312 VK_IMAGE_VIEW_TYPE_2D,
21313 VK_FORMAT_R8G8B8A8_UNORM,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021314 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
21315 VK_COMPONENT_SWIZZLE_IDENTITY},
21316 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021317 };
21318 VkImageView view;
21319 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
21320 ASSERT_VK_SUCCESS(err);
21321
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021322 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021323 VkFramebuffer fb;
21324 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
21325 ASSERT_VK_SUCCESS(err);
21326
21327 // Record a single command buffer which uses this renderpass twice. The
21328 // bug is triggered at the beginning of the second renderpass, when the
21329 // command buffer already has a layout recorded for the attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021330 VkRenderPassBeginInfo rpbi = {VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb, {{0, 0}, {32, 32}}, 0, nullptr};
Tony Barbour552f6c02016-12-21 14:34:07 -070021331 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021332 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
21333 vkCmdEndRenderPass(m_commandBuffer->handle());
21334 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
21335
21336 m_errorMonitor->VerifyNotFound();
21337
21338 vkCmdEndRenderPass(m_commandBuffer->handle());
Tony Barbour552f6c02016-12-21 14:34:07 -070021339 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021340
21341 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
21342 vkDestroyRenderPass(m_device->device(), rp, nullptr);
21343 vkDestroyImageView(m_device->device(), view, nullptr);
21344}
21345
21346TEST_F(VkPositiveLayerTest, FramebufferBindingDestroyCommandPool) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021347 TEST_DESCRIPTION(
21348 "This test should pass. Create a Framebuffer and "
21349 "command buffer, bind them together, then destroy "
21350 "command pool and framebuffer and verify there are no "
21351 "errors.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021352
21353 m_errorMonitor->ExpectSuccess();
21354
Tony Barbour1fa09702017-03-16 12:09:08 -060021355 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021356
21357 // A renderpass with one color attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021358 VkAttachmentDescription attachment = {0,
21359 VK_FORMAT_R8G8B8A8_UNORM,
21360 VK_SAMPLE_COUNT_1_BIT,
21361 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
21362 VK_ATTACHMENT_STORE_OP_STORE,
21363 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
21364 VK_ATTACHMENT_STORE_OP_DONT_CARE,
21365 VK_IMAGE_LAYOUT_UNDEFINED,
21366 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021367
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021368 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021369
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021370 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021371
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021372 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021373
21374 VkRenderPass rp;
21375 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
21376 ASSERT_VK_SUCCESS(err);
21377
21378 // A compatible framebuffer.
21379 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060021380 image.Init(32, 32, 1, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021381 ASSERT_TRUE(image.initialized());
21382
21383 VkImageViewCreateInfo ivci = {
21384 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
21385 nullptr,
21386 0,
21387 image.handle(),
21388 VK_IMAGE_VIEW_TYPE_2D,
21389 VK_FORMAT_R8G8B8A8_UNORM,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021390 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
21391 VK_COMPONENT_SWIZZLE_IDENTITY},
21392 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021393 };
21394 VkImageView view;
21395 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
21396 ASSERT_VK_SUCCESS(err);
21397
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021398 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021399 VkFramebuffer fb;
21400 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
21401 ASSERT_VK_SUCCESS(err);
21402
21403 // Explicitly create a command buffer to bind the FB to so that we can then
21404 // destroy the command pool in order to implicitly free command buffer
21405 VkCommandPool command_pool;
21406 VkCommandPoolCreateInfo pool_create_info{};
21407 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
21408 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
21409 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
21410 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
21411
21412 VkCommandBuffer command_buffer;
21413 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
21414 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
21415 command_buffer_allocate_info.commandPool = command_pool;
21416 command_buffer_allocate_info.commandBufferCount = 1;
21417 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
21418 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
21419
21420 // Begin our cmd buffer with renderpass using our framebuffer
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021421 VkRenderPassBeginInfo rpbi = {VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb, {{0, 0}, {32, 32}}, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021422 VkCommandBufferBeginInfo begin_info{};
21423 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21424 vkBeginCommandBuffer(command_buffer, &begin_info);
21425
21426 vkCmdBeginRenderPass(command_buffer, &rpbi, VK_SUBPASS_CONTENTS_INLINE);
21427 vkCmdEndRenderPass(command_buffer);
21428 vkEndCommandBuffer(command_buffer);
21429 vkDestroyImageView(m_device->device(), view, nullptr);
21430 // Destroy command pool to implicitly free command buffer
21431 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
21432 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
21433 vkDestroyRenderPass(m_device->device(), rp, nullptr);
21434 m_errorMonitor->VerifyNotFound();
21435}
21436
21437TEST_F(VkPositiveLayerTest, RenderPassSubpassZeroTransitionsApplied) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021438 TEST_DESCRIPTION(
21439 "Ensure that CmdBeginRenderPass applies the layout "
21440 "transitions for the first subpass");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021441
21442 m_errorMonitor->ExpectSuccess();
21443
Tony Barbour1fa09702017-03-16 12:09:08 -060021444 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021445
21446 // A renderpass with one color attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021447 VkAttachmentDescription attachment = {0,
21448 VK_FORMAT_R8G8B8A8_UNORM,
21449 VK_SAMPLE_COUNT_1_BIT,
21450 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
21451 VK_ATTACHMENT_STORE_OP_STORE,
21452 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
21453 VK_ATTACHMENT_STORE_OP_DONT_CARE,
21454 VK_IMAGE_LAYOUT_UNDEFINED,
21455 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021456
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021457 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021458
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021459 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021460
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021461 VkSubpassDependency dep = {0,
21462 0,
21463 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
21464 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
21465 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
21466 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
21467 VK_DEPENDENCY_BY_REGION_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021468
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021469 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021470
21471 VkResult err;
21472 VkRenderPass rp;
21473 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
21474 ASSERT_VK_SUCCESS(err);
21475
21476 // A compatible framebuffer.
21477 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060021478 image.Init(32, 32, 1, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021479 ASSERT_TRUE(image.initialized());
21480
21481 VkImageViewCreateInfo ivci = {
21482 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
21483 nullptr,
21484 0,
21485 image.handle(),
21486 VK_IMAGE_VIEW_TYPE_2D,
21487 VK_FORMAT_R8G8B8A8_UNORM,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021488 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
21489 VK_COMPONENT_SWIZZLE_IDENTITY},
21490 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021491 };
21492 VkImageView view;
21493 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
21494 ASSERT_VK_SUCCESS(err);
21495
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021496 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021497 VkFramebuffer fb;
21498 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
21499 ASSERT_VK_SUCCESS(err);
21500
21501 // Record a single command buffer which issues a pipeline barrier w/
21502 // image memory barrier for the attachment. This detects the previously
21503 // missing tracking of the subpass layout by throwing a validation error
21504 // if it doesn't occur.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021505 VkRenderPassBeginInfo rpbi = {VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb, {{0, 0}, {32, 32}}, 0, nullptr};
Tony Barbour552f6c02016-12-21 14:34:07 -070021506 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021507 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
21508
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021509 VkImageMemoryBarrier imb = {VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
21510 nullptr,
21511 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
21512 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
21513 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
21514 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
21515 VK_QUEUE_FAMILY_IGNORED,
21516 VK_QUEUE_FAMILY_IGNORED,
21517 image.handle(),
21518 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1}};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021519 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021520 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
21521 &imb);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021522
21523 vkCmdEndRenderPass(m_commandBuffer->handle());
21524 m_errorMonitor->VerifyNotFound();
Tony Barbour552f6c02016-12-21 14:34:07 -070021525 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021526
21527 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
21528 vkDestroyRenderPass(m_device->device(), rp, nullptr);
21529 vkDestroyImageView(m_device->device(), view, nullptr);
21530}
21531
21532TEST_F(VkPositiveLayerTest, DepthStencilLayoutTransitionForDepthOnlyImageview) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021533 TEST_DESCRIPTION(
21534 "Validate that when an imageView of a depth/stencil image "
21535 "is used as a depth/stencil framebuffer attachment, the "
21536 "aspectMask is ignored and both depth and stencil image "
21537 "subresources are used.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021538
Tony Barbour1fa09702017-03-16 12:09:08 -060021539 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021540 VkFormatProperties format_properties;
21541 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_D32_SFLOAT_S8_UINT, &format_properties);
21542 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
21543 return;
21544 }
21545
21546 m_errorMonitor->ExpectSuccess();
21547
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021548 VkAttachmentDescription attachment = {0,
21549 VK_FORMAT_D32_SFLOAT_S8_UINT,
21550 VK_SAMPLE_COUNT_1_BIT,
21551 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
21552 VK_ATTACHMENT_STORE_OP_STORE,
21553 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
21554 VK_ATTACHMENT_STORE_OP_DONT_CARE,
21555 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
21556 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021557
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021558 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021559
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021560 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, &att_ref, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021561
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021562 VkSubpassDependency dep = {0,
21563 0,
21564 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
21565 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
21566 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
21567 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
21568 VK_DEPENDENCY_BY_REGION_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021569
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021570 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021571
21572 VkResult err;
21573 VkRenderPass rp;
21574 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
21575 ASSERT_VK_SUCCESS(err);
21576
21577 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060021578 image.InitNoLayout(32, 32, 1, VK_FORMAT_D32_SFLOAT_S8_UINT,
21579 0x26, // usage
21580 VK_IMAGE_TILING_OPTIMAL, 0);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021581 ASSERT_TRUE(image.initialized());
21582 image.SetLayout(0x6, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
21583
21584 VkImageViewCreateInfo ivci = {
21585 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
21586 nullptr,
21587 0,
21588 image.handle(),
21589 VK_IMAGE_VIEW_TYPE_2D,
21590 VK_FORMAT_D32_SFLOAT_S8_UINT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021591 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
21592 {0x2, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021593 };
21594 VkImageView view;
21595 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
21596 ASSERT_VK_SUCCESS(err);
21597
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021598 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021599 VkFramebuffer fb;
21600 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
21601 ASSERT_VK_SUCCESS(err);
21602
Tony Barbour552f6c02016-12-21 14:34:07 -070021603 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021604
21605 VkImageMemoryBarrier imb = {};
21606 imb.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
21607 imb.pNext = nullptr;
21608 imb.srcAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
21609 imb.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
21610 imb.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
21611 imb.newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
21612 imb.srcQueueFamilyIndex = 0;
21613 imb.dstQueueFamilyIndex = 0;
21614 imb.image = image.handle();
21615 imb.subresourceRange.aspectMask = 0x6;
21616 imb.subresourceRange.baseMipLevel = 0;
21617 imb.subresourceRange.levelCount = 0x1;
21618 imb.subresourceRange.baseArrayLayer = 0;
21619 imb.subresourceRange.layerCount = 0x1;
21620
21621 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021622 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
21623 &imb);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021624
Tony Barbour552f6c02016-12-21 14:34:07 -070021625 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021626 QueueCommandBuffer(false);
21627 m_errorMonitor->VerifyNotFound();
21628
21629 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
21630 vkDestroyRenderPass(m_device->device(), rp, nullptr);
21631 vkDestroyImageView(m_device->device(), view, nullptr);
21632}
21633
21634TEST_F(VkPositiveLayerTest, RenderPassTransitionsAttachmentUnused) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021635 TEST_DESCRIPTION(
21636 "Ensure that layout transitions work correctly without "
21637 "errors, when an attachment reference is "
21638 "VK_ATTACHMENT_UNUSED");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021639
21640 m_errorMonitor->ExpectSuccess();
21641
Tony Barbour1fa09702017-03-16 12:09:08 -060021642 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021643
21644 // A renderpass with no attachments
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021645 VkAttachmentReference att_ref = {VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021646
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021647 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021648
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021649 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 1, &subpass, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021650
21651 VkRenderPass rp;
21652 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
21653 ASSERT_VK_SUCCESS(err);
21654
21655 // A compatible framebuffer.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021656 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021657 VkFramebuffer fb;
21658 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
21659 ASSERT_VK_SUCCESS(err);
21660
21661 // Record a command buffer which just begins and ends the renderpass. The
21662 // bug manifests in BeginRenderPass.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021663 VkRenderPassBeginInfo rpbi = {VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb, {{0, 0}, {32, 32}}, 0, nullptr};
Tony Barbour552f6c02016-12-21 14:34:07 -070021664 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021665 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
21666 vkCmdEndRenderPass(m_commandBuffer->handle());
21667 m_errorMonitor->VerifyNotFound();
Tony Barbour552f6c02016-12-21 14:34:07 -070021668 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021669
21670 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
21671 vkDestroyRenderPass(m_device->device(), rp, nullptr);
21672}
21673
21674// This is a positive test. No errors are expected.
21675TEST_F(VkPositiveLayerTest, StencilLoadOp) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021676 TEST_DESCRIPTION(
21677 "Create a stencil-only attachment with a LOAD_OP set to "
21678 "CLEAR. stencil[Load|Store]Op used to be ignored.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021679 VkResult result = VK_SUCCESS;
Tony Barbour1fa09702017-03-16 12:09:08 -060021680 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -060021681 auto depth_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbourf887b162017-03-09 10:06:46 -070021682 if (!depth_format) {
21683 printf(" No Depth + Stencil format found. Skipped.\n");
21684 return;
21685 }
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021686 VkImageFormatProperties formatProps;
Tony Barbourf887b162017-03-09 10:06:46 -070021687 vkGetPhysicalDeviceImageFormatProperties(gpu(), depth_format, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021688 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0,
21689 &formatProps);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021690 if (formatProps.maxExtent.width < 100 || formatProps.maxExtent.height < 100) {
21691 return;
21692 }
21693
Tony Barbourf887b162017-03-09 10:06:46 -070021694 VkFormat depth_stencil_fmt = depth_format;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021695 m_depthStencil->Init(m_device, 100, 100, depth_stencil_fmt,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021696 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021697 VkAttachmentDescription att = {};
21698 VkAttachmentReference ref = {};
21699 att.format = depth_stencil_fmt;
21700 att.samples = VK_SAMPLE_COUNT_1_BIT;
21701 att.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
21702 att.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
21703 att.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
21704 att.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE;
21705 att.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
21706 att.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
21707
21708 VkClearValue clear;
21709 clear.depthStencil.depth = 1.0;
21710 clear.depthStencil.stencil = 0;
21711 ref.attachment = 0;
21712 ref.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
21713
21714 VkSubpassDescription subpass = {};
21715 subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
21716 subpass.flags = 0;
21717 subpass.inputAttachmentCount = 0;
21718 subpass.pInputAttachments = NULL;
21719 subpass.colorAttachmentCount = 0;
21720 subpass.pColorAttachments = NULL;
21721 subpass.pResolveAttachments = NULL;
21722 subpass.pDepthStencilAttachment = &ref;
21723 subpass.preserveAttachmentCount = 0;
21724 subpass.pPreserveAttachments = NULL;
21725
21726 VkRenderPass rp;
21727 VkRenderPassCreateInfo rp_info = {};
21728 rp_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
21729 rp_info.attachmentCount = 1;
21730 rp_info.pAttachments = &att;
21731 rp_info.subpassCount = 1;
21732 rp_info.pSubpasses = &subpass;
21733 result = vkCreateRenderPass(device(), &rp_info, NULL, &rp);
21734 ASSERT_VK_SUCCESS(result);
21735
21736 VkImageView *depthView = m_depthStencil->BindInfo();
21737 VkFramebufferCreateInfo fb_info = {};
21738 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
21739 fb_info.pNext = NULL;
21740 fb_info.renderPass = rp;
21741 fb_info.attachmentCount = 1;
21742 fb_info.pAttachments = depthView;
21743 fb_info.width = 100;
21744 fb_info.height = 100;
21745 fb_info.layers = 1;
21746 VkFramebuffer fb;
21747 result = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
21748 ASSERT_VK_SUCCESS(result);
21749
21750 VkRenderPassBeginInfo rpbinfo = {};
21751 rpbinfo.clearValueCount = 1;
21752 rpbinfo.pClearValues = &clear;
21753 rpbinfo.pNext = NULL;
21754 rpbinfo.renderPass = rp;
21755 rpbinfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
21756 rpbinfo.renderArea.extent.width = 100;
21757 rpbinfo.renderArea.extent.height = 100;
21758 rpbinfo.renderArea.offset.x = 0;
21759 rpbinfo.renderArea.offset.y = 0;
21760 rpbinfo.framebuffer = fb;
21761
21762 VkFence fence = {};
21763 VkFenceCreateInfo fence_ci = {};
21764 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
21765 fence_ci.pNext = nullptr;
21766 fence_ci.flags = 0;
21767 result = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fence);
21768 ASSERT_VK_SUCCESS(result);
21769
21770 m_commandBuffer->BeginCommandBuffer();
21771 m_commandBuffer->BeginRenderPass(rpbinfo);
21772 m_commandBuffer->EndRenderPass();
21773 m_commandBuffer->EndCommandBuffer();
21774 m_commandBuffer->QueueCommandBuffer(fence);
21775
21776 VkImageObj destImage(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060021777 destImage.Init(100, 100, 1, depth_stencil_fmt, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021778 VK_IMAGE_TILING_OPTIMAL, 0);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021779 VkImageMemoryBarrier barrier = {};
21780 VkImageSubresourceRange range;
21781 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
21782 barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
21783 barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT;
21784 barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
21785 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
21786 barrier.image = m_depthStencil->handle();
21787 range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
21788 range.baseMipLevel = 0;
21789 range.levelCount = 1;
21790 range.baseArrayLayer = 0;
21791 range.layerCount = 1;
21792 barrier.subresourceRange = range;
21793 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
21794 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
21795 cmdbuf.BeginCommandBuffer();
21796 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021797 &barrier);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021798 barrier.srcAccessMask = 0;
21799 barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
21800 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
21801 barrier.image = destImage.handle();
21802 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
21803 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021804 &barrier);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021805 VkImageCopy cregion;
21806 cregion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
21807 cregion.srcSubresource.mipLevel = 0;
21808 cregion.srcSubresource.baseArrayLayer = 0;
21809 cregion.srcSubresource.layerCount = 1;
21810 cregion.srcOffset.x = 0;
21811 cregion.srcOffset.y = 0;
21812 cregion.srcOffset.z = 0;
21813 cregion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
21814 cregion.dstSubresource.mipLevel = 0;
21815 cregion.dstSubresource.baseArrayLayer = 0;
21816 cregion.dstSubresource.layerCount = 1;
21817 cregion.dstOffset.x = 0;
21818 cregion.dstOffset.y = 0;
21819 cregion.dstOffset.z = 0;
21820 cregion.extent.width = 100;
21821 cregion.extent.height = 100;
21822 cregion.extent.depth = 1;
21823 cmdbuf.CopyImage(m_depthStencil->handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, destImage.handle(),
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021824 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &cregion);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021825 cmdbuf.EndCommandBuffer();
21826
21827 VkSubmitInfo submit_info;
21828 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21829 submit_info.pNext = NULL;
21830 submit_info.waitSemaphoreCount = 0;
21831 submit_info.pWaitSemaphores = NULL;
21832 submit_info.pWaitDstStageMask = NULL;
21833 submit_info.commandBufferCount = 1;
21834 submit_info.pCommandBuffers = &cmdbuf.handle();
21835 submit_info.signalSemaphoreCount = 0;
21836 submit_info.pSignalSemaphores = NULL;
21837
21838 m_errorMonitor->ExpectSuccess();
21839 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
21840 m_errorMonitor->VerifyNotFound();
21841
21842 vkQueueWaitIdle(m_device->m_queue);
21843 vkDestroyFence(m_device->device(), fence, nullptr);
21844 vkDestroyRenderPass(m_device->device(), rp, nullptr);
21845 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
21846}
21847
21848// This is a positive test. No errors should be generated.
Mike Weiblene4e225d2017-03-07 23:15:43 -070021849TEST_F(VkPositiveLayerTest, BarrierLayoutToImageUsage) {
21850 TEST_DESCRIPTION("Ensure barriers' new and old VkImageLayout are compatible with their images' VkImageUsageFlags");
21851
21852 m_errorMonitor->ExpectSuccess();
21853
Tony Barbour1fa09702017-03-16 12:09:08 -060021854 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -060021855 auto depth_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbour9357d542017-03-24 15:42:21 -060021856 if (!depth_format) {
21857 printf(" No Depth + Stencil format found. Skipped.\n");
21858 return;
21859 }
Mike Weiblene4e225d2017-03-07 23:15:43 -070021860 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21861
21862 VkImageMemoryBarrier img_barrier = {};
21863 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
21864 img_barrier.pNext = NULL;
21865 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
21866 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
21867 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
21868 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
21869 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
21870 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
21871 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
21872 img_barrier.subresourceRange.baseArrayLayer = 0;
21873 img_barrier.subresourceRange.baseMipLevel = 0;
21874 img_barrier.subresourceRange.layerCount = 1;
21875 img_barrier.subresourceRange.levelCount = 1;
21876
21877 {
21878 VkImageObj img_color(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060021879 img_color.Init(128, 128, 1, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL);
Mike Weiblene4e225d2017-03-07 23:15:43 -070021880 ASSERT_TRUE(img_color.initialized());
21881
21882 VkImageObj img_ds1(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060021883 img_ds1.Init(128, 128, 1, depth_format, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL);
Mike Weiblene4e225d2017-03-07 23:15:43 -070021884 ASSERT_TRUE(img_ds1.initialized());
21885
21886 VkImageObj img_ds2(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060021887 img_ds2.Init(128, 128, 1, depth_format, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL);
Mike Weiblene4e225d2017-03-07 23:15:43 -070021888 ASSERT_TRUE(img_ds2.initialized());
21889
21890 VkImageObj img_xfer_src(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060021891 img_xfer_src.Init(128, 128, 1, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_OPTIMAL);
Mike Weiblene4e225d2017-03-07 23:15:43 -070021892 ASSERT_TRUE(img_xfer_src.initialized());
21893
21894 VkImageObj img_xfer_dst(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060021895 img_xfer_dst.Init(128, 128, 1, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_OPTIMAL);
Mike Weiblene4e225d2017-03-07 23:15:43 -070021896 ASSERT_TRUE(img_xfer_dst.initialized());
21897
21898 VkImageObj img_sampled(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060021899 img_sampled.Init(32, 32, 1, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL);
Mike Weiblene4e225d2017-03-07 23:15:43 -070021900 ASSERT_TRUE(img_sampled.initialized());
21901
21902 VkImageObj img_input(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060021903 img_input.Init(128, 128, 1, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL);
Mike Weiblene4e225d2017-03-07 23:15:43 -070021904 ASSERT_TRUE(img_input.initialized());
21905
21906 const struct {
21907 VkImageObj &image_obj;
21908 VkImageLayout old_layout;
21909 VkImageLayout new_layout;
21910 } buffer_layouts[] = {
21911 // clang-format off
21912 {img_color, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL},
21913 {img_ds1, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL},
21914 {img_ds2, VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL},
21915 {img_sampled, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL},
21916 {img_input, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL},
21917 {img_xfer_src, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL},
21918 {img_xfer_dst, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL},
21919 // clang-format on
21920 };
21921 const uint32_t layout_count = sizeof(buffer_layouts) / sizeof(buffer_layouts[0]);
21922
21923 m_commandBuffer->BeginCommandBuffer();
21924 for (uint32_t i = 0; i < layout_count; ++i) {
21925 img_barrier.image = buffer_layouts[i].image_obj.handle();
21926 const VkImageUsageFlags usage = buffer_layouts[i].image_obj.usage();
21927 img_barrier.subresourceRange.aspectMask = (usage == VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT)
21928 ? (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)
21929 : VK_IMAGE_ASPECT_COLOR_BIT;
21930
21931 img_barrier.oldLayout = buffer_layouts[i].old_layout;
21932 img_barrier.newLayout = buffer_layouts[i].new_layout;
21933 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT,
21934 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0, nullptr, 1, &img_barrier);
21935
21936 img_barrier.oldLayout = buffer_layouts[i].new_layout;
21937 img_barrier.newLayout = buffer_layouts[i].old_layout;
21938 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT,
21939 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0, nullptr, 1, &img_barrier);
21940 }
21941 m_commandBuffer->EndCommandBuffer();
21942
21943 img_barrier.oldLayout = VK_IMAGE_LAYOUT_GENERAL;
21944 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
21945 }
21946 m_errorMonitor->VerifyNotFound();
21947}
21948
21949// This is a positive test. No errors should be generated.
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021950TEST_F(VkPositiveLayerTest, WaitEventThenSet) {
21951 TEST_DESCRIPTION("Wait on a event then set it after the wait has been submitted.");
21952
21953 m_errorMonitor->ExpectSuccess();
Tony Barbour1fa09702017-03-16 12:09:08 -060021954 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021955
21956 VkEvent event;
21957 VkEventCreateInfo event_create_info{};
21958 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
21959 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
21960
21961 VkCommandPool command_pool;
21962 VkCommandPoolCreateInfo pool_create_info{};
21963 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
21964 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
21965 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
21966 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
21967
21968 VkCommandBuffer command_buffer;
21969 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
21970 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
21971 command_buffer_allocate_info.commandPool = command_pool;
21972 command_buffer_allocate_info.commandBufferCount = 1;
21973 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
21974 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
21975
21976 VkQueue queue = VK_NULL_HANDLE;
21977 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
21978
21979 {
21980 VkCommandBufferBeginInfo begin_info{};
21981 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21982 vkBeginCommandBuffer(command_buffer, &begin_info);
21983
21984 vkCmdWaitEvents(command_buffer, 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, nullptr, 0,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021985 nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021986 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
21987 vkEndCommandBuffer(command_buffer);
21988 }
21989 {
21990 VkSubmitInfo submit_info{};
21991 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21992 submit_info.commandBufferCount = 1;
21993 submit_info.pCommandBuffers = &command_buffer;
21994 submit_info.signalSemaphoreCount = 0;
21995 submit_info.pSignalSemaphores = nullptr;
21996 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
21997 }
21998 { vkSetEvent(m_device->device(), event); }
21999
22000 vkQueueWaitIdle(queue);
22001
22002 vkDestroyEvent(m_device->device(), event, nullptr);
22003 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
22004 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
22005
22006 m_errorMonitor->VerifyNotFound();
22007}
22008// This is a positive test. No errors should be generated.
22009TEST_F(VkPositiveLayerTest, QueryAndCopySecondaryCommandBuffers) {
22010 TEST_DESCRIPTION("Issue a query on a secondary command buffery and copy it on a primary.");
22011
Tony Barbour1fa09702017-03-16 12:09:08 -060022012 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022013 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022014
22015 m_errorMonitor->ExpectSuccess();
22016
22017 VkQueryPool query_pool;
22018 VkQueryPoolCreateInfo query_pool_create_info{};
22019 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
22020 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
22021 query_pool_create_info.queryCount = 1;
22022 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
22023
22024 VkCommandPool command_pool;
22025 VkCommandPoolCreateInfo pool_create_info{};
22026 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
22027 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
22028 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
22029 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
22030
22031 VkCommandBuffer command_buffer;
22032 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
22033 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
22034 command_buffer_allocate_info.commandPool = command_pool;
22035 command_buffer_allocate_info.commandBufferCount = 1;
22036 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
22037 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
22038
22039 VkCommandBuffer secondary_command_buffer;
22040 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
22041 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer);
22042
22043 VkQueue queue = VK_NULL_HANDLE;
22044 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
22045
22046 uint32_t qfi = 0;
22047 VkBufferCreateInfo buff_create_info = {};
22048 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
22049 buff_create_info.size = 1024;
22050 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
22051 buff_create_info.queueFamilyIndexCount = 1;
22052 buff_create_info.pQueueFamilyIndices = &qfi;
22053
22054 VkResult err;
22055 VkBuffer buffer;
22056 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
22057 ASSERT_VK_SUCCESS(err);
22058 VkMemoryAllocateInfo mem_alloc = {};
22059 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
22060 mem_alloc.pNext = NULL;
22061 mem_alloc.allocationSize = 1024;
22062 mem_alloc.memoryTypeIndex = 0;
22063
22064 VkMemoryRequirements memReqs;
22065 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
22066 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
22067 if (!pass) {
22068 vkDestroyBuffer(m_device->device(), buffer, NULL);
22069 return;
22070 }
22071
22072 VkDeviceMemory mem;
22073 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
22074 ASSERT_VK_SUCCESS(err);
22075 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
22076 ASSERT_VK_SUCCESS(err);
22077
22078 VkCommandBufferInheritanceInfo hinfo = {};
22079 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
22080 hinfo.renderPass = VK_NULL_HANDLE;
22081 hinfo.subpass = 0;
22082 hinfo.framebuffer = VK_NULL_HANDLE;
22083 hinfo.occlusionQueryEnable = VK_FALSE;
22084 hinfo.queryFlags = 0;
22085 hinfo.pipelineStatistics = 0;
22086
22087 {
22088 VkCommandBufferBeginInfo begin_info{};
22089 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22090 begin_info.pInheritanceInfo = &hinfo;
22091 vkBeginCommandBuffer(secondary_command_buffer, &begin_info);
22092
22093 vkCmdResetQueryPool(secondary_command_buffer, query_pool, 0, 1);
22094 vkCmdWriteTimestamp(secondary_command_buffer, VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
22095
22096 vkEndCommandBuffer(secondary_command_buffer);
22097
22098 begin_info.pInheritanceInfo = nullptr;
22099 vkBeginCommandBuffer(command_buffer, &begin_info);
22100
22101 vkCmdExecuteCommands(command_buffer, 1, &secondary_command_buffer);
22102 vkCmdCopyQueryPoolResults(command_buffer, query_pool, 0, 1, buffer, 0, 0, 0);
22103
22104 vkEndCommandBuffer(command_buffer);
22105 }
22106 {
22107 VkSubmitInfo submit_info{};
22108 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22109 submit_info.commandBufferCount = 1;
22110 submit_info.pCommandBuffers = &command_buffer;
22111 submit_info.signalSemaphoreCount = 0;
22112 submit_info.pSignalSemaphores = nullptr;
22113 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
22114 }
22115
22116 vkQueueWaitIdle(queue);
22117
22118 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
22119 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
22120 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &secondary_command_buffer);
22121 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
22122 vkDestroyBuffer(m_device->device(), buffer, NULL);
22123 vkFreeMemory(m_device->device(), mem, NULL);
22124
22125 m_errorMonitor->VerifyNotFound();
22126}
22127
22128// This is a positive test. No errors should be generated.
22129TEST_F(VkPositiveLayerTest, QueryAndCopyMultipleCommandBuffers) {
22130 TEST_DESCRIPTION("Issue a query and copy from it on a second command buffer.");
22131
Tony Barbour1fa09702017-03-16 12:09:08 -060022132 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022133 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022134
22135 m_errorMonitor->ExpectSuccess();
22136
22137 VkQueryPool query_pool;
22138 VkQueryPoolCreateInfo query_pool_create_info{};
22139 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
22140 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
22141 query_pool_create_info.queryCount = 1;
22142 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
22143
22144 VkCommandPool command_pool;
22145 VkCommandPoolCreateInfo pool_create_info{};
22146 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
22147 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
22148 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
22149 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
22150
22151 VkCommandBuffer command_buffer[2];
22152 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
22153 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
22154 command_buffer_allocate_info.commandPool = command_pool;
22155 command_buffer_allocate_info.commandBufferCount = 2;
22156 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
22157 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
22158
22159 VkQueue queue = VK_NULL_HANDLE;
22160 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
22161
22162 uint32_t qfi = 0;
22163 VkBufferCreateInfo buff_create_info = {};
22164 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
22165 buff_create_info.size = 1024;
22166 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
22167 buff_create_info.queueFamilyIndexCount = 1;
22168 buff_create_info.pQueueFamilyIndices = &qfi;
22169
22170 VkResult err;
22171 VkBuffer buffer;
22172 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
22173 ASSERT_VK_SUCCESS(err);
22174 VkMemoryAllocateInfo mem_alloc = {};
22175 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
22176 mem_alloc.pNext = NULL;
22177 mem_alloc.allocationSize = 1024;
22178 mem_alloc.memoryTypeIndex = 0;
22179
22180 VkMemoryRequirements memReqs;
22181 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
22182 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
22183 if (!pass) {
22184 vkDestroyBuffer(m_device->device(), buffer, NULL);
22185 return;
22186 }
22187
22188 VkDeviceMemory mem;
22189 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
22190 ASSERT_VK_SUCCESS(err);
22191 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
22192 ASSERT_VK_SUCCESS(err);
22193
22194 {
22195 VkCommandBufferBeginInfo begin_info{};
22196 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22197 vkBeginCommandBuffer(command_buffer[0], &begin_info);
22198
22199 vkCmdResetQueryPool(command_buffer[0], query_pool, 0, 1);
22200 vkCmdWriteTimestamp(command_buffer[0], VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
22201
22202 vkEndCommandBuffer(command_buffer[0]);
22203
22204 vkBeginCommandBuffer(command_buffer[1], &begin_info);
22205
22206 vkCmdCopyQueryPoolResults(command_buffer[1], query_pool, 0, 1, buffer, 0, 0, 0);
22207
22208 vkEndCommandBuffer(command_buffer[1]);
22209 }
22210 {
22211 VkSubmitInfo submit_info{};
22212 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22213 submit_info.commandBufferCount = 2;
22214 submit_info.pCommandBuffers = command_buffer;
22215 submit_info.signalSemaphoreCount = 0;
22216 submit_info.pSignalSemaphores = nullptr;
22217 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
22218 }
22219
22220 vkQueueWaitIdle(queue);
22221
22222 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
22223 vkFreeCommandBuffers(m_device->device(), command_pool, 2, command_buffer);
22224 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
22225 vkDestroyBuffer(m_device->device(), buffer, NULL);
22226 vkFreeMemory(m_device->device(), mem, NULL);
22227
22228 m_errorMonitor->VerifyNotFound();
22229}
22230
Tony Barbourc46924f2016-11-04 11:49:52 -060022231TEST_F(VkLayerTest, ResetEventThenSet) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022232 TEST_DESCRIPTION("Reset an event then set it after the reset has been submitted.");
22233
Tony Barbour1fa09702017-03-16 12:09:08 -060022234 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022235 VkEvent event;
22236 VkEventCreateInfo event_create_info{};
22237 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
22238 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
22239
22240 VkCommandPool command_pool;
22241 VkCommandPoolCreateInfo pool_create_info{};
22242 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
22243 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
22244 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
22245 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
22246
22247 VkCommandBuffer command_buffer;
22248 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
22249 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
22250 command_buffer_allocate_info.commandPool = command_pool;
22251 command_buffer_allocate_info.commandBufferCount = 1;
22252 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
22253 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
22254
22255 VkQueue queue = VK_NULL_HANDLE;
22256 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
22257
22258 {
22259 VkCommandBufferBeginInfo begin_info{};
22260 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22261 vkBeginCommandBuffer(command_buffer, &begin_info);
22262
22263 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022264 vkEndCommandBuffer(command_buffer);
22265 }
22266 {
22267 VkSubmitInfo submit_info{};
22268 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22269 submit_info.commandBufferCount = 1;
22270 submit_info.pCommandBuffers = &command_buffer;
22271 submit_info.signalSemaphoreCount = 0;
22272 submit_info.pSignalSemaphores = nullptr;
22273 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
22274 }
22275 {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022276 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
22277 "that is already in use by a "
22278 "command buffer.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022279 vkSetEvent(m_device->device(), event);
22280 m_errorMonitor->VerifyFound();
22281 }
22282
22283 vkQueueWaitIdle(queue);
22284
22285 vkDestroyEvent(m_device->device(), event, nullptr);
22286 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
22287 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
22288}
22289
22290// This is a positive test. No errors should be generated.
22291TEST_F(VkPositiveLayerTest, TwoFencesThreeFrames) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022292 TEST_DESCRIPTION(
22293 "Two command buffers with two separate fences are each "
22294 "run through a Submit & WaitForFences cycle 3 times. This "
22295 "previously revealed a bug so running this positive test "
22296 "to prevent a regression.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022297 m_errorMonitor->ExpectSuccess();
22298
Tony Barbour1fa09702017-03-16 12:09:08 -060022299 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022300 VkQueue queue = VK_NULL_HANDLE;
22301 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
22302
22303 static const uint32_t NUM_OBJECTS = 2;
22304 static const uint32_t NUM_FRAMES = 3;
22305 VkCommandBuffer cmd_buffers[NUM_OBJECTS] = {};
22306 VkFence fences[NUM_OBJECTS] = {};
22307
22308 VkCommandPool cmd_pool;
22309 VkCommandPoolCreateInfo cmd_pool_ci = {};
22310 cmd_pool_ci.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
22311 cmd_pool_ci.queueFamilyIndex = m_device->graphics_queue_node_index_;
22312 cmd_pool_ci.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
22313 VkResult err = vkCreateCommandPool(m_device->device(), &cmd_pool_ci, nullptr, &cmd_pool);
22314 ASSERT_VK_SUCCESS(err);
22315
22316 VkCommandBufferAllocateInfo cmd_buf_info = {};
22317 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
22318 cmd_buf_info.commandPool = cmd_pool;
22319 cmd_buf_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
22320 cmd_buf_info.commandBufferCount = 1;
22321
22322 VkFenceCreateInfo fence_ci = {};
22323 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
22324 fence_ci.pNext = nullptr;
22325 fence_ci.flags = 0;
22326
22327 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
22328 err = vkAllocateCommandBuffers(m_device->device(), &cmd_buf_info, &cmd_buffers[i]);
22329 ASSERT_VK_SUCCESS(err);
22330 err = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fences[i]);
22331 ASSERT_VK_SUCCESS(err);
22332 }
22333
22334 for (uint32_t frame = 0; frame < NUM_FRAMES; ++frame) {
22335 for (uint32_t obj = 0; obj < NUM_OBJECTS; ++obj) {
22336 // Create empty cmd buffer
22337 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
22338 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22339
22340 err = vkBeginCommandBuffer(cmd_buffers[obj], &cmdBufBeginDesc);
22341 ASSERT_VK_SUCCESS(err);
22342 err = vkEndCommandBuffer(cmd_buffers[obj]);
22343 ASSERT_VK_SUCCESS(err);
22344
22345 VkSubmitInfo submit_info = {};
22346 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22347 submit_info.commandBufferCount = 1;
22348 submit_info.pCommandBuffers = &cmd_buffers[obj];
22349 // Submit cmd buffer and wait for fence
22350 err = vkQueueSubmit(queue, 1, &submit_info, fences[obj]);
22351 ASSERT_VK_SUCCESS(err);
22352 err = vkWaitForFences(m_device->device(), 1, &fences[obj], VK_TRUE, UINT64_MAX);
22353 ASSERT_VK_SUCCESS(err);
22354 err = vkResetFences(m_device->device(), 1, &fences[obj]);
22355 ASSERT_VK_SUCCESS(err);
22356 }
22357 }
22358 m_errorMonitor->VerifyNotFound();
22359 vkDestroyCommandPool(m_device->device(), cmd_pool, NULL);
22360 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
22361 vkDestroyFence(m_device->device(), fences[i], nullptr);
22362 }
22363}
22364// This is a positive test. No errors should be generated.
22365TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWI) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022366 TEST_DESCRIPTION(
22367 "Two command buffers, each in a separate QueueSubmit call "
22368 "submitted on separate queues followed by a QueueWaitIdle.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022369
Tony Barbour1fa09702017-03-16 12:09:08 -060022370 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022371 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022372
22373 m_errorMonitor->ExpectSuccess();
22374
22375 VkSemaphore semaphore;
22376 VkSemaphoreCreateInfo semaphore_create_info{};
22377 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
22378 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
22379
22380 VkCommandPool command_pool;
22381 VkCommandPoolCreateInfo pool_create_info{};
22382 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
22383 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
22384 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
22385 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
22386
22387 VkCommandBuffer command_buffer[2];
22388 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
22389 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
22390 command_buffer_allocate_info.commandPool = command_pool;
22391 command_buffer_allocate_info.commandBufferCount = 2;
22392 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
22393 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
22394
22395 VkQueue queue = VK_NULL_HANDLE;
22396 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
22397
22398 {
22399 VkCommandBufferBeginInfo begin_info{};
22400 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22401 vkBeginCommandBuffer(command_buffer[0], &begin_info);
22402
22403 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022404 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022405
22406 VkViewport viewport{};
22407 viewport.maxDepth = 1.0f;
22408 viewport.minDepth = 0.0f;
22409 viewport.width = 512;
22410 viewport.height = 512;
22411 viewport.x = 0;
22412 viewport.y = 0;
22413 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
22414 vkEndCommandBuffer(command_buffer[0]);
22415 }
22416 {
22417 VkCommandBufferBeginInfo begin_info{};
22418 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22419 vkBeginCommandBuffer(command_buffer[1], &begin_info);
22420
22421 VkViewport viewport{};
22422 viewport.maxDepth = 1.0f;
22423 viewport.minDepth = 0.0f;
22424 viewport.width = 512;
22425 viewport.height = 512;
22426 viewport.x = 0;
22427 viewport.y = 0;
22428 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
22429 vkEndCommandBuffer(command_buffer[1]);
22430 }
22431 {
22432 VkSubmitInfo submit_info{};
22433 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22434 submit_info.commandBufferCount = 1;
22435 submit_info.pCommandBuffers = &command_buffer[0];
22436 submit_info.signalSemaphoreCount = 1;
22437 submit_info.pSignalSemaphores = &semaphore;
22438 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
22439 }
22440 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022441 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022442 VkSubmitInfo submit_info{};
22443 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22444 submit_info.commandBufferCount = 1;
22445 submit_info.pCommandBuffers = &command_buffer[1];
22446 submit_info.waitSemaphoreCount = 1;
22447 submit_info.pWaitSemaphores = &semaphore;
22448 submit_info.pWaitDstStageMask = flags;
22449 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
22450 }
22451
22452 vkQueueWaitIdle(m_device->m_queue);
22453
22454 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
22455 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
22456 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
22457
22458 m_errorMonitor->VerifyNotFound();
22459}
22460
22461// This is a positive test. No errors should be generated.
22462TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWIFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022463 TEST_DESCRIPTION(
22464 "Two command buffers, each in a separate QueueSubmit call "
22465 "submitted on separate queues, the second having a fence"
22466 "followed by a QueueWaitIdle.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022467
Tony Barbour1fa09702017-03-16 12:09:08 -060022468 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022469 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022470
22471 m_errorMonitor->ExpectSuccess();
22472
22473 VkFence fence;
22474 VkFenceCreateInfo fence_create_info{};
22475 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
22476 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
22477
22478 VkSemaphore semaphore;
22479 VkSemaphoreCreateInfo semaphore_create_info{};
22480 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
22481 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
22482
22483 VkCommandPool command_pool;
22484 VkCommandPoolCreateInfo pool_create_info{};
22485 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
22486 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
22487 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
22488 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
22489
22490 VkCommandBuffer command_buffer[2];
22491 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
22492 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
22493 command_buffer_allocate_info.commandPool = command_pool;
22494 command_buffer_allocate_info.commandBufferCount = 2;
22495 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
22496 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
22497
22498 VkQueue queue = VK_NULL_HANDLE;
22499 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
22500
22501 {
22502 VkCommandBufferBeginInfo begin_info{};
22503 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22504 vkBeginCommandBuffer(command_buffer[0], &begin_info);
22505
22506 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022507 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022508
22509 VkViewport viewport{};
22510 viewport.maxDepth = 1.0f;
22511 viewport.minDepth = 0.0f;
22512 viewport.width = 512;
22513 viewport.height = 512;
22514 viewport.x = 0;
22515 viewport.y = 0;
22516 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
22517 vkEndCommandBuffer(command_buffer[0]);
22518 }
22519 {
22520 VkCommandBufferBeginInfo begin_info{};
22521 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22522 vkBeginCommandBuffer(command_buffer[1], &begin_info);
22523
22524 VkViewport viewport{};
22525 viewport.maxDepth = 1.0f;
22526 viewport.minDepth = 0.0f;
22527 viewport.width = 512;
22528 viewport.height = 512;
22529 viewport.x = 0;
22530 viewport.y = 0;
22531 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
22532 vkEndCommandBuffer(command_buffer[1]);
22533 }
22534 {
22535 VkSubmitInfo submit_info{};
22536 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22537 submit_info.commandBufferCount = 1;
22538 submit_info.pCommandBuffers = &command_buffer[0];
22539 submit_info.signalSemaphoreCount = 1;
22540 submit_info.pSignalSemaphores = &semaphore;
22541 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
22542 }
22543 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022544 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022545 VkSubmitInfo submit_info{};
22546 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22547 submit_info.commandBufferCount = 1;
22548 submit_info.pCommandBuffers = &command_buffer[1];
22549 submit_info.waitSemaphoreCount = 1;
22550 submit_info.pWaitSemaphores = &semaphore;
22551 submit_info.pWaitDstStageMask = flags;
22552 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
22553 }
22554
22555 vkQueueWaitIdle(m_device->m_queue);
22556
22557 vkDestroyFence(m_device->device(), fence, nullptr);
22558 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
22559 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
22560 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
22561
22562 m_errorMonitor->VerifyNotFound();
22563}
22564
22565// This is a positive test. No errors should be generated.
22566TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceTwoWFF) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022567 TEST_DESCRIPTION(
22568 "Two command buffers, each in a separate QueueSubmit call "
22569 "submitted on separate queues, the second having a fence"
22570 "followed by two consecutive WaitForFences calls on the same fence.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022571
Tony Barbour1fa09702017-03-16 12:09:08 -060022572 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022573 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022574
22575 m_errorMonitor->ExpectSuccess();
22576
22577 VkFence fence;
22578 VkFenceCreateInfo fence_create_info{};
22579 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
22580 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
22581
22582 VkSemaphore semaphore;
22583 VkSemaphoreCreateInfo semaphore_create_info{};
22584 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
22585 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
22586
22587 VkCommandPool command_pool;
22588 VkCommandPoolCreateInfo pool_create_info{};
22589 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
22590 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
22591 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
22592 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
22593
22594 VkCommandBuffer command_buffer[2];
22595 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
22596 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
22597 command_buffer_allocate_info.commandPool = command_pool;
22598 command_buffer_allocate_info.commandBufferCount = 2;
22599 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
22600 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
22601
22602 VkQueue queue = VK_NULL_HANDLE;
22603 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
22604
22605 {
22606 VkCommandBufferBeginInfo begin_info{};
22607 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22608 vkBeginCommandBuffer(command_buffer[0], &begin_info);
22609
22610 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022611 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022612
22613 VkViewport viewport{};
22614 viewport.maxDepth = 1.0f;
22615 viewport.minDepth = 0.0f;
22616 viewport.width = 512;
22617 viewport.height = 512;
22618 viewport.x = 0;
22619 viewport.y = 0;
22620 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
22621 vkEndCommandBuffer(command_buffer[0]);
22622 }
22623 {
22624 VkCommandBufferBeginInfo begin_info{};
22625 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22626 vkBeginCommandBuffer(command_buffer[1], &begin_info);
22627
22628 VkViewport viewport{};
22629 viewport.maxDepth = 1.0f;
22630 viewport.minDepth = 0.0f;
22631 viewport.width = 512;
22632 viewport.height = 512;
22633 viewport.x = 0;
22634 viewport.y = 0;
22635 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
22636 vkEndCommandBuffer(command_buffer[1]);
22637 }
22638 {
22639 VkSubmitInfo submit_info{};
22640 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22641 submit_info.commandBufferCount = 1;
22642 submit_info.pCommandBuffers = &command_buffer[0];
22643 submit_info.signalSemaphoreCount = 1;
22644 submit_info.pSignalSemaphores = &semaphore;
22645 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
22646 }
22647 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022648 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022649 VkSubmitInfo submit_info{};
22650 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22651 submit_info.commandBufferCount = 1;
22652 submit_info.pCommandBuffers = &command_buffer[1];
22653 submit_info.waitSemaphoreCount = 1;
22654 submit_info.pWaitSemaphores = &semaphore;
22655 submit_info.pWaitDstStageMask = flags;
22656 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
22657 }
22658
22659 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
22660 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
22661
22662 vkDestroyFence(m_device->device(), fence, nullptr);
22663 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
22664 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
22665 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
22666
22667 m_errorMonitor->VerifyNotFound();
22668}
22669
22670TEST_F(VkPositiveLayerTest, TwoQueuesEnsureCorrectRetirementWithWorkStolen) {
Tony Barbour1fa09702017-03-16 12:09:08 -060022671 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022672 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070022673 printf(" Test requires two queues, skipping\n");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022674 return;
22675 }
22676
22677 VkResult err;
22678
22679 m_errorMonitor->ExpectSuccess();
22680
22681 VkQueue q0 = m_device->m_queue;
22682 VkQueue q1 = nullptr;
22683 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &q1);
22684 ASSERT_NE(q1, nullptr);
22685
22686 // An (empty) command buffer. We must have work in the first submission --
22687 // the layer treats unfenced work differently from fenced work.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022688 VkCommandPoolCreateInfo cpci = {VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, nullptr, 0, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022689 VkCommandPool pool;
22690 err = vkCreateCommandPool(m_device->device(), &cpci, nullptr, &pool);
22691 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022692 VkCommandBufferAllocateInfo cbai = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, nullptr, pool,
22693 VK_COMMAND_BUFFER_LEVEL_PRIMARY, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022694 VkCommandBuffer cb;
22695 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &cb);
22696 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022697 VkCommandBufferBeginInfo cbbi = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022698 err = vkBeginCommandBuffer(cb, &cbbi);
22699 ASSERT_VK_SUCCESS(err);
22700 err = vkEndCommandBuffer(cb);
22701 ASSERT_VK_SUCCESS(err);
22702
22703 // A semaphore
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022704 VkSemaphoreCreateInfo sci = {VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022705 VkSemaphore s;
22706 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s);
22707 ASSERT_VK_SUCCESS(err);
22708
22709 // First submission, to q0
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022710 VkSubmitInfo s0 = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &cb, 1, &s};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022711
22712 err = vkQueueSubmit(q0, 1, &s0, VK_NULL_HANDLE);
22713 ASSERT_VK_SUCCESS(err);
22714
22715 // Second submission, to q1, waiting on s
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022716 VkFlags waitmask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; // doesn't really matter what this value is.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022717 VkSubmitInfo s1 = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 1, &s, &waitmask, 0, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022718
22719 err = vkQueueSubmit(q1, 1, &s1, VK_NULL_HANDLE);
22720 ASSERT_VK_SUCCESS(err);
22721
22722 // Wait for q0 idle
22723 err = vkQueueWaitIdle(q0);
22724 ASSERT_VK_SUCCESS(err);
22725
22726 // Command buffer should have been completed (it was on q0); reset the pool.
22727 vkFreeCommandBuffers(m_device->device(), pool, 1, &cb);
22728
22729 m_errorMonitor->VerifyNotFound();
22730
22731 // Force device completely idle and clean up resources
22732 vkDeviceWaitIdle(m_device->device());
22733 vkDestroyCommandPool(m_device->device(), pool, nullptr);
22734 vkDestroySemaphore(m_device->device(), s, nullptr);
22735}
22736
22737// This is a positive test. No errors should be generated.
22738TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022739 TEST_DESCRIPTION(
22740 "Two command buffers, each in a separate QueueSubmit call "
22741 "submitted on separate queues, the second having a fence, "
22742 "followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022743
Tony Barbour1fa09702017-03-16 12:09:08 -060022744 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022745 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022746
22747 m_errorMonitor->ExpectSuccess();
22748
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022749 VkFence fence;
22750 VkFenceCreateInfo fence_create_info{};
22751 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
22752 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
22753
22754 VkSemaphore semaphore;
22755 VkSemaphoreCreateInfo semaphore_create_info{};
22756 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
22757 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
22758
22759 VkCommandPool command_pool;
22760 VkCommandPoolCreateInfo pool_create_info{};
22761 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
22762 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
22763 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
22764 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
22765
22766 VkCommandBuffer command_buffer[2];
22767 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
22768 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
22769 command_buffer_allocate_info.commandPool = command_pool;
22770 command_buffer_allocate_info.commandBufferCount = 2;
22771 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
22772 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
22773
22774 VkQueue queue = VK_NULL_HANDLE;
22775 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
22776
22777 {
22778 VkCommandBufferBeginInfo begin_info{};
22779 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22780 vkBeginCommandBuffer(command_buffer[0], &begin_info);
22781
22782 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022783 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022784
22785 VkViewport viewport{};
22786 viewport.maxDepth = 1.0f;
22787 viewport.minDepth = 0.0f;
22788 viewport.width = 512;
22789 viewport.height = 512;
22790 viewport.x = 0;
22791 viewport.y = 0;
22792 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
22793 vkEndCommandBuffer(command_buffer[0]);
22794 }
22795 {
22796 VkCommandBufferBeginInfo begin_info{};
22797 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22798 vkBeginCommandBuffer(command_buffer[1], &begin_info);
22799
22800 VkViewport viewport{};
22801 viewport.maxDepth = 1.0f;
22802 viewport.minDepth = 0.0f;
22803 viewport.width = 512;
22804 viewport.height = 512;
22805 viewport.x = 0;
22806 viewport.y = 0;
22807 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
22808 vkEndCommandBuffer(command_buffer[1]);
22809 }
22810 {
22811 VkSubmitInfo submit_info{};
22812 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22813 submit_info.commandBufferCount = 1;
22814 submit_info.pCommandBuffers = &command_buffer[0];
22815 submit_info.signalSemaphoreCount = 1;
22816 submit_info.pSignalSemaphores = &semaphore;
22817 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
22818 }
22819 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022820 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022821 VkSubmitInfo submit_info{};
22822 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22823 submit_info.commandBufferCount = 1;
22824 submit_info.pCommandBuffers = &command_buffer[1];
22825 submit_info.waitSemaphoreCount = 1;
22826 submit_info.pWaitSemaphores = &semaphore;
22827 submit_info.pWaitDstStageMask = flags;
22828 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
22829 }
22830
22831 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
22832
22833 vkDestroyFence(m_device->device(), fence, nullptr);
22834 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
22835 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
22836 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
22837
22838 m_errorMonitor->VerifyNotFound();
22839}
22840
22841// This is a positive test. No errors should be generated.
22842TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueWithSemaphoreAndOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022843 TEST_DESCRIPTION(
22844 "Two command buffers, each in a separate QueueSubmit call "
22845 "on the same queue, sharing a signal/wait semaphore, the "
22846 "second having a fence, "
22847 "followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022848
22849 m_errorMonitor->ExpectSuccess();
22850
Tony Barbour1fa09702017-03-16 12:09:08 -060022851 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022852 VkFence fence;
22853 VkFenceCreateInfo fence_create_info{};
22854 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
22855 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
22856
22857 VkSemaphore semaphore;
22858 VkSemaphoreCreateInfo semaphore_create_info{};
22859 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
22860 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
22861
22862 VkCommandPool command_pool;
22863 VkCommandPoolCreateInfo pool_create_info{};
22864 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
22865 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
22866 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
22867 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
22868
22869 VkCommandBuffer command_buffer[2];
22870 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
22871 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
22872 command_buffer_allocate_info.commandPool = command_pool;
22873 command_buffer_allocate_info.commandBufferCount = 2;
22874 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
22875 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
22876
22877 {
22878 VkCommandBufferBeginInfo begin_info{};
22879 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22880 vkBeginCommandBuffer(command_buffer[0], &begin_info);
22881
22882 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022883 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022884
22885 VkViewport viewport{};
22886 viewport.maxDepth = 1.0f;
22887 viewport.minDepth = 0.0f;
22888 viewport.width = 512;
22889 viewport.height = 512;
22890 viewport.x = 0;
22891 viewport.y = 0;
22892 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
22893 vkEndCommandBuffer(command_buffer[0]);
22894 }
22895 {
22896 VkCommandBufferBeginInfo begin_info{};
22897 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22898 vkBeginCommandBuffer(command_buffer[1], &begin_info);
22899
22900 VkViewport viewport{};
22901 viewport.maxDepth = 1.0f;
22902 viewport.minDepth = 0.0f;
22903 viewport.width = 512;
22904 viewport.height = 512;
22905 viewport.x = 0;
22906 viewport.y = 0;
22907 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
22908 vkEndCommandBuffer(command_buffer[1]);
22909 }
22910 {
22911 VkSubmitInfo submit_info{};
22912 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22913 submit_info.commandBufferCount = 1;
22914 submit_info.pCommandBuffers = &command_buffer[0];
22915 submit_info.signalSemaphoreCount = 1;
22916 submit_info.pSignalSemaphores = &semaphore;
22917 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
22918 }
22919 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022920 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022921 VkSubmitInfo submit_info{};
22922 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22923 submit_info.commandBufferCount = 1;
22924 submit_info.pCommandBuffers = &command_buffer[1];
22925 submit_info.waitSemaphoreCount = 1;
22926 submit_info.pWaitSemaphores = &semaphore;
22927 submit_info.pWaitDstStageMask = flags;
22928 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
22929 }
22930
22931 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
22932
22933 vkDestroyFence(m_device->device(), fence, nullptr);
22934 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
22935 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
22936 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
22937
22938 m_errorMonitor->VerifyNotFound();
22939}
22940
22941// This is a positive test. No errors should be generated.
22942TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueNullQueueSubmitWithFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022943 TEST_DESCRIPTION(
22944 "Two command buffers, each in a separate QueueSubmit call "
22945 "on the same queue, no fences, followed by a third QueueSubmit with NO "
22946 "SubmitInfos but with a fence, followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022947
22948 m_errorMonitor->ExpectSuccess();
22949
Tony Barbour1fa09702017-03-16 12:09:08 -060022950 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022951 VkFence fence;
22952 VkFenceCreateInfo fence_create_info{};
22953 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
22954 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
22955
22956 VkCommandPool command_pool;
22957 VkCommandPoolCreateInfo pool_create_info{};
22958 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
22959 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
22960 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
22961 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
22962
22963 VkCommandBuffer command_buffer[2];
22964 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
22965 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
22966 command_buffer_allocate_info.commandPool = command_pool;
22967 command_buffer_allocate_info.commandBufferCount = 2;
22968 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
22969 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
22970
22971 {
22972 VkCommandBufferBeginInfo begin_info{};
22973 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22974 vkBeginCommandBuffer(command_buffer[0], &begin_info);
22975
22976 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022977 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022978
22979 VkViewport viewport{};
22980 viewport.maxDepth = 1.0f;
22981 viewport.minDepth = 0.0f;
22982 viewport.width = 512;
22983 viewport.height = 512;
22984 viewport.x = 0;
22985 viewport.y = 0;
22986 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
22987 vkEndCommandBuffer(command_buffer[0]);
22988 }
22989 {
22990 VkCommandBufferBeginInfo begin_info{};
22991 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22992 vkBeginCommandBuffer(command_buffer[1], &begin_info);
22993
22994 VkViewport viewport{};
22995 viewport.maxDepth = 1.0f;
22996 viewport.minDepth = 0.0f;
22997 viewport.width = 512;
22998 viewport.height = 512;
22999 viewport.x = 0;
23000 viewport.y = 0;
23001 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
23002 vkEndCommandBuffer(command_buffer[1]);
23003 }
23004 {
23005 VkSubmitInfo submit_info{};
23006 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
23007 submit_info.commandBufferCount = 1;
23008 submit_info.pCommandBuffers = &command_buffer[0];
23009 submit_info.signalSemaphoreCount = 0;
23010 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
23011 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
23012 }
23013 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023014 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023015 VkSubmitInfo submit_info{};
23016 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
23017 submit_info.commandBufferCount = 1;
23018 submit_info.pCommandBuffers = &command_buffer[1];
23019 submit_info.waitSemaphoreCount = 0;
23020 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
23021 submit_info.pWaitDstStageMask = flags;
23022 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
23023 }
23024
23025 vkQueueSubmit(m_device->m_queue, 0, NULL, fence);
23026
23027 VkResult err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
23028 ASSERT_VK_SUCCESS(err);
23029
23030 vkDestroyFence(m_device->device(), fence, nullptr);
23031 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
23032 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
23033
23034 m_errorMonitor->VerifyNotFound();
23035}
23036
23037// This is a positive test. No errors should be generated.
23038TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023039 TEST_DESCRIPTION(
23040 "Two command buffers, each in a separate QueueSubmit call "
23041 "on the same queue, the second having a fence, followed "
23042 "by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023043
23044 m_errorMonitor->ExpectSuccess();
23045
Tony Barbour1fa09702017-03-16 12:09:08 -060023046 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023047 VkFence fence;
23048 VkFenceCreateInfo fence_create_info{};
23049 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
23050 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
23051
23052 VkCommandPool command_pool;
23053 VkCommandPoolCreateInfo pool_create_info{};
23054 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
23055 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
23056 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
23057 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
23058
23059 VkCommandBuffer command_buffer[2];
23060 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
23061 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
23062 command_buffer_allocate_info.commandPool = command_pool;
23063 command_buffer_allocate_info.commandBufferCount = 2;
23064 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
23065 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
23066
23067 {
23068 VkCommandBufferBeginInfo begin_info{};
23069 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
23070 vkBeginCommandBuffer(command_buffer[0], &begin_info);
23071
23072 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023073 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023074
23075 VkViewport viewport{};
23076 viewport.maxDepth = 1.0f;
23077 viewport.minDepth = 0.0f;
23078 viewport.width = 512;
23079 viewport.height = 512;
23080 viewport.x = 0;
23081 viewport.y = 0;
23082 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
23083 vkEndCommandBuffer(command_buffer[0]);
23084 }
23085 {
23086 VkCommandBufferBeginInfo begin_info{};
23087 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
23088 vkBeginCommandBuffer(command_buffer[1], &begin_info);
23089
23090 VkViewport viewport{};
23091 viewport.maxDepth = 1.0f;
23092 viewport.minDepth = 0.0f;
23093 viewport.width = 512;
23094 viewport.height = 512;
23095 viewport.x = 0;
23096 viewport.y = 0;
23097 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
23098 vkEndCommandBuffer(command_buffer[1]);
23099 }
23100 {
23101 VkSubmitInfo submit_info{};
23102 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
23103 submit_info.commandBufferCount = 1;
23104 submit_info.pCommandBuffers = &command_buffer[0];
23105 submit_info.signalSemaphoreCount = 0;
23106 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
23107 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
23108 }
23109 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023110 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023111 VkSubmitInfo submit_info{};
23112 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
23113 submit_info.commandBufferCount = 1;
23114 submit_info.pCommandBuffers = &command_buffer[1];
23115 submit_info.waitSemaphoreCount = 0;
23116 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
23117 submit_info.pWaitDstStageMask = flags;
23118 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
23119 }
23120
23121 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
23122
23123 vkDestroyFence(m_device->device(), fence, nullptr);
23124 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
23125 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
23126
23127 m_errorMonitor->VerifyNotFound();
23128}
23129
23130// This is a positive test. No errors should be generated.
23131TEST_F(VkPositiveLayerTest, TwoSubmitInfosWithSemaphoreOneQueueSubmitsOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023132 TEST_DESCRIPTION(
23133 "Two command buffers each in a separate SubmitInfo sent in a single "
23134 "QueueSubmit call followed by a WaitForFences call.");
Tony Barbour1fa09702017-03-16 12:09:08 -060023135 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023136
23137 m_errorMonitor->ExpectSuccess();
23138
23139 VkFence fence;
23140 VkFenceCreateInfo fence_create_info{};
23141 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
23142 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
23143
23144 VkSemaphore semaphore;
23145 VkSemaphoreCreateInfo semaphore_create_info{};
23146 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
23147 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
23148
23149 VkCommandPool command_pool;
23150 VkCommandPoolCreateInfo pool_create_info{};
23151 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
23152 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
23153 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
23154 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
23155
23156 VkCommandBuffer command_buffer[2];
23157 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
23158 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
23159 command_buffer_allocate_info.commandPool = command_pool;
23160 command_buffer_allocate_info.commandBufferCount = 2;
23161 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
23162 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
23163
23164 {
23165 VkCommandBufferBeginInfo begin_info{};
23166 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
23167 vkBeginCommandBuffer(command_buffer[0], &begin_info);
23168
23169 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023170 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023171
23172 VkViewport viewport{};
23173 viewport.maxDepth = 1.0f;
23174 viewport.minDepth = 0.0f;
23175 viewport.width = 512;
23176 viewport.height = 512;
23177 viewport.x = 0;
23178 viewport.y = 0;
23179 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
23180 vkEndCommandBuffer(command_buffer[0]);
23181 }
23182 {
23183 VkCommandBufferBeginInfo begin_info{};
23184 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
23185 vkBeginCommandBuffer(command_buffer[1], &begin_info);
23186
23187 VkViewport viewport{};
23188 viewport.maxDepth = 1.0f;
23189 viewport.minDepth = 0.0f;
23190 viewport.width = 512;
23191 viewport.height = 512;
23192 viewport.x = 0;
23193 viewport.y = 0;
23194 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
23195 vkEndCommandBuffer(command_buffer[1]);
23196 }
23197 {
23198 VkSubmitInfo submit_info[2];
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023199 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023200
23201 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
23202 submit_info[0].pNext = NULL;
23203 submit_info[0].commandBufferCount = 1;
23204 submit_info[0].pCommandBuffers = &command_buffer[0];
23205 submit_info[0].signalSemaphoreCount = 1;
23206 submit_info[0].pSignalSemaphores = &semaphore;
23207 submit_info[0].waitSemaphoreCount = 0;
23208 submit_info[0].pWaitSemaphores = NULL;
23209 submit_info[0].pWaitDstStageMask = 0;
23210
23211 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
23212 submit_info[1].pNext = NULL;
23213 submit_info[1].commandBufferCount = 1;
23214 submit_info[1].pCommandBuffers = &command_buffer[1];
23215 submit_info[1].waitSemaphoreCount = 1;
23216 submit_info[1].pWaitSemaphores = &semaphore;
23217 submit_info[1].pWaitDstStageMask = flags;
23218 submit_info[1].signalSemaphoreCount = 0;
23219 submit_info[1].pSignalSemaphores = NULL;
23220 vkQueueSubmit(m_device->m_queue, 2, &submit_info[0], fence);
23221 }
23222
23223 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
23224
23225 vkDestroyFence(m_device->device(), fence, nullptr);
23226 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
23227 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
23228 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
23229
23230 m_errorMonitor->VerifyNotFound();
23231}
23232
23233TEST_F(VkPositiveLayerTest, RenderPassSecondaryCommandBuffersMultipleTimes) {
23234 m_errorMonitor->ExpectSuccess();
23235
Tony Barbour1fa09702017-03-16 12:09:08 -060023236 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023237 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
23238
Tony Barbour552f6c02016-12-21 14:34:07 -070023239 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023240
23241 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
23242 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
23243 m_errorMonitor->VerifyNotFound();
23244 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
23245 m_errorMonitor->VerifyNotFound();
23246 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
23247 m_errorMonitor->VerifyNotFound();
23248
23249 m_commandBuffer->EndCommandBuffer();
23250 m_errorMonitor->VerifyNotFound();
23251}
23252
23253TEST_F(VkPositiveLayerTest, ValidRenderPassAttachmentLayoutWithLoadOp) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023254 TEST_DESCRIPTION(
23255 "Positive test where we create a renderpass with an "
23256 "attachment that uses LOAD_OP_CLEAR, the first subpass "
23257 "has a valid layout, and a second subpass then uses a "
23258 "valid *READ_ONLY* layout.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023259 m_errorMonitor->ExpectSuccess();
Tony Barbour1fa09702017-03-16 12:09:08 -060023260 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -060023261 auto depth_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbourf887b162017-03-09 10:06:46 -070023262 if (!depth_format) {
23263 printf(" No Depth + Stencil format found. Skipped.\n");
23264 return;
23265 }
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023266
23267 VkAttachmentReference attach[2] = {};
23268 attach[0].attachment = 0;
23269 attach[0].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
23270 attach[1].attachment = 0;
23271 attach[1].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
23272 VkSubpassDescription subpasses[2] = {};
23273 // First subpass clears DS attach on load
23274 subpasses[0].pDepthStencilAttachment = &attach[0];
23275 // 2nd subpass reads in DS as input attachment
23276 subpasses[1].inputAttachmentCount = 1;
23277 subpasses[1].pInputAttachments = &attach[1];
23278 VkAttachmentDescription attach_desc = {};
Tony Barbourf887b162017-03-09 10:06:46 -070023279 attach_desc.format = depth_format;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023280 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
23281 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
23282 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
23283 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
23284 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
23285 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
23286 attach_desc.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
23287 VkRenderPassCreateInfo rpci = {};
23288 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
23289 rpci.attachmentCount = 1;
23290 rpci.pAttachments = &attach_desc;
23291 rpci.subpassCount = 2;
23292 rpci.pSubpasses = subpasses;
23293
23294 // Now create RenderPass and verify no errors
23295 VkRenderPass rp;
23296 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
23297 m_errorMonitor->VerifyNotFound();
23298
23299 vkDestroyRenderPass(m_device->device(), rp, NULL);
23300}
23301
Tobin Ehlis01103de2017-02-16 13:22:47 -070023302TEST_F(VkPositiveLayerTest, RenderPassDepthStencilLayoutTransition) {
23303 TEST_DESCRIPTION(
23304 "Create a render pass with depth-stencil attachment where layout transition "
23305 "from UNDEFINED TO DS_READ_ONLY_OPTIMAL is set by render pass and verify that "
23306 "transition has correctly occurred at queue submit time with no validation errors.");
23307
Tony Barbour1fa09702017-03-16 12:09:08 -060023308 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -060023309 auto depth_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbourf887b162017-03-09 10:06:46 -070023310 if (!depth_format) {
23311 printf(" No Depth + Stencil format found. Skipped.\n");
23312 return;
23313 }
Tobin Ehlis01103de2017-02-16 13:22:47 -070023314 VkImageFormatProperties format_props;
Tony Barbourf887b162017-03-09 10:06:46 -070023315 vkGetPhysicalDeviceImageFormatProperties(gpu(), depth_format, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
Tobin Ehlis01103de2017-02-16 13:22:47 -070023316 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, 0, &format_props);
23317 if (format_props.maxExtent.width < 32 || format_props.maxExtent.height < 32) {
Tony Barbourf887b162017-03-09 10:06:46 -070023318 printf("Depth extent too small, RenderPassDepthStencilLayoutTransition skipped.\n");
Tobin Ehlis01103de2017-02-16 13:22:47 -070023319 return;
23320 }
23321
23322 m_errorMonitor->ExpectSuccess();
Tobin Ehlis01103de2017-02-16 13:22:47 -070023323 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
23324
23325 // A renderpass with one depth/stencil attachment.
23326 VkAttachmentDescription attachment = {0,
Tony Barbourf887b162017-03-09 10:06:46 -070023327 depth_format,
Tobin Ehlis01103de2017-02-16 13:22:47 -070023328 VK_SAMPLE_COUNT_1_BIT,
23329 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
23330 VK_ATTACHMENT_STORE_OP_DONT_CARE,
23331 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
23332 VK_ATTACHMENT_STORE_OP_DONT_CARE,
23333 VK_IMAGE_LAYOUT_UNDEFINED,
23334 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
23335
23336 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
23337
23338 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, &att_ref, 0, nullptr};
23339
23340 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
23341
23342 VkRenderPass rp;
23343 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
23344 ASSERT_VK_SUCCESS(err);
23345 // A compatible ds image.
23346 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060023347 image.Init(32, 32, 1, depth_format, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Tobin Ehlis01103de2017-02-16 13:22:47 -070023348 ASSERT_TRUE(image.initialized());
23349
23350 VkImageViewCreateInfo ivci = {
23351 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
23352 nullptr,
23353 0,
23354 image.handle(),
23355 VK_IMAGE_VIEW_TYPE_2D,
Tony Barbourf887b162017-03-09 10:06:46 -070023356 depth_format,
Tobin Ehlis01103de2017-02-16 13:22:47 -070023357 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
23358 VK_COMPONENT_SWIZZLE_IDENTITY},
23359 {VK_IMAGE_ASPECT_DEPTH_BIT, 0, 1, 0, 1},
23360 };
23361 VkImageView view;
23362 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
23363 ASSERT_VK_SUCCESS(err);
23364
23365 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
23366 VkFramebuffer fb;
23367 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
23368 ASSERT_VK_SUCCESS(err);
23369
23370 VkRenderPassBeginInfo rpbi = {VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb, {{0, 0}, {32, 32}}, 0, nullptr};
23371 m_commandBuffer->BeginCommandBuffer();
23372 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
23373 vkCmdEndRenderPass(m_commandBuffer->handle());
23374 m_commandBuffer->EndCommandBuffer();
23375 QueueCommandBuffer(false);
23376 m_errorMonitor->VerifyNotFound();
23377
23378 // Cleanup
23379 vkDestroyImageView(m_device->device(), view, NULL);
23380 vkDestroyRenderPass(m_device->device(), rp, NULL);
23381 vkDestroyFramebuffer(m_device->device(), fb, NULL);
23382}
23383
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023384TEST_F(VkPositiveLayerTest, CreatePipelineAttribMatrixType) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023385 TEST_DESCRIPTION(
23386 "Test that pipeline validation accepts matrices passed "
23387 "as vertex attributes");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023388 m_errorMonitor->ExpectSuccess();
23389
Tony Barbour1fa09702017-03-16 12:09:08 -060023390 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023391 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
23392
23393 VkVertexInputBindingDescription input_binding;
23394 memset(&input_binding, 0, sizeof(input_binding));
23395
23396 VkVertexInputAttributeDescription input_attribs[2];
23397 memset(input_attribs, 0, sizeof(input_attribs));
23398
23399 for (int i = 0; i < 2; i++) {
23400 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
23401 input_attribs[i].location = i;
23402 }
23403
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023404 char const *vsSource =
23405 "#version 450\n"
23406 "\n"
23407 "layout(location=0) in mat2x4 x;\n"
23408 "out gl_PerVertex {\n"
23409 " vec4 gl_Position;\n"
23410 "};\n"
23411 "void main(){\n"
23412 " gl_Position = x[0] + x[1];\n"
23413 "}\n";
23414 char const *fsSource =
23415 "#version 450\n"
23416 "\n"
23417 "layout(location=0) out vec4 color;\n"
23418 "void main(){\n"
23419 " color = vec4(1);\n"
23420 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023421
23422 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
23423 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
23424
23425 VkPipelineObj pipe(m_device);
23426 pipe.AddColorAttachment();
23427 pipe.AddShader(&vs);
23428 pipe.AddShader(&fs);
23429
23430 pipe.AddVertexInputBindings(&input_binding, 1);
23431 pipe.AddVertexInputAttribs(input_attribs, 2);
23432
23433 VkDescriptorSetObj descriptorSet(m_device);
23434 descriptorSet.AppendDummy();
23435 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
23436
23437 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
23438
23439 /* expect success */
23440 m_errorMonitor->VerifyNotFound();
23441}
23442
23443TEST_F(VkPositiveLayerTest, CreatePipelineAttribArrayType) {
23444 m_errorMonitor->ExpectSuccess();
23445
Tony Barbour1fa09702017-03-16 12:09:08 -060023446 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023447 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
23448
23449 VkVertexInputBindingDescription input_binding;
23450 memset(&input_binding, 0, sizeof(input_binding));
23451
23452 VkVertexInputAttributeDescription input_attribs[2];
23453 memset(input_attribs, 0, sizeof(input_attribs));
23454
23455 for (int i = 0; i < 2; i++) {
23456 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
23457 input_attribs[i].location = i;
23458 }
23459
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023460 char const *vsSource =
23461 "#version 450\n"
23462 "\n"
23463 "layout(location=0) in vec4 x[2];\n"
23464 "out gl_PerVertex {\n"
23465 " vec4 gl_Position;\n"
23466 "};\n"
23467 "void main(){\n"
23468 " gl_Position = x[0] + x[1];\n"
23469 "}\n";
23470 char const *fsSource =
23471 "#version 450\n"
23472 "\n"
23473 "layout(location=0) out vec4 color;\n"
23474 "void main(){\n"
23475 " color = vec4(1);\n"
23476 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023477
23478 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
23479 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
23480
23481 VkPipelineObj pipe(m_device);
23482 pipe.AddColorAttachment();
23483 pipe.AddShader(&vs);
23484 pipe.AddShader(&fs);
23485
23486 pipe.AddVertexInputBindings(&input_binding, 1);
23487 pipe.AddVertexInputAttribs(input_attribs, 2);
23488
23489 VkDescriptorSetObj descriptorSet(m_device);
23490 descriptorSet.AppendDummy();
23491 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
23492
23493 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
23494
23495 m_errorMonitor->VerifyNotFound();
23496}
23497
23498TEST_F(VkPositiveLayerTest, CreatePipelineAttribComponents) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023499 TEST_DESCRIPTION(
23500 "Test that pipeline validation accepts consuming a vertex attribute "
23501 "through multiple vertex shader inputs, each consuming a different "
23502 "subset of the components.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023503 m_errorMonitor->ExpectSuccess();
23504
Tony Barbour1fa09702017-03-16 12:09:08 -060023505 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023506 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
23507
23508 VkVertexInputBindingDescription input_binding;
23509 memset(&input_binding, 0, sizeof(input_binding));
23510
23511 VkVertexInputAttributeDescription input_attribs[3];
23512 memset(input_attribs, 0, sizeof(input_attribs));
23513
23514 for (int i = 0; i < 3; i++) {
23515 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
23516 input_attribs[i].location = i;
23517 }
23518
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023519 char const *vsSource =
23520 "#version 450\n"
23521 "\n"
23522 "layout(location=0) in vec4 x;\n"
23523 "layout(location=1) in vec3 y1;\n"
23524 "layout(location=1, component=3) in float y2;\n"
23525 "layout(location=2) in vec4 z;\n"
23526 "out gl_PerVertex {\n"
23527 " vec4 gl_Position;\n"
23528 "};\n"
23529 "void main(){\n"
23530 " gl_Position = x + vec4(y1, y2) + z;\n"
23531 "}\n";
23532 char const *fsSource =
23533 "#version 450\n"
23534 "\n"
23535 "layout(location=0) out vec4 color;\n"
23536 "void main(){\n"
23537 " color = vec4(1);\n"
23538 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023539
23540 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
23541 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
23542
23543 VkPipelineObj pipe(m_device);
23544 pipe.AddColorAttachment();
23545 pipe.AddShader(&vs);
23546 pipe.AddShader(&fs);
23547
23548 pipe.AddVertexInputBindings(&input_binding, 1);
23549 pipe.AddVertexInputAttribs(input_attribs, 3);
23550
23551 VkDescriptorSetObj descriptorSet(m_device);
23552 descriptorSet.AppendDummy();
23553 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
23554
23555 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
23556
23557 m_errorMonitor->VerifyNotFound();
23558}
23559
23560TEST_F(VkPositiveLayerTest, CreatePipelineSimplePositive) {
23561 m_errorMonitor->ExpectSuccess();
23562
Tony Barbour1fa09702017-03-16 12:09:08 -060023563 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023564 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
23565
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023566 char const *vsSource =
23567 "#version 450\n"
23568 "out gl_PerVertex {\n"
23569 " vec4 gl_Position;\n"
23570 "};\n"
23571 "void main(){\n"
23572 " gl_Position = vec4(0);\n"
23573 "}\n";
23574 char const *fsSource =
23575 "#version 450\n"
23576 "\n"
23577 "layout(location=0) out vec4 color;\n"
23578 "void main(){\n"
23579 " color = vec4(1);\n"
23580 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023581
23582 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
23583 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
23584
23585 VkPipelineObj pipe(m_device);
23586 pipe.AddColorAttachment();
23587 pipe.AddShader(&vs);
23588 pipe.AddShader(&fs);
23589
23590 VkDescriptorSetObj descriptorSet(m_device);
23591 descriptorSet.AppendDummy();
23592 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
23593
23594 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
23595
23596 m_errorMonitor->VerifyNotFound();
23597}
23598
23599TEST_F(VkPositiveLayerTest, CreatePipelineRelaxedTypeMatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023600 TEST_DESCRIPTION(
23601 "Test that pipeline validation accepts the relaxed type matching rules "
23602 "set out in 14.1.3: fundamental type must match, and producer side must "
23603 "have at least as many components");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023604 m_errorMonitor->ExpectSuccess();
23605
23606 // VK 1.0.8 Specification, 14.1.3 "Additionally,..." block
23607
Tony Barbour1fa09702017-03-16 12:09:08 -060023608 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023609 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
23610
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023611 char const *vsSource =
23612 "#version 450\n"
23613 "out gl_PerVertex {\n"
23614 " vec4 gl_Position;\n"
23615 "};\n"
23616 "layout(location=0) out vec3 x;\n"
23617 "layout(location=1) out ivec3 y;\n"
23618 "layout(location=2) out vec3 z;\n"
23619 "void main(){\n"
23620 " gl_Position = vec4(0);\n"
23621 " x = vec3(0); y = ivec3(0); z = vec3(0);\n"
23622 "}\n";
23623 char const *fsSource =
23624 "#version 450\n"
23625 "\n"
23626 "layout(location=0) out vec4 color;\n"
23627 "layout(location=0) in float x;\n"
23628 "layout(location=1) flat in int y;\n"
23629 "layout(location=2) in vec2 z;\n"
23630 "void main(){\n"
23631 " color = vec4(1 + x + y + z.x);\n"
23632 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023633
23634 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
23635 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
23636
23637 VkPipelineObj pipe(m_device);
23638 pipe.AddColorAttachment();
23639 pipe.AddShader(&vs);
23640 pipe.AddShader(&fs);
23641
23642 VkDescriptorSetObj descriptorSet(m_device);
23643 descriptorSet.AppendDummy();
23644 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
23645
23646 VkResult err = VK_SUCCESS;
23647 err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
23648 ASSERT_VK_SUCCESS(err);
23649
23650 m_errorMonitor->VerifyNotFound();
23651}
23652
23653TEST_F(VkPositiveLayerTest, CreatePipelineTessPerVertex) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023654 TEST_DESCRIPTION(
23655 "Test that pipeline validation accepts per-vertex variables "
23656 "passed between the TCS and TES stages");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023657 m_errorMonitor->ExpectSuccess();
23658
Tony Barbour1fa09702017-03-16 12:09:08 -060023659 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023660 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
23661
23662 if (!m_device->phy().features().tessellationShader) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070023663 printf(" Device does not support tessellation shaders; skipped.\n");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023664 return;
23665 }
23666
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023667 char const *vsSource =
23668 "#version 450\n"
23669 "void main(){}\n";
23670 char const *tcsSource =
23671 "#version 450\n"
23672 "layout(location=0) out int x[];\n"
23673 "layout(vertices=3) out;\n"
23674 "void main(){\n"
23675 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
23676 " gl_TessLevelInner[0] = 1;\n"
23677 " x[gl_InvocationID] = gl_InvocationID;\n"
23678 "}\n";
23679 char const *tesSource =
23680 "#version 450\n"
23681 "layout(triangles, equal_spacing, cw) in;\n"
23682 "layout(location=0) in int x[];\n"
23683 "out gl_PerVertex { vec4 gl_Position; };\n"
23684 "void main(){\n"
23685 " gl_Position.xyz = gl_TessCoord;\n"
23686 " gl_Position.w = x[0] + x[1] + x[2];\n"
23687 "}\n";
23688 char const *fsSource =
23689 "#version 450\n"
23690 "layout(location=0) out vec4 color;\n"
23691 "void main(){\n"
23692 " color = vec4(1);\n"
23693 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023694
23695 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
23696 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
23697 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
23698 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
23699
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023700 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
23701 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023702
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023703 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023704
23705 VkPipelineObj pipe(m_device);
23706 pipe.SetInputAssembly(&iasci);
23707 pipe.SetTessellation(&tsci);
23708 pipe.AddColorAttachment();
23709 pipe.AddShader(&vs);
23710 pipe.AddShader(&tcs);
23711 pipe.AddShader(&tes);
23712 pipe.AddShader(&fs);
23713
23714 VkDescriptorSetObj descriptorSet(m_device);
23715 descriptorSet.AppendDummy();
23716 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
23717
23718 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
23719
23720 m_errorMonitor->VerifyNotFound();
23721}
23722
23723TEST_F(VkPositiveLayerTest, CreatePipelineGeometryInputBlockPositive) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023724 TEST_DESCRIPTION(
23725 "Test that pipeline validation accepts a user-defined "
23726 "interface block passed into the geometry shader. This "
23727 "is interesting because the 'extra' array level is not "
23728 "present on the member type, but on the block instance.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023729 m_errorMonitor->ExpectSuccess();
23730
Tony Barbour1fa09702017-03-16 12:09:08 -060023731 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023732 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
23733
23734 if (!m_device->phy().features().geometryShader) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070023735 printf(" Device does not support geometry shaders; skipped.\n");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023736 return;
23737 }
23738
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023739 char const *vsSource =
23740 "#version 450\n"
23741 "layout(location=0) out VertexData { vec4 x; } vs_out;\n"
23742 "void main(){\n"
23743 " vs_out.x = vec4(1);\n"
23744 "}\n";
23745 char const *gsSource =
23746 "#version 450\n"
23747 "layout(triangles) in;\n"
23748 "layout(triangle_strip, max_vertices=3) out;\n"
23749 "layout(location=0) in VertexData { vec4 x; } gs_in[];\n"
23750 "out gl_PerVertex { vec4 gl_Position; };\n"
23751 "void main() {\n"
23752 " gl_Position = gs_in[0].x;\n"
23753 " EmitVertex();\n"
23754 "}\n";
23755 char const *fsSource =
23756 "#version 450\n"
23757 "layout(location=0) out vec4 color;\n"
23758 "void main(){\n"
23759 " color = vec4(1);\n"
23760 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023761
23762 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
23763 VkShaderObj gs(m_device, gsSource, VK_SHADER_STAGE_GEOMETRY_BIT, this);
23764 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
23765
23766 VkPipelineObj pipe(m_device);
23767 pipe.AddColorAttachment();
23768 pipe.AddShader(&vs);
23769 pipe.AddShader(&gs);
23770 pipe.AddShader(&fs);
23771
23772 VkDescriptorSetObj descriptorSet(m_device);
23773 descriptorSet.AppendDummy();
23774 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
23775
23776 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
23777
23778 m_errorMonitor->VerifyNotFound();
23779}
23780
23781TEST_F(VkPositiveLayerTest, CreatePipeline64BitAttributesPositive) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023782 TEST_DESCRIPTION(
23783 "Test that pipeline validation accepts basic use of 64bit vertex "
23784 "attributes. This is interesting because they consume multiple "
23785 "locations.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023786 m_errorMonitor->ExpectSuccess();
23787
Tony Barbour1fa09702017-03-16 12:09:08 -060023788 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023789 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
23790
23791 if (!m_device->phy().features().shaderFloat64) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070023792 printf(" Device does not support 64bit vertex attributes; skipped.\n");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023793 return;
23794 }
23795
23796 VkVertexInputBindingDescription input_bindings[1];
23797 memset(input_bindings, 0, sizeof(input_bindings));
23798
23799 VkVertexInputAttributeDescription input_attribs[4];
23800 memset(input_attribs, 0, sizeof(input_attribs));
23801 input_attribs[0].location = 0;
23802 input_attribs[0].offset = 0;
23803 input_attribs[0].format = VK_FORMAT_R64G64B64A64_SFLOAT;
23804 input_attribs[1].location = 2;
23805 input_attribs[1].offset = 32;
23806 input_attribs[1].format = VK_FORMAT_R64G64B64A64_SFLOAT;
23807 input_attribs[2].location = 4;
23808 input_attribs[2].offset = 64;
23809 input_attribs[2].format = VK_FORMAT_R64G64B64A64_SFLOAT;
23810 input_attribs[3].location = 6;
23811 input_attribs[3].offset = 96;
23812 input_attribs[3].format = VK_FORMAT_R64G64B64A64_SFLOAT;
23813
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023814 char const *vsSource =
23815 "#version 450\n"
23816 "\n"
23817 "layout(location=0) in dmat4 x;\n"
23818 "out gl_PerVertex {\n"
23819 " vec4 gl_Position;\n"
23820 "};\n"
23821 "void main(){\n"
23822 " gl_Position = vec4(x[0][0]);\n"
23823 "}\n";
23824 char const *fsSource =
23825 "#version 450\n"
23826 "\n"
23827 "layout(location=0) out vec4 color;\n"
23828 "void main(){\n"
23829 " color = vec4(1);\n"
23830 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023831
23832 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
23833 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
23834
23835 VkPipelineObj pipe(m_device);
23836 pipe.AddColorAttachment();
23837 pipe.AddShader(&vs);
23838 pipe.AddShader(&fs);
23839
23840 pipe.AddVertexInputBindings(input_bindings, 1);
23841 pipe.AddVertexInputAttribs(input_attribs, 4);
23842
23843 VkDescriptorSetObj descriptorSet(m_device);
23844 descriptorSet.AppendDummy();
23845 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
23846
23847 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
23848
23849 m_errorMonitor->VerifyNotFound();
23850}
23851
23852TEST_F(VkPositiveLayerTest, CreatePipelineInputAttachmentPositive) {
23853 TEST_DESCRIPTION("Positive test for a correctly matched input attachment");
23854 m_errorMonitor->ExpectSuccess();
23855
Tony Barbour1fa09702017-03-16 12:09:08 -060023856 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023857
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023858 char const *vsSource =
23859 "#version 450\n"
23860 "\n"
23861 "out gl_PerVertex {\n"
23862 " vec4 gl_Position;\n"
23863 "};\n"
23864 "void main(){\n"
23865 " gl_Position = vec4(1);\n"
23866 "}\n";
23867 char const *fsSource =
23868 "#version 450\n"
23869 "\n"
23870 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
23871 "layout(location=0) out vec4 color;\n"
23872 "void main() {\n"
23873 " color = subpassLoad(x);\n"
23874 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023875
23876 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
23877 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
23878
23879 VkPipelineObj pipe(m_device);
23880 pipe.AddShader(&vs);
23881 pipe.AddShader(&fs);
23882 pipe.AddColorAttachment();
23883 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
23884
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023885 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
23886 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023887 VkDescriptorSetLayout dsl;
23888 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
23889 ASSERT_VK_SUCCESS(err);
23890
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023891 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023892 VkPipelineLayout pl;
23893 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
23894 ASSERT_VK_SUCCESS(err);
23895
23896 VkAttachmentDescription descs[2] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023897 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
23898 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
23899 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
23900 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
23901 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_LAYOUT_GENERAL},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023902 };
23903 VkAttachmentReference color = {
23904 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
23905 };
23906 VkAttachmentReference input = {
23907 1, VK_IMAGE_LAYOUT_GENERAL,
23908 };
23909
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023910 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023911
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023912 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023913 VkRenderPass rp;
23914 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
23915 ASSERT_VK_SUCCESS(err);
23916
23917 // should be OK. would go wrong here if it's going to...
23918 pipe.CreateVKPipeline(pl, rp);
23919
23920 m_errorMonitor->VerifyNotFound();
23921
23922 vkDestroyRenderPass(m_device->device(), rp, nullptr);
23923 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
23924 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
23925}
23926
23927TEST_F(VkPositiveLayerTest, CreateComputePipelineMissingDescriptorUnusedPositive) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023928 TEST_DESCRIPTION(
23929 "Test that pipeline validation accepts a compute pipeline which declares a "
23930 "descriptor-backed resource which is not provided, but the shader does not "
23931 "statically use it. This is interesting because it requires compute pipelines "
23932 "to have a proper descriptor use walk, which they didn't for some time.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023933 m_errorMonitor->ExpectSuccess();
23934
Tony Barbour1fa09702017-03-16 12:09:08 -060023935 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023936
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023937 char const *csSource =
23938 "#version 450\n"
23939 "\n"
23940 "layout(local_size_x=1) in;\n"
23941 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
23942 "void main(){\n"
23943 " // x is not used.\n"
23944 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023945
23946 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
23947
23948 VkDescriptorSetObj descriptorSet(m_device);
23949 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
23950
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023951 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
23952 nullptr,
23953 0,
23954 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
23955 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
23956 descriptorSet.GetPipelineLayout(),
23957 VK_NULL_HANDLE,
23958 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023959
23960 VkPipeline pipe;
23961 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
23962
23963 m_errorMonitor->VerifyNotFound();
23964
23965 if (err == VK_SUCCESS) {
23966 vkDestroyPipeline(m_device->device(), pipe, nullptr);
23967 }
23968}
23969
23970TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsSampler) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023971 TEST_DESCRIPTION(
23972 "Test that pipeline validation accepts a shader consuming only the "
23973 "sampler portion of a combined image + sampler");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023974 m_errorMonitor->ExpectSuccess();
23975
Tony Barbour1fa09702017-03-16 12:09:08 -060023976 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023977
23978 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023979 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
23980 {1, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
23981 {2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023982 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023983 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023984 VkDescriptorSetLayout dsl;
23985 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
23986 ASSERT_VK_SUCCESS(err);
23987
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023988 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023989 VkPipelineLayout pl;
23990 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
23991 ASSERT_VK_SUCCESS(err);
23992
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023993 char const *csSource =
23994 "#version 450\n"
23995 "\n"
23996 "layout(local_size_x=1) in;\n"
23997 "layout(set=0, binding=0) uniform sampler s;\n"
23998 "layout(set=0, binding=1) uniform texture2D t;\n"
23999 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
24000 "void main() {\n"
24001 " x = texture(sampler2D(t, s), vec2(0));\n"
24002 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024003 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
24004
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070024005 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
24006 nullptr,
24007 0,
24008 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
24009 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
24010 pl,
24011 VK_NULL_HANDLE,
24012 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024013
24014 VkPipeline pipe;
24015 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
24016
24017 m_errorMonitor->VerifyNotFound();
24018
24019 if (err == VK_SUCCESS) {
24020 vkDestroyPipeline(m_device->device(), pipe, nullptr);
24021 }
24022
24023 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
24024 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
24025}
24026
24027TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsImage) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070024028 TEST_DESCRIPTION(
24029 "Test that pipeline validation accepts a shader consuming only the "
24030 "image portion of a combined image + sampler");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024031 m_errorMonitor->ExpectSuccess();
24032
Tony Barbour1fa09702017-03-16 12:09:08 -060024033 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024034
24035 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070024036 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
24037 {1, VK_DESCRIPTOR_TYPE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
24038 {2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024039 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070024040 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024041 VkDescriptorSetLayout dsl;
24042 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
24043 ASSERT_VK_SUCCESS(err);
24044
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070024045 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024046 VkPipelineLayout pl;
24047 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
24048 ASSERT_VK_SUCCESS(err);
24049
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070024050 char const *csSource =
24051 "#version 450\n"
24052 "\n"
24053 "layout(local_size_x=1) in;\n"
24054 "layout(set=0, binding=0) uniform texture2D t;\n"
24055 "layout(set=0, binding=1) uniform sampler s;\n"
24056 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
24057 "void main() {\n"
24058 " x = texture(sampler2D(t, s), vec2(0));\n"
24059 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024060 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
24061
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070024062 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
24063 nullptr,
24064 0,
24065 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
24066 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
24067 pl,
24068 VK_NULL_HANDLE,
24069 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024070
24071 VkPipeline pipe;
24072 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
24073
24074 m_errorMonitor->VerifyNotFound();
24075
24076 if (err == VK_SUCCESS) {
24077 vkDestroyPipeline(m_device->device(), pipe, nullptr);
24078 }
24079
24080 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
24081 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
24082}
24083
24084TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsBoth) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070024085 TEST_DESCRIPTION(
24086 "Test that pipeline validation accepts a shader consuming "
24087 "both the sampler and the image of a combined image+sampler "
24088 "but via separate variables");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024089 m_errorMonitor->ExpectSuccess();
24090
Tony Barbour1fa09702017-03-16 12:09:08 -060024091 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024092
24093 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070024094 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
24095 {1, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024096 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070024097 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 2, bindings};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024098 VkDescriptorSetLayout dsl;
24099 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
24100 ASSERT_VK_SUCCESS(err);
24101
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070024102 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024103 VkPipelineLayout pl;
24104 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
24105 ASSERT_VK_SUCCESS(err);
24106
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070024107 char const *csSource =
24108 "#version 450\n"
24109 "\n"
24110 "layout(local_size_x=1) in;\n"
24111 "layout(set=0, binding=0) uniform texture2D t;\n"
24112 "layout(set=0, binding=0) uniform sampler s; // both binding 0!\n"
24113 "layout(set=0, binding=1) buffer block { vec4 x; };\n"
24114 "void main() {\n"
24115 " x = texture(sampler2D(t, s), vec2(0));\n"
24116 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024117 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
24118
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070024119 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
24120 nullptr,
24121 0,
24122 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
24123 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
24124 pl,
24125 VK_NULL_HANDLE,
24126 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024127
24128 VkPipeline pipe;
24129 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
24130
24131 m_errorMonitor->VerifyNotFound();
24132
24133 if (err == VK_SUCCESS) {
24134 vkDestroyPipeline(m_device->device(), pipe, nullptr);
24135 }
24136
24137 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
24138 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
24139}
24140
Tony Barbour3ed87a02017-03-15 16:19:02 -060024141TEST_F(VkPositiveLayerTest, Maintenance1Tests) {
Mark Lobodzinskidf784fc2017-03-14 09:18:40 -060024142 TEST_DESCRIPTION("Validate various special cases for the Maintenance1_KHR extension");
24143
Tony Barbour3ed87a02017-03-15 16:19:02 -060024144 device_extension_names.push_back(VK_KHR_MAINTENANCE1_EXTENSION_NAME);
Tony Barbour73c0f352017-03-16 15:55:38 -060024145 InitFramework(instance_layer_names, instance_extension_names, device_extension_names, myDbgFunc, m_errorMonitor);
Tony Barbour3ed87a02017-03-15 16:19:02 -060024146
Mark Lobodzinskidf784fc2017-03-14 09:18:40 -060024147 // Ensure that extension is available and enabled.
24148 uint32_t extension_count = 0;
24149 bool supports_maintenance1_extension = false;
24150 VkResult err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, nullptr);
24151 ASSERT_VK_SUCCESS(err);
24152 if (extension_count > 0) {
24153 std::vector<VkExtensionProperties> available_extensions(extension_count);
24154
24155 err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, &available_extensions[0]);
24156 ASSERT_VK_SUCCESS(err);
24157 for (const auto &extension_props : available_extensions) {
24158 if (strcmp(extension_props.extensionName, VK_KHR_MAINTENANCE1_EXTENSION_NAME) == 0) {
24159 supports_maintenance1_extension = true;
24160 }
24161 }
24162 }
24163
24164 // Proceed if extension is supported by hardware
24165 if (!supports_maintenance1_extension) {
24166 printf(" Maintenance1 Extension not supported, skipping tests\n");
24167 return;
24168 }
Mark Lobodzinskidf784fc2017-03-14 09:18:40 -060024169
24170 m_errorMonitor->ExpectSuccess();
Dave Houlton8e0fe7a2017-03-30 10:32:10 -060024171 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskidf784fc2017-03-14 09:18:40 -060024172 VkCommandBuffer cmd_buf;
24173 VkCommandBufferAllocateInfo alloc_info;
24174 alloc_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
24175 alloc_info.pNext = NULL;
24176 alloc_info.commandBufferCount = 1;
Mike Schuchardt06304c22017-03-01 17:09:09 -070024177 alloc_info.commandPool = m_commandPool->handle();
Mark Lobodzinskidf784fc2017-03-14 09:18:40 -060024178 alloc_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
24179 vkAllocateCommandBuffers(m_device->device(), &alloc_info, &cmd_buf);
24180
24181 VkCommandBufferBeginInfo cb_binfo;
24182 cb_binfo.pNext = NULL;
24183 cb_binfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
24184 cb_binfo.pInheritanceInfo = VK_NULL_HANDLE;
24185 cb_binfo.flags = 0;
24186 vkBeginCommandBuffer(cmd_buf, &cb_binfo);
24187 // Set Negative height, should give error if Maintenance 1 is not enabled
24188 VkViewport viewport = {0, 0, 16, -16, 0, 1};
24189 vkCmdSetViewport(cmd_buf, 0, 1, &viewport);
24190 vkEndCommandBuffer(cmd_buf);
24191
24192 m_errorMonitor->VerifyNotFound();
24193}
24194
Mark Lobodzinski35ecad32017-03-27 13:09:07 -060024195TEST_F(VkLayerTest, DuplicateValidPNextStructures) {
24196 TEST_DESCRIPTION("Create a pNext chain containing valid strutures, but with a duplicate structure type");
24197
24198 ASSERT_NO_FATAL_FAILURE(Init());
24199
24200 uint32_t extension_count = 0;
24201 VkResult err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, nullptr);
24202 ASSERT_VK_SUCCESS(err);
24203
24204 if (extension_count > 0) {
24205 std::vector<VkExtensionProperties> available_extensions(extension_count);
24206 err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, &available_extensions[0]);
24207 ASSERT_VK_SUCCESS(err);
24208
24209 for (const auto &extension_props : available_extensions) {
24210 if (strcmp(extension_props.extensionName, VK_NV_DEDICATED_ALLOCATION_EXTENSION_NAME) == 0) {
24211 // Create two pNext structures which by themselves would be valid
24212 VkDedicatedAllocationBufferCreateInfoNV dedicated_buffer_create_info = {};
24213 VkDedicatedAllocationBufferCreateInfoNV dedicated_buffer_create_info_2 = {};
24214 dedicated_buffer_create_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_BUFFER_CREATE_INFO_NV;
24215 dedicated_buffer_create_info.pNext = &dedicated_buffer_create_info_2;
24216 dedicated_buffer_create_info.dedicatedAllocation = VK_TRUE;
24217
24218 dedicated_buffer_create_info_2.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_BUFFER_CREATE_INFO_NV;
24219 dedicated_buffer_create_info_2.pNext = nullptr;
24220 dedicated_buffer_create_info_2.dedicatedAllocation = VK_TRUE;
24221
24222 uint32_t queue_family_index = 0;
24223 VkBufferCreateInfo buffer_create_info = {};
24224 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
24225 buffer_create_info.pNext = &dedicated_buffer_create_info;
24226 buffer_create_info.size = 1024;
24227 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
24228 buffer_create_info.queueFamilyIndexCount = 1;
24229 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
24230
24231 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "chain contains duplicate structure types");
24232 VkBuffer buffer;
24233 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
24234 m_errorMonitor->VerifyFound();
24235 }
24236 }
24237 }
24238}
24239
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024240TEST_F(VkPositiveLayerTest, ValidStructPNext) {
24241 TEST_DESCRIPTION("Verify that a valid pNext value is handled correctly");
24242
Tony Barbour1fa09702017-03-16 12:09:08 -060024243 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024244
24245 // Positive test to check parameter_validation and unique_objects support
24246 // for NV_dedicated_allocation
24247 uint32_t extension_count = 0;
24248 bool supports_nv_dedicated_allocation = false;
24249 VkResult err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, nullptr);
24250 ASSERT_VK_SUCCESS(err);
24251
24252 if (extension_count > 0) {
24253 std::vector<VkExtensionProperties> available_extensions(extension_count);
24254
24255 err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, &available_extensions[0]);
24256 ASSERT_VK_SUCCESS(err);
24257
24258 for (const auto &extension_props : available_extensions) {
24259 if (strcmp(extension_props.extensionName, VK_NV_DEDICATED_ALLOCATION_EXTENSION_NAME) == 0) {
24260 supports_nv_dedicated_allocation = true;
24261 }
24262 }
24263 }
24264
24265 if (supports_nv_dedicated_allocation) {
24266 m_errorMonitor->ExpectSuccess();
24267
24268 VkDedicatedAllocationBufferCreateInfoNV dedicated_buffer_create_info = {};
24269 dedicated_buffer_create_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_BUFFER_CREATE_INFO_NV;
24270 dedicated_buffer_create_info.pNext = nullptr;
24271 dedicated_buffer_create_info.dedicatedAllocation = VK_TRUE;
24272
24273 uint32_t queue_family_index = 0;
24274 VkBufferCreateInfo buffer_create_info = {};
24275 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
24276 buffer_create_info.pNext = &dedicated_buffer_create_info;
24277 buffer_create_info.size = 1024;
24278 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
24279 buffer_create_info.queueFamilyIndexCount = 1;
24280 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
24281
24282 VkBuffer buffer;
Karl Schultz47dd59d2017-01-20 13:19:20 -070024283 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024284 ASSERT_VK_SUCCESS(err);
24285
24286 VkMemoryRequirements memory_reqs;
24287 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
24288
24289 VkDedicatedAllocationMemoryAllocateInfoNV dedicated_memory_info = {};
24290 dedicated_memory_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_MEMORY_ALLOCATE_INFO_NV;
24291 dedicated_memory_info.pNext = nullptr;
24292 dedicated_memory_info.buffer = buffer;
24293 dedicated_memory_info.image = VK_NULL_HANDLE;
24294
24295 VkMemoryAllocateInfo memory_info = {};
24296 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
24297 memory_info.pNext = &dedicated_memory_info;
24298 memory_info.allocationSize = memory_reqs.size;
24299
24300 bool pass;
24301 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
24302 ASSERT_TRUE(pass);
24303
24304 VkDeviceMemory buffer_memory;
24305 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
24306 ASSERT_VK_SUCCESS(err);
24307
24308 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
24309 ASSERT_VK_SUCCESS(err);
24310
24311 vkDestroyBuffer(m_device->device(), buffer, NULL);
24312 vkFreeMemory(m_device->device(), buffer_memory, NULL);
24313
24314 m_errorMonitor->VerifyNotFound();
24315 }
24316}
24317
24318TEST_F(VkPositiveLayerTest, PSOPolygonModeValid) {
24319 VkResult err;
24320
24321 TEST_DESCRIPTION("Verify that using a solid polygon fill mode works correctly.");
24322
Tony Barbour1fa09702017-03-16 12:09:08 -060024323 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024324 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
24325
24326 std::vector<const char *> device_extension_names;
24327 auto features = m_device->phy().features();
24328 // Artificially disable support for non-solid fill modes
24329 features.fillModeNonSolid = false;
24330 // The sacrificial device object
24331 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
24332
24333 VkRenderpassObj render_pass(&test_device);
24334
24335 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
24336 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
24337 pipeline_layout_ci.setLayoutCount = 0;
24338 pipeline_layout_ci.pSetLayouts = NULL;
24339
24340 VkPipelineLayout pipeline_layout;
24341 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
24342 ASSERT_VK_SUCCESS(err);
24343
24344 VkPipelineRasterizationStateCreateInfo rs_ci = {};
24345 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
24346 rs_ci.pNext = nullptr;
24347 rs_ci.lineWidth = 1.0f;
24348 rs_ci.rasterizerDiscardEnable = true;
24349
24350 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
24351 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
24352
24353 // Set polygonMode=FILL. No error is expected
24354 m_errorMonitor->ExpectSuccess();
24355 {
24356 VkPipelineObj pipe(&test_device);
24357 pipe.AddShader(&vs);
24358 pipe.AddShader(&fs);
24359 pipe.AddColorAttachment();
24360 // Set polygonMode to a good value
24361 rs_ci.polygonMode = VK_POLYGON_MODE_FILL;
24362 pipe.SetRasterization(&rs_ci);
24363 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
24364 }
24365 m_errorMonitor->VerifyNotFound();
24366
24367 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
24368}
24369
Dave Houlton1150cf52017-04-27 14:38:11 -060024370TEST_F(VkPositiveLayerTest, LongSemaphoreChain) {
Chris Forbes94196952017-04-06 16:30:59 -070024371 m_errorMonitor->ExpectSuccess();
24372
24373 ASSERT_NO_FATAL_FAILURE(Init());
24374 VkResult err;
24375
24376 std::vector<VkSemaphore> semaphores;
24377
24378 const int chainLength = 32768;
24379 VkPipelineStageFlags flags = VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT;
24380
24381 for (int i = 0; i < chainLength; i++) {
Dave Houlton1150cf52017-04-27 14:38:11 -060024382 VkSemaphoreCreateInfo sci = {VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0};
Chris Forbes94196952017-04-06 16:30:59 -070024383 VkSemaphore semaphore;
24384 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &semaphore);
24385 ASSERT_VK_SUCCESS(err);
24386
24387 semaphores.push_back(semaphore);
24388
Chris Forbesfc50aaa2017-05-01 10:20:17 -070024389 VkSubmitInfo si = {VK_STRUCTURE_TYPE_SUBMIT_INFO,
24390 nullptr,
24391 semaphores.size() > 1 ? 1u : 0u,
24392 semaphores.size() > 1 ? &semaphores[semaphores.size() - 2] : nullptr,
24393 &flags,
24394 0,
24395 nullptr,
24396 1,
24397 &semaphores[semaphores.size() - 1]};
Chris Forbes94196952017-04-06 16:30:59 -070024398 err = vkQueueSubmit(m_device->m_queue, 1, &si, VK_NULL_HANDLE);
24399 ASSERT_VK_SUCCESS(err);
24400 }
24401
Dave Houlton1150cf52017-04-27 14:38:11 -060024402 VkFenceCreateInfo fci = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0};
Chris Forbes94196952017-04-06 16:30:59 -070024403 VkFence fence;
24404 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
24405 ASSERT_VK_SUCCESS(err);
Dave Houlton1150cf52017-04-27 14:38:11 -060024406 VkSubmitInfo si = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 1, &semaphores.back(), &flags, 0, nullptr, 0, nullptr};
Chris Forbes94196952017-04-06 16:30:59 -070024407 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
24408 ASSERT_VK_SUCCESS(err);
24409
24410 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
24411
Dave Houlton1150cf52017-04-27 14:38:11 -060024412 for (auto semaphore : semaphores) vkDestroySemaphore(m_device->device(), semaphore, nullptr);
Chris Forbes94196952017-04-06 16:30:59 -070024413
24414 vkDestroyFence(m_device->device(), fence, nullptr);
24415
24416 m_errorMonitor->VerifyNotFound();
24417}
24418
Mike Stroyanca855662017-05-02 11:06:27 -060024419extern "C" void *ReleaseNullFence(void *arg) {
24420 struct thread_data_struct *data = (struct thread_data_struct *)arg;
24421
24422 for (int i = 0; i < 40000; i++) {
24423 vkDestroyFence(data->device, VK_NULL_HANDLE, NULL);
24424 if (data->bailout) {
24425 break;
24426 }
24427 }
24428 return NULL;
24429}
24430
24431TEST_F(VkPositiveLayerTest, ThreadNullFenceCollision) {
24432 test_platform_thread thread;
24433
24434 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "THREADING ERROR");
24435
24436 ASSERT_NO_FATAL_FAILURE(Init());
24437
24438 struct thread_data_struct data;
24439 data.device = m_device->device();
24440 data.bailout = false;
24441 m_errorMonitor->SetBailout(&data.bailout);
24442
24443 // Call vkDestroyFence of VK_NULL_HANDLE repeatedly using multiple threads.
24444 // There should be no validation error from collision of that non-object.
24445 test_platform_thread_create(&thread, ReleaseNullFence, (void *)&data);
24446 for (int i = 0; i < 40000; i++) {
24447 vkDestroyFence(m_device->device(), VK_NULL_HANDLE, NULL);
24448 }
24449 test_platform_thread_join(thread, NULL);
24450
24451 m_errorMonitor->SetBailout(NULL);
24452
24453 m_errorMonitor->VerifyNotFound();
24454}
24455
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070024456#if 0 // A few devices have issues with this test so disabling for now
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024457TEST_F(VkPositiveLayerTest, LongFenceChain)
24458{
24459 m_errorMonitor->ExpectSuccess();
24460
Tony Barbour1fa09702017-03-16 12:09:08 -060024461 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024462 VkResult err;
24463
24464 std::vector<VkFence> fences;
24465
24466 const int chainLength = 32768;
24467
24468 for (int i = 0; i < chainLength; i++) {
24469 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
24470 VkFence fence;
24471 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
24472 ASSERT_VK_SUCCESS(err);
24473
24474 fences.push_back(fence);
24475
24476 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr,
24477 0, nullptr, 0, nullptr };
24478 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
24479 ASSERT_VK_SUCCESS(err);
24480
24481 }
24482
24483 // BOOM, stack overflow.
24484 vkWaitForFences(m_device->device(), 1, &fences.back(), VK_TRUE, UINT64_MAX);
24485
24486 for (auto fence : fences)
24487 vkDestroyFence(m_device->device(), fence, nullptr);
24488
24489 m_errorMonitor->VerifyNotFound();
24490}
24491#endif
24492
Petr Kraus4d718682017-05-18 03:38:41 +020024493TEST_F(VkPositiveLayerTest, ClearColorImageWithValidRange) {
24494 TEST_DESCRIPTION("Record clear color with a valid VkImageSubresourceRange");
24495
24496 ASSERT_NO_FATAL_FAILURE(Init());
24497 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
24498
24499 VkImageObj image(m_device);
24500 image.Init(32, 32, 1, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_OPTIMAL);
24501 ASSERT_TRUE(image.create_info().arrayLayers == 1);
24502 ASSERT_TRUE(image.initialized());
24503 image.SetLayout(VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
24504
24505 const VkClearColorValue clear_color = {{0.0f, 0.0f, 0.0f, 1.0f}};
24506
24507 m_commandBuffer->BeginCommandBuffer();
24508 const auto cb_handle = m_commandBuffer->GetBufferHandle();
24509
24510 // Try good case
24511 {
24512 m_errorMonitor->ExpectSuccess();
24513 VkImageSubresourceRange range = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1};
24514 vkCmdClearColorImage(cb_handle, image.handle(), image.Layout(), &clear_color, 1, &range);
24515 m_errorMonitor->VerifyNotFound();
24516 }
24517
24518 // Try good case with VK_REMAINING
24519 {
24520 m_errorMonitor->ExpectSuccess();
24521 VkImageSubresourceRange range = {VK_IMAGE_ASPECT_COLOR_BIT, 0, VK_REMAINING_MIP_LEVELS, 0, VK_REMAINING_ARRAY_LAYERS};
24522 vkCmdClearColorImage(cb_handle, image.handle(), image.Layout(), &clear_color, 1, &range);
24523 m_errorMonitor->VerifyNotFound();
24524 }
24525}
24526
24527TEST_F(VkPositiveLayerTest, ClearDepthStencilWithValidRange) {
24528 TEST_DESCRIPTION("Record clear depth with a valid VkImageSubresourceRange");
24529
24530 ASSERT_NO_FATAL_FAILURE(Init());
24531 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
24532
24533 auto depth_format = FindSupportedDepthStencilFormat(gpu());
24534 if (!depth_format) {
24535 printf(" No Depth + Stencil format found. Skipped.\n");
24536 return;
24537 }
24538
24539 VkImageObj image(m_device);
24540 image.Init(32, 32, 1, depth_format, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_OPTIMAL);
24541 ASSERT_TRUE(image.create_info().arrayLayers == 1);
24542 ASSERT_TRUE(image.initialized());
24543 const VkImageAspectFlags ds_aspect = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
24544 image.SetLayout(ds_aspect, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
24545
24546 const VkClearDepthStencilValue clear_value = {};
24547
24548 m_commandBuffer->BeginCommandBuffer();
24549 const auto cb_handle = m_commandBuffer->GetBufferHandle();
24550
24551 // Try good case
24552 {
24553 m_errorMonitor->ExpectSuccess();
24554 VkImageSubresourceRange range = {ds_aspect, 0, 1, 0, 1};
24555 vkCmdClearDepthStencilImage(cb_handle, image.handle(), image.Layout(), &clear_value, 1, &range);
24556 m_errorMonitor->VerifyNotFound();
24557 }
24558
24559 // Try good case with VK_REMAINING
24560 {
24561 m_errorMonitor->ExpectSuccess();
24562 VkImageSubresourceRange range = {ds_aspect, 0, VK_REMAINING_MIP_LEVELS, 0, VK_REMAINING_ARRAY_LAYERS};
24563 vkCmdClearDepthStencilImage(cb_handle, image.handle(), image.Layout(), &clear_value, 1, &range);
24564 m_errorMonitor->VerifyNotFound();
24565 }
24566}
24567
Cody Northrop1242dfd2016-07-13 17:24:59 -060024568#if defined(ANDROID) && defined(VALIDATION_APK)
Cody Northropb94529f2017-04-05 13:05:51 -060024569const char *appTag = "VulkanLayerValidationTests";
Cody Northrop1242dfd2016-07-13 17:24:59 -060024570static bool initialized = false;
24571static bool active = false;
24572
24573// Convert Intents to argv
24574// Ported from Hologram sample, only difference is flexible key
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024575std::vector<std::string> get_args(android_app &app, const char *intent_extra_data_key) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060024576 std::vector<std::string> args;
24577 JavaVM &vm = *app.activity->vm;
24578 JNIEnv *p_env;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070024579 if (vm.AttachCurrentThread(&p_env, nullptr) != JNI_OK) return args;
Cody Northrop1242dfd2016-07-13 17:24:59 -060024580
24581 JNIEnv &env = *p_env;
24582 jobject activity = app.activity->clazz;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024583 jmethodID get_intent_method = env.GetMethodID(env.GetObjectClass(activity), "getIntent", "()Landroid/content/Intent;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060024584 jobject intent = env.CallObjectMethod(activity, get_intent_method);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024585 jmethodID get_string_extra_method =
24586 env.GetMethodID(env.GetObjectClass(intent), "getStringExtra", "(Ljava/lang/String;)Ljava/lang/String;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060024587 jvalue get_string_extra_args;
24588 get_string_extra_args.l = env.NewStringUTF(intent_extra_data_key);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024589 jstring extra_str = static_cast<jstring>(env.CallObjectMethodA(intent, get_string_extra_method, &get_string_extra_args));
Cody Northrop1242dfd2016-07-13 17:24:59 -060024590
24591 std::string args_str;
24592 if (extra_str) {
24593 const char *extra_utf = env.GetStringUTFChars(extra_str, nullptr);
24594 args_str = extra_utf;
24595 env.ReleaseStringUTFChars(extra_str, extra_utf);
24596 env.DeleteLocalRef(extra_str);
24597 }
24598
24599 env.DeleteLocalRef(get_string_extra_args.l);
24600 env.DeleteLocalRef(intent);
24601 vm.DetachCurrentThread();
24602
24603 // split args_str
24604 std::stringstream ss(args_str);
24605 std::string arg;
24606 while (std::getline(ss, arg, ' ')) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070024607 if (!arg.empty()) args.push_back(arg);
Cody Northrop1242dfd2016-07-13 17:24:59 -060024608 }
24609
24610 return args;
24611}
24612
Dave Houlton11dcd5e2017-04-25 16:00:10 -060024613void addFullTestCommentIfPresent(const ::testing::TestInfo &test_info, std::string &error_message) {
24614 const char *const type_param = test_info.type_param();
24615 const char *const value_param = test_info.value_param();
Cody Northropb94529f2017-04-05 13:05:51 -060024616
24617 if (type_param != NULL || value_param != NULL) {
24618 error_message.append(", where ");
24619 if (type_param != NULL) {
Dave Houlton11dcd5e2017-04-25 16:00:10 -060024620 error_message.append("TypeParam = ").append(type_param);
24621 if (value_param != NULL) error_message.append(" and ");
Cody Northropb94529f2017-04-05 13:05:51 -060024622 }
24623 if (value_param != NULL) {
24624 error_message.append("GetParam() = ").append(value_param);
24625 }
24626 }
24627}
24628
24629// Inspired by https://github.com/google/googletest/blob/master/googletest/docs/AdvancedGuide.md
24630class LogcatPrinter : public ::testing::EmptyTestEventListener {
24631 // Called before a test starts.
Dave Houlton11dcd5e2017-04-25 16:00:10 -060024632 virtual void OnTestStart(const ::testing::TestInfo &test_info) {
Cody Northropb94529f2017-04-05 13:05:51 -060024633 __android_log_print(ANDROID_LOG_INFO, appTag, "[ RUN ] %s.%s", test_info.test_case_name(), test_info.name());
24634 }
24635
24636 // Called after a failed assertion or a SUCCEED() invocation.
Dave Houlton11dcd5e2017-04-25 16:00:10 -060024637 virtual void OnTestPartResult(const ::testing::TestPartResult &result) {
Cody Northropb94529f2017-04-05 13:05:51 -060024638 // If the test part succeeded, we don't need to do anything.
Dave Houlton11dcd5e2017-04-25 16:00:10 -060024639 if (result.type() == ::testing::TestPartResult::kSuccess) return;
Cody Northropb94529f2017-04-05 13:05:51 -060024640
Dave Houlton11dcd5e2017-04-25 16:00:10 -060024641 __android_log_print(ANDROID_LOG_INFO, appTag, "%s in %s:%d %s", result.failed() ? "*** Failure" : "Success",
24642 result.file_name(), result.line_number(), result.summary());
Cody Northropb94529f2017-04-05 13:05:51 -060024643 }
24644
24645 // Called after a test ends.
Dave Houlton11dcd5e2017-04-25 16:00:10 -060024646 virtual void OnTestEnd(const ::testing::TestInfo &info) {
Cody Northropb94529f2017-04-05 13:05:51 -060024647 std::string result;
24648 if (info.result()->Passed()) {
24649 result.append("[ OK ]");
24650 } else {
24651 result.append("[ FAILED ]");
24652 }
24653 result.append(info.test_case_name()).append(".").append(info.name());
Dave Houlton11dcd5e2017-04-25 16:00:10 -060024654 if (info.result()->Failed()) addFullTestCommentIfPresent(info, result);
Cody Northropb94529f2017-04-05 13:05:51 -060024655
24656 if (::testing::GTEST_FLAG(print_time)) {
24657 std::ostringstream os;
24658 os << info.result()->elapsed_time();
24659 result.append(" (").append(os.str()).append(" ms)");
24660 }
24661
24662 __android_log_print(ANDROID_LOG_INFO, appTag, "%s", result.c_str());
24663 };
24664};
24665
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024666static int32_t processInput(struct android_app *app, AInputEvent *event) { return 0; }
Cody Northrop1242dfd2016-07-13 17:24:59 -060024667
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024668static void processCommand(struct android_app *app, int32_t cmd) {
24669 switch (cmd) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070024670 case APP_CMD_INIT_WINDOW: {
24671 if (app->window) {
24672 initialized = true;
24673 }
24674 break;
Cody Northrop1242dfd2016-07-13 17:24:59 -060024675 }
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070024676 case APP_CMD_GAINED_FOCUS: {
24677 active = true;
24678 break;
24679 }
24680 case APP_CMD_LOST_FOCUS: {
24681 active = false;
24682 break;
24683 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060024684 }
24685}
24686
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024687void android_main(struct android_app *app) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060024688 app_dummy();
24689
Cody Northrop1242dfd2016-07-13 17:24:59 -060024690 int vulkanSupport = InitVulkan();
24691 if (vulkanSupport == 0) {
24692 __android_log_print(ANDROID_LOG_INFO, appTag, "==== FAILED ==== No Vulkan support found");
24693 return;
24694 }
24695
24696 app->onAppCmd = processCommand;
24697 app->onInputEvent = processInput;
24698
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024699 while (1) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060024700 int events;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024701 struct android_poll_source *source;
24702 while (ALooper_pollAll(active ? 0 : -1, NULL, &events, (void **)&source) >= 0) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060024703 if (source) {
24704 source->process(app, source);
24705 }
24706
24707 if (app->destroyRequested != 0) {
24708 VkTestFramework::Finish();
24709 return;
24710 }
24711 }
24712
24713 if (initialized && active) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024714 // Use the following key to send arguments to gtest, i.e.
24715 // --es args "--gtest_filter=-VkLayerTest.foo"
24716 const char key[] = "args";
24717 std::vector<std::string> args = get_args(*app, key);
Cody Northrop1242dfd2016-07-13 17:24:59 -060024718
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024719 std::string filter = "";
24720 if (args.size() > 0) {
24721 __android_log_print(ANDROID_LOG_INFO, appTag, "Intent args = %s", args[0].c_str());
24722 filter += args[0];
24723 } else {
24724 __android_log_print(ANDROID_LOG_INFO, appTag, "No Intent args detected");
24725 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060024726
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024727 int argc = 2;
24728 char *argv[] = {(char *)"foo", (char *)filter.c_str()};
24729 __android_log_print(ANDROID_LOG_DEBUG, appTag, "filter = %s", argv[1]);
Cody Northrop1242dfd2016-07-13 17:24:59 -060024730
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024731 // Route output to files until we can override the gtest output
24732 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/out.txt", "w", stdout);
24733 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/err.txt", "w", stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060024734
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024735 ::testing::InitGoogleTest(&argc, argv);
Cody Northropb94529f2017-04-05 13:05:51 -060024736
Dave Houlton11dcd5e2017-04-25 16:00:10 -060024737 ::testing::TestEventListeners &listeners = ::testing::UnitTest::GetInstance()->listeners();
Cody Northropb94529f2017-04-05 13:05:51 -060024738 listeners.Append(new LogcatPrinter);
24739
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024740 VkTestFramework::InitArgs(&argc, argv);
24741 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Cody Northrop1242dfd2016-07-13 17:24:59 -060024742
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024743 int result = RUN_ALL_TESTS();
Cody Northrop1242dfd2016-07-13 17:24:59 -060024744
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024745 if (result != 0) {
24746 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests FAILED ====");
24747 } else {
24748 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests PASSED ====");
24749 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060024750
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024751 VkTestFramework::Finish();
Cody Northrop1242dfd2016-07-13 17:24:59 -060024752
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024753 fclose(stdout);
24754 fclose(stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060024755
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024756 ANativeActivity_finish(app->activity);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024757 return;
Cody Northrop1242dfd2016-07-13 17:24:59 -060024758 }
24759 }
24760}
24761#endif
24762
Tony Barbour300a6082015-04-07 13:44:53 -060024763int main(int argc, char **argv) {
24764 int result;
24765
Cody Northrop8e54a402016-03-08 22:25:52 -070024766#ifdef ANDROID
24767 int vulkanSupport = InitVulkan();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070024768 if (vulkanSupport == 0) return 1;
Cody Northrop8e54a402016-03-08 22:25:52 -070024769#endif
24770
Tony Barbour300a6082015-04-07 13:44:53 -060024771 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -060024772 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour300a6082015-04-07 13:44:53 -060024773
24774 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
24775
24776 result = RUN_ALL_TESTS();
24777
Tony Barbour6918cd52015-04-09 12:58:51 -060024778 VkTestFramework::Finish();
Tony Barbour300a6082015-04-07 13:44:53 -060024779 return result;
24780}