blob: 489612598643e5e56132dd9c3d475e96081db81f [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;
4872 bvci.format = VK_FORMAT_R8_UNORM;
4873 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"
4900 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
4901 "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;
12325
12326 unsigned feature_count = sizeof(VkPhysicalDeviceFeatures) / sizeof(VkBool32);
12327 VkBool32 *feature_array = reinterpret_cast<VkBool32 *>(&features);
12328 for (unsigned i = 0; i < feature_count; i++) {
12329 if (VK_FALSE == feature_array[i]) {
12330 feature_array[i] = VK_TRUE;
Mark Mueller2ee294f2016-08-04 12:59:48 -060012331 device_create_info.pEnabledFeatures = &features;
Jeremy Hayesb26fd042017-03-10 09:13:22 -070012332 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12333 "While calling vkCreateDevice(), requesting feature #");
Jeremy Hayes17fd3662017-03-17 11:51:11 -060012334 // The following unexpected error is coming from the LunarG loader. Do not make it a desired message because platforms
12335 // that do not use the LunarG loader (e.g. Android) will not see the message and the test will fail.
12336 m_errorMonitor->SetUnexpectedError("Failed to create device chain.");
Jeremy Hayesb26fd042017-03-10 09:13:22 -070012337 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12338 "You requested features that are unavailable on this device. You should first "
12339 "query feature availability by calling vkGetPhysicalDeviceFeatures().");
Mark Mueller2ee294f2016-08-04 12:59:48 -060012340 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
12341 m_errorMonitor->VerifyFound();
12342 break;
12343 }
12344 }
12345}
12346
Tobin Ehlis16edf082016-11-21 12:33:49 -070012347TEST_F(VkLayerTest, InvalidQueryPoolCreate) {
12348 TEST_DESCRIPTION("Attempt to create a query pool for PIPELINE_STATISTICS without enabling pipeline stats for the device.");
12349
Tony Barbour1fa09702017-03-16 12:09:08 -060012350 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis16edf082016-11-21 12:33:49 -070012351
12352 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
12353 std::vector<VkDeviceQueueCreateInfo> queue_info;
12354 queue_info.reserve(queue_props.size());
12355 std::vector<std::vector<float>> queue_priorities;
12356 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
12357 VkDeviceQueueCreateInfo qi{};
12358 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
12359 qi.queueFamilyIndex = i;
12360 qi.queueCount = queue_props[i].queueCount;
12361 queue_priorities.emplace_back(qi.queueCount, 0.0f);
12362 qi.pQueuePriorities = queue_priorities[i].data();
12363 queue_info.push_back(qi);
12364 }
12365
12366 std::vector<const char *> device_extension_names;
12367
12368 VkDevice local_device;
12369 VkDeviceCreateInfo device_create_info = {};
12370 auto features = m_device->phy().features();
12371 // Intentionally disable pipeline stats
12372 features.pipelineStatisticsQuery = VK_FALSE;
12373 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
12374 device_create_info.pNext = NULL;
12375 device_create_info.queueCreateInfoCount = queue_info.size();
12376 device_create_info.pQueueCreateInfos = queue_info.data();
12377 device_create_info.enabledLayerCount = 0;
12378 device_create_info.ppEnabledLayerNames = NULL;
12379 device_create_info.pEnabledFeatures = &features;
12380 VkResult err = vkCreateDevice(gpu(), &device_create_info, nullptr, &local_device);
12381 ASSERT_VK_SUCCESS(err);
12382
12383 VkQueryPoolCreateInfo qpci{};
12384 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
12385 qpci.queryType = VK_QUERY_TYPE_PIPELINE_STATISTICS;
12386 qpci.queryCount = 1;
12387 VkQueryPool query_pool;
12388
12389 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01006);
12390 vkCreateQueryPool(local_device, &qpci, nullptr, &query_pool);
12391 m_errorMonitor->VerifyFound();
12392
12393 vkDestroyDevice(local_device, nullptr);
12394}
12395
Mark Mueller2ee294f2016-08-04 12:59:48 -060012396TEST_F(VkLayerTest, InvalidQueueIndexInvalidQuery) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012397 TEST_DESCRIPTION(
12398 "Use an invalid queue index in a vkCmdWaitEvents call."
12399 "End a command buffer with a query still in progress.");
Mark Mueller2ee294f2016-08-04 12:59:48 -060012400
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012401 const char *invalid_queue_index =
12402 "was created with sharingMode of VK_SHARING_MODE_EXCLUSIVE. If one "
12403 "of src- or dstQueueFamilyIndex is VK_QUEUE_FAMILY_IGNORED, both "
12404 "must be.";
Mark Mueller2ee294f2016-08-04 12:59:48 -060012405
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012406 const char *invalid_query = "Ending command buffer with in progress query: queryPool 0x";
Mark Mueller2ee294f2016-08-04 12:59:48 -060012407
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012408 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queue_index);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012409
Tony Barbour1fa09702017-03-16 12:09:08 -060012410 ASSERT_NO_FATAL_FAILURE(Init());
Mark Mueller2ee294f2016-08-04 12:59:48 -060012411
12412 VkEvent event;
12413 VkEventCreateInfo event_create_info{};
12414 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
12415 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
12416
Mark Mueller2ee294f2016-08-04 12:59:48 -060012417 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012418 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012419
Tony Barbour552f6c02016-12-21 14:34:07 -070012420 m_commandBuffer->BeginCommandBuffer();
Mark Mueller2ee294f2016-08-04 12:59:48 -060012421
12422 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060012423 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 -060012424 ASSERT_TRUE(image.initialized());
12425 VkImageMemoryBarrier img_barrier = {};
12426 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
12427 img_barrier.pNext = NULL;
12428 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
12429 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
12430 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
12431 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
12432 img_barrier.image = image.handle();
12433 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
Mark Lobodzinski2a74c5c2016-08-17 13:26:28 -060012434
12435 // QueueFamilyIndex must be VK_QUEUE_FAMILY_IGNORED, this verifies
12436 // that layer validation catches the case when it is not.
12437 img_barrier.dstQueueFamilyIndex = 0;
Mark Mueller2ee294f2016-08-04 12:59:48 -060012438 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12439 img_barrier.subresourceRange.baseArrayLayer = 0;
12440 img_barrier.subresourceRange.baseMipLevel = 0;
12441 img_barrier.subresourceRange.layerCount = 1;
12442 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012443 vkCmdWaitEvents(m_commandBuffer->handle(), 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0,
12444 nullptr, 0, nullptr, 1, &img_barrier);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012445 m_errorMonitor->VerifyFound();
12446
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012447 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_query);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012448
12449 VkQueryPool query_pool;
12450 VkQueryPoolCreateInfo query_pool_create_info = {};
12451 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
12452 query_pool_create_info.queryType = VK_QUERY_TYPE_OCCLUSION;
12453 query_pool_create_info.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012454 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012455
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012456 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0 /*startQuery*/, 1 /*queryCount*/);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012457 vkCmdBeginQuery(m_commandBuffer->handle(), query_pool, 0, 0);
12458
12459 vkEndCommandBuffer(m_commandBuffer->handle());
12460 m_errorMonitor->VerifyFound();
12461
12462 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
12463 vkDestroyEvent(m_device->device(), event, nullptr);
12464}
12465
Mark Muellerdfe37552016-07-07 14:47:42 -060012466TEST_F(VkLayerTest, VertexBufferInvalid) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012467 TEST_DESCRIPTION(
12468 "Submit a command buffer using deleted vertex buffer, "
12469 "delete a buffer twice, use an invalid offset for each "
12470 "buffer type, and attempt to bind a null buffer");
Mark Muellerdfe37552016-07-07 14:47:42 -060012471
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012472 const char *deleted_buffer_in_command_buffer =
12473 "Cannot submit cmd buffer "
12474 "using deleted buffer ";
12475 const char *invalid_offset_message =
12476 "vkBindBufferMemory(): "
12477 "memoryOffset is 0x";
12478 const char *invalid_storage_buffer_offset_message =
12479 "vkBindBufferMemory(): "
12480 "storage memoryOffset "
12481 "is 0x";
12482 const char *invalid_texel_buffer_offset_message =
12483 "vkBindBufferMemory(): "
12484 "texel memoryOffset "
12485 "is 0x";
12486 const char *invalid_uniform_buffer_offset_message =
12487 "vkBindBufferMemory(): "
12488 "uniform memoryOffset "
12489 "is 0x";
Mark Muellerdfe37552016-07-07 14:47:42 -060012490
Tony Barbour1fa09702017-03-16 12:09:08 -060012491 ASSERT_NO_FATAL_FAILURE(Init());
Mark Muellerdfe37552016-07-07 14:47:42 -060012492 ASSERT_NO_FATAL_FAILURE(InitViewport());
12493 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12494
12495 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012496 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -060012497 pipe_ms_state_ci.pNext = NULL;
12498 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
12499 pipe_ms_state_ci.sampleShadingEnable = 0;
12500 pipe_ms_state_ci.minSampleShading = 1.0;
12501 pipe_ms_state_ci.pSampleMask = nullptr;
12502
12503 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12504 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12505 VkPipelineLayout pipeline_layout;
12506
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012507 VkResult err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, nullptr, &pipeline_layout);
Mark Muellerdfe37552016-07-07 14:47:42 -060012508 ASSERT_VK_SUCCESS(err);
12509
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012510 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
12511 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Muellerdfe37552016-07-07 14:47:42 -060012512 VkPipelineObj pipe(m_device);
12513 pipe.AddShader(&vs);
12514 pipe.AddShader(&fs);
12515 pipe.AddColorAttachment();
12516 pipe.SetMSAA(&pipe_ms_state_ci);
12517 pipe.SetViewport(m_viewports);
12518 pipe.SetScissor(m_scissors);
12519 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12520
Tony Barbour552f6c02016-12-21 14:34:07 -070012521 m_commandBuffer->BeginCommandBuffer();
12522 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012523 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Muellerdfe37552016-07-07 14:47:42 -060012524
12525 {
12526 // Create and bind a vertex buffer in a reduced scope, which will cause
12527 // it to be deleted upon leaving this scope
12528 const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012529 VkVerticesObj draw_verticies(m_device, 1, 1, sizeof(vbo_data), 3, vbo_data);
Mark Muellerdfe37552016-07-07 14:47:42 -060012530 draw_verticies.BindVertexBuffers(m_commandBuffer->handle());
12531 draw_verticies.AddVertexInputToPipe(pipe);
12532 }
12533
12534 Draw(1, 0, 0, 0);
12535
Tony Barbour552f6c02016-12-21 14:34:07 -070012536 m_commandBuffer->EndRenderPass();
12537 m_commandBuffer->EndCommandBuffer();
Mark Muellerdfe37552016-07-07 14:47:42 -060012538
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012539 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, deleted_buffer_in_command_buffer);
Mark Muellerdfe37552016-07-07 14:47:42 -060012540 QueueCommandBuffer(false);
12541 m_errorMonitor->VerifyFound();
12542
12543 {
12544 // Create and bind a vertex buffer in a reduced scope, and delete it
12545 // twice, the second through the destructor
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012546 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eDoubleDelete);
Karl Schultzf78bcdd2016-11-30 12:36:01 -070012547 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00680);
Mark Muellerdfe37552016-07-07 14:47:42 -060012548 buffer_test.TestDoubleDestroy();
12549 }
12550 m_errorMonitor->VerifyFound();
12551
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012552 m_errorMonitor->SetUnexpectedError("value of pCreateInfo->usage must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012553 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidMemoryOffset)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060012554 // Create and bind a memory buffer with an invalid offset.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012555 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_offset_message);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012556 m_errorMonitor->SetUnexpectedError(
12557 "If buffer was created with the VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT or VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT, "
12558 "memoryOffset must be a multiple of VkPhysicalDeviceLimits::minTexelBufferOffsetAlignment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012559 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidMemoryOffset);
12560 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012561 m_errorMonitor->VerifyFound();
12562 }
12563
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012564 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset,
12565 VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060012566 // Create and bind a memory buffer with an invalid offset again,
12567 // but look for a texel buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012568 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_texel_buffer_offset_message);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012569 m_errorMonitor->SetUnexpectedError(
12570 "memoryOffset must be an integer multiple of the alignment member of the VkMemoryRequirements structure returned from "
12571 "a call to vkGetBufferMemoryRequirements with buffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012572 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
12573 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012574 m_errorMonitor->VerifyFound();
12575 }
12576
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012577 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060012578 // Create and bind a memory buffer with an invalid offset again, but
12579 // look for a uniform buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012580 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_uniform_buffer_offset_message);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012581 m_errorMonitor->SetUnexpectedError(
12582 "memoryOffset must be an integer multiple of the alignment member of the VkMemoryRequirements structure returned from "
12583 "a call to vkGetBufferMemoryRequirements with buffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012584 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
12585 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012586 m_errorMonitor->VerifyFound();
12587 }
12588
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012589 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060012590 // Create and bind a memory buffer with an invalid offset again, but
12591 // look for a storage buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012592 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_storage_buffer_offset_message);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012593 m_errorMonitor->SetUnexpectedError(
12594 "memoryOffset must be an integer multiple of the alignment member of the VkMemoryRequirements structure returned from "
12595 "a call to vkGetBufferMemoryRequirements with buffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012596 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
12597 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012598 m_errorMonitor->VerifyFound();
12599 }
12600
12601 {
12602 // Attempt to bind a null buffer.
Karl Schultzf78bcdd2016-11-30 12:36:01 -070012603 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00799);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012604 m_errorMonitor->SetUnexpectedError("required parameter memory specified as VK_NULL_HANDLE");
12605 m_errorMonitor->SetUnexpectedError("memory must be a valid VkDeviceMemory handle");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012606 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eBindNullBuffer);
12607 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012608 m_errorMonitor->VerifyFound();
12609 }
12610
12611 {
12612 // Attempt to use an invalid handle to delete a buffer.
Karl Schultzf78bcdd2016-11-30 12:36:01 -070012613 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00622);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012614 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eFreeInvalidHandle);
12615 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012616 }
12617 m_errorMonitor->VerifyFound();
12618
12619 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12620}
12621
Tony Barbourff1351e2017-05-10 11:14:03 -060012622TEST_F(VkLayerTest, BadVertexBufferOffset) {
12623 TEST_DESCRIPTION("Submit an offset past the end of a vertex buffer");
12624
12625 ASSERT_NO_FATAL_FAILURE(Init());
12626 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12627 static const float vbo_data[3] = {1.f, 0.f, 1.f};
Tony Barboure94224e2017-05-11 15:22:43 -060012628 VkConstantBufferObj vbo(m_device, 3, sizeof(float), (const void *)&vbo_data);
Tony Barbourff1351e2017-05-10 11:14:03 -060012629 m_commandBuffer->BeginCommandBuffer();
12630 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
12631 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01417);
Tony Barboure94224e2017-05-11 15:22:43 -060012632 BindVertexBuffer(&vbo, (VkDeviceSize)(3 * sizeof(float)), 1); // Offset at the end of the buffer
Tony Barbourff1351e2017-05-10 11:14:03 -060012633 m_errorMonitor->VerifyFound();
12634}
12635
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012636// INVALID_IMAGE_LAYOUT tests (one other case is hit by MapMemWithoutHostVisibleBit and not here)
12637TEST_F(VkLayerTest, InvalidImageLayout) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012638 TEST_DESCRIPTION(
12639 "Hit all possible validation checks associated with the "
12640 "DRAWSTATE_INVALID_IMAGE_LAYOUT enum. Generally these involve having"
12641 "images in the wrong layout when they're copied or transitioned.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012642 // 3 in ValidateCmdBufImageLayouts
12643 // * -1 Attempt to submit cmd buf w/ deleted image
12644 // * -2 Cmd buf submit of image w/ layout not matching first use w/ subresource
12645 // * -3 Cmd buf submit of image w/ layout not matching first use w/o subresource
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012646
Tony Barbour1fa09702017-03-16 12:09:08 -060012647 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -060012648 auto depth_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbourf887b162017-03-09 10:06:46 -070012649 if (!depth_format) {
12650 printf(" No Depth + Stencil format found. Skipped.\n");
12651 return;
12652 }
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012653 // Create src & dst images to use for copy operations
12654 VkImage src_image;
12655 VkImage dst_image;
Cort3b021012016-12-07 12:00:57 -080012656 VkImage depth_image;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012657
12658 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
12659 const int32_t tex_width = 32;
12660 const int32_t tex_height = 32;
12661
12662 VkImageCreateInfo image_create_info = {};
12663 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
12664 image_create_info.pNext = NULL;
12665 image_create_info.imageType = VK_IMAGE_TYPE_2D;
12666 image_create_info.format = tex_format;
12667 image_create_info.extent.width = tex_width;
12668 image_create_info.extent.height = tex_height;
12669 image_create_info.extent.depth = 1;
12670 image_create_info.mipLevels = 1;
12671 image_create_info.arrayLayers = 4;
12672 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
12673 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
12674 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Cort3b021012016-12-07 12:00:57 -080012675 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012676 image_create_info.flags = 0;
12677
12678 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &src_image);
12679 ASSERT_VK_SUCCESS(err);
Cort3b021012016-12-07 12:00:57 -080012680 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012681 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dst_image);
12682 ASSERT_VK_SUCCESS(err);
Cort3b021012016-12-07 12:00:57 -080012683 image_create_info.format = VK_FORMAT_D32_SFLOAT;
12684 image_create_info.usage |= VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
12685 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &depth_image);
12686 ASSERT_VK_SUCCESS(err);
12687
12688 // Allocate memory
12689 VkMemoryRequirements img_mem_reqs = {};
Cort530cf382016-12-08 09:59:47 -080012690 VkMemoryAllocateInfo mem_alloc = {};
Cort3b021012016-12-07 12:00:57 -080012691 VkDeviceMemory src_image_mem, dst_image_mem, depth_image_mem;
Cort530cf382016-12-08 09:59:47 -080012692 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
12693 mem_alloc.pNext = NULL;
12694 mem_alloc.allocationSize = 0;
12695 mem_alloc.memoryTypeIndex = 0;
Cort3b021012016-12-07 12:00:57 -080012696
12697 vkGetImageMemoryRequirements(m_device->device(), src_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080012698 mem_alloc.allocationSize = img_mem_reqs.size;
12699 bool pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080012700 ASSERT_TRUE(pass);
Cort530cf382016-12-08 09:59:47 -080012701 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &src_image_mem);
Cort3b021012016-12-07 12:00:57 -080012702 ASSERT_VK_SUCCESS(err);
12703
12704 vkGetImageMemoryRequirements(m_device->device(), dst_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080012705 mem_alloc.allocationSize = img_mem_reqs.size;
12706 pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080012707 ASSERT_VK_SUCCESS(err);
Cort530cf382016-12-08 09:59:47 -080012708 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &dst_image_mem);
Cort3b021012016-12-07 12:00:57 -080012709 ASSERT_VK_SUCCESS(err);
12710
12711 vkGetImageMemoryRequirements(m_device->device(), depth_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080012712 mem_alloc.allocationSize = img_mem_reqs.size;
12713 pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080012714 ASSERT_VK_SUCCESS(err);
Cort530cf382016-12-08 09:59:47 -080012715 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &depth_image_mem);
Cort3b021012016-12-07 12:00:57 -080012716 ASSERT_VK_SUCCESS(err);
12717
12718 err = vkBindImageMemory(m_device->device(), src_image, src_image_mem, 0);
12719 ASSERT_VK_SUCCESS(err);
12720 err = vkBindImageMemory(m_device->device(), dst_image, dst_image_mem, 0);
12721 ASSERT_VK_SUCCESS(err);
12722 err = vkBindImageMemory(m_device->device(), depth_image, depth_image_mem, 0);
12723 ASSERT_VK_SUCCESS(err);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012724
Tony Barbour552f6c02016-12-21 14:34:07 -070012725 m_commandBuffer->BeginCommandBuffer();
Cort530cf382016-12-08 09:59:47 -080012726 VkImageCopy copy_region;
12727 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12728 copy_region.srcSubresource.mipLevel = 0;
12729 copy_region.srcSubresource.baseArrayLayer = 0;
12730 copy_region.srcSubresource.layerCount = 1;
12731 copy_region.srcOffset.x = 0;
12732 copy_region.srcOffset.y = 0;
12733 copy_region.srcOffset.z = 0;
12734 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12735 copy_region.dstSubresource.mipLevel = 0;
12736 copy_region.dstSubresource.baseArrayLayer = 0;
12737 copy_region.dstSubresource.layerCount = 1;
12738 copy_region.dstOffset.x = 0;
12739 copy_region.dstOffset.y = 0;
12740 copy_region.dstOffset.z = 0;
12741 copy_region.extent.width = 1;
12742 copy_region.extent.height = 1;
12743 copy_region.extent.depth = 1;
12744
Mark Lobodzinski91c28262017-03-22 13:06:12 -060012745 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
12746 "layout should be VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL instead of GENERAL.");
12747 m_errorMonitor->SetUnexpectedError("layout should be VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL instead of GENERAL.");
Tobin Ehlis74cc6822017-03-14 16:16:51 -060012748
Cort530cf382016-12-08 09:59:47 -080012749 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 -060012750 m_errorMonitor->VerifyFound();
Tobin Ehlise35b66a2017-03-15 12:18:31 -060012751 // The first call hits the expected WARNING and skips the call down the chain, so call a second time to call down chain and
12752 // update layer state
Mark Lobodzinski91c28262017-03-22 13:06:12 -060012753 m_errorMonitor->SetUnexpectedError("layout should be VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL instead of GENERAL.");
12754 m_errorMonitor->SetUnexpectedError("layout should be VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL instead of GENERAL.");
Tobin Ehlise35b66a2017-03-15 12:18:31 -060012755 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 -060012756 // Now cause error due to src image layout changing
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012757 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski91c28262017-03-22 13:06:12 -060012758 "with specific layout VK_IMAGE_LAYOUT_UNDEFINED that "
12759 "doesn't match the actual current layout VK_IMAGE_LAYOUT_GENERAL.");
Mark Lobodzinskic61e1da2017-05-15 16:18:13 -060012760 m_errorMonitor->SetUnexpectedError("is VK_IMAGE_LAYOUT_UNDEFINED but can only be VK_IMAGE_LAYOUT");
Cort530cf382016-12-08 09:59:47 -080012761 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 -060012762 m_errorMonitor->VerifyFound();
12763 // Final src error is due to bad layout type
Tobin Ehlis74cc6822017-03-14 16:16:51 -060012764 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski91c28262017-03-22 13:06:12 -060012765 "is VK_IMAGE_LAYOUT_UNDEFINED but can only be "
Tobin Ehlis74cc6822017-03-14 16:16:51 -060012766 "VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL or VK_IMAGE_LAYOUT_GENERAL.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012767 m_errorMonitor->SetUnexpectedError(
Mark Lobodzinski91c28262017-03-22 13:06:12 -060012768 "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 -080012769 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 -060012770 m_errorMonitor->VerifyFound();
12771 // Now verify same checks for dst
Mark Lobodzinski91c28262017-03-22 13:06:12 -060012772 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
12773 "layout should be VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL instead of GENERAL.");
12774 m_errorMonitor->SetUnexpectedError("layout should be VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL instead of GENERAL.");
Cort530cf382016-12-08 09:59:47 -080012775 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 -060012776 m_errorMonitor->VerifyFound();
12777 // Now cause error due to src image layout changing
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012778 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski91c28262017-03-22 13:06:12 -060012779 "with specific layout VK_IMAGE_LAYOUT_UNDEFINED that doesn't match "
Tobin Ehlis74cc6822017-03-14 16:16:51 -060012780 "the actual current layout VK_IMAGE_LAYOUT_GENERAL.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012781 m_errorMonitor->SetUnexpectedError(
Mark Lobodzinski91c28262017-03-22 13:06:12 -060012782 "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 -080012783 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 -060012784 m_errorMonitor->VerifyFound();
Tobin Ehlis74cc6822017-03-14 16:16:51 -060012785 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski91c28262017-03-22 13:06:12 -060012786 "is VK_IMAGE_LAYOUT_UNDEFINED but can only be VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL "
12787 "or VK_IMAGE_LAYOUT_GENERAL.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012788 m_errorMonitor->SetUnexpectedError(
Mark Lobodzinski91c28262017-03-22 13:06:12 -060012789 "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 -080012790 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 -060012791 m_errorMonitor->VerifyFound();
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010012792
Cort3b021012016-12-07 12:00:57 -080012793 // Convert dst and depth images to TRANSFER_DST for subsequent tests
12794 VkImageMemoryBarrier transfer_dst_image_barrier[1] = {};
12795 transfer_dst_image_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
12796 transfer_dst_image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
12797 transfer_dst_image_barrier[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
12798 transfer_dst_image_barrier[0].srcAccessMask = 0;
12799 transfer_dst_image_barrier[0].dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
12800 transfer_dst_image_barrier[0].image = dst_image;
12801 transfer_dst_image_barrier[0].subresourceRange.layerCount = image_create_info.arrayLayers;
12802 transfer_dst_image_barrier[0].subresourceRange.levelCount = image_create_info.mipLevels;
12803 transfer_dst_image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12804 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
12805 NULL, 0, NULL, 1, transfer_dst_image_barrier);
12806 transfer_dst_image_barrier[0].image = depth_image;
12807 transfer_dst_image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
12808 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
12809 NULL, 0, NULL, 1, transfer_dst_image_barrier);
12810
12811 // Cause errors due to clearing with invalid image layouts
Cort530cf382016-12-08 09:59:47 -080012812 VkClearColorValue color_clear_value = {};
12813 VkImageSubresourceRange clear_range;
12814 clear_range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12815 clear_range.baseMipLevel = 0;
12816 clear_range.baseArrayLayer = 0;
12817 clear_range.layerCount = 1;
12818 clear_range.levelCount = 1;
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010012819
Cort3b021012016-12-07 12:00:57 -080012820 // Fail due to explicitly prohibited layout for color clear (only GENERAL and TRANSFER_DST are permitted).
12821 // Since the image is currently not in UNDEFINED layout, this will emit two errors.
12822 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01086);
12823 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01085);
Cort530cf382016-12-08 09:59:47 -080012824 m_commandBuffer->ClearColorImage(dst_image, VK_IMAGE_LAYOUT_UNDEFINED, &color_clear_value, 1, &clear_range);
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010012825 m_errorMonitor->VerifyFound();
Cort3b021012016-12-07 12:00:57 -080012826 // Fail due to provided layout not matching actual current layout for color clear.
12827 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01085);
Cort530cf382016-12-08 09:59:47 -080012828 m_commandBuffer->ClearColorImage(dst_image, VK_IMAGE_LAYOUT_GENERAL, &color_clear_value, 1, &clear_range);
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010012829 m_errorMonitor->VerifyFound();
Cort3b021012016-12-07 12:00:57 -080012830
Cort530cf382016-12-08 09:59:47 -080012831 VkClearDepthStencilValue depth_clear_value = {};
12832 clear_range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Cort3b021012016-12-07 12:00:57 -080012833
12834 // Fail due to explicitly prohibited layout for depth clear (only GENERAL and TRANSFER_DST are permitted).
12835 // Since the image is currently not in UNDEFINED layout, this will emit two errors.
12836 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01101);
12837 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01100);
Cort530cf382016-12-08 09:59:47 -080012838 m_commandBuffer->ClearDepthStencilImage(depth_image, VK_IMAGE_LAYOUT_UNDEFINED, &depth_clear_value, 1, &clear_range);
Cort3b021012016-12-07 12:00:57 -080012839 m_errorMonitor->VerifyFound();
12840 // Fail due to provided layout not matching actual current layout for depth clear.
12841 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01100);
Cort530cf382016-12-08 09:59:47 -080012842 m_commandBuffer->ClearDepthStencilImage(depth_image, VK_IMAGE_LAYOUT_GENERAL, &depth_clear_value, 1, &clear_range);
Cort3b021012016-12-07 12:00:57 -080012843 m_errorMonitor->VerifyFound();
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010012844
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012845 // Now cause error due to bad image layout transition in PipelineBarrier
12846 VkImageMemoryBarrier image_barrier[1] = {};
Cort3b021012016-12-07 12:00:57 -080012847 image_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012848 image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
Cort3b021012016-12-07 12:00:57 -080012849 image_barrier[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012850 image_barrier[0].image = src_image;
Cort3b021012016-12-07 12:00:57 -080012851 image_barrier[0].subresourceRange.layerCount = image_create_info.arrayLayers;
12852 image_barrier[0].subresourceRange.levelCount = image_create_info.mipLevels;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012853 image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012854 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski91c28262017-03-22 13:06:12 -060012855 "you cannot transition the layout of aspect 1 from "
12856 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL when current layout is "
12857 "VK_IMAGE_LAYOUT_GENERAL.");
Mike Weiblen62d08a32017-03-07 22:18:27 -070012858 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00305);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012859 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
12860 NULL, 0, NULL, 1, image_barrier);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012861 m_errorMonitor->VerifyFound();
12862
12863 // Finally some layout errors at RenderPass create time
12864 // Just hacking in specific state to get to the errors we want so don't copy this unless you know what you're doing.
12865 VkAttachmentReference attach = {};
12866 // perf warning for GENERAL layout w/ non-DS input attachment
12867 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
12868 VkSubpassDescription subpass = {};
12869 subpass.inputAttachmentCount = 1;
12870 subpass.pInputAttachments = &attach;
12871 VkRenderPassCreateInfo rpci = {};
12872 rpci.subpassCount = 1;
12873 rpci.pSubpasses = &subpass;
12874 rpci.attachmentCount = 1;
12875 VkAttachmentDescription attach_desc = {};
12876 attach_desc.format = VK_FORMAT_UNDEFINED;
12877 rpci.pAttachments = &attach_desc;
Tobin Ehlis1efce022016-05-11 10:40:34 -060012878 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012879 VkRenderPass rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012880 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
12881 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012882 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12883 m_errorMonitor->VerifyFound();
12884 // error w/ non-general layout
12885 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
12886
12887 m_errorMonitor->SetDesiredFailureMsg(
12888 VK_DEBUG_REPORT_ERROR_BIT_EXT,
12889 "Layout for input attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be READ_ONLY_OPTIMAL or GENERAL.");
12890 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12891 m_errorMonitor->VerifyFound();
12892 subpass.inputAttachmentCount = 0;
12893 subpass.colorAttachmentCount = 1;
12894 subpass.pColorAttachments = &attach;
12895 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
12896 // perf warning for GENERAL layout on color attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012897 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
12898 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012899 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12900 m_errorMonitor->VerifyFound();
12901 // error w/ non-color opt or GENERAL layout for color attachment
12902 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
12903 m_errorMonitor->SetDesiredFailureMsg(
12904 VK_DEBUG_REPORT_ERROR_BIT_EXT,
12905 "Layout for color attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.");
12906 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12907 m_errorMonitor->VerifyFound();
12908 subpass.colorAttachmentCount = 0;
12909 subpass.pDepthStencilAttachment = &attach;
12910 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
12911 // perf warning for GENERAL layout on DS attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012912 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
12913 "GENERAL layout for depth attachment may not give optimal performance.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012914 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12915 m_errorMonitor->VerifyFound();
12916 // error w/ non-ds opt or GENERAL layout for color attachment
12917 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012918 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12919 "Layout for depth attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be "
12920 "DEPTH_STENCIL_ATTACHMENT_OPTIMAL, DEPTH_STENCIL_READ_ONLY_OPTIMAL or GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012921 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12922 m_errorMonitor->VerifyFound();
Tobin Ehlis1efce022016-05-11 10:40:34 -060012923 // For this error we need a valid renderpass so create default one
12924 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
12925 attach.attachment = 0;
Tony Barbourf887b162017-03-09 10:06:46 -070012926 attach_desc.format = depth_format;
Tobin Ehlis1efce022016-05-11 10:40:34 -060012927 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
12928 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
12929 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
12930 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
12931 // Can't do a CLEAR load on READ_ONLY initialLayout
12932 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
12933 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
12934 attach_desc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012935 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski91c28262017-03-22 13:06:12 -060012936 "with invalid first layout VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL");
Tobin Ehlis1efce022016-05-11 10:40:34 -060012937 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12938 m_errorMonitor->VerifyFound();
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012939
Cort3b021012016-12-07 12:00:57 -080012940 vkFreeMemory(m_device->device(), src_image_mem, NULL);
12941 vkFreeMemory(m_device->device(), dst_image_mem, NULL);
12942 vkFreeMemory(m_device->device(), depth_image_mem, NULL);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012943 vkDestroyImage(m_device->device(), src_image, NULL);
12944 vkDestroyImage(m_device->device(), dst_image, NULL);
Cort3b021012016-12-07 12:00:57 -080012945 vkDestroyImage(m_device->device(), depth_image, NULL);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012946}
Tobin Ehlisd8d89182016-07-18 20:13:11 -060012947
Tobin Ehlise0936662016-10-11 08:10:51 -060012948TEST_F(VkLayerTest, InvalidStorageImageLayout) {
12949 TEST_DESCRIPTION("Attempt to update a STORAGE_IMAGE descriptor w/o GENERAL layout.");
12950 VkResult err;
12951
Tony Barbour1fa09702017-03-16 12:09:08 -060012952 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlise0936662016-10-11 08:10:51 -060012953
12954 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
12955 VkImageTiling tiling;
12956 VkFormatProperties format_properties;
12957 vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties);
12958 if (format_properties.linearTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
12959 tiling = VK_IMAGE_TILING_LINEAR;
12960 } else if (format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
12961 tiling = VK_IMAGE_TILING_OPTIMAL;
12962 } else {
Dave Houlton584d51e2017-02-16 12:52:54 -070012963 printf(" Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; skipped.\n");
Tobin Ehlise0936662016-10-11 08:10:51 -060012964 return;
12965 }
12966
12967 VkDescriptorPoolSize ds_type = {};
12968 ds_type.type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
12969 ds_type.descriptorCount = 1;
12970
12971 VkDescriptorPoolCreateInfo ds_pool_ci = {};
12972 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12973 ds_pool_ci.maxSets = 1;
12974 ds_pool_ci.poolSizeCount = 1;
12975 ds_pool_ci.pPoolSizes = &ds_type;
12976 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
12977
12978 VkDescriptorPool ds_pool;
12979 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
12980 ASSERT_VK_SUCCESS(err);
12981
12982 VkDescriptorSetLayoutBinding dsl_binding = {};
12983 dsl_binding.binding = 0;
12984 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
12985 dsl_binding.descriptorCount = 1;
12986 dsl_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12987 dsl_binding.pImmutableSamplers = NULL;
12988
12989 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
12990 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12991 ds_layout_ci.pNext = NULL;
12992 ds_layout_ci.bindingCount = 1;
12993 ds_layout_ci.pBindings = &dsl_binding;
12994
12995 VkDescriptorSetLayout ds_layout;
12996 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
12997 ASSERT_VK_SUCCESS(err);
12998
12999 VkDescriptorSetAllocateInfo alloc_info = {};
13000 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
13001 alloc_info.descriptorSetCount = 1;
13002 alloc_info.descriptorPool = ds_pool;
13003 alloc_info.pSetLayouts = &ds_layout;
13004 VkDescriptorSet descriptor_set;
13005 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
13006 ASSERT_VK_SUCCESS(err);
13007
13008 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
13009 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13010 pipeline_layout_ci.pNext = NULL;
13011 pipeline_layout_ci.setLayoutCount = 1;
13012 pipeline_layout_ci.pSetLayouts = &ds_layout;
13013 VkPipelineLayout pipeline_layout;
13014 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
13015 ASSERT_VK_SUCCESS(err);
13016
13017 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060013018 image.Init(32, 32, 1, tex_format, VK_IMAGE_USAGE_STORAGE_BIT, tiling, 0);
Tobin Ehlise0936662016-10-11 08:10:51 -060013019 ASSERT_TRUE(image.initialized());
13020 VkImageView view = image.targetView(tex_format);
13021
13022 VkDescriptorImageInfo image_info = {};
13023 image_info.imageView = view;
13024 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
13025
13026 VkWriteDescriptorSet descriptor_write = {};
13027 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
13028 descriptor_write.dstSet = descriptor_set;
13029 descriptor_write.dstBinding = 0;
13030 descriptor_write.descriptorCount = 1;
13031 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
13032 descriptor_write.pImageInfo = &image_info;
13033
13034 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13035 " of VK_DESCRIPTOR_TYPE_STORAGE_IMAGE type is being updated with layout "
13036 "VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL but according to spec ");
13037 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
13038 m_errorMonitor->VerifyFound();
13039
13040 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
13041 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
13042 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
13043 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
13044}
13045
Chris Forbes3fa68552017-05-18 14:34:05 -070013046TEST_F(VkLayerTest, NonSimultaneousSecondaryMarksPrimary) {
Tony Barbour1fa09702017-03-16 12:09:08 -060013047 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes3fa68552017-05-18 14:34:05 -070013048 const char *simultaneous_use_message =
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013049 "does not have VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set and "
13050 "will cause primary command buffer";
Mark Mueller93b938f2016-08-18 10:27:40 -060013051
Chris Forbes3fa68552017-05-18 14:34:05 -070013052 VkCommandBufferObj secondary(m_device, m_commandPool, VK_COMMAND_BUFFER_LEVEL_SECONDARY);
Mark Mueller93b938f2016-08-18 10:27:40 -060013053
Chris Forbes3fa68552017-05-18 14:34:05 -070013054 secondary.begin();
13055 secondary.end();
Rene Lindsay24cf6c52017-01-04 12:06:59 -070013056
Chris Forbes3fa68552017-05-18 14:34:05 -070013057 VkCommandBufferBeginInfo cbbi = {
13058 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
13059 VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT, nullptr,
13060 };
Mark Mueller93b938f2016-08-18 10:27:40 -060013061
Chris Forbes3fa68552017-05-18 14:34:05 -070013062 m_commandBuffer->begin(&cbbi);
13063 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, simultaneous_use_message);
13064 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary.handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060013065 m_errorMonitor->VerifyFound();
Chris Forbes3fa68552017-05-18 14:34:05 -070013066 m_commandBuffer->end();
13067}
Mark Mueller93b938f2016-08-18 10:27:40 -060013068
Chris Forbes3fa68552017-05-18 14:34:05 -070013069TEST_F(VkLayerTest, SimultaneousUseSecondaryTwoExecutes) {
13070 ASSERT_NO_FATAL_FAILURE(Init());
Mark Mueller93b938f2016-08-18 10:27:40 -060013071
Chris Forbes3fa68552017-05-18 14:34:05 -070013072 const char *simultaneous_use_message = "without VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set!";
Mark Mueller4042b652016-09-05 22:52:21 -060013073
Chris Forbes3fa68552017-05-18 14:34:05 -070013074 VkCommandBufferObj secondary(m_device, m_commandPool, VK_COMMAND_BUFFER_LEVEL_SECONDARY);
13075
13076 VkCommandBufferInheritanceInfo inh = {
13077 VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO, nullptr,
13078 };
13079 VkCommandBufferBeginInfo cbbi = {
13080 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
13081 0, &inh
13082 };
13083
13084 secondary.begin(&cbbi);
13085 secondary.end();
13086
13087 m_commandBuffer->begin();
13088 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary.handle());
13089 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, simultaneous_use_message);
13090 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary.handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060013091 m_errorMonitor->VerifyFound();
Chris Forbes3fa68552017-05-18 14:34:05 -070013092 m_commandBuffer->end();
13093}
Rene Lindsay24cf6c52017-01-04 12:06:59 -070013094
Chris Forbes3fa68552017-05-18 14:34:05 -070013095TEST_F(VkLayerTest, SimultaneousUseSecondarySingleExecute) {
13096 ASSERT_NO_FATAL_FAILURE(Init());
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070013097
Chris Forbes3fa68552017-05-18 14:34:05 -070013098 // variation on previous test executing the same CB twice in the same
13099 // CmdExecuteCommands call
13100
13101 const char *simultaneous_use_message = "without VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set!";
13102
13103 VkCommandBufferObj secondary(m_device, m_commandPool, VK_COMMAND_BUFFER_LEVEL_SECONDARY);
13104
13105 VkCommandBufferInheritanceInfo inh = {
13106 VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO, nullptr,
13107 };
13108 VkCommandBufferBeginInfo cbbi = {
13109 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
13110 0, &inh
13111 };
13112
13113 secondary.begin(&cbbi);
13114 secondary.end();
13115
13116 m_commandBuffer->begin();
13117 VkCommandBuffer cbs[] = { secondary.handle(), secondary.handle() };
13118 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, simultaneous_use_message);
13119 vkCmdExecuteCommands(m_commandBuffer->handle(), 2, cbs);
13120 m_errorMonitor->VerifyFound();
13121 m_commandBuffer->end();
Mark Mueller93b938f2016-08-18 10:27:40 -060013122}
13123
Tony Barbour626994c2017-02-08 15:29:37 -070013124TEST_F(VkLayerTest, SimultaneousUseOneShot) {
13125 TEST_DESCRIPTION(
13126 "Submit the same command buffer twice in one submit looking for simultaneous use and one time submit"
13127 "errors");
13128 const char *simultaneous_use_message = "is already in use and is not marked for simultaneous use";
13129 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 -060013130 ASSERT_NO_FATAL_FAILURE(Init());
Tony Barbour626994c2017-02-08 15:29:37 -070013131
13132 VkCommandBuffer cmd_bufs[2];
13133 VkCommandBufferAllocateInfo alloc_info;
13134 alloc_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
13135 alloc_info.pNext = NULL;
13136 alloc_info.commandBufferCount = 2;
Mike Schuchardt06304c22017-03-01 17:09:09 -070013137 alloc_info.commandPool = m_commandPool->handle();
Tony Barbour626994c2017-02-08 15:29:37 -070013138 alloc_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
13139 vkAllocateCommandBuffers(m_device->device(), &alloc_info, cmd_bufs);
13140
13141 VkCommandBufferBeginInfo cb_binfo;
13142 cb_binfo.pNext = NULL;
13143 cb_binfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
13144 cb_binfo.pInheritanceInfo = VK_NULL_HANDLE;
13145 cb_binfo.flags = 0;
13146 vkBeginCommandBuffer(cmd_bufs[0], &cb_binfo);
13147 VkViewport viewport = {0, 0, 16, 16, 0, 1};
13148 vkCmdSetViewport(cmd_bufs[0], 0, 1, &viewport);
13149 vkEndCommandBuffer(cmd_bufs[0]);
13150 VkCommandBuffer duplicates[2] = {cmd_bufs[0], cmd_bufs[0]};
13151
13152 VkSubmitInfo submit_info = {};
13153 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
13154 submit_info.commandBufferCount = 2;
13155 submit_info.pCommandBuffers = duplicates;
13156 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, simultaneous_use_message);
13157 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
13158 m_errorMonitor->VerifyFound();
13159 vkQueueWaitIdle(m_device->m_queue);
13160
13161 // Set one time use and now look for one time submit
13162 duplicates[0] = duplicates[1] = cmd_bufs[1];
13163 cb_binfo.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT | VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
13164 vkBeginCommandBuffer(cmd_bufs[1], &cb_binfo);
13165 vkCmdSetViewport(cmd_bufs[1], 0, 1, &viewport);
13166 vkEndCommandBuffer(cmd_bufs[1]);
13167 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, one_shot_message);
13168 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
13169 m_errorMonitor->VerifyFound();
13170 vkQueueWaitIdle(m_device->m_queue);
13171}
13172
Tobin Ehlisb093da82017-01-19 12:05:27 -070013173TEST_F(VkLayerTest, StageMaskGsTsEnabled) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013174 TEST_DESCRIPTION(
13175 "Attempt to use a stageMask w/ geometry shader and tesselation shader bits enabled when those features are "
13176 "disabled on the device.");
Tobin Ehlisb093da82017-01-19 12:05:27 -070013177
Tony Barbour1fa09702017-03-16 12:09:08 -060013178 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisb093da82017-01-19 12:05:27 -070013179 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13180
13181 std::vector<const char *> device_extension_names;
13182 auto features = m_device->phy().features();
13183 // Make sure gs & ts are disabled
13184 features.geometryShader = false;
13185 features.tessellationShader = false;
13186 // The sacrificial device object
13187 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
13188
13189 VkCommandPoolCreateInfo pool_create_info{};
13190 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
13191 pool_create_info.queueFamilyIndex = test_device.graphics_queue_node_index_;
13192
13193 VkCommandPool command_pool;
13194 vkCreateCommandPool(test_device.handle(), &pool_create_info, nullptr, &command_pool);
13195
13196 VkCommandBufferAllocateInfo cmd = {};
13197 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
13198 cmd.pNext = NULL;
13199 cmd.commandPool = command_pool;
13200 cmd.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
13201 cmd.commandBufferCount = 1;
13202
13203 VkCommandBuffer cmd_buffer;
13204 VkResult err = vkAllocateCommandBuffers(test_device.handle(), &cmd, &cmd_buffer);
13205 ASSERT_VK_SUCCESS(err);
13206
13207 VkEvent event;
13208 VkEventCreateInfo evci = {};
13209 evci.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
13210 VkResult result = vkCreateEvent(test_device.handle(), &evci, NULL, &event);
13211 ASSERT_VK_SUCCESS(result);
13212
13213 VkCommandBufferBeginInfo cbbi = {};
13214 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
13215 vkBeginCommandBuffer(cmd_buffer, &cbbi);
13216 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00230);
13217 vkCmdSetEvent(cmd_buffer, event, VK_PIPELINE_STAGE_GEOMETRY_SHADER_BIT);
13218 m_errorMonitor->VerifyFound();
13219
13220 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00231);
13221 vkCmdSetEvent(cmd_buffer, event, VK_PIPELINE_STAGE_TESSELLATION_CONTROL_SHADER_BIT);
13222 m_errorMonitor->VerifyFound();
13223
13224 vkDestroyEvent(test_device.handle(), event, NULL);
13225 vkDestroyCommandPool(test_device.handle(), command_pool, NULL);
13226}
13227
Chris Forbesd70103a2017-04-13 11:34:09 -070013228TEST_F(VkLayerTest, EventInUseDestroyedSignaled) {
Tony Barbour1fa09702017-03-16 12:09:08 -060013229 ASSERT_NO_FATAL_FAILURE(Init());
Mark Mueller917f6bc2016-08-30 10:57:19 -060013230 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13231
Tony Barbour552f6c02016-12-21 14:34:07 -070013232 m_commandBuffer->BeginCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060013233
13234 VkEvent event;
13235 VkEventCreateInfo event_create_info = {};
13236 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
13237 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013238 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Mueller917f6bc2016-08-30 10:57:19 -060013239
Tony Barbour552f6c02016-12-21 14:34:07 -070013240 m_commandBuffer->EndCommandBuffer();
Mark Muellerc8d441e2016-08-23 17:36:00 -060013241 vkDestroyEvent(m_device->device(), event, nullptr);
13242
13243 VkSubmitInfo submit_info = {};
13244 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
13245 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013246 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Lobodzinskife4be302017-02-14 13:08:15 -070013247 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is invalid because bound");
Mark Muellerc8d441e2016-08-23 17:36:00 -060013248 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
13249 m_errorMonitor->VerifyFound();
Chris Forbesd70103a2017-04-13 11:34:09 -070013250}
Mark Muellerc8d441e2016-08-23 17:36:00 -060013251
Chris Forbesd70103a2017-04-13 11:34:09 -070013252TEST_F(VkLayerTest, InUseDestroyedSignaled) {
13253 TEST_DESCRIPTION(
13254 "Use vkCmdExecuteCommands with invalid state "
13255 "in primary and secondary command buffers. "
13256 "Delete objects that are inuse. Call VkQueueSubmit "
13257 "with an event that has been deleted.");
Mark Muellerc8d441e2016-08-23 17:36:00 -060013258
Chris Forbesd70103a2017-04-13 11:34:09 -070013259 ASSERT_NO_FATAL_FAILURE(Init());
13260 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13261
13262 m_errorMonitor->ExpectSuccess();
Mark Muellerc8d441e2016-08-23 17:36:00 -060013263
Mark Mueller917f6bc2016-08-30 10:57:19 -060013264 VkSemaphoreCreateInfo semaphore_create_info = {};
13265 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
13266 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013267 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller917f6bc2016-08-30 10:57:19 -060013268 VkFenceCreateInfo fence_create_info = {};
13269 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
13270 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013271 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller917f6bc2016-08-30 10:57:19 -060013272
13273 VkDescriptorPoolSize descriptor_pool_type_count = {};
Mark Mueller4042b652016-09-05 22:52:21 -060013274 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060013275 descriptor_pool_type_count.descriptorCount = 1;
13276
13277 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
13278 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
13279 descriptor_pool_create_info.maxSets = 1;
13280 descriptor_pool_create_info.poolSizeCount = 1;
13281 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013282 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Mark Mueller917f6bc2016-08-30 10:57:19 -060013283
13284 VkDescriptorPool descriptorset_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013285 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
Mark Mueller917f6bc2016-08-30 10:57:19 -060013286
13287 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
Mark Mueller4042b652016-09-05 22:52:21 -060013288 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060013289 descriptorset_layout_binding.descriptorCount = 1;
13290 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
13291
13292 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013293 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060013294 descriptorset_layout_create_info.bindingCount = 1;
13295 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
13296
13297 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013298 ASSERT_VK_SUCCESS(
13299 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060013300
13301 VkDescriptorSet descriptorset;
13302 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013303 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060013304 descriptorset_allocate_info.descriptorSetCount = 1;
13305 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
13306 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013307 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
Mark Mueller917f6bc2016-08-30 10:57:19 -060013308
Mark Mueller4042b652016-09-05 22:52:21 -060013309 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
13310
13311 VkDescriptorBufferInfo buffer_info = {};
13312 buffer_info.buffer = buffer_test.GetBuffer();
13313 buffer_info.offset = 0;
13314 buffer_info.range = 1024;
13315
13316 VkWriteDescriptorSet write_descriptor_set = {};
13317 write_descriptor_set.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
13318 write_descriptor_set.dstSet = descriptorset;
13319 write_descriptor_set.descriptorCount = 1;
13320 write_descriptor_set.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
13321 write_descriptor_set.pBufferInfo = &buffer_info;
13322
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013323 vkUpdateDescriptorSets(m_device->device(), 1, &write_descriptor_set, 0, nullptr);
Mark Mueller4042b652016-09-05 22:52:21 -060013324
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013325 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
13326 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Mueller917f6bc2016-08-30 10:57:19 -060013327
13328 VkPipelineObj pipe(m_device);
13329 pipe.AddColorAttachment();
13330 pipe.AddShader(&vs);
13331 pipe.AddShader(&fs);
13332
13333 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013334 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060013335 pipeline_layout_create_info.setLayoutCount = 1;
13336 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
13337
13338 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013339 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060013340
13341 pipe.CreateVKPipeline(pipeline_layout, m_renderPass);
13342
Chris Forbesd70103a2017-04-13 11:34:09 -070013343 VkEvent event;
13344 VkEventCreateInfo event_create_info = {};
13345 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
13346 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
13347
Tony Barbour552f6c02016-12-21 14:34:07 -070013348 m_commandBuffer->BeginCommandBuffer();
Chris Forbesd70103a2017-04-13 11:34:09 -070013349
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013350 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Muellerc8d441e2016-08-23 17:36:00 -060013351
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013352 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
13353 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
13354 &descriptorset, 0, NULL);
Mark Mueller917f6bc2016-08-30 10:57:19 -060013355
Tony Barbour552f6c02016-12-21 14:34:07 -070013356 m_commandBuffer->EndCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060013357
Chris Forbesd70103a2017-04-13 11:34:09 -070013358 VkSubmitInfo submit_info = {};
13359 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
13360 submit_info.commandBufferCount = 1;
13361 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller917f6bc2016-08-30 10:57:19 -060013362 submit_info.signalSemaphoreCount = 1;
13363 submit_info.pSignalSemaphores = &semaphore;
13364 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013365 m_errorMonitor->Reset(); // resume logmsg processing
Mark Muellerc8d441e2016-08-23 17:36:00 -060013366
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070013367 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00213);
Mark Mueller917f6bc2016-08-30 10:57:19 -060013368 vkDestroyEvent(m_device->device(), event, nullptr);
13369 m_errorMonitor->VerifyFound();
13370
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070013371 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00199);
Mark Mueller917f6bc2016-08-30 10:57:19 -060013372 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
13373 m_errorMonitor->VerifyFound();
13374
Jeremy Hayes08369882017-02-02 10:31:06 -070013375 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Fence 0x");
Mark Mueller917f6bc2016-08-30 10:57:19 -060013376 vkDestroyFence(m_device->device(), fence, nullptr);
13377 m_errorMonitor->VerifyFound();
13378
Tobin Ehlis122207b2016-09-01 08:50:06 -070013379 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070013380 m_errorMonitor->SetUnexpectedError("If semaphore is not VK_NULL_HANDLE, semaphore must be a valid VkSemaphore handle");
13381 m_errorMonitor->SetUnexpectedError("Unable to remove Semaphore obj");
Mark Mueller917f6bc2016-08-30 10:57:19 -060013382 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070013383 m_errorMonitor->SetUnexpectedError("If fence is not VK_NULL_HANDLE, fence must be a valid VkFence handle");
13384 m_errorMonitor->SetUnexpectedError("Unable to remove Fence obj");
Mark Mueller917f6bc2016-08-30 10:57:19 -060013385 vkDestroyFence(m_device->device(), fence, nullptr);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070013386 m_errorMonitor->SetUnexpectedError("If event is not VK_NULL_HANDLE, event must be a valid VkEvent handle");
13387 m_errorMonitor->SetUnexpectedError("Unable to remove Event obj");
Mark Mueller917f6bc2016-08-30 10:57:19 -060013388 vkDestroyEvent(m_device->device(), event, nullptr);
13389 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013390 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
Mark Mueller917f6bc2016-08-30 10:57:19 -060013391 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13392}
13393
Tobin Ehlis2adda372016-09-01 08:51:06 -070013394TEST_F(VkLayerTest, QueryPoolInUseDestroyedSignaled) {
13395 TEST_DESCRIPTION("Delete in-use query pool.");
13396
Tony Barbour1fa09702017-03-16 12:09:08 -060013397 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis2adda372016-09-01 08:51:06 -070013398 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13399
13400 VkQueryPool query_pool;
13401 VkQueryPoolCreateInfo query_pool_ci{};
13402 query_pool_ci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
13403 query_pool_ci.queryType = VK_QUERY_TYPE_TIMESTAMP;
13404 query_pool_ci.queryCount = 1;
13405 vkCreateQueryPool(m_device->device(), &query_pool_ci, nullptr, &query_pool);
Tony Barbour552f6c02016-12-21 14:34:07 -070013406 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis2adda372016-09-01 08:51:06 -070013407 // Reset query pool to create binding with cmd buffer
13408 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0, 1);
13409
Tony Barbour552f6c02016-12-21 14:34:07 -070013410 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis2adda372016-09-01 08:51:06 -070013411
13412 VkSubmitInfo submit_info = {};
13413 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
13414 submit_info.commandBufferCount = 1;
13415 submit_info.pCommandBuffers = &m_commandBuffer->handle();
13416 // Submit cmd buffer and then destroy query pool while in-flight
13417 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
13418
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070013419 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01012);
Tobin Ehlis2adda372016-09-01 08:51:06 -070013420 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
13421 m_errorMonitor->VerifyFound();
13422
13423 vkQueueWaitIdle(m_device->m_queue);
13424 // Now that cmd buffer done we can safely destroy query_pool
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070013425 m_errorMonitor->SetUnexpectedError("If queryPool is not VK_NULL_HANDLE, queryPool must be a valid VkQueryPool handle");
Mark Lobodzinski74597792017-04-11 15:43:49 -060013426 m_errorMonitor->SetUnexpectedError("Unable to remove QueryPool obj");
Tobin Ehlis2adda372016-09-01 08:51:06 -070013427 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
13428}
13429
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060013430TEST_F(VkLayerTest, PipelineInUseDestroyedSignaled) {
13431 TEST_DESCRIPTION("Delete in-use pipeline.");
13432
Tony Barbour1fa09702017-03-16 12:09:08 -060013433 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060013434 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13435
13436 // Empty pipeline layout used for binding PSO
13437 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
13438 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13439 pipeline_layout_ci.setLayoutCount = 0;
13440 pipeline_layout_ci.pSetLayouts = NULL;
13441
13442 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013443 VkResult err = vkCreatePipelineLayout(m_device->handle(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060013444 ASSERT_VK_SUCCESS(err);
13445
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070013446 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00555);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060013447 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013448 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
13449 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060013450 // Store pipeline handle so we can actually delete it before test finishes
13451 VkPipeline delete_this_pipeline;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013452 { // Scope pipeline so it will be auto-deleted
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060013453 VkPipelineObj pipe(m_device);
13454 pipe.AddShader(&vs);
13455 pipe.AddShader(&fs);
13456 pipe.AddColorAttachment();
13457 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13458 delete_this_pipeline = pipe.handle();
13459
Tony Barbour552f6c02016-12-21 14:34:07 -070013460 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060013461 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013462 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060013463
Tony Barbour552f6c02016-12-21 14:34:07 -070013464 m_commandBuffer->EndCommandBuffer();
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060013465
13466 VkSubmitInfo submit_info = {};
13467 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
13468 submit_info.commandBufferCount = 1;
13469 submit_info.pCommandBuffers = &m_commandBuffer->handle();
13470 // Submit cmd buffer and then pipeline destroyed while in-flight
13471 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013472 } // Pipeline deletion triggered here
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060013473 m_errorMonitor->VerifyFound();
13474 // Make sure queue finished and then actually delete pipeline
13475 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070013476 m_errorMonitor->SetUnexpectedError("If pipeline is not VK_NULL_HANDLE, pipeline must be a valid VkPipeline handle");
13477 m_errorMonitor->SetUnexpectedError("Unable to remove Pipeline obj");
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060013478 vkDestroyPipeline(m_device->handle(), delete_this_pipeline, nullptr);
13479 vkDestroyPipelineLayout(m_device->handle(), pipeline_layout, nullptr);
13480}
13481
Tobin Ehlis7d965da2016-09-19 16:15:45 -060013482TEST_F(VkLayerTest, ImageViewInUseDestroyedSignaled) {
13483 TEST_DESCRIPTION("Delete in-use imageView.");
13484
Tony Barbour1fa09702017-03-16 12:09:08 -060013485 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis7d965da2016-09-19 16:15:45 -060013486 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13487
13488 VkDescriptorPoolSize ds_type_count;
13489 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
13490 ds_type_count.descriptorCount = 1;
13491
13492 VkDescriptorPoolCreateInfo ds_pool_ci = {};
13493 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
13494 ds_pool_ci.maxSets = 1;
13495 ds_pool_ci.poolSizeCount = 1;
13496 ds_pool_ci.pPoolSizes = &ds_type_count;
13497
13498 VkDescriptorPool ds_pool;
13499 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
13500 ASSERT_VK_SUCCESS(err);
13501
13502 VkSamplerCreateInfo sampler_ci = {};
13503 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
13504 sampler_ci.pNext = NULL;
13505 sampler_ci.magFilter = VK_FILTER_NEAREST;
13506 sampler_ci.minFilter = VK_FILTER_NEAREST;
13507 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
13508 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
13509 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
13510 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
13511 sampler_ci.mipLodBias = 1.0;
13512 sampler_ci.anisotropyEnable = VK_FALSE;
13513 sampler_ci.maxAnisotropy = 1;
13514 sampler_ci.compareEnable = VK_FALSE;
13515 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
13516 sampler_ci.minLod = 1.0;
13517 sampler_ci.maxLod = 1.0;
13518 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
13519 sampler_ci.unnormalizedCoordinates = VK_FALSE;
13520 VkSampler sampler;
13521
13522 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
13523 ASSERT_VK_SUCCESS(err);
13524
13525 VkDescriptorSetLayoutBinding layout_binding;
13526 layout_binding.binding = 0;
13527 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
13528 layout_binding.descriptorCount = 1;
13529 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
13530 layout_binding.pImmutableSamplers = NULL;
13531
13532 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
13533 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
13534 ds_layout_ci.bindingCount = 1;
13535 ds_layout_ci.pBindings = &layout_binding;
13536 VkDescriptorSetLayout ds_layout;
13537 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
13538 ASSERT_VK_SUCCESS(err);
13539
13540 VkDescriptorSetAllocateInfo alloc_info = {};
13541 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
13542 alloc_info.descriptorSetCount = 1;
13543 alloc_info.descriptorPool = ds_pool;
13544 alloc_info.pSetLayouts = &ds_layout;
13545 VkDescriptorSet descriptor_set;
13546 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
13547 ASSERT_VK_SUCCESS(err);
13548
13549 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
13550 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13551 pipeline_layout_ci.pNext = NULL;
13552 pipeline_layout_ci.setLayoutCount = 1;
13553 pipeline_layout_ci.pSetLayouts = &ds_layout;
13554
13555 VkPipelineLayout pipeline_layout;
13556 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
13557 ASSERT_VK_SUCCESS(err);
13558
13559 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060013560 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 -060013561 ASSERT_TRUE(image.initialized());
13562
13563 VkImageView view;
13564 VkImageViewCreateInfo ivci = {};
13565 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
13566 ivci.image = image.handle();
13567 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
13568 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
13569 ivci.subresourceRange.layerCount = 1;
13570 ivci.subresourceRange.baseMipLevel = 0;
13571 ivci.subresourceRange.levelCount = 1;
13572 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
13573
13574 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
13575 ASSERT_VK_SUCCESS(err);
13576
13577 VkDescriptorImageInfo image_info{};
13578 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
13579 image_info.imageView = view;
13580 image_info.sampler = sampler;
13581
13582 VkWriteDescriptorSet descriptor_write = {};
13583 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
13584 descriptor_write.dstSet = descriptor_set;
13585 descriptor_write.dstBinding = 0;
13586 descriptor_write.descriptorCount = 1;
13587 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
13588 descriptor_write.pImageInfo = &image_info;
13589
13590 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
13591
13592 // Create PSO to use the sampler
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013593 char const *vsSource =
13594 "#version 450\n"
13595 "\n"
13596 "out gl_PerVertex { \n"
13597 " vec4 gl_Position;\n"
13598 "};\n"
13599 "void main(){\n"
13600 " gl_Position = vec4(1);\n"
13601 "}\n";
13602 char const *fsSource =
13603 "#version 450\n"
13604 "\n"
13605 "layout(set=0, binding=0) uniform sampler2D s;\n"
13606 "layout(location=0) out vec4 x;\n"
13607 "void main(){\n"
13608 " x = texture(s, vec2(1));\n"
13609 "}\n";
Tobin Ehlis7d965da2016-09-19 16:15:45 -060013610 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13611 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13612 VkPipelineObj pipe(m_device);
13613 pipe.AddShader(&vs);
13614 pipe.AddShader(&fs);
13615 pipe.AddColorAttachment();
13616 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13617
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070013618 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00776);
Tobin Ehlis7d965da2016-09-19 16:15:45 -060013619
Tony Barbour552f6c02016-12-21 14:34:07 -070013620 m_commandBuffer->BeginCommandBuffer();
13621 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis7d965da2016-09-19 16:15:45 -060013622 // Bind pipeline to cmd buffer
13623 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
13624 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
13625 &descriptor_set, 0, nullptr);
Rene Lindsaya8880622017-01-18 13:12:59 -070013626
13627 VkViewport viewport = {0, 0, 16, 16, 0, 1};
13628 VkRect2D scissor = {{0, 0}, {16, 16}};
13629 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
13630 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
13631
Tobin Ehlis7d965da2016-09-19 16:15:45 -060013632 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070013633 m_commandBuffer->EndRenderPass();
13634 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis7d965da2016-09-19 16:15:45 -060013635 // Submit cmd buffer then destroy sampler
13636 VkSubmitInfo submit_info = {};
13637 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
13638 submit_info.commandBufferCount = 1;
13639 submit_info.pCommandBuffers = &m_commandBuffer->handle();
13640 // Submit cmd buffer and then destroy imageView while in-flight
13641 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
13642
13643 vkDestroyImageView(m_device->device(), view, nullptr);
13644 m_errorMonitor->VerifyFound();
13645 vkQueueWaitIdle(m_device->m_queue);
13646 // Now we can actually destroy imageView
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070013647 m_errorMonitor->SetUnexpectedError("If imageView is not VK_NULL_HANDLE, imageView must be a valid VkImageView handle");
Mark Lobodzinski74597792017-04-11 15:43:49 -060013648 m_errorMonitor->SetUnexpectedError("Unable to remove ImageView obj");
Tobin Ehlis7d965da2016-09-19 16:15:45 -060013649 vkDestroyImageView(m_device->device(), view, NULL);
13650 vkDestroySampler(m_device->device(), sampler, nullptr);
13651 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
13652 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
13653 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
13654}
13655
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060013656TEST_F(VkLayerTest, BufferViewInUseDestroyedSignaled) {
13657 TEST_DESCRIPTION("Delete in-use bufferView.");
13658
Tony Barbour1fa09702017-03-16 12:09:08 -060013659 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060013660 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13661
13662 VkDescriptorPoolSize ds_type_count;
13663 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
13664 ds_type_count.descriptorCount = 1;
13665
13666 VkDescriptorPoolCreateInfo ds_pool_ci = {};
13667 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
13668 ds_pool_ci.maxSets = 1;
13669 ds_pool_ci.poolSizeCount = 1;
13670 ds_pool_ci.pPoolSizes = &ds_type_count;
13671
13672 VkDescriptorPool ds_pool;
13673 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
13674 ASSERT_VK_SUCCESS(err);
13675
13676 VkDescriptorSetLayoutBinding layout_binding;
13677 layout_binding.binding = 0;
13678 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
13679 layout_binding.descriptorCount = 1;
13680 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
13681 layout_binding.pImmutableSamplers = NULL;
13682
13683 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
13684 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
13685 ds_layout_ci.bindingCount = 1;
13686 ds_layout_ci.pBindings = &layout_binding;
13687 VkDescriptorSetLayout ds_layout;
13688 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
13689 ASSERT_VK_SUCCESS(err);
13690
13691 VkDescriptorSetAllocateInfo alloc_info = {};
13692 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
13693 alloc_info.descriptorSetCount = 1;
13694 alloc_info.descriptorPool = ds_pool;
13695 alloc_info.pSetLayouts = &ds_layout;
13696 VkDescriptorSet descriptor_set;
13697 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
13698 ASSERT_VK_SUCCESS(err);
13699
13700 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
13701 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13702 pipeline_layout_ci.pNext = NULL;
13703 pipeline_layout_ci.setLayoutCount = 1;
13704 pipeline_layout_ci.pSetLayouts = &ds_layout;
13705
13706 VkPipelineLayout pipeline_layout;
13707 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
13708 ASSERT_VK_SUCCESS(err);
13709
13710 VkBuffer buffer;
13711 uint32_t queue_family_index = 0;
13712 VkBufferCreateInfo buffer_create_info = {};
13713 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
13714 buffer_create_info.size = 1024;
13715 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
13716 buffer_create_info.queueFamilyIndexCount = 1;
13717 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
13718
13719 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
13720 ASSERT_VK_SUCCESS(err);
13721
13722 VkMemoryRequirements memory_reqs;
13723 VkDeviceMemory buffer_memory;
13724
13725 VkMemoryAllocateInfo memory_info = {};
13726 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
13727 memory_info.allocationSize = 0;
13728 memory_info.memoryTypeIndex = 0;
13729
13730 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
13731 memory_info.allocationSize = memory_reqs.size;
13732 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
13733 ASSERT_TRUE(pass);
13734
13735 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
13736 ASSERT_VK_SUCCESS(err);
13737 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
13738 ASSERT_VK_SUCCESS(err);
13739
13740 VkBufferView view;
13741 VkBufferViewCreateInfo bvci = {};
13742 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
13743 bvci.buffer = buffer;
13744 bvci.format = VK_FORMAT_R8_UNORM;
13745 bvci.range = VK_WHOLE_SIZE;
13746
13747 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
13748 ASSERT_VK_SUCCESS(err);
13749
13750 VkWriteDescriptorSet descriptor_write = {};
13751 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
13752 descriptor_write.dstSet = descriptor_set;
13753 descriptor_write.dstBinding = 0;
13754 descriptor_write.descriptorCount = 1;
13755 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
13756 descriptor_write.pTexelBufferView = &view;
13757
13758 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
13759
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013760 char const *vsSource =
13761 "#version 450\n"
13762 "\n"
13763 "out gl_PerVertex { \n"
13764 " vec4 gl_Position;\n"
13765 "};\n"
13766 "void main(){\n"
13767 " gl_Position = vec4(1);\n"
13768 "}\n";
13769 char const *fsSource =
13770 "#version 450\n"
13771 "\n"
13772 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
13773 "layout(location=0) out vec4 x;\n"
13774 "void main(){\n"
13775 " x = imageLoad(s, 0);\n"
13776 "}\n";
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060013777 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13778 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13779 VkPipelineObj pipe(m_device);
13780 pipe.AddShader(&vs);
13781 pipe.AddShader(&fs);
13782 pipe.AddColorAttachment();
13783 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13784
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070013785 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00701);
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060013786
Tony Barbour552f6c02016-12-21 14:34:07 -070013787 m_commandBuffer->BeginCommandBuffer();
13788 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060013789 VkViewport viewport = {0, 0, 16, 16, 0, 1};
13790 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
13791 VkRect2D scissor = {{0, 0}, {16, 16}};
13792 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
13793 // Bind pipeline to cmd buffer
13794 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
13795 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
13796 &descriptor_set, 0, nullptr);
13797 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070013798 m_commandBuffer->EndRenderPass();
13799 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060013800
13801 VkSubmitInfo submit_info = {};
13802 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
13803 submit_info.commandBufferCount = 1;
13804 submit_info.pCommandBuffers = &m_commandBuffer->handle();
13805 // Submit cmd buffer and then destroy bufferView while in-flight
13806 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
13807
13808 vkDestroyBufferView(m_device->device(), view, nullptr);
13809 m_errorMonitor->VerifyFound();
13810 vkQueueWaitIdle(m_device->m_queue);
13811 // Now we can actually destroy bufferView
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070013812 m_errorMonitor->SetUnexpectedError("If bufferView is not VK_NULL_HANDLE, bufferView must be a valid VkBufferView handle");
Mark Lobodzinski74597792017-04-11 15:43:49 -060013813 m_errorMonitor->SetUnexpectedError("Unable to remove BufferView obj");
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060013814 vkDestroyBufferView(m_device->device(), view, NULL);
13815 vkDestroyBuffer(m_device->device(), buffer, NULL);
13816 vkFreeMemory(m_device->device(), buffer_memory, NULL);
13817 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
13818 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
13819 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
13820}
13821
Tobin Ehlis209532e2016-09-07 13:52:18 -060013822TEST_F(VkLayerTest, SamplerInUseDestroyedSignaled) {
13823 TEST_DESCRIPTION("Delete in-use sampler.");
13824
Tony Barbour1fa09702017-03-16 12:09:08 -060013825 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis209532e2016-09-07 13:52:18 -060013826 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13827
13828 VkDescriptorPoolSize ds_type_count;
13829 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
13830 ds_type_count.descriptorCount = 1;
13831
13832 VkDescriptorPoolCreateInfo ds_pool_ci = {};
13833 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
13834 ds_pool_ci.maxSets = 1;
13835 ds_pool_ci.poolSizeCount = 1;
13836 ds_pool_ci.pPoolSizes = &ds_type_count;
13837
13838 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013839 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis209532e2016-09-07 13:52:18 -060013840 ASSERT_VK_SUCCESS(err);
13841
13842 VkSamplerCreateInfo sampler_ci = {};
13843 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
13844 sampler_ci.pNext = NULL;
13845 sampler_ci.magFilter = VK_FILTER_NEAREST;
13846 sampler_ci.minFilter = VK_FILTER_NEAREST;
13847 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
13848 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
13849 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
13850 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
13851 sampler_ci.mipLodBias = 1.0;
13852 sampler_ci.anisotropyEnable = VK_FALSE;
13853 sampler_ci.maxAnisotropy = 1;
13854 sampler_ci.compareEnable = VK_FALSE;
13855 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
13856 sampler_ci.minLod = 1.0;
13857 sampler_ci.maxLod = 1.0;
13858 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
13859 sampler_ci.unnormalizedCoordinates = VK_FALSE;
13860 VkSampler sampler;
13861
13862 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
13863 ASSERT_VK_SUCCESS(err);
13864
13865 VkDescriptorSetLayoutBinding layout_binding;
13866 layout_binding.binding = 0;
Tobin Ehlis94fc0ad2016-09-19 16:23:01 -060013867 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
Tobin Ehlis209532e2016-09-07 13:52:18 -060013868 layout_binding.descriptorCount = 1;
13869 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
13870 layout_binding.pImmutableSamplers = NULL;
13871
13872 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
13873 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
13874 ds_layout_ci.bindingCount = 1;
13875 ds_layout_ci.pBindings = &layout_binding;
13876 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013877 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060013878 ASSERT_VK_SUCCESS(err);
13879
13880 VkDescriptorSetAllocateInfo alloc_info = {};
13881 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
13882 alloc_info.descriptorSetCount = 1;
13883 alloc_info.descriptorPool = ds_pool;
13884 alloc_info.pSetLayouts = &ds_layout;
13885 VkDescriptorSet descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013886 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis209532e2016-09-07 13:52:18 -060013887 ASSERT_VK_SUCCESS(err);
13888
13889 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
13890 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13891 pipeline_layout_ci.pNext = NULL;
13892 pipeline_layout_ci.setLayoutCount = 1;
13893 pipeline_layout_ci.pSetLayouts = &ds_layout;
13894
13895 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013896 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060013897 ASSERT_VK_SUCCESS(err);
13898
13899 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060013900 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 -060013901 ASSERT_TRUE(image.initialized());
13902
13903 VkImageView view;
13904 VkImageViewCreateInfo ivci = {};
13905 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
13906 ivci.image = image.handle();
13907 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
13908 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
13909 ivci.subresourceRange.layerCount = 1;
13910 ivci.subresourceRange.baseMipLevel = 0;
13911 ivci.subresourceRange.levelCount = 1;
13912 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
13913
13914 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
13915 ASSERT_VK_SUCCESS(err);
13916
13917 VkDescriptorImageInfo image_info{};
13918 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
13919 image_info.imageView = view;
13920 image_info.sampler = sampler;
13921
13922 VkWriteDescriptorSet descriptor_write = {};
13923 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
13924 descriptor_write.dstSet = descriptor_set;
13925 descriptor_write.dstBinding = 0;
13926 descriptor_write.descriptorCount = 1;
13927 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
13928 descriptor_write.pImageInfo = &image_info;
13929
13930 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
13931
13932 // Create PSO to use the sampler
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013933 char const *vsSource =
13934 "#version 450\n"
13935 "\n"
13936 "out gl_PerVertex { \n"
13937 " vec4 gl_Position;\n"
13938 "};\n"
13939 "void main(){\n"
13940 " gl_Position = vec4(1);\n"
13941 "}\n";
13942 char const *fsSource =
13943 "#version 450\n"
13944 "\n"
13945 "layout(set=0, binding=0) uniform sampler2D s;\n"
13946 "layout(location=0) out vec4 x;\n"
13947 "void main(){\n"
13948 " x = texture(s, vec2(1));\n"
13949 "}\n";
Tobin Ehlis209532e2016-09-07 13:52:18 -060013950 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13951 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13952 VkPipelineObj pipe(m_device);
13953 pipe.AddShader(&vs);
13954 pipe.AddShader(&fs);
13955 pipe.AddColorAttachment();
13956 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13957
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070013958 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00837);
Tobin Ehlis209532e2016-09-07 13:52:18 -060013959
Tony Barbour552f6c02016-12-21 14:34:07 -070013960 m_commandBuffer->BeginCommandBuffer();
13961 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis209532e2016-09-07 13:52:18 -060013962 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013963 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
13964 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
13965 &descriptor_set, 0, nullptr);
Rene Lindsay4da11732017-01-13 14:42:10 -070013966
13967 VkViewport viewport = {0, 0, 16, 16, 0, 1};
13968 VkRect2D scissor = {{0, 0}, {16, 16}};
13969 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
13970 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
13971
Tobin Ehlis209532e2016-09-07 13:52:18 -060013972 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070013973 m_commandBuffer->EndRenderPass();
13974 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis209532e2016-09-07 13:52:18 -060013975 // Submit cmd buffer then destroy sampler
13976 VkSubmitInfo submit_info = {};
13977 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
13978 submit_info.commandBufferCount = 1;
13979 submit_info.pCommandBuffers = &m_commandBuffer->handle();
13980 // Submit cmd buffer and then destroy sampler while in-flight
13981 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
13982
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013983 vkDestroySampler(m_device->device(), sampler, nullptr); // Destroyed too soon
Tobin Ehlis209532e2016-09-07 13:52:18 -060013984 m_errorMonitor->VerifyFound();
13985 vkQueueWaitIdle(m_device->m_queue);
Rene Lindsay4da11732017-01-13 14:42:10 -070013986
Tobin Ehlis209532e2016-09-07 13:52:18 -060013987 // Now we can actually destroy sampler
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070013988 m_errorMonitor->SetUnexpectedError("If sampler is not VK_NULL_HANDLE, sampler must be a valid VkSampler handle");
13989 m_errorMonitor->SetUnexpectedError("Unable to remove Sampler obj");
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013990 vkDestroySampler(m_device->device(), sampler, NULL); // Destroyed for real
Tobin Ehlis209532e2016-09-07 13:52:18 -060013991 vkDestroyImageView(m_device->device(), view, NULL);
13992 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
13993 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
13994 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
13995}
13996
Mark Mueller1cd9f412016-08-25 13:23:52 -060013997TEST_F(VkLayerTest, QueueForwardProgressFenceWait) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013998 TEST_DESCRIPTION(
13999 "Call VkQueueSubmit with a semaphore that is already "
14000 "signaled but not waited on by the queue. Wait on a "
14001 "fence that has not yet been submitted to a queue.");
Mark Mueller96a56d52016-08-24 10:28:05 -060014002
Tony Barbour1fa09702017-03-16 12:09:08 -060014003 ASSERT_NO_FATAL_FAILURE(Init());
Mark Mueller96a56d52016-08-24 10:28:05 -060014004 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14005
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014006 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 -070014007 const char *invalid_fence_wait_message =
14008 " which has not been submitted on a Queue or during "
14009 "acquire next image.";
Mark Mueller96a56d52016-08-24 10:28:05 -060014010
Chris Forbese98aec12017-05-18 12:50:14 -070014011 VkCommandBufferObj cb1(m_device, m_commandPool);
14012 cb1.begin();
14013 cb1.end();
Mark Mueller96a56d52016-08-24 10:28:05 -060014014
14015 VkSemaphoreCreateInfo semaphore_create_info = {};
14016 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
14017 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014018 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller96a56d52016-08-24 10:28:05 -060014019 VkSubmitInfo submit_info = {};
14020 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
14021 submit_info.commandBufferCount = 1;
Chris Forbese98aec12017-05-18 12:50:14 -070014022 submit_info.pCommandBuffers = &cb1.handle();
Mark Mueller96a56d52016-08-24 10:28:05 -060014023 submit_info.signalSemaphoreCount = 1;
14024 submit_info.pSignalSemaphores = &semaphore;
14025 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Chris Forbese98aec12017-05-18 12:50:14 -070014026
Tony Barbour552f6c02016-12-21 14:34:07 -070014027 m_commandBuffer->BeginCommandBuffer();
14028 m_commandBuffer->EndCommandBuffer();
Chris Forbese98aec12017-05-18 12:50:14 -070014029 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014030 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, queue_forward_progress_message);
Mark Mueller96a56d52016-08-24 10:28:05 -060014031 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
14032 m_errorMonitor->VerifyFound();
14033
Mark Mueller1cd9f412016-08-25 13:23:52 -060014034 VkFenceCreateInfo fence_create_info = {};
14035 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
14036 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014037 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller1cd9f412016-08-25 13:23:52 -060014038
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014039 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, invalid_fence_wait_message);
Mark Mueller1cd9f412016-08-25 13:23:52 -060014040 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
14041 m_errorMonitor->VerifyFound();
14042
Mark Mueller4042b652016-09-05 22:52:21 -060014043 vkDeviceWaitIdle(m_device->device());
Mark Mueller1cd9f412016-08-25 13:23:52 -060014044 vkDestroyFence(m_device->device(), fence, nullptr);
Mark Mueller96a56d52016-08-24 10:28:05 -060014045 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
14046}
14047
Tobin Ehlis4af23302016-07-19 10:50:30 -060014048TEST_F(VkLayerTest, FramebufferIncompatible) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014049 TEST_DESCRIPTION(
14050 "Bind a secondary command buffer with with a framebuffer "
14051 "that does not match the framebuffer for the active "
14052 "renderpass.");
Tony Barbour1fa09702017-03-16 12:09:08 -060014053 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis4af23302016-07-19 10:50:30 -060014054 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14055
14056 // A renderpass with one color attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014057 VkAttachmentDescription attachment = {0,
14058 VK_FORMAT_B8G8R8A8_UNORM,
14059 VK_SAMPLE_COUNT_1_BIT,
14060 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
14061 VK_ATTACHMENT_STORE_OP_STORE,
14062 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
14063 VK_ATTACHMENT_STORE_OP_DONT_CARE,
14064 VK_IMAGE_LAYOUT_UNDEFINED,
14065 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060014066
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014067 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060014068
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014069 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060014070
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014071 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060014072
14073 VkRenderPass rp;
14074 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
14075 ASSERT_VK_SUCCESS(err);
14076
14077 // A compatible framebuffer.
14078 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060014079 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 -060014080 ASSERT_TRUE(image.initialized());
14081
14082 VkImageViewCreateInfo ivci = {
14083 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
14084 nullptr,
14085 0,
14086 image.handle(),
14087 VK_IMAGE_VIEW_TYPE_2D,
14088 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014089 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
14090 VK_COMPONENT_SWIZZLE_IDENTITY},
Tobin Ehlis4af23302016-07-19 10:50:30 -060014091 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
14092 };
14093 VkImageView view;
14094 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
14095 ASSERT_VK_SUCCESS(err);
14096
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014097 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Tobin Ehlis4af23302016-07-19 10:50:30 -060014098 VkFramebuffer fb;
14099 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
14100 ASSERT_VK_SUCCESS(err);
14101
14102 VkCommandBufferAllocateInfo cbai = {};
14103 cbai.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mike Schuchardt06304c22017-03-01 17:09:09 -070014104 cbai.commandPool = m_commandPool->handle();
Tobin Ehlis4af23302016-07-19 10:50:30 -060014105 cbai.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
14106 cbai.commandBufferCount = 1;
14107
14108 VkCommandBuffer sec_cb;
14109 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &sec_cb);
14110 ASSERT_VK_SUCCESS(err);
14111 VkCommandBufferBeginInfo cbbi = {};
14112 VkCommandBufferInheritanceInfo cbii = {};
Chris Forbes98420382016-11-28 17:56:51 +130014113 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Tobin Ehlis4af23302016-07-19 10:50:30 -060014114 cbii.renderPass = renderPass();
14115 cbii.framebuffer = fb;
14116 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
14117 cbbi.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014118 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 -060014119 cbbi.pInheritanceInfo = &cbii;
14120 vkBeginCommandBuffer(sec_cb, &cbbi);
14121 vkEndCommandBuffer(sec_cb);
14122
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014123 VkCommandBufferBeginInfo cbbi2 = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, 0, nullptr};
Chris Forbes3400bc52016-09-13 18:10:34 +120014124 vkBeginCommandBuffer(m_commandBuffer->GetBufferHandle(), &cbbi2);
14125 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Tobin Ehlis4af23302016-07-19 10:50:30 -060014126
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014127 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060014128 " that is not the same as the primary command buffer's current active framebuffer ");
Tobin Ehlis4af23302016-07-19 10:50:30 -060014129 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &sec_cb);
14130 m_errorMonitor->VerifyFound();
14131 // Cleanup
14132 vkDestroyImageView(m_device->device(), view, NULL);
14133 vkDestroyRenderPass(m_device->device(), rp, NULL);
14134 vkDestroyFramebuffer(m_device->device(), fb, NULL);
14135}
Tobin Ehlis52b504f2016-07-19 13:25:12 -060014136
14137TEST_F(VkLayerTest, ColorBlendLogicOpTests) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014138 TEST_DESCRIPTION(
14139 "If logicOp is available on the device, set it to an "
14140 "invalid value. If logicOp is not available, attempt to "
14141 "use it and verify that we see the correct error.");
Tony Barbour1fa09702017-03-16 12:09:08 -060014142 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis52b504f2016-07-19 13:25:12 -060014143 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14144
14145 auto features = m_device->phy().features();
14146 // Set the expected error depending on whether or not logicOp available
14147 if (VK_FALSE == features.logicOp) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014148 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14149 "If logic operations feature not "
14150 "enabled, logicOpEnable must be "
14151 "VK_FALSE");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060014152 } else {
Chris Forbes34797bc2016-10-03 15:28:49 +130014153 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "pColorBlendState->logicOp (16)");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060014154 }
14155 // Create a pipeline using logicOp
14156 VkResult err;
14157
14158 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
14159 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
14160
14161 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014162 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060014163 ASSERT_VK_SUCCESS(err);
14164
14165 VkPipelineViewportStateCreateInfo vp_state_ci = {};
14166 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
14167 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014168 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060014169 vp_state_ci.pViewports = &vp;
14170 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014171 VkRect2D scissors = {}; // Dummy scissors to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060014172 vp_state_ci.pScissors = &scissors;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060014173
14174 VkPipelineShaderStageCreateInfo shaderStages[2];
14175 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
14176
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014177 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
14178 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060014179 shaderStages[0] = vs.GetStageCreateInfo();
14180 shaderStages[1] = fs.GetStageCreateInfo();
14181
14182 VkPipelineVertexInputStateCreateInfo vi_ci = {};
14183 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
14184
14185 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
14186 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
14187 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
14188
14189 VkPipelineRasterizationStateCreateInfo rs_ci = {};
14190 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbes14088512016-10-03 14:28:00 +130014191 rs_ci.lineWidth = 1.0f;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060014192
14193 VkPipelineColorBlendAttachmentState att = {};
14194 att.blendEnable = VK_FALSE;
14195 att.colorWriteMask = 0xf;
14196
14197 VkPipelineColorBlendStateCreateInfo cb_ci = {};
14198 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
14199 // Enable logicOp & set logicOp to value 1 beyond allowed entries
14200 cb_ci.logicOpEnable = VK_TRUE;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014201 cb_ci.logicOp = VK_LOGIC_OP_RANGE_SIZE; // This should cause an error
Tobin Ehlis52b504f2016-07-19 13:25:12 -060014202 cb_ci.attachmentCount = 1;
14203 cb_ci.pAttachments = &att;
14204
Chris Forbes8aeacbf2016-10-03 14:25:08 +130014205 VkPipelineMultisampleStateCreateInfo ms_ci = {};
14206 ms_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
14207 ms_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
14208
Tobin Ehlis52b504f2016-07-19 13:25:12 -060014209 VkGraphicsPipelineCreateInfo gp_ci = {};
14210 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
14211 gp_ci.stageCount = 2;
14212 gp_ci.pStages = shaderStages;
14213 gp_ci.pVertexInputState = &vi_ci;
14214 gp_ci.pInputAssemblyState = &ia_ci;
14215 gp_ci.pViewportState = &vp_state_ci;
14216 gp_ci.pRasterizationState = &rs_ci;
14217 gp_ci.pColorBlendState = &cb_ci;
Chris Forbes8aeacbf2016-10-03 14:25:08 +130014218 gp_ci.pMultisampleState = &ms_ci;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060014219 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
14220 gp_ci.layout = pipeline_layout;
14221 gp_ci.renderPass = renderPass();
14222
14223 VkPipelineCacheCreateInfo pc_ci = {};
14224 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
14225
14226 VkPipeline pipeline;
14227 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014228 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060014229 ASSERT_VK_SUCCESS(err);
14230
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014231 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060014232 m_errorMonitor->VerifyFound();
14233 if (VK_SUCCESS == err) {
14234 vkDestroyPipeline(m_device->device(), pipeline, NULL);
14235 }
Tobin Ehlis52b504f2016-07-19 13:25:12 -060014236 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
14237 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
14238}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060014239
Mike Stroyanaccf7692015-05-12 16:00:45 -060014240#if GTEST_IS_THREADSAFE
14241struct thread_data_struct {
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014242 VkCommandBuffer commandBuffer;
Mike Stroyanca855662017-05-02 11:06:27 -060014243 VkDevice device;
Mike Stroyanaccf7692015-05-12 16:00:45 -060014244 VkEvent event;
14245 bool bailout;
14246};
14247
Karl Schultz6addd812016-02-02 17:17:23 -070014248extern "C" void *AddToCommandBuffer(void *arg) {
14249 struct thread_data_struct *data = (struct thread_data_struct *)arg;
Mike Stroyanaccf7692015-05-12 16:00:45 -060014250
Mike Stroyana6d14942016-07-13 15:10:05 -060014251 for (int i = 0; i < 80000; i++) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014252 vkCmdSetEvent(data->commandBuffer, data->event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mike Stroyanaccf7692015-05-12 16:00:45 -060014253 if (data->bailout) {
14254 break;
14255 }
14256 }
14257 return NULL;
14258}
14259
Karl Schultz6addd812016-02-02 17:17:23 -070014260TEST_F(VkLayerTest, ThreadCommandBufferCollision) {
Mike Stroyan4268d1f2015-07-13 14:45:35 -060014261 test_platform_thread thread;
Mike Stroyanaccf7692015-05-12 16:00:45 -060014262
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014263 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "THREADING ERROR");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014264
Tony Barbour1fa09702017-03-16 12:09:08 -060014265 ASSERT_NO_FATAL_FAILURE(Init());
Mike Stroyanaccf7692015-05-12 16:00:45 -060014266 ASSERT_NO_FATAL_FAILURE(InitViewport());
14267 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14268
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014269 // Calls AllocateCommandBuffers
14270 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060014271
14272 // Avoid creating RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014273 commandBuffer.BeginCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060014274
14275 VkEventCreateInfo event_info;
14276 VkEvent event;
Mike Stroyanaccf7692015-05-12 16:00:45 -060014277 VkResult err;
14278
14279 memset(&event_info, 0, sizeof(event_info));
14280 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
14281
Chia-I Wuf7458c52015-10-26 21:10:41 +080014282 err = vkCreateEvent(device(), &event_info, NULL, &event);
Mike Stroyanaccf7692015-05-12 16:00:45 -060014283 ASSERT_VK_SUCCESS(err);
14284
Mike Stroyanaccf7692015-05-12 16:00:45 -060014285 err = vkResetEvent(device(), event);
14286 ASSERT_VK_SUCCESS(err);
14287
14288 struct thread_data_struct data;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014289 data.commandBuffer = commandBuffer.GetBufferHandle();
Mike Stroyanaccf7692015-05-12 16:00:45 -060014290 data.event = event;
14291 data.bailout = false;
14292 m_errorMonitor->SetBailout(&data.bailout);
Mike Stroyana6d14942016-07-13 15:10:05 -060014293
14294 // First do some correct operations using multiple threads.
14295 // Add many entries to command buffer from another thread.
14296 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
14297 // Make non-conflicting calls from this thread at the same time.
14298 for (int i = 0; i < 80000; i++) {
Mike Stroyand6343902016-07-14 08:56:16 -060014299 uint32_t count;
14300 vkEnumeratePhysicalDevices(instance(), &count, NULL);
Mike Stroyana6d14942016-07-13 15:10:05 -060014301 }
14302 test_platform_thread_join(thread, NULL);
14303
14304 // Then do some incorrect operations using multiple threads.
Mike Stroyanaccf7692015-05-12 16:00:45 -060014305 // Add many entries to command buffer from another thread.
Mike Stroyan4268d1f2015-07-13 14:45:35 -060014306 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyanaccf7692015-05-12 16:00:45 -060014307 // Add many entries to command buffer from this thread at the same time.
14308 AddToCommandBuffer(&data);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060014309
Mike Stroyan4268d1f2015-07-13 14:45:35 -060014310 test_platform_thread_join(thread, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014311 commandBuffer.EndCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060014312
Mike Stroyan10b8cb72016-01-22 15:22:03 -070014313 m_errorMonitor->SetBailout(NULL);
14314
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014315 m_errorMonitor->VerifyFound();
Mike Stroyanaccf7692015-05-12 16:00:45 -060014316
Chia-I Wuf7458c52015-10-26 21:10:41 +080014317 vkDestroyEvent(device(), event, NULL);
Mike Stroyanaccf7692015-05-12 16:00:45 -060014318}
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014319#endif // GTEST_IS_THREADSAFE
Mark Lobodzinski209b5292015-09-17 09:44:05 -060014320
Karl Schultz6addd812016-02-02 17:17:23 -070014321TEST_F(VkLayerTest, InvalidSPIRVCodeSize) {
Mark Lobodzinskid742b312017-05-09 16:26:27 -060014322 TEST_DESCRIPTION("Test that errors are produced for a spirv modules with invalid code sizes");
Chris Forbes1cc79542016-07-20 11:13:44 +120014323
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014324 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014325
Tony Barbour1fa09702017-03-16 12:09:08 -060014326 ASSERT_NO_FATAL_FAILURE(Init());
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014327 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14328
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014329 VkShaderModule module;
14330 VkShaderModuleCreateInfo moduleCreateInfo;
14331 struct icd_spv_header spv;
14332
14333 spv.magic = ICD_SPV_MAGIC;
14334 spv.version = ICD_SPV_VERSION;
14335 spv.gen_magic = 0;
14336
14337 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
14338 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070014339 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014340 moduleCreateInfo.codeSize = 4;
14341 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080014342 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014343
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014344 m_errorMonitor->VerifyFound();
Mark Lobodzinskid742b312017-05-09 16:26:27 -060014345
14346 char const *vsSource =
14347 "#version 450\n"
14348 "\n"
14349 "layout(location=0) out float x;\n"
14350 "out gl_PerVertex {\n"
14351 " vec4 gl_Position;\n"
14352 "};\n"
14353 "void main(){\n"
14354 " gl_Position = vec4(1);\n"
14355 " x = 0;\n"
14356 "}\n";
14357
14358 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02816);
14359 std::vector<unsigned int> shader;
14360 VkShaderModuleCreateInfo module_create_info;
14361 VkShaderModule shader_module;
14362 module_create_info.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
14363 module_create_info.pNext = NULL;
14364 this->GLSLtoSPV(VK_SHADER_STAGE_VERTEX_BIT, vsSource, shader);
14365 module_create_info.pCode = shader.data();
14366 // Introduce failure by making codeSize a non-multiple of 4
14367 module_create_info.codeSize = shader.size() * sizeof(unsigned int) - 1;
14368 module_create_info.flags = 0;
14369 vkCreateShaderModule(m_device->handle(), &module_create_info, NULL, &shader_module);
14370
14371 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014372}
14373
Karl Schultz6addd812016-02-02 17:17:23 -070014374TEST_F(VkLayerTest, InvalidSPIRVMagic) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014375 TEST_DESCRIPTION(
14376 "Test that an error is produced for a spirv module "
14377 "with a bad magic number");
Chris Forbes1cc79542016-07-20 11:13:44 +120014378
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014379 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V magic number");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014380
Tony Barbour1fa09702017-03-16 12:09:08 -060014381 ASSERT_NO_FATAL_FAILURE(Init());
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014382 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14383
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014384 VkShaderModule module;
14385 VkShaderModuleCreateInfo moduleCreateInfo;
14386 struct icd_spv_header spv;
14387
14388 spv.magic = ~ICD_SPV_MAGIC;
14389 spv.version = ICD_SPV_VERSION;
14390 spv.gen_magic = 0;
14391
14392 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
14393 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070014394 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Mark Lobodzinskid742b312017-05-09 16:26:27 -060014395 moduleCreateInfo.codeSize = sizeof(spv) + 16;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014396 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080014397 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014398
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014399 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014400}
14401
Chris Forbesb4afd0f2016-04-04 10:48:35 +120014402#if 0
14403// Not currently covered by SPIRV-Tools validator
Karl Schultz6addd812016-02-02 17:17:23 -070014404TEST_F(VkLayerTest, InvalidSPIRVVersion) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070014405 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +120014406 "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014407
Tony Barbour1fa09702017-03-16 12:09:08 -060014408 ASSERT_NO_FATAL_FAILURE(Init());
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014409 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14410
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014411 VkShaderModule module;
14412 VkShaderModuleCreateInfo moduleCreateInfo;
14413 struct icd_spv_header spv;
14414
14415 spv.magic = ICD_SPV_MAGIC;
14416 spv.version = ~ICD_SPV_VERSION;
14417 spv.gen_magic = 0;
14418
14419 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
14420 moduleCreateInfo.pNext = NULL;
14421
Karl Schultz6addd812016-02-02 17:17:23 -070014422 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014423 moduleCreateInfo.codeSize = sizeof(spv) + 10;
14424 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080014425 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014426
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014427 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014428}
Chris Forbesb4afd0f2016-04-04 10:48:35 +120014429#endif
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014430
Karl Schultz6addd812016-02-02 17:17:23 -070014431TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014432 TEST_DESCRIPTION(
14433 "Test that a warning is produced for a vertex output that "
14434 "is not consumed by the fragment stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014435 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "not consumed by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014436
Tony Barbour1fa09702017-03-16 12:09:08 -060014437 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014438 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes9f7ff632015-05-25 11:13:08 +120014439
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014440 char const *vsSource =
14441 "#version 450\n"
14442 "\n"
14443 "layout(location=0) out float x;\n"
14444 "out gl_PerVertex {\n"
14445 " vec4 gl_Position;\n"
14446 "};\n"
14447 "void main(){\n"
14448 " gl_Position = vec4(1);\n"
14449 " x = 0;\n"
14450 "}\n";
14451 char const *fsSource =
14452 "#version 450\n"
14453 "\n"
14454 "layout(location=0) out vec4 color;\n"
14455 "void main(){\n"
14456 " color = vec4(1);\n"
14457 "}\n";
Chris Forbes9f7ff632015-05-25 11:13:08 +120014458
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014459 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14460 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes9f7ff632015-05-25 11:13:08 +120014461
14462 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014463 pipe.AddColorAttachment();
Chris Forbes9f7ff632015-05-25 11:13:08 +120014464 pipe.AddShader(&vs);
14465 pipe.AddShader(&fs);
14466
Chris Forbes9f7ff632015-05-25 11:13:08 +120014467 VkDescriptorSetObj descriptorSet(m_device);
14468 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014469 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes9f7ff632015-05-25 11:13:08 +120014470
Tony Barbour5781e8f2015-08-04 16:23:11 -060014471 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes9f7ff632015-05-25 11:13:08 +120014472
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014473 m_errorMonitor->VerifyFound();
Chris Forbes9f7ff632015-05-25 11:13:08 +120014474}
Chris Forbes9f7ff632015-05-25 11:13:08 +120014475
Mark Mueller098c9cb2016-09-08 09:01:57 -060014476TEST_F(VkLayerTest, CreatePipelineCheckShaderBadSpecialization) {
14477 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
14478
Tony Barbour1fa09702017-03-16 12:09:08 -060014479 ASSERT_NO_FATAL_FAILURE(Init());
Mark Mueller098c9cb2016-09-08 09:01:57 -060014480 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14481
14482 const char *bad_specialization_message =
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014483 "Specialization entry 0 (for constant id 0) references memory outside provided specialization data ";
Mark Mueller098c9cb2016-09-08 09:01:57 -060014484
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014485 char const *vsSource =
14486 "#version 450\n"
14487 "\n"
14488 "out gl_PerVertex {\n"
14489 " vec4 gl_Position;\n"
14490 "};\n"
14491 "void main(){\n"
14492 " gl_Position = vec4(1);\n"
14493 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060014494
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014495 char const *fsSource =
14496 "#version 450\n"
14497 "\n"
14498 "layout (constant_id = 0) const float r = 0.0f;\n"
14499 "layout(location = 0) out vec4 uFragColor;\n"
14500 "void main(){\n"
14501 " uFragColor = vec4(r,1,0,1);\n"
14502 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060014503
14504 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14505 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14506
14507 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
14508 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
14509
14510 VkPipelineLayout pipeline_layout;
14511 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
14512
14513 VkPipelineViewportStateCreateInfo vp_state_create_info = {};
14514 vp_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
14515 vp_state_create_info.viewportCount = 1;
14516 VkViewport viewport = {};
14517 vp_state_create_info.pViewports = &viewport;
14518 vp_state_create_info.scissorCount = 1;
14519 VkRect2D scissors = {};
14520 vp_state_create_info.pScissors = &scissors;
14521
14522 VkDynamicState scissor_state = VK_DYNAMIC_STATE_SCISSOR;
14523
14524 VkPipelineDynamicStateCreateInfo pipeline_dynamic_state_create_info = {};
14525 pipeline_dynamic_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
14526 pipeline_dynamic_state_create_info.dynamicStateCount = 1;
14527 pipeline_dynamic_state_create_info.pDynamicStates = &scissor_state;
14528
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014529 VkPipelineShaderStageCreateInfo shader_stage_create_info[2] = {vs.GetStageCreateInfo(), fs.GetStageCreateInfo()};
Mark Mueller098c9cb2016-09-08 09:01:57 -060014530
14531 VkPipelineVertexInputStateCreateInfo vertex_input_create_info = {};
14532 vertex_input_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
14533
14534 VkPipelineInputAssemblyStateCreateInfo input_assembly_create_info = {};
14535 input_assembly_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
14536 input_assembly_create_info.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
14537
14538 VkPipelineRasterizationStateCreateInfo rasterization_state_create_info = {};
14539 rasterization_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
14540 rasterization_state_create_info.pNext = nullptr;
14541 rasterization_state_create_info.lineWidth = 1.0f;
14542 rasterization_state_create_info.rasterizerDiscardEnable = true;
14543
14544 VkPipelineColorBlendAttachmentState color_blend_attachment_state = {};
14545 color_blend_attachment_state.blendEnable = VK_FALSE;
14546 color_blend_attachment_state.colorWriteMask = 0xf;
14547
14548 VkPipelineColorBlendStateCreateInfo color_blend_state_create_info = {};
14549 color_blend_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
14550 color_blend_state_create_info.attachmentCount = 1;
14551 color_blend_state_create_info.pAttachments = &color_blend_attachment_state;
14552
14553 VkGraphicsPipelineCreateInfo graphicspipe_create_info = {};
14554 graphicspipe_create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
14555 graphicspipe_create_info.stageCount = 2;
14556 graphicspipe_create_info.pStages = shader_stage_create_info;
14557 graphicspipe_create_info.pVertexInputState = &vertex_input_create_info;
14558 graphicspipe_create_info.pInputAssemblyState = &input_assembly_create_info;
14559 graphicspipe_create_info.pViewportState = &vp_state_create_info;
14560 graphicspipe_create_info.pRasterizationState = &rasterization_state_create_info;
14561 graphicspipe_create_info.pColorBlendState = &color_blend_state_create_info;
14562 graphicspipe_create_info.pDynamicState = &pipeline_dynamic_state_create_info;
14563 graphicspipe_create_info.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
14564 graphicspipe_create_info.layout = pipeline_layout;
14565 graphicspipe_create_info.renderPass = renderPass();
14566
14567 VkPipelineCacheCreateInfo pipeline_cache_create_info = {};
14568 pipeline_cache_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
14569
14570 VkPipelineCache pipelineCache;
14571 ASSERT_VK_SUCCESS(vkCreatePipelineCache(m_device->device(), &pipeline_cache_create_info, nullptr, &pipelineCache));
14572
14573 // This structure maps constant ids to data locations.
14574 const VkSpecializationMapEntry entry =
14575 // id, offset, size
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014576 {0, 4, sizeof(uint32_t)}; // Challenge core validation by using a bogus offset.
Mark Mueller098c9cb2016-09-08 09:01:57 -060014577
14578 uint32_t data = 1;
14579
14580 // Set up the info describing spec map and data
14581 const VkSpecializationInfo specialization_info = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014582 1, &entry, 1 * sizeof(float), &data,
Mark Mueller098c9cb2016-09-08 09:01:57 -060014583 };
14584 shader_stage_create_info[0].pSpecializationInfo = &specialization_info;
14585
14586 VkPipeline pipeline;
14587 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_specialization_message);
14588 vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &graphicspipe_create_info, nullptr, &pipeline);
14589 m_errorMonitor->VerifyFound();
14590
14591 vkDestroyPipelineCache(m_device->device(), pipelineCache, nullptr);
14592 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
14593}
14594
14595TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorTypeMismatch) {
14596 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
14597
Tony Barbour1fa09702017-03-16 12:09:08 -060014598 ASSERT_NO_FATAL_FAILURE(Init());
Mark Mueller098c9cb2016-09-08 09:01:57 -060014599 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14600
14601 const char *descriptor_type_mismatch_message = "Type mismatch on descriptor slot 0.0 (used as type ";
14602
14603 VkDescriptorPoolSize descriptor_pool_type_count[2] = {};
14604 descriptor_pool_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
14605 descriptor_pool_type_count[0].descriptorCount = 1;
14606 descriptor_pool_type_count[1].type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
14607 descriptor_pool_type_count[1].descriptorCount = 1;
14608
14609 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
14610 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
14611 descriptor_pool_create_info.maxSets = 1;
14612 descriptor_pool_create_info.poolSizeCount = 2;
14613 descriptor_pool_create_info.pPoolSizes = descriptor_pool_type_count;
14614 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
14615
14616 VkDescriptorPool descriptorset_pool;
14617 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
14618
14619 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
14620 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
14621 descriptorset_layout_binding.descriptorCount = 1;
14622 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
Cody Northropa6484fd2017-03-10 14:13:49 -070014623 descriptorset_layout_binding.pImmutableSamplers = nullptr;
Mark Mueller098c9cb2016-09-08 09:01:57 -060014624
14625 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
14626 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
14627 descriptorset_layout_create_info.bindingCount = 1;
14628 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
14629
14630 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014631 ASSERT_VK_SUCCESS(
14632 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller098c9cb2016-09-08 09:01:57 -060014633
14634 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
14635 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
14636 descriptorset_allocate_info.descriptorSetCount = 1;
14637 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
14638 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
14639 VkDescriptorSet descriptorset;
14640 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
14641
14642 // Challenge core_validation with a non uniform buffer type.
14643 VkBufferTest storage_buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT);
14644
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014645 char const *vsSource =
14646 "#version 450\n"
14647 "\n"
14648 "layout (std140, set = 0, binding = 0) uniform buf {\n"
14649 " mat4 mvp;\n"
14650 "} ubuf;\n"
14651 "out gl_PerVertex {\n"
14652 " vec4 gl_Position;\n"
14653 "};\n"
14654 "void main(){\n"
14655 " gl_Position = ubuf.mvp * vec4(1);\n"
14656 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060014657
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014658 char const *fsSource =
14659 "#version 450\n"
14660 "\n"
14661 "layout(location = 0) out vec4 uFragColor;\n"
14662 "void main(){\n"
14663 " uFragColor = vec4(0,1,0,1);\n"
14664 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060014665
14666 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14667 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14668
14669 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
14670 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
14671 pipeline_layout_create_info.setLayoutCount = 1;
14672 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
14673
14674 VkPipelineLayout pipeline_layout;
14675 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
14676
14677 VkPipelineObj pipe(m_device);
14678 pipe.AddColorAttachment();
14679 pipe.AddShader(&vs);
14680 pipe.AddShader(&fs);
14681
14682 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_type_mismatch_message);
14683 pipe.CreateVKPipeline(pipeline_layout, renderPass());
14684 m_errorMonitor->VerifyFound();
14685
14686 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
14687 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
14688 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
14689}
14690
14691TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorNotAccessible) {
14692 TEST_DESCRIPTION(
14693 "Create a pipeline in which a descriptor used by a shader stage does not include that stage in its stageFlags.");
14694
Tony Barbour1fa09702017-03-16 12:09:08 -060014695 ASSERT_NO_FATAL_FAILURE(Init());
Mark Mueller098c9cb2016-09-08 09:01:57 -060014696 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14697
14698 const char *descriptor_not_accessible_message = "Shader uses descriptor slot 0.0 (used as type ";
14699
14700 VkDescriptorPoolSize descriptor_pool_type_count = {};
14701 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
14702 descriptor_pool_type_count.descriptorCount = 1;
14703
14704 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
14705 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
14706 descriptor_pool_create_info.maxSets = 1;
14707 descriptor_pool_create_info.poolSizeCount = 1;
14708 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
14709 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
14710
14711 VkDescriptorPool descriptorset_pool;
14712 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
14713
14714 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
14715 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
14716 descriptorset_layout_binding.descriptorCount = 1;
14717 // Intentionally make the uniform buffer inaccessible to the vertex shader to challenge core_validation
14718 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
Cody Northropa6484fd2017-03-10 14:13:49 -070014719 descriptorset_layout_binding.pImmutableSamplers = nullptr;
Mark Mueller098c9cb2016-09-08 09:01:57 -060014720
14721 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
14722 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
14723 descriptorset_layout_create_info.bindingCount = 1;
14724 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
14725
14726 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014727 ASSERT_VK_SUCCESS(
14728 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller098c9cb2016-09-08 09:01:57 -060014729
14730 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
14731 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
14732 descriptorset_allocate_info.descriptorSetCount = 1;
14733 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
14734 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
14735 VkDescriptorSet descriptorset;
14736 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
14737
14738 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
14739
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014740 char const *vsSource =
14741 "#version 450\n"
14742 "\n"
14743 "layout (std140, set = 0, binding = 0) uniform buf {\n"
14744 " mat4 mvp;\n"
14745 "} ubuf;\n"
14746 "out gl_PerVertex {\n"
14747 " vec4 gl_Position;\n"
14748 "};\n"
14749 "void main(){\n"
14750 " gl_Position = ubuf.mvp * vec4(1);\n"
14751 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060014752
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014753 char const *fsSource =
14754 "#version 450\n"
14755 "\n"
14756 "layout(location = 0) out vec4 uFragColor;\n"
14757 "void main(){\n"
14758 " uFragColor = vec4(0,1,0,1);\n"
14759 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060014760
14761 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14762 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14763
14764 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
14765 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
14766 pipeline_layout_create_info.setLayoutCount = 1;
14767 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
14768
14769 VkPipelineLayout pipeline_layout;
14770 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
14771
14772 VkPipelineObj pipe(m_device);
14773 pipe.AddColorAttachment();
14774 pipe.AddShader(&vs);
14775 pipe.AddShader(&fs);
14776
14777 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_not_accessible_message);
14778 pipe.CreateVKPipeline(pipeline_layout, renderPass());
14779 m_errorMonitor->VerifyFound();
14780
14781 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
14782 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
14783 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
14784}
14785
14786TEST_F(VkLayerTest, CreatePipelineCheckShaderPushConstantNotAccessible) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014787 TEST_DESCRIPTION(
14788 "Create a graphics pipleine in which a push constant range containing a push constant block member is not "
14789 "accessible from the current shader stage.");
Mark Mueller098c9cb2016-09-08 09:01:57 -060014790
Tony Barbour1fa09702017-03-16 12:09:08 -060014791 ASSERT_NO_FATAL_FAILURE(Init());
Mark Mueller098c9cb2016-09-08 09:01:57 -060014792 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14793
14794 const char *push_constant_not_accessible_message =
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014795 "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 -060014796
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014797 char const *vsSource =
14798 "#version 450\n"
14799 "\n"
14800 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
14801 "out gl_PerVertex {\n"
14802 " vec4 gl_Position;\n"
14803 "};\n"
14804 "void main(){\n"
14805 " gl_Position = vec4(consts.x);\n"
14806 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060014807
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014808 char const *fsSource =
14809 "#version 450\n"
14810 "\n"
14811 "layout(location = 0) out vec4 uFragColor;\n"
14812 "void main(){\n"
14813 " uFragColor = vec4(0,1,0,1);\n"
14814 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060014815
14816 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14817 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14818
14819 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
14820 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
14821
14822 // Set up a push constant range
14823 VkPushConstantRange push_constant_ranges = {};
14824 // Set to the wrong stage to challenge core_validation
14825 push_constant_ranges.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
14826 push_constant_ranges.size = 4;
14827
14828 pipeline_layout_create_info.pPushConstantRanges = &push_constant_ranges;
14829 pipeline_layout_create_info.pushConstantRangeCount = 1;
14830
14831 VkPipelineLayout pipeline_layout;
14832 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
14833
14834 VkPipelineObj pipe(m_device);
14835 pipe.AddColorAttachment();
14836 pipe.AddShader(&vs);
14837 pipe.AddShader(&fs);
14838
14839 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, push_constant_not_accessible_message);
14840 pipe.CreateVKPipeline(pipeline_layout, renderPass());
14841 m_errorMonitor->VerifyFound();
14842
14843 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
14844}
14845
14846TEST_F(VkLayerTest, CreatePipelineCheckShaderNotEnabled) {
14847 TEST_DESCRIPTION(
14848 "Create a graphics pipeline in which a capability declared by the shader requires a feature not enabled on the device.");
14849
Tony Barbour1fa09702017-03-16 12:09:08 -060014850 ASSERT_NO_FATAL_FAILURE(Init());
Mark Mueller098c9cb2016-09-08 09:01:57 -060014851 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14852
14853 const char *feature_not_enabled_message =
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014854 "Shader requires VkPhysicalDeviceFeatures::shaderFloat64 but is not enabled on the device";
Mark Mueller098c9cb2016-09-08 09:01:57 -060014855
14856 // Some awkward steps are required to test with custom device features.
14857 std::vector<const char *> device_extension_names;
14858 auto features = m_device->phy().features();
14859 // Disable support for 64 bit floats
14860 features.shaderFloat64 = false;
14861 // The sacrificial device object
14862 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
14863
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014864 char const *vsSource =
14865 "#version 450\n"
14866 "\n"
14867 "out gl_PerVertex {\n"
14868 " vec4 gl_Position;\n"
14869 "};\n"
14870 "void main(){\n"
14871 " gl_Position = vec4(1);\n"
14872 "}\n";
14873 char const *fsSource =
14874 "#version 450\n"
14875 "\n"
14876 "layout(location=0) out vec4 color;\n"
14877 "void main(){\n"
14878 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
14879 " color = vec4(green);\n"
14880 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060014881
14882 VkShaderObj vs(&test_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14883 VkShaderObj fs(&test_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14884
14885 VkRenderpassObj render_pass(&test_device);
Mark Mueller098c9cb2016-09-08 09:01:57 -060014886
14887 VkPipelineObj pipe(&test_device);
14888 pipe.AddColorAttachment();
14889 pipe.AddShader(&vs);
14890 pipe.AddShader(&fs);
14891
14892 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
14893 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
14894 VkPipelineLayout pipeline_layout;
14895 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(test_device.device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
14896
14897 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, feature_not_enabled_message);
14898 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
14899 m_errorMonitor->VerifyFound();
14900
14901 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, nullptr);
14902}
14903
Mark Lobodzinski20832822017-03-24 14:49:45 -060014904TEST_F(VkLayerTest, CreateShaderModuleCheckBadCapability) {
14905 TEST_DESCRIPTION("Create a shader in which a capability declared by the shader is not supported.");
14906 // Note that this failure message comes from spirv-tools, specifically the validator.
Mark Mueller098c9cb2016-09-08 09:01:57 -060014907
Tony Barbour1fa09702017-03-16 12:09:08 -060014908 ASSERT_NO_FATAL_FAILURE(Init());
Mark Mueller098c9cb2016-09-08 09:01:57 -060014909 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14910
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014911 char const *vsSource =
14912 "#version 450\n"
14913 "\n"
14914 "out gl_PerVertex {\n"
14915 " vec4 gl_Position;\n"
14916 "};\n"
14917 "layout(xfb_buffer = 1) out;"
14918 "void main(){\n"
14919 " gl_Position = vec4(1);\n"
14920 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060014921
Mark Lobodzinski20832822017-03-24 14:49:45 -060014922 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Capability value 53 is not allowed by Vulkan");
Mark Mueller098c9cb2016-09-08 09:01:57 -060014923
Mark Lobodzinski20832822017-03-24 14:49:45 -060014924 std::vector<unsigned int> spv;
14925 VkShaderModuleCreateInfo module_create_info;
14926 VkShaderModule shader_module;
14927 module_create_info.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
14928 module_create_info.pNext = NULL;
14929 this->GLSLtoSPV(VK_SHADER_STAGE_VERTEX_BIT, vsSource, spv);
14930 module_create_info.pCode = spv.data();
14931 module_create_info.codeSize = spv.size() * sizeof(unsigned int);
14932 module_create_info.flags = 0;
Mark Mueller098c9cb2016-09-08 09:01:57 -060014933
Mark Lobodzinski20832822017-03-24 14:49:45 -060014934 vkCreateShaderModule(m_device->handle(), &module_create_info, NULL, &shader_module);
Mark Mueller098c9cb2016-09-08 09:01:57 -060014935
Mark Lobodzinski20832822017-03-24 14:49:45 -060014936 m_errorMonitor->VerifyFound();
Mark Mueller098c9cb2016-09-08 09:01:57 -060014937}
14938
Karl Schultz6addd812016-02-02 17:17:23 -070014939TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014940 TEST_DESCRIPTION(
14941 "Test that an error is produced for a fragment shader input "
14942 "which is not present in the outputs of the previous stage");
Chris Forbes1cc79542016-07-20 11:13:44 +120014943
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014944 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014945
Tony Barbour1fa09702017-03-16 12:09:08 -060014946 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014947 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes59cb88d2015-05-25 11:13:13 +120014948
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014949 char const *vsSource =
14950 "#version 450\n"
14951 "\n"
14952 "out gl_PerVertex {\n"
14953 " vec4 gl_Position;\n"
14954 "};\n"
14955 "void main(){\n"
14956 " gl_Position = vec4(1);\n"
14957 "}\n";
14958 char const *fsSource =
14959 "#version 450\n"
14960 "\n"
14961 "layout(location=0) in float x;\n"
14962 "layout(location=0) out vec4 color;\n"
14963 "void main(){\n"
14964 " color = vec4(x);\n"
14965 "}\n";
Chris Forbes59cb88d2015-05-25 11:13:13 +120014966
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014967 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14968 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes59cb88d2015-05-25 11:13:13 +120014969
14970 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014971 pipe.AddColorAttachment();
Chris Forbes59cb88d2015-05-25 11:13:13 +120014972 pipe.AddShader(&vs);
14973 pipe.AddShader(&fs);
14974
Chris Forbes59cb88d2015-05-25 11:13:13 +120014975 VkDescriptorSetObj descriptorSet(m_device);
14976 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014977 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes59cb88d2015-05-25 11:13:13 +120014978
Tony Barbour5781e8f2015-08-04 16:23:11 -060014979 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes59cb88d2015-05-25 11:13:13 +120014980
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014981 m_errorMonitor->VerifyFound();
Chris Forbes59cb88d2015-05-25 11:13:13 +120014982}
14983
Karl Schultz6addd812016-02-02 17:17:23 -070014984TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvidedInBlock) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014985 TEST_DESCRIPTION(
14986 "Test that an error is produced for a fragment shader input "
14987 "within an interace block, which is not present in the outputs "
14988 "of the previous stage.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014989 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Chris Forbesa3e85f62016-01-15 14:53:11 +130014990
Tony Barbour1fa09702017-03-16 12:09:08 -060014991 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbesa3e85f62016-01-15 14:53:11 +130014992 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14993
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014994 char const *vsSource =
14995 "#version 450\n"
14996 "\n"
14997 "out gl_PerVertex {\n"
14998 " vec4 gl_Position;\n"
14999 "};\n"
15000 "void main(){\n"
15001 " gl_Position = vec4(1);\n"
15002 "}\n";
15003 char const *fsSource =
15004 "#version 450\n"
15005 "\n"
15006 "in block { layout(location=0) float x; } ins;\n"
15007 "layout(location=0) out vec4 color;\n"
15008 "void main(){\n"
15009 " color = vec4(ins.x);\n"
15010 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130015011
15012 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15013 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15014
15015 VkPipelineObj pipe(m_device);
15016 pipe.AddColorAttachment();
15017 pipe.AddShader(&vs);
15018 pipe.AddShader(&fs);
15019
15020 VkDescriptorSetObj descriptorSet(m_device);
15021 descriptorSet.AppendDummy();
15022 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15023
15024 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15025
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015026 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130015027}
15028
Karl Schultz6addd812016-02-02 17:17:23 -070015029TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchArraySize) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015030 TEST_DESCRIPTION(
15031 "Test that an error is produced for mismatched array sizes "
15032 "across the vertex->fragment shader interface");
15033 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15034 "Type mismatch on location 0.0: 'ptr to "
15035 "output arr[2] of float32' vs 'ptr to "
15036 "input arr[1] of float32'");
Chris Forbes0036fd12016-01-26 14:19:49 +130015037
Tony Barbour1fa09702017-03-16 12:09:08 -060015038 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes0036fd12016-01-26 14:19:49 +130015039 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15040
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015041 char const *vsSource =
15042 "#version 450\n"
15043 "\n"
15044 "layout(location=0) out float x[2];\n"
15045 "out gl_PerVertex {\n"
15046 " vec4 gl_Position;\n"
15047 "};\n"
15048 "void main(){\n"
15049 " x[0] = 0; x[1] = 0;\n"
15050 " gl_Position = vec4(1);\n"
15051 "}\n";
15052 char const *fsSource =
15053 "#version 450\n"
15054 "\n"
15055 "layout(location=0) in float x[1];\n"
15056 "layout(location=0) out vec4 color;\n"
15057 "void main(){\n"
15058 " color = vec4(x[0]);\n"
15059 "}\n";
Chris Forbes0036fd12016-01-26 14:19:49 +130015060
15061 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15062 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15063
15064 VkPipelineObj pipe(m_device);
15065 pipe.AddColorAttachment();
15066 pipe.AddShader(&vs);
15067 pipe.AddShader(&fs);
15068
15069 VkDescriptorSetObj descriptorSet(m_device);
15070 descriptorSet.AppendDummy();
15071 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15072
15073 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15074
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015075 m_errorMonitor->VerifyFound();
Chris Forbes0036fd12016-01-26 14:19:49 +130015076}
15077
Karl Schultz6addd812016-02-02 17:17:23 -070015078TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015079 TEST_DESCRIPTION(
15080 "Test that an error is produced for mismatched types across "
15081 "the vertex->fragment shader interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015082 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015083
Tony Barbour1fa09702017-03-16 12:09:08 -060015084 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060015085 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesb56af562015-05-25 11:13:17 +120015086
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015087 char const *vsSource =
15088 "#version 450\n"
15089 "\n"
15090 "layout(location=0) out int x;\n"
15091 "out gl_PerVertex {\n"
15092 " vec4 gl_Position;\n"
15093 "};\n"
15094 "void main(){\n"
15095 " x = 0;\n"
15096 " gl_Position = vec4(1);\n"
15097 "}\n";
15098 char const *fsSource =
15099 "#version 450\n"
15100 "\n"
15101 "layout(location=0) in float x;\n" /* VS writes int */
15102 "layout(location=0) out vec4 color;\n"
15103 "void main(){\n"
15104 " color = vec4(x);\n"
15105 "}\n";
Chris Forbesb56af562015-05-25 11:13:17 +120015106
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060015107 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15108 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesb56af562015-05-25 11:13:17 +120015109
15110 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080015111 pipe.AddColorAttachment();
Chris Forbesb56af562015-05-25 11:13:17 +120015112 pipe.AddShader(&vs);
15113 pipe.AddShader(&fs);
15114
Chris Forbesb56af562015-05-25 11:13:17 +120015115 VkDescriptorSetObj descriptorSet(m_device);
15116 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015117 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesb56af562015-05-25 11:13:17 +120015118
Tony Barbour5781e8f2015-08-04 16:23:11 -060015119 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesb56af562015-05-25 11:13:17 +120015120
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015121 m_errorMonitor->VerifyFound();
Chris Forbesb56af562015-05-25 11:13:17 +120015122}
15123
Karl Schultz6addd812016-02-02 17:17:23 -070015124TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchInBlock) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015125 TEST_DESCRIPTION(
15126 "Test that an error is produced for mismatched types across "
15127 "the vertex->fragment shader interface, when the variable is contained within "
15128 "an interface block");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015129 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Chris Forbesa3e85f62016-01-15 14:53:11 +130015130
Tony Barbour1fa09702017-03-16 12:09:08 -060015131 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbesa3e85f62016-01-15 14:53:11 +130015132 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15133
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015134 char const *vsSource =
15135 "#version 450\n"
15136 "\n"
15137 "out block { layout(location=0) int x; } outs;\n"
15138 "out gl_PerVertex {\n"
15139 " vec4 gl_Position;\n"
15140 "};\n"
15141 "void main(){\n"
15142 " outs.x = 0;\n"
15143 " gl_Position = vec4(1);\n"
15144 "}\n";
15145 char const *fsSource =
15146 "#version 450\n"
15147 "\n"
15148 "in block { layout(location=0) float x; } ins;\n" /* VS writes int */
15149 "layout(location=0) out vec4 color;\n"
15150 "void main(){\n"
15151 " color = vec4(ins.x);\n"
15152 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130015153
15154 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15155 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15156
15157 VkPipelineObj pipe(m_device);
15158 pipe.AddColorAttachment();
15159 pipe.AddShader(&vs);
15160 pipe.AddShader(&fs);
15161
15162 VkDescriptorSetObj descriptorSet(m_device);
15163 descriptorSet.AppendDummy();
15164 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15165
15166 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15167
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015168 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130015169}
15170
15171TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByLocation) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015172 TEST_DESCRIPTION(
15173 "Test that an error is produced for location mismatches across "
15174 "the vertex->fragment shader interface; This should manifest as a not-written/not-consumed "
15175 "pair, but flushes out broken walking of the interfaces");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015176 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 +130015177
Tony Barbour1fa09702017-03-16 12:09:08 -060015178 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbese9928822016-02-17 14:44:52 +130015179 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15180
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015181 char const *vsSource =
15182 "#version 450\n"
15183 "\n"
15184 "out block { layout(location=1) float x; } outs;\n"
15185 "out gl_PerVertex {\n"
15186 " vec4 gl_Position;\n"
15187 "};\n"
15188 "void main(){\n"
15189 " outs.x = 0;\n"
15190 " gl_Position = vec4(1);\n"
15191 "}\n";
15192 char const *fsSource =
15193 "#version 450\n"
15194 "\n"
15195 "in block { layout(location=0) float x; } ins;\n"
15196 "layout(location=0) out vec4 color;\n"
15197 "void main(){\n"
15198 " color = vec4(ins.x);\n"
15199 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130015200
15201 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15202 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15203
15204 VkPipelineObj pipe(m_device);
15205 pipe.AddColorAttachment();
15206 pipe.AddShader(&vs);
15207 pipe.AddShader(&fs);
15208
15209 VkDescriptorSetObj descriptorSet(m_device);
15210 descriptorSet.AppendDummy();
15211 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15212
15213 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15214
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015215 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130015216}
15217
15218TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByComponent) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015219 TEST_DESCRIPTION(
15220 "Test that an error is produced for component mismatches across the "
15221 "vertex->fragment shader interface. It's not enough to have the same set of locations in "
15222 "use; matching is defined in terms of spirv variables.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015223 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 +130015224
Tony Barbour1fa09702017-03-16 12:09:08 -060015225 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbese9928822016-02-17 14:44:52 +130015226 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15227
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015228 char const *vsSource =
15229 "#version 450\n"
15230 "\n"
15231 "out block { layout(location=0, component=0) float x; } outs;\n"
15232 "out gl_PerVertex {\n"
15233 " vec4 gl_Position;\n"
15234 "};\n"
15235 "void main(){\n"
15236 " outs.x = 0;\n"
15237 " gl_Position = vec4(1);\n"
15238 "}\n";
15239 char const *fsSource =
15240 "#version 450\n"
15241 "\n"
15242 "in block { layout(location=0, component=1) float x; } ins;\n"
15243 "layout(location=0) out vec4 color;\n"
15244 "void main(){\n"
15245 " color = vec4(ins.x);\n"
15246 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130015247
15248 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15249 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15250
15251 VkPipelineObj pipe(m_device);
15252 pipe.AddColorAttachment();
15253 pipe.AddShader(&vs);
15254 pipe.AddShader(&fs);
15255
15256 VkDescriptorSetObj descriptorSet(m_device);
15257 descriptorSet.AppendDummy();
15258 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15259
15260 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15261
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015262 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130015263}
15264
Chris Forbes1f3b0152016-11-30 12:48:40 +130015265TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByPrecision) {
15266 TEST_DESCRIPTION("Test that the RelaxedPrecision decoration is validated to match");
15267
Tony Barbour1fa09702017-03-16 12:09:08 -060015268 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes1f3b0152016-11-30 12:48:40 +130015269 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15270
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015271 char const *vsSource =
15272 "#version 450\n"
15273 "layout(location=0) out mediump float x;\n"
15274 "void main() { gl_Position = vec4(0); x = 1.0; }\n";
15275 char const *fsSource =
15276 "#version 450\n"
15277 "layout(location=0) in highp float x;\n"
15278 "layout(location=0) out vec4 color;\n"
15279 "void main() { color = vec4(x); }\n";
Chris Forbes1f3b0152016-11-30 12:48:40 +130015280
15281 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15282 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15283
15284 VkPipelineObj pipe(m_device);
15285 pipe.AddColorAttachment();
15286 pipe.AddShader(&vs);
15287 pipe.AddShader(&fs);
15288
15289 VkDescriptorSetObj descriptorSet(m_device);
15290 descriptorSet.AppendDummy();
15291 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15292
15293 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "differ in precision");
15294
15295 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15296
15297 m_errorMonitor->VerifyFound();
15298}
15299
Chris Forbes870a39e2016-11-30 12:55:56 +130015300TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByPrecisionBlock) {
15301 TEST_DESCRIPTION("Test that the RelaxedPrecision decoration is validated to match");
15302
Tony Barbour1fa09702017-03-16 12:09:08 -060015303 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes870a39e2016-11-30 12:55:56 +130015304 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15305
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015306 char const *vsSource =
15307 "#version 450\n"
15308 "out block { layout(location=0) mediump float x; };\n"
15309 "void main() { gl_Position = vec4(0); x = 1.0; }\n";
15310 char const *fsSource =
15311 "#version 450\n"
15312 "in block { layout(location=0) highp float x; };\n"
15313 "layout(location=0) out vec4 color;\n"
15314 "void main() { color = vec4(x); }\n";
Chris Forbes870a39e2016-11-30 12:55:56 +130015315
15316 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15317 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15318
15319 VkPipelineObj pipe(m_device);
15320 pipe.AddColorAttachment();
15321 pipe.AddShader(&vs);
15322 pipe.AddShader(&fs);
15323
15324 VkDescriptorSetObj descriptorSet(m_device);
15325 descriptorSet.AppendDummy();
15326 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15327
15328 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "differ in precision");
15329
15330 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15331
15332 m_errorMonitor->VerifyFound();
15333}
15334
Karl Schultz6addd812016-02-02 17:17:23 -070015335TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015336 TEST_DESCRIPTION(
15337 "Test that a warning is produced for a vertex attribute which is "
15338 "not consumed by the vertex shader");
Mike Weiblencce7ec72016-10-17 19:33:05 -060015339 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015340
Tony Barbour1fa09702017-03-16 12:09:08 -060015341 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060015342 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesde136e02015-05-25 11:13:28 +120015343
15344 VkVertexInputBindingDescription input_binding;
15345 memset(&input_binding, 0, sizeof(input_binding));
15346
15347 VkVertexInputAttributeDescription input_attrib;
15348 memset(&input_attrib, 0, sizeof(input_attrib));
15349 input_attrib.format = VK_FORMAT_R32_SFLOAT;
15350
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015351 char const *vsSource =
15352 "#version 450\n"
15353 "\n"
15354 "out gl_PerVertex {\n"
15355 " vec4 gl_Position;\n"
15356 "};\n"
15357 "void main(){\n"
15358 " gl_Position = vec4(1);\n"
15359 "}\n";
15360 char const *fsSource =
15361 "#version 450\n"
15362 "\n"
15363 "layout(location=0) out vec4 color;\n"
15364 "void main(){\n"
15365 " color = vec4(1);\n"
15366 "}\n";
Chris Forbesde136e02015-05-25 11:13:28 +120015367
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060015368 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15369 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesde136e02015-05-25 11:13:28 +120015370
15371 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080015372 pipe.AddColorAttachment();
Chris Forbesde136e02015-05-25 11:13:28 +120015373 pipe.AddShader(&vs);
15374 pipe.AddShader(&fs);
15375
15376 pipe.AddVertexInputBindings(&input_binding, 1);
15377 pipe.AddVertexInputAttribs(&input_attrib, 1);
15378
Chris Forbesde136e02015-05-25 11:13:28 +120015379 VkDescriptorSetObj descriptorSet(m_device);
15380 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015381 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesde136e02015-05-25 11:13:28 +120015382
Tony Barbour5781e8f2015-08-04 16:23:11 -060015383 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesde136e02015-05-25 11:13:28 +120015384
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015385 m_errorMonitor->VerifyFound();
Chris Forbesde136e02015-05-25 11:13:28 +120015386}
15387
Karl Schultz6addd812016-02-02 17:17:23 -070015388TEST_F(VkLayerTest, CreatePipelineAttribLocationMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015389 TEST_DESCRIPTION(
15390 "Test that a warning is produced for a location mismatch on "
15391 "vertex attributes. This flushes out bad behavior in the interface walker");
Mike Weiblencce7ec72016-10-17 19:33:05 -060015392 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Chris Forbes7d83cd52016-01-15 11:32:03 +130015393
Tony Barbour1fa09702017-03-16 12:09:08 -060015394 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes7d83cd52016-01-15 11:32:03 +130015395 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15396
15397 VkVertexInputBindingDescription input_binding;
15398 memset(&input_binding, 0, sizeof(input_binding));
15399
15400 VkVertexInputAttributeDescription input_attrib;
15401 memset(&input_attrib, 0, sizeof(input_attrib));
15402 input_attrib.format = VK_FORMAT_R32_SFLOAT;
15403
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015404 char const *vsSource =
15405 "#version 450\n"
15406 "\n"
15407 "layout(location=1) in float x;\n"
15408 "out gl_PerVertex {\n"
15409 " vec4 gl_Position;\n"
15410 "};\n"
15411 "void main(){\n"
15412 " gl_Position = vec4(x);\n"
15413 "}\n";
15414 char const *fsSource =
15415 "#version 450\n"
15416 "\n"
15417 "layout(location=0) out vec4 color;\n"
15418 "void main(){\n"
15419 " color = vec4(1);\n"
15420 "}\n";
Chris Forbes7d83cd52016-01-15 11:32:03 +130015421
15422 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15423 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15424
15425 VkPipelineObj pipe(m_device);
15426 pipe.AddColorAttachment();
15427 pipe.AddShader(&vs);
15428 pipe.AddShader(&fs);
15429
15430 pipe.AddVertexInputBindings(&input_binding, 1);
15431 pipe.AddVertexInputAttribs(&input_attrib, 1);
15432
15433 VkDescriptorSetObj descriptorSet(m_device);
15434 descriptorSet.AppendDummy();
15435 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15436
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070015437 m_errorMonitor->SetUnexpectedError("Vertex shader consumes input at location 1 but not provided");
Chris Forbes7d83cd52016-01-15 11:32:03 +130015438 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15439
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015440 m_errorMonitor->VerifyFound();
Chris Forbes7d83cd52016-01-15 11:32:03 +130015441}
15442
Karl Schultz6addd812016-02-02 17:17:23 -070015443TEST_F(VkLayerTest, CreatePipelineAttribNotProvided) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015444 TEST_DESCRIPTION(
15445 "Test that an error is produced for a vertex shader input which is not "
15446 "provided by a vertex attribute");
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070015447 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15448 "Vertex shader consumes input at location 0 but not provided");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015449
Tony Barbour1fa09702017-03-16 12:09:08 -060015450 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060015451 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes62e8e502015-05-25 11:13:29 +120015452
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015453 char const *vsSource =
15454 "#version 450\n"
15455 "\n"
15456 "layout(location=0) in vec4 x;\n" /* not provided */
15457 "out gl_PerVertex {\n"
15458 " vec4 gl_Position;\n"
15459 "};\n"
15460 "void main(){\n"
15461 " gl_Position = x;\n"
15462 "}\n";
15463 char const *fsSource =
15464 "#version 450\n"
15465 "\n"
15466 "layout(location=0) out vec4 color;\n"
15467 "void main(){\n"
15468 " color = vec4(1);\n"
15469 "}\n";
Chris Forbes62e8e502015-05-25 11:13:29 +120015470
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060015471 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15472 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes62e8e502015-05-25 11:13:29 +120015473
15474 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080015475 pipe.AddColorAttachment();
Chris Forbes62e8e502015-05-25 11:13:29 +120015476 pipe.AddShader(&vs);
15477 pipe.AddShader(&fs);
15478
Chris Forbes62e8e502015-05-25 11:13:29 +120015479 VkDescriptorSetObj descriptorSet(m_device);
15480 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015481 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes62e8e502015-05-25 11:13:29 +120015482
Tony Barbour5781e8f2015-08-04 16:23:11 -060015483 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes62e8e502015-05-25 11:13:29 +120015484
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015485 m_errorMonitor->VerifyFound();
Chris Forbes62e8e502015-05-25 11:13:29 +120015486}
15487
Karl Schultz6addd812016-02-02 17:17:23 -070015488TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015489 TEST_DESCRIPTION(
15490 "Test that an error is produced for a mismatch between the "
15491 "fundamental type (float/int/uint) of an attribute and the "
15492 "vertex shader input that consumes it");
Mike Weiblen15bd38e2016-10-03 19:19:41 -060015493 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 -060015494
Tony Barbour1fa09702017-03-16 12:09:08 -060015495 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060015496 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc97d98e2015-05-25 11:13:31 +120015497
15498 VkVertexInputBindingDescription input_binding;
15499 memset(&input_binding, 0, sizeof(input_binding));
15500
15501 VkVertexInputAttributeDescription input_attrib;
15502 memset(&input_attrib, 0, sizeof(input_attrib));
15503 input_attrib.format = VK_FORMAT_R32_SFLOAT;
15504
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015505 char const *vsSource =
15506 "#version 450\n"
15507 "\n"
15508 "layout(location=0) in int x;\n" /* attrib provided float */
15509 "out gl_PerVertex {\n"
15510 " vec4 gl_Position;\n"
15511 "};\n"
15512 "void main(){\n"
15513 " gl_Position = vec4(x);\n"
15514 "}\n";
15515 char const *fsSource =
15516 "#version 450\n"
15517 "\n"
15518 "layout(location=0) out vec4 color;\n"
15519 "void main(){\n"
15520 " color = vec4(1);\n"
15521 "}\n";
Chris Forbesc97d98e2015-05-25 11:13:31 +120015522
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060015523 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15524 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc97d98e2015-05-25 11:13:31 +120015525
15526 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080015527 pipe.AddColorAttachment();
Chris Forbesc97d98e2015-05-25 11:13:31 +120015528 pipe.AddShader(&vs);
15529 pipe.AddShader(&fs);
15530
15531 pipe.AddVertexInputBindings(&input_binding, 1);
15532 pipe.AddVertexInputAttribs(&input_attrib, 1);
15533
Chris Forbesc97d98e2015-05-25 11:13:31 +120015534 VkDescriptorSetObj descriptorSet(m_device);
15535 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015536 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesc97d98e2015-05-25 11:13:31 +120015537
Tony Barbour5781e8f2015-08-04 16:23:11 -060015538 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc97d98e2015-05-25 11:13:31 +120015539
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015540 m_errorMonitor->VerifyFound();
Chris Forbesc97d98e2015-05-25 11:13:31 +120015541}
15542
Chris Forbesc68b43c2016-04-06 11:18:47 +120015543TEST_F(VkLayerTest, CreatePipelineDuplicateStage) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015544 TEST_DESCRIPTION(
15545 "Test that an error is produced for a pipeline containing multiple "
15546 "shaders for the same stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015547 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15548 "Multiple shaders provided for stage VK_SHADER_STAGE_VERTEX_BIT");
Chris Forbesc68b43c2016-04-06 11:18:47 +120015549
Tony Barbour1fa09702017-03-16 12:09:08 -060015550 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbesc68b43c2016-04-06 11:18:47 +120015551 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15552
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015553 char const *vsSource =
15554 "#version 450\n"
15555 "\n"
15556 "out gl_PerVertex {\n"
15557 " vec4 gl_Position;\n"
15558 "};\n"
15559 "void main(){\n"
15560 " gl_Position = vec4(1);\n"
15561 "}\n";
15562 char const *fsSource =
15563 "#version 450\n"
15564 "\n"
15565 "layout(location=0) out vec4 color;\n"
15566 "void main(){\n"
15567 " color = vec4(1);\n"
15568 "}\n";
Chris Forbesc68b43c2016-04-06 11:18:47 +120015569
15570 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15571 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15572
15573 VkPipelineObj pipe(m_device);
15574 pipe.AddColorAttachment();
15575 pipe.AddShader(&vs);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015576 pipe.AddShader(&vs); // intentionally duplicate vertex shader attachment
Chris Forbesc68b43c2016-04-06 11:18:47 +120015577 pipe.AddShader(&fs);
15578
15579 VkDescriptorSetObj descriptorSet(m_device);
15580 descriptorSet.AppendDummy();
15581 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15582
15583 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15584
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015585 m_errorMonitor->VerifyFound();
Chris Forbesc68b43c2016-04-06 11:18:47 +120015586}
15587
Chris Forbes82ff92a2016-09-09 10:50:24 +120015588TEST_F(VkLayerTest, CreatePipelineMissingEntrypoint) {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070015589 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "No entrypoint found named `foo`");
Chris Forbes82ff92a2016-09-09 10:50:24 +120015590
Tony Barbour1fa09702017-03-16 12:09:08 -060015591 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes82ff92a2016-09-09 10:50:24 +120015592 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15593
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015594 char const *vsSource =
15595 "#version 450\n"
15596 "out gl_PerVertex {\n"
15597 " vec4 gl_Position;\n"
15598 "};\n"
15599 "void main(){\n"
15600 " gl_Position = vec4(0);\n"
15601 "}\n";
15602 char const *fsSource =
15603 "#version 450\n"
15604 "\n"
15605 "layout(location=0) out vec4 color;\n"
15606 "void main(){\n"
15607 " color = vec4(1);\n"
15608 "}\n";
Chris Forbes82ff92a2016-09-09 10:50:24 +120015609
15610 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15611 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this, "foo");
15612
15613 VkPipelineObj pipe(m_device);
15614 pipe.AddColorAttachment();
15615 pipe.AddShader(&vs);
15616 pipe.AddShader(&fs);
15617
15618 VkDescriptorSetObj descriptorSet(m_device);
15619 descriptorSet.AppendDummy();
15620 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15621
15622 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15623
15624 m_errorMonitor->VerifyFound();
15625}
15626
Chris Forbesae9d8cd2016-09-13 16:32:57 +120015627TEST_F(VkLayerTest, CreatePipelineDepthStencilRequired) {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070015628 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15629 "pDepthStencilState is NULL when rasterization is enabled and subpass "
15630 "uses a depth/stencil attachment");
Chris Forbesae9d8cd2016-09-13 16:32:57 +120015631
Tony Barbour1fa09702017-03-16 12:09:08 -060015632 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbesae9d8cd2016-09-13 16:32:57 +120015633 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15634
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015635 char const *vsSource =
15636 "#version 450\n"
15637 "void main(){ gl_Position = vec4(0); }\n";
15638 char const *fsSource =
15639 "#version 450\n"
15640 "\n"
15641 "layout(location=0) out vec4 color;\n"
15642 "void main(){\n"
15643 " color = vec4(1);\n"
15644 "}\n";
Chris Forbesae9d8cd2016-09-13 16:32:57 +120015645
15646 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15647 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15648
15649 VkPipelineObj pipe(m_device);
15650 pipe.AddColorAttachment();
15651 pipe.AddShader(&vs);
15652 pipe.AddShader(&fs);
15653
15654 VkDescriptorSetObj descriptorSet(m_device);
15655 descriptorSet.AppendDummy();
15656 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15657
15658 VkAttachmentDescription attachments[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070015659 {
15660 0, VK_FORMAT_B8G8R8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
15661 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_UNDEFINED,
15662 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
Chris Forbesae9d8cd2016-09-13 16:32:57 +120015663 },
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070015664 {
15665 0, VK_FORMAT_D16_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
15666 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_UNDEFINED,
15667 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
Chris Forbesae9d8cd2016-09-13 16:32:57 +120015668 },
15669 };
15670 VkAttachmentReference refs[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070015671 {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL}, {1, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL},
Chris Forbesae9d8cd2016-09-13 16:32:57 +120015672 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070015673 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &refs[0], nullptr, &refs[1], 0, nullptr};
15674 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesae9d8cd2016-09-13 16:32:57 +120015675 VkRenderPass rp;
15676 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
15677 ASSERT_VK_SUCCESS(err);
15678
15679 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), rp);
15680
15681 m_errorMonitor->VerifyFound();
15682
15683 vkDestroyRenderPass(m_device->device(), rp, nullptr);
15684}
15685
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015686TEST_F(VkLayerTest, CreatePipelineTessPatchDecorationMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015687 TEST_DESCRIPTION(
15688 "Test that an error is produced for a variable output from "
15689 "the TCS without the patch decoration, but consumed in the TES "
15690 "with the decoration.");
15691 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15692 "is per-vertex in tessellation control shader stage "
15693 "but per-patch in tessellation evaluation shader stage");
Chris Forbesa0193bc2016-04-04 19:19:47 +120015694
Tony Barbour1fa09702017-03-16 12:09:08 -060015695 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbesa0193bc2016-04-04 19:19:47 +120015696 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15697
Chris Forbesc1e852d2016-04-04 19:26:42 +120015698 if (!m_device->phy().features().tessellationShader) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070015699 printf(" Device does not support tessellation shaders; skipped.\n");
Chris Forbesc1e852d2016-04-04 19:26:42 +120015700 return;
15701 }
15702
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015703 char const *vsSource =
15704 "#version 450\n"
15705 "void main(){}\n";
15706 char const *tcsSource =
15707 "#version 450\n"
15708 "layout(location=0) out int x[];\n"
15709 "layout(vertices=3) out;\n"
15710 "void main(){\n"
15711 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
15712 " gl_TessLevelInner[0] = 1;\n"
15713 " x[gl_InvocationID] = gl_InvocationID;\n"
15714 "}\n";
15715 char const *tesSource =
15716 "#version 450\n"
15717 "layout(triangles, equal_spacing, cw) in;\n"
15718 "layout(location=0) patch in int x;\n"
15719 "out gl_PerVertex { vec4 gl_Position; };\n"
15720 "void main(){\n"
15721 " gl_Position.xyz = gl_TessCoord;\n"
15722 " gl_Position.w = x;\n"
15723 "}\n";
15724 char const *fsSource =
15725 "#version 450\n"
15726 "layout(location=0) out vec4 color;\n"
15727 "void main(){\n"
15728 " color = vec4(1);\n"
15729 "}\n";
Chris Forbesa0193bc2016-04-04 19:19:47 +120015730
15731 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15732 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
15733 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
15734 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15735
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015736 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
15737 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Chris Forbesa0193bc2016-04-04 19:19:47 +120015738
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015739 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Chris Forbesa0193bc2016-04-04 19:19:47 +120015740
15741 VkPipelineObj pipe(m_device);
15742 pipe.SetInputAssembly(&iasci);
15743 pipe.SetTessellation(&tsci);
15744 pipe.AddColorAttachment();
15745 pipe.AddShader(&vs);
15746 pipe.AddShader(&tcs);
15747 pipe.AddShader(&tes);
15748 pipe.AddShader(&fs);
15749
15750 VkDescriptorSetObj descriptorSet(m_device);
15751 descriptorSet.AppendDummy();
15752 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15753
15754 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15755
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015756 m_errorMonitor->VerifyFound();
Chris Forbesa0193bc2016-04-04 19:19:47 +120015757}
15758
Cort Stratton2bcca1b2017-05-05 16:02:35 -070015759TEST_F(VkLayerTest, CreatePipelineTessErrors) {
15760 TEST_DESCRIPTION("Test various errors when creating a graphics pipeline with tessellation stages active.");
15761
15762 ASSERT_NO_FATAL_FAILURE(Init());
15763 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15764
15765 if (!m_device->phy().features().tessellationShader) {
15766 printf(" Device does not support tessellation shaders; skipped.\n");
15767 return;
15768 }
15769
15770 char const *vsSource =
15771 "#version 450\n"
15772 "void main(){}\n";
15773 char const *tcsSource =
15774 "#version 450\n"
15775 "layout(vertices=3) out;\n"
15776 "void main(){\n"
15777 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
15778 " gl_TessLevelInner[0] = 1;\n"
15779 "}\n";
15780 char const *tesSource =
15781 "#version 450\n"
15782 "layout(triangles, equal_spacing, cw) in;\n"
15783 "out gl_PerVertex { vec4 gl_Position; };\n"
15784 "void main(){\n"
15785 " gl_Position.xyz = gl_TessCoord;\n"
15786 " gl_Position.w = 0;\n"
15787 "}\n";
15788 char const *fsSource =
15789 "#version 450\n"
15790 "layout(location=0) out vec4 color;\n"
15791 "void main(){\n"
15792 " color = vec4(1);\n"
15793 "}\n";
15794
15795 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15796 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
15797 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
15798 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15799
15800 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
15801 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
15802
15803 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
15804
15805 VkDescriptorSetObj descriptorSet(m_device);
15806 descriptorSet.AppendDummy();
15807 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15808
15809 {
15810 VkPipelineObj pipe(m_device);
15811 VkPipelineInputAssemblyStateCreateInfo iasci_bad = iasci;
15812 iasci_bad.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST; // otherwise we get a failure about invalid topology
15813 pipe.SetInputAssembly(&iasci_bad);
15814 pipe.AddColorAttachment();
15815 pipe.AddShader(&vs);
15816 pipe.AddShader(&fs);
15817
15818 // Pass a tess control shader without a tess eval shader
15819 pipe.AddShader(&tcs);
15820 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00534);
15821 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15822 m_errorMonitor->VerifyFound();
15823 }
15824
15825 {
15826 VkPipelineObj pipe(m_device);
15827 VkPipelineInputAssemblyStateCreateInfo iasci_bad = iasci;
15828 iasci_bad.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST; // otherwise we get a failure about invalid topology
15829 pipe.SetInputAssembly(&iasci_bad);
15830 pipe.AddColorAttachment();
15831 pipe.AddShader(&vs);
15832 pipe.AddShader(&fs);
15833
15834 // Pass a tess eval shader without a tess control shader
15835 pipe.AddShader(&tes);
15836 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00535);
15837 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15838 m_errorMonitor->VerifyFound();
15839 }
15840
15841 {
15842 VkPipelineObj pipe(m_device);
15843 pipe.SetInputAssembly(&iasci);
15844 pipe.AddColorAttachment();
15845 pipe.AddShader(&vs);
15846 pipe.AddShader(&fs);
15847
15848 // Pass patch topology without tessellation shaders
15849 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02100);
15850 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15851 m_errorMonitor->VerifyFound();
15852
15853 pipe.AddShader(&tcs);
15854 pipe.AddShader(&tes);
15855 // Pass a NULL pTessellationState (with active tessellation shader stages)
15856 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00536);
15857 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15858 m_errorMonitor->VerifyFound();
15859
15860 // Pass an invalid pTessellationState (bad sType)
15861 VkPipelineTessellationStateCreateInfo tsci_bad = tsci;
15862 tsci_bad.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
15863 pipe.SetTessellation(&tsci_bad);
15864 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01427);
15865 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15866 m_errorMonitor->VerifyFound();
15867 // Pass out-of-range patchControlPoints
15868 tsci_bad = tsci;
15869 tsci_bad.patchControlPoints = 0;
15870 pipe.SetTessellation(&tsci);
15871 pipe.SetTessellation(&tsci_bad);
15872 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01426);
15873 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15874 m_errorMonitor->VerifyFound();
15875 tsci_bad.patchControlPoints = m_device->props.limits.maxTessellationPatchSize + 1;
15876 pipe.SetTessellation(&tsci_bad);
15877 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01426);
15878 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15879 m_errorMonitor->VerifyFound();
15880 pipe.SetTessellation(&tsci);
15881
15882 // Pass an invalid primitive topology
15883 VkPipelineInputAssemblyStateCreateInfo iasci_bad = iasci;
15884 iasci_bad.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
15885 pipe.SetInputAssembly(&iasci_bad);
15886 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02099);
15887 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15888 m_errorMonitor->VerifyFound();
15889 pipe.SetInputAssembly(&iasci);
15890 }
15891}
15892
Karl Schultz6addd812016-02-02 17:17:23 -070015893TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015894 TEST_DESCRIPTION(
15895 "Test that an error is produced for a vertex attribute setup where multiple "
15896 "bindings provide the same location");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015897 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15898 "Duplicate vertex input binding descriptions for binding 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015899
Tony Barbour1fa09702017-03-16 12:09:08 -060015900 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060015901 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes280ba2c2015-06-12 11:16:41 +120015902
15903 /* Two binding descriptions for binding 0 */
15904 VkVertexInputBindingDescription input_bindings[2];
15905 memset(input_bindings, 0, sizeof(input_bindings));
15906
15907 VkVertexInputAttributeDescription input_attrib;
15908 memset(&input_attrib, 0, sizeof(input_attrib));
15909 input_attrib.format = VK_FORMAT_R32_SFLOAT;
15910
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015911 char const *vsSource =
15912 "#version 450\n"
15913 "\n"
15914 "layout(location=0) in float x;\n" /* attrib provided float */
15915 "out gl_PerVertex {\n"
15916 " vec4 gl_Position;\n"
15917 "};\n"
15918 "void main(){\n"
15919 " gl_Position = vec4(x);\n"
15920 "}\n";
15921 char const *fsSource =
15922 "#version 450\n"
15923 "\n"
15924 "layout(location=0) out vec4 color;\n"
15925 "void main(){\n"
15926 " color = vec4(1);\n"
15927 "}\n";
Chris Forbes280ba2c2015-06-12 11:16:41 +120015928
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060015929 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15930 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes280ba2c2015-06-12 11:16:41 +120015931
15932 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080015933 pipe.AddColorAttachment();
Chris Forbes280ba2c2015-06-12 11:16:41 +120015934 pipe.AddShader(&vs);
15935 pipe.AddShader(&fs);
15936
15937 pipe.AddVertexInputBindings(input_bindings, 2);
15938 pipe.AddVertexInputAttribs(&input_attrib, 1);
15939
Chris Forbes280ba2c2015-06-12 11:16:41 +120015940 VkDescriptorSetObj descriptorSet(m_device);
15941 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015942 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes280ba2c2015-06-12 11:16:41 +120015943
Tony Barbour5781e8f2015-08-04 16:23:11 -060015944 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes280ba2c2015-06-12 11:16:41 +120015945
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015946 m_errorMonitor->VerifyFound();
Chris Forbes280ba2c2015-06-12 11:16:41 +120015947}
Chris Forbes8f68b562015-05-25 11:13:32 +120015948
Karl Schultz6addd812016-02-02 17:17:23 -070015949TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015950 TEST_DESCRIPTION(
15951 "Test that an error is produced for a fragment shader which does not "
15952 "provide an output for one of the pipeline's color attachments");
Mike Weiblencce7ec72016-10-17 19:33:05 -060015953 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attachment 0 not written by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015954
Tony Barbour1fa09702017-03-16 12:09:08 -060015955 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120015956
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015957 char const *vsSource =
15958 "#version 450\n"
15959 "\n"
15960 "out gl_PerVertex {\n"
15961 " vec4 gl_Position;\n"
15962 "};\n"
15963 "void main(){\n"
15964 " gl_Position = vec4(1);\n"
15965 "}\n";
15966 char const *fsSource =
15967 "#version 450\n"
15968 "\n"
15969 "void main(){\n"
15970 "}\n";
Chris Forbes4d6d1e52015-05-25 11:13:40 +120015971
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060015972 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15973 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120015974
15975 VkPipelineObj pipe(m_device);
15976 pipe.AddShader(&vs);
15977 pipe.AddShader(&fs);
15978
Chia-I Wu08accc62015-07-07 11:50:03 +080015979 /* set up CB 0, not written */
15980 pipe.AddColorAttachment();
15981 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120015982
Chris Forbes4d6d1e52015-05-25 11:13:40 +120015983 VkDescriptorSetObj descriptorSet(m_device);
15984 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015985 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120015986
Tony Barbour5781e8f2015-08-04 16:23:11 -060015987 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120015988
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015989 m_errorMonitor->VerifyFound();
Chris Forbes4d6d1e52015-05-25 11:13:40 +120015990}
15991
Karl Schultz6addd812016-02-02 17:17:23 -070015992TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015993 TEST_DESCRIPTION(
15994 "Test that a warning is produced for a fragment shader which provides a spurious "
15995 "output with no matching attachment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015996 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060015997 "fragment shader writes to output location 1 with no matching attachment");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015998
Tony Barbour1fa09702017-03-16 12:09:08 -060015999 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120016000
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016001 char const *vsSource =
16002 "#version 450\n"
16003 "\n"
16004 "out gl_PerVertex {\n"
16005 " vec4 gl_Position;\n"
16006 "};\n"
16007 "void main(){\n"
16008 " gl_Position = vec4(1);\n"
16009 "}\n";
16010 char const *fsSource =
16011 "#version 450\n"
16012 "\n"
16013 "layout(location=0) out vec4 x;\n"
16014 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
16015 "void main(){\n"
16016 " x = vec4(1);\n"
16017 " y = vec4(1);\n"
16018 "}\n";
Chris Forbesf3fffaa2015-05-25 11:13:43 +120016019
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060016020 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
16021 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120016022
16023 VkPipelineObj pipe(m_device);
16024 pipe.AddShader(&vs);
16025 pipe.AddShader(&fs);
16026
Chia-I Wu08accc62015-07-07 11:50:03 +080016027 /* set up CB 0, not written */
16028 pipe.AddColorAttachment();
16029 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120016030 /* FS writes CB 1, but we don't configure it */
16031
Chris Forbesf3fffaa2015-05-25 11:13:43 +120016032 VkDescriptorSetObj descriptorSet(m_device);
16033 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016034 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120016035
Tony Barbour5781e8f2015-08-04 16:23:11 -060016036 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120016037
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016038 m_errorMonitor->VerifyFound();
Chris Forbesf3fffaa2015-05-25 11:13:43 +120016039}
16040
Karl Schultz6addd812016-02-02 17:17:23 -070016041TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016042 TEST_DESCRIPTION(
16043 "Test that an error is produced for a mismatch between the fundamental "
16044 "type of an fragment shader output variable, and the format of the corresponding attachment");
Mike Weiblencce7ec72016-10-17 19:33:05 -060016045 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "does not match fragment shader output type");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016046
Tony Barbour1fa09702017-03-16 12:09:08 -060016047 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbesa36d69e2015-05-25 11:13:44 +120016048
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016049 char const *vsSource =
16050 "#version 450\n"
16051 "\n"
16052 "out gl_PerVertex {\n"
16053 " vec4 gl_Position;\n"
16054 "};\n"
16055 "void main(){\n"
16056 " gl_Position = vec4(1);\n"
16057 "}\n";
16058 char const *fsSource =
16059 "#version 450\n"
16060 "\n"
16061 "layout(location=0) out ivec4 x;\n" /* not UNORM */
16062 "void main(){\n"
16063 " x = ivec4(1);\n"
16064 "}\n";
Chris Forbesa36d69e2015-05-25 11:13:44 +120016065
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060016066 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
16067 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa36d69e2015-05-25 11:13:44 +120016068
16069 VkPipelineObj pipe(m_device);
16070 pipe.AddShader(&vs);
16071 pipe.AddShader(&fs);
16072
Chia-I Wu08accc62015-07-07 11:50:03 +080016073 /* set up CB 0; type is UNORM by default */
16074 pipe.AddColorAttachment();
16075 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa36d69e2015-05-25 11:13:44 +120016076
Chris Forbesa36d69e2015-05-25 11:13:44 +120016077 VkDescriptorSetObj descriptorSet(m_device);
16078 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016079 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesa36d69e2015-05-25 11:13:44 +120016080
Tony Barbour5781e8f2015-08-04 16:23:11 -060016081 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa36d69e2015-05-25 11:13:44 +120016082
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016083 m_errorMonitor->VerifyFound();
Chris Forbesa36d69e2015-05-25 11:13:44 +120016084}
Chris Forbes7b1b8932015-06-05 14:43:36 +120016085
Karl Schultz6addd812016-02-02 17:17:23 -070016086TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016087 TEST_DESCRIPTION(
16088 "Test that an error is produced for a shader consuming a uniform "
16089 "block which has no corresponding binding in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016090 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in pipeline layout");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016091
Tony Barbour1fa09702017-03-16 12:09:08 -060016092 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes556c76c2015-08-14 12:04:59 +120016093
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016094 char const *vsSource =
16095 "#version 450\n"
16096 "\n"
16097 "out gl_PerVertex {\n"
16098 " vec4 gl_Position;\n"
16099 "};\n"
16100 "void main(){\n"
16101 " gl_Position = vec4(1);\n"
16102 "}\n";
16103 char const *fsSource =
16104 "#version 450\n"
16105 "\n"
16106 "layout(location=0) out vec4 x;\n"
16107 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
16108 "void main(){\n"
16109 " x = vec4(bar.y);\n"
16110 "}\n";
Chris Forbes556c76c2015-08-14 12:04:59 +120016111
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060016112 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
16113 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes556c76c2015-08-14 12:04:59 +120016114
Chris Forbes556c76c2015-08-14 12:04:59 +120016115 VkPipelineObj pipe(m_device);
16116 pipe.AddShader(&vs);
16117 pipe.AddShader(&fs);
16118
16119 /* set up CB 0; type is UNORM by default */
16120 pipe.AddColorAttachment();
16121 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16122
16123 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016124 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes556c76c2015-08-14 12:04:59 +120016125
16126 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
16127
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016128 m_errorMonitor->VerifyFound();
Chris Forbes556c76c2015-08-14 12:04:59 +120016129}
16130
Chris Forbes5c59e902016-02-26 16:56:09 +130016131TEST_F(VkLayerTest, CreatePipelinePushConstantsNotInLayout) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016132 TEST_DESCRIPTION(
16133 "Test that an error is produced for a shader consuming push constants "
16134 "which are not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016135 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in layout");
Chris Forbes5c59e902016-02-26 16:56:09 +130016136
Tony Barbour1fa09702017-03-16 12:09:08 -060016137 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes5c59e902016-02-26 16:56:09 +130016138
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016139 char const *vsSource =
16140 "#version 450\n"
16141 "\n"
16142 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
16143 "out gl_PerVertex {\n"
16144 " vec4 gl_Position;\n"
16145 "};\n"
16146 "void main(){\n"
16147 " gl_Position = vec4(consts.x);\n"
16148 "}\n";
16149 char const *fsSource =
16150 "#version 450\n"
16151 "\n"
16152 "layout(location=0) out vec4 x;\n"
16153 "void main(){\n"
16154 " x = vec4(1);\n"
16155 "}\n";
Chris Forbes5c59e902016-02-26 16:56:09 +130016156
16157 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
16158 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
16159
16160 VkPipelineObj pipe(m_device);
16161 pipe.AddShader(&vs);
16162 pipe.AddShader(&fs);
16163
16164 /* set up CB 0; type is UNORM by default */
16165 pipe.AddColorAttachment();
16166 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16167
16168 VkDescriptorSetObj descriptorSet(m_device);
16169 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
16170
16171 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
16172
16173 /* should have generated an error -- no push constant ranges provided! */
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016174 m_errorMonitor->VerifyFound();
Chris Forbes5c59e902016-02-26 16:56:09 +130016175}
16176
Chris Forbes3fb17902016-08-22 14:57:55 +120016177TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissing) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016178 TEST_DESCRIPTION(
16179 "Test that an error is produced for a shader consuming an input attachment "
16180 "which is not included in the subpass description");
Chris Forbes3fb17902016-08-22 14:57:55 +120016181 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16182 "consumes input attachment index 0 but not provided in subpass");
16183
Tony Barbour1fa09702017-03-16 12:09:08 -060016184 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes3fb17902016-08-22 14:57:55 +120016185
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016186 char const *vsSource =
16187 "#version 450\n"
16188 "\n"
16189 "out gl_PerVertex {\n"
16190 " vec4 gl_Position;\n"
16191 "};\n"
16192 "void main(){\n"
16193 " gl_Position = vec4(1);\n"
16194 "}\n";
16195 char const *fsSource =
16196 "#version 450\n"
16197 "\n"
16198 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
16199 "layout(location=0) out vec4 color;\n"
16200 "void main() {\n"
16201 " color = subpassLoad(x);\n"
16202 "}\n";
Chris Forbes3fb17902016-08-22 14:57:55 +120016203
16204 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
16205 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
16206
16207 VkPipelineObj pipe(m_device);
16208 pipe.AddShader(&vs);
16209 pipe.AddShader(&fs);
16210 pipe.AddColorAttachment();
16211 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16212
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016213 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
16214 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes3fb17902016-08-22 14:57:55 +120016215 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016216 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes3fb17902016-08-22 14:57:55 +120016217 ASSERT_VK_SUCCESS(err);
16218
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016219 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes3fb17902016-08-22 14:57:55 +120016220 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016221 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes3fb17902016-08-22 14:57:55 +120016222 ASSERT_VK_SUCCESS(err);
16223
16224 // error here.
16225 pipe.CreateVKPipeline(pl, renderPass());
16226
16227 m_errorMonitor->VerifyFound();
16228
16229 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
16230 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
16231}
16232
Chris Forbes5a9a0472016-08-22 16:02:09 +120016233TEST_F(VkLayerTest, CreatePipelineInputAttachmentTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016234 TEST_DESCRIPTION(
16235 "Test that an error is produced for a shader consuming an input attachment "
16236 "with a format having a different fundamental type");
Chris Forbes5a9a0472016-08-22 16:02:09 +120016237 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16238 "input attachment 0 format of VK_FORMAT_R8G8B8A8_UINT does not match");
16239
Tony Barbour1fa09702017-03-16 12:09:08 -060016240 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes5a9a0472016-08-22 16:02:09 +120016241
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016242 char const *vsSource =
16243 "#version 450\n"
16244 "\n"
16245 "out gl_PerVertex {\n"
16246 " vec4 gl_Position;\n"
16247 "};\n"
16248 "void main(){\n"
16249 " gl_Position = vec4(1);\n"
16250 "}\n";
16251 char const *fsSource =
16252 "#version 450\n"
16253 "\n"
16254 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
16255 "layout(location=0) out vec4 color;\n"
16256 "void main() {\n"
16257 " color = subpassLoad(x);\n"
16258 "}\n";
Chris Forbes5a9a0472016-08-22 16:02:09 +120016259
16260 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
16261 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
16262
16263 VkPipelineObj pipe(m_device);
16264 pipe.AddShader(&vs);
16265 pipe.AddShader(&fs);
16266 pipe.AddColorAttachment();
16267 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16268
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016269 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
16270 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes5a9a0472016-08-22 16:02:09 +120016271 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016272 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120016273 ASSERT_VK_SUCCESS(err);
16274
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016275 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120016276 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016277 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120016278 ASSERT_VK_SUCCESS(err);
16279
16280 VkAttachmentDescription descs[2] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016281 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
16282 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
16283 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
16284 {0, VK_FORMAT_R8G8B8A8_UINT, 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_GENERAL, VK_IMAGE_LAYOUT_GENERAL},
Chris Forbes5a9a0472016-08-22 16:02:09 +120016286 };
16287 VkAttachmentReference color = {
16288 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
16289 };
16290 VkAttachmentReference input = {
16291 1, VK_IMAGE_LAYOUT_GENERAL,
16292 };
16293
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016294 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120016295
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016296 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120016297 VkRenderPass rp;
16298 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
16299 ASSERT_VK_SUCCESS(err);
16300
16301 // error here.
16302 pipe.CreateVKPipeline(pl, rp);
16303
16304 m_errorMonitor->VerifyFound();
16305
16306 vkDestroyRenderPass(m_device->device(), rp, nullptr);
16307 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
16308 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
16309}
16310
Chris Forbes541f7b02016-08-22 15:30:27 +120016311TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissingArray) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016312 TEST_DESCRIPTION(
16313 "Test that an error is produced for a shader consuming an input attachment "
16314 "which is not included in the subpass description -- array case");
Chris Forbes541f7b02016-08-22 15:30:27 +120016315 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Rene Lindsay07b60af2017-01-10 15:57:55 -070016316 "consumes input attachment index 0 but not provided in subpass");
Chris Forbes541f7b02016-08-22 15:30:27 +120016317
Tony Barbour1fa09702017-03-16 12:09:08 -060016318 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes541f7b02016-08-22 15:30:27 +120016319
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016320 char const *vsSource =
16321 "#version 450\n"
16322 "\n"
16323 "out gl_PerVertex {\n"
16324 " vec4 gl_Position;\n"
16325 "};\n"
16326 "void main(){\n"
16327 " gl_Position = vec4(1);\n"
16328 "}\n";
16329 char const *fsSource =
16330 "#version 450\n"
16331 "\n"
16332 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput xs[1];\n"
16333 "layout(location=0) out vec4 color;\n"
16334 "void main() {\n"
16335 " color = subpassLoad(xs[0]);\n"
16336 "}\n";
Chris Forbes541f7b02016-08-22 15:30:27 +120016337
16338 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
16339 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
16340
16341 VkPipelineObj pipe(m_device);
16342 pipe.AddShader(&vs);
16343 pipe.AddShader(&fs);
16344 pipe.AddColorAttachment();
16345 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16346
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016347 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 2, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
16348 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes541f7b02016-08-22 15:30:27 +120016349 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016350 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes541f7b02016-08-22 15:30:27 +120016351 ASSERT_VK_SUCCESS(err);
16352
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016353 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes541f7b02016-08-22 15:30:27 +120016354 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016355 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes541f7b02016-08-22 15:30:27 +120016356 ASSERT_VK_SUCCESS(err);
16357
16358 // error here.
16359 pipe.CreateVKPipeline(pl, renderPass());
16360
16361 m_errorMonitor->VerifyFound();
16362
16363 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
16364 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
16365}
16366
Chris Forbes10eb9ae2016-05-31 16:09:42 +120016367TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptor) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016368 TEST_DESCRIPTION(
16369 "Test that an error is produced for a compute pipeline consuming a "
16370 "descriptor which is not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016371 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Shader uses descriptor slot 0.0");
Chris Forbes10eb9ae2016-05-31 16:09:42 +120016372
Tony Barbour1fa09702017-03-16 12:09:08 -060016373 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes10eb9ae2016-05-31 16:09:42 +120016374
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016375 char const *csSource =
16376 "#version 450\n"
16377 "\n"
16378 "layout(local_size_x=1) in;\n"
16379 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
16380 "void main(){\n"
16381 " x = vec4(1);\n"
16382 "}\n";
Chris Forbes10eb9ae2016-05-31 16:09:42 +120016383
16384 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
16385
16386 VkDescriptorSetObj descriptorSet(m_device);
16387 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
16388
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016389 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
16390 nullptr,
16391 0,
16392 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
16393 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
16394 descriptorSet.GetPipelineLayout(),
16395 VK_NULL_HANDLE,
16396 -1};
Chris Forbes10eb9ae2016-05-31 16:09:42 +120016397
16398 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016399 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes10eb9ae2016-05-31 16:09:42 +120016400
16401 m_errorMonitor->VerifyFound();
16402
16403 if (err == VK_SUCCESS) {
16404 vkDestroyPipeline(m_device->device(), pipe, nullptr);
16405 }
16406}
16407
Chris Forbes22a9b092016-07-19 14:34:05 +120016408TEST_F(VkLayerTest, CreateComputePipelineDescriptorTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016409 TEST_DESCRIPTION(
16410 "Test that an error is produced for a pipeline consuming a "
16411 "descriptor-backed resource of a mismatched type");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016412 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16413 "but descriptor of type VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER");
Chris Forbes22a9b092016-07-19 14:34:05 +120016414
Tony Barbour1fa09702017-03-16 12:09:08 -060016415 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes22a9b092016-07-19 14:34:05 +120016416
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016417 VkDescriptorSetLayoutBinding binding = {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr};
16418 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &binding};
Chris Forbes22a9b092016-07-19 14:34:05 +120016419 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016420 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes22a9b092016-07-19 14:34:05 +120016421 ASSERT_VK_SUCCESS(err);
16422
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016423 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes22a9b092016-07-19 14:34:05 +120016424 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016425 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes22a9b092016-07-19 14:34:05 +120016426 ASSERT_VK_SUCCESS(err);
16427
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016428 char const *csSource =
16429 "#version 450\n"
16430 "\n"
16431 "layout(local_size_x=1) in;\n"
16432 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
16433 "void main() {\n"
16434 " x.x = 1.0f;\n"
16435 "}\n";
Chris Forbes22a9b092016-07-19 14:34:05 +120016436 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
16437
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016438 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
16439 nullptr,
16440 0,
16441 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
16442 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
16443 pl,
16444 VK_NULL_HANDLE,
16445 -1};
Chris Forbes22a9b092016-07-19 14:34:05 +120016446
16447 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016448 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes22a9b092016-07-19 14:34:05 +120016449
16450 m_errorMonitor->VerifyFound();
16451
16452 if (err == VK_SUCCESS) {
16453 vkDestroyPipeline(m_device->device(), pipe, nullptr);
16454 }
16455
16456 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
16457 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
16458}
16459
Chris Forbes50020592016-07-27 13:52:41 +120016460TEST_F(VkLayerTest, DrawTimeImageViewTypeMismatchWithPipeline) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016461 TEST_DESCRIPTION(
16462 "Test that an error is produced when an image view type "
16463 "does not match the dimensionality declared in the shader");
Chris Forbes50020592016-07-27 13:52:41 +120016464
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016465 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 +120016466
Tony Barbour1fa09702017-03-16 12:09:08 -060016467 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes50020592016-07-27 13:52:41 +120016468 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16469
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016470 char const *vsSource =
16471 "#version 450\n"
16472 "\n"
16473 "out gl_PerVertex { vec4 gl_Position; };\n"
16474 "void main() { gl_Position = vec4(0); }\n";
16475 char const *fsSource =
16476 "#version 450\n"
16477 "\n"
16478 "layout(set=0, binding=0) uniform sampler3D s;\n"
16479 "layout(location=0) out vec4 color;\n"
16480 "void main() {\n"
16481 " color = texture(s, vec3(0));\n"
16482 "}\n";
Chris Forbes50020592016-07-27 13:52:41 +120016483 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
16484 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
16485
16486 VkPipelineObj pipe(m_device);
16487 pipe.AddShader(&vs);
16488 pipe.AddShader(&fs);
16489 pipe.AddColorAttachment();
16490
16491 VkTextureObj texture(m_device, nullptr);
16492 VkSamplerObj sampler(m_device);
16493
16494 VkDescriptorSetObj descriptorSet(m_device);
16495 descriptorSet.AppendSamplerTexture(&sampler, &texture);
16496 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
16497
16498 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
16499 ASSERT_VK_SUCCESS(err);
16500
Tony Barbour552f6c02016-12-21 14:34:07 -070016501 m_commandBuffer->BeginCommandBuffer();
16502 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes50020592016-07-27 13:52:41 +120016503
16504 m_commandBuffer->BindPipeline(pipe);
16505 m_commandBuffer->BindDescriptorSet(descriptorSet);
16506
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016507 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes50020592016-07-27 13:52:41 +120016508 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016509 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes50020592016-07-27 13:52:41 +120016510 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16511
16512 // error produced here.
16513 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
16514
16515 m_errorMonitor->VerifyFound();
16516
Tony Barbour552f6c02016-12-21 14:34:07 -070016517 m_commandBuffer->EndRenderPass();
16518 m_commandBuffer->EndCommandBuffer();
Chris Forbes50020592016-07-27 13:52:41 +120016519}
16520
Chris Forbes5533bfc2016-07-27 14:12:34 +120016521TEST_F(VkLayerTest, DrawTimeImageMultisampleMismatchWithPipeline) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016522 TEST_DESCRIPTION(
16523 "Test that an error is produced when a multisampled images "
16524 "are consumed via singlesample images types in the shader, or vice versa.");
Chris Forbes5533bfc2016-07-27 14:12:34 +120016525
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016526 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "requires bound image to have multiple samples");
Chris Forbes5533bfc2016-07-27 14:12:34 +120016527
Tony Barbour1fa09702017-03-16 12:09:08 -060016528 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes5533bfc2016-07-27 14:12:34 +120016529 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16530
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016531 char const *vsSource =
16532 "#version 450\n"
16533 "\n"
16534 "out gl_PerVertex { vec4 gl_Position; };\n"
16535 "void main() { gl_Position = vec4(0); }\n";
16536 char const *fsSource =
16537 "#version 450\n"
16538 "\n"
16539 "layout(set=0, binding=0) uniform sampler2DMS s;\n"
16540 "layout(location=0) out vec4 color;\n"
16541 "void main() {\n"
16542 " color = texelFetch(s, ivec2(0), 0);\n"
16543 "}\n";
Chris Forbes5533bfc2016-07-27 14:12:34 +120016544 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
16545 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
16546
16547 VkPipelineObj pipe(m_device);
16548 pipe.AddShader(&vs);
16549 pipe.AddShader(&fs);
16550 pipe.AddColorAttachment();
16551
16552 VkTextureObj texture(m_device, nullptr);
16553 VkSamplerObj sampler(m_device);
16554
16555 VkDescriptorSetObj descriptorSet(m_device);
16556 descriptorSet.AppendSamplerTexture(&sampler, &texture);
16557 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
16558
16559 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
16560 ASSERT_VK_SUCCESS(err);
16561
Tony Barbour552f6c02016-12-21 14:34:07 -070016562 m_commandBuffer->BeginCommandBuffer();
16563 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes5533bfc2016-07-27 14:12:34 +120016564
16565 m_commandBuffer->BindPipeline(pipe);
16566 m_commandBuffer->BindDescriptorSet(descriptorSet);
16567
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016568 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes5533bfc2016-07-27 14:12:34 +120016569 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016570 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes5533bfc2016-07-27 14:12:34 +120016571 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16572
16573 // error produced here.
16574 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
16575
16576 m_errorMonitor->VerifyFound();
16577
Tony Barbour552f6c02016-12-21 14:34:07 -070016578 m_commandBuffer->EndRenderPass();
16579 m_commandBuffer->EndCommandBuffer();
Chris Forbes5533bfc2016-07-27 14:12:34 +120016580}
16581
Mark Youngc48c4c12016-04-11 14:26:49 -060016582TEST_F(VkLayerTest, CreateImageLimitsViolationMaxWidth) {
Tony Barbour1fa09702017-03-16 12:09:08 -060016583 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060016584
Jeremy Hayesbb63cc12017-03-20 15:33:01 -060016585 VkFormat const format = VK_FORMAT_B8G8R8A8_UNORM;
16586 {
16587 VkFormatProperties properties;
16588 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), format, &properties);
16589 if (properties.optimalTilingFeatures == 0) {
16590 printf(" Image format not supported; skipped.\n");
16591 return;
16592 }
16593 }
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060016594
Jeremy Hayesbb63cc12017-03-20 15:33:01 -060016595 VkImageCreateInfo info = {};
16596 info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16597 info.pNext = NULL;
16598 info.imageType = VK_IMAGE_TYPE_2D;
16599 info.format = format;
16600 info.extent.height = 32;
16601 info.extent.depth = 1;
16602 info.mipLevels = 1;
16603 info.arrayLayers = 1;
16604 info.samples = VK_SAMPLE_COUNT_1_BIT;
16605 info.tiling = VK_IMAGE_TILING_OPTIMAL;
16606 info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
16607 info.flags = 0;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060016608
16609 // Introduce error by sending down a bogus width extent
Jeremy Hayesbb63cc12017-03-20 15:33:01 -060016610 {
16611 VkImageFormatProperties properties;
16612 auto const result = vkGetPhysicalDeviceImageFormatProperties(m_device->phy().handle(), info.format, info.imageType,
16613 info.tiling, info.usage, info.flags, &properties);
16614 ASSERT_VK_SUCCESS(result);
16615 info.extent.width = properties.maxExtent.width + 1;
16616 }
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060016617
Jeremy Hayesbb63cc12017-03-20 15:33:01 -060016618 VkImage image;
16619 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
16620 vkCreateImage(m_device->device(), &info, NULL, &image);
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016621 m_errorMonitor->VerifyFound();
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060016622}
16623
Mark Youngc48c4c12016-04-11 14:26:49 -060016624TEST_F(VkLayerTest, CreateImageLimitsViolationMinWidth) {
Tony Barbour1fa09702017-03-16 12:09:08 -060016625 ASSERT_NO_FATAL_FAILURE(Init());
Mark Youngc48c4c12016-04-11 14:26:49 -060016626
Jeremy Hayesbb63cc12017-03-20 15:33:01 -060016627 VkFormat const format = VK_FORMAT_B8G8R8A8_UNORM;
16628 {
16629 VkFormatProperties properties;
16630 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), format, &properties);
16631 if (properties.optimalTilingFeatures == 0) {
16632 printf(" Image format not supported; skipped.\n");
16633 return;
16634 }
16635 }
Mark Youngc48c4c12016-04-11 14:26:49 -060016636
Jeremy Hayesbb63cc12017-03-20 15:33:01 -060016637 VkImageCreateInfo info = {};
16638 info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16639 info.pNext = NULL;
16640 info.imageType = VK_IMAGE_TYPE_2D;
16641 info.format = format;
16642 info.extent.height = 32;
16643 info.extent.depth = 1;
16644 info.mipLevels = 1;
16645 info.arrayLayers = 1;
16646 info.samples = VK_SAMPLE_COUNT_1_BIT;
16647 info.tiling = VK_IMAGE_TILING_OPTIMAL;
16648 info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
16649 info.flags = 0;
Mark Youngc48c4c12016-04-11 14:26:49 -060016650
16651 // Introduce error by sending down a bogus width extent
Jeremy Hayesbb63cc12017-03-20 15:33:01 -060016652 info.extent.width = 0;
Mark Youngc48c4c12016-04-11 14:26:49 -060016653
Jeremy Hayesbb63cc12017-03-20 15:33:01 -060016654 VkImage image;
Tobin Ehlisa55b1d42017-04-04 12:23:48 -060016655 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02917);
Jeremy Hayesbb63cc12017-03-20 15:33:01 -060016656 m_errorMonitor->SetUnexpectedError("parameter pCreateInfo->extent.width must be greater than 0");
16657 vkCreateImage(m_device->device(), &info, NULL, &image);
Mark Youngc48c4c12016-04-11 14:26:49 -060016658 m_errorMonitor->VerifyFound();
16659}
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -070016660
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060016661TEST_F(VkLayerTest, AttachmentDescriptionUndefinedFormat) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016662 TEST_DESCRIPTION(
16663 "Create a render pass with an attachment description "
16664 "format set to VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060016665
Tony Barbour1fa09702017-03-16 12:09:08 -060016666 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060016667 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16668
Jeremy Hayes632e0ab2017-02-09 13:32:28 -070016669 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "format is VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060016670
16671 VkAttachmentReference color_attach = {};
16672 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
16673 color_attach.attachment = 0;
16674 VkSubpassDescription subpass = {};
16675 subpass.colorAttachmentCount = 1;
16676 subpass.pColorAttachments = &color_attach;
16677
16678 VkRenderPassCreateInfo rpci = {};
16679 rpci.subpassCount = 1;
16680 rpci.pSubpasses = &subpass;
16681 rpci.attachmentCount = 1;
16682 VkAttachmentDescription attach_desc = {};
16683 attach_desc.format = VK_FORMAT_UNDEFINED;
16684 rpci.pAttachments = &attach_desc;
16685 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
16686 VkRenderPass rp;
16687 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
16688
16689 m_errorMonitor->VerifyFound();
16690
16691 if (result == VK_SUCCESS) {
16692 vkDestroyRenderPass(m_device->device(), rp, NULL);
16693 }
16694}
16695
Mark Youngd339ba32016-05-30 13:28:35 -060016696TEST_F(VkLayerTest, CreateImageViewNoMemoryBoundToImage) {
16697 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -060016698 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -060016699 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -060016700
Tony Barbour1fa09702017-03-16 12:09:08 -060016701 ASSERT_NO_FATAL_FAILURE(Init());
Mark Youngd339ba32016-05-30 13:28:35 -060016702
16703 // Create an image and try to create a view with no memory backing the image
16704 VkImage image;
16705
16706 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
16707 const int32_t tex_width = 32;
16708 const int32_t tex_height = 32;
16709
16710 VkImageCreateInfo image_create_info = {};
16711 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16712 image_create_info.pNext = NULL;
16713 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16714 image_create_info.format = tex_format;
16715 image_create_info.extent.width = tex_width;
16716 image_create_info.extent.height = tex_height;
16717 image_create_info.extent.depth = 1;
16718 image_create_info.mipLevels = 1;
16719 image_create_info.arrayLayers = 1;
16720 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16721 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16722 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
16723 image_create_info.flags = 0;
16724
16725 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
16726 ASSERT_VK_SUCCESS(err);
16727
16728 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130016729 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Mark Youngd339ba32016-05-30 13:28:35 -060016730 image_view_create_info.image = image;
16731 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
16732 image_view_create_info.format = tex_format;
16733 image_view_create_info.subresourceRange.layerCount = 1;
16734 image_view_create_info.subresourceRange.baseMipLevel = 0;
16735 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016736 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -060016737
16738 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016739 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Youngd339ba32016-05-30 13:28:35 -060016740
16741 m_errorMonitor->VerifyFound();
16742 vkDestroyImage(m_device->device(), image, NULL);
16743 // If last error is success, it still created the view, so delete it.
16744 if (err == VK_SUCCESS) {
16745 vkDestroyImageView(m_device->device(), view, NULL);
16746 }
Mark Youngd339ba32016-05-30 13:28:35 -060016747}
16748
Karl Schultz6addd812016-02-02 17:17:23 -070016749TEST_F(VkLayerTest, InvalidImageViewAspect) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016750 TEST_DESCRIPTION("Create an image and try to create a view with an invalid aspectMask");
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070016751 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00741);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016752
Tony Barbour1fa09702017-03-16 12:09:08 -060016753 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060016754
Karl Schultz6addd812016-02-02 17:17:23 -070016755 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060016756 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060016757 image.Init(32, 32, 1, tex_format, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_LINEAR, 0);
Tobin Ehlis1f567a22016-05-25 16:15:18 -060016758 ASSERT_TRUE(image.initialized());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060016759
16760 VkImageViewCreateInfo image_view_create_info = {};
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060016761 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060016762 image_view_create_info.image = image.handle();
Karl Schultz6addd812016-02-02 17:17:23 -070016763 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
16764 image_view_create_info.format = tex_format;
16765 image_view_create_info.subresourceRange.baseMipLevel = 0;
16766 image_view_create_info.subresourceRange.levelCount = 1;
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060016767 image_view_create_info.subresourceRange.layerCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070016768 // Cause an error by setting an invalid image aspect
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016769 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060016770
16771 VkImageView view;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060016772 vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060016773
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016774 m_errorMonitor->VerifyFound();
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060016775}
16776
Mike Weiblena1e13f42017-02-09 21:25:59 -070016777TEST_F(VkLayerTest, ExerciseGetImageSubresourceLayout) {
16778 TEST_DESCRIPTION("Test vkGetImageSubresourceLayout() valid usages");
16779
Tony Barbour1fa09702017-03-16 12:09:08 -060016780 ASSERT_NO_FATAL_FAILURE(Init());
Mike Weiblena1e13f42017-02-09 21:25:59 -070016781 VkSubresourceLayout subres_layout = {};
16782
16783 // VU 00732: image must have been created with tiling equal to VK_IMAGE_TILING_LINEAR
16784 {
16785 const VkImageTiling tiling = VK_IMAGE_TILING_OPTIMAL; // ERROR: violates VU 00732
16786 VkImageObj img(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060016787 img.InitNoLayout(32, 32, 1, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, tiling);
Mike Weiblena1e13f42017-02-09 21:25:59 -070016788 ASSERT_TRUE(img.initialized());
16789
16790 VkImageSubresource subres = {};
16791 subres.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16792 subres.mipLevel = 0;
16793 subres.arrayLayer = 0;
16794
16795 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00732);
16796 vkGetImageSubresourceLayout(m_device->device(), img.image(), &subres, &subres_layout);
16797 m_errorMonitor->VerifyFound();
16798 }
16799
16800 // VU 00733: The aspectMask member of pSubresource must only have a single bit set
16801 {
16802 VkImageObj img(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060016803 img.InitNoLayout(32, 32, 1, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
Mike Weiblena1e13f42017-02-09 21:25:59 -070016804 ASSERT_TRUE(img.initialized());
16805
16806 VkImageSubresource subres = {};
16807 subres.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_METADATA_BIT; // ERROR: triggers VU 00733
16808 subres.mipLevel = 0;
16809 subres.arrayLayer = 0;
16810
16811 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00733);
16812 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00741);
16813 vkGetImageSubresourceLayout(m_device->device(), img.image(), &subres, &subres_layout);
16814 m_errorMonitor->VerifyFound();
16815 }
16816
16817 // 00739 mipLevel must be less than the mipLevels specified in VkImageCreateInfo when the image was created
16818 {
16819 VkImageObj img(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060016820 img.InitNoLayout(32, 32, 1, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
Mike Weiblena1e13f42017-02-09 21:25:59 -070016821 ASSERT_TRUE(img.initialized());
16822
16823 VkImageSubresource subres = {};
16824 subres.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16825 subres.mipLevel = 1; // ERROR: triggers VU 00739
16826 subres.arrayLayer = 0;
16827
16828 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00739);
16829 vkGetImageSubresourceLayout(m_device->device(), img.image(), &subres, &subres_layout);
16830 m_errorMonitor->VerifyFound();
16831 }
16832
16833 // 00740 arrayLayer must be less than the arrayLayers specified in VkImageCreateInfo when the image was created
16834 {
16835 VkImageObj img(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060016836 img.InitNoLayout(32, 32, 1, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
Mike Weiblena1e13f42017-02-09 21:25:59 -070016837 ASSERT_TRUE(img.initialized());
16838
16839 VkImageSubresource subres = {};
16840 subres.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16841 subres.mipLevel = 0;
16842 subres.arrayLayer = 1; // ERROR: triggers VU 00740
16843
16844 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00740);
16845 vkGetImageSubresourceLayout(m_device->device(), img.image(), &subres, &subres_layout);
16846 m_errorMonitor->VerifyFound();
16847 }
16848}
16849
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016850TEST_F(VkLayerTest, CopyImageLayerCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -070016851 VkResult err;
16852 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016853
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070016854 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01198);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016855
Tony Barbour1fa09702017-03-16 12:09:08 -060016856 ASSERT_NO_FATAL_FAILURE(Init());
Mike Stroyana3082432015-09-25 13:39:21 -060016857
16858 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070016859 VkImage srcImage;
16860 VkImage dstImage;
16861 VkDeviceMemory srcMem;
16862 VkDeviceMemory destMem;
16863 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016864
16865 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016866 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16867 image_create_info.pNext = NULL;
16868 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16869 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16870 image_create_info.extent.width = 32;
16871 image_create_info.extent.height = 32;
16872 image_create_info.extent.depth = 1;
16873 image_create_info.mipLevels = 1;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016874 image_create_info.arrayLayers = 4;
Karl Schultz6addd812016-02-02 17:17:23 -070016875 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16876 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16877 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16878 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016879
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016880 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016881 ASSERT_VK_SUCCESS(err);
16882
Mark Lobodzinski867787a2016-10-14 11:49:55 -060016883 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016884 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016885 ASSERT_VK_SUCCESS(err);
16886
16887 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016888 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016889 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16890 memAlloc.pNext = NULL;
16891 memAlloc.allocationSize = 0;
16892 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016893
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060016894 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016895 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016896 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016897 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016898 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016899 ASSERT_VK_SUCCESS(err);
16900
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016901 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016902 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016903 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016904 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016905 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016906 ASSERT_VK_SUCCESS(err);
16907
16908 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16909 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016910 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016911 ASSERT_VK_SUCCESS(err);
16912
Tony Barbour552f6c02016-12-21 14:34:07 -070016913 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060016914 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016915 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016916 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060016917 copyRegion.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016918 copyRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060016919 copyRegion.srcOffset.x = 0;
16920 copyRegion.srcOffset.y = 0;
16921 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016922 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016923 copyRegion.dstSubresource.mipLevel = 0;
16924 copyRegion.dstSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016925 // Introduce failure by forcing the dst layerCount to differ from src
16926 copyRegion.dstSubresource.layerCount = 3;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016927 copyRegion.dstOffset.x = 0;
16928 copyRegion.dstOffset.y = 0;
16929 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016930 copyRegion.extent.width = 1;
16931 copyRegion.extent.height = 1;
16932 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016933 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070016934 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060016935
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016936 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060016937
Chia-I Wuf7458c52015-10-26 21:10:41 +080016938 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016939 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016940 vkFreeMemory(m_device->device(), srcMem, NULL);
16941 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016942}
16943
Tony Barbourd6673642016-05-05 14:46:39 -060016944TEST_F(VkLayerTest, ImageLayerUnsupportedFormat) {
Tony Barbourd6673642016-05-05 14:46:39 -060016945 TEST_DESCRIPTION("Creating images with unsuported formats ");
16946
Tony Barbour1fa09702017-03-16 12:09:08 -060016947 ASSERT_NO_FATAL_FAILURE(Init());
Tony Barbourd6673642016-05-05 14:46:39 -060016948 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourd6673642016-05-05 14:46:39 -060016949
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060016950 // Create image with unsupported format - Expect FORMAT_UNSUPPORTED
Chris Forbesf4d8e332016-11-28 17:51:10 +130016951 VkImageCreateInfo image_create_info = {};
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060016952 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060016953 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16954 image_create_info.format = VK_FORMAT_UNDEFINED;
16955 image_create_info.extent.width = 32;
16956 image_create_info.extent.height = 32;
16957 image_create_info.extent.depth = 1;
16958 image_create_info.mipLevels = 1;
16959 image_create_info.arrayLayers = 1;
16960 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16961 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16962 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060016963
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016964 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16965 "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED");
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060016966
Jeremy Hayes96dcd812017-03-14 14:04:19 -060016967 VkImage image;
16968 vkCreateImage(m_device->handle(), &image_create_info, NULL, &image);
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060016969 m_errorMonitor->VerifyFound();
16970
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060016971 // Look for a format that is COMPLETELY unsupported with this hardware
Jeremy Hayes96dcd812017-03-14 14:04:19 -060016972 VkFormat unsupported = VK_FORMAT_UNDEFINED;
Tony Barbourd6673642016-05-05 14:46:39 -060016973 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
16974 VkFormat format = static_cast<VkFormat>(f);
16975 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016976 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Tony Barbourd6673642016-05-05 14:46:39 -060016977 unsupported = format;
16978 break;
16979 }
16980 }
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060016981
Tony Barbourd6673642016-05-05 14:46:39 -060016982 if (unsupported != VK_FORMAT_UNDEFINED) {
Tony Barbourd6673642016-05-05 14:46:39 -060016983 image_create_info.format = unsupported;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016984 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is an unsupported format");
Tony Barbourd6673642016-05-05 14:46:39 -060016985
Jeremy Hayes96dcd812017-03-14 14:04:19 -060016986 vkCreateImage(m_device->handle(), &image_create_info, NULL, &image);
Tony Barbourd6673642016-05-05 14:46:39 -060016987 m_errorMonitor->VerifyFound();
16988 }
16989}
16990
16991TEST_F(VkLayerTest, ImageLayerViewTests) {
Tony Barbourd6673642016-05-05 14:46:39 -060016992 TEST_DESCRIPTION("Passing bad parameters to CreateImageView");
16993
Tony Barbour1fa09702017-03-16 12:09:08 -060016994 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -060016995 auto depth_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbourf887b162017-03-09 10:06:46 -070016996 if (!depth_format) {
16997 return;
16998 }
Tony Barbourd6673642016-05-05 14:46:39 -060016999
17000 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017001 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 -060017002 VK_IMAGE_TILING_OPTIMAL, 0);
17003 ASSERT_TRUE(image.initialized());
17004
17005 VkImageView imgView;
17006 VkImageViewCreateInfo imgViewInfo = {};
17007 imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
17008 imgViewInfo.image = image.handle();
17009 imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
17010 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
17011 imgViewInfo.subresourceRange.layerCount = 1;
17012 imgViewInfo.subresourceRange.baseMipLevel = 0;
17013 imgViewInfo.subresourceRange.levelCount = 1;
17014 imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17015
Tony Barbourd6673642016-05-05 14:46:39 -060017016
Tony Barbourd6673642016-05-05 14:46:39 -060017017 // Can't use depth format for view into color image - Expect INVALID_FORMAT
Tony Barbourf887b162017-03-09 10:06:46 -070017018 imgViewInfo.format = depth_format;
Jeremy Hayes2ffbaa72017-03-14 17:05:50 -060017019 m_errorMonitor->SetDesiredFailureMsg(
17020 VK_DEBUG_REPORT_ERROR_BIT_EXT,
17021 "Formats MUST be IDENTICAL unless VK_IMAGE_CREATE_MUTABLE_FORMAT BIT was set on image creation.");
Tony Barbourd6673642016-05-05 14:46:39 -060017022 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
17023 m_errorMonitor->VerifyFound();
17024 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
17025
Tony Barbourd6673642016-05-05 14:46:39 -060017026 // Same compatibility class but no MUTABLE_FORMAT bit - Expect
17027 // VIEW_CREATE_ERROR
17028 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UINT;
Jeremy Hayes2ffbaa72017-03-14 17:05:50 -060017029 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02172);
Tony Barbourd6673642016-05-05 14:46:39 -060017030 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
17031 m_errorMonitor->VerifyFound();
17032 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
17033
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060017034 // TODO: Update framework to easily passing mutable flag into ImageObj init
17035 // For now just allowing image for this one test to not have memory bound
Jeremy Hayes5a7cf2e2017-01-06 15:23:27 -070017036 // TODO: The following line is preventing the intended validation from occurring because of the way the error monitor works.
17037 // m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17038 // " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Tony Barbourd6673642016-05-05 14:46:39 -060017039 // Have MUTABLE_FORMAT bit but not in same compatibility class - Expect
17040 // VIEW_CREATE_ERROR
17041 VkImageCreateInfo mutImgInfo = image.create_info();
17042 VkImage mutImage;
17043 mutImgInfo.format = VK_FORMAT_R8_UINT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017044 assert(m_device->format_properties(VK_FORMAT_R8_UINT).optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
Tony Barbourd6673642016-05-05 14:46:39 -060017045 mutImgInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
17046 mutImgInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Jeremy Hayes2ffbaa72017-03-14 17:05:50 -060017047 VkResult ret = vkCreateImage(m_device->handle(), &mutImgInfo, NULL, &mutImage);
Tony Barbourd6673642016-05-05 14:46:39 -060017048 ASSERT_VK_SUCCESS(ret);
Jeremy Hayes2ffbaa72017-03-14 17:05:50 -060017049
17050 VkMemoryRequirements requirements;
17051 vkGetImageMemoryRequirements(m_device->device(), mutImage, &requirements);
17052
17053 VkMemoryAllocateInfo alloc_info{};
17054 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17055 alloc_info.pNext = NULL;
17056 alloc_info.memoryTypeIndex = 0;
17057 alloc_info.allocationSize = requirements.size;
17058 bool pass = m_device->phy().set_memory_type(requirements.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
17059 ASSERT_TRUE(pass);
17060
17061 VkDeviceMemory memory;
17062 ret = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &memory);
17063 ASSERT_VK_SUCCESS(ret);
17064
17065 ret = vkBindImageMemory(m_device->device(), mutImage, memory, 0);
17066 ASSERT_VK_SUCCESS(ret);
17067
Tony Barbourd6673642016-05-05 14:46:39 -060017068 imgViewInfo.image = mutImage;
Jeremy Hayes2ffbaa72017-03-14 17:05:50 -060017069 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02171);
Tony Barbourd6673642016-05-05 14:46:39 -060017070 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
17071 m_errorMonitor->VerifyFound();
17072 imgViewInfo.image = image.handle();
Jeremy Hayes2ffbaa72017-03-14 17:05:50 -060017073
17074 vkFreeMemory(m_device->device(), memory, NULL);
Tony Barbourd6673642016-05-05 14:46:39 -060017075 vkDestroyImage(m_device->handle(), mutImage, NULL);
17076}
17077
Petr Kraus4d718682017-05-18 03:38:41 +020017078TEST_F(VkLayerTest, ImageViewSubresourceRangeTests) {
17079 TEST_DESCRIPTION("Passing bad image subrange to CreateImageView");
17080
17081 ASSERT_NO_FATAL_FAILURE(Init());
17082 auto depth_format = FindSupportedDepthStencilFormat(gpu());
17083 if (!depth_format) {
17084 return;
17085 }
17086
17087 VkImageObj image(m_device);
17088 image.Init(128, 128, 1, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
17089 VK_IMAGE_TILING_OPTIMAL, 0);
17090 ASSERT_TRUE(image.initialized());
17091
17092 VkImageView imgView;
17093 VkImageViewCreateInfo imgViewInfo = {};
17094 imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
17095 imgViewInfo.image = image.handle();
17096 imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
17097 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
17098 imgViewInfo.subresourceRange.layerCount = 1;
17099 imgViewInfo.subresourceRange.baseMipLevel = 0;
17100 imgViewInfo.subresourceRange.levelCount = 1;
17101 imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17102
17103 // View's levelCount can't be 0
17104 imgViewInfo.subresourceRange.levelCount = 0;
17105 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
17106 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
17107 m_errorMonitor->VerifyFound();
17108 imgViewInfo.subresourceRange.levelCount = 1;
17109
17110 // View can't have baseMipLevel >= image's mipLevels
17111 imgViewInfo.subresourceRange.baseMipLevel = 1;
17112 imgViewInfo.subresourceRange.levelCount = VK_REMAINING_MIP_LEVELS;
17113 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17114 "vkCreateImageView: pCreateInfo->subresourceRange.baseMipLevel (= 1) is greater or equal "
17115 "to the mip level count of the image (i.e. greater or equal to 1).");
17116 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
17117 m_errorMonitor->VerifyFound();
17118 imgViewInfo.subresourceRange.baseMipLevel = 0;
17119 imgViewInfo.subresourceRange.levelCount = 1;
17120
17121 // View can't have baseMipLevel >= image's mipLevels
17122 imgViewInfo.subresourceRange.baseMipLevel = 1;
17123 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
17124 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
17125 m_errorMonitor->VerifyFound();
17126 imgViewInfo.subresourceRange.baseMipLevel = 0;
17127
17128 // View's baseMipLevel + levelCount can't be > image's mipLevels
17129 imgViewInfo.subresourceRange.levelCount = 2;
17130 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
17131 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
17132 m_errorMonitor->VerifyFound();
17133 imgViewInfo.subresourceRange.levelCount = 1;
17134
17135 // View's layerCount can't be 0
17136 imgViewInfo.subresourceRange.layerCount = 0;
17137 m_errorMonitor->SetDesiredFailureMsg(
17138 VK_DEBUG_REPORT_ERROR_BIT_EXT,
17139 "if pCreateInfo->viewType is VK_IMAGE_TYPE_2D, pCreateInfo->subresourceRange.layerCount must be 1");
17140 // m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02931); // overlap with param_validation
17141 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
17142 m_errorMonitor->VerifyFound();
17143 imgViewInfo.subresourceRange.layerCount = 1;
17144
17145 // View can't have baseArrayLayer >= image's arraySize
17146 imgViewInfo.subresourceRange.baseArrayLayer = 1;
17147 imgViewInfo.subresourceRange.layerCount = VK_REMAINING_ARRAY_LAYERS;
17148 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17149 "vkCreateImageView: pCreateInfo->subresourceRange.baseArrayLayer (= 1) is greater or "
17150 "equal to the arrayLayers of the image when it was created (i.e. greater or equal to 1).");
17151 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
17152 m_errorMonitor->VerifyFound();
17153 imgViewInfo.subresourceRange.baseArrayLayer = 0;
17154 imgViewInfo.subresourceRange.layerCount = 1;
17155
17156 // View can't have baseArrayLayer >= image's arraySize
17157 imgViewInfo.subresourceRange.baseArrayLayer = 1;
17158 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02931);
17159 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
17160 m_errorMonitor->VerifyFound();
17161 imgViewInfo.subresourceRange.baseArrayLayer = 0;
17162
17163 // View's baseArrayLayer + layerCount can't be > image's arrayLayers
17164 imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D_ARRAY;
17165 imgViewInfo.subresourceRange.layerCount = 2;
17166 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02931);
17167 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
17168 m_errorMonitor->VerifyFound();
17169 imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
17170 imgViewInfo.subresourceRange.layerCount = 1;
17171
17172 // View's layerCount of 2D view has to be 1
17173 imgViewInfo.subresourceRange.layerCount = 2;
17174 m_errorMonitor->SetDesiredFailureMsg(
17175 VK_DEBUG_REPORT_ERROR_BIT_EXT,
17176 "if pCreateInfo->viewType is VK_IMAGE_TYPE_2D, pCreateInfo->subresourceRange.layerCount must be 1");
17177 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
17178 m_errorMonitor->VerifyFound();
17179 imgViewInfo.subresourceRange.layerCount = 1;
17180
17181 // TODO: should test maitenance1 3D -> 2D array view feature
17182}
17183
Dave Houlton75967fc2017-03-06 17:21:16 -070017184TEST_F(VkLayerTest, CompressedImageMipCopyTests) {
17185 TEST_DESCRIPTION("Image/Buffer copies for higher mip levels");
17186
Tony Barbour1fa09702017-03-16 12:09:08 -060017187 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton75967fc2017-03-06 17:21:16 -070017188
Jamie Madill35127872017-03-15 16:17:46 -040017189 VkPhysicalDeviceFeatures device_features = {};
Dave Houlton75967fc2017-03-06 17:21:16 -070017190 ASSERT_NO_FATAL_FAILURE(GetPhysicalDeviceFeatures(&device_features));
17191 VkFormat compressed_format = VK_FORMAT_UNDEFINED;
17192 if (device_features.textureCompressionBC) {
17193 compressed_format = VK_FORMAT_BC3_SRGB_BLOCK;
17194 } else if (device_features.textureCompressionETC2) {
17195 compressed_format = VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK;
17196 } else if (device_features.textureCompressionASTC_LDR) {
17197 compressed_format = VK_FORMAT_ASTC_4x4_UNORM_BLOCK;
17198 } else {
17199 printf(" No compressed formats supported - CompressedImageMipCopyTests skipped.\n");
17200 return;
17201 }
17202
17203 VkImageCreateInfo ci;
17204 ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17205 ci.pNext = NULL;
17206 ci.flags = 0;
17207 ci.imageType = VK_IMAGE_TYPE_2D;
17208 ci.format = compressed_format;
17209 ci.extent = {32, 32, 1};
17210 ci.mipLevels = 6;
17211 ci.arrayLayers = 1;
17212 ci.samples = VK_SAMPLE_COUNT_1_BIT;
17213 ci.tiling = VK_IMAGE_TILING_OPTIMAL;
17214 ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
17215 ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
17216 ci.queueFamilyIndexCount = 0;
17217 ci.pQueueFamilyIndices = NULL;
17218 ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
17219
17220 VkImageObj image(m_device);
17221 image.init(&ci);
17222 ASSERT_TRUE(image.initialized());
17223
17224 VkImageObj odd_image(m_device);
17225 ci.extent = {31, 32, 1}; // Mips are [31,32] [15,16] [7,8] [3,4], [1,2] [1,1]
17226 odd_image.init(&ci);
17227 ASSERT_TRUE(odd_image.initialized());
17228
17229 // Allocate buffers
17230 VkMemoryPropertyFlags reqs = 0;
17231 vk_testing::Buffer buffer_1024, buffer_64, buffer_16, buffer_8;
17232 buffer_1024.init_as_src_and_dst(*m_device, 1024, reqs);
17233 buffer_64.init_as_src_and_dst(*m_device, 64, reqs);
17234 buffer_16.init_as_src_and_dst(*m_device, 16, reqs);
17235 buffer_8.init_as_src_and_dst(*m_device, 8, reqs);
17236
17237 VkBufferImageCopy region = {};
17238 region.bufferRowLength = 0;
17239 region.bufferImageHeight = 0;
17240 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17241 region.imageSubresource.layerCount = 1;
17242 region.imageOffset = {0, 0, 0};
17243 region.bufferOffset = 0;
17244
17245 // start recording
17246 m_commandBuffer->BeginCommandBuffer();
17247
17248 // Mip level copies that work - 5 levels
17249 m_errorMonitor->ExpectSuccess();
17250
17251 // Mip 0 should fit in 1k buffer - 1k texels @ 1b each
17252 region.imageExtent = {32, 32, 1};
17253 region.imageSubresource.mipLevel = 0;
17254 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_1024.handle(), 1,
17255 &region);
17256 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_1024.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17257 &region);
17258
17259 // Mip 2 should fit in 64b buffer - 64 texels @ 1b each
17260 region.imageExtent = {8, 8, 1};
17261 region.imageSubresource.mipLevel = 2;
17262 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_64.handle(), 1,
17263 &region);
17264 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17265 &region);
17266
17267 // Mip 3 should fit in 16b buffer - 16 texels @ 1b each
17268 region.imageExtent = {4, 4, 1};
17269 region.imageSubresource.mipLevel = 3;
17270 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
17271 &region);
17272 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17273 &region);
17274
17275 // Mip 4&5 should fit in 16b buffer with no complaint - 4 & 1 texels @ 1b each
17276 region.imageExtent = {2, 2, 1};
17277 region.imageSubresource.mipLevel = 4;
17278 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
17279 &region);
17280 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17281 &region);
17282
17283 region.imageExtent = {1, 1, 1};
17284 region.imageSubresource.mipLevel = 5;
17285 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
17286 &region);
17287 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17288 &region);
17289 m_errorMonitor->VerifyNotFound();
17290
17291 // Buffer must accomodate a full compressed block, regardless of texel count
17292 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01246);
17293 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_8.handle(), 1,
17294 &region);
17295 m_errorMonitor->VerifyFound();
17296 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01227);
17297 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_8.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17298 &region);
17299 m_errorMonitor->VerifyFound();
17300
17301 // Copy width < compressed block size, but not the full mip width
17302 region.imageExtent = {1, 2, 1};
17303 region.imageSubresource.mipLevel = 4;
17304 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01275);
17305 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
17306 &region);
17307 m_errorMonitor->VerifyFound();
17308 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01275);
17309 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17310 &region);
17311 m_errorMonitor->VerifyFound();
17312
17313 // Copy height < compressed block size but not the full mip height
17314 region.imageExtent = {2, 1, 1};
17315 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01276);
17316 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
17317 &region);
17318 m_errorMonitor->VerifyFound();
17319 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01276);
17320 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17321 &region);
17322 m_errorMonitor->VerifyFound();
17323
17324 // Offsets must be multiple of compressed block size
17325 region.imageOffset = {1, 1, 0};
17326 region.imageExtent = {1, 1, 1};
17327 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01273);
17328 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
17329 &region);
17330 m_errorMonitor->VerifyFound();
17331 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01273);
17332 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17333 &region);
17334 m_errorMonitor->VerifyFound();
17335
17336 // Offset + extent width = mip width - should succeed
17337 region.imageOffset = {4, 4, 0};
17338 region.imageExtent = {3, 4, 1};
17339 region.imageSubresource.mipLevel = 2;
17340 m_errorMonitor->ExpectSuccess();
17341 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), odd_image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
17342 &region);
17343 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), odd_image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17344 &region);
17345 m_errorMonitor->VerifyNotFound();
17346
17347 // Offset + extent width > mip width, but still within the final compressed block - should succeed
17348 region.imageExtent = {4, 4, 1};
17349 m_errorMonitor->ExpectSuccess();
17350 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), odd_image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
17351 &region);
17352 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), odd_image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17353 &region);
17354 m_errorMonitor->VerifyNotFound();
17355
17356 // Offset + extent width < mip width and not a multiple of block width - should fail
17357 region.imageExtent = {3, 3, 1};
17358 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01276);
17359 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), odd_image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
17360 &region);
17361 m_errorMonitor->VerifyFound();
17362 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01276);
17363 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), odd_image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17364 &region);
17365 m_errorMonitor->VerifyFound();
17366}
17367
Dave Houlton59a20702017-02-02 17:26:23 -070017368TEST_F(VkLayerTest, ImageBufferCopyTests) {
17369 TEST_DESCRIPTION("Image to buffer and buffer to image tests");
17370
Tony Barbour1fa09702017-03-16 12:09:08 -060017371 ASSERT_NO_FATAL_FAILURE(Init());
Tony Barbourf887b162017-03-09 10:06:46 -070017372 VkFormatProperties format_props = m_device->format_properties(VK_FORMAT_D24_UNORM_S8_UINT);
17373 if (!(format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT)) {
17374 printf(" VK_FORMAT_D24_UNORM_S8_UINT not supported. Skipped.\n");
17375 return;
17376 }
Dave Houlton584d51e2017-02-16 12:52:54 -070017377
17378 // Bail if any dimension of transfer granularity is 0.
17379 auto index = m_device->graphics_queue_node_index_;
17380 auto queue_family_properties = m_device->phy().queue_properties();
17381 if ((queue_family_properties[index].minImageTransferGranularity.depth == 0) ||
17382 (queue_family_properties[index].minImageTransferGranularity.width == 0) ||
17383 (queue_family_properties[index].minImageTransferGranularity.height == 0)) {
17384 printf(" Subresource copies are disallowed when xfer granularity (x|y|z) is 0. Skipped.\n");
17385 return;
17386 }
17387
Dave Houlton59a20702017-02-02 17:26:23 -070017388 VkImageObj image_64k(m_device); // 128^2 texels, 64k
17389 VkImageObj image_16k(m_device); // 64^2 texels, 16k
17390 VkImageObj image_16k_depth(m_device); // 64^2 texels, depth, 16k
Dave Houltonf3229d52017-02-21 15:59:08 -070017391 VkImageObj ds_image_4D_1S(m_device); // 256^2 texels, 512kb (256k depth, 64k stencil, 192k pack)
17392 VkImageObj ds_image_3D_1S(m_device); // 256^2 texels, 256kb (192k depth, 64k stencil)
17393 VkImageObj ds_image_2D(m_device); // 256^2 texels, 128k (128k depth)
17394 VkImageObj ds_image_1S(m_device); // 256^2 texels, 64k (64k stencil)
17395
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017396 image_64k.Init(128, 128, 1, VK_FORMAT_R8G8B8A8_UINT,
Dave Houlton59a20702017-02-02 17:26:23 -070017397 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
17398 VK_IMAGE_TILING_OPTIMAL, 0);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017399 image_16k.Init(64, 64, 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_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 -070017403 VK_IMAGE_TILING_OPTIMAL, 0);
Dave Houlton59a20702017-02-02 17:26:23 -070017404 ASSERT_TRUE(image_64k.initialized());
17405 ASSERT_TRUE(image_16k.initialized());
17406 ASSERT_TRUE(image_16k_depth.initialized());
Dave Houlton59a20702017-02-02 17:26:23 -070017407
Dave Houltonf3229d52017-02-21 15:59:08 -070017408 // Verify all needed Depth/Stencil formats are supported
17409 bool missing_ds_support = false;
17410 VkFormatProperties props = {0, 0, 0};
17411 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D32_SFLOAT_S8_UINT, &props);
17412 missing_ds_support |= (props.bufferFeatures == 0 && props.linearTilingFeatures == 0 && props.optimalTilingFeatures == 0);
17413 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D24_UNORM_S8_UINT, &props);
17414 missing_ds_support |= (props.bufferFeatures == 0 && props.linearTilingFeatures == 0 && props.optimalTilingFeatures == 0);
17415 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D16_UNORM, &props);
17416 missing_ds_support |= (props.bufferFeatures == 0 && props.linearTilingFeatures == 0 && props.optimalTilingFeatures == 0);
17417 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_S8_UINT, &props);
17418 missing_ds_support |= (props.bufferFeatures == 0 && props.linearTilingFeatures == 0 && props.optimalTilingFeatures == 0);
17419
17420 if (!missing_ds_support) {
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017421 ds_image_4D_1S.Init(
17422 256, 256, 1, VK_FORMAT_D32_SFLOAT_S8_UINT,
Dave Houltonf3229d52017-02-21 15:59:08 -070017423 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
17424 VK_IMAGE_TILING_OPTIMAL, 0);
17425 ASSERT_TRUE(ds_image_4D_1S.initialized());
17426
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017427 ds_image_3D_1S.Init(
17428 256, 256, 1, VK_FORMAT_D24_UNORM_S8_UINT,
Dave Houltonf3229d52017-02-21 15:59:08 -070017429 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
17430 VK_IMAGE_TILING_OPTIMAL, 0);
17431 ASSERT_TRUE(ds_image_3D_1S.initialized());
17432
Dave Houlton11dcd5e2017-04-25 16:00:10 -060017433 ds_image_2D.Init(
17434 256, 256, 1, VK_FORMAT_D16_UNORM,
17435 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
17436 VK_IMAGE_TILING_OPTIMAL, 0);
Dave Houltonf3229d52017-02-21 15:59:08 -070017437 ASSERT_TRUE(ds_image_2D.initialized());
17438
Dave Houlton11dcd5e2017-04-25 16:00:10 -060017439 ds_image_1S.Init(
17440 256, 256, 1, VK_FORMAT_S8_UINT,
17441 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
17442 VK_IMAGE_TILING_OPTIMAL, 0);
Dave Houltonf3229d52017-02-21 15:59:08 -070017443 ASSERT_TRUE(ds_image_1S.initialized());
17444 }
17445
17446 // Allocate buffers
17447 vk_testing::Buffer buffer_256k, buffer_128k, buffer_64k, buffer_16k;
Dave Houlton59a20702017-02-02 17:26:23 -070017448 VkMemoryPropertyFlags reqs = 0;
Dave Houltonf3229d52017-02-21 15:59:08 -070017449 buffer_256k.init_as_src_and_dst(*m_device, 262144, reqs); // 256k
17450 buffer_128k.init_as_src_and_dst(*m_device, 131072, reqs); // 128k
17451 buffer_64k.init_as_src_and_dst(*m_device, 65536, reqs); // 64k
17452 buffer_16k.init_as_src_and_dst(*m_device, 16384, reqs); // 16k
Dave Houlton59a20702017-02-02 17:26:23 -070017453
17454 VkBufferImageCopy region = {};
17455 region.bufferRowLength = 0;
17456 region.bufferImageHeight = 0;
17457 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17458 region.imageSubresource.layerCount = 1;
17459 region.imageOffset = {0, 0, 0};
17460 region.imageExtent = {64, 64, 1};
17461 region.bufferOffset = 0;
17462
17463 // attempt copies before putting command buffer in recording state
17464 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01240);
17465 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64k.handle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17466 &region);
17467 m_errorMonitor->VerifyFound();
17468
17469 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01258);
17470 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_64k.handle(), 1,
17471 &region);
17472 m_errorMonitor->VerifyFound();
17473
17474 // start recording
17475 m_commandBuffer->BeginCommandBuffer();
17476
17477 // successful copies
17478 m_errorMonitor->ExpectSuccess();
17479 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
17480 &region);
17481 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16k.handle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17482 &region);
17483 region.imageOffset.x = 16; // 16k copy, offset requires larger image
17484 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
17485 &region);
17486 region.imageExtent.height = 78; // > 16k copy requires larger buffer & image
17487 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64k.handle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17488 &region);
17489 region.imageOffset.x = 0;
17490 region.imageExtent.height = 64;
17491 region.bufferOffset = 256; // 16k copy with buffer offset, requires larger buffer
17492 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_64k.handle(), 1,
17493 &region);
17494 m_errorMonitor->VerifyNotFound();
17495
Dave Houlton9dae7ec2017-03-01 16:23:25 -070017496 // image/buffer too small (extent too large) on copy to image
Dave Houlton59a20702017-02-02 17:26:23 -070017497 region.imageExtent = {65, 64, 1};
17498 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01227); // buffer too small
17499 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16k.handle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17500 &region);
17501 m_errorMonitor->VerifyFound();
17502
17503 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01228); // image too small
17504 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64k.handle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17505 &region);
17506 m_errorMonitor->VerifyFound();
17507
17508 // image/buffer too small (offset) on copy to image
17509 region.imageExtent = {64, 64, 1};
17510 region.imageOffset = {0, 4, 0};
17511 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01227); // buffer too small
17512 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16k.handle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17513 &region);
17514 m_errorMonitor->VerifyFound();
17515
17516 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01228); // image too small
17517 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64k.handle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17518 &region);
17519 m_errorMonitor->VerifyFound();
17520
17521 // image/buffer too small on copy to buffer
17522 region.imageExtent = {64, 64, 1};
17523 region.imageOffset = {0, 0, 0};
Mark Lobodzinski80871462017-02-16 10:37:27 -070017524 region.bufferOffset = 4;
Dave Houlton59a20702017-02-02 17:26:23 -070017525 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01246); // buffer too small
17526 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
17527 &region);
17528 m_errorMonitor->VerifyFound();
17529
17530 region.imageExtent = {64, 65, 1};
17531 region.bufferOffset = 0;
17532 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01245); // image too small
17533 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_64k.handle(), 1,
17534 &region);
17535 m_errorMonitor->VerifyFound();
17536
17537 // buffer size ok but rowlength causes loose packing
17538 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01246);
17539 region.imageExtent = {64, 64, 1};
17540 region.bufferRowLength = 68;
17541 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
17542 &region);
17543 m_errorMonitor->VerifyFound();
17544
Dave Houlton9dae7ec2017-03-01 16:23:25 -070017545 // An extent with zero area should produce a warning, but no error
17546 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT | VK_DEBUG_REPORT_ERROR_BIT_EXT, "} has zero area");
17547 region.imageExtent.width = 0;
17548 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
17549 &region);
17550 m_errorMonitor->VerifyFound();
17551
Dave Houlton59a20702017-02-02 17:26:23 -070017552 // aspect bits
17553 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01280); // more than 1 aspect bit set
17554 region.imageExtent = {64, 64, 1};
17555 region.bufferRowLength = 0;
17556 region.bufferImageHeight = 0;
17557 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
17558 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_depth.handle(), VK_IMAGE_LAYOUT_GENERAL,
17559 buffer_16k.handle(), 1, &region);
17560 m_errorMonitor->VerifyFound();
17561
17562 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01279); // mis-matched aspect
17563 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
17564 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
17565 &region);
17566 m_errorMonitor->VerifyFound();
17567
17568 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01279); // different mis-matched aspect
17569 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17570 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_depth.handle(), VK_IMAGE_LAYOUT_GENERAL,
17571 buffer_16k.handle(), 1, &region);
17572 m_errorMonitor->VerifyFound();
17573
Dave Houltonf3229d52017-02-21 15:59:08 -070017574 // Test Depth/Stencil copies
17575 if (missing_ds_support) {
17576 printf(" Depth / Stencil formats unsupported - skipping D/S tests.\n");
17577 } else {
17578 VkBufferImageCopy ds_region = {};
17579 ds_region.bufferOffset = 0;
17580 ds_region.bufferRowLength = 0;
17581 ds_region.bufferImageHeight = 0;
17582 ds_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
17583 ds_region.imageSubresource.mipLevel = 0;
17584 ds_region.imageSubresource.baseArrayLayer = 0;
17585 ds_region.imageSubresource.layerCount = 1;
17586 ds_region.imageOffset = {0, 0, 0};
17587 ds_region.imageExtent = {256, 256, 1};
17588
17589 // Depth copies that should succeed
17590 m_errorMonitor->ExpectSuccess(); // Extract 4b depth per texel, pack into 256k buffer
17591 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_4D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
17592 buffer_256k.handle(), 1, &ds_region);
17593 m_errorMonitor->VerifyNotFound();
17594
17595 m_errorMonitor->ExpectSuccess(); // Extract 3b depth per texel, pack (loose) into 256k buffer
17596 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_3D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
17597 buffer_256k.handle(), 1, &ds_region);
17598 m_errorMonitor->VerifyNotFound();
17599
17600 m_errorMonitor->ExpectSuccess(); // Copy 2b depth per texel, into 128k buffer
17601 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_2D.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
17602 buffer_128k.handle(), 1, &ds_region);
17603 m_errorMonitor->VerifyNotFound();
17604
17605 // Depth copies that should fail
17606 ds_region.bufferOffset = 4;
17607 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17608 VALIDATION_ERROR_01246); // Extract 4b depth per texel, pack into 256k buffer
17609 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_4D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
17610 buffer_256k.handle(), 1, &ds_region);
17611 m_errorMonitor->VerifyFound();
17612
17613 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17614 VALIDATION_ERROR_01246); // Extract 3b depth per texel, pack (loose) into 256k buffer
17615 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_3D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
17616 buffer_256k.handle(), 1, &ds_region);
17617 m_errorMonitor->VerifyFound();
17618
17619 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17620 VALIDATION_ERROR_01246); // Copy 2b depth per texel, into 128k buffer
17621 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_2D.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
17622 buffer_128k.handle(), 1, &ds_region);
17623 m_errorMonitor->VerifyFound();
17624
17625 // Stencil copies that should succeed
17626 ds_region.bufferOffset = 0;
17627 ds_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT;
17628 m_errorMonitor->ExpectSuccess(); // Extract 1b stencil per texel, pack into 64k buffer
17629 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_4D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
17630 buffer_64k.handle(), 1, &ds_region);
17631 m_errorMonitor->VerifyNotFound();
17632
17633 m_errorMonitor->ExpectSuccess(); // Extract 1b stencil per texel, pack into 64k buffer
17634 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_3D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
17635 buffer_64k.handle(), 1, &ds_region);
17636 m_errorMonitor->VerifyNotFound();
17637
17638 m_errorMonitor->ExpectSuccess(); // Copy 1b depth per texel, into 64k buffer
17639 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
17640 buffer_64k.handle(), 1, &ds_region);
17641 m_errorMonitor->VerifyNotFound();
17642
17643 // Stencil copies that should fail
17644 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17645 VALIDATION_ERROR_01246); // Extract 1b stencil per texel, pack into 64k buffer
17646 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_4D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
17647 buffer_16k.handle(), 1, &ds_region);
17648 m_errorMonitor->VerifyFound();
17649
17650 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17651 VALIDATION_ERROR_01246); // Extract 1b stencil per texel, pack into 64k buffer
17652 ds_region.bufferRowLength = 260;
17653 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_3D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
17654 buffer_64k.handle(), 1, &ds_region);
17655 m_errorMonitor->VerifyFound();
17656
17657 ds_region.bufferRowLength = 0;
17658 ds_region.bufferOffset = 4;
17659 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17660 VALIDATION_ERROR_01246); // Copy 1b depth per texel, into 64k buffer
17661 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
17662 buffer_64k.handle(), 1, &ds_region);
17663 m_errorMonitor->VerifyFound();
17664 }
17665
Dave Houlton584d51e2017-02-16 12:52:54 -070017666 // Test compressed formats, if supported
Jamie Madill35127872017-03-15 16:17:46 -040017667 VkPhysicalDeviceFeatures device_features = {};
Dave Houlton584d51e2017-02-16 12:52:54 -070017668 ASSERT_NO_FATAL_FAILURE(GetPhysicalDeviceFeatures(&device_features));
Dave Houltonf3229d52017-02-21 15:59:08 -070017669 if (!(device_features.textureCompressionBC || device_features.textureCompressionETC2 ||
17670 device_features.textureCompressionASTC_LDR)) {
17671 printf(" No compressed formats supported - block compression tests skipped.\n");
17672 } else {
Dave Houlton67e9b532017-03-02 17:00:10 -070017673 VkImageObj image_16k_4x4comp(m_device); // 128^2 texels as 32^2 compressed (4x4) blocks, 16k
17674 VkImageObj image_NPOT_4x4comp(m_device); // 130^2 texels as 33^2 compressed (4x4) blocks
Dave Houlton584d51e2017-02-16 12:52:54 -070017675 if (device_features.textureCompressionBC) {
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017676 image_16k_4x4comp.Init(128, 128, 1, VK_FORMAT_BC3_SRGB_BLOCK, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_OPTIMAL,
17677 0);
17678 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 -070017679 0);
Dave Houlton584d51e2017-02-16 12:52:54 -070017680 } else if (device_features.textureCompressionETC2) {
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017681 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 -070017682 VK_IMAGE_TILING_OPTIMAL, 0);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017683 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 -070017684 VK_IMAGE_TILING_OPTIMAL, 0);
Dave Houlton584d51e2017-02-16 12:52:54 -070017685 } else {
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017686 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 -070017687 VK_IMAGE_TILING_OPTIMAL, 0);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017688 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 -070017689 VK_IMAGE_TILING_OPTIMAL, 0);
Dave Houlton584d51e2017-02-16 12:52:54 -070017690 }
17691 ASSERT_TRUE(image_16k_4x4comp.initialized());
Dave Houlton59a20702017-02-02 17:26:23 -070017692
Dave Houlton584d51e2017-02-16 12:52:54 -070017693 // Just fits
17694 m_errorMonitor->ExpectSuccess();
17695 region.imageExtent = {128, 128, 1};
17696 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
17697 buffer_16k.handle(), 1, &region);
17698 m_errorMonitor->VerifyNotFound();
Dave Houlton59a20702017-02-02 17:26:23 -070017699
Dave Houlton584d51e2017-02-16 12:52:54 -070017700 // with offset, too big for buffer
17701 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01246);
17702 region.bufferOffset = 16;
17703 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
17704 buffer_16k.handle(), 1, &region);
17705 m_errorMonitor->VerifyFound();
Dave Houlton67e9b532017-03-02 17:00:10 -070017706 region.bufferOffset = 0;
Dave Houlton59a20702017-02-02 17:26:23 -070017707
Dave Houlton67e9b532017-03-02 17:00:10 -070017708 // extents that are not a multiple of compressed block size
17709 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01275);
17710 region.imageExtent.width = 66;
17711 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_NPOT_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
17712 buffer_16k.handle(), 1, &region);
17713 m_errorMonitor->VerifyFound();
17714 region.imageExtent.width = 128;
17715
17716 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01276);
Dave Houlton9dae7ec2017-03-01 16:23:25 -070017717 region.imageExtent.height = 2;
Dave Houlton67e9b532017-03-02 17:00:10 -070017718 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_NPOT_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
17719 buffer_16k.handle(), 1, &region);
17720 m_errorMonitor->VerifyFound();
17721 region.imageExtent.height = 128;
17722
17723 // TODO: All available compressed formats are 2D, with block depth of 1. Unable to provoke VU_01277.
17724
17725 // non-multiple extents are allowed if at the far edge of a non-block-multiple image - these should pass
17726 m_errorMonitor->ExpectSuccess();
17727 region.imageExtent.width = 66;
17728 region.imageOffset.x = 64;
17729 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_NPOT_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
17730 buffer_16k.handle(), 1, &region);
17731 region.imageExtent.width = 16;
17732 region.imageOffset.x = 0;
17733 region.imageExtent.height = 2;
17734 region.imageOffset.y = 128;
17735 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_NPOT_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
Dave Houlton9dae7ec2017-03-01 16:23:25 -070017736 buffer_16k.handle(), 1, &region);
17737 m_errorMonitor->VerifyNotFound();
Dave Houlton67e9b532017-03-02 17:00:10 -070017738 region.imageOffset = {0, 0, 0};
Dave Houlton9dae7ec2017-03-01 16:23:25 -070017739
Dave Houlton584d51e2017-02-16 12:52:54 -070017740 // buffer offset must be a multiple of texel block size (16)
17741 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01274);
17742 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01263);
17743 region.imageExtent = {64, 64, 1};
17744 region.bufferOffset = 24;
17745 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
17746 buffer_16k.handle(), 1, &region);
17747 m_errorMonitor->VerifyFound();
Dave Houlton59a20702017-02-02 17:26:23 -070017748
Dave Houlton584d51e2017-02-16 12:52:54 -070017749 // rowlength not a multiple of block width (4)
17750 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01271);
17751 region.bufferOffset = 0;
17752 region.bufferRowLength = 130;
17753 region.bufferImageHeight = 0;
17754 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
17755 buffer_64k.handle(), 1, &region);
17756 m_errorMonitor->VerifyFound();
Dave Houlton59a20702017-02-02 17:26:23 -070017757
Dave Houlton584d51e2017-02-16 12:52:54 -070017758 // imageheight not a multiple of block height (4)
17759 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01272);
17760 region.bufferRowLength = 0;
17761 region.bufferImageHeight = 130;
17762 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
17763 buffer_64k.handle(), 1, &region);
17764 m_errorMonitor->VerifyFound();
Dave Houlton584d51e2017-02-16 12:52:54 -070017765 }
Dave Houlton59a20702017-02-02 17:26:23 -070017766}
17767
Tony Barbourd6673642016-05-05 14:46:39 -060017768TEST_F(VkLayerTest, MiscImageLayerTests) {
Mark Lobodzinskie6911292017-02-15 14:38:51 -070017769 TEST_DESCRIPTION("Image-related tests that don't belong elsewhare");
Tony Barbourd6673642016-05-05 14:46:39 -060017770
Tony Barbour1fa09702017-03-16 12:09:08 -060017771 ASSERT_NO_FATAL_FAILURE(Init());
Tony Barbourd6673642016-05-05 14:46:39 -060017772
Rene Lindsay135204f2016-12-22 17:11:09 -070017773 // TODO: Ideally we should check if a format is supported, before using it.
Tony Barbourd6673642016-05-05 14:46:39 -060017774 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017775 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 -070017776 VK_IMAGE_TILING_OPTIMAL, 0); // 64bpp
Tony Barbourd6673642016-05-05 14:46:39 -060017777 ASSERT_TRUE(image.initialized());
Tony Barbourd6673642016-05-05 14:46:39 -060017778 vk_testing::Buffer buffer;
17779 VkMemoryPropertyFlags reqs = 0;
Rene Lindsay135204f2016-12-22 17:11:09 -070017780 buffer.init_as_src(*m_device, 128 * 128 * 8, reqs);
Tony Barbourd6673642016-05-05 14:46:39 -060017781 VkBufferImageCopy region = {};
17782 region.bufferRowLength = 128;
17783 region.bufferImageHeight = 128;
17784 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17785 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
Mark Lobodzinski3702e932016-11-22 11:40:48 -070017786 region.imageSubresource.layerCount = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060017787 region.imageExtent.height = 4;
17788 region.imageExtent.width = 4;
17789 region.imageExtent.depth = 1;
Rene Lindsay135204f2016-12-22 17:11:09 -070017790
17791 VkImageObj image2(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017792 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 -070017793 VK_IMAGE_TILING_OPTIMAL, 0); // 16bpp
Rene Lindsay135204f2016-12-22 17:11:09 -070017794 ASSERT_TRUE(image2.initialized());
17795 vk_testing::Buffer buffer2;
17796 VkMemoryPropertyFlags reqs2 = 0;
17797 buffer2.init_as_src(*m_device, 128 * 128 * 2, reqs2);
17798 VkBufferImageCopy region2 = {};
17799 region2.bufferRowLength = 128;
17800 region2.bufferImageHeight = 128;
17801 region2.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17802 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
17803 region2.imageSubresource.layerCount = 1;
17804 region2.imageExtent.height = 4;
17805 region2.imageExtent.width = 4;
17806 region2.imageExtent.depth = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060017807 m_commandBuffer->BeginCommandBuffer();
Tony Barbourd6673642016-05-05 14:46:39 -060017808
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070017809 // Image must have offset.z of 0 and extent.depth of 1
17810 // Introduce failure by setting imageExtent.depth to 0
17811 region.imageExtent.depth = 0;
Dave Houlton59a20702017-02-02 17:26:23 -070017812 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01747);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070017813 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017814 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070017815 m_errorMonitor->VerifyFound();
17816
17817 region.imageExtent.depth = 1;
17818
17819 // Image must have offset.z of 0 and extent.depth of 1
17820 // Introduce failure by setting imageOffset.z to 4
Dave Houlton9dae7ec2017-03-01 16:23:25 -070017821 // Note: Also (unavoidably) triggers 'region exceeds image' #1228
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070017822 region.imageOffset.z = 4;
Dave Houlton59a20702017-02-02 17:26:23 -070017823 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01747);
Dave Houlton9dae7ec2017-03-01 16:23:25 -070017824 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01228);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070017825 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017826 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070017827 m_errorMonitor->VerifyFound();
17828
17829 region.imageOffset.z = 0;
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060017830 // BufferOffset must be a multiple of the calling command's VkImage parameter's texel size
17831 // Introduce failure by setting bufferOffset to 1 and 1/2 texels
Rene Lindsay135204f2016-12-22 17:11:09 -070017832 region.bufferOffset = 4;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070017833 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01263);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017834 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
17835 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060017836 m_errorMonitor->VerifyFound();
17837
17838 // BufferOffset must be a multiple of 4
17839 // Introduce failure by setting bufferOffset to a value not divisible by 4
Rene Lindsay135204f2016-12-22 17:11:09 -070017840 region2.bufferOffset = 6;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070017841 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01264);
Rene Lindsay135204f2016-12-22 17:11:09 -070017842 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer2.handle(), image2.handle(),
17843 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region2);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060017844 m_errorMonitor->VerifyFound();
17845
17846 // BufferRowLength must be 0, or greater than or equal to the width member of imageExtent
17847 region.bufferOffset = 0;
17848 region.imageExtent.height = 128;
17849 region.imageExtent.width = 128;
17850 // Introduce failure by setting bufferRowLength > 0 but less than width
17851 region.bufferRowLength = 64;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070017852 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01265);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017853 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
17854 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060017855 m_errorMonitor->VerifyFound();
17856
17857 // BufferImageHeight must be 0, or greater than or equal to the height member of imageExtent
17858 region.bufferRowLength = 128;
17859 // Introduce failure by setting bufferRowHeight > 0 but less than height
17860 region.bufferImageHeight = 64;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070017861 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01266);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017862 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
17863 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060017864 m_errorMonitor->VerifyFound();
17865
17866 region.bufferImageHeight = 128;
Tony Barbourd6673642016-05-05 14:46:39 -060017867 VkImageObj intImage1(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017868 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 -070017869 VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbourd6673642016-05-05 14:46:39 -060017870 VkImageObj intImage2(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017871 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 -070017872 VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbourd6673642016-05-05 14:46:39 -060017873 VkImageBlit blitRegion = {};
17874 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17875 blitRegion.srcSubresource.baseArrayLayer = 0;
17876 blitRegion.srcSubresource.layerCount = 1;
17877 blitRegion.srcSubresource.mipLevel = 0;
17878 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17879 blitRegion.dstSubresource.baseArrayLayer = 0;
17880 blitRegion.dstSubresource.layerCount = 1;
17881 blitRegion.dstSubresource.mipLevel = 0;
17882
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060017883 // Look for NULL-blit warning
Jeremy Hayesf8e749f2017-03-15 09:40:27 -060017884 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
17885 "vkCmdBlitImage: pRegions[0].srcOffsets specify a zero-volume area.");
17886 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
17887 "vkCmdBlitImage: pRegions[0].dstOffsets specify a zero-volume area.");
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017888 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.Layout(), intImage2.handle(),
17889 intImage2.Layout(), 1, &blitRegion, VK_FILTER_LINEAR);
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060017890 m_errorMonitor->VerifyFound();
17891
Petr Kraus4d718682017-05-18 03:38:41 +020017892 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02931);
Tony Barbourd6673642016-05-05 14:46:39 -060017893 VkImageMemoryBarrier img_barrier;
17894 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
17895 img_barrier.pNext = NULL;
17896 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
17897 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
17898 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
17899 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
17900 img_barrier.image = image.handle();
17901 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
17902 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
17903 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17904 img_barrier.subresourceRange.baseArrayLayer = 0;
17905 img_barrier.subresourceRange.baseMipLevel = 0;
Tony Barbourd6673642016-05-05 14:46:39 -060017906 img_barrier.subresourceRange.layerCount = 0;
17907 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017908 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
17909 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbourd6673642016-05-05 14:46:39 -060017910 m_errorMonitor->VerifyFound();
17911 img_barrier.subresourceRange.layerCount = 1;
17912}
17913
17914TEST_F(VkLayerTest, ImageFormatLimits) {
Tony Barbourd6673642016-05-05 14:46:39 -060017915 TEST_DESCRIPTION("Exceed the limits of image format ");
17916
Tony Barbour1fa09702017-03-16 12:09:08 -060017917 ASSERT_NO_FATAL_FAILURE(Init());
Jeremy Hayesbb63cc12017-03-20 15:33:01 -060017918
17919 VkFormat const format = VK_FORMAT_B8G8R8A8_UNORM;
17920 {
17921 VkFormatProperties properties;
17922 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), format, &properties);
17923 if (properties.linearTilingFeatures == 0) {
17924 printf(" Image format not supported; skipped.\n");
17925 return;
17926 }
17927 }
17928
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017929 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Tony Barbourd6673642016-05-05 14:46:39 -060017930 VkImageCreateInfo image_create_info = {};
17931 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17932 image_create_info.pNext = NULL;
17933 image_create_info.imageType = VK_IMAGE_TYPE_2D;
Jeremy Hayesbb63cc12017-03-20 15:33:01 -060017934 image_create_info.format = format;
Tony Barbourd6673642016-05-05 14:46:39 -060017935 image_create_info.extent.width = 32;
17936 image_create_info.extent.height = 32;
17937 image_create_info.extent.depth = 1;
17938 image_create_info.mipLevels = 1;
17939 image_create_info.arrayLayers = 1;
17940 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
17941 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
17942 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
17943 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
17944 image_create_info.flags = 0;
17945
17946 VkImage nullImg;
17947 VkImageFormatProperties imgFmtProps;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017948 vkGetPhysicalDeviceImageFormatProperties(gpu(), image_create_info.format, image_create_info.imageType, image_create_info.tiling,
17949 image_create_info.usage, image_create_info.flags, &imgFmtProps);
Rene Lindsayef5bc012017-01-06 15:38:00 -070017950 image_create_info.extent.width = imgFmtProps.maxExtent.width + 1;
Tony Barbourd6673642016-05-05 14:46:39 -060017951 // Expect INVALID_FORMAT_LIMITS_VIOLATION
17952 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
17953 m_errorMonitor->VerifyFound();
Rene Lindsayef5bc012017-01-06 15:38:00 -070017954 image_create_info.extent.width = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060017955
Tony Barbour0907e362017-03-09 15:05:30 -070017956 uint32_t maxDim =
17957 std::max(std::max(image_create_info.extent.width, image_create_info.extent.height), image_create_info.extent.depth);
17958 // If max mip levels exceeds image extents, skip the max mip levels test
17959 if ((imgFmtProps.maxMipLevels + 1) <= (floor(log2(maxDim)) + 1)) {
17960 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
17961 image_create_info.mipLevels = imgFmtProps.maxMipLevels + 1;
17962 // Expect INVALID_FORMAT_LIMITS_VIOLATION
17963 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
17964 m_errorMonitor->VerifyFound();
17965 image_create_info.mipLevels = 1;
17966 }
Tony Barbourd6673642016-05-05 14:46:39 -060017967
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017968 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060017969 image_create_info.arrayLayers = imgFmtProps.maxArrayLayers + 1;
17970 // Expect INVALID_FORMAT_LIMITS_VIOLATION
17971 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
17972 m_errorMonitor->VerifyFound();
17973 image_create_info.arrayLayers = 1;
17974
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017975 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is not supported by format");
Tony Barbourd6673642016-05-05 14:46:39 -060017976 int samples = imgFmtProps.sampleCounts >> 1;
17977 image_create_info.samples = (VkSampleCountFlagBits)samples;
17978 // Expect INVALID_FORMAT_LIMITS_VIOLATION
17979 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
17980 m_errorMonitor->VerifyFound();
17981 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
17982
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017983 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17984 "pCreateInfo->initialLayout, must be "
17985 "VK_IMAGE_LAYOUT_UNDEFINED or "
17986 "VK_IMAGE_LAYOUT_PREINITIALIZED");
Tony Barbourd6673642016-05-05 14:46:39 -060017987 image_create_info.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
17988 // Expect INVALID_LAYOUT
17989 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
17990 m_errorMonitor->VerifyFound();
17991 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
17992}
17993
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017994TEST_F(VkLayerTest, CopyImageSrcSizeExceeded) {
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017995 // Image copy with source region specified greater than src image size
Tony Barbour1fa09702017-03-16 12:09:08 -060017996 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017997
Dave Houltonfc1a4052017-04-27 14:32:45 -060017998 // Create images with full mip chain
17999 VkImageCreateInfo ci;
18000 ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
18001 ci.pNext = NULL;
18002 ci.flags = 0;
18003 ci.imageType = VK_IMAGE_TYPE_3D;
18004 ci.format = VK_FORMAT_R8G8B8A8_UNORM;
18005 ci.extent = {32, 32, 8};
18006 ci.mipLevels = 6;
18007 ci.arrayLayers = 1;
18008 ci.samples = VK_SAMPLE_COUNT_1_BIT;
18009 ci.tiling = VK_IMAGE_TILING_OPTIMAL;
18010 ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
18011 ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
18012 ci.queueFamilyIndexCount = 0;
18013 ci.pQueueFamilyIndices = NULL;
18014 ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
18015
Mark Lobodzinskicea14992016-10-14 10:59:42 -060018016 VkImageObj src_image(m_device);
Dave Houltonfc1a4052017-04-27 14:32:45 -060018017 src_image.init(&ci);
18018 ASSERT_TRUE(src_image.initialized());
18019
18020 // Dest image with one more mip level
18021 ci.extent = {64, 64, 16};
18022 ci.mipLevels = 7;
18023 ci.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskicea14992016-10-14 10:59:42 -060018024 VkImageObj dst_image(m_device);
Dave Houltonfc1a4052017-04-27 14:32:45 -060018025 dst_image.init(&ci);
18026 ASSERT_TRUE(dst_image.initialized());
Mark Lobodzinskicea14992016-10-14 10:59:42 -060018027
Tony Barbour552f6c02016-12-21 14:34:07 -070018028 m_commandBuffer->BeginCommandBuffer();
Dave Houltonfc1a4052017-04-27 14:32:45 -060018029
Mark Lobodzinskicea14992016-10-14 10:59:42 -060018030 VkImageCopy copy_region;
Dave Houltonfc1a4052017-04-27 14:32:45 -060018031 copy_region.extent = {32, 32, 8};
Mark Lobodzinskicea14992016-10-14 10:59:42 -060018032 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskicea14992016-10-14 10:59:42 -060018033 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Dave Houltoncee81d02017-05-02 11:00:10 -060018034 copy_region.srcSubresource.mipLevel = 0;
18035 copy_region.dstSubresource.mipLevel = 0;
Dave Houltonfc1a4052017-04-27 14:32:45 -060018036 copy_region.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinskicea14992016-10-14 10:59:42 -060018037 copy_region.dstSubresource.baseArrayLayer = 0;
Dave Houltonfc1a4052017-04-27 14:32:45 -060018038 copy_region.srcSubresource.layerCount = 1;
18039 copy_region.dstSubresource.layerCount = 1;
18040 copy_region.srcOffset = {0, 0, 0};
18041 copy_region.dstOffset = {0, 0, 0};
18042
18043 m_errorMonitor->ExpectSuccess();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060018044 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
18045 &copy_region);
Dave Houltonfc1a4052017-04-27 14:32:45 -060018046 m_errorMonitor->VerifyNotFound();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060018047
Dave Houltonfc1a4052017-04-27 14:32:45 -060018048 // Source exceeded in x-dim, VU 01202
18049 copy_region.srcOffset.x = 4;
18050 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01175); // General "contained within" VU
18051 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01202);
18052 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
18053 &copy_region);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060018054 m_errorMonitor->VerifyFound();
Dave Houltonfc1a4052017-04-27 14:32:45 -060018055
18056 // Source exceeded in y-dim, VU 01203
18057 copy_region.srcOffset.x = 0;
18058 copy_region.extent.height = 48;
18059 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01175);
18060 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01203);
18061 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
18062 &copy_region);
18063 m_errorMonitor->VerifyFound();
18064
18065 // Source exceeded in z-dim, VU 01204
18066 copy_region.extent = {4, 4, 4};
18067 copy_region.srcSubresource.mipLevel = 2;
18068 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01175);
18069 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01204);
18070 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
18071 &copy_region);
18072 m_errorMonitor->VerifyFound();
18073
18074 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060018075}
18076
18077TEST_F(VkLayerTest, CopyImageDstSizeExceeded) {
Mark Lobodzinskicea14992016-10-14 10:59:42 -060018078 // Image copy with dest region specified greater than dest image size
Tony Barbour1fa09702017-03-16 12:09:08 -060018079 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskicea14992016-10-14 10:59:42 -060018080
Dave Houltonfc1a4052017-04-27 14:32:45 -060018081 // Create images with full mip chain
18082 VkImageCreateInfo ci;
18083 ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
18084 ci.pNext = NULL;
18085 ci.flags = 0;
18086 ci.imageType = VK_IMAGE_TYPE_3D;
18087 ci.format = VK_FORMAT_R8G8B8A8_UNORM;
18088 ci.extent = {32, 32, 8};
18089 ci.mipLevels = 6;
18090 ci.arrayLayers = 1;
18091 ci.samples = VK_SAMPLE_COUNT_1_BIT;
18092 ci.tiling = VK_IMAGE_TILING_OPTIMAL;
18093 ci.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
18094 ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
18095 ci.queueFamilyIndexCount = 0;
18096 ci.pQueueFamilyIndices = NULL;
18097 ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
18098
Mark Lobodzinskicea14992016-10-14 10:59:42 -060018099 VkImageObj dst_image(m_device);
Dave Houltonfc1a4052017-04-27 14:32:45 -060018100 dst_image.init(&ci);
18101 ASSERT_TRUE(dst_image.initialized());
18102
18103 // Src image with one more mip level
18104 ci.extent = {64, 64, 16};
18105 ci.mipLevels = 7;
18106 ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
18107 VkImageObj src_image(m_device);
18108 src_image.init(&ci);
18109 ASSERT_TRUE(src_image.initialized());
Mark Lobodzinskicea14992016-10-14 10:59:42 -060018110
Tony Barbour552f6c02016-12-21 14:34:07 -070018111 m_commandBuffer->BeginCommandBuffer();
Dave Houltonfc1a4052017-04-27 14:32:45 -060018112
Mark Lobodzinskicea14992016-10-14 10:59:42 -060018113 VkImageCopy copy_region;
Dave Houltonfc1a4052017-04-27 14:32:45 -060018114 copy_region.extent = {32, 32, 8};
Mark Lobodzinskicea14992016-10-14 10:59:42 -060018115 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskicea14992016-10-14 10:59:42 -060018116 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Dave Houltoncee81d02017-05-02 11:00:10 -060018117 copy_region.srcSubresource.mipLevel = 0;
18118 copy_region.dstSubresource.mipLevel = 0;
Dave Houltonfc1a4052017-04-27 14:32:45 -060018119 copy_region.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinskicea14992016-10-14 10:59:42 -060018120 copy_region.dstSubresource.baseArrayLayer = 0;
Dave Houltonfc1a4052017-04-27 14:32:45 -060018121 copy_region.srcSubresource.layerCount = 1;
18122 copy_region.dstSubresource.layerCount = 1;
18123 copy_region.srcOffset = {0, 0, 0};
18124 copy_region.dstOffset = {0, 0, 0};
18125
18126 m_errorMonitor->ExpectSuccess();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060018127 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
18128 &copy_region);
Dave Houltonfc1a4052017-04-27 14:32:45 -060018129 m_errorMonitor->VerifyNotFound();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060018130
Dave Houltonfc1a4052017-04-27 14:32:45 -060018131 // Dest exceeded in x-dim, VU 01205
18132 copy_region.dstOffset.x = 4;
18133 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01176); // General "contained within" VU
18134 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01205);
18135 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
18136 &copy_region);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060018137 m_errorMonitor->VerifyFound();
Dave Houltonfc1a4052017-04-27 14:32:45 -060018138
18139 // Dest exceeded in y-dim, VU 01206
18140 copy_region.dstOffset.x = 0;
18141 copy_region.extent.height = 48;
18142 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01176);
18143 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01206);
18144 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
18145 &copy_region);
18146 m_errorMonitor->VerifyFound();
18147
18148 // Dest exceeded in z-dim, VU 01207
18149 copy_region.extent = {4, 4, 4};
18150 copy_region.dstSubresource.mipLevel = 2;
18151 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01176);
18152 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01207);
18153 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
18154 &copy_region);
18155 m_errorMonitor->VerifyFound();
18156
18157 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060018158}
18159
Karl Schultz6addd812016-02-02 17:17:23 -070018160TEST_F(VkLayerTest, CopyImageFormatSizeMismatch) {
Karl Schultzbdb75952016-04-19 11:36:49 -060018161 VkResult err;
18162 bool pass;
18163
18164 // Create color images with different format sizes and try to copy between them
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070018165 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01184);
Karl Schultzbdb75952016-04-19 11:36:49 -060018166
Tony Barbour1fa09702017-03-16 12:09:08 -060018167 ASSERT_NO_FATAL_FAILURE(Init());
Karl Schultzbdb75952016-04-19 11:36:49 -060018168
18169 // Create two images of different types and try to copy between them
18170 VkImage srcImage;
18171 VkImage dstImage;
18172 VkDeviceMemory srcMem;
18173 VkDeviceMemory destMem;
18174 VkMemoryRequirements memReqs;
18175
18176 VkImageCreateInfo image_create_info = {};
18177 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
18178 image_create_info.pNext = NULL;
18179 image_create_info.imageType = VK_IMAGE_TYPE_2D;
18180 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
18181 image_create_info.extent.width = 32;
18182 image_create_info.extent.height = 32;
18183 image_create_info.extent.depth = 1;
18184 image_create_info.mipLevels = 1;
18185 image_create_info.arrayLayers = 1;
18186 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
18187 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
18188 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
18189 image_create_info.flags = 0;
18190
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018191 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060018192 ASSERT_VK_SUCCESS(err);
18193
18194 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
18195 // Introduce failure by creating second image with a different-sized format.
18196 image_create_info.format = VK_FORMAT_R5G5B5A1_UNORM_PACK16;
Tobin Ehlis6d4d1d52017-04-05 12:06:10 -060018197 VkFormatProperties properties;
18198 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), image_create_info.format, &properties);
18199 if (properties.optimalTilingFeatures == 0) {
18200 printf(" Image format not supported; skipped.\n");
18201 return;
18202 }
Karl Schultzbdb75952016-04-19 11:36:49 -060018203
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018204 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060018205 ASSERT_VK_SUCCESS(err);
18206
18207 // Allocate memory
18208 VkMemoryAllocateInfo memAlloc = {};
18209 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18210 memAlloc.pNext = NULL;
18211 memAlloc.allocationSize = 0;
18212 memAlloc.memoryTypeIndex = 0;
18213
18214 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
18215 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018216 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060018217 ASSERT_TRUE(pass);
18218 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
18219 ASSERT_VK_SUCCESS(err);
18220
18221 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
18222 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018223 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060018224 ASSERT_TRUE(pass);
18225 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
18226 ASSERT_VK_SUCCESS(err);
18227
18228 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
18229 ASSERT_VK_SUCCESS(err);
18230 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
18231 ASSERT_VK_SUCCESS(err);
18232
Tony Barbour552f6c02016-12-21 14:34:07 -070018233 m_commandBuffer->BeginCommandBuffer();
Karl Schultzbdb75952016-04-19 11:36:49 -060018234 VkImageCopy copyRegion;
18235 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
18236 copyRegion.srcSubresource.mipLevel = 0;
18237 copyRegion.srcSubresource.baseArrayLayer = 0;
18238 copyRegion.srcSubresource.layerCount = 0;
18239 copyRegion.srcOffset.x = 0;
18240 copyRegion.srcOffset.y = 0;
18241 copyRegion.srcOffset.z = 0;
18242 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
18243 copyRegion.dstSubresource.mipLevel = 0;
18244 copyRegion.dstSubresource.baseArrayLayer = 0;
18245 copyRegion.dstSubresource.layerCount = 0;
18246 copyRegion.dstOffset.x = 0;
18247 copyRegion.dstOffset.y = 0;
18248 copyRegion.dstOffset.z = 0;
18249 copyRegion.extent.width = 1;
18250 copyRegion.extent.height = 1;
18251 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018252 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070018253 m_commandBuffer->EndCommandBuffer();
Karl Schultzbdb75952016-04-19 11:36:49 -060018254
18255 m_errorMonitor->VerifyFound();
18256
18257 vkDestroyImage(m_device->device(), srcImage, NULL);
18258 vkDestroyImage(m_device->device(), dstImage, NULL);
18259 vkFreeMemory(m_device->device(), srcMem, NULL);
18260 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060018261}
18262
Karl Schultz6addd812016-02-02 17:17:23 -070018263TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch) {
18264 VkResult err;
18265 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060018266
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018267 // Create a depth image and a depth/stencil image and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018268 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
18269 "vkCmdCopyImage called with unmatched source and dest image depth");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060018270
Tony Barbour1fa09702017-03-16 12:09:08 -060018271 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -060018272 auto depth_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbourf887b162017-03-09 10:06:46 -070018273 if (!depth_format) {
18274 return;
18275 }
Mike Stroyana3082432015-09-25 13:39:21 -060018276
18277 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070018278 VkImage srcImage;
18279 VkImage dstImage;
18280 VkDeviceMemory srcMem;
18281 VkDeviceMemory destMem;
18282 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060018283
18284 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070018285 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
18286 image_create_info.pNext = NULL;
18287 image_create_info.imageType = VK_IMAGE_TYPE_2D;
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018288 image_create_info.format = VK_FORMAT_D32_SFLOAT;
Karl Schultz6addd812016-02-02 17:17:23 -070018289 image_create_info.extent.width = 32;
18290 image_create_info.extent.height = 32;
18291 image_create_info.extent.depth = 1;
18292 image_create_info.mipLevels = 1;
18293 image_create_info.arrayLayers = 1;
18294 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Youngad61f4b2017-04-07 08:59:56 -060018295 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Karl Schultz6addd812016-02-02 17:17:23 -070018296 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
18297 image_create_info.flags = 0;
Tobin Ehlis6d4d1d52017-04-05 12:06:10 -060018298 VkFormatProperties properties;
18299 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), image_create_info.format, &properties);
18300 if (properties.optimalTilingFeatures == 0) {
18301 printf(" Image format not supported; skipped.\n");
18302 return;
18303 }
Mike Stroyana3082432015-09-25 13:39:21 -060018304
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018305 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060018306 ASSERT_VK_SUCCESS(err);
18307
Karl Schultzbdb75952016-04-19 11:36:49 -060018308 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
18309
Mark Lobodzinskidb117632016-03-31 10:45:56 -060018310 // Introduce failure by creating second image with a depth/stencil format
Karl Schultz6addd812016-02-02 17:17:23 -070018311 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Tony Barbourf887b162017-03-09 10:06:46 -070018312 image_create_info.format = depth_format;
Mark Lobodzinski867787a2016-10-14 11:49:55 -060018313 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060018314
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018315 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060018316 ASSERT_VK_SUCCESS(err);
18317
18318 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018319 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070018320 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18321 memAlloc.pNext = NULL;
18322 memAlloc.allocationSize = 0;
18323 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018324
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060018325 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060018326 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018327 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060018328 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018329 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060018330 ASSERT_VK_SUCCESS(err);
18331
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018332 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060018333 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018334 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060018335 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018336 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060018337 ASSERT_VK_SUCCESS(err);
18338
18339 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
18340 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018341 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060018342 ASSERT_VK_SUCCESS(err);
18343
Tony Barbour552f6c02016-12-21 14:34:07 -070018344 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060018345 VkImageCopy copyRegion;
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018346 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060018347 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060018348 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018349 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018350 copyRegion.srcOffset.x = 0;
18351 copyRegion.srcOffset.y = 0;
18352 copyRegion.srcOffset.z = 0;
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018353 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018354 copyRegion.dstSubresource.mipLevel = 0;
18355 copyRegion.dstSubresource.baseArrayLayer = 0;
18356 copyRegion.dstSubresource.layerCount = 0;
18357 copyRegion.dstOffset.x = 0;
18358 copyRegion.dstOffset.y = 0;
18359 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018360 copyRegion.extent.width = 1;
18361 copyRegion.extent.height = 1;
18362 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018363 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070018364 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060018365
Chris Forbes8f36a8a2016-04-07 13:21:07 +120018366 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060018367
Chia-I Wuf7458c52015-10-26 21:10:41 +080018368 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018369 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080018370 vkFreeMemory(m_device->device(), srcMem, NULL);
18371 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060018372}
18373
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018374TEST_F(VkLayerTest, CopyImageSampleCountMismatch) {
18375 TEST_DESCRIPTION("Image copies with sample count mis-matches");
Dave Houlton33c22b72017-02-28 13:16:02 -070018376
Mark Lobodzinski77e590c2017-03-17 12:05:16 -060018377 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton33c22b72017-02-28 13:16:02 -070018378
18379 VkImageFormatProperties image_format_properties;
18380 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
18381 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT, 0,
18382 &image_format_properties);
18383
18384 if ((0 == (VK_SAMPLE_COUNT_2_BIT & image_format_properties.sampleCounts)) ||
18385 (0 == (VK_SAMPLE_COUNT_4_BIT & image_format_properties.sampleCounts))) {
18386 printf(" Image multi-sample support not found; skipped.\n");
18387 return;
18388 }
18389
18390 VkImageCreateInfo ci;
18391 ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
18392 ci.pNext = NULL;
18393 ci.flags = 0;
18394 ci.imageType = VK_IMAGE_TYPE_2D;
18395 ci.format = VK_FORMAT_R8G8B8A8_UNORM;
18396 ci.extent = {128, 128, 1};
18397 ci.mipLevels = 1;
18398 ci.arrayLayers = 1;
18399 ci.samples = VK_SAMPLE_COUNT_1_BIT;
18400 ci.tiling = VK_IMAGE_TILING_OPTIMAL;
18401 ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
18402 ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
18403 ci.queueFamilyIndexCount = 0;
18404 ci.pQueueFamilyIndices = NULL;
18405 ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
18406
18407 VkImageObj image1(m_device);
18408 image1.init(&ci);
18409 ASSERT_TRUE(image1.initialized());
18410
18411 ci.samples = VK_SAMPLE_COUNT_2_BIT;
18412 VkImageObj image2(m_device);
18413 image2.init(&ci);
18414 ASSERT_TRUE(image2.initialized());
18415
18416 ci.samples = VK_SAMPLE_COUNT_4_BIT;
18417 VkImageObj image4(m_device);
18418 image4.init(&ci);
18419 ASSERT_TRUE(image4.initialized());
18420
18421 m_commandBuffer->BeginCommandBuffer();
18422
18423 VkImageCopy copyRegion;
18424 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
18425 copyRegion.srcSubresource.mipLevel = 0;
18426 copyRegion.srcSubresource.baseArrayLayer = 0;
18427 copyRegion.srcSubresource.layerCount = 1;
18428 copyRegion.srcOffset = {0, 0, 0};
18429 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
18430 copyRegion.dstSubresource.mipLevel = 0;
18431 copyRegion.dstSubresource.baseArrayLayer = 0;
18432 copyRegion.dstSubresource.layerCount = 1;
18433 copyRegion.dstOffset = {0, 0, 0};
18434 copyRegion.extent = {128, 128, 1};
18435
18436 // Copy a single sample image to/from a multi-sample image
18437 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01185);
18438 vkCmdCopyImage(m_commandBuffer->GetBufferHandle(), image1.handle(), VK_IMAGE_LAYOUT_GENERAL, image4.handle(),
18439 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
18440 m_errorMonitor->VerifyFound();
18441
18442 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01185);
18443 vkCmdCopyImage(m_commandBuffer->GetBufferHandle(), image2.handle(), VK_IMAGE_LAYOUT_GENERAL, image1.handle(),
18444 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
18445 m_errorMonitor->VerifyFound();
18446
18447 // Copy between multi-sample images with different sample counts
18448 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01185);
18449 vkCmdCopyImage(m_commandBuffer->GetBufferHandle(), image2.handle(), VK_IMAGE_LAYOUT_GENERAL, image4.handle(),
18450 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
18451 m_errorMonitor->VerifyFound();
18452
18453 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01185);
18454 vkCmdCopyImage(m_commandBuffer->GetBufferHandle(), image4.handle(), VK_IMAGE_LAYOUT_GENERAL, image2.handle(),
18455 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
18456 m_errorMonitor->VerifyFound();
18457
18458 m_commandBuffer->EndCommandBuffer();
18459}
18460
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018461TEST_F(VkLayerTest, CopyImageAspectMismatch) {
18462 TEST_DESCRIPTION("Image copies with aspect mask errors");
Mark Lobodzinski77e590c2017-03-17 12:05:16 -060018463 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -060018464 auto ds_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbour9357d542017-03-24 15:42:21 -060018465 if (!ds_format) {
18466 return;
18467 }
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018468
Tobin Ehlis6d4d1d52017-04-05 12:06:10 -060018469 VkFormatProperties properties;
18470 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D32_SFLOAT, &properties);
18471 if (properties.optimalTilingFeatures == 0) {
18472 printf(" Image format VK_FORMAT_D32_SFLOAT not supported; skipped.\n");
18473 return;
18474 }
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018475 VkImageObj color_image(m_device), ds_image(m_device), depth_image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060018476 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 -060018477 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 -060018478 VK_IMAGE_TILING_OPTIMAL, 0);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060018479 ds_image.Init(128, 128, 1, ds_format, VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
18480 VK_IMAGE_TILING_OPTIMAL, 0);
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018481 ASSERT_TRUE(color_image.initialized());
18482 ASSERT_TRUE(depth_image.initialized());
18483 ASSERT_TRUE(ds_image.initialized());
18484
18485 VkImageCopy copyRegion;
18486 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
18487 copyRegion.srcSubresource.mipLevel = 0;
18488 copyRegion.srcSubresource.baseArrayLayer = 0;
18489 copyRegion.srcSubresource.layerCount = 1;
18490 copyRegion.srcOffset = {0, 0, 0};
18491 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
18492 copyRegion.dstSubresource.mipLevel = 0;
18493 copyRegion.dstSubresource.baseArrayLayer = 0;
18494 copyRegion.dstSubresource.layerCount = 1;
18495 copyRegion.dstOffset = {64, 0, 0};
18496 copyRegion.extent = {64, 128, 1};
18497
18498 // Submitting command before command buffer is in recording state
Dave Houlton3c9fca72017-03-27 17:25:54 -060018499 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
18500 "You must call vkBeginCommandBuffer"); // VALIDATION_ERROR_01192);
18501 vkCmdCopyImage(m_commandBuffer->GetBufferHandle(), depth_image.handle(), VK_IMAGE_LAYOUT_GENERAL, depth_image.handle(),
18502 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018503 m_errorMonitor->VerifyFound();
18504
18505 m_commandBuffer->BeginCommandBuffer();
18506
18507 // Src and dest aspect masks don't match
18508 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT;
18509 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01197);
Dave Houlton3c9fca72017-03-27 17:25:54 -060018510 vkCmdCopyImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, ds_image.handle(),
18511 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018512 m_errorMonitor->VerifyFound();
18513 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
18514
18515 // Illegal combinations of aspect bits - VU 01221
Dave Houlton3c9fca72017-03-27 17:25:54 -060018516 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT; // color must be alone
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018517 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT;
18518 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01221);
18519 // These aspect/format mismatches are redundant but unavoidable here
18520 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01200);
18521 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01201);
Dave Houlton3c9fca72017-03-27 17:25:54 -060018522 vkCmdCopyImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_GENERAL, color_image.handle(),
18523 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018524 m_errorMonitor->VerifyFound();
18525 // Metadata aspect is illegal - VU 01222
18526 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
18527 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
18528 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01222);
18529 // These aspect/format mismatches are redundant but unavoidable here
Dave Houlton3c9fca72017-03-27 17:25:54 -060018530 vkCmdCopyImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_GENERAL, color_image.handle(),
18531 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018532 m_errorMonitor->VerifyFound();
18533
18534 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
18535 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
18536
18537 // Aspect mask doesn't match source image format - VU 01200
18538 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01200);
18539 // Again redundant but unavoidable when provoking vu01200 w/o vu01201
18540 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "unmatched source and dest image depth/stencil formats");
18541 vkCmdCopyImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_GENERAL, depth_image.handle(),
18542 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
18543 m_errorMonitor->VerifyFound();
18544
18545 // Aspect mask doesn't match dest image format - VU 01201
18546 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
18547 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
18548 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01201);
18549 // Again redundant but unavoidable when provoking vu01201 w/o vu01200
18550 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "unmatched source and dest image depth/stencil formats");
18551 vkCmdCopyImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_GENERAL, depth_image.handle(),
18552 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
18553 m_errorMonitor->VerifyFound();
18554
18555 m_commandBuffer->EndCommandBuffer();
18556}
18557
Karl Schultz6addd812016-02-02 17:17:23 -070018558TEST_F(VkLayerTest, ResolveImageLowSampleCount) {
18559 VkResult err;
18560 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060018561
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018562 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
18563 "vkCmdResolveImage called with source sample count less than 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060018564
Tony Barbour1fa09702017-03-16 12:09:08 -060018565 ASSERT_NO_FATAL_FAILURE(Init());
Mike Stroyana3082432015-09-25 13:39:21 -060018566
18567 // Create two images of sample count 1 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070018568 VkImage srcImage;
18569 VkImage dstImage;
18570 VkDeviceMemory srcMem;
18571 VkDeviceMemory destMem;
18572 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060018573
18574 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070018575 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
18576 image_create_info.pNext = NULL;
18577 image_create_info.imageType = VK_IMAGE_TYPE_2D;
18578 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
18579 image_create_info.extent.width = 32;
18580 image_create_info.extent.height = 1;
18581 image_create_info.extent.depth = 1;
18582 image_create_info.mipLevels = 1;
18583 image_create_info.arrayLayers = 1;
18584 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
18585 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
18586 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
18587 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018588
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018589 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060018590 ASSERT_VK_SUCCESS(err);
18591
Karl Schultz6addd812016-02-02 17:17:23 -070018592 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060018593
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018594 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060018595 ASSERT_VK_SUCCESS(err);
18596
18597 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018598 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070018599 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18600 memAlloc.pNext = NULL;
18601 memAlloc.allocationSize = 0;
18602 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018603
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060018604 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060018605 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018606 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060018607 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018608 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060018609 ASSERT_VK_SUCCESS(err);
18610
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018611 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060018612 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018613 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060018614 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018615 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060018616 ASSERT_VK_SUCCESS(err);
18617
18618 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
18619 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018620 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060018621 ASSERT_VK_SUCCESS(err);
18622
Tony Barbour552f6c02016-12-21 14:34:07 -070018623 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060018624 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070018625 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
18626 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060018627 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080018628 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060018629 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060018630 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130018631 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060018632 resolveRegion.srcOffset.x = 0;
18633 resolveRegion.srcOffset.y = 0;
18634 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080018635 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018636 resolveRegion.dstSubresource.mipLevel = 0;
18637 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130018638 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018639 resolveRegion.dstOffset.x = 0;
18640 resolveRegion.dstOffset.y = 0;
18641 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018642 resolveRegion.extent.width = 1;
18643 resolveRegion.extent.height = 1;
18644 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018645 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070018646 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060018647
Chris Forbes8f36a8a2016-04-07 13:21:07 +120018648 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060018649
Chia-I Wuf7458c52015-10-26 21:10:41 +080018650 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018651 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080018652 vkFreeMemory(m_device->device(), srcMem, NULL);
18653 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060018654}
18655
Karl Schultz6addd812016-02-02 17:17:23 -070018656TEST_F(VkLayerTest, ResolveImageHighSampleCount) {
18657 VkResult err;
18658 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060018659
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018660 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
18661 "vkCmdResolveImage called with dest sample count greater than 1.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060018662
Tony Barbour1fa09702017-03-16 12:09:08 -060018663 ASSERT_NO_FATAL_FAILURE(Init());
Mike Stroyana3082432015-09-25 13:39:21 -060018664
Chris Forbesa7530692016-05-08 12:35:39 +120018665 // Create two images of sample count 4 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070018666 VkImage srcImage;
18667 VkImage dstImage;
18668 VkDeviceMemory srcMem;
18669 VkDeviceMemory destMem;
18670 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060018671
18672 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070018673 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
18674 image_create_info.pNext = NULL;
18675 image_create_info.imageType = VK_IMAGE_TYPE_2D;
18676 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
18677 image_create_info.extent.width = 32;
18678 image_create_info.extent.height = 1;
18679 image_create_info.extent.depth = 1;
18680 image_create_info.mipLevels = 1;
18681 image_create_info.arrayLayers = 1;
Chris Forbesa7530692016-05-08 12:35:39 +120018682 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070018683 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
18684 // Note: Some implementations expect color attachment usage for any
18685 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018686 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070018687 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018688
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018689 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060018690 ASSERT_VK_SUCCESS(err);
18691
Karl Schultz6addd812016-02-02 17:17:23 -070018692 // Note: Some implementations expect color attachment usage for any
18693 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018694 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060018695
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018696 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060018697 ASSERT_VK_SUCCESS(err);
18698
18699 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018700 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070018701 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18702 memAlloc.pNext = NULL;
18703 memAlloc.allocationSize = 0;
18704 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018705
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060018706 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060018707 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018708 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060018709 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018710 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060018711 ASSERT_VK_SUCCESS(err);
18712
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018713 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060018714 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018715 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060018716 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018717 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060018718 ASSERT_VK_SUCCESS(err);
18719
18720 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
18721 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018722 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060018723 ASSERT_VK_SUCCESS(err);
18724
Tony Barbour552f6c02016-12-21 14:34:07 -070018725 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060018726 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070018727 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
18728 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060018729 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080018730 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060018731 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060018732 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130018733 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060018734 resolveRegion.srcOffset.x = 0;
18735 resolveRegion.srcOffset.y = 0;
18736 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080018737 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018738 resolveRegion.dstSubresource.mipLevel = 0;
18739 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130018740 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018741 resolveRegion.dstOffset.x = 0;
18742 resolveRegion.dstOffset.y = 0;
18743 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018744 resolveRegion.extent.width = 1;
18745 resolveRegion.extent.height = 1;
18746 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018747 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070018748 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060018749
Chris Forbes8f36a8a2016-04-07 13:21:07 +120018750 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060018751
Chia-I Wuf7458c52015-10-26 21:10:41 +080018752 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018753 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080018754 vkFreeMemory(m_device->device(), srcMem, NULL);
18755 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060018756}
18757
Karl Schultz6addd812016-02-02 17:17:23 -070018758TEST_F(VkLayerTest, ResolveImageFormatMismatch) {
18759 VkResult err;
18760 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060018761
Mark Lobodzinski50fbef12017-02-06 15:31:33 -070018762 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018763 "vkCmdResolveImage called with unmatched source and dest formats.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060018764
Tony Barbour1fa09702017-03-16 12:09:08 -060018765 ASSERT_NO_FATAL_FAILURE(Init());
Mike Stroyana3082432015-09-25 13:39:21 -060018766
18767 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070018768 VkImage srcImage;
18769 VkImage dstImage;
18770 VkDeviceMemory srcMem;
18771 VkDeviceMemory destMem;
18772 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060018773
18774 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070018775 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
18776 image_create_info.pNext = NULL;
18777 image_create_info.imageType = VK_IMAGE_TYPE_2D;
18778 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
18779 image_create_info.extent.width = 32;
18780 image_create_info.extent.height = 1;
18781 image_create_info.extent.depth = 1;
18782 image_create_info.mipLevels = 1;
18783 image_create_info.arrayLayers = 1;
18784 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
18785 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
18786 // Note: Some implementations expect color attachment usage for any
18787 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018788 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070018789 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018790
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018791 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060018792 ASSERT_VK_SUCCESS(err);
18793
Karl Schultz6addd812016-02-02 17:17:23 -070018794 // Set format to something other than source image
18795 image_create_info.format = VK_FORMAT_R32_SFLOAT;
18796 // Note: Some implementations expect color attachment usage for any
18797 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018798 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070018799 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060018800
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018801 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060018802 ASSERT_VK_SUCCESS(err);
18803
18804 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018805 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070018806 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18807 memAlloc.pNext = NULL;
18808 memAlloc.allocationSize = 0;
18809 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018810
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060018811 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060018812 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018813 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060018814 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018815 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060018816 ASSERT_VK_SUCCESS(err);
18817
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018818 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060018819 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018820 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060018821 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018822 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060018823 ASSERT_VK_SUCCESS(err);
18824
18825 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
18826 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018827 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060018828 ASSERT_VK_SUCCESS(err);
18829
Tony Barbour552f6c02016-12-21 14:34:07 -070018830 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060018831 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070018832 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
18833 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060018834 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080018835 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060018836 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060018837 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130018838 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060018839 resolveRegion.srcOffset.x = 0;
18840 resolveRegion.srcOffset.y = 0;
18841 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080018842 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018843 resolveRegion.dstSubresource.mipLevel = 0;
18844 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130018845 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018846 resolveRegion.dstOffset.x = 0;
18847 resolveRegion.dstOffset.y = 0;
18848 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018849 resolveRegion.extent.width = 1;
18850 resolveRegion.extent.height = 1;
18851 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018852 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070018853 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060018854
Chris Forbes8f36a8a2016-04-07 13:21:07 +120018855 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060018856
Chia-I Wuf7458c52015-10-26 21:10:41 +080018857 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018858 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080018859 vkFreeMemory(m_device->device(), srcMem, NULL);
18860 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060018861}
18862
Karl Schultz6addd812016-02-02 17:17:23 -070018863TEST_F(VkLayerTest, ResolveImageTypeMismatch) {
18864 VkResult err;
18865 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060018866
Mark Lobodzinski50fbef12017-02-06 15:31:33 -070018867 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018868 "vkCmdResolveImage called with unmatched source and dest image types.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060018869
Tony Barbour1fa09702017-03-16 12:09:08 -060018870 ASSERT_NO_FATAL_FAILURE(Init());
Mike Stroyana3082432015-09-25 13:39:21 -060018871
18872 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070018873 VkImage srcImage;
18874 VkImage dstImage;
18875 VkDeviceMemory srcMem;
18876 VkDeviceMemory destMem;
18877 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060018878
18879 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070018880 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
18881 image_create_info.pNext = NULL;
18882 image_create_info.imageType = VK_IMAGE_TYPE_2D;
18883 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
18884 image_create_info.extent.width = 32;
18885 image_create_info.extent.height = 1;
18886 image_create_info.extent.depth = 1;
18887 image_create_info.mipLevels = 1;
18888 image_create_info.arrayLayers = 1;
18889 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
18890 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
18891 // Note: Some implementations expect color attachment usage for any
18892 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018893 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070018894 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018895
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018896 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060018897 ASSERT_VK_SUCCESS(err);
18898
Karl Schultz6addd812016-02-02 17:17:23 -070018899 image_create_info.imageType = VK_IMAGE_TYPE_1D;
18900 // Note: Some implementations expect color attachment usage for any
18901 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018902 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070018903 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060018904
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018905 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060018906 ASSERT_VK_SUCCESS(err);
18907
18908 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018909 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070018910 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18911 memAlloc.pNext = NULL;
18912 memAlloc.allocationSize = 0;
18913 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018914
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060018915 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060018916 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018917 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060018918 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018919 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060018920 ASSERT_VK_SUCCESS(err);
18921
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018922 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060018923 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018924 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060018925 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018926 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060018927 ASSERT_VK_SUCCESS(err);
18928
18929 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
18930 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018931 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060018932 ASSERT_VK_SUCCESS(err);
18933
Tony Barbour552f6c02016-12-21 14:34:07 -070018934 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060018935 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070018936 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
18937 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060018938 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080018939 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060018940 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060018941 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130018942 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060018943 resolveRegion.srcOffset.x = 0;
18944 resolveRegion.srcOffset.y = 0;
18945 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080018946 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018947 resolveRegion.dstSubresource.mipLevel = 0;
18948 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130018949 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018950 resolveRegion.dstOffset.x = 0;
18951 resolveRegion.dstOffset.y = 0;
18952 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018953 resolveRegion.extent.width = 1;
18954 resolveRegion.extent.height = 1;
18955 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018956 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070018957 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060018958
Chris Forbes8f36a8a2016-04-07 13:21:07 +120018959 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060018960
Chia-I Wuf7458c52015-10-26 21:10:41 +080018961 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018962 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080018963 vkFreeMemory(m_device->device(), srcMem, NULL);
18964 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060018965}
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018966
Karl Schultz6addd812016-02-02 17:17:23 -070018967TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018968 // Create a single Image descriptor and cause it to first hit an error due
Karl Schultz6addd812016-02-02 17:17:23 -070018969 // to using a DS format, then cause it to hit error due to COLOR_BIT not
18970 // set in aspect
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018971 // The image format check comes 2nd in validation so we trigger it first,
18972 // then when we cause aspect fail next, bad format check will be preempted
Karl Schultz6addd812016-02-02 17:17:23 -070018973 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018974
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018975 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
18976 "Combination depth/stencil image formats can have only the ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060018977
Tony Barbour1fa09702017-03-16 12:09:08 -060018978 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -060018979 auto depth_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbourf887b162017-03-09 10:06:46 -070018980 if (!depth_format) {
18981 return;
18982 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060018983
Chia-I Wu1b99bb22015-10-27 19:25:11 +080018984 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070018985 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
18986 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018987
18988 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070018989 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
18990 ds_pool_ci.pNext = NULL;
18991 ds_pool_ci.maxSets = 1;
18992 ds_pool_ci.poolSizeCount = 1;
18993 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018994
18995 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018996 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018997 ASSERT_VK_SUCCESS(err);
18998
18999 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070019000 dsl_binding.binding = 0;
19001 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
19002 dsl_binding.descriptorCount = 1;
19003 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
19004 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060019005
19006 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070019007 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
19008 ds_layout_ci.pNext = NULL;
19009 ds_layout_ci.bindingCount = 1;
19010 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060019011 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019012 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060019013 ASSERT_VK_SUCCESS(err);
19014
19015 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080019016 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080019017 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070019018 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060019019 alloc_info.descriptorPool = ds_pool;
19020 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019021 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060019022 ASSERT_VK_SUCCESS(err);
19023
Karl Schultz6addd812016-02-02 17:17:23 -070019024 VkImage image_bad;
19025 VkImage image_good;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060019026 // One bad format and one good format for Color attachment
Tony Barbourf887b162017-03-09 10:06:46 -070019027 const VkFormat tex_format_bad = depth_format;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060019028 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
Karl Schultz6addd812016-02-02 17:17:23 -070019029 const int32_t tex_width = 32;
19030 const int32_t tex_height = 32;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060019031
19032 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070019033 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
19034 image_create_info.pNext = NULL;
19035 image_create_info.imageType = VK_IMAGE_TYPE_2D;
19036 image_create_info.format = tex_format_bad;
19037 image_create_info.extent.width = tex_width;
19038 image_create_info.extent.height = tex_height;
19039 image_create_info.extent.depth = 1;
19040 image_create_info.mipLevels = 1;
19041 image_create_info.arrayLayers = 1;
19042 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
19043 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019044 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070019045 image_create_info.flags = 0;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060019046
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019047 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060019048 ASSERT_VK_SUCCESS(err);
19049 image_create_info.format = tex_format_good;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019050 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
19051 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_good);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060019052 ASSERT_VK_SUCCESS(err);
19053
Rene Lindsayf1e89c82016-12-28 13:18:31 -070019054 // ---Bind image memory---
19055 VkMemoryRequirements img_mem_reqs;
19056 vkGetImageMemoryRequirements(m_device->device(), image_bad, &img_mem_reqs);
19057 VkMemoryAllocateInfo image_alloc_info = {};
19058 image_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
19059 image_alloc_info.pNext = NULL;
19060 image_alloc_info.memoryTypeIndex = 0;
19061 image_alloc_info.allocationSize = img_mem_reqs.size;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019062 bool pass =
19063 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 -070019064 ASSERT_TRUE(pass);
19065 VkDeviceMemory mem;
19066 err = vkAllocateMemory(m_device->device(), &image_alloc_info, NULL, &mem);
19067 ASSERT_VK_SUCCESS(err);
19068 err = vkBindImageMemory(m_device->device(), image_bad, mem, 0);
19069 ASSERT_VK_SUCCESS(err);
19070 // -----------------------
19071
Tobin Ehlisa1c28562015-10-23 16:00:08 -060019072 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130019073 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070019074 image_view_create_info.image = image_bad;
19075 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
19076 image_view_create_info.format = tex_format_bad;
19077 image_view_create_info.subresourceRange.baseArrayLayer = 0;
19078 image_view_create_info.subresourceRange.baseMipLevel = 0;
19079 image_view_create_info.subresourceRange.layerCount = 1;
19080 image_view_create_info.subresourceRange.levelCount = 1;
Rene Lindsayf1e89c82016-12-28 13:18:31 -070019081 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060019082
19083 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019084 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060019085
Chris Forbes8f36a8a2016-04-07 13:21:07 +120019086 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060019087
Chia-I Wuf7458c52015-10-26 21:10:41 +080019088 vkDestroyImage(m_device->device(), image_bad, NULL);
19089 vkDestroyImage(m_device->device(), image_good, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080019090 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
19091 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Rene Lindsayf1e89c82016-12-28 13:18:31 -070019092
19093 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060019094}
Tobin Ehlis6e23d772016-05-19 11:08:34 -060019095
19096TEST_F(VkLayerTest, ClearImageErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019097 TEST_DESCRIPTION(
19098 "Call ClearColorImage w/ a depth|stencil image and "
19099 "ClearDepthStencilImage with a color image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060019100
Tony Barbour1fa09702017-03-16 12:09:08 -060019101 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -060019102 auto depth_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbourf887b162017-03-09 10:06:46 -070019103 if (!depth_format) {
19104 return;
19105 }
Tobin Ehlis6e23d772016-05-19 11:08:34 -060019106 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19107
Tony Barbour552f6c02016-12-21 14:34:07 -070019108 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis6e23d772016-05-19 11:08:34 -060019109
19110 // Color image
19111 VkClearColorValue clear_color;
19112 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
19113 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
19114 const VkFormat color_format = VK_FORMAT_B8G8R8A8_UNORM;
19115 const int32_t img_width = 32;
19116 const int32_t img_height = 32;
19117 VkImageCreateInfo image_create_info = {};
19118 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
19119 image_create_info.pNext = NULL;
19120 image_create_info.imageType = VK_IMAGE_TYPE_2D;
19121 image_create_info.format = color_format;
19122 image_create_info.extent.width = img_width;
19123 image_create_info.extent.height = img_height;
19124 image_create_info.extent.depth = 1;
19125 image_create_info.mipLevels = 1;
19126 image_create_info.arrayLayers = 1;
19127 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
19128 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
19129 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
19130
19131 vk_testing::Image color_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019132 color_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060019133
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019134 const VkImageSubresourceRange color_range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060019135
19136 // Depth/Stencil image
19137 VkClearDepthStencilValue clear_value = {0};
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019138 reqs = 0; // don't need HOST_VISIBLE DS image
Tobin Ehlis6e23d772016-05-19 11:08:34 -060019139 VkImageCreateInfo ds_image_create_info = vk_testing::Image::create_info();
19140 ds_image_create_info.imageType = VK_IMAGE_TYPE_2D;
Tony Barbourf887b162017-03-09 10:06:46 -070019141 ds_image_create_info.format = depth_format;
Tobin Ehlis6e23d772016-05-19 11:08:34 -060019142 ds_image_create_info.extent.width = 64;
19143 ds_image_create_info.extent.height = 64;
19144 ds_image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Rene Lindsaya1fc64a2016-12-27 15:18:54 -070019145 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 -060019146
19147 vk_testing::Image ds_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019148 ds_image.init(*m_device, (const VkImageCreateInfo &)ds_image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060019149
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019150 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 -060019151
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019152 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060019153
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019154 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tobin Ehlis6e23d772016-05-19 11:08:34 -060019155 &color_range);
19156
19157 m_errorMonitor->VerifyFound();
19158
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019159 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
19160 "vkCmdClearColorImage called with "
19161 "image created without "
19162 "VK_IMAGE_USAGE_TRANSFER_DST_BIT");
Tony Barbour26434b92016-06-02 09:43:50 -060019163
Rene Lindsaya1fc64a2016-12-27 15:18:54 -070019164 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tony Barbour26434b92016-06-02 09:43:50 -060019165 &color_range);
19166
19167 m_errorMonitor->VerifyFound();
19168
Tobin Ehlis6e23d772016-05-19 11:08:34 -060019169 // Call CmdClearDepthStencilImage with color image
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019170 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
19171 "vkCmdClearDepthStencilImage called without a depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060019172
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019173 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
19174 &clear_value, 1, &ds_range);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060019175
19176 m_errorMonitor->VerifyFound();
19177}
Tobin Ehliscde08892015-09-22 10:11:37 -060019178
Mike Schuchardt35fece12017-03-07 14:40:28 -070019179TEST_F(VkLayerTest, CommandQueueFlags) {
19180 TEST_DESCRIPTION(
19181 "Allocate a command buffer on a queue that does not support graphics and try to issue a "
19182 "graphics-only command");
19183
19184 ASSERT_NO_FATAL_FAILURE(Init());
19185
19186 uint32_t queueFamilyIndex = m_device->QueueFamilyWithoutCapabilities(VK_QUEUE_GRAPHICS_BIT);
Dave Houlton3c9fca72017-03-27 17:25:54 -060019187 if (queueFamilyIndex == UINT32_MAX) {
Mike Schuchardt35fece12017-03-07 14:40:28 -070019188 printf(" Non-graphics queue family not found; skipped.\n");
19189 return;
19190 } else {
19191 // Create command pool on a non-graphics queue
19192 VkCommandPoolObj command_pool(m_device, queueFamilyIndex);
19193
19194 // Setup command buffer on pool
19195 VkCommandBufferObj command_buffer(m_device, &command_pool);
19196 command_buffer.BeginCommandBuffer();
19197
19198 // Issue a graphics only command
19199 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01446);
19200 VkViewport viewport = {0, 0, 16, 16, 0, 1};
19201 command_buffer.SetViewport(0, 1, &viewport);
19202 m_errorMonitor->VerifyFound();
19203 }
19204}
19205
Mark Lobodzinskib8359282017-05-16 09:17:51 -060019206TEST_F(VkLayerTest, ExecuteUnrecordedCBs) {
19207 TEST_DESCRIPTION(
19208 "Attempt vkCmdExecuteCommands and then QueueSubmit with an unrecorded secondary and primary command buffer, respectively");
19209
19210 ASSERT_NO_FATAL_FAILURE(Init());
19211 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19212 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00155);
19213 // Allocate a secondary command buffer
19214 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
19215 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19216 command_buffer_allocate_info.commandPool = m_commandPool->handle();
19217 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
19218 command_buffer_allocate_info.commandBufferCount = 1;
19219 VkCommandBuffer secondary_command_buffer;
19220 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
19221 VkCommandBufferBeginInfo command_buffer_begin_info = {};
19222 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19223 command_buffer_begin_info.flags =
19224 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
19225 command_buffer_begin_info.pInheritanceInfo = nullptr;
19226
19227 // Now update primary cmd buffer to execute unrecorded secondary
19228 VkResult err = vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
19229 ASSERT_VK_SUCCESS(err);
19230 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
19231 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
19232 vkCmdEndRenderPass(m_commandBuffer->handle());
19233 err = vkEndCommandBuffer(m_commandBuffer->handle());
19234 ASSERT_VK_SUCCESS(err);
19235 m_errorMonitor->VerifyFound();
19236
19237 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00134);
19238 // Allocate a primary command buffer
19239 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19240 command_buffer_allocate_info.commandBufferCount = 1;
19241 VkCommandBuffer primary_command_buffer;
19242 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &primary_command_buffer));
19243
19244 // And submit the unrecorded command buffer
19245 VkSubmitInfo submit_info = {};
19246 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19247 submit_info.commandBufferCount = 1;
19248 submit_info.pCommandBuffers = &primary_command_buffer;
19249 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
19250 m_errorMonitor->VerifyFound();
19251}
19252
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019253// WSI Enabled Tests
19254//
Chris Forbes09368e42016-10-13 11:59:22 +130019255#if 0
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019256TEST_F(VkWsiEnabledLayerTest, TestEnabledWsi) {
19257
19258#if defined(VK_USE_PLATFORM_XCB_KHR)
19259 VkSurfaceKHR surface = VK_NULL_HANDLE;
19260
19261 VkResult err;
19262 bool pass;
19263 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
19264 VkSwapchainCreateInfoKHR swapchain_create_info = {};
19265 // uint32_t swapchain_image_count = 0;
19266 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
19267 // uint32_t image_index = 0;
19268 // VkPresentInfoKHR present_info = {};
19269
Tony Barbour1fa09702017-03-16 12:09:08 -060019270 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019271
19272 // Use the create function from one of the VK_KHR_*_surface extension in
19273 // order to create a surface, testing all known errors in the process,
19274 // before successfully creating a surface:
19275 // First, try to create a surface without a VkXcbSurfaceCreateInfoKHR:
19276 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo specified as NULL");
19277 err = vkCreateXcbSurfaceKHR(instance(), NULL, NULL, &surface);
19278 pass = (err != VK_SUCCESS);
19279 ASSERT_TRUE(pass);
19280 m_errorMonitor->VerifyFound();
19281
19282 // Next, try to create a surface with the wrong
19283 // VkXcbSurfaceCreateInfoKHR::sType:
19284 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
19285 xcb_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
19286 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
19287 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
19288 pass = (err != VK_SUCCESS);
19289 ASSERT_TRUE(pass);
19290 m_errorMonitor->VerifyFound();
19291
19292 // Create a native window, and then correctly create a surface:
19293 xcb_connection_t *connection;
19294 xcb_screen_t *screen;
19295 xcb_window_t xcb_window;
19296 xcb_intern_atom_reply_t *atom_wm_delete_window;
19297
19298 const xcb_setup_t *setup;
19299 xcb_screen_iterator_t iter;
19300 int scr;
19301 uint32_t value_mask, value_list[32];
19302 int width = 1;
19303 int height = 1;
19304
19305 connection = xcb_connect(NULL, &scr);
19306 ASSERT_TRUE(connection != NULL);
19307 setup = xcb_get_setup(connection);
19308 iter = xcb_setup_roots_iterator(setup);
19309 while (scr-- > 0)
19310 xcb_screen_next(&iter);
19311 screen = iter.data;
19312
19313 xcb_window = xcb_generate_id(connection);
19314
19315 value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
19316 value_list[0] = screen->black_pixel;
19317 value_list[1] = XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_STRUCTURE_NOTIFY;
19318
19319 xcb_create_window(connection, XCB_COPY_FROM_PARENT, xcb_window, screen->root, 0, 0, width, height, 0,
19320 XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual, value_mask, value_list);
19321
19322 /* Magic code that will send notification when window is destroyed */
19323 xcb_intern_atom_cookie_t cookie = xcb_intern_atom(connection, 1, 12, "WM_PROTOCOLS");
19324 xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply(connection, cookie, 0);
19325
19326 xcb_intern_atom_cookie_t cookie2 = xcb_intern_atom(connection, 0, 16, "WM_DELETE_WINDOW");
19327 atom_wm_delete_window = xcb_intern_atom_reply(connection, cookie2, 0);
19328 xcb_change_property(connection, XCB_PROP_MODE_REPLACE, xcb_window, (*reply).atom, 4, 32, 1, &(*atom_wm_delete_window).atom);
19329 free(reply);
19330
19331 xcb_map_window(connection, xcb_window);
19332
19333 // Force the x/y coordinates to 100,100 results are identical in consecutive
19334 // runs
19335 const uint32_t coords[] = { 100, 100 };
19336 xcb_configure_window(connection, xcb_window, XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, coords);
19337
19338 // Finally, try to correctly create a surface:
19339 xcb_create_info.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
19340 xcb_create_info.pNext = NULL;
19341 xcb_create_info.flags = 0;
19342 xcb_create_info.connection = connection;
19343 xcb_create_info.window = xcb_window;
19344 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
19345 pass = (err == VK_SUCCESS);
19346 ASSERT_TRUE(pass);
19347
19348 // Check if surface supports presentation:
19349
19350 // 1st, do so without having queried the queue families:
19351 VkBool32 supported = false;
19352 // TODO: Get the following error to come out:
19353 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
19354 "called before calling the vkGetPhysicalDeviceQueueFamilyProperties "
19355 "function");
19356 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
19357 pass = (err != VK_SUCCESS);
19358 // ASSERT_TRUE(pass);
19359 // m_errorMonitor->VerifyFound();
19360
19361 // Next, query a queue family index that's too large:
19362 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
19363 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 100000, surface, &supported);
19364 pass = (err != VK_SUCCESS);
19365 ASSERT_TRUE(pass);
19366 m_errorMonitor->VerifyFound();
19367
19368 // Finally, do so correctly:
19369 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
19370 // SUPPORTED
19371 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
19372 pass = (err == VK_SUCCESS);
19373 ASSERT_TRUE(pass);
19374
19375 // Before proceeding, try to create a swapchain without having called
19376 // vkGetPhysicalDeviceSurfaceCapabilitiesKHR():
19377 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
19378 swapchain_create_info.pNext = NULL;
19379 swapchain_create_info.flags = 0;
19380 swapchain_create_info.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
19381 swapchain_create_info.surface = surface;
19382 swapchain_create_info.imageArrayLayers = 1;
19383 swapchain_create_info.preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
19384 swapchain_create_info.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
19385 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
19386 "called before calling vkGetPhysicalDeviceSurfaceCapabilitiesKHR().");
19387 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
19388 pass = (err != VK_SUCCESS);
19389 ASSERT_TRUE(pass);
19390 m_errorMonitor->VerifyFound();
19391
19392 // Get the surface capabilities:
19393 VkSurfaceCapabilitiesKHR surface_capabilities;
19394
19395 // Do so correctly (only error logged by this entrypoint is if the
19396 // extension isn't enabled):
19397 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &surface_capabilities);
19398 pass = (err == VK_SUCCESS);
19399 ASSERT_TRUE(pass);
19400
19401 // Get the surface formats:
19402 uint32_t surface_format_count;
19403
19404 // First, try without a pointer to surface_format_count:
19405 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSurfaceFormatCount "
19406 "specified as NULL");
19407 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, NULL, NULL);
19408 pass = (err == VK_SUCCESS);
19409 ASSERT_TRUE(pass);
19410 m_errorMonitor->VerifyFound();
19411
19412 // Next, call with a non-NULL pSurfaceFormats, even though we haven't
19413 // correctly done a 1st try (to get the count):
19414 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
19415 surface_format_count = 0;
19416 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, (VkSurfaceFormatKHR *)&surface_format_count);
19417 pass = (err == VK_SUCCESS);
19418 ASSERT_TRUE(pass);
19419 m_errorMonitor->VerifyFound();
19420
19421 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
19422 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
19423 pass = (err == VK_SUCCESS);
19424 ASSERT_TRUE(pass);
19425
19426 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
19427 VkSurfaceFormatKHR *surface_formats = (VkSurfaceFormatKHR *)malloc(surface_format_count * sizeof(VkSurfaceFormatKHR));
19428
19429 // Next, do a 2nd try with surface_format_count being set too high:
19430 surface_format_count += 5;
19431 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
19432 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
19433 pass = (err == VK_SUCCESS);
19434 ASSERT_TRUE(pass);
19435 m_errorMonitor->VerifyFound();
19436
19437 // Finally, do a correct 1st and 2nd try:
19438 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
19439 pass = (err == VK_SUCCESS);
19440 ASSERT_TRUE(pass);
19441 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
19442 pass = (err == VK_SUCCESS);
19443 ASSERT_TRUE(pass);
19444
19445 // Get the surface present modes:
19446 uint32_t surface_present_mode_count;
19447
19448 // First, try without a pointer to surface_format_count:
19449 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pPresentModeCount "
19450 "specified as NULL");
19451
19452 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, NULL, NULL);
19453 pass = (err == VK_SUCCESS);
19454 ASSERT_TRUE(pass);
19455 m_errorMonitor->VerifyFound();
19456
19457 // Next, call with a non-NULL VkPresentModeKHR, even though we haven't
19458 // correctly done a 1st try (to get the count):
19459 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
19460 surface_present_mode_count = 0;
19461 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count,
19462 (VkPresentModeKHR *)&surface_present_mode_count);
19463 pass = (err == VK_SUCCESS);
19464 ASSERT_TRUE(pass);
19465 m_errorMonitor->VerifyFound();
19466
19467 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
19468 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
19469 pass = (err == VK_SUCCESS);
19470 ASSERT_TRUE(pass);
19471
19472 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
19473 VkPresentModeKHR *surface_present_modes = (VkPresentModeKHR *)malloc(surface_present_mode_count * sizeof(VkPresentModeKHR));
19474
19475 // Next, do a 2nd try with surface_format_count being set too high:
19476 surface_present_mode_count += 5;
19477 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
19478 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
19479 pass = (err == VK_SUCCESS);
19480 ASSERT_TRUE(pass);
19481 m_errorMonitor->VerifyFound();
19482
19483 // Finally, do a correct 1st and 2nd try:
19484 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
19485 pass = (err == VK_SUCCESS);
19486 ASSERT_TRUE(pass);
19487 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
19488 pass = (err == VK_SUCCESS);
19489 ASSERT_TRUE(pass);
19490
19491 // Create a swapchain:
19492
19493 // First, try without a pointer to swapchain_create_info:
19494 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo "
19495 "specified as NULL");
19496
19497 err = vkCreateSwapchainKHR(m_device->device(), NULL, NULL, &swapchain);
19498 pass = (err != VK_SUCCESS);
19499 ASSERT_TRUE(pass);
19500 m_errorMonitor->VerifyFound();
19501
19502 // Next, call with a non-NULL swapchain_create_info, that has the wrong
19503 // sType:
19504 swapchain_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
19505 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
19506
19507 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
19508 pass = (err != VK_SUCCESS);
19509 ASSERT_TRUE(pass);
19510 m_errorMonitor->VerifyFound();
19511
19512 // Next, call with a NULL swapchain pointer:
19513 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
19514 swapchain_create_info.pNext = NULL;
19515 swapchain_create_info.flags = 0;
19516 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSwapchain "
19517 "specified as NULL");
19518
19519 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, NULL);
19520 pass = (err != VK_SUCCESS);
19521 ASSERT_TRUE(pass);
19522 m_errorMonitor->VerifyFound();
19523
19524 // TODO: Enhance swapchain layer so that
19525 // swapchain_create_info.queueFamilyIndexCount is checked against something?
19526
19527 // Next, call with a queue family index that's too large:
19528 uint32_t queueFamilyIndex[2] = { 100000, 0 };
19529 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
19530 swapchain_create_info.queueFamilyIndexCount = 2;
19531 swapchain_create_info.pQueueFamilyIndices = queueFamilyIndex;
19532 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
19533 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
19534 pass = (err != VK_SUCCESS);
19535 ASSERT_TRUE(pass);
19536 m_errorMonitor->VerifyFound();
19537
19538 // Next, call a queueFamilyIndexCount that's too small for CONCURRENT:
19539 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
19540 swapchain_create_info.queueFamilyIndexCount = 1;
19541 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
19542 "but with a bad value(s) for pCreateInfo->queueFamilyIndexCount or "
19543 "pCreateInfo->pQueueFamilyIndices).");
19544 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
19545 pass = (err != VK_SUCCESS);
19546 ASSERT_TRUE(pass);
19547 m_errorMonitor->VerifyFound();
19548
19549 // Next, call with an invalid imageSharingMode:
19550 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_MAX_ENUM;
19551 swapchain_create_info.queueFamilyIndexCount = 1;
19552 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
19553 "called with a non-supported pCreateInfo->imageSharingMode (i.e.");
19554 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
19555 pass = (err != VK_SUCCESS);
19556 ASSERT_TRUE(pass);
19557 m_errorMonitor->VerifyFound();
19558 // Fix for the future:
19559 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
19560 // SUPPORTED
19561 swapchain_create_info.queueFamilyIndexCount = 0;
19562 queueFamilyIndex[0] = 0;
19563 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
19564
19565 // TODO: CONTINUE TESTING VALIDATION OF vkCreateSwapchainKHR() ...
19566 // Get the images from a swapchain:
19567 // Acquire an image from a swapchain:
19568 // Present an image to a swapchain:
19569 // Destroy the swapchain:
19570
19571 // TODOs:
19572 //
19573 // - Try destroying the device without first destroying the swapchain
19574 //
19575 // - Try destroying the device without first destroying the surface
19576 //
19577 // - Try destroying the surface without first destroying the swapchain
19578
19579 // Destroy the surface:
19580 vkDestroySurfaceKHR(instance(), surface, NULL);
19581
19582 // Tear down the window:
19583 xcb_destroy_window(connection, xcb_window);
19584 xcb_disconnect(connection);
19585
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019586#else // VK_USE_PLATFORM_XCB_KHR
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019587 return;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019588#endif // VK_USE_PLATFORM_XCB_KHR
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019589}
Chris Forbes09368e42016-10-13 11:59:22 +130019590#endif
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019591
19592//
19593// POSITIVE VALIDATION TESTS
19594//
19595// These tests do not expect to encounter ANY validation errors pass only if this is true
19596
Mark Lobodzinski781aeb52017-02-22 10:57:53 -070019597TEST_F(VkPositiveLayerTest, SecondaryCommandBufferClearColorAttachments) {
19598 TEST_DESCRIPTION("Create a secondary command buffer and record a CmdClearAttachments call into it");
Tony Barbour1fa09702017-03-16 12:09:08 -060019599 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski781aeb52017-02-22 10:57:53 -070019600 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19601
19602 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
19603 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mike Schuchardt06304c22017-03-01 17:09:09 -070019604 command_buffer_allocate_info.commandPool = m_commandPool->handle();
Mark Lobodzinski781aeb52017-02-22 10:57:53 -070019605 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
19606 command_buffer_allocate_info.commandBufferCount = 1;
19607
19608 VkCommandBuffer secondary_command_buffer;
19609 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
19610 VkCommandBufferBeginInfo command_buffer_begin_info = {};
19611 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
19612 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
19613 command_buffer_inheritance_info.renderPass = m_renderPass;
19614 command_buffer_inheritance_info.framebuffer = m_framebuffer;
19615
19616 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19617 command_buffer_begin_info.flags =
19618 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
19619 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
19620
19621 vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
19622 VkClearAttachment color_attachment;
19623 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
19624 color_attachment.clearValue.color.float32[0] = 0;
19625 color_attachment.clearValue.color.float32[1] = 0;
19626 color_attachment.clearValue.color.float32[2] = 0;
19627 color_attachment.clearValue.color.float32[3] = 0;
19628 color_attachment.colorAttachment = 0;
19629 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
19630 vkCmdClearAttachments(secondary_command_buffer, 1, &color_attachment, 1, &clear_rect);
19631}
19632
Tobin Ehlise0006882016-11-03 10:14:28 -060019633TEST_F(VkPositiveLayerTest, SecondaryCommandBufferImageLayoutTransitions) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019634 TEST_DESCRIPTION(
19635 "Perform an image layout transition in a secondary command buffer followed "
19636 "by a transition in the primary.");
Tobin Ehlise0006882016-11-03 10:14:28 -060019637 VkResult err;
19638 m_errorMonitor->ExpectSuccess();
Tony Barbour1fa09702017-03-16 12:09:08 -060019639 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -060019640 auto depth_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbourf887b162017-03-09 10:06:46 -070019641 if (!depth_format) {
19642 return;
19643 }
Tobin Ehlise0006882016-11-03 10:14:28 -060019644 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19645 // Allocate a secondary and primary cmd buffer
19646 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
19647 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mike Schuchardt06304c22017-03-01 17:09:09 -070019648 command_buffer_allocate_info.commandPool = m_commandPool->handle();
Tobin Ehlise0006882016-11-03 10:14:28 -060019649 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
19650 command_buffer_allocate_info.commandBufferCount = 1;
19651
19652 VkCommandBuffer secondary_command_buffer;
19653 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
19654 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19655 VkCommandBuffer primary_command_buffer;
19656 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &primary_command_buffer));
19657 VkCommandBufferBeginInfo command_buffer_begin_info = {};
19658 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
19659 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
19660 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19661 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
19662 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
19663
19664 err = vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
19665 ASSERT_VK_SUCCESS(err);
19666 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060019667 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 -060019668 ASSERT_TRUE(image.initialized());
19669 VkImageMemoryBarrier img_barrier = {};
19670 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
19671 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
19672 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
19673 img_barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
19674 img_barrier.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19675 img_barrier.image = image.handle();
19676 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
19677 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
19678 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
19679 img_barrier.subresourceRange.baseArrayLayer = 0;
19680 img_barrier.subresourceRange.baseMipLevel = 0;
19681 img_barrier.subresourceRange.layerCount = 1;
19682 img_barrier.subresourceRange.levelCount = 1;
19683 vkCmdPipelineBarrier(secondary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr,
19684 0, nullptr, 1, &img_barrier);
19685 err = vkEndCommandBuffer(secondary_command_buffer);
19686 ASSERT_VK_SUCCESS(err);
19687
19688 // Now update primary cmd buffer to execute secondary and transitions image
19689 command_buffer_begin_info.pInheritanceInfo = nullptr;
19690 err = vkBeginCommandBuffer(primary_command_buffer, &command_buffer_begin_info);
19691 ASSERT_VK_SUCCESS(err);
19692 vkCmdExecuteCommands(primary_command_buffer, 1, &secondary_command_buffer);
19693 VkImageMemoryBarrier img_barrier2 = {};
19694 img_barrier2.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
19695 img_barrier2.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
19696 img_barrier2.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
19697 img_barrier2.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19698 img_barrier2.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19699 img_barrier2.image = image.handle();
19700 img_barrier2.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
19701 img_barrier2.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
19702 img_barrier2.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
19703 img_barrier2.subresourceRange.baseArrayLayer = 0;
19704 img_barrier2.subresourceRange.baseMipLevel = 0;
19705 img_barrier2.subresourceRange.layerCount = 1;
19706 img_barrier2.subresourceRange.levelCount = 1;
19707 vkCmdPipelineBarrier(primary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
19708 nullptr, 1, &img_barrier2);
19709 err = vkEndCommandBuffer(primary_command_buffer);
19710 ASSERT_VK_SUCCESS(err);
19711 VkSubmitInfo submit_info = {};
19712 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19713 submit_info.commandBufferCount = 1;
19714 submit_info.pCommandBuffers = &primary_command_buffer;
19715 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
19716 ASSERT_VK_SUCCESS(err);
19717 m_errorMonitor->VerifyNotFound();
19718 err = vkDeviceWaitIdle(m_device->device());
19719 ASSERT_VK_SUCCESS(err);
Mike Schuchardt06304c22017-03-01 17:09:09 -070019720 vkFreeCommandBuffers(m_device->device(), m_commandPool->handle(), 1, &secondary_command_buffer);
19721 vkFreeCommandBuffers(m_device->device(), m_commandPool->handle(), 1, &primary_command_buffer);
Tobin Ehlise0006882016-11-03 10:14:28 -060019722}
19723
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019724// This is a positive test. No failures are expected.
19725TEST_F(VkPositiveLayerTest, IgnoreUnrelatedDescriptor) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019726 TEST_DESCRIPTION(
19727 "Ensure that the vkUpdateDescriptorSets validation code "
19728 "is ignoring VkWriteDescriptorSet members that are not "
19729 "related to the descriptor type specified by "
19730 "VkWriteDescriptorSet::descriptorType. Correct "
19731 "validation behavior will result in the test running to "
19732 "completion without validation errors.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019733
19734 const uintptr_t invalid_ptr = 0xcdcdcdcd;
19735
Tony Barbour1fa09702017-03-16 12:09:08 -060019736 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019737
19738 // Image Case
19739 {
19740 m_errorMonitor->ExpectSuccess();
19741
19742 VkImage image;
19743 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
19744 const int32_t tex_width = 32;
19745 const int32_t tex_height = 32;
19746 VkImageCreateInfo image_create_info = {};
19747 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
19748 image_create_info.pNext = NULL;
19749 image_create_info.imageType = VK_IMAGE_TYPE_2D;
19750 image_create_info.format = tex_format;
19751 image_create_info.extent.width = tex_width;
19752 image_create_info.extent.height = tex_height;
19753 image_create_info.extent.depth = 1;
19754 image_create_info.mipLevels = 1;
19755 image_create_info.arrayLayers = 1;
19756 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
19757 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
19758 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
19759 image_create_info.flags = 0;
19760 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
19761 ASSERT_VK_SUCCESS(err);
19762
19763 VkMemoryRequirements memory_reqs;
19764 VkDeviceMemory image_memory;
19765 bool pass;
19766 VkMemoryAllocateInfo memory_info = {};
19767 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
19768 memory_info.pNext = NULL;
19769 memory_info.allocationSize = 0;
19770 memory_info.memoryTypeIndex = 0;
19771 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
19772 memory_info.allocationSize = memory_reqs.size;
19773 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
19774 ASSERT_TRUE(pass);
19775 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
19776 ASSERT_VK_SUCCESS(err);
19777 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
19778 ASSERT_VK_SUCCESS(err);
19779
19780 VkImageViewCreateInfo image_view_create_info = {};
19781 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
19782 image_view_create_info.image = image;
19783 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
19784 image_view_create_info.format = tex_format;
19785 image_view_create_info.subresourceRange.layerCount = 1;
19786 image_view_create_info.subresourceRange.baseMipLevel = 0;
19787 image_view_create_info.subresourceRange.levelCount = 1;
19788 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
19789
19790 VkImageView view;
19791 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
19792 ASSERT_VK_SUCCESS(err);
19793
19794 VkDescriptorPoolSize ds_type_count = {};
19795 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
19796 ds_type_count.descriptorCount = 1;
19797
19798 VkDescriptorPoolCreateInfo ds_pool_ci = {};
19799 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
19800 ds_pool_ci.pNext = NULL;
19801 ds_pool_ci.maxSets = 1;
19802 ds_pool_ci.poolSizeCount = 1;
19803 ds_pool_ci.pPoolSizes = &ds_type_count;
19804
19805 VkDescriptorPool ds_pool;
19806 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
19807 ASSERT_VK_SUCCESS(err);
19808
19809 VkDescriptorSetLayoutBinding dsl_binding = {};
19810 dsl_binding.binding = 0;
19811 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
19812 dsl_binding.descriptorCount = 1;
19813 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
19814 dsl_binding.pImmutableSamplers = NULL;
19815
19816 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
19817 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
19818 ds_layout_ci.pNext = NULL;
19819 ds_layout_ci.bindingCount = 1;
19820 ds_layout_ci.pBindings = &dsl_binding;
19821 VkDescriptorSetLayout ds_layout;
19822 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
19823 ASSERT_VK_SUCCESS(err);
19824
19825 VkDescriptorSet descriptor_set;
19826 VkDescriptorSetAllocateInfo alloc_info = {};
19827 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
19828 alloc_info.descriptorSetCount = 1;
19829 alloc_info.descriptorPool = ds_pool;
19830 alloc_info.pSetLayouts = &ds_layout;
19831 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
19832 ASSERT_VK_SUCCESS(err);
19833
19834 VkDescriptorImageInfo image_info = {};
19835 image_info.imageView = view;
19836 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
19837
19838 VkWriteDescriptorSet descriptor_write;
19839 memset(&descriptor_write, 0, sizeof(descriptor_write));
19840 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
19841 descriptor_write.dstSet = descriptor_set;
19842 descriptor_write.dstBinding = 0;
19843 descriptor_write.descriptorCount = 1;
19844 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
19845 descriptor_write.pImageInfo = &image_info;
19846
19847 // Set pBufferInfo and pTexelBufferView to invalid values, which should
19848 // be
19849 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE.
19850 // This will most likely produce a crash if the parameter_validation
19851 // layer
19852 // does not correctly ignore pBufferInfo.
19853 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
19854 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
19855
19856 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
19857
19858 m_errorMonitor->VerifyNotFound();
19859
19860 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
19861 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
19862 vkDestroyImageView(m_device->device(), view, NULL);
19863 vkDestroyImage(m_device->device(), image, NULL);
19864 vkFreeMemory(m_device->device(), image_memory, NULL);
19865 }
19866
19867 // Buffer Case
19868 {
19869 m_errorMonitor->ExpectSuccess();
19870
19871 VkBuffer buffer;
19872 uint32_t queue_family_index = 0;
19873 VkBufferCreateInfo buffer_create_info = {};
19874 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
19875 buffer_create_info.size = 1024;
19876 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
19877 buffer_create_info.queueFamilyIndexCount = 1;
19878 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
19879
19880 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
19881 ASSERT_VK_SUCCESS(err);
19882
19883 VkMemoryRequirements memory_reqs;
19884 VkDeviceMemory buffer_memory;
19885 bool pass;
19886 VkMemoryAllocateInfo memory_info = {};
19887 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
19888 memory_info.pNext = NULL;
19889 memory_info.allocationSize = 0;
19890 memory_info.memoryTypeIndex = 0;
19891
19892 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
19893 memory_info.allocationSize = memory_reqs.size;
19894 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
19895 ASSERT_TRUE(pass);
19896
19897 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
19898 ASSERT_VK_SUCCESS(err);
19899 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
19900 ASSERT_VK_SUCCESS(err);
19901
19902 VkDescriptorPoolSize ds_type_count = {};
19903 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
19904 ds_type_count.descriptorCount = 1;
19905
19906 VkDescriptorPoolCreateInfo ds_pool_ci = {};
19907 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
19908 ds_pool_ci.pNext = NULL;
19909 ds_pool_ci.maxSets = 1;
19910 ds_pool_ci.poolSizeCount = 1;
19911 ds_pool_ci.pPoolSizes = &ds_type_count;
19912
19913 VkDescriptorPool ds_pool;
19914 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
19915 ASSERT_VK_SUCCESS(err);
19916
19917 VkDescriptorSetLayoutBinding dsl_binding = {};
19918 dsl_binding.binding = 0;
19919 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
19920 dsl_binding.descriptorCount = 1;
19921 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
19922 dsl_binding.pImmutableSamplers = NULL;
19923
19924 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
19925 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
19926 ds_layout_ci.pNext = NULL;
19927 ds_layout_ci.bindingCount = 1;
19928 ds_layout_ci.pBindings = &dsl_binding;
19929 VkDescriptorSetLayout ds_layout;
19930 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
19931 ASSERT_VK_SUCCESS(err);
19932
19933 VkDescriptorSet descriptor_set;
19934 VkDescriptorSetAllocateInfo alloc_info = {};
19935 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
19936 alloc_info.descriptorSetCount = 1;
19937 alloc_info.descriptorPool = ds_pool;
19938 alloc_info.pSetLayouts = &ds_layout;
19939 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
19940 ASSERT_VK_SUCCESS(err);
19941
19942 VkDescriptorBufferInfo buffer_info = {};
19943 buffer_info.buffer = buffer;
19944 buffer_info.offset = 0;
19945 buffer_info.range = 1024;
19946
19947 VkWriteDescriptorSet descriptor_write;
19948 memset(&descriptor_write, 0, sizeof(descriptor_write));
19949 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
19950 descriptor_write.dstSet = descriptor_set;
19951 descriptor_write.dstBinding = 0;
19952 descriptor_write.descriptorCount = 1;
19953 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
19954 descriptor_write.pBufferInfo = &buffer_info;
19955
19956 // Set pImageInfo and pTexelBufferView to invalid values, which should
19957 // be
19958 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER.
19959 // This will most likely produce a crash if the parameter_validation
19960 // layer
19961 // does not correctly ignore pImageInfo.
19962 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
19963 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
19964
19965 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
19966
19967 m_errorMonitor->VerifyNotFound();
19968
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019969 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
19970 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
19971 vkDestroyBuffer(m_device->device(), buffer, NULL);
19972 vkFreeMemory(m_device->device(), buffer_memory, NULL);
19973 }
19974
19975 // Texel Buffer Case
19976 {
19977 m_errorMonitor->ExpectSuccess();
19978
19979 VkBuffer buffer;
19980 uint32_t queue_family_index = 0;
19981 VkBufferCreateInfo buffer_create_info = {};
19982 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
19983 buffer_create_info.size = 1024;
19984 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
19985 buffer_create_info.queueFamilyIndexCount = 1;
19986 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
19987
19988 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
19989 ASSERT_VK_SUCCESS(err);
19990
19991 VkMemoryRequirements memory_reqs;
19992 VkDeviceMemory buffer_memory;
19993 bool pass;
19994 VkMemoryAllocateInfo memory_info = {};
19995 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
19996 memory_info.pNext = NULL;
19997 memory_info.allocationSize = 0;
19998 memory_info.memoryTypeIndex = 0;
19999
20000 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
20001 memory_info.allocationSize = memory_reqs.size;
20002 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
20003 ASSERT_TRUE(pass);
20004
20005 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
20006 ASSERT_VK_SUCCESS(err);
20007 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
20008 ASSERT_VK_SUCCESS(err);
20009
20010 VkBufferViewCreateInfo buff_view_ci = {};
20011 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
20012 buff_view_ci.buffer = buffer;
20013 buff_view_ci.format = VK_FORMAT_R8_UNORM;
20014 buff_view_ci.range = VK_WHOLE_SIZE;
20015 VkBufferView buffer_view;
20016 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buffer_view);
20017
20018 VkDescriptorPoolSize ds_type_count = {};
20019 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
20020 ds_type_count.descriptorCount = 1;
20021
20022 VkDescriptorPoolCreateInfo ds_pool_ci = {};
20023 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
20024 ds_pool_ci.pNext = NULL;
20025 ds_pool_ci.maxSets = 1;
20026 ds_pool_ci.poolSizeCount = 1;
20027 ds_pool_ci.pPoolSizes = &ds_type_count;
20028
20029 VkDescriptorPool ds_pool;
20030 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
20031 ASSERT_VK_SUCCESS(err);
20032
20033 VkDescriptorSetLayoutBinding dsl_binding = {};
20034 dsl_binding.binding = 0;
20035 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
20036 dsl_binding.descriptorCount = 1;
20037 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
20038 dsl_binding.pImmutableSamplers = NULL;
20039
20040 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
20041 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
20042 ds_layout_ci.pNext = NULL;
20043 ds_layout_ci.bindingCount = 1;
20044 ds_layout_ci.pBindings = &dsl_binding;
20045 VkDescriptorSetLayout ds_layout;
20046 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
20047 ASSERT_VK_SUCCESS(err);
20048
20049 VkDescriptorSet descriptor_set;
20050 VkDescriptorSetAllocateInfo alloc_info = {};
20051 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
20052 alloc_info.descriptorSetCount = 1;
20053 alloc_info.descriptorPool = ds_pool;
20054 alloc_info.pSetLayouts = &ds_layout;
20055 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
20056 ASSERT_VK_SUCCESS(err);
20057
20058 VkWriteDescriptorSet descriptor_write;
20059 memset(&descriptor_write, 0, sizeof(descriptor_write));
20060 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
20061 descriptor_write.dstSet = descriptor_set;
20062 descriptor_write.dstBinding = 0;
20063 descriptor_write.descriptorCount = 1;
20064 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
20065 descriptor_write.pTexelBufferView = &buffer_view;
20066
20067 // Set pImageInfo and pBufferInfo to invalid values, which should be
20068 // ignored for descriptorType ==
20069 // VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER.
20070 // This will most likely produce a crash if the parameter_validation
20071 // layer
20072 // does not correctly ignore pImageInfo and pBufferInfo.
20073 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
20074 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
20075
20076 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
20077
20078 m_errorMonitor->VerifyNotFound();
20079
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020080 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
20081 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
20082 vkDestroyBufferView(m_device->device(), buffer_view, NULL);
20083 vkDestroyBuffer(m_device->device(), buffer, NULL);
20084 vkFreeMemory(m_device->device(), buffer_memory, NULL);
20085 }
20086}
20087
Tobin Ehlis8893af82017-05-08 12:52:25 -060020088TEST_F(VkPositiveLayerTest, ImmutableSamplerOnlyDescriptor) {
20089 TEST_DESCRIPTION(
20090 "Bind a DescriptorSet with only an immutable sampler"
20091 "and make sure that we don't warn for no update.");
20092
20093 ASSERT_NO_FATAL_FAILURE(Init());
20094 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20095
20096 VkDescriptorPoolSize ds_type_count = {};
20097 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
20098 ds_type_count.descriptorCount = 1;
20099
20100 VkDescriptorPoolCreateInfo ds_pool_ci = {};
20101 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
20102 ds_pool_ci.maxSets = 1;
20103 ds_pool_ci.poolSizeCount = 1;
20104 ds_pool_ci.pPoolSizes = &ds_type_count;
20105
20106 VkDescriptorPool ds_pool;
20107 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
20108 ASSERT_VK_SUCCESS(err);
20109
20110 VkSamplerCreateInfo sampler_ci = {};
20111 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
20112 sampler_ci.pNext = NULL;
20113 sampler_ci.magFilter = VK_FILTER_NEAREST;
20114 sampler_ci.minFilter = VK_FILTER_NEAREST;
20115 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
20116 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
20117 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
20118 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
20119 sampler_ci.mipLodBias = 1.0;
20120 sampler_ci.anisotropyEnable = VK_FALSE;
20121 sampler_ci.maxAnisotropy = 1;
20122 sampler_ci.compareEnable = VK_FALSE;
20123 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
20124 sampler_ci.minLod = 1.0;
20125 sampler_ci.maxLod = 1.0;
20126 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
20127 sampler_ci.unnormalizedCoordinates = VK_FALSE;
20128 VkSampler sampler;
20129
20130 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
20131 ASSERT_VK_SUCCESS(err);
20132
20133 VkDescriptorSetLayoutBinding layout_binding = {};
20134 layout_binding.binding = 0;
20135 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
20136 layout_binding.descriptorCount = 1;
20137 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
20138 layout_binding.pImmutableSamplers = static_cast<VkSampler *>(&sampler);
20139
20140 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
20141 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
20142 ds_layout_ci.bindingCount = 1;
20143 ds_layout_ci.pBindings = &layout_binding;
20144 VkDescriptorSetLayout ds_layout;
20145 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
20146 ASSERT_VK_SUCCESS(err);
20147
20148 VkDescriptorSetAllocateInfo alloc_info = {};
20149 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
20150 alloc_info.descriptorSetCount = 1;
20151 alloc_info.descriptorPool = ds_pool;
20152 alloc_info.pSetLayouts = &ds_layout;
20153 VkDescriptorSet descriptor_set;
20154 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
20155 ASSERT_VK_SUCCESS(err);
20156
20157 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
20158 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
20159 pipeline_layout_ci.pNext = NULL;
20160 pipeline_layout_ci.setLayoutCount = 1;
20161 pipeline_layout_ci.pSetLayouts = &ds_layout;
20162
20163 VkPipelineLayout pipeline_layout;
20164 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
20165 ASSERT_VK_SUCCESS(err);
20166
20167 m_errorMonitor->ExpectSuccess();
20168 m_commandBuffer->BeginCommandBuffer();
20169 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
20170
20171 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
20172 &descriptor_set, 0, nullptr);
20173 m_errorMonitor->VerifyNotFound();
20174
20175 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
20176 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
20177 vkDestroySampler(m_device->device(), sampler, NULL);
20178 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
20179}
20180
Tobin Ehlisf7428442016-10-25 07:58:24 -060020181TEST_F(VkLayerTest, DuplicateDescriptorBinding) {
20182 TEST_DESCRIPTION("Create a descriptor set layout with a duplicate binding number.");
20183
Tony Barbour1fa09702017-03-16 12:09:08 -060020184 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisf7428442016-10-25 07:58:24 -060020185 // Create layout where two binding #s are "1"
20186 static const uint32_t NUM_BINDINGS = 3;
20187 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
20188 dsl_binding[0].binding = 1;
20189 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
20190 dsl_binding[0].descriptorCount = 1;
20191 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
20192 dsl_binding[0].pImmutableSamplers = NULL;
20193 dsl_binding[1].binding = 0;
20194 dsl_binding[1].descriptorCount = 1;
20195 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
20196 dsl_binding[1].descriptorCount = 1;
20197 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
20198 dsl_binding[1].pImmutableSamplers = NULL;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020199 dsl_binding[2].binding = 1; // Duplicate binding should cause error
Tobin Ehlisf7428442016-10-25 07:58:24 -060020200 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
20201 dsl_binding[2].descriptorCount = 1;
20202 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
20203 dsl_binding[2].pImmutableSamplers = NULL;
20204
20205 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
20206 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
20207 ds_layout_ci.pNext = NULL;
20208 ds_layout_ci.bindingCount = NUM_BINDINGS;
20209 ds_layout_ci.pBindings = dsl_binding;
20210 VkDescriptorSetLayout ds_layout;
20211 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02345);
20212 vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
20213 m_errorMonitor->VerifyFound();
20214}
20215
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060020216TEST_F(VkLayerTest, ViewportAndScissorBoundsChecking) {
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060020217 TEST_DESCRIPTION("Verify errors are detected on misuse of SetViewport and SetScissor.");
20218
Tony Barbour1fa09702017-03-16 12:09:08 -060020219 ASSERT_NO_FATAL_FAILURE(Init());
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060020220
Tony Barbour552f6c02016-12-21 14:34:07 -070020221 m_commandBuffer->BeginCommandBuffer();
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060020222
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060020223 const VkPhysicalDeviceLimits &limits = m_device->props.limits;
20224
20225 {
20226 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01448);
20227 VkViewport viewport = {0, 0, static_cast<float>(limits.maxViewportDimensions[0] + 1), 16, 0, 1};
20228 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
20229 m_errorMonitor->VerifyFound();
20230 }
20231
20232 {
20233 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01449);
20234 VkViewport viewport = {0, 0, 16, static_cast<float>(limits.maxViewportDimensions[1] + 1), 0, 1};
20235 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
20236 m_errorMonitor->VerifyFound();
20237 }
20238
20239 {
20240 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
20241 VkViewport viewport = {limits.viewportBoundsRange[0] - 1, 0, 16, 16, 0, 1};
20242 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
20243 m_errorMonitor->VerifyFound();
20244 }
20245
20246 {
20247 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
20248 VkViewport viewport = {0, limits.viewportBoundsRange[0] - 1, 16, 16, 0, 1};
20249 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
20250 m_errorMonitor->VerifyFound();
20251 }
20252
20253 {
20254 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01451);
20255 VkViewport viewport = {limits.viewportBoundsRange[1], 0, 16, 16, 0, 1};
20256 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
20257 m_errorMonitor->VerifyFound();
20258 }
20259
20260 {
20261 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01452);
20262 VkViewport viewport = {0, limits.viewportBoundsRange[1], 16, 16, 0, 1};
20263 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
20264 m_errorMonitor->VerifyFound();
20265 }
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060020266
20267 {
20268 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
20269 VkRect2D scissor = {{-1, 0}, {16, 16}};
20270 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
20271 m_errorMonitor->VerifyFound();
20272 }
20273
20274 {
20275 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
20276 VkRect2D scissor = {{0, -2}, {16, 16}};
20277 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
20278 m_errorMonitor->VerifyFound();
20279 }
20280
20281 {
20282 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01490);
20283 VkRect2D scissor = {{100, 100}, {INT_MAX, 16}};
20284 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
20285 m_errorMonitor->VerifyFound();
20286 }
20287
20288 {
20289 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01491);
20290 VkRect2D scissor = {{100, 100}, {16, INT_MAX}};
20291 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
20292 m_errorMonitor->VerifyFound();
20293 }
20294
Tony Barbour552f6c02016-12-21 14:34:07 -070020295 m_commandBuffer->EndCommandBuffer();
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060020296}
20297
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020298// This is a positive test. No failures are expected.
20299TEST_F(VkPositiveLayerTest, EmptyDescriptorUpdateTest) {
20300 TEST_DESCRIPTION("Update last descriptor in a set that includes an empty binding");
20301 VkResult err;
20302
Tony Barbour1fa09702017-03-16 12:09:08 -060020303 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020304 m_errorMonitor->ExpectSuccess();
20305 VkDescriptorPoolSize ds_type_count = {};
20306 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
20307 ds_type_count.descriptorCount = 2;
20308
20309 VkDescriptorPoolCreateInfo ds_pool_ci = {};
20310 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
20311 ds_pool_ci.pNext = NULL;
20312 ds_pool_ci.maxSets = 1;
20313 ds_pool_ci.poolSizeCount = 1;
20314 ds_pool_ci.pPoolSizes = &ds_type_count;
20315
20316 VkDescriptorPool ds_pool;
20317 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
20318 ASSERT_VK_SUCCESS(err);
20319
20320 // Create layout with two uniform buffer descriptors w/ empty binding between them
20321 static const uint32_t NUM_BINDINGS = 3;
20322 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
20323 dsl_binding[0].binding = 0;
20324 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
20325 dsl_binding[0].descriptorCount = 1;
20326 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
20327 dsl_binding[0].pImmutableSamplers = NULL;
20328 dsl_binding[1].binding = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020329 dsl_binding[1].descriptorCount = 0; // empty binding
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020330 dsl_binding[2].binding = 2;
20331 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
20332 dsl_binding[2].descriptorCount = 1;
20333 dsl_binding[2].stageFlags = VK_SHADER_STAGE_ALL;
20334 dsl_binding[2].pImmutableSamplers = NULL;
20335
20336 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
20337 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
20338 ds_layout_ci.pNext = NULL;
20339 ds_layout_ci.bindingCount = NUM_BINDINGS;
20340 ds_layout_ci.pBindings = dsl_binding;
20341 VkDescriptorSetLayout ds_layout;
20342 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
20343 ASSERT_VK_SUCCESS(err);
20344
20345 VkDescriptorSet descriptor_set = {};
20346 VkDescriptorSetAllocateInfo alloc_info = {};
20347 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
20348 alloc_info.descriptorSetCount = 1;
20349 alloc_info.descriptorPool = ds_pool;
20350 alloc_info.pSetLayouts = &ds_layout;
20351 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
20352 ASSERT_VK_SUCCESS(err);
20353
20354 // Create a buffer to be used for update
20355 VkBufferCreateInfo buff_ci = {};
20356 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
20357 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
20358 buff_ci.size = 256;
20359 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
20360 VkBuffer buffer;
20361 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
20362 ASSERT_VK_SUCCESS(err);
20363 // Have to bind memory to buffer before descriptor update
20364 VkMemoryAllocateInfo mem_alloc = {};
20365 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
20366 mem_alloc.pNext = NULL;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020367 mem_alloc.allocationSize = 512; // one allocation for both buffers
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020368 mem_alloc.memoryTypeIndex = 0;
20369
20370 VkMemoryRequirements mem_reqs;
20371 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
20372 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
20373 if (!pass) {
20374 vkDestroyBuffer(m_device->device(), buffer, NULL);
20375 return;
20376 }
20377
20378 VkDeviceMemory mem;
20379 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
20380 ASSERT_VK_SUCCESS(err);
20381 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
20382 ASSERT_VK_SUCCESS(err);
20383
20384 // Only update the descriptor at binding 2
20385 VkDescriptorBufferInfo buff_info = {};
20386 buff_info.buffer = buffer;
20387 buff_info.offset = 0;
20388 buff_info.range = VK_WHOLE_SIZE;
20389 VkWriteDescriptorSet descriptor_write = {};
20390 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
20391 descriptor_write.dstBinding = 2;
20392 descriptor_write.descriptorCount = 1;
20393 descriptor_write.pTexelBufferView = nullptr;
20394 descriptor_write.pBufferInfo = &buff_info;
20395 descriptor_write.pImageInfo = nullptr;
20396 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
20397 descriptor_write.dstSet = descriptor_set;
20398
20399 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
20400
20401 m_errorMonitor->VerifyNotFound();
20402 // Cleanup
20403 vkFreeMemory(m_device->device(), mem, NULL);
20404 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
20405 vkDestroyBuffer(m_device->device(), buffer, NULL);
20406 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
20407}
20408
20409// This is a positive test. No failures are expected.
20410TEST_F(VkPositiveLayerTest, TestAliasedMemoryTracking) {
20411 VkResult err;
20412 bool pass;
20413
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020414 TEST_DESCRIPTION(
20415 "Create a buffer, allocate memory, bind memory, destroy "
20416 "the buffer, create an image, and bind the same memory to "
20417 "it");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020418
20419 m_errorMonitor->ExpectSuccess();
20420
Tony Barbour1fa09702017-03-16 12:09:08 -060020421 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020422
20423 VkBuffer buffer;
20424 VkImage image;
20425 VkDeviceMemory mem;
20426 VkMemoryRequirements mem_reqs;
20427
20428 VkBufferCreateInfo buf_info = {};
20429 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
20430 buf_info.pNext = NULL;
20431 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
20432 buf_info.size = 256;
20433 buf_info.queueFamilyIndexCount = 0;
20434 buf_info.pQueueFamilyIndices = NULL;
20435 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
20436 buf_info.flags = 0;
20437 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
20438 ASSERT_VK_SUCCESS(err);
20439
20440 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
20441
20442 VkMemoryAllocateInfo alloc_info = {};
20443 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
20444 alloc_info.pNext = NULL;
20445 alloc_info.memoryTypeIndex = 0;
Dave Houlton9dae7ec2017-03-01 16:23:25 -070020446
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020447 // Ensure memory is big enough for both bindings
20448 alloc_info.allocationSize = 0x10000;
20449
20450 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
20451 if (!pass) {
20452 vkDestroyBuffer(m_device->device(), buffer, NULL);
20453 return;
20454 }
20455
20456 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
20457 ASSERT_VK_SUCCESS(err);
20458
20459 uint8_t *pData;
20460 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
20461 ASSERT_VK_SUCCESS(err);
20462
20463 memset(pData, 0xCADECADE, static_cast<size_t>(mem_reqs.size));
20464
20465 vkUnmapMemory(m_device->device(), mem);
20466
20467 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
20468 ASSERT_VK_SUCCESS(err);
20469
20470 // NOW, destroy the buffer. Obviously, the resource no longer occupies this
20471 // memory. In fact, it was never used by the GPU.
20472 // Just be be sure, wait for idle.
20473 vkDestroyBuffer(m_device->device(), buffer, NULL);
20474 vkDeviceWaitIdle(m_device->device());
20475
Tobin Ehlis6a005702016-12-28 15:25:56 -070020476 // Use optimal as some platforms report linear support but then fail image creation
20477 VkImageTiling image_tiling = VK_IMAGE_TILING_OPTIMAL;
20478 VkImageFormatProperties image_format_properties;
20479 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D, image_tiling,
20480 VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0, &image_format_properties);
20481 if (image_format_properties.maxExtent.width == 0) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070020482 printf(" Image format not supported; skipped.\n");
Tobin Ehlis6a005702016-12-28 15:25:56 -070020483 vkFreeMemory(m_device->device(), mem, NULL);
20484 return;
20485 }
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020486 VkImageCreateInfo image_create_info = {};
20487 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
20488 image_create_info.pNext = NULL;
20489 image_create_info.imageType = VK_IMAGE_TYPE_2D;
20490 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
20491 image_create_info.extent.width = 64;
20492 image_create_info.extent.height = 64;
20493 image_create_info.extent.depth = 1;
20494 image_create_info.mipLevels = 1;
20495 image_create_info.arrayLayers = 1;
20496 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis6a005702016-12-28 15:25:56 -070020497 image_create_info.tiling = image_tiling;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020498 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
20499 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
20500 image_create_info.queueFamilyIndexCount = 0;
20501 image_create_info.pQueueFamilyIndices = NULL;
20502 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
20503 image_create_info.flags = 0;
20504
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020505 /* Create a mappable image. It will be the texture if linear images are ok
Dave Houlton9dae7ec2017-03-01 16:23:25 -070020506 * to be textures or it will be the staging image if they are not.
20507 */
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020508 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
20509 ASSERT_VK_SUCCESS(err);
20510
20511 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
20512
Tobin Ehlis6a005702016-12-28 15:25:56 -070020513 VkMemoryAllocateInfo mem_alloc = {};
20514 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
20515 mem_alloc.pNext = NULL;
20516 mem_alloc.allocationSize = 0;
20517 mem_alloc.memoryTypeIndex = 0;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020518 mem_alloc.allocationSize = mem_reqs.size;
20519
20520 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
20521 if (!pass) {
Tobin Ehlis6a005702016-12-28 15:25:56 -070020522 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020523 vkDestroyImage(m_device->device(), image, NULL);
20524 return;
20525 }
20526
20527 // VALIDATION FAILURE:
20528 err = vkBindImageMemory(m_device->device(), image, mem, 0);
20529 ASSERT_VK_SUCCESS(err);
20530
20531 m_errorMonitor->VerifyNotFound();
20532
20533 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020534 vkDestroyImage(m_device->device(), image, NULL);
20535}
20536
Tony Barbourab713912017-02-02 14:17:35 -070020537// This is a positive test. No failures are expected.
20538TEST_F(VkPositiveLayerTest, TestDestroyFreeNullHandles) {
20539 VkResult err;
20540
20541 TEST_DESCRIPTION(
20542 "Call all applicable destroy and free routines with NULL"
20543 "handles, expecting no validation errors");
20544
20545 m_errorMonitor->ExpectSuccess();
20546
Tony Barbour1fa09702017-03-16 12:09:08 -060020547 ASSERT_NO_FATAL_FAILURE(Init());
Tony Barbourab713912017-02-02 14:17:35 -070020548 vkDestroyBuffer(m_device->device(), VK_NULL_HANDLE, NULL);
20549 vkDestroyBufferView(m_device->device(), VK_NULL_HANDLE, NULL);
20550 vkDestroyCommandPool(m_device->device(), VK_NULL_HANDLE, NULL);
20551 vkDestroyDescriptorPool(m_device->device(), VK_NULL_HANDLE, NULL);
20552 vkDestroyDescriptorSetLayout(m_device->device(), VK_NULL_HANDLE, NULL);
20553 vkDestroyDevice(VK_NULL_HANDLE, NULL);
20554 vkDestroyEvent(m_device->device(), VK_NULL_HANDLE, NULL);
20555 vkDestroyFence(m_device->device(), VK_NULL_HANDLE, NULL);
20556 vkDestroyFramebuffer(m_device->device(), VK_NULL_HANDLE, NULL);
20557 vkDestroyImage(m_device->device(), VK_NULL_HANDLE, NULL);
20558 vkDestroyImageView(m_device->device(), VK_NULL_HANDLE, NULL);
20559 vkDestroyInstance(VK_NULL_HANDLE, NULL);
20560 vkDestroyPipeline(m_device->device(), VK_NULL_HANDLE, NULL);
20561 vkDestroyPipelineCache(m_device->device(), VK_NULL_HANDLE, NULL);
20562 vkDestroyPipelineLayout(m_device->device(), VK_NULL_HANDLE, NULL);
20563 vkDestroyQueryPool(m_device->device(), VK_NULL_HANDLE, NULL);
20564 vkDestroyRenderPass(m_device->device(), VK_NULL_HANDLE, NULL);
20565 vkDestroySampler(m_device->device(), VK_NULL_HANDLE, NULL);
20566 vkDestroySemaphore(m_device->device(), VK_NULL_HANDLE, NULL);
20567 vkDestroyShaderModule(m_device->device(), VK_NULL_HANDLE, NULL);
20568
20569 VkCommandPool command_pool;
20570 VkCommandPoolCreateInfo pool_create_info{};
20571 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20572 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20573 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20574 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20575 VkCommandBuffer command_buffers[3] = {};
20576 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20577 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20578 command_buffer_allocate_info.commandPool = command_pool;
20579 command_buffer_allocate_info.commandBufferCount = 1;
20580 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20581 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffers[1]);
20582 vkFreeCommandBuffers(m_device->device(), command_pool, 3, command_buffers);
20583 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20584
20585 VkDescriptorPoolSize ds_type_count = {};
20586 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
20587 ds_type_count.descriptorCount = 1;
20588
20589 VkDescriptorPoolCreateInfo ds_pool_ci = {};
20590 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
20591 ds_pool_ci.pNext = NULL;
20592 ds_pool_ci.maxSets = 1;
20593 ds_pool_ci.poolSizeCount = 1;
20594 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
20595 ds_pool_ci.pPoolSizes = &ds_type_count;
20596
20597 VkDescriptorPool ds_pool;
20598 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
20599 ASSERT_VK_SUCCESS(err);
20600
20601 VkDescriptorSetLayoutBinding dsl_binding = {};
20602 dsl_binding.binding = 2;
20603 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
20604 dsl_binding.descriptorCount = 1;
20605 dsl_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
20606 dsl_binding.pImmutableSamplers = NULL;
20607 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
20608 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
20609 ds_layout_ci.pNext = NULL;
20610 ds_layout_ci.bindingCount = 1;
20611 ds_layout_ci.pBindings = &dsl_binding;
20612 VkDescriptorSetLayout ds_layout;
20613 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
20614 ASSERT_VK_SUCCESS(err);
20615
20616 VkDescriptorSet descriptor_sets[3] = {};
20617 VkDescriptorSetAllocateInfo alloc_info = {};
20618 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
20619 alloc_info.descriptorSetCount = 1;
20620 alloc_info.descriptorPool = ds_pool;
20621 alloc_info.pSetLayouts = &ds_layout;
20622 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_sets[1]);
20623 ASSERT_VK_SUCCESS(err);
20624 vkFreeDescriptorSets(m_device->device(), ds_pool, 3, descriptor_sets);
20625 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
20626 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
20627
20628 vkFreeMemory(m_device->device(), VK_NULL_HANDLE, NULL);
20629
20630 m_errorMonitor->VerifyNotFound();
20631}
20632
Tony Barbour626994c2017-02-08 15:29:37 -070020633TEST_F(VkPositiveLayerTest, QueueSubmitSemaphoresAndLayoutTracking) {
Tony Barboure0c5cc92017-02-08 13:53:39 -070020634 TEST_DESCRIPTION("Submit multiple command buffers with chained semaphore signals and layout transitions");
Tony Barbour626994c2017-02-08 15:29:37 -070020635
20636 m_errorMonitor->ExpectSuccess();
20637
Tony Barbour1fa09702017-03-16 12:09:08 -060020638 ASSERT_NO_FATAL_FAILURE(Init());
Tony Barbour626994c2017-02-08 15:29:37 -070020639 VkCommandBuffer cmd_bufs[4];
20640 VkCommandBufferAllocateInfo alloc_info;
20641 alloc_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20642 alloc_info.pNext = NULL;
20643 alloc_info.commandBufferCount = 4;
Mike Schuchardt06304c22017-03-01 17:09:09 -070020644 alloc_info.commandPool = m_commandPool->handle();
Tony Barbour626994c2017-02-08 15:29:37 -070020645 alloc_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20646 vkAllocateCommandBuffers(m_device->device(), &alloc_info, cmd_bufs);
20647 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060020648 image.Init(128, 128, 1, VK_FORMAT_B8G8R8A8_UNORM,
Mike Weiblen62d08a32017-03-07 22:18:27 -070020649 (VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT),
20650 VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbour626994c2017-02-08 15:29:37 -070020651 ASSERT_TRUE(image.initialized());
20652 VkCommandBufferBeginInfo cb_binfo;
20653 cb_binfo.pNext = NULL;
20654 cb_binfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20655 cb_binfo.pInheritanceInfo = VK_NULL_HANDLE;
20656 cb_binfo.flags = 0;
20657 // Use 4 command buffers, each with an image layout transition, ColorAO->General->ColorAO->TransferSrc->TransferDst
20658 vkBeginCommandBuffer(cmd_bufs[0], &cb_binfo);
20659 VkImageMemoryBarrier img_barrier = {};
20660 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
20661 img_barrier.pNext = NULL;
20662 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
20663 img_barrier.dstAccessMask = VK_ACCESS_HOST_WRITE_BIT;
20664 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
20665 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
20666 img_barrier.image = image.handle();
20667 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
20668 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
20669 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
20670 img_barrier.subresourceRange.baseArrayLayer = 0;
20671 img_barrier.subresourceRange.baseMipLevel = 0;
20672 img_barrier.subresourceRange.layerCount = 1;
20673 img_barrier.subresourceRange.levelCount = 1;
20674 vkCmdPipelineBarrier(cmd_bufs[0], VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 0, nullptr, 0, nullptr, 1,
20675 &img_barrier);
20676 vkEndCommandBuffer(cmd_bufs[0]);
20677 vkBeginCommandBuffer(cmd_bufs[1], &cb_binfo);
20678 img_barrier.oldLayout = VK_IMAGE_LAYOUT_GENERAL;
20679 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
20680 vkCmdPipelineBarrier(cmd_bufs[1], VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 0, nullptr, 0, nullptr, 1,
20681 &img_barrier);
20682 vkEndCommandBuffer(cmd_bufs[1]);
20683 vkBeginCommandBuffer(cmd_bufs[2], &cb_binfo);
20684 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
20685 img_barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
20686 vkCmdPipelineBarrier(cmd_bufs[2], VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 0, nullptr, 0, nullptr, 1,
20687 &img_barrier);
20688 vkEndCommandBuffer(cmd_bufs[2]);
20689 vkBeginCommandBuffer(cmd_bufs[3], &cb_binfo);
20690 img_barrier.oldLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
20691 img_barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
20692 vkCmdPipelineBarrier(cmd_bufs[3], VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 0, nullptr, 0, nullptr, 1,
20693 &img_barrier);
20694 vkEndCommandBuffer(cmd_bufs[3]);
20695
20696 // Submit 4 command buffers in 3 submits, with submits 2 and 3 waiting for semaphores from submits 1 and 2
20697 VkSemaphore semaphore1, semaphore2;
20698 VkSemaphoreCreateInfo semaphore_create_info{};
20699 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
20700 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore1);
20701 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore2);
20702 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
20703 VkSubmitInfo submit_info[3];
20704 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20705 submit_info[0].pNext = nullptr;
20706 submit_info[0].commandBufferCount = 1;
20707 submit_info[0].pCommandBuffers = &cmd_bufs[0];
20708 submit_info[0].signalSemaphoreCount = 1;
20709 submit_info[0].pSignalSemaphores = &semaphore1;
20710 submit_info[0].waitSemaphoreCount = 0;
20711 submit_info[0].pWaitDstStageMask = nullptr;
20712 submit_info[0].pWaitDstStageMask = flags;
20713 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20714 submit_info[1].pNext = nullptr;
20715 submit_info[1].commandBufferCount = 1;
20716 submit_info[1].pCommandBuffers = &cmd_bufs[1];
20717 submit_info[1].waitSemaphoreCount = 1;
20718 submit_info[1].pWaitSemaphores = &semaphore1;
20719 submit_info[1].signalSemaphoreCount = 1;
20720 submit_info[1].pSignalSemaphores = &semaphore2;
20721 submit_info[1].pWaitDstStageMask = flags;
20722 submit_info[2].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20723 submit_info[2].pNext = nullptr;
20724 submit_info[2].commandBufferCount = 2;
20725 submit_info[2].pCommandBuffers = &cmd_bufs[2];
20726 submit_info[2].waitSemaphoreCount = 1;
20727 submit_info[2].pWaitSemaphores = &semaphore2;
20728 submit_info[2].signalSemaphoreCount = 0;
20729 submit_info[2].pSignalSemaphores = nullptr;
20730 submit_info[2].pWaitDstStageMask = flags;
20731 vkQueueSubmit(m_device->m_queue, 3, submit_info, VK_NULL_HANDLE);
20732 vkQueueWaitIdle(m_device->m_queue);
20733
20734 vkDestroySemaphore(m_device->device(), semaphore1, NULL);
20735 vkDestroySemaphore(m_device->device(), semaphore2, NULL);
20736 m_errorMonitor->VerifyNotFound();
20737}
20738
Tobin Ehlis953e8392016-11-17 10:54:13 -070020739TEST_F(VkPositiveLayerTest, DynamicOffsetWithInactiveBinding) {
20740 // Create a descriptorSet w/ dynamic descriptors where 1 binding is inactive
20741 // We previously had a bug where dynamic offset of inactive bindings was still being used
20742 VkResult err;
20743 m_errorMonitor->ExpectSuccess();
20744
Tony Barbour1fa09702017-03-16 12:09:08 -060020745 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis953e8392016-11-17 10:54:13 -070020746 ASSERT_NO_FATAL_FAILURE(InitViewport());
20747 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20748
20749 VkDescriptorPoolSize ds_type_count = {};
20750 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
20751 ds_type_count.descriptorCount = 3;
20752
20753 VkDescriptorPoolCreateInfo ds_pool_ci = {};
20754 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
20755 ds_pool_ci.pNext = NULL;
20756 ds_pool_ci.maxSets = 1;
20757 ds_pool_ci.poolSizeCount = 1;
20758 ds_pool_ci.pPoolSizes = &ds_type_count;
20759
20760 VkDescriptorPool ds_pool;
20761 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
20762 ASSERT_VK_SUCCESS(err);
20763
20764 const uint32_t BINDING_COUNT = 3;
20765 VkDescriptorSetLayoutBinding dsl_binding[BINDING_COUNT] = {};
Tobin Ehlis0050fba2016-11-30 10:22:02 -070020766 dsl_binding[0].binding = 2;
Tobin Ehlis953e8392016-11-17 10:54:13 -070020767 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
20768 dsl_binding[0].descriptorCount = 1;
20769 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
20770 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis0050fba2016-11-30 10:22:02 -070020771 dsl_binding[1].binding = 0;
Tobin Ehlis953e8392016-11-17 10:54:13 -070020772 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
20773 dsl_binding[1].descriptorCount = 1;
20774 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
20775 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis0050fba2016-11-30 10:22:02 -070020776 dsl_binding[2].binding = 1;
Tobin Ehlis953e8392016-11-17 10:54:13 -070020777 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
20778 dsl_binding[2].descriptorCount = 1;
20779 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
20780 dsl_binding[2].pImmutableSamplers = NULL;
20781
20782 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
20783 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
20784 ds_layout_ci.pNext = NULL;
20785 ds_layout_ci.bindingCount = BINDING_COUNT;
20786 ds_layout_ci.pBindings = dsl_binding;
20787 VkDescriptorSetLayout ds_layout;
20788 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
20789 ASSERT_VK_SUCCESS(err);
20790
20791 VkDescriptorSet descriptor_set;
20792 VkDescriptorSetAllocateInfo alloc_info = {};
20793 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
20794 alloc_info.descriptorSetCount = 1;
20795 alloc_info.descriptorPool = ds_pool;
20796 alloc_info.pSetLayouts = &ds_layout;
20797 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
20798 ASSERT_VK_SUCCESS(err);
20799
20800 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
20801 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
20802 pipeline_layout_ci.pNext = NULL;
20803 pipeline_layout_ci.setLayoutCount = 1;
20804 pipeline_layout_ci.pSetLayouts = &ds_layout;
20805
20806 VkPipelineLayout pipeline_layout;
20807 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
20808 ASSERT_VK_SUCCESS(err);
20809
20810 // Create two buffers to update the descriptors with
20811 // The first will be 2k and used for bindings 0 & 1, the second is 1k for binding 2
20812 uint32_t qfi = 0;
20813 VkBufferCreateInfo buffCI = {};
20814 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
20815 buffCI.size = 2048;
20816 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
20817 buffCI.queueFamilyIndexCount = 1;
20818 buffCI.pQueueFamilyIndices = &qfi;
20819
20820 VkBuffer dyub1;
20821 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub1);
20822 ASSERT_VK_SUCCESS(err);
20823 // buffer2
20824 buffCI.size = 1024;
20825 VkBuffer dyub2;
20826 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub2);
20827 ASSERT_VK_SUCCESS(err);
20828 // Allocate memory and bind to buffers
20829 VkMemoryAllocateInfo mem_alloc[2] = {};
20830 mem_alloc[0].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
20831 mem_alloc[0].pNext = NULL;
20832 mem_alloc[0].memoryTypeIndex = 0;
20833 mem_alloc[1].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
20834 mem_alloc[1].pNext = NULL;
20835 mem_alloc[1].memoryTypeIndex = 0;
20836
20837 VkMemoryRequirements mem_reqs1;
20838 vkGetBufferMemoryRequirements(m_device->device(), dyub1, &mem_reqs1);
20839 VkMemoryRequirements mem_reqs2;
20840 vkGetBufferMemoryRequirements(m_device->device(), dyub2, &mem_reqs2);
20841 mem_alloc[0].allocationSize = mem_reqs1.size;
20842 bool pass = m_device->phy().set_memory_type(mem_reqs1.memoryTypeBits, &mem_alloc[0], 0);
20843 mem_alloc[1].allocationSize = mem_reqs2.size;
20844 pass &= m_device->phy().set_memory_type(mem_reqs2.memoryTypeBits, &mem_alloc[1], 0);
20845 if (!pass) {
20846 vkDestroyBuffer(m_device->device(), dyub1, NULL);
20847 vkDestroyBuffer(m_device->device(), dyub2, NULL);
20848 return;
20849 }
20850
20851 VkDeviceMemory mem1;
20852 err = vkAllocateMemory(m_device->device(), &mem_alloc[0], NULL, &mem1);
20853 ASSERT_VK_SUCCESS(err);
20854 err = vkBindBufferMemory(m_device->device(), dyub1, mem1, 0);
20855 ASSERT_VK_SUCCESS(err);
20856 VkDeviceMemory mem2;
20857 err = vkAllocateMemory(m_device->device(), &mem_alloc[1], NULL, &mem2);
20858 ASSERT_VK_SUCCESS(err);
20859 err = vkBindBufferMemory(m_device->device(), dyub2, mem2, 0);
20860 ASSERT_VK_SUCCESS(err);
20861 // Update descriptors
20862 VkDescriptorBufferInfo buff_info[BINDING_COUNT] = {};
20863 buff_info[0].buffer = dyub1;
20864 buff_info[0].offset = 0;
20865 buff_info[0].range = 256;
20866 buff_info[1].buffer = dyub1;
20867 buff_info[1].offset = 256;
20868 buff_info[1].range = 512;
20869 buff_info[2].buffer = dyub2;
20870 buff_info[2].offset = 0;
20871 buff_info[2].range = 512;
20872
20873 VkWriteDescriptorSet descriptor_write;
20874 memset(&descriptor_write, 0, sizeof(descriptor_write));
20875 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
20876 descriptor_write.dstSet = descriptor_set;
20877 descriptor_write.dstBinding = 0;
20878 descriptor_write.descriptorCount = BINDING_COUNT;
20879 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
20880 descriptor_write.pBufferInfo = buff_info;
20881
20882 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
20883
Tony Barbour552f6c02016-12-21 14:34:07 -070020884 m_commandBuffer->BeginCommandBuffer();
20885 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis953e8392016-11-17 10:54:13 -070020886
20887 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020888 char const *vsSource =
20889 "#version 450\n"
20890 "\n"
20891 "out gl_PerVertex { \n"
20892 " vec4 gl_Position;\n"
20893 "};\n"
20894 "void main(){\n"
20895 " gl_Position = vec4(1);\n"
20896 "}\n";
20897 char const *fsSource =
20898 "#version 450\n"
20899 "\n"
20900 "layout(location=0) out vec4 x;\n"
20901 "layout(set=0) layout(binding=0) uniform foo1 { int x; int y; } bar1;\n"
20902 "layout(set=0) layout(binding=2) uniform foo2 { int x; int y; } bar2;\n"
20903 "void main(){\n"
20904 " x = vec4(bar1.y) + vec4(bar2.y);\n"
20905 "}\n";
Tobin Ehlis953e8392016-11-17 10:54:13 -070020906 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
20907 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
20908 VkPipelineObj pipe(m_device);
20909 pipe.SetViewport(m_viewports);
20910 pipe.SetScissor(m_scissors);
20911 pipe.AddShader(&vs);
20912 pipe.AddShader(&fs);
20913 pipe.AddColorAttachment();
20914 pipe.CreateVKPipeline(pipeline_layout, renderPass());
20915
20916 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
20917 // This update should succeed, but offset of inactive binding 1 oversteps binding 2 buffer size
20918 // we used to have a bug in this case.
20919 uint32_t dyn_off[BINDING_COUNT] = {0, 1024, 256};
20920 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
20921 &descriptor_set, BINDING_COUNT, dyn_off);
20922 Draw(1, 0, 0, 0);
20923 m_errorMonitor->VerifyNotFound();
20924
20925 vkDestroyBuffer(m_device->device(), dyub1, NULL);
20926 vkDestroyBuffer(m_device->device(), dyub2, NULL);
20927 vkFreeMemory(m_device->device(), mem1, NULL);
20928 vkFreeMemory(m_device->device(), mem2, NULL);
20929
20930 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
20931 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
20932 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
20933}
20934
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020935TEST_F(VkPositiveLayerTest, NonCoherentMemoryMapping) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020936 TEST_DESCRIPTION(
20937 "Ensure that validations handling of non-coherent memory "
20938 "mapping while using VK_WHOLE_SIZE does not cause access "
20939 "violations");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020940 VkResult err;
20941 uint8_t *pData;
Tony Barbour1fa09702017-03-16 12:09:08 -060020942 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020943
20944 VkDeviceMemory mem;
20945 VkMemoryRequirements mem_reqs;
20946 mem_reqs.memoryTypeBits = 0xFFFFFFFF;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070020947 const VkDeviceSize atom_size = m_device->props.limits.nonCoherentAtomSize;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020948 VkMemoryAllocateInfo alloc_info = {};
20949 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
20950 alloc_info.pNext = NULL;
20951 alloc_info.memoryTypeIndex = 0;
20952
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070020953 static const VkDeviceSize allocation_size = 32 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020954 alloc_info.allocationSize = allocation_size;
20955
20956 // Find a memory configurations WITHOUT a COHERENT bit, otherwise exit
20957 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 -070020958 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020959 if (!pass) {
20960 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020961 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
20962 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020963 if (!pass) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020964 pass = m_device->phy().set_memory_type(
20965 mem_reqs.memoryTypeBits, &alloc_info,
20966 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT | VK_MEMORY_PROPERTY_HOST_CACHED_BIT,
20967 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020968 if (!pass) {
20969 return;
20970 }
20971 }
20972 }
20973
20974 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
20975 ASSERT_VK_SUCCESS(err);
20976
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070020977 // Map/Flush/Invalidate using WHOLE_SIZE and zero offsets and entire mapped range
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020978 m_errorMonitor->ExpectSuccess();
20979 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
20980 ASSERT_VK_SUCCESS(err);
20981 VkMappedMemoryRange mmr = {};
20982 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
20983 mmr.memory = mem;
20984 mmr.offset = 0;
20985 mmr.size = VK_WHOLE_SIZE;
20986 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
20987 ASSERT_VK_SUCCESS(err);
20988 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
20989 ASSERT_VK_SUCCESS(err);
20990 m_errorMonitor->VerifyNotFound();
20991 vkUnmapMemory(m_device->device(), mem);
20992
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070020993 // Map/Flush/Invalidate using WHOLE_SIZE and an offset and entire mapped range
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020994 m_errorMonitor->ExpectSuccess();
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070020995 err = vkMapMemory(m_device->device(), mem, 5 * atom_size, VK_WHOLE_SIZE, 0, (void **)&pData);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020996 ASSERT_VK_SUCCESS(err);
20997 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
20998 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070020999 mmr.offset = 6 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021000 mmr.size = VK_WHOLE_SIZE;
21001 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
21002 ASSERT_VK_SUCCESS(err);
21003 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
21004 ASSERT_VK_SUCCESS(err);
21005 m_errorMonitor->VerifyNotFound();
21006 vkUnmapMemory(m_device->device(), mem);
21007
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070021008 // Map with offset and size
21009 // Flush/Invalidate subrange of mapped area with offset and size
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021010 m_errorMonitor->ExpectSuccess();
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070021011 err = vkMapMemory(m_device->device(), mem, 3 * atom_size, 9 * atom_size, 0, (void **)&pData);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021012 ASSERT_VK_SUCCESS(err);
21013 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
21014 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070021015 mmr.offset = 4 * atom_size;
21016 mmr.size = 2 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021017 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
21018 ASSERT_VK_SUCCESS(err);
21019 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
21020 ASSERT_VK_SUCCESS(err);
21021 m_errorMonitor->VerifyNotFound();
21022 vkUnmapMemory(m_device->device(), mem);
21023
21024 // Map without offset and flush WHOLE_SIZE with two separate offsets
21025 m_errorMonitor->ExpectSuccess();
21026 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
21027 ASSERT_VK_SUCCESS(err);
21028 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
21029 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070021030 mmr.offset = allocation_size - (4 * atom_size);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021031 mmr.size = VK_WHOLE_SIZE;
21032 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
21033 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070021034 mmr.offset = allocation_size - (6 * 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);
21038 m_errorMonitor->VerifyNotFound();
21039 vkUnmapMemory(m_device->device(), mem);
21040
21041 vkFreeMemory(m_device->device(), mem, NULL);
21042}
21043
21044// This is a positive test. We used to expect error in this case but spec now allows it
21045TEST_F(VkPositiveLayerTest, ResetUnsignaledFence) {
21046 m_errorMonitor->ExpectSuccess();
21047 vk_testing::Fence testFence;
21048 VkFenceCreateInfo fenceInfo = {};
21049 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
21050 fenceInfo.pNext = NULL;
21051
Tony Barbour1fa09702017-03-16 12:09:08 -060021052 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021053 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021054 VkFence fences[1] = {testFence.handle()};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021055 VkResult result = vkResetFences(m_device->device(), 1, fences);
21056 ASSERT_VK_SUCCESS(result);
21057
21058 m_errorMonitor->VerifyNotFound();
21059}
21060
21061TEST_F(VkPositiveLayerTest, CommandBufferSimultaneousUseSync) {
21062 m_errorMonitor->ExpectSuccess();
21063
Tony Barbour1fa09702017-03-16 12:09:08 -060021064 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021065 VkResult err;
21066
21067 // Record (empty!) command buffer that can be submitted multiple times
21068 // simultaneously.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021069 VkCommandBufferBeginInfo cbbi = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
21070 VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021071 m_commandBuffer->BeginCommandBuffer(&cbbi);
21072 m_commandBuffer->EndCommandBuffer();
21073
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021074 VkFenceCreateInfo fci = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021075 VkFence fence;
21076 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
21077 ASSERT_VK_SUCCESS(err);
21078
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021079 VkSemaphoreCreateInfo sci = {VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021080 VkSemaphore s1, s2;
21081 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s1);
21082 ASSERT_VK_SUCCESS(err);
21083 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s2);
21084 ASSERT_VK_SUCCESS(err);
21085
21086 // Submit CB once signaling s1, with fence so we can roll forward to its retirement.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021087 VkSubmitInfo si = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &m_commandBuffer->handle(), 1, &s1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021088 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
21089 ASSERT_VK_SUCCESS(err);
21090
21091 // Submit CB again, signaling s2.
21092 si.pSignalSemaphores = &s2;
21093 err = vkQueueSubmit(m_device->m_queue, 1, &si, VK_NULL_HANDLE);
21094 ASSERT_VK_SUCCESS(err);
21095
21096 // Wait for fence.
21097 err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
21098 ASSERT_VK_SUCCESS(err);
21099
21100 // CB is still in flight from second submission, but semaphore s1 is no
21101 // longer in flight. delete it.
21102 vkDestroySemaphore(m_device->device(), s1, nullptr);
21103
21104 m_errorMonitor->VerifyNotFound();
21105
21106 // Force device idle and clean up remaining objects
21107 vkDeviceWaitIdle(m_device->device());
21108 vkDestroySemaphore(m_device->device(), s2, nullptr);
21109 vkDestroyFence(m_device->device(), fence, nullptr);
21110}
21111
21112TEST_F(VkPositiveLayerTest, FenceCreateSignaledWaitHandling) {
21113 m_errorMonitor->ExpectSuccess();
21114
Tony Barbour1fa09702017-03-16 12:09:08 -060021115 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021116 VkResult err;
21117
21118 // A fence created signaled
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021119 VkFenceCreateInfo fci1 = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, VK_FENCE_CREATE_SIGNALED_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021120 VkFence f1;
21121 err = vkCreateFence(m_device->device(), &fci1, nullptr, &f1);
21122 ASSERT_VK_SUCCESS(err);
21123
21124 // A fence created not
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021125 VkFenceCreateInfo fci2 = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021126 VkFence f2;
21127 err = vkCreateFence(m_device->device(), &fci2, nullptr, &f2);
21128 ASSERT_VK_SUCCESS(err);
21129
21130 // Submit the unsignaled fence
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021131 VkSubmitInfo si = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 0, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021132 err = vkQueueSubmit(m_device->m_queue, 1, &si, f2);
21133
21134 // Wait on both fences, with signaled first.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021135 VkFence fences[] = {f1, f2};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021136 vkWaitForFences(m_device->device(), 2, fences, VK_TRUE, UINT64_MAX);
21137
21138 // Should have both retired!
21139 vkDestroyFence(m_device->device(), f1, nullptr);
21140 vkDestroyFence(m_device->device(), f2, nullptr);
21141
21142 m_errorMonitor->VerifyNotFound();
21143}
21144
21145TEST_F(VkPositiveLayerTest, ValidUsage) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021146 TEST_DESCRIPTION(
21147 "Verify that creating an image view from an image with valid usage "
21148 "doesn't generate validation errors");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021149
Tony Barbour1fa09702017-03-16 12:09:08 -060021150 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021151
21152 m_errorMonitor->ExpectSuccess();
21153 // Verify that we can create a view with usage INPUT_ATTACHMENT
21154 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060021155 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 -060021156 ASSERT_TRUE(image.initialized());
21157 VkImageView imageView;
21158 VkImageViewCreateInfo ivci = {};
21159 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
21160 ivci.image = image.handle();
21161 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
21162 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
21163 ivci.subresourceRange.layerCount = 1;
21164 ivci.subresourceRange.baseMipLevel = 0;
21165 ivci.subresourceRange.levelCount = 1;
21166 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
21167
21168 vkCreateImageView(m_device->device(), &ivci, NULL, &imageView);
21169 m_errorMonitor->VerifyNotFound();
21170 vkDestroyImageView(m_device->device(), imageView, NULL);
21171}
21172
21173// This is a positive test. No failures are expected.
21174TEST_F(VkPositiveLayerTest, BindSparse) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021175 TEST_DESCRIPTION(
21176 "Bind 2 memory ranges to one image using vkQueueBindSparse, destroy the image"
21177 "and then free the memory");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021178
Tony Barbour1fa09702017-03-16 12:09:08 -060021179 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021180
21181 auto index = m_device->graphics_queue_node_index_;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021182 if (!(m_device->queue_props[index].queueFlags & VK_QUEUE_SPARSE_BINDING_BIT)) return;
Tony Barbour623721f2017-03-24 15:00:21 -060021183 if (!m_device->phy().features().sparseBinding) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021184
21185 m_errorMonitor->ExpectSuccess();
21186
21187 VkImage image;
21188 VkImageCreateInfo image_create_info = {};
21189 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
21190 image_create_info.pNext = NULL;
21191 image_create_info.imageType = VK_IMAGE_TYPE_2D;
21192 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
21193 image_create_info.extent.width = 64;
21194 image_create_info.extent.height = 64;
21195 image_create_info.extent.depth = 1;
21196 image_create_info.mipLevels = 1;
21197 image_create_info.arrayLayers = 1;
21198 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
21199 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
21200 image_create_info.usage = VK_IMAGE_USAGE_STORAGE_BIT;
21201 image_create_info.flags = VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
21202 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
21203 ASSERT_VK_SUCCESS(err);
21204
21205 VkMemoryRequirements memory_reqs;
21206 VkDeviceMemory memory_one, memory_two;
21207 bool pass;
21208 VkMemoryAllocateInfo memory_info = {};
21209 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
21210 memory_info.pNext = NULL;
21211 memory_info.allocationSize = 0;
21212 memory_info.memoryTypeIndex = 0;
21213 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
21214 // Find an image big enough to allow sparse mapping of 2 memory regions
21215 // Increase the image size until it is at least twice the
21216 // size of the required alignment, to ensure we can bind both
21217 // allocated memory blocks to the image on aligned offsets.
21218 while (memory_reqs.size < (memory_reqs.alignment * 2)) {
21219 vkDestroyImage(m_device->device(), image, nullptr);
21220 image_create_info.extent.width *= 2;
21221 image_create_info.extent.height *= 2;
21222 err = vkCreateImage(m_device->device(), &image_create_info, nullptr, &image);
21223 ASSERT_VK_SUCCESS(err);
21224 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
21225 }
21226 // Allocate 2 memory regions of minimum alignment size, bind one at 0, the other
21227 // at the end of the first
21228 memory_info.allocationSize = memory_reqs.alignment;
21229 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
21230 ASSERT_TRUE(pass);
21231 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_one);
21232 ASSERT_VK_SUCCESS(err);
21233 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_two);
21234 ASSERT_VK_SUCCESS(err);
21235 VkSparseMemoryBind binds[2];
21236 binds[0].flags = 0;
21237 binds[0].memory = memory_one;
21238 binds[0].memoryOffset = 0;
21239 binds[0].resourceOffset = 0;
21240 binds[0].size = memory_info.allocationSize;
21241 binds[1].flags = 0;
21242 binds[1].memory = memory_two;
21243 binds[1].memoryOffset = 0;
21244 binds[1].resourceOffset = memory_info.allocationSize;
21245 binds[1].size = memory_info.allocationSize;
21246
21247 VkSparseImageOpaqueMemoryBindInfo opaqueBindInfo;
21248 opaqueBindInfo.image = image;
21249 opaqueBindInfo.bindCount = 2;
21250 opaqueBindInfo.pBinds = binds;
21251
21252 VkFence fence = VK_NULL_HANDLE;
21253 VkBindSparseInfo bindSparseInfo = {};
21254 bindSparseInfo.sType = VK_STRUCTURE_TYPE_BIND_SPARSE_INFO;
21255 bindSparseInfo.imageOpaqueBindCount = 1;
21256 bindSparseInfo.pImageOpaqueBinds = &opaqueBindInfo;
21257
21258 vkQueueBindSparse(m_device->m_queue, 1, &bindSparseInfo, fence);
21259 vkQueueWaitIdle(m_device->m_queue);
21260 vkDestroyImage(m_device->device(), image, NULL);
21261 vkFreeMemory(m_device->device(), memory_one, NULL);
21262 vkFreeMemory(m_device->device(), memory_two, NULL);
21263 m_errorMonitor->VerifyNotFound();
21264}
21265
21266TEST_F(VkPositiveLayerTest, RenderPassInitialLayoutUndefined) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021267 TEST_DESCRIPTION(
21268 "Ensure that CmdBeginRenderPass with an attachment's "
21269 "initialLayout of VK_IMAGE_LAYOUT_UNDEFINED works when "
21270 "the command buffer has prior knowledge of that "
21271 "attachment's layout.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021272
21273 m_errorMonitor->ExpectSuccess();
21274
Tony Barbour1fa09702017-03-16 12:09:08 -060021275 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021276
21277 // A renderpass with one color attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021278 VkAttachmentDescription attachment = {0,
21279 VK_FORMAT_R8G8B8A8_UNORM,
21280 VK_SAMPLE_COUNT_1_BIT,
21281 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
21282 VK_ATTACHMENT_STORE_OP_STORE,
21283 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
21284 VK_ATTACHMENT_STORE_OP_DONT_CARE,
21285 VK_IMAGE_LAYOUT_UNDEFINED,
21286 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021287
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021288 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021289
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021290 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021291
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021292 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021293
21294 VkRenderPass rp;
21295 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
21296 ASSERT_VK_SUCCESS(err);
21297
21298 // A compatible framebuffer.
21299 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060021300 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 -060021301 ASSERT_TRUE(image.initialized());
21302
21303 VkImageViewCreateInfo ivci = {
21304 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
21305 nullptr,
21306 0,
21307 image.handle(),
21308 VK_IMAGE_VIEW_TYPE_2D,
21309 VK_FORMAT_R8G8B8A8_UNORM,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021310 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
21311 VK_COMPONENT_SWIZZLE_IDENTITY},
21312 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021313 };
21314 VkImageView view;
21315 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
21316 ASSERT_VK_SUCCESS(err);
21317
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021318 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021319 VkFramebuffer fb;
21320 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
21321 ASSERT_VK_SUCCESS(err);
21322
21323 // Record a single command buffer which uses this renderpass twice. The
21324 // bug is triggered at the beginning of the second renderpass, when the
21325 // command buffer already has a layout recorded for the attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021326 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 -070021327 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021328 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
21329 vkCmdEndRenderPass(m_commandBuffer->handle());
21330 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
21331
21332 m_errorMonitor->VerifyNotFound();
21333
21334 vkCmdEndRenderPass(m_commandBuffer->handle());
Tony Barbour552f6c02016-12-21 14:34:07 -070021335 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021336
21337 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
21338 vkDestroyRenderPass(m_device->device(), rp, nullptr);
21339 vkDestroyImageView(m_device->device(), view, nullptr);
21340}
21341
21342TEST_F(VkPositiveLayerTest, FramebufferBindingDestroyCommandPool) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021343 TEST_DESCRIPTION(
21344 "This test should pass. Create a Framebuffer and "
21345 "command buffer, bind them together, then destroy "
21346 "command pool and framebuffer and verify there are no "
21347 "errors.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021348
21349 m_errorMonitor->ExpectSuccess();
21350
Tony Barbour1fa09702017-03-16 12:09:08 -060021351 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021352
21353 // A renderpass with one color attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021354 VkAttachmentDescription attachment = {0,
21355 VK_FORMAT_R8G8B8A8_UNORM,
21356 VK_SAMPLE_COUNT_1_BIT,
21357 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
21358 VK_ATTACHMENT_STORE_OP_STORE,
21359 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
21360 VK_ATTACHMENT_STORE_OP_DONT_CARE,
21361 VK_IMAGE_LAYOUT_UNDEFINED,
21362 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021363
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021364 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021365
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021366 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021367
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021368 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021369
21370 VkRenderPass rp;
21371 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
21372 ASSERT_VK_SUCCESS(err);
21373
21374 // A compatible framebuffer.
21375 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060021376 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 -060021377 ASSERT_TRUE(image.initialized());
21378
21379 VkImageViewCreateInfo ivci = {
21380 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
21381 nullptr,
21382 0,
21383 image.handle(),
21384 VK_IMAGE_VIEW_TYPE_2D,
21385 VK_FORMAT_R8G8B8A8_UNORM,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021386 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
21387 VK_COMPONENT_SWIZZLE_IDENTITY},
21388 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021389 };
21390 VkImageView view;
21391 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
21392 ASSERT_VK_SUCCESS(err);
21393
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021394 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021395 VkFramebuffer fb;
21396 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
21397 ASSERT_VK_SUCCESS(err);
21398
21399 // Explicitly create a command buffer to bind the FB to so that we can then
21400 // destroy the command pool in order to implicitly free command buffer
21401 VkCommandPool command_pool;
21402 VkCommandPoolCreateInfo pool_create_info{};
21403 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
21404 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
21405 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
21406 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
21407
21408 VkCommandBuffer command_buffer;
21409 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
21410 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
21411 command_buffer_allocate_info.commandPool = command_pool;
21412 command_buffer_allocate_info.commandBufferCount = 1;
21413 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
21414 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
21415
21416 // Begin our cmd buffer with renderpass using our framebuffer
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021417 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 -060021418 VkCommandBufferBeginInfo begin_info{};
21419 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21420 vkBeginCommandBuffer(command_buffer, &begin_info);
21421
21422 vkCmdBeginRenderPass(command_buffer, &rpbi, VK_SUBPASS_CONTENTS_INLINE);
21423 vkCmdEndRenderPass(command_buffer);
21424 vkEndCommandBuffer(command_buffer);
21425 vkDestroyImageView(m_device->device(), view, nullptr);
21426 // Destroy command pool to implicitly free command buffer
21427 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
21428 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
21429 vkDestroyRenderPass(m_device->device(), rp, nullptr);
21430 m_errorMonitor->VerifyNotFound();
21431}
21432
21433TEST_F(VkPositiveLayerTest, RenderPassSubpassZeroTransitionsApplied) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021434 TEST_DESCRIPTION(
21435 "Ensure that CmdBeginRenderPass applies the layout "
21436 "transitions for the first subpass");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021437
21438 m_errorMonitor->ExpectSuccess();
21439
Tony Barbour1fa09702017-03-16 12:09:08 -060021440 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021441
21442 // A renderpass with one color attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021443 VkAttachmentDescription attachment = {0,
21444 VK_FORMAT_R8G8B8A8_UNORM,
21445 VK_SAMPLE_COUNT_1_BIT,
21446 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
21447 VK_ATTACHMENT_STORE_OP_STORE,
21448 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
21449 VK_ATTACHMENT_STORE_OP_DONT_CARE,
21450 VK_IMAGE_LAYOUT_UNDEFINED,
21451 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021452
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021453 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021454
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021455 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021456
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021457 VkSubpassDependency dep = {0,
21458 0,
21459 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
21460 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
21461 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
21462 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
21463 VK_DEPENDENCY_BY_REGION_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021464
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021465 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021466
21467 VkResult err;
21468 VkRenderPass rp;
21469 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
21470 ASSERT_VK_SUCCESS(err);
21471
21472 // A compatible framebuffer.
21473 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060021474 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 -060021475 ASSERT_TRUE(image.initialized());
21476
21477 VkImageViewCreateInfo ivci = {
21478 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
21479 nullptr,
21480 0,
21481 image.handle(),
21482 VK_IMAGE_VIEW_TYPE_2D,
21483 VK_FORMAT_R8G8B8A8_UNORM,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021484 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
21485 VK_COMPONENT_SWIZZLE_IDENTITY},
21486 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021487 };
21488 VkImageView view;
21489 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
21490 ASSERT_VK_SUCCESS(err);
21491
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021492 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021493 VkFramebuffer fb;
21494 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
21495 ASSERT_VK_SUCCESS(err);
21496
21497 // Record a single command buffer which issues a pipeline barrier w/
21498 // image memory barrier for the attachment. This detects the previously
21499 // missing tracking of the subpass layout by throwing a validation error
21500 // if it doesn't occur.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021501 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 -070021502 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021503 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
21504
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021505 VkImageMemoryBarrier imb = {VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
21506 nullptr,
21507 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
21508 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
21509 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
21510 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
21511 VK_QUEUE_FAMILY_IGNORED,
21512 VK_QUEUE_FAMILY_IGNORED,
21513 image.handle(),
21514 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1}};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021515 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021516 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
21517 &imb);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021518
21519 vkCmdEndRenderPass(m_commandBuffer->handle());
21520 m_errorMonitor->VerifyNotFound();
Tony Barbour552f6c02016-12-21 14:34:07 -070021521 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021522
21523 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
21524 vkDestroyRenderPass(m_device->device(), rp, nullptr);
21525 vkDestroyImageView(m_device->device(), view, nullptr);
21526}
21527
21528TEST_F(VkPositiveLayerTest, DepthStencilLayoutTransitionForDepthOnlyImageview) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021529 TEST_DESCRIPTION(
21530 "Validate that when an imageView of a depth/stencil image "
21531 "is used as a depth/stencil framebuffer attachment, the "
21532 "aspectMask is ignored and both depth and stencil image "
21533 "subresources are used.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021534
Tony Barbour1fa09702017-03-16 12:09:08 -060021535 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021536 VkFormatProperties format_properties;
21537 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_D32_SFLOAT_S8_UINT, &format_properties);
21538 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
21539 return;
21540 }
21541
21542 m_errorMonitor->ExpectSuccess();
21543
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021544 VkAttachmentDescription attachment = {0,
21545 VK_FORMAT_D32_SFLOAT_S8_UINT,
21546 VK_SAMPLE_COUNT_1_BIT,
21547 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
21548 VK_ATTACHMENT_STORE_OP_STORE,
21549 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
21550 VK_ATTACHMENT_STORE_OP_DONT_CARE,
21551 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
21552 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021553
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021554 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021555
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021556 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, &att_ref, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021557
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021558 VkSubpassDependency dep = {0,
21559 0,
21560 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
21561 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
21562 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
21563 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
21564 VK_DEPENDENCY_BY_REGION_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021565
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021566 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021567
21568 VkResult err;
21569 VkRenderPass rp;
21570 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
21571 ASSERT_VK_SUCCESS(err);
21572
21573 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060021574 image.InitNoLayout(32, 32, 1, VK_FORMAT_D32_SFLOAT_S8_UINT,
21575 0x26, // usage
21576 VK_IMAGE_TILING_OPTIMAL, 0);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021577 ASSERT_TRUE(image.initialized());
21578 image.SetLayout(0x6, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
21579
21580 VkImageViewCreateInfo ivci = {
21581 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
21582 nullptr,
21583 0,
21584 image.handle(),
21585 VK_IMAGE_VIEW_TYPE_2D,
21586 VK_FORMAT_D32_SFLOAT_S8_UINT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021587 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
21588 {0x2, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021589 };
21590 VkImageView view;
21591 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
21592 ASSERT_VK_SUCCESS(err);
21593
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021594 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021595 VkFramebuffer fb;
21596 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
21597 ASSERT_VK_SUCCESS(err);
21598
Tony Barbour552f6c02016-12-21 14:34:07 -070021599 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021600
21601 VkImageMemoryBarrier imb = {};
21602 imb.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
21603 imb.pNext = nullptr;
21604 imb.srcAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
21605 imb.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
21606 imb.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
21607 imb.newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
21608 imb.srcQueueFamilyIndex = 0;
21609 imb.dstQueueFamilyIndex = 0;
21610 imb.image = image.handle();
21611 imb.subresourceRange.aspectMask = 0x6;
21612 imb.subresourceRange.baseMipLevel = 0;
21613 imb.subresourceRange.levelCount = 0x1;
21614 imb.subresourceRange.baseArrayLayer = 0;
21615 imb.subresourceRange.layerCount = 0x1;
21616
21617 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021618 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
21619 &imb);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021620
Tony Barbour552f6c02016-12-21 14:34:07 -070021621 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021622 QueueCommandBuffer(false);
21623 m_errorMonitor->VerifyNotFound();
21624
21625 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
21626 vkDestroyRenderPass(m_device->device(), rp, nullptr);
21627 vkDestroyImageView(m_device->device(), view, nullptr);
21628}
21629
21630TEST_F(VkPositiveLayerTest, RenderPassTransitionsAttachmentUnused) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021631 TEST_DESCRIPTION(
21632 "Ensure that layout transitions work correctly without "
21633 "errors, when an attachment reference is "
21634 "VK_ATTACHMENT_UNUSED");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021635
21636 m_errorMonitor->ExpectSuccess();
21637
Tony Barbour1fa09702017-03-16 12:09:08 -060021638 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021639
21640 // A renderpass with no attachments
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021641 VkAttachmentReference att_ref = {VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021642
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021643 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021644
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021645 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 1, &subpass, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021646
21647 VkRenderPass rp;
21648 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
21649 ASSERT_VK_SUCCESS(err);
21650
21651 // A compatible framebuffer.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021652 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021653 VkFramebuffer fb;
21654 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
21655 ASSERT_VK_SUCCESS(err);
21656
21657 // Record a command buffer which just begins and ends the renderpass. The
21658 // bug manifests in BeginRenderPass.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021659 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 -070021660 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021661 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
21662 vkCmdEndRenderPass(m_commandBuffer->handle());
21663 m_errorMonitor->VerifyNotFound();
Tony Barbour552f6c02016-12-21 14:34:07 -070021664 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021665
21666 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
21667 vkDestroyRenderPass(m_device->device(), rp, nullptr);
21668}
21669
21670// This is a positive test. No errors are expected.
21671TEST_F(VkPositiveLayerTest, StencilLoadOp) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021672 TEST_DESCRIPTION(
21673 "Create a stencil-only attachment with a LOAD_OP set to "
21674 "CLEAR. stencil[Load|Store]Op used to be ignored.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021675 VkResult result = VK_SUCCESS;
Tony Barbour1fa09702017-03-16 12:09:08 -060021676 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -060021677 auto depth_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbourf887b162017-03-09 10:06:46 -070021678 if (!depth_format) {
21679 printf(" No Depth + Stencil format found. Skipped.\n");
21680 return;
21681 }
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021682 VkImageFormatProperties formatProps;
Tony Barbourf887b162017-03-09 10:06:46 -070021683 vkGetPhysicalDeviceImageFormatProperties(gpu(), depth_format, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021684 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0,
21685 &formatProps);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021686 if (formatProps.maxExtent.width < 100 || formatProps.maxExtent.height < 100) {
21687 return;
21688 }
21689
Tony Barbourf887b162017-03-09 10:06:46 -070021690 VkFormat depth_stencil_fmt = depth_format;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021691 m_depthStencil->Init(m_device, 100, 100, depth_stencil_fmt,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021692 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021693 VkAttachmentDescription att = {};
21694 VkAttachmentReference ref = {};
21695 att.format = depth_stencil_fmt;
21696 att.samples = VK_SAMPLE_COUNT_1_BIT;
21697 att.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
21698 att.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
21699 att.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
21700 att.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE;
21701 att.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
21702 att.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
21703
21704 VkClearValue clear;
21705 clear.depthStencil.depth = 1.0;
21706 clear.depthStencil.stencil = 0;
21707 ref.attachment = 0;
21708 ref.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
21709
21710 VkSubpassDescription subpass = {};
21711 subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
21712 subpass.flags = 0;
21713 subpass.inputAttachmentCount = 0;
21714 subpass.pInputAttachments = NULL;
21715 subpass.colorAttachmentCount = 0;
21716 subpass.pColorAttachments = NULL;
21717 subpass.pResolveAttachments = NULL;
21718 subpass.pDepthStencilAttachment = &ref;
21719 subpass.preserveAttachmentCount = 0;
21720 subpass.pPreserveAttachments = NULL;
21721
21722 VkRenderPass rp;
21723 VkRenderPassCreateInfo rp_info = {};
21724 rp_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
21725 rp_info.attachmentCount = 1;
21726 rp_info.pAttachments = &att;
21727 rp_info.subpassCount = 1;
21728 rp_info.pSubpasses = &subpass;
21729 result = vkCreateRenderPass(device(), &rp_info, NULL, &rp);
21730 ASSERT_VK_SUCCESS(result);
21731
21732 VkImageView *depthView = m_depthStencil->BindInfo();
21733 VkFramebufferCreateInfo fb_info = {};
21734 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
21735 fb_info.pNext = NULL;
21736 fb_info.renderPass = rp;
21737 fb_info.attachmentCount = 1;
21738 fb_info.pAttachments = depthView;
21739 fb_info.width = 100;
21740 fb_info.height = 100;
21741 fb_info.layers = 1;
21742 VkFramebuffer fb;
21743 result = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
21744 ASSERT_VK_SUCCESS(result);
21745
21746 VkRenderPassBeginInfo rpbinfo = {};
21747 rpbinfo.clearValueCount = 1;
21748 rpbinfo.pClearValues = &clear;
21749 rpbinfo.pNext = NULL;
21750 rpbinfo.renderPass = rp;
21751 rpbinfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
21752 rpbinfo.renderArea.extent.width = 100;
21753 rpbinfo.renderArea.extent.height = 100;
21754 rpbinfo.renderArea.offset.x = 0;
21755 rpbinfo.renderArea.offset.y = 0;
21756 rpbinfo.framebuffer = fb;
21757
21758 VkFence fence = {};
21759 VkFenceCreateInfo fence_ci = {};
21760 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
21761 fence_ci.pNext = nullptr;
21762 fence_ci.flags = 0;
21763 result = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fence);
21764 ASSERT_VK_SUCCESS(result);
21765
21766 m_commandBuffer->BeginCommandBuffer();
21767 m_commandBuffer->BeginRenderPass(rpbinfo);
21768 m_commandBuffer->EndRenderPass();
21769 m_commandBuffer->EndCommandBuffer();
21770 m_commandBuffer->QueueCommandBuffer(fence);
21771
21772 VkImageObj destImage(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060021773 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 -070021774 VK_IMAGE_TILING_OPTIMAL, 0);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021775 VkImageMemoryBarrier barrier = {};
21776 VkImageSubresourceRange range;
21777 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
21778 barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
21779 barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT;
21780 barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
21781 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
21782 barrier.image = m_depthStencil->handle();
21783 range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
21784 range.baseMipLevel = 0;
21785 range.levelCount = 1;
21786 range.baseArrayLayer = 0;
21787 range.layerCount = 1;
21788 barrier.subresourceRange = range;
21789 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
21790 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
21791 cmdbuf.BeginCommandBuffer();
21792 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 -070021793 &barrier);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021794 barrier.srcAccessMask = 0;
21795 barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
21796 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
21797 barrier.image = destImage.handle();
21798 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
21799 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 -070021800 &barrier);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021801 VkImageCopy cregion;
21802 cregion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
21803 cregion.srcSubresource.mipLevel = 0;
21804 cregion.srcSubresource.baseArrayLayer = 0;
21805 cregion.srcSubresource.layerCount = 1;
21806 cregion.srcOffset.x = 0;
21807 cregion.srcOffset.y = 0;
21808 cregion.srcOffset.z = 0;
21809 cregion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
21810 cregion.dstSubresource.mipLevel = 0;
21811 cregion.dstSubresource.baseArrayLayer = 0;
21812 cregion.dstSubresource.layerCount = 1;
21813 cregion.dstOffset.x = 0;
21814 cregion.dstOffset.y = 0;
21815 cregion.dstOffset.z = 0;
21816 cregion.extent.width = 100;
21817 cregion.extent.height = 100;
21818 cregion.extent.depth = 1;
21819 cmdbuf.CopyImage(m_depthStencil->handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, destImage.handle(),
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021820 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &cregion);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021821 cmdbuf.EndCommandBuffer();
21822
21823 VkSubmitInfo submit_info;
21824 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21825 submit_info.pNext = NULL;
21826 submit_info.waitSemaphoreCount = 0;
21827 submit_info.pWaitSemaphores = NULL;
21828 submit_info.pWaitDstStageMask = NULL;
21829 submit_info.commandBufferCount = 1;
21830 submit_info.pCommandBuffers = &cmdbuf.handle();
21831 submit_info.signalSemaphoreCount = 0;
21832 submit_info.pSignalSemaphores = NULL;
21833
21834 m_errorMonitor->ExpectSuccess();
21835 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
21836 m_errorMonitor->VerifyNotFound();
21837
21838 vkQueueWaitIdle(m_device->m_queue);
21839 vkDestroyFence(m_device->device(), fence, nullptr);
21840 vkDestroyRenderPass(m_device->device(), rp, nullptr);
21841 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
21842}
21843
21844// This is a positive test. No errors should be generated.
Mike Weiblene4e225d2017-03-07 23:15:43 -070021845TEST_F(VkPositiveLayerTest, BarrierLayoutToImageUsage) {
21846 TEST_DESCRIPTION("Ensure barriers' new and old VkImageLayout are compatible with their images' VkImageUsageFlags");
21847
21848 m_errorMonitor->ExpectSuccess();
21849
Tony Barbour1fa09702017-03-16 12:09:08 -060021850 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -060021851 auto depth_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbour9357d542017-03-24 15:42:21 -060021852 if (!depth_format) {
21853 printf(" No Depth + Stencil format found. Skipped.\n");
21854 return;
21855 }
Mike Weiblene4e225d2017-03-07 23:15:43 -070021856 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21857
21858 VkImageMemoryBarrier img_barrier = {};
21859 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
21860 img_barrier.pNext = NULL;
21861 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
21862 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
21863 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
21864 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
21865 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
21866 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
21867 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
21868 img_barrier.subresourceRange.baseArrayLayer = 0;
21869 img_barrier.subresourceRange.baseMipLevel = 0;
21870 img_barrier.subresourceRange.layerCount = 1;
21871 img_barrier.subresourceRange.levelCount = 1;
21872
21873 {
21874 VkImageObj img_color(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060021875 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 -070021876 ASSERT_TRUE(img_color.initialized());
21877
21878 VkImageObj img_ds1(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060021879 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 -070021880 ASSERT_TRUE(img_ds1.initialized());
21881
21882 VkImageObj img_ds2(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060021883 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 -070021884 ASSERT_TRUE(img_ds2.initialized());
21885
21886 VkImageObj img_xfer_src(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060021887 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 -070021888 ASSERT_TRUE(img_xfer_src.initialized());
21889
21890 VkImageObj img_xfer_dst(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060021891 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 -070021892 ASSERT_TRUE(img_xfer_dst.initialized());
21893
21894 VkImageObj img_sampled(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060021895 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 -070021896 ASSERT_TRUE(img_sampled.initialized());
21897
21898 VkImageObj img_input(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060021899 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 -070021900 ASSERT_TRUE(img_input.initialized());
21901
21902 const struct {
21903 VkImageObj &image_obj;
21904 VkImageLayout old_layout;
21905 VkImageLayout new_layout;
21906 } buffer_layouts[] = {
21907 // clang-format off
21908 {img_color, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL},
21909 {img_ds1, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL},
21910 {img_ds2, VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL},
21911 {img_sampled, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL},
21912 {img_input, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL},
21913 {img_xfer_src, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL},
21914 {img_xfer_dst, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL},
21915 // clang-format on
21916 };
21917 const uint32_t layout_count = sizeof(buffer_layouts) / sizeof(buffer_layouts[0]);
21918
21919 m_commandBuffer->BeginCommandBuffer();
21920 for (uint32_t i = 0; i < layout_count; ++i) {
21921 img_barrier.image = buffer_layouts[i].image_obj.handle();
21922 const VkImageUsageFlags usage = buffer_layouts[i].image_obj.usage();
21923 img_barrier.subresourceRange.aspectMask = (usage == VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT)
21924 ? (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)
21925 : VK_IMAGE_ASPECT_COLOR_BIT;
21926
21927 img_barrier.oldLayout = buffer_layouts[i].old_layout;
21928 img_barrier.newLayout = buffer_layouts[i].new_layout;
21929 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT,
21930 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0, nullptr, 1, &img_barrier);
21931
21932 img_barrier.oldLayout = buffer_layouts[i].new_layout;
21933 img_barrier.newLayout = buffer_layouts[i].old_layout;
21934 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT,
21935 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0, nullptr, 1, &img_barrier);
21936 }
21937 m_commandBuffer->EndCommandBuffer();
21938
21939 img_barrier.oldLayout = VK_IMAGE_LAYOUT_GENERAL;
21940 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
21941 }
21942 m_errorMonitor->VerifyNotFound();
21943}
21944
21945// This is a positive test. No errors should be generated.
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021946TEST_F(VkPositiveLayerTest, WaitEventThenSet) {
21947 TEST_DESCRIPTION("Wait on a event then set it after the wait has been submitted.");
21948
21949 m_errorMonitor->ExpectSuccess();
Tony Barbour1fa09702017-03-16 12:09:08 -060021950 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021951
21952 VkEvent event;
21953 VkEventCreateInfo event_create_info{};
21954 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
21955 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
21956
21957 VkCommandPool command_pool;
21958 VkCommandPoolCreateInfo pool_create_info{};
21959 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
21960 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
21961 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
21962 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
21963
21964 VkCommandBuffer command_buffer;
21965 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
21966 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
21967 command_buffer_allocate_info.commandPool = command_pool;
21968 command_buffer_allocate_info.commandBufferCount = 1;
21969 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
21970 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
21971
21972 VkQueue queue = VK_NULL_HANDLE;
21973 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
21974
21975 {
21976 VkCommandBufferBeginInfo begin_info{};
21977 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21978 vkBeginCommandBuffer(command_buffer, &begin_info);
21979
21980 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 -070021981 nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021982 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
21983 vkEndCommandBuffer(command_buffer);
21984 }
21985 {
21986 VkSubmitInfo submit_info{};
21987 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21988 submit_info.commandBufferCount = 1;
21989 submit_info.pCommandBuffers = &command_buffer;
21990 submit_info.signalSemaphoreCount = 0;
21991 submit_info.pSignalSemaphores = nullptr;
21992 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
21993 }
21994 { vkSetEvent(m_device->device(), event); }
21995
21996 vkQueueWaitIdle(queue);
21997
21998 vkDestroyEvent(m_device->device(), event, nullptr);
21999 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
22000 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
22001
22002 m_errorMonitor->VerifyNotFound();
22003}
22004// This is a positive test. No errors should be generated.
22005TEST_F(VkPositiveLayerTest, QueryAndCopySecondaryCommandBuffers) {
22006 TEST_DESCRIPTION("Issue a query on a secondary command buffery and copy it on a primary.");
22007
Tony Barbour1fa09702017-03-16 12:09:08 -060022008 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022009 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022010
22011 m_errorMonitor->ExpectSuccess();
22012
22013 VkQueryPool query_pool;
22014 VkQueryPoolCreateInfo query_pool_create_info{};
22015 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
22016 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
22017 query_pool_create_info.queryCount = 1;
22018 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
22019
22020 VkCommandPool command_pool;
22021 VkCommandPoolCreateInfo pool_create_info{};
22022 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
22023 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
22024 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
22025 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
22026
22027 VkCommandBuffer command_buffer;
22028 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
22029 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
22030 command_buffer_allocate_info.commandPool = command_pool;
22031 command_buffer_allocate_info.commandBufferCount = 1;
22032 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
22033 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
22034
22035 VkCommandBuffer secondary_command_buffer;
22036 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
22037 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer);
22038
22039 VkQueue queue = VK_NULL_HANDLE;
22040 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
22041
22042 uint32_t qfi = 0;
22043 VkBufferCreateInfo buff_create_info = {};
22044 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
22045 buff_create_info.size = 1024;
22046 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
22047 buff_create_info.queueFamilyIndexCount = 1;
22048 buff_create_info.pQueueFamilyIndices = &qfi;
22049
22050 VkResult err;
22051 VkBuffer buffer;
22052 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
22053 ASSERT_VK_SUCCESS(err);
22054 VkMemoryAllocateInfo mem_alloc = {};
22055 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
22056 mem_alloc.pNext = NULL;
22057 mem_alloc.allocationSize = 1024;
22058 mem_alloc.memoryTypeIndex = 0;
22059
22060 VkMemoryRequirements memReqs;
22061 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
22062 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
22063 if (!pass) {
22064 vkDestroyBuffer(m_device->device(), buffer, NULL);
22065 return;
22066 }
22067
22068 VkDeviceMemory mem;
22069 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
22070 ASSERT_VK_SUCCESS(err);
22071 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
22072 ASSERT_VK_SUCCESS(err);
22073
22074 VkCommandBufferInheritanceInfo hinfo = {};
22075 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
22076 hinfo.renderPass = VK_NULL_HANDLE;
22077 hinfo.subpass = 0;
22078 hinfo.framebuffer = VK_NULL_HANDLE;
22079 hinfo.occlusionQueryEnable = VK_FALSE;
22080 hinfo.queryFlags = 0;
22081 hinfo.pipelineStatistics = 0;
22082
22083 {
22084 VkCommandBufferBeginInfo begin_info{};
22085 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22086 begin_info.pInheritanceInfo = &hinfo;
22087 vkBeginCommandBuffer(secondary_command_buffer, &begin_info);
22088
22089 vkCmdResetQueryPool(secondary_command_buffer, query_pool, 0, 1);
22090 vkCmdWriteTimestamp(secondary_command_buffer, VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
22091
22092 vkEndCommandBuffer(secondary_command_buffer);
22093
22094 begin_info.pInheritanceInfo = nullptr;
22095 vkBeginCommandBuffer(command_buffer, &begin_info);
22096
22097 vkCmdExecuteCommands(command_buffer, 1, &secondary_command_buffer);
22098 vkCmdCopyQueryPoolResults(command_buffer, query_pool, 0, 1, buffer, 0, 0, 0);
22099
22100 vkEndCommandBuffer(command_buffer);
22101 }
22102 {
22103 VkSubmitInfo submit_info{};
22104 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22105 submit_info.commandBufferCount = 1;
22106 submit_info.pCommandBuffers = &command_buffer;
22107 submit_info.signalSemaphoreCount = 0;
22108 submit_info.pSignalSemaphores = nullptr;
22109 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
22110 }
22111
22112 vkQueueWaitIdle(queue);
22113
22114 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
22115 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
22116 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &secondary_command_buffer);
22117 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
22118 vkDestroyBuffer(m_device->device(), buffer, NULL);
22119 vkFreeMemory(m_device->device(), mem, NULL);
22120
22121 m_errorMonitor->VerifyNotFound();
22122}
22123
22124// This is a positive test. No errors should be generated.
22125TEST_F(VkPositiveLayerTest, QueryAndCopyMultipleCommandBuffers) {
22126 TEST_DESCRIPTION("Issue a query and copy from it on a second command buffer.");
22127
Tony Barbour1fa09702017-03-16 12:09:08 -060022128 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022129 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022130
22131 m_errorMonitor->ExpectSuccess();
22132
22133 VkQueryPool query_pool;
22134 VkQueryPoolCreateInfo query_pool_create_info{};
22135 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
22136 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
22137 query_pool_create_info.queryCount = 1;
22138 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
22139
22140 VkCommandPool command_pool;
22141 VkCommandPoolCreateInfo pool_create_info{};
22142 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
22143 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
22144 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
22145 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
22146
22147 VkCommandBuffer command_buffer[2];
22148 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
22149 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
22150 command_buffer_allocate_info.commandPool = command_pool;
22151 command_buffer_allocate_info.commandBufferCount = 2;
22152 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
22153 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
22154
22155 VkQueue queue = VK_NULL_HANDLE;
22156 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
22157
22158 uint32_t qfi = 0;
22159 VkBufferCreateInfo buff_create_info = {};
22160 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
22161 buff_create_info.size = 1024;
22162 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
22163 buff_create_info.queueFamilyIndexCount = 1;
22164 buff_create_info.pQueueFamilyIndices = &qfi;
22165
22166 VkResult err;
22167 VkBuffer buffer;
22168 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
22169 ASSERT_VK_SUCCESS(err);
22170 VkMemoryAllocateInfo mem_alloc = {};
22171 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
22172 mem_alloc.pNext = NULL;
22173 mem_alloc.allocationSize = 1024;
22174 mem_alloc.memoryTypeIndex = 0;
22175
22176 VkMemoryRequirements memReqs;
22177 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
22178 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
22179 if (!pass) {
22180 vkDestroyBuffer(m_device->device(), buffer, NULL);
22181 return;
22182 }
22183
22184 VkDeviceMemory mem;
22185 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
22186 ASSERT_VK_SUCCESS(err);
22187 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
22188 ASSERT_VK_SUCCESS(err);
22189
22190 {
22191 VkCommandBufferBeginInfo begin_info{};
22192 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22193 vkBeginCommandBuffer(command_buffer[0], &begin_info);
22194
22195 vkCmdResetQueryPool(command_buffer[0], query_pool, 0, 1);
22196 vkCmdWriteTimestamp(command_buffer[0], VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
22197
22198 vkEndCommandBuffer(command_buffer[0]);
22199
22200 vkBeginCommandBuffer(command_buffer[1], &begin_info);
22201
22202 vkCmdCopyQueryPoolResults(command_buffer[1], query_pool, 0, 1, buffer, 0, 0, 0);
22203
22204 vkEndCommandBuffer(command_buffer[1]);
22205 }
22206 {
22207 VkSubmitInfo submit_info{};
22208 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22209 submit_info.commandBufferCount = 2;
22210 submit_info.pCommandBuffers = command_buffer;
22211 submit_info.signalSemaphoreCount = 0;
22212 submit_info.pSignalSemaphores = nullptr;
22213 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
22214 }
22215
22216 vkQueueWaitIdle(queue);
22217
22218 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
22219 vkFreeCommandBuffers(m_device->device(), command_pool, 2, command_buffer);
22220 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
22221 vkDestroyBuffer(m_device->device(), buffer, NULL);
22222 vkFreeMemory(m_device->device(), mem, NULL);
22223
22224 m_errorMonitor->VerifyNotFound();
22225}
22226
Tony Barbourc46924f2016-11-04 11:49:52 -060022227TEST_F(VkLayerTest, ResetEventThenSet) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022228 TEST_DESCRIPTION("Reset an event then set it after the reset has been submitted.");
22229
Tony Barbour1fa09702017-03-16 12:09:08 -060022230 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022231 VkEvent event;
22232 VkEventCreateInfo event_create_info{};
22233 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
22234 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
22235
22236 VkCommandPool command_pool;
22237 VkCommandPoolCreateInfo pool_create_info{};
22238 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
22239 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
22240 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
22241 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
22242
22243 VkCommandBuffer command_buffer;
22244 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
22245 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
22246 command_buffer_allocate_info.commandPool = command_pool;
22247 command_buffer_allocate_info.commandBufferCount = 1;
22248 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
22249 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
22250
22251 VkQueue queue = VK_NULL_HANDLE;
22252 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
22253
22254 {
22255 VkCommandBufferBeginInfo begin_info{};
22256 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22257 vkBeginCommandBuffer(command_buffer, &begin_info);
22258
22259 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022260 vkEndCommandBuffer(command_buffer);
22261 }
22262 {
22263 VkSubmitInfo submit_info{};
22264 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22265 submit_info.commandBufferCount = 1;
22266 submit_info.pCommandBuffers = &command_buffer;
22267 submit_info.signalSemaphoreCount = 0;
22268 submit_info.pSignalSemaphores = nullptr;
22269 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
22270 }
22271 {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022272 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
22273 "that is already in use by a "
22274 "command buffer.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022275 vkSetEvent(m_device->device(), event);
22276 m_errorMonitor->VerifyFound();
22277 }
22278
22279 vkQueueWaitIdle(queue);
22280
22281 vkDestroyEvent(m_device->device(), event, nullptr);
22282 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
22283 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
22284}
22285
22286// This is a positive test. No errors should be generated.
22287TEST_F(VkPositiveLayerTest, TwoFencesThreeFrames) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022288 TEST_DESCRIPTION(
22289 "Two command buffers with two separate fences are each "
22290 "run through a Submit & WaitForFences cycle 3 times. This "
22291 "previously revealed a bug so running this positive test "
22292 "to prevent a regression.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022293 m_errorMonitor->ExpectSuccess();
22294
Tony Barbour1fa09702017-03-16 12:09:08 -060022295 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022296 VkQueue queue = VK_NULL_HANDLE;
22297 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
22298
22299 static const uint32_t NUM_OBJECTS = 2;
22300 static const uint32_t NUM_FRAMES = 3;
22301 VkCommandBuffer cmd_buffers[NUM_OBJECTS] = {};
22302 VkFence fences[NUM_OBJECTS] = {};
22303
22304 VkCommandPool cmd_pool;
22305 VkCommandPoolCreateInfo cmd_pool_ci = {};
22306 cmd_pool_ci.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
22307 cmd_pool_ci.queueFamilyIndex = m_device->graphics_queue_node_index_;
22308 cmd_pool_ci.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
22309 VkResult err = vkCreateCommandPool(m_device->device(), &cmd_pool_ci, nullptr, &cmd_pool);
22310 ASSERT_VK_SUCCESS(err);
22311
22312 VkCommandBufferAllocateInfo cmd_buf_info = {};
22313 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
22314 cmd_buf_info.commandPool = cmd_pool;
22315 cmd_buf_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
22316 cmd_buf_info.commandBufferCount = 1;
22317
22318 VkFenceCreateInfo fence_ci = {};
22319 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
22320 fence_ci.pNext = nullptr;
22321 fence_ci.flags = 0;
22322
22323 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
22324 err = vkAllocateCommandBuffers(m_device->device(), &cmd_buf_info, &cmd_buffers[i]);
22325 ASSERT_VK_SUCCESS(err);
22326 err = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fences[i]);
22327 ASSERT_VK_SUCCESS(err);
22328 }
22329
22330 for (uint32_t frame = 0; frame < NUM_FRAMES; ++frame) {
22331 for (uint32_t obj = 0; obj < NUM_OBJECTS; ++obj) {
22332 // Create empty cmd buffer
22333 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
22334 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22335
22336 err = vkBeginCommandBuffer(cmd_buffers[obj], &cmdBufBeginDesc);
22337 ASSERT_VK_SUCCESS(err);
22338 err = vkEndCommandBuffer(cmd_buffers[obj]);
22339 ASSERT_VK_SUCCESS(err);
22340
22341 VkSubmitInfo submit_info = {};
22342 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22343 submit_info.commandBufferCount = 1;
22344 submit_info.pCommandBuffers = &cmd_buffers[obj];
22345 // Submit cmd buffer and wait for fence
22346 err = vkQueueSubmit(queue, 1, &submit_info, fences[obj]);
22347 ASSERT_VK_SUCCESS(err);
22348 err = vkWaitForFences(m_device->device(), 1, &fences[obj], VK_TRUE, UINT64_MAX);
22349 ASSERT_VK_SUCCESS(err);
22350 err = vkResetFences(m_device->device(), 1, &fences[obj]);
22351 ASSERT_VK_SUCCESS(err);
22352 }
22353 }
22354 m_errorMonitor->VerifyNotFound();
22355 vkDestroyCommandPool(m_device->device(), cmd_pool, NULL);
22356 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
22357 vkDestroyFence(m_device->device(), fences[i], nullptr);
22358 }
22359}
22360// This is a positive test. No errors should be generated.
22361TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWI) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022362 TEST_DESCRIPTION(
22363 "Two command buffers, each in a separate QueueSubmit call "
22364 "submitted on separate queues followed by a QueueWaitIdle.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022365
Tony Barbour1fa09702017-03-16 12:09:08 -060022366 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022367 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022368
22369 m_errorMonitor->ExpectSuccess();
22370
22371 VkSemaphore semaphore;
22372 VkSemaphoreCreateInfo semaphore_create_info{};
22373 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
22374 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
22375
22376 VkCommandPool command_pool;
22377 VkCommandPoolCreateInfo pool_create_info{};
22378 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
22379 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
22380 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
22381 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
22382
22383 VkCommandBuffer command_buffer[2];
22384 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
22385 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
22386 command_buffer_allocate_info.commandPool = command_pool;
22387 command_buffer_allocate_info.commandBufferCount = 2;
22388 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
22389 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
22390
22391 VkQueue queue = VK_NULL_HANDLE;
22392 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
22393
22394 {
22395 VkCommandBufferBeginInfo begin_info{};
22396 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22397 vkBeginCommandBuffer(command_buffer[0], &begin_info);
22398
22399 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 -070022400 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022401
22402 VkViewport viewport{};
22403 viewport.maxDepth = 1.0f;
22404 viewport.minDepth = 0.0f;
22405 viewport.width = 512;
22406 viewport.height = 512;
22407 viewport.x = 0;
22408 viewport.y = 0;
22409 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
22410 vkEndCommandBuffer(command_buffer[0]);
22411 }
22412 {
22413 VkCommandBufferBeginInfo begin_info{};
22414 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22415 vkBeginCommandBuffer(command_buffer[1], &begin_info);
22416
22417 VkViewport viewport{};
22418 viewport.maxDepth = 1.0f;
22419 viewport.minDepth = 0.0f;
22420 viewport.width = 512;
22421 viewport.height = 512;
22422 viewport.x = 0;
22423 viewport.y = 0;
22424 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
22425 vkEndCommandBuffer(command_buffer[1]);
22426 }
22427 {
22428 VkSubmitInfo submit_info{};
22429 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22430 submit_info.commandBufferCount = 1;
22431 submit_info.pCommandBuffers = &command_buffer[0];
22432 submit_info.signalSemaphoreCount = 1;
22433 submit_info.pSignalSemaphores = &semaphore;
22434 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
22435 }
22436 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022437 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022438 VkSubmitInfo submit_info{};
22439 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22440 submit_info.commandBufferCount = 1;
22441 submit_info.pCommandBuffers = &command_buffer[1];
22442 submit_info.waitSemaphoreCount = 1;
22443 submit_info.pWaitSemaphores = &semaphore;
22444 submit_info.pWaitDstStageMask = flags;
22445 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
22446 }
22447
22448 vkQueueWaitIdle(m_device->m_queue);
22449
22450 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
22451 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
22452 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
22453
22454 m_errorMonitor->VerifyNotFound();
22455}
22456
22457// This is a positive test. No errors should be generated.
22458TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWIFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022459 TEST_DESCRIPTION(
22460 "Two command buffers, each in a separate QueueSubmit call "
22461 "submitted on separate queues, the second having a fence"
22462 "followed by a QueueWaitIdle.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022463
Tony Barbour1fa09702017-03-16 12:09:08 -060022464 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022465 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022466
22467 m_errorMonitor->ExpectSuccess();
22468
22469 VkFence fence;
22470 VkFenceCreateInfo fence_create_info{};
22471 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
22472 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
22473
22474 VkSemaphore semaphore;
22475 VkSemaphoreCreateInfo semaphore_create_info{};
22476 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
22477 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
22478
22479 VkCommandPool command_pool;
22480 VkCommandPoolCreateInfo pool_create_info{};
22481 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
22482 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
22483 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
22484 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
22485
22486 VkCommandBuffer command_buffer[2];
22487 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
22488 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
22489 command_buffer_allocate_info.commandPool = command_pool;
22490 command_buffer_allocate_info.commandBufferCount = 2;
22491 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
22492 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
22493
22494 VkQueue queue = VK_NULL_HANDLE;
22495 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
22496
22497 {
22498 VkCommandBufferBeginInfo begin_info{};
22499 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22500 vkBeginCommandBuffer(command_buffer[0], &begin_info);
22501
22502 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 -070022503 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022504
22505 VkViewport viewport{};
22506 viewport.maxDepth = 1.0f;
22507 viewport.minDepth = 0.0f;
22508 viewport.width = 512;
22509 viewport.height = 512;
22510 viewport.x = 0;
22511 viewport.y = 0;
22512 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
22513 vkEndCommandBuffer(command_buffer[0]);
22514 }
22515 {
22516 VkCommandBufferBeginInfo begin_info{};
22517 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22518 vkBeginCommandBuffer(command_buffer[1], &begin_info);
22519
22520 VkViewport viewport{};
22521 viewport.maxDepth = 1.0f;
22522 viewport.minDepth = 0.0f;
22523 viewport.width = 512;
22524 viewport.height = 512;
22525 viewport.x = 0;
22526 viewport.y = 0;
22527 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
22528 vkEndCommandBuffer(command_buffer[1]);
22529 }
22530 {
22531 VkSubmitInfo submit_info{};
22532 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22533 submit_info.commandBufferCount = 1;
22534 submit_info.pCommandBuffers = &command_buffer[0];
22535 submit_info.signalSemaphoreCount = 1;
22536 submit_info.pSignalSemaphores = &semaphore;
22537 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
22538 }
22539 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022540 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022541 VkSubmitInfo submit_info{};
22542 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22543 submit_info.commandBufferCount = 1;
22544 submit_info.pCommandBuffers = &command_buffer[1];
22545 submit_info.waitSemaphoreCount = 1;
22546 submit_info.pWaitSemaphores = &semaphore;
22547 submit_info.pWaitDstStageMask = flags;
22548 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
22549 }
22550
22551 vkQueueWaitIdle(m_device->m_queue);
22552
22553 vkDestroyFence(m_device->device(), fence, nullptr);
22554 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
22555 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
22556 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
22557
22558 m_errorMonitor->VerifyNotFound();
22559}
22560
22561// This is a positive test. No errors should be generated.
22562TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceTwoWFF) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022563 TEST_DESCRIPTION(
22564 "Two command buffers, each in a separate QueueSubmit call "
22565 "submitted on separate queues, the second having a fence"
22566 "followed by two consecutive WaitForFences calls on the same fence.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022567
Tony Barbour1fa09702017-03-16 12:09:08 -060022568 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022569 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022570
22571 m_errorMonitor->ExpectSuccess();
22572
22573 VkFence fence;
22574 VkFenceCreateInfo fence_create_info{};
22575 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
22576 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
22577
22578 VkSemaphore semaphore;
22579 VkSemaphoreCreateInfo semaphore_create_info{};
22580 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
22581 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
22582
22583 VkCommandPool command_pool;
22584 VkCommandPoolCreateInfo pool_create_info{};
22585 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
22586 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
22587 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
22588 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
22589
22590 VkCommandBuffer command_buffer[2];
22591 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
22592 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
22593 command_buffer_allocate_info.commandPool = command_pool;
22594 command_buffer_allocate_info.commandBufferCount = 2;
22595 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
22596 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
22597
22598 VkQueue queue = VK_NULL_HANDLE;
22599 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
22600
22601 {
22602 VkCommandBufferBeginInfo begin_info{};
22603 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22604 vkBeginCommandBuffer(command_buffer[0], &begin_info);
22605
22606 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 -070022607 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022608
22609 VkViewport viewport{};
22610 viewport.maxDepth = 1.0f;
22611 viewport.minDepth = 0.0f;
22612 viewport.width = 512;
22613 viewport.height = 512;
22614 viewport.x = 0;
22615 viewport.y = 0;
22616 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
22617 vkEndCommandBuffer(command_buffer[0]);
22618 }
22619 {
22620 VkCommandBufferBeginInfo begin_info{};
22621 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22622 vkBeginCommandBuffer(command_buffer[1], &begin_info);
22623
22624 VkViewport viewport{};
22625 viewport.maxDepth = 1.0f;
22626 viewport.minDepth = 0.0f;
22627 viewport.width = 512;
22628 viewport.height = 512;
22629 viewport.x = 0;
22630 viewport.y = 0;
22631 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
22632 vkEndCommandBuffer(command_buffer[1]);
22633 }
22634 {
22635 VkSubmitInfo submit_info{};
22636 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22637 submit_info.commandBufferCount = 1;
22638 submit_info.pCommandBuffers = &command_buffer[0];
22639 submit_info.signalSemaphoreCount = 1;
22640 submit_info.pSignalSemaphores = &semaphore;
22641 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
22642 }
22643 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022644 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022645 VkSubmitInfo submit_info{};
22646 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22647 submit_info.commandBufferCount = 1;
22648 submit_info.pCommandBuffers = &command_buffer[1];
22649 submit_info.waitSemaphoreCount = 1;
22650 submit_info.pWaitSemaphores = &semaphore;
22651 submit_info.pWaitDstStageMask = flags;
22652 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
22653 }
22654
22655 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
22656 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
22657
22658 vkDestroyFence(m_device->device(), fence, nullptr);
22659 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
22660 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
22661 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
22662
22663 m_errorMonitor->VerifyNotFound();
22664}
22665
22666TEST_F(VkPositiveLayerTest, TwoQueuesEnsureCorrectRetirementWithWorkStolen) {
Tony Barbour1fa09702017-03-16 12:09:08 -060022667 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022668 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070022669 printf(" Test requires two queues, skipping\n");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022670 return;
22671 }
22672
22673 VkResult err;
22674
22675 m_errorMonitor->ExpectSuccess();
22676
22677 VkQueue q0 = m_device->m_queue;
22678 VkQueue q1 = nullptr;
22679 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &q1);
22680 ASSERT_NE(q1, nullptr);
22681
22682 // An (empty) command buffer. We must have work in the first submission --
22683 // the layer treats unfenced work differently from fenced work.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022684 VkCommandPoolCreateInfo cpci = {VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, nullptr, 0, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022685 VkCommandPool pool;
22686 err = vkCreateCommandPool(m_device->device(), &cpci, nullptr, &pool);
22687 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022688 VkCommandBufferAllocateInfo cbai = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, nullptr, pool,
22689 VK_COMMAND_BUFFER_LEVEL_PRIMARY, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022690 VkCommandBuffer cb;
22691 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &cb);
22692 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022693 VkCommandBufferBeginInfo cbbi = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022694 err = vkBeginCommandBuffer(cb, &cbbi);
22695 ASSERT_VK_SUCCESS(err);
22696 err = vkEndCommandBuffer(cb);
22697 ASSERT_VK_SUCCESS(err);
22698
22699 // A semaphore
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022700 VkSemaphoreCreateInfo sci = {VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022701 VkSemaphore s;
22702 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s);
22703 ASSERT_VK_SUCCESS(err);
22704
22705 // First submission, to q0
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022706 VkSubmitInfo s0 = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &cb, 1, &s};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022707
22708 err = vkQueueSubmit(q0, 1, &s0, VK_NULL_HANDLE);
22709 ASSERT_VK_SUCCESS(err);
22710
22711 // Second submission, to q1, waiting on s
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022712 VkFlags waitmask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; // doesn't really matter what this value is.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022713 VkSubmitInfo s1 = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 1, &s, &waitmask, 0, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022714
22715 err = vkQueueSubmit(q1, 1, &s1, VK_NULL_HANDLE);
22716 ASSERT_VK_SUCCESS(err);
22717
22718 // Wait for q0 idle
22719 err = vkQueueWaitIdle(q0);
22720 ASSERT_VK_SUCCESS(err);
22721
22722 // Command buffer should have been completed (it was on q0); reset the pool.
22723 vkFreeCommandBuffers(m_device->device(), pool, 1, &cb);
22724
22725 m_errorMonitor->VerifyNotFound();
22726
22727 // Force device completely idle and clean up resources
22728 vkDeviceWaitIdle(m_device->device());
22729 vkDestroyCommandPool(m_device->device(), pool, nullptr);
22730 vkDestroySemaphore(m_device->device(), s, nullptr);
22731}
22732
22733// This is a positive test. No errors should be generated.
22734TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022735 TEST_DESCRIPTION(
22736 "Two command buffers, each in a separate QueueSubmit call "
22737 "submitted on separate queues, the second having a fence, "
22738 "followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022739
Tony Barbour1fa09702017-03-16 12:09:08 -060022740 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022741 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022742
22743 m_errorMonitor->ExpectSuccess();
22744
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022745 VkFence fence;
22746 VkFenceCreateInfo fence_create_info{};
22747 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
22748 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
22749
22750 VkSemaphore semaphore;
22751 VkSemaphoreCreateInfo semaphore_create_info{};
22752 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
22753 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
22754
22755 VkCommandPool command_pool;
22756 VkCommandPoolCreateInfo pool_create_info{};
22757 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
22758 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
22759 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
22760 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
22761
22762 VkCommandBuffer command_buffer[2];
22763 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
22764 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
22765 command_buffer_allocate_info.commandPool = command_pool;
22766 command_buffer_allocate_info.commandBufferCount = 2;
22767 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
22768 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
22769
22770 VkQueue queue = VK_NULL_HANDLE;
22771 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
22772
22773 {
22774 VkCommandBufferBeginInfo begin_info{};
22775 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22776 vkBeginCommandBuffer(command_buffer[0], &begin_info);
22777
22778 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 -070022779 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022780
22781 VkViewport viewport{};
22782 viewport.maxDepth = 1.0f;
22783 viewport.minDepth = 0.0f;
22784 viewport.width = 512;
22785 viewport.height = 512;
22786 viewport.x = 0;
22787 viewport.y = 0;
22788 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
22789 vkEndCommandBuffer(command_buffer[0]);
22790 }
22791 {
22792 VkCommandBufferBeginInfo begin_info{};
22793 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22794 vkBeginCommandBuffer(command_buffer[1], &begin_info);
22795
22796 VkViewport viewport{};
22797 viewport.maxDepth = 1.0f;
22798 viewport.minDepth = 0.0f;
22799 viewport.width = 512;
22800 viewport.height = 512;
22801 viewport.x = 0;
22802 viewport.y = 0;
22803 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
22804 vkEndCommandBuffer(command_buffer[1]);
22805 }
22806 {
22807 VkSubmitInfo submit_info{};
22808 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22809 submit_info.commandBufferCount = 1;
22810 submit_info.pCommandBuffers = &command_buffer[0];
22811 submit_info.signalSemaphoreCount = 1;
22812 submit_info.pSignalSemaphores = &semaphore;
22813 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
22814 }
22815 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022816 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022817 VkSubmitInfo submit_info{};
22818 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22819 submit_info.commandBufferCount = 1;
22820 submit_info.pCommandBuffers = &command_buffer[1];
22821 submit_info.waitSemaphoreCount = 1;
22822 submit_info.pWaitSemaphores = &semaphore;
22823 submit_info.pWaitDstStageMask = flags;
22824 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
22825 }
22826
22827 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
22828
22829 vkDestroyFence(m_device->device(), fence, nullptr);
22830 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
22831 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
22832 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
22833
22834 m_errorMonitor->VerifyNotFound();
22835}
22836
22837// This is a positive test. No errors should be generated.
22838TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueWithSemaphoreAndOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022839 TEST_DESCRIPTION(
22840 "Two command buffers, each in a separate QueueSubmit call "
22841 "on the same queue, sharing a signal/wait semaphore, the "
22842 "second having a fence, "
22843 "followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022844
22845 m_errorMonitor->ExpectSuccess();
22846
Tony Barbour1fa09702017-03-16 12:09:08 -060022847 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022848 VkFence fence;
22849 VkFenceCreateInfo fence_create_info{};
22850 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
22851 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
22852
22853 VkSemaphore semaphore;
22854 VkSemaphoreCreateInfo semaphore_create_info{};
22855 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
22856 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
22857
22858 VkCommandPool command_pool;
22859 VkCommandPoolCreateInfo pool_create_info{};
22860 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
22861 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
22862 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
22863 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
22864
22865 VkCommandBuffer command_buffer[2];
22866 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
22867 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
22868 command_buffer_allocate_info.commandPool = command_pool;
22869 command_buffer_allocate_info.commandBufferCount = 2;
22870 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
22871 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
22872
22873 {
22874 VkCommandBufferBeginInfo begin_info{};
22875 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22876 vkBeginCommandBuffer(command_buffer[0], &begin_info);
22877
22878 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 -070022879 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022880
22881 VkViewport viewport{};
22882 viewport.maxDepth = 1.0f;
22883 viewport.minDepth = 0.0f;
22884 viewport.width = 512;
22885 viewport.height = 512;
22886 viewport.x = 0;
22887 viewport.y = 0;
22888 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
22889 vkEndCommandBuffer(command_buffer[0]);
22890 }
22891 {
22892 VkCommandBufferBeginInfo begin_info{};
22893 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22894 vkBeginCommandBuffer(command_buffer[1], &begin_info);
22895
22896 VkViewport viewport{};
22897 viewport.maxDepth = 1.0f;
22898 viewport.minDepth = 0.0f;
22899 viewport.width = 512;
22900 viewport.height = 512;
22901 viewport.x = 0;
22902 viewport.y = 0;
22903 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
22904 vkEndCommandBuffer(command_buffer[1]);
22905 }
22906 {
22907 VkSubmitInfo submit_info{};
22908 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22909 submit_info.commandBufferCount = 1;
22910 submit_info.pCommandBuffers = &command_buffer[0];
22911 submit_info.signalSemaphoreCount = 1;
22912 submit_info.pSignalSemaphores = &semaphore;
22913 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
22914 }
22915 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022916 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022917 VkSubmitInfo submit_info{};
22918 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22919 submit_info.commandBufferCount = 1;
22920 submit_info.pCommandBuffers = &command_buffer[1];
22921 submit_info.waitSemaphoreCount = 1;
22922 submit_info.pWaitSemaphores = &semaphore;
22923 submit_info.pWaitDstStageMask = flags;
22924 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
22925 }
22926
22927 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
22928
22929 vkDestroyFence(m_device->device(), fence, nullptr);
22930 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
22931 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
22932 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
22933
22934 m_errorMonitor->VerifyNotFound();
22935}
22936
22937// This is a positive test. No errors should be generated.
22938TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueNullQueueSubmitWithFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022939 TEST_DESCRIPTION(
22940 "Two command buffers, each in a separate QueueSubmit call "
22941 "on the same queue, no fences, followed by a third QueueSubmit with NO "
22942 "SubmitInfos but with a fence, followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022943
22944 m_errorMonitor->ExpectSuccess();
22945
Tony Barbour1fa09702017-03-16 12:09:08 -060022946 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022947 VkFence fence;
22948 VkFenceCreateInfo fence_create_info{};
22949 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
22950 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
22951
22952 VkCommandPool command_pool;
22953 VkCommandPoolCreateInfo pool_create_info{};
22954 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
22955 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
22956 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
22957 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
22958
22959 VkCommandBuffer command_buffer[2];
22960 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
22961 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
22962 command_buffer_allocate_info.commandPool = command_pool;
22963 command_buffer_allocate_info.commandBufferCount = 2;
22964 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
22965 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
22966
22967 {
22968 VkCommandBufferBeginInfo begin_info{};
22969 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22970 vkBeginCommandBuffer(command_buffer[0], &begin_info);
22971
22972 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 -070022973 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022974
22975 VkViewport viewport{};
22976 viewport.maxDepth = 1.0f;
22977 viewport.minDepth = 0.0f;
22978 viewport.width = 512;
22979 viewport.height = 512;
22980 viewport.x = 0;
22981 viewport.y = 0;
22982 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
22983 vkEndCommandBuffer(command_buffer[0]);
22984 }
22985 {
22986 VkCommandBufferBeginInfo begin_info{};
22987 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22988 vkBeginCommandBuffer(command_buffer[1], &begin_info);
22989
22990 VkViewport viewport{};
22991 viewport.maxDepth = 1.0f;
22992 viewport.minDepth = 0.0f;
22993 viewport.width = 512;
22994 viewport.height = 512;
22995 viewport.x = 0;
22996 viewport.y = 0;
22997 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
22998 vkEndCommandBuffer(command_buffer[1]);
22999 }
23000 {
23001 VkSubmitInfo submit_info{};
23002 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
23003 submit_info.commandBufferCount = 1;
23004 submit_info.pCommandBuffers = &command_buffer[0];
23005 submit_info.signalSemaphoreCount = 0;
23006 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
23007 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
23008 }
23009 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023010 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023011 VkSubmitInfo submit_info{};
23012 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
23013 submit_info.commandBufferCount = 1;
23014 submit_info.pCommandBuffers = &command_buffer[1];
23015 submit_info.waitSemaphoreCount = 0;
23016 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
23017 submit_info.pWaitDstStageMask = flags;
23018 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
23019 }
23020
23021 vkQueueSubmit(m_device->m_queue, 0, NULL, fence);
23022
23023 VkResult err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
23024 ASSERT_VK_SUCCESS(err);
23025
23026 vkDestroyFence(m_device->device(), fence, nullptr);
23027 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
23028 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
23029
23030 m_errorMonitor->VerifyNotFound();
23031}
23032
23033// This is a positive test. No errors should be generated.
23034TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023035 TEST_DESCRIPTION(
23036 "Two command buffers, each in a separate QueueSubmit call "
23037 "on the same queue, the second having a fence, followed "
23038 "by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023039
23040 m_errorMonitor->ExpectSuccess();
23041
Tony Barbour1fa09702017-03-16 12:09:08 -060023042 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023043 VkFence fence;
23044 VkFenceCreateInfo fence_create_info{};
23045 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
23046 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
23047
23048 VkCommandPool command_pool;
23049 VkCommandPoolCreateInfo pool_create_info{};
23050 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
23051 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
23052 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
23053 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
23054
23055 VkCommandBuffer command_buffer[2];
23056 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
23057 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
23058 command_buffer_allocate_info.commandPool = command_pool;
23059 command_buffer_allocate_info.commandBufferCount = 2;
23060 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
23061 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
23062
23063 {
23064 VkCommandBufferBeginInfo begin_info{};
23065 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
23066 vkBeginCommandBuffer(command_buffer[0], &begin_info);
23067
23068 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 -070023069 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023070
23071 VkViewport viewport{};
23072 viewport.maxDepth = 1.0f;
23073 viewport.minDepth = 0.0f;
23074 viewport.width = 512;
23075 viewport.height = 512;
23076 viewport.x = 0;
23077 viewport.y = 0;
23078 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
23079 vkEndCommandBuffer(command_buffer[0]);
23080 }
23081 {
23082 VkCommandBufferBeginInfo begin_info{};
23083 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
23084 vkBeginCommandBuffer(command_buffer[1], &begin_info);
23085
23086 VkViewport viewport{};
23087 viewport.maxDepth = 1.0f;
23088 viewport.minDepth = 0.0f;
23089 viewport.width = 512;
23090 viewport.height = 512;
23091 viewport.x = 0;
23092 viewport.y = 0;
23093 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
23094 vkEndCommandBuffer(command_buffer[1]);
23095 }
23096 {
23097 VkSubmitInfo submit_info{};
23098 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
23099 submit_info.commandBufferCount = 1;
23100 submit_info.pCommandBuffers = &command_buffer[0];
23101 submit_info.signalSemaphoreCount = 0;
23102 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
23103 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
23104 }
23105 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023106 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023107 VkSubmitInfo submit_info{};
23108 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
23109 submit_info.commandBufferCount = 1;
23110 submit_info.pCommandBuffers = &command_buffer[1];
23111 submit_info.waitSemaphoreCount = 0;
23112 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
23113 submit_info.pWaitDstStageMask = flags;
23114 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
23115 }
23116
23117 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
23118
23119 vkDestroyFence(m_device->device(), fence, nullptr);
23120 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
23121 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
23122
23123 m_errorMonitor->VerifyNotFound();
23124}
23125
23126// This is a positive test. No errors should be generated.
23127TEST_F(VkPositiveLayerTest, TwoSubmitInfosWithSemaphoreOneQueueSubmitsOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023128 TEST_DESCRIPTION(
23129 "Two command buffers each in a separate SubmitInfo sent in a single "
23130 "QueueSubmit call followed by a WaitForFences call.");
Tony Barbour1fa09702017-03-16 12:09:08 -060023131 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023132
23133 m_errorMonitor->ExpectSuccess();
23134
23135 VkFence fence;
23136 VkFenceCreateInfo fence_create_info{};
23137 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
23138 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
23139
23140 VkSemaphore semaphore;
23141 VkSemaphoreCreateInfo semaphore_create_info{};
23142 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
23143 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
23144
23145 VkCommandPool command_pool;
23146 VkCommandPoolCreateInfo pool_create_info{};
23147 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
23148 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
23149 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
23150 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
23151
23152 VkCommandBuffer command_buffer[2];
23153 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
23154 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
23155 command_buffer_allocate_info.commandPool = command_pool;
23156 command_buffer_allocate_info.commandBufferCount = 2;
23157 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
23158 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
23159
23160 {
23161 VkCommandBufferBeginInfo begin_info{};
23162 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
23163 vkBeginCommandBuffer(command_buffer[0], &begin_info);
23164
23165 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 -070023166 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023167
23168 VkViewport viewport{};
23169 viewport.maxDepth = 1.0f;
23170 viewport.minDepth = 0.0f;
23171 viewport.width = 512;
23172 viewport.height = 512;
23173 viewport.x = 0;
23174 viewport.y = 0;
23175 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
23176 vkEndCommandBuffer(command_buffer[0]);
23177 }
23178 {
23179 VkCommandBufferBeginInfo begin_info{};
23180 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
23181 vkBeginCommandBuffer(command_buffer[1], &begin_info);
23182
23183 VkViewport viewport{};
23184 viewport.maxDepth = 1.0f;
23185 viewport.minDepth = 0.0f;
23186 viewport.width = 512;
23187 viewport.height = 512;
23188 viewport.x = 0;
23189 viewport.y = 0;
23190 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
23191 vkEndCommandBuffer(command_buffer[1]);
23192 }
23193 {
23194 VkSubmitInfo submit_info[2];
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023195 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023196
23197 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
23198 submit_info[0].pNext = NULL;
23199 submit_info[0].commandBufferCount = 1;
23200 submit_info[0].pCommandBuffers = &command_buffer[0];
23201 submit_info[0].signalSemaphoreCount = 1;
23202 submit_info[0].pSignalSemaphores = &semaphore;
23203 submit_info[0].waitSemaphoreCount = 0;
23204 submit_info[0].pWaitSemaphores = NULL;
23205 submit_info[0].pWaitDstStageMask = 0;
23206
23207 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
23208 submit_info[1].pNext = NULL;
23209 submit_info[1].commandBufferCount = 1;
23210 submit_info[1].pCommandBuffers = &command_buffer[1];
23211 submit_info[1].waitSemaphoreCount = 1;
23212 submit_info[1].pWaitSemaphores = &semaphore;
23213 submit_info[1].pWaitDstStageMask = flags;
23214 submit_info[1].signalSemaphoreCount = 0;
23215 submit_info[1].pSignalSemaphores = NULL;
23216 vkQueueSubmit(m_device->m_queue, 2, &submit_info[0], fence);
23217 }
23218
23219 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
23220
23221 vkDestroyFence(m_device->device(), fence, nullptr);
23222 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
23223 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
23224 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
23225
23226 m_errorMonitor->VerifyNotFound();
23227}
23228
23229TEST_F(VkPositiveLayerTest, RenderPassSecondaryCommandBuffersMultipleTimes) {
23230 m_errorMonitor->ExpectSuccess();
23231
Tony Barbour1fa09702017-03-16 12:09:08 -060023232 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023233 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
23234
Tony Barbour552f6c02016-12-21 14:34:07 -070023235 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023236
23237 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
23238 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
23239 m_errorMonitor->VerifyNotFound();
23240 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
23241 m_errorMonitor->VerifyNotFound();
23242 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
23243 m_errorMonitor->VerifyNotFound();
23244
23245 m_commandBuffer->EndCommandBuffer();
23246 m_errorMonitor->VerifyNotFound();
23247}
23248
23249TEST_F(VkPositiveLayerTest, ValidRenderPassAttachmentLayoutWithLoadOp) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023250 TEST_DESCRIPTION(
23251 "Positive test where we create a renderpass with an "
23252 "attachment that uses LOAD_OP_CLEAR, the first subpass "
23253 "has a valid layout, and a second subpass then uses a "
23254 "valid *READ_ONLY* layout.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023255 m_errorMonitor->ExpectSuccess();
Tony Barbour1fa09702017-03-16 12:09:08 -060023256 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -060023257 auto depth_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbourf887b162017-03-09 10:06:46 -070023258 if (!depth_format) {
23259 printf(" No Depth + Stencil format found. Skipped.\n");
23260 return;
23261 }
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023262
23263 VkAttachmentReference attach[2] = {};
23264 attach[0].attachment = 0;
23265 attach[0].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
23266 attach[1].attachment = 0;
23267 attach[1].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
23268 VkSubpassDescription subpasses[2] = {};
23269 // First subpass clears DS attach on load
23270 subpasses[0].pDepthStencilAttachment = &attach[0];
23271 // 2nd subpass reads in DS as input attachment
23272 subpasses[1].inputAttachmentCount = 1;
23273 subpasses[1].pInputAttachments = &attach[1];
23274 VkAttachmentDescription attach_desc = {};
Tony Barbourf887b162017-03-09 10:06:46 -070023275 attach_desc.format = depth_format;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023276 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
23277 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
23278 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
23279 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
23280 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
23281 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
23282 attach_desc.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
23283 VkRenderPassCreateInfo rpci = {};
23284 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
23285 rpci.attachmentCount = 1;
23286 rpci.pAttachments = &attach_desc;
23287 rpci.subpassCount = 2;
23288 rpci.pSubpasses = subpasses;
23289
23290 // Now create RenderPass and verify no errors
23291 VkRenderPass rp;
23292 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
23293 m_errorMonitor->VerifyNotFound();
23294
23295 vkDestroyRenderPass(m_device->device(), rp, NULL);
23296}
23297
Tobin Ehlis01103de2017-02-16 13:22:47 -070023298TEST_F(VkPositiveLayerTest, RenderPassDepthStencilLayoutTransition) {
23299 TEST_DESCRIPTION(
23300 "Create a render pass with depth-stencil attachment where layout transition "
23301 "from UNDEFINED TO DS_READ_ONLY_OPTIMAL is set by render pass and verify that "
23302 "transition has correctly occurred at queue submit time with no validation errors.");
23303
Tony Barbour1fa09702017-03-16 12:09:08 -060023304 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -060023305 auto depth_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbourf887b162017-03-09 10:06:46 -070023306 if (!depth_format) {
23307 printf(" No Depth + Stencil format found. Skipped.\n");
23308 return;
23309 }
Tobin Ehlis01103de2017-02-16 13:22:47 -070023310 VkImageFormatProperties format_props;
Tony Barbourf887b162017-03-09 10:06:46 -070023311 vkGetPhysicalDeviceImageFormatProperties(gpu(), depth_format, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
Tobin Ehlis01103de2017-02-16 13:22:47 -070023312 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, 0, &format_props);
23313 if (format_props.maxExtent.width < 32 || format_props.maxExtent.height < 32) {
Tony Barbourf887b162017-03-09 10:06:46 -070023314 printf("Depth extent too small, RenderPassDepthStencilLayoutTransition skipped.\n");
Tobin Ehlis01103de2017-02-16 13:22:47 -070023315 return;
23316 }
23317
23318 m_errorMonitor->ExpectSuccess();
Tobin Ehlis01103de2017-02-16 13:22:47 -070023319 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
23320
23321 // A renderpass with one depth/stencil attachment.
23322 VkAttachmentDescription attachment = {0,
Tony Barbourf887b162017-03-09 10:06:46 -070023323 depth_format,
Tobin Ehlis01103de2017-02-16 13:22:47 -070023324 VK_SAMPLE_COUNT_1_BIT,
23325 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
23326 VK_ATTACHMENT_STORE_OP_DONT_CARE,
23327 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
23328 VK_ATTACHMENT_STORE_OP_DONT_CARE,
23329 VK_IMAGE_LAYOUT_UNDEFINED,
23330 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
23331
23332 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
23333
23334 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, &att_ref, 0, nullptr};
23335
23336 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
23337
23338 VkRenderPass rp;
23339 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
23340 ASSERT_VK_SUCCESS(err);
23341 // A compatible ds image.
23342 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060023343 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 -070023344 ASSERT_TRUE(image.initialized());
23345
23346 VkImageViewCreateInfo ivci = {
23347 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
23348 nullptr,
23349 0,
23350 image.handle(),
23351 VK_IMAGE_VIEW_TYPE_2D,
Tony Barbourf887b162017-03-09 10:06:46 -070023352 depth_format,
Tobin Ehlis01103de2017-02-16 13:22:47 -070023353 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
23354 VK_COMPONENT_SWIZZLE_IDENTITY},
23355 {VK_IMAGE_ASPECT_DEPTH_BIT, 0, 1, 0, 1},
23356 };
23357 VkImageView view;
23358 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
23359 ASSERT_VK_SUCCESS(err);
23360
23361 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
23362 VkFramebuffer fb;
23363 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
23364 ASSERT_VK_SUCCESS(err);
23365
23366 VkRenderPassBeginInfo rpbi = {VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb, {{0, 0}, {32, 32}}, 0, nullptr};
23367 m_commandBuffer->BeginCommandBuffer();
23368 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
23369 vkCmdEndRenderPass(m_commandBuffer->handle());
23370 m_commandBuffer->EndCommandBuffer();
23371 QueueCommandBuffer(false);
23372 m_errorMonitor->VerifyNotFound();
23373
23374 // Cleanup
23375 vkDestroyImageView(m_device->device(), view, NULL);
23376 vkDestroyRenderPass(m_device->device(), rp, NULL);
23377 vkDestroyFramebuffer(m_device->device(), fb, NULL);
23378}
23379
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023380TEST_F(VkPositiveLayerTest, CreatePipelineAttribMatrixType) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023381 TEST_DESCRIPTION(
23382 "Test that pipeline validation accepts matrices passed "
23383 "as vertex attributes");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023384 m_errorMonitor->ExpectSuccess();
23385
Tony Barbour1fa09702017-03-16 12:09:08 -060023386 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023387 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
23388
23389 VkVertexInputBindingDescription input_binding;
23390 memset(&input_binding, 0, sizeof(input_binding));
23391
23392 VkVertexInputAttributeDescription input_attribs[2];
23393 memset(input_attribs, 0, sizeof(input_attribs));
23394
23395 for (int i = 0; i < 2; i++) {
23396 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
23397 input_attribs[i].location = i;
23398 }
23399
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023400 char const *vsSource =
23401 "#version 450\n"
23402 "\n"
23403 "layout(location=0) in mat2x4 x;\n"
23404 "out gl_PerVertex {\n"
23405 " vec4 gl_Position;\n"
23406 "};\n"
23407 "void main(){\n"
23408 " gl_Position = x[0] + x[1];\n"
23409 "}\n";
23410 char const *fsSource =
23411 "#version 450\n"
23412 "\n"
23413 "layout(location=0) out vec4 color;\n"
23414 "void main(){\n"
23415 " color = vec4(1);\n"
23416 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023417
23418 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
23419 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
23420
23421 VkPipelineObj pipe(m_device);
23422 pipe.AddColorAttachment();
23423 pipe.AddShader(&vs);
23424 pipe.AddShader(&fs);
23425
23426 pipe.AddVertexInputBindings(&input_binding, 1);
23427 pipe.AddVertexInputAttribs(input_attribs, 2);
23428
23429 VkDescriptorSetObj descriptorSet(m_device);
23430 descriptorSet.AppendDummy();
23431 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
23432
23433 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
23434
23435 /* expect success */
23436 m_errorMonitor->VerifyNotFound();
23437}
23438
23439TEST_F(VkPositiveLayerTest, CreatePipelineAttribArrayType) {
23440 m_errorMonitor->ExpectSuccess();
23441
Tony Barbour1fa09702017-03-16 12:09:08 -060023442 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023443 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
23444
23445 VkVertexInputBindingDescription input_binding;
23446 memset(&input_binding, 0, sizeof(input_binding));
23447
23448 VkVertexInputAttributeDescription input_attribs[2];
23449 memset(input_attribs, 0, sizeof(input_attribs));
23450
23451 for (int i = 0; i < 2; i++) {
23452 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
23453 input_attribs[i].location = i;
23454 }
23455
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023456 char const *vsSource =
23457 "#version 450\n"
23458 "\n"
23459 "layout(location=0) in vec4 x[2];\n"
23460 "out gl_PerVertex {\n"
23461 " vec4 gl_Position;\n"
23462 "};\n"
23463 "void main(){\n"
23464 " gl_Position = x[0] + x[1];\n"
23465 "}\n";
23466 char const *fsSource =
23467 "#version 450\n"
23468 "\n"
23469 "layout(location=0) out vec4 color;\n"
23470 "void main(){\n"
23471 " color = vec4(1);\n"
23472 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023473
23474 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
23475 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
23476
23477 VkPipelineObj pipe(m_device);
23478 pipe.AddColorAttachment();
23479 pipe.AddShader(&vs);
23480 pipe.AddShader(&fs);
23481
23482 pipe.AddVertexInputBindings(&input_binding, 1);
23483 pipe.AddVertexInputAttribs(input_attribs, 2);
23484
23485 VkDescriptorSetObj descriptorSet(m_device);
23486 descriptorSet.AppendDummy();
23487 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
23488
23489 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
23490
23491 m_errorMonitor->VerifyNotFound();
23492}
23493
23494TEST_F(VkPositiveLayerTest, CreatePipelineAttribComponents) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023495 TEST_DESCRIPTION(
23496 "Test that pipeline validation accepts consuming a vertex attribute "
23497 "through multiple vertex shader inputs, each consuming a different "
23498 "subset of the components.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023499 m_errorMonitor->ExpectSuccess();
23500
Tony Barbour1fa09702017-03-16 12:09:08 -060023501 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023502 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
23503
23504 VkVertexInputBindingDescription input_binding;
23505 memset(&input_binding, 0, sizeof(input_binding));
23506
23507 VkVertexInputAttributeDescription input_attribs[3];
23508 memset(input_attribs, 0, sizeof(input_attribs));
23509
23510 for (int i = 0; i < 3; i++) {
23511 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
23512 input_attribs[i].location = i;
23513 }
23514
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023515 char const *vsSource =
23516 "#version 450\n"
23517 "\n"
23518 "layout(location=0) in vec4 x;\n"
23519 "layout(location=1) in vec3 y1;\n"
23520 "layout(location=1, component=3) in float y2;\n"
23521 "layout(location=2) in vec4 z;\n"
23522 "out gl_PerVertex {\n"
23523 " vec4 gl_Position;\n"
23524 "};\n"
23525 "void main(){\n"
23526 " gl_Position = x + vec4(y1, y2) + z;\n"
23527 "}\n";
23528 char const *fsSource =
23529 "#version 450\n"
23530 "\n"
23531 "layout(location=0) out vec4 color;\n"
23532 "void main(){\n"
23533 " color = vec4(1);\n"
23534 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023535
23536 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
23537 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
23538
23539 VkPipelineObj pipe(m_device);
23540 pipe.AddColorAttachment();
23541 pipe.AddShader(&vs);
23542 pipe.AddShader(&fs);
23543
23544 pipe.AddVertexInputBindings(&input_binding, 1);
23545 pipe.AddVertexInputAttribs(input_attribs, 3);
23546
23547 VkDescriptorSetObj descriptorSet(m_device);
23548 descriptorSet.AppendDummy();
23549 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
23550
23551 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
23552
23553 m_errorMonitor->VerifyNotFound();
23554}
23555
23556TEST_F(VkPositiveLayerTest, CreatePipelineSimplePositive) {
23557 m_errorMonitor->ExpectSuccess();
23558
Tony Barbour1fa09702017-03-16 12:09:08 -060023559 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023560 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
23561
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023562 char const *vsSource =
23563 "#version 450\n"
23564 "out gl_PerVertex {\n"
23565 " vec4 gl_Position;\n"
23566 "};\n"
23567 "void main(){\n"
23568 " gl_Position = vec4(0);\n"
23569 "}\n";
23570 char const *fsSource =
23571 "#version 450\n"
23572 "\n"
23573 "layout(location=0) out vec4 color;\n"
23574 "void main(){\n"
23575 " color = vec4(1);\n"
23576 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023577
23578 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
23579 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
23580
23581 VkPipelineObj pipe(m_device);
23582 pipe.AddColorAttachment();
23583 pipe.AddShader(&vs);
23584 pipe.AddShader(&fs);
23585
23586 VkDescriptorSetObj descriptorSet(m_device);
23587 descriptorSet.AppendDummy();
23588 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
23589
23590 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
23591
23592 m_errorMonitor->VerifyNotFound();
23593}
23594
23595TEST_F(VkPositiveLayerTest, CreatePipelineRelaxedTypeMatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023596 TEST_DESCRIPTION(
23597 "Test that pipeline validation accepts the relaxed type matching rules "
23598 "set out in 14.1.3: fundamental type must match, and producer side must "
23599 "have at least as many components");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023600 m_errorMonitor->ExpectSuccess();
23601
23602 // VK 1.0.8 Specification, 14.1.3 "Additionally,..." block
23603
Tony Barbour1fa09702017-03-16 12:09:08 -060023604 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023605 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
23606
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023607 char const *vsSource =
23608 "#version 450\n"
23609 "out gl_PerVertex {\n"
23610 " vec4 gl_Position;\n"
23611 "};\n"
23612 "layout(location=0) out vec3 x;\n"
23613 "layout(location=1) out ivec3 y;\n"
23614 "layout(location=2) out vec3 z;\n"
23615 "void main(){\n"
23616 " gl_Position = vec4(0);\n"
23617 " x = vec3(0); y = ivec3(0); z = vec3(0);\n"
23618 "}\n";
23619 char const *fsSource =
23620 "#version 450\n"
23621 "\n"
23622 "layout(location=0) out vec4 color;\n"
23623 "layout(location=0) in float x;\n"
23624 "layout(location=1) flat in int y;\n"
23625 "layout(location=2) in vec2 z;\n"
23626 "void main(){\n"
23627 " color = vec4(1 + x + y + z.x);\n"
23628 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023629
23630 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
23631 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
23632
23633 VkPipelineObj pipe(m_device);
23634 pipe.AddColorAttachment();
23635 pipe.AddShader(&vs);
23636 pipe.AddShader(&fs);
23637
23638 VkDescriptorSetObj descriptorSet(m_device);
23639 descriptorSet.AppendDummy();
23640 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
23641
23642 VkResult err = VK_SUCCESS;
23643 err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
23644 ASSERT_VK_SUCCESS(err);
23645
23646 m_errorMonitor->VerifyNotFound();
23647}
23648
23649TEST_F(VkPositiveLayerTest, CreatePipelineTessPerVertex) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023650 TEST_DESCRIPTION(
23651 "Test that pipeline validation accepts per-vertex variables "
23652 "passed between the TCS and TES stages");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023653 m_errorMonitor->ExpectSuccess();
23654
Tony Barbour1fa09702017-03-16 12:09:08 -060023655 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023656 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
23657
23658 if (!m_device->phy().features().tessellationShader) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070023659 printf(" Device does not support tessellation shaders; skipped.\n");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023660 return;
23661 }
23662
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023663 char const *vsSource =
23664 "#version 450\n"
23665 "void main(){}\n";
23666 char const *tcsSource =
23667 "#version 450\n"
23668 "layout(location=0) out int x[];\n"
23669 "layout(vertices=3) out;\n"
23670 "void main(){\n"
23671 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
23672 " gl_TessLevelInner[0] = 1;\n"
23673 " x[gl_InvocationID] = gl_InvocationID;\n"
23674 "}\n";
23675 char const *tesSource =
23676 "#version 450\n"
23677 "layout(triangles, equal_spacing, cw) in;\n"
23678 "layout(location=0) in int x[];\n"
23679 "out gl_PerVertex { vec4 gl_Position; };\n"
23680 "void main(){\n"
23681 " gl_Position.xyz = gl_TessCoord;\n"
23682 " gl_Position.w = x[0] + x[1] + x[2];\n"
23683 "}\n";
23684 char const *fsSource =
23685 "#version 450\n"
23686 "layout(location=0) out vec4 color;\n"
23687 "void main(){\n"
23688 " color = vec4(1);\n"
23689 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023690
23691 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
23692 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
23693 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
23694 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
23695
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023696 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
23697 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023698
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023699 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023700
23701 VkPipelineObj pipe(m_device);
23702 pipe.SetInputAssembly(&iasci);
23703 pipe.SetTessellation(&tsci);
23704 pipe.AddColorAttachment();
23705 pipe.AddShader(&vs);
23706 pipe.AddShader(&tcs);
23707 pipe.AddShader(&tes);
23708 pipe.AddShader(&fs);
23709
23710 VkDescriptorSetObj descriptorSet(m_device);
23711 descriptorSet.AppendDummy();
23712 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
23713
23714 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
23715
23716 m_errorMonitor->VerifyNotFound();
23717}
23718
23719TEST_F(VkPositiveLayerTest, CreatePipelineGeometryInputBlockPositive) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023720 TEST_DESCRIPTION(
23721 "Test that pipeline validation accepts a user-defined "
23722 "interface block passed into the geometry shader. This "
23723 "is interesting because the 'extra' array level is not "
23724 "present on the member type, but on the block instance.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023725 m_errorMonitor->ExpectSuccess();
23726
Tony Barbour1fa09702017-03-16 12:09:08 -060023727 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023728 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
23729
23730 if (!m_device->phy().features().geometryShader) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070023731 printf(" Device does not support geometry shaders; skipped.\n");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023732 return;
23733 }
23734
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023735 char const *vsSource =
23736 "#version 450\n"
23737 "layout(location=0) out VertexData { vec4 x; } vs_out;\n"
23738 "void main(){\n"
23739 " vs_out.x = vec4(1);\n"
23740 "}\n";
23741 char const *gsSource =
23742 "#version 450\n"
23743 "layout(triangles) in;\n"
23744 "layout(triangle_strip, max_vertices=3) out;\n"
23745 "layout(location=0) in VertexData { vec4 x; } gs_in[];\n"
23746 "out gl_PerVertex { vec4 gl_Position; };\n"
23747 "void main() {\n"
23748 " gl_Position = gs_in[0].x;\n"
23749 " EmitVertex();\n"
23750 "}\n";
23751 char const *fsSource =
23752 "#version 450\n"
23753 "layout(location=0) out vec4 color;\n"
23754 "void main(){\n"
23755 " color = vec4(1);\n"
23756 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023757
23758 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
23759 VkShaderObj gs(m_device, gsSource, VK_SHADER_STAGE_GEOMETRY_BIT, this);
23760 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
23761
23762 VkPipelineObj pipe(m_device);
23763 pipe.AddColorAttachment();
23764 pipe.AddShader(&vs);
23765 pipe.AddShader(&gs);
23766 pipe.AddShader(&fs);
23767
23768 VkDescriptorSetObj descriptorSet(m_device);
23769 descriptorSet.AppendDummy();
23770 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
23771
23772 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
23773
23774 m_errorMonitor->VerifyNotFound();
23775}
23776
23777TEST_F(VkPositiveLayerTest, CreatePipeline64BitAttributesPositive) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023778 TEST_DESCRIPTION(
23779 "Test that pipeline validation accepts basic use of 64bit vertex "
23780 "attributes. This is interesting because they consume multiple "
23781 "locations.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023782 m_errorMonitor->ExpectSuccess();
23783
Tony Barbour1fa09702017-03-16 12:09:08 -060023784 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023785 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
23786
23787 if (!m_device->phy().features().shaderFloat64) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070023788 printf(" Device does not support 64bit vertex attributes; skipped.\n");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023789 return;
23790 }
23791
23792 VkVertexInputBindingDescription input_bindings[1];
23793 memset(input_bindings, 0, sizeof(input_bindings));
23794
23795 VkVertexInputAttributeDescription input_attribs[4];
23796 memset(input_attribs, 0, sizeof(input_attribs));
23797 input_attribs[0].location = 0;
23798 input_attribs[0].offset = 0;
23799 input_attribs[0].format = VK_FORMAT_R64G64B64A64_SFLOAT;
23800 input_attribs[1].location = 2;
23801 input_attribs[1].offset = 32;
23802 input_attribs[1].format = VK_FORMAT_R64G64B64A64_SFLOAT;
23803 input_attribs[2].location = 4;
23804 input_attribs[2].offset = 64;
23805 input_attribs[2].format = VK_FORMAT_R64G64B64A64_SFLOAT;
23806 input_attribs[3].location = 6;
23807 input_attribs[3].offset = 96;
23808 input_attribs[3].format = VK_FORMAT_R64G64B64A64_SFLOAT;
23809
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023810 char const *vsSource =
23811 "#version 450\n"
23812 "\n"
23813 "layout(location=0) in dmat4 x;\n"
23814 "out gl_PerVertex {\n"
23815 " vec4 gl_Position;\n"
23816 "};\n"
23817 "void main(){\n"
23818 " gl_Position = vec4(x[0][0]);\n"
23819 "}\n";
23820 char const *fsSource =
23821 "#version 450\n"
23822 "\n"
23823 "layout(location=0) out vec4 color;\n"
23824 "void main(){\n"
23825 " color = vec4(1);\n"
23826 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023827
23828 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
23829 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
23830
23831 VkPipelineObj pipe(m_device);
23832 pipe.AddColorAttachment();
23833 pipe.AddShader(&vs);
23834 pipe.AddShader(&fs);
23835
23836 pipe.AddVertexInputBindings(input_bindings, 1);
23837 pipe.AddVertexInputAttribs(input_attribs, 4);
23838
23839 VkDescriptorSetObj descriptorSet(m_device);
23840 descriptorSet.AppendDummy();
23841 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
23842
23843 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
23844
23845 m_errorMonitor->VerifyNotFound();
23846}
23847
23848TEST_F(VkPositiveLayerTest, CreatePipelineInputAttachmentPositive) {
23849 TEST_DESCRIPTION("Positive test for a correctly matched input attachment");
23850 m_errorMonitor->ExpectSuccess();
23851
Tony Barbour1fa09702017-03-16 12:09:08 -060023852 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023853
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023854 char const *vsSource =
23855 "#version 450\n"
23856 "\n"
23857 "out gl_PerVertex {\n"
23858 " vec4 gl_Position;\n"
23859 "};\n"
23860 "void main(){\n"
23861 " gl_Position = vec4(1);\n"
23862 "}\n";
23863 char const *fsSource =
23864 "#version 450\n"
23865 "\n"
23866 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
23867 "layout(location=0) out vec4 color;\n"
23868 "void main() {\n"
23869 " color = subpassLoad(x);\n"
23870 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023871
23872 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
23873 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
23874
23875 VkPipelineObj pipe(m_device);
23876 pipe.AddShader(&vs);
23877 pipe.AddShader(&fs);
23878 pipe.AddColorAttachment();
23879 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
23880
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023881 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
23882 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023883 VkDescriptorSetLayout dsl;
23884 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
23885 ASSERT_VK_SUCCESS(err);
23886
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023887 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023888 VkPipelineLayout pl;
23889 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
23890 ASSERT_VK_SUCCESS(err);
23891
23892 VkAttachmentDescription descs[2] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023893 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
23894 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
23895 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
23896 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
23897 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 -060023898 };
23899 VkAttachmentReference color = {
23900 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
23901 };
23902 VkAttachmentReference input = {
23903 1, VK_IMAGE_LAYOUT_GENERAL,
23904 };
23905
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023906 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023907
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023908 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023909 VkRenderPass rp;
23910 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
23911 ASSERT_VK_SUCCESS(err);
23912
23913 // should be OK. would go wrong here if it's going to...
23914 pipe.CreateVKPipeline(pl, rp);
23915
23916 m_errorMonitor->VerifyNotFound();
23917
23918 vkDestroyRenderPass(m_device->device(), rp, nullptr);
23919 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
23920 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
23921}
23922
23923TEST_F(VkPositiveLayerTest, CreateComputePipelineMissingDescriptorUnusedPositive) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023924 TEST_DESCRIPTION(
23925 "Test that pipeline validation accepts a compute pipeline which declares a "
23926 "descriptor-backed resource which is not provided, but the shader does not "
23927 "statically use it. This is interesting because it requires compute pipelines "
23928 "to have a proper descriptor use walk, which they didn't for some time.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023929 m_errorMonitor->ExpectSuccess();
23930
Tony Barbour1fa09702017-03-16 12:09:08 -060023931 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023932
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023933 char const *csSource =
23934 "#version 450\n"
23935 "\n"
23936 "layout(local_size_x=1) in;\n"
23937 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
23938 "void main(){\n"
23939 " // x is not used.\n"
23940 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023941
23942 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
23943
23944 VkDescriptorSetObj descriptorSet(m_device);
23945 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
23946
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023947 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
23948 nullptr,
23949 0,
23950 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
23951 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
23952 descriptorSet.GetPipelineLayout(),
23953 VK_NULL_HANDLE,
23954 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023955
23956 VkPipeline pipe;
23957 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
23958
23959 m_errorMonitor->VerifyNotFound();
23960
23961 if (err == VK_SUCCESS) {
23962 vkDestroyPipeline(m_device->device(), pipe, nullptr);
23963 }
23964}
23965
23966TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsSampler) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023967 TEST_DESCRIPTION(
23968 "Test that pipeline validation accepts a shader consuming only the "
23969 "sampler portion of a combined image + sampler");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023970 m_errorMonitor->ExpectSuccess();
23971
Tony Barbour1fa09702017-03-16 12:09:08 -060023972 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023973
23974 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023975 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
23976 {1, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
23977 {2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023978 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023979 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023980 VkDescriptorSetLayout dsl;
23981 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
23982 ASSERT_VK_SUCCESS(err);
23983
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023984 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023985 VkPipelineLayout pl;
23986 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
23987 ASSERT_VK_SUCCESS(err);
23988
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023989 char const *csSource =
23990 "#version 450\n"
23991 "\n"
23992 "layout(local_size_x=1) in;\n"
23993 "layout(set=0, binding=0) uniform sampler s;\n"
23994 "layout(set=0, binding=1) uniform texture2D t;\n"
23995 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
23996 "void main() {\n"
23997 " x = texture(sampler2D(t, s), vec2(0));\n"
23998 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023999 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
24000
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070024001 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
24002 nullptr,
24003 0,
24004 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
24005 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
24006 pl,
24007 VK_NULL_HANDLE,
24008 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024009
24010 VkPipeline pipe;
24011 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
24012
24013 m_errorMonitor->VerifyNotFound();
24014
24015 if (err == VK_SUCCESS) {
24016 vkDestroyPipeline(m_device->device(), pipe, nullptr);
24017 }
24018
24019 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
24020 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
24021}
24022
24023TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsImage) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070024024 TEST_DESCRIPTION(
24025 "Test that pipeline validation accepts a shader consuming only the "
24026 "image portion of a combined image + sampler");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024027 m_errorMonitor->ExpectSuccess();
24028
Tony Barbour1fa09702017-03-16 12:09:08 -060024029 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024030
24031 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070024032 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
24033 {1, VK_DESCRIPTOR_TYPE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
24034 {2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024035 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070024036 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024037 VkDescriptorSetLayout dsl;
24038 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
24039 ASSERT_VK_SUCCESS(err);
24040
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070024041 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024042 VkPipelineLayout pl;
24043 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
24044 ASSERT_VK_SUCCESS(err);
24045
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070024046 char const *csSource =
24047 "#version 450\n"
24048 "\n"
24049 "layout(local_size_x=1) in;\n"
24050 "layout(set=0, binding=0) uniform texture2D t;\n"
24051 "layout(set=0, binding=1) uniform sampler s;\n"
24052 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
24053 "void main() {\n"
24054 " x = texture(sampler2D(t, s), vec2(0));\n"
24055 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024056 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
24057
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070024058 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
24059 nullptr,
24060 0,
24061 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
24062 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
24063 pl,
24064 VK_NULL_HANDLE,
24065 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024066
24067 VkPipeline pipe;
24068 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
24069
24070 m_errorMonitor->VerifyNotFound();
24071
24072 if (err == VK_SUCCESS) {
24073 vkDestroyPipeline(m_device->device(), pipe, nullptr);
24074 }
24075
24076 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
24077 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
24078}
24079
24080TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsBoth) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070024081 TEST_DESCRIPTION(
24082 "Test that pipeline validation accepts a shader consuming "
24083 "both the sampler and the image of a combined image+sampler "
24084 "but via separate variables");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024085 m_errorMonitor->ExpectSuccess();
24086
Tony Barbour1fa09702017-03-16 12:09:08 -060024087 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024088
24089 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070024090 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
24091 {1, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024092 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070024093 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 2, bindings};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024094 VkDescriptorSetLayout dsl;
24095 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
24096 ASSERT_VK_SUCCESS(err);
24097
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070024098 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024099 VkPipelineLayout pl;
24100 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
24101 ASSERT_VK_SUCCESS(err);
24102
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070024103 char const *csSource =
24104 "#version 450\n"
24105 "\n"
24106 "layout(local_size_x=1) in;\n"
24107 "layout(set=0, binding=0) uniform texture2D t;\n"
24108 "layout(set=0, binding=0) uniform sampler s; // both binding 0!\n"
24109 "layout(set=0, binding=1) buffer block { vec4 x; };\n"
24110 "void main() {\n"
24111 " x = texture(sampler2D(t, s), vec2(0));\n"
24112 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024113 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
24114
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070024115 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
24116 nullptr,
24117 0,
24118 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
24119 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
24120 pl,
24121 VK_NULL_HANDLE,
24122 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024123
24124 VkPipeline pipe;
24125 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
24126
24127 m_errorMonitor->VerifyNotFound();
24128
24129 if (err == VK_SUCCESS) {
24130 vkDestroyPipeline(m_device->device(), pipe, nullptr);
24131 }
24132
24133 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
24134 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
24135}
24136
Tony Barbour3ed87a02017-03-15 16:19:02 -060024137TEST_F(VkPositiveLayerTest, Maintenance1Tests) {
Mark Lobodzinskidf784fc2017-03-14 09:18:40 -060024138 TEST_DESCRIPTION("Validate various special cases for the Maintenance1_KHR extension");
24139
Tony Barbour3ed87a02017-03-15 16:19:02 -060024140 device_extension_names.push_back(VK_KHR_MAINTENANCE1_EXTENSION_NAME);
Tony Barbour73c0f352017-03-16 15:55:38 -060024141 InitFramework(instance_layer_names, instance_extension_names, device_extension_names, myDbgFunc, m_errorMonitor);
Tony Barbour3ed87a02017-03-15 16:19:02 -060024142
Mark Lobodzinskidf784fc2017-03-14 09:18:40 -060024143 // Ensure that extension is available and enabled.
24144 uint32_t extension_count = 0;
24145 bool supports_maintenance1_extension = false;
24146 VkResult err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, nullptr);
24147 ASSERT_VK_SUCCESS(err);
24148 if (extension_count > 0) {
24149 std::vector<VkExtensionProperties> available_extensions(extension_count);
24150
24151 err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, &available_extensions[0]);
24152 ASSERT_VK_SUCCESS(err);
24153 for (const auto &extension_props : available_extensions) {
24154 if (strcmp(extension_props.extensionName, VK_KHR_MAINTENANCE1_EXTENSION_NAME) == 0) {
24155 supports_maintenance1_extension = true;
24156 }
24157 }
24158 }
24159
24160 // Proceed if extension is supported by hardware
24161 if (!supports_maintenance1_extension) {
24162 printf(" Maintenance1 Extension not supported, skipping tests\n");
24163 return;
24164 }
Mark Lobodzinskidf784fc2017-03-14 09:18:40 -060024165
24166 m_errorMonitor->ExpectSuccess();
Dave Houlton8e0fe7a2017-03-30 10:32:10 -060024167 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskidf784fc2017-03-14 09:18:40 -060024168 VkCommandBuffer cmd_buf;
24169 VkCommandBufferAllocateInfo alloc_info;
24170 alloc_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
24171 alloc_info.pNext = NULL;
24172 alloc_info.commandBufferCount = 1;
Mike Schuchardt06304c22017-03-01 17:09:09 -070024173 alloc_info.commandPool = m_commandPool->handle();
Mark Lobodzinskidf784fc2017-03-14 09:18:40 -060024174 alloc_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
24175 vkAllocateCommandBuffers(m_device->device(), &alloc_info, &cmd_buf);
24176
24177 VkCommandBufferBeginInfo cb_binfo;
24178 cb_binfo.pNext = NULL;
24179 cb_binfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
24180 cb_binfo.pInheritanceInfo = VK_NULL_HANDLE;
24181 cb_binfo.flags = 0;
24182 vkBeginCommandBuffer(cmd_buf, &cb_binfo);
24183 // Set Negative height, should give error if Maintenance 1 is not enabled
24184 VkViewport viewport = {0, 0, 16, -16, 0, 1};
24185 vkCmdSetViewport(cmd_buf, 0, 1, &viewport);
24186 vkEndCommandBuffer(cmd_buf);
24187
24188 m_errorMonitor->VerifyNotFound();
24189}
24190
Mark Lobodzinski35ecad32017-03-27 13:09:07 -060024191TEST_F(VkLayerTest, DuplicateValidPNextStructures) {
24192 TEST_DESCRIPTION("Create a pNext chain containing valid strutures, but with a duplicate structure type");
24193
24194 ASSERT_NO_FATAL_FAILURE(Init());
24195
24196 uint32_t extension_count = 0;
24197 VkResult err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, nullptr);
24198 ASSERT_VK_SUCCESS(err);
24199
24200 if (extension_count > 0) {
24201 std::vector<VkExtensionProperties> available_extensions(extension_count);
24202 err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, &available_extensions[0]);
24203 ASSERT_VK_SUCCESS(err);
24204
24205 for (const auto &extension_props : available_extensions) {
24206 if (strcmp(extension_props.extensionName, VK_NV_DEDICATED_ALLOCATION_EXTENSION_NAME) == 0) {
24207 // Create two pNext structures which by themselves would be valid
24208 VkDedicatedAllocationBufferCreateInfoNV dedicated_buffer_create_info = {};
24209 VkDedicatedAllocationBufferCreateInfoNV dedicated_buffer_create_info_2 = {};
24210 dedicated_buffer_create_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_BUFFER_CREATE_INFO_NV;
24211 dedicated_buffer_create_info.pNext = &dedicated_buffer_create_info_2;
24212 dedicated_buffer_create_info.dedicatedAllocation = VK_TRUE;
24213
24214 dedicated_buffer_create_info_2.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_BUFFER_CREATE_INFO_NV;
24215 dedicated_buffer_create_info_2.pNext = nullptr;
24216 dedicated_buffer_create_info_2.dedicatedAllocation = VK_TRUE;
24217
24218 uint32_t queue_family_index = 0;
24219 VkBufferCreateInfo buffer_create_info = {};
24220 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
24221 buffer_create_info.pNext = &dedicated_buffer_create_info;
24222 buffer_create_info.size = 1024;
24223 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
24224 buffer_create_info.queueFamilyIndexCount = 1;
24225 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
24226
24227 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "chain contains duplicate structure types");
24228 VkBuffer buffer;
24229 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
24230 m_errorMonitor->VerifyFound();
24231 }
24232 }
24233 }
24234}
24235
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024236TEST_F(VkPositiveLayerTest, ValidStructPNext) {
24237 TEST_DESCRIPTION("Verify that a valid pNext value is handled correctly");
24238
Tony Barbour1fa09702017-03-16 12:09:08 -060024239 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024240
24241 // Positive test to check parameter_validation and unique_objects support
24242 // for NV_dedicated_allocation
24243 uint32_t extension_count = 0;
24244 bool supports_nv_dedicated_allocation = false;
24245 VkResult err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, nullptr);
24246 ASSERT_VK_SUCCESS(err);
24247
24248 if (extension_count > 0) {
24249 std::vector<VkExtensionProperties> available_extensions(extension_count);
24250
24251 err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, &available_extensions[0]);
24252 ASSERT_VK_SUCCESS(err);
24253
24254 for (const auto &extension_props : available_extensions) {
24255 if (strcmp(extension_props.extensionName, VK_NV_DEDICATED_ALLOCATION_EXTENSION_NAME) == 0) {
24256 supports_nv_dedicated_allocation = true;
24257 }
24258 }
24259 }
24260
24261 if (supports_nv_dedicated_allocation) {
24262 m_errorMonitor->ExpectSuccess();
24263
24264 VkDedicatedAllocationBufferCreateInfoNV dedicated_buffer_create_info = {};
24265 dedicated_buffer_create_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_BUFFER_CREATE_INFO_NV;
24266 dedicated_buffer_create_info.pNext = nullptr;
24267 dedicated_buffer_create_info.dedicatedAllocation = VK_TRUE;
24268
24269 uint32_t queue_family_index = 0;
24270 VkBufferCreateInfo buffer_create_info = {};
24271 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
24272 buffer_create_info.pNext = &dedicated_buffer_create_info;
24273 buffer_create_info.size = 1024;
24274 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
24275 buffer_create_info.queueFamilyIndexCount = 1;
24276 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
24277
24278 VkBuffer buffer;
Karl Schultz47dd59d2017-01-20 13:19:20 -070024279 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024280 ASSERT_VK_SUCCESS(err);
24281
24282 VkMemoryRequirements memory_reqs;
24283 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
24284
24285 VkDedicatedAllocationMemoryAllocateInfoNV dedicated_memory_info = {};
24286 dedicated_memory_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_MEMORY_ALLOCATE_INFO_NV;
24287 dedicated_memory_info.pNext = nullptr;
24288 dedicated_memory_info.buffer = buffer;
24289 dedicated_memory_info.image = VK_NULL_HANDLE;
24290
24291 VkMemoryAllocateInfo memory_info = {};
24292 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
24293 memory_info.pNext = &dedicated_memory_info;
24294 memory_info.allocationSize = memory_reqs.size;
24295
24296 bool pass;
24297 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
24298 ASSERT_TRUE(pass);
24299
24300 VkDeviceMemory buffer_memory;
24301 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
24302 ASSERT_VK_SUCCESS(err);
24303
24304 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
24305 ASSERT_VK_SUCCESS(err);
24306
24307 vkDestroyBuffer(m_device->device(), buffer, NULL);
24308 vkFreeMemory(m_device->device(), buffer_memory, NULL);
24309
24310 m_errorMonitor->VerifyNotFound();
24311 }
24312}
24313
24314TEST_F(VkPositiveLayerTest, PSOPolygonModeValid) {
24315 VkResult err;
24316
24317 TEST_DESCRIPTION("Verify that using a solid polygon fill mode works correctly.");
24318
Tony Barbour1fa09702017-03-16 12:09:08 -060024319 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024320 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
24321
24322 std::vector<const char *> device_extension_names;
24323 auto features = m_device->phy().features();
24324 // Artificially disable support for non-solid fill modes
24325 features.fillModeNonSolid = false;
24326 // The sacrificial device object
24327 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
24328
24329 VkRenderpassObj render_pass(&test_device);
24330
24331 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
24332 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
24333 pipeline_layout_ci.setLayoutCount = 0;
24334 pipeline_layout_ci.pSetLayouts = NULL;
24335
24336 VkPipelineLayout pipeline_layout;
24337 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
24338 ASSERT_VK_SUCCESS(err);
24339
24340 VkPipelineRasterizationStateCreateInfo rs_ci = {};
24341 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
24342 rs_ci.pNext = nullptr;
24343 rs_ci.lineWidth = 1.0f;
24344 rs_ci.rasterizerDiscardEnable = true;
24345
24346 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
24347 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
24348
24349 // Set polygonMode=FILL. No error is expected
24350 m_errorMonitor->ExpectSuccess();
24351 {
24352 VkPipelineObj pipe(&test_device);
24353 pipe.AddShader(&vs);
24354 pipe.AddShader(&fs);
24355 pipe.AddColorAttachment();
24356 // Set polygonMode to a good value
24357 rs_ci.polygonMode = VK_POLYGON_MODE_FILL;
24358 pipe.SetRasterization(&rs_ci);
24359 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
24360 }
24361 m_errorMonitor->VerifyNotFound();
24362
24363 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
24364}
24365
Dave Houlton1150cf52017-04-27 14:38:11 -060024366TEST_F(VkPositiveLayerTest, LongSemaphoreChain) {
Chris Forbes94196952017-04-06 16:30:59 -070024367 m_errorMonitor->ExpectSuccess();
24368
24369 ASSERT_NO_FATAL_FAILURE(Init());
24370 VkResult err;
24371
24372 std::vector<VkSemaphore> semaphores;
24373
24374 const int chainLength = 32768;
24375 VkPipelineStageFlags flags = VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT;
24376
24377 for (int i = 0; i < chainLength; i++) {
Dave Houlton1150cf52017-04-27 14:38:11 -060024378 VkSemaphoreCreateInfo sci = {VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0};
Chris Forbes94196952017-04-06 16:30:59 -070024379 VkSemaphore semaphore;
24380 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &semaphore);
24381 ASSERT_VK_SUCCESS(err);
24382
24383 semaphores.push_back(semaphore);
24384
Chris Forbesfc50aaa2017-05-01 10:20:17 -070024385 VkSubmitInfo si = {VK_STRUCTURE_TYPE_SUBMIT_INFO,
24386 nullptr,
24387 semaphores.size() > 1 ? 1u : 0u,
24388 semaphores.size() > 1 ? &semaphores[semaphores.size() - 2] : nullptr,
24389 &flags,
24390 0,
24391 nullptr,
24392 1,
24393 &semaphores[semaphores.size() - 1]};
Chris Forbes94196952017-04-06 16:30:59 -070024394 err = vkQueueSubmit(m_device->m_queue, 1, &si, VK_NULL_HANDLE);
24395 ASSERT_VK_SUCCESS(err);
24396 }
24397
Dave Houlton1150cf52017-04-27 14:38:11 -060024398 VkFenceCreateInfo fci = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0};
Chris Forbes94196952017-04-06 16:30:59 -070024399 VkFence fence;
24400 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
24401 ASSERT_VK_SUCCESS(err);
Dave Houlton1150cf52017-04-27 14:38:11 -060024402 VkSubmitInfo si = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 1, &semaphores.back(), &flags, 0, nullptr, 0, nullptr};
Chris Forbes94196952017-04-06 16:30:59 -070024403 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
24404 ASSERT_VK_SUCCESS(err);
24405
24406 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
24407
Dave Houlton1150cf52017-04-27 14:38:11 -060024408 for (auto semaphore : semaphores) vkDestroySemaphore(m_device->device(), semaphore, nullptr);
Chris Forbes94196952017-04-06 16:30:59 -070024409
24410 vkDestroyFence(m_device->device(), fence, nullptr);
24411
24412 m_errorMonitor->VerifyNotFound();
24413}
24414
Mike Stroyanca855662017-05-02 11:06:27 -060024415extern "C" void *ReleaseNullFence(void *arg) {
24416 struct thread_data_struct *data = (struct thread_data_struct *)arg;
24417
24418 for (int i = 0; i < 40000; i++) {
24419 vkDestroyFence(data->device, VK_NULL_HANDLE, NULL);
24420 if (data->bailout) {
24421 break;
24422 }
24423 }
24424 return NULL;
24425}
24426
24427TEST_F(VkPositiveLayerTest, ThreadNullFenceCollision) {
24428 test_platform_thread thread;
24429
24430 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "THREADING ERROR");
24431
24432 ASSERT_NO_FATAL_FAILURE(Init());
24433
24434 struct thread_data_struct data;
24435 data.device = m_device->device();
24436 data.bailout = false;
24437 m_errorMonitor->SetBailout(&data.bailout);
24438
24439 // Call vkDestroyFence of VK_NULL_HANDLE repeatedly using multiple threads.
24440 // There should be no validation error from collision of that non-object.
24441 test_platform_thread_create(&thread, ReleaseNullFence, (void *)&data);
24442 for (int i = 0; i < 40000; i++) {
24443 vkDestroyFence(m_device->device(), VK_NULL_HANDLE, NULL);
24444 }
24445 test_platform_thread_join(thread, NULL);
24446
24447 m_errorMonitor->SetBailout(NULL);
24448
24449 m_errorMonitor->VerifyNotFound();
24450}
24451
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070024452#if 0 // A few devices have issues with this test so disabling for now
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024453TEST_F(VkPositiveLayerTest, LongFenceChain)
24454{
24455 m_errorMonitor->ExpectSuccess();
24456
Tony Barbour1fa09702017-03-16 12:09:08 -060024457 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024458 VkResult err;
24459
24460 std::vector<VkFence> fences;
24461
24462 const int chainLength = 32768;
24463
24464 for (int i = 0; i < chainLength; i++) {
24465 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
24466 VkFence fence;
24467 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
24468 ASSERT_VK_SUCCESS(err);
24469
24470 fences.push_back(fence);
24471
24472 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr,
24473 0, nullptr, 0, nullptr };
24474 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
24475 ASSERT_VK_SUCCESS(err);
24476
24477 }
24478
24479 // BOOM, stack overflow.
24480 vkWaitForFences(m_device->device(), 1, &fences.back(), VK_TRUE, UINT64_MAX);
24481
24482 for (auto fence : fences)
24483 vkDestroyFence(m_device->device(), fence, nullptr);
24484
24485 m_errorMonitor->VerifyNotFound();
24486}
24487#endif
24488
Petr Kraus4d718682017-05-18 03:38:41 +020024489TEST_F(VkPositiveLayerTest, ClearColorImageWithValidRange) {
24490 TEST_DESCRIPTION("Record clear color with a valid VkImageSubresourceRange");
24491
24492 ASSERT_NO_FATAL_FAILURE(Init());
24493 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
24494
24495 VkImageObj image(m_device);
24496 image.Init(32, 32, 1, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_OPTIMAL);
24497 ASSERT_TRUE(image.create_info().arrayLayers == 1);
24498 ASSERT_TRUE(image.initialized());
24499 image.SetLayout(VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
24500
24501 const VkClearColorValue clear_color = {{0.0f, 0.0f, 0.0f, 1.0f}};
24502
24503 m_commandBuffer->BeginCommandBuffer();
24504 const auto cb_handle = m_commandBuffer->GetBufferHandle();
24505
24506 // Try good case
24507 {
24508 m_errorMonitor->ExpectSuccess();
24509 VkImageSubresourceRange range = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1};
24510 vkCmdClearColorImage(cb_handle, image.handle(), image.Layout(), &clear_color, 1, &range);
24511 m_errorMonitor->VerifyNotFound();
24512 }
24513
24514 // Try good case with VK_REMAINING
24515 {
24516 m_errorMonitor->ExpectSuccess();
24517 VkImageSubresourceRange range = {VK_IMAGE_ASPECT_COLOR_BIT, 0, VK_REMAINING_MIP_LEVELS, 0, VK_REMAINING_ARRAY_LAYERS};
24518 vkCmdClearColorImage(cb_handle, image.handle(), image.Layout(), &clear_color, 1, &range);
24519 m_errorMonitor->VerifyNotFound();
24520 }
24521}
24522
24523TEST_F(VkPositiveLayerTest, ClearDepthStencilWithValidRange) {
24524 TEST_DESCRIPTION("Record clear depth with a valid VkImageSubresourceRange");
24525
24526 ASSERT_NO_FATAL_FAILURE(Init());
24527 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
24528
24529 auto depth_format = FindSupportedDepthStencilFormat(gpu());
24530 if (!depth_format) {
24531 printf(" No Depth + Stencil format found. Skipped.\n");
24532 return;
24533 }
24534
24535 VkImageObj image(m_device);
24536 image.Init(32, 32, 1, depth_format, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_OPTIMAL);
24537 ASSERT_TRUE(image.create_info().arrayLayers == 1);
24538 ASSERT_TRUE(image.initialized());
24539 const VkImageAspectFlags ds_aspect = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
24540 image.SetLayout(ds_aspect, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
24541
24542 const VkClearDepthStencilValue clear_value = {};
24543
24544 m_commandBuffer->BeginCommandBuffer();
24545 const auto cb_handle = m_commandBuffer->GetBufferHandle();
24546
24547 // Try good case
24548 {
24549 m_errorMonitor->ExpectSuccess();
24550 VkImageSubresourceRange range = {ds_aspect, 0, 1, 0, 1};
24551 vkCmdClearDepthStencilImage(cb_handle, image.handle(), image.Layout(), &clear_value, 1, &range);
24552 m_errorMonitor->VerifyNotFound();
24553 }
24554
24555 // Try good case with VK_REMAINING
24556 {
24557 m_errorMonitor->ExpectSuccess();
24558 VkImageSubresourceRange range = {ds_aspect, 0, VK_REMAINING_MIP_LEVELS, 0, VK_REMAINING_ARRAY_LAYERS};
24559 vkCmdClearDepthStencilImage(cb_handle, image.handle(), image.Layout(), &clear_value, 1, &range);
24560 m_errorMonitor->VerifyNotFound();
24561 }
24562}
24563
Cody Northrop1242dfd2016-07-13 17:24:59 -060024564#if defined(ANDROID) && defined(VALIDATION_APK)
Cody Northropb94529f2017-04-05 13:05:51 -060024565const char *appTag = "VulkanLayerValidationTests";
Cody Northrop1242dfd2016-07-13 17:24:59 -060024566static bool initialized = false;
24567static bool active = false;
24568
24569// Convert Intents to argv
24570// Ported from Hologram sample, only difference is flexible key
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024571std::vector<std::string> get_args(android_app &app, const char *intent_extra_data_key) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060024572 std::vector<std::string> args;
24573 JavaVM &vm = *app.activity->vm;
24574 JNIEnv *p_env;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070024575 if (vm.AttachCurrentThread(&p_env, nullptr) != JNI_OK) return args;
Cody Northrop1242dfd2016-07-13 17:24:59 -060024576
24577 JNIEnv &env = *p_env;
24578 jobject activity = app.activity->clazz;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024579 jmethodID get_intent_method = env.GetMethodID(env.GetObjectClass(activity), "getIntent", "()Landroid/content/Intent;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060024580 jobject intent = env.CallObjectMethod(activity, get_intent_method);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024581 jmethodID get_string_extra_method =
24582 env.GetMethodID(env.GetObjectClass(intent), "getStringExtra", "(Ljava/lang/String;)Ljava/lang/String;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060024583 jvalue get_string_extra_args;
24584 get_string_extra_args.l = env.NewStringUTF(intent_extra_data_key);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024585 jstring extra_str = static_cast<jstring>(env.CallObjectMethodA(intent, get_string_extra_method, &get_string_extra_args));
Cody Northrop1242dfd2016-07-13 17:24:59 -060024586
24587 std::string args_str;
24588 if (extra_str) {
24589 const char *extra_utf = env.GetStringUTFChars(extra_str, nullptr);
24590 args_str = extra_utf;
24591 env.ReleaseStringUTFChars(extra_str, extra_utf);
24592 env.DeleteLocalRef(extra_str);
24593 }
24594
24595 env.DeleteLocalRef(get_string_extra_args.l);
24596 env.DeleteLocalRef(intent);
24597 vm.DetachCurrentThread();
24598
24599 // split args_str
24600 std::stringstream ss(args_str);
24601 std::string arg;
24602 while (std::getline(ss, arg, ' ')) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070024603 if (!arg.empty()) args.push_back(arg);
Cody Northrop1242dfd2016-07-13 17:24:59 -060024604 }
24605
24606 return args;
24607}
24608
Dave Houlton11dcd5e2017-04-25 16:00:10 -060024609void addFullTestCommentIfPresent(const ::testing::TestInfo &test_info, std::string &error_message) {
24610 const char *const type_param = test_info.type_param();
24611 const char *const value_param = test_info.value_param();
Cody Northropb94529f2017-04-05 13:05:51 -060024612
24613 if (type_param != NULL || value_param != NULL) {
24614 error_message.append(", where ");
24615 if (type_param != NULL) {
Dave Houlton11dcd5e2017-04-25 16:00:10 -060024616 error_message.append("TypeParam = ").append(type_param);
24617 if (value_param != NULL) error_message.append(" and ");
Cody Northropb94529f2017-04-05 13:05:51 -060024618 }
24619 if (value_param != NULL) {
24620 error_message.append("GetParam() = ").append(value_param);
24621 }
24622 }
24623}
24624
24625// Inspired by https://github.com/google/googletest/blob/master/googletest/docs/AdvancedGuide.md
24626class LogcatPrinter : public ::testing::EmptyTestEventListener {
24627 // Called before a test starts.
Dave Houlton11dcd5e2017-04-25 16:00:10 -060024628 virtual void OnTestStart(const ::testing::TestInfo &test_info) {
Cody Northropb94529f2017-04-05 13:05:51 -060024629 __android_log_print(ANDROID_LOG_INFO, appTag, "[ RUN ] %s.%s", test_info.test_case_name(), test_info.name());
24630 }
24631
24632 // Called after a failed assertion or a SUCCEED() invocation.
Dave Houlton11dcd5e2017-04-25 16:00:10 -060024633 virtual void OnTestPartResult(const ::testing::TestPartResult &result) {
Cody Northropb94529f2017-04-05 13:05:51 -060024634 // If the test part succeeded, we don't need to do anything.
Dave Houlton11dcd5e2017-04-25 16:00:10 -060024635 if (result.type() == ::testing::TestPartResult::kSuccess) return;
Cody Northropb94529f2017-04-05 13:05:51 -060024636
Dave Houlton11dcd5e2017-04-25 16:00:10 -060024637 __android_log_print(ANDROID_LOG_INFO, appTag, "%s in %s:%d %s", result.failed() ? "*** Failure" : "Success",
24638 result.file_name(), result.line_number(), result.summary());
Cody Northropb94529f2017-04-05 13:05:51 -060024639 }
24640
24641 // Called after a test ends.
Dave Houlton11dcd5e2017-04-25 16:00:10 -060024642 virtual void OnTestEnd(const ::testing::TestInfo &info) {
Cody Northropb94529f2017-04-05 13:05:51 -060024643 std::string result;
24644 if (info.result()->Passed()) {
24645 result.append("[ OK ]");
24646 } else {
24647 result.append("[ FAILED ]");
24648 }
24649 result.append(info.test_case_name()).append(".").append(info.name());
Dave Houlton11dcd5e2017-04-25 16:00:10 -060024650 if (info.result()->Failed()) addFullTestCommentIfPresent(info, result);
Cody Northropb94529f2017-04-05 13:05:51 -060024651
24652 if (::testing::GTEST_FLAG(print_time)) {
24653 std::ostringstream os;
24654 os << info.result()->elapsed_time();
24655 result.append(" (").append(os.str()).append(" ms)");
24656 }
24657
24658 __android_log_print(ANDROID_LOG_INFO, appTag, "%s", result.c_str());
24659 };
24660};
24661
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024662static int32_t processInput(struct android_app *app, AInputEvent *event) { return 0; }
Cody Northrop1242dfd2016-07-13 17:24:59 -060024663
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024664static void processCommand(struct android_app *app, int32_t cmd) {
24665 switch (cmd) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070024666 case APP_CMD_INIT_WINDOW: {
24667 if (app->window) {
24668 initialized = true;
24669 }
24670 break;
Cody Northrop1242dfd2016-07-13 17:24:59 -060024671 }
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070024672 case APP_CMD_GAINED_FOCUS: {
24673 active = true;
24674 break;
24675 }
24676 case APP_CMD_LOST_FOCUS: {
24677 active = false;
24678 break;
24679 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060024680 }
24681}
24682
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024683void android_main(struct android_app *app) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060024684 app_dummy();
24685
Cody Northrop1242dfd2016-07-13 17:24:59 -060024686 int vulkanSupport = InitVulkan();
24687 if (vulkanSupport == 0) {
24688 __android_log_print(ANDROID_LOG_INFO, appTag, "==== FAILED ==== No Vulkan support found");
24689 return;
24690 }
24691
24692 app->onAppCmd = processCommand;
24693 app->onInputEvent = processInput;
24694
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024695 while (1) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060024696 int events;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024697 struct android_poll_source *source;
24698 while (ALooper_pollAll(active ? 0 : -1, NULL, &events, (void **)&source) >= 0) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060024699 if (source) {
24700 source->process(app, source);
24701 }
24702
24703 if (app->destroyRequested != 0) {
24704 VkTestFramework::Finish();
24705 return;
24706 }
24707 }
24708
24709 if (initialized && active) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024710 // Use the following key to send arguments to gtest, i.e.
24711 // --es args "--gtest_filter=-VkLayerTest.foo"
24712 const char key[] = "args";
24713 std::vector<std::string> args = get_args(*app, key);
Cody Northrop1242dfd2016-07-13 17:24:59 -060024714
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024715 std::string filter = "";
24716 if (args.size() > 0) {
24717 __android_log_print(ANDROID_LOG_INFO, appTag, "Intent args = %s", args[0].c_str());
24718 filter += args[0];
24719 } else {
24720 __android_log_print(ANDROID_LOG_INFO, appTag, "No Intent args detected");
24721 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060024722
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024723 int argc = 2;
24724 char *argv[] = {(char *)"foo", (char *)filter.c_str()};
24725 __android_log_print(ANDROID_LOG_DEBUG, appTag, "filter = %s", argv[1]);
Cody Northrop1242dfd2016-07-13 17:24:59 -060024726
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024727 // Route output to files until we can override the gtest output
24728 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/out.txt", "w", stdout);
24729 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/err.txt", "w", stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060024730
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024731 ::testing::InitGoogleTest(&argc, argv);
Cody Northropb94529f2017-04-05 13:05:51 -060024732
Dave Houlton11dcd5e2017-04-25 16:00:10 -060024733 ::testing::TestEventListeners &listeners = ::testing::UnitTest::GetInstance()->listeners();
Cody Northropb94529f2017-04-05 13:05:51 -060024734 listeners.Append(new LogcatPrinter);
24735
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024736 VkTestFramework::InitArgs(&argc, argv);
24737 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Cody Northrop1242dfd2016-07-13 17:24:59 -060024738
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024739 int result = RUN_ALL_TESTS();
Cody Northrop1242dfd2016-07-13 17:24:59 -060024740
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024741 if (result != 0) {
24742 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests FAILED ====");
24743 } else {
24744 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests PASSED ====");
24745 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060024746
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024747 VkTestFramework::Finish();
Cody Northrop1242dfd2016-07-13 17:24:59 -060024748
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024749 fclose(stdout);
24750 fclose(stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060024751
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024752 ANativeActivity_finish(app->activity);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024753 return;
Cody Northrop1242dfd2016-07-13 17:24:59 -060024754 }
24755 }
24756}
24757#endif
24758
Tony Barbour300a6082015-04-07 13:44:53 -060024759int main(int argc, char **argv) {
24760 int result;
24761
Cody Northrop8e54a402016-03-08 22:25:52 -070024762#ifdef ANDROID
24763 int vulkanSupport = InitVulkan();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070024764 if (vulkanSupport == 0) return 1;
Cody Northrop8e54a402016-03-08 22:25:52 -070024765#endif
24766
Tony Barbour300a6082015-04-07 13:44:53 -060024767 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -060024768 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour300a6082015-04-07 13:44:53 -060024769
24770 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
24771
24772 result = RUN_ALL_TESTS();
24773
Tony Barbour6918cd52015-04-09 12:58:51 -060024774 VkTestFramework::Finish();
Tony Barbour300a6082015-04-07 13:44:53 -060024775 return result;
24776}