blob: 92e812f4f996c8c4533cd4607ff3497ba266c1bc [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
994TEST_F(VkLayerTest, UnrecognizedValue) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600995 TEST_DESCRIPTION("Specify unrecognized Vulkan enumeration, flags, and VkBool32 values");
Dustin Graves5d33d532016-05-09 16:21:12 -0600996
Tony Barbour1fa09702017-03-16 12:09:08 -0600997 ASSERT_NO_FATAL_FAILURE(Init());
Dustin Graves5d33d532016-05-09 16:21:12 -0600998
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700999 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1000 "does not fall within the begin..end "
1001 "range of the core VkFormat "
1002 "enumeration tokens");
Dustin Graves5d33d532016-05-09 16:21:12 -06001003 // Specify an invalid VkFormat value
1004 // Expected to trigger an error with
1005 // parameter_validation::validate_ranged_enum
1006 VkFormatProperties format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001007 vkGetPhysicalDeviceFormatProperties(gpu(), static_cast<VkFormat>(8000), &format_properties);
Dustin Graves5d33d532016-05-09 16:21:12 -06001008 m_errorMonitor->VerifyFound();
1009
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001010 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 -06001011 // Specify an invalid VkFlags bitmask value
1012 // Expected to trigger an error with parameter_validation::validate_flags
1013 VkImageFormatProperties image_format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001014 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
1015 static_cast<VkImageUsageFlags>(1 << 25), 0, &image_format_properties);
Dustin Graves5d33d532016-05-09 16:21:12 -06001016 m_errorMonitor->VerifyFound();
1017
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001018 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 -06001019 // Specify an invalid VkFlags array entry
1020 // Expected to trigger an error with
1021 // parameter_validation::validate_flags_array
1022 VkSemaphore semaphore = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001023 VkPipelineStageFlags stage_flags = static_cast<VkPipelineStageFlags>(1 << 25);
Dustin Graves5d33d532016-05-09 16:21:12 -06001024 VkSubmitInfo submit_info = {};
1025 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1026 submit_info.waitSemaphoreCount = 1;
1027 submit_info.pWaitSemaphores = &semaphore;
1028 submit_info.pWaitDstStageMask = &stage_flags;
1029 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
1030 m_errorMonitor->VerifyFound();
1031
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001032 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "is neither VK_TRUE nor VK_FALSE");
Dustin Graves5d33d532016-05-09 16:21:12 -06001033 // Specify an invalid VkBool32 value
1034 // Expected to trigger a warning with
1035 // parameter_validation::validate_bool32
1036 VkSampler sampler = VK_NULL_HANDLE;
1037 VkSamplerCreateInfo sampler_info = {};
1038 sampler_info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
1039 sampler_info.pNext = NULL;
1040 sampler_info.magFilter = VK_FILTER_NEAREST;
1041 sampler_info.minFilter = VK_FILTER_NEAREST;
1042 sampler_info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
1043 sampler_info.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1044 sampler_info.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1045 sampler_info.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1046 sampler_info.mipLodBias = 1.0;
1047 sampler_info.maxAnisotropy = 1;
1048 sampler_info.compareEnable = VK_FALSE;
1049 sampler_info.compareOp = VK_COMPARE_OP_NEVER;
1050 sampler_info.minLod = 1.0;
1051 sampler_info.maxLod = 1.0;
1052 sampler_info.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
1053 sampler_info.unnormalizedCoordinates = VK_FALSE;
1054 // Not VK_TRUE or VK_FALSE
1055 sampler_info.anisotropyEnable = 3;
1056 vkCreateSampler(m_device->device(), &sampler_info, NULL, &sampler);
1057 m_errorMonitor->VerifyFound();
1058}
Dustin Gravesfce74c02016-05-10 11:42:58 -06001059
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001060TEST_F(VkLayerTest, UpdateBufferAlignment) {
1061 TEST_DESCRIPTION("Check alignment parameters for vkCmdUpdateBuffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001062 uint32_t updateData[] = {1, 2, 3, 4, 5, 6, 7, 8};
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001063
Tony Barbour1fa09702017-03-16 12:09:08 -06001064 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001065
1066 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1067 vk_testing::Buffer buffer;
1068 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
1069
Tony Barbour552f6c02016-12-21 14:34:07 -07001070 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001071 // Introduce failure by using dstOffset that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001072 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001073 m_commandBuffer->UpdateBuffer(buffer.handle(), 1, 4, updateData);
1074 m_errorMonitor->VerifyFound();
1075
1076 // Introduce failure by using dataSize that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001077 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001078 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 6, updateData);
1079 m_errorMonitor->VerifyFound();
1080
1081 // Introduce failure by using dataSize that is < 0
1082 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001083 "must be greater than zero and less than or equal to 65536");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001084 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, -44, updateData);
1085 m_errorMonitor->VerifyFound();
1086
1087 // Introduce failure by using dataSize that is > 65536
1088 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001089 "must be greater than zero and less than or equal to 65536");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001090 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 80000, updateData);
1091 m_errorMonitor->VerifyFound();
1092
Tony Barbour552f6c02016-12-21 14:34:07 -07001093 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001094}
1095
1096TEST_F(VkLayerTest, FillBufferAlignment) {
1097 TEST_DESCRIPTION("Check alignment parameters for vkCmdFillBuffer");
1098
Tony Barbour1fa09702017-03-16 12:09:08 -06001099 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001100
1101 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1102 vk_testing::Buffer buffer;
1103 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
1104
Tony Barbour552f6c02016-12-21 14:34:07 -07001105 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001106
1107 // Introduce failure by using dstOffset that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001108 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001109 m_commandBuffer->FillBuffer(buffer.handle(), 1, 4, 0x11111111);
1110 m_errorMonitor->VerifyFound();
1111
1112 // Introduce failure by using size that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001113 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001114 m_commandBuffer->FillBuffer(buffer.handle(), 0, 6, 0x11111111);
1115 m_errorMonitor->VerifyFound();
1116
1117 // Introduce failure by using size that is zero
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001118 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must be greater than zero");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001119 m_commandBuffer->FillBuffer(buffer.handle(), 0, 0, 0x11111111);
1120 m_errorMonitor->VerifyFound();
1121
Tony Barbour552f6c02016-12-21 14:34:07 -07001122 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001123}
Dustin Graves40f35822016-06-23 11:12:53 -06001124
Cortd889ff92016-07-27 09:51:27 -07001125TEST_F(VkLayerTest, PSOPolygonModeInvalid) {
1126 VkResult err;
1127
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001128 TEST_DESCRIPTION(
1129 "Attempt to use a non-solid polygon fill mode in a "
1130 "pipeline when this feature is not enabled.");
Cortd889ff92016-07-27 09:51:27 -07001131
Tony Barbour1fa09702017-03-16 12:09:08 -06001132 ASSERT_NO_FATAL_FAILURE(Init());
Cortd889ff92016-07-27 09:51:27 -07001133 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1134
1135 std::vector<const char *> device_extension_names;
1136 auto features = m_device->phy().features();
1137 // Artificially disable support for non-solid fill modes
1138 features.fillModeNonSolid = false;
1139 // The sacrificial device object
1140 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
1141
1142 VkRenderpassObj render_pass(&test_device);
1143
1144 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1145 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1146 pipeline_layout_ci.setLayoutCount = 0;
1147 pipeline_layout_ci.pSetLayouts = NULL;
1148
1149 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001150 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Cortd889ff92016-07-27 09:51:27 -07001151 ASSERT_VK_SUCCESS(err);
1152
1153 VkPipelineRasterizationStateCreateInfo rs_ci = {};
1154 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
1155 rs_ci.pNext = nullptr;
1156 rs_ci.lineWidth = 1.0f;
1157 rs_ci.rasterizerDiscardEnable = true;
1158
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001159 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
1160 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Cortd889ff92016-07-27 09:51:27 -07001161
Mark Lobodzinski5e644732016-08-15 16:51:19 -06001162 // Set polygonMode to unsupported value POINT, should fail
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001163 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1164 "polygonMode cannot be VK_POLYGON_MODE_POINT or VK_POLYGON_MODE_LINE");
Cortd889ff92016-07-27 09:51:27 -07001165 {
1166 VkPipelineObj pipe(&test_device);
1167 pipe.AddShader(&vs);
1168 pipe.AddShader(&fs);
1169 pipe.AddColorAttachment();
1170 // Introduce failure by setting unsupported polygon mode
1171 rs_ci.polygonMode = VK_POLYGON_MODE_POINT;
1172 pipe.SetRasterization(&rs_ci);
1173 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
1174 }
1175 m_errorMonitor->VerifyFound();
1176
1177 // Try again with polygonMode=LINE, should fail
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001178 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1179 "polygonMode cannot be VK_POLYGON_MODE_POINT or VK_POLYGON_MODE_LINE");
Cortd889ff92016-07-27 09:51:27 -07001180 {
1181 VkPipelineObj pipe(&test_device);
1182 pipe.AddShader(&vs);
1183 pipe.AddShader(&fs);
1184 pipe.AddColorAttachment();
1185 // Introduce failure by setting unsupported polygon mode
1186 rs_ci.polygonMode = VK_POLYGON_MODE_LINE;
1187 pipe.SetRasterization(&rs_ci);
1188 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
1189 }
1190 m_errorMonitor->VerifyFound();
1191
Cortd889ff92016-07-27 09:51:27 -07001192 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
1193}
1194
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001195#if 0
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001196TEST_F(VkLayerTest, CallResetCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001197{
1198 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001199 VkFenceCreateInfo fenceInfo = {};
1200 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1201 fenceInfo.pNext = NULL;
1202 fenceInfo.flags = 0;
1203
Mike Weiblencce7ec72016-10-17 19:33:05 -06001204 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Resetting command buffer");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001205
Tony Barbour1fa09702017-03-16 12:09:08 -06001206 ASSERT_NO_FATAL_FAILURE(Init());
Tony Barbourc1eb1a52015-07-20 13:00:10 -06001207
1208 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1209 vk_testing::Buffer buffer;
1210 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001211
Tony Barbourfe3351b2015-07-28 10:17:20 -06001212 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001213 m_commandBuffer->FillBuffer(buffer.handle(), 0, 4, 0x11111111);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001214 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001215
1216 testFence.init(*m_device, fenceInfo);
1217
1218 // Bypass framework since it does the waits automatically
1219 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001220 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001221 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1222 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001223 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001224 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001225 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001226 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001227 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001228 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001229 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001230
1231 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001232 ASSERT_VK_SUCCESS( err );
1233
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001234 // Introduce failure by calling begin again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001235 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001236
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001237 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001238}
1239
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001240TEST_F(VkLayerTest, CallBeginCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001241{
1242 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001243 VkFenceCreateInfo fenceInfo = {};
1244 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1245 fenceInfo.pNext = NULL;
1246 fenceInfo.flags = 0;
1247
Mike Weiblencce7ec72016-10-17 19:33:05 -06001248 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Calling vkBeginCommandBuffer() on active command buffer");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001249
Tony Barbour1fa09702017-03-16 12:09:08 -06001250 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001251 ASSERT_NO_FATAL_FAILURE(InitViewport());
1252 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1253
Tony Barbourfe3351b2015-07-28 10:17:20 -06001254 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001255 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001256 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001257
1258 testFence.init(*m_device, fenceInfo);
1259
1260 // Bypass framework since it does the waits automatically
1261 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001262 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001263 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1264 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001265 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001266 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001267 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001268 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001269 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001270 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001271 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001272
1273 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001274 ASSERT_VK_SUCCESS( err );
1275
Jon Ashburnf19916e2016-01-11 13:12:43 -07001276 VkCommandBufferInheritanceInfo hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001277 VkCommandBufferBeginInfo info = {};
1278 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
1279 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001280 info.renderPass = VK_NULL_HANDLE;
1281 info.subpass = 0;
1282 info.framebuffer = VK_NULL_HANDLE;
Chia-I Wub8d47ae2015-11-11 10:18:12 +08001283 info.occlusionQueryEnable = VK_FALSE;
1284 info.queryFlags = 0;
1285 info.pipelineStatistics = 0;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001286
1287 // Introduce failure by calling BCB again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001288 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001289
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001290 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001291}
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001292#endif
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001293
Mark Lobodzinski833bb552016-12-15 07:41:13 -07001294TEST_F(VkLayerTest, SparseBindingImageBufferCreate) {
1295 TEST_DESCRIPTION("Create buffer/image with sparse attributes but without the sparse_binding bit set");
1296
Tony Barbour1fa09702017-03-16 12:09:08 -06001297 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski833bb552016-12-15 07:41:13 -07001298
1299 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00669);
1300 VkBuffer buffer;
1301 VkBufferCreateInfo buf_info = {};
1302 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1303 buf_info.pNext = NULL;
1304 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
1305 buf_info.size = 2048;
1306 buf_info.queueFamilyIndexCount = 0;
1307 buf_info.pQueueFamilyIndices = NULL;
1308 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1309 buf_info.flags = VK_BUFFER_CREATE_SPARSE_RESIDENCY_BIT;
1310 vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1311 m_errorMonitor->VerifyFound();
1312
1313 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02160);
1314 VkImage image;
1315 VkImageCreateInfo image_create_info = {};
1316 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1317 image_create_info.pNext = NULL;
1318 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1319 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1320 image_create_info.extent.width = 512;
1321 image_create_info.extent.height = 64;
1322 image_create_info.extent.depth = 1;
1323 image_create_info.mipLevels = 1;
1324 image_create_info.arrayLayers = 1;
1325 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1326 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
1327 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1328 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1329 image_create_info.queueFamilyIndexCount = 0;
1330 image_create_info.pQueueFamilyIndices = NULL;
1331 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1332 image_create_info.flags = VK_BUFFER_CREATE_SPARSE_ALIASED_BIT;
1333 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1334 m_errorMonitor->VerifyFound();
1335}
1336
Dave Houlton829c0d82017-01-24 15:09:17 -07001337TEST_F(VkLayerTest, SparseResidencyImageCreateUnsupportedTypes) {
1338 TEST_DESCRIPTION("Create images with sparse residency with unsupported types");
1339
1340 // Determine which device feature are available
Dave Houlton0ba0fdf2017-03-29 12:05:26 -06001341 VkPhysicalDeviceFeatures device_features = {};
Dave Houlton8e0fe7a2017-03-30 10:32:10 -06001342 ASSERT_NO_FATAL_FAILURE(
1343 InitFramework(instance_layer_names, instance_extension_names, device_extension_names, myDbgFunc, m_errorMonitor));
Dave Houlton0ba0fdf2017-03-29 12:05:26 -06001344 ASSERT_NO_FATAL_FAILURE(GetPhysicalDeviceFeatures(&device_features));
Dave Houlton829c0d82017-01-24 15:09:17 -07001345
Dave Houlton8e0fe7a2017-03-30 10:32:10 -06001346 // Mask out device features we don't want and initialize device state
Dave Houlton0ba0fdf2017-03-29 12:05:26 -06001347 device_features.sparseResidencyImage2D = VK_FALSE;
1348 device_features.sparseResidencyImage3D = VK_FALSE;
Dave Houlton8e0fe7a2017-03-30 10:32:10 -06001349 ASSERT_NO_FATAL_FAILURE(InitState(&device_features));
Dave Houlton829c0d82017-01-24 15:09:17 -07001350
1351 VkImage image = VK_NULL_HANDLE;
1352 VkResult result = VK_RESULT_MAX_ENUM;
1353 VkImageCreateInfo image_create_info = {};
1354 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1355 image_create_info.pNext = NULL;
1356 image_create_info.imageType = VK_IMAGE_TYPE_1D;
1357 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1358 image_create_info.extent.width = 512;
1359 image_create_info.extent.height = 1;
1360 image_create_info.extent.depth = 1;
1361 image_create_info.mipLevels = 1;
1362 image_create_info.arrayLayers = 1;
1363 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1364 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
1365 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1366 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1367 image_create_info.queueFamilyIndexCount = 0;
1368 image_create_info.pQueueFamilyIndices = NULL;
1369 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1370 image_create_info.flags = VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT | VK_BUFFER_CREATE_SPARSE_BINDING_BIT;
1371
1372 // 1D image w/ sparse residency is an error
1373 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02352);
1374 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1375 m_errorMonitor->VerifyFound();
1376 if (VK_SUCCESS == result) {
1377 vkDestroyImage(m_device->device(), image, NULL);
1378 image = VK_NULL_HANDLE;
1379 }
1380
1381 // 2D image w/ sparse residency when feature isn't available
1382 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1383 image_create_info.extent.height = 64;
1384 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02144);
1385 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1386 m_errorMonitor->VerifyFound();
1387 if (VK_SUCCESS == result) {
1388 vkDestroyImage(m_device->device(), image, NULL);
1389 image = VK_NULL_HANDLE;
1390 }
1391
1392 // 3D image w/ sparse residency when feature isn't available
1393 image_create_info.imageType = VK_IMAGE_TYPE_3D;
1394 image_create_info.extent.depth = 8;
1395 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02145);
1396 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1397 m_errorMonitor->VerifyFound();
1398 if (VK_SUCCESS == result) {
1399 vkDestroyImage(m_device->device(), image, NULL);
1400 image = VK_NULL_HANDLE;
1401 }
1402}
1403
1404TEST_F(VkLayerTest, SparseResidencyImageCreateUnsupportedSamples) {
1405 TEST_DESCRIPTION("Create images with sparse residency with unsupported tiling or sample counts");
1406
1407 // Determine which device feature are available
Dave Houlton0ba0fdf2017-03-29 12:05:26 -06001408 VkPhysicalDeviceFeatures device_features = {};
Dave Houlton8e0fe7a2017-03-30 10:32:10 -06001409 ASSERT_NO_FATAL_FAILURE(
1410 InitFramework(instance_layer_names, instance_extension_names, device_extension_names, myDbgFunc, m_errorMonitor));
Dave Houlton0ba0fdf2017-03-29 12:05:26 -06001411 ASSERT_NO_FATAL_FAILURE(GetPhysicalDeviceFeatures(&device_features));
Dave Houlton829c0d82017-01-24 15:09:17 -07001412
Dave Houlton0ba0fdf2017-03-29 12:05:26 -06001413 // These tests require that the device support sparse residency for 2D images
1414 if (VK_TRUE != device_features.sparseResidencyImage2D) {
1415 printf(" Test requires unsupported SparseResidencyImage2D feature. Skipped.\n");
Dave Houlton829c0d82017-01-24 15:09:17 -07001416 return;
1417 }
1418
Dave Houlton8e0fe7a2017-03-30 10:32:10 -06001419 // Mask out device features we don't want and initialize device state
Dave Houlton0ba0fdf2017-03-29 12:05:26 -06001420 device_features.sparseResidency2Samples = VK_FALSE;
1421 device_features.sparseResidency4Samples = VK_FALSE;
1422 device_features.sparseResidency8Samples = VK_FALSE;
1423 device_features.sparseResidency16Samples = VK_FALSE;
Dave Houlton8e0fe7a2017-03-30 10:32:10 -06001424 ASSERT_NO_FATAL_FAILURE(InitState(&device_features));
Dave Houlton829c0d82017-01-24 15:09:17 -07001425
1426 VkImage image = VK_NULL_HANDLE;
1427 VkResult result = VK_RESULT_MAX_ENUM;
1428 VkImageCreateInfo image_create_info = {};
1429 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1430 image_create_info.pNext = NULL;
1431 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1432 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1433 image_create_info.extent.width = 64;
1434 image_create_info.extent.height = 64;
1435 image_create_info.extent.depth = 1;
1436 image_create_info.mipLevels = 1;
1437 image_create_info.arrayLayers = 1;
1438 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1439 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1440 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1441 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1442 image_create_info.queueFamilyIndexCount = 0;
1443 image_create_info.pQueueFamilyIndices = NULL;
1444 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1445 image_create_info.flags = VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT | VK_BUFFER_CREATE_SPARSE_BINDING_BIT;
1446
1447 // 2D image w/ sparse residency and linear tiling is an error
1448 m_errorMonitor->SetDesiredFailureMsg(
1449 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1450 "VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT then image tiling of VK_IMAGE_TILING_LINEAR is not supported");
1451 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1452 m_errorMonitor->VerifyFound();
1453 if (VK_SUCCESS == result) {
1454 vkDestroyImage(m_device->device(), image, NULL);
1455 image = VK_NULL_HANDLE;
1456 }
1457 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
1458
1459 // Multi-sample image w/ sparse residency when feature isn't available (4 flavors)
1460 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
1461 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02146);
1462 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1463 m_errorMonitor->VerifyFound();
1464 if (VK_SUCCESS == result) {
1465 vkDestroyImage(m_device->device(), image, NULL);
1466 image = VK_NULL_HANDLE;
1467 }
1468
1469 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
1470 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02147);
1471 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1472 m_errorMonitor->VerifyFound();
1473 if (VK_SUCCESS == result) {
1474 vkDestroyImage(m_device->device(), image, NULL);
1475 image = VK_NULL_HANDLE;
1476 }
1477
1478 image_create_info.samples = VK_SAMPLE_COUNT_8_BIT;
1479 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02148);
1480 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1481 m_errorMonitor->VerifyFound();
1482 if (VK_SUCCESS == result) {
1483 vkDestroyImage(m_device->device(), image, NULL);
1484 image = VK_NULL_HANDLE;
1485 }
1486
1487 image_create_info.samples = VK_SAMPLE_COUNT_16_BIT;
1488 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02149);
1489 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1490 m_errorMonitor->VerifyFound();
1491 if (VK_SUCCESS == result) {
1492 vkDestroyImage(m_device->device(), image, NULL);
1493 image = VK_NULL_HANDLE;
1494 }
1495}
1496
Tobin Ehlisf11be982016-05-11 13:52:53 -06001497TEST_F(VkLayerTest, InvalidMemoryAliasing) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001498 TEST_DESCRIPTION(
1499 "Create a buffer and image, allocate memory, and bind the "
1500 "buffer and image to memory such that they will alias.");
Tobin Ehlisf11be982016-05-11 13:52:53 -06001501 VkResult err;
1502 bool pass;
Tony Barbour1fa09702017-03-16 12:09:08 -06001503 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisf11be982016-05-11 13:52:53 -06001504
Tobin Ehlis077ded32016-05-12 17:39:13 -06001505 VkBuffer buffer, buffer2;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001506 VkImage image;
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001507 VkImage image2;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001508 VkDeviceMemory mem; // buffer will be bound first
1509 VkDeviceMemory mem_img; // image bound first
Tobin Ehlis077ded32016-05-12 17:39:13 -06001510 VkMemoryRequirements buff_mem_reqs, img_mem_reqs;
Rene Lindsayd14f5572016-12-16 14:57:18 -07001511 VkMemoryRequirements buff_mem_reqs2, img_mem_reqs2;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001512
1513 VkBufferCreateInfo buf_info = {};
1514 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1515 buf_info.pNext = NULL;
1516 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1517 buf_info.size = 256;
1518 buf_info.queueFamilyIndexCount = 0;
1519 buf_info.pQueueFamilyIndices = NULL;
1520 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1521 buf_info.flags = 0;
1522 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1523 ASSERT_VK_SUCCESS(err);
1524
Tobin Ehlis077ded32016-05-12 17:39:13 -06001525 vkGetBufferMemoryRequirements(m_device->device(), buffer, &buff_mem_reqs);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001526
1527 VkImageCreateInfo image_create_info = {};
1528 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1529 image_create_info.pNext = NULL;
1530 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1531 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1532 image_create_info.extent.width = 64;
1533 image_create_info.extent.height = 64;
1534 image_create_info.extent.depth = 1;
1535 image_create_info.mipLevels = 1;
1536 image_create_info.arrayLayers = 1;
1537 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis12a4b5e2016-08-08 12:33:11 -06001538 // Image tiling must be optimal to trigger error when aliasing linear buffer
1539 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001540 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1541 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1542 image_create_info.queueFamilyIndexCount = 0;
1543 image_create_info.pQueueFamilyIndices = NULL;
1544 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1545 image_create_info.flags = 0;
1546
Tobin Ehlisf11be982016-05-11 13:52:53 -06001547 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1548 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001549 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
1550 ASSERT_VK_SUCCESS(err);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001551
Tobin Ehlis077ded32016-05-12 17:39:13 -06001552 vkGetImageMemoryRequirements(m_device->device(), image, &img_mem_reqs);
1553
1554 VkMemoryAllocateInfo alloc_info = {};
1555 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1556 alloc_info.pNext = NULL;
1557 alloc_info.memoryTypeIndex = 0;
1558 // Ensure memory is big enough for both bindings
1559 alloc_info.allocationSize = buff_mem_reqs.size + img_mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001560 pass = m_device->phy().set_memory_type(buff_mem_reqs.memoryTypeBits & img_mem_reqs.memoryTypeBits, &alloc_info,
1561 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001562 if (!pass) {
Tobin Ehlis077ded32016-05-12 17:39:13 -06001563 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001564 vkDestroyImage(m_device->device(), image, NULL);
Mark Lobodzinskid2d2d4c2017-02-16 11:51:58 -07001565 vkDestroyImage(m_device->device(), image2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001566 return;
1567 }
Tobin Ehlis077ded32016-05-12 17:39:13 -06001568 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1569 ASSERT_VK_SUCCESS(err);
1570 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
1571 ASSERT_VK_SUCCESS(err);
1572
Rene Lindsayd14f5572016-12-16 14:57:18 -07001573 vkGetImageMemoryRequirements(m_device->device(), image2, &img_mem_reqs2);
1574
Tobin Ehlis32b2bbc2016-12-13 17:33:41 -07001575 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " is aliased with linear buffer 0x");
Tobin Ehlis077ded32016-05-12 17:39:13 -06001576 // VALIDATION FAILURE due to image mapping overlapping buffer mapping
Tobin Ehlisf11be982016-05-11 13:52:53 -06001577 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1578 m_errorMonitor->VerifyFound();
1579
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001580 // Now correctly bind image2 to second mem allocation before incorrectly
Tobin Ehlis077ded32016-05-12 17:39:13 -06001581 // aliasing buffer2
1582 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer2);
1583 ASSERT_VK_SUCCESS(err);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001584 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem_img);
1585 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001586 err = vkBindImageMemory(m_device->device(), image2, mem_img, 0);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001587 ASSERT_VK_SUCCESS(err);
Tobin Ehlis32b2bbc2016-12-13 17:33:41 -07001588 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "is aliased with non-linear image 0x");
Rene Lindsayd14f5572016-12-16 14:57:18 -07001589 vkGetBufferMemoryRequirements(m_device->device(), buffer2, &buff_mem_reqs2);
Tobin Ehlis077ded32016-05-12 17:39:13 -06001590 err = vkBindBufferMemory(m_device->device(), buffer2, mem_img, 0);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001591 m_errorMonitor->VerifyFound();
1592
1593 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlis077ded32016-05-12 17:39:13 -06001594 vkDestroyBuffer(m_device->device(), buffer2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001595 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001596 vkDestroyImage(m_device->device(), image2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001597 vkFreeMemory(m_device->device(), mem, NULL);
1598 vkFreeMemory(m_device->device(), mem_img, NULL);
1599}
1600
Tobin Ehlis35372522016-05-12 08:32:31 -06001601TEST_F(VkLayerTest, InvalidMemoryMapping) {
1602 TEST_DESCRIPTION("Attempt to map memory in a number of incorrect ways");
1603 VkResult err;
1604 bool pass;
Tony Barbour1fa09702017-03-16 12:09:08 -06001605 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis35372522016-05-12 08:32:31 -06001606
1607 VkBuffer buffer;
1608 VkDeviceMemory mem;
1609 VkMemoryRequirements mem_reqs;
1610
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001611 const VkDeviceSize atom_size = m_device->props.limits.nonCoherentAtomSize;
1612
Tobin Ehlis35372522016-05-12 08:32:31 -06001613 VkBufferCreateInfo buf_info = {};
1614 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1615 buf_info.pNext = NULL;
1616 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1617 buf_info.size = 256;
1618 buf_info.queueFamilyIndexCount = 0;
1619 buf_info.pQueueFamilyIndices = NULL;
1620 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1621 buf_info.flags = 0;
1622 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1623 ASSERT_VK_SUCCESS(err);
1624
1625 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
1626 VkMemoryAllocateInfo alloc_info = {};
1627 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1628 alloc_info.pNext = NULL;
1629 alloc_info.memoryTypeIndex = 0;
1630
1631 // Ensure memory is big enough for both bindings
1632 static const VkDeviceSize allocation_size = 0x10000;
1633 alloc_info.allocationSize = allocation_size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001634 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 -06001635 if (!pass) {
1636 vkDestroyBuffer(m_device->device(), buffer, NULL);
1637 return;
1638 }
1639 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1640 ASSERT_VK_SUCCESS(err);
1641
1642 uint8_t *pData;
1643 // Attempt to map memory size 0 is invalid
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001644 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 -06001645 err = vkMapMemory(m_device->device(), mem, 0, 0, 0, (void **)&pData);
1646 m_errorMonitor->VerifyFound();
1647 // Map memory twice
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001648 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001649 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001650 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1651 "VkMapMemory: Attempting to map memory on an already-mapped object ");
1652 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001653 m_errorMonitor->VerifyFound();
1654
1655 // Unmap the memory to avoid re-map error
1656 vkUnmapMemory(m_device->device(), mem);
1657 // overstep allocation with VK_WHOLE_SIZE
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001658 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1659 " with size of VK_WHOLE_SIZE oversteps total array size 0x");
1660 err = vkMapMemory(m_device->device(), mem, allocation_size + 1, VK_WHOLE_SIZE, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001661 m_errorMonitor->VerifyFound();
1662 // overstep allocation w/o VK_WHOLE_SIZE
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001663 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " oversteps total array size 0x");
1664 err = vkMapMemory(m_device->device(), mem, 1, allocation_size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001665 m_errorMonitor->VerifyFound();
1666 // Now error due to unmapping memory that's not mapped
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001667 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Unmapping Memory without memory being mapped: ");
Tobin Ehlis35372522016-05-12 08:32:31 -06001668 vkUnmapMemory(m_device->device(), mem);
1669 m_errorMonitor->VerifyFound();
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001670
Tobin Ehlis35372522016-05-12 08:32:31 -06001671 // Now map memory and cause errors due to flushing invalid ranges
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001672 err = vkMapMemory(m_device->device(), mem, 4 * atom_size, VK_WHOLE_SIZE, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001673 ASSERT_VK_SUCCESS(err);
1674 VkMappedMemoryRange mmr = {};
Chris Forbes3aec0892016-06-13 10:29:26 +12001675 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
Tobin Ehlis35372522016-05-12 08:32:31 -06001676 mmr.memory = mem;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001677 mmr.offset = atom_size; // Error b/c offset less than offset of mapped mem
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001678 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00642);
Tobin Ehlis35372522016-05-12 08:32:31 -06001679 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1680 m_errorMonitor->VerifyFound();
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001681
Tobin Ehlis35372522016-05-12 08:32:31 -06001682 // Now flush range that oversteps mapped range
1683 vkUnmapMemory(m_device->device(), mem);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001684 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001685 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001686 mmr.offset = atom_size;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001687 mmr.size = 4 * atom_size; // Flushing bounds exceed mapped bounds
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001688 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00642);
1689 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1690 m_errorMonitor->VerifyFound();
1691
1692 // Now flush range with VK_WHOLE_SIZE that oversteps offset
1693 vkUnmapMemory(m_device->device(), mem);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001694 err = vkMapMemory(m_device->device(), mem, 2 * atom_size, 4 * atom_size, 0, (void **)&pData);
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001695 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001696 mmr.offset = atom_size;
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001697 mmr.size = VK_WHOLE_SIZE;
1698 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00643);
Tobin Ehlis35372522016-05-12 08:32:31 -06001699 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1700 m_errorMonitor->VerifyFound();
1701
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001702#if 0 // Planning discussion with working group on this validation check.
Mark Lobodzinski3826a4f2016-11-15 09:38:51 -07001703 // Some platforms have an atomsize of 1 which makes the test meaningless
1704 if (atom_size > 3) {
1705 // Now with an offset NOT a multiple of the device limit
1706 vkUnmapMemory(m_device->device(), mem);
1707 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
1708 ASSERT_VK_SUCCESS(err);
1709 mmr.offset = 3; // Not a multiple of atom_size
1710 mmr.size = VK_WHOLE_SIZE;
1711 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00644);
1712 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1713 m_errorMonitor->VerifyFound();
1714
1715 // Now with a size NOT a multiple of the device limit
1716 vkUnmapMemory(m_device->device(), mem);
1717 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
1718 ASSERT_VK_SUCCESS(err);
1719 mmr.offset = atom_size;
1720 mmr.size = 2 * atom_size + 1; // Not a multiple of atom_size
1721 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00645);
1722 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1723 m_errorMonitor->VerifyFound();
1724 }
Tony Barboure3975eb2016-12-15 14:52:44 -07001725#endif
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001726 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
1727 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Tobin Ehlis35372522016-05-12 08:32:31 -06001728 if (!pass) {
1729 vkFreeMemory(m_device->device(), mem, NULL);
1730 vkDestroyBuffer(m_device->device(), buffer, NULL);
1731 return;
1732 }
1733 // TODO : If we can get HOST_VISIBLE w/o HOST_COHERENT we can test cases of
1734 // MEMTRACK_INVALID_MAP in validateAndCopyNoncoherentMemoryToDriver()
1735
1736 vkDestroyBuffer(m_device->device(), buffer, NULL);
1737 vkFreeMemory(m_device->device(), mem, NULL);
1738}
1739
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001740#if 0 // disabled until PV gets real extension enable checks
Ian Elliott1c32c772016-04-28 14:47:13 -06001741TEST_F(VkLayerTest, EnableWsiBeforeUse) {
1742 VkResult err;
1743 bool pass;
1744
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001745 // FIXME: After we turn on this code for non-Linux platforms, uncomment the
1746 // following declaration (which is temporarily being moved below):
1747 // VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott1c32c772016-04-28 14:47:13 -06001748 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001749 VkSwapchainCreateInfoKHR swapchain_create_info = {VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR};
Ian Elliott1c32c772016-04-28 14:47:13 -06001750 uint32_t swapchain_image_count = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001751 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
Ian Elliott1c32c772016-04-28 14:47:13 -06001752 uint32_t image_index = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001753 // VkPresentInfoKHR present_info = {};
Ian Elliott1c32c772016-04-28 14:47:13 -06001754
Tony Barbour1fa09702017-03-16 12:09:08 -06001755 ASSERT_NO_FATAL_FAILURE(Init());
Ian Elliott1c32c772016-04-28 14:47:13 -06001756
Ian Elliott3f06ce52016-04-29 14:46:21 -06001757#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
1758#if defined(VK_USE_PLATFORM_ANDROID_KHR)
1759 // Use the functions from the VK_KHR_android_surface extension without
1760 // enabling that extension:
1761
1762 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001763 VkAndroidSurfaceCreateInfoKHR android_create_info = {VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001764 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1765 err = vkCreateAndroidSurfaceKHR(instance(), &android_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001766 pass = (err != VK_SUCCESS);
1767 ASSERT_TRUE(pass);
1768 m_errorMonitor->VerifyFound();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001769#endif // VK_USE_PLATFORM_ANDROID_KHR
Ian Elliott3f06ce52016-04-29 14:46:21 -06001770
Ian Elliott3f06ce52016-04-29 14:46:21 -06001771#if defined(VK_USE_PLATFORM_MIR_KHR)
1772 // Use the functions from the VK_KHR_mir_surface extension without enabling
1773 // that extension:
1774
1775 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001776 VkMirSurfaceCreateInfoKHR mir_create_info = {VK_STRUCTURE_TYPE_MIR_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001777 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott3f06ce52016-04-29 14:46:21 -06001778 err = vkCreateMirSurfaceKHR(instance(), &mir_create_info, NULL, &surface);
1779 pass = (err != VK_SUCCESS);
1780 ASSERT_TRUE(pass);
1781 m_errorMonitor->VerifyFound();
1782
1783 // Tell whether an mir_connection supports presentation:
1784 MirConnection *mir_connection = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001785 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1786 vkGetPhysicalDeviceMirPresentationSupportKHR(gpu(), 0, mir_connection, visual_id);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001787 m_errorMonitor->VerifyFound();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001788#endif // VK_USE_PLATFORM_MIR_KHR
Ian Elliott3f06ce52016-04-29 14:46:21 -06001789
Ian Elliott3f06ce52016-04-29 14:46:21 -06001790#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
1791 // Use the functions from the VK_KHR_wayland_surface extension without
1792 // enabling that extension:
1793
1794 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001795 VkWaylandSurfaceCreateInfoKHR wayland_create_info = {VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001796 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1797 err = vkCreateWaylandSurfaceKHR(instance(), &wayland_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001798 pass = (err != VK_SUCCESS);
1799 ASSERT_TRUE(pass);
1800 m_errorMonitor->VerifyFound();
1801
1802 // Tell whether an wayland_display supports presentation:
1803 struct wl_display wayland_display = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001804 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1805 vkGetPhysicalDeviceWaylandPresentationSupportKHR(gpu(), 0, &wayland_display);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001806 m_errorMonitor->VerifyFound();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001807#endif // VK_USE_PLATFORM_WAYLAND_KHR
1808#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott3f06ce52016-04-29 14:46:21 -06001809
Ian Elliott3f06ce52016-04-29 14:46:21 -06001810#if defined(VK_USE_PLATFORM_WIN32_KHR)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001811 // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1812 // TO NON-LINUX PLATFORMS:
1813 VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott3f06ce52016-04-29 14:46:21 -06001814 // Use the functions from the VK_KHR_win32_surface extension without
1815 // enabling that extension:
1816
1817 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001818 VkWin32SurfaceCreateInfoKHR win32_create_info = {VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001819 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1820 err = vkCreateWin32SurfaceKHR(instance(), &win32_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001821 pass = (err != VK_SUCCESS);
1822 ASSERT_TRUE(pass);
1823 m_errorMonitor->VerifyFound();
1824
1825 // Tell whether win32 supports presentation:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001826 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott489eec02016-05-05 14:12:44 -06001827 vkGetPhysicalDeviceWin32PresentationSupportKHR(gpu(), 0);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001828 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001829// Set this (for now, until all platforms are supported and tested):
1830#define NEED_TO_TEST_THIS_ON_PLATFORM
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001831#endif // VK_USE_PLATFORM_WIN32_KHR
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07001832#if defined(VK_USE_PLATFORM_XCB_KHR) || defined(VK_USE_PLATFORM_XLIB_KHR)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001833 // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1834 // TO NON-LINUX PLATFORMS:
1835 VkSurfaceKHR surface = VK_NULL_HANDLE;
Tony Barbour2e7bd402016-11-14 14:46:33 -07001836#endif
1837#if defined(VK_USE_PLATFORM_XCB_KHR)
Ian Elliott1c32c772016-04-28 14:47:13 -06001838 // Use the functions from the VK_KHR_xcb_surface extension without enabling
1839 // that extension:
1840
1841 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001842 VkXcbSurfaceCreateInfoKHR xcb_create_info = {VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001843 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001844 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
1845 pass = (err != VK_SUCCESS);
1846 ASSERT_TRUE(pass);
1847 m_errorMonitor->VerifyFound();
1848
1849 // Tell whether an xcb_visualid_t supports presentation:
Ian Elliott3f06ce52016-04-29 14:46:21 -06001850 xcb_connection_t *xcb_connection = NULL;
Ian Elliott1c32c772016-04-28 14:47:13 -06001851 xcb_visualid_t visual_id = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001852 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1853 vkGetPhysicalDeviceXcbPresentationSupportKHR(gpu(), 0, xcb_connection, visual_id);
Ian Elliott1c32c772016-04-28 14:47:13 -06001854 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001855// Set this (for now, until all platforms are supported and tested):
1856#define NEED_TO_TEST_THIS_ON_PLATFORM
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001857#endif // VK_USE_PLATFORM_XCB_KHR
Ian Elliott1c32c772016-04-28 14:47:13 -06001858
Ian Elliott12630812016-04-29 14:35:43 -06001859#if defined(VK_USE_PLATFORM_XLIB_KHR)
1860 // Use the functions from the VK_KHR_xlib_surface extension without enabling
1861 // that extension:
1862
1863 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001864 VkXlibSurfaceCreateInfoKHR xlib_create_info = {VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001865 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06001866 err = vkCreateXlibSurfaceKHR(instance(), &xlib_create_info, NULL, &surface);
1867 pass = (err != VK_SUCCESS);
1868 ASSERT_TRUE(pass);
1869 m_errorMonitor->VerifyFound();
1870
1871 // Tell whether an Xlib VisualID supports presentation:
1872 Display *dpy = NULL;
1873 VisualID visual = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001874 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06001875 vkGetPhysicalDeviceXlibPresentationSupportKHR(gpu(), 0, dpy, visual);
1876 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001877// Set this (for now, until all platforms are supported and tested):
1878#define NEED_TO_TEST_THIS_ON_PLATFORM
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001879#endif // VK_USE_PLATFORM_XLIB_KHR
Ian Elliott12630812016-04-29 14:35:43 -06001880
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001881// Use the functions from the VK_KHR_surface extension without enabling
1882// that extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06001883
Ian Elliott489eec02016-05-05 14:12:44 -06001884#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001885 // Destroy a surface:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001886 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001887 vkDestroySurfaceKHR(instance(), surface, NULL);
1888 m_errorMonitor->VerifyFound();
1889
1890 // Check if surface supports presentation:
1891 VkBool32 supported = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001892 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001893 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
1894 pass = (err != VK_SUCCESS);
1895 ASSERT_TRUE(pass);
1896 m_errorMonitor->VerifyFound();
1897
1898 // Check surface capabilities:
1899 VkSurfaceCapabilitiesKHR capabilities = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001900 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1901 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &capabilities);
Ian Elliott1c32c772016-04-28 14:47:13 -06001902 pass = (err != VK_SUCCESS);
1903 ASSERT_TRUE(pass);
1904 m_errorMonitor->VerifyFound();
1905
1906 // Check surface formats:
1907 uint32_t format_count = 0;
1908 VkSurfaceFormatKHR *formats = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001909 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1910 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &format_count, formats);
Ian Elliott1c32c772016-04-28 14:47:13 -06001911 pass = (err != VK_SUCCESS);
1912 ASSERT_TRUE(pass);
1913 m_errorMonitor->VerifyFound();
1914
1915 // Check surface present modes:
1916 uint32_t present_mode_count = 0;
1917 VkSurfaceFormatKHR *present_modes = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001918 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1919 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &present_mode_count, present_modes);
Ian Elliott1c32c772016-04-28 14:47:13 -06001920 pass = (err != VK_SUCCESS);
1921 ASSERT_TRUE(pass);
1922 m_errorMonitor->VerifyFound();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001923#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001924
Ian Elliott1c32c772016-04-28 14:47:13 -06001925 // Use the functions from the VK_KHR_swapchain extension without enabling
1926 // that extension:
1927
1928 // Create a swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001929 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001930 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
1931 swapchain_create_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001932 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
Ian Elliott1c32c772016-04-28 14:47:13 -06001933 pass = (err != VK_SUCCESS);
1934 ASSERT_TRUE(pass);
1935 m_errorMonitor->VerifyFound();
1936
1937 // Get the images from the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001938 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1939 err = vkGetSwapchainImagesKHR(m_device->device(), swapchain, &swapchain_image_count, NULL);
Ian Elliott1c32c772016-04-28 14:47:13 -06001940 pass = (err != VK_SUCCESS);
1941 ASSERT_TRUE(pass);
1942 m_errorMonitor->VerifyFound();
1943
Chris Forbeseb7d5502016-09-13 18:19:21 +12001944 // Add a fence to avoid (justifiable) error about not providing fence OR semaphore
1945 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
1946 VkFence fence;
1947 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
1948
Ian Elliott1c32c772016-04-28 14:47:13 -06001949 // Try to acquire an image:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001950 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Chris Forbeseb7d5502016-09-13 18:19:21 +12001951 err = vkAcquireNextImageKHR(m_device->device(), swapchain, 0, VK_NULL_HANDLE, fence, &image_index);
Ian Elliott1c32c772016-04-28 14:47:13 -06001952 pass = (err != VK_SUCCESS);
1953 ASSERT_TRUE(pass);
1954 m_errorMonitor->VerifyFound();
1955
Chris Forbeseb7d5502016-09-13 18:19:21 +12001956 vkDestroyFence(m_device->device(), fence, nullptr);
1957
Ian Elliott1c32c772016-04-28 14:47:13 -06001958 // Try to present an image:
Ian Elliott2c1daf52016-05-12 09:41:46 -06001959 //
1960 // NOTE: Currently can't test this because a real swapchain is needed (as
1961 // opposed to the fake one we created) in order for the layer to lookup the
1962 // VkDevice used to enable the extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06001963
1964 // Destroy the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001965 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001966 vkDestroySwapchainKHR(m_device->device(), swapchain, NULL);
1967 m_errorMonitor->VerifyFound();
1968}
Chris Forbes09368e42016-10-13 11:59:22 +13001969#endif
Ian Elliott1c32c772016-04-28 14:47:13 -06001970
Karl Schultz6addd812016-02-02 17:17:23 -07001971TEST_F(VkLayerTest, MapMemWithoutHostVisibleBit) {
1972 VkResult err;
1973 bool pass;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001974
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001975 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1976 "Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001977
Tony Barbour1fa09702017-03-16 12:09:08 -06001978 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001979
1980 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07001981 VkImage image;
1982 VkDeviceMemory mem;
1983 VkMemoryRequirements mem_reqs;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001984
Karl Schultz6addd812016-02-02 17:17:23 -07001985 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
1986 const int32_t tex_width = 32;
1987 const int32_t tex_height = 32;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001988
Tony Barboureb254902015-07-15 12:50:33 -06001989 VkImageCreateInfo image_create_info = {};
1990 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07001991 image_create_info.pNext = NULL;
1992 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1993 image_create_info.format = tex_format;
1994 image_create_info.extent.width = tex_width;
1995 image_create_info.extent.height = tex_height;
1996 image_create_info.extent.depth = 1;
1997 image_create_info.mipLevels = 1;
1998 image_create_info.arrayLayers = 1;
1999 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2000 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2001 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2002 image_create_info.flags = 0;
Chris Forbese65e4d02016-09-13 17:39:18 +12002003 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002004
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002005 VkMemoryAllocateInfo mem_alloc = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002006 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07002007 mem_alloc.pNext = NULL;
2008 mem_alloc.allocationSize = 0;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002009
Chia-I Wuf7458c52015-10-26 21:10:41 +08002010 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002011 ASSERT_VK_SUCCESS(err);
2012
Karl Schultz6addd812016-02-02 17:17:23 -07002013 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002014
Mark Lobodzinski23065352015-05-29 09:32:35 -05002015 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002016
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002017 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 -07002018 if (!pass) { // If we can't find any unmappable memory this test doesn't
2019 // make sense
Chia-I Wuf7458c52015-10-26 21:10:41 +08002020 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbour02fdc7d2015-08-04 16:13:01 -06002021 return;
Mike Stroyand1c84a52015-08-18 14:40:24 -06002022 }
Mike Stroyan713b2d72015-08-04 10:49:29 -06002023
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002024 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002025 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002026 ASSERT_VK_SUCCESS(err);
2027
2028 // Try to bind free memory that has been freed
Tony Barbour67e99152015-07-10 14:10:27 -06002029 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002030 ASSERT_VK_SUCCESS(err);
2031
2032 // Map memory as if to initialize the image
2033 void *mappedAddress = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002034 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, &mappedAddress);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002035
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002036 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002037
Chia-I Wuf7458c52015-10-26 21:10:41 +08002038 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06002039 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002040}
2041
Karl Schultz6addd812016-02-02 17:17:23 -07002042TEST_F(VkLayerTest, RebindMemory) {
2043 VkResult err;
2044 bool pass;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002045
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002046 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which has already been bound to mem object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002047
Tony Barbour1fa09702017-03-16 12:09:08 -06002048 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002049
2050 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07002051 VkImage image;
2052 VkDeviceMemory mem1;
2053 VkDeviceMemory mem2;
2054 VkMemoryRequirements mem_reqs;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002055
Karl Schultz6addd812016-02-02 17:17:23 -07002056 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2057 const int32_t tex_width = 32;
2058 const int32_t tex_height = 32;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002059
Tony Barboureb254902015-07-15 12:50:33 -06002060 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002061 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2062 image_create_info.pNext = NULL;
2063 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2064 image_create_info.format = tex_format;
2065 image_create_info.extent.width = tex_width;
2066 image_create_info.extent.height = tex_height;
2067 image_create_info.extent.depth = 1;
2068 image_create_info.mipLevels = 1;
2069 image_create_info.arrayLayers = 1;
2070 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2071 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2072 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2073 image_create_info.flags = 0;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002074
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002075 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002076 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2077 mem_alloc.pNext = NULL;
2078 mem_alloc.allocationSize = 0;
2079 mem_alloc.memoryTypeIndex = 0;
Tony Barboureb254902015-07-15 12:50:33 -06002080
Karl Schultz6addd812016-02-02 17:17:23 -07002081 // Introduce failure, do NOT set memProps to
2082 // VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
Tony Barboureb254902015-07-15 12:50:33 -06002083 mem_alloc.memoryTypeIndex = 1;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002084 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002085 ASSERT_VK_SUCCESS(err);
2086
Karl Schultz6addd812016-02-02 17:17:23 -07002087 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002088
2089 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002090 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002091 ASSERT_TRUE(pass);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002092
2093 // allocate 2 memory objects
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002094 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem1);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002095 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002096 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem2);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002097 ASSERT_VK_SUCCESS(err);
2098
2099 // Bind first memory object to Image object
Tony Barbour67e99152015-07-10 14:10:27 -06002100 err = vkBindImageMemory(m_device->device(), image, mem1, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002101 ASSERT_VK_SUCCESS(err);
2102
Karl Schultz6addd812016-02-02 17:17:23 -07002103 // Introduce validation failure, try to bind a different memory object to
2104 // the same image object
Tony Barbour67e99152015-07-10 14:10:27 -06002105 err = vkBindImageMemory(m_device->device(), image, mem2, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002106
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002107 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002108
Chia-I Wuf7458c52015-10-26 21:10:41 +08002109 vkDestroyImage(m_device->device(), image, NULL);
2110 vkFreeMemory(m_device->device(), mem1, NULL);
2111 vkFreeMemory(m_device->device(), mem2, NULL);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002112}
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002113
Karl Schultz6addd812016-02-02 17:17:23 -07002114TEST_F(VkLayerTest, SubmitSignaledFence) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002115 vk_testing::Fence testFence;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002116
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002117 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2118 "submitted in SIGNALED state. Fences "
2119 "must be reset before being submitted");
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002120
2121 VkFenceCreateInfo fenceInfo = {};
Tony Barbour0b4d9562015-04-09 10:48:04 -06002122 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2123 fenceInfo.pNext = NULL;
2124 fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
Tony Barbour300a6082015-04-07 13:44:53 -06002125
Tony Barbour1fa09702017-03-16 12:09:08 -06002126 ASSERT_NO_FATAL_FAILURE(Init());
Tony Barbour300a6082015-04-07 13:44:53 -06002127 ASSERT_NO_FATAL_FAILURE(InitViewport());
2128 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2129
Tony Barbour552f6c02016-12-21 14:34:07 -07002130 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002131 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbour552f6c02016-12-21 14:34:07 -07002132 m_commandBuffer->EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -06002133
2134 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002135
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002136 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08002137 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2138 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002139 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002140 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07002141 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002142 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002143 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08002144 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002145 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06002146
2147 vkQueueSubmit(m_device->m_queue, 1, &submit_info, testFence.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07002148 vkQueueWaitIdle(m_device->m_queue);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002149
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002150 m_errorMonitor->VerifyFound();
Tony Barbour0b4d9562015-04-09 10:48:04 -06002151}
Chris Forbes4e44c912016-06-16 10:20:00 +12002152
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002153TEST_F(VkLayerTest, InvalidUsageBits) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002154 TEST_DESCRIPTION(
2155 "Specify wrong usage for image then create conflicting view of image "
2156 "Initialize buffer with wrong usage then perform copy expecting errors "
2157 "from both the image and the buffer (2 calls)");
Mark Lobodzinski33826372017-04-13 11:10:11 -06002158 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid usage flag for Image ");
Tobin Ehlis41376e12015-07-03 08:45:14 -06002159
Tony Barbour1fa09702017-03-16 12:09:08 -06002160 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -06002161 auto format = FindSupportedDepthStencilFormat(gpu());
Tony Barbourf887b162017-03-09 10:06:46 -07002162 if (!format) {
2163 printf(" No Depth + Stencil format found. Skipped.\n");
2164 return;
2165 }
Chris Forbesd2b5fe42016-11-28 18:00:00 +13002166
Tony Barbourf92621a2016-05-02 14:28:12 -06002167 VkImageObj image(m_device);
Tony Barbour75d79f02016-08-30 09:39:07 -06002168 // Initialize image with USAGE_TRANSIENT_ATTACHMENT
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06002169 image.Init(128, 128, 1, format, VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Karl Schultzb5bc11e2016-05-04 08:36:08 -06002170 ASSERT_TRUE(image.initialized());
Tobin Ehlis41376e12015-07-03 08:45:14 -06002171
Tony Barbourf92621a2016-05-02 14:28:12 -06002172 VkImageView dsv;
2173 VkImageViewCreateInfo dsvci = {};
2174 dsvci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
2175 dsvci.image = image.handle();
2176 dsvci.viewType = VK_IMAGE_VIEW_TYPE_2D;
Chris Forbesd2b5fe42016-11-28 18:00:00 +13002177 dsvci.format = format;
Tony Barbourf92621a2016-05-02 14:28:12 -06002178 dsvci.subresourceRange.layerCount = 1;
2179 dsvci.subresourceRange.baseMipLevel = 0;
2180 dsvci.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002181 dsvci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis41376e12015-07-03 08:45:14 -06002182
Tony Barbourf92621a2016-05-02 14:28:12 -06002183 // Create a view with depth / stencil aspect for image with different usage
2184 vkCreateImageView(m_device->device(), &dsvci, NULL, &dsv);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002185
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002186 m_errorMonitor->VerifyFound();
Tony Barbourf92621a2016-05-02 14:28:12 -06002187
2188 // Initialize buffer with TRANSFER_DST usage
2189 vk_testing::Buffer buffer;
2190 VkMemoryPropertyFlags reqs = 0;
2191 buffer.init_as_dst(*m_device, 128 * 128, reqs);
2192 VkBufferImageCopy region = {};
2193 region.bufferRowLength = 128;
2194 region.bufferImageHeight = 128;
Mark Lobodzinski80871462017-02-16 10:37:27 -07002195 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Tony Barbourf92621a2016-05-02 14:28:12 -06002196 region.imageSubresource.layerCount = 1;
2197 region.imageExtent.height = 16;
2198 region.imageExtent.width = 16;
2199 region.imageExtent.depth = 1;
2200
Mark Lobodzinski80871462017-02-16 10:37:27 -07002201 // Buffer usage not set to TRANSFER_SRC and image usage not set to TRANSFER_DST
Tony Barbour552f6c02016-12-21 14:34:07 -07002202 m_commandBuffer->BeginCommandBuffer();
Tony Barbourf92621a2016-05-02 14:28:12 -06002203
Chris Forbesda581202016-10-06 18:25:26 +13002204 // two separate errors from this call:
Mark Lobodzinski33826372017-04-13 11:10:11 -06002205 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image should have VK_IMAGE_USAGE_TRANSFER_DST_BIT");
2206 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 +13002207
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002208 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
2209 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourf92621a2016-05-02 14:28:12 -06002210 m_errorMonitor->VerifyFound();
Tobin Ehlis41376e12015-07-03 08:45:14 -06002211}
Tony Barbour75d79f02016-08-30 09:39:07 -06002212
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002213TEST_F(VkLayerTest, LeakAnObject) {
2214 VkResult err;
2215
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002216 TEST_DESCRIPTION("Create a fence and destroy its device without first destroying the fence.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002217
2218 // Note that we have to create a new device since destroying the
2219 // framework's device causes Teardown() to fail and just calling Teardown
2220 // will destroy the errorMonitor.
2221
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002222 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "has not been destroyed.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002223
Tony Barbour1fa09702017-03-16 12:09:08 -06002224 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002225
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002226 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002227 std::vector<VkDeviceQueueCreateInfo> queue_info;
2228 queue_info.reserve(queue_props.size());
2229 std::vector<std::vector<float>> queue_priorities;
2230 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
2231 VkDeviceQueueCreateInfo qi = {};
2232 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
2233 qi.pNext = NULL;
2234 qi.queueFamilyIndex = i;
2235 qi.queueCount = queue_props[i].queueCount;
2236 queue_priorities.emplace_back(qi.queueCount, 0.0f);
2237 qi.pQueuePriorities = queue_priorities[i].data();
2238 queue_info.push_back(qi);
2239 }
2240
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002241 std::vector<const char *> device_extension_names;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002242
2243 // The sacrificial device object
2244 VkDevice testDevice;
2245 VkDeviceCreateInfo device_create_info = {};
2246 auto features = m_device->phy().features();
2247 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
2248 device_create_info.pNext = NULL;
2249 device_create_info.queueCreateInfoCount = queue_info.size();
2250 device_create_info.pQueueCreateInfos = queue_info.data();
Tony Barbour4c70d102016-08-08 16:06:56 -06002251 device_create_info.enabledLayerCount = 0;
2252 device_create_info.ppEnabledLayerNames = NULL;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002253 device_create_info.pEnabledFeatures = &features;
2254 err = vkCreateDevice(gpu(), &device_create_info, NULL, &testDevice);
2255 ASSERT_VK_SUCCESS(err);
2256
2257 VkFence fence;
2258 VkFenceCreateInfo fence_create_info = {};
2259 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2260 fence_create_info.pNext = NULL;
2261 fence_create_info.flags = 0;
2262 err = vkCreateFence(testDevice, &fence_create_info, NULL, &fence);
2263 ASSERT_VK_SUCCESS(err);
2264
2265 // Induce failure by not calling vkDestroyFence
2266 vkDestroyDevice(testDevice, NULL);
2267 m_errorMonitor->VerifyFound();
2268}
2269
2270TEST_F(VkLayerTest, InvalidCommandPoolConsistency) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002271 TEST_DESCRIPTION(
2272 "Allocate command buffers from one command pool and "
2273 "attempt to delete them from another.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002274
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002275 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeCommandBuffers is attempting to free Command Buffer");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002276
Tony Barbour1fa09702017-03-16 12:09:08 -06002277 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002278 VkCommandPool command_pool_one;
2279 VkCommandPool command_pool_two;
2280
2281 VkCommandPoolCreateInfo pool_create_info{};
2282 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
2283 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
2284 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
2285
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002286 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002287
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002288 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002289
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002290 VkCommandBuffer cb;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002291 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002292 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002293 command_buffer_allocate_info.commandPool = command_pool_one;
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002294 command_buffer_allocate_info.commandBufferCount = 1;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002295 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002296 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &cb);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002297
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002298 vkFreeCommandBuffers(m_device->device(), command_pool_two, 1, &cb);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002299
2300 m_errorMonitor->VerifyFound();
2301
2302 vkDestroyCommandPool(m_device->device(), command_pool_one, NULL);
2303 vkDestroyCommandPool(m_device->device(), command_pool_two, NULL);
2304}
2305
2306TEST_F(VkLayerTest, InvalidDescriptorPoolConsistency) {
2307 VkResult err;
2308
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002309 TEST_DESCRIPTION(
2310 "Allocate descriptor sets from one DS pool and "
2311 "attempt to delete them from another.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002312
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002313 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeDescriptorSets is attempting to free descriptorSet");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002314
Tony Barbour1fa09702017-03-16 12:09:08 -06002315 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002316 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2317
2318 VkDescriptorPoolSize ds_type_count = {};
2319 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
2320 ds_type_count.descriptorCount = 1;
2321
2322 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2323 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2324 ds_pool_ci.pNext = NULL;
2325 ds_pool_ci.flags = 0;
2326 ds_pool_ci.maxSets = 1;
2327 ds_pool_ci.poolSizeCount = 1;
2328 ds_pool_ci.pPoolSizes = &ds_type_count;
2329
2330 VkDescriptorPool ds_pool_one;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002331 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002332 ASSERT_VK_SUCCESS(err);
2333
2334 // Create a second descriptor pool
2335 VkDescriptorPool ds_pool_two;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002336 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002337 ASSERT_VK_SUCCESS(err);
2338
2339 VkDescriptorSetLayoutBinding dsl_binding = {};
2340 dsl_binding.binding = 0;
2341 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
2342 dsl_binding.descriptorCount = 1;
2343 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2344 dsl_binding.pImmutableSamplers = NULL;
2345
2346 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2347 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2348 ds_layout_ci.pNext = NULL;
2349 ds_layout_ci.bindingCount = 1;
2350 ds_layout_ci.pBindings = &dsl_binding;
2351
2352 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002353 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002354 ASSERT_VK_SUCCESS(err);
2355
2356 VkDescriptorSet descriptorSet;
2357 VkDescriptorSetAllocateInfo alloc_info = {};
2358 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
2359 alloc_info.descriptorSetCount = 1;
2360 alloc_info.descriptorPool = ds_pool_one;
2361 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002362 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002363 ASSERT_VK_SUCCESS(err);
2364
2365 err = vkFreeDescriptorSets(m_device->device(), ds_pool_two, 1, &descriptorSet);
2366
2367 m_errorMonitor->VerifyFound();
2368
2369 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2370 vkDestroyDescriptorPool(m_device->device(), ds_pool_one, NULL);
2371 vkDestroyDescriptorPool(m_device->device(), ds_pool_two, NULL);
2372}
2373
2374TEST_F(VkLayerTest, CreateUnknownObject) {
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002375 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00788);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002376
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002377 TEST_DESCRIPTION("Pass an invalid image object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002378
Tony Barbour1fa09702017-03-16 12:09:08 -06002379 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002380
2381 // Pass bogus handle into GetImageMemoryRequirements
2382 VkMemoryRequirements mem_reqs;
2383 uint64_t fakeImageHandle = 0xCADECADE;
2384 VkImage fauxImage = reinterpret_cast<VkImage &>(fakeImageHandle);
2385
2386 vkGetImageMemoryRequirements(m_device->device(), fauxImage, &mem_reqs);
2387
2388 m_errorMonitor->VerifyFound();
2389}
2390
Mike Schuchardt17838902017-02-21 09:48:06 -07002391TEST_F(VkLayerTest, UseObjectWithWrongDevice) {
2392 TEST_DESCRIPTION(
2393 "Try to destroy a render pass object using a device other than the one it was created on. "
2394 "This should generate a distinct error from the invalid handle error.");
2395 // Create first device and renderpass
Tony Barbour1fa09702017-03-16 12:09:08 -06002396 ASSERT_NO_FATAL_FAILURE(Init());
Mike Schuchardt17838902017-02-21 09:48:06 -07002397 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2398
2399 // Create second device
2400 float priorities[] = {1.0f};
2401 VkDeviceQueueCreateInfo queue_info{};
2402 queue_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
2403 queue_info.pNext = NULL;
2404 queue_info.flags = 0;
2405 queue_info.queueFamilyIndex = 0;
2406 queue_info.queueCount = 1;
2407 queue_info.pQueuePriorities = &priorities[0];
2408
2409 VkDeviceCreateInfo device_create_info = {};
2410 auto features = m_device->phy().features();
2411 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
2412 device_create_info.pNext = NULL;
2413 device_create_info.queueCreateInfoCount = 1;
2414 device_create_info.pQueueCreateInfos = &queue_info;
2415 device_create_info.enabledLayerCount = 0;
2416 device_create_info.ppEnabledLayerNames = NULL;
2417 device_create_info.pEnabledFeatures = &features;
2418
2419 VkDevice second_device;
2420 ASSERT_VK_SUCCESS(vkCreateDevice(gpu(), &device_create_info, NULL, &second_device));
2421
2422 // Try to destroy the renderpass from the first device using the second device
2423 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00399);
2424 vkDestroyRenderPass(second_device, m_renderPass, NULL);
2425 m_errorMonitor->VerifyFound();
2426
2427 vkDestroyDevice(second_device, NULL);
2428}
2429
Karl Schultz6addd812016-02-02 17:17:23 -07002430TEST_F(VkLayerTest, PipelineNotBound) {
2431 VkResult err;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002432
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002433 TEST_DESCRIPTION("Pass in an invalid pipeline object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002434
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002435 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00601);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002436
Tony Barbour1fa09702017-03-16 12:09:08 -06002437 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002438 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002439
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002440 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002441 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2442 ds_type_count.descriptorCount = 1;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002443
2444 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002445 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2446 ds_pool_ci.pNext = NULL;
2447 ds_pool_ci.maxSets = 1;
2448 ds_pool_ci.poolSizeCount = 1;
2449 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002450
2451 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002452 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002453 ASSERT_VK_SUCCESS(err);
2454
2455 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002456 dsl_binding.binding = 0;
2457 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2458 dsl_binding.descriptorCount = 1;
2459 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2460 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002461
2462 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002463 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2464 ds_layout_ci.pNext = NULL;
2465 ds_layout_ci.bindingCount = 1;
2466 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002467
2468 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002469 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002470 ASSERT_VK_SUCCESS(err);
2471
2472 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002473 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002474 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07002475 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002476 alloc_info.descriptorPool = ds_pool;
2477 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002478 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002479 ASSERT_VK_SUCCESS(err);
2480
2481 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002482 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2483 pipeline_layout_ci.pNext = NULL;
2484 pipeline_layout_ci.setLayoutCount = 1;
2485 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002486
2487 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002488 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002489 ASSERT_VK_SUCCESS(err);
2490
Mark Youngad779052016-01-06 14:26:04 -07002491 VkPipeline badPipeline = (VkPipeline)((size_t)0xbaadb1be);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002492
Tony Barbour552f6c02016-12-21 14:34:07 -07002493 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002494 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002495
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002496 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002497
Chia-I Wuf7458c52015-10-26 21:10:41 +08002498 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2499 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2500 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002501}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002502
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002503TEST_F(VkLayerTest, BindImageInvalidMemoryType) {
2504 VkResult err;
2505
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002506 TEST_DESCRIPTION(
2507 "Test validation check for an invalid memory type index "
2508 "during bind[Buffer|Image]Memory time");
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002509
Tony Barbour1fa09702017-03-16 12:09:08 -06002510 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002511
2512 // Create an image, allocate memory, set a bad typeIndex and then try to
2513 // bind it
2514 VkImage image;
2515 VkDeviceMemory mem;
2516 VkMemoryRequirements mem_reqs;
2517 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2518 const int32_t tex_width = 32;
2519 const int32_t tex_height = 32;
2520
2521 VkImageCreateInfo image_create_info = {};
2522 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2523 image_create_info.pNext = NULL;
2524 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2525 image_create_info.format = tex_format;
2526 image_create_info.extent.width = tex_width;
2527 image_create_info.extent.height = tex_height;
2528 image_create_info.extent.depth = 1;
2529 image_create_info.mipLevels = 1;
2530 image_create_info.arrayLayers = 1;
2531 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2532 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2533 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2534 image_create_info.flags = 0;
2535
2536 VkMemoryAllocateInfo mem_alloc = {};
2537 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2538 mem_alloc.pNext = NULL;
2539 mem_alloc.allocationSize = 0;
2540 mem_alloc.memoryTypeIndex = 0;
2541
2542 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
2543 ASSERT_VK_SUCCESS(err);
2544
2545 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
2546 mem_alloc.allocationSize = mem_reqs.size;
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002547
2548 // Introduce Failure, select invalid TypeIndex
2549 VkPhysicalDeviceMemoryProperties memory_info;
2550
2551 vkGetPhysicalDeviceMemoryProperties(gpu(), &memory_info);
2552 unsigned int i;
2553 for (i = 0; i < memory_info.memoryTypeCount; i++) {
2554 if ((mem_reqs.memoryTypeBits & (1 << i)) == 0) {
2555 mem_alloc.memoryTypeIndex = i;
2556 break;
2557 }
2558 }
2559 if (i >= memory_info.memoryTypeCount) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07002560 printf(" No invalid memory type index could be found; skipped.\n");
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002561 vkDestroyImage(m_device->device(), image, NULL);
2562 return;
2563 }
2564
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002565 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 -06002566
2567 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
2568 ASSERT_VK_SUCCESS(err);
2569
2570 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2571 (void)err;
2572
2573 m_errorMonitor->VerifyFound();
2574
2575 vkDestroyImage(m_device->device(), image, NULL);
2576 vkFreeMemory(m_device->device(), mem, NULL);
2577}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002578
Karl Schultz6addd812016-02-02 17:17:23 -07002579TEST_F(VkLayerTest, BindInvalidMemory) {
2580 VkResult err;
2581 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002582
Tony Barbour1fa09702017-03-16 12:09:08 -06002583 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisec598302015-09-15 15:02:17 -06002584
Cortf801b982017-01-17 18:10:21 -08002585 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
Cort Strattonde748202017-02-17 12:50:01 -08002586 const int32_t tex_width = 256;
2587 const int32_t tex_height = 256;
Tobin Ehlisec598302015-09-15 15:02:17 -06002588
2589 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002590 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2591 image_create_info.pNext = NULL;
2592 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2593 image_create_info.format = tex_format;
2594 image_create_info.extent.width = tex_width;
2595 image_create_info.extent.height = tex_height;
2596 image_create_info.extent.depth = 1;
2597 image_create_info.mipLevels = 1;
2598 image_create_info.arrayLayers = 1;
2599 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Cort Strattonf1d8a4a2017-01-28 14:17:04 -08002600 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Karl Schultz6addd812016-02-02 17:17:23 -07002601 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2602 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002603
Cortf801b982017-01-17 18:10:21 -08002604 VkBufferCreateInfo buffer_create_info = {};
2605 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
2606 buffer_create_info.pNext = NULL;
2607 buffer_create_info.flags = 0;
Cort Strattonde748202017-02-17 12:50:01 -08002608 buffer_create_info.size = 4 * 1024 * 1024;
2609 buffer_create_info.usage = VK_BUFFER_USAGE_VERTEX_BUFFER_BIT;
Cortf801b982017-01-17 18:10:21 -08002610 buffer_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
Tobin Ehlisec598302015-09-15 15:02:17 -06002611
Cortf801b982017-01-17 18:10:21 -08002612 // Create an image/buffer, allocate memory, free it, and then try to bind it
2613 {
2614 VkImage image = VK_NULL_HANDLE;
2615 VkBuffer buffer = VK_NULL_HANDLE;
2616 err = vkCreateImage(device(), &image_create_info, NULL, &image);
2617 ASSERT_VK_SUCCESS(err);
2618 err = vkCreateBuffer(device(), &buffer_create_info, NULL, &buffer);
2619 ASSERT_VK_SUCCESS(err);
2620 VkMemoryRequirements image_mem_reqs = {}, buffer_mem_reqs = {};
2621 vkGetImageMemoryRequirements(device(), image, &image_mem_reqs);
2622 vkGetBufferMemoryRequirements(device(), buffer, &buffer_mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002623
Cortf801b982017-01-17 18:10:21 -08002624 VkMemoryAllocateInfo image_mem_alloc = {}, buffer_mem_alloc = {};
2625 image_mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2626 image_mem_alloc.allocationSize = image_mem_reqs.size;
2627 pass = m_device->phy().set_memory_type(image_mem_reqs.memoryTypeBits, &image_mem_alloc, 0);
2628 ASSERT_TRUE(pass);
2629 buffer_mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2630 buffer_mem_alloc.allocationSize = buffer_mem_reqs.size;
2631 pass = m_device->phy().set_memory_type(buffer_mem_reqs.memoryTypeBits, &buffer_mem_alloc, 0);
2632 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002633
Cortf801b982017-01-17 18:10:21 -08002634 VkDeviceMemory image_mem = VK_NULL_HANDLE, buffer_mem = VK_NULL_HANDLE;
2635 err = vkAllocateMemory(device(), &image_mem_alloc, NULL, &image_mem);
2636 ASSERT_VK_SUCCESS(err);
2637 err = vkAllocateMemory(device(), &buffer_mem_alloc, NULL, &buffer_mem);
2638 ASSERT_VK_SUCCESS(err);
Tobin Ehlisec598302015-09-15 15:02:17 -06002639
Cortf801b982017-01-17 18:10:21 -08002640 vkFreeMemory(device(), image_mem, NULL);
2641 vkFreeMemory(device(), buffer_mem, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002642
Cortf801b982017-01-17 18:10:21 -08002643 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00809);
2644 err = vkBindImageMemory(device(), image, image_mem, 0);
2645 (void)err; // This may very well return an error.
2646 m_errorMonitor->VerifyFound();
Tobin Ehlisec598302015-09-15 15:02:17 -06002647
Cortf801b982017-01-17 18:10:21 -08002648 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00800);
2649 err = vkBindBufferMemory(device(), buffer, buffer_mem, 0);
2650 (void)err; // This may very well return an error.
2651 m_errorMonitor->VerifyFound();
Tobin Ehlisec598302015-09-15 15:02:17 -06002652
Cortf801b982017-01-17 18:10:21 -08002653 vkDestroyImage(m_device->device(), image, NULL);
2654 vkDestroyBuffer(m_device->device(), buffer, NULL);
2655 }
Cort Strattonc21601b2017-01-28 14:16:16 -08002656
2657 // Try to bind memory to an object that already has a memory binding
2658 {
2659 VkImage image = VK_NULL_HANDLE;
2660 err = vkCreateImage(device(), &image_create_info, NULL, &image);
2661 ASSERT_VK_SUCCESS(err);
2662 VkBuffer buffer = VK_NULL_HANDLE;
2663 err = vkCreateBuffer(device(), &buffer_create_info, NULL, &buffer);
2664 ASSERT_VK_SUCCESS(err);
2665 VkMemoryRequirements image_mem_reqs = {}, buffer_mem_reqs = {};
2666 vkGetImageMemoryRequirements(device(), image, &image_mem_reqs);
2667 vkGetBufferMemoryRequirements(device(), buffer, &buffer_mem_reqs);
2668 VkMemoryAllocateInfo image_alloc_info = {}, buffer_alloc_info = {};
2669 image_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2670 image_alloc_info.allocationSize = image_mem_reqs.size;
2671 buffer_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2672 buffer_alloc_info.allocationSize = buffer_mem_reqs.size;
2673 pass = m_device->phy().set_memory_type(image_mem_reqs.memoryTypeBits, &image_alloc_info, 0);
2674 ASSERT_TRUE(pass);
2675 pass = m_device->phy().set_memory_type(buffer_mem_reqs.memoryTypeBits, &buffer_alloc_info, 0);
2676 ASSERT_TRUE(pass);
2677 VkDeviceMemory image_mem, buffer_mem;
2678 err = vkAllocateMemory(device(), &image_alloc_info, NULL, &image_mem);
2679 ASSERT_VK_SUCCESS(err);
2680 err = vkAllocateMemory(device(), &buffer_alloc_info, NULL, &buffer_mem);
2681 ASSERT_VK_SUCCESS(err);
2682
2683 err = vkBindImageMemory(device(), image, image_mem, 0);
2684 ASSERT_VK_SUCCESS(err);
2685 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00803);
2686 err = vkBindImageMemory(device(), image, image_mem, 0);
2687 (void)err; // This may very well return an error.
2688 m_errorMonitor->VerifyFound();
2689
2690 err = vkBindBufferMemory(device(), buffer, buffer_mem, 0);
2691 ASSERT_VK_SUCCESS(err);
2692 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00791);
2693 err = vkBindBufferMemory(device(), buffer, buffer_mem, 0);
2694 (void)err; // This may very well return an error.
2695 m_errorMonitor->VerifyFound();
2696
2697 vkFreeMemory(device(), image_mem, NULL);
2698 vkFreeMemory(device(), buffer_mem, NULL);
2699 vkDestroyImage(device(), image, NULL);
2700 vkDestroyBuffer(device(), buffer, NULL);
2701 }
Cort Strattonf1d8a4a2017-01-28 14:17:04 -08002702
Cort Strattonde748202017-02-17 12:50:01 -08002703 // Try to bind memory to an object with an invalid memoryOffset
Cort6c7dff72017-01-27 18:34:50 -08002704 {
2705 VkImage image = VK_NULL_HANDLE;
2706 err = vkCreateImage(device(), &image_create_info, NULL, &image);
2707 ASSERT_VK_SUCCESS(err);
2708 VkBuffer buffer = VK_NULL_HANDLE;
2709 err = vkCreateBuffer(device(), &buffer_create_info, NULL, &buffer);
2710 ASSERT_VK_SUCCESS(err);
2711 VkMemoryRequirements image_mem_reqs = {}, buffer_mem_reqs = {};
2712 vkGetImageMemoryRequirements(device(), image, &image_mem_reqs);
2713 vkGetBufferMemoryRequirements(device(), buffer, &buffer_mem_reqs);
2714 VkMemoryAllocateInfo image_alloc_info = {}, buffer_alloc_info = {};
2715 image_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Cort Strattonde748202017-02-17 12:50:01 -08002716 // Leave some extra space for alignment wiggle room
2717 image_alloc_info.allocationSize = image_mem_reqs.size + image_mem_reqs.alignment;
Cort6c7dff72017-01-27 18:34:50 -08002718 buffer_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Cort Strattonde748202017-02-17 12:50:01 -08002719 buffer_alloc_info.allocationSize = buffer_mem_reqs.size + buffer_mem_reqs.alignment;
Cort6c7dff72017-01-27 18:34:50 -08002720 pass = m_device->phy().set_memory_type(image_mem_reqs.memoryTypeBits, &image_alloc_info, 0);
2721 ASSERT_TRUE(pass);
2722 pass = m_device->phy().set_memory_type(buffer_mem_reqs.memoryTypeBits, &buffer_alloc_info, 0);
2723 ASSERT_TRUE(pass);
2724 VkDeviceMemory image_mem, buffer_mem;
2725 err = vkAllocateMemory(device(), &image_alloc_info, NULL, &image_mem);
2726 ASSERT_VK_SUCCESS(err);
2727 err = vkAllocateMemory(device(), &buffer_alloc_info, NULL, &buffer_mem);
2728 ASSERT_VK_SUCCESS(err);
2729
Cort Strattonde748202017-02-17 12:50:01 -08002730 // Test unaligned memory offset
2731 {
2732 if (image_mem_reqs.alignment > 1) {
2733 VkDeviceSize image_offset = 1;
2734 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02178);
2735 err = vkBindImageMemory(device(), image, image_mem, image_offset);
2736 (void)err; // This may very well return an error.
2737 m_errorMonitor->VerifyFound();
2738 }
Cort6c7dff72017-01-27 18:34:50 -08002739
Cort Strattonde748202017-02-17 12:50:01 -08002740 if (buffer_mem_reqs.alignment > 1) {
2741 VkDeviceSize buffer_offset = 1;
2742 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02174);
2743 err = vkBindBufferMemory(device(), buffer, buffer_mem, buffer_offset);
2744 (void)err; // This may very well return an error.
2745 m_errorMonitor->VerifyFound();
2746 }
2747 }
2748
2749 // Test memory offsets outside the memory allocation
2750 {
2751 VkDeviceSize image_offset =
2752 (image_alloc_info.allocationSize + image_mem_reqs.alignment) & ~(image_mem_reqs.alignment - 1);
2753 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00805);
2754 err = vkBindImageMemory(device(), image, image_mem, image_offset);
2755 (void)err; // This may very well return an error.
2756 m_errorMonitor->VerifyFound();
2757
2758 VkDeviceSize buffer_offset =
2759 (buffer_alloc_info.allocationSize + buffer_mem_reqs.alignment) & ~(buffer_mem_reqs.alignment - 1);
2760 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00793);
2761 err = vkBindBufferMemory(device(), buffer, buffer_mem, buffer_offset);
2762 (void)err; // This may very well return an error.
2763 m_errorMonitor->VerifyFound();
2764 }
2765
2766 // Test memory offsets within the memory allocation, but which leave too little memory for
2767 // the resource.
2768 {
2769 VkDeviceSize image_offset = (image_mem_reqs.size - 1) & ~(image_mem_reqs.alignment - 1);
Tony Barbour02d08552017-03-24 16:36:01 -06002770 if ((image_offset > 0) && (image_mem_reqs.size < (image_alloc_info.allocationSize - image_mem_reqs.alignment))) {
Cort Strattonde748202017-02-17 12:50:01 -08002771 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02179);
2772 err = vkBindImageMemory(device(), image, image_mem, image_offset);
2773 (void)err; // This may very well return an error.
2774 m_errorMonitor->VerifyFound();
2775 }
2776
2777 VkDeviceSize buffer_offset = (buffer_mem_reqs.size - 1) & ~(buffer_mem_reqs.alignment - 1);
2778 if (buffer_offset > 0) {
2779 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02175);
2780 err = vkBindBufferMemory(device(), buffer, buffer_mem, buffer_offset);
2781 (void)err; // This may very well return an error.
2782 m_errorMonitor->VerifyFound();
2783 }
2784 }
Cort6c7dff72017-01-27 18:34:50 -08002785
2786 vkFreeMemory(device(), image_mem, NULL);
2787 vkFreeMemory(device(), buffer_mem, NULL);
2788 vkDestroyImage(device(), image, NULL);
2789 vkDestroyBuffer(device(), buffer, NULL);
2790 }
2791
Cort Stratton4c38bb52017-01-28 13:33:10 -08002792 // Try to bind memory to an object with an invalid memory type
2793 {
2794 VkImage image = VK_NULL_HANDLE;
2795 err = vkCreateImage(device(), &image_create_info, NULL, &image);
2796 ASSERT_VK_SUCCESS(err);
2797 VkBuffer buffer = VK_NULL_HANDLE;
2798 err = vkCreateBuffer(device(), &buffer_create_info, NULL, &buffer);
2799 ASSERT_VK_SUCCESS(err);
2800 VkMemoryRequirements image_mem_reqs = {}, buffer_mem_reqs = {};
2801 vkGetImageMemoryRequirements(device(), image, &image_mem_reqs);
2802 vkGetBufferMemoryRequirements(device(), buffer, &buffer_mem_reqs);
2803 VkMemoryAllocateInfo image_alloc_info = {}, buffer_alloc_info = {};
2804 image_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2805 image_alloc_info.allocationSize = image_mem_reqs.size;
2806 buffer_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2807 buffer_alloc_info.allocationSize = buffer_mem_reqs.size;
Cort Strattonccc90e32017-02-04 13:47:42 -08002808 // Create a mask of available memory types *not* supported by these resources,
2809 // and try to use one of them.
Cort Stratton4c38bb52017-01-28 13:33:10 -08002810 VkPhysicalDeviceMemoryProperties memory_properties = {};
2811 vkGetPhysicalDeviceMemoryProperties(m_device->phy().handle(), &memory_properties);
Cort Strattonccc90e32017-02-04 13:47:42 -08002812 VkDeviceMemory image_mem, buffer_mem;
2813
Cort Stratton4c38bb52017-01-28 13:33:10 -08002814 uint32_t image_unsupported_mem_type_bits = ((1 << memory_properties.memoryTypeCount) - 1) & ~image_mem_reqs.memoryTypeBits;
Cort Strattonccc90e32017-02-04 13:47:42 -08002815 if (image_unsupported_mem_type_bits != 0) {
Dave Houlton584d51e2017-02-16 12:52:54 -07002816 pass = m_device->phy().set_memory_type(image_unsupported_mem_type_bits, &image_alloc_info, 0);
2817 ASSERT_TRUE(pass);
2818 err = vkAllocateMemory(device(), &image_alloc_info, NULL, &image_mem);
2819 ASSERT_VK_SUCCESS(err);
2820 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00806);
2821 err = vkBindImageMemory(device(), image, image_mem, 0);
2822 (void)err; // This may very well return an error.
2823 m_errorMonitor->VerifyFound();
2824 vkFreeMemory(device(), image_mem, NULL);
Cort Strattonccc90e32017-02-04 13:47:42 -08002825 }
2826
Cort Stratton4c38bb52017-01-28 13:33:10 -08002827 uint32_t buffer_unsupported_mem_type_bits =
2828 ((1 << memory_properties.memoryTypeCount) - 1) & ~buffer_mem_reqs.memoryTypeBits;
Cort Strattonccc90e32017-02-04 13:47:42 -08002829 if (buffer_unsupported_mem_type_bits != 0) {
Dave Houlton584d51e2017-02-16 12:52:54 -07002830 pass = m_device->phy().set_memory_type(buffer_unsupported_mem_type_bits, &buffer_alloc_info, 0);
2831 ASSERT_TRUE(pass);
2832 err = vkAllocateMemory(device(), &buffer_alloc_info, NULL, &buffer_mem);
2833 ASSERT_VK_SUCCESS(err);
2834 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00797);
2835 err = vkBindBufferMemory(device(), buffer, buffer_mem, 0);
2836 (void)err; // This may very well return an error.
2837 m_errorMonitor->VerifyFound();
2838 vkFreeMemory(device(), buffer_mem, NULL);
Cort Strattonccc90e32017-02-04 13:47:42 -08002839 }
Cort Stratton4c38bb52017-01-28 13:33:10 -08002840
Cort Stratton4c38bb52017-01-28 13:33:10 -08002841 vkDestroyImage(device(), image, NULL);
2842 vkDestroyBuffer(device(), buffer, NULL);
2843 }
2844
Cort Strattonf1d8a4a2017-01-28 14:17:04 -08002845 // Try to bind memory to an image created with sparse memory flags
2846 {
2847 VkImageCreateInfo sparse_image_create_info = image_create_info;
2848 sparse_image_create_info.flags |= VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
2849 VkImageFormatProperties image_format_properties = {};
2850 err = vkGetPhysicalDeviceImageFormatProperties(m_device->phy().handle(), sparse_image_create_info.format,
2851 sparse_image_create_info.imageType, sparse_image_create_info.tiling,
2852 sparse_image_create_info.usage, sparse_image_create_info.flags,
2853 &image_format_properties);
2854 if (!m_device->phy().features().sparseResidencyImage2D || err == VK_ERROR_FORMAT_NOT_SUPPORTED) {
2855 // most likely means sparse formats aren't supported here; skip this test.
2856 } else {
2857 ASSERT_VK_SUCCESS(err);
2858 if (image_format_properties.maxExtent.width == 0) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07002859 printf(" Sparse image format not supported; skipped.\n");
Cort Strattonf1d8a4a2017-01-28 14:17:04 -08002860 return;
2861 } else {
2862 VkImage sparse_image = VK_NULL_HANDLE;
2863 err = vkCreateImage(m_device->device(), &sparse_image_create_info, NULL, &sparse_image);
2864 ASSERT_VK_SUCCESS(err);
2865 VkMemoryRequirements sparse_mem_reqs = {};
2866 vkGetImageMemoryRequirements(m_device->device(), sparse_image, &sparse_mem_reqs);
2867 if (sparse_mem_reqs.memoryTypeBits != 0) {
2868 VkMemoryAllocateInfo sparse_mem_alloc = {};
2869 sparse_mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2870 sparse_mem_alloc.pNext = NULL;
2871 sparse_mem_alloc.allocationSize = sparse_mem_reqs.size;
2872 sparse_mem_alloc.memoryTypeIndex = 0;
2873 pass = m_device->phy().set_memory_type(sparse_mem_reqs.memoryTypeBits, &sparse_mem_alloc, 0);
2874 ASSERT_TRUE(pass);
2875 VkDeviceMemory sparse_mem = VK_NULL_HANDLE;
2876 err = vkAllocateMemory(m_device->device(), &sparse_mem_alloc, NULL, &sparse_mem);
2877 ASSERT_VK_SUCCESS(err);
2878 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00804);
2879 err = vkBindImageMemory(m_device->device(), sparse_image, sparse_mem, 0);
2880 // This may very well return an error.
2881 (void)err;
2882 m_errorMonitor->VerifyFound();
2883 vkFreeMemory(m_device->device(), sparse_mem, NULL);
2884 }
2885 vkDestroyImage(m_device->device(), sparse_image, NULL);
2886 }
2887 }
2888 }
2889
2890 // Try to bind memory to a buffer created with sparse memory flags
2891 {
2892 VkBufferCreateInfo sparse_buffer_create_info = buffer_create_info;
2893 sparse_buffer_create_info.flags |= VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
2894 if (!m_device->phy().features().sparseResidencyBuffer) {
2895 // most likely means sparse formats aren't supported here; skip this test.
2896 } else {
2897 VkBuffer sparse_buffer = VK_NULL_HANDLE;
2898 err = vkCreateBuffer(m_device->device(), &sparse_buffer_create_info, NULL, &sparse_buffer);
2899 ASSERT_VK_SUCCESS(err);
2900 VkMemoryRequirements sparse_mem_reqs = {};
2901 vkGetBufferMemoryRequirements(m_device->device(), sparse_buffer, &sparse_mem_reqs);
2902 if (sparse_mem_reqs.memoryTypeBits != 0) {
2903 VkMemoryAllocateInfo sparse_mem_alloc = {};
2904 sparse_mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2905 sparse_mem_alloc.pNext = NULL;
2906 sparse_mem_alloc.allocationSize = sparse_mem_reqs.size;
2907 sparse_mem_alloc.memoryTypeIndex = 0;
2908 pass = m_device->phy().set_memory_type(sparse_mem_reqs.memoryTypeBits, &sparse_mem_alloc, 0);
2909 ASSERT_TRUE(pass);
2910 VkDeviceMemory sparse_mem = VK_NULL_HANDLE;
2911 err = vkAllocateMemory(m_device->device(), &sparse_mem_alloc, NULL, &sparse_mem);
2912 ASSERT_VK_SUCCESS(err);
2913 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00792);
2914 err = vkBindBufferMemory(m_device->device(), sparse_buffer, sparse_mem, 0);
2915 // This may very well return an error.
2916 (void)err;
2917 m_errorMonitor->VerifyFound();
2918 vkFreeMemory(m_device->device(), sparse_mem, NULL);
2919 }
2920 vkDestroyBuffer(m_device->device(), sparse_buffer, NULL);
2921 }
2922 }
Tobin Ehlisec598302015-09-15 15:02:17 -06002923}
2924
Karl Schultz6addd812016-02-02 17:17:23 -07002925TEST_F(VkLayerTest, BindMemoryToDestroyedObject) {
2926 VkResult err;
2927 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002928
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002929 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00808);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002930
Tony Barbour1fa09702017-03-16 12:09:08 -06002931 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisec598302015-09-15 15:02:17 -06002932
Karl Schultz6addd812016-02-02 17:17:23 -07002933 // Create an image object, allocate memory, destroy the object and then try
2934 // to bind it
2935 VkImage image;
2936 VkDeviceMemory mem;
2937 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06002938
Karl Schultz6addd812016-02-02 17:17:23 -07002939 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2940 const int32_t tex_width = 32;
2941 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06002942
2943 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002944 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2945 image_create_info.pNext = NULL;
2946 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2947 image_create_info.format = tex_format;
2948 image_create_info.extent.width = tex_width;
2949 image_create_info.extent.height = tex_height;
2950 image_create_info.extent.depth = 1;
2951 image_create_info.mipLevels = 1;
2952 image_create_info.arrayLayers = 1;
2953 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2954 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2955 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2956 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002957
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002958 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002959 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2960 mem_alloc.pNext = NULL;
2961 mem_alloc.allocationSize = 0;
2962 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002963
Chia-I Wuf7458c52015-10-26 21:10:41 +08002964 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06002965 ASSERT_VK_SUCCESS(err);
2966
Karl Schultz6addd812016-02-02 17:17:23 -07002967 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002968
2969 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002970 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002971 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002972
2973 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002974 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06002975 ASSERT_VK_SUCCESS(err);
2976
2977 // Introduce validation failure, destroy Image object before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08002978 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002979 ASSERT_VK_SUCCESS(err);
2980
2981 // Now Try to bind memory to this destroyed object
2982 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2983 // This may very well return an error.
Karl Schultz6addd812016-02-02 17:17:23 -07002984 (void)err;
Tobin Ehlisec598302015-09-15 15:02:17 -06002985
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002986 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002987
Chia-I Wuf7458c52015-10-26 21:10:41 +08002988 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002989}
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002990
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -07002991TEST_F(VkLayerTest, CreatePipelineBadVertexAttributeFormat) {
2992 TEST_DESCRIPTION("Test that pipeline validation catches invalid vertex attribute formats");
2993
Tony Barbour1fa09702017-03-16 12:09:08 -06002994 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -07002995 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2996
2997 VkVertexInputBindingDescription input_binding;
2998 memset(&input_binding, 0, sizeof(input_binding));
2999
3000 VkVertexInputAttributeDescription input_attribs;
3001 memset(&input_attribs, 0, sizeof(input_attribs));
3002
3003 // Pick a really bad format for this purpose and make sure it should fail
3004 input_attribs.format = VK_FORMAT_BC2_UNORM_BLOCK;
3005 VkFormatProperties format_props = m_device->format_properties(input_attribs.format);
3006 if ((format_props.bufferFeatures & VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT) != 0) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07003007 printf(" Format unsuitable for test; skipped.\n");
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -07003008 return;
3009 }
3010
3011 input_attribs.location = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003012 char const *vsSource =
3013 "#version 450\n"
3014 "\n"
3015 "out gl_PerVertex {\n"
3016 " vec4 gl_Position;\n"
3017 "};\n"
3018 "void main(){\n"
3019 " gl_Position = vec4(1);\n"
3020 "}\n";
3021 char const *fsSource =
3022 "#version 450\n"
3023 "\n"
3024 "layout(location=0) out vec4 color;\n"
3025 "void main(){\n"
3026 " color = vec4(1);\n"
3027 "}\n";
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -07003028
3029 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01413);
3030 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
3031 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
3032
3033 VkPipelineObj pipe(m_device);
3034 pipe.AddColorAttachment();
3035 pipe.AddShader(&vs);
3036 pipe.AddShader(&fs);
3037
3038 pipe.AddVertexInputBindings(&input_binding, 1);
3039 pipe.AddVertexInputAttribs(&input_attribs, 1);
3040
3041 VkDescriptorSetObj descriptorSet(m_device);
3042 descriptorSet.AppendDummy();
3043 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
3044
3045 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
3046
3047 m_errorMonitor->VerifyFound();
3048}
3049
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003050TEST_F(VkLayerTest, ImageSampleCounts) {
Jeremy Hayes0d104082017-02-21 10:24:16 -07003051 TEST_DESCRIPTION("Use bad sample counts in image transfer calls to trigger validation errors.");
Tony Barbour1fa09702017-03-16 12:09:08 -06003052 ASSERT_NO_FATAL_FAILURE(Init(nullptr, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT));
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003053
3054 VkMemoryPropertyFlags reqs = 0;
3055 VkImageCreateInfo image_create_info = {};
3056 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3057 image_create_info.pNext = NULL;
3058 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3059 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
3060 image_create_info.extent.width = 256;
3061 image_create_info.extent.height = 256;
3062 image_create_info.extent.depth = 1;
3063 image_create_info.mipLevels = 1;
3064 image_create_info.arrayLayers = 1;
3065 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
3066 image_create_info.flags = 0;
3067
3068 VkImageBlit blit_region = {};
3069 blit_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3070 blit_region.srcSubresource.baseArrayLayer = 0;
3071 blit_region.srcSubresource.layerCount = 1;
3072 blit_region.srcSubresource.mipLevel = 0;
3073 blit_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3074 blit_region.dstSubresource.baseArrayLayer = 0;
3075 blit_region.dstSubresource.layerCount = 1;
3076 blit_region.dstSubresource.mipLevel = 0;
3077
3078 // Create two images, the source with sampleCount = 2, and attempt to blit
3079 // between them
3080 {
3081 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003082 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003083 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003084 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003085 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003086 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003087 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003088 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003089 m_commandBuffer->BeginCommandBuffer();
Jeremy Hayes0d104082017-02-21 10:24:16 -07003090 m_errorMonitor->SetDesiredFailureMsg(
3091 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3092 "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 -06003093 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3094 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003095 m_errorMonitor->VerifyFound();
3096 m_commandBuffer->EndCommandBuffer();
3097 }
3098
3099 // Create two images, the dest with sampleCount = 4, and attempt to blit
3100 // between them
3101 {
3102 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003103 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003104 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003105 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003106 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003107 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003108 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003109 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003110 m_commandBuffer->BeginCommandBuffer();
Jeremy Hayes0d104082017-02-21 10:24:16 -07003111 m_errorMonitor->SetDesiredFailureMsg(
3112 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3113 "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 -06003114 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3115 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003116 m_errorMonitor->VerifyFound();
3117 m_commandBuffer->EndCommandBuffer();
3118 }
3119
3120 VkBufferImageCopy copy_region = {};
3121 copy_region.bufferRowLength = 128;
3122 copy_region.bufferImageHeight = 128;
3123 copy_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3124 copy_region.imageSubresource.layerCount = 1;
3125 copy_region.imageExtent.height = 64;
3126 copy_region.imageExtent.width = 64;
3127 copy_region.imageExtent.depth = 1;
3128
3129 // Create src buffer and dst image with sampleCount = 4 and attempt to copy
3130 // buffer to image
3131 {
3132 vk_testing::Buffer src_buffer;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003133 src_buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
3134 image_create_info.samples = VK_SAMPLE_COUNT_8_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003135 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003136 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003137 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003138 m_commandBuffer->BeginCommandBuffer();
Jeremy Hayes0d104082017-02-21 10:24:16 -07003139 m_errorMonitor->SetDesiredFailureMsg(
3140 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3141 "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 -06003142 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), src_buffer.handle(), dst_image.handle(),
3143 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &copy_region);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003144 m_errorMonitor->VerifyFound();
3145 m_commandBuffer->EndCommandBuffer();
3146 }
3147
3148 // Create dst buffer and src image with sampleCount = 2 and attempt to copy
3149 // image to buffer
3150 {
3151 vk_testing::Buffer dst_buffer;
3152 dst_buffer.init_as_dst(*m_device, 128 * 128 * 4, reqs);
3153 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003154 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003155 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003156 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003157 m_commandBuffer->BeginCommandBuffer();
Jeremy Hayes0d104082017-02-21 10:24:16 -07003158 m_errorMonitor->SetDesiredFailureMsg(
3159 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3160 "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 -06003161 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003162 dst_buffer.handle(), 1, &copy_region);
3163 m_errorMonitor->VerifyFound();
3164 m_commandBuffer->EndCommandBuffer();
3165 }
3166}
3167
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003168TEST_F(VkLayerTest, BlitImageFormats) {
Tony Barbour1fa09702017-03-16 12:09:08 -06003169 ASSERT_NO_FATAL_FAILURE(Init());
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003170
3171 VkImageObj src_image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06003172 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 -06003173 VkImageObj dst_image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06003174 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 -06003175 VkImageObj dst_image2(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06003176 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 -06003177
3178 VkImageBlit blitRegion = {};
3179 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3180 blitRegion.srcSubresource.baseArrayLayer = 0;
3181 blitRegion.srcSubresource.layerCount = 1;
3182 blitRegion.srcSubresource.mipLevel = 0;
3183 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3184 blitRegion.dstSubresource.baseArrayLayer = 0;
3185 blitRegion.dstSubresource.layerCount = 1;
3186 blitRegion.dstSubresource.mipLevel = 0;
3187
Dave Houlton34df4cb2016-12-01 16:43:06 -07003188 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02191);
3189
3190 // TODO: there are 9 permutations of signed, unsigned, & other for source and dest
3191 // this test is only checking 2 of them at the moment
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003192
3193 // Unsigned int vs not an int
Tony Barbour552f6c02016-12-21 14:34:07 -07003194 m_commandBuffer->BeginCommandBuffer();
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06003195 vkCmdBlitImage(m_commandBuffer->handle(), src_image.image(), src_image.Layout(), dst_image.image(), dst_image.Layout(), 1,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003196 &blitRegion, VK_FILTER_NEAREST);
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003197
3198 m_errorMonitor->VerifyFound();
3199
Dave Houlton34df4cb2016-12-01 16:43:06 -07003200 // Test should generate 2 VU failures
3201 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02190);
3202 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02191);
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003203
3204 // Unsigned int vs signed int
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06003205 vkCmdBlitImage(m_commandBuffer->handle(), src_image.image(), src_image.Layout(), dst_image2.image(), dst_image2.Layout(), 1,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003206 &blitRegion, VK_FILTER_NEAREST);
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003207
Dave Houlton34df4cb2016-12-01 16:43:06 -07003208 // TODO: Note that this only verifies that at least one of the VU enums was found
3209 // 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 -06003210 m_errorMonitor->VerifyFound();
3211
Tony Barbour552f6c02016-12-21 14:34:07 -07003212 m_commandBuffer->EndCommandBuffer();
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003213}
3214
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003215TEST_F(VkLayerTest, DSImageTransferGranularityTests) {
3216 VkResult err;
3217 bool pass;
3218
3219 TEST_DESCRIPTION("Tests for validaiton of Queue Family property minImageTransferGranularity.");
Tony Barbour1fa09702017-03-16 12:09:08 -06003220 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003221
3222 // If w/d/h granularity is 1, test is not meaningful
3223 // TODO: When virtual device limits are available, create a set of limits for this test that
3224 // will always have a granularity of > 1 for w, h, and d
3225 auto index = m_device->graphics_queue_node_index_;
3226 auto queue_family_properties = m_device->phy().queue_properties();
3227
3228 if ((queue_family_properties[index].minImageTransferGranularity.depth < 4) ||
3229 (queue_family_properties[index].minImageTransferGranularity.width < 4) ||
3230 (queue_family_properties[index].minImageTransferGranularity.height < 4)) {
3231 return;
3232 }
3233
3234 // Create two images of different types and try to copy between them
3235 VkImage srcImage;
3236 VkImage dstImage;
3237 VkDeviceMemory srcMem;
3238 VkDeviceMemory destMem;
3239 VkMemoryRequirements memReqs;
3240
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003241 VkImageCreateInfo image_create_info = {};
3242 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3243 image_create_info.pNext = NULL;
3244 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3245 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
3246 image_create_info.extent.width = 32;
3247 image_create_info.extent.height = 32;
3248 image_create_info.extent.depth = 1;
3249 image_create_info.mipLevels = 1;
3250 image_create_info.arrayLayers = 4;
3251 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
3252 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
3253 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
3254 image_create_info.flags = 0;
3255
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003256 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003257 ASSERT_VK_SUCCESS(err);
3258
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003259 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003260 ASSERT_VK_SUCCESS(err);
3261
3262 // Allocate memory
3263 VkMemoryAllocateInfo memAlloc = {};
3264 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
3265 memAlloc.pNext = NULL;
3266 memAlloc.allocationSize = 0;
3267 memAlloc.memoryTypeIndex = 0;
3268
3269 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
3270 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003271 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003272 ASSERT_TRUE(pass);
3273 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
3274 ASSERT_VK_SUCCESS(err);
3275
3276 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
3277 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003278 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003279 ASSERT_VK_SUCCESS(err);
3280 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
3281 ASSERT_VK_SUCCESS(err);
3282
3283 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
3284 ASSERT_VK_SUCCESS(err);
3285 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
3286 ASSERT_VK_SUCCESS(err);
3287
Tony Barbour552f6c02016-12-21 14:34:07 -07003288 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003289 VkImageCopy copyRegion;
3290 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3291 copyRegion.srcSubresource.mipLevel = 0;
3292 copyRegion.srcSubresource.baseArrayLayer = 0;
3293 copyRegion.srcSubresource.layerCount = 1;
3294 copyRegion.srcOffset.x = 0;
3295 copyRegion.srcOffset.y = 0;
3296 copyRegion.srcOffset.z = 0;
3297 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3298 copyRegion.dstSubresource.mipLevel = 0;
3299 copyRegion.dstSubresource.baseArrayLayer = 0;
3300 copyRegion.dstSubresource.layerCount = 1;
3301 copyRegion.dstOffset.x = 0;
3302 copyRegion.dstOffset.y = 0;
3303 copyRegion.dstOffset.z = 0;
3304 copyRegion.extent.width = 1;
3305 copyRegion.extent.height = 1;
3306 copyRegion.extent.depth = 1;
3307
3308 // Introduce failure by setting srcOffset to a bad granularity value
3309 copyRegion.srcOffset.y = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003310 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3311 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003312 m_errorMonitor->VerifyFound();
3313
3314 // Introduce failure by setting extent to a bad granularity value
3315 copyRegion.srcOffset.y = 0;
3316 copyRegion.extent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003317 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3318 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003319 m_errorMonitor->VerifyFound();
3320
3321 // Now do some buffer/image copies
3322 vk_testing::Buffer buffer;
3323 VkMemoryPropertyFlags reqs = 0;
3324 buffer.init_as_dst(*m_device, 128 * 128, reqs);
3325 VkBufferImageCopy region = {};
3326 region.bufferOffset = 0;
3327 region.bufferRowLength = 3;
3328 region.bufferImageHeight = 128;
3329 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3330 region.imageSubresource.layerCount = 1;
3331 region.imageExtent.height = 16;
3332 region.imageExtent.width = 16;
3333 region.imageExtent.depth = 1;
3334 region.imageOffset.x = 0;
3335 region.imageOffset.y = 0;
3336 region.imageOffset.z = 0;
3337
3338 // Introduce failure by setting bufferRowLength to a bad granularity value
3339 region.bufferRowLength = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003340 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3341 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
3342 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003343 m_errorMonitor->VerifyFound();
3344 region.bufferRowLength = 128;
3345
3346 // Introduce failure by setting bufferOffset to a bad granularity value
3347 region.bufferOffset = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003348 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3349 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
3350 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003351 m_errorMonitor->VerifyFound();
3352 region.bufferOffset = 0;
3353
3354 // Introduce failure by setting bufferImageHeight to a bad granularity value
3355 region.bufferImageHeight = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003356 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3357 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
3358 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003359 m_errorMonitor->VerifyFound();
3360 region.bufferImageHeight = 128;
3361
3362 // Introduce failure by setting imageExtent to a bad granularity value
3363 region.imageExtent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003364 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3365 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
3366 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003367 m_errorMonitor->VerifyFound();
3368 region.imageExtent.width = 16;
3369
3370 // Introduce failure by setting imageOffset to a bad granularity value
3371 region.imageOffset.z = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003372 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3373 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
3374 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003375 m_errorMonitor->VerifyFound();
3376
Tony Barbour552f6c02016-12-21 14:34:07 -07003377 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003378
3379 vkDestroyImage(m_device->device(), srcImage, NULL);
3380 vkDestroyImage(m_device->device(), dstImage, NULL);
3381 vkFreeMemory(m_device->device(), srcMem, NULL);
3382 vkFreeMemory(m_device->device(), destMem, NULL);
3383}
3384
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003385TEST_F(VkLayerTest, MismatchedQueueFamiliesOnSubmit) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003386 TEST_DESCRIPTION(
3387 "Submit command buffer created using one queue family and "
3388 "attempt to submit them on a queue created in a different "
3389 "queue family.");
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003390
Tony Barbour1fa09702017-03-16 12:09:08 -06003391 ASSERT_NO_FATAL_FAILURE(Init());
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07003392
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003393 // This test is meaningless unless we have multiple queue families
3394 auto queue_family_properties = m_device->phy().queue_properties();
3395 if (queue_family_properties.size() < 2) {
3396 return;
3397 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003398 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is being submitted on queue ");
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003399 // Get safe index of another queue family
3400 uint32_t other_queue_family = (m_device->graphics_queue_node_index_ == 0) ? 1 : 0;
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003401 VkQueue other_queue;
3402 vkGetDeviceQueue(m_device->device(), other_queue_family, 0, &other_queue);
3403
3404 // Record an empty cmd buffer
3405 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
3406 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3407 vkBeginCommandBuffer(m_commandBuffer->handle(), &cmdBufBeginDesc);
3408 vkEndCommandBuffer(m_commandBuffer->handle());
3409
3410 // And submit on the wrong queue
3411 VkSubmitInfo submit_info = {};
3412 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3413 submit_info.commandBufferCount = 1;
3414 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Tobin Ehlisfd213ea2016-08-10 17:10:46 -06003415 vkQueueSubmit(other_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003416
3417 m_errorMonitor->VerifyFound();
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003418}
3419
Chris Forbes4c24a922016-11-16 08:59:10 +13003420TEST_F(VkLayerTest, RenderPassAttachmentIndexOutOfRange) {
Tony Barbour1fa09702017-03-16 12:09:08 -06003421 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes4c24a922016-11-16 08:59:10 +13003422
Chris Forbes2d9b2a82016-11-21 10:45:39 +13003423 // There are no attachments, but refer to attachment 0.
3424 VkAttachmentReference ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbes4c24a922016-11-16 08:59:10 +13003425 VkSubpassDescription subpasses[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003426 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &ref, nullptr, nullptr, 0, nullptr},
Chris Forbes4c24a922016-11-16 08:59:10 +13003427 };
3428
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003429 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 1, subpasses, 0, nullptr};
Chris Forbes4c24a922016-11-16 08:59:10 +13003430 VkRenderPass rp;
3431
Chris Forbes2d9b2a82016-11-21 10:45:39 +13003432 // "... must be less than the total number of attachments ..."
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003433 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00325);
Chris Forbes4c24a922016-11-16 08:59:10 +13003434 vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3435 m_errorMonitor->VerifyFound();
3436}
3437
Chris Forbesa58c4522016-09-28 15:19:39 +13003438TEST_F(VkLayerTest, RenderPassPipelineSubpassMismatch) {
3439 TEST_DESCRIPTION("Use a pipeline for the wrong subpass in a render pass instance");
Tony Barbour1fa09702017-03-16 12:09:08 -06003440 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbesa58c4522016-09-28 15:19:39 +13003441
3442 // A renderpass with two subpasses, both writing the same attachment.
3443 VkAttachmentDescription attach[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003444 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3445 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_UNDEFINED,
3446 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesa58c4522016-09-28 15:19:39 +13003447 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003448 VkAttachmentReference ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbesa58c4522016-09-28 15:19:39 +13003449 VkSubpassDescription subpasses[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003450 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &ref, nullptr, nullptr, 0, nullptr},
3451 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &ref, nullptr, nullptr, 0, nullptr},
Chris Forbesa58c4522016-09-28 15:19:39 +13003452 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003453 VkSubpassDependency dep = {0,
3454 1,
3455 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
3456 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
3457 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
3458 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
3459 VK_DEPENDENCY_BY_REGION_BIT};
3460 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, attach, 2, subpasses, 1, &dep};
Chris Forbesa58c4522016-09-28 15:19:39 +13003461 VkRenderPass rp;
3462 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3463 ASSERT_VK_SUCCESS(err);
3464
3465 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06003466 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 +13003467 VkImageView imageView = image.targetView(VK_FORMAT_R8G8B8A8_UNORM);
3468
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003469 VkFramebufferCreateInfo fbci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &imageView, 32, 32, 1};
Chris Forbesa58c4522016-09-28 15:19:39 +13003470 VkFramebuffer fb;
3471 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
3472 ASSERT_VK_SUCCESS(err);
3473
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003474 char const *vsSource =
3475 "#version 450\n"
3476 "void main() { gl_Position = vec4(1); }\n";
3477 char const *fsSource =
3478 "#version 450\n"
3479 "layout(location=0) out vec4 color;\n"
3480 "void main() { color = vec4(1); }\n";
Chris Forbesa58c4522016-09-28 15:19:39 +13003481
3482 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
3483 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
3484 VkPipelineObj pipe(m_device);
3485 pipe.AddColorAttachment();
3486 pipe.AddShader(&vs);
3487 pipe.AddShader(&fs);
3488 VkViewport view_port = {};
3489 m_viewports.push_back(view_port);
3490 pipe.SetViewport(m_viewports);
3491 VkRect2D rect = {};
3492 m_scissors.push_back(rect);
3493 pipe.SetScissor(m_scissors);
3494
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003495 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 0, nullptr, 0, nullptr};
Chris Forbesa58c4522016-09-28 15:19:39 +13003496 VkPipelineLayout pl;
3497 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
3498 ASSERT_VK_SUCCESS(err);
3499 pipe.CreateVKPipeline(pl, rp);
3500
Tony Barbour552f6c02016-12-21 14:34:07 -07003501 m_commandBuffer->BeginCommandBuffer();
Chris Forbesa58c4522016-09-28 15:19:39 +13003502
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003503 VkRenderPassBeginInfo rpbi = {VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO,
3504 nullptr,
3505 rp,
3506 fb,
3507 {{
3508 0, 0,
3509 },
3510 {32, 32}},
3511 0,
3512 nullptr};
Chris Forbesa58c4522016-09-28 15:19:39 +13003513
3514 // subtest 1: bind in the wrong subpass
3515 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
3516 vkCmdNextSubpass(m_commandBuffer->handle(), VK_SUBPASS_CONTENTS_INLINE);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003517 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 +13003518 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
3519 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
3520 m_errorMonitor->VerifyFound();
3521
3522 vkCmdEndRenderPass(m_commandBuffer->handle());
3523
3524 // subtest 2: bind in correct subpass, then transition to next subpass
3525 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
3526 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
3527 vkCmdNextSubpass(m_commandBuffer->handle(), VK_SUBPASS_CONTENTS_INLINE);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003528 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 +13003529 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
3530 m_errorMonitor->VerifyFound();
3531
3532 vkCmdEndRenderPass(m_commandBuffer->handle());
3533
Tony Barbour552f6c02016-12-21 14:34:07 -07003534 m_commandBuffer->EndCommandBuffer();
Chris Forbesa58c4522016-09-28 15:19:39 +13003535
3536 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
3537 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
3538 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3539}
3540
Tony Barbour4e919972016-08-09 13:27:40 -06003541TEST_F(VkLayerTest, RenderPassInvalidRenderArea) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003542 TEST_DESCRIPTION(
3543 "Generate INVALID_RENDER_AREA error by beginning renderpass"
3544 "with extent outside of framebuffer");
Tony Barbour1fa09702017-03-16 12:09:08 -06003545 ASSERT_NO_FATAL_FAILURE(Init());
Tony Barbour4e919972016-08-09 13:27:40 -06003546 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3547
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003548 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3549 "Cannot execute a render pass with renderArea "
3550 "not within the bound of the framebuffer.");
Tony Barbour4e919972016-08-09 13:27:40 -06003551
3552 // Framebuffer for render target is 256x256, exceed that for INVALID_RENDER_AREA
3553 m_renderPassBeginInfo.renderArea.extent.width = 257;
3554 m_renderPassBeginInfo.renderArea.extent.height = 257;
Tony Barbour552f6c02016-12-21 14:34:07 -07003555 m_commandBuffer->BeginCommandBuffer();
3556 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tony Barbour4e919972016-08-09 13:27:40 -06003557 m_errorMonitor->VerifyFound();
3558}
3559
3560TEST_F(VkLayerTest, DisabledIndependentBlend) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003561 TEST_DESCRIPTION(
3562 "Generate INDEPENDENT_BLEND by disabling independent "
3563 "blend and then specifying different blend states for two "
3564 "attachements");
Cody Northrop5703cc72016-08-19 09:57:10 -06003565 VkPhysicalDeviceFeatures features = {};
3566 features.independentBlend = VK_FALSE;
Tony Barbour1fa09702017-03-16 12:09:08 -06003567 ASSERT_NO_FATAL_FAILURE(Init(&features));
Tony Barbour4e919972016-08-09 13:27:40 -06003568
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003569 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3570 "Invalid Pipeline CreateInfo: If independent blend feature not "
3571 "enabled, all elements of pAttachments must be identical");
Tony Barbour4e919972016-08-09 13:27:40 -06003572
Cody Northropc31a84f2016-08-22 10:41:47 -06003573 VkDescriptorSetObj descriptorSet(m_device);
3574 descriptorSet.AppendDummy();
3575 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Tony Barbour4e919972016-08-09 13:27:40 -06003576
Cody Northropc31a84f2016-08-22 10:41:47 -06003577 VkPipelineObj pipeline(m_device);
Tony Barbour0ace59a2017-02-06 13:38:36 -07003578 // Create a renderPass with two color attachments
3579 VkAttachmentReference attachments[2] = {};
3580 attachments[0].layout = VK_IMAGE_LAYOUT_GENERAL;
Tony Barbourffd60bd2017-03-09 12:04:55 -07003581 attachments[1].attachment = 1;
Tony Barbour0ace59a2017-02-06 13:38:36 -07003582 attachments[1].layout = VK_IMAGE_LAYOUT_GENERAL;
3583
3584 VkSubpassDescription subpass = {};
3585 subpass.pColorAttachments = attachments;
3586 subpass.colorAttachmentCount = 2;
3587
3588 VkRenderPassCreateInfo rpci = {};
3589 rpci.subpassCount = 1;
3590 rpci.pSubpasses = &subpass;
Tony Barbourffd60bd2017-03-09 12:04:55 -07003591 rpci.attachmentCount = 2;
Tony Barbour0ace59a2017-02-06 13:38:36 -07003592
Tony Barbourffd60bd2017-03-09 12:04:55 -07003593 VkAttachmentDescription attach_desc[2] = {};
3594 attach_desc[0].format = VK_FORMAT_B8G8R8A8_UNORM;
3595 attach_desc[0].samples = VK_SAMPLE_COUNT_1_BIT;
3596 attach_desc[0].initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
3597 attach_desc[0].finalLayout = VK_IMAGE_LAYOUT_GENERAL;
3598 attach_desc[1].format = VK_FORMAT_B8G8R8A8_UNORM;
3599 attach_desc[1].samples = VK_SAMPLE_COUNT_1_BIT;
3600 attach_desc[1].initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
3601 attach_desc[1].finalLayout = VK_IMAGE_LAYOUT_GENERAL;
Tony Barbour0ace59a2017-02-06 13:38:36 -07003602
Tony Barbourffd60bd2017-03-09 12:04:55 -07003603 rpci.pAttachments = attach_desc;
Tony Barbour0ace59a2017-02-06 13:38:36 -07003604 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3605
3606 VkRenderPass renderpass;
3607 vkCreateRenderPass(m_device->device(), &rpci, NULL, &renderpass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003608 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Cody Northropc31a84f2016-08-22 10:41:47 -06003609 pipeline.AddShader(&vs);
Cody Northrop5703cc72016-08-19 09:57:10 -06003610
Cody Northropc31a84f2016-08-22 10:41:47 -06003611 VkPipelineColorBlendAttachmentState att_state1 = {}, att_state2 = {};
3612 att_state1.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3613 att_state1.blendEnable = VK_TRUE;
3614 att_state2.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3615 att_state2.blendEnable = VK_FALSE;
3616 pipeline.AddColorAttachment(0, &att_state1);
3617 pipeline.AddColorAttachment(1, &att_state2);
Tony Barbour0ace59a2017-02-06 13:38:36 -07003618 pipeline.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderpass);
Cody Northropc31a84f2016-08-22 10:41:47 -06003619 m_errorMonitor->VerifyFound();
Tony Barbour0ace59a2017-02-06 13:38:36 -07003620 vkDestroyRenderPass(m_device->device(), renderpass, NULL);
Tony Barbour4e919972016-08-09 13:27:40 -06003621}
3622
Mike Weiblen40b160e2017-02-06 19:21:52 -07003623// Is the Pipeline compatible with the expectations of the Renderpass/subpasses?
3624TEST_F(VkLayerTest, PipelineRenderpassCompatibility) {
3625 TEST_DESCRIPTION(
3626 "Create a graphics pipeline that is incompatible with the requirements "
3627 "of its contained Renderpass/subpasses.");
Tony Barbour1fa09702017-03-16 12:09:08 -06003628 ASSERT_NO_FATAL_FAILURE(Init());
Mike Weiblen40b160e2017-02-06 19:21:52 -07003629
3630 VkDescriptorSetObj ds_obj(m_device);
3631 ds_obj.AppendDummy();
3632 ds_obj.CreateVKDescriptorSet(m_commandBuffer);
3633
3634 VkShaderObj vs_obj(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
3635
3636 VkPipelineColorBlendAttachmentState att_state1 = {};
3637 att_state1.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3638 att_state1.blendEnable = VK_TRUE;
3639
3640 VkRenderpassObj rp_obj(m_device);
3641
3642 {
3643 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02116);
3644 VkPipelineObj pipeline(m_device);
3645 pipeline.AddShader(&vs_obj);
3646 pipeline.AddColorAttachment(0, &att_state1);
3647
3648 VkGraphicsPipelineCreateInfo info = {};
3649 pipeline.InitGraphicsPipelineCreateInfo(&info);
3650 info.pColorBlendState = nullptr;
3651
3652 pipeline.CreateVKPipeline(ds_obj.GetPipelineLayout(), rp_obj.handle(), &info);
3653 m_errorMonitor->VerifyFound();
3654 }
3655}
3656
Cort Stratton7547f772017-05-04 15:18:52 -07003657TEST_F(VkLayerTest, CreateRenderPassAttachments) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003658 TEST_DESCRIPTION(
Cort Stratton7547f772017-05-04 15:18:52 -07003659 "Ensure that CreateRenderPass produces the expected validation errors "
3660 "when a subpass's attachments violate the valid usage conditions.");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003661
Tony Barbour1fa09702017-03-16 12:09:08 -06003662 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003663
Cort Stratton7547f772017-05-04 15:18:52 -07003664 std::vector<VkAttachmentDescription> attachments = {
3665 // input attachments
3666 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3667 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_GENERAL,
3668 VK_IMAGE_LAYOUT_GENERAL},
3669 // color attachments
3670 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3671 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3672 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3673 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3674 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3675 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3676 // depth attachment
3677 {0, VK_FORMAT_D24_UNORM_S8_UINT, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3678 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
3679 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL},
3680 // resolve attachment
3681 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3682 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3683 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3684 // preserve attachments
3685 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3686 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3687 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3688 };
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003689
Cort Stratton7547f772017-05-04 15:18:52 -07003690 std::vector<VkAttachmentReference> input = {
3691 {0, VK_IMAGE_LAYOUT_GENERAL},
3692 };
3693 std::vector<VkAttachmentReference> color = {
3694 {1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL}, {2, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3695 };
3696 VkAttachmentReference depth = {3, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
3697 std::vector<VkAttachmentReference> resolve = {
3698 {4, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL}, {VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3699 };
3700 std::vector<uint32_t> preserve = {5};
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003701
Cort Stratton7547f772017-05-04 15:18:52 -07003702 VkSubpassDescription subpass = {0,
3703 VK_PIPELINE_BIND_POINT_GRAPHICS,
3704 (uint32_t)input.size(),
3705 input.data(),
3706 (uint32_t)color.size(),
3707 color.data(),
3708 resolve.data(),
3709 &depth,
3710 (uint32_t)preserve.size(),
3711 preserve.data()};
3712
3713 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO,
3714 nullptr,
3715 0,
3716 (uint32_t)attachments.size(),
3717 attachments.data(),
3718 1,
3719 &subpass,
3720 0,
3721 nullptr};
3722
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003723 VkRenderPass rp;
Cort Stratton7547f772017-05-04 15:18:52 -07003724 VkResult err;
3725 // Test too many color attachments
3726 {
3727 std::vector<VkAttachmentReference> too_many_colors(m_device->props.limits.maxColorAttachments + 1, color[0]);
3728 subpass.colorAttachmentCount = (uint32_t)too_many_colors.size();
3729 subpass.pColorAttachments = too_many_colors.data();
3730 subpass.pResolveAttachments = NULL;
3731 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00348);
3732 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3733 m_errorMonitor->VerifyFound();
3734 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
3735 subpass.colorAttachmentCount = (uint32_t)color.size();
3736 subpass.pColorAttachments = color.data();
3737 subpass.pResolveAttachments = resolve.data();
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003738 }
Cort Stratton7547f772017-05-04 15:18:52 -07003739 // Test sample count mismatch between color buffers
3740 attachments[subpass.pColorAttachments[1].attachment].samples = VK_SAMPLE_COUNT_8_BIT;
3741 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00337);
3742 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
Chris Forbesc5389742016-06-29 11:49:23 +12003743 m_errorMonitor->VerifyFound();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003744 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
Cort Stratton7547f772017-05-04 15:18:52 -07003745 attachments[subpass.pColorAttachments[1].attachment].samples = attachments[subpass.pColorAttachments[0].attachment].samples;
3746 // Test sample count mismatch between color buffers and depth buffer
3747 attachments[subpass.pDepthStencilAttachment->attachment].samples = VK_SAMPLE_COUNT_8_BIT;
3748 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00337);
3749 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
Chris Forbesc5389742016-06-29 11:49:23 +12003750 m_errorMonitor->VerifyFound();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003751 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
Cort Stratton7547f772017-05-04 15:18:52 -07003752 attachments[subpass.pDepthStencilAttachment->attachment].samples = attachments[subpass.pColorAttachments[0].attachment].samples;
3753 // Test resolve attachment with UNUSED color attachment
3754 color[0].attachment = VK_ATTACHMENT_UNUSED;
3755 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00350);
3756 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
Chris Forbes3f128ef2016-06-29 14:58:53 +12003757 m_errorMonitor->VerifyFound();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003758 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
Cort Stratton7547f772017-05-04 15:18:52 -07003759 color[0].attachment = 1;
3760 // Test resolve from a single-sampled color attachment
3761 attachments[subpass.pColorAttachments[0].attachment].samples = VK_SAMPLE_COUNT_1_BIT;
3762 attachments[subpass.pColorAttachments[1].attachment].samples = VK_SAMPLE_COUNT_1_BIT; // avoid mismatch (00337)
3763 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00351);
3764 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3765 m_errorMonitor->VerifyFound();
3766 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
3767 attachments[subpass.pColorAttachments[0].attachment].samples = VK_SAMPLE_COUNT_4_BIT;
3768 attachments[subpass.pColorAttachments[1].attachment].samples = VK_SAMPLE_COUNT_4_BIT;
3769 // Test resolve to a multi-sampled resolve attachment
3770 attachments[subpass.pResolveAttachments[0].attachment].samples = VK_SAMPLE_COUNT_4_BIT;
3771 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00352);
3772 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3773 m_errorMonitor->VerifyFound();
3774 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
3775 attachments[subpass.pResolveAttachments[0].attachment].samples = VK_SAMPLE_COUNT_1_BIT;
3776 // Test with color/resolve format mismatch
3777 attachments[subpass.pColorAttachments[0].attachment].format = VK_FORMAT_R8G8B8A8_SRGB;
3778 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00353);
3779 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3780 m_errorMonitor->VerifyFound();
3781 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
3782 attachments[subpass.pColorAttachments[0].attachment].format = attachments[subpass.pResolveAttachments[0].attachment].format;
3783 // Test for UNUSED preserve attachments
3784 preserve[0] = VK_ATTACHMENT_UNUSED;
3785 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00356);
3786 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3787 m_errorMonitor->VerifyFound();
3788 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
3789 preserve[0] = 5;
3790 // Test for preserve attachments used elsewhere in the subpass
3791 color[0].attachment = preserve[0];
3792 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00357);
3793 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3794 m_errorMonitor->VerifyFound();
3795 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
3796 color[0].attachment = 1;
3797 // test for layout mismatch between input attachment and color attachment
3798 input[0].attachment = color[0].attachment;
3799 input[0].layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
3800 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00358);
3801 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3802 m_errorMonitor->VerifyFound();
3803 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
3804 input[0].attachment = 0;
3805 input[0].layout = VK_IMAGE_LAYOUT_GENERAL;
3806 // test for layout mismatch between input attachment and depth attachment
3807 input[0].attachment = depth.attachment;
3808 input[0].layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
3809 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00358);
3810 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3811 m_errorMonitor->VerifyFound();
3812 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
3813 input[0].attachment = 0;
3814 input[0].layout = VK_IMAGE_LAYOUT_GENERAL;
3815 // Test for attachment used first as input with loadOp=CLEAR
3816 {
3817 std::vector<VkSubpassDescription> subpasses = {subpass, subpass, subpass};
3818 subpasses[0].inputAttachmentCount = 0;
3819 subpasses[1].inputAttachmentCount = 0;
3820 attachments[input[0].attachment].loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
3821 VkRenderPassCreateInfo rpci_multipass = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO,
3822 nullptr,
3823 0,
3824 (uint32_t)attachments.size(),
3825 attachments.data(),
3826 (uint32_t)subpasses.size(),
3827 subpasses.data(),
3828 0,
3829 nullptr};
3830 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00349);
3831 err = vkCreateRenderPass(m_device->device(), &rpci_multipass, nullptr, &rp);
3832 m_errorMonitor->VerifyFound();
3833 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
3834 attachments[input[0].attachment].loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
3835 }
Chris Forbes3f128ef2016-06-29 14:58:53 +12003836}
3837
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003838TEST_F(VkLayerTest, FramebufferCreateErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003839 TEST_DESCRIPTION(
3840 "Hit errors when attempting to create a framebuffer :\n"
3841 " 1. Mismatch between framebuffer & renderPass attachmentCount\n"
3842 " 2. Use a color image as depthStencil attachment\n"
3843 " 3. Mismatch framebuffer & renderPass attachment formats\n"
3844 " 4. Mismatch framebuffer & renderPass attachment #samples\n"
3845 " 5. Framebuffer attachment w/ non-1 mip-levels\n"
3846 " 6. Framebuffer attachment where dimensions don't match\n"
Cort Stratton8133ec22017-04-27 16:25:03 +02003847 " 7. Framebuffer attachment where dimensions don't match\n"
3848 " 8. Framebuffer attachment w/o identity swizzle\n"
3849 " 9. framebuffer dimensions exceed physical device limits\n");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003850
Tony Barbour1fa09702017-03-16 12:09:08 -06003851 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003852 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3853
Cort Stratton8133ec22017-04-27 16:25:03 +02003854 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00404);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003855
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003856 // Create a renderPass with a single color attachment
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003857 VkAttachmentReference attach = {};
3858 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
3859 VkSubpassDescription subpass = {};
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003860 subpass.pColorAttachments = &attach;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003861 VkRenderPassCreateInfo rpci = {};
3862 rpci.subpassCount = 1;
3863 rpci.pSubpasses = &subpass;
3864 rpci.attachmentCount = 1;
3865 VkAttachmentDescription attach_desc = {};
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003866 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003867 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003868 rpci.pAttachments = &attach_desc;
3869 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3870 VkRenderPass rp;
3871 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3872 ASSERT_VK_SUCCESS(err);
3873
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003874 VkImageView ivs[2];
3875 ivs[0] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
3876 ivs[1] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003877 VkFramebufferCreateInfo fb_info = {};
3878 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
3879 fb_info.pNext = NULL;
3880 fb_info.renderPass = rp;
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003881 // Set mis-matching attachmentCount
3882 fb_info.attachmentCount = 2;
3883 fb_info.pAttachments = ivs;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003884 fb_info.width = 100;
3885 fb_info.height = 100;
3886 fb_info.layers = 1;
3887
3888 VkFramebuffer fb;
3889 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3890
3891 m_errorMonitor->VerifyFound();
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003892 if (err == VK_SUCCESS) {
3893 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3894 }
3895 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003896
3897 // Create a renderPass with a depth-stencil attachment created with
3898 // IMAGE_USAGE_COLOR_ATTACHMENT
3899 // Add our color attachment to pDepthStencilAttachment
3900 subpass.pDepthStencilAttachment = &attach;
3901 subpass.pColorAttachments = NULL;
3902 VkRenderPass rp_ds;
3903 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp_ds);
3904 ASSERT_VK_SUCCESS(err);
3905 // Set correct attachment count, but attachment has COLOR usage bit set
3906 fb_info.attachmentCount = 1;
3907 fb_info.renderPass = rp_ds;
3908
Cort Stratton8133ec22017-04-27 16:25:03 +02003909 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00406);
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003910 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3911
3912 m_errorMonitor->VerifyFound();
3913 if (err == VK_SUCCESS) {
3914 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3915 }
3916 vkDestroyRenderPass(m_device->device(), rp_ds, NULL);
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003917
3918 // Create new renderpass with alternate attachment format from fb
3919 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
3920 subpass.pDepthStencilAttachment = NULL;
3921 subpass.pColorAttachments = &attach;
3922 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3923 ASSERT_VK_SUCCESS(err);
3924
3925 // Cause error due to mis-matched formats between rp & fb
3926 // rp attachment 0 now has RGBA8 but corresponding fb attach is BGRA8
3927 fb_info.renderPass = rp;
Cort Stratton8133ec22017-04-27 16:25:03 +02003928 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00408);
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003929 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3930
3931 m_errorMonitor->VerifyFound();
3932 if (err == VK_SUCCESS) {
3933 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3934 }
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003935 vkDestroyRenderPass(m_device->device(), rp, NULL);
3936
3937 // Create new renderpass with alternate sample count from fb
3938 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
3939 attach_desc.samples = VK_SAMPLE_COUNT_4_BIT;
3940 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3941 ASSERT_VK_SUCCESS(err);
3942
3943 // Cause error due to mis-matched sample count between rp & fb
3944 fb_info.renderPass = rp;
Cort Stratton8133ec22017-04-27 16:25:03 +02003945 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00409);
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003946 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3947
3948 m_errorMonitor->VerifyFound();
3949 if (err == VK_SUCCESS) {
3950 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3951 }
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003952
3953 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003954
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06003955 {
3956 // Create an image with 2 mip levels.
3957 VkImageObj image(m_device);
3958 image.Init(128, 128, 2, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
3959 ASSERT_TRUE(image.initialized());
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003960
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06003961 // Create a image view with two mip levels.
3962 VkImageView view;
3963 VkImageViewCreateInfo ivci = {};
3964 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
3965 ivci.image = image.handle();
3966 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
3967 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
3968 ivci.subresourceRange.layerCount = 1;
3969 ivci.subresourceRange.baseMipLevel = 0;
3970 // Set level count to 2 (only 1 is allowed for FB attachment)
3971 ivci.subresourceRange.levelCount = 2;
3972 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3973 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
3974 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003975
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06003976 // Re-create renderpass to have matching sample count
3977 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
3978 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3979 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003980
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06003981 fb_info.renderPass = rp;
3982 fb_info.pAttachments = &view;
Cort Stratton8133ec22017-04-27 16:25:03 +02003983 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00411);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06003984 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3985
3986 m_errorMonitor->VerifyFound();
3987 if (err == VK_SUCCESS) {
3988 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3989 }
3990 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003991 }
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06003992
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003993 // Update view to original color buffer and grow FB dimensions too big
3994 fb_info.pAttachments = ivs;
3995 fb_info.height = 1024;
3996 fb_info.width = 1024;
3997 fb_info.layers = 2;
Cort Stratton8133ec22017-04-27 16:25:03 +02003998 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00410);
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003999 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4000
4001 m_errorMonitor->VerifyFound();
4002 if (err == VK_SUCCESS) {
4003 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4004 }
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06004005
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06004006 {
4007 // Create an image with one mip level.
4008 VkImageObj image(m_device);
4009 image.Init(128, 128, 1, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
4010 ASSERT_TRUE(image.initialized());
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06004011
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06004012 // Create view attachment with non-identity swizzle
4013 VkImageView view;
4014 VkImageViewCreateInfo ivci = {};
4015 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
4016 ivci.image = image.handle();
4017 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
4018 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
4019 ivci.subresourceRange.layerCount = 1;
4020 ivci.subresourceRange.baseMipLevel = 0;
4021 ivci.subresourceRange.levelCount = 1;
4022 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4023 ivci.components.r = VK_COMPONENT_SWIZZLE_G;
4024 ivci.components.g = VK_COMPONENT_SWIZZLE_R;
4025 ivci.components.b = VK_COMPONENT_SWIZZLE_A;
4026 ivci.components.a = VK_COMPONENT_SWIZZLE_B;
4027 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
4028 ASSERT_VK_SUCCESS(err);
4029
4030 fb_info.pAttachments = &view;
4031 fb_info.height = 100;
4032 fb_info.width = 100;
4033 fb_info.layers = 1;
4034
Cort Stratton8133ec22017-04-27 16:25:03 +02004035 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00412);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06004036 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4037
4038 m_errorMonitor->VerifyFound();
4039 if (err == VK_SUCCESS) {
4040 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4041 }
4042 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06004043 }
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06004044
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004045 // reset attachment to color attachment
4046 fb_info.pAttachments = ivs;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004047
4048 // Request fb that exceeds max width
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004049 fb_info.width = m_device->props.limits.maxFramebufferWidth + 1;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004050 fb_info.height = 100;
4051 fb_info.layers = 1;
4052 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00413);
Cort Stratton8133ec22017-04-27 16:25:03 +02004053 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00410);
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004054 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
Cort Stratton8133ec22017-04-27 16:25:03 +02004055 m_errorMonitor->VerifyFound();
4056 if (err == VK_SUCCESS) {
4057 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4058 }
4059 // and width=0
4060 fb_info.width = 0;
4061 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02806);
4062 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004063 m_errorMonitor->VerifyFound();
4064 if (err == VK_SUCCESS) {
4065 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4066 }
4067
4068 // Request fb that exceeds max height
4069 fb_info.width = 100;
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004070 fb_info.height = m_device->props.limits.maxFramebufferHeight + 1;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004071 fb_info.layers = 1;
4072 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00414);
Cort Stratton8133ec22017-04-27 16:25:03 +02004073 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00410);
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004074 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
Cort Stratton8133ec22017-04-27 16:25:03 +02004075 m_errorMonitor->VerifyFound();
4076 if (err == VK_SUCCESS) {
4077 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4078 }
4079 // and height=0
4080 fb_info.height = 0;
4081 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02807);
4082 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004083 m_errorMonitor->VerifyFound();
4084 if (err == VK_SUCCESS) {
4085 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4086 }
4087
4088 // Request fb that exceeds max layers
4089 fb_info.width = 100;
4090 fb_info.height = 100;
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004091 fb_info.layers = m_device->props.limits.maxFramebufferLayers + 1;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004092 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00415);
Cort Stratton8133ec22017-04-27 16:25:03 +02004093 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00410);
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004094 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
Cort Stratton8133ec22017-04-27 16:25:03 +02004095 m_errorMonitor->VerifyFound();
4096 if (err == VK_SUCCESS) {
4097 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4098 }
4099 // and layers=0
4100 fb_info.layers = 0;
4101 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02808);
4102 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004103 m_errorMonitor->VerifyFound();
4104 if (err == VK_SUCCESS) {
4105 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4106 }
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06004107
Tobin Ehlis6cfda642016-06-22 16:12:58 -06004108 vkDestroyRenderPass(m_device->device(), rp, NULL);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004109}
4110
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004111TEST_F(VkLayerTest, DynamicDepthBiasNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004112 TEST_DESCRIPTION(
4113 "Run a simple draw calls to validate failure when Depth Bias dynamic "
4114 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004115
Tony Barbour1fa09702017-03-16 12:09:08 -06004116 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004117 // Dynamic depth bias
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004118 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic depth bias state not set for this command buffer");
4119 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBias);
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004120 m_errorMonitor->VerifyFound();
4121}
4122
4123TEST_F(VkLayerTest, DynamicLineWidthNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004124 TEST_DESCRIPTION(
4125 "Run a simple draw calls to validate failure when Line Width dynamic "
4126 "state is required but not correctly bound.");
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004127
Tony Barbour1fa09702017-03-16 12:09:08 -06004128 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004129 // Dynamic line width
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004130 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic line width state not set for this command buffer");
4131 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailLineWidth);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004132 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004133}
4134
4135TEST_F(VkLayerTest, DynamicViewportNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004136 TEST_DESCRIPTION(
4137 "Run a simple draw calls to validate failure when Viewport dynamic "
4138 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004139
Tony Barbour1fa09702017-03-16 12:09:08 -06004140 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004141 // Dynamic viewport state
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07004142 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4143 "Dynamic viewport(s) 0 are used by pipeline state object, but were not provided");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004144 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailViewport);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004145 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004146}
4147
4148TEST_F(VkLayerTest, DynamicScissorNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004149 TEST_DESCRIPTION(
4150 "Run a simple draw calls to validate failure when Scissor dynamic "
4151 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004152
Tony Barbour1fa09702017-03-16 12:09:08 -06004153 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004154 // Dynamic scissor state
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07004155 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4156 "Dynamic scissor(s) 0 are used by pipeline state object, but were not provided");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004157 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailScissor);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004158 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004159}
4160
Cortd713fe82016-07-27 09:51:27 -07004161TEST_F(VkLayerTest, DynamicBlendConstantsNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004162 TEST_DESCRIPTION(
4163 "Run a simple draw calls to validate failure when Blend Constants "
4164 "dynamic state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004165
Tony Barbour1fa09702017-03-16 12:09:08 -06004166 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis21c88352016-05-26 06:15:45 -06004167 // Dynamic blend constant state
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004168 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4169 "Dynamic blend constants state not set for this command buffer");
4170 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailBlend);
Tobin Ehlis21c88352016-05-26 06:15:45 -06004171 m_errorMonitor->VerifyFound();
4172}
4173
4174TEST_F(VkLayerTest, DynamicDepthBoundsNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004175 TEST_DESCRIPTION(
4176 "Run a simple draw calls to validate failure when Depth Bounds dynamic "
4177 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004178
Tony Barbour1fa09702017-03-16 12:09:08 -06004179 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis21c88352016-05-26 06:15:45 -06004180 if (!m_device->phy().features().depthBounds) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07004181 printf(" Device does not support depthBounds test; skipped.\n");
Tobin Ehlis21c88352016-05-26 06:15:45 -06004182 return;
4183 }
4184 // Dynamic depth bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004185 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4186 "Dynamic depth bounds state not set for this command buffer");
4187 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBounds);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004188 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004189}
4190
4191TEST_F(VkLayerTest, DynamicStencilReadNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004192 TEST_DESCRIPTION(
4193 "Run a simple draw calls to validate failure when Stencil Read dynamic "
4194 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004195
Tony Barbour1fa09702017-03-16 12:09:08 -06004196 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004197 // Dynamic stencil read mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004198 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4199 "Dynamic stencil read mask state not set for this command buffer");
4200 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReadMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004201 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004202}
4203
4204TEST_F(VkLayerTest, DynamicStencilWriteNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004205 TEST_DESCRIPTION(
4206 "Run a simple draw calls to validate failure when Stencil Write dynamic"
4207 " state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004208
Tony Barbour1fa09702017-03-16 12:09:08 -06004209 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004210 // Dynamic stencil write mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004211 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4212 "Dynamic stencil write mask state not set for this command buffer");
4213 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilWriteMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004214 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004215}
4216
4217TEST_F(VkLayerTest, DynamicStencilRefNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004218 TEST_DESCRIPTION(
4219 "Run a simple draw calls to validate failure when Stencil Ref dynamic "
4220 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004221
Tony Barbour1fa09702017-03-16 12:09:08 -06004222 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004223 // Dynamic stencil reference
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004224 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4225 "Dynamic stencil reference state not set for this command buffer");
4226 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReference);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004227 m_errorMonitor->VerifyFound();
Tobin Ehlis963a4042015-09-29 08:18:34 -06004228}
4229
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06004230TEST_F(VkLayerTest, IndexBufferNotBound) {
4231 TEST_DESCRIPTION("Run an indexed draw call without an index buffer bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004232
Tony Barbour1fa09702017-03-16 12:09:08 -06004233 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004234 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4235 "Index buffer object not bound to this command buffer when Indexed ");
4236 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailIndexBuffer);
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06004237 m_errorMonitor->VerifyFound();
4238}
4239
Karl Schultz6addd812016-02-02 17:17:23 -07004240TEST_F(VkLayerTest, CommandBufferTwoSubmits) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004241 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4242 "was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has "
4243 "been submitted");
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004244
Tony Barbour1fa09702017-03-16 12:09:08 -06004245 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004246 ASSERT_NO_FATAL_FAILURE(InitViewport());
4247 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4248
Karl Schultz6addd812016-02-02 17:17:23 -07004249 // We luck out b/c by default the framework creates CB w/ the
4250 // VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set
Tony Barbour552f6c02016-12-21 14:34:07 -07004251 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004252 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbour552f6c02016-12-21 14:34:07 -07004253 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004254
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004255 // Bypass framework since it does the waits automatically
4256 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06004257 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08004258 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4259 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004260 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06004261 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07004262 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004263 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004264 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08004265 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06004266 submit_info.pSignalSemaphores = NULL;
4267
Chris Forbes40028e22016-06-13 09:59:34 +12004268 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Karl Schultz6addd812016-02-02 17:17:23 -07004269 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski89cad1a2016-11-11 15:51:31 -07004270 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004271
Karl Schultz6addd812016-02-02 17:17:23 -07004272 // Cause validation error by re-submitting cmd buffer that should only be
4273 // submitted once
Chris Forbes40028e22016-06-13 09:59:34 +12004274 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski89cad1a2016-11-11 15:51:31 -07004275 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004276
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004277 m_errorMonitor->VerifyFound();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004278}
4279
Karl Schultz6addd812016-02-02 17:17:23 -07004280TEST_F(VkLayerTest, AllocDescriptorFromEmptyPool) {
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004281 TEST_DESCRIPTION("Attempt to allocate more sets and descriptors than descriptor pool has available.");
Karl Schultz6addd812016-02-02 17:17:23 -07004282 VkResult err;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004283
Tony Barbour1fa09702017-03-16 12:09:08 -06004284 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004285 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004286
Karl Schultz6addd812016-02-02 17:17:23 -07004287 // Create Pool w/ 1 Sampler descriptor, but try to alloc Uniform Buffer
4288 // descriptor from it
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004289 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004290 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004291 ds_type_count.descriptorCount = 2;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004292
4293 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004294 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4295 ds_pool_ci.pNext = NULL;
4296 ds_pool_ci.flags = 0;
4297 ds_pool_ci.maxSets = 1;
4298 ds_pool_ci.poolSizeCount = 1;
4299 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004300
4301 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004302 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004303 ASSERT_VK_SUCCESS(err);
4304
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004305 VkDescriptorSetLayoutBinding dsl_binding_samp = {};
4306 dsl_binding_samp.binding = 0;
4307 dsl_binding_samp.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
4308 dsl_binding_samp.descriptorCount = 1;
4309 dsl_binding_samp.stageFlags = VK_SHADER_STAGE_ALL;
4310 dsl_binding_samp.pImmutableSamplers = NULL;
4311
4312 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4313 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4314 ds_layout_ci.pNext = NULL;
4315 ds_layout_ci.bindingCount = 1;
4316 ds_layout_ci.pBindings = &dsl_binding_samp;
4317
4318 VkDescriptorSetLayout ds_layout_samp;
4319 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_samp);
4320 ASSERT_VK_SUCCESS(err);
4321
4322 // Try to allocate 2 sets when pool only has 1 set
4323 VkDescriptorSet descriptor_sets[2];
4324 VkDescriptorSetLayout set_layouts[2] = {ds_layout_samp, ds_layout_samp};
4325 VkDescriptorSetAllocateInfo alloc_info = {};
4326 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4327 alloc_info.descriptorSetCount = 2;
4328 alloc_info.descriptorPool = ds_pool;
4329 alloc_info.pSetLayouts = set_layouts;
4330 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00911);
4331 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
4332 m_errorMonitor->VerifyFound();
4333
4334 alloc_info.descriptorSetCount = 1;
4335 // Create layout w/ descriptor type not available in pool
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004336 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004337 dsl_binding.binding = 0;
4338 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4339 dsl_binding.descriptorCount = 1;
4340 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4341 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004342
Karl Schultz6addd812016-02-02 17:17:23 -07004343 ds_layout_ci.bindingCount = 1;
4344 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004345
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004346 VkDescriptorSetLayout ds_layout_ub;
4347 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_ub);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004348 ASSERT_VK_SUCCESS(err);
4349
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004350 VkDescriptorSet descriptor_set;
Jon Ashburnf19916e2016-01-11 13:12:43 -07004351 alloc_info.descriptorSetCount = 1;
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004352 alloc_info.pSetLayouts = &ds_layout_ub;
4353 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00912);
4354 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004355
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004356 m_errorMonitor->VerifyFound();
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004357
Karl Schultz2825ab92016-12-02 08:23:14 -07004358 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_samp, NULL);
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004359 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_ub, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +08004360 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004361}
4362
Karl Schultz6addd812016-02-02 17:17:23 -07004363TEST_F(VkLayerTest, FreeDescriptorFromOneShotPool) {
4364 VkResult err;
Tobin Ehlise735c692015-10-08 13:13:50 -06004365
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07004366 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00922);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004367
Tony Barbour1fa09702017-03-16 12:09:08 -06004368 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlise735c692015-10-08 13:13:50 -06004369 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise735c692015-10-08 13:13:50 -06004370
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004371 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004372 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4373 ds_type_count.descriptorCount = 1;
Tobin Ehlise735c692015-10-08 13:13:50 -06004374
4375 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004376 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4377 ds_pool_ci.pNext = NULL;
4378 ds_pool_ci.maxSets = 1;
4379 ds_pool_ci.poolSizeCount = 1;
4380 ds_pool_ci.flags = 0;
4381 // Not specifying VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT means
4382 // app can only call vkResetDescriptorPool on this pool.;
4383 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise735c692015-10-08 13:13:50 -06004384
4385 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004386 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise735c692015-10-08 13:13:50 -06004387 ASSERT_VK_SUCCESS(err);
4388
4389 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004390 dsl_binding.binding = 0;
4391 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4392 dsl_binding.descriptorCount = 1;
4393 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4394 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise735c692015-10-08 13:13:50 -06004395
4396 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004397 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4398 ds_layout_ci.pNext = NULL;
4399 ds_layout_ci.bindingCount = 1;
4400 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise735c692015-10-08 13:13:50 -06004401
4402 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004403 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise735c692015-10-08 13:13:50 -06004404 ASSERT_VK_SUCCESS(err);
4405
4406 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004407 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08004408 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07004409 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06004410 alloc_info.descriptorPool = ds_pool;
4411 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004412 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise735c692015-10-08 13:13:50 -06004413 ASSERT_VK_SUCCESS(err);
4414
4415 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004416 m_errorMonitor->VerifyFound();
Tobin Ehlise735c692015-10-08 13:13:50 -06004417
Chia-I Wuf7458c52015-10-26 21:10:41 +08004418 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4419 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise735c692015-10-08 13:13:50 -06004420}
4421
Karl Schultz6addd812016-02-02 17:17:23 -07004422TEST_F(VkLayerTest, InvalidDescriptorPool) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004423 // Attempt to clear Descriptor Pool with bad object.
4424 // ObjectTracker should catch this.
Cody Northropc31a84f2016-08-22 10:41:47 -06004425
Tony Barbour1fa09702017-03-16 12:09:08 -06004426 ASSERT_NO_FATAL_FAILURE(Init());
Karl Schultzf78bcdd2016-11-30 12:36:01 -07004427 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00930);
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004428 uint64_t fake_pool_handle = 0xbaad6001;
4429 VkDescriptorPool bad_pool = reinterpret_cast<VkDescriptorPool &>(fake_pool_handle);
4430 vkResetDescriptorPool(device(), bad_pool, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -06004431 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004432}
4433
Karl Schultzf78bcdd2016-11-30 12:36:01 -07004434TEST_F(VkLayerTest, InvalidDescriptorSet) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004435 // Attempt to bind an invalid Descriptor Set to a valid Command Buffer
4436 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004437 // Create a valid cmd buffer
Karl Schultzbdb75952016-04-19 11:36:49 -06004438 // call vkCmdBindDescriptorSets w/ false Descriptor Set
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004439
4440 uint64_t fake_set_handle = 0xbaad6001;
4441 VkDescriptorSet bad_set = reinterpret_cast<VkDescriptorSet &>(fake_set_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06004442 VkResult err;
Karl Schultzf78bcdd2016-11-30 12:36:01 -07004443 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00982);
Karl Schultzbdb75952016-04-19 11:36:49 -06004444
Tony Barbour1fa09702017-03-16 12:09:08 -06004445 ASSERT_NO_FATAL_FAILURE(Init());
Karl Schultzbdb75952016-04-19 11:36:49 -06004446
4447 VkDescriptorSetLayoutBinding layout_bindings[1] = {};
4448 layout_bindings[0].binding = 0;
4449 layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4450 layout_bindings[0].descriptorCount = 1;
4451 layout_bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
4452 layout_bindings[0].pImmutableSamplers = NULL;
4453
4454 VkDescriptorSetLayout descriptor_set_layout;
4455 VkDescriptorSetLayoutCreateInfo dslci = {};
4456 dslci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4457 dslci.pNext = NULL;
4458 dslci.bindingCount = 1;
4459 dslci.pBindings = layout_bindings;
4460 err = vkCreateDescriptorSetLayout(device(), &dslci, NULL, &descriptor_set_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06004461 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06004462
4463 VkPipelineLayout pipeline_layout;
4464 VkPipelineLayoutCreateInfo plci = {};
4465 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4466 plci.pNext = NULL;
4467 plci.setLayoutCount = 1;
4468 plci.pSetLayouts = &descriptor_set_layout;
4469 err = vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06004470 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06004471
Tony Barbour552f6c02016-12-21 14:34:07 -07004472 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004473 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &bad_set, 0,
4474 NULL);
Karl Schultzbdb75952016-04-19 11:36:49 -06004475 m_errorMonitor->VerifyFound();
Tony Barbour552f6c02016-12-21 14:34:07 -07004476 m_commandBuffer->EndCommandBuffer();
Karl Schultzbdb75952016-04-19 11:36:49 -06004477 vkDestroyPipelineLayout(device(), pipeline_layout, NULL);
4478 vkDestroyDescriptorSetLayout(device(), descriptor_set_layout, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004479}
4480
Karl Schultz6addd812016-02-02 17:17:23 -07004481TEST_F(VkLayerTest, InvalidDescriptorSetLayout) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004482 // Attempt to create a Pipeline Layout with an invalid Descriptor Set Layout.
4483 // ObjectTracker should catch this.
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004484 uint64_t fake_layout_handle = 0xbaad6001;
4485 VkDescriptorSetLayout bad_layout = reinterpret_cast<VkDescriptorSetLayout &>(fake_layout_handle);
Karl Schultzf78bcdd2016-11-30 12:36:01 -07004486 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00875);
Tony Barbour1fa09702017-03-16 12:09:08 -06004487 ASSERT_NO_FATAL_FAILURE(Init());
Karl Schultzbdb75952016-04-19 11:36:49 -06004488 VkPipelineLayout pipeline_layout;
4489 VkPipelineLayoutCreateInfo plci = {};
4490 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4491 plci.pNext = NULL;
4492 plci.setLayoutCount = 1;
4493 plci.pSetLayouts = &bad_layout;
4494 vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
4495
4496 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004497}
4498
Mark Muellerd4914412016-06-13 17:52:06 -06004499TEST_F(VkLayerTest, WriteDescriptorSetIntegrityCheck) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004500 TEST_DESCRIPTION(
4501 "This test verifies some requirements of chapter 13.2.3 of the Vulkan Spec "
4502 "1) A uniform buffer update must have a valid buffer index."
4503 "2) When using an array of descriptors in a single WriteDescriptor,"
4504 " the descriptor types and stageflags must all be the same."
4505 "3) Immutable Sampler state must match across descriptors");
Mark Muellerd4914412016-06-13 17:52:06 -06004506
Mike Weiblena6666382017-01-05 15:16:11 -07004507 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00941);
Mark Muellerd4914412016-06-13 17:52:06 -06004508
Tony Barbour1fa09702017-03-16 12:09:08 -06004509 ASSERT_NO_FATAL_FAILURE(Init());
Mark Muellerd4914412016-06-13 17:52:06 -06004510 VkDescriptorPoolSize ds_type_count[4] = {};
4511 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4512 ds_type_count[0].descriptorCount = 1;
Tony Barboure132c5f2016-12-12 11:50:20 -07004513 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Muellerd4914412016-06-13 17:52:06 -06004514 ds_type_count[1].descriptorCount = 1;
Tony Barboure132c5f2016-12-12 11:50:20 -07004515 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Muellerd4914412016-06-13 17:52:06 -06004516 ds_type_count[2].descriptorCount = 1;
4517 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
4518 ds_type_count[3].descriptorCount = 1;
4519
4520 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4521 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4522 ds_pool_ci.maxSets = 1;
4523 ds_pool_ci.poolSizeCount = sizeof(ds_type_count) / sizeof(VkDescriptorPoolSize);
4524 ds_pool_ci.pPoolSizes = ds_type_count;
4525
4526 VkDescriptorPool ds_pool;
4527 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
4528 ASSERT_VK_SUCCESS(err);
4529
Mark Muellerb9896722016-06-16 09:54:29 -06004530 VkDescriptorSetLayoutBinding layout_binding[3] = {};
Mark Muellerd4914412016-06-13 17:52:06 -06004531 layout_binding[0].binding = 0;
4532 layout_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4533 layout_binding[0].descriptorCount = 1;
4534 layout_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
4535 layout_binding[0].pImmutableSamplers = NULL;
4536
4537 layout_binding[1].binding = 1;
4538 layout_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
4539 layout_binding[1].descriptorCount = 1;
4540 layout_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4541 layout_binding[1].pImmutableSamplers = NULL;
4542
4543 VkSamplerCreateInfo sampler_ci = {};
4544 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
4545 sampler_ci.pNext = NULL;
4546 sampler_ci.magFilter = VK_FILTER_NEAREST;
4547 sampler_ci.minFilter = VK_FILTER_NEAREST;
4548 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
4549 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4550 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4551 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4552 sampler_ci.mipLodBias = 1.0;
4553 sampler_ci.anisotropyEnable = VK_FALSE;
4554 sampler_ci.maxAnisotropy = 1;
4555 sampler_ci.compareEnable = VK_FALSE;
4556 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
4557 sampler_ci.minLod = 1.0;
4558 sampler_ci.maxLod = 1.0;
4559 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
4560 sampler_ci.unnormalizedCoordinates = VK_FALSE;
4561 VkSampler sampler;
4562
4563 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
4564 ASSERT_VK_SUCCESS(err);
4565
4566 layout_binding[2].binding = 2;
4567 layout_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
4568 layout_binding[2].descriptorCount = 1;
4569 layout_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4570 layout_binding[2].pImmutableSamplers = static_cast<VkSampler *>(&sampler);
4571
Mark Muellerd4914412016-06-13 17:52:06 -06004572 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4573 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4574 ds_layout_ci.bindingCount = sizeof(layout_binding) / sizeof(VkDescriptorSetLayoutBinding);
4575 ds_layout_ci.pBindings = layout_binding;
4576 VkDescriptorSetLayout ds_layout;
4577 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
4578 ASSERT_VK_SUCCESS(err);
4579
4580 VkDescriptorSetAllocateInfo alloc_info = {};
4581 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4582 alloc_info.descriptorSetCount = 1;
4583 alloc_info.descriptorPool = ds_pool;
4584 alloc_info.pSetLayouts = &ds_layout;
4585 VkDescriptorSet descriptorSet;
4586 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
4587 ASSERT_VK_SUCCESS(err);
4588
4589 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4590 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4591 pipeline_layout_ci.pNext = NULL;
4592 pipeline_layout_ci.setLayoutCount = 1;
4593 pipeline_layout_ci.pSetLayouts = &ds_layout;
4594
4595 VkPipelineLayout pipeline_layout;
4596 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4597 ASSERT_VK_SUCCESS(err);
4598
Mark Mueller5c838ce2016-06-16 09:54:29 -06004599 VkWriteDescriptorSet descriptor_write = {};
Mark Muellerd4914412016-06-13 17:52:06 -06004600 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4601 descriptor_write.dstSet = descriptorSet;
4602 descriptor_write.dstBinding = 0;
4603 descriptor_write.descriptorCount = 1;
4604 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4605
Mark Mueller5c838ce2016-06-16 09:54:29 -06004606 // 1) The uniform buffer is intentionally invalid here
Mark Muellerd4914412016-06-13 17:52:06 -06004607 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4608 m_errorMonitor->VerifyFound();
4609
4610 // Create a buffer to update the descriptor with
4611 uint32_t qfi = 0;
4612 VkBufferCreateInfo buffCI = {};
4613 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4614 buffCI.size = 1024;
4615 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
4616 buffCI.queueFamilyIndexCount = 1;
4617 buffCI.pQueueFamilyIndices = &qfi;
4618
4619 VkBuffer dyub;
4620 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
4621 ASSERT_VK_SUCCESS(err);
Mark Muellerd4914412016-06-13 17:52:06 -06004622
Tony Barboure132c5f2016-12-12 11:50:20 -07004623 VkDeviceMemory mem;
4624 VkMemoryRequirements mem_reqs;
4625 vkGetBufferMemoryRequirements(m_device->device(), dyub, &mem_reqs);
4626
4627 VkMemoryAllocateInfo mem_alloc_info = {};
4628 mem_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4629 mem_alloc_info.allocationSize = mem_reqs.size;
4630 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
4631 err = vkAllocateMemory(m_device->device(), &mem_alloc_info, NULL, &mem);
4632 ASSERT_VK_SUCCESS(err);
4633
4634 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
4635 ASSERT_VK_SUCCESS(err);
4636
4637 VkDescriptorBufferInfo buffInfo[2] = {};
4638 buffInfo[0].buffer = dyub;
4639 buffInfo[0].offset = 0;
4640 buffInfo[0].range = 1024;
4641 buffInfo[1].buffer = dyub;
4642 buffInfo[1].offset = 0;
4643 buffInfo[1].range = 1024;
4644 descriptor_write.pBufferInfo = buffInfo;
Mark Muellerd4914412016-06-13 17:52:06 -06004645 descriptor_write.descriptorCount = 2;
4646
Mark Mueller5c838ce2016-06-16 09:54:29 -06004647 // 2) The stateFlags don't match between the first and second descriptor
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07004648 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00938);
Mark Muellerd4914412016-06-13 17:52:06 -06004649 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4650 m_errorMonitor->VerifyFound();
4651
Mark Mueller5c838ce2016-06-16 09:54:29 -06004652 // 3) The second descriptor has a null_ptr pImmutableSamplers and
4653 // the third descriptor contains an immutable sampler
Mark Muellerd4914412016-06-13 17:52:06 -06004654 descriptor_write.dstBinding = 1;
4655 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Mueller5c838ce2016-06-16 09:54:29 -06004656
Mark Mueller5c838ce2016-06-16 09:54:29 -06004657 // Make pImageInfo index non-null to avoid complaints of it missing
4658 VkDescriptorImageInfo imageInfo = {};
4659 imageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
4660 descriptor_write.pImageInfo = &imageInfo;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07004661 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00938);
Mark Muellerd4914412016-06-13 17:52:06 -06004662 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4663 m_errorMonitor->VerifyFound();
4664
Mark Muellerd4914412016-06-13 17:52:06 -06004665 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tony Barboure132c5f2016-12-12 11:50:20 -07004666 vkFreeMemory(m_device->device(), mem, NULL);
Mark Muellerd4914412016-06-13 17:52:06 -06004667 vkDestroySampler(m_device->device(), sampler, NULL);
4668 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4669 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4670 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4671}
4672
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004673TEST_F(VkLayerTest, InvalidCmdBufferBufferDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004674 TEST_DESCRIPTION(
4675 "Attempt to draw with a command buffer that is invalid "
4676 "due to a buffer dependency being destroyed.");
Tony Barbour1fa09702017-03-16 12:09:08 -06004677 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004678
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004679 VkBuffer buffer;
4680 VkDeviceMemory mem;
4681 VkMemoryRequirements mem_reqs;
4682
4683 VkBufferCreateInfo buf_info = {};
4684 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes3d5882f2016-09-16 17:37:17 +12004685 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004686 buf_info.size = 256;
4687 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
4688 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
4689 ASSERT_VK_SUCCESS(err);
4690
4691 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
4692
4693 VkMemoryAllocateInfo alloc_info = {};
4694 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4695 alloc_info.allocationSize = 256;
4696 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004697 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 -06004698 if (!pass) {
4699 vkDestroyBuffer(m_device->device(), buffer, NULL);
4700 return;
4701 }
4702 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
4703 ASSERT_VK_SUCCESS(err);
4704
4705 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
4706 ASSERT_VK_SUCCESS(err);
4707
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004708 m_commandBuffer->BeginCommandBuffer();
Chris Forbes3d5882f2016-09-16 17:37:17 +12004709 vkCmdFillBuffer(m_commandBuffer->GetBufferHandle(), buffer, 0, VK_WHOLE_SIZE, 0);
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004710 m_commandBuffer->EndCommandBuffer();
4711
Mark Lobodzinski33826372017-04-13 11:10:11 -06004712 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound Buffer ");
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004713 // Destroy buffer dependency prior to submit to cause ERROR
4714 vkDestroyBuffer(m_device->device(), buffer, NULL);
4715
4716 VkSubmitInfo submit_info = {};
4717 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4718 submit_info.commandBufferCount = 1;
4719 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4720 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4721
4722 m_errorMonitor->VerifyFound();
Rene Lindsayab6c5cd2016-12-20 14:05:37 -07004723 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004724 vkFreeMemory(m_device->handle(), mem, NULL);
4725}
4726
Tobin Ehlisea413442016-09-28 10:23:59 -06004727TEST_F(VkLayerTest, InvalidCmdBufferBufferViewDestroyed) {
4728 TEST_DESCRIPTION("Delete bufferView bound to cmd buffer, then attempt to submit cmd buffer.");
4729
Tony Barbour1fa09702017-03-16 12:09:08 -06004730 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisea413442016-09-28 10:23:59 -06004731 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4732
4733 VkDescriptorPoolSize ds_type_count;
4734 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4735 ds_type_count.descriptorCount = 1;
4736
4737 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4738 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4739 ds_pool_ci.maxSets = 1;
4740 ds_pool_ci.poolSizeCount = 1;
4741 ds_pool_ci.pPoolSizes = &ds_type_count;
4742
4743 VkDescriptorPool ds_pool;
4744 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
4745 ASSERT_VK_SUCCESS(err);
4746
4747 VkDescriptorSetLayoutBinding layout_binding;
4748 layout_binding.binding = 0;
4749 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4750 layout_binding.descriptorCount = 1;
4751 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4752 layout_binding.pImmutableSamplers = NULL;
4753
4754 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4755 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4756 ds_layout_ci.bindingCount = 1;
4757 ds_layout_ci.pBindings = &layout_binding;
4758 VkDescriptorSetLayout ds_layout;
4759 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
4760 ASSERT_VK_SUCCESS(err);
4761
4762 VkDescriptorSetAllocateInfo alloc_info = {};
4763 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4764 alloc_info.descriptorSetCount = 1;
4765 alloc_info.descriptorPool = ds_pool;
4766 alloc_info.pSetLayouts = &ds_layout;
4767 VkDescriptorSet descriptor_set;
4768 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
4769 ASSERT_VK_SUCCESS(err);
4770
4771 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4772 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4773 pipeline_layout_ci.pNext = NULL;
4774 pipeline_layout_ci.setLayoutCount = 1;
4775 pipeline_layout_ci.pSetLayouts = &ds_layout;
4776
4777 VkPipelineLayout pipeline_layout;
4778 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4779 ASSERT_VK_SUCCESS(err);
4780
4781 VkBuffer buffer;
4782 uint32_t queue_family_index = 0;
4783 VkBufferCreateInfo buffer_create_info = {};
4784 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4785 buffer_create_info.size = 1024;
4786 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
4787 buffer_create_info.queueFamilyIndexCount = 1;
4788 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
4789
4790 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
4791 ASSERT_VK_SUCCESS(err);
4792
4793 VkMemoryRequirements memory_reqs;
4794 VkDeviceMemory buffer_memory;
4795
4796 VkMemoryAllocateInfo memory_info = {};
4797 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4798 memory_info.allocationSize = 0;
4799 memory_info.memoryTypeIndex = 0;
4800
4801 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
4802 memory_info.allocationSize = memory_reqs.size;
4803 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
4804 ASSERT_TRUE(pass);
4805
4806 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
4807 ASSERT_VK_SUCCESS(err);
4808 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
4809 ASSERT_VK_SUCCESS(err);
4810
4811 VkBufferView view;
4812 VkBufferViewCreateInfo bvci = {};
4813 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
4814 bvci.buffer = buffer;
4815 bvci.format = VK_FORMAT_R8_UNORM;
4816 bvci.range = VK_WHOLE_SIZE;
4817
4818 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
4819 ASSERT_VK_SUCCESS(err);
4820
4821 VkWriteDescriptorSet descriptor_write = {};
4822 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4823 descriptor_write.dstSet = descriptor_set;
4824 descriptor_write.dstBinding = 0;
4825 descriptor_write.descriptorCount = 1;
4826 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4827 descriptor_write.pTexelBufferView = &view;
4828
4829 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4830
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004831 char const *vsSource =
4832 "#version 450\n"
4833 "\n"
4834 "out gl_PerVertex { \n"
4835 " vec4 gl_Position;\n"
4836 "};\n"
4837 "void main(){\n"
4838 " gl_Position = vec4(1);\n"
4839 "}\n";
4840 char const *fsSource =
4841 "#version 450\n"
4842 "\n"
4843 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
4844 "layout(location=0) out vec4 x;\n"
4845 "void main(){\n"
4846 " x = imageLoad(s, 0);\n"
4847 "}\n";
Tobin Ehlisea413442016-09-28 10:23:59 -06004848 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4849 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
4850 VkPipelineObj pipe(m_device);
4851 pipe.AddShader(&vs);
4852 pipe.AddShader(&fs);
4853 pipe.AddColorAttachment();
4854 pipe.CreateVKPipeline(pipeline_layout, renderPass());
4855
Mark Lobodzinski33826372017-04-13 11:10:11 -06004856 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound BufferView ");
Tobin Ehlisea413442016-09-28 10:23:59 -06004857
Tony Barbour552f6c02016-12-21 14:34:07 -07004858 m_commandBuffer->BeginCommandBuffer();
4859 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
4860
Tobin Ehlisea413442016-09-28 10:23:59 -06004861 VkViewport viewport = {0, 0, 16, 16, 0, 1};
4862 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
4863 VkRect2D scissor = {{0, 0}, {16, 16}};
4864 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
4865 // Bind pipeline to cmd buffer
4866 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
4867 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
4868 &descriptor_set, 0, nullptr);
4869 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07004870 m_commandBuffer->EndRenderPass();
4871 m_commandBuffer->EndCommandBuffer();
Tobin Ehlisea413442016-09-28 10:23:59 -06004872
4873 // Delete BufferView in order to invalidate cmd buffer
4874 vkDestroyBufferView(m_device->device(), view, NULL);
4875 // Now attempt submit of cmd buffer
4876 VkSubmitInfo submit_info = {};
4877 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4878 submit_info.commandBufferCount = 1;
4879 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4880 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4881 m_errorMonitor->VerifyFound();
4882
4883 // Clean-up
4884 vkDestroyBuffer(m_device->device(), buffer, NULL);
4885 vkFreeMemory(m_device->device(), buffer_memory, NULL);
4886 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4887 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4888 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4889}
4890
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004891TEST_F(VkLayerTest, InvalidCmdBufferImageDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004892 TEST_DESCRIPTION(
4893 "Attempt to draw with a command buffer that is invalid "
4894 "due to an image dependency being destroyed.");
Tony Barbour1fa09702017-03-16 12:09:08 -06004895 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004896
4897 VkImage image;
4898 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4899 VkImageCreateInfo image_create_info = {};
4900 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4901 image_create_info.pNext = NULL;
4902 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4903 image_create_info.format = tex_format;
4904 image_create_info.extent.width = 32;
4905 image_create_info.extent.height = 32;
4906 image_create_info.extent.depth = 1;
4907 image_create_info.mipLevels = 1;
4908 image_create_info.arrayLayers = 1;
4909 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
4910 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004911 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004912 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004913 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004914 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004915 // Have to bind memory to image before recording cmd in cmd buffer using it
4916 VkMemoryRequirements mem_reqs;
4917 VkDeviceMemory image_mem;
4918 bool pass;
4919 VkMemoryAllocateInfo mem_alloc = {};
4920 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4921 mem_alloc.pNext = NULL;
4922 mem_alloc.memoryTypeIndex = 0;
4923 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
4924 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004925 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004926 ASSERT_TRUE(pass);
4927 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
4928 ASSERT_VK_SUCCESS(err);
4929 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
4930 ASSERT_VK_SUCCESS(err);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004931
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004932 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis764d7072016-07-01 12:54:29 -06004933 VkClearColorValue ccv;
4934 ccv.float32[0] = 1.0f;
4935 ccv.float32[1] = 1.0f;
4936 ccv.float32[2] = 1.0f;
4937 ccv.float32[3] = 1.0f;
4938 VkImageSubresourceRange isr = {};
4939 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004940 isr.baseArrayLayer = 0;
4941 isr.baseMipLevel = 0;
Tobin Ehlis764d7072016-07-01 12:54:29 -06004942 isr.layerCount = 1;
4943 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004944 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004945 m_commandBuffer->EndCommandBuffer();
4946
Mark Lobodzinski33826372017-04-13 11:10:11 -06004947 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound Image ");
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004948 // Destroy image dependency prior to submit to cause ERROR
4949 vkDestroyImage(m_device->device(), image, NULL);
4950
4951 VkSubmitInfo submit_info = {};
4952 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4953 submit_info.commandBufferCount = 1;
4954 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4955 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4956
4957 m_errorMonitor->VerifyFound();
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004958 vkFreeMemory(m_device->device(), image_mem, nullptr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004959}
4960
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004961TEST_F(VkLayerTest, InvalidCmdBufferFramebufferImageDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004962 TEST_DESCRIPTION(
4963 "Attempt to draw with a command buffer that is invalid "
4964 "due to a framebuffer image dependency being destroyed.");
Tony Barbour1fa09702017-03-16 12:09:08 -06004965 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004966 VkFormatProperties format_properties;
4967 VkResult err = VK_SUCCESS;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004968 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
4969 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004970 return;
4971 }
4972
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004973 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4974
4975 VkImageCreateInfo image_ci = {};
4976 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4977 image_ci.pNext = NULL;
4978 image_ci.imageType = VK_IMAGE_TYPE_2D;
4979 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
4980 image_ci.extent.width = 32;
4981 image_ci.extent.height = 32;
4982 image_ci.extent.depth = 1;
4983 image_ci.mipLevels = 1;
4984 image_ci.arrayLayers = 1;
4985 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
4986 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004987 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT;
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004988 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
4989 image_ci.flags = 0;
4990 VkImage image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004991 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004992
4993 VkMemoryRequirements memory_reqs;
4994 VkDeviceMemory image_memory;
4995 bool pass;
4996 VkMemoryAllocateInfo memory_info = {};
4997 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4998 memory_info.pNext = NULL;
4999 memory_info.allocationSize = 0;
5000 memory_info.memoryTypeIndex = 0;
5001 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5002 memory_info.allocationSize = memory_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005003 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005004 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005005 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005006 ASSERT_VK_SUCCESS(err);
5007 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5008 ASSERT_VK_SUCCESS(err);
5009
5010 VkImageViewCreateInfo ivci = {
5011 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
5012 nullptr,
5013 0,
5014 image,
5015 VK_IMAGE_VIEW_TYPE_2D,
5016 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005017 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005018 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
5019 };
5020 VkImageView view;
5021 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
5022 ASSERT_VK_SUCCESS(err);
5023
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005024 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 32, 32, 1};
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005025 VkFramebuffer fb;
5026 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
5027 ASSERT_VK_SUCCESS(err);
5028
5029 // Just use default renderpass with our framebuffer
5030 m_renderPassBeginInfo.framebuffer = fb;
Jeremy Hayesba817e12017-03-03 15:51:11 -07005031 m_renderPassBeginInfo.renderArea.extent.width = 32;
5032 m_renderPassBeginInfo.renderArea.extent.height = 32;
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005033 // Create Null cmd buffer for submit
Tony Barbour552f6c02016-12-21 14:34:07 -07005034 m_commandBuffer->BeginCommandBuffer();
5035 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
5036 m_commandBuffer->EndRenderPass();
5037 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005038 // Destroy image attached to framebuffer to invalidate cmd buffer
5039 vkDestroyImage(m_device->device(), image, NULL);
5040 // Now attempt to submit cmd buffer and verify error
Mark Lobodzinski33826372017-04-13 11:10:11 -06005041 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound Image ");
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005042 QueueCommandBuffer(false);
5043 m_errorMonitor->VerifyFound();
5044
5045 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
5046 vkDestroyImageView(m_device->device(), view, nullptr);
5047 vkFreeMemory(m_device->device(), image_memory, nullptr);
5048}
5049
Tobin Ehlisb329f992016-10-12 13:20:29 -06005050TEST_F(VkLayerTest, FramebufferInUseDestroyedSignaled) {
5051 TEST_DESCRIPTION("Delete in-use framebuffer.");
Tony Barbour1fa09702017-03-16 12:09:08 -06005052 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisb329f992016-10-12 13:20:29 -06005053 VkFormatProperties format_properties;
5054 VkResult err = VK_SUCCESS;
5055 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
5056
Tobin Ehlisb329f992016-10-12 13:20:29 -06005057 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5058
5059 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06005060 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 -06005061 ASSERT_TRUE(image.initialized());
5062 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
5063
5064 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
5065 VkFramebuffer fb;
5066 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
5067 ASSERT_VK_SUCCESS(err);
5068
5069 // Just use default renderpass with our framebuffer
5070 m_renderPassBeginInfo.framebuffer = fb;
5071 // Create Null cmd buffer for submit
Tony Barbour552f6c02016-12-21 14:34:07 -07005072 m_commandBuffer->BeginCommandBuffer();
5073 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
5074 m_commandBuffer->EndRenderPass();
5075 m_commandBuffer->EndCommandBuffer();
Tobin Ehlisb329f992016-10-12 13:20:29 -06005076 // Submit cmd buffer to put it in-flight
5077 VkSubmitInfo submit_info = {};
5078 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5079 submit_info.commandBufferCount = 1;
5080 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5081 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5082 // Destroy framebuffer while in-flight
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07005083 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00422);
Tobin Ehlisb329f992016-10-12 13:20:29 -06005084 vkDestroyFramebuffer(m_device->device(), fb, NULL);
5085 m_errorMonitor->VerifyFound();
5086 // Wait for queue to complete so we can safely destroy everything
5087 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005088 m_errorMonitor->SetUnexpectedError("If framebuffer is not VK_NULL_HANDLE, framebuffer must be a valid VkFramebuffer handle");
5089 m_errorMonitor->SetUnexpectedError("Unable to remove Framebuffer obj");
Tobin Ehlisb329f992016-10-12 13:20:29 -06005090 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
5091}
5092
Tobin Ehlis88becd72016-09-21 14:33:41 -06005093TEST_F(VkLayerTest, FramebufferImageInUseDestroyedSignaled) {
5094 TEST_DESCRIPTION("Delete in-use image that's child of framebuffer.");
Tony Barbour1fa09702017-03-16 12:09:08 -06005095 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis88becd72016-09-21 14:33:41 -06005096 VkFormatProperties format_properties;
5097 VkResult err = VK_SUCCESS;
5098 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
Tobin Ehlis88becd72016-09-21 14:33:41 -06005099
Tobin Ehlis88becd72016-09-21 14:33:41 -06005100 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5101
5102 VkImageCreateInfo image_ci = {};
5103 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5104 image_ci.pNext = NULL;
5105 image_ci.imageType = VK_IMAGE_TYPE_2D;
5106 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
5107 image_ci.extent.width = 256;
5108 image_ci.extent.height = 256;
5109 image_ci.extent.depth = 1;
5110 image_ci.mipLevels = 1;
5111 image_ci.arrayLayers = 1;
5112 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
5113 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisc8ca0312016-09-22 07:30:05 -06005114 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Tobin Ehlis88becd72016-09-21 14:33:41 -06005115 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
5116 image_ci.flags = 0;
5117 VkImage image;
5118 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
5119
5120 VkMemoryRequirements memory_reqs;
5121 VkDeviceMemory image_memory;
5122 bool pass;
5123 VkMemoryAllocateInfo memory_info = {};
5124 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5125 memory_info.pNext = NULL;
5126 memory_info.allocationSize = 0;
5127 memory_info.memoryTypeIndex = 0;
5128 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5129 memory_info.allocationSize = memory_reqs.size;
5130 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
5131 ASSERT_TRUE(pass);
5132 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
5133 ASSERT_VK_SUCCESS(err);
5134 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5135 ASSERT_VK_SUCCESS(err);
5136
5137 VkImageViewCreateInfo ivci = {
5138 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
5139 nullptr,
5140 0,
5141 image,
5142 VK_IMAGE_VIEW_TYPE_2D,
5143 VK_FORMAT_B8G8R8A8_UNORM,
5144 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
5145 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
5146 };
5147 VkImageView view;
5148 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
5149 ASSERT_VK_SUCCESS(err);
5150
5151 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
5152 VkFramebuffer fb;
5153 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
5154 ASSERT_VK_SUCCESS(err);
5155
5156 // Just use default renderpass with our framebuffer
5157 m_renderPassBeginInfo.framebuffer = fb;
5158 // Create Null cmd buffer for submit
Tony Barbour552f6c02016-12-21 14:34:07 -07005159 m_commandBuffer->BeginCommandBuffer();
5160 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
5161 m_commandBuffer->EndRenderPass();
5162 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis88becd72016-09-21 14:33:41 -06005163 // Submit cmd buffer to put it (and attached imageView) in-flight
5164 VkSubmitInfo submit_info = {};
5165 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5166 submit_info.commandBufferCount = 1;
5167 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5168 // Submit cmd buffer to put framebuffer and children in-flight
5169 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5170 // Destroy image attached to framebuffer while in-flight
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07005171 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00743);
Tobin Ehlis88becd72016-09-21 14:33:41 -06005172 vkDestroyImage(m_device->device(), image, NULL);
5173 m_errorMonitor->VerifyFound();
5174 // Wait for queue to complete so we can safely destroy image and other objects
5175 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005176 m_errorMonitor->SetUnexpectedError("If image is not VK_NULL_HANDLE, image must be a valid VkImage handle");
5177 m_errorMonitor->SetUnexpectedError("Unable to remove Image obj");
Tobin Ehlis88becd72016-09-21 14:33:41 -06005178 vkDestroyImage(m_device->device(), image, NULL);
5179 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
5180 vkDestroyImageView(m_device->device(), view, nullptr);
5181 vkFreeMemory(m_device->device(), image_memory, nullptr);
5182}
5183
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005184TEST_F(VkLayerTest, RenderPassInUseDestroyedSignaled) {
5185 TEST_DESCRIPTION("Delete in-use renderPass.");
5186
Tony Barbour1fa09702017-03-16 12:09:08 -06005187 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005188 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5189
5190 // Create simple renderpass
5191 VkAttachmentReference attach = {};
5192 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
5193 VkSubpassDescription subpass = {};
Dave Houlton756e6742017-03-23 14:33:22 -06005194 subpass.colorAttachmentCount = 1;
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005195 subpass.pColorAttachments = &attach;
5196 VkRenderPassCreateInfo rpci = {};
5197 rpci.subpassCount = 1;
5198 rpci.pSubpasses = &subpass;
5199 rpci.attachmentCount = 1;
5200 VkAttachmentDescription attach_desc = {};
5201 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
5202 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
5203 rpci.pAttachments = &attach_desc;
5204 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
5205 VkRenderPass rp;
5206 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
5207 ASSERT_VK_SUCCESS(err);
5208
5209 // Create a pipeline that uses the given renderpass
5210 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5211 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5212
5213 VkPipelineLayout pipeline_layout;
5214 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
5215 ASSERT_VK_SUCCESS(err);
5216
5217 VkPipelineViewportStateCreateInfo vp_state_ci = {};
5218 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
5219 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005220 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005221 vp_state_ci.pViewports = &vp;
5222 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005223 VkRect2D scissors = {}; // Dummy scissors to point to
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005224 vp_state_ci.pScissors = &scissors;
5225
5226 VkPipelineShaderStageCreateInfo shaderStages[2];
5227 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
5228
5229 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005230 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 -06005231 // but add it to be able to run on more devices
5232 shaderStages[0] = vs.GetStageCreateInfo();
5233 shaderStages[1] = fs.GetStageCreateInfo();
5234
5235 VkPipelineVertexInputStateCreateInfo vi_ci = {};
5236 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
5237
5238 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
5239 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
5240 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
5241
5242 VkPipelineRasterizationStateCreateInfo rs_ci = {};
5243 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
5244 rs_ci.rasterizerDiscardEnable = true;
5245 rs_ci.lineWidth = 1.0f;
5246
5247 VkPipelineColorBlendAttachmentState att = {};
5248 att.blendEnable = VK_FALSE;
5249 att.colorWriteMask = 0xf;
5250
5251 VkPipelineColorBlendStateCreateInfo cb_ci = {};
5252 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
5253 cb_ci.attachmentCount = 1;
5254 cb_ci.pAttachments = &att;
5255
5256 VkGraphicsPipelineCreateInfo gp_ci = {};
5257 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
5258 gp_ci.stageCount = 2;
5259 gp_ci.pStages = shaderStages;
5260 gp_ci.pVertexInputState = &vi_ci;
5261 gp_ci.pInputAssemblyState = &ia_ci;
5262 gp_ci.pViewportState = &vp_state_ci;
5263 gp_ci.pRasterizationState = &rs_ci;
5264 gp_ci.pColorBlendState = &cb_ci;
5265 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
5266 gp_ci.layout = pipeline_layout;
5267 gp_ci.renderPass = rp;
5268
5269 VkPipelineCacheCreateInfo pc_ci = {};
5270 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
5271
Dave Houlton756e6742017-03-23 14:33:22 -06005272 m_errorMonitor->ExpectSuccess();
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005273 VkPipeline pipeline;
5274 VkPipelineCache pipe_cache;
5275 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipe_cache);
5276 ASSERT_VK_SUCCESS(err);
5277
5278 err = vkCreateGraphicsPipelines(m_device->device(), pipe_cache, 1, &gp_ci, NULL, &pipeline);
5279 ASSERT_VK_SUCCESS(err);
Dave Houlton756e6742017-03-23 14:33:22 -06005280
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005281 // Bind pipeline to cmd buffer, will also bind renderpass
5282 m_commandBuffer->BeginCommandBuffer();
5283 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
5284 m_commandBuffer->EndCommandBuffer();
5285
5286 VkSubmitInfo submit_info = {};
5287 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5288 submit_info.commandBufferCount = 1;
5289 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5290 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Dave Houlton756e6742017-03-23 14:33:22 -06005291 m_errorMonitor->VerifyNotFound();
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005292
5293 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00393);
5294 vkDestroyRenderPass(m_device->device(), rp, nullptr);
5295 m_errorMonitor->VerifyFound();
5296
5297 // Wait for queue to complete so we can safely destroy everything
5298 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005299 m_errorMonitor->SetUnexpectedError("If renderPass is not VK_NULL_HANDLE, renderPass must be a valid VkRenderPass handle");
Mark Lobodzinski74597792017-04-11 15:43:49 -06005300 m_errorMonitor->SetUnexpectedError("Unable to remove RenderPass obj");
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005301 vkDestroyRenderPass(m_device->device(), rp, nullptr);
5302 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
5303 vkDestroyPipelineCache(m_device->device(), pipe_cache, nullptr);
5304 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
5305}
5306
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005307TEST_F(VkLayerTest, ImageMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005308 TEST_DESCRIPTION("Attempt to draw with an image which has not had memory bound to it.");
Tony Barbour1fa09702017-03-16 12:09:08 -06005309 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005310
5311 VkImage image;
5312 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5313 VkImageCreateInfo image_create_info = {};
5314 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5315 image_create_info.pNext = NULL;
5316 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5317 image_create_info.format = tex_format;
5318 image_create_info.extent.width = 32;
5319 image_create_info.extent.height = 32;
5320 image_create_info.extent.depth = 1;
5321 image_create_info.mipLevels = 1;
5322 image_create_info.arrayLayers = 1;
5323 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5324 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005325 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005326 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005327 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005328 ASSERT_VK_SUCCESS(err);
5329 // Have to bind memory to image before recording cmd in cmd buffer using it
5330 VkMemoryRequirements mem_reqs;
5331 VkDeviceMemory image_mem;
5332 bool pass;
5333 VkMemoryAllocateInfo mem_alloc = {};
5334 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5335 mem_alloc.pNext = NULL;
5336 mem_alloc.memoryTypeIndex = 0;
5337 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
5338 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005339 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005340 ASSERT_TRUE(pass);
5341 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
5342 ASSERT_VK_SUCCESS(err);
5343
Tobin Ehlisfed999f2016-09-21 15:09:45 -06005344 // Introduce error, do not call vkBindImageMemory(m_device->device(), image, image_mem, 0);
5345 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005346 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005347
5348 m_commandBuffer->BeginCommandBuffer();
5349 VkClearColorValue ccv;
5350 ccv.float32[0] = 1.0f;
5351 ccv.float32[1] = 1.0f;
5352 ccv.float32[2] = 1.0f;
5353 ccv.float32[3] = 1.0f;
5354 VkImageSubresourceRange isr = {};
5355 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
5356 isr.baseArrayLayer = 0;
5357 isr.baseMipLevel = 0;
5358 isr.layerCount = 1;
5359 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005360 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005361 m_commandBuffer->EndCommandBuffer();
5362
5363 m_errorMonitor->VerifyFound();
5364 vkDestroyImage(m_device->device(), image, NULL);
5365 vkFreeMemory(m_device->device(), image_mem, nullptr);
5366}
5367
5368TEST_F(VkLayerTest, BufferMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005369 TEST_DESCRIPTION("Attempt to copy from a buffer which has not had memory bound to it.");
Tony Barbour1fa09702017-03-16 12:09:08 -06005370 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005371
5372 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06005373 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 -06005374 VK_IMAGE_TILING_OPTIMAL, 0);
5375 ASSERT_TRUE(image.initialized());
5376
5377 VkBuffer buffer;
5378 VkDeviceMemory mem;
5379 VkMemoryRequirements mem_reqs;
5380
5381 VkBufferCreateInfo buf_info = {};
5382 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes8d260dd2016-09-16 17:42:42 +12005383 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski80871462017-02-16 10:37:27 -07005384 buf_info.size = 1024;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005385 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
5386 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
5387 ASSERT_VK_SUCCESS(err);
5388
5389 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
5390
5391 VkMemoryAllocateInfo alloc_info = {};
5392 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Mark Lobodzinski80871462017-02-16 10:37:27 -07005393 alloc_info.allocationSize = 1024;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005394 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005395 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 -06005396 if (!pass) {
5397 vkDestroyBuffer(m_device->device(), buffer, NULL);
5398 return;
5399 }
5400 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
5401 ASSERT_VK_SUCCESS(err);
5402
Tobin Ehlisfed999f2016-09-21 15:09:45 -06005403 // Introduce failure by not calling vkBindBufferMemory(m_device->device(), buffer, mem, 0);
5404 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005405 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005406 VkBufferImageCopy region = {};
Mark Lobodzinski80871462017-02-16 10:37:27 -07005407 region.bufferRowLength = 16;
5408 region.bufferImageHeight = 16;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005409 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
5410
5411 region.imageSubresource.layerCount = 1;
5412 region.imageExtent.height = 4;
5413 region.imageExtent.width = 4;
5414 region.imageExtent.depth = 1;
5415 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005416 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer, image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
5417 &region);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005418 m_commandBuffer->EndCommandBuffer();
5419
5420 m_errorMonitor->VerifyFound();
5421
5422 vkDestroyBuffer(m_device->device(), buffer, NULL);
5423 vkFreeMemory(m_device->handle(), mem, NULL);
5424}
5425
Tobin Ehlis85940f52016-07-07 16:57:21 -06005426TEST_F(VkLayerTest, InvalidCmdBufferEventDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005427 TEST_DESCRIPTION(
5428 "Attempt to draw with a command buffer that is invalid "
5429 "due to an event dependency being destroyed.");
Tony Barbour1fa09702017-03-16 12:09:08 -06005430 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis85940f52016-07-07 16:57:21 -06005431
5432 VkEvent event;
5433 VkEventCreateInfo evci = {};
5434 evci.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
5435 VkResult result = vkCreateEvent(m_device->device(), &evci, NULL, &event);
5436 ASSERT_VK_SUCCESS(result);
5437
5438 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005439 vkCmdSetEvent(m_commandBuffer->GetBufferHandle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Tobin Ehlis85940f52016-07-07 16:57:21 -06005440 m_commandBuffer->EndCommandBuffer();
5441
Mark Lobodzinski33826372017-04-13 11:10:11 -06005442 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound Event ");
Tobin Ehlis85940f52016-07-07 16:57:21 -06005443 // Destroy event dependency prior to submit to cause ERROR
5444 vkDestroyEvent(m_device->device(), event, NULL);
5445
5446 VkSubmitInfo submit_info = {};
5447 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5448 submit_info.commandBufferCount = 1;
5449 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5450 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5451
5452 m_errorMonitor->VerifyFound();
5453}
5454
Tobin Ehlisdbea7552016-07-08 14:33:31 -06005455TEST_F(VkLayerTest, InvalidCmdBufferQueryPoolDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005456 TEST_DESCRIPTION(
5457 "Attempt to draw with a command buffer that is invalid "
5458 "due to a query pool dependency being destroyed.");
Tony Barbour1fa09702017-03-16 12:09:08 -06005459 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisdbea7552016-07-08 14:33:31 -06005460
5461 VkQueryPool query_pool;
5462 VkQueryPoolCreateInfo qpci{};
5463 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
5464 qpci.queryType = VK_QUERY_TYPE_TIMESTAMP;
5465 qpci.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005466 VkResult result = vkCreateQueryPool(m_device->device(), &qpci, nullptr, &query_pool);
Tobin Ehlisdbea7552016-07-08 14:33:31 -06005467 ASSERT_VK_SUCCESS(result);
5468
5469 m_commandBuffer->BeginCommandBuffer();
5470 vkCmdResetQueryPool(m_commandBuffer->GetBufferHandle(), query_pool, 0, 1);
5471 m_commandBuffer->EndCommandBuffer();
5472
Mark Lobodzinski33826372017-04-13 11:10:11 -06005473 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound QueryPool ");
Tobin Ehlisdbea7552016-07-08 14:33:31 -06005474 // Destroy query pool dependency prior to submit to cause ERROR
5475 vkDestroyQueryPool(m_device->device(), query_pool, NULL);
5476
5477 VkSubmitInfo submit_info = {};
5478 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5479 submit_info.commandBufferCount = 1;
5480 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5481 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5482
5483 m_errorMonitor->VerifyFound();
5484}
5485
Tobin Ehlis24130d92016-07-08 15:50:53 -06005486TEST_F(VkLayerTest, InvalidCmdBufferPipelineDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005487 TEST_DESCRIPTION(
5488 "Attempt to draw with a command buffer that is invalid "
5489 "due to a pipeline dependency being destroyed.");
Tony Barbour1fa09702017-03-16 12:09:08 -06005490 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis24130d92016-07-08 15:50:53 -06005491 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5492
5493 VkResult err;
5494
5495 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5496 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5497
5498 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005499 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis24130d92016-07-08 15:50:53 -06005500 ASSERT_VK_SUCCESS(err);
5501
5502 VkPipelineViewportStateCreateInfo vp_state_ci = {};
5503 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
5504 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005505 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -06005506 vp_state_ci.pViewports = &vp;
Tobin Ehlis24130d92016-07-08 15:50:53 -06005507 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005508 VkRect2D scissors = {}; // Dummy scissors to point to
Tobin Ehlis24130d92016-07-08 15:50:53 -06005509 vp_state_ci.pScissors = &scissors;
Tobin Ehlis24130d92016-07-08 15:50:53 -06005510
5511 VkPipelineShaderStageCreateInfo shaderStages[2];
5512 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
5513
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005514 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005515 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 -06005516 // but add it to be able to run on more devices
Tobin Ehlis24130d92016-07-08 15:50:53 -06005517 shaderStages[0] = vs.GetStageCreateInfo();
5518 shaderStages[1] = fs.GetStageCreateInfo();
5519
5520 VkPipelineVertexInputStateCreateInfo vi_ci = {};
5521 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
5522
5523 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
5524 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
5525 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
5526
5527 VkPipelineRasterizationStateCreateInfo rs_ci = {};
5528 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbese06ba252016-09-16 17:48:53 +12005529 rs_ci.rasterizerDiscardEnable = true;
5530 rs_ci.lineWidth = 1.0f;
Tobin Ehlis24130d92016-07-08 15:50:53 -06005531
5532 VkPipelineColorBlendAttachmentState att = {};
5533 att.blendEnable = VK_FALSE;
5534 att.colorWriteMask = 0xf;
5535
5536 VkPipelineColorBlendStateCreateInfo cb_ci = {};
5537 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
5538 cb_ci.attachmentCount = 1;
5539 cb_ci.pAttachments = &att;
5540
5541 VkGraphicsPipelineCreateInfo gp_ci = {};
5542 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
5543 gp_ci.stageCount = 2;
5544 gp_ci.pStages = shaderStages;
5545 gp_ci.pVertexInputState = &vi_ci;
5546 gp_ci.pInputAssemblyState = &ia_ci;
5547 gp_ci.pViewportState = &vp_state_ci;
5548 gp_ci.pRasterizationState = &rs_ci;
5549 gp_ci.pColorBlendState = &cb_ci;
Tobin Ehlis24130d92016-07-08 15:50:53 -06005550 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
5551 gp_ci.layout = pipeline_layout;
5552 gp_ci.renderPass = renderPass();
5553
5554 VkPipelineCacheCreateInfo pc_ci = {};
5555 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
5556
5557 VkPipeline pipeline;
5558 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005559 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis24130d92016-07-08 15:50:53 -06005560 ASSERT_VK_SUCCESS(err);
5561
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005562 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06005563 ASSERT_VK_SUCCESS(err);
5564
5565 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005566 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06005567 m_commandBuffer->EndCommandBuffer();
5568 // Now destroy pipeline in order to cause error when submitting
5569 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
5570
Mark Lobodzinski33826372017-04-13 11:10:11 -06005571 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound Pipeline ");
Tobin Ehlis24130d92016-07-08 15:50:53 -06005572
5573 VkSubmitInfo submit_info = {};
5574 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5575 submit_info.commandBufferCount = 1;
5576 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5577 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5578
5579 m_errorMonitor->VerifyFound();
5580 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
5581 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5582}
5583
Tobin Ehlis31289162016-08-17 14:57:58 -06005584TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetBufferDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005585 TEST_DESCRIPTION(
5586 "Attempt to draw with a command buffer that is invalid "
5587 "due to a bound descriptor set with a buffer dependency "
5588 "being destroyed.");
Tony Barbour1fa09702017-03-16 12:09:08 -06005589 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis31289162016-08-17 14:57:58 -06005590 ASSERT_NO_FATAL_FAILURE(InitViewport());
5591 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5592
5593 VkDescriptorPoolSize ds_type_count = {};
5594 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5595 ds_type_count.descriptorCount = 1;
5596
5597 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5598 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5599 ds_pool_ci.pNext = NULL;
5600 ds_pool_ci.maxSets = 1;
5601 ds_pool_ci.poolSizeCount = 1;
5602 ds_pool_ci.pPoolSizes = &ds_type_count;
5603
5604 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005605 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis31289162016-08-17 14:57:58 -06005606 ASSERT_VK_SUCCESS(err);
5607
5608 VkDescriptorSetLayoutBinding dsl_binding = {};
5609 dsl_binding.binding = 0;
5610 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5611 dsl_binding.descriptorCount = 1;
5612 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5613 dsl_binding.pImmutableSamplers = NULL;
5614
5615 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5616 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5617 ds_layout_ci.pNext = NULL;
5618 ds_layout_ci.bindingCount = 1;
5619 ds_layout_ci.pBindings = &dsl_binding;
5620 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005621 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06005622 ASSERT_VK_SUCCESS(err);
5623
5624 VkDescriptorSet descriptorSet;
5625 VkDescriptorSetAllocateInfo alloc_info = {};
5626 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5627 alloc_info.descriptorSetCount = 1;
5628 alloc_info.descriptorPool = ds_pool;
5629 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005630 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis31289162016-08-17 14:57:58 -06005631 ASSERT_VK_SUCCESS(err);
5632
5633 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5634 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5635 pipeline_layout_ci.pNext = NULL;
5636 pipeline_layout_ci.setLayoutCount = 1;
5637 pipeline_layout_ci.pSetLayouts = &ds_layout;
5638
5639 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005640 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06005641 ASSERT_VK_SUCCESS(err);
5642
5643 // Create a buffer to update the descriptor with
5644 uint32_t qfi = 0;
5645 VkBufferCreateInfo buffCI = {};
5646 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
5647 buffCI.size = 1024;
5648 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
5649 buffCI.queueFamilyIndexCount = 1;
5650 buffCI.pQueueFamilyIndices = &qfi;
5651
5652 VkBuffer buffer;
5653 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &buffer);
5654 ASSERT_VK_SUCCESS(err);
5655 // Allocate memory and bind to buffer so we can make it to the appropriate
5656 // error
5657 VkMemoryAllocateInfo mem_alloc = {};
5658 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5659 mem_alloc.pNext = NULL;
5660 mem_alloc.allocationSize = 1024;
5661 mem_alloc.memoryTypeIndex = 0;
5662
5663 VkMemoryRequirements memReqs;
5664 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005665 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis31289162016-08-17 14:57:58 -06005666 if (!pass) {
5667 vkDestroyBuffer(m_device->device(), buffer, NULL);
5668 return;
5669 }
5670
5671 VkDeviceMemory mem;
5672 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
5673 ASSERT_VK_SUCCESS(err);
5674 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
5675 ASSERT_VK_SUCCESS(err);
5676 // Correctly update descriptor to avoid "NOT_UPDATED" error
5677 VkDescriptorBufferInfo buffInfo = {};
5678 buffInfo.buffer = buffer;
5679 buffInfo.offset = 0;
5680 buffInfo.range = 1024;
5681
5682 VkWriteDescriptorSet descriptor_write;
5683 memset(&descriptor_write, 0, sizeof(descriptor_write));
5684 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5685 descriptor_write.dstSet = descriptorSet;
5686 descriptor_write.dstBinding = 0;
5687 descriptor_write.descriptorCount = 1;
5688 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5689 descriptor_write.pBufferInfo = &buffInfo;
5690
5691 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5692
5693 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005694 char const *vsSource =
5695 "#version 450\n"
5696 "\n"
5697 "out gl_PerVertex { \n"
5698 " vec4 gl_Position;\n"
5699 "};\n"
5700 "void main(){\n"
5701 " gl_Position = vec4(1);\n"
5702 "}\n";
5703 char const *fsSource =
5704 "#version 450\n"
5705 "\n"
5706 "layout(location=0) out vec4 x;\n"
5707 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
5708 "void main(){\n"
5709 " x = vec4(bar.y);\n"
5710 "}\n";
Tobin Ehlis31289162016-08-17 14:57:58 -06005711 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5712 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5713 VkPipelineObj pipe(m_device);
5714 pipe.AddShader(&vs);
5715 pipe.AddShader(&fs);
5716 pipe.AddColorAttachment();
5717 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5718
Tony Barbour552f6c02016-12-21 14:34:07 -07005719 m_commandBuffer->BeginCommandBuffer();
5720 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005721 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5722 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5723 &descriptorSet, 0, NULL);
Rene Lindsay0583ac92017-01-16 14:29:10 -07005724
5725 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &m_viewports[0]);
5726 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &m_scissors[0]);
5727
Tobin Ehlis31289162016-08-17 14:57:58 -06005728 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005729 m_commandBuffer->EndRenderPass();
5730 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski33826372017-04-13 11:10:11 -06005731 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound Buffer ");
Tobin Ehlis31289162016-08-17 14:57:58 -06005732 // Destroy buffer should invalidate the cmd buffer, causing error on submit
5733 vkDestroyBuffer(m_device->device(), buffer, NULL);
5734 // Attempt to submit cmd buffer
5735 VkSubmitInfo submit_info = {};
5736 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5737 submit_info.commandBufferCount = 1;
5738 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5739 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5740 m_errorMonitor->VerifyFound();
5741 // Cleanup
5742 vkFreeMemory(m_device->device(), mem, NULL);
5743
5744 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5745 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5746 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5747}
5748
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005749TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetImageSamplerDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005750 TEST_DESCRIPTION(
5751 "Attempt to draw with a command buffer that is invalid "
5752 "due to a bound descriptor sets with a combined image "
5753 "sampler having their image, sampler, and descriptor set "
5754 "each respectively destroyed and then attempting to "
5755 "submit associated cmd buffers. Attempt to destroy a "
5756 "DescriptorSet that is in use.");
Tony Barbour1fa09702017-03-16 12:09:08 -06005757 ASSERT_NO_FATAL_FAILURE(Init(nullptr, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT));
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005758 ASSERT_NO_FATAL_FAILURE(InitViewport());
5759 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5760
5761 VkDescriptorPoolSize ds_type_count = {};
5762 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5763 ds_type_count.descriptorCount = 1;
5764
5765 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5766 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5767 ds_pool_ci.pNext = NULL;
Rene Lindsayed88b732017-01-27 15:55:29 -07005768 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005769 ds_pool_ci.maxSets = 1;
5770 ds_pool_ci.poolSizeCount = 1;
5771 ds_pool_ci.pPoolSizes = &ds_type_count;
5772
5773 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005774 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005775 ASSERT_VK_SUCCESS(err);
5776
5777 VkDescriptorSetLayoutBinding dsl_binding = {};
5778 dsl_binding.binding = 0;
5779 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5780 dsl_binding.descriptorCount = 1;
5781 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5782 dsl_binding.pImmutableSamplers = NULL;
5783
5784 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5785 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5786 ds_layout_ci.pNext = NULL;
5787 ds_layout_ci.bindingCount = 1;
5788 ds_layout_ci.pBindings = &dsl_binding;
5789 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005790 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005791 ASSERT_VK_SUCCESS(err);
5792
5793 VkDescriptorSet descriptorSet;
5794 VkDescriptorSetAllocateInfo alloc_info = {};
5795 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5796 alloc_info.descriptorSetCount = 1;
5797 alloc_info.descriptorPool = ds_pool;
5798 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005799 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005800 ASSERT_VK_SUCCESS(err);
5801
5802 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5803 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5804 pipeline_layout_ci.pNext = NULL;
5805 pipeline_layout_ci.setLayoutCount = 1;
5806 pipeline_layout_ci.pSetLayouts = &ds_layout;
5807
5808 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005809 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005810 ASSERT_VK_SUCCESS(err);
5811
5812 // Create images to update the descriptor with
5813 VkImage image;
5814 VkImage image2;
5815 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5816 const int32_t tex_width = 32;
5817 const int32_t tex_height = 32;
5818 VkImageCreateInfo image_create_info = {};
5819 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5820 image_create_info.pNext = NULL;
5821 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5822 image_create_info.format = tex_format;
5823 image_create_info.extent.width = tex_width;
5824 image_create_info.extent.height = tex_height;
5825 image_create_info.extent.depth = 1;
5826 image_create_info.mipLevels = 1;
5827 image_create_info.arrayLayers = 1;
5828 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5829 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
5830 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5831 image_create_info.flags = 0;
5832 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
5833 ASSERT_VK_SUCCESS(err);
5834 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
5835 ASSERT_VK_SUCCESS(err);
5836
5837 VkMemoryRequirements memory_reqs;
5838 VkDeviceMemory image_memory;
5839 bool pass;
5840 VkMemoryAllocateInfo memory_info = {};
5841 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5842 memory_info.pNext = NULL;
5843 memory_info.allocationSize = 0;
5844 memory_info.memoryTypeIndex = 0;
5845 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5846 // Allocate enough memory for both images
5847 memory_info.allocationSize = memory_reqs.size * 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005848 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005849 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005850 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005851 ASSERT_VK_SUCCESS(err);
5852 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5853 ASSERT_VK_SUCCESS(err);
5854 // Bind second image to memory right after first image
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005855 err = vkBindImageMemory(m_device->device(), image2, image_memory, memory_reqs.size);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005856 ASSERT_VK_SUCCESS(err);
5857
5858 VkImageViewCreateInfo image_view_create_info = {};
5859 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5860 image_view_create_info.image = image;
5861 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5862 image_view_create_info.format = tex_format;
5863 image_view_create_info.subresourceRange.layerCount = 1;
5864 image_view_create_info.subresourceRange.baseMipLevel = 0;
5865 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005866 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005867
5868 VkImageView view;
5869 VkImageView view2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005870 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005871 ASSERT_VK_SUCCESS(err);
5872 image_view_create_info.image = image2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005873 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view2);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005874 ASSERT_VK_SUCCESS(err);
5875 // Create Samplers
5876 VkSamplerCreateInfo sampler_ci = {};
5877 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5878 sampler_ci.pNext = NULL;
5879 sampler_ci.magFilter = VK_FILTER_NEAREST;
5880 sampler_ci.minFilter = VK_FILTER_NEAREST;
5881 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5882 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5883 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5884 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5885 sampler_ci.mipLodBias = 1.0;
5886 sampler_ci.anisotropyEnable = VK_FALSE;
5887 sampler_ci.maxAnisotropy = 1;
5888 sampler_ci.compareEnable = VK_FALSE;
5889 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5890 sampler_ci.minLod = 1.0;
5891 sampler_ci.maxLod = 1.0;
5892 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5893 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5894 VkSampler sampler;
5895 VkSampler sampler2;
5896 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5897 ASSERT_VK_SUCCESS(err);
5898 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler2);
5899 ASSERT_VK_SUCCESS(err);
5900 // Update descriptor with image and sampler
5901 VkDescriptorImageInfo img_info = {};
5902 img_info.sampler = sampler;
5903 img_info.imageView = view;
5904 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5905
5906 VkWriteDescriptorSet descriptor_write;
5907 memset(&descriptor_write, 0, sizeof(descriptor_write));
5908 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5909 descriptor_write.dstSet = descriptorSet;
5910 descriptor_write.dstBinding = 0;
5911 descriptor_write.descriptorCount = 1;
5912 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5913 descriptor_write.pImageInfo = &img_info;
5914
5915 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5916
5917 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005918 char const *vsSource =
5919 "#version 450\n"
5920 "\n"
5921 "out gl_PerVertex { \n"
5922 " vec4 gl_Position;\n"
5923 "};\n"
5924 "void main(){\n"
5925 " gl_Position = vec4(1);\n"
5926 "}\n";
5927 char const *fsSource =
5928 "#version 450\n"
5929 "\n"
5930 "layout(set=0, binding=0) uniform sampler2D s;\n"
5931 "layout(location=0) out vec4 x;\n"
5932 "void main(){\n"
5933 " x = texture(s, vec2(1));\n"
5934 "}\n";
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005935 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5936 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5937 VkPipelineObj pipe(m_device);
5938 pipe.AddShader(&vs);
5939 pipe.AddShader(&fs);
5940 pipe.AddColorAttachment();
5941 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5942
5943 // First error case is destroying sampler prior to cmd buffer submission
Mark Lobodzinski33826372017-04-13 11:10:11 -06005944 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is invalid because bound Sampler");
Tony Barbour552f6c02016-12-21 14:34:07 -07005945 m_commandBuffer->BeginCommandBuffer();
5946 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005947 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5948 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5949 &descriptorSet, 0, NULL);
Rene Lindsaya31285f2017-01-11 16:35:53 -07005950 VkViewport viewport = {0, 0, 16, 16, 0, 1};
5951 VkRect2D scissor = {{0, 0}, {16, 16}};
5952 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
5953 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005954 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005955 m_commandBuffer->EndRenderPass();
5956 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005957 // Destroy sampler invalidates the cmd buffer, causing error on submit
5958 vkDestroySampler(m_device->device(), sampler, NULL);
5959 // Attempt to submit cmd buffer
5960 VkSubmitInfo submit_info = {};
5961 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5962 submit_info.commandBufferCount = 1;
5963 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5964 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5965 m_errorMonitor->VerifyFound();
Rene Lindsaya31285f2017-01-11 16:35:53 -07005966
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005967 // Now re-update descriptor with valid sampler and delete image
5968 img_info.sampler = sampler2;
5969 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Rene Lindsayed88b732017-01-27 15:55:29 -07005970
5971 VkCommandBufferBeginInfo info = {};
5972 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5973 info.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
5974
Mark Lobodzinski33826372017-04-13 11:10:11 -06005975 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound Image ");
Rene Lindsayed88b732017-01-27 15:55:29 -07005976 m_commandBuffer->BeginCommandBuffer(&info);
Tony Barbour552f6c02016-12-21 14:34:07 -07005977 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005978 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5979 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5980 &descriptorSet, 0, NULL);
Rene Lindsaya31285f2017-01-11 16:35:53 -07005981 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
5982 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005983 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005984 m_commandBuffer->EndRenderPass();
5985 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005986 // Destroy image invalidates the cmd buffer, causing error on submit
5987 vkDestroyImage(m_device->device(), image, NULL);
5988 // Attempt to submit cmd buffer
5989 submit_info = {};
5990 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5991 submit_info.commandBufferCount = 1;
5992 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5993 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5994 m_errorMonitor->VerifyFound();
5995 // Now update descriptor to be valid, but then free descriptor
5996 img_info.imageView = view2;
5997 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Rene Lindsayed88b732017-01-27 15:55:29 -07005998 m_commandBuffer->BeginCommandBuffer(&info);
Tony Barbour552f6c02016-12-21 14:34:07 -07005999 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006000 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
6001 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6002 &descriptorSet, 0, NULL);
Rene Lindsaya31285f2017-01-11 16:35:53 -07006003 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
6004 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06006005 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07006006 m_commandBuffer->EndRenderPass();
6007 m_commandBuffer->EndCommandBuffer();
Tony Barbourc373c012017-01-26 10:53:28 -07006008 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Dave Houltonfbf52152017-01-06 12:55:29 -07006009
6010 // Immediately try to destroy the descriptor set in the active command buffer - failure expected
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006011 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call vkFreeDescriptorSets() on descriptor set 0x");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06006012 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Mark Mueller917f6bc2016-08-30 10:57:19 -06006013 m_errorMonitor->VerifyFound();
Dave Houltonfbf52152017-01-06 12:55:29 -07006014
6015 // Try again once the queue is idle - should succeed w/o error
Dave Houltond5507dd2017-01-24 15:29:02 -07006016 // 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 -07006017 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07006018 m_errorMonitor->SetUnexpectedError(
6019 "pDescriptorSets must be a pointer to an array of descriptorSetCount VkDescriptorSet handles, each element of which must "
6020 "either be a valid handle or VK_NULL_HANDLE");
Mark Lobodzinski74597792017-04-11 15:43:49 -06006021 m_errorMonitor->SetUnexpectedError("Unable to remove DescriptorSet obj");
Dave Houltonfbf52152017-01-06 12:55:29 -07006022 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
6023
6024 // Attempt to submit cmd buffer containing the freed descriptor set
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06006025 submit_info = {};
6026 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6027 submit_info.commandBufferCount = 1;
6028 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Lobodzinski33826372017-04-13 11:10:11 -06006029 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound DescriptorSet ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06006030 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
6031 m_errorMonitor->VerifyFound();
Dave Houltonfbf52152017-01-06 12:55:29 -07006032
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06006033 // Cleanup
6034 vkFreeMemory(m_device->device(), image_memory, NULL);
6035 vkDestroySampler(m_device->device(), sampler2, NULL);
6036 vkDestroyImage(m_device->device(), image2, NULL);
6037 vkDestroyImageView(m_device->device(), view, NULL);
6038 vkDestroyImageView(m_device->device(), view2, NULL);
6039 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6040 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6041 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6042}
6043
Tobin Ehlisaabbcd02017-04-13 14:15:21 -06006044TEST_F(VkLayerTest, ImageDescriptorLayoutMismatch) {
6045 TEST_DESCRIPTION("Update an image sampler with a layout that doesn't match the actual image layout at the image is used.");
6046 ASSERT_NO_FATAL_FAILURE(Init(nullptr, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT));
6047 ASSERT_NO_FATAL_FAILURE(InitViewport());
6048 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6049
6050 VkDescriptorPoolSize ds_type_count = {};
6051 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6052 ds_type_count.descriptorCount = 1;
6053
6054 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6055 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6056 ds_pool_ci.pNext = NULL;
6057 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
6058 ds_pool_ci.maxSets = 1;
6059 ds_pool_ci.poolSizeCount = 1;
6060 ds_pool_ci.pPoolSizes = &ds_type_count;
6061
6062 VkDescriptorPool ds_pool;
6063 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
6064 ASSERT_VK_SUCCESS(err);
6065
6066 VkDescriptorSetLayoutBinding dsl_binding = {};
6067 dsl_binding.binding = 0;
6068 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6069 dsl_binding.descriptorCount = 1;
6070 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6071 dsl_binding.pImmutableSamplers = NULL;
6072
6073 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6074 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6075 ds_layout_ci.pNext = NULL;
6076 ds_layout_ci.bindingCount = 1;
6077 ds_layout_ci.pBindings = &dsl_binding;
6078 VkDescriptorSetLayout ds_layout;
6079 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
6080 ASSERT_VK_SUCCESS(err);
6081
6082 VkDescriptorSet descriptorSet;
6083 VkDescriptorSetAllocateInfo alloc_info = {};
6084 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6085 alloc_info.descriptorSetCount = 1;
6086 alloc_info.descriptorPool = ds_pool;
6087 alloc_info.pSetLayouts = &ds_layout;
6088 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
6089 ASSERT_VK_SUCCESS(err);
6090
6091 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6092 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6093 pipeline_layout_ci.pNext = NULL;
6094 pipeline_layout_ci.setLayoutCount = 1;
6095 pipeline_layout_ci.pSetLayouts = &ds_layout;
6096
6097 VkPipelineLayout pipeline_layout;
6098 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
6099 ASSERT_VK_SUCCESS(err);
6100
6101 // Create images to update the descriptor with
6102 const VkFormat format = VK_FORMAT_B8G8R8A8_UNORM;
6103 VkImageObj image(m_device);
6104 image.Init(32, 32, 1, format, VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VK_IMAGE_TILING_OPTIMAL,
6105 0);
6106 ASSERT_TRUE(image.initialized());
6107
6108 VkImageViewCreateInfo image_view_create_info = {};
6109 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
6110 image_view_create_info.image = image.handle();
6111 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
6112 image_view_create_info.format = format;
6113 image_view_create_info.subresourceRange.layerCount = 1;
6114 image_view_create_info.subresourceRange.baseMipLevel = 0;
6115 image_view_create_info.subresourceRange.levelCount = 1;
6116 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
6117
6118 VkImageView view;
6119 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
6120 ASSERT_VK_SUCCESS(err);
6121 // Create Sampler
6122 VkSamplerCreateInfo sampler_ci = {};
6123 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
6124 sampler_ci.pNext = NULL;
6125 sampler_ci.magFilter = VK_FILTER_NEAREST;
6126 sampler_ci.minFilter = VK_FILTER_NEAREST;
6127 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
6128 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6129 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6130 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6131 sampler_ci.mipLodBias = 1.0;
6132 sampler_ci.anisotropyEnable = VK_FALSE;
6133 sampler_ci.maxAnisotropy = 1;
6134 sampler_ci.compareEnable = VK_FALSE;
6135 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
6136 sampler_ci.minLod = 1.0;
6137 sampler_ci.maxLod = 1.0;
6138 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
6139 sampler_ci.unnormalizedCoordinates = VK_FALSE;
6140 VkSampler sampler;
6141 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
6142 ASSERT_VK_SUCCESS(err);
6143 // Update descriptor with image and sampler
6144 VkDescriptorImageInfo img_info = {};
6145 img_info.sampler = sampler;
6146 img_info.imageView = view;
6147 // This should cause a mis-match. Actual layout at use time is SHADER_RO
6148 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
6149
6150 VkWriteDescriptorSet descriptor_write;
6151 memset(&descriptor_write, 0, sizeof(descriptor_write));
6152 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6153 descriptor_write.dstSet = descriptorSet;
6154 descriptor_write.dstBinding = 0;
6155 descriptor_write.descriptorCount = 1;
6156 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6157 descriptor_write.pImageInfo = &img_info;
6158
6159 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6160
6161 // Create PSO to be used for draw-time errors below
6162 char const *vsSource =
6163 "#version 450\n"
6164 "\n"
6165 "out gl_PerVertex { \n"
6166 " vec4 gl_Position;\n"
6167 "};\n"
6168 "void main(){\n"
6169 " gl_Position = vec4(1);\n"
6170 "}\n";
6171 char const *fsSource =
6172 "#version 450\n"
6173 "\n"
6174 "layout(set=0, binding=0) uniform sampler2D s;\n"
6175 "layout(location=0) out vec4 x;\n"
6176 "void main(){\n"
6177 " x = texture(s, vec2(1));\n"
6178 "}\n";
6179 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6180 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
6181 VkPipelineObj pipe(m_device);
6182 pipe.AddShader(&vs);
6183 pipe.AddShader(&fs);
6184 pipe.AddColorAttachment();
6185 pipe.CreateVKPipeline(pipeline_layout, renderPass());
6186
6187 VkCommandBufferObj cmd_buf(m_device, m_commandPool);
6188 cmd_buf.BeginCommandBuffer();
Tobin Ehlisaabbcd02017-04-13 14:15:21 -06006189 // record layout different than actual descriptor layout of SHADER_RO
6190 image.SetLayout(&cmd_buf, VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL);
Mark Lobodzinski95512b72017-05-10 12:21:30 -06006191 cmd_buf.BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlisaabbcd02017-04-13 14:15:21 -06006192 vkCmdBindPipeline(cmd_buf.handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
6193 vkCmdBindDescriptorSets(cmd_buf.handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &descriptorSet, 0, NULL);
6194 VkViewport viewport = {0, 0, 16, 16, 0, 1};
6195 VkRect2D scissor = {{0, 0}, {16, 16}};
6196 vkCmdSetViewport(cmd_buf.handle(), 0, 1, &viewport);
6197 vkCmdSetScissor(cmd_buf.handle(), 0, 1, &scissor);
6198 // At draw time the update layout will mis-match the actual layout
6199 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6200 " with specific layout VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL that doesn't match the "
6201 "actual current layout VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL.");
6202 m_errorMonitor->SetDesiredFailureMsg(
6203 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6204 " Image layout specified at vkUpdateDescriptorSets() time doesn't match actual image layout at time descriptor is used.");
6205 cmd_buf.Draw(1, 0, 0, 0);
6206 m_errorMonitor->VerifyFound();
6207 cmd_buf.EndRenderPass();
6208 cmd_buf.EndCommandBuffer();
6209 // Submit cmd buffer
6210 VkSubmitInfo submit_info = {};
6211 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6212 submit_info.commandBufferCount = 1;
6213 submit_info.pCommandBuffers = &cmd_buf.handle();
6214 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
6215 vkQueueWaitIdle(m_device->m_queue);
6216 // Cleanup
6217 vkDestroySampler(m_device->device(), sampler, NULL);
6218 vkDestroyImageView(m_device->device(), view, NULL);
6219 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6220 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6221 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6222}
6223
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006224TEST_F(VkLayerTest, DescriptorPoolInUseDestroyedSignaled) {
6225 TEST_DESCRIPTION("Delete a DescriptorPool with a DescriptorSet that is in use.");
Tony Barbour1fa09702017-03-16 12:09:08 -06006226 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006227 ASSERT_NO_FATAL_FAILURE(InitViewport());
6228 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6229
6230 VkDescriptorPoolSize ds_type_count = {};
6231 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6232 ds_type_count.descriptorCount = 1;
6233
6234 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6235 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6236 ds_pool_ci.pNext = NULL;
6237 ds_pool_ci.maxSets = 1;
6238 ds_pool_ci.poolSizeCount = 1;
6239 ds_pool_ci.pPoolSizes = &ds_type_count;
6240
6241 VkDescriptorPool ds_pool;
6242 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
6243 ASSERT_VK_SUCCESS(err);
6244
6245 VkDescriptorSetLayoutBinding dsl_binding = {};
6246 dsl_binding.binding = 0;
6247 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6248 dsl_binding.descriptorCount = 1;
6249 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6250 dsl_binding.pImmutableSamplers = NULL;
6251
6252 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6253 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6254 ds_layout_ci.pNext = NULL;
6255 ds_layout_ci.bindingCount = 1;
6256 ds_layout_ci.pBindings = &dsl_binding;
6257 VkDescriptorSetLayout ds_layout;
6258 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
6259 ASSERT_VK_SUCCESS(err);
6260
6261 VkDescriptorSet descriptor_set;
6262 VkDescriptorSetAllocateInfo alloc_info = {};
6263 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6264 alloc_info.descriptorSetCount = 1;
6265 alloc_info.descriptorPool = ds_pool;
6266 alloc_info.pSetLayouts = &ds_layout;
6267 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
6268 ASSERT_VK_SUCCESS(err);
6269
6270 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6271 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6272 pipeline_layout_ci.pNext = NULL;
6273 pipeline_layout_ci.setLayoutCount = 1;
6274 pipeline_layout_ci.pSetLayouts = &ds_layout;
6275
6276 VkPipelineLayout pipeline_layout;
6277 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
6278 ASSERT_VK_SUCCESS(err);
6279
6280 // Create image to update the descriptor with
6281 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06006282 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 -06006283 ASSERT_TRUE(image.initialized());
6284
6285 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
6286 // Create Sampler
6287 VkSamplerCreateInfo sampler_ci = {};
6288 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
6289 sampler_ci.pNext = NULL;
6290 sampler_ci.magFilter = VK_FILTER_NEAREST;
6291 sampler_ci.minFilter = VK_FILTER_NEAREST;
6292 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
6293 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6294 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6295 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6296 sampler_ci.mipLodBias = 1.0;
6297 sampler_ci.anisotropyEnable = VK_FALSE;
6298 sampler_ci.maxAnisotropy = 1;
6299 sampler_ci.compareEnable = VK_FALSE;
6300 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
6301 sampler_ci.minLod = 1.0;
6302 sampler_ci.maxLod = 1.0;
6303 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
6304 sampler_ci.unnormalizedCoordinates = VK_FALSE;
6305 VkSampler sampler;
6306 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
6307 ASSERT_VK_SUCCESS(err);
6308 // Update descriptor with image and sampler
6309 VkDescriptorImageInfo img_info = {};
6310 img_info.sampler = sampler;
6311 img_info.imageView = view;
6312 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
6313
6314 VkWriteDescriptorSet descriptor_write;
6315 memset(&descriptor_write, 0, sizeof(descriptor_write));
6316 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6317 descriptor_write.dstSet = descriptor_set;
6318 descriptor_write.dstBinding = 0;
6319 descriptor_write.descriptorCount = 1;
6320 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6321 descriptor_write.pImageInfo = &img_info;
6322
6323 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6324
6325 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006326 char const *vsSource =
6327 "#version 450\n"
6328 "\n"
6329 "out gl_PerVertex { \n"
6330 " vec4 gl_Position;\n"
6331 "};\n"
6332 "void main(){\n"
6333 " gl_Position = vec4(1);\n"
6334 "}\n";
6335 char const *fsSource =
6336 "#version 450\n"
6337 "\n"
6338 "layout(set=0, binding=0) uniform sampler2D s;\n"
6339 "layout(location=0) out vec4 x;\n"
6340 "void main(){\n"
6341 " x = texture(s, vec2(1));\n"
6342 "}\n";
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006343 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6344 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
6345 VkPipelineObj pipe(m_device);
6346 pipe.AddShader(&vs);
6347 pipe.AddShader(&fs);
6348 pipe.AddColorAttachment();
6349 pipe.CreateVKPipeline(pipeline_layout, renderPass());
6350
Tony Barbour552f6c02016-12-21 14:34:07 -07006351 m_commandBuffer->BeginCommandBuffer();
6352 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006353 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
6354 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6355 &descriptor_set, 0, NULL);
Rene Lindsaye353a072017-01-16 11:07:28 -07006356
6357 VkViewport viewport = {0, 0, 16, 16, 0, 1};
6358 VkRect2D scissor = {{0, 0}, {16, 16}};
6359 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
6360 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
6361
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006362 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07006363 m_commandBuffer->EndRenderPass();
6364 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006365 // Submit cmd buffer to put pool in-flight
6366 VkSubmitInfo submit_info = {};
6367 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6368 submit_info.commandBufferCount = 1;
6369 submit_info.pCommandBuffers = &m_commandBuffer->handle();
6370 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
6371 // Destroy pool while in-flight, causing error
Mark Lobodzinski33826372017-04-13 11:10:11 -06006372 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete DescriptorPool ");
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006373 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6374 m_errorMonitor->VerifyFound();
6375 vkQueueWaitIdle(m_device->m_queue);
6376 // Cleanup
6377 vkDestroySampler(m_device->device(), sampler, NULL);
6378 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6379 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07006380 m_errorMonitor->SetUnexpectedError(
6381 "If descriptorPool is not VK_NULL_HANDLE, descriptorPool must be a valid VkDescriptorPool handle");
Mark Lobodzinski74597792017-04-11 15:43:49 -06006382 m_errorMonitor->SetUnexpectedError("Unable to remove DescriptorPool obj");
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006383 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Rene Lindsaye353a072017-01-16 11:07:28 -07006384 // TODO : It seems Validation layers think ds_pool was already destroyed, even though it wasn't?
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006385}
6386
Tobin Ehlis50a095d2016-09-21 17:32:49 -06006387TEST_F(VkLayerTest, DescriptorImageUpdateNoMemoryBound) {
6388 TEST_DESCRIPTION("Attempt an image descriptor set update where image's bound memory has been freed.");
Tony Barbour1fa09702017-03-16 12:09:08 -06006389 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis50a095d2016-09-21 17:32:49 -06006390 ASSERT_NO_FATAL_FAILURE(InitViewport());
6391 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6392
6393 VkDescriptorPoolSize ds_type_count = {};
6394 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6395 ds_type_count.descriptorCount = 1;
6396
6397 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6398 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6399 ds_pool_ci.pNext = NULL;
6400 ds_pool_ci.maxSets = 1;
6401 ds_pool_ci.poolSizeCount = 1;
6402 ds_pool_ci.pPoolSizes = &ds_type_count;
6403
6404 VkDescriptorPool ds_pool;
6405 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
6406 ASSERT_VK_SUCCESS(err);
6407
6408 VkDescriptorSetLayoutBinding dsl_binding = {};
6409 dsl_binding.binding = 0;
6410 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6411 dsl_binding.descriptorCount = 1;
6412 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6413 dsl_binding.pImmutableSamplers = NULL;
6414
6415 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6416 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6417 ds_layout_ci.pNext = NULL;
6418 ds_layout_ci.bindingCount = 1;
6419 ds_layout_ci.pBindings = &dsl_binding;
6420 VkDescriptorSetLayout ds_layout;
6421 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
6422 ASSERT_VK_SUCCESS(err);
6423
6424 VkDescriptorSet descriptorSet;
6425 VkDescriptorSetAllocateInfo alloc_info = {};
6426 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6427 alloc_info.descriptorSetCount = 1;
6428 alloc_info.descriptorPool = ds_pool;
6429 alloc_info.pSetLayouts = &ds_layout;
6430 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
6431 ASSERT_VK_SUCCESS(err);
6432
6433 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6434 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6435 pipeline_layout_ci.pNext = NULL;
6436 pipeline_layout_ci.setLayoutCount = 1;
6437 pipeline_layout_ci.pSetLayouts = &ds_layout;
6438
6439 VkPipelineLayout pipeline_layout;
6440 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
6441 ASSERT_VK_SUCCESS(err);
6442
6443 // Create images to update the descriptor with
6444 VkImage image;
6445 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
6446 const int32_t tex_width = 32;
6447 const int32_t tex_height = 32;
6448 VkImageCreateInfo image_create_info = {};
6449 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6450 image_create_info.pNext = NULL;
6451 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6452 image_create_info.format = tex_format;
6453 image_create_info.extent.width = tex_width;
6454 image_create_info.extent.height = tex_height;
6455 image_create_info.extent.depth = 1;
6456 image_create_info.mipLevels = 1;
6457 image_create_info.arrayLayers = 1;
6458 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
6459 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
6460 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
6461 image_create_info.flags = 0;
6462 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
6463 ASSERT_VK_SUCCESS(err);
6464 // Initially bind memory to avoid error at bind view time. We'll break binding before update.
6465 VkMemoryRequirements memory_reqs;
6466 VkDeviceMemory image_memory;
6467 bool pass;
6468 VkMemoryAllocateInfo memory_info = {};
6469 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6470 memory_info.pNext = NULL;
6471 memory_info.allocationSize = 0;
6472 memory_info.memoryTypeIndex = 0;
6473 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
6474 // Allocate enough memory for image
6475 memory_info.allocationSize = memory_reqs.size;
6476 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
6477 ASSERT_TRUE(pass);
6478 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
6479 ASSERT_VK_SUCCESS(err);
6480 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
6481 ASSERT_VK_SUCCESS(err);
6482
6483 VkImageViewCreateInfo image_view_create_info = {};
6484 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
6485 image_view_create_info.image = image;
6486 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
6487 image_view_create_info.format = tex_format;
6488 image_view_create_info.subresourceRange.layerCount = 1;
6489 image_view_create_info.subresourceRange.baseMipLevel = 0;
6490 image_view_create_info.subresourceRange.levelCount = 1;
6491 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
6492
6493 VkImageView view;
6494 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
6495 ASSERT_VK_SUCCESS(err);
6496 // Create Samplers
6497 VkSamplerCreateInfo sampler_ci = {};
6498 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
6499 sampler_ci.pNext = NULL;
6500 sampler_ci.magFilter = VK_FILTER_NEAREST;
6501 sampler_ci.minFilter = VK_FILTER_NEAREST;
6502 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
6503 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6504 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6505 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6506 sampler_ci.mipLodBias = 1.0;
6507 sampler_ci.anisotropyEnable = VK_FALSE;
6508 sampler_ci.maxAnisotropy = 1;
6509 sampler_ci.compareEnable = VK_FALSE;
6510 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
6511 sampler_ci.minLod = 1.0;
6512 sampler_ci.maxLod = 1.0;
6513 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
6514 sampler_ci.unnormalizedCoordinates = VK_FALSE;
6515 VkSampler sampler;
6516 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
6517 ASSERT_VK_SUCCESS(err);
6518 // Update descriptor with image and sampler
6519 VkDescriptorImageInfo img_info = {};
6520 img_info.sampler = sampler;
6521 img_info.imageView = view;
6522 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
6523
6524 VkWriteDescriptorSet descriptor_write;
6525 memset(&descriptor_write, 0, sizeof(descriptor_write));
6526 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6527 descriptor_write.dstSet = descriptorSet;
6528 descriptor_write.dstBinding = 0;
6529 descriptor_write.descriptorCount = 1;
6530 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6531 descriptor_write.pImageInfo = &img_info;
6532 // Break memory binding and attempt update
6533 vkFreeMemory(m_device->device(), image_memory, nullptr);
6534 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006535 " previously bound memory was freed. Memory must not be freed prior to this operation.");
Tobin Ehlis50a095d2016-09-21 17:32:49 -06006536 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6537 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
6538 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6539 m_errorMonitor->VerifyFound();
6540 // Cleanup
6541 vkDestroyImage(m_device->device(), image, NULL);
6542 vkDestroySampler(m_device->device(), sampler, NULL);
6543 vkDestroyImageView(m_device->device(), view, NULL);
6544 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6545 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6546 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6547}
6548
Karl Schultz6addd812016-02-02 17:17:23 -07006549TEST_F(VkLayerTest, InvalidPipeline) {
Karl Schultzbdb75952016-04-19 11:36:49 -06006550 // Attempt to bind an invalid Pipeline to a valid Command Buffer
6551 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06006552 // Create a valid cmd buffer
6553 // call vkCmdBindPipeline w/ false Pipeline
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06006554 uint64_t fake_pipeline_handle = 0xbaad6001;
6555 VkPipeline bad_pipeline = reinterpret_cast<VkPipeline &>(fake_pipeline_handle);
Tony Barbour1fa09702017-03-16 12:09:08 -06006556 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes4dbf70f2016-09-16 17:58:00 +12006557 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6558
Karl Schultzf78bcdd2016-11-30 12:36:01 -07006559 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00601);
Tony Barbour552f6c02016-12-21 14:34:07 -07006560 m_commandBuffer->BeginCommandBuffer();
6561 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006562 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, bad_pipeline);
Karl Schultzbdb75952016-04-19 11:36:49 -06006563 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12006564
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06006565 // Now issue a draw call with no pipeline bound
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006566 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 -06006567 Draw(1, 0, 0, 0);
6568 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12006569
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06006570 // Finally same check once more but with Dispatch/Compute
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006571 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 -07006572 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); // must be outside renderpass
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06006573 vkCmdDispatch(m_commandBuffer->GetBufferHandle(), 0, 0, 0);
6574 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06006575}
6576
Karl Schultz6addd812016-02-02 17:17:23 -07006577TEST_F(VkLayerTest, DescriptorSetNotUpdated) {
Tobin Ehlis5a5f5ef2016-08-17 13:56:55 -06006578 TEST_DESCRIPTION("Bind a descriptor set that hasn't been updated.");
Karl Schultz6addd812016-02-02 17:17:23 -07006579 VkResult err;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006580
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006581 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " bound but it was never updated. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006582
Tony Barbour1fa09702017-03-16 12:09:08 -06006583 ASSERT_NO_FATAL_FAILURE(Init());
Mike Stroyan713b2d72015-08-04 10:49:29 -06006584 ASSERT_NO_FATAL_FAILURE(InitViewport());
6585 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006586 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006587 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6588 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06006589
6590 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006591 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6592 ds_pool_ci.pNext = NULL;
6593 ds_pool_ci.maxSets = 1;
6594 ds_pool_ci.poolSizeCount = 1;
6595 ds_pool_ci.pPoolSizes = &ds_type_count;
Mike Stroyan713b2d72015-08-04 10:49:29 -06006596
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006597 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006598 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006599 ASSERT_VK_SUCCESS(err);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006600
Tony Barboureb254902015-07-15 12:50:33 -06006601 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006602 dsl_binding.binding = 0;
6603 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6604 dsl_binding.descriptorCount = 1;
6605 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6606 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006607
Tony Barboureb254902015-07-15 12:50:33 -06006608 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006609 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6610 ds_layout_ci.pNext = NULL;
6611 ds_layout_ci.bindingCount = 1;
6612 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006613 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006614 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006615 ASSERT_VK_SUCCESS(err);
6616
6617 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006618 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006619 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006620 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006621 alloc_info.descriptorPool = ds_pool;
6622 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006623 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006624 ASSERT_VK_SUCCESS(err);
6625
Tony Barboureb254902015-07-15 12:50:33 -06006626 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006627 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6628 pipeline_layout_ci.pNext = NULL;
6629 pipeline_layout_ci.setLayoutCount = 1;
6630 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006631
6632 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006633 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006634 ASSERT_VK_SUCCESS(err);
6635
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006636 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06006637 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07006638 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006639 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006640
Tony Barbourc95e4ac2015-08-04 17:05:26 -06006641 VkPipelineObj pipe(m_device);
6642 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06006643 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06006644 pipe.AddColorAttachment();
Tony Barbourc95e4ac2015-08-04 17:05:26 -06006645 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06006646
Tony Barbour552f6c02016-12-21 14:34:07 -07006647 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006648 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
6649 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6650 &descriptorSet, 0, NULL);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006651
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006652 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06006653
Chia-I Wuf7458c52015-10-26 21:10:41 +08006654 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6655 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6656 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006657}
6658
Karl Schultz6addd812016-02-02 17:17:23 -07006659TEST_F(VkLayerTest, InvalidBufferViewObject) {
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006660 // Create a single TEXEL_BUFFER descriptor and send it an invalid bufferView
Karl Schultz6addd812016-02-02 17:17:23 -07006661 VkResult err;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006662
Karl Schultzf78bcdd2016-11-30 12:36:01 -07006663 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00940);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006664
Tony Barbour1fa09702017-03-16 12:09:08 -06006665 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006666 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006667 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
6668 ds_type_count.descriptorCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006669
6670 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006671 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6672 ds_pool_ci.pNext = NULL;
6673 ds_pool_ci.maxSets = 1;
6674 ds_pool_ci.poolSizeCount = 1;
6675 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006676
6677 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006678 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006679 ASSERT_VK_SUCCESS(err);
6680
6681 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006682 dsl_binding.binding = 0;
6683 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
6684 dsl_binding.descriptorCount = 1;
6685 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6686 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006687
6688 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006689 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6690 ds_layout_ci.pNext = NULL;
6691 ds_layout_ci.bindingCount = 1;
6692 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006693 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006694 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006695 ASSERT_VK_SUCCESS(err);
6696
6697 VkDescriptorSet descriptorSet;
6698 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006699 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006700 alloc_info.descriptorSetCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006701 alloc_info.descriptorPool = ds_pool;
6702 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006703 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006704 ASSERT_VK_SUCCESS(err);
6705
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006706 VkBufferView view = (VkBufferView)((size_t)0xbaadbeef); // invalid bufferView object
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006707 VkWriteDescriptorSet descriptor_write;
6708 memset(&descriptor_write, 0, sizeof(descriptor_write));
6709 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6710 descriptor_write.dstSet = descriptorSet;
6711 descriptor_write.dstBinding = 0;
6712 descriptor_write.descriptorCount = 1;
6713 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
6714 descriptor_write.pTexelBufferView = &view;
6715
6716 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6717
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006718 m_errorMonitor->VerifyFound();
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006719
6720 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6721 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6722}
6723
Mark Youngd339ba32016-05-30 13:28:35 -06006724TEST_F(VkLayerTest, CreateBufferViewNoMemoryBoundToBuffer) {
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006725 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 -06006726
6727 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06006728 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006729 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -06006730
Tony Barbour1fa09702017-03-16 12:09:08 -06006731 ASSERT_NO_FATAL_FAILURE(Init());
Mark Youngd339ba32016-05-30 13:28:35 -06006732
6733 // Create a buffer with no bound memory and then attempt to create
6734 // a buffer view.
6735 VkBufferCreateInfo buff_ci = {};
6736 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes4538d242016-09-13 18:13:58 +12006737 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -06006738 buff_ci.size = 256;
6739 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
6740 VkBuffer buffer;
6741 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
6742 ASSERT_VK_SUCCESS(err);
6743
6744 VkBufferViewCreateInfo buff_view_ci = {};
6745 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
6746 buff_view_ci.buffer = buffer;
6747 buff_view_ci.format = VK_FORMAT_R8_UNORM;
6748 buff_view_ci.range = VK_WHOLE_SIZE;
6749 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006750 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Mark Youngd339ba32016-05-30 13:28:35 -06006751
6752 m_errorMonitor->VerifyFound();
6753 vkDestroyBuffer(m_device->device(), buffer, NULL);
6754 // If last error is success, it still created the view, so delete it.
6755 if (err == VK_SUCCESS) {
6756 vkDestroyBufferView(m_device->device(), buff_view, NULL);
6757 }
6758}
6759
Karl Schultz6addd812016-02-02 17:17:23 -07006760TEST_F(VkLayerTest, InvalidDynamicOffsetCases) {
6761 // Create a descriptorSet w/ dynamic descriptor and then hit 3 offset error
6762 // cases:
Tobin Ehlisf6585052015-12-17 11:48:42 -07006763 // 1. No dynamicOffset supplied
6764 // 2. Too many dynamicOffsets supplied
6765 // 3. Dynamic offset oversteps buffer being updated
Karl Schultz6addd812016-02-02 17:17:23 -07006766 VkResult err;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006767 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6768 " requires 1 dynamicOffsets, but only "
6769 "0 dynamicOffsets are left in "
6770 "pDynamicOffsets ");
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006771
Tony Barbour1fa09702017-03-16 12:09:08 -06006772 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006773 ASSERT_NO_FATAL_FAILURE(InitViewport());
6774 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6775
6776 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006777 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6778 ds_type_count.descriptorCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006779
6780 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006781 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6782 ds_pool_ci.pNext = NULL;
6783 ds_pool_ci.maxSets = 1;
6784 ds_pool_ci.poolSizeCount = 1;
6785 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006786
6787 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006788 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006789 ASSERT_VK_SUCCESS(err);
6790
6791 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006792 dsl_binding.binding = 0;
6793 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6794 dsl_binding.descriptorCount = 1;
6795 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6796 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006797
6798 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006799 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6800 ds_layout_ci.pNext = NULL;
6801 ds_layout_ci.bindingCount = 1;
6802 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006803 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006804 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006805 ASSERT_VK_SUCCESS(err);
6806
6807 VkDescriptorSet descriptorSet;
6808 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006809 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006810 alloc_info.descriptorSetCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006811 alloc_info.descriptorPool = ds_pool;
6812 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006813 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006814 ASSERT_VK_SUCCESS(err);
6815
6816 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006817 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6818 pipeline_layout_ci.pNext = NULL;
6819 pipeline_layout_ci.setLayoutCount = 1;
6820 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006821
6822 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006823 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006824 ASSERT_VK_SUCCESS(err);
6825
6826 // Create a buffer to update the descriptor with
6827 uint32_t qfi = 0;
6828 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006829 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6830 buffCI.size = 1024;
6831 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6832 buffCI.queueFamilyIndexCount = 1;
6833 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006834
6835 VkBuffer dyub;
6836 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6837 ASSERT_VK_SUCCESS(err);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006838 // Allocate memory and bind to buffer so we can make it to the appropriate
6839 // error
6840 VkMemoryAllocateInfo mem_alloc = {};
6841 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6842 mem_alloc.pNext = NULL;
6843 mem_alloc.allocationSize = 1024;
Chris Forbesb6116cc2016-05-08 11:39:59 +12006844 mem_alloc.memoryTypeIndex = 0;
6845
6846 VkMemoryRequirements memReqs;
6847 vkGetBufferMemoryRequirements(m_device->device(), dyub, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006848 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Chris Forbesb6116cc2016-05-08 11:39:59 +12006849 if (!pass) {
6850 vkDestroyBuffer(m_device->device(), dyub, NULL);
6851 return;
6852 }
6853
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006854 VkDeviceMemory mem;
6855 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
6856 ASSERT_VK_SUCCESS(err);
6857 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
6858 ASSERT_VK_SUCCESS(err);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006859 // Correctly update descriptor to avoid "NOT_UPDATED" error
6860 VkDescriptorBufferInfo buffInfo = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006861 buffInfo.buffer = dyub;
6862 buffInfo.offset = 0;
6863 buffInfo.range = 1024;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006864
6865 VkWriteDescriptorSet descriptor_write;
6866 memset(&descriptor_write, 0, sizeof(descriptor_write));
6867 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6868 descriptor_write.dstSet = descriptorSet;
6869 descriptor_write.dstBinding = 0;
6870 descriptor_write.descriptorCount = 1;
6871 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6872 descriptor_write.pBufferInfo = &buffInfo;
6873
6874 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6875
Tony Barbour552f6c02016-12-21 14:34:07 -07006876 m_commandBuffer->BeginCommandBuffer();
6877 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006878 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6879 &descriptorSet, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006880 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07006881 uint32_t pDynOff[2] = {512, 756};
6882 // Now cause error b/c too many dynOffsets in array for # of dyn descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006883 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6884 "Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but ");
6885 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6886 &descriptorSet, 2, pDynOff);
Chris Forbes7b342802016-04-07 13:20:10 +12006887 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07006888 // Finally cause error due to dynamicOffset being too big
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006889 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6890 " dynamic offset 512 combined with "
6891 "offset 0 and range 1024 that "
6892 "oversteps the buffer size of 1024");
Tobin Ehlisf6585052015-12-17 11:48:42 -07006893 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006894 char const *vsSource =
6895 "#version 450\n"
6896 "\n"
6897 "out gl_PerVertex { \n"
6898 " vec4 gl_Position;\n"
6899 "};\n"
6900 "void main(){\n"
6901 " gl_Position = vec4(1);\n"
6902 "}\n";
6903 char const *fsSource =
6904 "#version 450\n"
6905 "\n"
6906 "layout(location=0) out vec4 x;\n"
6907 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
6908 "void main(){\n"
6909 " x = vec4(bar.y);\n"
6910 "}\n";
Tobin Ehlisf6585052015-12-17 11:48:42 -07006911 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6912 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
6913 VkPipelineObj pipe(m_device);
6914 pipe.AddShader(&vs);
6915 pipe.AddShader(&fs);
6916 pipe.AddColorAttachment();
6917 pipe.CreateVKPipeline(pipeline_layout, renderPass());
6918
Rene Lindsayacbf5e62016-12-15 18:47:11 -07006919 VkViewport viewport = {0, 0, 16, 16, 0, 1};
6920 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
6921 VkRect2D scissor = {{0, 0}, {16, 16}};
6922 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
6923
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006924 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07006925 // This update should succeed, but offset size of 512 will overstep buffer
6926 // /w range 1024 & size 1024
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006927 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6928 &descriptorSet, 1, pDynOff);
Tobin Ehlisf6585052015-12-17 11:48:42 -07006929 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006930 m_errorMonitor->VerifyFound();
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006931
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006932 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis512098e2016-05-05 09:06:12 -06006933 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006934
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006935 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06006936 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006937 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6938}
6939
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006940TEST_F(VkLayerTest, DescriptorBufferUpdateNoMemoryBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006941 TEST_DESCRIPTION(
6942 "Attempt to update a descriptor with a non-sparse buffer "
6943 "that doesn't have memory bound");
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006944 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06006945 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006946 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Tobin Ehlisfed999f2016-09-21 15:09:45 -06006947 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6948 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006949
Tony Barbour1fa09702017-03-16 12:09:08 -06006950 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006951 ASSERT_NO_FATAL_FAILURE(InitViewport());
6952 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6953
6954 VkDescriptorPoolSize ds_type_count = {};
6955 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6956 ds_type_count.descriptorCount = 1;
6957
6958 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6959 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6960 ds_pool_ci.pNext = NULL;
6961 ds_pool_ci.maxSets = 1;
6962 ds_pool_ci.poolSizeCount = 1;
6963 ds_pool_ci.pPoolSizes = &ds_type_count;
6964
6965 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006966 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006967 ASSERT_VK_SUCCESS(err);
6968
6969 VkDescriptorSetLayoutBinding dsl_binding = {};
6970 dsl_binding.binding = 0;
6971 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6972 dsl_binding.descriptorCount = 1;
6973 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6974 dsl_binding.pImmutableSamplers = NULL;
6975
6976 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6977 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6978 ds_layout_ci.pNext = NULL;
6979 ds_layout_ci.bindingCount = 1;
6980 ds_layout_ci.pBindings = &dsl_binding;
6981 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006982 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006983 ASSERT_VK_SUCCESS(err);
6984
6985 VkDescriptorSet descriptorSet;
6986 VkDescriptorSetAllocateInfo alloc_info = {};
6987 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6988 alloc_info.descriptorSetCount = 1;
6989 alloc_info.descriptorPool = ds_pool;
6990 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006991 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006992 ASSERT_VK_SUCCESS(err);
6993
6994 // Create a buffer to update the descriptor with
6995 uint32_t qfi = 0;
6996 VkBufferCreateInfo buffCI = {};
6997 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6998 buffCI.size = 1024;
6999 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
7000 buffCI.queueFamilyIndexCount = 1;
7001 buffCI.pQueueFamilyIndices = &qfi;
7002
7003 VkBuffer dyub;
7004 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
7005 ASSERT_VK_SUCCESS(err);
7006
7007 // Attempt to update descriptor without binding memory to it
7008 VkDescriptorBufferInfo buffInfo = {};
7009 buffInfo.buffer = dyub;
7010 buffInfo.offset = 0;
7011 buffInfo.range = 1024;
7012
7013 VkWriteDescriptorSet descriptor_write;
7014 memset(&descriptor_write, 0, sizeof(descriptor_write));
7015 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
7016 descriptor_write.dstSet = descriptorSet;
7017 descriptor_write.dstBinding = 0;
7018 descriptor_write.descriptorCount = 1;
7019 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
7020 descriptor_write.pBufferInfo = &buffInfo;
7021
7022 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
7023 m_errorMonitor->VerifyFound();
7024
7025 vkDestroyBuffer(m_device->device(), dyub, NULL);
7026 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7027 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
7028}
7029
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07007030TEST_F(VkLayerTest, InvalidPushConstants) {
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07007031 VkResult err;
Tony Barbour1fa09702017-03-16 12:09:08 -06007032 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07007033 ASSERT_NO_FATAL_FAILURE(InitViewport());
7034 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7035
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007036 VkPipelineLayout pipeline_layout;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07007037 VkPushConstantRange pc_range = {};
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07007038 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7039 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7040 pipeline_layout_ci.pushConstantRangeCount = 1;
7041 pipeline_layout_ci.pPushConstantRanges = &pc_range;
7042
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007043 //
7044 // Check for invalid push constant ranges in pipeline layouts.
7045 //
7046 struct PipelineLayoutTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06007047 VkPushConstantRange const range;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007048 char const *msg;
7049 };
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07007050
Karl Schultzc81037d2016-05-12 08:11:23 -06007051 const uint32_t too_big = m_device->props.limits.maxPushConstantsSize + 0x4;
7052 const std::array<PipelineLayoutTestCase, 10> range_tests = {{
7053 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0},
7054 "vkCreatePipelineLayout() call has push constants index 0 with "
7055 "size 0."},
7056 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
7057 "vkCreatePipelineLayout() call has push constants index 0 with "
7058 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06007059 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Karl Schultzc81037d2016-05-12 08:11:23 -06007060 "vkCreatePipelineLayout() call has push constants index 0 with "
7061 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06007062 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 0},
Karl Schultzc81037d2016-05-12 08:11:23 -06007063 "vkCreatePipelineLayout() call has push constants index 0 with "
7064 "size 0."},
7065 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
7066 "vkCreatePipelineLayout() call has push constants index 0 with "
7067 "offset 1. Offset must"},
7068 {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big},
7069 "vkCreatePipelineLayout() call has push constants index 0 "
7070 "with offset "},
7071 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big},
7072 "vkCreatePipelineLayout() call has push constants "
7073 "index 0 with offset "},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06007074 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06007075 "vkCreatePipelineLayout() call has push constants index 0 "
7076 "with offset "},
7077 {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020},
7078 "vkCreatePipelineLayout() call has push "
7079 "constants index 0 with offset "},
7080 {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0},
7081 "vkCreatePipelineLayout() call has push "
7082 "constants index 0 with offset "},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007083 }};
7084
7085 // Check for invalid offset and size
Karl Schultzc81037d2016-05-12 08:11:23 -06007086 for (const auto &iter : range_tests) {
7087 pc_range = iter.range;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007088 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
7089 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007090 m_errorMonitor->VerifyFound();
7091 if (VK_SUCCESS == err) {
7092 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7093 }
7094 }
7095
7096 // Check for invalid stage flag
7097 pc_range.offset = 0;
7098 pc_range.size = 16;
7099 pc_range.stageFlags = 0;
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06007100 m_errorMonitor->SetDesiredFailureMsg(
7101 VK_DEBUG_REPORT_ERROR_BIT_EXT,
7102 "vkCreatePipelineLayout: value of pCreateInfo->pPushConstantRanges[0].stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007103 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007104 m_errorMonitor->VerifyFound();
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007105 if (VK_SUCCESS == err) {
7106 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7107 }
7108
Karl Schultzc59b72d2017-02-24 15:45:05 -07007109 // Check for duplicate stage flags in a list of push constant ranges.
7110 // A shader can only have one push constant block and that block is mapped
7111 // to the push constant range that has that shader's stage flag set.
7112 // The shader's stage flag can only appear once in all the ranges, so the
7113 // implementation can find the one and only range to map it to.
Karl Schultzc81037d2016-05-12 08:11:23 -06007114 const uint32_t ranges_per_test = 5;
Karl Schultzc59b72d2017-02-24 15:45:05 -07007115 struct DuplicateStageFlagsTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06007116 VkPushConstantRange const ranges[ranges_per_test];
Jeremy Hayesde6d96c2017-02-01 15:22:32 -07007117 std::vector<char const *> const msg;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007118 };
Karl Schultzc59b72d2017-02-24 15:45:05 -07007119 // Overlapping ranges are OK, but a stage flag can appear only once.
7120 const std::array<DuplicateStageFlagsTestCase, 3> duplicate_stageFlags_tests = {
7121 {
7122 {{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
7123 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
7124 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
7125 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007126 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzc59b72d2017-02-24 15:45:05 -07007127 {
7128 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 0 and 1.",
7129 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 0 and 2.",
7130 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 0 and 3.",
7131 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 0 and 4.",
7132 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 1 and 2.",
7133 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 1 and 3.",
7134 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 1 and 4.",
7135 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 2 and 3.",
7136 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 2 and 4.",
7137 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 3 and 4.",
7138 }},
7139 {{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
7140 {VK_SHADER_STAGE_GEOMETRY_BIT, 0, 4},
7141 {VK_SHADER_STAGE_FRAGMENT_BIT, 0, 4},
7142 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
7143 {VK_SHADER_STAGE_GEOMETRY_BIT, 0, 4}},
7144 {
7145 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 0 and 3.",
7146 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 1 and 4.",
7147 }},
7148 {{{VK_SHADER_STAGE_FRAGMENT_BIT, 0, 4},
7149 {VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 4},
7150 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
7151 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
7152 {VK_SHADER_STAGE_GEOMETRY_BIT, 0, 4}},
7153 {
7154 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 2 and 3.",
7155 }},
7156 },
7157 };
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007158
Karl Schultzc59b72d2017-02-24 15:45:05 -07007159 for (const auto &iter : duplicate_stageFlags_tests) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007160 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
Karl Schultzc81037d2016-05-12 08:11:23 -06007161 pipeline_layout_ci.pushConstantRangeCount = ranges_per_test;
Karl Schultzc59b72d2017-02-24 15:45:05 -07007162 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg.begin(), iter.msg.end());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007163 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007164 m_errorMonitor->VerifyFound();
7165 if (VK_SUCCESS == err) {
7166 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7167 }
7168 }
7169
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007170 //
7171 // CmdPushConstants tests
7172 //
7173
Karl Schultzc59b72d2017-02-24 15:45:05 -07007174 // Setup a pipeline layout with ranges: [0,16) [64,80)
Karl Schultzc81037d2016-05-12 08:11:23 -06007175 const VkPushConstantRange pc_range2[] = {
Karl Schultzc59b72d2017-02-24 15:45:05 -07007176 {VK_SHADER_STAGE_VERTEX_BIT, 64, 16}, {VK_SHADER_STAGE_FRAGMENT_BIT, 0, 16},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007177 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007178 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range2) / sizeof(VkPushConstantRange);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007179 pipeline_layout_ci.pPushConstantRanges = pc_range2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007180 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07007181 ASSERT_VK_SUCCESS(err);
Karl Schultzc59b72d2017-02-24 15:45:05 -07007182
7183 const uint8_t dummy_values[100] = {};
7184
7185 m_commandBuffer->BeginCommandBuffer();
7186 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007187
7188 // Check for invalid stage flag
Karl Schultzc59b72d2017-02-24 15:45:05 -07007189 // Note that VU 00996 isn't reached due to parameter validation
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06007190 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdPushConstants: value of stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007191 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, 0, 0, 16, dummy_values);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007192 m_errorMonitor->VerifyFound();
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007193
Karl Schultzc59b72d2017-02-24 15:45:05 -07007194 m_errorMonitor->ExpectSuccess();
7195 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, VK_SHADER_STAGE_FRAGMENT_BIT, 0, 16, dummy_values);
7196 m_errorMonitor->VerifyNotFound();
7197 m_errorMonitor->ExpectSuccess();
7198 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, VK_SHADER_STAGE_VERTEX_BIT, 64, 16, dummy_values);
7199 m_errorMonitor->VerifyNotFound();
7200 const std::array<VkPushConstantRange, 6> cmd_range_tests = {{
7201 {VK_SHADER_STAGE_FRAGMENT_BIT, 64, 16},
7202 {VK_SHADER_STAGE_VERTEX_BIT, 0, 16},
7203 {VK_SHADER_STAGE_GEOMETRY_BIT, 0, 16},
7204 {VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT, 0, 16},
7205 {VK_SHADER_STAGE_VERTEX_BIT, 24, 16},
7206 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06007207 }};
Karl Schultzc59b72d2017-02-24 15:45:05 -07007208 for (const auto &iter : cmd_range_tests) {
7209 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00988);
7210 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.stageFlags, iter.offset, iter.size,
7211 dummy_values);
Karl Schultzc81037d2016-05-12 08:11:23 -06007212 m_errorMonitor->VerifyFound();
7213 }
Karl Schultzc81037d2016-05-12 08:11:23 -06007214
Tony Barbour552f6c02016-12-21 14:34:07 -07007215 m_commandBuffer->EndRenderPass();
7216 m_commandBuffer->EndCommandBuffer();
Karl Schultzc59b72d2017-02-24 15:45:05 -07007217 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07007218}
7219
Karl Schultz6addd812016-02-02 17:17:23 -07007220TEST_F(VkLayerTest, DescriptorSetCompatibility) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07007221 // Test various desriptorSet errors with bad binding combinations
Karl Schultz6addd812016-02-02 17:17:23 -07007222 VkResult err;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007223
Tony Barbour1fa09702017-03-16 12:09:08 -06007224 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis559c6382015-11-05 09:52:49 -07007225 ASSERT_NO_FATAL_FAILURE(InitViewport());
7226 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7227
7228 static const uint32_t NUM_DESCRIPTOR_TYPES = 5;
7229 VkDescriptorPoolSize ds_type_count[NUM_DESCRIPTOR_TYPES] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007230 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7231 ds_type_count[0].descriptorCount = 10;
7232 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
7233 ds_type_count[1].descriptorCount = 2;
7234 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
7235 ds_type_count[2].descriptorCount = 2;
7236 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_SAMPLER;
7237 ds_type_count[3].descriptorCount = 5;
7238 // TODO : LunarG ILO driver currently asserts in desc.c w/ INPUT_ATTACHMENT
7239 // type
7240 // ds_type_count[4].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
7241 ds_type_count[4].type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
7242 ds_type_count[4].descriptorCount = 2;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007243
7244 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007245 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7246 ds_pool_ci.pNext = NULL;
7247 ds_pool_ci.maxSets = 5;
7248 ds_pool_ci.poolSizeCount = NUM_DESCRIPTOR_TYPES;
7249 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007250
7251 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007252 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007253 ASSERT_VK_SUCCESS(err);
7254
7255 static const uint32_t MAX_DS_TYPES_IN_LAYOUT = 2;
7256 VkDescriptorSetLayoutBinding dsl_binding[MAX_DS_TYPES_IN_LAYOUT] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007257 dsl_binding[0].binding = 0;
7258 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7259 dsl_binding[0].descriptorCount = 5;
7260 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
7261 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007262
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007263 // Create layout identical to set0 layout but w/ different stageFlags
7264 VkDescriptorSetLayoutBinding dsl_fs_stage_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007265 dsl_fs_stage_only.binding = 0;
7266 dsl_fs_stage_only.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7267 dsl_fs_stage_only.descriptorCount = 5;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007268 dsl_fs_stage_only.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; // Different stageFlags to cause error at
7269 // bind time
Karl Schultz6addd812016-02-02 17:17:23 -07007270 dsl_fs_stage_only.pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007271 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007272 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7273 ds_layout_ci.pNext = NULL;
7274 ds_layout_ci.bindingCount = 1;
7275 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007276 static const uint32_t NUM_LAYOUTS = 4;
7277 VkDescriptorSetLayout ds_layout[NUM_LAYOUTS] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007278 VkDescriptorSetLayout ds_layout_fs_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007279 // Create 4 unique layouts for full pipelineLayout, and 1 special fs-only
7280 // layout for error case
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007281 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[0]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007282 ASSERT_VK_SUCCESS(err);
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07007283 ds_layout_ci.pBindings = &dsl_fs_stage_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007284 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007285 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007286 dsl_binding[0].binding = 0;
7287 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007288 dsl_binding[0].descriptorCount = 2;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07007289 dsl_binding[1].binding = 1;
7290 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
7291 dsl_binding[1].descriptorCount = 2;
7292 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
7293 dsl_binding[1].pImmutableSamplers = NULL;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07007294 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007295 ds_layout_ci.bindingCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007296 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[1]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007297 ASSERT_VK_SUCCESS(err);
7298 dsl_binding[0].binding = 0;
7299 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007300 dsl_binding[0].descriptorCount = 5;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007301 ds_layout_ci.bindingCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007302 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[2]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007303 ASSERT_VK_SUCCESS(err);
7304 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007305 dsl_binding[0].descriptorCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007306 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[3]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007307 ASSERT_VK_SUCCESS(err);
7308
7309 static const uint32_t NUM_SETS = 4;
7310 VkDescriptorSet descriptorSet[NUM_SETS] = {};
7311 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007312 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007313 alloc_info.descriptorSetCount = NUM_LAYOUTS;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007314 alloc_info.descriptorPool = ds_pool;
7315 alloc_info.pSetLayouts = ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007316 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptorSet);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007317 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007318 VkDescriptorSet ds0_fs_only = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07007319 alloc_info.descriptorSetCount = 1;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007320 alloc_info.pSetLayouts = &ds_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007321 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &ds0_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007322 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007323
7324 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007325 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7326 pipeline_layout_ci.pNext = NULL;
7327 pipeline_layout_ci.setLayoutCount = NUM_LAYOUTS;
7328 pipeline_layout_ci.pSetLayouts = ds_layout;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007329
7330 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007331 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007332 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007333 // Create pipelineLayout with only one setLayout
7334 pipeline_layout_ci.setLayoutCount = 1;
7335 VkPipelineLayout single_pipe_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007336 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &single_pipe_layout);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007337 ASSERT_VK_SUCCESS(err);
7338 // Create pipelineLayout with 2 descriptor setLayout at index 0
7339 pipeline_layout_ci.pSetLayouts = &ds_layout[3];
7340 VkPipelineLayout pipe_layout_one_desc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007341 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_one_desc);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007342 ASSERT_VK_SUCCESS(err);
7343 // Create pipelineLayout with 5 SAMPLER descriptor setLayout at index 0
7344 pipeline_layout_ci.pSetLayouts = &ds_layout[2];
7345 VkPipelineLayout pipe_layout_five_samp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007346 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_five_samp);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007347 ASSERT_VK_SUCCESS(err);
7348 // Create pipelineLayout with UB type, but stageFlags for FS only
7349 pipeline_layout_ci.pSetLayouts = &ds_layout_fs_only;
7350 VkPipelineLayout pipe_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007351 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007352 ASSERT_VK_SUCCESS(err);
7353 // Create pipelineLayout w/ incompatible set0 layout, but set1 is fine
7354 VkDescriptorSetLayout pl_bad_s0[2] = {};
7355 pl_bad_s0[0] = ds_layout_fs_only;
7356 pl_bad_s0[1] = ds_layout[1];
7357 pipeline_layout_ci.setLayoutCount = 2;
7358 pipeline_layout_ci.pSetLayouts = pl_bad_s0;
7359 VkPipelineLayout pipe_layout_bad_set0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007360 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_bad_set0);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007361 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007362
Tobin Ehlis88452832015-12-03 09:40:56 -07007363 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007364 char const *vsSource =
7365 "#version 450\n"
7366 "\n"
7367 "out gl_PerVertex {\n"
7368 " vec4 gl_Position;\n"
7369 "};\n"
7370 "void main(){\n"
7371 " gl_Position = vec4(1);\n"
7372 "}\n";
7373 char const *fsSource =
7374 "#version 450\n"
7375 "\n"
7376 "layout(location=0) out vec4 x;\n"
7377 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
7378 "void main(){\n"
7379 " x = vec4(bar.y);\n"
7380 "}\n";
Tobin Ehlis88452832015-12-03 09:40:56 -07007381 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
7382 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007383 VkPipelineObj pipe(m_device);
7384 pipe.AddShader(&vs);
7385 pipe.AddShader(&fs);
Tobin Ehlis88452832015-12-03 09:40:56 -07007386 pipe.AddColorAttachment();
7387 pipe.CreateVKPipeline(pipe_layout_fs_only, renderPass());
Tobin Ehlis559c6382015-11-05 09:52:49 -07007388
Tony Barbour552f6c02016-12-21 14:34:07 -07007389 m_commandBuffer->BeginCommandBuffer();
7390 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis88452832015-12-03 09:40:56 -07007391
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007392 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07007393 // NOTE : I believe LunarG ilo driver has bug (LX#189) that requires binding
7394 // of PSO
7395 // here before binding DSs. Otherwise we assert in cmd_copy_dset_data() of
7396 // cmd_pipeline.c
7397 // due to the fact that cmd_alloc_dset_data() has not been called in
7398 // cmd_bind_graphics_pipeline()
7399 // TODO : Want to cause various binding incompatibility issues here to test
7400 // DrawState
Tobin Ehlis559c6382015-11-05 09:52:49 -07007401 // First cause various verify_layout_compatibility() fails
7402 // Second disturb early and late sets and verify INFO msgs
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007403 // verify_set_layout_compatibility fail cases:
7404 // 1. invalid VkPipelineLayout (layout) passed into vkCmdBindDescriptorSets
Karl Schultzf78bcdd2016-11-30 12:36:01 -07007405 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00981);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007406 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
7407 (VkPipelineLayout)((size_t)0xbaadb1be), 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007408 m_errorMonitor->VerifyFound();
7409
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007410 // 2. layoutIndex exceeds # of layouts in layout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007411 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempting to bind set to index 1");
7412 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, single_pipe_layout, 0, 2,
7413 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007414 m_errorMonitor->VerifyFound();
7415
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007416 vkDestroyPipelineLayout(m_device->device(), single_pipe_layout, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07007417 // 3. Pipeline setLayout[0] has 2 descriptors, but set being bound has 5
7418 // descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007419 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has 2 descriptors, but DescriptorSetLayout ");
7420 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_one_desc, 0, 1,
7421 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007422 m_errorMonitor->VerifyFound();
7423
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007424 vkDestroyPipelineLayout(m_device->device(), pipe_layout_one_desc, NULL);
7425 // 4. same # of descriptors but mismatch in type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007426 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is type 'VK_DESCRIPTOR_TYPE_SAMPLER' but binding ");
7427 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_five_samp, 0, 1,
7428 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007429 m_errorMonitor->VerifyFound();
7430
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007431 vkDestroyPipelineLayout(m_device->device(), pipe_layout_five_samp, NULL);
7432 // 5. same # of descriptors but mismatch in stageFlags
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007433 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7434 " has stageFlags 16 but binding 0 for DescriptorSetLayout ");
7435 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
7436 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007437 m_errorMonitor->VerifyFound();
7438
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007439 // Cause INFO messages due to disturbing previously bound Sets
7440 // First bind sets 0 & 1
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007441 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
7442 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007443 // 1. Disturb bound set0 by re-binding set1 w/ updated pipelineLayout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007444 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " previously bound as set #0 was disturbed ");
7445 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
7446 &descriptorSet[1], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007447 m_errorMonitor->VerifyFound();
7448
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007449 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
7450 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007451 // 2. Disturb set after last bound set
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007452 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
7453 " newly bound as set #0 so set #1 and "
7454 "any subsequent sets were disturbed ");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007455 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
7456 &ds0_fs_only, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007457 m_errorMonitor->VerifyFound();
7458
Tobin Ehlis10fad692016-07-07 12:00:36 -06007459 // Now that we're done actively using the pipelineLayout that gfx pipeline
7460 // was created with, we should be able to delete it. Do that now to verify
7461 // that validation obeys pipelineLayout lifetime
7462 vkDestroyPipelineLayout(m_device->device(), pipe_layout_fs_only, NULL);
7463
Tobin Ehlis88452832015-12-03 09:40:56 -07007464 // Cause draw-time errors due to PSO incompatibilities
Karl Schultz6addd812016-02-02 17:17:23 -07007465 // 1. Error due to not binding required set (we actually use same code as
7466 // above to disturb set0)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007467 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
7468 &descriptorSet[0], 0, NULL);
7469 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
7470 &descriptorSet[1], 0, NULL);
7471 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 -07007472
7473 VkViewport viewport = {0, 0, 16, 16, 0, 1};
7474 VkRect2D scissor = {{0, 0}, {16, 16}};
7475 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
7476 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
7477
Tobin Ehlis88452832015-12-03 09:40:56 -07007478 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007479 m_errorMonitor->VerifyFound();
7480
Tobin Ehlis991d45a2016-01-06 08:48:41 -07007481 vkDestroyPipelineLayout(m_device->device(), pipe_layout_bad_set0, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07007482 // 2. Error due to bound set not being compatible with PSO's
7483 // VkPipelineLayout (diff stageFlags in this case)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007484 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
7485 &descriptorSet[0], 0, NULL);
7486 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " bound as set #0 is not compatible with ");
Tobin Ehlis88452832015-12-03 09:40:56 -07007487 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007488 m_errorMonitor->VerifyFound();
7489
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007490 // Remaining clean-up
Karl Schultz6addd812016-02-02 17:17:23 -07007491 for (uint32_t i = 0; i < NUM_LAYOUTS; ++i) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007492 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout[i], NULL);
7493 }
7494 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_fs_only, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007495 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7496 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
7497}
Tobin Ehlis559c6382015-11-05 09:52:49 -07007498
Karl Schultz6addd812016-02-02 17:17:23 -07007499TEST_F(VkLayerTest, NoBeginCommandBuffer) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007500 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7501 "You must call vkBeginCommandBuffer() before this call to ");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007502
Tony Barbour1fa09702017-03-16 12:09:08 -06007503 ASSERT_NO_FATAL_FAILURE(Init());
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007504 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007505 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007506 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007507
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007508 m_errorMonitor->VerifyFound();
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007509}
7510
Karl Schultz6addd812016-02-02 17:17:23 -07007511TEST_F(VkLayerTest, SecondaryCommandBufferNullRenderpass) {
7512 VkResult err;
7513 VkCommandBuffer draw_cmd;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007514
Karl Schultzf78bcdd2016-11-30 12:36:01 -07007515 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00110);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007516
Tony Barbour1fa09702017-03-16 12:09:08 -06007517 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06007518
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007519 VkCommandBufferAllocateInfo cmd = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007520 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06007521 cmd.pNext = NULL;
Mike Schuchardt06304c22017-03-01 17:09:09 -07007522 cmd.commandPool = m_commandPool->handle();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007523 cmd.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007524 cmd.commandBufferCount = 1;
Cody Northropb4569702015-08-04 17:35:57 -06007525
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007526 err = vkAllocateCommandBuffers(m_device->device(), &cmd, &draw_cmd);
Mike Stroyand1c84a52015-08-18 14:40:24 -06007527 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06007528
7529 // Force the failure by not setting the Renderpass and Framebuffer fields
Jon Ashburnf19916e2016-01-11 13:12:43 -07007530 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Rene Lindsay65072a92017-01-23 11:38:10 -07007531 cmd_buf_hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
7532
7533 VkCommandBufferBeginInfo cmd_buf_info = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007534 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06007535 cmd_buf_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007536 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 -07007537 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06007538
7539 // The error should be caught by validation of the BeginCommandBuffer call
7540 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
7541
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007542 m_errorMonitor->VerifyFound();
Mike Schuchardt06304c22017-03-01 17:09:09 -07007543 vkFreeCommandBuffers(m_device->device(), m_commandPool->handle(), 1, &draw_cmd);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06007544}
7545
Karl Schultz6addd812016-02-02 17:17:23 -07007546TEST_F(VkLayerTest, CommandBufferResetErrors) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007547 // Cause error due to Begin while recording CB
7548 // Then cause 2 errors for attempting to reset CB w/o having
7549 // VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT set for the pool from
7550 // which CBs were allocated. Note that this bit is off by default.
Mike Weiblencce7ec72016-10-17 19:33:05 -06007551 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call Begin on command buffer");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007552
Tony Barbour1fa09702017-03-16 12:09:08 -06007553 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007554
7555 // Calls AllocateCommandBuffers
7556 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
7557
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07007558 // Force the failure by setting the Renderpass and Framebuffer fields with (fake) data
Jon Ashburnf19916e2016-01-11 13:12:43 -07007559 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07007560 cmd_buf_hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
7561 VkCommandBufferBeginInfo cmd_buf_info = {};
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007562 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
7563 cmd_buf_info.pNext = NULL;
7564 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007565 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007566
7567 // Begin CB to transition to recording state
7568 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
7569 // Can't re-begin. This should trigger error
7570 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007571 m_errorMonitor->VerifyFound();
7572
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07007573 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00093);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007574 VkCommandBufferResetFlags flags = 0; // Don't care about flags for this test
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007575 // Reset attempt will trigger error due to incorrect CommandPool state
7576 vkResetCommandBuffer(commandBuffer.GetBufferHandle(), flags);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007577 m_errorMonitor->VerifyFound();
7578
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07007579 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00105);
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007580 // Transition CB to RECORDED state
7581 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
7582 // Now attempting to Begin will implicitly reset, which triggers error
7583 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007584 m_errorMonitor->VerifyFound();
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007585}
7586
Karl Schultz6addd812016-02-02 17:17:23 -07007587TEST_F(VkLayerTest, InvalidPipelineCreateState) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007588 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07007589 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007590
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07007591 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7592 "Invalid Pipeline CreateInfo State: Vertex Shader required");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007593
Tony Barbour1fa09702017-03-16 12:09:08 -06007594 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06007595 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06007596
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007597 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007598 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7599 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06007600
7601 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007602 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7603 ds_pool_ci.pNext = NULL;
7604 ds_pool_ci.maxSets = 1;
7605 ds_pool_ci.poolSizeCount = 1;
7606 ds_pool_ci.pPoolSizes = &ds_type_count;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06007607
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007608 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007609 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007610 ASSERT_VK_SUCCESS(err);
7611
Tony Barboureb254902015-07-15 12:50:33 -06007612 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007613 dsl_binding.binding = 0;
7614 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7615 dsl_binding.descriptorCount = 1;
7616 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7617 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007618
Tony Barboureb254902015-07-15 12:50:33 -06007619 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007620 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7621 ds_layout_ci.pNext = NULL;
7622 ds_layout_ci.bindingCount = 1;
7623 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06007624
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007625 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007626 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007627 ASSERT_VK_SUCCESS(err);
7628
7629 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007630 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007631 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007632 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007633 alloc_info.descriptorPool = ds_pool;
7634 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007635 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007636 ASSERT_VK_SUCCESS(err);
7637
Tony Barboureb254902015-07-15 12:50:33 -06007638 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007639 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7640 pipeline_layout_ci.setLayoutCount = 1;
7641 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007642
7643 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007644 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007645 ASSERT_VK_SUCCESS(err);
7646
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007647 VkViewport vp = {}; // Just need dummy vp to point to
7648 VkRect2D sc = {}; // dummy scissor to point to
Tobin Ehlise68360f2015-10-01 11:15:13 -06007649
7650 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007651 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7652 vp_state_ci.scissorCount = 1;
7653 vp_state_ci.pScissors = &sc;
7654 vp_state_ci.viewportCount = 1;
7655 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007656
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007657 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7658 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7659 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7660 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7661 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7662 rs_state_ci.depthClampEnable = VK_FALSE;
Rene Lindsayae4977b2017-01-23 14:55:54 -07007663 rs_state_ci.rasterizerDiscardEnable = VK_TRUE;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007664 rs_state_ci.depthBiasEnable = VK_FALSE;
Rene Lindsayae4977b2017-01-23 14:55:54 -07007665 rs_state_ci.lineWidth = 1.0f;
7666
7667 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7668 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7669 vi_ci.pNext = nullptr;
7670 vi_ci.vertexBindingDescriptionCount = 0;
7671 vi_ci.pVertexBindingDescriptions = nullptr;
7672 vi_ci.vertexAttributeDescriptionCount = 0;
7673 vi_ci.pVertexAttributeDescriptions = nullptr;
7674
7675 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7676 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7677 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7678
7679 VkPipelineShaderStageCreateInfo shaderStages[2];
7680 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7681
7682 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7683 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Dave Houlton59a20702017-02-02 17:26:23 -07007684 shaderStages[0] = fs.GetStageCreateInfo(); // should be: vs.GetStageCreateInfo();
Rene Lindsayae4977b2017-01-23 14:55:54 -07007685 shaderStages[1] = fs.GetStageCreateInfo();
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007686
Tony Barboureb254902015-07-15 12:50:33 -06007687 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007688 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7689 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007690 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007691 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7692 gp_ci.layout = pipeline_layout;
7693 gp_ci.renderPass = renderPass();
Rene Lindsayae4977b2017-01-23 14:55:54 -07007694 gp_ci.pVertexInputState = &vi_ci;
7695 gp_ci.pInputAssemblyState = &ia_ci;
7696
7697 gp_ci.stageCount = 1;
7698 gp_ci.pStages = shaderStages;
Tony Barboureb254902015-07-15 12:50:33 -06007699
7700 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007701 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7702 pc_ci.initialDataSize = 0;
7703 pc_ci.pInitialData = 0;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007704
7705 VkPipeline pipeline;
Jon Ashburnc669cc62015-07-09 15:02:25 -06007706 VkPipelineCache pipelineCache;
7707
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007708 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Jon Ashburnc669cc62015-07-09 15:02:25 -06007709 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007710 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007711 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007712
Chia-I Wuf7458c52015-10-26 21:10:41 +08007713 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7714 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7715 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7716 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007717}
Rene Lindsayae4977b2017-01-23 14:55:54 -07007718
Tobin Ehlis912df022015-09-17 08:46:18 -06007719/*// TODO : This test should be good, but needs Tess support in compiler to run
7720TEST_F(VkLayerTest, InvalidPatchControlPoints)
7721{
7722 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis912df022015-09-17 08:46:18 -06007723 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007724
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07007725 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07007726 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH
7727primitive ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007728
Tony Barbour1fa09702017-03-16 12:09:08 -06007729 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis912df022015-09-17 08:46:18 -06007730 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis912df022015-09-17 08:46:18 -06007731
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007732 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis912df022015-09-17 08:46:18 -06007733 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007734 ds_type_count.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007735
7736 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7737 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7738 ds_pool_ci.pNext = NULL;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007739 ds_pool_ci.poolSizeCount = 1;
7740 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis912df022015-09-17 08:46:18 -06007741
7742 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07007743 err = vkCreateDescriptorPool(m_device->device(),
7744VK_DESCRIPTOR_POOL_USAGE_NON_FREE, 1, &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis912df022015-09-17 08:46:18 -06007745 ASSERT_VK_SUCCESS(err);
7746
7747 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08007748 dsl_binding.binding = 0;
Tobin Ehlis912df022015-09-17 08:46:18 -06007749 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08007750 dsl_binding.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007751 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7752 dsl_binding.pImmutableSamplers = NULL;
7753
7754 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007755 ds_layout_ci.sType =
7756VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06007757 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007758 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07007759 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis912df022015-09-17 08:46:18 -06007760
7761 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007762 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
7763&ds_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06007764 ASSERT_VK_SUCCESS(err);
7765
7766 VkDescriptorSet descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07007767 err = vkAllocateDescriptorSets(m_device->device(), ds_pool,
7768VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet);
Tobin Ehlis912df022015-09-17 08:46:18 -06007769 ASSERT_VK_SUCCESS(err);
7770
7771 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007772 pipeline_layout_ci.sType =
7773VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06007774 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007775 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007776 pipeline_layout_ci.pSetLayouts = &ds_layout;
7777
7778 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007779 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
7780&pipeline_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06007781 ASSERT_VK_SUCCESS(err);
7782
7783 VkPipelineShaderStageCreateInfo shaderStages[3];
7784 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
7785
Karl Schultz6addd812016-02-02 17:17:23 -07007786 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT,
7787this);
Tobin Ehlis912df022015-09-17 08:46:18 -06007788 // Just using VS txt for Tess shaders as we don't care about functionality
Karl Schultz6addd812016-02-02 17:17:23 -07007789 VkShaderObj
7790tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
7791this);
7792 VkShaderObj
7793te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT,
7794this);
Tobin Ehlis912df022015-09-17 08:46:18 -06007795
Karl Schultz6addd812016-02-02 17:17:23 -07007796 shaderStages[0].sType =
7797VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007798 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007799 shaderStages[0].shader = vs.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07007800 shaderStages[1].sType =
7801VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007802 shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007803 shaderStages[1].shader = tc.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07007804 shaderStages[2].sType =
7805VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007806 shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007807 shaderStages[2].shader = te.handle();
7808
7809 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007810 iaCI.sType =
7811VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Chia-I Wu515eb8f2015-10-31 00:31:16 +08007812 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST;
Tobin Ehlis912df022015-09-17 08:46:18 -06007813
7814 VkPipelineTessellationStateCreateInfo tsCI = {};
7815 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
7816 tsCI.patchControlPoints = 0; // This will cause an error
7817
7818 VkGraphicsPipelineCreateInfo gp_ci = {};
7819 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7820 gp_ci.pNext = NULL;
7821 gp_ci.stageCount = 3;
7822 gp_ci.pStages = shaderStages;
7823 gp_ci.pVertexInputState = NULL;
7824 gp_ci.pInputAssemblyState = &iaCI;
7825 gp_ci.pTessellationState = &tsCI;
7826 gp_ci.pViewportState = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007827 gp_ci.pRasterizationState = NULL;
Tobin Ehlis912df022015-09-17 08:46:18 -06007828 gp_ci.pMultisampleState = NULL;
7829 gp_ci.pDepthStencilState = NULL;
7830 gp_ci.pColorBlendState = NULL;
7831 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7832 gp_ci.layout = pipeline_layout;
7833 gp_ci.renderPass = renderPass();
7834
7835 VkPipelineCacheCreateInfo pc_ci = {};
7836 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7837 pc_ci.pNext = NULL;
7838 pc_ci.initialSize = 0;
7839 pc_ci.initialData = 0;
7840 pc_ci.maxSize = 0;
7841
7842 VkPipeline pipeline;
7843 VkPipelineCache pipelineCache;
7844
Karl Schultz6addd812016-02-02 17:17:23 -07007845 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL,
7846&pipelineCache);
Tobin Ehlis912df022015-09-17 08:46:18 -06007847 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07007848 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
7849&gp_ci, NULL, &pipeline);
Tobin Ehlis912df022015-09-17 08:46:18 -06007850
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007851 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007852
Chia-I Wuf7458c52015-10-26 21:10:41 +08007853 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7854 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7855 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7856 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis912df022015-09-17 08:46:18 -06007857}
7858*/
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007859
Mark Lobodzinski510aa5c2016-12-19 07:59:10 -07007860TEST_F(VkLayerTest, PSOViewportScissorCountTests) {
Karl Schultz6addd812016-02-02 17:17:23 -07007861 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007862
Mark Lobodzinski510aa5c2016-12-19 07:59:10 -07007863 TEST_DESCRIPTION("Test various cases of viewport and scissor count validation");
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007864
Tony Barbour1fa09702017-03-16 12:09:08 -06007865 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007866 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007867
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007868 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007869 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7870 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007871
7872 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007873 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7874 ds_pool_ci.maxSets = 1;
7875 ds_pool_ci.poolSizeCount = 1;
7876 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007877
7878 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007879 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007880 ASSERT_VK_SUCCESS(err);
7881
7882 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007883 dsl_binding.binding = 0;
7884 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7885 dsl_binding.descriptorCount = 1;
7886 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007887
7888 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007889 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7890 ds_layout_ci.bindingCount = 1;
7891 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007892
7893 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007894 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007895 ASSERT_VK_SUCCESS(err);
7896
7897 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007898 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007899 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007900 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007901 alloc_info.descriptorPool = ds_pool;
7902 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007903 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007904 ASSERT_VK_SUCCESS(err);
7905
7906 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007907 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7908 pipeline_layout_ci.setLayoutCount = 1;
7909 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007910
7911 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007912 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007913 ASSERT_VK_SUCCESS(err);
7914
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007915 VkViewport vp = {};
Tobin Ehlise68360f2015-10-01 11:15:13 -06007916 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007917 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
Mark Lobodzinski510aa5c2016-12-19 07:59:10 -07007918 vp_state_ci.scissorCount = 1;
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007919 vp_state_ci.viewportCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -07007920 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007921
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007922 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7923 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7924 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7925 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7926 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7927 rs_state_ci.depthClampEnable = VK_FALSE;
7928 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
7929 rs_state_ci.depthBiasEnable = VK_FALSE;
7930
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007931 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7932 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7933 vi_ci.pNext = nullptr;
7934 vi_ci.vertexBindingDescriptionCount = 0;
7935 vi_ci.pVertexBindingDescriptions = nullptr;
7936 vi_ci.vertexAttributeDescriptionCount = 0;
7937 vi_ci.pVertexAttributeDescriptions = nullptr;
7938
7939 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7940 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7941 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7942
7943 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
7944 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
7945 pipe_ms_state_ci.pNext = NULL;
7946 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
7947 pipe_ms_state_ci.sampleShadingEnable = 0;
7948 pipe_ms_state_ci.minSampleShading = 1.0;
7949 pipe_ms_state_ci.pSampleMask = NULL;
7950
Cody Northropeb3a6c12015-10-05 14:44:45 -06007951 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007952 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007953
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007954 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07007955 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chia-I Wu28e06912015-10-31 00:31:16 +08007956 shaderStages[0] = vs.GetStageCreateInfo();
7957 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007958
7959 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007960 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7961 gp_ci.stageCount = 2;
7962 gp_ci.pStages = shaderStages;
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007963 gp_ci.pVertexInputState = &vi_ci;
7964 gp_ci.pInputAssemblyState = &ia_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007965 gp_ci.pViewportState = &vp_state_ci;
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007966 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007967 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007968 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7969 gp_ci.layout = pipeline_layout;
7970 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007971
7972 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007973 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007974
7975 VkPipeline pipeline;
7976 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007977 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007978 ASSERT_VK_SUCCESS(err);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007979
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007980 if (!m_device->phy().features().multiViewport) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07007981 printf(" MultiViewport feature is disabled -- skipping enabled-state checks.\n");
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007982
7983 // Check case where multiViewport is disabled and viewport count is not 1
7984 // We check scissor/viewport simultaneously since separating them would trigger the mismatch error, 1434.
7985 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01430);
7986 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01431);
7987 vp_state_ci.scissorCount = 0;
7988 vp_state_ci.viewportCount = 0;
7989 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
7990 m_errorMonitor->VerifyFound();
7991 } else {
7992 if (m_device->props.limits.maxViewports == 1) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07007993 printf(" Device limit maxViewports is 1, skipping tests that require higher limits.\n");
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007994 } else {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07007995 printf(" MultiViewport feature is enabled -- skipping disabled-state checks.\n");
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007996
7997 // Check is that viewportcount and scissorcount match
7998 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01434);
7999 vp_state_ci.scissorCount = 1;
8000 vp_state_ci.viewportCount = m_device->props.limits.maxViewports;
8001 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
8002 m_errorMonitor->VerifyFound();
8003
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07008004 // Check case where multiViewport is enabled and viewport count is greater than max
8005 // We check scissor/viewport simultaneously since separating them would trigger the mismatch error, 1434.
8006 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01432);
8007 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01433);
8008 vp_state_ci.scissorCount = m_device->props.limits.maxViewports + 1;
8009 vp_state_ci.viewportCount = m_device->props.limits.maxViewports + 1;
8010 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
8011 m_errorMonitor->VerifyFound();
8012 }
8013 }
Tobin Ehlise68360f2015-10-01 11:15:13 -06008014
Chia-I Wuf7458c52015-10-26 21:10:41 +08008015 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
8016 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8017 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8018 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008019}
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07008020
8021// 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
8022// set dynamically.
Karl Schultz6addd812016-02-02 17:17:23 -07008023TEST_F(VkLayerTest, PSOViewportStateNotSet) {
Karl Schultz6addd812016-02-02 17:17:23 -07008024 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008025
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07008026 TEST_DESCRIPTION("Create a graphics pipeline with rasterization enabled but no viewport state.");
8027
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07008028 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02113);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008029
Tony Barbour1fa09702017-03-16 12:09:08 -06008030 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlise68360f2015-10-01 11:15:13 -06008031 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06008032
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008033 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008034 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8035 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008036
8037 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008038 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8039 ds_pool_ci.maxSets = 1;
8040 ds_pool_ci.poolSizeCount = 1;
8041 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008042
8043 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008044 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008045 ASSERT_VK_SUCCESS(err);
8046
8047 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008048 dsl_binding.binding = 0;
8049 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8050 dsl_binding.descriptorCount = 1;
8051 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008052
8053 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008054 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8055 ds_layout_ci.bindingCount = 1;
8056 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008057
8058 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008059 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008060 ASSERT_VK_SUCCESS(err);
8061
8062 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008063 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008064 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008065 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008066 alloc_info.descriptorPool = ds_pool;
8067 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008068 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008069 ASSERT_VK_SUCCESS(err);
8070
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07008071 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 VkPipelineVertexInputStateCreateInfo vi_ci = {};
8076 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
8077 vi_ci.pNext = nullptr;
8078 vi_ci.vertexBindingDescriptionCount = 0;
8079 vi_ci.pVertexBindingDescriptions = nullptr;
8080 vi_ci.vertexAttributeDescriptionCount = 0;
8081 vi_ci.pVertexAttributeDescriptions = nullptr;
8082
8083 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
8084 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
8085 pipe_ms_state_ci.pNext = NULL;
8086 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
8087 pipe_ms_state_ci.sampleShadingEnable = 0;
8088 pipe_ms_state_ci.minSampleShading = 1.0;
8089 pipe_ms_state_ci.pSampleMask = NULL;
8090
Tobin Ehlise68360f2015-10-01 11:15:13 -06008091 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008092 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8093 pipeline_layout_ci.setLayoutCount = 1;
8094 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008095
8096 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008097 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008098 ASSERT_VK_SUCCESS(err);
8099
8100 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
8101 // Set scissor as dynamic to avoid second error
8102 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008103 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
8104 dyn_state_ci.dynamicStateCount = 1;
8105 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008106
Cody Northropeb3a6c12015-10-05 14:44:45 -06008107 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07008108 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06008109
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008110 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07008111 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
8112 // 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 +08008113 shaderStages[0] = vs.GetStageCreateInfo();
8114 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06008115
Karl Schultzdfdb8d42016-03-08 10:30:21 -07008116 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
8117 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
8118 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
8119 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
8120 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
8121 rs_state_ci.depthClampEnable = VK_FALSE;
8122 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
8123 rs_state_ci.depthBiasEnable = VK_FALSE;
8124
Tobin Ehlise68360f2015-10-01 11:15:13 -06008125 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008126 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8127 gp_ci.stageCount = 2;
8128 gp_ci.pStages = shaderStages;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07008129 gp_ci.pRasterizationState = &rs_state_ci;
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07008130 // Not setting VP state w/o dynamic vp state should cause validation error
8131 gp_ci.pViewportState = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -07008132 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07008133 gp_ci.pVertexInputState = &vi_ci;
8134 gp_ci.pInputAssemblyState = &ia_ci;
8135 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07008136 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
8137 gp_ci.layout = pipeline_layout;
8138 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06008139
8140 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008141 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008142
8143 VkPipeline pipeline;
8144 VkPipelineCache pipelineCache;
8145
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008146 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008147 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008148 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008149
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008150 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06008151
Chia-I Wuf7458c52015-10-26 21:10:41 +08008152 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
8153 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8154 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8155 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008156}
Mark Lobodzinski73169e22016-12-16 14:01:17 -07008157
8158// Create PSO w/o non-zero viewportCount but no viewport data, then run second test where dynamic scissor count doesn't match PSO
8159// scissor count
Karl Schultz6addd812016-02-02 17:17:23 -07008160TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch) {
8161 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008162
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07008163 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02110);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008164
Tony Barbour1fa09702017-03-16 12:09:08 -06008165 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12008166
8167 if (!m_device->phy().features().multiViewport) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07008168 printf(" Device does not support multiple viewports/scissors; skipped.\n");
Chris Forbesc08a6ca2016-07-28 14:14:07 +12008169 return;
8170 }
8171
Tobin Ehlise68360f2015-10-01 11:15:13 -06008172 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06008173
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008174 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008175 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8176 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008177
8178 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008179 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8180 ds_pool_ci.maxSets = 1;
8181 ds_pool_ci.poolSizeCount = 1;
8182 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008183
8184 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008185 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008186 ASSERT_VK_SUCCESS(err);
8187
8188 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008189 dsl_binding.binding = 0;
8190 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8191 dsl_binding.descriptorCount = 1;
8192 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008193
8194 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008195 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8196 ds_layout_ci.bindingCount = 1;
8197 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008198
8199 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008200 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008201 ASSERT_VK_SUCCESS(err);
8202
8203 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008204 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008205 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008206 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008207 alloc_info.descriptorPool = ds_pool;
8208 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008209 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008210 ASSERT_VK_SUCCESS(err);
8211
8212 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008213 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8214 pipeline_layout_ci.setLayoutCount = 1;
8215 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008216
8217 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008218 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008219 ASSERT_VK_SUCCESS(err);
8220
8221 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008222 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
8223 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008224 vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error
Karl Schultz6addd812016-02-02 17:17:23 -07008225 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008226 vp_state_ci.pScissors = NULL; // Scissor is dynamic (below) so this won't cause error
Tobin Ehlise68360f2015-10-01 11:15:13 -06008227
8228 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
8229 // Set scissor as dynamic to avoid that error
8230 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008231 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
8232 dyn_state_ci.dynamicStateCount = 1;
8233 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008234
Mark Lobodzinski73169e22016-12-16 14:01:17 -07008235 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
8236 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
8237 pipe_ms_state_ci.pNext = NULL;
8238 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
8239 pipe_ms_state_ci.sampleShadingEnable = 0;
8240 pipe_ms_state_ci.minSampleShading = 1.0;
8241 pipe_ms_state_ci.pSampleMask = NULL;
8242
Cody Northropeb3a6c12015-10-05 14:44:45 -06008243 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07008244 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06008245
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008246 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski73169e22016-12-16 14:01:17 -07008247 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
8248 // 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 +08008249 shaderStages[0] = vs.GetStageCreateInfo();
8250 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06008251
Cody Northropf6622dc2015-10-06 10:33:21 -06008252 VkPipelineVertexInputStateCreateInfo vi_ci = {};
8253 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
8254 vi_ci.pNext = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008255 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06008256 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008257 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06008258 vi_ci.pVertexAttributeDescriptions = nullptr;
8259
8260 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
8261 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
8262 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
8263
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008264 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008265 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Mark Lobodzinski73169e22016-12-16 14:01:17 -07008266 rs_ci.lineWidth = m_device->props.limits.lineWidthRange[0];
Cody Northropf6622dc2015-10-06 10:33:21 -06008267 rs_ci.pNext = nullptr;
8268
Mark Youngc89c6312016-03-31 16:03:20 -06008269 VkPipelineColorBlendAttachmentState att = {};
8270 att.blendEnable = VK_FALSE;
8271 att.colorWriteMask = 0xf;
8272
Cody Northropf6622dc2015-10-06 10:33:21 -06008273 VkPipelineColorBlendStateCreateInfo cb_ci = {};
8274 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
8275 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06008276 cb_ci.attachmentCount = 1;
8277 cb_ci.pAttachments = &att;
Cody Northropf6622dc2015-10-06 10:33:21 -06008278
Tobin Ehlise68360f2015-10-01 11:15:13 -06008279 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008280 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8281 gp_ci.stageCount = 2;
8282 gp_ci.pStages = shaderStages;
8283 gp_ci.pVertexInputState = &vi_ci;
8284 gp_ci.pInputAssemblyState = &ia_ci;
8285 gp_ci.pViewportState = &vp_state_ci;
8286 gp_ci.pRasterizationState = &rs_ci;
8287 gp_ci.pColorBlendState = &cb_ci;
8288 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski73169e22016-12-16 14:01:17 -07008289 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07008290 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
8291 gp_ci.layout = pipeline_layout;
8292 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06008293
8294 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008295 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008296
8297 VkPipeline pipeline;
8298 VkPipelineCache pipelineCache;
8299
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008300 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008301 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008302 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008303
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008304 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008305
Tobin Ehlisd332f282015-10-02 11:00:56 -06008306 // Now hit second fail case where we set scissor w/ different count than PSO
Karl Schultz6addd812016-02-02 17:17:23 -07008307 // First need to successfully create the PSO from above by setting
8308 // pViewports
Mike Weiblen95dd0f92016-10-19 12:28:27 -06008309 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 -07008310
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008311 VkViewport vp = {}; // Just need dummy vp to point to
Karl Schultz6addd812016-02-02 17:17:23 -07008312 vp_state_ci.pViewports = &vp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008313 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07008314 ASSERT_VK_SUCCESS(err);
Tony Barbour552f6c02016-12-21 14:34:07 -07008315 m_commandBuffer->BeginCommandBuffer();
8316 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008317 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008318 VkRect2D scissors[1] = {}; // don't care about data
Karl Schultz6addd812016-02-02 17:17:23 -07008319 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12008320 vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 1, 1, scissors);
Karl Schultz6addd812016-02-02 17:17:23 -07008321 Draw(1, 0, 0, 0);
8322
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008323 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07008324
8325 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
8326 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8327 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8328 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008329 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07008330}
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008331
8332// 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 -07008333// viewportCount
8334TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch) {
8335 VkResult err;
8336
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07008337 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02111);
Karl Schultz6addd812016-02-02 17:17:23 -07008338
Tony Barbour1fa09702017-03-16 12:09:08 -06008339 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12008340
8341 if (!m_device->phy().features().multiViewport) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07008342 printf(" Device does not support multiple viewports/scissors; skipped.\n");
Chris Forbesc08a6ca2016-07-28 14:14:07 +12008343 return;
8344 }
8345
Karl Schultz6addd812016-02-02 17:17:23 -07008346 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8347
8348 VkDescriptorPoolSize ds_type_count = {};
8349 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8350 ds_type_count.descriptorCount = 1;
8351
8352 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8353 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8354 ds_pool_ci.maxSets = 1;
8355 ds_pool_ci.poolSizeCount = 1;
8356 ds_pool_ci.pPoolSizes = &ds_type_count;
8357
8358 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008359 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Karl Schultz6addd812016-02-02 17:17:23 -07008360 ASSERT_VK_SUCCESS(err);
8361
8362 VkDescriptorSetLayoutBinding dsl_binding = {};
8363 dsl_binding.binding = 0;
8364 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8365 dsl_binding.descriptorCount = 1;
8366 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8367
8368 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8369 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8370 ds_layout_ci.bindingCount = 1;
8371 ds_layout_ci.pBindings = &dsl_binding;
8372
8373 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008374 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07008375 ASSERT_VK_SUCCESS(err);
8376
8377 VkDescriptorSet descriptorSet;
8378 VkDescriptorSetAllocateInfo alloc_info = {};
8379 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8380 alloc_info.descriptorSetCount = 1;
8381 alloc_info.descriptorPool = ds_pool;
8382 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008383 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Karl Schultz6addd812016-02-02 17:17:23 -07008384 ASSERT_VK_SUCCESS(err);
8385
8386 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
8387 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8388 pipeline_layout_ci.setLayoutCount = 1;
8389 pipeline_layout_ci.pSetLayouts = &ds_layout;
8390
8391 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008392 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07008393 ASSERT_VK_SUCCESS(err);
8394
8395 VkPipelineViewportStateCreateInfo vp_state_ci = {};
8396 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
8397 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008398 vp_state_ci.pScissors = NULL; // Null scissor w/ count of 1 should cause error
Karl Schultz6addd812016-02-02 17:17:23 -07008399 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008400 vp_state_ci.pViewports = NULL; // vp is dynamic (below) so this won't cause error
Karl Schultz6addd812016-02-02 17:17:23 -07008401
8402 VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT;
8403 // Set scissor as dynamic to avoid that error
8404 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
8405 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
8406 dyn_state_ci.dynamicStateCount = 1;
8407 dyn_state_ci.pDynamicStates = &vp_state;
8408
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008409 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
8410 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
8411 pipe_ms_state_ci.pNext = NULL;
8412 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
8413 pipe_ms_state_ci.sampleShadingEnable = 0;
8414 pipe_ms_state_ci.minSampleShading = 1.0;
8415 pipe_ms_state_ci.pSampleMask = NULL;
8416
Karl Schultz6addd812016-02-02 17:17:23 -07008417 VkPipelineShaderStageCreateInfo shaderStages[2];
8418 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
8419
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008420 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008421 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
8422 // 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 -07008423 shaderStages[0] = vs.GetStageCreateInfo();
8424 shaderStages[1] = fs.GetStageCreateInfo();
8425
8426 VkPipelineVertexInputStateCreateInfo vi_ci = {};
8427 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
8428 vi_ci.pNext = nullptr;
8429 vi_ci.vertexBindingDescriptionCount = 0;
8430 vi_ci.pVertexBindingDescriptions = nullptr;
8431 vi_ci.vertexAttributeDescriptionCount = 0;
8432 vi_ci.pVertexAttributeDescriptions = nullptr;
8433
8434 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
8435 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
8436 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
8437
8438 VkPipelineRasterizationStateCreateInfo rs_ci = {};
8439 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008440 rs_ci.lineWidth = m_device->props.limits.lineWidthRange[0];
Karl Schultz6addd812016-02-02 17:17:23 -07008441 rs_ci.pNext = nullptr;
8442
Mark Youngc89c6312016-03-31 16:03:20 -06008443 VkPipelineColorBlendAttachmentState att = {};
8444 att.blendEnable = VK_FALSE;
8445 att.colorWriteMask = 0xf;
8446
Karl Schultz6addd812016-02-02 17:17:23 -07008447 VkPipelineColorBlendStateCreateInfo cb_ci = {};
8448 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
8449 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06008450 cb_ci.attachmentCount = 1;
8451 cb_ci.pAttachments = &att;
Karl Schultz6addd812016-02-02 17:17:23 -07008452
8453 VkGraphicsPipelineCreateInfo gp_ci = {};
8454 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8455 gp_ci.stageCount = 2;
8456 gp_ci.pStages = shaderStages;
8457 gp_ci.pVertexInputState = &vi_ci;
8458 gp_ci.pInputAssemblyState = &ia_ci;
8459 gp_ci.pViewportState = &vp_state_ci;
8460 gp_ci.pRasterizationState = &rs_ci;
8461 gp_ci.pColorBlendState = &cb_ci;
8462 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008463 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07008464 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
8465 gp_ci.layout = pipeline_layout;
8466 gp_ci.renderPass = renderPass();
8467
8468 VkPipelineCacheCreateInfo pc_ci = {};
8469 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
8470
8471 VkPipeline pipeline;
8472 VkPipelineCache pipelineCache;
8473
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008474 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Karl Schultz6addd812016-02-02 17:17:23 -07008475 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008476 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07008477
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008478 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07008479
8480 // Now hit second fail case where we set scissor w/ different count than PSO
8481 // First need to successfully create the PSO from above by setting
8482 // pViewports
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07008483 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8484 "Dynamic viewport(s) 0 are used by pipeline state object, ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008485
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008486 VkRect2D sc = {}; // Just need dummy vp to point to
Tobin Ehlisd332f282015-10-02 11:00:56 -06008487 vp_state_ci.pScissors = &sc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008488 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06008489 ASSERT_VK_SUCCESS(err);
Tony Barbour552f6c02016-12-21 14:34:07 -07008490 m_commandBuffer->BeginCommandBuffer();
8491 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008492 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008493 VkViewport viewports[1] = {};
8494 viewports[0].width = 8;
8495 viewports[0].height = 8;
Tobin Ehlisd332f282015-10-02 11:00:56 -06008496 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12008497 vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 1, 1, viewports);
Tobin Ehlisd332f282015-10-02 11:00:56 -06008498 Draw(1, 0, 0, 0);
8499
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008500 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06008501
Chia-I Wuf7458c52015-10-26 21:10:41 +08008502 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
8503 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8504 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8505 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008506 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008507}
8508
Mark Young7394fdd2016-03-31 14:56:43 -06008509TEST_F(VkLayerTest, PSOLineWidthInvalid) {
8510 VkResult err;
8511
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008512 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06008513
Tony Barbour1fa09702017-03-16 12:09:08 -06008514 ASSERT_NO_FATAL_FAILURE(Init());
Mark Young7394fdd2016-03-31 14:56:43 -06008515 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8516
8517 VkDescriptorPoolSize ds_type_count = {};
8518 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8519 ds_type_count.descriptorCount = 1;
8520
8521 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8522 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8523 ds_pool_ci.maxSets = 1;
8524 ds_pool_ci.poolSizeCount = 1;
8525 ds_pool_ci.pPoolSizes = &ds_type_count;
8526
8527 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008528 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Young7394fdd2016-03-31 14:56:43 -06008529 ASSERT_VK_SUCCESS(err);
8530
8531 VkDescriptorSetLayoutBinding dsl_binding = {};
8532 dsl_binding.binding = 0;
8533 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8534 dsl_binding.descriptorCount = 1;
8535 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8536
8537 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8538 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8539 ds_layout_ci.bindingCount = 1;
8540 ds_layout_ci.pBindings = &dsl_binding;
8541
8542 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008543 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06008544 ASSERT_VK_SUCCESS(err);
8545
8546 VkDescriptorSet descriptorSet;
8547 VkDescriptorSetAllocateInfo alloc_info = {};
8548 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8549 alloc_info.descriptorSetCount = 1;
8550 alloc_info.descriptorPool = ds_pool;
8551 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008552 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Young7394fdd2016-03-31 14:56:43 -06008553 ASSERT_VK_SUCCESS(err);
8554
8555 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
8556 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8557 pipeline_layout_ci.setLayoutCount = 1;
8558 pipeline_layout_ci.pSetLayouts = &ds_layout;
8559
8560 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008561 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06008562 ASSERT_VK_SUCCESS(err);
8563
8564 VkPipelineViewportStateCreateInfo vp_state_ci = {};
8565 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
8566 vp_state_ci.scissorCount = 1;
8567 vp_state_ci.pScissors = NULL;
8568 vp_state_ci.viewportCount = 1;
8569 vp_state_ci.pViewports = NULL;
8570
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008571 VkDynamicState dynamic_states[3] = {VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR, VK_DYNAMIC_STATE_LINE_WIDTH};
Mark Young7394fdd2016-03-31 14:56:43 -06008572 // Set scissor as dynamic to avoid that error
8573 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
8574 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
8575 dyn_state_ci.dynamicStateCount = 2;
8576 dyn_state_ci.pDynamicStates = dynamic_states;
8577
8578 VkPipelineShaderStageCreateInfo shaderStages[2];
8579 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
8580
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008581 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
8582 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT,
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008583 this); // TODO - We shouldn't need a fragment shader
8584 // but add it to be able to run on more devices
Mark Young7394fdd2016-03-31 14:56:43 -06008585 shaderStages[0] = vs.GetStageCreateInfo();
8586 shaderStages[1] = fs.GetStageCreateInfo();
8587
8588 VkPipelineVertexInputStateCreateInfo vi_ci = {};
8589 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
8590 vi_ci.pNext = nullptr;
8591 vi_ci.vertexBindingDescriptionCount = 0;
8592 vi_ci.pVertexBindingDescriptions = nullptr;
8593 vi_ci.vertexAttributeDescriptionCount = 0;
8594 vi_ci.pVertexAttributeDescriptions = nullptr;
8595
8596 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
8597 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
8598 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
8599
8600 VkPipelineRasterizationStateCreateInfo rs_ci = {};
8601 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
8602 rs_ci.pNext = nullptr;
Rene Lindsay144e4842017-01-20 14:27:15 -07008603 rs_ci.rasterizerDiscardEnable = VK_TRUE;
Mark Young7394fdd2016-03-31 14:56:43 -06008604
Mark Young47107952016-05-02 15:59:55 -06008605 // Check too low (line width of -1.0f).
8606 rs_ci.lineWidth = -1.0f;
Mark Young7394fdd2016-03-31 14:56:43 -06008607
8608 VkPipelineColorBlendAttachmentState att = {};
8609 att.blendEnable = VK_FALSE;
8610 att.colorWriteMask = 0xf;
8611
8612 VkPipelineColorBlendStateCreateInfo cb_ci = {};
8613 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
8614 cb_ci.pNext = nullptr;
8615 cb_ci.attachmentCount = 1;
8616 cb_ci.pAttachments = &att;
8617
8618 VkGraphicsPipelineCreateInfo gp_ci = {};
8619 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8620 gp_ci.stageCount = 2;
8621 gp_ci.pStages = shaderStages;
8622 gp_ci.pVertexInputState = &vi_ci;
8623 gp_ci.pInputAssemblyState = &ia_ci;
8624 gp_ci.pViewportState = &vp_state_ci;
8625 gp_ci.pRasterizationState = &rs_ci;
8626 gp_ci.pColorBlendState = &cb_ci;
8627 gp_ci.pDynamicState = &dyn_state_ci;
8628 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
8629 gp_ci.layout = pipeline_layout;
8630 gp_ci.renderPass = renderPass();
8631
8632 VkPipelineCacheCreateInfo pc_ci = {};
8633 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
8634
8635 VkPipeline pipeline;
8636 VkPipelineCache pipelineCache;
8637
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008638 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06008639 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008640 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06008641
8642 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06008643 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06008644
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008645 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06008646
8647 // Check too high (line width of 65536.0f).
8648 rs_ci.lineWidth = 65536.0f;
8649
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008650 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06008651 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008652 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06008653
8654 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06008655 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06008656
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008657 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06008658
8659 dyn_state_ci.dynamicStateCount = 3;
8660
8661 rs_ci.lineWidth = 1.0f;
8662
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008663 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06008664 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008665 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tony Barbour552f6c02016-12-21 14:34:07 -07008666 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008667 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06008668
8669 // Check too low with dynamic setting.
Mark Young47107952016-05-02 15:59:55 -06008670 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), -1.0f);
Mark Young7394fdd2016-03-31 14:56:43 -06008671 m_errorMonitor->VerifyFound();
8672
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008673 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06008674
8675 // Check too high with dynamic setting.
8676 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), 65536.0f);
8677 m_errorMonitor->VerifyFound();
Tony Barbour552f6c02016-12-21 14:34:07 -07008678 m_commandBuffer->EndCommandBuffer();
Mark Young7394fdd2016-03-31 14:56:43 -06008679
8680 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
8681 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8682 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8683 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008684 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06008685}
8686
Jeremy Hayes37f0cdd2017-05-04 18:08:49 -06008687TEST_F(VkLayerTest, VALIDATION_ERROR_01407) {
8688 TEST_DESCRIPTION("Test VALIDATION_ERROR_01407: binding must be less than VkPhysicalDeviceLimits::maxVertexInputBindings");
8689
8690 ASSERT_NO_FATAL_FAILURE(Init());
8691 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8692
8693 VkPipelineCache pipeline_cache;
8694 {
8695 VkPipelineCacheCreateInfo create_info{};
8696 create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
8697
8698 VkResult err = vkCreatePipelineCache(m_device->device(), &create_info, nullptr, &pipeline_cache);
8699 ASSERT_VK_SUCCESS(err);
8700 }
8701
8702 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
8703 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
8704
8705 VkPipelineShaderStageCreateInfo stages[2]{{}};
8706 stages[0] = vs.GetStageCreateInfo();
8707 stages[1] = fs.GetStageCreateInfo();
8708
8709 // Test when binding is greater than or equal to VkPhysicalDeviceLimits::maxVertexInputBindings.
8710 VkVertexInputBindingDescription vertex_input_binding_description{};
8711 vertex_input_binding_description.binding = m_device->props.limits.maxVertexInputBindings;
8712
8713 VkPipelineVertexInputStateCreateInfo vertex_input_state{};
8714 vertex_input_state.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
8715 vertex_input_state.pNext = nullptr;
8716 vertex_input_state.vertexBindingDescriptionCount = 1;
8717 vertex_input_state.pVertexBindingDescriptions = &vertex_input_binding_description;
8718 vertex_input_state.vertexAttributeDescriptionCount = 0;
8719 vertex_input_state.pVertexAttributeDescriptions = nullptr;
8720
8721 VkPipelineInputAssemblyStateCreateInfo input_assembly_state{};
8722 input_assembly_state.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
8723 input_assembly_state.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
8724
8725 VkViewport viewport{};
8726 VkPipelineViewportStateCreateInfo viewport_state{};
8727 viewport_state.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
8728 viewport_state.scissorCount = 1;
8729 viewport_state.viewportCount = 1;
8730 viewport_state.pViewports = &viewport;
8731
8732 VkPipelineMultisampleStateCreateInfo multisample_state{};
8733 multisample_state.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
8734 multisample_state.pNext = nullptr;
8735 multisample_state.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
8736 multisample_state.sampleShadingEnable = 0;
8737 multisample_state.minSampleShading = 1.0;
8738 multisample_state.pSampleMask = nullptr;
8739
8740 VkPipelineRasterizationStateCreateInfo rasterization_state{};
8741 rasterization_state.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
8742 rasterization_state.polygonMode = VK_POLYGON_MODE_FILL;
8743 rasterization_state.cullMode = VK_CULL_MODE_BACK_BIT;
8744 rasterization_state.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
8745 rasterization_state.depthClampEnable = VK_FALSE;
8746 rasterization_state.rasterizerDiscardEnable = VK_FALSE;
8747 rasterization_state.depthBiasEnable = VK_FALSE;
8748
8749 VkPipelineLayout pipeline_layout;
8750 {
8751 VkPipelineLayoutCreateInfo create_info{};
8752 create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8753 create_info.setLayoutCount = 0;
8754 create_info.pSetLayouts = nullptr;
8755
8756 VkResult err = vkCreatePipelineLayout(m_device->device(), &create_info, nullptr, &pipeline_layout);
8757 ASSERT_VK_SUCCESS(err);
8758 }
8759
8760 {
8761 VkGraphicsPipelineCreateInfo create_info{};
8762 create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8763 create_info.stageCount = 2;
8764 create_info.pStages = stages;
8765 create_info.pVertexInputState = &vertex_input_state;
8766 create_info.pInputAssemblyState = &input_assembly_state;
8767 create_info.pViewportState = &viewport_state;
8768 create_info.pMultisampleState = &multisample_state;
8769 create_info.pRasterizationState = &rasterization_state;
8770 create_info.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
8771 create_info.layout = pipeline_layout;
8772 create_info.renderPass = renderPass();
8773
8774 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01407);
8775 VkPipeline pipeline;
8776 vkCreateGraphicsPipelines(m_device->device(), pipeline_cache, 1, &create_info, nullptr, &pipeline);
8777 m_errorMonitor->VerifyFound();
8778 }
8779
8780 vkDestroyPipelineCache(m_device->device(), pipeline_cache, nullptr);
8781 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
8782}
8783
8784TEST_F(VkLayerTest, VALIDATION_ERROR_01408) {
8785 TEST_DESCRIPTION(
8786 "Test VALIDATION_ERROR_01408: stride must be less than or equal to VkPhysicalDeviceLimits::maxVertexInputBindingStride");
8787
8788 ASSERT_NO_FATAL_FAILURE(Init());
8789 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8790
8791 VkPipelineCache pipeline_cache;
8792 {
8793 VkPipelineCacheCreateInfo create_info{};
8794 create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
8795
8796 VkResult err = vkCreatePipelineCache(m_device->device(), &create_info, nullptr, &pipeline_cache);
8797 ASSERT_VK_SUCCESS(err);
8798 }
8799
8800 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
8801 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
8802
8803 VkPipelineShaderStageCreateInfo stages[2]{{}};
8804 stages[0] = vs.GetStageCreateInfo();
8805 stages[1] = fs.GetStageCreateInfo();
8806
8807 // Test when stride is greater than VkPhysicalDeviceLimits::maxVertexInputBindingStride.
8808 VkVertexInputBindingDescription vertex_input_binding_description{};
8809 vertex_input_binding_description.stride = m_device->props.limits.maxVertexInputBindingStride + 1;
8810
8811 VkPipelineVertexInputStateCreateInfo vertex_input_state{};
8812 vertex_input_state.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
8813 vertex_input_state.pNext = nullptr;
8814 vertex_input_state.vertexBindingDescriptionCount = 1;
8815 vertex_input_state.pVertexBindingDescriptions = &vertex_input_binding_description;
8816 vertex_input_state.vertexAttributeDescriptionCount = 0;
8817 vertex_input_state.pVertexAttributeDescriptions = nullptr;
8818
8819 VkPipelineInputAssemblyStateCreateInfo input_assembly_state{};
8820 input_assembly_state.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
8821 input_assembly_state.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
8822
8823 VkViewport viewport{};
8824 VkPipelineViewportStateCreateInfo viewport_state{};
8825 viewport_state.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
8826 viewport_state.scissorCount = 1;
8827 viewport_state.viewportCount = 1;
8828 viewport_state.pViewports = &viewport;
8829
8830 VkPipelineMultisampleStateCreateInfo multisample_state{};
8831 multisample_state.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
8832 multisample_state.pNext = nullptr;
8833 multisample_state.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
8834 multisample_state.sampleShadingEnable = 0;
8835 multisample_state.minSampleShading = 1.0;
8836 multisample_state.pSampleMask = nullptr;
8837
8838 VkPipelineRasterizationStateCreateInfo rasterization_state{};
8839 rasterization_state.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
8840 rasterization_state.polygonMode = VK_POLYGON_MODE_FILL;
8841 rasterization_state.cullMode = VK_CULL_MODE_BACK_BIT;
8842 rasterization_state.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
8843 rasterization_state.depthClampEnable = VK_FALSE;
8844 rasterization_state.rasterizerDiscardEnable = VK_FALSE;
8845 rasterization_state.depthBiasEnable = VK_FALSE;
8846
8847 VkPipelineLayout pipeline_layout;
8848 {
8849 VkPipelineLayoutCreateInfo create_info{};
8850 create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8851 create_info.setLayoutCount = 0;
8852 create_info.pSetLayouts = nullptr;
8853
8854 VkResult err = vkCreatePipelineLayout(m_device->device(), &create_info, nullptr, &pipeline_layout);
8855 ASSERT_VK_SUCCESS(err);
8856 }
8857
8858 {
8859 VkGraphicsPipelineCreateInfo create_info{};
8860 create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8861 create_info.stageCount = 2;
8862 create_info.pStages = stages;
8863 create_info.pVertexInputState = &vertex_input_state;
8864 create_info.pInputAssemblyState = &input_assembly_state;
8865 create_info.pViewportState = &viewport_state;
8866 create_info.pMultisampleState = &multisample_state;
8867 create_info.pRasterizationState = &rasterization_state;
8868 create_info.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
8869 create_info.layout = pipeline_layout;
8870 create_info.renderPass = renderPass();
8871
8872 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01408);
8873 VkPipeline pipeline;
8874 vkCreateGraphicsPipelines(m_device->device(), pipeline_cache, 1, &create_info, nullptr, &pipeline);
8875 m_errorMonitor->VerifyFound();
8876 }
8877
8878 vkDestroyPipelineCache(m_device->device(), pipeline_cache, nullptr);
8879 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
8880}
8881
Jeremy Hayes091e1ab2017-05-04 18:10:28 -06008882TEST_F(VkLayerTest, VALIDATION_ERROR_01410) {
8883 TEST_DESCRIPTION("Test VALIDATION_ERROR_01410: location must be less than VkPhysicalDeviceLimits::maxVertexInputAttributes");
8884
8885 ASSERT_NO_FATAL_FAILURE(Init());
8886 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8887
8888 VkPipelineCache pipeline_cache;
8889 {
8890 VkPipelineCacheCreateInfo create_info{};
8891 create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
8892
8893 VkResult err = vkCreatePipelineCache(m_device->device(), &create_info, nullptr, &pipeline_cache);
8894 ASSERT_VK_SUCCESS(err);
8895 }
8896
8897 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
8898 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
8899
8900 VkPipelineShaderStageCreateInfo stages[2]{{}};
8901 stages[0] = vs.GetStageCreateInfo();
8902 stages[1] = fs.GetStageCreateInfo();
8903
8904 // Test when location is greater than or equal to VkPhysicalDeviceLimits::maxVertexInputAttributes.
8905 VkVertexInputAttributeDescription vertex_input_attribute_description{};
8906 vertex_input_attribute_description.location = m_device->props.limits.maxVertexInputAttributes;
8907
8908 VkPipelineVertexInputStateCreateInfo vertex_input_state{};
8909 vertex_input_state.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
8910 vertex_input_state.pNext = nullptr;
8911 vertex_input_state.vertexBindingDescriptionCount = 0;
8912 vertex_input_state.pVertexBindingDescriptions = nullptr;
8913 vertex_input_state.vertexAttributeDescriptionCount = 1;
8914 vertex_input_state.pVertexAttributeDescriptions = &vertex_input_attribute_description;
8915
8916 VkPipelineInputAssemblyStateCreateInfo input_assembly_state{};
8917 input_assembly_state.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
8918 input_assembly_state.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
8919
8920 VkViewport viewport{};
8921 VkPipelineViewportStateCreateInfo viewport_state{};
8922 viewport_state.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
8923 viewport_state.scissorCount = 1;
8924 viewport_state.viewportCount = 1;
8925 viewport_state.pViewports = &viewport;
8926
8927 VkPipelineMultisampleStateCreateInfo multisample_state{};
8928 multisample_state.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
8929 multisample_state.pNext = nullptr;
8930 multisample_state.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
8931 multisample_state.sampleShadingEnable = 0;
8932 multisample_state.minSampleShading = 1.0;
8933 multisample_state.pSampleMask = nullptr;
8934
8935 VkPipelineRasterizationStateCreateInfo rasterization_state{};
8936 rasterization_state.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
8937 rasterization_state.polygonMode = VK_POLYGON_MODE_FILL;
8938 rasterization_state.cullMode = VK_CULL_MODE_BACK_BIT;
8939 rasterization_state.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
8940 rasterization_state.depthClampEnable = VK_FALSE;
8941 rasterization_state.rasterizerDiscardEnable = VK_FALSE;
8942 rasterization_state.depthBiasEnable = VK_FALSE;
8943
8944 VkPipelineLayout pipeline_layout;
8945 {
8946 VkPipelineLayoutCreateInfo create_info{};
8947 create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8948 create_info.setLayoutCount = 0;
8949 create_info.pSetLayouts = nullptr;
8950
8951 VkResult err = vkCreatePipelineLayout(m_device->device(), &create_info, nullptr, &pipeline_layout);
8952 ASSERT_VK_SUCCESS(err);
8953 }
8954
8955 {
8956 VkGraphicsPipelineCreateInfo create_info{};
8957 create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8958 create_info.stageCount = 2;
8959 create_info.pStages = stages;
8960 create_info.pVertexInputState = &vertex_input_state;
8961 create_info.pInputAssemblyState = &input_assembly_state;
8962 create_info.pViewportState = &viewport_state;
8963 create_info.pMultisampleState = &multisample_state;
8964 create_info.pRasterizationState = &rasterization_state;
8965 create_info.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
8966 create_info.layout = pipeline_layout;
8967 create_info.renderPass = renderPass();
8968
8969 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01410);
8970 VkPipeline pipeline;
8971 vkCreateGraphicsPipelines(m_device->device(), pipeline_cache, 1, &create_info, nullptr, &pipeline);
8972 m_errorMonitor->VerifyFound();
8973 }
8974
8975 vkDestroyPipelineCache(m_device->device(), pipeline_cache, nullptr);
8976 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
8977}
8978
8979TEST_F(VkLayerTest, VALIDATION_ERROR_01411) {
8980 TEST_DESCRIPTION("Test VALIDATION_ERROR_01411: binding must be less than VkPhysicalDeviceLimits::maxVertexInputBindings");
8981
8982 ASSERT_NO_FATAL_FAILURE(Init());
8983 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8984
8985 VkPipelineCache pipeline_cache;
8986 {
8987 VkPipelineCacheCreateInfo create_info{};
8988 create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
8989
8990 VkResult err = vkCreatePipelineCache(m_device->device(), &create_info, nullptr, &pipeline_cache);
8991 ASSERT_VK_SUCCESS(err);
8992 }
8993
8994 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
8995 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
8996
8997 VkPipelineShaderStageCreateInfo stages[2]{{}};
8998 stages[0] = vs.GetStageCreateInfo();
8999 stages[1] = fs.GetStageCreateInfo();
9000
9001 // Test when binding is greater than or equal to VkPhysicalDeviceLimits::maxVertexInputBindings.
9002 VkVertexInputAttributeDescription vertex_input_attribute_description{};
9003 vertex_input_attribute_description.binding = m_device->props.limits.maxVertexInputBindings;
9004
9005 VkPipelineVertexInputStateCreateInfo vertex_input_state{};
9006 vertex_input_state.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
9007 vertex_input_state.pNext = nullptr;
9008 vertex_input_state.vertexBindingDescriptionCount = 0;
9009 vertex_input_state.pVertexBindingDescriptions = nullptr;
9010 vertex_input_state.vertexAttributeDescriptionCount = 1;
9011 vertex_input_state.pVertexAttributeDescriptions = &vertex_input_attribute_description;
9012
9013 VkPipelineInputAssemblyStateCreateInfo input_assembly_state{};
9014 input_assembly_state.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
9015 input_assembly_state.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
9016
9017 VkViewport viewport{};
9018 VkPipelineViewportStateCreateInfo viewport_state{};
9019 viewport_state.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
9020 viewport_state.scissorCount = 1;
9021 viewport_state.viewportCount = 1;
9022 viewport_state.pViewports = &viewport;
9023
9024 VkPipelineMultisampleStateCreateInfo multisample_state{};
9025 multisample_state.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
9026 multisample_state.pNext = nullptr;
9027 multisample_state.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
9028 multisample_state.sampleShadingEnable = 0;
9029 multisample_state.minSampleShading = 1.0;
9030 multisample_state.pSampleMask = nullptr;
9031
9032 VkPipelineRasterizationStateCreateInfo rasterization_state{};
9033 rasterization_state.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
9034 rasterization_state.polygonMode = VK_POLYGON_MODE_FILL;
9035 rasterization_state.cullMode = VK_CULL_MODE_BACK_BIT;
9036 rasterization_state.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
9037 rasterization_state.depthClampEnable = VK_FALSE;
9038 rasterization_state.rasterizerDiscardEnable = VK_FALSE;
9039 rasterization_state.depthBiasEnable = VK_FALSE;
9040
9041 VkPipelineLayout pipeline_layout;
9042 {
9043 VkPipelineLayoutCreateInfo create_info{};
9044 create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9045 create_info.setLayoutCount = 0;
9046 create_info.pSetLayouts = nullptr;
9047
9048 VkResult err = vkCreatePipelineLayout(m_device->device(), &create_info, nullptr, &pipeline_layout);
9049 ASSERT_VK_SUCCESS(err);
9050 }
9051
9052 {
9053 VkGraphicsPipelineCreateInfo create_info{};
9054 create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
9055 create_info.stageCount = 2;
9056 create_info.pStages = stages;
9057 create_info.pVertexInputState = &vertex_input_state;
9058 create_info.pInputAssemblyState = &input_assembly_state;
9059 create_info.pViewportState = &viewport_state;
9060 create_info.pMultisampleState = &multisample_state;
9061 create_info.pRasterizationState = &rasterization_state;
9062 create_info.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
9063 create_info.layout = pipeline_layout;
9064 create_info.renderPass = renderPass();
9065
9066 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01411);
9067 VkPipeline pipeline;
9068 vkCreateGraphicsPipelines(m_device->device(), pipeline_cache, 1, &create_info, nullptr, &pipeline);
9069 m_errorMonitor->VerifyFound();
9070 }
9071
9072 vkDestroyPipelineCache(m_device->device(), pipeline_cache, nullptr);
9073 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
9074}
9075
9076TEST_F(VkLayerTest, VALIDATION_ERROR_01412) {
9077 TEST_DESCRIPTION(
9078 "Test VALIDATION_ERROR_01412: offset must be less than or equal to VkPhysicalDeviceLimits::maxVertexInputAttributeOffset");
9079
9080 ASSERT_NO_FATAL_FAILURE(Init());
9081 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9082
9083 VkPipelineCache pipeline_cache;
9084 {
9085 VkPipelineCacheCreateInfo create_info{};
9086 create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
9087
9088 VkResult err = vkCreatePipelineCache(m_device->device(), &create_info, nullptr, &pipeline_cache);
9089 ASSERT_VK_SUCCESS(err);
9090 }
9091
9092 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9093 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
9094
9095 VkPipelineShaderStageCreateInfo stages[2]{{}};
9096 stages[0] = vs.GetStageCreateInfo();
9097 stages[1] = fs.GetStageCreateInfo();
9098
9099 // Test when offset is greater than maximum.
9100 VkVertexInputAttributeDescription vertex_input_attribute_description{};
9101 vertex_input_attribute_description.offset = m_device->props.limits.maxVertexInputAttributeOffset + 1;
9102
9103 VkPipelineVertexInputStateCreateInfo vertex_input_state{};
9104 vertex_input_state.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
9105 vertex_input_state.pNext = nullptr;
9106 vertex_input_state.vertexBindingDescriptionCount = 0;
9107 vertex_input_state.pVertexBindingDescriptions = nullptr;
9108 vertex_input_state.vertexAttributeDescriptionCount = 1;
9109 vertex_input_state.pVertexAttributeDescriptions = &vertex_input_attribute_description;
9110
9111 VkPipelineInputAssemblyStateCreateInfo input_assembly_state{};
9112 input_assembly_state.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
9113 input_assembly_state.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
9114
9115 VkViewport viewport{};
9116 VkPipelineViewportStateCreateInfo viewport_state{};
9117 viewport_state.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
9118 viewport_state.scissorCount = 1;
9119 viewport_state.viewportCount = 1;
9120 viewport_state.pViewports = &viewport;
9121
9122 VkPipelineMultisampleStateCreateInfo multisample_state{};
9123 multisample_state.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
9124 multisample_state.pNext = nullptr;
9125 multisample_state.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
9126 multisample_state.sampleShadingEnable = 0;
9127 multisample_state.minSampleShading = 1.0;
9128 multisample_state.pSampleMask = nullptr;
9129
9130 VkPipelineRasterizationStateCreateInfo rasterization_state{};
9131 rasterization_state.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
9132 rasterization_state.polygonMode = VK_POLYGON_MODE_FILL;
9133 rasterization_state.cullMode = VK_CULL_MODE_BACK_BIT;
9134 rasterization_state.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
9135 rasterization_state.depthClampEnable = VK_FALSE;
9136 rasterization_state.rasterizerDiscardEnable = VK_FALSE;
9137 rasterization_state.depthBiasEnable = VK_FALSE;
9138
9139 VkPipelineLayout pipeline_layout;
9140 {
9141 VkPipelineLayoutCreateInfo create_info{};
9142 create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9143 create_info.setLayoutCount = 0;
9144 create_info.pSetLayouts = nullptr;
9145
9146 VkResult err = vkCreatePipelineLayout(m_device->device(), &create_info, nullptr, &pipeline_layout);
9147 ASSERT_VK_SUCCESS(err);
9148 }
9149
9150 {
9151 VkGraphicsPipelineCreateInfo create_info{};
9152 create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
9153 create_info.stageCount = 2;
9154 create_info.pStages = stages;
9155 create_info.pVertexInputState = &vertex_input_state;
9156 create_info.pInputAssemblyState = &input_assembly_state;
9157 create_info.pViewportState = &viewport_state;
9158 create_info.pMultisampleState = &multisample_state;
9159 create_info.pRasterizationState = &rasterization_state;
9160 create_info.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
9161 create_info.layout = pipeline_layout;
9162 create_info.renderPass = renderPass();
9163
9164 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01412);
9165 VkPipeline pipeline;
9166 vkCreateGraphicsPipelines(m_device->device(), pipeline_cache, 1, &create_info, nullptr, &pipeline);
9167 m_errorMonitor->VerifyFound();
9168 }
9169
9170 vkDestroyPipelineCache(m_device->device(), pipeline_cache, nullptr);
9171 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
9172}
9173
Karl Schultz6addd812016-02-02 17:17:23 -07009174TEST_F(VkLayerTest, NullRenderPass) {
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06009175 // Bind a NULL RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009176 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mike Schuchardt0b1f2f82016-12-28 15:11:20 -07009177 "vkCmdBeginRenderPass: required parameter pRenderPassBegin specified as NULL");
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06009178
Tony Barbour1fa09702017-03-16 12:09:08 -06009179 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06009180 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06009181
Tony Barbour552f6c02016-12-21 14:34:07 -07009182 m_commandBuffer->BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07009183 // Don't care about RenderPass handle b/c error should be flagged before
9184 // that
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009185 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06009186
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009187 m_errorMonitor->VerifyFound();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06009188}
9189
Karl Schultz6addd812016-02-02 17:17:23 -07009190TEST_F(VkLayerTest, RenderPassWithinRenderPass) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009191 // Bind a BeginRenderPass within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009192 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9193 "It is invalid to issue this call inside an active render pass");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009194
Tony Barbour1fa09702017-03-16 12:09:08 -06009195 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009196 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009197
Tony Barbour552f6c02016-12-21 14:34:07 -07009198 m_commandBuffer->BeginCommandBuffer();
9199 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Karl Schultz6addd812016-02-02 17:17:23 -07009200 // Just create a dummy Renderpass that's non-NULL so we can get to the
9201 // proper error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009202 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009203
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009204 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009205}
9206
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06009207TEST_F(VkLayerTest, RenderPassClearOpMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009208 TEST_DESCRIPTION(
9209 "Begin a renderPass where clearValueCount is less than"
9210 "the number of renderPass attachments that use loadOp"
9211 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06009212
Tony Barbour1fa09702017-03-16 12:09:08 -06009213 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06009214 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9215
9216 // Create a renderPass with a single attachment that uses loadOp CLEAR
9217 VkAttachmentReference attach = {};
9218 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
9219 VkSubpassDescription subpass = {};
Cort Stratton7547f772017-05-04 15:18:52 -07009220 subpass.colorAttachmentCount = 1;
9221 subpass.pColorAttachments = &attach;
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06009222 VkRenderPassCreateInfo rpci = {};
9223 rpci.subpassCount = 1;
9224 rpci.pSubpasses = &subpass;
9225 rpci.attachmentCount = 1;
9226 VkAttachmentDescription attach_desc = {};
Rene Lindsay4bf0e4c2017-01-31 14:20:34 -07009227 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06009228 // Set loadOp to CLEAR
9229 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
9230 rpci.pAttachments = &attach_desc;
9231 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
9232 VkRenderPass rp;
9233 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
9234
9235 VkCommandBufferInheritanceInfo hinfo = {};
9236 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
9237 hinfo.renderPass = VK_NULL_HANDLE;
9238 hinfo.subpass = 0;
9239 hinfo.framebuffer = VK_NULL_HANDLE;
9240 hinfo.occlusionQueryEnable = VK_FALSE;
9241 hinfo.queryFlags = 0;
9242 hinfo.pipelineStatistics = 0;
9243 VkCommandBufferBeginInfo info = {};
9244 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
9245 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
9246 info.pInheritanceInfo = &hinfo;
9247
9248 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
9249 VkRenderPassBeginInfo rp_begin = {};
9250 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
9251 rp_begin.pNext = NULL;
9252 rp_begin.renderPass = renderPass();
9253 rp_begin.framebuffer = framebuffer();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009254 rp_begin.clearValueCount = 0; // Should be 1
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06009255
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07009256 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00442);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06009257
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009258 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06009259
9260 m_errorMonitor->VerifyFound();
Mark Lobodzinski5c70ebd2016-06-09 13:45:00 -06009261
9262 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06009263}
9264
Slawomir Cygan0808f392016-11-28 17:53:23 +01009265TEST_F(VkLayerTest, RenderPassClearOpTooManyValues) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009266 TEST_DESCRIPTION(
9267 "Begin a renderPass where clearValueCount is greater than"
9268 "the number of renderPass attachments that use loadOp"
9269 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
Slawomir Cygan0808f392016-11-28 17:53:23 +01009270
Tony Barbour1fa09702017-03-16 12:09:08 -06009271 ASSERT_NO_FATAL_FAILURE(Init());
Slawomir Cygan0808f392016-11-28 17:53:23 +01009272 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9273
9274 // Create a renderPass with a single attachment that uses loadOp CLEAR
9275 VkAttachmentReference attach = {};
9276 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
9277 VkSubpassDescription subpass = {};
Cort Stratton7547f772017-05-04 15:18:52 -07009278 subpass.colorAttachmentCount = 1;
9279 subpass.pColorAttachments = &attach;
Slawomir Cygan0808f392016-11-28 17:53:23 +01009280 VkRenderPassCreateInfo rpci = {};
9281 rpci.subpassCount = 1;
9282 rpci.pSubpasses = &subpass;
9283 rpci.attachmentCount = 1;
9284 VkAttachmentDescription attach_desc = {};
9285 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
9286 // Set loadOp to CLEAR
9287 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
9288 rpci.pAttachments = &attach_desc;
9289 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
9290 VkRenderPass rp;
9291 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
9292
9293 VkCommandBufferBeginInfo info = {};
9294 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
9295 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
9296
9297 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
9298 VkRenderPassBeginInfo rp_begin = {};
9299 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
9300 rp_begin.pNext = NULL;
9301 rp_begin.renderPass = renderPass();
9302 rp_begin.framebuffer = framebuffer();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009303 rp_begin.clearValueCount = 2; // Should be 1
Slawomir Cygan0808f392016-11-28 17:53:23 +01009304
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07009305 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
9306 " has a clearValueCount of"
9307 " 2 but only first 1 entries in pClearValues array are used");
Slawomir Cygan0808f392016-11-28 17:53:23 +01009308
9309 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
9310
9311 m_errorMonitor->VerifyFound();
9312
9313 vkDestroyRenderPass(m_device->device(), rp, NULL);
9314}
9315
Cody Northrop3bb4d962016-05-09 16:15:57 -06009316TEST_F(VkLayerTest, EndCommandBufferWithinRenderPass) {
Cody Northrop3bb4d962016-05-09 16:15:57 -06009317 TEST_DESCRIPTION("End a command buffer with an active render pass");
9318
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009319 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9320 "It is invalid to issue this call inside an active render pass");
Cody Northrop3bb4d962016-05-09 16:15:57 -06009321
Tony Barbour1fa09702017-03-16 12:09:08 -06009322 ASSERT_NO_FATAL_FAILURE(Init());
Cody Northrop3bb4d962016-05-09 16:15:57 -06009323 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9324
Tony Barbour552f6c02016-12-21 14:34:07 -07009325 m_commandBuffer->BeginCommandBuffer();
9326 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
9327 vkEndCommandBuffer(m_commandBuffer->handle());
Cody Northrop3bb4d962016-05-09 16:15:57 -06009328
9329 m_errorMonitor->VerifyFound();
9330
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009331 // TODO: Add test for VK_COMMAND_BUFFER_LEVEL_SECONDARY
9332 // TODO: Add test for VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT
Cody Northrop3bb4d962016-05-09 16:15:57 -06009333}
9334
Karl Schultz6addd812016-02-02 17:17:23 -07009335TEST_F(VkLayerTest, FillBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009336 // Call CmdFillBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009337 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9338 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009339
Tony Barbour1fa09702017-03-16 12:09:08 -06009340 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009341 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009342
Tony Barbour552f6c02016-12-21 14:34:07 -07009343 m_commandBuffer->BeginCommandBuffer();
9344 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009345
9346 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009347 vk_testing::Buffer dstBuffer;
9348 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009349
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009350 m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009351
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009352 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009353}
9354
Karl Schultz6addd812016-02-02 17:17:23 -07009355TEST_F(VkLayerTest, UpdateBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009356 // Call CmdUpdateBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009357 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9358 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009359
Tony Barbour1fa09702017-03-16 12:09:08 -06009360 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009361 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009362
Tony Barbour552f6c02016-12-21 14:34:07 -07009363 m_commandBuffer->BeginCommandBuffer();
9364 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009365
9366 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009367 vk_testing::Buffer dstBuffer;
9368 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009369
Karl Schultz6addd812016-02-02 17:17:23 -07009370 VkDeviceSize dstOffset = 0;
Rene Lindsay32d26902017-02-02 16:49:24 -07009371 uint32_t Data[] = {1, 2, 3, 4, 5, 6, 7, 8};
9372 VkDeviceSize dataSize = sizeof(Data) / sizeof(uint32_t);
9373 vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(), dstOffset, dataSize, &Data);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009374
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009375 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009376}
9377
Karl Schultz6addd812016-02-02 17:17:23 -07009378TEST_F(VkLayerTest, ClearColorImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009379 // Call CmdClearColorImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009380 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9381 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009382
Tony Barbour1fa09702017-03-16 12:09:08 -06009383 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009384 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009385
Tony Barbour552f6c02016-12-21 14:34:07 -07009386 m_commandBuffer->BeginCommandBuffer();
9387 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009388
Michael Lentine0a369f62016-02-03 16:51:46 -06009389 VkClearColorValue clear_color;
9390 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
Karl Schultz6addd812016-02-02 17:17:23 -07009391 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
9392 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
9393 const int32_t tex_width = 32;
9394 const int32_t tex_height = 32;
9395 VkImageCreateInfo image_create_info = {};
9396 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
9397 image_create_info.pNext = NULL;
9398 image_create_info.imageType = VK_IMAGE_TYPE_2D;
9399 image_create_info.format = tex_format;
9400 image_create_info.extent.width = tex_width;
9401 image_create_info.extent.height = tex_height;
9402 image_create_info.extent.depth = 1;
9403 image_create_info.mipLevels = 1;
9404 image_create_info.arrayLayers = 1;
9405 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
9406 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
Jeremy Hayesa3d5c7b2017-03-07 16:01:52 -07009407 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009408
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009409 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009410 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009411
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009412 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009413
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009414 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009415
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009416 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009417}
9418
Karl Schultz6addd812016-02-02 17:17:23 -07009419TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009420 // Call CmdClearDepthStencilImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009421 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9422 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009423
Tony Barbour1fa09702017-03-16 12:09:08 -06009424 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009425 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009426
Dave Houlton1d2022c2017-03-29 11:43:58 -06009427 auto depth_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbourf887b162017-03-09 10:06:46 -07009428 if (!depth_format) {
9429 printf(" No Depth + Stencil format found. Skipped.\n");
9430 return;
9431 }
9432
Tony Barbour552f6c02016-12-21 14:34:07 -07009433 m_commandBuffer->BeginCommandBuffer();
9434 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009435
9436 VkClearDepthStencilValue clear_value = {0};
Dustin Gravesa2e5c942016-02-11 18:28:06 -07009437 VkMemoryPropertyFlags reqs = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07009438 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
9439 image_create_info.imageType = VK_IMAGE_TYPE_2D;
Tony Barbourf887b162017-03-09 10:06:46 -07009440 image_create_info.format = depth_format;
Karl Schultz6addd812016-02-02 17:17:23 -07009441 image_create_info.extent.width = 64;
9442 image_create_info.extent.height = 64;
9443 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
9444 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009445
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009446 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009447 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009448
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009449 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009450
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07009451 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_value, 1,
9452 &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009453
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009454 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009455}
9456
Karl Schultz6addd812016-02-02 17:17:23 -07009457TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass) {
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06009458 // Call CmdClearAttachmentss outside of an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07009459 VkResult err;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009460
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009461 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9462 "vkCmdClearAttachments(): This call "
9463 "must be issued inside an active "
9464 "render pass");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009465
Tony Barbour1fa09702017-03-16 12:09:08 -06009466 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009467 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009468
9469 // Start no RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009470 err = m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009471 ASSERT_VK_SUCCESS(err);
9472
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06009473 VkClearAttachment color_attachment;
9474 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9475 color_attachment.clearValue.color.float32[0] = 0;
9476 color_attachment.clearValue.color.float32[1] = 0;
9477 color_attachment.clearValue.color.float32[2] = 0;
9478 color_attachment.clearValue.color.float32[3] = 0;
9479 color_attachment.colorAttachment = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07009480 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009481 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009482
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009483 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009484}
9485
Chris Forbes3b97e932016-09-07 11:29:24 +12009486TEST_F(VkLayerTest, RenderPassExcessiveNextSubpass) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009487 TEST_DESCRIPTION(
9488 "Test that an error is produced when CmdNextSubpass is "
9489 "called too many times in a renderpass instance");
Chris Forbes3b97e932016-09-07 11:29:24 +12009490
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009491 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9492 "vkCmdNextSubpass(): Attempted to advance "
9493 "beyond final subpass");
Chris Forbes3b97e932016-09-07 11:29:24 +12009494
Tony Barbour1fa09702017-03-16 12:09:08 -06009495 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes3b97e932016-09-07 11:29:24 +12009496 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9497
Tony Barbour552f6c02016-12-21 14:34:07 -07009498 m_commandBuffer->BeginCommandBuffer();
9499 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes3b97e932016-09-07 11:29:24 +12009500
9501 // error here.
9502 vkCmdNextSubpass(m_commandBuffer->GetBufferHandle(), VK_SUBPASS_CONTENTS_INLINE);
9503 m_errorMonitor->VerifyFound();
9504
Tony Barbour552f6c02016-12-21 14:34:07 -07009505 m_commandBuffer->EndRenderPass();
9506 m_commandBuffer->EndCommandBuffer();
Chris Forbes3b97e932016-09-07 11:29:24 +12009507}
9508
Chris Forbes6d624702016-09-07 13:57:05 +12009509TEST_F(VkLayerTest, RenderPassEndedBeforeFinalSubpass) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009510 TEST_DESCRIPTION(
9511 "Test that an error is produced when CmdEndRenderPass is "
9512 "called before the final subpass has been reached");
Chris Forbes6d624702016-09-07 13:57:05 +12009513
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009514 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9515 "vkCmdEndRenderPass(): Called before reaching "
9516 "final subpass");
Chris Forbes6d624702016-09-07 13:57:05 +12009517
Tony Barbour1fa09702017-03-16 12:09:08 -06009518 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009519 VkSubpassDescription sd[2] = {{0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr},
9520 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr}};
Chris Forbes6d624702016-09-07 13:57:05 +12009521
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009522 VkRenderPassCreateInfo rcpi = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 2, sd, 0, nullptr};
Chris Forbes6d624702016-09-07 13:57:05 +12009523
9524 VkRenderPass rp;
9525 VkResult err = vkCreateRenderPass(m_device->device(), &rcpi, nullptr, &rp);
9526 ASSERT_VK_SUCCESS(err);
9527
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009528 VkFramebufferCreateInfo fbci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 16, 16, 1};
Chris Forbes6d624702016-09-07 13:57:05 +12009529
9530 VkFramebuffer fb;
9531 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
9532 ASSERT_VK_SUCCESS(err);
9533
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009534 m_commandBuffer->BeginCommandBuffer(); // no implicit RP begin
Chris Forbes6d624702016-09-07 13:57:05 +12009535
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009536 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 +12009537
9538 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
9539
9540 // Error here.
9541 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
9542 m_errorMonitor->VerifyFound();
9543
9544 // Clean up.
9545 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
9546 vkDestroyRenderPass(m_device->device(), rp, nullptr);
9547}
9548
Karl Schultz9e66a292016-04-21 15:57:51 -06009549TEST_F(VkLayerTest, BufferMemoryBarrierNoBuffer) {
9550 // Try to add a buffer memory barrier with no buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009551 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9552 "required parameter pBufferMemoryBarriers[0].buffer specified as VK_NULL_HANDLE");
Karl Schultz9e66a292016-04-21 15:57:51 -06009553
Tony Barbour1fa09702017-03-16 12:09:08 -06009554 ASSERT_NO_FATAL_FAILURE(Init());
Tony Barbour552f6c02016-12-21 14:34:07 -07009555 m_commandBuffer->BeginCommandBuffer();
Karl Schultz9e66a292016-04-21 15:57:51 -06009556
9557 VkBufferMemoryBarrier buf_barrier = {};
9558 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
9559 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
9560 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
9561 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
9562 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
9563 buf_barrier.buffer = VK_NULL_HANDLE;
9564 buf_barrier.offset = 0;
9565 buf_barrier.size = VK_WHOLE_SIZE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009566 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9567 nullptr, 1, &buf_barrier, 0, nullptr);
Karl Schultz9e66a292016-04-21 15:57:51 -06009568
9569 m_errorMonitor->VerifyFound();
9570}
9571
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009572TEST_F(VkLayerTest, InvalidBarriers) {
9573 TEST_DESCRIPTION("A variety of ways to get VK_INVALID_BARRIER ");
9574
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009575 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Barriers cannot be set during subpass");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009576
Tony Barbour1fa09702017-03-16 12:09:08 -06009577 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -06009578 auto depth_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbourf887b162017-03-09 10:06:46 -07009579 if (!depth_format) {
9580 printf(" No Depth + Stencil format found. Skipped.\n");
9581 return;
9582 }
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009583 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9584
9585 VkMemoryBarrier mem_barrier = {};
9586 mem_barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER;
9587 mem_barrier.pNext = NULL;
9588 mem_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
9589 mem_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
Tony Barbour552f6c02016-12-21 14:34:07 -07009590 m_commandBuffer->BeginCommandBuffer();
9591 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009592 // BeginCommandBuffer() starts a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009593 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 1,
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009594 &mem_barrier, 0, nullptr, 0, nullptr);
9595 m_errorMonitor->VerifyFound();
9596
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009597 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image Layout cannot be transitioned to UNDEFINED");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009598 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06009599 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 -06009600 ASSERT_TRUE(image.initialized());
9601 VkImageMemoryBarrier img_barrier = {};
9602 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
9603 img_barrier.pNext = NULL;
9604 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
9605 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
Mark Lobodzinski95512b72017-05-10 12:21:30 -06009606 img_barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009607 // New layout can't be UNDEFINED
9608 img_barrier.newLayout = VK_IMAGE_LAYOUT_UNDEFINED;
9609 img_barrier.image = image.handle();
9610 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
9611 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
9612 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9613 img_barrier.subresourceRange.baseArrayLayer = 0;
9614 img_barrier.subresourceRange.baseMipLevel = 0;
9615 img_barrier.subresourceRange.layerCount = 1;
9616 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009617 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9618 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009619 m_errorMonitor->VerifyFound();
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009620
Mark Lobodzinski95512b72017-05-10 12:21:30 -06009621 // Transition image to color attachment optimal
9622 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
9623 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
9624 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9625 nullptr, 0, nullptr, 1, &img_barrier);
9626 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinski95512b72017-05-10 12:21:30 -06009627
Mark Lobodzinski45daf6e2017-05-10 13:19:02 -06009628 // Try to change layout in a renderpass
9629 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02080);
9630 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9631 nullptr, 0, nullptr, 1, &img_barrier);
9632 m_errorMonitor->VerifyFound();
9633
9634 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
Mark Lobodzinski95512b72017-05-10 12:21:30 -06009635 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the baseArrayLayer");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009636 // baseArrayLayer + layerCount must be <= image's arrayLayers
9637 img_barrier.subresourceRange.baseArrayLayer = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009638 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9639 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009640 m_errorMonitor->VerifyFound();
9641 img_barrier.subresourceRange.baseArrayLayer = 0;
9642
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009643 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the baseMipLevel");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009644 // baseMipLevel + levelCount must be <= image's mipLevels
9645 img_barrier.subresourceRange.baseMipLevel = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009646 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9647 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009648 m_errorMonitor->VerifyFound();
9649 img_barrier.subresourceRange.baseMipLevel = 0;
9650
Mike Weiblen7053aa32017-01-25 15:21:10 -07009651 // levelCount must be non-zero.
9652 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
9653 img_barrier.subresourceRange.levelCount = 0;
9654 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9655 nullptr, 0, nullptr, 1, &img_barrier);
9656 m_errorMonitor->VerifyFound();
9657 img_barrier.subresourceRange.levelCount = 1;
9658
9659 // layerCount must be non-zero.
9660 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00769);
9661 img_barrier.subresourceRange.layerCount = 0;
9662 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9663 nullptr, 0, nullptr, 1, &img_barrier);
9664 m_errorMonitor->VerifyFound();
9665 img_barrier.subresourceRange.layerCount = 1;
9666
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009667 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 -06009668 vk_testing::Buffer buffer;
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07009669 VkMemoryPropertyFlags mem_reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
9670 buffer.init_as_src_and_dst(*m_device, 256, mem_reqs);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009671 VkBufferMemoryBarrier buf_barrier = {};
9672 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
9673 buf_barrier.pNext = NULL;
9674 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
9675 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
9676 buf_barrier.buffer = buffer.handle();
9677 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
9678 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
9679 buf_barrier.offset = 0;
9680 buf_barrier.size = VK_WHOLE_SIZE;
9681 // Can't send buffer barrier during a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009682 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9683 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009684 m_errorMonitor->VerifyFound();
9685 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
9686
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009687 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which is not less than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009688 buf_barrier.offset = 257;
9689 // Offset greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009690 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9691 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009692 m_errorMonitor->VerifyFound();
9693 buf_barrier.offset = 0;
9694
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009695 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "whose sum is greater than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009696 buf_barrier.size = 257;
9697 // Size greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009698 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9699 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009700 m_errorMonitor->VerifyFound();
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009701
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009702 // Now exercise barrier aspect bit errors, first DS
Tobin Ehlis99ab0d22017-04-26 16:53:52 -06009703 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00741);
9704 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00302);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009705 VkDepthStencilObj ds_image(m_device);
Tony Barbourf887b162017-03-09 10:06:46 -07009706 ds_image.Init(m_device, 128, 128, depth_format);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009707 ASSERT_TRUE(ds_image.initialized());
Tobin Ehlis15684a02016-07-21 14:55:26 -06009708 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
9709 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009710 img_barrier.image = ds_image.handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07009711
9712 // Not having DEPTH or STENCIL set is an error
Rene Lindsay4834cba2017-02-02 17:18:56 -07009713 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009714 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9715 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009716 m_errorMonitor->VerifyFound();
Dave Houltonfbf52152017-01-06 12:55:29 -07009717
Tobin Ehlis99ab0d22017-04-26 16:53:52 -06009718 // Having only one of depth or stencil set for DS image is an error
9719 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00302);
9720 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT;
9721 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9722 nullptr, 0, nullptr, 1, &img_barrier);
9723 m_errorMonitor->VerifyFound();
9724
9725 // Having anything other than DEPTH and STENCIL is an error
9726 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00741);
Dave Houltonfbf52152017-01-06 12:55:29 -07009727 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT | VK_IMAGE_ASPECT_COLOR_BIT;
9728 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9729 nullptr, 0, nullptr, 1, &img_barrier);
9730 m_errorMonitor->VerifyFound();
9731
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009732 // Now test depth-only
9733 VkFormatProperties format_props;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009734 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D16_UNORM, &format_props);
9735 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009736 VkDepthStencilObj d_image(m_device);
9737 d_image.Init(m_device, 128, 128, VK_FORMAT_D16_UNORM);
9738 ASSERT_TRUE(d_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009739 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06009740 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009741 img_barrier.image = d_image.handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07009742
9743 // DEPTH bit must be set
9744 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9745 "Depth-only image formats must have the VK_IMAGE_ASPECT_DEPTH_BIT set.");
Rene Lindsay4834cba2017-02-02 17:18:56 -07009746 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Dave Houltonfbf52152017-01-06 12:55:29 -07009747 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
9748 0, nullptr, 0, nullptr, 1, &img_barrier);
9749 m_errorMonitor->VerifyFound();
9750
9751 // No bits other than DEPTH may be set
9752 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9753 "Depth-only image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT set.");
9754 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009755 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
9756 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009757 m_errorMonitor->VerifyFound();
9758 }
Dave Houltonfbf52152017-01-06 12:55:29 -07009759
9760 // Now test stencil-only
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009761 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_S8_UINT, &format_props);
9762 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009763 VkDepthStencilObj s_image(m_device);
9764 s_image.Init(m_device, 128, 128, VK_FORMAT_S8_UINT);
9765 ASSERT_TRUE(s_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009766 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06009767 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009768 img_barrier.image = s_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06009769 // Use of COLOR aspect on depth image is error
Dave Houltonf3229d52017-02-21 15:59:08 -07009770 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9771 "Stencil-only image formats must have the VK_IMAGE_ASPECT_STENCIL_BIT set.");
Tobin Ehlis15684a02016-07-21 14:55:26 -06009772 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009773 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
9774 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009775 m_errorMonitor->VerifyFound();
9776 }
Dave Houltonfbf52152017-01-06 12:55:29 -07009777
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009778 // Finally test color
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009779 VkImageObj c_image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06009780 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 -06009781 ASSERT_TRUE(c_image.initialized());
9782 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
9783 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
9784 img_barrier.image = c_image.handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07009785
9786 // COLOR bit must be set
9787 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9788 "Color image formats must have the VK_IMAGE_ASPECT_COLOR_BIT set.");
Rene Lindsay4834cba2017-02-02 17:18:56 -07009789 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Dave Houltonfbf52152017-01-06 12:55:29 -07009790 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9791 nullptr, 0, nullptr, 1, &img_barrier);
9792 m_errorMonitor->VerifyFound();
9793
9794 // No bits other than COLOR may be set
9795 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9796 "Color image formats must have ONLY the VK_IMAGE_ASPECT_COLOR_BIT set.");
9797 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009798 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9799 nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009800 m_errorMonitor->VerifyFound();
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07009801
Mike Weiblene6e01172017-03-07 22:18:40 -07009802 // A barrier's new and old VkImageLayout must be compatible with an image's VkImageUsageFlags.
9803 {
9804 VkImageObj img_color(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06009805 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 -07009806 ASSERT_TRUE(img_color.initialized());
9807
9808 VkImageObj img_ds(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06009809 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 -07009810 ASSERT_TRUE(img_ds.initialized());
9811
9812 VkImageObj img_xfer_src(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06009813 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 -07009814 ASSERT_TRUE(img_xfer_src.initialized());
9815
9816 VkImageObj img_xfer_dst(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06009817 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 -07009818 ASSERT_TRUE(img_xfer_dst.initialized());
9819
9820 VkImageObj img_sampled(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06009821 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 -07009822 ASSERT_TRUE(img_sampled.initialized());
9823
9824 VkImageObj img_input(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06009825 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 -07009826 ASSERT_TRUE(img_input.initialized());
9827
9828 const struct {
9829 VkImageObj &image_obj;
9830 VkImageLayout bad_layout;
9831 UNIQUE_VALIDATION_ERROR_CODE msg_code;
9832 } bad_buffer_layouts[] = {
9833 // clang-format off
9834 // images _without_ VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT
9835 {img_ds, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VALIDATION_ERROR_00303},
9836 {img_xfer_src, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VALIDATION_ERROR_00303},
9837 {img_xfer_dst, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VALIDATION_ERROR_00303},
9838 {img_sampled, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VALIDATION_ERROR_00303},
9839 {img_input, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VALIDATION_ERROR_00303},
9840 // images _without_ VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT
9841 {img_color, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, VALIDATION_ERROR_00304},
9842 {img_xfer_src, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, VALIDATION_ERROR_00304},
9843 {img_xfer_dst, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, VALIDATION_ERROR_00304},
9844 {img_sampled, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, VALIDATION_ERROR_00304},
9845 {img_input, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, VALIDATION_ERROR_00304},
9846 {img_color, VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL, VALIDATION_ERROR_00305},
9847 {img_xfer_src, VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL, VALIDATION_ERROR_00305},
9848 {img_xfer_dst, VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL, VALIDATION_ERROR_00305},
9849 {img_sampled, VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL, VALIDATION_ERROR_00305},
9850 {img_input, VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL, VALIDATION_ERROR_00305},
9851 // images _without_ VK_IMAGE_USAGE_SAMPLED_BIT or VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT
9852 {img_color, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VALIDATION_ERROR_00306},
9853 {img_ds, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VALIDATION_ERROR_00306},
9854 {img_xfer_src, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VALIDATION_ERROR_00306},
9855 {img_xfer_dst, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VALIDATION_ERROR_00306},
9856 // images _without_ VK_IMAGE_USAGE_TRANSFER_SRC_BIT
9857 {img_color, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VALIDATION_ERROR_00307},
9858 {img_ds, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VALIDATION_ERROR_00307},
9859 {img_xfer_dst, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VALIDATION_ERROR_00307},
9860 {img_sampled, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VALIDATION_ERROR_00307},
9861 {img_input, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VALIDATION_ERROR_00307},
9862 // images _without_ VK_IMAGE_USAGE_TRANSFER_DST_BIT
9863 {img_color, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VALIDATION_ERROR_00308},
9864 {img_ds, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VALIDATION_ERROR_00308},
9865 {img_xfer_src, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VALIDATION_ERROR_00308},
9866 {img_sampled, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VALIDATION_ERROR_00308},
9867 {img_input, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VALIDATION_ERROR_00308},
9868 // clang-format on
9869 };
9870 const uint32_t layout_count = sizeof(bad_buffer_layouts) / sizeof(bad_buffer_layouts[0]);
9871
9872 for (uint32_t i = 0; i < layout_count; ++i) {
9873 img_barrier.image = bad_buffer_layouts[i].image_obj.handle();
9874 const VkImageUsageFlags usage = bad_buffer_layouts[i].image_obj.usage();
9875 img_barrier.subresourceRange.aspectMask = (usage == VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT)
9876 ? (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)
9877 : VK_IMAGE_ASPECT_COLOR_BIT;
9878
9879 img_barrier.oldLayout = bad_buffer_layouts[i].bad_layout;
9880 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
9881 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_buffer_layouts[i].msg_code);
9882 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT,
9883 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0, nullptr, 1, &img_barrier);
9884 m_errorMonitor->VerifyFound();
9885
9886 img_barrier.oldLayout = VK_IMAGE_LAYOUT_GENERAL;
9887 img_barrier.newLayout = bad_buffer_layouts[i].bad_layout;
9888 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_buffer_layouts[i].msg_code);
9889 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT,
9890 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0, nullptr, 1, &img_barrier);
9891 m_errorMonitor->VerifyFound();
9892 }
9893
9894 img_barrier.oldLayout = VK_IMAGE_LAYOUT_GENERAL;
9895 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
9896 }
9897
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07009898 // Attempt to mismatch barriers/waitEvents calls with incompatible queues
9899
9900 // Create command pool with incompatible queueflags
9901 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
Mike Schuchardt06304c22017-03-01 17:09:09 -07009902 uint32_t queue_family_index = m_device->QueueFamilyWithoutCapabilities(VK_QUEUE_COMPUTE_BIT);
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07009903 if (queue_family_index == UINT32_MAX) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07009904 printf(" No non-compute queue found; skipped.\n");
Mike Weiblene6e01172017-03-07 22:18:40 -07009905 return; // NOTE: this exits the test function!
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07009906 }
9907 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02513);
9908
9909 VkCommandPool command_pool;
9910 VkCommandPoolCreateInfo pool_create_info{};
9911 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
9912 pool_create_info.queueFamilyIndex = queue_family_index;
9913 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
9914 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
9915
9916 // Allocate a command buffer
9917 VkCommandBuffer bad_command_buffer;
9918 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
9919 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
9920 command_buffer_allocate_info.commandPool = command_pool;
9921 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
9922 command_buffer_allocate_info.commandBufferCount = 1;
9923 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &bad_command_buffer));
9924
9925 VkCommandBufferBeginInfo cbbi = {};
9926 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
9927 vkBeginCommandBuffer(bad_command_buffer, &cbbi);
9928 buf_barrier.offset = 0;
9929 buf_barrier.size = VK_WHOLE_SIZE;
9930 vkCmdPipelineBarrier(bad_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1,
9931 &buf_barrier, 0, nullptr);
9932 m_errorMonitor->VerifyFound();
9933
9934 if ((queue_props[queue_family_index].queueFlags & VK_QUEUE_GRAPHICS_BIT) == 0) {
9935 vkEndCommandBuffer(bad_command_buffer);
9936 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07009937 printf(" The non-compute queue does not support graphics; skipped.\n");
Mike Weiblene6e01172017-03-07 22:18:40 -07009938 return; // NOTE: this exits the test function!
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07009939 }
9940 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02510);
9941 VkEvent event;
9942 VkEventCreateInfo event_create_info{};
9943 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
9944 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
9945 vkCmdWaitEvents(bad_command_buffer, 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, nullptr, 0,
9946 nullptr, 0, nullptr);
9947 m_errorMonitor->VerifyFound();
9948
9949 vkEndCommandBuffer(bad_command_buffer);
9950 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009951}
9952
Chris Forbes50223732017-05-01 09:43:35 -07009953TEST_F(VkPositiveLayerTest, LayoutFromPresentWithoutAccessMemoryRead) {
9954 // Transition an image away from PRESENT_SRC_KHR without ACCESS_MEMORY_READ
9955 // in srcAccessMask.
Tony Barbour18ba25c2016-09-29 13:42:40 -06009956
Chris Forbes50223732017-05-01 09:43:35 -07009957 // The required behavior here was a bit unclear in earlier versions of the
9958 // spec, but there is no memory dependency required here, so this should
9959 // work without warnings.
9960
9961 m_errorMonitor->ExpectSuccess();
Tony Barbour1fa09702017-03-16 12:09:08 -06009962 ASSERT_NO_FATAL_FAILURE(Init());
Tony Barbour18ba25c2016-09-29 13:42:40 -06009963 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06009964 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 -07009965 VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbour18ba25c2016-09-29 13:42:40 -06009966 ASSERT_TRUE(image.initialized());
9967
9968 VkImageMemoryBarrier barrier = {};
9969 VkImageSubresourceRange range;
9970 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
Tony Barbour18ba25c2016-09-29 13:42:40 -06009971 barrier.srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
Chris Forbes50223732017-05-01 09:43:35 -07009972 barrier.dstAccessMask = 0;
Tony Barbour18ba25c2016-09-29 13:42:40 -06009973 barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
9974 barrier.newLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
9975 barrier.image = image.handle();
9976 range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9977 range.baseMipLevel = 0;
9978 range.levelCount = 1;
9979 range.baseArrayLayer = 0;
9980 range.layerCount = 1;
9981 barrier.subresourceRange = range;
9982 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
9983 cmdbuf.BeginCommandBuffer();
9984 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
9985 &barrier);
9986 barrier.oldLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
9987 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
9988 barrier.srcAccessMask = 0;
9989 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
9990 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
9991 &barrier);
9992
Chris Forbes50223732017-05-01 09:43:35 -07009993 m_errorMonitor->VerifyNotFound();
Tony Barbour18ba25c2016-09-29 13:42:40 -06009994}
9995
Karl Schultz6addd812016-02-02 17:17:23 -07009996TEST_F(VkLayerTest, IdxBufferAlignmentError) {
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009997 // Bind a BeginRenderPass within an active RenderPass
Tony Barbour1fa09702017-03-16 12:09:08 -06009998 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009999 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010000
Jeremy Hayes483d95d2017-03-08 11:03:01 -070010001 uint32_t const indices[] = {0};
10002 VkBufferCreateInfo buf_info = {};
10003 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
10004 buf_info.size = 1024;
10005 buf_info.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
10006 buf_info.queueFamilyIndexCount = 1;
10007 buf_info.pQueueFamilyIndices = indices;
10008
10009 VkBuffer buffer;
10010 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
10011 ASSERT_VK_SUCCESS(err);
10012
10013 VkMemoryRequirements requirements;
10014 vkGetBufferMemoryRequirements(m_device->device(), buffer, &requirements);
10015
10016 VkMemoryAllocateInfo alloc_info{};
10017 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10018 alloc_info.pNext = NULL;
10019 alloc_info.memoryTypeIndex = 0;
10020 alloc_info.allocationSize = requirements.size;
10021 bool pass = m_device->phy().set_memory_type(requirements.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
10022 ASSERT_TRUE(pass);
10023
10024 VkDeviceMemory memory;
10025 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &memory);
10026 ASSERT_VK_SUCCESS(err);
10027
10028 err = vkBindBufferMemory(m_device->device(), buffer, memory, 0);
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010029 ASSERT_VK_SUCCESS(err);
10030
Tony Barbour552f6c02016-12-21 14:34:07 -070010031 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010032 ASSERT_VK_SUCCESS(err);
Jeremy Hayes483d95d2017-03-08 11:03:01 -070010033
Karl Schultz6addd812016-02-02 17:17:23 -070010034 // vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
10035 // VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010036 // Should error before calling to driver so don't care about actual data
Jeremy Hayes483d95d2017-03-08 11:03:01 -070010037 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdBindIndexBuffer() offset (0x7) does not fall on ");
10038 vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), buffer, 7, VK_INDEX_TYPE_UINT16);
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010039 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010040
Jeremy Hayes483d95d2017-03-08 11:03:01 -070010041 vkFreeMemory(m_device->device(), memory, NULL);
10042 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010043}
10044
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -070010045TEST_F(VkLayerTest, InvalidQueueFamilyIndex) {
10046 // Create an out-of-range queueFamilyIndex
Tony Barbour1fa09702017-03-16 12:09:08 -060010047 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -070010048 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10049 VkBufferCreateInfo buffCI = {};
10050 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
10051 buffCI.size = 1024;
Mark Lobodzinski4761d212017-02-28 13:12:44 -070010052 buffCI.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
Jeremy Hayes8a43a0d2017-03-09 11:27:52 -070010053 buffCI.queueFamilyIndexCount = 2;
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -070010054 // Introduce failure by specifying invalid queue_family_index
Mark Lobodzinski4761d212017-02-28 13:12:44 -070010055 uint32_t qfi[2];
10056 qfi[0] = 777;
Jeremy Hayes8a43a0d2017-03-09 11:27:52 -070010057 qfi[1] = 0;
Mark Lobodzinski4761d212017-02-28 13:12:44 -070010058
10059 buffCI.pQueueFamilyIndices = qfi;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010060 buffCI.sharingMode = VK_SHARING_MODE_CONCURRENT; // qfi only matters in CONCURRENT mode
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -070010061
10062 VkBuffer ib;
Jeremy Hayes8a43a0d2017-03-09 11:27:52 -070010063 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10064 "vkCreateBuffer: pCreateInfo->pQueueFamilyIndices[0] (777) must be one of the indices "
10065 "specified when the device was created, via the VkDeviceQueueCreateInfo structure.");
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -070010066 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010067 m_errorMonitor->VerifyFound();
Mark Lobodzinski4761d212017-02-28 13:12:44 -070010068
10069 if (m_device->queue_props.size() > 2) {
Tony Barbour75db7402017-03-09 14:51:36 -070010070 VkBuffer ib2;
Mark Lobodzinski4761d212017-02-28 13:12:44 -070010071 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which was not created allowing concurrent");
10072
10073 // Create buffer shared to queue families 1 and 2, but submitted on queue family 0
10074 buffCI.queueFamilyIndexCount = 2;
10075 qfi[0] = 1;
10076 qfi[1] = 2;
Tony Barbour75db7402017-03-09 14:51:36 -070010077 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib2);
Mark Lobodzinski4761d212017-02-28 13:12:44 -070010078 VkDeviceMemory mem;
10079 VkMemoryRequirements mem_reqs;
Tony Barbour75db7402017-03-09 14:51:36 -070010080 vkGetBufferMemoryRequirements(m_device->device(), ib2, &mem_reqs);
Mark Lobodzinski4761d212017-02-28 13:12:44 -070010081
10082 VkMemoryAllocateInfo alloc_info = {};
10083 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10084 alloc_info.allocationSize = 1024;
10085 bool pass = false;
10086 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
10087 if (!pass) {
Tony Barbour75db7402017-03-09 14:51:36 -070010088 vkDestroyBuffer(m_device->device(), ib2, NULL);
Mark Lobodzinski4761d212017-02-28 13:12:44 -070010089 return;
10090 }
10091 vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
Tony Barbour75db7402017-03-09 14:51:36 -070010092 vkBindBufferMemory(m_device->device(), ib2, mem, 0);
Mark Lobodzinski4761d212017-02-28 13:12:44 -070010093
10094 m_commandBuffer->begin();
Tony Barbour75db7402017-03-09 14:51:36 -070010095 vkCmdFillBuffer(m_commandBuffer->handle(), ib2, 0, 16, 5);
Mark Lobodzinski4761d212017-02-28 13:12:44 -070010096 m_commandBuffer->end();
10097 QueueCommandBuffer(false);
10098 m_errorMonitor->VerifyFound();
Tony Barbour75db7402017-03-09 14:51:36 -070010099 vkDestroyBuffer(m_device->device(), ib2, NULL);
10100 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski4761d212017-02-28 13:12:44 -070010101 }
10102
Tony Barbourdf4c0042016-06-01 15:55:43 -060010103 vkDestroyBuffer(m_device->device(), ib, NULL);
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -070010104}
10105
Karl Schultz6addd812016-02-02 17:17:23 -070010106TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010107 TEST_DESCRIPTION(
10108 "Attempt vkCmdExecuteCommands with a primary command buffer"
10109 " (should only be secondary)");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010110
Tony Barbour1fa09702017-03-16 12:09:08 -060010111 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -060010112 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -060010113
Chris Forbesf29a84f2016-10-06 18:39:28 +130010114 // An empty primary command buffer
10115 VkCommandBufferObj cb(m_device, m_commandPool);
10116 cb.BeginCommandBuffer();
10117 cb.EndCommandBuffer();
Tobin Ehlis0c94db02016-07-19 10:49:32 -060010118
Chris Forbesf29a84f2016-10-06 18:39:28 +130010119 m_commandBuffer->BeginCommandBuffer();
10120 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
10121 VkCommandBuffer handle = cb.handle();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -060010122
Chris Forbesf29a84f2016-10-06 18:39:28 +130010123 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdExecuteCommands() called w/ Primary Cmd Buffer ");
10124 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &handle);
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010125 m_errorMonitor->VerifyFound();
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070010126
Tobin Ehlis6d4d1d52017-04-05 12:06:10 -060010127 m_errorMonitor->SetUnexpectedError("All elements of pCommandBuffers must not be in the pending state");
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -060010128}
10129
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010130TEST_F(VkLayerTest, DSUsageBitsErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010131 TEST_DESCRIPTION(
10132 "Attempt to update descriptor sets for images and buffers "
10133 "that do not have correct usage bits sets.");
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010134 VkResult err;
10135
Tony Barbour1fa09702017-03-16 12:09:08 -060010136 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010137 VkDescriptorPoolSize ds_type_count[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
10138 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
10139 ds_type_count[i].type = VkDescriptorType(i);
10140 ds_type_count[i].descriptorCount = 1;
10141 }
10142 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10143 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10144 ds_pool_ci.pNext = NULL;
10145 ds_pool_ci.maxSets = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
10146 ds_pool_ci.poolSizeCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
10147 ds_pool_ci.pPoolSizes = ds_type_count;
10148
10149 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010150 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010151 ASSERT_VK_SUCCESS(err);
10152
10153 // Create 10 layouts where each has a single descriptor of different type
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010154 VkDescriptorSetLayoutBinding dsl_binding[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010155 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
10156 dsl_binding[i].binding = 0;
10157 dsl_binding[i].descriptorType = VkDescriptorType(i);
10158 dsl_binding[i].descriptorCount = 1;
10159 dsl_binding[i].stageFlags = VK_SHADER_STAGE_ALL;
10160 dsl_binding[i].pImmutableSamplers = NULL;
10161 }
10162
10163 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10164 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10165 ds_layout_ci.pNext = NULL;
10166 ds_layout_ci.bindingCount = 1;
10167 VkDescriptorSetLayout ds_layouts[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
10168 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
10169 ds_layout_ci.pBindings = dsl_binding + i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010170 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, ds_layouts + i);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010171 ASSERT_VK_SUCCESS(err);
10172 }
10173 VkDescriptorSet descriptor_sets[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
10174 VkDescriptorSetAllocateInfo alloc_info = {};
10175 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10176 alloc_info.descriptorSetCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
10177 alloc_info.descriptorPool = ds_pool;
10178 alloc_info.pSetLayouts = ds_layouts;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010179 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010180 ASSERT_VK_SUCCESS(err);
10181
10182 // Create a buffer & bufferView to be used for invalid updates
10183 VkBufferCreateInfo buff_ci = {};
10184 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Tony Barbour415497c2017-01-24 10:06:09 -070010185 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010186 buff_ci.size = 256;
10187 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
Tony Barbour415497c2017-01-24 10:06:09 -070010188 VkBuffer buffer, storage_texel_buffer;
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010189 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
10190 ASSERT_VK_SUCCESS(err);
Tony Barbour415497c2017-01-24 10:06:09 -070010191
10192 // Create another buffer to use in testing the UNIFORM_TEXEL_BUFFER case
10193 buff_ci.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
10194 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &storage_texel_buffer);
10195 ASSERT_VK_SUCCESS(err);
10196
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -070010197 VkMemoryRequirements mem_reqs;
10198 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
10199 VkMemoryAllocateInfo mem_alloc_info = {};
10200 mem_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10201 mem_alloc_info.pNext = NULL;
10202 mem_alloc_info.memoryTypeIndex = 0;
10203 mem_alloc_info.allocationSize = mem_reqs.size;
10204 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc_info, 0);
10205 if (!pass) {
10206 vkDestroyBuffer(m_device->device(), buffer, NULL);
10207 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10208 return;
10209 }
10210 VkDeviceMemory mem;
10211 err = vkAllocateMemory(m_device->device(), &mem_alloc_info, NULL, &mem);
10212 ASSERT_VK_SUCCESS(err);
10213 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
10214 ASSERT_VK_SUCCESS(err);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010215
10216 VkBufferViewCreateInfo buff_view_ci = {};
10217 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
10218 buff_view_ci.buffer = buffer;
10219 buff_view_ci.format = VK_FORMAT_R8_UNORM;
10220 buff_view_ci.range = VK_WHOLE_SIZE;
10221 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010222 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010223 ASSERT_VK_SUCCESS(err);
10224
Tony Barbour415497c2017-01-24 10:06:09 -070010225 // Now get resources / view for storage_texel_buffer
10226 vkGetBufferMemoryRequirements(m_device->device(), storage_texel_buffer, &mem_reqs);
10227 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc_info, 0);
10228 if (!pass) {
10229 vkDestroyBuffer(m_device->device(), buffer, NULL);
10230 vkDestroyBufferView(m_device->device(), buff_view, NULL);
10231 vkFreeMemory(m_device->device(), mem, NULL);
10232 vkDestroyBuffer(m_device->device(), storage_texel_buffer, NULL);
10233 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10234 return;
10235 }
10236 VkDeviceMemory storage_texel_buffer_mem;
10237 VkBufferView storage_texel_buffer_view;
10238 err = vkAllocateMemory(m_device->device(), &mem_alloc_info, NULL, &storage_texel_buffer_mem);
10239 ASSERT_VK_SUCCESS(err);
10240 err = vkBindBufferMemory(m_device->device(), storage_texel_buffer, storage_texel_buffer_mem, 0);
10241 ASSERT_VK_SUCCESS(err);
10242 buff_view_ci.buffer = storage_texel_buffer;
10243 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &storage_texel_buffer_view);
10244 ASSERT_VK_SUCCESS(err);
10245
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010246 // Create an image to be used for invalid updates
Tony Barbour4b4a4222017-01-24 11:46:34 -070010247 // Find a format / tiling for COLOR_ATTACHMENT
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010248 VkImageCreateInfo image_ci = {};
Tony Barbour4b4a4222017-01-24 11:46:34 -070010249 image_ci.format = VK_FORMAT_UNDEFINED;
10250 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
10251 VkFormat format = static_cast<VkFormat>(f);
10252 VkFormatProperties fProps = m_device->format_properties(format);
10253 if (fProps.linearTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) {
10254 image_ci.format = format;
10255 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
10256 break;
10257 } else if (fProps.optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) {
10258 image_ci.format = format;
10259 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
10260 break;
10261 }
10262 }
10263 if (image_ci.format == VK_FORMAT_UNDEFINED) {
10264 return;
10265 }
10266
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010267 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10268 image_ci.imageType = VK_IMAGE_TYPE_2D;
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010269 image_ci.extent.width = 64;
10270 image_ci.extent.height = 64;
10271 image_ci.extent.depth = 1;
10272 image_ci.mipLevels = 1;
10273 image_ci.arrayLayers = 1;
10274 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010275 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
Tony Barbour4b4a4222017-01-24 11:46:34 -070010276 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010277 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
10278 VkImage image;
10279 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
10280 ASSERT_VK_SUCCESS(err);
10281 // Bind memory to image
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010282 VkDeviceMemory image_mem;
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -070010283
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010284 VkMemoryAllocateInfo mem_alloc = {};
10285 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10286 mem_alloc.pNext = NULL;
10287 mem_alloc.allocationSize = 0;
10288 mem_alloc.memoryTypeIndex = 0;
10289 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
10290 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010291 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010292 ASSERT_TRUE(pass);
10293 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
10294 ASSERT_VK_SUCCESS(err);
10295 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
10296 ASSERT_VK_SUCCESS(err);
10297 // Now create view for image
10298 VkImageViewCreateInfo image_view_ci = {};
10299 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
10300 image_view_ci.image = image;
Tony Barbour4b4a4222017-01-24 11:46:34 -070010301 image_view_ci.format = image_ci.format;
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010302 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
10303 image_view_ci.subresourceRange.layerCount = 1;
10304 image_view_ci.subresourceRange.baseArrayLayer = 0;
10305 image_view_ci.subresourceRange.levelCount = 1;
10306 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10307 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010308 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010309 ASSERT_VK_SUCCESS(err);
10310
10311 VkDescriptorBufferInfo buff_info = {};
10312 buff_info.buffer = buffer;
10313 VkDescriptorImageInfo img_info = {};
10314 img_info.imageView = image_view;
10315 VkWriteDescriptorSet descriptor_write = {};
10316 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10317 descriptor_write.dstBinding = 0;
10318 descriptor_write.descriptorCount = 1;
10319 descriptor_write.pTexelBufferView = &buff_view;
10320 descriptor_write.pBufferInfo = &buff_info;
10321 descriptor_write.pImageInfo = &img_info;
10322
10323 // These error messages align with VkDescriptorType struct
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -070010324 UNIQUE_VALIDATION_ERROR_CODE error_codes[] = {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010325 VALIDATION_ERROR_00943, // placeholder, no error for SAMPLER descriptor
10326 VALIDATION_ERROR_00943, // COMBINED_IMAGE_SAMPLER
10327 VALIDATION_ERROR_00943, // SAMPLED_IMAGE
10328 VALIDATION_ERROR_00943, // STORAGE_IMAGE
10329 VALIDATION_ERROR_00950, // UNIFORM_TEXEL_BUFFER
10330 VALIDATION_ERROR_00951, // STORAGE_TEXEL_BUFFER
10331 VALIDATION_ERROR_00946, // UNIFORM_BUFFER
10332 VALIDATION_ERROR_00947, // STORAGE_BUFFER
10333 VALIDATION_ERROR_00946, // UNIFORM_BUFFER_DYNAMIC
10334 VALIDATION_ERROR_00947, // STORAGE_BUFFER_DYNAMIC
10335 VALIDATION_ERROR_00943 // INPUT_ATTACHMENT
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -070010336 };
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010337 // Start loop at 1 as SAMPLER desc type has no usage bit error
10338 for (uint32_t i = 1; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
Tony Barbour415497c2017-01-24 10:06:09 -070010339 if (VkDescriptorType(i) == VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER) {
10340 // Now check for UNIFORM_TEXEL_BUFFER using storage_texel_buffer_view
10341 descriptor_write.pTexelBufferView = &storage_texel_buffer_view;
10342 }
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010343 descriptor_write.descriptorType = VkDescriptorType(i);
10344 descriptor_write.dstSet = descriptor_sets[i];
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -070010345 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_codes[i]);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010346
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010347 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010348
10349 m_errorMonitor->VerifyFound();
10350 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[i], NULL);
Tony Barbour415497c2017-01-24 10:06:09 -070010351 if (VkDescriptorType(i) == VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER) {
10352 descriptor_write.pTexelBufferView = &buff_view;
10353 }
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010354 }
Tony Barbour415497c2017-01-24 10:06:09 -070010355
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010356 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[0], NULL);
10357 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -060010358 vkFreeMemory(m_device->device(), image_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010359 vkDestroyImageView(m_device->device(), image_view, NULL);
10360 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tony Barbour415497c2017-01-24 10:06:09 -070010361 vkDestroyBuffer(m_device->device(), storage_texel_buffer, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010362 vkDestroyBufferView(m_device->device(), buff_view, NULL);
Tony Barbour415497c2017-01-24 10:06:09 -070010363 vkDestroyBufferView(m_device->device(), storage_texel_buffer_view, NULL);
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -070010364 vkFreeMemory(m_device->device(), mem, NULL);
Tony Barbour415497c2017-01-24 10:06:09 -070010365 vkFreeMemory(m_device->device(), storage_texel_buffer_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010366 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10367}
10368
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010369TEST_F(VkLayerTest, DSBufferInfoErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010370 TEST_DESCRIPTION(
10371 "Attempt to update buffer descriptor set that has incorrect "
10372 "parameters in VkDescriptorBufferInfo struct. This includes:\n"
Jeremy Hayesd1a6a822017-03-09 14:39:45 -070010373 "1. offset value greater than or equal to buffer size\n"
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010374 "2. range value of 0\n"
10375 "3. range value greater than buffer (size - offset)");
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010376 VkResult err;
10377
Tony Barbour1fa09702017-03-16 12:09:08 -060010378 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010379 VkDescriptorPoolSize ds_type_count = {};
10380 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10381 ds_type_count.descriptorCount = 1;
10382
10383 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10384 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10385 ds_pool_ci.pNext = NULL;
Jeremy Hayesd1a6a822017-03-09 14:39:45 -070010386 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010387 ds_pool_ci.maxSets = 1;
10388 ds_pool_ci.poolSizeCount = 1;
10389 ds_pool_ci.pPoolSizes = &ds_type_count;
10390
10391 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010392 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010393 ASSERT_VK_SUCCESS(err);
10394
10395 // Create layout with single uniform buffer descriptor
10396 VkDescriptorSetLayoutBinding dsl_binding = {};
10397 dsl_binding.binding = 0;
10398 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10399 dsl_binding.descriptorCount = 1;
10400 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10401 dsl_binding.pImmutableSamplers = NULL;
10402
10403 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10404 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10405 ds_layout_ci.pNext = NULL;
10406 ds_layout_ci.bindingCount = 1;
10407 ds_layout_ci.pBindings = &dsl_binding;
10408 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010409 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010410 ASSERT_VK_SUCCESS(err);
10411
10412 VkDescriptorSet descriptor_set = {};
10413 VkDescriptorSetAllocateInfo alloc_info = {};
10414 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10415 alloc_info.descriptorSetCount = 1;
10416 alloc_info.descriptorPool = ds_pool;
10417 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010418 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010419 ASSERT_VK_SUCCESS(err);
10420
10421 // Create a buffer to be used for invalid updates
10422 VkBufferCreateInfo buff_ci = {};
10423 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
10424 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
Jeremy Hayesd1a6a822017-03-09 14:39:45 -070010425 buff_ci.size = m_device->props.limits.minUniformBufferOffsetAlignment;
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010426 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
10427 VkBuffer buffer;
10428 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
10429 ASSERT_VK_SUCCESS(err);
Jeremy Hayesd1a6a822017-03-09 14:39:45 -070010430
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010431 // Have to bind memory to buffer before descriptor update
10432 VkMemoryAllocateInfo mem_alloc = {};
10433 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10434 mem_alloc.pNext = NULL;
Jeremy Hayesd1a6a822017-03-09 14:39:45 -070010435 mem_alloc.allocationSize = buff_ci.size;
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010436 mem_alloc.memoryTypeIndex = 0;
10437
10438 VkMemoryRequirements mem_reqs;
10439 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010440 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010441 if (!pass) {
10442 vkDestroyBuffer(m_device->device(), buffer, NULL);
10443 return;
10444 }
10445
10446 VkDeviceMemory mem;
10447 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
10448 ASSERT_VK_SUCCESS(err);
10449 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
10450 ASSERT_VK_SUCCESS(err);
10451
10452 VkDescriptorBufferInfo buff_info = {};
10453 buff_info.buffer = buffer;
Jeremy Hayesd1a6a822017-03-09 14:39:45 -070010454 // Cause error due to offset out of range
10455 buff_info.offset = buff_ci.size;
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010456 buff_info.range = VK_WHOLE_SIZE;
10457 VkWriteDescriptorSet descriptor_write = {};
10458 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10459 descriptor_write.dstBinding = 0;
10460 descriptor_write.descriptorCount = 1;
10461 descriptor_write.pTexelBufferView = nullptr;
10462 descriptor_write.pBufferInfo = &buff_info;
10463 descriptor_write.pImageInfo = nullptr;
10464
10465 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10466 descriptor_write.dstSet = descriptor_set;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070010467 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00959);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010468
10469 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10470
10471 m_errorMonitor->VerifyFound();
10472 // Now cause error due to range of 0
10473 buff_info.offset = 0;
10474 buff_info.range = 0;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070010475 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00960);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010476
10477 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10478
10479 m_errorMonitor->VerifyFound();
10480 // Now cause error due to range exceeding buffer size - offset
Jeremy Hayesd1a6a822017-03-09 14:39:45 -070010481 buff_info.offset = 0;
10482 buff_info.range = buff_ci.size + 1;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070010483 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00961);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010484
10485 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10486
10487 m_errorMonitor->VerifyFound();
Mark Lobodzinski4bb54092016-07-06 14:27:19 -060010488 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010489 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10490 vkDestroyBuffer(m_device->device(), buffer, NULL);
10491 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
10492 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10493}
10494
Tobin Ehlis845887e2017-02-02 19:01:44 -070010495TEST_F(VkLayerTest, DSBufferLimitErrors) {
10496 TEST_DESCRIPTION(
10497 "Attempt to update buffer descriptor set that has VkDescriptorBufferInfo values that violate device limits.\n"
10498 "Test cases include:\n"
10499 "1. range of uniform buffer update exceeds maxUniformBufferRange\n"
10500 "2. offset of uniform buffer update is not multiple of minUniformBufferOffsetAlignment\n"
10501 "3. range of storage buffer update exceeds maxStorageBufferRange\n"
10502 "4. offset of storage buffer update is not multiple of minStorageBufferOffsetAlignment");
10503 VkResult err;
10504
Tony Barbour1fa09702017-03-16 12:09:08 -060010505 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis845887e2017-02-02 19:01:44 -070010506 VkDescriptorPoolSize ds_type_count[2] = {};
10507 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10508 ds_type_count[0].descriptorCount = 1;
10509 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
10510 ds_type_count[1].descriptorCount = 1;
10511
10512 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10513 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10514 ds_pool_ci.pNext = NULL;
10515 ds_pool_ci.maxSets = 1;
10516 ds_pool_ci.poolSizeCount = 2;
10517 ds_pool_ci.pPoolSizes = ds_type_count;
10518
10519 VkDescriptorPool ds_pool;
10520 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
10521 ASSERT_VK_SUCCESS(err);
10522
10523 // Create layout with single uniform buffer & single storage buffer descriptor
10524 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
10525 dsl_binding[0].binding = 0;
10526 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10527 dsl_binding[0].descriptorCount = 1;
10528 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
10529 dsl_binding[0].pImmutableSamplers = NULL;
10530 dsl_binding[1].binding = 1;
10531 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
10532 dsl_binding[1].descriptorCount = 1;
10533 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
10534 dsl_binding[1].pImmutableSamplers = NULL;
10535
10536 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10537 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10538 ds_layout_ci.pNext = NULL;
10539 ds_layout_ci.bindingCount = 2;
10540 ds_layout_ci.pBindings = dsl_binding;
10541 VkDescriptorSetLayout ds_layout;
10542 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
10543 ASSERT_VK_SUCCESS(err);
10544
10545 VkDescriptorSet descriptor_set = {};
10546 VkDescriptorSetAllocateInfo alloc_info = {};
10547 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10548 alloc_info.descriptorSetCount = 1;
10549 alloc_info.descriptorPool = ds_pool;
10550 alloc_info.pSetLayouts = &ds_layout;
10551 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
10552 ASSERT_VK_SUCCESS(err);
10553
10554 // Create a buffer to be used for invalid updates
10555 auto max_ub_range = m_device->props.limits.maxUniformBufferRange;
10556 auto min_ub_align = m_device->props.limits.minUniformBufferOffsetAlignment;
10557 auto max_sb_range = m_device->props.limits.maxStorageBufferRange;
10558 auto min_sb_align = m_device->props.limits.minStorageBufferOffsetAlignment;
10559 VkBufferCreateInfo ub_ci = {};
10560 ub_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
10561 ub_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
10562 ub_ci.size = max_ub_range + 128; // Make buffer bigger than range limit
10563 ub_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
10564 VkBuffer uniform_buffer;
10565 err = vkCreateBuffer(m_device->device(), &ub_ci, NULL, &uniform_buffer);
10566 ASSERT_VK_SUCCESS(err);
10567 VkBufferCreateInfo sb_ci = {};
10568 sb_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
10569 sb_ci.usage = VK_BUFFER_USAGE_STORAGE_BUFFER_BIT;
10570 sb_ci.size = max_sb_range + 128; // Make buffer bigger than range limit
10571 sb_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
10572 VkBuffer storage_buffer;
10573 err = vkCreateBuffer(m_device->device(), &sb_ci, NULL, &storage_buffer);
10574 ASSERT_VK_SUCCESS(err);
10575 // Have to bind memory to buffer before descriptor update
10576 VkMemoryAllocateInfo mem_alloc = {};
10577 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10578 mem_alloc.pNext = NULL;
10579 mem_alloc.allocationSize = ub_ci.size + sb_ci.size + 1024; // additional buffer for offset
10580 mem_alloc.memoryTypeIndex = 0;
10581
Cort Stratton77a0d592017-02-17 13:14:13 -080010582 VkMemoryRequirements ub_mem_reqs, sb_mem_reqs;
10583 vkGetBufferMemoryRequirements(m_device->device(), uniform_buffer, &ub_mem_reqs);
10584 bool pass = m_device->phy().set_memory_type(ub_mem_reqs.memoryTypeBits, &mem_alloc, 0);
10585 vkGetBufferMemoryRequirements(m_device->device(), storage_buffer, &sb_mem_reqs);
10586 pass &= m_device->phy().set_memory_type(sb_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis845887e2017-02-02 19:01:44 -070010587 if (!pass) {
Tobin Ehlis15c83792017-02-07 10:09:33 -070010588 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Tobin Ehlis845887e2017-02-02 19:01:44 -070010589 vkDestroyBuffer(m_device->device(), uniform_buffer, NULL);
Tobin Ehlis15c83792017-02-07 10:09:33 -070010590 vkDestroyBuffer(m_device->device(), storage_buffer, NULL);
10591 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis845887e2017-02-02 19:01:44 -070010592 return;
10593 }
10594
10595 VkDeviceMemory mem;
10596 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlis15c83792017-02-07 10:09:33 -070010597 if (VK_SUCCESS != err) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070010598 printf(" Failed to allocate memory in DSBufferLimitErrors; skipped.\n");
Tobin Ehlis15c83792017-02-07 10:09:33 -070010599 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10600 vkDestroyBuffer(m_device->device(), uniform_buffer, NULL);
10601 vkDestroyBuffer(m_device->device(), storage_buffer, NULL);
10602 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10603 return;
10604 }
Tobin Ehlis845887e2017-02-02 19:01:44 -070010605 ASSERT_VK_SUCCESS(err);
10606 err = vkBindBufferMemory(m_device->device(), uniform_buffer, mem, 0);
10607 ASSERT_VK_SUCCESS(err);
Cort Stratton77a0d592017-02-17 13:14:13 -080010608 auto sb_offset = (ub_ci.size + sb_mem_reqs.alignment - 1) & ~(sb_mem_reqs.alignment - 1);
Tobin Ehlis845887e2017-02-02 19:01:44 -070010609 err = vkBindBufferMemory(m_device->device(), storage_buffer, mem, sb_offset);
10610 ASSERT_VK_SUCCESS(err);
10611
10612 VkDescriptorBufferInfo buff_info = {};
10613 buff_info.buffer = uniform_buffer;
10614 buff_info.range = ub_ci.size; // This will exceed limit
10615 VkWriteDescriptorSet descriptor_write = {};
10616 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10617 descriptor_write.dstBinding = 0;
10618 descriptor_write.descriptorCount = 1;
10619 descriptor_write.pTexelBufferView = nullptr;
10620 descriptor_write.pBufferInfo = &buff_info;
10621 descriptor_write.pImageInfo = nullptr;
10622
10623 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10624 descriptor_write.dstSet = descriptor_set;
Tony Barbour02d08552017-03-24 16:36:01 -060010625 if (max_ub_range != UINT32_MAX) {
10626 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00948);
10627 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10628 m_errorMonitor->VerifyFound();
10629 }
Tobin Ehlis845887e2017-02-02 19:01:44 -070010630 // Reduce size of range to acceptable limit & cause offset error
10631 buff_info.range = max_ub_range;
10632 buff_info.offset = min_ub_align - 1;
10633 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00944);
10634 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10635 m_errorMonitor->VerifyFound();
10636
10637 // Now break storage updates
10638 buff_info.buffer = storage_buffer;
10639 buff_info.range = sb_ci.size; // This will exceed limit
10640 buff_info.offset = 0; // Reset offset for this update
10641
10642 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
10643 descriptor_write.dstBinding = 1;
Tony Barbour02d08552017-03-24 16:36:01 -060010644 if (max_ub_range != UINT32_MAX) {
10645 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00949);
10646 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10647 m_errorMonitor->VerifyFound();
10648 }
Tobin Ehlis845887e2017-02-02 19:01:44 -070010649
10650 // Reduce size of range to acceptable limit & cause offset error
10651 buff_info.range = max_sb_range;
10652 buff_info.offset = min_sb_align - 1;
10653 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00945);
10654 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10655 m_errorMonitor->VerifyFound();
10656
10657 vkFreeMemory(m_device->device(), mem, NULL);
10658 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10659 vkDestroyBuffer(m_device->device(), uniform_buffer, NULL);
10660 vkDestroyBuffer(m_device->device(), storage_buffer, NULL);
10661 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10662}
10663
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010664TEST_F(VkLayerTest, DSAspectBitsErrors) {
10665 // TODO : Initially only catching case where DEPTH & STENCIL aspect bits
10666 // are set, but could expand this test to hit more cases.
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010667 TEST_DESCRIPTION(
10668 "Attempt to update descriptor sets for images "
10669 "that do not have correct aspect bits sets.");
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010670 VkResult err;
10671
Tony Barbour1fa09702017-03-16 12:09:08 -060010672 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -060010673 auto depth_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbourf887b162017-03-09 10:06:46 -070010674 if (!depth_format) {
10675 printf(" No Depth + Stencil format found. Skipped.\n");
10676 return;
10677 }
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010678 VkDescriptorPoolSize ds_type_count = {};
10679 ds_type_count.type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
10680 ds_type_count.descriptorCount = 1;
10681
10682 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10683 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10684 ds_pool_ci.pNext = NULL;
Jeremy Hayes293c7ed2017-03-09 14:47:07 -070010685 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010686 ds_pool_ci.maxSets = 5;
10687 ds_pool_ci.poolSizeCount = 1;
10688 ds_pool_ci.pPoolSizes = &ds_type_count;
10689
10690 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010691 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010692 ASSERT_VK_SUCCESS(err);
10693
10694 VkDescriptorSetLayoutBinding dsl_binding = {};
10695 dsl_binding.binding = 0;
10696 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
10697 dsl_binding.descriptorCount = 1;
10698 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10699 dsl_binding.pImmutableSamplers = NULL;
10700
10701 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10702 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10703 ds_layout_ci.pNext = NULL;
10704 ds_layout_ci.bindingCount = 1;
10705 ds_layout_ci.pBindings = &dsl_binding;
10706 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010707 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010708 ASSERT_VK_SUCCESS(err);
10709
10710 VkDescriptorSet descriptor_set = {};
10711 VkDescriptorSetAllocateInfo alloc_info = {};
10712 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10713 alloc_info.descriptorSetCount = 1;
10714 alloc_info.descriptorPool = ds_pool;
10715 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010716 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010717 ASSERT_VK_SUCCESS(err);
10718
10719 // Create an image to be used for invalid updates
10720 VkImageCreateInfo image_ci = {};
10721 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10722 image_ci.imageType = VK_IMAGE_TYPE_2D;
Tony Barbourf887b162017-03-09 10:06:46 -070010723 image_ci.format = depth_format;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010724 image_ci.extent.width = 64;
10725 image_ci.extent.height = 64;
10726 image_ci.extent.depth = 1;
10727 image_ci.mipLevels = 1;
10728 image_ci.arrayLayers = 1;
10729 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Young2d1fa302017-03-02 10:13:09 -070010730 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010731 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
10732 image_ci.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
10733 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
10734 VkImage image;
10735 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
10736 ASSERT_VK_SUCCESS(err);
10737 // Bind memory to image
10738 VkMemoryRequirements mem_reqs;
10739 VkDeviceMemory image_mem;
10740 bool pass;
10741 VkMemoryAllocateInfo mem_alloc = {};
10742 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10743 mem_alloc.pNext = NULL;
10744 mem_alloc.allocationSize = 0;
10745 mem_alloc.memoryTypeIndex = 0;
10746 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
10747 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010748 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010749 ASSERT_TRUE(pass);
10750 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
10751 ASSERT_VK_SUCCESS(err);
10752 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
10753 ASSERT_VK_SUCCESS(err);
10754 // Now create view for image
10755 VkImageViewCreateInfo image_view_ci = {};
10756 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
10757 image_view_ci.image = image;
Tony Barbourf887b162017-03-09 10:06:46 -070010758 image_view_ci.format = depth_format;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010759 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
10760 image_view_ci.subresourceRange.layerCount = 1;
10761 image_view_ci.subresourceRange.baseArrayLayer = 0;
10762 image_view_ci.subresourceRange.levelCount = 1;
10763 // Setting both depth & stencil aspect bits is illegal for descriptor
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010764 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010765
10766 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010767 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010768 ASSERT_VK_SUCCESS(err);
10769
10770 VkDescriptorImageInfo img_info = {};
10771 img_info.imageView = image_view;
10772 VkWriteDescriptorSet descriptor_write = {};
10773 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10774 descriptor_write.dstBinding = 0;
10775 descriptor_write.descriptorCount = 1;
10776 descriptor_write.pTexelBufferView = NULL;
10777 descriptor_write.pBufferInfo = NULL;
10778 descriptor_write.pImageInfo = &img_info;
10779 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
10780 descriptor_write.dstSet = descriptor_set;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010781 const char *error_msg =
10782 " please only set either VK_IMAGE_ASPECT_DEPTH_BIT "
10783 "or VK_IMAGE_ASPECT_STENCIL_BIT ";
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010784 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msg);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010785
10786 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10787
10788 m_errorMonitor->VerifyFound();
10789 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10790 vkDestroyImage(m_device->device(), image, NULL);
10791 vkFreeMemory(m_device->device(), image_mem, NULL);
10792 vkDestroyImageView(m_device->device(), image_view, NULL);
10793 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
10794 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10795}
10796
Karl Schultz6addd812016-02-02 17:17:23 -070010797TEST_F(VkLayerTest, DSTypeMismatch) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010798 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Karl Schultz6addd812016-02-02 17:17:23 -070010799 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010800
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010801 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10802 " binding #0 with type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER but update "
10803 "type is VK_DESCRIPTOR_TYPE_SAMPLER");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010804
Tony Barbour1fa09702017-03-16 12:09:08 -060010805 ASSERT_NO_FATAL_FAILURE(Init());
Karl Schultz6addd812016-02-02 17:17:23 -070010806 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010807 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010808 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10809 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010810
10811 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010812 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10813 ds_pool_ci.pNext = NULL;
10814 ds_pool_ci.maxSets = 1;
10815 ds_pool_ci.poolSizeCount = 1;
10816 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060010817
Tobin Ehlis3b780662015-05-28 12:11:26 -060010818 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010819 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010820 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -060010821 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010822 dsl_binding.binding = 0;
10823 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10824 dsl_binding.descriptorCount = 1;
10825 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10826 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010827
Tony Barboureb254902015-07-15 12:50:33 -060010828 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010829 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10830 ds_layout_ci.pNext = NULL;
10831 ds_layout_ci.bindingCount = 1;
10832 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010833
Tobin Ehlis3b780662015-05-28 12:11:26 -060010834 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010835 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010836 ASSERT_VK_SUCCESS(err);
10837
10838 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010839 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010840 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010841 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010842 alloc_info.descriptorPool = ds_pool;
10843 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010844 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010845 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010846
Tobin Ehlis30db8f82016-05-05 08:19:48 -060010847 VkSamplerCreateInfo sampler_ci = {};
10848 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10849 sampler_ci.pNext = NULL;
10850 sampler_ci.magFilter = VK_FILTER_NEAREST;
10851 sampler_ci.minFilter = VK_FILTER_NEAREST;
10852 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10853 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10854 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10855 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10856 sampler_ci.mipLodBias = 1.0;
10857 sampler_ci.anisotropyEnable = VK_FALSE;
10858 sampler_ci.maxAnisotropy = 1;
10859 sampler_ci.compareEnable = VK_FALSE;
10860 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10861 sampler_ci.minLod = 1.0;
10862 sampler_ci.maxLod = 1.0;
10863 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10864 sampler_ci.unnormalizedCoordinates = VK_FALSE;
10865 VkSampler sampler;
10866 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
10867 ASSERT_VK_SUCCESS(err);
10868
10869 VkDescriptorImageInfo info = {};
10870 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010871
10872 VkWriteDescriptorSet descriptor_write;
10873 memset(&descriptor_write, 0, sizeof(descriptor_write));
10874 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010875 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010876 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010877 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010878 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060010879 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010880
10881 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10882
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010883 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010884
Chia-I Wuf7458c52015-10-26 21:10:41 +080010885 vkDestroySampler(m_device->device(), sampler, NULL);
10886 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10887 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010888}
10889
Karl Schultz6addd812016-02-02 17:17:23 -070010890TEST_F(VkLayerTest, DSUpdateOutOfBounds) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010891 // For overlapping Update, have arrayIndex exceed that of layout
Karl Schultz6addd812016-02-02 17:17:23 -070010892 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010893
Tobin Ehlisf922ef82016-11-30 10:19:14 -070010894 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00938);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010895
Tony Barbour1fa09702017-03-16 12:09:08 -060010896 ASSERT_NO_FATAL_FAILURE(Init());
Karl Schultz6addd812016-02-02 17:17:23 -070010897 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010898 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010899 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10900 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010901
10902 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010903 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10904 ds_pool_ci.pNext = NULL;
10905 ds_pool_ci.maxSets = 1;
10906 ds_pool_ci.poolSizeCount = 1;
10907 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060010908
Tobin Ehlis3b780662015-05-28 12:11:26 -060010909 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010910 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010911 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010912
Tony Barboureb254902015-07-15 12:50:33 -060010913 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010914 dsl_binding.binding = 0;
10915 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10916 dsl_binding.descriptorCount = 1;
10917 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10918 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -060010919
10920 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010921 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10922 ds_layout_ci.pNext = NULL;
10923 ds_layout_ci.bindingCount = 1;
10924 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010925
Tobin Ehlis3b780662015-05-28 12:11:26 -060010926 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010927 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010928 ASSERT_VK_SUCCESS(err);
10929
10930 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010931 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010932 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010933 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010934 alloc_info.descriptorPool = ds_pool;
10935 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010936 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010937 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010938
Jeremy Hayesd5b95db2017-03-09 15:24:24 -070010939 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
10940
Tobin Ehlis30db8f82016-05-05 08:19:48 -060010941 // Correctly update descriptor to avoid "NOT_UPDATED" error
10942 VkDescriptorBufferInfo buff_info = {};
Jeremy Hayesd5b95db2017-03-09 15:24:24 -070010943 buff_info.buffer = buffer_test.GetBuffer();
Tobin Ehlis30db8f82016-05-05 08:19:48 -060010944 buff_info.offset = 0;
10945 buff_info.range = 1024;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010946
10947 VkWriteDescriptorSet descriptor_write;
10948 memset(&descriptor_write, 0, sizeof(descriptor_write));
10949 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010950 descriptor_write.dstSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010951 descriptor_write.dstArrayElement = 1; /* This index out of bounds for the update */
Chia-I Wud50a7d72015-10-26 20:48:51 +080010952 descriptor_write.descriptorCount = 1;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -060010953 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10954 descriptor_write.pBufferInfo = &buff_info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010955
10956 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10957
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010958 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010959
Chia-I Wuf7458c52015-10-26 21:10:41 +080010960 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10961 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010962}
10963
Karl Schultz6addd812016-02-02 17:17:23 -070010964TEST_F(VkLayerTest, InvalidDSUpdateIndex) {
Tobin Ehlisc8d352d2016-11-21 10:33:40 -070010965 // Create layout w/ count of 1 and attempt update to that layout w/ binding index 2
Karl Schultz6addd812016-02-02 17:17:23 -070010966 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010967
Tobin Ehlisc8d352d2016-11-21 10:33:40 -070010968 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00936);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010969
Tony Barbour1fa09702017-03-16 12:09:08 -060010970 ASSERT_NO_FATAL_FAILURE(Init());
Karl Schultz6addd812016-02-02 17:17:23 -070010971 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010972 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010973 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10974 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010975
10976 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010977 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10978 ds_pool_ci.pNext = NULL;
10979 ds_pool_ci.maxSets = 1;
10980 ds_pool_ci.poolSizeCount = 1;
10981 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060010982
Tobin Ehlis3b780662015-05-28 12:11:26 -060010983 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010984 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010985 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010986
Tony Barboureb254902015-07-15 12:50:33 -060010987 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010988 dsl_binding.binding = 0;
10989 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10990 dsl_binding.descriptorCount = 1;
10991 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10992 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -060010993
10994 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010995 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10996 ds_layout_ci.pNext = NULL;
10997 ds_layout_ci.bindingCount = 1;
10998 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010999 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011000 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011001 ASSERT_VK_SUCCESS(err);
11002
11003 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011004 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011005 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011006 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011007 alloc_info.descriptorPool = ds_pool;
11008 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011009 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011010 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011011
Tony Barboureb254902015-07-15 12:50:33 -060011012 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011013 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11014 sampler_ci.pNext = NULL;
11015 sampler_ci.magFilter = VK_FILTER_NEAREST;
11016 sampler_ci.minFilter = VK_FILTER_NEAREST;
11017 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11018 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11019 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11020 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11021 sampler_ci.mipLodBias = 1.0;
11022 sampler_ci.anisotropyEnable = VK_FALSE;
11023 sampler_ci.maxAnisotropy = 1;
11024 sampler_ci.compareEnable = VK_FALSE;
11025 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11026 sampler_ci.minLod = 1.0;
11027 sampler_ci.maxLod = 1.0;
11028 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11029 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -060011030
Tobin Ehlis3b780662015-05-28 12:11:26 -060011031 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011032 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011033 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011034
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060011035 VkDescriptorImageInfo info = {};
11036 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011037
11038 VkWriteDescriptorSet descriptor_write;
11039 memset(&descriptor_write, 0, sizeof(descriptor_write));
11040 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011041 descriptor_write.dstSet = descriptorSet;
11042 descriptor_write.dstBinding = 2;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011043 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011044 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011045 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060011046 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011047
11048 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11049
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011050 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011051
Chia-I Wuf7458c52015-10-26 21:10:41 +080011052 vkDestroySampler(m_device->device(), sampler, NULL);
11053 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11054 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060011055}
11056
Tobin Ehlise202b2d2016-11-21 10:36:16 -070011057TEST_F(VkLayerTest, DSUpdateEmptyBinding) {
11058 // Create layout w/ empty binding and attempt to update it
11059 VkResult err;
11060
Tony Barbour1fa09702017-03-16 12:09:08 -060011061 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlise202b2d2016-11-21 10:36:16 -070011062
11063 VkDescriptorPoolSize ds_type_count = {};
11064 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
11065 ds_type_count.descriptorCount = 1;
11066
11067 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11068 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11069 ds_pool_ci.pNext = NULL;
11070 ds_pool_ci.maxSets = 1;
11071 ds_pool_ci.poolSizeCount = 1;
11072 ds_pool_ci.pPoolSizes = &ds_type_count;
11073
11074 VkDescriptorPool ds_pool;
11075 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
11076 ASSERT_VK_SUCCESS(err);
11077
11078 VkDescriptorSetLayoutBinding dsl_binding = {};
11079 dsl_binding.binding = 0;
11080 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
11081 dsl_binding.descriptorCount = 0;
11082 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11083 dsl_binding.pImmutableSamplers = NULL;
11084
11085 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11086 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11087 ds_layout_ci.pNext = NULL;
11088 ds_layout_ci.bindingCount = 1;
11089 ds_layout_ci.pBindings = &dsl_binding;
11090 VkDescriptorSetLayout ds_layout;
11091 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
11092 ASSERT_VK_SUCCESS(err);
11093
11094 VkDescriptorSet descriptor_set;
11095 VkDescriptorSetAllocateInfo alloc_info = {};
11096 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11097 alloc_info.descriptorSetCount = 1;
11098 alloc_info.descriptorPool = ds_pool;
11099 alloc_info.pSetLayouts = &ds_layout;
11100 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
11101 ASSERT_VK_SUCCESS(err);
11102
11103 VkSamplerCreateInfo sampler_ci = {};
11104 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11105 sampler_ci.magFilter = VK_FILTER_NEAREST;
11106 sampler_ci.minFilter = VK_FILTER_NEAREST;
11107 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11108 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11109 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11110 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11111 sampler_ci.mipLodBias = 1.0;
11112 sampler_ci.maxAnisotropy = 1;
11113 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11114 sampler_ci.minLod = 1.0;
11115 sampler_ci.maxLod = 1.0;
11116 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11117
11118 VkSampler sampler;
11119 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
11120 ASSERT_VK_SUCCESS(err);
11121
11122 VkDescriptorImageInfo info = {};
11123 info.sampler = sampler;
11124
11125 VkWriteDescriptorSet descriptor_write;
11126 memset(&descriptor_write, 0, sizeof(descriptor_write));
11127 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11128 descriptor_write.dstSet = descriptor_set;
11129 descriptor_write.dstBinding = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011130 descriptor_write.descriptorCount = 1; // Lie here to avoid parameter_validation error
Tobin Ehlise202b2d2016-11-21 10:36:16 -070011131 // This is the wrong type, but empty binding error will be flagged first
11132 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
11133 descriptor_write.pImageInfo = &info;
11134
11135 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02348);
11136 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11137 m_errorMonitor->VerifyFound();
11138
11139 vkDestroySampler(m_device->device(), sampler, NULL);
11140 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11141 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11142}
11143
Karl Schultz6addd812016-02-02 17:17:23 -070011144TEST_F(VkLayerTest, InvalidDSUpdateStruct) {
11145 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_*
11146 // types
11147 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011148
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011149 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 -060011150
Tony Barbour1fa09702017-03-16 12:09:08 -060011151 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011152
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011153 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011154 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11155 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011156
11157 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011158 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11159 ds_pool_ci.pNext = NULL;
11160 ds_pool_ci.maxSets = 1;
11161 ds_pool_ci.poolSizeCount = 1;
11162 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060011163
Tobin Ehlis3b780662015-05-28 12:11:26 -060011164 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011165 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011166 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -060011167 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011168 dsl_binding.binding = 0;
11169 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11170 dsl_binding.descriptorCount = 1;
11171 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11172 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011173
Tony Barboureb254902015-07-15 12:50:33 -060011174 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011175 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11176 ds_layout_ci.pNext = NULL;
11177 ds_layout_ci.bindingCount = 1;
11178 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060011179
Tobin Ehlis3b780662015-05-28 12:11:26 -060011180 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011181 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011182 ASSERT_VK_SUCCESS(err);
11183
11184 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011185 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011186 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011187 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011188 alloc_info.descriptorPool = ds_pool;
11189 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011190 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011191 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011192
Tony Barboureb254902015-07-15 12:50:33 -060011193 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011194 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11195 sampler_ci.pNext = NULL;
11196 sampler_ci.magFilter = VK_FILTER_NEAREST;
11197 sampler_ci.minFilter = VK_FILTER_NEAREST;
11198 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11199 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11200 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11201 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11202 sampler_ci.mipLodBias = 1.0;
11203 sampler_ci.anisotropyEnable = VK_FALSE;
11204 sampler_ci.maxAnisotropy = 1;
11205 sampler_ci.compareEnable = VK_FALSE;
11206 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11207 sampler_ci.minLod = 1.0;
11208 sampler_ci.maxLod = 1.0;
11209 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11210 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011211 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011212 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011213 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011214
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060011215 VkDescriptorImageInfo info = {};
11216 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011217
11218 VkWriteDescriptorSet descriptor_write;
11219 memset(&descriptor_write, 0, sizeof(descriptor_write));
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011220 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011221 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011222 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011223 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011224 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060011225 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011226
11227 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11228
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011229 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011230
Chia-I Wuf7458c52015-10-26 21:10:41 +080011231 vkDestroySampler(m_device->device(), sampler, NULL);
11232 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11233 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060011234}
11235
Karl Schultz6addd812016-02-02 17:17:23 -070011236TEST_F(VkLayerTest, SampleDescriptorUpdateError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011237 // Create a single Sampler descriptor and send it an invalid Sampler
Karl Schultz6addd812016-02-02 17:17:23 -070011238 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011239
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070011240 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00942);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011241
Tony Barbour1fa09702017-03-16 12:09:08 -060011242 ASSERT_NO_FATAL_FAILURE(Init());
Karl Schultz6addd812016-02-02 17:17:23 -070011243 // TODO : Farm Descriptor setup code to helper function(s) to reduce copied
11244 // code
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011245 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011246 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
11247 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011248
11249 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011250 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11251 ds_pool_ci.pNext = NULL;
11252 ds_pool_ci.maxSets = 1;
11253 ds_pool_ci.poolSizeCount = 1;
11254 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011255
11256 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011257 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011258 ASSERT_VK_SUCCESS(err);
11259
11260 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011261 dsl_binding.binding = 0;
11262 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
11263 dsl_binding.descriptorCount = 1;
11264 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11265 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011266
11267 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011268 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11269 ds_layout_ci.pNext = NULL;
11270 ds_layout_ci.bindingCount = 1;
11271 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011272 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011273 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011274 ASSERT_VK_SUCCESS(err);
11275
11276 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011277 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011278 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011279 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011280 alloc_info.descriptorPool = ds_pool;
11281 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011282 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011283 ASSERT_VK_SUCCESS(err);
11284
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011285 VkSampler sampler = (VkSampler)((size_t)0xbaadbeef); // Sampler with invalid handle
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011286
11287 VkDescriptorImageInfo descriptor_info;
11288 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
11289 descriptor_info.sampler = sampler;
11290
11291 VkWriteDescriptorSet descriptor_write;
11292 memset(&descriptor_write, 0, sizeof(descriptor_write));
11293 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011294 descriptor_write.dstSet = descriptorSet;
11295 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011296 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011297 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
11298 descriptor_write.pImageInfo = &descriptor_info;
11299
11300 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11301
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011302 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011303
Chia-I Wuf7458c52015-10-26 21:10:41 +080011304 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11305 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011306}
11307
Karl Schultz6addd812016-02-02 17:17:23 -070011308TEST_F(VkLayerTest, ImageViewDescriptorUpdateError) {
11309 // Create a single combined Image/Sampler descriptor and send it an invalid
11310 // imageView
11311 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011312
Karl Schultzf78bcdd2016-11-30 12:36:01 -070011313 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00943);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011314
Tony Barbour1fa09702017-03-16 12:09:08 -060011315 ASSERT_NO_FATAL_FAILURE(Init());
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011316 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011317 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11318 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011319
11320 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011321 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11322 ds_pool_ci.pNext = NULL;
11323 ds_pool_ci.maxSets = 1;
11324 ds_pool_ci.poolSizeCount = 1;
11325 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011326
11327 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011328 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011329 ASSERT_VK_SUCCESS(err);
11330
11331 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011332 dsl_binding.binding = 0;
11333 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11334 dsl_binding.descriptorCount = 1;
11335 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11336 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011337
11338 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011339 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11340 ds_layout_ci.pNext = NULL;
11341 ds_layout_ci.bindingCount = 1;
11342 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011343 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011344 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011345 ASSERT_VK_SUCCESS(err);
11346
11347 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011348 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011349 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011350 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011351 alloc_info.descriptorPool = ds_pool;
11352 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011353 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011354 ASSERT_VK_SUCCESS(err);
11355
11356 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011357 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11358 sampler_ci.pNext = NULL;
11359 sampler_ci.magFilter = VK_FILTER_NEAREST;
11360 sampler_ci.minFilter = VK_FILTER_NEAREST;
11361 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11362 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11363 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11364 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11365 sampler_ci.mipLodBias = 1.0;
11366 sampler_ci.anisotropyEnable = VK_FALSE;
11367 sampler_ci.maxAnisotropy = 1;
11368 sampler_ci.compareEnable = VK_FALSE;
11369 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11370 sampler_ci.minLod = 1.0;
11371 sampler_ci.maxLod = 1.0;
11372 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11373 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011374
11375 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011376 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011377 ASSERT_VK_SUCCESS(err);
11378
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011379 VkImageView view = (VkImageView)((size_t)0xbaadbeef); // invalid imageView object
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011380
11381 VkDescriptorImageInfo descriptor_info;
11382 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
11383 descriptor_info.sampler = sampler;
11384 descriptor_info.imageView = view;
11385
11386 VkWriteDescriptorSet descriptor_write;
11387 memset(&descriptor_write, 0, sizeof(descriptor_write));
11388 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011389 descriptor_write.dstSet = descriptorSet;
11390 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011391 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011392 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11393 descriptor_write.pImageInfo = &descriptor_info;
11394
11395 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11396
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011397 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011398
Chia-I Wuf7458c52015-10-26 21:10:41 +080011399 vkDestroySampler(m_device->device(), sampler, NULL);
11400 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11401 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011402}
11403
Karl Schultz6addd812016-02-02 17:17:23 -070011404TEST_F(VkLayerTest, CopyDescriptorUpdateErrors) {
11405 // Create DS w/ layout of 2 types, write update 1 and attempt to copy-update
11406 // into the other
11407 VkResult err;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011408
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011409 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11410 " binding #1 with type "
11411 "VK_DESCRIPTOR_TYPE_SAMPLER. Types do "
11412 "not match.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011413
Tony Barbour1fa09702017-03-16 12:09:08 -060011414 ASSERT_NO_FATAL_FAILURE(Init());
Karl Schultz6addd812016-02-02 17:17:23 -070011415 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011416 VkDescriptorPoolSize ds_type_count[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011417 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11418 ds_type_count[0].descriptorCount = 1;
11419 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
11420 ds_type_count[1].descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011421
11422 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011423 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11424 ds_pool_ci.pNext = NULL;
11425 ds_pool_ci.maxSets = 1;
11426 ds_pool_ci.poolSizeCount = 2;
11427 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011428
11429 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011430 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis04356f92015-10-27 16:35:27 -060011431 ASSERT_VK_SUCCESS(err);
11432 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011433 dsl_binding[0].binding = 0;
11434 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11435 dsl_binding[0].descriptorCount = 1;
11436 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
11437 dsl_binding[0].pImmutableSamplers = NULL;
11438 dsl_binding[1].binding = 1;
11439 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
11440 dsl_binding[1].descriptorCount = 1;
11441 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
11442 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011443
11444 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011445 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11446 ds_layout_ci.pNext = NULL;
11447 ds_layout_ci.bindingCount = 2;
11448 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011449
11450 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011451 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis04356f92015-10-27 16:35:27 -060011452 ASSERT_VK_SUCCESS(err);
11453
11454 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011455 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011456 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011457 alloc_info.descriptorSetCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011458 alloc_info.descriptorPool = ds_pool;
11459 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011460 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis04356f92015-10-27 16:35:27 -060011461 ASSERT_VK_SUCCESS(err);
11462
11463 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011464 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11465 sampler_ci.pNext = NULL;
11466 sampler_ci.magFilter = VK_FILTER_NEAREST;
11467 sampler_ci.minFilter = VK_FILTER_NEAREST;
11468 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11469 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11470 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11471 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11472 sampler_ci.mipLodBias = 1.0;
11473 sampler_ci.anisotropyEnable = VK_FALSE;
11474 sampler_ci.maxAnisotropy = 1;
11475 sampler_ci.compareEnable = VK_FALSE;
11476 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11477 sampler_ci.minLod = 1.0;
11478 sampler_ci.maxLod = 1.0;
11479 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11480 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011481
11482 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011483 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis04356f92015-10-27 16:35:27 -060011484 ASSERT_VK_SUCCESS(err);
11485
11486 VkDescriptorImageInfo info = {};
11487 info.sampler = sampler;
11488
11489 VkWriteDescriptorSet descriptor_write;
11490 memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet));
11491 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011492 descriptor_write.dstSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011493 descriptor_write.dstBinding = 1; // SAMPLER binding from layout above
Chia-I Wud50a7d72015-10-26 20:48:51 +080011494 descriptor_write.descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011495 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
11496 descriptor_write.pImageInfo = &info;
11497 // This write update should succeed
11498 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11499 // Now perform a copy update that fails due to type mismatch
11500 VkCopyDescriptorSet copy_ds_update;
11501 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
11502 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
11503 copy_ds_update.srcSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011504 copy_ds_update.srcBinding = 1; // Copy from SAMPLER binding
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011505 copy_ds_update.dstSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011506 copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding
11507 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -060011508 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
11509
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011510 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -060011511 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011512 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 -060011513 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
11514 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
11515 copy_ds_update.srcSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011516 copy_ds_update.srcBinding = 3; // ERROR : Invalid binding for matching layout
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011517 copy_ds_update.dstSet = descriptorSet;
11518 copy_ds_update.dstBinding = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011519 copy_ds_update.descriptorCount = 1; // Copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -060011520 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
11521
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011522 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011523
Tobin Ehlis04356f92015-10-27 16:35:27 -060011524 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011525 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11526 " binding#1 with offset index of 1 plus "
11527 "update array offset of 0 and update of "
11528 "5 descriptors oversteps total number "
11529 "of descriptors in set: 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011530
Tobin Ehlis04356f92015-10-27 16:35:27 -060011531 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
11532 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
11533 copy_ds_update.srcSet = descriptorSet;
11534 copy_ds_update.srcBinding = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011535 copy_ds_update.dstSet = descriptorSet;
11536 copy_ds_update.dstBinding = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011537 copy_ds_update.descriptorCount = 5; // ERROR copy 5 descriptors (out of bounds for layout)
Tobin Ehlis04356f92015-10-27 16:35:27 -060011538 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
11539
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011540 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -060011541
Chia-I Wuf7458c52015-10-26 21:10:41 +080011542 vkDestroySampler(m_device->device(), sampler, NULL);
11543 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11544 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis04356f92015-10-27 16:35:27 -060011545}
11546
Karl Schultz6addd812016-02-02 17:17:23 -070011547TEST_F(VkLayerTest, NumSamplesMismatch) {
11548 // Create CommandBuffer where MSAA samples doesn't match RenderPass
11549 // sampleCount
11550 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011551
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011552 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Num samples mismatch! ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011553
Tony Barbour1fa09702017-03-16 12:09:08 -060011554 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis3b780662015-05-28 12:11:26 -060011555 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011556 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -060011557 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011558 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011559
11560 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011561 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11562 ds_pool_ci.pNext = NULL;
11563 ds_pool_ci.maxSets = 1;
11564 ds_pool_ci.poolSizeCount = 1;
11565 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060011566
Tobin Ehlis3b780662015-05-28 12:11:26 -060011567 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011568 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011569 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011570
Tony Barboureb254902015-07-15 12:50:33 -060011571 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +080011572 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -060011573 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +080011574 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011575 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11576 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011577
Tony Barboureb254902015-07-15 12:50:33 -060011578 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11579 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11580 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011581 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -070011582 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060011583
Tobin Ehlis3b780662015-05-28 12:11:26 -060011584 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011585 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011586 ASSERT_VK_SUCCESS(err);
11587
11588 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011589 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011590 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011591 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011592 alloc_info.descriptorPool = ds_pool;
11593 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011594 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011595 ASSERT_VK_SUCCESS(err);
11596
Tony Barboureb254902015-07-15 12:50:33 -060011597 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011598 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070011599 pipe_ms_state_ci.pNext = NULL;
11600 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
11601 pipe_ms_state_ci.sampleShadingEnable = 0;
11602 pipe_ms_state_ci.minSampleShading = 1.0;
11603 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011604
Tony Barboureb254902015-07-15 12:50:33 -060011605 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011606 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11607 pipeline_layout_ci.pNext = NULL;
11608 pipeline_layout_ci.setLayoutCount = 1;
11609 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011610
11611 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011612 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011613 ASSERT_VK_SUCCESS(err);
11614
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011615 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011616 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 -060011617 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011618 VkPipelineObj pipe(m_device);
11619 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060011620 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -060011621 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011622 pipe.SetMSAA(&pipe_ms_state_ci);
11623 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis3b780662015-05-28 12:11:26 -060011624
Tony Barbour552f6c02016-12-21 14:34:07 -070011625 m_commandBuffer->BeginCommandBuffer();
11626 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011627 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis3b780662015-05-28 12:11:26 -060011628
Rene Lindsay3bdc7a42017-01-06 13:20:15 -070011629 VkViewport viewport = {0, 0, 16, 16, 0, 1};
11630 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
11631 VkRect2D scissor = {{0, 0}, {16, 16}};
11632 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
11633
Mark Young29927482016-05-04 14:38:51 -060011634 // Render triangle (the error should trigger on the attempt to draw).
11635 Draw(3, 1, 0, 0);
11636
11637 // Finalize recording of the command buffer
Tony Barbour552f6c02016-12-21 14:34:07 -070011638 m_commandBuffer->EndRenderPass();
11639 m_commandBuffer->EndCommandBuffer();
Mark Young29927482016-05-04 14:38:51 -060011640
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011641 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011642
Chia-I Wuf7458c52015-10-26 21:10:41 +080011643 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11644 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11645 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060011646}
Mark Young29927482016-05-04 14:38:51 -060011647
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011648TEST_F(VkLayerTest, RenderPassIncompatible) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011649 TEST_DESCRIPTION(
11650 "Hit RenderPass incompatible cases. "
11651 "Initial case is drawing with an active renderpass that's "
11652 "not compatible with the bound pipeline state object's creation renderpass");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011653 VkResult err;
11654
Tony Barbour1fa09702017-03-16 12:09:08 -060011655 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011656 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11657
11658 VkDescriptorSetLayoutBinding dsl_binding = {};
11659 dsl_binding.binding = 0;
11660 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11661 dsl_binding.descriptorCount = 1;
11662 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11663 dsl_binding.pImmutableSamplers = NULL;
11664
11665 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11666 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11667 ds_layout_ci.pNext = NULL;
11668 ds_layout_ci.bindingCount = 1;
11669 ds_layout_ci.pBindings = &dsl_binding;
11670
11671 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011672 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011673 ASSERT_VK_SUCCESS(err);
11674
11675 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11676 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11677 pipeline_layout_ci.pNext = NULL;
11678 pipeline_layout_ci.setLayoutCount = 1;
11679 pipeline_layout_ci.pSetLayouts = &ds_layout;
11680
11681 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011682 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011683 ASSERT_VK_SUCCESS(err);
11684
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011685 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011686 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 -060011687 // but add it to be able to run on more devices
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011688 // Create a renderpass that will be incompatible with default renderpass
11689 VkAttachmentReference attach = {};
Cort Stratton7547f772017-05-04 15:18:52 -070011690 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011691 VkAttachmentReference color_att = {};
Cort Stratton7547f772017-05-04 15:18:52 -070011692 color_att.layout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011693 VkSubpassDescription subpass = {};
11694 subpass.inputAttachmentCount = 1;
11695 subpass.pInputAttachments = &attach;
11696 subpass.colorAttachmentCount = 1;
11697 subpass.pColorAttachments = &color_att;
11698 VkRenderPassCreateInfo rpci = {};
11699 rpci.subpassCount = 1;
11700 rpci.pSubpasses = &subpass;
11701 rpci.attachmentCount = 1;
11702 VkAttachmentDescription attach_desc = {};
11703 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Cody Northropbd16af12016-06-21 09:25:48 -060011704 // Format incompatible with PSO RP color attach format B8G8R8A8_UNORM
11705 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011706 rpci.pAttachments = &attach_desc;
11707 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
11708 VkRenderPass rp;
11709 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11710 VkPipelineObj pipe(m_device);
11711 pipe.AddShader(&vs);
11712 pipe.AddShader(&fs);
11713 pipe.AddColorAttachment();
11714 VkViewport view_port = {};
11715 m_viewports.push_back(view_port);
11716 pipe.SetViewport(m_viewports);
11717 VkRect2D rect = {};
11718 m_scissors.push_back(rect);
11719 pipe.SetScissor(m_scissors);
11720 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11721
11722 VkCommandBufferInheritanceInfo cbii = {};
11723 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
11724 cbii.renderPass = rp;
11725 cbii.subpass = 0;
11726 VkCommandBufferBeginInfo cbbi = {};
11727 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
11728 cbbi.pInheritanceInfo = &cbii;
11729 vkBeginCommandBuffer(m_commandBuffer->handle(), &cbbi);
11730 VkRenderPassBeginInfo rpbi = {};
11731 rpbi.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
11732 rpbi.framebuffer = m_framebuffer;
11733 rpbi.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011734 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
11735 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011736
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011737 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is incompatible w/ gfx pipeline ");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011738 // Render triangle (the error should trigger on the attempt to draw).
11739 Draw(3, 1, 0, 0);
11740
11741 // Finalize recording of the command buffer
Tony Barbour552f6c02016-12-21 14:34:07 -070011742 m_commandBuffer->EndRenderPass();
11743 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011744
11745 m_errorMonitor->VerifyFound();
11746
11747 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11748 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11749 vkDestroyRenderPass(m_device->device(), rp, NULL);
11750}
11751
Mark Youngc89c6312016-03-31 16:03:20 -060011752TEST_F(VkLayerTest, NumBlendAttachMismatch) {
11753 // Create Pipeline where the number of blend attachments doesn't match the
11754 // number of color attachments. In this case, we don't add any color
11755 // blend attachments even though we have a color attachment.
11756 VkResult err;
11757
Tobin Ehlis974c0d92017-02-01 13:31:22 -070011758 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02109);
Mark Youngc89c6312016-03-31 16:03:20 -060011759
Tony Barbour1fa09702017-03-16 12:09:08 -060011760 ASSERT_NO_FATAL_FAILURE(Init());
Mark Youngc89c6312016-03-31 16:03:20 -060011761 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11762 VkDescriptorPoolSize ds_type_count = {};
11763 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11764 ds_type_count.descriptorCount = 1;
11765
11766 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11767 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11768 ds_pool_ci.pNext = NULL;
11769 ds_pool_ci.maxSets = 1;
11770 ds_pool_ci.poolSizeCount = 1;
11771 ds_pool_ci.pPoolSizes = &ds_type_count;
11772
11773 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011774 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Youngc89c6312016-03-31 16:03:20 -060011775 ASSERT_VK_SUCCESS(err);
11776
11777 VkDescriptorSetLayoutBinding dsl_binding = {};
11778 dsl_binding.binding = 0;
11779 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11780 dsl_binding.descriptorCount = 1;
11781 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11782 dsl_binding.pImmutableSamplers = NULL;
11783
11784 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11785 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11786 ds_layout_ci.pNext = NULL;
11787 ds_layout_ci.bindingCount = 1;
11788 ds_layout_ci.pBindings = &dsl_binding;
11789
11790 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011791 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Youngc89c6312016-03-31 16:03:20 -060011792 ASSERT_VK_SUCCESS(err);
11793
11794 VkDescriptorSet descriptorSet;
11795 VkDescriptorSetAllocateInfo alloc_info = {};
11796 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11797 alloc_info.descriptorSetCount = 1;
11798 alloc_info.descriptorPool = ds_pool;
11799 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011800 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Youngc89c6312016-03-31 16:03:20 -060011801 ASSERT_VK_SUCCESS(err);
11802
11803 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011804 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Youngc89c6312016-03-31 16:03:20 -060011805 pipe_ms_state_ci.pNext = NULL;
11806 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
11807 pipe_ms_state_ci.sampleShadingEnable = 0;
11808 pipe_ms_state_ci.minSampleShading = 1.0;
11809 pipe_ms_state_ci.pSampleMask = NULL;
11810
11811 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11812 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11813 pipeline_layout_ci.pNext = NULL;
11814 pipeline_layout_ci.setLayoutCount = 1;
11815 pipeline_layout_ci.pSetLayouts = &ds_layout;
11816
11817 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011818 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Youngc89c6312016-03-31 16:03:20 -060011819 ASSERT_VK_SUCCESS(err);
11820
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011821 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011822 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 -060011823 // but add it to be able to run on more devices
Mark Youngc89c6312016-03-31 16:03:20 -060011824 VkPipelineObj pipe(m_device);
11825 pipe.AddShader(&vs);
11826 pipe.AddShader(&fs);
11827 pipe.SetMSAA(&pipe_ms_state_ci);
11828 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011829 m_errorMonitor->VerifyFound();
Mark Youngc89c6312016-03-31 16:03:20 -060011830
11831 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11832 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11833 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11834}
Mark Young29927482016-05-04 14:38:51 -060011835
Mark Muellerd4914412016-06-13 17:52:06 -060011836TEST_F(VkLayerTest, MissingClearAttachment) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011837 TEST_DESCRIPTION(
11838 "Points to a wrong colorAttachment index in a VkClearAttachment "
11839 "structure passed to vkCmdClearAttachments");
Tony Barbour1fa09702017-03-16 12:09:08 -060011840 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070011841 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01114);
Mark Muellerd4914412016-06-13 17:52:06 -060011842
11843 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailCmdClearAttachments);
11844 m_errorMonitor->VerifyFound();
11845}
11846
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070011847TEST_F(VkLayerTest, CmdClearAttachmentTests) {
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070011848 TEST_DESCRIPTION("Various tests for validating usage of vkCmdClearAttachments");
11849 VkResult err;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011850
Tony Barbour1fa09702017-03-16 12:09:08 -060011851 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011852 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060011853
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011854 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011855 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11856 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011857
11858 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011859 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11860 ds_pool_ci.pNext = NULL;
11861 ds_pool_ci.maxSets = 1;
11862 ds_pool_ci.poolSizeCount = 1;
11863 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060011864
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011865 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011866 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011867 ASSERT_VK_SUCCESS(err);
11868
Tony Barboureb254902015-07-15 12:50:33 -060011869 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011870 dsl_binding.binding = 0;
11871 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11872 dsl_binding.descriptorCount = 1;
11873 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11874 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011875
Tony Barboureb254902015-07-15 12:50:33 -060011876 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011877 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11878 ds_layout_ci.pNext = NULL;
11879 ds_layout_ci.bindingCount = 1;
11880 ds_layout_ci.pBindings = &dsl_binding;
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011881
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011882 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011883 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011884 ASSERT_VK_SUCCESS(err);
11885
11886 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011887 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011888 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011889 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011890 alloc_info.descriptorPool = ds_pool;
11891 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011892 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011893 ASSERT_VK_SUCCESS(err);
11894
Tony Barboureb254902015-07-15 12:50:33 -060011895 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011896 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070011897 pipe_ms_state_ci.pNext = NULL;
11898 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
11899 pipe_ms_state_ci.sampleShadingEnable = 0;
11900 pipe_ms_state_ci.minSampleShading = 1.0;
11901 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011902
Tony Barboureb254902015-07-15 12:50:33 -060011903 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011904 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11905 pipeline_layout_ci.pNext = NULL;
11906 pipeline_layout_ci.setLayoutCount = 1;
11907 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011908
11909 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011910 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011911 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011912
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011913 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -060011914 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -070011915 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011916 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011917
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011918 VkPipelineObj pipe(m_device);
11919 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060011920 pipe.AddShader(&fs);
Jeremy Hayes7332f342017-03-09 15:54:12 -070011921 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011922 pipe.SetMSAA(&pipe_ms_state_ci);
11923 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060011924
Tony Barbour552f6c02016-12-21 14:34:07 -070011925 m_commandBuffer->BeginCommandBuffer();
11926 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011927
Karl Schultz6addd812016-02-02 17:17:23 -070011928 // Main thing we care about for this test is that the VkImage obj we're
11929 // clearing matches Color Attachment of FB
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011930 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -060011931 VkClearAttachment color_attachment;
11932 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11933 color_attachment.clearValue.color.float32[0] = 1.0;
11934 color_attachment.clearValue.color.float32[1] = 1.0;
11935 color_attachment.clearValue.color.float32[2] = 1.0;
11936 color_attachment.clearValue.color.float32[3] = 1.0;
11937 color_attachment.colorAttachment = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011938 VkClearRect clear_rect = {{{0, 0}, {(uint32_t)m_width, (uint32_t)m_height}}};
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011939
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070011940 // Call for full-sized FB Color attachment prior to issuing a Draw
11941 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070011942 "vkCmdClearAttachments() issued on command buffer object ");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011943 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070011944 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011945
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070011946 clear_rect.rect.extent.width = renderPassBeginInfo().renderArea.extent.width + 4;
11947 clear_rect.rect.extent.height = clear_rect.rect.extent.height / 2;
11948 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01115);
11949 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
11950 m_errorMonitor->VerifyFound();
11951
11952 clear_rect.rect.extent.width = (uint32_t)m_width / 2;
11953 clear_rect.layerCount = 2;
11954 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01116);
11955 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011956 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011957
Chia-I Wuf7458c52015-10-26 21:10:41 +080011958 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11959 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11960 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011961}
11962
Karl Schultz6addd812016-02-02 17:17:23 -070011963TEST_F(VkLayerTest, VtxBufferBadIndex) {
11964 VkResult err;
Tobin Ehlis502480b2015-06-24 15:53:07 -060011965
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011966 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11967 "but no vertex buffers are attached to this Pipeline State Object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011968
Tony Barbour1fa09702017-03-16 12:09:08 -060011969 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisd332f282015-10-02 11:00:56 -060011970 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlis502480b2015-06-24 15:53:07 -060011971 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060011972
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011973 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011974 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11975 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011976
11977 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011978 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11979 ds_pool_ci.pNext = NULL;
11980 ds_pool_ci.maxSets = 1;
11981 ds_pool_ci.poolSizeCount = 1;
11982 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060011983
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060011984 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011985 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011986 ASSERT_VK_SUCCESS(err);
11987
Tony Barboureb254902015-07-15 12:50:33 -060011988 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011989 dsl_binding.binding = 0;
11990 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11991 dsl_binding.descriptorCount = 1;
11992 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11993 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060011994
Tony Barboureb254902015-07-15 12:50:33 -060011995 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011996 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11997 ds_layout_ci.pNext = NULL;
11998 ds_layout_ci.bindingCount = 1;
11999 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060012000
Tobin Ehlis502480b2015-06-24 15:53:07 -060012001 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012002 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060012003 ASSERT_VK_SUCCESS(err);
12004
12005 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012006 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080012007 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070012008 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060012009 alloc_info.descriptorPool = ds_pool;
12010 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012011 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis502480b2015-06-24 15:53:07 -060012012 ASSERT_VK_SUCCESS(err);
12013
Tony Barboureb254902015-07-15 12:50:33 -060012014 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012015 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070012016 pipe_ms_state_ci.pNext = NULL;
12017 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
12018 pipe_ms_state_ci.sampleShadingEnable = 0;
12019 pipe_ms_state_ci.minSampleShading = 1.0;
12020 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060012021
Tony Barboureb254902015-07-15 12:50:33 -060012022 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012023 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12024 pipeline_layout_ci.pNext = NULL;
12025 pipeline_layout_ci.setLayoutCount = 1;
12026 pipeline_layout_ci.pSetLayouts = &ds_layout;
12027 VkPipelineLayout pipeline_layout;
Tobin Ehlis502480b2015-06-24 15:53:07 -060012028
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012029 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060012030 ASSERT_VK_SUCCESS(err);
12031
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012032 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012033 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 -060012034 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -060012035 VkPipelineObj pipe(m_device);
12036 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060012037 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -060012038 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060012039 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -060012040 pipe.SetViewport(m_viewports);
12041 pipe.SetScissor(m_scissors);
Tony Barbour62e1a5b2015-08-06 10:16:07 -060012042 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060012043
Tony Barbour552f6c02016-12-21 14:34:07 -070012044 m_commandBuffer->BeginCommandBuffer();
12045 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012046 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisf7bf4502015-09-09 15:12:35 -060012047 // Don't care about actual data, just need to get to draw to flag error
12048 static const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012049 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), (const void *)&vbo_data);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012050 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -060012051 Draw(1, 0, 0, 0);
Tobin Ehlis502480b2015-06-24 15:53:07 -060012052
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012053 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060012054
Chia-I Wuf7458c52015-10-26 21:10:41 +080012055 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12056 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12057 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis502480b2015-06-24 15:53:07 -060012058}
Mark Muellerdfe37552016-07-07 14:47:42 -060012059
Mark Mueller2ee294f2016-08-04 12:59:48 -060012060TEST_F(VkLayerTest, MismatchCountQueueCreateRequestedFeature) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012061 TEST_DESCRIPTION(
12062 "Use an invalid count in a vkEnumeratePhysicalDevices call."
12063 "Use invalid Queue Family Index in vkCreateDevice");
Tony Barbour1fa09702017-03-16 12:09:08 -060012064 ASSERT_NO_FATAL_FAILURE(Init());
Mark Mueller2ee294f2016-08-04 12:59:48 -060012065
Mark Mueller880fce52016-08-17 15:23:23 -060012066 // The following test fails with recent NVidia drivers.
12067 // By the time core_validation is reached, the NVidia
12068 // driver has sanitized the invalid condition and core_validation
12069 // is not introduced to the failure condition. This is not the case
12070 // with AMD and Mesa drivers. Futher investigation is required
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012071 // uint32_t count = static_cast<uint32_t>(~0);
12072 // VkPhysicalDevice physical_device;
12073 // vkEnumeratePhysicalDevices(instance(), &count, &physical_device);
12074 // m_errorMonitor->VerifyFound();
Mark Mueller2ee294f2016-08-04 12:59:48 -060012075
Mark Mueller2ee294f2016-08-04 12:59:48 -060012076 float queue_priority = 0.0;
Mark Mueller2ee294f2016-08-04 12:59:48 -060012077 VkDeviceQueueCreateInfo queue_create_info = {};
12078 queue_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
12079 queue_create_info.queueCount = 1;
12080 queue_create_info.pQueuePriorities = &queue_priority;
12081 queue_create_info.queueFamilyIndex = static_cast<uint32_t>(~0);
12082
12083 VkPhysicalDeviceFeatures features = m_device->phy().features();
12084 VkDevice testDevice;
12085 VkDeviceCreateInfo device_create_info = {};
12086 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
12087 device_create_info.queueCreateInfoCount = 1;
12088 device_create_info.pQueueCreateInfos = &queue_create_info;
12089 device_create_info.pEnabledFeatures = &features;
Jeremy Hayesb26fd042017-03-10 09:13:22 -070012090
Petr Kraus56ed9192017-05-08 23:45:36 +020012091 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00054);
Jeremy Hayes17fd3662017-03-17 11:51:11 -060012092 // The following unexpected error is coming from the LunarG loader. Do not make it a desired message because platforms that do
12093 // not use the LunarG loader (e.g. Android) will not see the message and the test will fail.
12094 m_errorMonitor->SetUnexpectedError("Failed to create device chain.");
Mark Mueller2ee294f2016-08-04 12:59:48 -060012095 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
12096 m_errorMonitor->VerifyFound();
12097
12098 queue_create_info.queueFamilyIndex = 1;
12099
12100 unsigned feature_count = sizeof(VkPhysicalDeviceFeatures) / sizeof(VkBool32);
12101 VkBool32 *feature_array = reinterpret_cast<VkBool32 *>(&features);
12102 for (unsigned i = 0; i < feature_count; i++) {
12103 if (VK_FALSE == feature_array[i]) {
12104 feature_array[i] = VK_TRUE;
Mark Mueller2ee294f2016-08-04 12:59:48 -060012105 device_create_info.pEnabledFeatures = &features;
Jeremy Hayesb26fd042017-03-10 09:13:22 -070012106 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12107 "While calling vkCreateDevice(), requesting feature #");
Jeremy Hayes17fd3662017-03-17 11:51:11 -060012108 // The following unexpected error is coming from the LunarG loader. Do not make it a desired message because platforms
12109 // that do not use the LunarG loader (e.g. Android) will not see the message and the test will fail.
12110 m_errorMonitor->SetUnexpectedError("Failed to create device chain.");
Jeremy Hayesb26fd042017-03-10 09:13:22 -070012111 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12112 "You requested features that are unavailable on this device. You should first "
12113 "query feature availability by calling vkGetPhysicalDeviceFeatures().");
Mark Mueller2ee294f2016-08-04 12:59:48 -060012114 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
12115 m_errorMonitor->VerifyFound();
12116 break;
12117 }
12118 }
12119}
12120
Tobin Ehlis16edf082016-11-21 12:33:49 -070012121TEST_F(VkLayerTest, InvalidQueryPoolCreate) {
12122 TEST_DESCRIPTION("Attempt to create a query pool for PIPELINE_STATISTICS without enabling pipeline stats for the device.");
12123
Tony Barbour1fa09702017-03-16 12:09:08 -060012124 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis16edf082016-11-21 12:33:49 -070012125
12126 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
12127 std::vector<VkDeviceQueueCreateInfo> queue_info;
12128 queue_info.reserve(queue_props.size());
12129 std::vector<std::vector<float>> queue_priorities;
12130 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
12131 VkDeviceQueueCreateInfo qi{};
12132 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
12133 qi.queueFamilyIndex = i;
12134 qi.queueCount = queue_props[i].queueCount;
12135 queue_priorities.emplace_back(qi.queueCount, 0.0f);
12136 qi.pQueuePriorities = queue_priorities[i].data();
12137 queue_info.push_back(qi);
12138 }
12139
12140 std::vector<const char *> device_extension_names;
12141
12142 VkDevice local_device;
12143 VkDeviceCreateInfo device_create_info = {};
12144 auto features = m_device->phy().features();
12145 // Intentionally disable pipeline stats
12146 features.pipelineStatisticsQuery = VK_FALSE;
12147 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
12148 device_create_info.pNext = NULL;
12149 device_create_info.queueCreateInfoCount = queue_info.size();
12150 device_create_info.pQueueCreateInfos = queue_info.data();
12151 device_create_info.enabledLayerCount = 0;
12152 device_create_info.ppEnabledLayerNames = NULL;
12153 device_create_info.pEnabledFeatures = &features;
12154 VkResult err = vkCreateDevice(gpu(), &device_create_info, nullptr, &local_device);
12155 ASSERT_VK_SUCCESS(err);
12156
12157 VkQueryPoolCreateInfo qpci{};
12158 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
12159 qpci.queryType = VK_QUERY_TYPE_PIPELINE_STATISTICS;
12160 qpci.queryCount = 1;
12161 VkQueryPool query_pool;
12162
12163 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01006);
12164 vkCreateQueryPool(local_device, &qpci, nullptr, &query_pool);
12165 m_errorMonitor->VerifyFound();
12166
12167 vkDestroyDevice(local_device, nullptr);
12168}
12169
Mark Mueller2ee294f2016-08-04 12:59:48 -060012170TEST_F(VkLayerTest, InvalidQueueIndexInvalidQuery) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012171 TEST_DESCRIPTION(
12172 "Use an invalid queue index in a vkCmdWaitEvents call."
12173 "End a command buffer with a query still in progress.");
Mark Mueller2ee294f2016-08-04 12:59:48 -060012174
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012175 const char *invalid_queue_index =
12176 "was created with sharingMode of VK_SHARING_MODE_EXCLUSIVE. If one "
12177 "of src- or dstQueueFamilyIndex is VK_QUEUE_FAMILY_IGNORED, both "
12178 "must be.";
Mark Mueller2ee294f2016-08-04 12:59:48 -060012179
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012180 const char *invalid_query = "Ending command buffer with in progress query: queryPool 0x";
Mark Mueller2ee294f2016-08-04 12:59:48 -060012181
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012182 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queue_index);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012183
Tony Barbour1fa09702017-03-16 12:09:08 -060012184 ASSERT_NO_FATAL_FAILURE(Init());
Mark Mueller2ee294f2016-08-04 12:59:48 -060012185
12186 VkEvent event;
12187 VkEventCreateInfo event_create_info{};
12188 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
12189 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
12190
Mark Mueller2ee294f2016-08-04 12:59:48 -060012191 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012192 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012193
Tony Barbour552f6c02016-12-21 14:34:07 -070012194 m_commandBuffer->BeginCommandBuffer();
Mark Mueller2ee294f2016-08-04 12:59:48 -060012195
12196 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060012197 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 -060012198 ASSERT_TRUE(image.initialized());
12199 VkImageMemoryBarrier img_barrier = {};
12200 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
12201 img_barrier.pNext = NULL;
12202 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
12203 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
12204 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
12205 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
12206 img_barrier.image = image.handle();
12207 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
Mark Lobodzinski2a74c5c2016-08-17 13:26:28 -060012208
12209 // QueueFamilyIndex must be VK_QUEUE_FAMILY_IGNORED, this verifies
12210 // that layer validation catches the case when it is not.
12211 img_barrier.dstQueueFamilyIndex = 0;
Mark Mueller2ee294f2016-08-04 12:59:48 -060012212 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12213 img_barrier.subresourceRange.baseArrayLayer = 0;
12214 img_barrier.subresourceRange.baseMipLevel = 0;
12215 img_barrier.subresourceRange.layerCount = 1;
12216 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012217 vkCmdWaitEvents(m_commandBuffer->handle(), 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0,
12218 nullptr, 0, nullptr, 1, &img_barrier);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012219 m_errorMonitor->VerifyFound();
12220
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012221 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_query);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012222
12223 VkQueryPool query_pool;
12224 VkQueryPoolCreateInfo query_pool_create_info = {};
12225 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
12226 query_pool_create_info.queryType = VK_QUERY_TYPE_OCCLUSION;
12227 query_pool_create_info.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012228 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012229
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012230 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0 /*startQuery*/, 1 /*queryCount*/);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012231 vkCmdBeginQuery(m_commandBuffer->handle(), query_pool, 0, 0);
12232
12233 vkEndCommandBuffer(m_commandBuffer->handle());
12234 m_errorMonitor->VerifyFound();
12235
12236 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
12237 vkDestroyEvent(m_device->device(), event, nullptr);
12238}
12239
Mark Muellerdfe37552016-07-07 14:47:42 -060012240TEST_F(VkLayerTest, VertexBufferInvalid) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012241 TEST_DESCRIPTION(
12242 "Submit a command buffer using deleted vertex buffer, "
12243 "delete a buffer twice, use an invalid offset for each "
12244 "buffer type, and attempt to bind a null buffer");
Mark Muellerdfe37552016-07-07 14:47:42 -060012245
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012246 const char *deleted_buffer_in_command_buffer =
12247 "Cannot submit cmd buffer "
12248 "using deleted buffer ";
12249 const char *invalid_offset_message =
12250 "vkBindBufferMemory(): "
12251 "memoryOffset is 0x";
12252 const char *invalid_storage_buffer_offset_message =
12253 "vkBindBufferMemory(): "
12254 "storage memoryOffset "
12255 "is 0x";
12256 const char *invalid_texel_buffer_offset_message =
12257 "vkBindBufferMemory(): "
12258 "texel memoryOffset "
12259 "is 0x";
12260 const char *invalid_uniform_buffer_offset_message =
12261 "vkBindBufferMemory(): "
12262 "uniform memoryOffset "
12263 "is 0x";
Mark Muellerdfe37552016-07-07 14:47:42 -060012264
Tony Barbour1fa09702017-03-16 12:09:08 -060012265 ASSERT_NO_FATAL_FAILURE(Init());
Mark Muellerdfe37552016-07-07 14:47:42 -060012266 ASSERT_NO_FATAL_FAILURE(InitViewport());
12267 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12268
12269 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012270 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -060012271 pipe_ms_state_ci.pNext = NULL;
12272 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
12273 pipe_ms_state_ci.sampleShadingEnable = 0;
12274 pipe_ms_state_ci.minSampleShading = 1.0;
12275 pipe_ms_state_ci.pSampleMask = nullptr;
12276
12277 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12278 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12279 VkPipelineLayout pipeline_layout;
12280
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012281 VkResult err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, nullptr, &pipeline_layout);
Mark Muellerdfe37552016-07-07 14:47:42 -060012282 ASSERT_VK_SUCCESS(err);
12283
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012284 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
12285 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Muellerdfe37552016-07-07 14:47:42 -060012286 VkPipelineObj pipe(m_device);
12287 pipe.AddShader(&vs);
12288 pipe.AddShader(&fs);
12289 pipe.AddColorAttachment();
12290 pipe.SetMSAA(&pipe_ms_state_ci);
12291 pipe.SetViewport(m_viewports);
12292 pipe.SetScissor(m_scissors);
12293 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12294
Tony Barbour552f6c02016-12-21 14:34:07 -070012295 m_commandBuffer->BeginCommandBuffer();
12296 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012297 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Muellerdfe37552016-07-07 14:47:42 -060012298
12299 {
12300 // Create and bind a vertex buffer in a reduced scope, which will cause
12301 // it to be deleted upon leaving this scope
12302 const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012303 VkVerticesObj draw_verticies(m_device, 1, 1, sizeof(vbo_data), 3, vbo_data);
Mark Muellerdfe37552016-07-07 14:47:42 -060012304 draw_verticies.BindVertexBuffers(m_commandBuffer->handle());
12305 draw_verticies.AddVertexInputToPipe(pipe);
12306 }
12307
12308 Draw(1, 0, 0, 0);
12309
Tony Barbour552f6c02016-12-21 14:34:07 -070012310 m_commandBuffer->EndRenderPass();
12311 m_commandBuffer->EndCommandBuffer();
Mark Muellerdfe37552016-07-07 14:47:42 -060012312
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012313 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, deleted_buffer_in_command_buffer);
Mark Muellerdfe37552016-07-07 14:47:42 -060012314 QueueCommandBuffer(false);
12315 m_errorMonitor->VerifyFound();
12316
12317 {
12318 // Create and bind a vertex buffer in a reduced scope, and delete it
12319 // twice, the second through the destructor
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012320 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eDoubleDelete);
Karl Schultzf78bcdd2016-11-30 12:36:01 -070012321 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00680);
Mark Muellerdfe37552016-07-07 14:47:42 -060012322 buffer_test.TestDoubleDestroy();
12323 }
12324 m_errorMonitor->VerifyFound();
12325
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012326 m_errorMonitor->SetUnexpectedError("value of pCreateInfo->usage must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012327 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidMemoryOffset)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060012328 // Create and bind a memory buffer with an invalid offset.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012329 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_offset_message);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012330 m_errorMonitor->SetUnexpectedError(
12331 "If buffer was created with the VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT or VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT, "
12332 "memoryOffset must be a multiple of VkPhysicalDeviceLimits::minTexelBufferOffsetAlignment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012333 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidMemoryOffset);
12334 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012335 m_errorMonitor->VerifyFound();
12336 }
12337
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012338 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset,
12339 VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060012340 // Create and bind a memory buffer with an invalid offset again,
12341 // but look for a texel buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012342 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_texel_buffer_offset_message);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012343 m_errorMonitor->SetUnexpectedError(
12344 "memoryOffset must be an integer multiple of the alignment member of the VkMemoryRequirements structure returned from "
12345 "a call to vkGetBufferMemoryRequirements with buffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012346 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
12347 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012348 m_errorMonitor->VerifyFound();
12349 }
12350
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012351 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060012352 // Create and bind a memory buffer with an invalid offset again, but
12353 // look for a uniform buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012354 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_uniform_buffer_offset_message);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012355 m_errorMonitor->SetUnexpectedError(
12356 "memoryOffset must be an integer multiple of the alignment member of the VkMemoryRequirements structure returned from "
12357 "a call to vkGetBufferMemoryRequirements with buffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012358 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
12359 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012360 m_errorMonitor->VerifyFound();
12361 }
12362
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012363 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060012364 // Create and bind a memory buffer with an invalid offset again, but
12365 // look for a storage buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012366 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_storage_buffer_offset_message);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012367 m_errorMonitor->SetUnexpectedError(
12368 "memoryOffset must be an integer multiple of the alignment member of the VkMemoryRequirements structure returned from "
12369 "a call to vkGetBufferMemoryRequirements with buffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012370 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
12371 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012372 m_errorMonitor->VerifyFound();
12373 }
12374
12375 {
12376 // Attempt to bind a null buffer.
Karl Schultzf78bcdd2016-11-30 12:36:01 -070012377 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00799);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012378 m_errorMonitor->SetUnexpectedError("required parameter memory specified as VK_NULL_HANDLE");
12379 m_errorMonitor->SetUnexpectedError("memory must be a valid VkDeviceMemory handle");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012380 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eBindNullBuffer);
12381 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012382 m_errorMonitor->VerifyFound();
12383 }
12384
12385 {
12386 // Attempt to use an invalid handle to delete a buffer.
Karl Schultzf78bcdd2016-11-30 12:36:01 -070012387 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00622);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012388 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eFreeInvalidHandle);
12389 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012390 }
12391 m_errorMonitor->VerifyFound();
12392
12393 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12394}
12395
Tony Barbourff1351e2017-05-10 11:14:03 -060012396TEST_F(VkLayerTest, BadVertexBufferOffset) {
12397 TEST_DESCRIPTION("Submit an offset past the end of a vertex buffer");
12398
12399 ASSERT_NO_FATAL_FAILURE(Init());
12400 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12401 static const float vbo_data[3] = {1.f, 0.f, 1.f};
12402 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), (const void *)&vbo_data);
12403 VkMemoryRequirements memory_reqs;
12404 vkGetBufferMemoryRequirements(m_device->device(), vbo.handle(), &memory_reqs);
12405 m_commandBuffer->BeginCommandBuffer();
12406 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
12407 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01417);
12408 BindVertexBuffer(&vbo, (VkDeviceSize)(memory_reqs.size + 1), 1); // Offset past the end of the buffer
12409 m_errorMonitor->VerifyFound();
12410}
12411
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012412// INVALID_IMAGE_LAYOUT tests (one other case is hit by MapMemWithoutHostVisibleBit and not here)
12413TEST_F(VkLayerTest, InvalidImageLayout) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012414 TEST_DESCRIPTION(
12415 "Hit all possible validation checks associated with the "
12416 "DRAWSTATE_INVALID_IMAGE_LAYOUT enum. Generally these involve having"
12417 "images in the wrong layout when they're copied or transitioned.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012418 // 3 in ValidateCmdBufImageLayouts
12419 // * -1 Attempt to submit cmd buf w/ deleted image
12420 // * -2 Cmd buf submit of image w/ layout not matching first use w/ subresource
12421 // * -3 Cmd buf submit of image w/ layout not matching first use w/o subresource
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012422
Tony Barbour1fa09702017-03-16 12:09:08 -060012423 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -060012424 auto depth_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbourf887b162017-03-09 10:06:46 -070012425 if (!depth_format) {
12426 printf(" No Depth + Stencil format found. Skipped.\n");
12427 return;
12428 }
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012429 // Create src & dst images to use for copy operations
12430 VkImage src_image;
12431 VkImage dst_image;
Cort3b021012016-12-07 12:00:57 -080012432 VkImage depth_image;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012433
12434 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
12435 const int32_t tex_width = 32;
12436 const int32_t tex_height = 32;
12437
12438 VkImageCreateInfo image_create_info = {};
12439 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
12440 image_create_info.pNext = NULL;
12441 image_create_info.imageType = VK_IMAGE_TYPE_2D;
12442 image_create_info.format = tex_format;
12443 image_create_info.extent.width = tex_width;
12444 image_create_info.extent.height = tex_height;
12445 image_create_info.extent.depth = 1;
12446 image_create_info.mipLevels = 1;
12447 image_create_info.arrayLayers = 4;
12448 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
12449 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
12450 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Cort3b021012016-12-07 12:00:57 -080012451 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012452 image_create_info.flags = 0;
12453
12454 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &src_image);
12455 ASSERT_VK_SUCCESS(err);
Cort3b021012016-12-07 12:00:57 -080012456 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012457 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dst_image);
12458 ASSERT_VK_SUCCESS(err);
Cort3b021012016-12-07 12:00:57 -080012459 image_create_info.format = VK_FORMAT_D32_SFLOAT;
12460 image_create_info.usage |= VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
12461 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &depth_image);
12462 ASSERT_VK_SUCCESS(err);
12463
12464 // Allocate memory
12465 VkMemoryRequirements img_mem_reqs = {};
Cort530cf382016-12-08 09:59:47 -080012466 VkMemoryAllocateInfo mem_alloc = {};
Cort3b021012016-12-07 12:00:57 -080012467 VkDeviceMemory src_image_mem, dst_image_mem, depth_image_mem;
Cort530cf382016-12-08 09:59:47 -080012468 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
12469 mem_alloc.pNext = NULL;
12470 mem_alloc.allocationSize = 0;
12471 mem_alloc.memoryTypeIndex = 0;
Cort3b021012016-12-07 12:00:57 -080012472
12473 vkGetImageMemoryRequirements(m_device->device(), src_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080012474 mem_alloc.allocationSize = img_mem_reqs.size;
12475 bool pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080012476 ASSERT_TRUE(pass);
Cort530cf382016-12-08 09:59:47 -080012477 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &src_image_mem);
Cort3b021012016-12-07 12:00:57 -080012478 ASSERT_VK_SUCCESS(err);
12479
12480 vkGetImageMemoryRequirements(m_device->device(), dst_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080012481 mem_alloc.allocationSize = img_mem_reqs.size;
12482 pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080012483 ASSERT_VK_SUCCESS(err);
Cort530cf382016-12-08 09:59:47 -080012484 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &dst_image_mem);
Cort3b021012016-12-07 12:00:57 -080012485 ASSERT_VK_SUCCESS(err);
12486
12487 vkGetImageMemoryRequirements(m_device->device(), depth_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080012488 mem_alloc.allocationSize = img_mem_reqs.size;
12489 pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080012490 ASSERT_VK_SUCCESS(err);
Cort530cf382016-12-08 09:59:47 -080012491 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &depth_image_mem);
Cort3b021012016-12-07 12:00:57 -080012492 ASSERT_VK_SUCCESS(err);
12493
12494 err = vkBindImageMemory(m_device->device(), src_image, src_image_mem, 0);
12495 ASSERT_VK_SUCCESS(err);
12496 err = vkBindImageMemory(m_device->device(), dst_image, dst_image_mem, 0);
12497 ASSERT_VK_SUCCESS(err);
12498 err = vkBindImageMemory(m_device->device(), depth_image, depth_image_mem, 0);
12499 ASSERT_VK_SUCCESS(err);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012500
Tony Barbour552f6c02016-12-21 14:34:07 -070012501 m_commandBuffer->BeginCommandBuffer();
Cort530cf382016-12-08 09:59:47 -080012502 VkImageCopy copy_region;
12503 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12504 copy_region.srcSubresource.mipLevel = 0;
12505 copy_region.srcSubresource.baseArrayLayer = 0;
12506 copy_region.srcSubresource.layerCount = 1;
12507 copy_region.srcOffset.x = 0;
12508 copy_region.srcOffset.y = 0;
12509 copy_region.srcOffset.z = 0;
12510 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12511 copy_region.dstSubresource.mipLevel = 0;
12512 copy_region.dstSubresource.baseArrayLayer = 0;
12513 copy_region.dstSubresource.layerCount = 1;
12514 copy_region.dstOffset.x = 0;
12515 copy_region.dstOffset.y = 0;
12516 copy_region.dstOffset.z = 0;
12517 copy_region.extent.width = 1;
12518 copy_region.extent.height = 1;
12519 copy_region.extent.depth = 1;
12520
Mark Lobodzinski91c28262017-03-22 13:06:12 -060012521 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
12522 "layout should be VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL instead of GENERAL.");
12523 m_errorMonitor->SetUnexpectedError("layout should be VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL instead of GENERAL.");
Tobin Ehlis74cc6822017-03-14 16:16:51 -060012524
Cort530cf382016-12-08 09:59:47 -080012525 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 -060012526 m_errorMonitor->VerifyFound();
Tobin Ehlise35b66a2017-03-15 12:18:31 -060012527 // The first call hits the expected WARNING and skips the call down the chain, so call a second time to call down chain and
12528 // update layer state
Mark Lobodzinski91c28262017-03-22 13:06:12 -060012529 m_errorMonitor->SetUnexpectedError("layout should be VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL instead of GENERAL.");
12530 m_errorMonitor->SetUnexpectedError("layout should be VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL instead of GENERAL.");
Tobin Ehlise35b66a2017-03-15 12:18:31 -060012531 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 -060012532 // Now cause error due to src image layout changing
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012533 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski91c28262017-03-22 13:06:12 -060012534 "with specific layout VK_IMAGE_LAYOUT_UNDEFINED that "
12535 "doesn't match the actual current layout VK_IMAGE_LAYOUT_GENERAL.");
Tobin Ehlis6d4d1d52017-04-05 12:06:10 -060012536 m_errorMonitor->SetUnexpectedError("srcImageLayout must be VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL or VK_IMAGE_LAYOUT_GENERAL");
Cort530cf382016-12-08 09:59:47 -080012537 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 -060012538 m_errorMonitor->VerifyFound();
12539 // Final src error is due to bad layout type
Tobin Ehlis74cc6822017-03-14 16:16:51 -060012540 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski91c28262017-03-22 13:06:12 -060012541 "is VK_IMAGE_LAYOUT_UNDEFINED but can only be "
Tobin Ehlis74cc6822017-03-14 16:16:51 -060012542 "VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL or VK_IMAGE_LAYOUT_GENERAL.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012543 m_errorMonitor->SetUnexpectedError(
Mark Lobodzinski91c28262017-03-22 13:06:12 -060012544 "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 -080012545 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 -060012546 m_errorMonitor->VerifyFound();
12547 // Now verify same checks for dst
Mark Lobodzinski91c28262017-03-22 13:06:12 -060012548 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
12549 "layout should be VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL instead of GENERAL.");
12550 m_errorMonitor->SetUnexpectedError("layout should be VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL instead of GENERAL.");
Cort530cf382016-12-08 09:59:47 -080012551 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 -060012552 m_errorMonitor->VerifyFound();
12553 // Now cause error due to src image layout changing
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012554 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski91c28262017-03-22 13:06:12 -060012555 "with specific layout VK_IMAGE_LAYOUT_UNDEFINED that doesn't match "
Tobin Ehlis74cc6822017-03-14 16:16:51 -060012556 "the actual current layout VK_IMAGE_LAYOUT_GENERAL.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012557 m_errorMonitor->SetUnexpectedError(
Mark Lobodzinski91c28262017-03-22 13:06:12 -060012558 "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 -080012559 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 -060012560 m_errorMonitor->VerifyFound();
Tobin Ehlis74cc6822017-03-14 16:16:51 -060012561 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski91c28262017-03-22 13:06:12 -060012562 "is VK_IMAGE_LAYOUT_UNDEFINED but can only be VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL "
12563 "or VK_IMAGE_LAYOUT_GENERAL.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012564 m_errorMonitor->SetUnexpectedError(
Mark Lobodzinski91c28262017-03-22 13:06:12 -060012565 "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 -080012566 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 -060012567 m_errorMonitor->VerifyFound();
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010012568
Cort3b021012016-12-07 12:00:57 -080012569 // Convert dst and depth images to TRANSFER_DST for subsequent tests
12570 VkImageMemoryBarrier transfer_dst_image_barrier[1] = {};
12571 transfer_dst_image_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
12572 transfer_dst_image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
12573 transfer_dst_image_barrier[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
12574 transfer_dst_image_barrier[0].srcAccessMask = 0;
12575 transfer_dst_image_barrier[0].dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
12576 transfer_dst_image_barrier[0].image = dst_image;
12577 transfer_dst_image_barrier[0].subresourceRange.layerCount = image_create_info.arrayLayers;
12578 transfer_dst_image_barrier[0].subresourceRange.levelCount = image_create_info.mipLevels;
12579 transfer_dst_image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12580 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
12581 NULL, 0, NULL, 1, transfer_dst_image_barrier);
12582 transfer_dst_image_barrier[0].image = depth_image;
12583 transfer_dst_image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
12584 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
12585 NULL, 0, NULL, 1, transfer_dst_image_barrier);
12586
12587 // Cause errors due to clearing with invalid image layouts
Cort530cf382016-12-08 09:59:47 -080012588 VkClearColorValue color_clear_value = {};
12589 VkImageSubresourceRange clear_range;
12590 clear_range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12591 clear_range.baseMipLevel = 0;
12592 clear_range.baseArrayLayer = 0;
12593 clear_range.layerCount = 1;
12594 clear_range.levelCount = 1;
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010012595
Cort3b021012016-12-07 12:00:57 -080012596 // Fail due to explicitly prohibited layout for color clear (only GENERAL and TRANSFER_DST are permitted).
12597 // Since the image is currently not in UNDEFINED layout, this will emit two errors.
12598 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01086);
12599 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01085);
Cort530cf382016-12-08 09:59:47 -080012600 m_commandBuffer->ClearColorImage(dst_image, VK_IMAGE_LAYOUT_UNDEFINED, &color_clear_value, 1, &clear_range);
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010012601 m_errorMonitor->VerifyFound();
Cort3b021012016-12-07 12:00:57 -080012602 // Fail due to provided layout not matching actual current layout for color clear.
12603 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01085);
Cort530cf382016-12-08 09:59:47 -080012604 m_commandBuffer->ClearColorImage(dst_image, VK_IMAGE_LAYOUT_GENERAL, &color_clear_value, 1, &clear_range);
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010012605 m_errorMonitor->VerifyFound();
Cort3b021012016-12-07 12:00:57 -080012606
Cort530cf382016-12-08 09:59:47 -080012607 VkClearDepthStencilValue depth_clear_value = {};
12608 clear_range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Cort3b021012016-12-07 12:00:57 -080012609
12610 // Fail due to explicitly prohibited layout for depth clear (only GENERAL and TRANSFER_DST are permitted).
12611 // Since the image is currently not in UNDEFINED layout, this will emit two errors.
12612 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01101);
12613 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01100);
Cort530cf382016-12-08 09:59:47 -080012614 m_commandBuffer->ClearDepthStencilImage(depth_image, VK_IMAGE_LAYOUT_UNDEFINED, &depth_clear_value, 1, &clear_range);
Cort3b021012016-12-07 12:00:57 -080012615 m_errorMonitor->VerifyFound();
12616 // Fail due to provided layout not matching actual current layout for depth clear.
12617 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01100);
Cort530cf382016-12-08 09:59:47 -080012618 m_commandBuffer->ClearDepthStencilImage(depth_image, VK_IMAGE_LAYOUT_GENERAL, &depth_clear_value, 1, &clear_range);
Cort3b021012016-12-07 12:00:57 -080012619 m_errorMonitor->VerifyFound();
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010012620
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012621 // Now cause error due to bad image layout transition in PipelineBarrier
12622 VkImageMemoryBarrier image_barrier[1] = {};
Cort3b021012016-12-07 12:00:57 -080012623 image_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012624 image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
Cort3b021012016-12-07 12:00:57 -080012625 image_barrier[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012626 image_barrier[0].image = src_image;
Cort3b021012016-12-07 12:00:57 -080012627 image_barrier[0].subresourceRange.layerCount = image_create_info.arrayLayers;
12628 image_barrier[0].subresourceRange.levelCount = image_create_info.mipLevels;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012629 image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012630 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski91c28262017-03-22 13:06:12 -060012631 "you cannot transition the layout of aspect 1 from "
12632 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL when current layout is "
12633 "VK_IMAGE_LAYOUT_GENERAL.");
Mike Weiblen62d08a32017-03-07 22:18:27 -070012634 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00305);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012635 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
12636 NULL, 0, NULL, 1, image_barrier);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012637 m_errorMonitor->VerifyFound();
12638
12639 // Finally some layout errors at RenderPass create time
12640 // Just hacking in specific state to get to the errors we want so don't copy this unless you know what you're doing.
12641 VkAttachmentReference attach = {};
12642 // perf warning for GENERAL layout w/ non-DS input attachment
12643 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
12644 VkSubpassDescription subpass = {};
12645 subpass.inputAttachmentCount = 1;
12646 subpass.pInputAttachments = &attach;
12647 VkRenderPassCreateInfo rpci = {};
12648 rpci.subpassCount = 1;
12649 rpci.pSubpasses = &subpass;
12650 rpci.attachmentCount = 1;
12651 VkAttachmentDescription attach_desc = {};
12652 attach_desc.format = VK_FORMAT_UNDEFINED;
12653 rpci.pAttachments = &attach_desc;
Tobin Ehlis1efce022016-05-11 10:40:34 -060012654 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012655 VkRenderPass rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012656 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
12657 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012658 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12659 m_errorMonitor->VerifyFound();
12660 // error w/ non-general layout
12661 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
12662
12663 m_errorMonitor->SetDesiredFailureMsg(
12664 VK_DEBUG_REPORT_ERROR_BIT_EXT,
12665 "Layout for input attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be READ_ONLY_OPTIMAL or GENERAL.");
12666 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12667 m_errorMonitor->VerifyFound();
12668 subpass.inputAttachmentCount = 0;
12669 subpass.colorAttachmentCount = 1;
12670 subpass.pColorAttachments = &attach;
12671 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
12672 // perf warning for GENERAL layout on color attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012673 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
12674 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012675 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12676 m_errorMonitor->VerifyFound();
12677 // error w/ non-color opt or GENERAL layout for color attachment
12678 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
12679 m_errorMonitor->SetDesiredFailureMsg(
12680 VK_DEBUG_REPORT_ERROR_BIT_EXT,
12681 "Layout for color attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.");
12682 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12683 m_errorMonitor->VerifyFound();
12684 subpass.colorAttachmentCount = 0;
12685 subpass.pDepthStencilAttachment = &attach;
12686 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
12687 // perf warning for GENERAL layout on DS attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012688 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
12689 "GENERAL layout for depth attachment may not give optimal performance.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012690 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12691 m_errorMonitor->VerifyFound();
12692 // error w/ non-ds opt or GENERAL layout for color attachment
12693 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012694 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12695 "Layout for depth attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be "
12696 "DEPTH_STENCIL_ATTACHMENT_OPTIMAL, DEPTH_STENCIL_READ_ONLY_OPTIMAL or GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012697 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12698 m_errorMonitor->VerifyFound();
Tobin Ehlis1efce022016-05-11 10:40:34 -060012699 // For this error we need a valid renderpass so create default one
12700 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
12701 attach.attachment = 0;
Tony Barbourf887b162017-03-09 10:06:46 -070012702 attach_desc.format = depth_format;
Tobin Ehlis1efce022016-05-11 10:40:34 -060012703 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
12704 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
12705 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
12706 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
12707 // Can't do a CLEAR load on READ_ONLY initialLayout
12708 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
12709 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
12710 attach_desc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012711 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski91c28262017-03-22 13:06:12 -060012712 "with invalid first layout VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL");
Tobin Ehlis1efce022016-05-11 10:40:34 -060012713 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12714 m_errorMonitor->VerifyFound();
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012715
Cort3b021012016-12-07 12:00:57 -080012716 vkFreeMemory(m_device->device(), src_image_mem, NULL);
12717 vkFreeMemory(m_device->device(), dst_image_mem, NULL);
12718 vkFreeMemory(m_device->device(), depth_image_mem, NULL);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012719 vkDestroyImage(m_device->device(), src_image, NULL);
12720 vkDestroyImage(m_device->device(), dst_image, NULL);
Cort3b021012016-12-07 12:00:57 -080012721 vkDestroyImage(m_device->device(), depth_image, NULL);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012722}
Tobin Ehlisd8d89182016-07-18 20:13:11 -060012723
Tobin Ehlise0936662016-10-11 08:10:51 -060012724TEST_F(VkLayerTest, InvalidStorageImageLayout) {
12725 TEST_DESCRIPTION("Attempt to update a STORAGE_IMAGE descriptor w/o GENERAL layout.");
12726 VkResult err;
12727
Tony Barbour1fa09702017-03-16 12:09:08 -060012728 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlise0936662016-10-11 08:10:51 -060012729
12730 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
12731 VkImageTiling tiling;
12732 VkFormatProperties format_properties;
12733 vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties);
12734 if (format_properties.linearTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
12735 tiling = VK_IMAGE_TILING_LINEAR;
12736 } else if (format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
12737 tiling = VK_IMAGE_TILING_OPTIMAL;
12738 } else {
Dave Houlton584d51e2017-02-16 12:52:54 -070012739 printf(" Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; skipped.\n");
Tobin Ehlise0936662016-10-11 08:10:51 -060012740 return;
12741 }
12742
12743 VkDescriptorPoolSize ds_type = {};
12744 ds_type.type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
12745 ds_type.descriptorCount = 1;
12746
12747 VkDescriptorPoolCreateInfo ds_pool_ci = {};
12748 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12749 ds_pool_ci.maxSets = 1;
12750 ds_pool_ci.poolSizeCount = 1;
12751 ds_pool_ci.pPoolSizes = &ds_type;
12752 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
12753
12754 VkDescriptorPool ds_pool;
12755 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
12756 ASSERT_VK_SUCCESS(err);
12757
12758 VkDescriptorSetLayoutBinding dsl_binding = {};
12759 dsl_binding.binding = 0;
12760 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
12761 dsl_binding.descriptorCount = 1;
12762 dsl_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12763 dsl_binding.pImmutableSamplers = NULL;
12764
12765 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
12766 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12767 ds_layout_ci.pNext = NULL;
12768 ds_layout_ci.bindingCount = 1;
12769 ds_layout_ci.pBindings = &dsl_binding;
12770
12771 VkDescriptorSetLayout ds_layout;
12772 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
12773 ASSERT_VK_SUCCESS(err);
12774
12775 VkDescriptorSetAllocateInfo alloc_info = {};
12776 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12777 alloc_info.descriptorSetCount = 1;
12778 alloc_info.descriptorPool = ds_pool;
12779 alloc_info.pSetLayouts = &ds_layout;
12780 VkDescriptorSet descriptor_set;
12781 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
12782 ASSERT_VK_SUCCESS(err);
12783
12784 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12785 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12786 pipeline_layout_ci.pNext = NULL;
12787 pipeline_layout_ci.setLayoutCount = 1;
12788 pipeline_layout_ci.pSetLayouts = &ds_layout;
12789 VkPipelineLayout pipeline_layout;
12790 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
12791 ASSERT_VK_SUCCESS(err);
12792
12793 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060012794 image.Init(32, 32, 1, tex_format, VK_IMAGE_USAGE_STORAGE_BIT, tiling, 0);
Tobin Ehlise0936662016-10-11 08:10:51 -060012795 ASSERT_TRUE(image.initialized());
12796 VkImageView view = image.targetView(tex_format);
12797
12798 VkDescriptorImageInfo image_info = {};
12799 image_info.imageView = view;
12800 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
12801
12802 VkWriteDescriptorSet descriptor_write = {};
12803 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12804 descriptor_write.dstSet = descriptor_set;
12805 descriptor_write.dstBinding = 0;
12806 descriptor_write.descriptorCount = 1;
12807 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
12808 descriptor_write.pImageInfo = &image_info;
12809
12810 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12811 " of VK_DESCRIPTOR_TYPE_STORAGE_IMAGE type is being updated with layout "
12812 "VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL but according to spec ");
12813 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
12814 m_errorMonitor->VerifyFound();
12815
12816 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12817 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12818 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
12819 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
12820}
12821
Mark Mueller93b938f2016-08-18 10:27:40 -060012822TEST_F(VkLayerTest, SimultaneousUse) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012823 TEST_DESCRIPTION(
12824 "Use vkCmdExecuteCommands with invalid state "
12825 "in primary and secondary command buffers.");
Mark Mueller93b938f2016-08-18 10:27:40 -060012826
Tony Barbour1fa09702017-03-16 12:09:08 -060012827 ASSERT_NO_FATAL_FAILURE(Init());
Mark Mueller93b938f2016-08-18 10:27:40 -060012828 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12829
Mike Weiblen95dd0f92016-10-19 12:28:27 -060012830 const char *simultaneous_use_message1 = "without VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set!";
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012831 const char *simultaneous_use_message2 =
12832 "does not have VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set and "
12833 "will cause primary command buffer";
Mark Mueller93b938f2016-08-18 10:27:40 -060012834
12835 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012836 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mike Schuchardt06304c22017-03-01 17:09:09 -070012837 command_buffer_allocate_info.commandPool = m_commandPool->handle();
Mark Mueller93b938f2016-08-18 10:27:40 -060012838 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
12839 command_buffer_allocate_info.commandBufferCount = 1;
12840
12841 VkCommandBuffer secondary_command_buffer;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012842 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
Mark Mueller93b938f2016-08-18 10:27:40 -060012843 VkCommandBufferBeginInfo command_buffer_begin_info = {};
12844 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012845 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060012846 command_buffer_inheritance_info.renderPass = m_renderPass;
12847 command_buffer_inheritance_info.framebuffer = m_framebuffer;
Rene Lindsay24cf6c52017-01-04 12:06:59 -070012848
Mark Mueller93b938f2016-08-18 10:27:40 -060012849 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012850 command_buffer_begin_info.flags =
12851 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060012852 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
12853
12854 vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
12855 vkEndCommandBuffer(secondary_command_buffer);
12856
Mark Mueller93b938f2016-08-18 10:27:40 -060012857 VkSubmitInfo submit_info = {};
12858 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12859 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012860 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller93b938f2016-08-18 10:27:40 -060012861
Mark Mueller4042b652016-09-05 22:52:21 -060012862 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012863 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
12864 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, simultaneous_use_message1);
12865 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Rene Lindsay24cf6c52017-01-04 12:06:59 -070012866 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060012867 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060012868 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
12869 vkEndCommandBuffer(m_commandBuffer->handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060012870
Dave Houltonfbf52152017-01-06 12:55:29 -070012871 m_errorMonitor->ExpectSuccess(0);
Mark Mueller93b938f2016-08-18 10:27:40 -060012872 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Dave Houltonfbf52152017-01-06 12:55:29 -070012873 m_errorMonitor->VerifyNotFound();
Mark Mueller93b938f2016-08-18 10:27:40 -060012874
Mark Mueller4042b652016-09-05 22:52:21 -060012875 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
Tobin Ehlis6d4d1d52017-04-05 12:06:10 -060012876 m_errorMonitor->SetUnexpectedError("commandBuffer must not be in the recording or pending state.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012877 m_errorMonitor->SetUnexpectedError(
12878 "If commandBuffer was allocated from a VkCommandPool which did not have the "
12879 "VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT flag set, commandBuffer must be in the initial state");
Mark Mueller93b938f2016-08-18 10:27:40 -060012880 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012881 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Mark Mueller4042b652016-09-05 22:52:21 -060012882
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012883 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, simultaneous_use_message2);
12884 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060012885 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060012886 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
12887 vkEndCommandBuffer(m_commandBuffer->handle());
Rene Lindsay24cf6c52017-01-04 12:06:59 -070012888
12889 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012890
Tobin Ehlis6d4d1d52017-04-05 12:06:10 -060012891 m_errorMonitor->SetUnexpectedError("All elements of pCommandBuffers must not be in the pending state");
Mark Mueller93b938f2016-08-18 10:27:40 -060012892}
12893
Tony Barbour626994c2017-02-08 15:29:37 -070012894TEST_F(VkLayerTest, SimultaneousUseOneShot) {
12895 TEST_DESCRIPTION(
12896 "Submit the same command buffer twice in one submit looking for simultaneous use and one time submit"
12897 "errors");
12898 const char *simultaneous_use_message = "is already in use and is not marked for simultaneous use";
12899 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 -060012900 ASSERT_NO_FATAL_FAILURE(Init());
Tony Barbour626994c2017-02-08 15:29:37 -070012901
12902 VkCommandBuffer cmd_bufs[2];
12903 VkCommandBufferAllocateInfo alloc_info;
12904 alloc_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
12905 alloc_info.pNext = NULL;
12906 alloc_info.commandBufferCount = 2;
Mike Schuchardt06304c22017-03-01 17:09:09 -070012907 alloc_info.commandPool = m_commandPool->handle();
Tony Barbour626994c2017-02-08 15:29:37 -070012908 alloc_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
12909 vkAllocateCommandBuffers(m_device->device(), &alloc_info, cmd_bufs);
12910
12911 VkCommandBufferBeginInfo cb_binfo;
12912 cb_binfo.pNext = NULL;
12913 cb_binfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
12914 cb_binfo.pInheritanceInfo = VK_NULL_HANDLE;
12915 cb_binfo.flags = 0;
12916 vkBeginCommandBuffer(cmd_bufs[0], &cb_binfo);
12917 VkViewport viewport = {0, 0, 16, 16, 0, 1};
12918 vkCmdSetViewport(cmd_bufs[0], 0, 1, &viewport);
12919 vkEndCommandBuffer(cmd_bufs[0]);
12920 VkCommandBuffer duplicates[2] = {cmd_bufs[0], cmd_bufs[0]};
12921
12922 VkSubmitInfo submit_info = {};
12923 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12924 submit_info.commandBufferCount = 2;
12925 submit_info.pCommandBuffers = duplicates;
12926 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, simultaneous_use_message);
12927 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12928 m_errorMonitor->VerifyFound();
12929 vkQueueWaitIdle(m_device->m_queue);
12930
12931 // Set one time use and now look for one time submit
12932 duplicates[0] = duplicates[1] = cmd_bufs[1];
12933 cb_binfo.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT | VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
12934 vkBeginCommandBuffer(cmd_bufs[1], &cb_binfo);
12935 vkCmdSetViewport(cmd_bufs[1], 0, 1, &viewport);
12936 vkEndCommandBuffer(cmd_bufs[1]);
12937 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, one_shot_message);
12938 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12939 m_errorMonitor->VerifyFound();
12940 vkQueueWaitIdle(m_device->m_queue);
12941}
12942
Tobin Ehlisb093da82017-01-19 12:05:27 -070012943TEST_F(VkLayerTest, StageMaskGsTsEnabled) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012944 TEST_DESCRIPTION(
12945 "Attempt to use a stageMask w/ geometry shader and tesselation shader bits enabled when those features are "
12946 "disabled on the device.");
Tobin Ehlisb093da82017-01-19 12:05:27 -070012947
Tony Barbour1fa09702017-03-16 12:09:08 -060012948 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisb093da82017-01-19 12:05:27 -070012949 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12950
12951 std::vector<const char *> device_extension_names;
12952 auto features = m_device->phy().features();
12953 // Make sure gs & ts are disabled
12954 features.geometryShader = false;
12955 features.tessellationShader = false;
12956 // The sacrificial device object
12957 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
12958
12959 VkCommandPoolCreateInfo pool_create_info{};
12960 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
12961 pool_create_info.queueFamilyIndex = test_device.graphics_queue_node_index_;
12962
12963 VkCommandPool command_pool;
12964 vkCreateCommandPool(test_device.handle(), &pool_create_info, nullptr, &command_pool);
12965
12966 VkCommandBufferAllocateInfo cmd = {};
12967 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
12968 cmd.pNext = NULL;
12969 cmd.commandPool = command_pool;
12970 cmd.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
12971 cmd.commandBufferCount = 1;
12972
12973 VkCommandBuffer cmd_buffer;
12974 VkResult err = vkAllocateCommandBuffers(test_device.handle(), &cmd, &cmd_buffer);
12975 ASSERT_VK_SUCCESS(err);
12976
12977 VkEvent event;
12978 VkEventCreateInfo evci = {};
12979 evci.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
12980 VkResult result = vkCreateEvent(test_device.handle(), &evci, NULL, &event);
12981 ASSERT_VK_SUCCESS(result);
12982
12983 VkCommandBufferBeginInfo cbbi = {};
12984 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
12985 vkBeginCommandBuffer(cmd_buffer, &cbbi);
12986 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00230);
12987 vkCmdSetEvent(cmd_buffer, event, VK_PIPELINE_STAGE_GEOMETRY_SHADER_BIT);
12988 m_errorMonitor->VerifyFound();
12989
12990 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00231);
12991 vkCmdSetEvent(cmd_buffer, event, VK_PIPELINE_STAGE_TESSELLATION_CONTROL_SHADER_BIT);
12992 m_errorMonitor->VerifyFound();
12993
12994 vkDestroyEvent(test_device.handle(), event, NULL);
12995 vkDestroyCommandPool(test_device.handle(), command_pool, NULL);
12996}
12997
Chris Forbesd70103a2017-04-13 11:34:09 -070012998TEST_F(VkLayerTest, EventInUseDestroyedSignaled) {
Tony Barbour1fa09702017-03-16 12:09:08 -060012999 ASSERT_NO_FATAL_FAILURE(Init());
Mark Mueller917f6bc2016-08-30 10:57:19 -060013000 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13001
Tony Barbour552f6c02016-12-21 14:34:07 -070013002 m_commandBuffer->BeginCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060013003
13004 VkEvent event;
13005 VkEventCreateInfo event_create_info = {};
13006 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
13007 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013008 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Mueller917f6bc2016-08-30 10:57:19 -060013009
Tony Barbour552f6c02016-12-21 14:34:07 -070013010 m_commandBuffer->EndCommandBuffer();
Mark Muellerc8d441e2016-08-23 17:36:00 -060013011 vkDestroyEvent(m_device->device(), event, nullptr);
13012
13013 VkSubmitInfo submit_info = {};
13014 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
13015 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013016 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Lobodzinskife4be302017-02-14 13:08:15 -070013017 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is invalid because bound");
Mark Muellerc8d441e2016-08-23 17:36:00 -060013018 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
13019 m_errorMonitor->VerifyFound();
Chris Forbesd70103a2017-04-13 11:34:09 -070013020}
Mark Muellerc8d441e2016-08-23 17:36:00 -060013021
Chris Forbesd70103a2017-04-13 11:34:09 -070013022TEST_F(VkLayerTest, InUseDestroyedSignaled) {
13023 TEST_DESCRIPTION(
13024 "Use vkCmdExecuteCommands with invalid state "
13025 "in primary and secondary command buffers. "
13026 "Delete objects that are inuse. Call VkQueueSubmit "
13027 "with an event that has been deleted.");
Mark Muellerc8d441e2016-08-23 17:36:00 -060013028
Chris Forbesd70103a2017-04-13 11:34:09 -070013029 ASSERT_NO_FATAL_FAILURE(Init());
13030 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13031
13032 m_errorMonitor->ExpectSuccess();
Mark Muellerc8d441e2016-08-23 17:36:00 -060013033
Mark Mueller917f6bc2016-08-30 10:57:19 -060013034 VkSemaphoreCreateInfo semaphore_create_info = {};
13035 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
13036 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013037 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller917f6bc2016-08-30 10:57:19 -060013038 VkFenceCreateInfo fence_create_info = {};
13039 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
13040 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013041 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller917f6bc2016-08-30 10:57:19 -060013042
13043 VkDescriptorPoolSize descriptor_pool_type_count = {};
Mark Mueller4042b652016-09-05 22:52:21 -060013044 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060013045 descriptor_pool_type_count.descriptorCount = 1;
13046
13047 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
13048 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
13049 descriptor_pool_create_info.maxSets = 1;
13050 descriptor_pool_create_info.poolSizeCount = 1;
13051 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013052 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Mark Mueller917f6bc2016-08-30 10:57:19 -060013053
13054 VkDescriptorPool descriptorset_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013055 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
Mark Mueller917f6bc2016-08-30 10:57:19 -060013056
13057 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
Mark Mueller4042b652016-09-05 22:52:21 -060013058 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060013059 descriptorset_layout_binding.descriptorCount = 1;
13060 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
13061
13062 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013063 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060013064 descriptorset_layout_create_info.bindingCount = 1;
13065 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
13066
13067 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013068 ASSERT_VK_SUCCESS(
13069 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060013070
13071 VkDescriptorSet descriptorset;
13072 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013073 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060013074 descriptorset_allocate_info.descriptorSetCount = 1;
13075 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
13076 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013077 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
Mark Mueller917f6bc2016-08-30 10:57:19 -060013078
Mark Mueller4042b652016-09-05 22:52:21 -060013079 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
13080
13081 VkDescriptorBufferInfo buffer_info = {};
13082 buffer_info.buffer = buffer_test.GetBuffer();
13083 buffer_info.offset = 0;
13084 buffer_info.range = 1024;
13085
13086 VkWriteDescriptorSet write_descriptor_set = {};
13087 write_descriptor_set.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
13088 write_descriptor_set.dstSet = descriptorset;
13089 write_descriptor_set.descriptorCount = 1;
13090 write_descriptor_set.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
13091 write_descriptor_set.pBufferInfo = &buffer_info;
13092
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013093 vkUpdateDescriptorSets(m_device->device(), 1, &write_descriptor_set, 0, nullptr);
Mark Mueller4042b652016-09-05 22:52:21 -060013094
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013095 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
13096 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Mueller917f6bc2016-08-30 10:57:19 -060013097
13098 VkPipelineObj pipe(m_device);
13099 pipe.AddColorAttachment();
13100 pipe.AddShader(&vs);
13101 pipe.AddShader(&fs);
13102
13103 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013104 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060013105 pipeline_layout_create_info.setLayoutCount = 1;
13106 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
13107
13108 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013109 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060013110
13111 pipe.CreateVKPipeline(pipeline_layout, m_renderPass);
13112
Chris Forbesd70103a2017-04-13 11:34:09 -070013113 VkEvent event;
13114 VkEventCreateInfo event_create_info = {};
13115 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
13116 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
13117
Tony Barbour552f6c02016-12-21 14:34:07 -070013118 m_commandBuffer->BeginCommandBuffer();
Chris Forbesd70103a2017-04-13 11:34:09 -070013119
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013120 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Muellerc8d441e2016-08-23 17:36:00 -060013121
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013122 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
13123 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
13124 &descriptorset, 0, NULL);
Mark Mueller917f6bc2016-08-30 10:57:19 -060013125
Tony Barbour552f6c02016-12-21 14:34:07 -070013126 m_commandBuffer->EndCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060013127
Chris Forbesd70103a2017-04-13 11:34:09 -070013128 VkSubmitInfo submit_info = {};
13129 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
13130 submit_info.commandBufferCount = 1;
13131 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller917f6bc2016-08-30 10:57:19 -060013132 submit_info.signalSemaphoreCount = 1;
13133 submit_info.pSignalSemaphores = &semaphore;
13134 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013135 m_errorMonitor->Reset(); // resume logmsg processing
Mark Muellerc8d441e2016-08-23 17:36:00 -060013136
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070013137 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00213);
Mark Mueller917f6bc2016-08-30 10:57:19 -060013138 vkDestroyEvent(m_device->device(), event, nullptr);
13139 m_errorMonitor->VerifyFound();
13140
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070013141 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00199);
Mark Mueller917f6bc2016-08-30 10:57:19 -060013142 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
13143 m_errorMonitor->VerifyFound();
13144
Jeremy Hayes08369882017-02-02 10:31:06 -070013145 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Fence 0x");
Mark Mueller917f6bc2016-08-30 10:57:19 -060013146 vkDestroyFence(m_device->device(), fence, nullptr);
13147 m_errorMonitor->VerifyFound();
13148
Tobin Ehlis122207b2016-09-01 08:50:06 -070013149 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070013150 m_errorMonitor->SetUnexpectedError("If semaphore is not VK_NULL_HANDLE, semaphore must be a valid VkSemaphore handle");
13151 m_errorMonitor->SetUnexpectedError("Unable to remove Semaphore obj");
Mark Mueller917f6bc2016-08-30 10:57:19 -060013152 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070013153 m_errorMonitor->SetUnexpectedError("If fence is not VK_NULL_HANDLE, fence must be a valid VkFence handle");
13154 m_errorMonitor->SetUnexpectedError("Unable to remove Fence obj");
Mark Mueller917f6bc2016-08-30 10:57:19 -060013155 vkDestroyFence(m_device->device(), fence, nullptr);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070013156 m_errorMonitor->SetUnexpectedError("If event is not VK_NULL_HANDLE, event must be a valid VkEvent handle");
13157 m_errorMonitor->SetUnexpectedError("Unable to remove Event obj");
Mark Mueller917f6bc2016-08-30 10:57:19 -060013158 vkDestroyEvent(m_device->device(), event, nullptr);
13159 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013160 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
Mark Mueller917f6bc2016-08-30 10:57:19 -060013161 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13162}
13163
Tobin Ehlis2adda372016-09-01 08:51:06 -070013164TEST_F(VkLayerTest, QueryPoolInUseDestroyedSignaled) {
13165 TEST_DESCRIPTION("Delete in-use query pool.");
13166
Tony Barbour1fa09702017-03-16 12:09:08 -060013167 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis2adda372016-09-01 08:51:06 -070013168 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13169
13170 VkQueryPool query_pool;
13171 VkQueryPoolCreateInfo query_pool_ci{};
13172 query_pool_ci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
13173 query_pool_ci.queryType = VK_QUERY_TYPE_TIMESTAMP;
13174 query_pool_ci.queryCount = 1;
13175 vkCreateQueryPool(m_device->device(), &query_pool_ci, nullptr, &query_pool);
Tony Barbour552f6c02016-12-21 14:34:07 -070013176 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis2adda372016-09-01 08:51:06 -070013177 // Reset query pool to create binding with cmd buffer
13178 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0, 1);
13179
Tony Barbour552f6c02016-12-21 14:34:07 -070013180 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis2adda372016-09-01 08:51:06 -070013181
13182 VkSubmitInfo submit_info = {};
13183 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
13184 submit_info.commandBufferCount = 1;
13185 submit_info.pCommandBuffers = &m_commandBuffer->handle();
13186 // Submit cmd buffer and then destroy query pool while in-flight
13187 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
13188
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070013189 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01012);
Tobin Ehlis2adda372016-09-01 08:51:06 -070013190 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
13191 m_errorMonitor->VerifyFound();
13192
13193 vkQueueWaitIdle(m_device->m_queue);
13194 // Now that cmd buffer done we can safely destroy query_pool
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070013195 m_errorMonitor->SetUnexpectedError("If queryPool is not VK_NULL_HANDLE, queryPool must be a valid VkQueryPool handle");
Mark Lobodzinski74597792017-04-11 15:43:49 -060013196 m_errorMonitor->SetUnexpectedError("Unable to remove QueryPool obj");
Tobin Ehlis2adda372016-09-01 08:51:06 -070013197 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
13198}
13199
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060013200TEST_F(VkLayerTest, PipelineInUseDestroyedSignaled) {
13201 TEST_DESCRIPTION("Delete in-use pipeline.");
13202
Tony Barbour1fa09702017-03-16 12:09:08 -060013203 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060013204 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13205
13206 // Empty pipeline layout used for binding PSO
13207 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
13208 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13209 pipeline_layout_ci.setLayoutCount = 0;
13210 pipeline_layout_ci.pSetLayouts = NULL;
13211
13212 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013213 VkResult err = vkCreatePipelineLayout(m_device->handle(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060013214 ASSERT_VK_SUCCESS(err);
13215
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070013216 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00555);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060013217 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013218 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
13219 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060013220 // Store pipeline handle so we can actually delete it before test finishes
13221 VkPipeline delete_this_pipeline;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013222 { // Scope pipeline so it will be auto-deleted
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060013223 VkPipelineObj pipe(m_device);
13224 pipe.AddShader(&vs);
13225 pipe.AddShader(&fs);
13226 pipe.AddColorAttachment();
13227 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13228 delete_this_pipeline = pipe.handle();
13229
Tony Barbour552f6c02016-12-21 14:34:07 -070013230 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060013231 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013232 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060013233
Tony Barbour552f6c02016-12-21 14:34:07 -070013234 m_commandBuffer->EndCommandBuffer();
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060013235
13236 VkSubmitInfo submit_info = {};
13237 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
13238 submit_info.commandBufferCount = 1;
13239 submit_info.pCommandBuffers = &m_commandBuffer->handle();
13240 // Submit cmd buffer and then pipeline destroyed while in-flight
13241 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013242 } // Pipeline deletion triggered here
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060013243 m_errorMonitor->VerifyFound();
13244 // Make sure queue finished and then actually delete pipeline
13245 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070013246 m_errorMonitor->SetUnexpectedError("If pipeline is not VK_NULL_HANDLE, pipeline must be a valid VkPipeline handle");
13247 m_errorMonitor->SetUnexpectedError("Unable to remove Pipeline obj");
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060013248 vkDestroyPipeline(m_device->handle(), delete_this_pipeline, nullptr);
13249 vkDestroyPipelineLayout(m_device->handle(), pipeline_layout, nullptr);
13250}
13251
Tobin Ehlis7d965da2016-09-19 16:15:45 -060013252TEST_F(VkLayerTest, ImageViewInUseDestroyedSignaled) {
13253 TEST_DESCRIPTION("Delete in-use imageView.");
13254
Tony Barbour1fa09702017-03-16 12:09:08 -060013255 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis7d965da2016-09-19 16:15:45 -060013256 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13257
13258 VkDescriptorPoolSize ds_type_count;
13259 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
13260 ds_type_count.descriptorCount = 1;
13261
13262 VkDescriptorPoolCreateInfo ds_pool_ci = {};
13263 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
13264 ds_pool_ci.maxSets = 1;
13265 ds_pool_ci.poolSizeCount = 1;
13266 ds_pool_ci.pPoolSizes = &ds_type_count;
13267
13268 VkDescriptorPool ds_pool;
13269 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
13270 ASSERT_VK_SUCCESS(err);
13271
13272 VkSamplerCreateInfo sampler_ci = {};
13273 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
13274 sampler_ci.pNext = NULL;
13275 sampler_ci.magFilter = VK_FILTER_NEAREST;
13276 sampler_ci.minFilter = VK_FILTER_NEAREST;
13277 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
13278 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
13279 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
13280 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
13281 sampler_ci.mipLodBias = 1.0;
13282 sampler_ci.anisotropyEnable = VK_FALSE;
13283 sampler_ci.maxAnisotropy = 1;
13284 sampler_ci.compareEnable = VK_FALSE;
13285 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
13286 sampler_ci.minLod = 1.0;
13287 sampler_ci.maxLod = 1.0;
13288 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
13289 sampler_ci.unnormalizedCoordinates = VK_FALSE;
13290 VkSampler sampler;
13291
13292 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
13293 ASSERT_VK_SUCCESS(err);
13294
13295 VkDescriptorSetLayoutBinding layout_binding;
13296 layout_binding.binding = 0;
13297 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
13298 layout_binding.descriptorCount = 1;
13299 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
13300 layout_binding.pImmutableSamplers = NULL;
13301
13302 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
13303 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
13304 ds_layout_ci.bindingCount = 1;
13305 ds_layout_ci.pBindings = &layout_binding;
13306 VkDescriptorSetLayout ds_layout;
13307 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
13308 ASSERT_VK_SUCCESS(err);
13309
13310 VkDescriptorSetAllocateInfo alloc_info = {};
13311 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
13312 alloc_info.descriptorSetCount = 1;
13313 alloc_info.descriptorPool = ds_pool;
13314 alloc_info.pSetLayouts = &ds_layout;
13315 VkDescriptorSet descriptor_set;
13316 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
13317 ASSERT_VK_SUCCESS(err);
13318
13319 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
13320 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13321 pipeline_layout_ci.pNext = NULL;
13322 pipeline_layout_ci.setLayoutCount = 1;
13323 pipeline_layout_ci.pSetLayouts = &ds_layout;
13324
13325 VkPipelineLayout pipeline_layout;
13326 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
13327 ASSERT_VK_SUCCESS(err);
13328
13329 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060013330 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 -060013331 ASSERT_TRUE(image.initialized());
13332
13333 VkImageView view;
13334 VkImageViewCreateInfo ivci = {};
13335 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
13336 ivci.image = image.handle();
13337 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
13338 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
13339 ivci.subresourceRange.layerCount = 1;
13340 ivci.subresourceRange.baseMipLevel = 0;
13341 ivci.subresourceRange.levelCount = 1;
13342 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
13343
13344 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
13345 ASSERT_VK_SUCCESS(err);
13346
13347 VkDescriptorImageInfo image_info{};
13348 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
13349 image_info.imageView = view;
13350 image_info.sampler = sampler;
13351
13352 VkWriteDescriptorSet descriptor_write = {};
13353 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
13354 descriptor_write.dstSet = descriptor_set;
13355 descriptor_write.dstBinding = 0;
13356 descriptor_write.descriptorCount = 1;
13357 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
13358 descriptor_write.pImageInfo = &image_info;
13359
13360 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
13361
13362 // Create PSO to use the sampler
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013363 char const *vsSource =
13364 "#version 450\n"
13365 "\n"
13366 "out gl_PerVertex { \n"
13367 " vec4 gl_Position;\n"
13368 "};\n"
13369 "void main(){\n"
13370 " gl_Position = vec4(1);\n"
13371 "}\n";
13372 char const *fsSource =
13373 "#version 450\n"
13374 "\n"
13375 "layout(set=0, binding=0) uniform sampler2D s;\n"
13376 "layout(location=0) out vec4 x;\n"
13377 "void main(){\n"
13378 " x = texture(s, vec2(1));\n"
13379 "}\n";
Tobin Ehlis7d965da2016-09-19 16:15:45 -060013380 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13381 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13382 VkPipelineObj pipe(m_device);
13383 pipe.AddShader(&vs);
13384 pipe.AddShader(&fs);
13385 pipe.AddColorAttachment();
13386 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13387
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070013388 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00776);
Tobin Ehlis7d965da2016-09-19 16:15:45 -060013389
Tony Barbour552f6c02016-12-21 14:34:07 -070013390 m_commandBuffer->BeginCommandBuffer();
13391 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis7d965da2016-09-19 16:15:45 -060013392 // Bind pipeline to cmd buffer
13393 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
13394 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
13395 &descriptor_set, 0, nullptr);
Rene Lindsaya8880622017-01-18 13:12:59 -070013396
13397 VkViewport viewport = {0, 0, 16, 16, 0, 1};
13398 VkRect2D scissor = {{0, 0}, {16, 16}};
13399 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
13400 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
13401
Tobin Ehlis7d965da2016-09-19 16:15:45 -060013402 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070013403 m_commandBuffer->EndRenderPass();
13404 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis7d965da2016-09-19 16:15:45 -060013405 // Submit cmd buffer then destroy sampler
13406 VkSubmitInfo submit_info = {};
13407 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
13408 submit_info.commandBufferCount = 1;
13409 submit_info.pCommandBuffers = &m_commandBuffer->handle();
13410 // Submit cmd buffer and then destroy imageView while in-flight
13411 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
13412
13413 vkDestroyImageView(m_device->device(), view, nullptr);
13414 m_errorMonitor->VerifyFound();
13415 vkQueueWaitIdle(m_device->m_queue);
13416 // Now we can actually destroy imageView
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070013417 m_errorMonitor->SetUnexpectedError("If imageView is not VK_NULL_HANDLE, imageView must be a valid VkImageView handle");
Mark Lobodzinski74597792017-04-11 15:43:49 -060013418 m_errorMonitor->SetUnexpectedError("Unable to remove ImageView obj");
Tobin Ehlis7d965da2016-09-19 16:15:45 -060013419 vkDestroyImageView(m_device->device(), view, NULL);
13420 vkDestroySampler(m_device->device(), sampler, nullptr);
13421 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
13422 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
13423 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
13424}
13425
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060013426TEST_F(VkLayerTest, BufferViewInUseDestroyedSignaled) {
13427 TEST_DESCRIPTION("Delete in-use bufferView.");
13428
Tony Barbour1fa09702017-03-16 12:09:08 -060013429 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060013430 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13431
13432 VkDescriptorPoolSize ds_type_count;
13433 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
13434 ds_type_count.descriptorCount = 1;
13435
13436 VkDescriptorPoolCreateInfo ds_pool_ci = {};
13437 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
13438 ds_pool_ci.maxSets = 1;
13439 ds_pool_ci.poolSizeCount = 1;
13440 ds_pool_ci.pPoolSizes = &ds_type_count;
13441
13442 VkDescriptorPool ds_pool;
13443 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
13444 ASSERT_VK_SUCCESS(err);
13445
13446 VkDescriptorSetLayoutBinding layout_binding;
13447 layout_binding.binding = 0;
13448 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
13449 layout_binding.descriptorCount = 1;
13450 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
13451 layout_binding.pImmutableSamplers = NULL;
13452
13453 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
13454 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
13455 ds_layout_ci.bindingCount = 1;
13456 ds_layout_ci.pBindings = &layout_binding;
13457 VkDescriptorSetLayout ds_layout;
13458 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
13459 ASSERT_VK_SUCCESS(err);
13460
13461 VkDescriptorSetAllocateInfo alloc_info = {};
13462 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
13463 alloc_info.descriptorSetCount = 1;
13464 alloc_info.descriptorPool = ds_pool;
13465 alloc_info.pSetLayouts = &ds_layout;
13466 VkDescriptorSet descriptor_set;
13467 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
13468 ASSERT_VK_SUCCESS(err);
13469
13470 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
13471 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13472 pipeline_layout_ci.pNext = NULL;
13473 pipeline_layout_ci.setLayoutCount = 1;
13474 pipeline_layout_ci.pSetLayouts = &ds_layout;
13475
13476 VkPipelineLayout pipeline_layout;
13477 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
13478 ASSERT_VK_SUCCESS(err);
13479
13480 VkBuffer buffer;
13481 uint32_t queue_family_index = 0;
13482 VkBufferCreateInfo buffer_create_info = {};
13483 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
13484 buffer_create_info.size = 1024;
13485 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
13486 buffer_create_info.queueFamilyIndexCount = 1;
13487 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
13488
13489 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
13490 ASSERT_VK_SUCCESS(err);
13491
13492 VkMemoryRequirements memory_reqs;
13493 VkDeviceMemory buffer_memory;
13494
13495 VkMemoryAllocateInfo memory_info = {};
13496 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
13497 memory_info.allocationSize = 0;
13498 memory_info.memoryTypeIndex = 0;
13499
13500 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
13501 memory_info.allocationSize = memory_reqs.size;
13502 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
13503 ASSERT_TRUE(pass);
13504
13505 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
13506 ASSERT_VK_SUCCESS(err);
13507 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
13508 ASSERT_VK_SUCCESS(err);
13509
13510 VkBufferView view;
13511 VkBufferViewCreateInfo bvci = {};
13512 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
13513 bvci.buffer = buffer;
13514 bvci.format = VK_FORMAT_R8_UNORM;
13515 bvci.range = VK_WHOLE_SIZE;
13516
13517 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
13518 ASSERT_VK_SUCCESS(err);
13519
13520 VkWriteDescriptorSet descriptor_write = {};
13521 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
13522 descriptor_write.dstSet = descriptor_set;
13523 descriptor_write.dstBinding = 0;
13524 descriptor_write.descriptorCount = 1;
13525 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
13526 descriptor_write.pTexelBufferView = &view;
13527
13528 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
13529
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013530 char const *vsSource =
13531 "#version 450\n"
13532 "\n"
13533 "out gl_PerVertex { \n"
13534 " vec4 gl_Position;\n"
13535 "};\n"
13536 "void main(){\n"
13537 " gl_Position = vec4(1);\n"
13538 "}\n";
13539 char const *fsSource =
13540 "#version 450\n"
13541 "\n"
13542 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
13543 "layout(location=0) out vec4 x;\n"
13544 "void main(){\n"
13545 " x = imageLoad(s, 0);\n"
13546 "}\n";
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060013547 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13548 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13549 VkPipelineObj pipe(m_device);
13550 pipe.AddShader(&vs);
13551 pipe.AddShader(&fs);
13552 pipe.AddColorAttachment();
13553 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13554
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070013555 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00701);
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060013556
Tony Barbour552f6c02016-12-21 14:34:07 -070013557 m_commandBuffer->BeginCommandBuffer();
13558 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060013559 VkViewport viewport = {0, 0, 16, 16, 0, 1};
13560 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
13561 VkRect2D scissor = {{0, 0}, {16, 16}};
13562 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
13563 // Bind pipeline to cmd buffer
13564 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
13565 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
13566 &descriptor_set, 0, nullptr);
13567 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070013568 m_commandBuffer->EndRenderPass();
13569 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060013570
13571 VkSubmitInfo submit_info = {};
13572 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
13573 submit_info.commandBufferCount = 1;
13574 submit_info.pCommandBuffers = &m_commandBuffer->handle();
13575 // Submit cmd buffer and then destroy bufferView while in-flight
13576 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
13577
13578 vkDestroyBufferView(m_device->device(), view, nullptr);
13579 m_errorMonitor->VerifyFound();
13580 vkQueueWaitIdle(m_device->m_queue);
13581 // Now we can actually destroy bufferView
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070013582 m_errorMonitor->SetUnexpectedError("If bufferView is not VK_NULL_HANDLE, bufferView must be a valid VkBufferView handle");
Mark Lobodzinski74597792017-04-11 15:43:49 -060013583 m_errorMonitor->SetUnexpectedError("Unable to remove BufferView obj");
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060013584 vkDestroyBufferView(m_device->device(), view, NULL);
13585 vkDestroyBuffer(m_device->device(), buffer, NULL);
13586 vkFreeMemory(m_device->device(), buffer_memory, NULL);
13587 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
13588 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
13589 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
13590}
13591
Tobin Ehlis209532e2016-09-07 13:52:18 -060013592TEST_F(VkLayerTest, SamplerInUseDestroyedSignaled) {
13593 TEST_DESCRIPTION("Delete in-use sampler.");
13594
Tony Barbour1fa09702017-03-16 12:09:08 -060013595 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis209532e2016-09-07 13:52:18 -060013596 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13597
13598 VkDescriptorPoolSize ds_type_count;
13599 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
13600 ds_type_count.descriptorCount = 1;
13601
13602 VkDescriptorPoolCreateInfo ds_pool_ci = {};
13603 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
13604 ds_pool_ci.maxSets = 1;
13605 ds_pool_ci.poolSizeCount = 1;
13606 ds_pool_ci.pPoolSizes = &ds_type_count;
13607
13608 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013609 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis209532e2016-09-07 13:52:18 -060013610 ASSERT_VK_SUCCESS(err);
13611
13612 VkSamplerCreateInfo sampler_ci = {};
13613 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
13614 sampler_ci.pNext = NULL;
13615 sampler_ci.magFilter = VK_FILTER_NEAREST;
13616 sampler_ci.minFilter = VK_FILTER_NEAREST;
13617 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
13618 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
13619 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
13620 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
13621 sampler_ci.mipLodBias = 1.0;
13622 sampler_ci.anisotropyEnable = VK_FALSE;
13623 sampler_ci.maxAnisotropy = 1;
13624 sampler_ci.compareEnable = VK_FALSE;
13625 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
13626 sampler_ci.minLod = 1.0;
13627 sampler_ci.maxLod = 1.0;
13628 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
13629 sampler_ci.unnormalizedCoordinates = VK_FALSE;
13630 VkSampler sampler;
13631
13632 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
13633 ASSERT_VK_SUCCESS(err);
13634
13635 VkDescriptorSetLayoutBinding layout_binding;
13636 layout_binding.binding = 0;
Tobin Ehlis94fc0ad2016-09-19 16:23:01 -060013637 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
Tobin Ehlis209532e2016-09-07 13:52:18 -060013638 layout_binding.descriptorCount = 1;
13639 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
13640 layout_binding.pImmutableSamplers = NULL;
13641
13642 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
13643 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
13644 ds_layout_ci.bindingCount = 1;
13645 ds_layout_ci.pBindings = &layout_binding;
13646 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013647 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060013648 ASSERT_VK_SUCCESS(err);
13649
13650 VkDescriptorSetAllocateInfo alloc_info = {};
13651 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
13652 alloc_info.descriptorSetCount = 1;
13653 alloc_info.descriptorPool = ds_pool;
13654 alloc_info.pSetLayouts = &ds_layout;
13655 VkDescriptorSet descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013656 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis209532e2016-09-07 13:52:18 -060013657 ASSERT_VK_SUCCESS(err);
13658
13659 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
13660 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13661 pipeline_layout_ci.pNext = NULL;
13662 pipeline_layout_ci.setLayoutCount = 1;
13663 pipeline_layout_ci.pSetLayouts = &ds_layout;
13664
13665 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013666 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060013667 ASSERT_VK_SUCCESS(err);
13668
13669 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060013670 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 -060013671 ASSERT_TRUE(image.initialized());
13672
13673 VkImageView view;
13674 VkImageViewCreateInfo ivci = {};
13675 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
13676 ivci.image = image.handle();
13677 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
13678 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
13679 ivci.subresourceRange.layerCount = 1;
13680 ivci.subresourceRange.baseMipLevel = 0;
13681 ivci.subresourceRange.levelCount = 1;
13682 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
13683
13684 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
13685 ASSERT_VK_SUCCESS(err);
13686
13687 VkDescriptorImageInfo image_info{};
13688 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
13689 image_info.imageView = view;
13690 image_info.sampler = sampler;
13691
13692 VkWriteDescriptorSet descriptor_write = {};
13693 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
13694 descriptor_write.dstSet = descriptor_set;
13695 descriptor_write.dstBinding = 0;
13696 descriptor_write.descriptorCount = 1;
13697 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
13698 descriptor_write.pImageInfo = &image_info;
13699
13700 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
13701
13702 // Create PSO to use the sampler
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013703 char const *vsSource =
13704 "#version 450\n"
13705 "\n"
13706 "out gl_PerVertex { \n"
13707 " vec4 gl_Position;\n"
13708 "};\n"
13709 "void main(){\n"
13710 " gl_Position = vec4(1);\n"
13711 "}\n";
13712 char const *fsSource =
13713 "#version 450\n"
13714 "\n"
13715 "layout(set=0, binding=0) uniform sampler2D s;\n"
13716 "layout(location=0) out vec4 x;\n"
13717 "void main(){\n"
13718 " x = texture(s, vec2(1));\n"
13719 "}\n";
Tobin Ehlis209532e2016-09-07 13:52:18 -060013720 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13721 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13722 VkPipelineObj pipe(m_device);
13723 pipe.AddShader(&vs);
13724 pipe.AddShader(&fs);
13725 pipe.AddColorAttachment();
13726 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13727
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070013728 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00837);
Tobin Ehlis209532e2016-09-07 13:52:18 -060013729
Tony Barbour552f6c02016-12-21 14:34:07 -070013730 m_commandBuffer->BeginCommandBuffer();
13731 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis209532e2016-09-07 13:52:18 -060013732 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013733 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
13734 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
13735 &descriptor_set, 0, nullptr);
Rene Lindsay4da11732017-01-13 14:42:10 -070013736
13737 VkViewport viewport = {0, 0, 16, 16, 0, 1};
13738 VkRect2D scissor = {{0, 0}, {16, 16}};
13739 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
13740 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
13741
Tobin Ehlis209532e2016-09-07 13:52:18 -060013742 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070013743 m_commandBuffer->EndRenderPass();
13744 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis209532e2016-09-07 13:52:18 -060013745 // Submit cmd buffer then destroy sampler
13746 VkSubmitInfo submit_info = {};
13747 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
13748 submit_info.commandBufferCount = 1;
13749 submit_info.pCommandBuffers = &m_commandBuffer->handle();
13750 // Submit cmd buffer and then destroy sampler while in-flight
13751 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
13752
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013753 vkDestroySampler(m_device->device(), sampler, nullptr); // Destroyed too soon
Tobin Ehlis209532e2016-09-07 13:52:18 -060013754 m_errorMonitor->VerifyFound();
13755 vkQueueWaitIdle(m_device->m_queue);
Rene Lindsay4da11732017-01-13 14:42:10 -070013756
Tobin Ehlis209532e2016-09-07 13:52:18 -060013757 // Now we can actually destroy sampler
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070013758 m_errorMonitor->SetUnexpectedError("If sampler is not VK_NULL_HANDLE, sampler must be a valid VkSampler handle");
13759 m_errorMonitor->SetUnexpectedError("Unable to remove Sampler obj");
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013760 vkDestroySampler(m_device->device(), sampler, NULL); // Destroyed for real
Tobin Ehlis209532e2016-09-07 13:52:18 -060013761 vkDestroyImageView(m_device->device(), view, NULL);
13762 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
13763 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
13764 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
13765}
13766
Mark Mueller1cd9f412016-08-25 13:23:52 -060013767TEST_F(VkLayerTest, QueueForwardProgressFenceWait) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013768 TEST_DESCRIPTION(
13769 "Call VkQueueSubmit with a semaphore that is already "
13770 "signaled but not waited on by the queue. Wait on a "
13771 "fence that has not yet been submitted to a queue.");
Mark Mueller96a56d52016-08-24 10:28:05 -060013772
Tony Barbour1fa09702017-03-16 12:09:08 -060013773 ASSERT_NO_FATAL_FAILURE(Init());
Mark Mueller96a56d52016-08-24 10:28:05 -060013774 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13775
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013776 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 -070013777 const char *invalid_fence_wait_message =
13778 " which has not been submitted on a Queue or during "
13779 "acquire next image.";
Mark Mueller96a56d52016-08-24 10:28:05 -060013780
Tony Barbour552f6c02016-12-21 14:34:07 -070013781 m_commandBuffer->BeginCommandBuffer();
13782 m_commandBuffer->EndCommandBuffer();
Mark Mueller96a56d52016-08-24 10:28:05 -060013783
13784 VkSemaphoreCreateInfo semaphore_create_info = {};
13785 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
13786 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013787 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller96a56d52016-08-24 10:28:05 -060013788 VkSubmitInfo submit_info = {};
13789 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
13790 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013791 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller96a56d52016-08-24 10:28:05 -060013792 submit_info.signalSemaphoreCount = 1;
13793 submit_info.pSignalSemaphores = &semaphore;
13794 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Dave Houltonfbf52152017-01-06 12:55:29 -070013795 m_errorMonitor->ExpectSuccess(0);
Mark Mueller96a56d52016-08-24 10:28:05 -060013796 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
Dave Houltonfbf52152017-01-06 12:55:29 -070013797 m_errorMonitor->VerifyNotFound();
Tony Barbour552f6c02016-12-21 14:34:07 -070013798 m_commandBuffer->BeginCommandBuffer();
13799 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013800 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, queue_forward_progress_message);
Mark Mueller96a56d52016-08-24 10:28:05 -060013801 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
13802 m_errorMonitor->VerifyFound();
13803
Mark Mueller1cd9f412016-08-25 13:23:52 -060013804 VkFenceCreateInfo fence_create_info = {};
13805 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
13806 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013807 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller1cd9f412016-08-25 13:23:52 -060013808
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013809 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, invalid_fence_wait_message);
Mark Mueller1cd9f412016-08-25 13:23:52 -060013810 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
13811 m_errorMonitor->VerifyFound();
13812
Mark Mueller4042b652016-09-05 22:52:21 -060013813 vkDeviceWaitIdle(m_device->device());
Mark Mueller1cd9f412016-08-25 13:23:52 -060013814 vkDestroyFence(m_device->device(), fence, nullptr);
Mark Mueller96a56d52016-08-24 10:28:05 -060013815 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
13816}
13817
Tobin Ehlis4af23302016-07-19 10:50:30 -060013818TEST_F(VkLayerTest, FramebufferIncompatible) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013819 TEST_DESCRIPTION(
13820 "Bind a secondary command buffer with with a framebuffer "
13821 "that does not match the framebuffer for the active "
13822 "renderpass.");
Tony Barbour1fa09702017-03-16 12:09:08 -060013823 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis4af23302016-07-19 10:50:30 -060013824 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13825
13826 // A renderpass with one color attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013827 VkAttachmentDescription attachment = {0,
13828 VK_FORMAT_B8G8R8A8_UNORM,
13829 VK_SAMPLE_COUNT_1_BIT,
13830 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
13831 VK_ATTACHMENT_STORE_OP_STORE,
13832 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
13833 VK_ATTACHMENT_STORE_OP_DONT_CARE,
13834 VK_IMAGE_LAYOUT_UNDEFINED,
13835 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013836
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013837 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013838
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013839 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013840
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013841 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013842
13843 VkRenderPass rp;
13844 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
13845 ASSERT_VK_SUCCESS(err);
13846
13847 // A compatible framebuffer.
13848 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060013849 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 -060013850 ASSERT_TRUE(image.initialized());
13851
13852 VkImageViewCreateInfo ivci = {
13853 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
13854 nullptr,
13855 0,
13856 image.handle(),
13857 VK_IMAGE_VIEW_TYPE_2D,
13858 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013859 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
13860 VK_COMPONENT_SWIZZLE_IDENTITY},
Tobin Ehlis4af23302016-07-19 10:50:30 -060013861 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
13862 };
13863 VkImageView view;
13864 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
13865 ASSERT_VK_SUCCESS(err);
13866
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013867 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013868 VkFramebuffer fb;
13869 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
13870 ASSERT_VK_SUCCESS(err);
13871
13872 VkCommandBufferAllocateInfo cbai = {};
13873 cbai.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mike Schuchardt06304c22017-03-01 17:09:09 -070013874 cbai.commandPool = m_commandPool->handle();
Tobin Ehlis4af23302016-07-19 10:50:30 -060013875 cbai.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
13876 cbai.commandBufferCount = 1;
13877
13878 VkCommandBuffer sec_cb;
13879 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &sec_cb);
13880 ASSERT_VK_SUCCESS(err);
13881 VkCommandBufferBeginInfo cbbi = {};
13882 VkCommandBufferInheritanceInfo cbii = {};
Chris Forbes98420382016-11-28 17:56:51 +130013883 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Tobin Ehlis4af23302016-07-19 10:50:30 -060013884 cbii.renderPass = renderPass();
13885 cbii.framebuffer = fb;
13886 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
13887 cbbi.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013888 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 -060013889 cbbi.pInheritanceInfo = &cbii;
13890 vkBeginCommandBuffer(sec_cb, &cbbi);
13891 vkEndCommandBuffer(sec_cb);
13892
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013893 VkCommandBufferBeginInfo cbbi2 = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, 0, nullptr};
Chris Forbes3400bc52016-09-13 18:10:34 +120013894 vkBeginCommandBuffer(m_commandBuffer->GetBufferHandle(), &cbbi2);
13895 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Tobin Ehlis4af23302016-07-19 10:50:30 -060013896
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013897 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060013898 " that is not the same as the primary command buffer's current active framebuffer ");
Tobin Ehlis4af23302016-07-19 10:50:30 -060013899 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &sec_cb);
13900 m_errorMonitor->VerifyFound();
13901 // Cleanup
13902 vkDestroyImageView(m_device->device(), view, NULL);
13903 vkDestroyRenderPass(m_device->device(), rp, NULL);
13904 vkDestroyFramebuffer(m_device->device(), fb, NULL);
13905}
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013906
13907TEST_F(VkLayerTest, ColorBlendLogicOpTests) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013908 TEST_DESCRIPTION(
13909 "If logicOp is available on the device, set it to an "
13910 "invalid value. If logicOp is not available, attempt to "
13911 "use it and verify that we see the correct error.");
Tony Barbour1fa09702017-03-16 12:09:08 -060013912 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013913 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13914
13915 auto features = m_device->phy().features();
13916 // Set the expected error depending on whether or not logicOp available
13917 if (VK_FALSE == features.logicOp) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013918 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13919 "If logic operations feature not "
13920 "enabled, logicOpEnable must be "
13921 "VK_FALSE");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013922 } else {
Chris Forbes34797bc2016-10-03 15:28:49 +130013923 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "pColorBlendState->logicOp (16)");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013924 }
13925 // Create a pipeline using logicOp
13926 VkResult err;
13927
13928 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
13929 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13930
13931 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013932 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013933 ASSERT_VK_SUCCESS(err);
13934
13935 VkPipelineViewportStateCreateInfo vp_state_ci = {};
13936 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
13937 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013938 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013939 vp_state_ci.pViewports = &vp;
13940 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013941 VkRect2D scissors = {}; // Dummy scissors to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013942 vp_state_ci.pScissors = &scissors;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013943
13944 VkPipelineShaderStageCreateInfo shaderStages[2];
13945 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
13946
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013947 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
13948 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013949 shaderStages[0] = vs.GetStageCreateInfo();
13950 shaderStages[1] = fs.GetStageCreateInfo();
13951
13952 VkPipelineVertexInputStateCreateInfo vi_ci = {};
13953 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
13954
13955 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
13956 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
13957 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
13958
13959 VkPipelineRasterizationStateCreateInfo rs_ci = {};
13960 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbes14088512016-10-03 14:28:00 +130013961 rs_ci.lineWidth = 1.0f;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013962
13963 VkPipelineColorBlendAttachmentState att = {};
13964 att.blendEnable = VK_FALSE;
13965 att.colorWriteMask = 0xf;
13966
13967 VkPipelineColorBlendStateCreateInfo cb_ci = {};
13968 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
13969 // Enable logicOp & set logicOp to value 1 beyond allowed entries
13970 cb_ci.logicOpEnable = VK_TRUE;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013971 cb_ci.logicOp = VK_LOGIC_OP_RANGE_SIZE; // This should cause an error
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013972 cb_ci.attachmentCount = 1;
13973 cb_ci.pAttachments = &att;
13974
Chris Forbes8aeacbf2016-10-03 14:25:08 +130013975 VkPipelineMultisampleStateCreateInfo ms_ci = {};
13976 ms_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
13977 ms_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
13978
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013979 VkGraphicsPipelineCreateInfo gp_ci = {};
13980 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
13981 gp_ci.stageCount = 2;
13982 gp_ci.pStages = shaderStages;
13983 gp_ci.pVertexInputState = &vi_ci;
13984 gp_ci.pInputAssemblyState = &ia_ci;
13985 gp_ci.pViewportState = &vp_state_ci;
13986 gp_ci.pRasterizationState = &rs_ci;
13987 gp_ci.pColorBlendState = &cb_ci;
Chris Forbes8aeacbf2016-10-03 14:25:08 +130013988 gp_ci.pMultisampleState = &ms_ci;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013989 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
13990 gp_ci.layout = pipeline_layout;
13991 gp_ci.renderPass = renderPass();
13992
13993 VkPipelineCacheCreateInfo pc_ci = {};
13994 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
13995
13996 VkPipeline pipeline;
13997 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013998 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013999 ASSERT_VK_SUCCESS(err);
14000
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014001 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060014002 m_errorMonitor->VerifyFound();
14003 if (VK_SUCCESS == err) {
14004 vkDestroyPipeline(m_device->device(), pipeline, NULL);
14005 }
Tobin Ehlis52b504f2016-07-19 13:25:12 -060014006 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
14007 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
14008}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060014009
Mike Stroyanaccf7692015-05-12 16:00:45 -060014010#if GTEST_IS_THREADSAFE
14011struct thread_data_struct {
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014012 VkCommandBuffer commandBuffer;
Mike Stroyanca855662017-05-02 11:06:27 -060014013 VkDevice device;
Mike Stroyanaccf7692015-05-12 16:00:45 -060014014 VkEvent event;
14015 bool bailout;
14016};
14017
Karl Schultz6addd812016-02-02 17:17:23 -070014018extern "C" void *AddToCommandBuffer(void *arg) {
14019 struct thread_data_struct *data = (struct thread_data_struct *)arg;
Mike Stroyanaccf7692015-05-12 16:00:45 -060014020
Mike Stroyana6d14942016-07-13 15:10:05 -060014021 for (int i = 0; i < 80000; i++) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014022 vkCmdSetEvent(data->commandBuffer, data->event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mike Stroyanaccf7692015-05-12 16:00:45 -060014023 if (data->bailout) {
14024 break;
14025 }
14026 }
14027 return NULL;
14028}
14029
Karl Schultz6addd812016-02-02 17:17:23 -070014030TEST_F(VkLayerTest, ThreadCommandBufferCollision) {
Mike Stroyan4268d1f2015-07-13 14:45:35 -060014031 test_platform_thread thread;
Mike Stroyanaccf7692015-05-12 16:00:45 -060014032
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014033 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "THREADING ERROR");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014034
Tony Barbour1fa09702017-03-16 12:09:08 -060014035 ASSERT_NO_FATAL_FAILURE(Init());
Mike Stroyanaccf7692015-05-12 16:00:45 -060014036 ASSERT_NO_FATAL_FAILURE(InitViewport());
14037 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14038
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014039 // Calls AllocateCommandBuffers
14040 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060014041
14042 // Avoid creating RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014043 commandBuffer.BeginCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060014044
14045 VkEventCreateInfo event_info;
14046 VkEvent event;
Mike Stroyanaccf7692015-05-12 16:00:45 -060014047 VkResult err;
14048
14049 memset(&event_info, 0, sizeof(event_info));
14050 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
14051
Chia-I Wuf7458c52015-10-26 21:10:41 +080014052 err = vkCreateEvent(device(), &event_info, NULL, &event);
Mike Stroyanaccf7692015-05-12 16:00:45 -060014053 ASSERT_VK_SUCCESS(err);
14054
Mike Stroyanaccf7692015-05-12 16:00:45 -060014055 err = vkResetEvent(device(), event);
14056 ASSERT_VK_SUCCESS(err);
14057
14058 struct thread_data_struct data;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014059 data.commandBuffer = commandBuffer.GetBufferHandle();
Mike Stroyanaccf7692015-05-12 16:00:45 -060014060 data.event = event;
14061 data.bailout = false;
14062 m_errorMonitor->SetBailout(&data.bailout);
Mike Stroyana6d14942016-07-13 15:10:05 -060014063
14064 // First do some correct operations using multiple threads.
14065 // Add many entries to command buffer from another thread.
14066 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
14067 // Make non-conflicting calls from this thread at the same time.
14068 for (int i = 0; i < 80000; i++) {
Mike Stroyand6343902016-07-14 08:56:16 -060014069 uint32_t count;
14070 vkEnumeratePhysicalDevices(instance(), &count, NULL);
Mike Stroyana6d14942016-07-13 15:10:05 -060014071 }
14072 test_platform_thread_join(thread, NULL);
14073
14074 // Then do some incorrect operations using multiple threads.
Mike Stroyanaccf7692015-05-12 16:00:45 -060014075 // Add many entries to command buffer from another thread.
Mike Stroyan4268d1f2015-07-13 14:45:35 -060014076 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyanaccf7692015-05-12 16:00:45 -060014077 // Add many entries to command buffer from this thread at the same time.
14078 AddToCommandBuffer(&data);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060014079
Mike Stroyan4268d1f2015-07-13 14:45:35 -060014080 test_platform_thread_join(thread, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014081 commandBuffer.EndCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060014082
Mike Stroyan10b8cb72016-01-22 15:22:03 -070014083 m_errorMonitor->SetBailout(NULL);
14084
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014085 m_errorMonitor->VerifyFound();
Mike Stroyanaccf7692015-05-12 16:00:45 -060014086
Chia-I Wuf7458c52015-10-26 21:10:41 +080014087 vkDestroyEvent(device(), event, NULL);
Mike Stroyanaccf7692015-05-12 16:00:45 -060014088}
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014089#endif // GTEST_IS_THREADSAFE
Mark Lobodzinski209b5292015-09-17 09:44:05 -060014090
Karl Schultz6addd812016-02-02 17:17:23 -070014091TEST_F(VkLayerTest, InvalidSPIRVCodeSize) {
Mark Lobodzinskid742b312017-05-09 16:26:27 -060014092 TEST_DESCRIPTION("Test that errors are produced for a spirv modules with invalid code sizes");
Chris Forbes1cc79542016-07-20 11:13:44 +120014093
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014094 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014095
Tony Barbour1fa09702017-03-16 12:09:08 -060014096 ASSERT_NO_FATAL_FAILURE(Init());
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014097 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14098
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014099 VkShaderModule module;
14100 VkShaderModuleCreateInfo moduleCreateInfo;
14101 struct icd_spv_header spv;
14102
14103 spv.magic = ICD_SPV_MAGIC;
14104 spv.version = ICD_SPV_VERSION;
14105 spv.gen_magic = 0;
14106
14107 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
14108 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070014109 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014110 moduleCreateInfo.codeSize = 4;
14111 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080014112 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014113
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014114 m_errorMonitor->VerifyFound();
Mark Lobodzinskid742b312017-05-09 16:26:27 -060014115
14116 char const *vsSource =
14117 "#version 450\n"
14118 "\n"
14119 "layout(location=0) out float x;\n"
14120 "out gl_PerVertex {\n"
14121 " vec4 gl_Position;\n"
14122 "};\n"
14123 "void main(){\n"
14124 " gl_Position = vec4(1);\n"
14125 " x = 0;\n"
14126 "}\n";
14127
14128 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02816);
14129 std::vector<unsigned int> shader;
14130 VkShaderModuleCreateInfo module_create_info;
14131 VkShaderModule shader_module;
14132 module_create_info.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
14133 module_create_info.pNext = NULL;
14134 this->GLSLtoSPV(VK_SHADER_STAGE_VERTEX_BIT, vsSource, shader);
14135 module_create_info.pCode = shader.data();
14136 // Introduce failure by making codeSize a non-multiple of 4
14137 module_create_info.codeSize = shader.size() * sizeof(unsigned int) - 1;
14138 module_create_info.flags = 0;
14139 vkCreateShaderModule(m_device->handle(), &module_create_info, NULL, &shader_module);
14140
14141 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014142}
14143
Karl Schultz6addd812016-02-02 17:17:23 -070014144TEST_F(VkLayerTest, InvalidSPIRVMagic) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014145 TEST_DESCRIPTION(
14146 "Test that an error is produced for a spirv module "
14147 "with a bad magic number");
Chris Forbes1cc79542016-07-20 11:13:44 +120014148
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014149 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V magic number");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014150
Tony Barbour1fa09702017-03-16 12:09:08 -060014151 ASSERT_NO_FATAL_FAILURE(Init());
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014152 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14153
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014154 VkShaderModule module;
14155 VkShaderModuleCreateInfo moduleCreateInfo;
14156 struct icd_spv_header spv;
14157
14158 spv.magic = ~ICD_SPV_MAGIC;
14159 spv.version = ICD_SPV_VERSION;
14160 spv.gen_magic = 0;
14161
14162 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
14163 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070014164 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Mark Lobodzinskid742b312017-05-09 16:26:27 -060014165 moduleCreateInfo.codeSize = sizeof(spv) + 16;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014166 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080014167 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014168
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014169 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014170}
14171
Chris Forbesb4afd0f2016-04-04 10:48:35 +120014172#if 0
14173// Not currently covered by SPIRV-Tools validator
Karl Schultz6addd812016-02-02 17:17:23 -070014174TEST_F(VkLayerTest, InvalidSPIRVVersion) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070014175 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +120014176 "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014177
Tony Barbour1fa09702017-03-16 12:09:08 -060014178 ASSERT_NO_FATAL_FAILURE(Init());
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014179 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14180
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014181 VkShaderModule module;
14182 VkShaderModuleCreateInfo moduleCreateInfo;
14183 struct icd_spv_header spv;
14184
14185 spv.magic = ICD_SPV_MAGIC;
14186 spv.version = ~ICD_SPV_VERSION;
14187 spv.gen_magic = 0;
14188
14189 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
14190 moduleCreateInfo.pNext = NULL;
14191
Karl Schultz6addd812016-02-02 17:17:23 -070014192 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014193 moduleCreateInfo.codeSize = sizeof(spv) + 10;
14194 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080014195 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014196
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014197 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014198}
Chris Forbesb4afd0f2016-04-04 10:48:35 +120014199#endif
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014200
Karl Schultz6addd812016-02-02 17:17:23 -070014201TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014202 TEST_DESCRIPTION(
14203 "Test that a warning is produced for a vertex output that "
14204 "is not consumed by the fragment stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014205 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "not consumed by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014206
Tony Barbour1fa09702017-03-16 12:09:08 -060014207 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014208 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes9f7ff632015-05-25 11:13:08 +120014209
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014210 char const *vsSource =
14211 "#version 450\n"
14212 "\n"
14213 "layout(location=0) out float x;\n"
14214 "out gl_PerVertex {\n"
14215 " vec4 gl_Position;\n"
14216 "};\n"
14217 "void main(){\n"
14218 " gl_Position = vec4(1);\n"
14219 " x = 0;\n"
14220 "}\n";
14221 char const *fsSource =
14222 "#version 450\n"
14223 "\n"
14224 "layout(location=0) out vec4 color;\n"
14225 "void main(){\n"
14226 " color = vec4(1);\n"
14227 "}\n";
Chris Forbes9f7ff632015-05-25 11:13:08 +120014228
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014229 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14230 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes9f7ff632015-05-25 11:13:08 +120014231
14232 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014233 pipe.AddColorAttachment();
Chris Forbes9f7ff632015-05-25 11:13:08 +120014234 pipe.AddShader(&vs);
14235 pipe.AddShader(&fs);
14236
Chris Forbes9f7ff632015-05-25 11:13:08 +120014237 VkDescriptorSetObj descriptorSet(m_device);
14238 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014239 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes9f7ff632015-05-25 11:13:08 +120014240
Tony Barbour5781e8f2015-08-04 16:23:11 -060014241 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes9f7ff632015-05-25 11:13:08 +120014242
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014243 m_errorMonitor->VerifyFound();
Chris Forbes9f7ff632015-05-25 11:13:08 +120014244}
Chris Forbes9f7ff632015-05-25 11:13:08 +120014245
Mark Mueller098c9cb2016-09-08 09:01:57 -060014246TEST_F(VkLayerTest, CreatePipelineCheckShaderBadSpecialization) {
14247 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
14248
Tony Barbour1fa09702017-03-16 12:09:08 -060014249 ASSERT_NO_FATAL_FAILURE(Init());
Mark Mueller098c9cb2016-09-08 09:01:57 -060014250 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14251
14252 const char *bad_specialization_message =
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014253 "Specialization entry 0 (for constant id 0) references memory outside provided specialization data ";
Mark Mueller098c9cb2016-09-08 09:01:57 -060014254
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014255 char const *vsSource =
14256 "#version 450\n"
14257 "\n"
14258 "out gl_PerVertex {\n"
14259 " vec4 gl_Position;\n"
14260 "};\n"
14261 "void main(){\n"
14262 " gl_Position = vec4(1);\n"
14263 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060014264
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014265 char const *fsSource =
14266 "#version 450\n"
14267 "\n"
14268 "layout (constant_id = 0) const float r = 0.0f;\n"
14269 "layout(location = 0) out vec4 uFragColor;\n"
14270 "void main(){\n"
14271 " uFragColor = vec4(r,1,0,1);\n"
14272 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060014273
14274 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14275 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14276
14277 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
14278 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
14279
14280 VkPipelineLayout pipeline_layout;
14281 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
14282
14283 VkPipelineViewportStateCreateInfo vp_state_create_info = {};
14284 vp_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
14285 vp_state_create_info.viewportCount = 1;
14286 VkViewport viewport = {};
14287 vp_state_create_info.pViewports = &viewport;
14288 vp_state_create_info.scissorCount = 1;
14289 VkRect2D scissors = {};
14290 vp_state_create_info.pScissors = &scissors;
14291
14292 VkDynamicState scissor_state = VK_DYNAMIC_STATE_SCISSOR;
14293
14294 VkPipelineDynamicStateCreateInfo pipeline_dynamic_state_create_info = {};
14295 pipeline_dynamic_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
14296 pipeline_dynamic_state_create_info.dynamicStateCount = 1;
14297 pipeline_dynamic_state_create_info.pDynamicStates = &scissor_state;
14298
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014299 VkPipelineShaderStageCreateInfo shader_stage_create_info[2] = {vs.GetStageCreateInfo(), fs.GetStageCreateInfo()};
Mark Mueller098c9cb2016-09-08 09:01:57 -060014300
14301 VkPipelineVertexInputStateCreateInfo vertex_input_create_info = {};
14302 vertex_input_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
14303
14304 VkPipelineInputAssemblyStateCreateInfo input_assembly_create_info = {};
14305 input_assembly_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
14306 input_assembly_create_info.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
14307
14308 VkPipelineRasterizationStateCreateInfo rasterization_state_create_info = {};
14309 rasterization_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
14310 rasterization_state_create_info.pNext = nullptr;
14311 rasterization_state_create_info.lineWidth = 1.0f;
14312 rasterization_state_create_info.rasterizerDiscardEnable = true;
14313
14314 VkPipelineColorBlendAttachmentState color_blend_attachment_state = {};
14315 color_blend_attachment_state.blendEnable = VK_FALSE;
14316 color_blend_attachment_state.colorWriteMask = 0xf;
14317
14318 VkPipelineColorBlendStateCreateInfo color_blend_state_create_info = {};
14319 color_blend_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
14320 color_blend_state_create_info.attachmentCount = 1;
14321 color_blend_state_create_info.pAttachments = &color_blend_attachment_state;
14322
14323 VkGraphicsPipelineCreateInfo graphicspipe_create_info = {};
14324 graphicspipe_create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
14325 graphicspipe_create_info.stageCount = 2;
14326 graphicspipe_create_info.pStages = shader_stage_create_info;
14327 graphicspipe_create_info.pVertexInputState = &vertex_input_create_info;
14328 graphicspipe_create_info.pInputAssemblyState = &input_assembly_create_info;
14329 graphicspipe_create_info.pViewportState = &vp_state_create_info;
14330 graphicspipe_create_info.pRasterizationState = &rasterization_state_create_info;
14331 graphicspipe_create_info.pColorBlendState = &color_blend_state_create_info;
14332 graphicspipe_create_info.pDynamicState = &pipeline_dynamic_state_create_info;
14333 graphicspipe_create_info.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
14334 graphicspipe_create_info.layout = pipeline_layout;
14335 graphicspipe_create_info.renderPass = renderPass();
14336
14337 VkPipelineCacheCreateInfo pipeline_cache_create_info = {};
14338 pipeline_cache_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
14339
14340 VkPipelineCache pipelineCache;
14341 ASSERT_VK_SUCCESS(vkCreatePipelineCache(m_device->device(), &pipeline_cache_create_info, nullptr, &pipelineCache));
14342
14343 // This structure maps constant ids to data locations.
14344 const VkSpecializationMapEntry entry =
14345 // id, offset, size
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014346 {0, 4, sizeof(uint32_t)}; // Challenge core validation by using a bogus offset.
Mark Mueller098c9cb2016-09-08 09:01:57 -060014347
14348 uint32_t data = 1;
14349
14350 // Set up the info describing spec map and data
14351 const VkSpecializationInfo specialization_info = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014352 1, &entry, 1 * sizeof(float), &data,
Mark Mueller098c9cb2016-09-08 09:01:57 -060014353 };
14354 shader_stage_create_info[0].pSpecializationInfo = &specialization_info;
14355
14356 VkPipeline pipeline;
14357 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_specialization_message);
14358 vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &graphicspipe_create_info, nullptr, &pipeline);
14359 m_errorMonitor->VerifyFound();
14360
14361 vkDestroyPipelineCache(m_device->device(), pipelineCache, nullptr);
14362 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
14363}
14364
14365TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorTypeMismatch) {
14366 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
14367
Tony Barbour1fa09702017-03-16 12:09:08 -060014368 ASSERT_NO_FATAL_FAILURE(Init());
Mark Mueller098c9cb2016-09-08 09:01:57 -060014369 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14370
14371 const char *descriptor_type_mismatch_message = "Type mismatch on descriptor slot 0.0 (used as type ";
14372
14373 VkDescriptorPoolSize descriptor_pool_type_count[2] = {};
14374 descriptor_pool_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
14375 descriptor_pool_type_count[0].descriptorCount = 1;
14376 descriptor_pool_type_count[1].type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
14377 descriptor_pool_type_count[1].descriptorCount = 1;
14378
14379 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
14380 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
14381 descriptor_pool_create_info.maxSets = 1;
14382 descriptor_pool_create_info.poolSizeCount = 2;
14383 descriptor_pool_create_info.pPoolSizes = descriptor_pool_type_count;
14384 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
14385
14386 VkDescriptorPool descriptorset_pool;
14387 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
14388
14389 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
14390 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
14391 descriptorset_layout_binding.descriptorCount = 1;
14392 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
Cody Northropa6484fd2017-03-10 14:13:49 -070014393 descriptorset_layout_binding.pImmutableSamplers = nullptr;
Mark Mueller098c9cb2016-09-08 09:01:57 -060014394
14395 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
14396 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
14397 descriptorset_layout_create_info.bindingCount = 1;
14398 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
14399
14400 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014401 ASSERT_VK_SUCCESS(
14402 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller098c9cb2016-09-08 09:01:57 -060014403
14404 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
14405 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
14406 descriptorset_allocate_info.descriptorSetCount = 1;
14407 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
14408 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
14409 VkDescriptorSet descriptorset;
14410 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
14411
14412 // Challenge core_validation with a non uniform buffer type.
14413 VkBufferTest storage_buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT);
14414
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014415 char const *vsSource =
14416 "#version 450\n"
14417 "\n"
14418 "layout (std140, set = 0, binding = 0) uniform buf {\n"
14419 " mat4 mvp;\n"
14420 "} ubuf;\n"
14421 "out gl_PerVertex {\n"
14422 " vec4 gl_Position;\n"
14423 "};\n"
14424 "void main(){\n"
14425 " gl_Position = ubuf.mvp * vec4(1);\n"
14426 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060014427
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014428 char const *fsSource =
14429 "#version 450\n"
14430 "\n"
14431 "layout(location = 0) out vec4 uFragColor;\n"
14432 "void main(){\n"
14433 " uFragColor = vec4(0,1,0,1);\n"
14434 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060014435
14436 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14437 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14438
14439 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
14440 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
14441 pipeline_layout_create_info.setLayoutCount = 1;
14442 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
14443
14444 VkPipelineLayout pipeline_layout;
14445 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
14446
14447 VkPipelineObj pipe(m_device);
14448 pipe.AddColorAttachment();
14449 pipe.AddShader(&vs);
14450 pipe.AddShader(&fs);
14451
14452 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_type_mismatch_message);
14453 pipe.CreateVKPipeline(pipeline_layout, renderPass());
14454 m_errorMonitor->VerifyFound();
14455
14456 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
14457 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
14458 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
14459}
14460
14461TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorNotAccessible) {
14462 TEST_DESCRIPTION(
14463 "Create a pipeline in which a descriptor used by a shader stage does not include that stage in its stageFlags.");
14464
Tony Barbour1fa09702017-03-16 12:09:08 -060014465 ASSERT_NO_FATAL_FAILURE(Init());
Mark Mueller098c9cb2016-09-08 09:01:57 -060014466 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14467
14468 const char *descriptor_not_accessible_message = "Shader uses descriptor slot 0.0 (used as type ";
14469
14470 VkDescriptorPoolSize descriptor_pool_type_count = {};
14471 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
14472 descriptor_pool_type_count.descriptorCount = 1;
14473
14474 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
14475 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
14476 descriptor_pool_create_info.maxSets = 1;
14477 descriptor_pool_create_info.poolSizeCount = 1;
14478 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
14479 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
14480
14481 VkDescriptorPool descriptorset_pool;
14482 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
14483
14484 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
14485 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
14486 descriptorset_layout_binding.descriptorCount = 1;
14487 // Intentionally make the uniform buffer inaccessible to the vertex shader to challenge core_validation
14488 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
Cody Northropa6484fd2017-03-10 14:13:49 -070014489 descriptorset_layout_binding.pImmutableSamplers = nullptr;
Mark Mueller098c9cb2016-09-08 09:01:57 -060014490
14491 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
14492 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
14493 descriptorset_layout_create_info.bindingCount = 1;
14494 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
14495
14496 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014497 ASSERT_VK_SUCCESS(
14498 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller098c9cb2016-09-08 09:01:57 -060014499
14500 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
14501 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
14502 descriptorset_allocate_info.descriptorSetCount = 1;
14503 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
14504 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
14505 VkDescriptorSet descriptorset;
14506 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
14507
14508 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
14509
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014510 char const *vsSource =
14511 "#version 450\n"
14512 "\n"
14513 "layout (std140, set = 0, binding = 0) uniform buf {\n"
14514 " mat4 mvp;\n"
14515 "} ubuf;\n"
14516 "out gl_PerVertex {\n"
14517 " vec4 gl_Position;\n"
14518 "};\n"
14519 "void main(){\n"
14520 " gl_Position = ubuf.mvp * vec4(1);\n"
14521 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060014522
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014523 char const *fsSource =
14524 "#version 450\n"
14525 "\n"
14526 "layout(location = 0) out vec4 uFragColor;\n"
14527 "void main(){\n"
14528 " uFragColor = vec4(0,1,0,1);\n"
14529 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060014530
14531 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14532 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14533
14534 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
14535 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
14536 pipeline_layout_create_info.setLayoutCount = 1;
14537 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
14538
14539 VkPipelineLayout pipeline_layout;
14540 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
14541
14542 VkPipelineObj pipe(m_device);
14543 pipe.AddColorAttachment();
14544 pipe.AddShader(&vs);
14545 pipe.AddShader(&fs);
14546
14547 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_not_accessible_message);
14548 pipe.CreateVKPipeline(pipeline_layout, renderPass());
14549 m_errorMonitor->VerifyFound();
14550
14551 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
14552 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
14553 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
14554}
14555
14556TEST_F(VkLayerTest, CreatePipelineCheckShaderPushConstantNotAccessible) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014557 TEST_DESCRIPTION(
14558 "Create a graphics pipleine in which a push constant range containing a push constant block member is not "
14559 "accessible from the current shader stage.");
Mark Mueller098c9cb2016-09-08 09:01:57 -060014560
Tony Barbour1fa09702017-03-16 12:09:08 -060014561 ASSERT_NO_FATAL_FAILURE(Init());
Mark Mueller098c9cb2016-09-08 09:01:57 -060014562 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14563
14564 const char *push_constant_not_accessible_message =
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014565 "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 -060014566
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014567 char const *vsSource =
14568 "#version 450\n"
14569 "\n"
14570 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
14571 "out gl_PerVertex {\n"
14572 " vec4 gl_Position;\n"
14573 "};\n"
14574 "void main(){\n"
14575 " gl_Position = vec4(consts.x);\n"
14576 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060014577
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014578 char const *fsSource =
14579 "#version 450\n"
14580 "\n"
14581 "layout(location = 0) out vec4 uFragColor;\n"
14582 "void main(){\n"
14583 " uFragColor = vec4(0,1,0,1);\n"
14584 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060014585
14586 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14587 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14588
14589 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
14590 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
14591
14592 // Set up a push constant range
14593 VkPushConstantRange push_constant_ranges = {};
14594 // Set to the wrong stage to challenge core_validation
14595 push_constant_ranges.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
14596 push_constant_ranges.size = 4;
14597
14598 pipeline_layout_create_info.pPushConstantRanges = &push_constant_ranges;
14599 pipeline_layout_create_info.pushConstantRangeCount = 1;
14600
14601 VkPipelineLayout pipeline_layout;
14602 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
14603
14604 VkPipelineObj pipe(m_device);
14605 pipe.AddColorAttachment();
14606 pipe.AddShader(&vs);
14607 pipe.AddShader(&fs);
14608
14609 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, push_constant_not_accessible_message);
14610 pipe.CreateVKPipeline(pipeline_layout, renderPass());
14611 m_errorMonitor->VerifyFound();
14612
14613 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
14614}
14615
14616TEST_F(VkLayerTest, CreatePipelineCheckShaderNotEnabled) {
14617 TEST_DESCRIPTION(
14618 "Create a graphics pipeline in which a capability declared by the shader requires a feature not enabled on the device.");
14619
Tony Barbour1fa09702017-03-16 12:09:08 -060014620 ASSERT_NO_FATAL_FAILURE(Init());
Mark Mueller098c9cb2016-09-08 09:01:57 -060014621 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14622
14623 const char *feature_not_enabled_message =
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014624 "Shader requires VkPhysicalDeviceFeatures::shaderFloat64 but is not enabled on the device";
Mark Mueller098c9cb2016-09-08 09:01:57 -060014625
14626 // Some awkward steps are required to test with custom device features.
14627 std::vector<const char *> device_extension_names;
14628 auto features = m_device->phy().features();
14629 // Disable support for 64 bit floats
14630 features.shaderFloat64 = false;
14631 // The sacrificial device object
14632 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
14633
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014634 char const *vsSource =
14635 "#version 450\n"
14636 "\n"
14637 "out gl_PerVertex {\n"
14638 " vec4 gl_Position;\n"
14639 "};\n"
14640 "void main(){\n"
14641 " gl_Position = vec4(1);\n"
14642 "}\n";
14643 char const *fsSource =
14644 "#version 450\n"
14645 "\n"
14646 "layout(location=0) out vec4 color;\n"
14647 "void main(){\n"
14648 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
14649 " color = vec4(green);\n"
14650 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060014651
14652 VkShaderObj vs(&test_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14653 VkShaderObj fs(&test_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14654
14655 VkRenderpassObj render_pass(&test_device);
Mark Mueller098c9cb2016-09-08 09:01:57 -060014656
14657 VkPipelineObj pipe(&test_device);
14658 pipe.AddColorAttachment();
14659 pipe.AddShader(&vs);
14660 pipe.AddShader(&fs);
14661
14662 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
14663 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
14664 VkPipelineLayout pipeline_layout;
14665 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(test_device.device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
14666
14667 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, feature_not_enabled_message);
14668 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
14669 m_errorMonitor->VerifyFound();
14670
14671 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, nullptr);
14672}
14673
Mark Lobodzinski20832822017-03-24 14:49:45 -060014674TEST_F(VkLayerTest, CreateShaderModuleCheckBadCapability) {
14675 TEST_DESCRIPTION("Create a shader in which a capability declared by the shader is not supported.");
14676 // Note that this failure message comes from spirv-tools, specifically the validator.
Mark Mueller098c9cb2016-09-08 09:01:57 -060014677
Tony Barbour1fa09702017-03-16 12:09:08 -060014678 ASSERT_NO_FATAL_FAILURE(Init());
Mark Mueller098c9cb2016-09-08 09:01:57 -060014679 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14680
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014681 char const *vsSource =
14682 "#version 450\n"
14683 "\n"
14684 "out gl_PerVertex {\n"
14685 " vec4 gl_Position;\n"
14686 "};\n"
14687 "layout(xfb_buffer = 1) out;"
14688 "void main(){\n"
14689 " gl_Position = vec4(1);\n"
14690 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060014691
Mark Lobodzinski20832822017-03-24 14:49:45 -060014692 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Capability value 53 is not allowed by Vulkan");
Mark Mueller098c9cb2016-09-08 09:01:57 -060014693
Mark Lobodzinski20832822017-03-24 14:49:45 -060014694 std::vector<unsigned int> spv;
14695 VkShaderModuleCreateInfo module_create_info;
14696 VkShaderModule shader_module;
14697 module_create_info.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
14698 module_create_info.pNext = NULL;
14699 this->GLSLtoSPV(VK_SHADER_STAGE_VERTEX_BIT, vsSource, spv);
14700 module_create_info.pCode = spv.data();
14701 module_create_info.codeSize = spv.size() * sizeof(unsigned int);
14702 module_create_info.flags = 0;
Mark Mueller098c9cb2016-09-08 09:01:57 -060014703
Mark Lobodzinski20832822017-03-24 14:49:45 -060014704 vkCreateShaderModule(m_device->handle(), &module_create_info, NULL, &shader_module);
Mark Mueller098c9cb2016-09-08 09:01:57 -060014705
Mark Lobodzinski20832822017-03-24 14:49:45 -060014706 m_errorMonitor->VerifyFound();
Mark Mueller098c9cb2016-09-08 09:01:57 -060014707}
14708
Karl Schultz6addd812016-02-02 17:17:23 -070014709TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014710 TEST_DESCRIPTION(
14711 "Test that an error is produced for a fragment shader input "
14712 "which is not present in the outputs of the previous stage");
Chris Forbes1cc79542016-07-20 11:13:44 +120014713
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014714 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014715
Tony Barbour1fa09702017-03-16 12:09:08 -060014716 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014717 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes59cb88d2015-05-25 11:13:13 +120014718
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014719 char const *vsSource =
14720 "#version 450\n"
14721 "\n"
14722 "out gl_PerVertex {\n"
14723 " vec4 gl_Position;\n"
14724 "};\n"
14725 "void main(){\n"
14726 " gl_Position = vec4(1);\n"
14727 "}\n";
14728 char const *fsSource =
14729 "#version 450\n"
14730 "\n"
14731 "layout(location=0) in float x;\n"
14732 "layout(location=0) out vec4 color;\n"
14733 "void main(){\n"
14734 " color = vec4(x);\n"
14735 "}\n";
Chris Forbes59cb88d2015-05-25 11:13:13 +120014736
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014737 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14738 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes59cb88d2015-05-25 11:13:13 +120014739
14740 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014741 pipe.AddColorAttachment();
Chris Forbes59cb88d2015-05-25 11:13:13 +120014742 pipe.AddShader(&vs);
14743 pipe.AddShader(&fs);
14744
Chris Forbes59cb88d2015-05-25 11:13:13 +120014745 VkDescriptorSetObj descriptorSet(m_device);
14746 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014747 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes59cb88d2015-05-25 11:13:13 +120014748
Tony Barbour5781e8f2015-08-04 16:23:11 -060014749 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes59cb88d2015-05-25 11:13:13 +120014750
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014751 m_errorMonitor->VerifyFound();
Chris Forbes59cb88d2015-05-25 11:13:13 +120014752}
14753
Karl Schultz6addd812016-02-02 17:17:23 -070014754TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvidedInBlock) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014755 TEST_DESCRIPTION(
14756 "Test that an error is produced for a fragment shader input "
14757 "within an interace block, which is not present in the outputs "
14758 "of the previous stage.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014759 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Chris Forbesa3e85f62016-01-15 14:53:11 +130014760
Tony Barbour1fa09702017-03-16 12:09:08 -060014761 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbesa3e85f62016-01-15 14:53:11 +130014762 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14763
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014764 char const *vsSource =
14765 "#version 450\n"
14766 "\n"
14767 "out gl_PerVertex {\n"
14768 " vec4 gl_Position;\n"
14769 "};\n"
14770 "void main(){\n"
14771 " gl_Position = vec4(1);\n"
14772 "}\n";
14773 char const *fsSource =
14774 "#version 450\n"
14775 "\n"
14776 "in block { layout(location=0) float x; } ins;\n"
14777 "layout(location=0) out vec4 color;\n"
14778 "void main(){\n"
14779 " color = vec4(ins.x);\n"
14780 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130014781
14782 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14783 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14784
14785 VkPipelineObj pipe(m_device);
14786 pipe.AddColorAttachment();
14787 pipe.AddShader(&vs);
14788 pipe.AddShader(&fs);
14789
14790 VkDescriptorSetObj descriptorSet(m_device);
14791 descriptorSet.AppendDummy();
14792 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14793
14794 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14795
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014796 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130014797}
14798
Karl Schultz6addd812016-02-02 17:17:23 -070014799TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchArraySize) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014800 TEST_DESCRIPTION(
14801 "Test that an error is produced for mismatched array sizes "
14802 "across the vertex->fragment shader interface");
14803 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14804 "Type mismatch on location 0.0: 'ptr to "
14805 "output arr[2] of float32' vs 'ptr to "
14806 "input arr[1] of float32'");
Chris Forbes0036fd12016-01-26 14:19:49 +130014807
Tony Barbour1fa09702017-03-16 12:09:08 -060014808 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes0036fd12016-01-26 14:19:49 +130014809 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14810
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014811 char const *vsSource =
14812 "#version 450\n"
14813 "\n"
14814 "layout(location=0) out float x[2];\n"
14815 "out gl_PerVertex {\n"
14816 " vec4 gl_Position;\n"
14817 "};\n"
14818 "void main(){\n"
14819 " x[0] = 0; x[1] = 0;\n"
14820 " gl_Position = vec4(1);\n"
14821 "}\n";
14822 char const *fsSource =
14823 "#version 450\n"
14824 "\n"
14825 "layout(location=0) in float x[1];\n"
14826 "layout(location=0) out vec4 color;\n"
14827 "void main(){\n"
14828 " color = vec4(x[0]);\n"
14829 "}\n";
Chris Forbes0036fd12016-01-26 14:19:49 +130014830
14831 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14832 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14833
14834 VkPipelineObj pipe(m_device);
14835 pipe.AddColorAttachment();
14836 pipe.AddShader(&vs);
14837 pipe.AddShader(&fs);
14838
14839 VkDescriptorSetObj descriptorSet(m_device);
14840 descriptorSet.AppendDummy();
14841 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14842
14843 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14844
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014845 m_errorMonitor->VerifyFound();
Chris Forbes0036fd12016-01-26 14:19:49 +130014846}
14847
Karl Schultz6addd812016-02-02 17:17:23 -070014848TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014849 TEST_DESCRIPTION(
14850 "Test that an error is produced for mismatched types across "
14851 "the vertex->fragment shader interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014852 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014853
Tony Barbour1fa09702017-03-16 12:09:08 -060014854 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014855 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesb56af562015-05-25 11:13:17 +120014856
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014857 char const *vsSource =
14858 "#version 450\n"
14859 "\n"
14860 "layout(location=0) out int x;\n"
14861 "out gl_PerVertex {\n"
14862 " vec4 gl_Position;\n"
14863 "};\n"
14864 "void main(){\n"
14865 " x = 0;\n"
14866 " gl_Position = vec4(1);\n"
14867 "}\n";
14868 char const *fsSource =
14869 "#version 450\n"
14870 "\n"
14871 "layout(location=0) in float x;\n" /* VS writes int */
14872 "layout(location=0) out vec4 color;\n"
14873 "void main(){\n"
14874 " color = vec4(x);\n"
14875 "}\n";
Chris Forbesb56af562015-05-25 11:13:17 +120014876
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014877 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14878 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesb56af562015-05-25 11:13:17 +120014879
14880 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014881 pipe.AddColorAttachment();
Chris Forbesb56af562015-05-25 11:13:17 +120014882 pipe.AddShader(&vs);
14883 pipe.AddShader(&fs);
14884
Chris Forbesb56af562015-05-25 11:13:17 +120014885 VkDescriptorSetObj descriptorSet(m_device);
14886 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014887 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesb56af562015-05-25 11:13:17 +120014888
Tony Barbour5781e8f2015-08-04 16:23:11 -060014889 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesb56af562015-05-25 11:13:17 +120014890
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014891 m_errorMonitor->VerifyFound();
Chris Forbesb56af562015-05-25 11:13:17 +120014892}
14893
Karl Schultz6addd812016-02-02 17:17:23 -070014894TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchInBlock) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014895 TEST_DESCRIPTION(
14896 "Test that an error is produced for mismatched types across "
14897 "the vertex->fragment shader interface, when the variable is contained within "
14898 "an interface block");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014899 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Chris Forbesa3e85f62016-01-15 14:53:11 +130014900
Tony Barbour1fa09702017-03-16 12:09:08 -060014901 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbesa3e85f62016-01-15 14:53:11 +130014902 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14903
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014904 char const *vsSource =
14905 "#version 450\n"
14906 "\n"
14907 "out block { layout(location=0) int x; } outs;\n"
14908 "out gl_PerVertex {\n"
14909 " vec4 gl_Position;\n"
14910 "};\n"
14911 "void main(){\n"
14912 " outs.x = 0;\n"
14913 " gl_Position = vec4(1);\n"
14914 "}\n";
14915 char const *fsSource =
14916 "#version 450\n"
14917 "\n"
14918 "in block { layout(location=0) float x; } ins;\n" /* VS writes int */
14919 "layout(location=0) out vec4 color;\n"
14920 "void main(){\n"
14921 " color = vec4(ins.x);\n"
14922 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130014923
14924 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14925 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14926
14927 VkPipelineObj pipe(m_device);
14928 pipe.AddColorAttachment();
14929 pipe.AddShader(&vs);
14930 pipe.AddShader(&fs);
14931
14932 VkDescriptorSetObj descriptorSet(m_device);
14933 descriptorSet.AppendDummy();
14934 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14935
14936 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14937
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014938 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130014939}
14940
14941TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByLocation) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014942 TEST_DESCRIPTION(
14943 "Test that an error is produced for location mismatches across "
14944 "the vertex->fragment shader interface; This should manifest as a not-written/not-consumed "
14945 "pair, but flushes out broken walking of the interfaces");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014946 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 +130014947
Tony Barbour1fa09702017-03-16 12:09:08 -060014948 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbese9928822016-02-17 14:44:52 +130014949 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14950
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014951 char const *vsSource =
14952 "#version 450\n"
14953 "\n"
14954 "out block { layout(location=1) float x; } outs;\n"
14955 "out gl_PerVertex {\n"
14956 " vec4 gl_Position;\n"
14957 "};\n"
14958 "void main(){\n"
14959 " outs.x = 0;\n"
14960 " gl_Position = vec4(1);\n"
14961 "}\n";
14962 char const *fsSource =
14963 "#version 450\n"
14964 "\n"
14965 "in block { layout(location=0) float x; } ins;\n"
14966 "layout(location=0) out vec4 color;\n"
14967 "void main(){\n"
14968 " color = vec4(ins.x);\n"
14969 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130014970
14971 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14972 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14973
14974 VkPipelineObj pipe(m_device);
14975 pipe.AddColorAttachment();
14976 pipe.AddShader(&vs);
14977 pipe.AddShader(&fs);
14978
14979 VkDescriptorSetObj descriptorSet(m_device);
14980 descriptorSet.AppendDummy();
14981 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14982
14983 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14984
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014985 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130014986}
14987
14988TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByComponent) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014989 TEST_DESCRIPTION(
14990 "Test that an error is produced for component mismatches across the "
14991 "vertex->fragment shader interface. It's not enough to have the same set of locations in "
14992 "use; matching is defined in terms of spirv variables.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014993 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 +130014994
Tony Barbour1fa09702017-03-16 12:09:08 -060014995 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbese9928822016-02-17 14:44:52 +130014996 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14997
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014998 char const *vsSource =
14999 "#version 450\n"
15000 "\n"
15001 "out block { layout(location=0, component=0) float x; } outs;\n"
15002 "out gl_PerVertex {\n"
15003 " vec4 gl_Position;\n"
15004 "};\n"
15005 "void main(){\n"
15006 " outs.x = 0;\n"
15007 " gl_Position = vec4(1);\n"
15008 "}\n";
15009 char const *fsSource =
15010 "#version 450\n"
15011 "\n"
15012 "in block { layout(location=0, component=1) float x; } ins;\n"
15013 "layout(location=0) out vec4 color;\n"
15014 "void main(){\n"
15015 " color = vec4(ins.x);\n"
15016 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130015017
15018 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15019 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15020
15021 VkPipelineObj pipe(m_device);
15022 pipe.AddColorAttachment();
15023 pipe.AddShader(&vs);
15024 pipe.AddShader(&fs);
15025
15026 VkDescriptorSetObj descriptorSet(m_device);
15027 descriptorSet.AppendDummy();
15028 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15029
15030 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15031
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015032 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130015033}
15034
Chris Forbes1f3b0152016-11-30 12:48:40 +130015035TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByPrecision) {
15036 TEST_DESCRIPTION("Test that the RelaxedPrecision decoration is validated to match");
15037
Tony Barbour1fa09702017-03-16 12:09:08 -060015038 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes1f3b0152016-11-30 12:48:40 +130015039 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15040
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015041 char const *vsSource =
15042 "#version 450\n"
15043 "layout(location=0) out mediump float x;\n"
15044 "void main() { gl_Position = vec4(0); x = 1.0; }\n";
15045 char const *fsSource =
15046 "#version 450\n"
15047 "layout(location=0) in highp float x;\n"
15048 "layout(location=0) out vec4 color;\n"
15049 "void main() { color = vec4(x); }\n";
Chris Forbes1f3b0152016-11-30 12:48:40 +130015050
15051 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15052 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15053
15054 VkPipelineObj pipe(m_device);
15055 pipe.AddColorAttachment();
15056 pipe.AddShader(&vs);
15057 pipe.AddShader(&fs);
15058
15059 VkDescriptorSetObj descriptorSet(m_device);
15060 descriptorSet.AppendDummy();
15061 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15062
15063 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "differ in precision");
15064
15065 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15066
15067 m_errorMonitor->VerifyFound();
15068}
15069
Chris Forbes870a39e2016-11-30 12:55:56 +130015070TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByPrecisionBlock) {
15071 TEST_DESCRIPTION("Test that the RelaxedPrecision decoration is validated to match");
15072
Tony Barbour1fa09702017-03-16 12:09:08 -060015073 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes870a39e2016-11-30 12:55:56 +130015074 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15075
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015076 char const *vsSource =
15077 "#version 450\n"
15078 "out block { layout(location=0) mediump float x; };\n"
15079 "void main() { gl_Position = vec4(0); x = 1.0; }\n";
15080 char const *fsSource =
15081 "#version 450\n"
15082 "in block { layout(location=0) highp float x; };\n"
15083 "layout(location=0) out vec4 color;\n"
15084 "void main() { color = vec4(x); }\n";
Chris Forbes870a39e2016-11-30 12:55:56 +130015085
15086 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15087 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15088
15089 VkPipelineObj pipe(m_device);
15090 pipe.AddColorAttachment();
15091 pipe.AddShader(&vs);
15092 pipe.AddShader(&fs);
15093
15094 VkDescriptorSetObj descriptorSet(m_device);
15095 descriptorSet.AppendDummy();
15096 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15097
15098 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "differ in precision");
15099
15100 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15101
15102 m_errorMonitor->VerifyFound();
15103}
15104
Karl Schultz6addd812016-02-02 17:17:23 -070015105TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015106 TEST_DESCRIPTION(
15107 "Test that a warning is produced for a vertex attribute which is "
15108 "not consumed by the vertex shader");
Mike Weiblencce7ec72016-10-17 19:33:05 -060015109 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015110
Tony Barbour1fa09702017-03-16 12:09:08 -060015111 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060015112 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesde136e02015-05-25 11:13:28 +120015113
15114 VkVertexInputBindingDescription input_binding;
15115 memset(&input_binding, 0, sizeof(input_binding));
15116
15117 VkVertexInputAttributeDescription input_attrib;
15118 memset(&input_attrib, 0, sizeof(input_attrib));
15119 input_attrib.format = VK_FORMAT_R32_SFLOAT;
15120
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015121 char const *vsSource =
15122 "#version 450\n"
15123 "\n"
15124 "out gl_PerVertex {\n"
15125 " vec4 gl_Position;\n"
15126 "};\n"
15127 "void main(){\n"
15128 " gl_Position = vec4(1);\n"
15129 "}\n";
15130 char const *fsSource =
15131 "#version 450\n"
15132 "\n"
15133 "layout(location=0) out vec4 color;\n"
15134 "void main(){\n"
15135 " color = vec4(1);\n"
15136 "}\n";
Chris Forbesde136e02015-05-25 11:13:28 +120015137
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060015138 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15139 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesde136e02015-05-25 11:13:28 +120015140
15141 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080015142 pipe.AddColorAttachment();
Chris Forbesde136e02015-05-25 11:13:28 +120015143 pipe.AddShader(&vs);
15144 pipe.AddShader(&fs);
15145
15146 pipe.AddVertexInputBindings(&input_binding, 1);
15147 pipe.AddVertexInputAttribs(&input_attrib, 1);
15148
Chris Forbesde136e02015-05-25 11:13:28 +120015149 VkDescriptorSetObj descriptorSet(m_device);
15150 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015151 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesde136e02015-05-25 11:13:28 +120015152
Tony Barbour5781e8f2015-08-04 16:23:11 -060015153 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesde136e02015-05-25 11:13:28 +120015154
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015155 m_errorMonitor->VerifyFound();
Chris Forbesde136e02015-05-25 11:13:28 +120015156}
15157
Karl Schultz6addd812016-02-02 17:17:23 -070015158TEST_F(VkLayerTest, CreatePipelineAttribLocationMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015159 TEST_DESCRIPTION(
15160 "Test that a warning is produced for a location mismatch on "
15161 "vertex attributes. This flushes out bad behavior in the interface walker");
Mike Weiblencce7ec72016-10-17 19:33:05 -060015162 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Chris Forbes7d83cd52016-01-15 11:32:03 +130015163
Tony Barbour1fa09702017-03-16 12:09:08 -060015164 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes7d83cd52016-01-15 11:32:03 +130015165 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15166
15167 VkVertexInputBindingDescription input_binding;
15168 memset(&input_binding, 0, sizeof(input_binding));
15169
15170 VkVertexInputAttributeDescription input_attrib;
15171 memset(&input_attrib, 0, sizeof(input_attrib));
15172 input_attrib.format = VK_FORMAT_R32_SFLOAT;
15173
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015174 char const *vsSource =
15175 "#version 450\n"
15176 "\n"
15177 "layout(location=1) in float x;\n"
15178 "out gl_PerVertex {\n"
15179 " vec4 gl_Position;\n"
15180 "};\n"
15181 "void main(){\n"
15182 " gl_Position = vec4(x);\n"
15183 "}\n";
15184 char const *fsSource =
15185 "#version 450\n"
15186 "\n"
15187 "layout(location=0) out vec4 color;\n"
15188 "void main(){\n"
15189 " color = vec4(1);\n"
15190 "}\n";
Chris Forbes7d83cd52016-01-15 11:32:03 +130015191
15192 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15193 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15194
15195 VkPipelineObj pipe(m_device);
15196 pipe.AddColorAttachment();
15197 pipe.AddShader(&vs);
15198 pipe.AddShader(&fs);
15199
15200 pipe.AddVertexInputBindings(&input_binding, 1);
15201 pipe.AddVertexInputAttribs(&input_attrib, 1);
15202
15203 VkDescriptorSetObj descriptorSet(m_device);
15204 descriptorSet.AppendDummy();
15205 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15206
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070015207 m_errorMonitor->SetUnexpectedError("Vertex shader consumes input at location 1 but not provided");
Chris Forbes7d83cd52016-01-15 11:32:03 +130015208 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15209
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015210 m_errorMonitor->VerifyFound();
Chris Forbes7d83cd52016-01-15 11:32:03 +130015211}
15212
Karl Schultz6addd812016-02-02 17:17:23 -070015213TEST_F(VkLayerTest, CreatePipelineAttribNotProvided) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015214 TEST_DESCRIPTION(
15215 "Test that an error is produced for a vertex shader input which is not "
15216 "provided by a vertex attribute");
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070015217 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15218 "Vertex shader consumes input at location 0 but not provided");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015219
Tony Barbour1fa09702017-03-16 12:09:08 -060015220 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060015221 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes62e8e502015-05-25 11:13:29 +120015222
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015223 char const *vsSource =
15224 "#version 450\n"
15225 "\n"
15226 "layout(location=0) in vec4 x;\n" /* not provided */
15227 "out gl_PerVertex {\n"
15228 " vec4 gl_Position;\n"
15229 "};\n"
15230 "void main(){\n"
15231 " gl_Position = x;\n"
15232 "}\n";
15233 char const *fsSource =
15234 "#version 450\n"
15235 "\n"
15236 "layout(location=0) out vec4 color;\n"
15237 "void main(){\n"
15238 " color = vec4(1);\n"
15239 "}\n";
Chris Forbes62e8e502015-05-25 11:13:29 +120015240
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060015241 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15242 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes62e8e502015-05-25 11:13:29 +120015243
15244 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080015245 pipe.AddColorAttachment();
Chris Forbes62e8e502015-05-25 11:13:29 +120015246 pipe.AddShader(&vs);
15247 pipe.AddShader(&fs);
15248
Chris Forbes62e8e502015-05-25 11:13:29 +120015249 VkDescriptorSetObj descriptorSet(m_device);
15250 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015251 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes62e8e502015-05-25 11:13:29 +120015252
Tony Barbour5781e8f2015-08-04 16:23:11 -060015253 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes62e8e502015-05-25 11:13:29 +120015254
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015255 m_errorMonitor->VerifyFound();
Chris Forbes62e8e502015-05-25 11:13:29 +120015256}
15257
Karl Schultz6addd812016-02-02 17:17:23 -070015258TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015259 TEST_DESCRIPTION(
15260 "Test that an error is produced for a mismatch between the "
15261 "fundamental type (float/int/uint) of an attribute and the "
15262 "vertex shader input that consumes it");
Mike Weiblen15bd38e2016-10-03 19:19:41 -060015263 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 -060015264
Tony Barbour1fa09702017-03-16 12:09:08 -060015265 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060015266 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc97d98e2015-05-25 11:13:31 +120015267
15268 VkVertexInputBindingDescription input_binding;
15269 memset(&input_binding, 0, sizeof(input_binding));
15270
15271 VkVertexInputAttributeDescription input_attrib;
15272 memset(&input_attrib, 0, sizeof(input_attrib));
15273 input_attrib.format = VK_FORMAT_R32_SFLOAT;
15274
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015275 char const *vsSource =
15276 "#version 450\n"
15277 "\n"
15278 "layout(location=0) in int x;\n" /* attrib provided float */
15279 "out gl_PerVertex {\n"
15280 " vec4 gl_Position;\n"
15281 "};\n"
15282 "void main(){\n"
15283 " gl_Position = vec4(x);\n"
15284 "}\n";
15285 char const *fsSource =
15286 "#version 450\n"
15287 "\n"
15288 "layout(location=0) out vec4 color;\n"
15289 "void main(){\n"
15290 " color = vec4(1);\n"
15291 "}\n";
Chris Forbesc97d98e2015-05-25 11:13:31 +120015292
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060015293 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15294 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc97d98e2015-05-25 11:13:31 +120015295
15296 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080015297 pipe.AddColorAttachment();
Chris Forbesc97d98e2015-05-25 11:13:31 +120015298 pipe.AddShader(&vs);
15299 pipe.AddShader(&fs);
15300
15301 pipe.AddVertexInputBindings(&input_binding, 1);
15302 pipe.AddVertexInputAttribs(&input_attrib, 1);
15303
Chris Forbesc97d98e2015-05-25 11:13:31 +120015304 VkDescriptorSetObj descriptorSet(m_device);
15305 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015306 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesc97d98e2015-05-25 11:13:31 +120015307
Tony Barbour5781e8f2015-08-04 16:23:11 -060015308 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc97d98e2015-05-25 11:13:31 +120015309
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015310 m_errorMonitor->VerifyFound();
Chris Forbesc97d98e2015-05-25 11:13:31 +120015311}
15312
Chris Forbesc68b43c2016-04-06 11:18:47 +120015313TEST_F(VkLayerTest, CreatePipelineDuplicateStage) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015314 TEST_DESCRIPTION(
15315 "Test that an error is produced for a pipeline containing multiple "
15316 "shaders for the same stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015317 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15318 "Multiple shaders provided for stage VK_SHADER_STAGE_VERTEX_BIT");
Chris Forbesc68b43c2016-04-06 11:18:47 +120015319
Tony Barbour1fa09702017-03-16 12:09:08 -060015320 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbesc68b43c2016-04-06 11:18:47 +120015321 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15322
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015323 char const *vsSource =
15324 "#version 450\n"
15325 "\n"
15326 "out gl_PerVertex {\n"
15327 " vec4 gl_Position;\n"
15328 "};\n"
15329 "void main(){\n"
15330 " gl_Position = vec4(1);\n"
15331 "}\n";
15332 char const *fsSource =
15333 "#version 450\n"
15334 "\n"
15335 "layout(location=0) out vec4 color;\n"
15336 "void main(){\n"
15337 " color = vec4(1);\n"
15338 "}\n";
Chris Forbesc68b43c2016-04-06 11:18:47 +120015339
15340 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15341 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15342
15343 VkPipelineObj pipe(m_device);
15344 pipe.AddColorAttachment();
15345 pipe.AddShader(&vs);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015346 pipe.AddShader(&vs); // intentionally duplicate vertex shader attachment
Chris Forbesc68b43c2016-04-06 11:18:47 +120015347 pipe.AddShader(&fs);
15348
15349 VkDescriptorSetObj descriptorSet(m_device);
15350 descriptorSet.AppendDummy();
15351 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15352
15353 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15354
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015355 m_errorMonitor->VerifyFound();
Chris Forbesc68b43c2016-04-06 11:18:47 +120015356}
15357
Chris Forbes82ff92a2016-09-09 10:50:24 +120015358TEST_F(VkLayerTest, CreatePipelineMissingEntrypoint) {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070015359 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "No entrypoint found named `foo`");
Chris Forbes82ff92a2016-09-09 10:50:24 +120015360
Tony Barbour1fa09702017-03-16 12:09:08 -060015361 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes82ff92a2016-09-09 10:50:24 +120015362 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15363
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015364 char const *vsSource =
15365 "#version 450\n"
15366 "out gl_PerVertex {\n"
15367 " vec4 gl_Position;\n"
15368 "};\n"
15369 "void main(){\n"
15370 " gl_Position = vec4(0);\n"
15371 "}\n";
15372 char const *fsSource =
15373 "#version 450\n"
15374 "\n"
15375 "layout(location=0) out vec4 color;\n"
15376 "void main(){\n"
15377 " color = vec4(1);\n"
15378 "}\n";
Chris Forbes82ff92a2016-09-09 10:50:24 +120015379
15380 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15381 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this, "foo");
15382
15383 VkPipelineObj pipe(m_device);
15384 pipe.AddColorAttachment();
15385 pipe.AddShader(&vs);
15386 pipe.AddShader(&fs);
15387
15388 VkDescriptorSetObj descriptorSet(m_device);
15389 descriptorSet.AppendDummy();
15390 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15391
15392 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15393
15394 m_errorMonitor->VerifyFound();
15395}
15396
Chris Forbesae9d8cd2016-09-13 16:32:57 +120015397TEST_F(VkLayerTest, CreatePipelineDepthStencilRequired) {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070015398 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15399 "pDepthStencilState is NULL when rasterization is enabled and subpass "
15400 "uses a depth/stencil attachment");
Chris Forbesae9d8cd2016-09-13 16:32:57 +120015401
Tony Barbour1fa09702017-03-16 12:09:08 -060015402 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbesae9d8cd2016-09-13 16:32:57 +120015403 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15404
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015405 char const *vsSource =
15406 "#version 450\n"
15407 "void main(){ gl_Position = vec4(0); }\n";
15408 char const *fsSource =
15409 "#version 450\n"
15410 "\n"
15411 "layout(location=0) out vec4 color;\n"
15412 "void main(){\n"
15413 " color = vec4(1);\n"
15414 "}\n";
Chris Forbesae9d8cd2016-09-13 16:32:57 +120015415
15416 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15417 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15418
15419 VkPipelineObj pipe(m_device);
15420 pipe.AddColorAttachment();
15421 pipe.AddShader(&vs);
15422 pipe.AddShader(&fs);
15423
15424 VkDescriptorSetObj descriptorSet(m_device);
15425 descriptorSet.AppendDummy();
15426 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15427
15428 VkAttachmentDescription attachments[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070015429 {
15430 0, VK_FORMAT_B8G8R8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
15431 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_UNDEFINED,
15432 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
Chris Forbesae9d8cd2016-09-13 16:32:57 +120015433 },
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070015434 {
15435 0, VK_FORMAT_D16_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
15436 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_UNDEFINED,
15437 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
Chris Forbesae9d8cd2016-09-13 16:32:57 +120015438 },
15439 };
15440 VkAttachmentReference refs[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070015441 {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL}, {1, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL},
Chris Forbesae9d8cd2016-09-13 16:32:57 +120015442 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070015443 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &refs[0], nullptr, &refs[1], 0, nullptr};
15444 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesae9d8cd2016-09-13 16:32:57 +120015445 VkRenderPass rp;
15446 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
15447 ASSERT_VK_SUCCESS(err);
15448
15449 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), rp);
15450
15451 m_errorMonitor->VerifyFound();
15452
15453 vkDestroyRenderPass(m_device->device(), rp, nullptr);
15454}
15455
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015456TEST_F(VkLayerTest, CreatePipelineTessPatchDecorationMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015457 TEST_DESCRIPTION(
15458 "Test that an error is produced for a variable output from "
15459 "the TCS without the patch decoration, but consumed in the TES "
15460 "with the decoration.");
15461 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15462 "is per-vertex in tessellation control shader stage "
15463 "but per-patch in tessellation evaluation shader stage");
Chris Forbesa0193bc2016-04-04 19:19:47 +120015464
Tony Barbour1fa09702017-03-16 12:09:08 -060015465 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbesa0193bc2016-04-04 19:19:47 +120015466 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15467
Chris Forbesc1e852d2016-04-04 19:26:42 +120015468 if (!m_device->phy().features().tessellationShader) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070015469 printf(" Device does not support tessellation shaders; skipped.\n");
Chris Forbesc1e852d2016-04-04 19:26:42 +120015470 return;
15471 }
15472
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015473 char const *vsSource =
15474 "#version 450\n"
15475 "void main(){}\n";
15476 char const *tcsSource =
15477 "#version 450\n"
15478 "layout(location=0) out int x[];\n"
15479 "layout(vertices=3) out;\n"
15480 "void main(){\n"
15481 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
15482 " gl_TessLevelInner[0] = 1;\n"
15483 " x[gl_InvocationID] = gl_InvocationID;\n"
15484 "}\n";
15485 char const *tesSource =
15486 "#version 450\n"
15487 "layout(triangles, equal_spacing, cw) in;\n"
15488 "layout(location=0) patch in int x;\n"
15489 "out gl_PerVertex { vec4 gl_Position; };\n"
15490 "void main(){\n"
15491 " gl_Position.xyz = gl_TessCoord;\n"
15492 " gl_Position.w = x;\n"
15493 "}\n";
15494 char const *fsSource =
15495 "#version 450\n"
15496 "layout(location=0) out vec4 color;\n"
15497 "void main(){\n"
15498 " color = vec4(1);\n"
15499 "}\n";
Chris Forbesa0193bc2016-04-04 19:19:47 +120015500
15501 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15502 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
15503 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
15504 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15505
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015506 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
15507 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Chris Forbesa0193bc2016-04-04 19:19:47 +120015508
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015509 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Chris Forbesa0193bc2016-04-04 19:19:47 +120015510
15511 VkPipelineObj pipe(m_device);
15512 pipe.SetInputAssembly(&iasci);
15513 pipe.SetTessellation(&tsci);
15514 pipe.AddColorAttachment();
15515 pipe.AddShader(&vs);
15516 pipe.AddShader(&tcs);
15517 pipe.AddShader(&tes);
15518 pipe.AddShader(&fs);
15519
15520 VkDescriptorSetObj descriptorSet(m_device);
15521 descriptorSet.AppendDummy();
15522 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15523
15524 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15525
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015526 m_errorMonitor->VerifyFound();
Chris Forbesa0193bc2016-04-04 19:19:47 +120015527}
15528
Cort Stratton2bcca1b2017-05-05 16:02:35 -070015529TEST_F(VkLayerTest, CreatePipelineTessErrors) {
15530 TEST_DESCRIPTION("Test various errors when creating a graphics pipeline with tessellation stages active.");
15531
15532 ASSERT_NO_FATAL_FAILURE(Init());
15533 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15534
15535 if (!m_device->phy().features().tessellationShader) {
15536 printf(" Device does not support tessellation shaders; skipped.\n");
15537 return;
15538 }
15539
15540 char const *vsSource =
15541 "#version 450\n"
15542 "void main(){}\n";
15543 char const *tcsSource =
15544 "#version 450\n"
15545 "layout(vertices=3) out;\n"
15546 "void main(){\n"
15547 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
15548 " gl_TessLevelInner[0] = 1;\n"
15549 "}\n";
15550 char const *tesSource =
15551 "#version 450\n"
15552 "layout(triangles, equal_spacing, cw) in;\n"
15553 "out gl_PerVertex { vec4 gl_Position; };\n"
15554 "void main(){\n"
15555 " gl_Position.xyz = gl_TessCoord;\n"
15556 " gl_Position.w = 0;\n"
15557 "}\n";
15558 char const *fsSource =
15559 "#version 450\n"
15560 "layout(location=0) out vec4 color;\n"
15561 "void main(){\n"
15562 " color = vec4(1);\n"
15563 "}\n";
15564
15565 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15566 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
15567 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
15568 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15569
15570 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
15571 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
15572
15573 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
15574
15575 VkDescriptorSetObj descriptorSet(m_device);
15576 descriptorSet.AppendDummy();
15577 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15578
15579 {
15580 VkPipelineObj pipe(m_device);
15581 VkPipelineInputAssemblyStateCreateInfo iasci_bad = iasci;
15582 iasci_bad.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST; // otherwise we get a failure about invalid topology
15583 pipe.SetInputAssembly(&iasci_bad);
15584 pipe.AddColorAttachment();
15585 pipe.AddShader(&vs);
15586 pipe.AddShader(&fs);
15587
15588 // Pass a tess control shader without a tess eval shader
15589 pipe.AddShader(&tcs);
15590 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00534);
15591 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15592 m_errorMonitor->VerifyFound();
15593 }
15594
15595 {
15596 VkPipelineObj pipe(m_device);
15597 VkPipelineInputAssemblyStateCreateInfo iasci_bad = iasci;
15598 iasci_bad.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST; // otherwise we get a failure about invalid topology
15599 pipe.SetInputAssembly(&iasci_bad);
15600 pipe.AddColorAttachment();
15601 pipe.AddShader(&vs);
15602 pipe.AddShader(&fs);
15603
15604 // Pass a tess eval shader without a tess control shader
15605 pipe.AddShader(&tes);
15606 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00535);
15607 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15608 m_errorMonitor->VerifyFound();
15609 }
15610
15611 {
15612 VkPipelineObj pipe(m_device);
15613 pipe.SetInputAssembly(&iasci);
15614 pipe.AddColorAttachment();
15615 pipe.AddShader(&vs);
15616 pipe.AddShader(&fs);
15617
15618 // Pass patch topology without tessellation shaders
15619 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02100);
15620 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15621 m_errorMonitor->VerifyFound();
15622
15623 pipe.AddShader(&tcs);
15624 pipe.AddShader(&tes);
15625 // Pass a NULL pTessellationState (with active tessellation shader stages)
15626 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00536);
15627 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15628 m_errorMonitor->VerifyFound();
15629
15630 // Pass an invalid pTessellationState (bad sType)
15631 VkPipelineTessellationStateCreateInfo tsci_bad = tsci;
15632 tsci_bad.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
15633 pipe.SetTessellation(&tsci_bad);
15634 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01427);
15635 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15636 m_errorMonitor->VerifyFound();
15637 // Pass out-of-range patchControlPoints
15638 tsci_bad = tsci;
15639 tsci_bad.patchControlPoints = 0;
15640 pipe.SetTessellation(&tsci);
15641 pipe.SetTessellation(&tsci_bad);
15642 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01426);
15643 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15644 m_errorMonitor->VerifyFound();
15645 tsci_bad.patchControlPoints = m_device->props.limits.maxTessellationPatchSize + 1;
15646 pipe.SetTessellation(&tsci_bad);
15647 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01426);
15648 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15649 m_errorMonitor->VerifyFound();
15650 pipe.SetTessellation(&tsci);
15651
15652 // Pass an invalid primitive topology
15653 VkPipelineInputAssemblyStateCreateInfo iasci_bad = iasci;
15654 iasci_bad.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
15655 pipe.SetInputAssembly(&iasci_bad);
15656 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02099);
15657 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15658 m_errorMonitor->VerifyFound();
15659 pipe.SetInputAssembly(&iasci);
15660 }
15661}
15662
Karl Schultz6addd812016-02-02 17:17:23 -070015663TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015664 TEST_DESCRIPTION(
15665 "Test that an error is produced for a vertex attribute setup where multiple "
15666 "bindings provide the same location");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015667 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15668 "Duplicate vertex input binding descriptions for binding 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015669
Tony Barbour1fa09702017-03-16 12:09:08 -060015670 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060015671 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes280ba2c2015-06-12 11:16:41 +120015672
15673 /* Two binding descriptions for binding 0 */
15674 VkVertexInputBindingDescription input_bindings[2];
15675 memset(input_bindings, 0, sizeof(input_bindings));
15676
15677 VkVertexInputAttributeDescription input_attrib;
15678 memset(&input_attrib, 0, sizeof(input_attrib));
15679 input_attrib.format = VK_FORMAT_R32_SFLOAT;
15680
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015681 char const *vsSource =
15682 "#version 450\n"
15683 "\n"
15684 "layout(location=0) in float x;\n" /* attrib provided float */
15685 "out gl_PerVertex {\n"
15686 " vec4 gl_Position;\n"
15687 "};\n"
15688 "void main(){\n"
15689 " gl_Position = vec4(x);\n"
15690 "}\n";
15691 char const *fsSource =
15692 "#version 450\n"
15693 "\n"
15694 "layout(location=0) out vec4 color;\n"
15695 "void main(){\n"
15696 " color = vec4(1);\n"
15697 "}\n";
Chris Forbes280ba2c2015-06-12 11:16:41 +120015698
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060015699 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15700 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes280ba2c2015-06-12 11:16:41 +120015701
15702 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080015703 pipe.AddColorAttachment();
Chris Forbes280ba2c2015-06-12 11:16:41 +120015704 pipe.AddShader(&vs);
15705 pipe.AddShader(&fs);
15706
15707 pipe.AddVertexInputBindings(input_bindings, 2);
15708 pipe.AddVertexInputAttribs(&input_attrib, 1);
15709
Chris Forbes280ba2c2015-06-12 11:16:41 +120015710 VkDescriptorSetObj descriptorSet(m_device);
15711 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015712 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes280ba2c2015-06-12 11:16:41 +120015713
Tony Barbour5781e8f2015-08-04 16:23:11 -060015714 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes280ba2c2015-06-12 11:16:41 +120015715
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015716 m_errorMonitor->VerifyFound();
Chris Forbes280ba2c2015-06-12 11:16:41 +120015717}
Chris Forbes8f68b562015-05-25 11:13:32 +120015718
Karl Schultz6addd812016-02-02 17:17:23 -070015719TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015720 TEST_DESCRIPTION(
15721 "Test that an error is produced for a fragment shader which does not "
15722 "provide an output for one of the pipeline's color attachments");
Mike Weiblencce7ec72016-10-17 19:33:05 -060015723 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attachment 0 not written by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015724
Tony Barbour1fa09702017-03-16 12:09:08 -060015725 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120015726
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015727 char const *vsSource =
15728 "#version 450\n"
15729 "\n"
15730 "out gl_PerVertex {\n"
15731 " vec4 gl_Position;\n"
15732 "};\n"
15733 "void main(){\n"
15734 " gl_Position = vec4(1);\n"
15735 "}\n";
15736 char const *fsSource =
15737 "#version 450\n"
15738 "\n"
15739 "void main(){\n"
15740 "}\n";
Chris Forbes4d6d1e52015-05-25 11:13:40 +120015741
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060015742 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15743 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120015744
15745 VkPipelineObj pipe(m_device);
15746 pipe.AddShader(&vs);
15747 pipe.AddShader(&fs);
15748
Chia-I Wu08accc62015-07-07 11:50:03 +080015749 /* set up CB 0, not written */
15750 pipe.AddColorAttachment();
15751 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120015752
Chris Forbes4d6d1e52015-05-25 11:13:40 +120015753 VkDescriptorSetObj descriptorSet(m_device);
15754 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015755 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120015756
Tony Barbour5781e8f2015-08-04 16:23:11 -060015757 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120015758
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015759 m_errorMonitor->VerifyFound();
Chris Forbes4d6d1e52015-05-25 11:13:40 +120015760}
15761
Karl Schultz6addd812016-02-02 17:17:23 -070015762TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015763 TEST_DESCRIPTION(
15764 "Test that a warning is produced for a fragment shader which provides a spurious "
15765 "output with no matching attachment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015766 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060015767 "fragment shader writes to output location 1 with no matching attachment");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015768
Tony Barbour1fa09702017-03-16 12:09:08 -060015769 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120015770
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015771 char const *vsSource =
15772 "#version 450\n"
15773 "\n"
15774 "out gl_PerVertex {\n"
15775 " vec4 gl_Position;\n"
15776 "};\n"
15777 "void main(){\n"
15778 " gl_Position = vec4(1);\n"
15779 "}\n";
15780 char const *fsSource =
15781 "#version 450\n"
15782 "\n"
15783 "layout(location=0) out vec4 x;\n"
15784 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
15785 "void main(){\n"
15786 " x = vec4(1);\n"
15787 " y = vec4(1);\n"
15788 "}\n";
Chris Forbesf3fffaa2015-05-25 11:13:43 +120015789
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060015790 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15791 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120015792
15793 VkPipelineObj pipe(m_device);
15794 pipe.AddShader(&vs);
15795 pipe.AddShader(&fs);
15796
Chia-I Wu08accc62015-07-07 11:50:03 +080015797 /* set up CB 0, not written */
15798 pipe.AddColorAttachment();
15799 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120015800 /* FS writes CB 1, but we don't configure it */
15801
Chris Forbesf3fffaa2015-05-25 11:13:43 +120015802 VkDescriptorSetObj descriptorSet(m_device);
15803 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015804 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120015805
Tony Barbour5781e8f2015-08-04 16:23:11 -060015806 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120015807
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015808 m_errorMonitor->VerifyFound();
Chris Forbesf3fffaa2015-05-25 11:13:43 +120015809}
15810
Karl Schultz6addd812016-02-02 17:17:23 -070015811TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015812 TEST_DESCRIPTION(
15813 "Test that an error is produced for a mismatch between the fundamental "
15814 "type of an fragment shader output variable, and the format of the corresponding attachment");
Mike Weiblencce7ec72016-10-17 19:33:05 -060015815 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "does not match fragment shader output type");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015816
Tony Barbour1fa09702017-03-16 12:09:08 -060015817 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbesa36d69e2015-05-25 11:13:44 +120015818
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015819 char const *vsSource =
15820 "#version 450\n"
15821 "\n"
15822 "out gl_PerVertex {\n"
15823 " vec4 gl_Position;\n"
15824 "};\n"
15825 "void main(){\n"
15826 " gl_Position = vec4(1);\n"
15827 "}\n";
15828 char const *fsSource =
15829 "#version 450\n"
15830 "\n"
15831 "layout(location=0) out ivec4 x;\n" /* not UNORM */
15832 "void main(){\n"
15833 " x = ivec4(1);\n"
15834 "}\n";
Chris Forbesa36d69e2015-05-25 11:13:44 +120015835
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060015836 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15837 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa36d69e2015-05-25 11:13:44 +120015838
15839 VkPipelineObj pipe(m_device);
15840 pipe.AddShader(&vs);
15841 pipe.AddShader(&fs);
15842
Chia-I Wu08accc62015-07-07 11:50:03 +080015843 /* set up CB 0; type is UNORM by default */
15844 pipe.AddColorAttachment();
15845 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa36d69e2015-05-25 11:13:44 +120015846
Chris Forbesa36d69e2015-05-25 11:13:44 +120015847 VkDescriptorSetObj descriptorSet(m_device);
15848 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015849 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesa36d69e2015-05-25 11:13:44 +120015850
Tony Barbour5781e8f2015-08-04 16:23:11 -060015851 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa36d69e2015-05-25 11:13:44 +120015852
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015853 m_errorMonitor->VerifyFound();
Chris Forbesa36d69e2015-05-25 11:13:44 +120015854}
Chris Forbes7b1b8932015-06-05 14:43:36 +120015855
Karl Schultz6addd812016-02-02 17:17:23 -070015856TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015857 TEST_DESCRIPTION(
15858 "Test that an error is produced for a shader consuming a uniform "
15859 "block which has no corresponding binding in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015860 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in pipeline layout");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015861
Tony Barbour1fa09702017-03-16 12:09:08 -060015862 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes556c76c2015-08-14 12:04:59 +120015863
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015864 char const *vsSource =
15865 "#version 450\n"
15866 "\n"
15867 "out gl_PerVertex {\n"
15868 " vec4 gl_Position;\n"
15869 "};\n"
15870 "void main(){\n"
15871 " gl_Position = vec4(1);\n"
15872 "}\n";
15873 char const *fsSource =
15874 "#version 450\n"
15875 "\n"
15876 "layout(location=0) out vec4 x;\n"
15877 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
15878 "void main(){\n"
15879 " x = vec4(bar.y);\n"
15880 "}\n";
Chris Forbes556c76c2015-08-14 12:04:59 +120015881
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060015882 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15883 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes556c76c2015-08-14 12:04:59 +120015884
Chris Forbes556c76c2015-08-14 12:04:59 +120015885 VkPipelineObj pipe(m_device);
15886 pipe.AddShader(&vs);
15887 pipe.AddShader(&fs);
15888
15889 /* set up CB 0; type is UNORM by default */
15890 pipe.AddColorAttachment();
15891 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15892
15893 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015894 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes556c76c2015-08-14 12:04:59 +120015895
15896 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15897
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015898 m_errorMonitor->VerifyFound();
Chris Forbes556c76c2015-08-14 12:04:59 +120015899}
15900
Chris Forbes5c59e902016-02-26 16:56:09 +130015901TEST_F(VkLayerTest, CreatePipelinePushConstantsNotInLayout) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015902 TEST_DESCRIPTION(
15903 "Test that an error is produced for a shader consuming push constants "
15904 "which are not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015905 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in layout");
Chris Forbes5c59e902016-02-26 16:56:09 +130015906
Tony Barbour1fa09702017-03-16 12:09:08 -060015907 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes5c59e902016-02-26 16:56:09 +130015908
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015909 char const *vsSource =
15910 "#version 450\n"
15911 "\n"
15912 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
15913 "out gl_PerVertex {\n"
15914 " vec4 gl_Position;\n"
15915 "};\n"
15916 "void main(){\n"
15917 " gl_Position = vec4(consts.x);\n"
15918 "}\n";
15919 char const *fsSource =
15920 "#version 450\n"
15921 "\n"
15922 "layout(location=0) out vec4 x;\n"
15923 "void main(){\n"
15924 " x = vec4(1);\n"
15925 "}\n";
Chris Forbes5c59e902016-02-26 16:56:09 +130015926
15927 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15928 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15929
15930 VkPipelineObj pipe(m_device);
15931 pipe.AddShader(&vs);
15932 pipe.AddShader(&fs);
15933
15934 /* set up CB 0; type is UNORM by default */
15935 pipe.AddColorAttachment();
15936 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15937
15938 VkDescriptorSetObj descriptorSet(m_device);
15939 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15940
15941 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15942
15943 /* should have generated an error -- no push constant ranges provided! */
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015944 m_errorMonitor->VerifyFound();
Chris Forbes5c59e902016-02-26 16:56:09 +130015945}
15946
Chris Forbes3fb17902016-08-22 14:57:55 +120015947TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissing) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015948 TEST_DESCRIPTION(
15949 "Test that an error is produced for a shader consuming an input attachment "
15950 "which is not included in the subpass description");
Chris Forbes3fb17902016-08-22 14:57:55 +120015951 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15952 "consumes input attachment index 0 but not provided in subpass");
15953
Tony Barbour1fa09702017-03-16 12:09:08 -060015954 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes3fb17902016-08-22 14:57:55 +120015955
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015956 char const *vsSource =
15957 "#version 450\n"
15958 "\n"
15959 "out gl_PerVertex {\n"
15960 " vec4 gl_Position;\n"
15961 "};\n"
15962 "void main(){\n"
15963 " gl_Position = vec4(1);\n"
15964 "}\n";
15965 char const *fsSource =
15966 "#version 450\n"
15967 "\n"
15968 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
15969 "layout(location=0) out vec4 color;\n"
15970 "void main() {\n"
15971 " color = subpassLoad(x);\n"
15972 "}\n";
Chris Forbes3fb17902016-08-22 14:57:55 +120015973
15974 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15975 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15976
15977 VkPipelineObj pipe(m_device);
15978 pipe.AddShader(&vs);
15979 pipe.AddShader(&fs);
15980 pipe.AddColorAttachment();
15981 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15982
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015983 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
15984 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes3fb17902016-08-22 14:57:55 +120015985 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015986 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes3fb17902016-08-22 14:57:55 +120015987 ASSERT_VK_SUCCESS(err);
15988
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015989 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes3fb17902016-08-22 14:57:55 +120015990 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015991 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes3fb17902016-08-22 14:57:55 +120015992 ASSERT_VK_SUCCESS(err);
15993
15994 // error here.
15995 pipe.CreateVKPipeline(pl, renderPass());
15996
15997 m_errorMonitor->VerifyFound();
15998
15999 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
16000 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
16001}
16002
Chris Forbes5a9a0472016-08-22 16:02:09 +120016003TEST_F(VkLayerTest, CreatePipelineInputAttachmentTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016004 TEST_DESCRIPTION(
16005 "Test that an error is produced for a shader consuming an input attachment "
16006 "with a format having a different fundamental type");
Chris Forbes5a9a0472016-08-22 16:02:09 +120016007 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16008 "input attachment 0 format of VK_FORMAT_R8G8B8A8_UINT does not match");
16009
Tony Barbour1fa09702017-03-16 12:09:08 -060016010 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes5a9a0472016-08-22 16:02:09 +120016011
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016012 char const *vsSource =
16013 "#version 450\n"
16014 "\n"
16015 "out gl_PerVertex {\n"
16016 " vec4 gl_Position;\n"
16017 "};\n"
16018 "void main(){\n"
16019 " gl_Position = vec4(1);\n"
16020 "}\n";
16021 char const *fsSource =
16022 "#version 450\n"
16023 "\n"
16024 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
16025 "layout(location=0) out vec4 color;\n"
16026 "void main() {\n"
16027 " color = subpassLoad(x);\n"
16028 "}\n";
Chris Forbes5a9a0472016-08-22 16:02:09 +120016029
16030 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
16031 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
16032
16033 VkPipelineObj pipe(m_device);
16034 pipe.AddShader(&vs);
16035 pipe.AddShader(&fs);
16036 pipe.AddColorAttachment();
16037 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16038
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016039 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
16040 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes5a9a0472016-08-22 16:02:09 +120016041 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016042 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120016043 ASSERT_VK_SUCCESS(err);
16044
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016045 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120016046 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016047 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120016048 ASSERT_VK_SUCCESS(err);
16049
16050 VkAttachmentDescription descs[2] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016051 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
16052 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
16053 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
16054 {0, VK_FORMAT_R8G8B8A8_UINT, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
16055 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 +120016056 };
16057 VkAttachmentReference color = {
16058 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
16059 };
16060 VkAttachmentReference input = {
16061 1, VK_IMAGE_LAYOUT_GENERAL,
16062 };
16063
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016064 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120016065
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016066 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120016067 VkRenderPass rp;
16068 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
16069 ASSERT_VK_SUCCESS(err);
16070
16071 // error here.
16072 pipe.CreateVKPipeline(pl, rp);
16073
16074 m_errorMonitor->VerifyFound();
16075
16076 vkDestroyRenderPass(m_device->device(), rp, nullptr);
16077 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
16078 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
16079}
16080
Chris Forbes541f7b02016-08-22 15:30:27 +120016081TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissingArray) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016082 TEST_DESCRIPTION(
16083 "Test that an error is produced for a shader consuming an input attachment "
16084 "which is not included in the subpass description -- array case");
Chris Forbes541f7b02016-08-22 15:30:27 +120016085 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Rene Lindsay07b60af2017-01-10 15:57:55 -070016086 "consumes input attachment index 0 but not provided in subpass");
Chris Forbes541f7b02016-08-22 15:30:27 +120016087
Tony Barbour1fa09702017-03-16 12:09:08 -060016088 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes541f7b02016-08-22 15:30:27 +120016089
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016090 char const *vsSource =
16091 "#version 450\n"
16092 "\n"
16093 "out gl_PerVertex {\n"
16094 " vec4 gl_Position;\n"
16095 "};\n"
16096 "void main(){\n"
16097 " gl_Position = vec4(1);\n"
16098 "}\n";
16099 char const *fsSource =
16100 "#version 450\n"
16101 "\n"
16102 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput xs[1];\n"
16103 "layout(location=0) out vec4 color;\n"
16104 "void main() {\n"
16105 " color = subpassLoad(xs[0]);\n"
16106 "}\n";
Chris Forbes541f7b02016-08-22 15:30:27 +120016107
16108 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
16109 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
16110
16111 VkPipelineObj pipe(m_device);
16112 pipe.AddShader(&vs);
16113 pipe.AddShader(&fs);
16114 pipe.AddColorAttachment();
16115 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16116
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016117 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 2, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
16118 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes541f7b02016-08-22 15:30:27 +120016119 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016120 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes541f7b02016-08-22 15:30:27 +120016121 ASSERT_VK_SUCCESS(err);
16122
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016123 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes541f7b02016-08-22 15:30:27 +120016124 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016125 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes541f7b02016-08-22 15:30:27 +120016126 ASSERT_VK_SUCCESS(err);
16127
16128 // error here.
16129 pipe.CreateVKPipeline(pl, renderPass());
16130
16131 m_errorMonitor->VerifyFound();
16132
16133 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
16134 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
16135}
16136
Chris Forbes10eb9ae2016-05-31 16:09:42 +120016137TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptor) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016138 TEST_DESCRIPTION(
16139 "Test that an error is produced for a compute pipeline consuming a "
16140 "descriptor which is not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016141 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Shader uses descriptor slot 0.0");
Chris Forbes10eb9ae2016-05-31 16:09:42 +120016142
Tony Barbour1fa09702017-03-16 12:09:08 -060016143 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes10eb9ae2016-05-31 16:09:42 +120016144
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016145 char const *csSource =
16146 "#version 450\n"
16147 "\n"
16148 "layout(local_size_x=1) in;\n"
16149 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
16150 "void main(){\n"
16151 " x = vec4(1);\n"
16152 "}\n";
Chris Forbes10eb9ae2016-05-31 16:09:42 +120016153
16154 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
16155
16156 VkDescriptorSetObj descriptorSet(m_device);
16157 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
16158
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016159 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
16160 nullptr,
16161 0,
16162 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
16163 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
16164 descriptorSet.GetPipelineLayout(),
16165 VK_NULL_HANDLE,
16166 -1};
Chris Forbes10eb9ae2016-05-31 16:09:42 +120016167
16168 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016169 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes10eb9ae2016-05-31 16:09:42 +120016170
16171 m_errorMonitor->VerifyFound();
16172
16173 if (err == VK_SUCCESS) {
16174 vkDestroyPipeline(m_device->device(), pipe, nullptr);
16175 }
16176}
16177
Chris Forbes22a9b092016-07-19 14:34:05 +120016178TEST_F(VkLayerTest, CreateComputePipelineDescriptorTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016179 TEST_DESCRIPTION(
16180 "Test that an error is produced for a pipeline consuming a "
16181 "descriptor-backed resource of a mismatched type");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016182 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16183 "but descriptor of type VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER");
Chris Forbes22a9b092016-07-19 14:34:05 +120016184
Tony Barbour1fa09702017-03-16 12:09:08 -060016185 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes22a9b092016-07-19 14:34:05 +120016186
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016187 VkDescriptorSetLayoutBinding binding = {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr};
16188 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &binding};
Chris Forbes22a9b092016-07-19 14:34:05 +120016189 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016190 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes22a9b092016-07-19 14:34:05 +120016191 ASSERT_VK_SUCCESS(err);
16192
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016193 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes22a9b092016-07-19 14:34:05 +120016194 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016195 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes22a9b092016-07-19 14:34:05 +120016196 ASSERT_VK_SUCCESS(err);
16197
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016198 char const *csSource =
16199 "#version 450\n"
16200 "\n"
16201 "layout(local_size_x=1) in;\n"
16202 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
16203 "void main() {\n"
16204 " x.x = 1.0f;\n"
16205 "}\n";
Chris Forbes22a9b092016-07-19 14:34:05 +120016206 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
16207
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016208 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
16209 nullptr,
16210 0,
16211 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
16212 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
16213 pl,
16214 VK_NULL_HANDLE,
16215 -1};
Chris Forbes22a9b092016-07-19 14:34:05 +120016216
16217 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016218 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes22a9b092016-07-19 14:34:05 +120016219
16220 m_errorMonitor->VerifyFound();
16221
16222 if (err == VK_SUCCESS) {
16223 vkDestroyPipeline(m_device->device(), pipe, nullptr);
16224 }
16225
16226 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
16227 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
16228}
16229
Chris Forbes50020592016-07-27 13:52:41 +120016230TEST_F(VkLayerTest, DrawTimeImageViewTypeMismatchWithPipeline) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016231 TEST_DESCRIPTION(
16232 "Test that an error is produced when an image view type "
16233 "does not match the dimensionality declared in the shader");
Chris Forbes50020592016-07-27 13:52:41 +120016234
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016235 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 +120016236
Tony Barbour1fa09702017-03-16 12:09:08 -060016237 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes50020592016-07-27 13:52:41 +120016238 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16239
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016240 char const *vsSource =
16241 "#version 450\n"
16242 "\n"
16243 "out gl_PerVertex { vec4 gl_Position; };\n"
16244 "void main() { gl_Position = vec4(0); }\n";
16245 char const *fsSource =
16246 "#version 450\n"
16247 "\n"
16248 "layout(set=0, binding=0) uniform sampler3D s;\n"
16249 "layout(location=0) out vec4 color;\n"
16250 "void main() {\n"
16251 " color = texture(s, vec3(0));\n"
16252 "}\n";
Chris Forbes50020592016-07-27 13:52:41 +120016253 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
16254 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
16255
16256 VkPipelineObj pipe(m_device);
16257 pipe.AddShader(&vs);
16258 pipe.AddShader(&fs);
16259 pipe.AddColorAttachment();
16260
16261 VkTextureObj texture(m_device, nullptr);
16262 VkSamplerObj sampler(m_device);
16263
16264 VkDescriptorSetObj descriptorSet(m_device);
16265 descriptorSet.AppendSamplerTexture(&sampler, &texture);
16266 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
16267
16268 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
16269 ASSERT_VK_SUCCESS(err);
16270
Tony Barbour552f6c02016-12-21 14:34:07 -070016271 m_commandBuffer->BeginCommandBuffer();
16272 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes50020592016-07-27 13:52:41 +120016273
16274 m_commandBuffer->BindPipeline(pipe);
16275 m_commandBuffer->BindDescriptorSet(descriptorSet);
16276
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016277 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes50020592016-07-27 13:52:41 +120016278 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016279 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes50020592016-07-27 13:52:41 +120016280 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16281
16282 // error produced here.
16283 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
16284
16285 m_errorMonitor->VerifyFound();
16286
Tony Barbour552f6c02016-12-21 14:34:07 -070016287 m_commandBuffer->EndRenderPass();
16288 m_commandBuffer->EndCommandBuffer();
Chris Forbes50020592016-07-27 13:52:41 +120016289}
16290
Chris Forbes5533bfc2016-07-27 14:12:34 +120016291TEST_F(VkLayerTest, DrawTimeImageMultisampleMismatchWithPipeline) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016292 TEST_DESCRIPTION(
16293 "Test that an error is produced when a multisampled images "
16294 "are consumed via singlesample images types in the shader, or vice versa.");
Chris Forbes5533bfc2016-07-27 14:12:34 +120016295
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016296 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "requires bound image to have multiple samples");
Chris Forbes5533bfc2016-07-27 14:12:34 +120016297
Tony Barbour1fa09702017-03-16 12:09:08 -060016298 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes5533bfc2016-07-27 14:12:34 +120016299 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16300
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016301 char const *vsSource =
16302 "#version 450\n"
16303 "\n"
16304 "out gl_PerVertex { vec4 gl_Position; };\n"
16305 "void main() { gl_Position = vec4(0); }\n";
16306 char const *fsSource =
16307 "#version 450\n"
16308 "\n"
16309 "layout(set=0, binding=0) uniform sampler2DMS s;\n"
16310 "layout(location=0) out vec4 color;\n"
16311 "void main() {\n"
16312 " color = texelFetch(s, ivec2(0), 0);\n"
16313 "}\n";
Chris Forbes5533bfc2016-07-27 14:12:34 +120016314 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
16315 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
16316
16317 VkPipelineObj pipe(m_device);
16318 pipe.AddShader(&vs);
16319 pipe.AddShader(&fs);
16320 pipe.AddColorAttachment();
16321
16322 VkTextureObj texture(m_device, nullptr);
16323 VkSamplerObj sampler(m_device);
16324
16325 VkDescriptorSetObj descriptorSet(m_device);
16326 descriptorSet.AppendSamplerTexture(&sampler, &texture);
16327 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
16328
16329 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
16330 ASSERT_VK_SUCCESS(err);
16331
Tony Barbour552f6c02016-12-21 14:34:07 -070016332 m_commandBuffer->BeginCommandBuffer();
16333 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes5533bfc2016-07-27 14:12:34 +120016334
16335 m_commandBuffer->BindPipeline(pipe);
16336 m_commandBuffer->BindDescriptorSet(descriptorSet);
16337
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016338 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes5533bfc2016-07-27 14:12:34 +120016339 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016340 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes5533bfc2016-07-27 14:12:34 +120016341 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16342
16343 // error produced here.
16344 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
16345
16346 m_errorMonitor->VerifyFound();
16347
Tony Barbour552f6c02016-12-21 14:34:07 -070016348 m_commandBuffer->EndRenderPass();
16349 m_commandBuffer->EndCommandBuffer();
Chris Forbes5533bfc2016-07-27 14:12:34 +120016350}
16351
Mark Youngc48c4c12016-04-11 14:26:49 -060016352TEST_F(VkLayerTest, CreateImageLimitsViolationMaxWidth) {
Tony Barbour1fa09702017-03-16 12:09:08 -060016353 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060016354
Jeremy Hayesbb63cc12017-03-20 15:33:01 -060016355 VkFormat const format = VK_FORMAT_B8G8R8A8_UNORM;
16356 {
16357 VkFormatProperties properties;
16358 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), format, &properties);
16359 if (properties.optimalTilingFeatures == 0) {
16360 printf(" Image format not supported; skipped.\n");
16361 return;
16362 }
16363 }
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060016364
Jeremy Hayesbb63cc12017-03-20 15:33:01 -060016365 VkImageCreateInfo info = {};
16366 info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16367 info.pNext = NULL;
16368 info.imageType = VK_IMAGE_TYPE_2D;
16369 info.format = format;
16370 info.extent.height = 32;
16371 info.extent.depth = 1;
16372 info.mipLevels = 1;
16373 info.arrayLayers = 1;
16374 info.samples = VK_SAMPLE_COUNT_1_BIT;
16375 info.tiling = VK_IMAGE_TILING_OPTIMAL;
16376 info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
16377 info.flags = 0;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060016378
16379 // Introduce error by sending down a bogus width extent
Jeremy Hayesbb63cc12017-03-20 15:33:01 -060016380 {
16381 VkImageFormatProperties properties;
16382 auto const result = vkGetPhysicalDeviceImageFormatProperties(m_device->phy().handle(), info.format, info.imageType,
16383 info.tiling, info.usage, info.flags, &properties);
16384 ASSERT_VK_SUCCESS(result);
16385 info.extent.width = properties.maxExtent.width + 1;
16386 }
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060016387
Jeremy Hayesbb63cc12017-03-20 15:33:01 -060016388 VkImage image;
16389 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
16390 vkCreateImage(m_device->device(), &info, NULL, &image);
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016391 m_errorMonitor->VerifyFound();
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060016392}
16393
Mark Youngc48c4c12016-04-11 14:26:49 -060016394TEST_F(VkLayerTest, CreateImageLimitsViolationMinWidth) {
Tony Barbour1fa09702017-03-16 12:09:08 -060016395 ASSERT_NO_FATAL_FAILURE(Init());
Mark Youngc48c4c12016-04-11 14:26:49 -060016396
Jeremy Hayesbb63cc12017-03-20 15:33:01 -060016397 VkFormat const format = VK_FORMAT_B8G8R8A8_UNORM;
16398 {
16399 VkFormatProperties properties;
16400 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), format, &properties);
16401 if (properties.optimalTilingFeatures == 0) {
16402 printf(" Image format not supported; skipped.\n");
16403 return;
16404 }
16405 }
Mark Youngc48c4c12016-04-11 14:26:49 -060016406
Jeremy Hayesbb63cc12017-03-20 15:33:01 -060016407 VkImageCreateInfo info = {};
16408 info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16409 info.pNext = NULL;
16410 info.imageType = VK_IMAGE_TYPE_2D;
16411 info.format = format;
16412 info.extent.height = 32;
16413 info.extent.depth = 1;
16414 info.mipLevels = 1;
16415 info.arrayLayers = 1;
16416 info.samples = VK_SAMPLE_COUNT_1_BIT;
16417 info.tiling = VK_IMAGE_TILING_OPTIMAL;
16418 info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
16419 info.flags = 0;
Mark Youngc48c4c12016-04-11 14:26:49 -060016420
16421 // Introduce error by sending down a bogus width extent
Jeremy Hayesbb63cc12017-03-20 15:33:01 -060016422 info.extent.width = 0;
Mark Youngc48c4c12016-04-11 14:26:49 -060016423
Jeremy Hayesbb63cc12017-03-20 15:33:01 -060016424 VkImage image;
Tobin Ehlisa55b1d42017-04-04 12:23:48 -060016425 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02917);
Jeremy Hayesbb63cc12017-03-20 15:33:01 -060016426 m_errorMonitor->SetUnexpectedError("parameter pCreateInfo->extent.width must be greater than 0");
16427 vkCreateImage(m_device->device(), &info, NULL, &image);
Mark Youngc48c4c12016-04-11 14:26:49 -060016428 m_errorMonitor->VerifyFound();
16429}
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -070016430
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060016431TEST_F(VkLayerTest, AttachmentDescriptionUndefinedFormat) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016432 TEST_DESCRIPTION(
16433 "Create a render pass with an attachment description "
16434 "format set to VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060016435
Tony Barbour1fa09702017-03-16 12:09:08 -060016436 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060016437 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16438
Jeremy Hayes632e0ab2017-02-09 13:32:28 -070016439 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "format is VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060016440
16441 VkAttachmentReference color_attach = {};
16442 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
16443 color_attach.attachment = 0;
16444 VkSubpassDescription subpass = {};
16445 subpass.colorAttachmentCount = 1;
16446 subpass.pColorAttachments = &color_attach;
16447
16448 VkRenderPassCreateInfo rpci = {};
16449 rpci.subpassCount = 1;
16450 rpci.pSubpasses = &subpass;
16451 rpci.attachmentCount = 1;
16452 VkAttachmentDescription attach_desc = {};
16453 attach_desc.format = VK_FORMAT_UNDEFINED;
16454 rpci.pAttachments = &attach_desc;
16455 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
16456 VkRenderPass rp;
16457 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
16458
16459 m_errorMonitor->VerifyFound();
16460
16461 if (result == VK_SUCCESS) {
16462 vkDestroyRenderPass(m_device->device(), rp, NULL);
16463 }
16464}
16465
Karl Schultz6addd812016-02-02 17:17:23 -070016466TEST_F(VkLayerTest, InvalidImageView) {
Tony Barbour1fa09702017-03-16 12:09:08 -060016467 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehliscde08892015-09-22 10:11:37 -060016468
Mike Stroyana3082432015-09-25 13:39:21 -060016469 // Create an image and try to create a view with bad baseMipLevel
Karl Schultz6addd812016-02-02 17:17:23 -070016470 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
16471 const int32_t tex_width = 32;
16472 const int32_t tex_height = 32;
Tobin Ehliscde08892015-09-22 10:11:37 -060016473
16474 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016475 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16476 image_create_info.pNext = NULL;
16477 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16478 image_create_info.format = tex_format;
16479 image_create_info.extent.width = tex_width;
16480 image_create_info.extent.height = tex_height;
16481 image_create_info.extent.depth = 1;
16482 image_create_info.mipLevels = 1;
16483 image_create_info.arrayLayers = 1;
16484 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16485 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16486 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
16487 image_create_info.flags = 0;
Tobin Ehliscde08892015-09-22 10:11:37 -060016488
Jeremy Hayesa1ffc2b2017-03-10 16:05:37 -070016489 VkImage image;
16490 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehliscde08892015-09-22 10:11:37 -060016491 ASSERT_VK_SUCCESS(err);
16492
Jeremy Hayesa1ffc2b2017-03-10 16:05:37 -070016493 VkMemoryRequirements requirements;
16494 vkGetImageMemoryRequirements(m_device->device(), image, &requirements);
16495
16496 VkMemoryAllocateInfo alloc_info{};
16497 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16498 alloc_info.pNext = NULL;
16499 alloc_info.memoryTypeIndex = 0;
16500 alloc_info.allocationSize = requirements.size;
16501 bool pass = m_device->phy().set_memory_type(requirements.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
16502 ASSERT_TRUE(pass);
16503
16504 VkDeviceMemory memory;
16505 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &memory);
16506 ASSERT_VK_SUCCESS(err);
16507
16508 err = vkBindImageMemory(m_device->device(), image, memory, 0);
16509
Tobin Ehliscde08892015-09-22 10:11:37 -060016510 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130016511 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070016512 image_view_create_info.image = image;
16513 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
16514 image_view_create_info.format = tex_format;
16515 image_view_create_info.subresourceRange.layerCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016516 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
Karl Schultz6addd812016-02-02 17:17:23 -070016517 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016518 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehliscde08892015-09-22 10:11:37 -060016519
16520 VkImageView view;
Jeremy Hayesa1ffc2b2017-03-10 16:05:37 -070016521 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016522 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016523 m_errorMonitor->VerifyFound();
Jeremy Hayesa1ffc2b2017-03-10 16:05:37 -070016524
16525 vkFreeMemory(m_device->device(), memory, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -060016526 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehliscde08892015-09-22 10:11:37 -060016527}
Mike Stroyana3082432015-09-25 13:39:21 -060016528
Mark Youngd339ba32016-05-30 13:28:35 -060016529TEST_F(VkLayerTest, CreateImageViewNoMemoryBoundToImage) {
16530 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -060016531 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -060016532 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -060016533
Tony Barbour1fa09702017-03-16 12:09:08 -060016534 ASSERT_NO_FATAL_FAILURE(Init());
Mark Youngd339ba32016-05-30 13:28:35 -060016535
16536 // Create an image and try to create a view with no memory backing the image
16537 VkImage image;
16538
16539 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
16540 const int32_t tex_width = 32;
16541 const int32_t tex_height = 32;
16542
16543 VkImageCreateInfo image_create_info = {};
16544 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16545 image_create_info.pNext = NULL;
16546 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16547 image_create_info.format = tex_format;
16548 image_create_info.extent.width = tex_width;
16549 image_create_info.extent.height = tex_height;
16550 image_create_info.extent.depth = 1;
16551 image_create_info.mipLevels = 1;
16552 image_create_info.arrayLayers = 1;
16553 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16554 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16555 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
16556 image_create_info.flags = 0;
16557
16558 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
16559 ASSERT_VK_SUCCESS(err);
16560
16561 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130016562 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Mark Youngd339ba32016-05-30 13:28:35 -060016563 image_view_create_info.image = image;
16564 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
16565 image_view_create_info.format = tex_format;
16566 image_view_create_info.subresourceRange.layerCount = 1;
16567 image_view_create_info.subresourceRange.baseMipLevel = 0;
16568 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016569 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -060016570
16571 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016572 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Youngd339ba32016-05-30 13:28:35 -060016573
16574 m_errorMonitor->VerifyFound();
16575 vkDestroyImage(m_device->device(), image, NULL);
16576 // If last error is success, it still created the view, so delete it.
16577 if (err == VK_SUCCESS) {
16578 vkDestroyImageView(m_device->device(), view, NULL);
16579 }
Mark Youngd339ba32016-05-30 13:28:35 -060016580}
16581
Karl Schultz6addd812016-02-02 17:17:23 -070016582TEST_F(VkLayerTest, InvalidImageViewAspect) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016583 TEST_DESCRIPTION("Create an image and try to create a view with an invalid aspectMask");
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070016584 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00741);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016585
Tony Barbour1fa09702017-03-16 12:09:08 -060016586 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060016587
Karl Schultz6addd812016-02-02 17:17:23 -070016588 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060016589 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060016590 image.Init(32, 32, 1, tex_format, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_LINEAR, 0);
Tobin Ehlis1f567a22016-05-25 16:15:18 -060016591 ASSERT_TRUE(image.initialized());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060016592
16593 VkImageViewCreateInfo image_view_create_info = {};
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060016594 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060016595 image_view_create_info.image = image.handle();
Karl Schultz6addd812016-02-02 17:17:23 -070016596 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
16597 image_view_create_info.format = tex_format;
16598 image_view_create_info.subresourceRange.baseMipLevel = 0;
16599 image_view_create_info.subresourceRange.levelCount = 1;
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060016600 image_view_create_info.subresourceRange.layerCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070016601 // Cause an error by setting an invalid image aspect
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016602 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060016603
16604 VkImageView view;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060016605 vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060016606
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016607 m_errorMonitor->VerifyFound();
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060016608}
16609
Mike Weiblena1e13f42017-02-09 21:25:59 -070016610TEST_F(VkLayerTest, ExerciseGetImageSubresourceLayout) {
16611 TEST_DESCRIPTION("Test vkGetImageSubresourceLayout() valid usages");
16612
Tony Barbour1fa09702017-03-16 12:09:08 -060016613 ASSERT_NO_FATAL_FAILURE(Init());
Mike Weiblena1e13f42017-02-09 21:25:59 -070016614 VkSubresourceLayout subres_layout = {};
16615
16616 // VU 00732: image must have been created with tiling equal to VK_IMAGE_TILING_LINEAR
16617 {
16618 const VkImageTiling tiling = VK_IMAGE_TILING_OPTIMAL; // ERROR: violates VU 00732
16619 VkImageObj img(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060016620 img.InitNoLayout(32, 32, 1, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, tiling);
Mike Weiblena1e13f42017-02-09 21:25:59 -070016621 ASSERT_TRUE(img.initialized());
16622
16623 VkImageSubresource subres = {};
16624 subres.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16625 subres.mipLevel = 0;
16626 subres.arrayLayer = 0;
16627
16628 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00732);
16629 vkGetImageSubresourceLayout(m_device->device(), img.image(), &subres, &subres_layout);
16630 m_errorMonitor->VerifyFound();
16631 }
16632
16633 // VU 00733: The aspectMask member of pSubresource must only have a single bit set
16634 {
16635 VkImageObj img(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060016636 img.InitNoLayout(32, 32, 1, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
Mike Weiblena1e13f42017-02-09 21:25:59 -070016637 ASSERT_TRUE(img.initialized());
16638
16639 VkImageSubresource subres = {};
16640 subres.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_METADATA_BIT; // ERROR: triggers VU 00733
16641 subres.mipLevel = 0;
16642 subres.arrayLayer = 0;
16643
16644 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00733);
16645 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00741);
16646 vkGetImageSubresourceLayout(m_device->device(), img.image(), &subres, &subres_layout);
16647 m_errorMonitor->VerifyFound();
16648 }
16649
16650 // 00739 mipLevel must be less than the mipLevels specified in VkImageCreateInfo when the image was created
16651 {
16652 VkImageObj img(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060016653 img.InitNoLayout(32, 32, 1, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
Mike Weiblena1e13f42017-02-09 21:25:59 -070016654 ASSERT_TRUE(img.initialized());
16655
16656 VkImageSubresource subres = {};
16657 subres.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16658 subres.mipLevel = 1; // ERROR: triggers VU 00739
16659 subres.arrayLayer = 0;
16660
16661 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00739);
16662 vkGetImageSubresourceLayout(m_device->device(), img.image(), &subres, &subres_layout);
16663 m_errorMonitor->VerifyFound();
16664 }
16665
16666 // 00740 arrayLayer must be less than the arrayLayers specified in VkImageCreateInfo when the image was created
16667 {
16668 VkImageObj img(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060016669 img.InitNoLayout(32, 32, 1, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
Mike Weiblena1e13f42017-02-09 21:25:59 -070016670 ASSERT_TRUE(img.initialized());
16671
16672 VkImageSubresource subres = {};
16673 subres.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16674 subres.mipLevel = 0;
16675 subres.arrayLayer = 1; // ERROR: triggers VU 00740
16676
16677 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00740);
16678 vkGetImageSubresourceLayout(m_device->device(), img.image(), &subres, &subres_layout);
16679 m_errorMonitor->VerifyFound();
16680 }
16681}
16682
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016683TEST_F(VkLayerTest, CopyImageLayerCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -070016684 VkResult err;
16685 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016686
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070016687 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01198);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016688
Tony Barbour1fa09702017-03-16 12:09:08 -060016689 ASSERT_NO_FATAL_FAILURE(Init());
Mike Stroyana3082432015-09-25 13:39:21 -060016690
16691 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070016692 VkImage srcImage;
16693 VkImage dstImage;
16694 VkDeviceMemory srcMem;
16695 VkDeviceMemory destMem;
16696 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016697
16698 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016699 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16700 image_create_info.pNext = NULL;
16701 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16702 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16703 image_create_info.extent.width = 32;
16704 image_create_info.extent.height = 32;
16705 image_create_info.extent.depth = 1;
16706 image_create_info.mipLevels = 1;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016707 image_create_info.arrayLayers = 4;
Karl Schultz6addd812016-02-02 17:17:23 -070016708 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16709 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16710 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16711 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016712
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016713 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016714 ASSERT_VK_SUCCESS(err);
16715
Mark Lobodzinski867787a2016-10-14 11:49:55 -060016716 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016717 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016718 ASSERT_VK_SUCCESS(err);
16719
16720 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016721 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016722 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16723 memAlloc.pNext = NULL;
16724 memAlloc.allocationSize = 0;
16725 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016726
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060016727 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016728 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016729 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016730 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016731 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016732 ASSERT_VK_SUCCESS(err);
16733
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016734 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016735 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016736 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016737 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016738 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016739 ASSERT_VK_SUCCESS(err);
16740
16741 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16742 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016743 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016744 ASSERT_VK_SUCCESS(err);
16745
Tony Barbour552f6c02016-12-21 14:34:07 -070016746 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060016747 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016748 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016749 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060016750 copyRegion.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016751 copyRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060016752 copyRegion.srcOffset.x = 0;
16753 copyRegion.srcOffset.y = 0;
16754 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016755 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016756 copyRegion.dstSubresource.mipLevel = 0;
16757 copyRegion.dstSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016758 // Introduce failure by forcing the dst layerCount to differ from src
16759 copyRegion.dstSubresource.layerCount = 3;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016760 copyRegion.dstOffset.x = 0;
16761 copyRegion.dstOffset.y = 0;
16762 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016763 copyRegion.extent.width = 1;
16764 copyRegion.extent.height = 1;
16765 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016766 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070016767 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060016768
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016769 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060016770
Chia-I Wuf7458c52015-10-26 21:10:41 +080016771 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016772 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016773 vkFreeMemory(m_device->device(), srcMem, NULL);
16774 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016775}
16776
Tony Barbourd6673642016-05-05 14:46:39 -060016777TEST_F(VkLayerTest, ImageLayerUnsupportedFormat) {
Tony Barbourd6673642016-05-05 14:46:39 -060016778 TEST_DESCRIPTION("Creating images with unsuported formats ");
16779
Tony Barbour1fa09702017-03-16 12:09:08 -060016780 ASSERT_NO_FATAL_FAILURE(Init());
Tony Barbourd6673642016-05-05 14:46:39 -060016781 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourd6673642016-05-05 14:46:39 -060016782
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060016783 // Create image with unsupported format - Expect FORMAT_UNSUPPORTED
Chris Forbesf4d8e332016-11-28 17:51:10 +130016784 VkImageCreateInfo image_create_info = {};
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060016785 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060016786 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16787 image_create_info.format = VK_FORMAT_UNDEFINED;
16788 image_create_info.extent.width = 32;
16789 image_create_info.extent.height = 32;
16790 image_create_info.extent.depth = 1;
16791 image_create_info.mipLevels = 1;
16792 image_create_info.arrayLayers = 1;
16793 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16794 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16795 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060016796
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016797 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16798 "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED");
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060016799
Jeremy Hayes96dcd812017-03-14 14:04:19 -060016800 VkImage image;
16801 vkCreateImage(m_device->handle(), &image_create_info, NULL, &image);
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060016802 m_errorMonitor->VerifyFound();
16803
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060016804 // Look for a format that is COMPLETELY unsupported with this hardware
Jeremy Hayes96dcd812017-03-14 14:04:19 -060016805 VkFormat unsupported = VK_FORMAT_UNDEFINED;
Tony Barbourd6673642016-05-05 14:46:39 -060016806 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
16807 VkFormat format = static_cast<VkFormat>(f);
16808 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016809 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Tony Barbourd6673642016-05-05 14:46:39 -060016810 unsupported = format;
16811 break;
16812 }
16813 }
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060016814
Tony Barbourd6673642016-05-05 14:46:39 -060016815 if (unsupported != VK_FORMAT_UNDEFINED) {
Tony Barbourd6673642016-05-05 14:46:39 -060016816 image_create_info.format = unsupported;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016817 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is an unsupported format");
Tony Barbourd6673642016-05-05 14:46:39 -060016818
Jeremy Hayes96dcd812017-03-14 14:04:19 -060016819 vkCreateImage(m_device->handle(), &image_create_info, NULL, &image);
Tony Barbourd6673642016-05-05 14:46:39 -060016820 m_errorMonitor->VerifyFound();
16821 }
16822}
16823
16824TEST_F(VkLayerTest, ImageLayerViewTests) {
Tony Barbourd6673642016-05-05 14:46:39 -060016825 TEST_DESCRIPTION("Passing bad parameters to CreateImageView");
16826
Tony Barbour1fa09702017-03-16 12:09:08 -060016827 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -060016828 auto depth_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbourf887b162017-03-09 10:06:46 -070016829 if (!depth_format) {
16830 return;
16831 }
Tony Barbourd6673642016-05-05 14:46:39 -060016832
16833 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060016834 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 -060016835 VK_IMAGE_TILING_OPTIMAL, 0);
16836 ASSERT_TRUE(image.initialized());
16837
16838 VkImageView imgView;
16839 VkImageViewCreateInfo imgViewInfo = {};
16840 imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
16841 imgViewInfo.image = image.handle();
16842 imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
16843 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
16844 imgViewInfo.subresourceRange.layerCount = 1;
16845 imgViewInfo.subresourceRange.baseMipLevel = 0;
16846 imgViewInfo.subresourceRange.levelCount = 1;
16847 imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16848
Jeremy Hayes2ffbaa72017-03-14 17:05:50 -060016849 // View can't have baseMipLevel >= image's mipLevels - Expect VIEW_CREATE_ERROR
Tony Barbourd6673642016-05-05 14:46:39 -060016850 imgViewInfo.subresourceRange.baseMipLevel = 1;
Jeremy Hayes2ffbaa72017-03-14 17:05:50 -060016851 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
Tony Barbourd6673642016-05-05 14:46:39 -060016852 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
16853 m_errorMonitor->VerifyFound();
16854 imgViewInfo.subresourceRange.baseMipLevel = 0;
16855
Tony Barbourd6673642016-05-05 14:46:39 -060016856 // View's levelCount can't be 0 - Expect VIEW_CREATE_ERROR
16857 imgViewInfo.subresourceRange.levelCount = 0;
Jeremy Hayes2ffbaa72017-03-14 17:05:50 -060016858 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
Tony Barbourd6673642016-05-05 14:46:39 -060016859 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
16860 m_errorMonitor->VerifyFound();
16861 imgViewInfo.subresourceRange.levelCount = 1;
16862
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060016863 // View's levelCount can't be > image's mipLevels - Expect VIEW_CREATE_ERROR
16864 imgViewInfo.subresourceRange.levelCount = 2;
16865 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
16866 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
16867 m_errorMonitor->VerifyFound();
16868 imgViewInfo.subresourceRange.levelCount = 1;
16869
16870 // View can't have baseArrayLayer >= image's arraySize - Expect VIEW_CREATE_ERROR
16871 imgViewInfo.subresourceRange.baseArrayLayer = 1;
16872 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00769);
16873 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
16874 m_errorMonitor->VerifyFound();
16875 imgViewInfo.subresourceRange.baseArrayLayer = 0;
16876
Jeremy Hayes2ffbaa72017-03-14 17:05:50 -060016877 // View's layerCount can't be 0 - Expect VIEW_CREATE_ERROR
16878 imgViewInfo.subresourceRange.layerCount = 0;
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060016879 m_errorMonitor->SetDesiredFailureMsg(
16880 VK_DEBUG_REPORT_ERROR_BIT_EXT,
16881 "if pCreateInfo->viewType is VK_IMAGE_TYPE_2D, pCreateInfo->subresourceRange.layerCount must be 1");
Tony Barbourd6673642016-05-05 14:46:39 -060016882 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
16883 m_errorMonitor->VerifyFound();
16884 imgViewInfo.subresourceRange.layerCount = 1;
16885
Tony Barbourd6673642016-05-05 14:46:39 -060016886 // Can't use depth format for view into color image - Expect INVALID_FORMAT
Tony Barbourf887b162017-03-09 10:06:46 -070016887 imgViewInfo.format = depth_format;
Jeremy Hayes2ffbaa72017-03-14 17:05:50 -060016888 m_errorMonitor->SetDesiredFailureMsg(
16889 VK_DEBUG_REPORT_ERROR_BIT_EXT,
16890 "Formats MUST be IDENTICAL unless VK_IMAGE_CREATE_MUTABLE_FORMAT BIT was set on image creation.");
Tony Barbourd6673642016-05-05 14:46:39 -060016891 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
16892 m_errorMonitor->VerifyFound();
16893 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
16894
Tony Barbourd6673642016-05-05 14:46:39 -060016895 // Same compatibility class but no MUTABLE_FORMAT bit - Expect
16896 // VIEW_CREATE_ERROR
16897 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UINT;
Jeremy Hayes2ffbaa72017-03-14 17:05:50 -060016898 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02172);
Tony Barbourd6673642016-05-05 14:46:39 -060016899 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
16900 m_errorMonitor->VerifyFound();
16901 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
16902
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060016903 // TODO: Update framework to easily passing mutable flag into ImageObj init
16904 // For now just allowing image for this one test to not have memory bound
Jeremy Hayes5a7cf2e2017-01-06 15:23:27 -070016905 // TODO: The following line is preventing the intended validation from occurring because of the way the error monitor works.
16906 // m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16907 // " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Tony Barbourd6673642016-05-05 14:46:39 -060016908 // Have MUTABLE_FORMAT bit but not in same compatibility class - Expect
16909 // VIEW_CREATE_ERROR
16910 VkImageCreateInfo mutImgInfo = image.create_info();
16911 VkImage mutImage;
16912 mutImgInfo.format = VK_FORMAT_R8_UINT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016913 assert(m_device->format_properties(VK_FORMAT_R8_UINT).optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
Tony Barbourd6673642016-05-05 14:46:39 -060016914 mutImgInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
16915 mutImgInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Jeremy Hayes2ffbaa72017-03-14 17:05:50 -060016916 VkResult ret = vkCreateImage(m_device->handle(), &mutImgInfo, NULL, &mutImage);
Tony Barbourd6673642016-05-05 14:46:39 -060016917 ASSERT_VK_SUCCESS(ret);
Jeremy Hayes2ffbaa72017-03-14 17:05:50 -060016918
16919 VkMemoryRequirements requirements;
16920 vkGetImageMemoryRequirements(m_device->device(), mutImage, &requirements);
16921
16922 VkMemoryAllocateInfo alloc_info{};
16923 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16924 alloc_info.pNext = NULL;
16925 alloc_info.memoryTypeIndex = 0;
16926 alloc_info.allocationSize = requirements.size;
16927 bool pass = m_device->phy().set_memory_type(requirements.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
16928 ASSERT_TRUE(pass);
16929
16930 VkDeviceMemory memory;
16931 ret = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &memory);
16932 ASSERT_VK_SUCCESS(ret);
16933
16934 ret = vkBindImageMemory(m_device->device(), mutImage, memory, 0);
16935 ASSERT_VK_SUCCESS(ret);
16936
Tony Barbourd6673642016-05-05 14:46:39 -060016937 imgViewInfo.image = mutImage;
Jeremy Hayes2ffbaa72017-03-14 17:05:50 -060016938 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02171);
Tony Barbourd6673642016-05-05 14:46:39 -060016939 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
16940 m_errorMonitor->VerifyFound();
16941 imgViewInfo.image = image.handle();
Jeremy Hayes2ffbaa72017-03-14 17:05:50 -060016942
16943 vkFreeMemory(m_device->device(), memory, NULL);
Tony Barbourd6673642016-05-05 14:46:39 -060016944 vkDestroyImage(m_device->handle(), mutImage, NULL);
16945}
16946
Dave Houlton75967fc2017-03-06 17:21:16 -070016947TEST_F(VkLayerTest, CompressedImageMipCopyTests) {
16948 TEST_DESCRIPTION("Image/Buffer copies for higher mip levels");
16949
Tony Barbour1fa09702017-03-16 12:09:08 -060016950 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton75967fc2017-03-06 17:21:16 -070016951
Jamie Madill35127872017-03-15 16:17:46 -040016952 VkPhysicalDeviceFeatures device_features = {};
Dave Houlton75967fc2017-03-06 17:21:16 -070016953 ASSERT_NO_FATAL_FAILURE(GetPhysicalDeviceFeatures(&device_features));
16954 VkFormat compressed_format = VK_FORMAT_UNDEFINED;
16955 if (device_features.textureCompressionBC) {
16956 compressed_format = VK_FORMAT_BC3_SRGB_BLOCK;
16957 } else if (device_features.textureCompressionETC2) {
16958 compressed_format = VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK;
16959 } else if (device_features.textureCompressionASTC_LDR) {
16960 compressed_format = VK_FORMAT_ASTC_4x4_UNORM_BLOCK;
16961 } else {
16962 printf(" No compressed formats supported - CompressedImageMipCopyTests skipped.\n");
16963 return;
16964 }
16965
16966 VkImageCreateInfo ci;
16967 ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16968 ci.pNext = NULL;
16969 ci.flags = 0;
16970 ci.imageType = VK_IMAGE_TYPE_2D;
16971 ci.format = compressed_format;
16972 ci.extent = {32, 32, 1};
16973 ci.mipLevels = 6;
16974 ci.arrayLayers = 1;
16975 ci.samples = VK_SAMPLE_COUNT_1_BIT;
16976 ci.tiling = VK_IMAGE_TILING_OPTIMAL;
16977 ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
16978 ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
16979 ci.queueFamilyIndexCount = 0;
16980 ci.pQueueFamilyIndices = NULL;
16981 ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
16982
16983 VkImageObj image(m_device);
16984 image.init(&ci);
16985 ASSERT_TRUE(image.initialized());
16986
16987 VkImageObj odd_image(m_device);
16988 ci.extent = {31, 32, 1}; // Mips are [31,32] [15,16] [7,8] [3,4], [1,2] [1,1]
16989 odd_image.init(&ci);
16990 ASSERT_TRUE(odd_image.initialized());
16991
16992 // Allocate buffers
16993 VkMemoryPropertyFlags reqs = 0;
16994 vk_testing::Buffer buffer_1024, buffer_64, buffer_16, buffer_8;
16995 buffer_1024.init_as_src_and_dst(*m_device, 1024, reqs);
16996 buffer_64.init_as_src_and_dst(*m_device, 64, reqs);
16997 buffer_16.init_as_src_and_dst(*m_device, 16, reqs);
16998 buffer_8.init_as_src_and_dst(*m_device, 8, reqs);
16999
17000 VkBufferImageCopy region = {};
17001 region.bufferRowLength = 0;
17002 region.bufferImageHeight = 0;
17003 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17004 region.imageSubresource.layerCount = 1;
17005 region.imageOffset = {0, 0, 0};
17006 region.bufferOffset = 0;
17007
17008 // start recording
17009 m_commandBuffer->BeginCommandBuffer();
17010
17011 // Mip level copies that work - 5 levels
17012 m_errorMonitor->ExpectSuccess();
17013
17014 // Mip 0 should fit in 1k buffer - 1k texels @ 1b each
17015 region.imageExtent = {32, 32, 1};
17016 region.imageSubresource.mipLevel = 0;
17017 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_1024.handle(), 1,
17018 &region);
17019 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_1024.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17020 &region);
17021
17022 // Mip 2 should fit in 64b buffer - 64 texels @ 1b each
17023 region.imageExtent = {8, 8, 1};
17024 region.imageSubresource.mipLevel = 2;
17025 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_64.handle(), 1,
17026 &region);
17027 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17028 &region);
17029
17030 // Mip 3 should fit in 16b buffer - 16 texels @ 1b each
17031 region.imageExtent = {4, 4, 1};
17032 region.imageSubresource.mipLevel = 3;
17033 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
17034 &region);
17035 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17036 &region);
17037
17038 // Mip 4&5 should fit in 16b buffer with no complaint - 4 & 1 texels @ 1b each
17039 region.imageExtent = {2, 2, 1};
17040 region.imageSubresource.mipLevel = 4;
17041 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
17042 &region);
17043 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17044 &region);
17045
17046 region.imageExtent = {1, 1, 1};
17047 region.imageSubresource.mipLevel = 5;
17048 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
17049 &region);
17050 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17051 &region);
17052 m_errorMonitor->VerifyNotFound();
17053
17054 // Buffer must accomodate a full compressed block, regardless of texel count
17055 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01246);
17056 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_8.handle(), 1,
17057 &region);
17058 m_errorMonitor->VerifyFound();
17059 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01227);
17060 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_8.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17061 &region);
17062 m_errorMonitor->VerifyFound();
17063
17064 // Copy width < compressed block size, but not the full mip width
17065 region.imageExtent = {1, 2, 1};
17066 region.imageSubresource.mipLevel = 4;
17067 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01275);
17068 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
17069 &region);
17070 m_errorMonitor->VerifyFound();
17071 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01275);
17072 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17073 &region);
17074 m_errorMonitor->VerifyFound();
17075
17076 // Copy height < compressed block size but not the full mip height
17077 region.imageExtent = {2, 1, 1};
17078 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01276);
17079 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
17080 &region);
17081 m_errorMonitor->VerifyFound();
17082 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01276);
17083 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17084 &region);
17085 m_errorMonitor->VerifyFound();
17086
17087 // Offsets must be multiple of compressed block size
17088 region.imageOffset = {1, 1, 0};
17089 region.imageExtent = {1, 1, 1};
17090 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01273);
17091 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
17092 &region);
17093 m_errorMonitor->VerifyFound();
17094 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01273);
17095 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17096 &region);
17097 m_errorMonitor->VerifyFound();
17098
17099 // Offset + extent width = mip width - should succeed
17100 region.imageOffset = {4, 4, 0};
17101 region.imageExtent = {3, 4, 1};
17102 region.imageSubresource.mipLevel = 2;
17103 m_errorMonitor->ExpectSuccess();
17104 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), odd_image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
17105 &region);
17106 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), odd_image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17107 &region);
17108 m_errorMonitor->VerifyNotFound();
17109
17110 // Offset + extent width > mip width, but still within the final compressed block - should succeed
17111 region.imageExtent = {4, 4, 1};
17112 m_errorMonitor->ExpectSuccess();
17113 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), odd_image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
17114 &region);
17115 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), odd_image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17116 &region);
17117 m_errorMonitor->VerifyNotFound();
17118
17119 // Offset + extent width < mip width and not a multiple of block width - should fail
17120 region.imageExtent = {3, 3, 1};
17121 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01276);
17122 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), odd_image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
17123 &region);
17124 m_errorMonitor->VerifyFound();
17125 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01276);
17126 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), odd_image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17127 &region);
17128 m_errorMonitor->VerifyFound();
17129}
17130
Dave Houlton59a20702017-02-02 17:26:23 -070017131TEST_F(VkLayerTest, ImageBufferCopyTests) {
17132 TEST_DESCRIPTION("Image to buffer and buffer to image tests");
17133
Tony Barbour1fa09702017-03-16 12:09:08 -060017134 ASSERT_NO_FATAL_FAILURE(Init());
Tony Barbourf887b162017-03-09 10:06:46 -070017135 VkFormatProperties format_props = m_device->format_properties(VK_FORMAT_D24_UNORM_S8_UINT);
17136 if (!(format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT)) {
17137 printf(" VK_FORMAT_D24_UNORM_S8_UINT not supported. Skipped.\n");
17138 return;
17139 }
Dave Houlton584d51e2017-02-16 12:52:54 -070017140
17141 // Bail if any dimension of transfer granularity is 0.
17142 auto index = m_device->graphics_queue_node_index_;
17143 auto queue_family_properties = m_device->phy().queue_properties();
17144 if ((queue_family_properties[index].minImageTransferGranularity.depth == 0) ||
17145 (queue_family_properties[index].minImageTransferGranularity.width == 0) ||
17146 (queue_family_properties[index].minImageTransferGranularity.height == 0)) {
17147 printf(" Subresource copies are disallowed when xfer granularity (x|y|z) is 0. Skipped.\n");
17148 return;
17149 }
17150
Dave Houlton59a20702017-02-02 17:26:23 -070017151 VkImageObj image_64k(m_device); // 128^2 texels, 64k
17152 VkImageObj image_16k(m_device); // 64^2 texels, 16k
17153 VkImageObj image_16k_depth(m_device); // 64^2 texels, depth, 16k
Dave Houltonf3229d52017-02-21 15:59:08 -070017154 VkImageObj ds_image_4D_1S(m_device); // 256^2 texels, 512kb (256k depth, 64k stencil, 192k pack)
17155 VkImageObj ds_image_3D_1S(m_device); // 256^2 texels, 256kb (192k depth, 64k stencil)
17156 VkImageObj ds_image_2D(m_device); // 256^2 texels, 128k (128k depth)
17157 VkImageObj ds_image_1S(m_device); // 256^2 texels, 64k (64k stencil)
17158
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017159 image_64k.Init(128, 128, 1, VK_FORMAT_R8G8B8A8_UINT,
Dave Houlton59a20702017-02-02 17:26:23 -070017160 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
17161 VK_IMAGE_TILING_OPTIMAL, 0);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017162 image_16k.Init(64, 64, 1, VK_FORMAT_R8G8B8A8_UINT,
Dave Houlton59a20702017-02-02 17:26:23 -070017163 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
17164 VK_IMAGE_TILING_OPTIMAL, 0);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017165 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 -070017166 VK_IMAGE_TILING_OPTIMAL, 0);
Dave Houlton59a20702017-02-02 17:26:23 -070017167 ASSERT_TRUE(image_64k.initialized());
17168 ASSERT_TRUE(image_16k.initialized());
17169 ASSERT_TRUE(image_16k_depth.initialized());
Dave Houlton59a20702017-02-02 17:26:23 -070017170
Dave Houltonf3229d52017-02-21 15:59:08 -070017171 // Verify all needed Depth/Stencil formats are supported
17172 bool missing_ds_support = false;
17173 VkFormatProperties props = {0, 0, 0};
17174 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D32_SFLOAT_S8_UINT, &props);
17175 missing_ds_support |= (props.bufferFeatures == 0 && props.linearTilingFeatures == 0 && props.optimalTilingFeatures == 0);
17176 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D24_UNORM_S8_UINT, &props);
17177 missing_ds_support |= (props.bufferFeatures == 0 && props.linearTilingFeatures == 0 && props.optimalTilingFeatures == 0);
17178 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D16_UNORM, &props);
17179 missing_ds_support |= (props.bufferFeatures == 0 && props.linearTilingFeatures == 0 && props.optimalTilingFeatures == 0);
17180 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_S8_UINT, &props);
17181 missing_ds_support |= (props.bufferFeatures == 0 && props.linearTilingFeatures == 0 && props.optimalTilingFeatures == 0);
17182
17183 if (!missing_ds_support) {
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017184 ds_image_4D_1S.Init(
17185 256, 256, 1, VK_FORMAT_D32_SFLOAT_S8_UINT,
Dave Houltonf3229d52017-02-21 15:59:08 -070017186 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
17187 VK_IMAGE_TILING_OPTIMAL, 0);
17188 ASSERT_TRUE(ds_image_4D_1S.initialized());
17189
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017190 ds_image_3D_1S.Init(
17191 256, 256, 1, VK_FORMAT_D24_UNORM_S8_UINT,
Dave Houltonf3229d52017-02-21 15:59:08 -070017192 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
17193 VK_IMAGE_TILING_OPTIMAL, 0);
17194 ASSERT_TRUE(ds_image_3D_1S.initialized());
17195
Dave Houlton11dcd5e2017-04-25 16:00:10 -060017196 ds_image_2D.Init(
17197 256, 256, 1, VK_FORMAT_D16_UNORM,
17198 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
17199 VK_IMAGE_TILING_OPTIMAL, 0);
Dave Houltonf3229d52017-02-21 15:59:08 -070017200 ASSERT_TRUE(ds_image_2D.initialized());
17201
Dave Houlton11dcd5e2017-04-25 16:00:10 -060017202 ds_image_1S.Init(
17203 256, 256, 1, VK_FORMAT_S8_UINT,
17204 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
17205 VK_IMAGE_TILING_OPTIMAL, 0);
Dave Houltonf3229d52017-02-21 15:59:08 -070017206 ASSERT_TRUE(ds_image_1S.initialized());
17207 }
17208
17209 // Allocate buffers
17210 vk_testing::Buffer buffer_256k, buffer_128k, buffer_64k, buffer_16k;
Dave Houlton59a20702017-02-02 17:26:23 -070017211 VkMemoryPropertyFlags reqs = 0;
Dave Houltonf3229d52017-02-21 15:59:08 -070017212 buffer_256k.init_as_src_and_dst(*m_device, 262144, reqs); // 256k
17213 buffer_128k.init_as_src_and_dst(*m_device, 131072, reqs); // 128k
17214 buffer_64k.init_as_src_and_dst(*m_device, 65536, reqs); // 64k
17215 buffer_16k.init_as_src_and_dst(*m_device, 16384, reqs); // 16k
Dave Houlton59a20702017-02-02 17:26:23 -070017216
17217 VkBufferImageCopy region = {};
17218 region.bufferRowLength = 0;
17219 region.bufferImageHeight = 0;
17220 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17221 region.imageSubresource.layerCount = 1;
17222 region.imageOffset = {0, 0, 0};
17223 region.imageExtent = {64, 64, 1};
17224 region.bufferOffset = 0;
17225
17226 // attempt copies before putting command buffer in recording state
17227 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01240);
17228 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64k.handle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17229 &region);
17230 m_errorMonitor->VerifyFound();
17231
17232 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01258);
17233 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_64k.handle(), 1,
17234 &region);
17235 m_errorMonitor->VerifyFound();
17236
17237 // start recording
17238 m_commandBuffer->BeginCommandBuffer();
17239
17240 // successful copies
17241 m_errorMonitor->ExpectSuccess();
17242 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
17243 &region);
17244 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16k.handle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17245 &region);
17246 region.imageOffset.x = 16; // 16k copy, offset requires larger image
17247 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
17248 &region);
17249 region.imageExtent.height = 78; // > 16k copy requires larger buffer & image
17250 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64k.handle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17251 &region);
17252 region.imageOffset.x = 0;
17253 region.imageExtent.height = 64;
17254 region.bufferOffset = 256; // 16k copy with buffer offset, requires larger buffer
17255 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_64k.handle(), 1,
17256 &region);
17257 m_errorMonitor->VerifyNotFound();
17258
Dave Houlton9dae7ec2017-03-01 16:23:25 -070017259 // image/buffer too small (extent too large) on copy to image
Dave Houlton59a20702017-02-02 17:26:23 -070017260 region.imageExtent = {65, 64, 1};
17261 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01227); // buffer too small
17262 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16k.handle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17263 &region);
17264 m_errorMonitor->VerifyFound();
17265
17266 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01228); // image too small
17267 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64k.handle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17268 &region);
17269 m_errorMonitor->VerifyFound();
17270
17271 // image/buffer too small (offset) on copy to image
17272 region.imageExtent = {64, 64, 1};
17273 region.imageOffset = {0, 4, 0};
17274 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01227); // buffer too small
17275 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16k.handle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17276 &region);
17277 m_errorMonitor->VerifyFound();
17278
17279 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01228); // image too small
17280 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64k.handle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17281 &region);
17282 m_errorMonitor->VerifyFound();
17283
17284 // image/buffer too small on copy to buffer
17285 region.imageExtent = {64, 64, 1};
17286 region.imageOffset = {0, 0, 0};
Mark Lobodzinski80871462017-02-16 10:37:27 -070017287 region.bufferOffset = 4;
Dave Houlton59a20702017-02-02 17:26:23 -070017288 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01246); // buffer too small
17289 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
17290 &region);
17291 m_errorMonitor->VerifyFound();
17292
17293 region.imageExtent = {64, 65, 1};
17294 region.bufferOffset = 0;
17295 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01245); // image too small
17296 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_64k.handle(), 1,
17297 &region);
17298 m_errorMonitor->VerifyFound();
17299
17300 // buffer size ok but rowlength causes loose packing
17301 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01246);
17302 region.imageExtent = {64, 64, 1};
17303 region.bufferRowLength = 68;
17304 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
17305 &region);
17306 m_errorMonitor->VerifyFound();
17307
Dave Houlton9dae7ec2017-03-01 16:23:25 -070017308 // An extent with zero area should produce a warning, but no error
17309 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT | VK_DEBUG_REPORT_ERROR_BIT_EXT, "} has zero area");
17310 region.imageExtent.width = 0;
17311 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
17312 &region);
17313 m_errorMonitor->VerifyFound();
17314
Dave Houlton59a20702017-02-02 17:26:23 -070017315 // aspect bits
17316 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01280); // more than 1 aspect bit set
17317 region.imageExtent = {64, 64, 1};
17318 region.bufferRowLength = 0;
17319 region.bufferImageHeight = 0;
17320 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
17321 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_depth.handle(), VK_IMAGE_LAYOUT_GENERAL,
17322 buffer_16k.handle(), 1, &region);
17323 m_errorMonitor->VerifyFound();
17324
17325 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01279); // mis-matched aspect
17326 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
17327 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
17328 &region);
17329 m_errorMonitor->VerifyFound();
17330
17331 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01279); // different mis-matched aspect
17332 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17333 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_depth.handle(), VK_IMAGE_LAYOUT_GENERAL,
17334 buffer_16k.handle(), 1, &region);
17335 m_errorMonitor->VerifyFound();
17336
Dave Houltonf3229d52017-02-21 15:59:08 -070017337 // Test Depth/Stencil copies
17338 if (missing_ds_support) {
17339 printf(" Depth / Stencil formats unsupported - skipping D/S tests.\n");
17340 } else {
17341 VkBufferImageCopy ds_region = {};
17342 ds_region.bufferOffset = 0;
17343 ds_region.bufferRowLength = 0;
17344 ds_region.bufferImageHeight = 0;
17345 ds_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
17346 ds_region.imageSubresource.mipLevel = 0;
17347 ds_region.imageSubresource.baseArrayLayer = 0;
17348 ds_region.imageSubresource.layerCount = 1;
17349 ds_region.imageOffset = {0, 0, 0};
17350 ds_region.imageExtent = {256, 256, 1};
17351
17352 // Depth copies that should succeed
17353 m_errorMonitor->ExpectSuccess(); // Extract 4b depth per texel, pack into 256k buffer
17354 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_4D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
17355 buffer_256k.handle(), 1, &ds_region);
17356 m_errorMonitor->VerifyNotFound();
17357
17358 m_errorMonitor->ExpectSuccess(); // Extract 3b depth per texel, pack (loose) into 256k buffer
17359 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_3D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
17360 buffer_256k.handle(), 1, &ds_region);
17361 m_errorMonitor->VerifyNotFound();
17362
17363 m_errorMonitor->ExpectSuccess(); // Copy 2b depth per texel, into 128k buffer
17364 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_2D.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
17365 buffer_128k.handle(), 1, &ds_region);
17366 m_errorMonitor->VerifyNotFound();
17367
17368 // Depth copies that should fail
17369 ds_region.bufferOffset = 4;
17370 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17371 VALIDATION_ERROR_01246); // Extract 4b depth per texel, pack into 256k buffer
17372 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_4D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
17373 buffer_256k.handle(), 1, &ds_region);
17374 m_errorMonitor->VerifyFound();
17375
17376 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17377 VALIDATION_ERROR_01246); // Extract 3b depth per texel, pack (loose) into 256k buffer
17378 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_3D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
17379 buffer_256k.handle(), 1, &ds_region);
17380 m_errorMonitor->VerifyFound();
17381
17382 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17383 VALIDATION_ERROR_01246); // Copy 2b depth per texel, into 128k buffer
17384 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_2D.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
17385 buffer_128k.handle(), 1, &ds_region);
17386 m_errorMonitor->VerifyFound();
17387
17388 // Stencil copies that should succeed
17389 ds_region.bufferOffset = 0;
17390 ds_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT;
17391 m_errorMonitor->ExpectSuccess(); // Extract 1b stencil per texel, pack into 64k buffer
17392 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_4D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
17393 buffer_64k.handle(), 1, &ds_region);
17394 m_errorMonitor->VerifyNotFound();
17395
17396 m_errorMonitor->ExpectSuccess(); // Extract 1b stencil per texel, pack into 64k buffer
17397 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_3D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
17398 buffer_64k.handle(), 1, &ds_region);
17399 m_errorMonitor->VerifyNotFound();
17400
17401 m_errorMonitor->ExpectSuccess(); // Copy 1b depth per texel, into 64k buffer
17402 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
17403 buffer_64k.handle(), 1, &ds_region);
17404 m_errorMonitor->VerifyNotFound();
17405
17406 // Stencil copies that should fail
17407 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17408 VALIDATION_ERROR_01246); // Extract 1b stencil per texel, pack into 64k buffer
17409 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_4D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
17410 buffer_16k.handle(), 1, &ds_region);
17411 m_errorMonitor->VerifyFound();
17412
17413 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17414 VALIDATION_ERROR_01246); // Extract 1b stencil per texel, pack into 64k buffer
17415 ds_region.bufferRowLength = 260;
17416 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_3D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
17417 buffer_64k.handle(), 1, &ds_region);
17418 m_errorMonitor->VerifyFound();
17419
17420 ds_region.bufferRowLength = 0;
17421 ds_region.bufferOffset = 4;
17422 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17423 VALIDATION_ERROR_01246); // Copy 1b depth per texel, into 64k buffer
17424 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
17425 buffer_64k.handle(), 1, &ds_region);
17426 m_errorMonitor->VerifyFound();
17427 }
17428
Dave Houlton584d51e2017-02-16 12:52:54 -070017429 // Test compressed formats, if supported
Jamie Madill35127872017-03-15 16:17:46 -040017430 VkPhysicalDeviceFeatures device_features = {};
Dave Houlton584d51e2017-02-16 12:52:54 -070017431 ASSERT_NO_FATAL_FAILURE(GetPhysicalDeviceFeatures(&device_features));
Dave Houltonf3229d52017-02-21 15:59:08 -070017432 if (!(device_features.textureCompressionBC || device_features.textureCompressionETC2 ||
17433 device_features.textureCompressionASTC_LDR)) {
17434 printf(" No compressed formats supported - block compression tests skipped.\n");
17435 } else {
Dave Houlton67e9b532017-03-02 17:00:10 -070017436 VkImageObj image_16k_4x4comp(m_device); // 128^2 texels as 32^2 compressed (4x4) blocks, 16k
17437 VkImageObj image_NPOT_4x4comp(m_device); // 130^2 texels as 33^2 compressed (4x4) blocks
Dave Houlton584d51e2017-02-16 12:52:54 -070017438 if (device_features.textureCompressionBC) {
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017439 image_16k_4x4comp.Init(128, 128, 1, VK_FORMAT_BC3_SRGB_BLOCK, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_OPTIMAL,
17440 0);
17441 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 -070017442 0);
Dave Houlton584d51e2017-02-16 12:52:54 -070017443 } else if (device_features.textureCompressionETC2) {
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017444 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 -070017445 VK_IMAGE_TILING_OPTIMAL, 0);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017446 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 -070017447 VK_IMAGE_TILING_OPTIMAL, 0);
Dave Houlton584d51e2017-02-16 12:52:54 -070017448 } else {
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017449 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 -070017450 VK_IMAGE_TILING_OPTIMAL, 0);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017451 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 -070017452 VK_IMAGE_TILING_OPTIMAL, 0);
Dave Houlton584d51e2017-02-16 12:52:54 -070017453 }
17454 ASSERT_TRUE(image_16k_4x4comp.initialized());
Dave Houlton59a20702017-02-02 17:26:23 -070017455
Dave Houlton584d51e2017-02-16 12:52:54 -070017456 // Just fits
17457 m_errorMonitor->ExpectSuccess();
17458 region.imageExtent = {128, 128, 1};
17459 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
17460 buffer_16k.handle(), 1, &region);
17461 m_errorMonitor->VerifyNotFound();
Dave Houlton59a20702017-02-02 17:26:23 -070017462
Dave Houlton584d51e2017-02-16 12:52:54 -070017463 // with offset, too big for buffer
17464 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01246);
17465 region.bufferOffset = 16;
17466 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
17467 buffer_16k.handle(), 1, &region);
17468 m_errorMonitor->VerifyFound();
Dave Houlton67e9b532017-03-02 17:00:10 -070017469 region.bufferOffset = 0;
Dave Houlton59a20702017-02-02 17:26:23 -070017470
Dave Houlton67e9b532017-03-02 17:00:10 -070017471 // extents that are not a multiple of compressed block size
17472 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01275);
17473 region.imageExtent.width = 66;
17474 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_NPOT_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
17475 buffer_16k.handle(), 1, &region);
17476 m_errorMonitor->VerifyFound();
17477 region.imageExtent.width = 128;
17478
17479 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01276);
Dave Houlton9dae7ec2017-03-01 16:23:25 -070017480 region.imageExtent.height = 2;
Dave Houlton67e9b532017-03-02 17:00:10 -070017481 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_NPOT_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
17482 buffer_16k.handle(), 1, &region);
17483 m_errorMonitor->VerifyFound();
17484 region.imageExtent.height = 128;
17485
17486 // TODO: All available compressed formats are 2D, with block depth of 1. Unable to provoke VU_01277.
17487
17488 // non-multiple extents are allowed if at the far edge of a non-block-multiple image - these should pass
17489 m_errorMonitor->ExpectSuccess();
17490 region.imageExtent.width = 66;
17491 region.imageOffset.x = 64;
17492 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_NPOT_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
17493 buffer_16k.handle(), 1, &region);
17494 region.imageExtent.width = 16;
17495 region.imageOffset.x = 0;
17496 region.imageExtent.height = 2;
17497 region.imageOffset.y = 128;
17498 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_NPOT_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
Dave Houlton9dae7ec2017-03-01 16:23:25 -070017499 buffer_16k.handle(), 1, &region);
17500 m_errorMonitor->VerifyNotFound();
Dave Houlton67e9b532017-03-02 17:00:10 -070017501 region.imageOffset = {0, 0, 0};
Dave Houlton9dae7ec2017-03-01 16:23:25 -070017502
Dave Houlton584d51e2017-02-16 12:52:54 -070017503 // buffer offset must be a multiple of texel block size (16)
17504 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01274);
17505 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01263);
17506 region.imageExtent = {64, 64, 1};
17507 region.bufferOffset = 24;
17508 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
17509 buffer_16k.handle(), 1, &region);
17510 m_errorMonitor->VerifyFound();
Dave Houlton59a20702017-02-02 17:26:23 -070017511
Dave Houlton584d51e2017-02-16 12:52:54 -070017512 // rowlength not a multiple of block width (4)
17513 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01271);
17514 region.bufferOffset = 0;
17515 region.bufferRowLength = 130;
17516 region.bufferImageHeight = 0;
17517 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
17518 buffer_64k.handle(), 1, &region);
17519 m_errorMonitor->VerifyFound();
Dave Houlton59a20702017-02-02 17:26:23 -070017520
Dave Houlton584d51e2017-02-16 12:52:54 -070017521 // imageheight not a multiple of block height (4)
17522 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01272);
17523 region.bufferRowLength = 0;
17524 region.bufferImageHeight = 130;
17525 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
17526 buffer_64k.handle(), 1, &region);
17527 m_errorMonitor->VerifyFound();
Dave Houlton584d51e2017-02-16 12:52:54 -070017528 }
Dave Houlton59a20702017-02-02 17:26:23 -070017529}
17530
Tony Barbourd6673642016-05-05 14:46:39 -060017531TEST_F(VkLayerTest, MiscImageLayerTests) {
Mark Lobodzinskie6911292017-02-15 14:38:51 -070017532 TEST_DESCRIPTION("Image-related tests that don't belong elsewhare");
Tony Barbourd6673642016-05-05 14:46:39 -060017533
Tony Barbour1fa09702017-03-16 12:09:08 -060017534 ASSERT_NO_FATAL_FAILURE(Init());
Tony Barbourd6673642016-05-05 14:46:39 -060017535
Rene Lindsay135204f2016-12-22 17:11:09 -070017536 // TODO: Ideally we should check if a format is supported, before using it.
Tony Barbourd6673642016-05-05 14:46:39 -060017537 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017538 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 -070017539 VK_IMAGE_TILING_OPTIMAL, 0); // 64bpp
Tony Barbourd6673642016-05-05 14:46:39 -060017540 ASSERT_TRUE(image.initialized());
Tony Barbourd6673642016-05-05 14:46:39 -060017541 vk_testing::Buffer buffer;
17542 VkMemoryPropertyFlags reqs = 0;
Rene Lindsay135204f2016-12-22 17:11:09 -070017543 buffer.init_as_src(*m_device, 128 * 128 * 8, reqs);
Tony Barbourd6673642016-05-05 14:46:39 -060017544 VkBufferImageCopy region = {};
17545 region.bufferRowLength = 128;
17546 region.bufferImageHeight = 128;
17547 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17548 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
Mark Lobodzinski3702e932016-11-22 11:40:48 -070017549 region.imageSubresource.layerCount = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060017550 region.imageExtent.height = 4;
17551 region.imageExtent.width = 4;
17552 region.imageExtent.depth = 1;
Rene Lindsay135204f2016-12-22 17:11:09 -070017553
17554 VkImageObj image2(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017555 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 -070017556 VK_IMAGE_TILING_OPTIMAL, 0); // 16bpp
Rene Lindsay135204f2016-12-22 17:11:09 -070017557 ASSERT_TRUE(image2.initialized());
17558 vk_testing::Buffer buffer2;
17559 VkMemoryPropertyFlags reqs2 = 0;
17560 buffer2.init_as_src(*m_device, 128 * 128 * 2, reqs2);
17561 VkBufferImageCopy region2 = {};
17562 region2.bufferRowLength = 128;
17563 region2.bufferImageHeight = 128;
17564 region2.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17565 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
17566 region2.imageSubresource.layerCount = 1;
17567 region2.imageExtent.height = 4;
17568 region2.imageExtent.width = 4;
17569 region2.imageExtent.depth = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060017570 m_commandBuffer->BeginCommandBuffer();
Tony Barbourd6673642016-05-05 14:46:39 -060017571
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070017572 // Image must have offset.z of 0 and extent.depth of 1
17573 // Introduce failure by setting imageExtent.depth to 0
17574 region.imageExtent.depth = 0;
Dave Houlton59a20702017-02-02 17:26:23 -070017575 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01747);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070017576 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017577 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070017578 m_errorMonitor->VerifyFound();
17579
17580 region.imageExtent.depth = 1;
17581
17582 // Image must have offset.z of 0 and extent.depth of 1
17583 // Introduce failure by setting imageOffset.z to 4
Dave Houlton9dae7ec2017-03-01 16:23:25 -070017584 // Note: Also (unavoidably) triggers 'region exceeds image' #1228
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070017585 region.imageOffset.z = 4;
Dave Houlton59a20702017-02-02 17:26:23 -070017586 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01747);
Dave Houlton9dae7ec2017-03-01 16:23:25 -070017587 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01228);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070017588 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017589 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070017590 m_errorMonitor->VerifyFound();
17591
17592 region.imageOffset.z = 0;
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060017593 // BufferOffset must be a multiple of the calling command's VkImage parameter's texel size
17594 // Introduce failure by setting bufferOffset to 1 and 1/2 texels
Rene Lindsay135204f2016-12-22 17:11:09 -070017595 region.bufferOffset = 4;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070017596 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01263);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017597 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
17598 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060017599 m_errorMonitor->VerifyFound();
17600
17601 // BufferOffset must be a multiple of 4
17602 // Introduce failure by setting bufferOffset to a value not divisible by 4
Rene Lindsay135204f2016-12-22 17:11:09 -070017603 region2.bufferOffset = 6;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070017604 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01264);
Rene Lindsay135204f2016-12-22 17:11:09 -070017605 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer2.handle(), image2.handle(),
17606 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region2);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060017607 m_errorMonitor->VerifyFound();
17608
17609 // BufferRowLength must be 0, or greater than or equal to the width member of imageExtent
17610 region.bufferOffset = 0;
17611 region.imageExtent.height = 128;
17612 region.imageExtent.width = 128;
17613 // Introduce failure by setting bufferRowLength > 0 but less than width
17614 region.bufferRowLength = 64;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070017615 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01265);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017616 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
17617 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060017618 m_errorMonitor->VerifyFound();
17619
17620 // BufferImageHeight must be 0, or greater than or equal to the height member of imageExtent
17621 region.bufferRowLength = 128;
17622 // Introduce failure by setting bufferRowHeight > 0 but less than height
17623 region.bufferImageHeight = 64;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070017624 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01266);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017625 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
17626 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060017627 m_errorMonitor->VerifyFound();
17628
17629 region.bufferImageHeight = 128;
Tony Barbourd6673642016-05-05 14:46:39 -060017630 VkImageObj intImage1(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017631 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 -070017632 VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbourd6673642016-05-05 14:46:39 -060017633 VkImageObj intImage2(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017634 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 -070017635 VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbourd6673642016-05-05 14:46:39 -060017636 VkImageBlit blitRegion = {};
17637 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17638 blitRegion.srcSubresource.baseArrayLayer = 0;
17639 blitRegion.srcSubresource.layerCount = 1;
17640 blitRegion.srcSubresource.mipLevel = 0;
17641 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17642 blitRegion.dstSubresource.baseArrayLayer = 0;
17643 blitRegion.dstSubresource.layerCount = 1;
17644 blitRegion.dstSubresource.mipLevel = 0;
17645
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060017646 // Look for NULL-blit warning
Jeremy Hayesf8e749f2017-03-15 09:40:27 -060017647 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
17648 "vkCmdBlitImage: pRegions[0].srcOffsets specify a zero-volume area.");
17649 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
17650 "vkCmdBlitImage: pRegions[0].dstOffsets specify a zero-volume area.");
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017651 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.Layout(), intImage2.handle(),
17652 intImage2.Layout(), 1, &blitRegion, VK_FILTER_LINEAR);
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060017653 m_errorMonitor->VerifyFound();
17654
Mark Lobodzinskic386ecb2017-02-02 16:12:37 -070017655 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00769);
Tony Barbourd6673642016-05-05 14:46:39 -060017656 VkImageMemoryBarrier img_barrier;
17657 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
17658 img_barrier.pNext = NULL;
17659 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
17660 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
17661 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
17662 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
17663 img_barrier.image = image.handle();
17664 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
17665 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
17666 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17667 img_barrier.subresourceRange.baseArrayLayer = 0;
17668 img_barrier.subresourceRange.baseMipLevel = 0;
Tony Barbourd6673642016-05-05 14:46:39 -060017669 img_barrier.subresourceRange.layerCount = 0;
17670 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017671 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
17672 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbourd6673642016-05-05 14:46:39 -060017673 m_errorMonitor->VerifyFound();
17674 img_barrier.subresourceRange.layerCount = 1;
17675}
17676
17677TEST_F(VkLayerTest, ImageFormatLimits) {
Tony Barbourd6673642016-05-05 14:46:39 -060017678 TEST_DESCRIPTION("Exceed the limits of image format ");
17679
Tony Barbour1fa09702017-03-16 12:09:08 -060017680 ASSERT_NO_FATAL_FAILURE(Init());
Jeremy Hayesbb63cc12017-03-20 15:33:01 -060017681
17682 VkFormat const format = VK_FORMAT_B8G8R8A8_UNORM;
17683 {
17684 VkFormatProperties properties;
17685 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), format, &properties);
17686 if (properties.linearTilingFeatures == 0) {
17687 printf(" Image format not supported; skipped.\n");
17688 return;
17689 }
17690 }
17691
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017692 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Tony Barbourd6673642016-05-05 14:46:39 -060017693 VkImageCreateInfo image_create_info = {};
17694 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17695 image_create_info.pNext = NULL;
17696 image_create_info.imageType = VK_IMAGE_TYPE_2D;
Jeremy Hayesbb63cc12017-03-20 15:33:01 -060017697 image_create_info.format = format;
Tony Barbourd6673642016-05-05 14:46:39 -060017698 image_create_info.extent.width = 32;
17699 image_create_info.extent.height = 32;
17700 image_create_info.extent.depth = 1;
17701 image_create_info.mipLevels = 1;
17702 image_create_info.arrayLayers = 1;
17703 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
17704 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
17705 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
17706 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
17707 image_create_info.flags = 0;
17708
17709 VkImage nullImg;
17710 VkImageFormatProperties imgFmtProps;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017711 vkGetPhysicalDeviceImageFormatProperties(gpu(), image_create_info.format, image_create_info.imageType, image_create_info.tiling,
17712 image_create_info.usage, image_create_info.flags, &imgFmtProps);
Rene Lindsayef5bc012017-01-06 15:38:00 -070017713 image_create_info.extent.width = imgFmtProps.maxExtent.width + 1;
Tony Barbourd6673642016-05-05 14:46:39 -060017714 // Expect INVALID_FORMAT_LIMITS_VIOLATION
17715 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
17716 m_errorMonitor->VerifyFound();
Rene Lindsayef5bc012017-01-06 15:38:00 -070017717 image_create_info.extent.width = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060017718
Tony Barbour0907e362017-03-09 15:05:30 -070017719 uint32_t maxDim =
17720 std::max(std::max(image_create_info.extent.width, image_create_info.extent.height), image_create_info.extent.depth);
17721 // If max mip levels exceeds image extents, skip the max mip levels test
17722 if ((imgFmtProps.maxMipLevels + 1) <= (floor(log2(maxDim)) + 1)) {
17723 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
17724 image_create_info.mipLevels = imgFmtProps.maxMipLevels + 1;
17725 // Expect INVALID_FORMAT_LIMITS_VIOLATION
17726 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
17727 m_errorMonitor->VerifyFound();
17728 image_create_info.mipLevels = 1;
17729 }
Tony Barbourd6673642016-05-05 14:46:39 -060017730
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017731 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060017732 image_create_info.arrayLayers = imgFmtProps.maxArrayLayers + 1;
17733 // Expect INVALID_FORMAT_LIMITS_VIOLATION
17734 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
17735 m_errorMonitor->VerifyFound();
17736 image_create_info.arrayLayers = 1;
17737
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017738 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is not supported by format");
Tony Barbourd6673642016-05-05 14:46:39 -060017739 int samples = imgFmtProps.sampleCounts >> 1;
17740 image_create_info.samples = (VkSampleCountFlagBits)samples;
17741 // Expect INVALID_FORMAT_LIMITS_VIOLATION
17742 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
17743 m_errorMonitor->VerifyFound();
17744 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
17745
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017746 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17747 "pCreateInfo->initialLayout, must be "
17748 "VK_IMAGE_LAYOUT_UNDEFINED or "
17749 "VK_IMAGE_LAYOUT_PREINITIALIZED");
Tony Barbourd6673642016-05-05 14:46:39 -060017750 image_create_info.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
17751 // Expect INVALID_LAYOUT
17752 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
17753 m_errorMonitor->VerifyFound();
17754 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
17755}
17756
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017757TEST_F(VkLayerTest, CopyImageSrcSizeExceeded) {
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017758 // Image copy with source region specified greater than src image size
Tony Barbour1fa09702017-03-16 12:09:08 -060017759 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017760
Dave Houltonfc1a4052017-04-27 14:32:45 -060017761 // Create images with full mip chain
17762 VkImageCreateInfo ci;
17763 ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17764 ci.pNext = NULL;
17765 ci.flags = 0;
17766 ci.imageType = VK_IMAGE_TYPE_3D;
17767 ci.format = VK_FORMAT_R8G8B8A8_UNORM;
17768 ci.extent = {32, 32, 8};
17769 ci.mipLevels = 6;
17770 ci.arrayLayers = 1;
17771 ci.samples = VK_SAMPLE_COUNT_1_BIT;
17772 ci.tiling = VK_IMAGE_TILING_OPTIMAL;
17773 ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
17774 ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
17775 ci.queueFamilyIndexCount = 0;
17776 ci.pQueueFamilyIndices = NULL;
17777 ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
17778
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017779 VkImageObj src_image(m_device);
Dave Houltonfc1a4052017-04-27 14:32:45 -060017780 src_image.init(&ci);
17781 ASSERT_TRUE(src_image.initialized());
17782
17783 // Dest image with one more mip level
17784 ci.extent = {64, 64, 16};
17785 ci.mipLevels = 7;
17786 ci.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017787 VkImageObj dst_image(m_device);
Dave Houltonfc1a4052017-04-27 14:32:45 -060017788 dst_image.init(&ci);
17789 ASSERT_TRUE(dst_image.initialized());
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017790
Tony Barbour552f6c02016-12-21 14:34:07 -070017791 m_commandBuffer->BeginCommandBuffer();
Dave Houltonfc1a4052017-04-27 14:32:45 -060017792
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017793 VkImageCopy copy_region;
Dave Houltonfc1a4052017-04-27 14:32:45 -060017794 copy_region.extent = {32, 32, 8};
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017795 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017796 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Dave Houltoncee81d02017-05-02 11:00:10 -060017797 copy_region.srcSubresource.mipLevel = 0;
17798 copy_region.dstSubresource.mipLevel = 0;
Dave Houltonfc1a4052017-04-27 14:32:45 -060017799 copy_region.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017800 copy_region.dstSubresource.baseArrayLayer = 0;
Dave Houltonfc1a4052017-04-27 14:32:45 -060017801 copy_region.srcSubresource.layerCount = 1;
17802 copy_region.dstSubresource.layerCount = 1;
17803 copy_region.srcOffset = {0, 0, 0};
17804 copy_region.dstOffset = {0, 0, 0};
17805
17806 m_errorMonitor->ExpectSuccess();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017807 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
17808 &copy_region);
Dave Houltonfc1a4052017-04-27 14:32:45 -060017809 m_errorMonitor->VerifyNotFound();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017810
Dave Houltonfc1a4052017-04-27 14:32:45 -060017811 // Source exceeded in x-dim, VU 01202
17812 copy_region.srcOffset.x = 4;
17813 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01175); // General "contained within" VU
17814 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01202);
17815 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
17816 &copy_region);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017817 m_errorMonitor->VerifyFound();
Dave Houltonfc1a4052017-04-27 14:32:45 -060017818
17819 // Source exceeded in y-dim, VU 01203
17820 copy_region.srcOffset.x = 0;
17821 copy_region.extent.height = 48;
17822 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01175);
17823 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01203);
17824 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
17825 &copy_region);
17826 m_errorMonitor->VerifyFound();
17827
17828 // Source exceeded in z-dim, VU 01204
17829 copy_region.extent = {4, 4, 4};
17830 copy_region.srcSubresource.mipLevel = 2;
17831 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01175);
17832 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01204);
17833 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
17834 &copy_region);
17835 m_errorMonitor->VerifyFound();
17836
17837 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017838}
17839
17840TEST_F(VkLayerTest, CopyImageDstSizeExceeded) {
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017841 // Image copy with dest region specified greater than dest image size
Tony Barbour1fa09702017-03-16 12:09:08 -060017842 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017843
Dave Houltonfc1a4052017-04-27 14:32:45 -060017844 // Create images with full mip chain
17845 VkImageCreateInfo ci;
17846 ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17847 ci.pNext = NULL;
17848 ci.flags = 0;
17849 ci.imageType = VK_IMAGE_TYPE_3D;
17850 ci.format = VK_FORMAT_R8G8B8A8_UNORM;
17851 ci.extent = {32, 32, 8};
17852 ci.mipLevels = 6;
17853 ci.arrayLayers = 1;
17854 ci.samples = VK_SAMPLE_COUNT_1_BIT;
17855 ci.tiling = VK_IMAGE_TILING_OPTIMAL;
17856 ci.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
17857 ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
17858 ci.queueFamilyIndexCount = 0;
17859 ci.pQueueFamilyIndices = NULL;
17860 ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
17861
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017862 VkImageObj dst_image(m_device);
Dave Houltonfc1a4052017-04-27 14:32:45 -060017863 dst_image.init(&ci);
17864 ASSERT_TRUE(dst_image.initialized());
17865
17866 // Src image with one more mip level
17867 ci.extent = {64, 64, 16};
17868 ci.mipLevels = 7;
17869 ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
17870 VkImageObj src_image(m_device);
17871 src_image.init(&ci);
17872 ASSERT_TRUE(src_image.initialized());
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017873
Tony Barbour552f6c02016-12-21 14:34:07 -070017874 m_commandBuffer->BeginCommandBuffer();
Dave Houltonfc1a4052017-04-27 14:32:45 -060017875
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017876 VkImageCopy copy_region;
Dave Houltonfc1a4052017-04-27 14:32:45 -060017877 copy_region.extent = {32, 32, 8};
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017878 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017879 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Dave Houltoncee81d02017-05-02 11:00:10 -060017880 copy_region.srcSubresource.mipLevel = 0;
17881 copy_region.dstSubresource.mipLevel = 0;
Dave Houltonfc1a4052017-04-27 14:32:45 -060017882 copy_region.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017883 copy_region.dstSubresource.baseArrayLayer = 0;
Dave Houltonfc1a4052017-04-27 14:32:45 -060017884 copy_region.srcSubresource.layerCount = 1;
17885 copy_region.dstSubresource.layerCount = 1;
17886 copy_region.srcOffset = {0, 0, 0};
17887 copy_region.dstOffset = {0, 0, 0};
17888
17889 m_errorMonitor->ExpectSuccess();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017890 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
17891 &copy_region);
Dave Houltonfc1a4052017-04-27 14:32:45 -060017892 m_errorMonitor->VerifyNotFound();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017893
Dave Houltonfc1a4052017-04-27 14:32:45 -060017894 // Dest exceeded in x-dim, VU 01205
17895 copy_region.dstOffset.x = 4;
17896 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01176); // General "contained within" VU
17897 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01205);
17898 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
17899 &copy_region);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017900 m_errorMonitor->VerifyFound();
Dave Houltonfc1a4052017-04-27 14:32:45 -060017901
17902 // Dest exceeded in y-dim, VU 01206
17903 copy_region.dstOffset.x = 0;
17904 copy_region.extent.height = 48;
17905 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01176);
17906 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01206);
17907 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
17908 &copy_region);
17909 m_errorMonitor->VerifyFound();
17910
17911 // Dest exceeded in z-dim, VU 01207
17912 copy_region.extent = {4, 4, 4};
17913 copy_region.dstSubresource.mipLevel = 2;
17914 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01176);
17915 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01207);
17916 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
17917 &copy_region);
17918 m_errorMonitor->VerifyFound();
17919
17920 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017921}
17922
Karl Schultz6addd812016-02-02 17:17:23 -070017923TEST_F(VkLayerTest, CopyImageFormatSizeMismatch) {
Karl Schultzbdb75952016-04-19 11:36:49 -060017924 VkResult err;
17925 bool pass;
17926
17927 // Create color images with different format sizes and try to copy between them
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070017928 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01184);
Karl Schultzbdb75952016-04-19 11:36:49 -060017929
Tony Barbour1fa09702017-03-16 12:09:08 -060017930 ASSERT_NO_FATAL_FAILURE(Init());
Karl Schultzbdb75952016-04-19 11:36:49 -060017931
17932 // Create two images of different types and try to copy between them
17933 VkImage srcImage;
17934 VkImage dstImage;
17935 VkDeviceMemory srcMem;
17936 VkDeviceMemory destMem;
17937 VkMemoryRequirements memReqs;
17938
17939 VkImageCreateInfo image_create_info = {};
17940 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17941 image_create_info.pNext = NULL;
17942 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17943 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
17944 image_create_info.extent.width = 32;
17945 image_create_info.extent.height = 32;
17946 image_create_info.extent.depth = 1;
17947 image_create_info.mipLevels = 1;
17948 image_create_info.arrayLayers = 1;
17949 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
17950 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
17951 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
17952 image_create_info.flags = 0;
17953
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017954 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060017955 ASSERT_VK_SUCCESS(err);
17956
17957 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
17958 // Introduce failure by creating second image with a different-sized format.
17959 image_create_info.format = VK_FORMAT_R5G5B5A1_UNORM_PACK16;
Tobin Ehlis6d4d1d52017-04-05 12:06:10 -060017960 VkFormatProperties properties;
17961 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), image_create_info.format, &properties);
17962 if (properties.optimalTilingFeatures == 0) {
17963 printf(" Image format not supported; skipped.\n");
17964 return;
17965 }
Karl Schultzbdb75952016-04-19 11:36:49 -060017966
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017967 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060017968 ASSERT_VK_SUCCESS(err);
17969
17970 // Allocate memory
17971 VkMemoryAllocateInfo memAlloc = {};
17972 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17973 memAlloc.pNext = NULL;
17974 memAlloc.allocationSize = 0;
17975 memAlloc.memoryTypeIndex = 0;
17976
17977 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
17978 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017979 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060017980 ASSERT_TRUE(pass);
17981 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
17982 ASSERT_VK_SUCCESS(err);
17983
17984 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
17985 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017986 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060017987 ASSERT_TRUE(pass);
17988 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
17989 ASSERT_VK_SUCCESS(err);
17990
17991 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
17992 ASSERT_VK_SUCCESS(err);
17993 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
17994 ASSERT_VK_SUCCESS(err);
17995
Tony Barbour552f6c02016-12-21 14:34:07 -070017996 m_commandBuffer->BeginCommandBuffer();
Karl Schultzbdb75952016-04-19 11:36:49 -060017997 VkImageCopy copyRegion;
17998 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17999 copyRegion.srcSubresource.mipLevel = 0;
18000 copyRegion.srcSubresource.baseArrayLayer = 0;
18001 copyRegion.srcSubresource.layerCount = 0;
18002 copyRegion.srcOffset.x = 0;
18003 copyRegion.srcOffset.y = 0;
18004 copyRegion.srcOffset.z = 0;
18005 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
18006 copyRegion.dstSubresource.mipLevel = 0;
18007 copyRegion.dstSubresource.baseArrayLayer = 0;
18008 copyRegion.dstSubresource.layerCount = 0;
18009 copyRegion.dstOffset.x = 0;
18010 copyRegion.dstOffset.y = 0;
18011 copyRegion.dstOffset.z = 0;
18012 copyRegion.extent.width = 1;
18013 copyRegion.extent.height = 1;
18014 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018015 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070018016 m_commandBuffer->EndCommandBuffer();
Karl Schultzbdb75952016-04-19 11:36:49 -060018017
18018 m_errorMonitor->VerifyFound();
18019
18020 vkDestroyImage(m_device->device(), srcImage, NULL);
18021 vkDestroyImage(m_device->device(), dstImage, NULL);
18022 vkFreeMemory(m_device->device(), srcMem, NULL);
18023 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060018024}
18025
Karl Schultz6addd812016-02-02 17:17:23 -070018026TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch) {
18027 VkResult err;
18028 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060018029
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018030 // Create a depth image and a depth/stencil image and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018031 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
18032 "vkCmdCopyImage called with unmatched source and dest image depth");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060018033
Tony Barbour1fa09702017-03-16 12:09:08 -060018034 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -060018035 auto depth_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbourf887b162017-03-09 10:06:46 -070018036 if (!depth_format) {
18037 return;
18038 }
Mike Stroyana3082432015-09-25 13:39:21 -060018039
18040 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070018041 VkImage srcImage;
18042 VkImage dstImage;
18043 VkDeviceMemory srcMem;
18044 VkDeviceMemory destMem;
18045 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060018046
18047 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070018048 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
18049 image_create_info.pNext = NULL;
18050 image_create_info.imageType = VK_IMAGE_TYPE_2D;
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018051 image_create_info.format = VK_FORMAT_D32_SFLOAT;
Karl Schultz6addd812016-02-02 17:17:23 -070018052 image_create_info.extent.width = 32;
18053 image_create_info.extent.height = 32;
18054 image_create_info.extent.depth = 1;
18055 image_create_info.mipLevels = 1;
18056 image_create_info.arrayLayers = 1;
18057 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Youngad61f4b2017-04-07 08:59:56 -060018058 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Karl Schultz6addd812016-02-02 17:17:23 -070018059 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
18060 image_create_info.flags = 0;
Tobin Ehlis6d4d1d52017-04-05 12:06:10 -060018061 VkFormatProperties properties;
18062 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), image_create_info.format, &properties);
18063 if (properties.optimalTilingFeatures == 0) {
18064 printf(" Image format not supported; skipped.\n");
18065 return;
18066 }
Mike Stroyana3082432015-09-25 13:39:21 -060018067
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018068 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060018069 ASSERT_VK_SUCCESS(err);
18070
Karl Schultzbdb75952016-04-19 11:36:49 -060018071 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
18072
Mark Lobodzinskidb117632016-03-31 10:45:56 -060018073 // Introduce failure by creating second image with a depth/stencil format
Karl Schultz6addd812016-02-02 17:17:23 -070018074 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Tony Barbourf887b162017-03-09 10:06:46 -070018075 image_create_info.format = depth_format;
Mark Lobodzinski867787a2016-10-14 11:49:55 -060018076 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060018077
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018078 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060018079 ASSERT_VK_SUCCESS(err);
18080
18081 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018082 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070018083 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18084 memAlloc.pNext = NULL;
18085 memAlloc.allocationSize = 0;
18086 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018087
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060018088 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060018089 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018090 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060018091 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018092 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060018093 ASSERT_VK_SUCCESS(err);
18094
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018095 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060018096 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018097 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060018098 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018099 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060018100 ASSERT_VK_SUCCESS(err);
18101
18102 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
18103 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018104 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060018105 ASSERT_VK_SUCCESS(err);
18106
Tony Barbour552f6c02016-12-21 14:34:07 -070018107 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060018108 VkImageCopy copyRegion;
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018109 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060018110 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060018111 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018112 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018113 copyRegion.srcOffset.x = 0;
18114 copyRegion.srcOffset.y = 0;
18115 copyRegion.srcOffset.z = 0;
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018116 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018117 copyRegion.dstSubresource.mipLevel = 0;
18118 copyRegion.dstSubresource.baseArrayLayer = 0;
18119 copyRegion.dstSubresource.layerCount = 0;
18120 copyRegion.dstOffset.x = 0;
18121 copyRegion.dstOffset.y = 0;
18122 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018123 copyRegion.extent.width = 1;
18124 copyRegion.extent.height = 1;
18125 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018126 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070018127 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060018128
Chris Forbes8f36a8a2016-04-07 13:21:07 +120018129 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060018130
Chia-I Wuf7458c52015-10-26 21:10:41 +080018131 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018132 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080018133 vkFreeMemory(m_device->device(), srcMem, NULL);
18134 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060018135}
18136
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018137TEST_F(VkLayerTest, CopyImageSampleCountMismatch) {
18138 TEST_DESCRIPTION("Image copies with sample count mis-matches");
Dave Houlton33c22b72017-02-28 13:16:02 -070018139
Mark Lobodzinski77e590c2017-03-17 12:05:16 -060018140 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton33c22b72017-02-28 13:16:02 -070018141
18142 VkImageFormatProperties image_format_properties;
18143 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
18144 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT, 0,
18145 &image_format_properties);
18146
18147 if ((0 == (VK_SAMPLE_COUNT_2_BIT & image_format_properties.sampleCounts)) ||
18148 (0 == (VK_SAMPLE_COUNT_4_BIT & image_format_properties.sampleCounts))) {
18149 printf(" Image multi-sample support not found; skipped.\n");
18150 return;
18151 }
18152
18153 VkImageCreateInfo ci;
18154 ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
18155 ci.pNext = NULL;
18156 ci.flags = 0;
18157 ci.imageType = VK_IMAGE_TYPE_2D;
18158 ci.format = VK_FORMAT_R8G8B8A8_UNORM;
18159 ci.extent = {128, 128, 1};
18160 ci.mipLevels = 1;
18161 ci.arrayLayers = 1;
18162 ci.samples = VK_SAMPLE_COUNT_1_BIT;
18163 ci.tiling = VK_IMAGE_TILING_OPTIMAL;
18164 ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
18165 ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
18166 ci.queueFamilyIndexCount = 0;
18167 ci.pQueueFamilyIndices = NULL;
18168 ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
18169
18170 VkImageObj image1(m_device);
18171 image1.init(&ci);
18172 ASSERT_TRUE(image1.initialized());
18173
18174 ci.samples = VK_SAMPLE_COUNT_2_BIT;
18175 VkImageObj image2(m_device);
18176 image2.init(&ci);
18177 ASSERT_TRUE(image2.initialized());
18178
18179 ci.samples = VK_SAMPLE_COUNT_4_BIT;
18180 VkImageObj image4(m_device);
18181 image4.init(&ci);
18182 ASSERT_TRUE(image4.initialized());
18183
18184 m_commandBuffer->BeginCommandBuffer();
18185
18186 VkImageCopy copyRegion;
18187 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
18188 copyRegion.srcSubresource.mipLevel = 0;
18189 copyRegion.srcSubresource.baseArrayLayer = 0;
18190 copyRegion.srcSubresource.layerCount = 1;
18191 copyRegion.srcOffset = {0, 0, 0};
18192 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
18193 copyRegion.dstSubresource.mipLevel = 0;
18194 copyRegion.dstSubresource.baseArrayLayer = 0;
18195 copyRegion.dstSubresource.layerCount = 1;
18196 copyRegion.dstOffset = {0, 0, 0};
18197 copyRegion.extent = {128, 128, 1};
18198
18199 // Copy a single sample image to/from a multi-sample image
18200 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01185);
18201 vkCmdCopyImage(m_commandBuffer->GetBufferHandle(), image1.handle(), VK_IMAGE_LAYOUT_GENERAL, image4.handle(),
18202 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
18203 m_errorMonitor->VerifyFound();
18204
18205 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01185);
18206 vkCmdCopyImage(m_commandBuffer->GetBufferHandle(), image2.handle(), VK_IMAGE_LAYOUT_GENERAL, image1.handle(),
18207 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
18208 m_errorMonitor->VerifyFound();
18209
18210 // Copy between multi-sample images with different sample counts
18211 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01185);
18212 vkCmdCopyImage(m_commandBuffer->GetBufferHandle(), image2.handle(), VK_IMAGE_LAYOUT_GENERAL, image4.handle(),
18213 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
18214 m_errorMonitor->VerifyFound();
18215
18216 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01185);
18217 vkCmdCopyImage(m_commandBuffer->GetBufferHandle(), image4.handle(), VK_IMAGE_LAYOUT_GENERAL, image2.handle(),
18218 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
18219 m_errorMonitor->VerifyFound();
18220
18221 m_commandBuffer->EndCommandBuffer();
18222}
18223
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018224TEST_F(VkLayerTest, CopyImageAspectMismatch) {
18225 TEST_DESCRIPTION("Image copies with aspect mask errors");
Mark Lobodzinski77e590c2017-03-17 12:05:16 -060018226 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -060018227 auto ds_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbour9357d542017-03-24 15:42:21 -060018228 if (!ds_format) {
18229 return;
18230 }
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018231
Tobin Ehlis6d4d1d52017-04-05 12:06:10 -060018232 VkFormatProperties properties;
18233 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D32_SFLOAT, &properties);
18234 if (properties.optimalTilingFeatures == 0) {
18235 printf(" Image format VK_FORMAT_D32_SFLOAT not supported; skipped.\n");
18236 return;
18237 }
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018238 VkImageObj color_image(m_device), ds_image(m_device), depth_image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060018239 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 -060018240 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 -060018241 VK_IMAGE_TILING_OPTIMAL, 0);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060018242 ds_image.Init(128, 128, 1, ds_format, VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
18243 VK_IMAGE_TILING_OPTIMAL, 0);
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018244 ASSERT_TRUE(color_image.initialized());
18245 ASSERT_TRUE(depth_image.initialized());
18246 ASSERT_TRUE(ds_image.initialized());
18247
18248 VkImageCopy copyRegion;
18249 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
18250 copyRegion.srcSubresource.mipLevel = 0;
18251 copyRegion.srcSubresource.baseArrayLayer = 0;
18252 copyRegion.srcSubresource.layerCount = 1;
18253 copyRegion.srcOffset = {0, 0, 0};
18254 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
18255 copyRegion.dstSubresource.mipLevel = 0;
18256 copyRegion.dstSubresource.baseArrayLayer = 0;
18257 copyRegion.dstSubresource.layerCount = 1;
18258 copyRegion.dstOffset = {64, 0, 0};
18259 copyRegion.extent = {64, 128, 1};
18260
18261 // Submitting command before command buffer is in recording state
Dave Houlton3c9fca72017-03-27 17:25:54 -060018262 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
18263 "You must call vkBeginCommandBuffer"); // VALIDATION_ERROR_01192);
18264 vkCmdCopyImage(m_commandBuffer->GetBufferHandle(), depth_image.handle(), VK_IMAGE_LAYOUT_GENERAL, depth_image.handle(),
18265 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018266 m_errorMonitor->VerifyFound();
18267
18268 m_commandBuffer->BeginCommandBuffer();
18269
18270 // Src and dest aspect masks don't match
18271 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT;
18272 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01197);
Dave Houlton3c9fca72017-03-27 17:25:54 -060018273 vkCmdCopyImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, ds_image.handle(),
18274 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018275 m_errorMonitor->VerifyFound();
18276 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
18277
18278 // Illegal combinations of aspect bits - VU 01221
Dave Houlton3c9fca72017-03-27 17:25:54 -060018279 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT; // color must be alone
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018280 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT;
18281 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01221);
18282 // These aspect/format mismatches are redundant but unavoidable here
18283 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01200);
18284 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01201);
Dave Houlton3c9fca72017-03-27 17:25:54 -060018285 vkCmdCopyImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_GENERAL, color_image.handle(),
18286 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018287 m_errorMonitor->VerifyFound();
18288 // Metadata aspect is illegal - VU 01222
18289 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
18290 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
18291 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01222);
18292 // These aspect/format mismatches are redundant but unavoidable here
Dave Houlton3c9fca72017-03-27 17:25:54 -060018293 vkCmdCopyImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_GENERAL, color_image.handle(),
18294 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018295 m_errorMonitor->VerifyFound();
18296
18297 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
18298 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
18299
18300 // Aspect mask doesn't match source image format - VU 01200
18301 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01200);
18302 // Again redundant but unavoidable when provoking vu01200 w/o vu01201
18303 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "unmatched source and dest image depth/stencil formats");
18304 vkCmdCopyImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_GENERAL, depth_image.handle(),
18305 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
18306 m_errorMonitor->VerifyFound();
18307
18308 // Aspect mask doesn't match dest image format - VU 01201
18309 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
18310 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
18311 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01201);
18312 // Again redundant but unavoidable when provoking vu01201 w/o vu01200
18313 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "unmatched source and dest image depth/stencil formats");
18314 vkCmdCopyImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_GENERAL, depth_image.handle(),
18315 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
18316 m_errorMonitor->VerifyFound();
18317
18318 m_commandBuffer->EndCommandBuffer();
18319}
18320
Karl Schultz6addd812016-02-02 17:17:23 -070018321TEST_F(VkLayerTest, ResolveImageLowSampleCount) {
18322 VkResult err;
18323 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060018324
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018325 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
18326 "vkCmdResolveImage called with source sample count less than 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060018327
Tony Barbour1fa09702017-03-16 12:09:08 -060018328 ASSERT_NO_FATAL_FAILURE(Init());
Mike Stroyana3082432015-09-25 13:39:21 -060018329
18330 // Create two images of sample count 1 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070018331 VkImage srcImage;
18332 VkImage dstImage;
18333 VkDeviceMemory srcMem;
18334 VkDeviceMemory destMem;
18335 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060018336
18337 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070018338 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
18339 image_create_info.pNext = NULL;
18340 image_create_info.imageType = VK_IMAGE_TYPE_2D;
18341 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
18342 image_create_info.extent.width = 32;
18343 image_create_info.extent.height = 1;
18344 image_create_info.extent.depth = 1;
18345 image_create_info.mipLevels = 1;
18346 image_create_info.arrayLayers = 1;
18347 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
18348 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
18349 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
18350 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018351
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018352 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060018353 ASSERT_VK_SUCCESS(err);
18354
Karl Schultz6addd812016-02-02 17:17:23 -070018355 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060018356
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018357 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060018358 ASSERT_VK_SUCCESS(err);
18359
18360 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018361 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070018362 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18363 memAlloc.pNext = NULL;
18364 memAlloc.allocationSize = 0;
18365 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018366
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060018367 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060018368 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018369 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060018370 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018371 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060018372 ASSERT_VK_SUCCESS(err);
18373
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018374 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060018375 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018376 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060018377 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018378 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060018379 ASSERT_VK_SUCCESS(err);
18380
18381 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
18382 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018383 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060018384 ASSERT_VK_SUCCESS(err);
18385
Tony Barbour552f6c02016-12-21 14:34:07 -070018386 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060018387 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070018388 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
18389 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060018390 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080018391 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060018392 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060018393 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130018394 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060018395 resolveRegion.srcOffset.x = 0;
18396 resolveRegion.srcOffset.y = 0;
18397 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080018398 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018399 resolveRegion.dstSubresource.mipLevel = 0;
18400 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130018401 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018402 resolveRegion.dstOffset.x = 0;
18403 resolveRegion.dstOffset.y = 0;
18404 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018405 resolveRegion.extent.width = 1;
18406 resolveRegion.extent.height = 1;
18407 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018408 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070018409 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060018410
Chris Forbes8f36a8a2016-04-07 13:21:07 +120018411 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060018412
Chia-I Wuf7458c52015-10-26 21:10:41 +080018413 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018414 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080018415 vkFreeMemory(m_device->device(), srcMem, NULL);
18416 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060018417}
18418
Karl Schultz6addd812016-02-02 17:17:23 -070018419TEST_F(VkLayerTest, ResolveImageHighSampleCount) {
18420 VkResult err;
18421 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060018422
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018423 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
18424 "vkCmdResolveImage called with dest sample count greater than 1.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060018425
Tony Barbour1fa09702017-03-16 12:09:08 -060018426 ASSERT_NO_FATAL_FAILURE(Init());
Mike Stroyana3082432015-09-25 13:39:21 -060018427
Chris Forbesa7530692016-05-08 12:35:39 +120018428 // Create two images of sample count 4 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070018429 VkImage srcImage;
18430 VkImage dstImage;
18431 VkDeviceMemory srcMem;
18432 VkDeviceMemory destMem;
18433 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060018434
18435 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070018436 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
18437 image_create_info.pNext = NULL;
18438 image_create_info.imageType = VK_IMAGE_TYPE_2D;
18439 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
18440 image_create_info.extent.width = 32;
18441 image_create_info.extent.height = 1;
18442 image_create_info.extent.depth = 1;
18443 image_create_info.mipLevels = 1;
18444 image_create_info.arrayLayers = 1;
Chris Forbesa7530692016-05-08 12:35:39 +120018445 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070018446 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
18447 // Note: Some implementations expect color attachment usage for any
18448 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018449 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070018450 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018451
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018452 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060018453 ASSERT_VK_SUCCESS(err);
18454
Karl Schultz6addd812016-02-02 17:17:23 -070018455 // Note: Some implementations expect color attachment usage for any
18456 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018457 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060018458
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018459 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060018460 ASSERT_VK_SUCCESS(err);
18461
18462 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018463 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070018464 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18465 memAlloc.pNext = NULL;
18466 memAlloc.allocationSize = 0;
18467 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018468
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060018469 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060018470 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018471 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060018472 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018473 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060018474 ASSERT_VK_SUCCESS(err);
18475
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018476 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060018477 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018478 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060018479 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018480 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060018481 ASSERT_VK_SUCCESS(err);
18482
18483 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
18484 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018485 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060018486 ASSERT_VK_SUCCESS(err);
18487
Tony Barbour552f6c02016-12-21 14:34:07 -070018488 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060018489 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070018490 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
18491 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060018492 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080018493 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060018494 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060018495 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130018496 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060018497 resolveRegion.srcOffset.x = 0;
18498 resolveRegion.srcOffset.y = 0;
18499 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080018500 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018501 resolveRegion.dstSubresource.mipLevel = 0;
18502 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130018503 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018504 resolveRegion.dstOffset.x = 0;
18505 resolveRegion.dstOffset.y = 0;
18506 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018507 resolveRegion.extent.width = 1;
18508 resolveRegion.extent.height = 1;
18509 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018510 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070018511 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060018512
Chris Forbes8f36a8a2016-04-07 13:21:07 +120018513 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060018514
Chia-I Wuf7458c52015-10-26 21:10:41 +080018515 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018516 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080018517 vkFreeMemory(m_device->device(), srcMem, NULL);
18518 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060018519}
18520
Karl Schultz6addd812016-02-02 17:17:23 -070018521TEST_F(VkLayerTest, ResolveImageFormatMismatch) {
18522 VkResult err;
18523 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060018524
Mark Lobodzinski50fbef12017-02-06 15:31:33 -070018525 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018526 "vkCmdResolveImage called with unmatched source and dest formats.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060018527
Tony Barbour1fa09702017-03-16 12:09:08 -060018528 ASSERT_NO_FATAL_FAILURE(Init());
Mike Stroyana3082432015-09-25 13:39:21 -060018529
18530 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070018531 VkImage srcImage;
18532 VkImage dstImage;
18533 VkDeviceMemory srcMem;
18534 VkDeviceMemory destMem;
18535 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060018536
18537 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070018538 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
18539 image_create_info.pNext = NULL;
18540 image_create_info.imageType = VK_IMAGE_TYPE_2D;
18541 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
18542 image_create_info.extent.width = 32;
18543 image_create_info.extent.height = 1;
18544 image_create_info.extent.depth = 1;
18545 image_create_info.mipLevels = 1;
18546 image_create_info.arrayLayers = 1;
18547 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
18548 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
18549 // Note: Some implementations expect color attachment usage for any
18550 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018551 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070018552 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018553
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018554 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060018555 ASSERT_VK_SUCCESS(err);
18556
Karl Schultz6addd812016-02-02 17:17:23 -070018557 // Set format to something other than source image
18558 image_create_info.format = VK_FORMAT_R32_SFLOAT;
18559 // Note: Some implementations expect color attachment usage for any
18560 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018561 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070018562 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060018563
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018564 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060018565 ASSERT_VK_SUCCESS(err);
18566
18567 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018568 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070018569 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18570 memAlloc.pNext = NULL;
18571 memAlloc.allocationSize = 0;
18572 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018573
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060018574 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060018575 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018576 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060018577 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018578 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060018579 ASSERT_VK_SUCCESS(err);
18580
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018581 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060018582 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018583 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060018584 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018585 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060018586 ASSERT_VK_SUCCESS(err);
18587
18588 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
18589 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018590 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060018591 ASSERT_VK_SUCCESS(err);
18592
Tony Barbour552f6c02016-12-21 14:34:07 -070018593 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060018594 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070018595 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
18596 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060018597 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080018598 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060018599 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060018600 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130018601 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060018602 resolveRegion.srcOffset.x = 0;
18603 resolveRegion.srcOffset.y = 0;
18604 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080018605 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018606 resolveRegion.dstSubresource.mipLevel = 0;
18607 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130018608 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018609 resolveRegion.dstOffset.x = 0;
18610 resolveRegion.dstOffset.y = 0;
18611 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018612 resolveRegion.extent.width = 1;
18613 resolveRegion.extent.height = 1;
18614 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018615 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070018616 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060018617
Chris Forbes8f36a8a2016-04-07 13:21:07 +120018618 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060018619
Chia-I Wuf7458c52015-10-26 21:10:41 +080018620 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018621 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080018622 vkFreeMemory(m_device->device(), srcMem, NULL);
18623 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060018624}
18625
Karl Schultz6addd812016-02-02 17:17:23 -070018626TEST_F(VkLayerTest, ResolveImageTypeMismatch) {
18627 VkResult err;
18628 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060018629
Mark Lobodzinski50fbef12017-02-06 15:31:33 -070018630 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018631 "vkCmdResolveImage called with unmatched source and dest image types.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060018632
Tony Barbour1fa09702017-03-16 12:09:08 -060018633 ASSERT_NO_FATAL_FAILURE(Init());
Mike Stroyana3082432015-09-25 13:39:21 -060018634
18635 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070018636 VkImage srcImage;
18637 VkImage dstImage;
18638 VkDeviceMemory srcMem;
18639 VkDeviceMemory destMem;
18640 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060018641
18642 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070018643 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
18644 image_create_info.pNext = NULL;
18645 image_create_info.imageType = VK_IMAGE_TYPE_2D;
18646 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
18647 image_create_info.extent.width = 32;
18648 image_create_info.extent.height = 1;
18649 image_create_info.extent.depth = 1;
18650 image_create_info.mipLevels = 1;
18651 image_create_info.arrayLayers = 1;
18652 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
18653 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
18654 // Note: Some implementations expect color attachment usage for any
18655 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018656 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070018657 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018658
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018659 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060018660 ASSERT_VK_SUCCESS(err);
18661
Karl Schultz6addd812016-02-02 17:17:23 -070018662 image_create_info.imageType = VK_IMAGE_TYPE_1D;
18663 // Note: Some implementations expect color attachment usage for any
18664 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018665 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070018666 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060018667
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018668 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060018669 ASSERT_VK_SUCCESS(err);
18670
18671 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018672 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070018673 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18674 memAlloc.pNext = NULL;
18675 memAlloc.allocationSize = 0;
18676 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018677
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060018678 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060018679 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018680 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060018681 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018682 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060018683 ASSERT_VK_SUCCESS(err);
18684
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018685 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060018686 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018687 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060018688 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018689 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060018690 ASSERT_VK_SUCCESS(err);
18691
18692 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
18693 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018694 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060018695 ASSERT_VK_SUCCESS(err);
18696
Tony Barbour552f6c02016-12-21 14:34:07 -070018697 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060018698 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070018699 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
18700 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060018701 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080018702 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060018703 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060018704 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130018705 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060018706 resolveRegion.srcOffset.x = 0;
18707 resolveRegion.srcOffset.y = 0;
18708 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080018709 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018710 resolveRegion.dstSubresource.mipLevel = 0;
18711 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130018712 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018713 resolveRegion.dstOffset.x = 0;
18714 resolveRegion.dstOffset.y = 0;
18715 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018716 resolveRegion.extent.width = 1;
18717 resolveRegion.extent.height = 1;
18718 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018719 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070018720 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060018721
Chris Forbes8f36a8a2016-04-07 13:21:07 +120018722 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060018723
Chia-I Wuf7458c52015-10-26 21:10:41 +080018724 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018725 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080018726 vkFreeMemory(m_device->device(), srcMem, NULL);
18727 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060018728}
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018729
Karl Schultz6addd812016-02-02 17:17:23 -070018730TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018731 // Create a single Image descriptor and cause it to first hit an error due
Karl Schultz6addd812016-02-02 17:17:23 -070018732 // to using a DS format, then cause it to hit error due to COLOR_BIT not
18733 // set in aspect
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018734 // The image format check comes 2nd in validation so we trigger it first,
18735 // then when we cause aspect fail next, bad format check will be preempted
Karl Schultz6addd812016-02-02 17:17:23 -070018736 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018737
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018738 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
18739 "Combination depth/stencil image formats can have only the ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060018740
Tony Barbour1fa09702017-03-16 12:09:08 -060018741 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -060018742 auto depth_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbourf887b162017-03-09 10:06:46 -070018743 if (!depth_format) {
18744 return;
18745 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060018746
Chia-I Wu1b99bb22015-10-27 19:25:11 +080018747 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070018748 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
18749 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018750
18751 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070018752 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
18753 ds_pool_ci.pNext = NULL;
18754 ds_pool_ci.maxSets = 1;
18755 ds_pool_ci.poolSizeCount = 1;
18756 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018757
18758 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018759 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018760 ASSERT_VK_SUCCESS(err);
18761
18762 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070018763 dsl_binding.binding = 0;
18764 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
18765 dsl_binding.descriptorCount = 1;
18766 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
18767 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018768
18769 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070018770 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
18771 ds_layout_ci.pNext = NULL;
18772 ds_layout_ci.bindingCount = 1;
18773 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018774 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018775 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018776 ASSERT_VK_SUCCESS(err);
18777
18778 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018779 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080018780 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070018781 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018782 alloc_info.descriptorPool = ds_pool;
18783 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018784 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018785 ASSERT_VK_SUCCESS(err);
18786
Karl Schultz6addd812016-02-02 17:17:23 -070018787 VkImage image_bad;
18788 VkImage image_good;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018789 // One bad format and one good format for Color attachment
Tony Barbourf887b162017-03-09 10:06:46 -070018790 const VkFormat tex_format_bad = depth_format;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018791 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
Karl Schultz6addd812016-02-02 17:17:23 -070018792 const int32_t tex_width = 32;
18793 const int32_t tex_height = 32;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018794
18795 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070018796 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
18797 image_create_info.pNext = NULL;
18798 image_create_info.imageType = VK_IMAGE_TYPE_2D;
18799 image_create_info.format = tex_format_bad;
18800 image_create_info.extent.width = tex_width;
18801 image_create_info.extent.height = tex_height;
18802 image_create_info.extent.depth = 1;
18803 image_create_info.mipLevels = 1;
18804 image_create_info.arrayLayers = 1;
18805 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
18806 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018807 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070018808 image_create_info.flags = 0;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018809
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018810 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018811 ASSERT_VK_SUCCESS(err);
18812 image_create_info.format = tex_format_good;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018813 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
18814 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_good);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018815 ASSERT_VK_SUCCESS(err);
18816
Rene Lindsayf1e89c82016-12-28 13:18:31 -070018817 // ---Bind image memory---
18818 VkMemoryRequirements img_mem_reqs;
18819 vkGetImageMemoryRequirements(m_device->device(), image_bad, &img_mem_reqs);
18820 VkMemoryAllocateInfo image_alloc_info = {};
18821 image_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18822 image_alloc_info.pNext = NULL;
18823 image_alloc_info.memoryTypeIndex = 0;
18824 image_alloc_info.allocationSize = img_mem_reqs.size;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018825 bool pass =
18826 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 -070018827 ASSERT_TRUE(pass);
18828 VkDeviceMemory mem;
18829 err = vkAllocateMemory(m_device->device(), &image_alloc_info, NULL, &mem);
18830 ASSERT_VK_SUCCESS(err);
18831 err = vkBindImageMemory(m_device->device(), image_bad, mem, 0);
18832 ASSERT_VK_SUCCESS(err);
18833 // -----------------------
18834
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018835 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130018836 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070018837 image_view_create_info.image = image_bad;
18838 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
18839 image_view_create_info.format = tex_format_bad;
18840 image_view_create_info.subresourceRange.baseArrayLayer = 0;
18841 image_view_create_info.subresourceRange.baseMipLevel = 0;
18842 image_view_create_info.subresourceRange.layerCount = 1;
18843 image_view_create_info.subresourceRange.levelCount = 1;
Rene Lindsayf1e89c82016-12-28 13:18:31 -070018844 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018845
18846 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018847 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060018848
Chris Forbes8f36a8a2016-04-07 13:21:07 +120018849 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018850
Chia-I Wuf7458c52015-10-26 21:10:41 +080018851 vkDestroyImage(m_device->device(), image_bad, NULL);
18852 vkDestroyImage(m_device->device(), image_good, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080018853 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
18854 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Rene Lindsayf1e89c82016-12-28 13:18:31 -070018855
18856 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018857}
Tobin Ehlis6e23d772016-05-19 11:08:34 -060018858
18859TEST_F(VkLayerTest, ClearImageErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018860 TEST_DESCRIPTION(
18861 "Call ClearColorImage w/ a depth|stencil image and "
18862 "ClearDepthStencilImage with a color image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060018863
Tony Barbour1fa09702017-03-16 12:09:08 -060018864 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -060018865 auto depth_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbourf887b162017-03-09 10:06:46 -070018866 if (!depth_format) {
18867 return;
18868 }
Tobin Ehlis6e23d772016-05-19 11:08:34 -060018869 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18870
Tony Barbour552f6c02016-12-21 14:34:07 -070018871 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis6e23d772016-05-19 11:08:34 -060018872
18873 // Color image
18874 VkClearColorValue clear_color;
18875 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
18876 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
18877 const VkFormat color_format = VK_FORMAT_B8G8R8A8_UNORM;
18878 const int32_t img_width = 32;
18879 const int32_t img_height = 32;
18880 VkImageCreateInfo image_create_info = {};
18881 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
18882 image_create_info.pNext = NULL;
18883 image_create_info.imageType = VK_IMAGE_TYPE_2D;
18884 image_create_info.format = color_format;
18885 image_create_info.extent.width = img_width;
18886 image_create_info.extent.height = img_height;
18887 image_create_info.extent.depth = 1;
18888 image_create_info.mipLevels = 1;
18889 image_create_info.arrayLayers = 1;
18890 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
18891 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
18892 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
18893
18894 vk_testing::Image color_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018895 color_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060018896
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018897 const VkImageSubresourceRange color_range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060018898
18899 // Depth/Stencil image
18900 VkClearDepthStencilValue clear_value = {0};
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018901 reqs = 0; // don't need HOST_VISIBLE DS image
Tobin Ehlis6e23d772016-05-19 11:08:34 -060018902 VkImageCreateInfo ds_image_create_info = vk_testing::Image::create_info();
18903 ds_image_create_info.imageType = VK_IMAGE_TYPE_2D;
Tony Barbourf887b162017-03-09 10:06:46 -070018904 ds_image_create_info.format = depth_format;
Tobin Ehlis6e23d772016-05-19 11:08:34 -060018905 ds_image_create_info.extent.width = 64;
18906 ds_image_create_info.extent.height = 64;
18907 ds_image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Rene Lindsaya1fc64a2016-12-27 15:18:54 -070018908 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 -060018909
18910 vk_testing::Image ds_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018911 ds_image.init(*m_device, (const VkImageCreateInfo &)ds_image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060018912
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018913 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 -060018914
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018915 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060018916
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018917 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tobin Ehlis6e23d772016-05-19 11:08:34 -060018918 &color_range);
18919
18920 m_errorMonitor->VerifyFound();
18921
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018922 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
18923 "vkCmdClearColorImage called with "
18924 "image created without "
18925 "VK_IMAGE_USAGE_TRANSFER_DST_BIT");
Tony Barbour26434b92016-06-02 09:43:50 -060018926
Rene Lindsaya1fc64a2016-12-27 15:18:54 -070018927 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tony Barbour26434b92016-06-02 09:43:50 -060018928 &color_range);
18929
18930 m_errorMonitor->VerifyFound();
18931
Tobin Ehlis6e23d772016-05-19 11:08:34 -060018932 // Call CmdClearDepthStencilImage with color image
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018933 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
18934 "vkCmdClearDepthStencilImage called without a depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060018935
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018936 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
18937 &clear_value, 1, &ds_range);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060018938
18939 m_errorMonitor->VerifyFound();
18940}
Tobin Ehliscde08892015-09-22 10:11:37 -060018941
Mike Schuchardt35fece12017-03-07 14:40:28 -070018942TEST_F(VkLayerTest, CommandQueueFlags) {
18943 TEST_DESCRIPTION(
18944 "Allocate a command buffer on a queue that does not support graphics and try to issue a "
18945 "graphics-only command");
18946
18947 ASSERT_NO_FATAL_FAILURE(Init());
18948
18949 uint32_t queueFamilyIndex = m_device->QueueFamilyWithoutCapabilities(VK_QUEUE_GRAPHICS_BIT);
Dave Houlton3c9fca72017-03-27 17:25:54 -060018950 if (queueFamilyIndex == UINT32_MAX) {
Mike Schuchardt35fece12017-03-07 14:40:28 -070018951 printf(" Non-graphics queue family not found; skipped.\n");
18952 return;
18953 } else {
18954 // Create command pool on a non-graphics queue
18955 VkCommandPoolObj command_pool(m_device, queueFamilyIndex);
18956
18957 // Setup command buffer on pool
18958 VkCommandBufferObj command_buffer(m_device, &command_pool);
18959 command_buffer.BeginCommandBuffer();
18960
18961 // Issue a graphics only command
18962 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01446);
18963 VkViewport viewport = {0, 0, 16, 16, 0, 1};
18964 command_buffer.SetViewport(0, 1, &viewport);
18965 m_errorMonitor->VerifyFound();
18966 }
18967}
18968
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018969// WSI Enabled Tests
18970//
Chris Forbes09368e42016-10-13 11:59:22 +130018971#if 0
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018972TEST_F(VkWsiEnabledLayerTest, TestEnabledWsi) {
18973
18974#if defined(VK_USE_PLATFORM_XCB_KHR)
18975 VkSurfaceKHR surface = VK_NULL_HANDLE;
18976
18977 VkResult err;
18978 bool pass;
18979 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
18980 VkSwapchainCreateInfoKHR swapchain_create_info = {};
18981 // uint32_t swapchain_image_count = 0;
18982 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
18983 // uint32_t image_index = 0;
18984 // VkPresentInfoKHR present_info = {};
18985
Tony Barbour1fa09702017-03-16 12:09:08 -060018986 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018987
18988 // Use the create function from one of the VK_KHR_*_surface extension in
18989 // order to create a surface, testing all known errors in the process,
18990 // before successfully creating a surface:
18991 // First, try to create a surface without a VkXcbSurfaceCreateInfoKHR:
18992 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo specified as NULL");
18993 err = vkCreateXcbSurfaceKHR(instance(), NULL, NULL, &surface);
18994 pass = (err != VK_SUCCESS);
18995 ASSERT_TRUE(pass);
18996 m_errorMonitor->VerifyFound();
18997
18998 // Next, try to create a surface with the wrong
18999 // VkXcbSurfaceCreateInfoKHR::sType:
19000 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
19001 xcb_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
19002 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
19003 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
19004 pass = (err != VK_SUCCESS);
19005 ASSERT_TRUE(pass);
19006 m_errorMonitor->VerifyFound();
19007
19008 // Create a native window, and then correctly create a surface:
19009 xcb_connection_t *connection;
19010 xcb_screen_t *screen;
19011 xcb_window_t xcb_window;
19012 xcb_intern_atom_reply_t *atom_wm_delete_window;
19013
19014 const xcb_setup_t *setup;
19015 xcb_screen_iterator_t iter;
19016 int scr;
19017 uint32_t value_mask, value_list[32];
19018 int width = 1;
19019 int height = 1;
19020
19021 connection = xcb_connect(NULL, &scr);
19022 ASSERT_TRUE(connection != NULL);
19023 setup = xcb_get_setup(connection);
19024 iter = xcb_setup_roots_iterator(setup);
19025 while (scr-- > 0)
19026 xcb_screen_next(&iter);
19027 screen = iter.data;
19028
19029 xcb_window = xcb_generate_id(connection);
19030
19031 value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
19032 value_list[0] = screen->black_pixel;
19033 value_list[1] = XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_STRUCTURE_NOTIFY;
19034
19035 xcb_create_window(connection, XCB_COPY_FROM_PARENT, xcb_window, screen->root, 0, 0, width, height, 0,
19036 XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual, value_mask, value_list);
19037
19038 /* Magic code that will send notification when window is destroyed */
19039 xcb_intern_atom_cookie_t cookie = xcb_intern_atom(connection, 1, 12, "WM_PROTOCOLS");
19040 xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply(connection, cookie, 0);
19041
19042 xcb_intern_atom_cookie_t cookie2 = xcb_intern_atom(connection, 0, 16, "WM_DELETE_WINDOW");
19043 atom_wm_delete_window = xcb_intern_atom_reply(connection, cookie2, 0);
19044 xcb_change_property(connection, XCB_PROP_MODE_REPLACE, xcb_window, (*reply).atom, 4, 32, 1, &(*atom_wm_delete_window).atom);
19045 free(reply);
19046
19047 xcb_map_window(connection, xcb_window);
19048
19049 // Force the x/y coordinates to 100,100 results are identical in consecutive
19050 // runs
19051 const uint32_t coords[] = { 100, 100 };
19052 xcb_configure_window(connection, xcb_window, XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, coords);
19053
19054 // Finally, try to correctly create a surface:
19055 xcb_create_info.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
19056 xcb_create_info.pNext = NULL;
19057 xcb_create_info.flags = 0;
19058 xcb_create_info.connection = connection;
19059 xcb_create_info.window = xcb_window;
19060 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
19061 pass = (err == VK_SUCCESS);
19062 ASSERT_TRUE(pass);
19063
19064 // Check if surface supports presentation:
19065
19066 // 1st, do so without having queried the queue families:
19067 VkBool32 supported = false;
19068 // TODO: Get the following error to come out:
19069 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
19070 "called before calling the vkGetPhysicalDeviceQueueFamilyProperties "
19071 "function");
19072 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
19073 pass = (err != VK_SUCCESS);
19074 // ASSERT_TRUE(pass);
19075 // m_errorMonitor->VerifyFound();
19076
19077 // Next, query a queue family index that's too large:
19078 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
19079 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 100000, surface, &supported);
19080 pass = (err != VK_SUCCESS);
19081 ASSERT_TRUE(pass);
19082 m_errorMonitor->VerifyFound();
19083
19084 // Finally, do so correctly:
19085 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
19086 // SUPPORTED
19087 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
19088 pass = (err == VK_SUCCESS);
19089 ASSERT_TRUE(pass);
19090
19091 // Before proceeding, try to create a swapchain without having called
19092 // vkGetPhysicalDeviceSurfaceCapabilitiesKHR():
19093 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
19094 swapchain_create_info.pNext = NULL;
19095 swapchain_create_info.flags = 0;
19096 swapchain_create_info.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
19097 swapchain_create_info.surface = surface;
19098 swapchain_create_info.imageArrayLayers = 1;
19099 swapchain_create_info.preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
19100 swapchain_create_info.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
19101 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
19102 "called before calling vkGetPhysicalDeviceSurfaceCapabilitiesKHR().");
19103 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
19104 pass = (err != VK_SUCCESS);
19105 ASSERT_TRUE(pass);
19106 m_errorMonitor->VerifyFound();
19107
19108 // Get the surface capabilities:
19109 VkSurfaceCapabilitiesKHR surface_capabilities;
19110
19111 // Do so correctly (only error logged by this entrypoint is if the
19112 // extension isn't enabled):
19113 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &surface_capabilities);
19114 pass = (err == VK_SUCCESS);
19115 ASSERT_TRUE(pass);
19116
19117 // Get the surface formats:
19118 uint32_t surface_format_count;
19119
19120 // First, try without a pointer to surface_format_count:
19121 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSurfaceFormatCount "
19122 "specified as NULL");
19123 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, NULL, NULL);
19124 pass = (err == VK_SUCCESS);
19125 ASSERT_TRUE(pass);
19126 m_errorMonitor->VerifyFound();
19127
19128 // Next, call with a non-NULL pSurfaceFormats, even though we haven't
19129 // correctly done a 1st try (to get the count):
19130 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
19131 surface_format_count = 0;
19132 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, (VkSurfaceFormatKHR *)&surface_format_count);
19133 pass = (err == VK_SUCCESS);
19134 ASSERT_TRUE(pass);
19135 m_errorMonitor->VerifyFound();
19136
19137 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
19138 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
19139 pass = (err == VK_SUCCESS);
19140 ASSERT_TRUE(pass);
19141
19142 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
19143 VkSurfaceFormatKHR *surface_formats = (VkSurfaceFormatKHR *)malloc(surface_format_count * sizeof(VkSurfaceFormatKHR));
19144
19145 // Next, do a 2nd try with surface_format_count being set too high:
19146 surface_format_count += 5;
19147 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
19148 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
19149 pass = (err == VK_SUCCESS);
19150 ASSERT_TRUE(pass);
19151 m_errorMonitor->VerifyFound();
19152
19153 // Finally, do a correct 1st and 2nd try:
19154 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
19155 pass = (err == VK_SUCCESS);
19156 ASSERT_TRUE(pass);
19157 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
19158 pass = (err == VK_SUCCESS);
19159 ASSERT_TRUE(pass);
19160
19161 // Get the surface present modes:
19162 uint32_t surface_present_mode_count;
19163
19164 // First, try without a pointer to surface_format_count:
19165 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pPresentModeCount "
19166 "specified as NULL");
19167
19168 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, NULL, NULL);
19169 pass = (err == VK_SUCCESS);
19170 ASSERT_TRUE(pass);
19171 m_errorMonitor->VerifyFound();
19172
19173 // Next, call with a non-NULL VkPresentModeKHR, even though we haven't
19174 // correctly done a 1st try (to get the count):
19175 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
19176 surface_present_mode_count = 0;
19177 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count,
19178 (VkPresentModeKHR *)&surface_present_mode_count);
19179 pass = (err == VK_SUCCESS);
19180 ASSERT_TRUE(pass);
19181 m_errorMonitor->VerifyFound();
19182
19183 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
19184 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
19185 pass = (err == VK_SUCCESS);
19186 ASSERT_TRUE(pass);
19187
19188 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
19189 VkPresentModeKHR *surface_present_modes = (VkPresentModeKHR *)malloc(surface_present_mode_count * sizeof(VkPresentModeKHR));
19190
19191 // Next, do a 2nd try with surface_format_count being set too high:
19192 surface_present_mode_count += 5;
19193 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
19194 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
19195 pass = (err == VK_SUCCESS);
19196 ASSERT_TRUE(pass);
19197 m_errorMonitor->VerifyFound();
19198
19199 // Finally, do a correct 1st and 2nd try:
19200 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
19201 pass = (err == VK_SUCCESS);
19202 ASSERT_TRUE(pass);
19203 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
19204 pass = (err == VK_SUCCESS);
19205 ASSERT_TRUE(pass);
19206
19207 // Create a swapchain:
19208
19209 // First, try without a pointer to swapchain_create_info:
19210 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo "
19211 "specified as NULL");
19212
19213 err = vkCreateSwapchainKHR(m_device->device(), NULL, NULL, &swapchain);
19214 pass = (err != VK_SUCCESS);
19215 ASSERT_TRUE(pass);
19216 m_errorMonitor->VerifyFound();
19217
19218 // Next, call with a non-NULL swapchain_create_info, that has the wrong
19219 // sType:
19220 swapchain_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
19221 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
19222
19223 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
19224 pass = (err != VK_SUCCESS);
19225 ASSERT_TRUE(pass);
19226 m_errorMonitor->VerifyFound();
19227
19228 // Next, call with a NULL swapchain pointer:
19229 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
19230 swapchain_create_info.pNext = NULL;
19231 swapchain_create_info.flags = 0;
19232 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSwapchain "
19233 "specified as NULL");
19234
19235 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, NULL);
19236 pass = (err != VK_SUCCESS);
19237 ASSERT_TRUE(pass);
19238 m_errorMonitor->VerifyFound();
19239
19240 // TODO: Enhance swapchain layer so that
19241 // swapchain_create_info.queueFamilyIndexCount is checked against something?
19242
19243 // Next, call with a queue family index that's too large:
19244 uint32_t queueFamilyIndex[2] = { 100000, 0 };
19245 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
19246 swapchain_create_info.queueFamilyIndexCount = 2;
19247 swapchain_create_info.pQueueFamilyIndices = queueFamilyIndex;
19248 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
19249 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
19250 pass = (err != VK_SUCCESS);
19251 ASSERT_TRUE(pass);
19252 m_errorMonitor->VerifyFound();
19253
19254 // Next, call a queueFamilyIndexCount that's too small for CONCURRENT:
19255 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
19256 swapchain_create_info.queueFamilyIndexCount = 1;
19257 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
19258 "but with a bad value(s) for pCreateInfo->queueFamilyIndexCount or "
19259 "pCreateInfo->pQueueFamilyIndices).");
19260 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
19261 pass = (err != VK_SUCCESS);
19262 ASSERT_TRUE(pass);
19263 m_errorMonitor->VerifyFound();
19264
19265 // Next, call with an invalid imageSharingMode:
19266 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_MAX_ENUM;
19267 swapchain_create_info.queueFamilyIndexCount = 1;
19268 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
19269 "called with a non-supported pCreateInfo->imageSharingMode (i.e.");
19270 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
19271 pass = (err != VK_SUCCESS);
19272 ASSERT_TRUE(pass);
19273 m_errorMonitor->VerifyFound();
19274 // Fix for the future:
19275 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
19276 // SUPPORTED
19277 swapchain_create_info.queueFamilyIndexCount = 0;
19278 queueFamilyIndex[0] = 0;
19279 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
19280
19281 // TODO: CONTINUE TESTING VALIDATION OF vkCreateSwapchainKHR() ...
19282 // Get the images from a swapchain:
19283 // Acquire an image from a swapchain:
19284 // Present an image to a swapchain:
19285 // Destroy the swapchain:
19286
19287 // TODOs:
19288 //
19289 // - Try destroying the device without first destroying the swapchain
19290 //
19291 // - Try destroying the device without first destroying the surface
19292 //
19293 // - Try destroying the surface without first destroying the swapchain
19294
19295 // Destroy the surface:
19296 vkDestroySurfaceKHR(instance(), surface, NULL);
19297
19298 // Tear down the window:
19299 xcb_destroy_window(connection, xcb_window);
19300 xcb_disconnect(connection);
19301
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019302#else // VK_USE_PLATFORM_XCB_KHR
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019303 return;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019304#endif // VK_USE_PLATFORM_XCB_KHR
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019305}
Chris Forbes09368e42016-10-13 11:59:22 +130019306#endif
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019307
19308//
19309// POSITIVE VALIDATION TESTS
19310//
19311// These tests do not expect to encounter ANY validation errors pass only if this is true
19312
Mark Lobodzinski781aeb52017-02-22 10:57:53 -070019313TEST_F(VkPositiveLayerTest, SecondaryCommandBufferClearColorAttachments) {
19314 TEST_DESCRIPTION("Create a secondary command buffer and record a CmdClearAttachments call into it");
Tony Barbour1fa09702017-03-16 12:09:08 -060019315 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski781aeb52017-02-22 10:57:53 -070019316 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19317
19318 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
19319 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mike Schuchardt06304c22017-03-01 17:09:09 -070019320 command_buffer_allocate_info.commandPool = m_commandPool->handle();
Mark Lobodzinski781aeb52017-02-22 10:57:53 -070019321 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
19322 command_buffer_allocate_info.commandBufferCount = 1;
19323
19324 VkCommandBuffer secondary_command_buffer;
19325 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
19326 VkCommandBufferBeginInfo command_buffer_begin_info = {};
19327 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
19328 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
19329 command_buffer_inheritance_info.renderPass = m_renderPass;
19330 command_buffer_inheritance_info.framebuffer = m_framebuffer;
19331
19332 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19333 command_buffer_begin_info.flags =
19334 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
19335 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
19336
19337 vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
19338 VkClearAttachment color_attachment;
19339 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
19340 color_attachment.clearValue.color.float32[0] = 0;
19341 color_attachment.clearValue.color.float32[1] = 0;
19342 color_attachment.clearValue.color.float32[2] = 0;
19343 color_attachment.clearValue.color.float32[3] = 0;
19344 color_attachment.colorAttachment = 0;
19345 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
19346 vkCmdClearAttachments(secondary_command_buffer, 1, &color_attachment, 1, &clear_rect);
19347}
19348
Tobin Ehlise0006882016-11-03 10:14:28 -060019349TEST_F(VkPositiveLayerTest, SecondaryCommandBufferImageLayoutTransitions) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019350 TEST_DESCRIPTION(
19351 "Perform an image layout transition in a secondary command buffer followed "
19352 "by a transition in the primary.");
Tobin Ehlise0006882016-11-03 10:14:28 -060019353 VkResult err;
19354 m_errorMonitor->ExpectSuccess();
Tony Barbour1fa09702017-03-16 12:09:08 -060019355 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -060019356 auto depth_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbourf887b162017-03-09 10:06:46 -070019357 if (!depth_format) {
19358 return;
19359 }
Tobin Ehlise0006882016-11-03 10:14:28 -060019360 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19361 // Allocate a secondary and primary cmd buffer
19362 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
19363 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mike Schuchardt06304c22017-03-01 17:09:09 -070019364 command_buffer_allocate_info.commandPool = m_commandPool->handle();
Tobin Ehlise0006882016-11-03 10:14:28 -060019365 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
19366 command_buffer_allocate_info.commandBufferCount = 1;
19367
19368 VkCommandBuffer secondary_command_buffer;
19369 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
19370 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19371 VkCommandBuffer primary_command_buffer;
19372 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &primary_command_buffer));
19373 VkCommandBufferBeginInfo command_buffer_begin_info = {};
19374 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
19375 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
19376 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19377 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
19378 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
19379
19380 err = vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
19381 ASSERT_VK_SUCCESS(err);
19382 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060019383 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 -060019384 ASSERT_TRUE(image.initialized());
19385 VkImageMemoryBarrier img_barrier = {};
19386 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
19387 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
19388 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
19389 img_barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
19390 img_barrier.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19391 img_barrier.image = image.handle();
19392 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
19393 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
19394 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
19395 img_barrier.subresourceRange.baseArrayLayer = 0;
19396 img_barrier.subresourceRange.baseMipLevel = 0;
19397 img_barrier.subresourceRange.layerCount = 1;
19398 img_barrier.subresourceRange.levelCount = 1;
19399 vkCmdPipelineBarrier(secondary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr,
19400 0, nullptr, 1, &img_barrier);
19401 err = vkEndCommandBuffer(secondary_command_buffer);
19402 ASSERT_VK_SUCCESS(err);
19403
19404 // Now update primary cmd buffer to execute secondary and transitions image
19405 command_buffer_begin_info.pInheritanceInfo = nullptr;
19406 err = vkBeginCommandBuffer(primary_command_buffer, &command_buffer_begin_info);
19407 ASSERT_VK_SUCCESS(err);
19408 vkCmdExecuteCommands(primary_command_buffer, 1, &secondary_command_buffer);
19409 VkImageMemoryBarrier img_barrier2 = {};
19410 img_barrier2.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
19411 img_barrier2.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
19412 img_barrier2.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
19413 img_barrier2.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19414 img_barrier2.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19415 img_barrier2.image = image.handle();
19416 img_barrier2.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
19417 img_barrier2.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
19418 img_barrier2.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
19419 img_barrier2.subresourceRange.baseArrayLayer = 0;
19420 img_barrier2.subresourceRange.baseMipLevel = 0;
19421 img_barrier2.subresourceRange.layerCount = 1;
19422 img_barrier2.subresourceRange.levelCount = 1;
19423 vkCmdPipelineBarrier(primary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
19424 nullptr, 1, &img_barrier2);
19425 err = vkEndCommandBuffer(primary_command_buffer);
19426 ASSERT_VK_SUCCESS(err);
19427 VkSubmitInfo submit_info = {};
19428 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19429 submit_info.commandBufferCount = 1;
19430 submit_info.pCommandBuffers = &primary_command_buffer;
19431 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
19432 ASSERT_VK_SUCCESS(err);
19433 m_errorMonitor->VerifyNotFound();
19434 err = vkDeviceWaitIdle(m_device->device());
19435 ASSERT_VK_SUCCESS(err);
Mike Schuchardt06304c22017-03-01 17:09:09 -070019436 vkFreeCommandBuffers(m_device->device(), m_commandPool->handle(), 1, &secondary_command_buffer);
19437 vkFreeCommandBuffers(m_device->device(), m_commandPool->handle(), 1, &primary_command_buffer);
Tobin Ehlise0006882016-11-03 10:14:28 -060019438}
19439
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019440// This is a positive test. No failures are expected.
19441TEST_F(VkPositiveLayerTest, IgnoreUnrelatedDescriptor) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019442 TEST_DESCRIPTION(
19443 "Ensure that the vkUpdateDescriptorSets validation code "
19444 "is ignoring VkWriteDescriptorSet members that are not "
19445 "related to the descriptor type specified by "
19446 "VkWriteDescriptorSet::descriptorType. Correct "
19447 "validation behavior will result in the test running to "
19448 "completion without validation errors.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019449
19450 const uintptr_t invalid_ptr = 0xcdcdcdcd;
19451
Tony Barbour1fa09702017-03-16 12:09:08 -060019452 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019453
19454 // Image Case
19455 {
19456 m_errorMonitor->ExpectSuccess();
19457
19458 VkImage image;
19459 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
19460 const int32_t tex_width = 32;
19461 const int32_t tex_height = 32;
19462 VkImageCreateInfo image_create_info = {};
19463 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
19464 image_create_info.pNext = NULL;
19465 image_create_info.imageType = VK_IMAGE_TYPE_2D;
19466 image_create_info.format = tex_format;
19467 image_create_info.extent.width = tex_width;
19468 image_create_info.extent.height = tex_height;
19469 image_create_info.extent.depth = 1;
19470 image_create_info.mipLevels = 1;
19471 image_create_info.arrayLayers = 1;
19472 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
19473 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
19474 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
19475 image_create_info.flags = 0;
19476 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
19477 ASSERT_VK_SUCCESS(err);
19478
19479 VkMemoryRequirements memory_reqs;
19480 VkDeviceMemory image_memory;
19481 bool pass;
19482 VkMemoryAllocateInfo memory_info = {};
19483 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
19484 memory_info.pNext = NULL;
19485 memory_info.allocationSize = 0;
19486 memory_info.memoryTypeIndex = 0;
19487 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
19488 memory_info.allocationSize = memory_reqs.size;
19489 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
19490 ASSERT_TRUE(pass);
19491 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
19492 ASSERT_VK_SUCCESS(err);
19493 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
19494 ASSERT_VK_SUCCESS(err);
19495
19496 VkImageViewCreateInfo image_view_create_info = {};
19497 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
19498 image_view_create_info.image = image;
19499 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
19500 image_view_create_info.format = tex_format;
19501 image_view_create_info.subresourceRange.layerCount = 1;
19502 image_view_create_info.subresourceRange.baseMipLevel = 0;
19503 image_view_create_info.subresourceRange.levelCount = 1;
19504 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
19505
19506 VkImageView view;
19507 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
19508 ASSERT_VK_SUCCESS(err);
19509
19510 VkDescriptorPoolSize ds_type_count = {};
19511 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
19512 ds_type_count.descriptorCount = 1;
19513
19514 VkDescriptorPoolCreateInfo ds_pool_ci = {};
19515 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
19516 ds_pool_ci.pNext = NULL;
19517 ds_pool_ci.maxSets = 1;
19518 ds_pool_ci.poolSizeCount = 1;
19519 ds_pool_ci.pPoolSizes = &ds_type_count;
19520
19521 VkDescriptorPool ds_pool;
19522 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
19523 ASSERT_VK_SUCCESS(err);
19524
19525 VkDescriptorSetLayoutBinding dsl_binding = {};
19526 dsl_binding.binding = 0;
19527 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
19528 dsl_binding.descriptorCount = 1;
19529 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
19530 dsl_binding.pImmutableSamplers = NULL;
19531
19532 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
19533 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
19534 ds_layout_ci.pNext = NULL;
19535 ds_layout_ci.bindingCount = 1;
19536 ds_layout_ci.pBindings = &dsl_binding;
19537 VkDescriptorSetLayout ds_layout;
19538 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
19539 ASSERT_VK_SUCCESS(err);
19540
19541 VkDescriptorSet descriptor_set;
19542 VkDescriptorSetAllocateInfo alloc_info = {};
19543 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
19544 alloc_info.descriptorSetCount = 1;
19545 alloc_info.descriptorPool = ds_pool;
19546 alloc_info.pSetLayouts = &ds_layout;
19547 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
19548 ASSERT_VK_SUCCESS(err);
19549
19550 VkDescriptorImageInfo image_info = {};
19551 image_info.imageView = view;
19552 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
19553
19554 VkWriteDescriptorSet descriptor_write;
19555 memset(&descriptor_write, 0, sizeof(descriptor_write));
19556 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
19557 descriptor_write.dstSet = descriptor_set;
19558 descriptor_write.dstBinding = 0;
19559 descriptor_write.descriptorCount = 1;
19560 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
19561 descriptor_write.pImageInfo = &image_info;
19562
19563 // Set pBufferInfo and pTexelBufferView to invalid values, which should
19564 // be
19565 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE.
19566 // This will most likely produce a crash if the parameter_validation
19567 // layer
19568 // does not correctly ignore pBufferInfo.
19569 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
19570 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
19571
19572 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
19573
19574 m_errorMonitor->VerifyNotFound();
19575
19576 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
19577 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
19578 vkDestroyImageView(m_device->device(), view, NULL);
19579 vkDestroyImage(m_device->device(), image, NULL);
19580 vkFreeMemory(m_device->device(), image_memory, NULL);
19581 }
19582
19583 // Buffer Case
19584 {
19585 m_errorMonitor->ExpectSuccess();
19586
19587 VkBuffer buffer;
19588 uint32_t queue_family_index = 0;
19589 VkBufferCreateInfo buffer_create_info = {};
19590 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
19591 buffer_create_info.size = 1024;
19592 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
19593 buffer_create_info.queueFamilyIndexCount = 1;
19594 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
19595
19596 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
19597 ASSERT_VK_SUCCESS(err);
19598
19599 VkMemoryRequirements memory_reqs;
19600 VkDeviceMemory buffer_memory;
19601 bool pass;
19602 VkMemoryAllocateInfo memory_info = {};
19603 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
19604 memory_info.pNext = NULL;
19605 memory_info.allocationSize = 0;
19606 memory_info.memoryTypeIndex = 0;
19607
19608 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
19609 memory_info.allocationSize = memory_reqs.size;
19610 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
19611 ASSERT_TRUE(pass);
19612
19613 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
19614 ASSERT_VK_SUCCESS(err);
19615 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
19616 ASSERT_VK_SUCCESS(err);
19617
19618 VkDescriptorPoolSize ds_type_count = {};
19619 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
19620 ds_type_count.descriptorCount = 1;
19621
19622 VkDescriptorPoolCreateInfo ds_pool_ci = {};
19623 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
19624 ds_pool_ci.pNext = NULL;
19625 ds_pool_ci.maxSets = 1;
19626 ds_pool_ci.poolSizeCount = 1;
19627 ds_pool_ci.pPoolSizes = &ds_type_count;
19628
19629 VkDescriptorPool ds_pool;
19630 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
19631 ASSERT_VK_SUCCESS(err);
19632
19633 VkDescriptorSetLayoutBinding dsl_binding = {};
19634 dsl_binding.binding = 0;
19635 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
19636 dsl_binding.descriptorCount = 1;
19637 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
19638 dsl_binding.pImmutableSamplers = NULL;
19639
19640 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
19641 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
19642 ds_layout_ci.pNext = NULL;
19643 ds_layout_ci.bindingCount = 1;
19644 ds_layout_ci.pBindings = &dsl_binding;
19645 VkDescriptorSetLayout ds_layout;
19646 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
19647 ASSERT_VK_SUCCESS(err);
19648
19649 VkDescriptorSet descriptor_set;
19650 VkDescriptorSetAllocateInfo alloc_info = {};
19651 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
19652 alloc_info.descriptorSetCount = 1;
19653 alloc_info.descriptorPool = ds_pool;
19654 alloc_info.pSetLayouts = &ds_layout;
19655 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
19656 ASSERT_VK_SUCCESS(err);
19657
19658 VkDescriptorBufferInfo buffer_info = {};
19659 buffer_info.buffer = buffer;
19660 buffer_info.offset = 0;
19661 buffer_info.range = 1024;
19662
19663 VkWriteDescriptorSet descriptor_write;
19664 memset(&descriptor_write, 0, sizeof(descriptor_write));
19665 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
19666 descriptor_write.dstSet = descriptor_set;
19667 descriptor_write.dstBinding = 0;
19668 descriptor_write.descriptorCount = 1;
19669 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
19670 descriptor_write.pBufferInfo = &buffer_info;
19671
19672 // Set pImageInfo and pTexelBufferView to invalid values, which should
19673 // be
19674 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER.
19675 // This will most likely produce a crash if the parameter_validation
19676 // layer
19677 // does not correctly ignore pImageInfo.
19678 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
19679 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
19680
19681 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
19682
19683 m_errorMonitor->VerifyNotFound();
19684
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019685 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
19686 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
19687 vkDestroyBuffer(m_device->device(), buffer, NULL);
19688 vkFreeMemory(m_device->device(), buffer_memory, NULL);
19689 }
19690
19691 // Texel Buffer Case
19692 {
19693 m_errorMonitor->ExpectSuccess();
19694
19695 VkBuffer buffer;
19696 uint32_t queue_family_index = 0;
19697 VkBufferCreateInfo buffer_create_info = {};
19698 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
19699 buffer_create_info.size = 1024;
19700 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
19701 buffer_create_info.queueFamilyIndexCount = 1;
19702 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
19703
19704 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
19705 ASSERT_VK_SUCCESS(err);
19706
19707 VkMemoryRequirements memory_reqs;
19708 VkDeviceMemory buffer_memory;
19709 bool pass;
19710 VkMemoryAllocateInfo memory_info = {};
19711 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
19712 memory_info.pNext = NULL;
19713 memory_info.allocationSize = 0;
19714 memory_info.memoryTypeIndex = 0;
19715
19716 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
19717 memory_info.allocationSize = memory_reqs.size;
19718 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
19719 ASSERT_TRUE(pass);
19720
19721 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
19722 ASSERT_VK_SUCCESS(err);
19723 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
19724 ASSERT_VK_SUCCESS(err);
19725
19726 VkBufferViewCreateInfo buff_view_ci = {};
19727 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
19728 buff_view_ci.buffer = buffer;
19729 buff_view_ci.format = VK_FORMAT_R8_UNORM;
19730 buff_view_ci.range = VK_WHOLE_SIZE;
19731 VkBufferView buffer_view;
19732 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buffer_view);
19733
19734 VkDescriptorPoolSize ds_type_count = {};
19735 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
19736 ds_type_count.descriptorCount = 1;
19737
19738 VkDescriptorPoolCreateInfo ds_pool_ci = {};
19739 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
19740 ds_pool_ci.pNext = NULL;
19741 ds_pool_ci.maxSets = 1;
19742 ds_pool_ci.poolSizeCount = 1;
19743 ds_pool_ci.pPoolSizes = &ds_type_count;
19744
19745 VkDescriptorPool ds_pool;
19746 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
19747 ASSERT_VK_SUCCESS(err);
19748
19749 VkDescriptorSetLayoutBinding dsl_binding = {};
19750 dsl_binding.binding = 0;
19751 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
19752 dsl_binding.descriptorCount = 1;
19753 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
19754 dsl_binding.pImmutableSamplers = NULL;
19755
19756 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
19757 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
19758 ds_layout_ci.pNext = NULL;
19759 ds_layout_ci.bindingCount = 1;
19760 ds_layout_ci.pBindings = &dsl_binding;
19761 VkDescriptorSetLayout ds_layout;
19762 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
19763 ASSERT_VK_SUCCESS(err);
19764
19765 VkDescriptorSet descriptor_set;
19766 VkDescriptorSetAllocateInfo alloc_info = {};
19767 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
19768 alloc_info.descriptorSetCount = 1;
19769 alloc_info.descriptorPool = ds_pool;
19770 alloc_info.pSetLayouts = &ds_layout;
19771 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
19772 ASSERT_VK_SUCCESS(err);
19773
19774 VkWriteDescriptorSet descriptor_write;
19775 memset(&descriptor_write, 0, sizeof(descriptor_write));
19776 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
19777 descriptor_write.dstSet = descriptor_set;
19778 descriptor_write.dstBinding = 0;
19779 descriptor_write.descriptorCount = 1;
19780 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
19781 descriptor_write.pTexelBufferView = &buffer_view;
19782
19783 // Set pImageInfo and pBufferInfo to invalid values, which should be
19784 // ignored for descriptorType ==
19785 // VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER.
19786 // This will most likely produce a crash if the parameter_validation
19787 // layer
19788 // does not correctly ignore pImageInfo and pBufferInfo.
19789 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
19790 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
19791
19792 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
19793
19794 m_errorMonitor->VerifyNotFound();
19795
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019796 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
19797 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
19798 vkDestroyBufferView(m_device->device(), buffer_view, NULL);
19799 vkDestroyBuffer(m_device->device(), buffer, NULL);
19800 vkFreeMemory(m_device->device(), buffer_memory, NULL);
19801 }
19802}
19803
Tobin Ehlis8893af82017-05-08 12:52:25 -060019804TEST_F(VkPositiveLayerTest, ImmutableSamplerOnlyDescriptor) {
19805 TEST_DESCRIPTION(
19806 "Bind a DescriptorSet with only an immutable sampler"
19807 "and make sure that we don't warn for no update.");
19808
19809 ASSERT_NO_FATAL_FAILURE(Init());
19810 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19811
19812 VkDescriptorPoolSize ds_type_count = {};
19813 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
19814 ds_type_count.descriptorCount = 1;
19815
19816 VkDescriptorPoolCreateInfo ds_pool_ci = {};
19817 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
19818 ds_pool_ci.maxSets = 1;
19819 ds_pool_ci.poolSizeCount = 1;
19820 ds_pool_ci.pPoolSizes = &ds_type_count;
19821
19822 VkDescriptorPool ds_pool;
19823 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
19824 ASSERT_VK_SUCCESS(err);
19825
19826 VkSamplerCreateInfo sampler_ci = {};
19827 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
19828 sampler_ci.pNext = NULL;
19829 sampler_ci.magFilter = VK_FILTER_NEAREST;
19830 sampler_ci.minFilter = VK_FILTER_NEAREST;
19831 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
19832 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
19833 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
19834 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
19835 sampler_ci.mipLodBias = 1.0;
19836 sampler_ci.anisotropyEnable = VK_FALSE;
19837 sampler_ci.maxAnisotropy = 1;
19838 sampler_ci.compareEnable = VK_FALSE;
19839 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
19840 sampler_ci.minLod = 1.0;
19841 sampler_ci.maxLod = 1.0;
19842 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
19843 sampler_ci.unnormalizedCoordinates = VK_FALSE;
19844 VkSampler sampler;
19845
19846 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
19847 ASSERT_VK_SUCCESS(err);
19848
19849 VkDescriptorSetLayoutBinding layout_binding = {};
19850 layout_binding.binding = 0;
19851 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
19852 layout_binding.descriptorCount = 1;
19853 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
19854 layout_binding.pImmutableSamplers = static_cast<VkSampler *>(&sampler);
19855
19856 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
19857 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
19858 ds_layout_ci.bindingCount = 1;
19859 ds_layout_ci.pBindings = &layout_binding;
19860 VkDescriptorSetLayout ds_layout;
19861 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
19862 ASSERT_VK_SUCCESS(err);
19863
19864 VkDescriptorSetAllocateInfo alloc_info = {};
19865 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
19866 alloc_info.descriptorSetCount = 1;
19867 alloc_info.descriptorPool = ds_pool;
19868 alloc_info.pSetLayouts = &ds_layout;
19869 VkDescriptorSet descriptor_set;
19870 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
19871 ASSERT_VK_SUCCESS(err);
19872
19873 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
19874 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
19875 pipeline_layout_ci.pNext = NULL;
19876 pipeline_layout_ci.setLayoutCount = 1;
19877 pipeline_layout_ci.pSetLayouts = &ds_layout;
19878
19879 VkPipelineLayout pipeline_layout;
19880 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
19881 ASSERT_VK_SUCCESS(err);
19882
19883 m_errorMonitor->ExpectSuccess();
19884 m_commandBuffer->BeginCommandBuffer();
19885 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
19886
19887 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
19888 &descriptor_set, 0, nullptr);
19889 m_errorMonitor->VerifyNotFound();
19890
19891 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
19892 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
19893 vkDestroySampler(m_device->device(), sampler, NULL);
19894 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
19895}
19896
Tobin Ehlisf7428442016-10-25 07:58:24 -060019897TEST_F(VkLayerTest, DuplicateDescriptorBinding) {
19898 TEST_DESCRIPTION("Create a descriptor set layout with a duplicate binding number.");
19899
Tony Barbour1fa09702017-03-16 12:09:08 -060019900 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisf7428442016-10-25 07:58:24 -060019901 // Create layout where two binding #s are "1"
19902 static const uint32_t NUM_BINDINGS = 3;
19903 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
19904 dsl_binding[0].binding = 1;
19905 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
19906 dsl_binding[0].descriptorCount = 1;
19907 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
19908 dsl_binding[0].pImmutableSamplers = NULL;
19909 dsl_binding[1].binding = 0;
19910 dsl_binding[1].descriptorCount = 1;
19911 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
19912 dsl_binding[1].descriptorCount = 1;
19913 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
19914 dsl_binding[1].pImmutableSamplers = NULL;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019915 dsl_binding[2].binding = 1; // Duplicate binding should cause error
Tobin Ehlisf7428442016-10-25 07:58:24 -060019916 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
19917 dsl_binding[2].descriptorCount = 1;
19918 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
19919 dsl_binding[2].pImmutableSamplers = NULL;
19920
19921 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
19922 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
19923 ds_layout_ci.pNext = NULL;
19924 ds_layout_ci.bindingCount = NUM_BINDINGS;
19925 ds_layout_ci.pBindings = dsl_binding;
19926 VkDescriptorSetLayout ds_layout;
19927 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02345);
19928 vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
19929 m_errorMonitor->VerifyFound();
19930}
19931
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060019932TEST_F(VkLayerTest, ViewportAndScissorBoundsChecking) {
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060019933 TEST_DESCRIPTION("Verify errors are detected on misuse of SetViewport and SetScissor.");
19934
Tony Barbour1fa09702017-03-16 12:09:08 -060019935 ASSERT_NO_FATAL_FAILURE(Init());
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060019936
Tony Barbour552f6c02016-12-21 14:34:07 -070019937 m_commandBuffer->BeginCommandBuffer();
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060019938
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060019939 const VkPhysicalDeviceLimits &limits = m_device->props.limits;
19940
19941 {
19942 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01448);
19943 VkViewport viewport = {0, 0, static_cast<float>(limits.maxViewportDimensions[0] + 1), 16, 0, 1};
19944 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
19945 m_errorMonitor->VerifyFound();
19946 }
19947
19948 {
19949 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01449);
19950 VkViewport viewport = {0, 0, 16, static_cast<float>(limits.maxViewportDimensions[1] + 1), 0, 1};
19951 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
19952 m_errorMonitor->VerifyFound();
19953 }
19954
19955 {
19956 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
19957 VkViewport viewport = {limits.viewportBoundsRange[0] - 1, 0, 16, 16, 0, 1};
19958 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
19959 m_errorMonitor->VerifyFound();
19960 }
19961
19962 {
19963 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
19964 VkViewport viewport = {0, limits.viewportBoundsRange[0] - 1, 16, 16, 0, 1};
19965 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
19966 m_errorMonitor->VerifyFound();
19967 }
19968
19969 {
19970 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01451);
19971 VkViewport viewport = {limits.viewportBoundsRange[1], 0, 16, 16, 0, 1};
19972 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
19973 m_errorMonitor->VerifyFound();
19974 }
19975
19976 {
19977 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01452);
19978 VkViewport viewport = {0, limits.viewportBoundsRange[1], 16, 16, 0, 1};
19979 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
19980 m_errorMonitor->VerifyFound();
19981 }
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060019982
19983 {
19984 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
19985 VkRect2D scissor = {{-1, 0}, {16, 16}};
19986 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
19987 m_errorMonitor->VerifyFound();
19988 }
19989
19990 {
19991 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
19992 VkRect2D scissor = {{0, -2}, {16, 16}};
19993 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
19994 m_errorMonitor->VerifyFound();
19995 }
19996
19997 {
19998 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01490);
19999 VkRect2D scissor = {{100, 100}, {INT_MAX, 16}};
20000 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
20001 m_errorMonitor->VerifyFound();
20002 }
20003
20004 {
20005 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01491);
20006 VkRect2D scissor = {{100, 100}, {16, INT_MAX}};
20007 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
20008 m_errorMonitor->VerifyFound();
20009 }
20010
Tony Barbour552f6c02016-12-21 14:34:07 -070020011 m_commandBuffer->EndCommandBuffer();
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060020012}
20013
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020014// This is a positive test. No failures are expected.
20015TEST_F(VkPositiveLayerTest, EmptyDescriptorUpdateTest) {
20016 TEST_DESCRIPTION("Update last descriptor in a set that includes an empty binding");
20017 VkResult err;
20018
Tony Barbour1fa09702017-03-16 12:09:08 -060020019 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020020 m_errorMonitor->ExpectSuccess();
20021 VkDescriptorPoolSize ds_type_count = {};
20022 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
20023 ds_type_count.descriptorCount = 2;
20024
20025 VkDescriptorPoolCreateInfo ds_pool_ci = {};
20026 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
20027 ds_pool_ci.pNext = NULL;
20028 ds_pool_ci.maxSets = 1;
20029 ds_pool_ci.poolSizeCount = 1;
20030 ds_pool_ci.pPoolSizes = &ds_type_count;
20031
20032 VkDescriptorPool ds_pool;
20033 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
20034 ASSERT_VK_SUCCESS(err);
20035
20036 // Create layout with two uniform buffer descriptors w/ empty binding between them
20037 static const uint32_t NUM_BINDINGS = 3;
20038 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
20039 dsl_binding[0].binding = 0;
20040 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
20041 dsl_binding[0].descriptorCount = 1;
20042 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
20043 dsl_binding[0].pImmutableSamplers = NULL;
20044 dsl_binding[1].binding = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020045 dsl_binding[1].descriptorCount = 0; // empty binding
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020046 dsl_binding[2].binding = 2;
20047 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
20048 dsl_binding[2].descriptorCount = 1;
20049 dsl_binding[2].stageFlags = VK_SHADER_STAGE_ALL;
20050 dsl_binding[2].pImmutableSamplers = NULL;
20051
20052 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
20053 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
20054 ds_layout_ci.pNext = NULL;
20055 ds_layout_ci.bindingCount = NUM_BINDINGS;
20056 ds_layout_ci.pBindings = dsl_binding;
20057 VkDescriptorSetLayout ds_layout;
20058 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
20059 ASSERT_VK_SUCCESS(err);
20060
20061 VkDescriptorSet descriptor_set = {};
20062 VkDescriptorSetAllocateInfo alloc_info = {};
20063 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
20064 alloc_info.descriptorSetCount = 1;
20065 alloc_info.descriptorPool = ds_pool;
20066 alloc_info.pSetLayouts = &ds_layout;
20067 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
20068 ASSERT_VK_SUCCESS(err);
20069
20070 // Create a buffer to be used for update
20071 VkBufferCreateInfo buff_ci = {};
20072 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
20073 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
20074 buff_ci.size = 256;
20075 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
20076 VkBuffer buffer;
20077 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
20078 ASSERT_VK_SUCCESS(err);
20079 // Have to bind memory to buffer before descriptor update
20080 VkMemoryAllocateInfo mem_alloc = {};
20081 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
20082 mem_alloc.pNext = NULL;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020083 mem_alloc.allocationSize = 512; // one allocation for both buffers
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020084 mem_alloc.memoryTypeIndex = 0;
20085
20086 VkMemoryRequirements mem_reqs;
20087 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
20088 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
20089 if (!pass) {
20090 vkDestroyBuffer(m_device->device(), buffer, NULL);
20091 return;
20092 }
20093
20094 VkDeviceMemory mem;
20095 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
20096 ASSERT_VK_SUCCESS(err);
20097 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
20098 ASSERT_VK_SUCCESS(err);
20099
20100 // Only update the descriptor at binding 2
20101 VkDescriptorBufferInfo buff_info = {};
20102 buff_info.buffer = buffer;
20103 buff_info.offset = 0;
20104 buff_info.range = VK_WHOLE_SIZE;
20105 VkWriteDescriptorSet descriptor_write = {};
20106 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
20107 descriptor_write.dstBinding = 2;
20108 descriptor_write.descriptorCount = 1;
20109 descriptor_write.pTexelBufferView = nullptr;
20110 descriptor_write.pBufferInfo = &buff_info;
20111 descriptor_write.pImageInfo = nullptr;
20112 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
20113 descriptor_write.dstSet = descriptor_set;
20114
20115 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
20116
20117 m_errorMonitor->VerifyNotFound();
20118 // Cleanup
20119 vkFreeMemory(m_device->device(), mem, NULL);
20120 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
20121 vkDestroyBuffer(m_device->device(), buffer, NULL);
20122 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
20123}
20124
20125// This is a positive test. No failures are expected.
20126TEST_F(VkPositiveLayerTest, TestAliasedMemoryTracking) {
20127 VkResult err;
20128 bool pass;
20129
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020130 TEST_DESCRIPTION(
20131 "Create a buffer, allocate memory, bind memory, destroy "
20132 "the buffer, create an image, and bind the same memory to "
20133 "it");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020134
20135 m_errorMonitor->ExpectSuccess();
20136
Tony Barbour1fa09702017-03-16 12:09:08 -060020137 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020138
20139 VkBuffer buffer;
20140 VkImage image;
20141 VkDeviceMemory mem;
20142 VkMemoryRequirements mem_reqs;
20143
20144 VkBufferCreateInfo buf_info = {};
20145 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
20146 buf_info.pNext = NULL;
20147 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
20148 buf_info.size = 256;
20149 buf_info.queueFamilyIndexCount = 0;
20150 buf_info.pQueueFamilyIndices = NULL;
20151 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
20152 buf_info.flags = 0;
20153 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
20154 ASSERT_VK_SUCCESS(err);
20155
20156 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
20157
20158 VkMemoryAllocateInfo alloc_info = {};
20159 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
20160 alloc_info.pNext = NULL;
20161 alloc_info.memoryTypeIndex = 0;
Dave Houlton9dae7ec2017-03-01 16:23:25 -070020162
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020163 // Ensure memory is big enough for both bindings
20164 alloc_info.allocationSize = 0x10000;
20165
20166 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
20167 if (!pass) {
20168 vkDestroyBuffer(m_device->device(), buffer, NULL);
20169 return;
20170 }
20171
20172 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
20173 ASSERT_VK_SUCCESS(err);
20174
20175 uint8_t *pData;
20176 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
20177 ASSERT_VK_SUCCESS(err);
20178
20179 memset(pData, 0xCADECADE, static_cast<size_t>(mem_reqs.size));
20180
20181 vkUnmapMemory(m_device->device(), mem);
20182
20183 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
20184 ASSERT_VK_SUCCESS(err);
20185
20186 // NOW, destroy the buffer. Obviously, the resource no longer occupies this
20187 // memory. In fact, it was never used by the GPU.
20188 // Just be be sure, wait for idle.
20189 vkDestroyBuffer(m_device->device(), buffer, NULL);
20190 vkDeviceWaitIdle(m_device->device());
20191
Tobin Ehlis6a005702016-12-28 15:25:56 -070020192 // Use optimal as some platforms report linear support but then fail image creation
20193 VkImageTiling image_tiling = VK_IMAGE_TILING_OPTIMAL;
20194 VkImageFormatProperties image_format_properties;
20195 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D, image_tiling,
20196 VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0, &image_format_properties);
20197 if (image_format_properties.maxExtent.width == 0) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070020198 printf(" Image format not supported; skipped.\n");
Tobin Ehlis6a005702016-12-28 15:25:56 -070020199 vkFreeMemory(m_device->device(), mem, NULL);
20200 return;
20201 }
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020202 VkImageCreateInfo image_create_info = {};
20203 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
20204 image_create_info.pNext = NULL;
20205 image_create_info.imageType = VK_IMAGE_TYPE_2D;
20206 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
20207 image_create_info.extent.width = 64;
20208 image_create_info.extent.height = 64;
20209 image_create_info.extent.depth = 1;
20210 image_create_info.mipLevels = 1;
20211 image_create_info.arrayLayers = 1;
20212 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis6a005702016-12-28 15:25:56 -070020213 image_create_info.tiling = image_tiling;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020214 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
20215 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
20216 image_create_info.queueFamilyIndexCount = 0;
20217 image_create_info.pQueueFamilyIndices = NULL;
20218 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
20219 image_create_info.flags = 0;
20220
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020221 /* Create a mappable image. It will be the texture if linear images are ok
Dave Houlton9dae7ec2017-03-01 16:23:25 -070020222 * to be textures or it will be the staging image if they are not.
20223 */
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020224 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
20225 ASSERT_VK_SUCCESS(err);
20226
20227 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
20228
Tobin Ehlis6a005702016-12-28 15:25:56 -070020229 VkMemoryAllocateInfo mem_alloc = {};
20230 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
20231 mem_alloc.pNext = NULL;
20232 mem_alloc.allocationSize = 0;
20233 mem_alloc.memoryTypeIndex = 0;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020234 mem_alloc.allocationSize = mem_reqs.size;
20235
20236 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
20237 if (!pass) {
Tobin Ehlis6a005702016-12-28 15:25:56 -070020238 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020239 vkDestroyImage(m_device->device(), image, NULL);
20240 return;
20241 }
20242
20243 // VALIDATION FAILURE:
20244 err = vkBindImageMemory(m_device->device(), image, mem, 0);
20245 ASSERT_VK_SUCCESS(err);
20246
20247 m_errorMonitor->VerifyNotFound();
20248
20249 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020250 vkDestroyImage(m_device->device(), image, NULL);
20251}
20252
Tony Barbourab713912017-02-02 14:17:35 -070020253// This is a positive test. No failures are expected.
20254TEST_F(VkPositiveLayerTest, TestDestroyFreeNullHandles) {
20255 VkResult err;
20256
20257 TEST_DESCRIPTION(
20258 "Call all applicable destroy and free routines with NULL"
20259 "handles, expecting no validation errors");
20260
20261 m_errorMonitor->ExpectSuccess();
20262
Tony Barbour1fa09702017-03-16 12:09:08 -060020263 ASSERT_NO_FATAL_FAILURE(Init());
Tony Barbourab713912017-02-02 14:17:35 -070020264 vkDestroyBuffer(m_device->device(), VK_NULL_HANDLE, NULL);
20265 vkDestroyBufferView(m_device->device(), VK_NULL_HANDLE, NULL);
20266 vkDestroyCommandPool(m_device->device(), VK_NULL_HANDLE, NULL);
20267 vkDestroyDescriptorPool(m_device->device(), VK_NULL_HANDLE, NULL);
20268 vkDestroyDescriptorSetLayout(m_device->device(), VK_NULL_HANDLE, NULL);
20269 vkDestroyDevice(VK_NULL_HANDLE, NULL);
20270 vkDestroyEvent(m_device->device(), VK_NULL_HANDLE, NULL);
20271 vkDestroyFence(m_device->device(), VK_NULL_HANDLE, NULL);
20272 vkDestroyFramebuffer(m_device->device(), VK_NULL_HANDLE, NULL);
20273 vkDestroyImage(m_device->device(), VK_NULL_HANDLE, NULL);
20274 vkDestroyImageView(m_device->device(), VK_NULL_HANDLE, NULL);
20275 vkDestroyInstance(VK_NULL_HANDLE, NULL);
20276 vkDestroyPipeline(m_device->device(), VK_NULL_HANDLE, NULL);
20277 vkDestroyPipelineCache(m_device->device(), VK_NULL_HANDLE, NULL);
20278 vkDestroyPipelineLayout(m_device->device(), VK_NULL_HANDLE, NULL);
20279 vkDestroyQueryPool(m_device->device(), VK_NULL_HANDLE, NULL);
20280 vkDestroyRenderPass(m_device->device(), VK_NULL_HANDLE, NULL);
20281 vkDestroySampler(m_device->device(), VK_NULL_HANDLE, NULL);
20282 vkDestroySemaphore(m_device->device(), VK_NULL_HANDLE, NULL);
20283 vkDestroyShaderModule(m_device->device(), VK_NULL_HANDLE, NULL);
20284
20285 VkCommandPool command_pool;
20286 VkCommandPoolCreateInfo pool_create_info{};
20287 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20288 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20289 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20290 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20291 VkCommandBuffer command_buffers[3] = {};
20292 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20293 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20294 command_buffer_allocate_info.commandPool = command_pool;
20295 command_buffer_allocate_info.commandBufferCount = 1;
20296 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20297 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffers[1]);
20298 vkFreeCommandBuffers(m_device->device(), command_pool, 3, command_buffers);
20299 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20300
20301 VkDescriptorPoolSize ds_type_count = {};
20302 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
20303 ds_type_count.descriptorCount = 1;
20304
20305 VkDescriptorPoolCreateInfo ds_pool_ci = {};
20306 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
20307 ds_pool_ci.pNext = NULL;
20308 ds_pool_ci.maxSets = 1;
20309 ds_pool_ci.poolSizeCount = 1;
20310 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
20311 ds_pool_ci.pPoolSizes = &ds_type_count;
20312
20313 VkDescriptorPool ds_pool;
20314 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
20315 ASSERT_VK_SUCCESS(err);
20316
20317 VkDescriptorSetLayoutBinding dsl_binding = {};
20318 dsl_binding.binding = 2;
20319 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
20320 dsl_binding.descriptorCount = 1;
20321 dsl_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
20322 dsl_binding.pImmutableSamplers = NULL;
20323 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
20324 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
20325 ds_layout_ci.pNext = NULL;
20326 ds_layout_ci.bindingCount = 1;
20327 ds_layout_ci.pBindings = &dsl_binding;
20328 VkDescriptorSetLayout ds_layout;
20329 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
20330 ASSERT_VK_SUCCESS(err);
20331
20332 VkDescriptorSet descriptor_sets[3] = {};
20333 VkDescriptorSetAllocateInfo alloc_info = {};
20334 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
20335 alloc_info.descriptorSetCount = 1;
20336 alloc_info.descriptorPool = ds_pool;
20337 alloc_info.pSetLayouts = &ds_layout;
20338 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_sets[1]);
20339 ASSERT_VK_SUCCESS(err);
20340 vkFreeDescriptorSets(m_device->device(), ds_pool, 3, descriptor_sets);
20341 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
20342 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
20343
20344 vkFreeMemory(m_device->device(), VK_NULL_HANDLE, NULL);
20345
20346 m_errorMonitor->VerifyNotFound();
20347}
20348
Tony Barbour626994c2017-02-08 15:29:37 -070020349TEST_F(VkPositiveLayerTest, QueueSubmitSemaphoresAndLayoutTracking) {
Tony Barboure0c5cc92017-02-08 13:53:39 -070020350 TEST_DESCRIPTION("Submit multiple command buffers with chained semaphore signals and layout transitions");
Tony Barbour626994c2017-02-08 15:29:37 -070020351
20352 m_errorMonitor->ExpectSuccess();
20353
Tony Barbour1fa09702017-03-16 12:09:08 -060020354 ASSERT_NO_FATAL_FAILURE(Init());
Tony Barbour626994c2017-02-08 15:29:37 -070020355 VkCommandBuffer cmd_bufs[4];
20356 VkCommandBufferAllocateInfo alloc_info;
20357 alloc_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20358 alloc_info.pNext = NULL;
20359 alloc_info.commandBufferCount = 4;
Mike Schuchardt06304c22017-03-01 17:09:09 -070020360 alloc_info.commandPool = m_commandPool->handle();
Tony Barbour626994c2017-02-08 15:29:37 -070020361 alloc_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20362 vkAllocateCommandBuffers(m_device->device(), &alloc_info, cmd_bufs);
20363 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060020364 image.Init(128, 128, 1, VK_FORMAT_B8G8R8A8_UNORM,
Mike Weiblen62d08a32017-03-07 22:18:27 -070020365 (VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT),
20366 VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbour626994c2017-02-08 15:29:37 -070020367 ASSERT_TRUE(image.initialized());
20368 VkCommandBufferBeginInfo cb_binfo;
20369 cb_binfo.pNext = NULL;
20370 cb_binfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20371 cb_binfo.pInheritanceInfo = VK_NULL_HANDLE;
20372 cb_binfo.flags = 0;
20373 // Use 4 command buffers, each with an image layout transition, ColorAO->General->ColorAO->TransferSrc->TransferDst
20374 vkBeginCommandBuffer(cmd_bufs[0], &cb_binfo);
20375 VkImageMemoryBarrier img_barrier = {};
20376 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
20377 img_barrier.pNext = NULL;
20378 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
20379 img_barrier.dstAccessMask = VK_ACCESS_HOST_WRITE_BIT;
20380 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
20381 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
20382 img_barrier.image = image.handle();
20383 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
20384 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
20385 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
20386 img_barrier.subresourceRange.baseArrayLayer = 0;
20387 img_barrier.subresourceRange.baseMipLevel = 0;
20388 img_barrier.subresourceRange.layerCount = 1;
20389 img_barrier.subresourceRange.levelCount = 1;
20390 vkCmdPipelineBarrier(cmd_bufs[0], VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 0, nullptr, 0, nullptr, 1,
20391 &img_barrier);
20392 vkEndCommandBuffer(cmd_bufs[0]);
20393 vkBeginCommandBuffer(cmd_bufs[1], &cb_binfo);
20394 img_barrier.oldLayout = VK_IMAGE_LAYOUT_GENERAL;
20395 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
20396 vkCmdPipelineBarrier(cmd_bufs[1], VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 0, nullptr, 0, nullptr, 1,
20397 &img_barrier);
20398 vkEndCommandBuffer(cmd_bufs[1]);
20399 vkBeginCommandBuffer(cmd_bufs[2], &cb_binfo);
20400 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
20401 img_barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
20402 vkCmdPipelineBarrier(cmd_bufs[2], VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 0, nullptr, 0, nullptr, 1,
20403 &img_barrier);
20404 vkEndCommandBuffer(cmd_bufs[2]);
20405 vkBeginCommandBuffer(cmd_bufs[3], &cb_binfo);
20406 img_barrier.oldLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
20407 img_barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
20408 vkCmdPipelineBarrier(cmd_bufs[3], VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 0, nullptr, 0, nullptr, 1,
20409 &img_barrier);
20410 vkEndCommandBuffer(cmd_bufs[3]);
20411
20412 // Submit 4 command buffers in 3 submits, with submits 2 and 3 waiting for semaphores from submits 1 and 2
20413 VkSemaphore semaphore1, semaphore2;
20414 VkSemaphoreCreateInfo semaphore_create_info{};
20415 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
20416 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore1);
20417 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore2);
20418 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
20419 VkSubmitInfo submit_info[3];
20420 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20421 submit_info[0].pNext = nullptr;
20422 submit_info[0].commandBufferCount = 1;
20423 submit_info[0].pCommandBuffers = &cmd_bufs[0];
20424 submit_info[0].signalSemaphoreCount = 1;
20425 submit_info[0].pSignalSemaphores = &semaphore1;
20426 submit_info[0].waitSemaphoreCount = 0;
20427 submit_info[0].pWaitDstStageMask = nullptr;
20428 submit_info[0].pWaitDstStageMask = flags;
20429 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20430 submit_info[1].pNext = nullptr;
20431 submit_info[1].commandBufferCount = 1;
20432 submit_info[1].pCommandBuffers = &cmd_bufs[1];
20433 submit_info[1].waitSemaphoreCount = 1;
20434 submit_info[1].pWaitSemaphores = &semaphore1;
20435 submit_info[1].signalSemaphoreCount = 1;
20436 submit_info[1].pSignalSemaphores = &semaphore2;
20437 submit_info[1].pWaitDstStageMask = flags;
20438 submit_info[2].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20439 submit_info[2].pNext = nullptr;
20440 submit_info[2].commandBufferCount = 2;
20441 submit_info[2].pCommandBuffers = &cmd_bufs[2];
20442 submit_info[2].waitSemaphoreCount = 1;
20443 submit_info[2].pWaitSemaphores = &semaphore2;
20444 submit_info[2].signalSemaphoreCount = 0;
20445 submit_info[2].pSignalSemaphores = nullptr;
20446 submit_info[2].pWaitDstStageMask = flags;
20447 vkQueueSubmit(m_device->m_queue, 3, submit_info, VK_NULL_HANDLE);
20448 vkQueueWaitIdle(m_device->m_queue);
20449
20450 vkDestroySemaphore(m_device->device(), semaphore1, NULL);
20451 vkDestroySemaphore(m_device->device(), semaphore2, NULL);
20452 m_errorMonitor->VerifyNotFound();
20453}
20454
Tobin Ehlis953e8392016-11-17 10:54:13 -070020455TEST_F(VkPositiveLayerTest, DynamicOffsetWithInactiveBinding) {
20456 // Create a descriptorSet w/ dynamic descriptors where 1 binding is inactive
20457 // We previously had a bug where dynamic offset of inactive bindings was still being used
20458 VkResult err;
20459 m_errorMonitor->ExpectSuccess();
20460
Tony Barbour1fa09702017-03-16 12:09:08 -060020461 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis953e8392016-11-17 10:54:13 -070020462 ASSERT_NO_FATAL_FAILURE(InitViewport());
20463 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20464
20465 VkDescriptorPoolSize ds_type_count = {};
20466 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
20467 ds_type_count.descriptorCount = 3;
20468
20469 VkDescriptorPoolCreateInfo ds_pool_ci = {};
20470 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
20471 ds_pool_ci.pNext = NULL;
20472 ds_pool_ci.maxSets = 1;
20473 ds_pool_ci.poolSizeCount = 1;
20474 ds_pool_ci.pPoolSizes = &ds_type_count;
20475
20476 VkDescriptorPool ds_pool;
20477 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
20478 ASSERT_VK_SUCCESS(err);
20479
20480 const uint32_t BINDING_COUNT = 3;
20481 VkDescriptorSetLayoutBinding dsl_binding[BINDING_COUNT] = {};
Tobin Ehlis0050fba2016-11-30 10:22:02 -070020482 dsl_binding[0].binding = 2;
Tobin Ehlis953e8392016-11-17 10:54:13 -070020483 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
20484 dsl_binding[0].descriptorCount = 1;
20485 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
20486 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis0050fba2016-11-30 10:22:02 -070020487 dsl_binding[1].binding = 0;
Tobin Ehlis953e8392016-11-17 10:54:13 -070020488 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
20489 dsl_binding[1].descriptorCount = 1;
20490 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
20491 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis0050fba2016-11-30 10:22:02 -070020492 dsl_binding[2].binding = 1;
Tobin Ehlis953e8392016-11-17 10:54:13 -070020493 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
20494 dsl_binding[2].descriptorCount = 1;
20495 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
20496 dsl_binding[2].pImmutableSamplers = NULL;
20497
20498 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
20499 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
20500 ds_layout_ci.pNext = NULL;
20501 ds_layout_ci.bindingCount = BINDING_COUNT;
20502 ds_layout_ci.pBindings = dsl_binding;
20503 VkDescriptorSetLayout ds_layout;
20504 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
20505 ASSERT_VK_SUCCESS(err);
20506
20507 VkDescriptorSet descriptor_set;
20508 VkDescriptorSetAllocateInfo alloc_info = {};
20509 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
20510 alloc_info.descriptorSetCount = 1;
20511 alloc_info.descriptorPool = ds_pool;
20512 alloc_info.pSetLayouts = &ds_layout;
20513 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
20514 ASSERT_VK_SUCCESS(err);
20515
20516 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
20517 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
20518 pipeline_layout_ci.pNext = NULL;
20519 pipeline_layout_ci.setLayoutCount = 1;
20520 pipeline_layout_ci.pSetLayouts = &ds_layout;
20521
20522 VkPipelineLayout pipeline_layout;
20523 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
20524 ASSERT_VK_SUCCESS(err);
20525
20526 // Create two buffers to update the descriptors with
20527 // The first will be 2k and used for bindings 0 & 1, the second is 1k for binding 2
20528 uint32_t qfi = 0;
20529 VkBufferCreateInfo buffCI = {};
20530 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
20531 buffCI.size = 2048;
20532 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
20533 buffCI.queueFamilyIndexCount = 1;
20534 buffCI.pQueueFamilyIndices = &qfi;
20535
20536 VkBuffer dyub1;
20537 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub1);
20538 ASSERT_VK_SUCCESS(err);
20539 // buffer2
20540 buffCI.size = 1024;
20541 VkBuffer dyub2;
20542 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub2);
20543 ASSERT_VK_SUCCESS(err);
20544 // Allocate memory and bind to buffers
20545 VkMemoryAllocateInfo mem_alloc[2] = {};
20546 mem_alloc[0].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
20547 mem_alloc[0].pNext = NULL;
20548 mem_alloc[0].memoryTypeIndex = 0;
20549 mem_alloc[1].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
20550 mem_alloc[1].pNext = NULL;
20551 mem_alloc[1].memoryTypeIndex = 0;
20552
20553 VkMemoryRequirements mem_reqs1;
20554 vkGetBufferMemoryRequirements(m_device->device(), dyub1, &mem_reqs1);
20555 VkMemoryRequirements mem_reqs2;
20556 vkGetBufferMemoryRequirements(m_device->device(), dyub2, &mem_reqs2);
20557 mem_alloc[0].allocationSize = mem_reqs1.size;
20558 bool pass = m_device->phy().set_memory_type(mem_reqs1.memoryTypeBits, &mem_alloc[0], 0);
20559 mem_alloc[1].allocationSize = mem_reqs2.size;
20560 pass &= m_device->phy().set_memory_type(mem_reqs2.memoryTypeBits, &mem_alloc[1], 0);
20561 if (!pass) {
20562 vkDestroyBuffer(m_device->device(), dyub1, NULL);
20563 vkDestroyBuffer(m_device->device(), dyub2, NULL);
20564 return;
20565 }
20566
20567 VkDeviceMemory mem1;
20568 err = vkAllocateMemory(m_device->device(), &mem_alloc[0], NULL, &mem1);
20569 ASSERT_VK_SUCCESS(err);
20570 err = vkBindBufferMemory(m_device->device(), dyub1, mem1, 0);
20571 ASSERT_VK_SUCCESS(err);
20572 VkDeviceMemory mem2;
20573 err = vkAllocateMemory(m_device->device(), &mem_alloc[1], NULL, &mem2);
20574 ASSERT_VK_SUCCESS(err);
20575 err = vkBindBufferMemory(m_device->device(), dyub2, mem2, 0);
20576 ASSERT_VK_SUCCESS(err);
20577 // Update descriptors
20578 VkDescriptorBufferInfo buff_info[BINDING_COUNT] = {};
20579 buff_info[0].buffer = dyub1;
20580 buff_info[0].offset = 0;
20581 buff_info[0].range = 256;
20582 buff_info[1].buffer = dyub1;
20583 buff_info[1].offset = 256;
20584 buff_info[1].range = 512;
20585 buff_info[2].buffer = dyub2;
20586 buff_info[2].offset = 0;
20587 buff_info[2].range = 512;
20588
20589 VkWriteDescriptorSet descriptor_write;
20590 memset(&descriptor_write, 0, sizeof(descriptor_write));
20591 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
20592 descriptor_write.dstSet = descriptor_set;
20593 descriptor_write.dstBinding = 0;
20594 descriptor_write.descriptorCount = BINDING_COUNT;
20595 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
20596 descriptor_write.pBufferInfo = buff_info;
20597
20598 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
20599
Tony Barbour552f6c02016-12-21 14:34:07 -070020600 m_commandBuffer->BeginCommandBuffer();
20601 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis953e8392016-11-17 10:54:13 -070020602
20603 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020604 char const *vsSource =
20605 "#version 450\n"
20606 "\n"
20607 "out gl_PerVertex { \n"
20608 " vec4 gl_Position;\n"
20609 "};\n"
20610 "void main(){\n"
20611 " gl_Position = vec4(1);\n"
20612 "}\n";
20613 char const *fsSource =
20614 "#version 450\n"
20615 "\n"
20616 "layout(location=0) out vec4 x;\n"
20617 "layout(set=0) layout(binding=0) uniform foo1 { int x; int y; } bar1;\n"
20618 "layout(set=0) layout(binding=2) uniform foo2 { int x; int y; } bar2;\n"
20619 "void main(){\n"
20620 " x = vec4(bar1.y) + vec4(bar2.y);\n"
20621 "}\n";
Tobin Ehlis953e8392016-11-17 10:54:13 -070020622 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
20623 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
20624 VkPipelineObj pipe(m_device);
20625 pipe.SetViewport(m_viewports);
20626 pipe.SetScissor(m_scissors);
20627 pipe.AddShader(&vs);
20628 pipe.AddShader(&fs);
20629 pipe.AddColorAttachment();
20630 pipe.CreateVKPipeline(pipeline_layout, renderPass());
20631
20632 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
20633 // This update should succeed, but offset of inactive binding 1 oversteps binding 2 buffer size
20634 // we used to have a bug in this case.
20635 uint32_t dyn_off[BINDING_COUNT] = {0, 1024, 256};
20636 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
20637 &descriptor_set, BINDING_COUNT, dyn_off);
20638 Draw(1, 0, 0, 0);
20639 m_errorMonitor->VerifyNotFound();
20640
20641 vkDestroyBuffer(m_device->device(), dyub1, NULL);
20642 vkDestroyBuffer(m_device->device(), dyub2, NULL);
20643 vkFreeMemory(m_device->device(), mem1, NULL);
20644 vkFreeMemory(m_device->device(), mem2, NULL);
20645
20646 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
20647 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
20648 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
20649}
20650
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020651TEST_F(VkPositiveLayerTest, NonCoherentMemoryMapping) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020652 TEST_DESCRIPTION(
20653 "Ensure that validations handling of non-coherent memory "
20654 "mapping while using VK_WHOLE_SIZE does not cause access "
20655 "violations");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020656 VkResult err;
20657 uint8_t *pData;
Tony Barbour1fa09702017-03-16 12:09:08 -060020658 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020659
20660 VkDeviceMemory mem;
20661 VkMemoryRequirements mem_reqs;
20662 mem_reqs.memoryTypeBits = 0xFFFFFFFF;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070020663 const VkDeviceSize atom_size = m_device->props.limits.nonCoherentAtomSize;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020664 VkMemoryAllocateInfo alloc_info = {};
20665 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
20666 alloc_info.pNext = NULL;
20667 alloc_info.memoryTypeIndex = 0;
20668
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070020669 static const VkDeviceSize allocation_size = 32 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020670 alloc_info.allocationSize = allocation_size;
20671
20672 // Find a memory configurations WITHOUT a COHERENT bit, otherwise exit
20673 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 -070020674 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020675 if (!pass) {
20676 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020677 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
20678 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020679 if (!pass) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020680 pass = m_device->phy().set_memory_type(
20681 mem_reqs.memoryTypeBits, &alloc_info,
20682 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT | VK_MEMORY_PROPERTY_HOST_CACHED_BIT,
20683 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020684 if (!pass) {
20685 return;
20686 }
20687 }
20688 }
20689
20690 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
20691 ASSERT_VK_SUCCESS(err);
20692
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070020693 // Map/Flush/Invalidate using WHOLE_SIZE and zero offsets and entire mapped range
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020694 m_errorMonitor->ExpectSuccess();
20695 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
20696 ASSERT_VK_SUCCESS(err);
20697 VkMappedMemoryRange mmr = {};
20698 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
20699 mmr.memory = mem;
20700 mmr.offset = 0;
20701 mmr.size = VK_WHOLE_SIZE;
20702 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
20703 ASSERT_VK_SUCCESS(err);
20704 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
20705 ASSERT_VK_SUCCESS(err);
20706 m_errorMonitor->VerifyNotFound();
20707 vkUnmapMemory(m_device->device(), mem);
20708
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070020709 // Map/Flush/Invalidate using WHOLE_SIZE and an offset and entire mapped range
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020710 m_errorMonitor->ExpectSuccess();
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070020711 err = vkMapMemory(m_device->device(), mem, 5 * atom_size, VK_WHOLE_SIZE, 0, (void **)&pData);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020712 ASSERT_VK_SUCCESS(err);
20713 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
20714 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070020715 mmr.offset = 6 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020716 mmr.size = VK_WHOLE_SIZE;
20717 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
20718 ASSERT_VK_SUCCESS(err);
20719 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
20720 ASSERT_VK_SUCCESS(err);
20721 m_errorMonitor->VerifyNotFound();
20722 vkUnmapMemory(m_device->device(), mem);
20723
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070020724 // Map with offset and size
20725 // Flush/Invalidate subrange of mapped area with offset and size
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020726 m_errorMonitor->ExpectSuccess();
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070020727 err = vkMapMemory(m_device->device(), mem, 3 * atom_size, 9 * atom_size, 0, (void **)&pData);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020728 ASSERT_VK_SUCCESS(err);
20729 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
20730 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070020731 mmr.offset = 4 * atom_size;
20732 mmr.size = 2 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020733 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
20734 ASSERT_VK_SUCCESS(err);
20735 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
20736 ASSERT_VK_SUCCESS(err);
20737 m_errorMonitor->VerifyNotFound();
20738 vkUnmapMemory(m_device->device(), mem);
20739
20740 // Map without offset and flush WHOLE_SIZE with two separate offsets
20741 m_errorMonitor->ExpectSuccess();
20742 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
20743 ASSERT_VK_SUCCESS(err);
20744 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
20745 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070020746 mmr.offset = allocation_size - (4 * atom_size);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020747 mmr.size = VK_WHOLE_SIZE;
20748 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
20749 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070020750 mmr.offset = allocation_size - (6 * atom_size);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020751 mmr.size = VK_WHOLE_SIZE;
20752 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
20753 ASSERT_VK_SUCCESS(err);
20754 m_errorMonitor->VerifyNotFound();
20755 vkUnmapMemory(m_device->device(), mem);
20756
20757 vkFreeMemory(m_device->device(), mem, NULL);
20758}
20759
20760// This is a positive test. We used to expect error in this case but spec now allows it
20761TEST_F(VkPositiveLayerTest, ResetUnsignaledFence) {
20762 m_errorMonitor->ExpectSuccess();
20763 vk_testing::Fence testFence;
20764 VkFenceCreateInfo fenceInfo = {};
20765 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
20766 fenceInfo.pNext = NULL;
20767
Tony Barbour1fa09702017-03-16 12:09:08 -060020768 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020769 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020770 VkFence fences[1] = {testFence.handle()};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020771 VkResult result = vkResetFences(m_device->device(), 1, fences);
20772 ASSERT_VK_SUCCESS(result);
20773
20774 m_errorMonitor->VerifyNotFound();
20775}
20776
20777TEST_F(VkPositiveLayerTest, CommandBufferSimultaneousUseSync) {
20778 m_errorMonitor->ExpectSuccess();
20779
Tony Barbour1fa09702017-03-16 12:09:08 -060020780 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020781 VkResult err;
20782
20783 // Record (empty!) command buffer that can be submitted multiple times
20784 // simultaneously.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020785 VkCommandBufferBeginInfo cbbi = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
20786 VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020787 m_commandBuffer->BeginCommandBuffer(&cbbi);
20788 m_commandBuffer->EndCommandBuffer();
20789
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020790 VkFenceCreateInfo fci = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020791 VkFence fence;
20792 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
20793 ASSERT_VK_SUCCESS(err);
20794
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020795 VkSemaphoreCreateInfo sci = {VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020796 VkSemaphore s1, s2;
20797 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s1);
20798 ASSERT_VK_SUCCESS(err);
20799 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s2);
20800 ASSERT_VK_SUCCESS(err);
20801
20802 // Submit CB once signaling s1, with fence so we can roll forward to its retirement.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020803 VkSubmitInfo si = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &m_commandBuffer->handle(), 1, &s1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020804 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
20805 ASSERT_VK_SUCCESS(err);
20806
20807 // Submit CB again, signaling s2.
20808 si.pSignalSemaphores = &s2;
20809 err = vkQueueSubmit(m_device->m_queue, 1, &si, VK_NULL_HANDLE);
20810 ASSERT_VK_SUCCESS(err);
20811
20812 // Wait for fence.
20813 err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
20814 ASSERT_VK_SUCCESS(err);
20815
20816 // CB is still in flight from second submission, but semaphore s1 is no
20817 // longer in flight. delete it.
20818 vkDestroySemaphore(m_device->device(), s1, nullptr);
20819
20820 m_errorMonitor->VerifyNotFound();
20821
20822 // Force device idle and clean up remaining objects
20823 vkDeviceWaitIdle(m_device->device());
20824 vkDestroySemaphore(m_device->device(), s2, nullptr);
20825 vkDestroyFence(m_device->device(), fence, nullptr);
20826}
20827
20828TEST_F(VkPositiveLayerTest, FenceCreateSignaledWaitHandling) {
20829 m_errorMonitor->ExpectSuccess();
20830
Tony Barbour1fa09702017-03-16 12:09:08 -060020831 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020832 VkResult err;
20833
20834 // A fence created signaled
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020835 VkFenceCreateInfo fci1 = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, VK_FENCE_CREATE_SIGNALED_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020836 VkFence f1;
20837 err = vkCreateFence(m_device->device(), &fci1, nullptr, &f1);
20838 ASSERT_VK_SUCCESS(err);
20839
20840 // A fence created not
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020841 VkFenceCreateInfo fci2 = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020842 VkFence f2;
20843 err = vkCreateFence(m_device->device(), &fci2, nullptr, &f2);
20844 ASSERT_VK_SUCCESS(err);
20845
20846 // Submit the unsignaled fence
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020847 VkSubmitInfo si = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 0, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020848 err = vkQueueSubmit(m_device->m_queue, 1, &si, f2);
20849
20850 // Wait on both fences, with signaled first.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020851 VkFence fences[] = {f1, f2};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020852 vkWaitForFences(m_device->device(), 2, fences, VK_TRUE, UINT64_MAX);
20853
20854 // Should have both retired!
20855 vkDestroyFence(m_device->device(), f1, nullptr);
20856 vkDestroyFence(m_device->device(), f2, nullptr);
20857
20858 m_errorMonitor->VerifyNotFound();
20859}
20860
20861TEST_F(VkPositiveLayerTest, ValidUsage) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020862 TEST_DESCRIPTION(
20863 "Verify that creating an image view from an image with valid usage "
20864 "doesn't generate validation errors");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020865
Tony Barbour1fa09702017-03-16 12:09:08 -060020866 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020867
20868 m_errorMonitor->ExpectSuccess();
20869 // Verify that we can create a view with usage INPUT_ATTACHMENT
20870 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060020871 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 -060020872 ASSERT_TRUE(image.initialized());
20873 VkImageView imageView;
20874 VkImageViewCreateInfo ivci = {};
20875 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
20876 ivci.image = image.handle();
20877 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
20878 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
20879 ivci.subresourceRange.layerCount = 1;
20880 ivci.subresourceRange.baseMipLevel = 0;
20881 ivci.subresourceRange.levelCount = 1;
20882 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
20883
20884 vkCreateImageView(m_device->device(), &ivci, NULL, &imageView);
20885 m_errorMonitor->VerifyNotFound();
20886 vkDestroyImageView(m_device->device(), imageView, NULL);
20887}
20888
20889// This is a positive test. No failures are expected.
20890TEST_F(VkPositiveLayerTest, BindSparse) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020891 TEST_DESCRIPTION(
20892 "Bind 2 memory ranges to one image using vkQueueBindSparse, destroy the image"
20893 "and then free the memory");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020894
Tony Barbour1fa09702017-03-16 12:09:08 -060020895 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020896
20897 auto index = m_device->graphics_queue_node_index_;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020898 if (!(m_device->queue_props[index].queueFlags & VK_QUEUE_SPARSE_BINDING_BIT)) return;
Tony Barbour623721f2017-03-24 15:00:21 -060020899 if (!m_device->phy().features().sparseBinding) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020900
20901 m_errorMonitor->ExpectSuccess();
20902
20903 VkImage image;
20904 VkImageCreateInfo image_create_info = {};
20905 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
20906 image_create_info.pNext = NULL;
20907 image_create_info.imageType = VK_IMAGE_TYPE_2D;
20908 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
20909 image_create_info.extent.width = 64;
20910 image_create_info.extent.height = 64;
20911 image_create_info.extent.depth = 1;
20912 image_create_info.mipLevels = 1;
20913 image_create_info.arrayLayers = 1;
20914 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
20915 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
20916 image_create_info.usage = VK_IMAGE_USAGE_STORAGE_BIT;
20917 image_create_info.flags = VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
20918 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
20919 ASSERT_VK_SUCCESS(err);
20920
20921 VkMemoryRequirements memory_reqs;
20922 VkDeviceMemory memory_one, memory_two;
20923 bool pass;
20924 VkMemoryAllocateInfo memory_info = {};
20925 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
20926 memory_info.pNext = NULL;
20927 memory_info.allocationSize = 0;
20928 memory_info.memoryTypeIndex = 0;
20929 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
20930 // Find an image big enough to allow sparse mapping of 2 memory regions
20931 // Increase the image size until it is at least twice the
20932 // size of the required alignment, to ensure we can bind both
20933 // allocated memory blocks to the image on aligned offsets.
20934 while (memory_reqs.size < (memory_reqs.alignment * 2)) {
20935 vkDestroyImage(m_device->device(), image, nullptr);
20936 image_create_info.extent.width *= 2;
20937 image_create_info.extent.height *= 2;
20938 err = vkCreateImage(m_device->device(), &image_create_info, nullptr, &image);
20939 ASSERT_VK_SUCCESS(err);
20940 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
20941 }
20942 // Allocate 2 memory regions of minimum alignment size, bind one at 0, the other
20943 // at the end of the first
20944 memory_info.allocationSize = memory_reqs.alignment;
20945 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
20946 ASSERT_TRUE(pass);
20947 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_one);
20948 ASSERT_VK_SUCCESS(err);
20949 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_two);
20950 ASSERT_VK_SUCCESS(err);
20951 VkSparseMemoryBind binds[2];
20952 binds[0].flags = 0;
20953 binds[0].memory = memory_one;
20954 binds[0].memoryOffset = 0;
20955 binds[0].resourceOffset = 0;
20956 binds[0].size = memory_info.allocationSize;
20957 binds[1].flags = 0;
20958 binds[1].memory = memory_two;
20959 binds[1].memoryOffset = 0;
20960 binds[1].resourceOffset = memory_info.allocationSize;
20961 binds[1].size = memory_info.allocationSize;
20962
20963 VkSparseImageOpaqueMemoryBindInfo opaqueBindInfo;
20964 opaqueBindInfo.image = image;
20965 opaqueBindInfo.bindCount = 2;
20966 opaqueBindInfo.pBinds = binds;
20967
20968 VkFence fence = VK_NULL_HANDLE;
20969 VkBindSparseInfo bindSparseInfo = {};
20970 bindSparseInfo.sType = VK_STRUCTURE_TYPE_BIND_SPARSE_INFO;
20971 bindSparseInfo.imageOpaqueBindCount = 1;
20972 bindSparseInfo.pImageOpaqueBinds = &opaqueBindInfo;
20973
20974 vkQueueBindSparse(m_device->m_queue, 1, &bindSparseInfo, fence);
20975 vkQueueWaitIdle(m_device->m_queue);
20976 vkDestroyImage(m_device->device(), image, NULL);
20977 vkFreeMemory(m_device->device(), memory_one, NULL);
20978 vkFreeMemory(m_device->device(), memory_two, NULL);
20979 m_errorMonitor->VerifyNotFound();
20980}
20981
20982TEST_F(VkPositiveLayerTest, RenderPassInitialLayoutUndefined) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020983 TEST_DESCRIPTION(
20984 "Ensure that CmdBeginRenderPass with an attachment's "
20985 "initialLayout of VK_IMAGE_LAYOUT_UNDEFINED works when "
20986 "the command buffer has prior knowledge of that "
20987 "attachment's layout.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020988
20989 m_errorMonitor->ExpectSuccess();
20990
Tony Barbour1fa09702017-03-16 12:09:08 -060020991 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020992
20993 // A renderpass with one color attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020994 VkAttachmentDescription attachment = {0,
20995 VK_FORMAT_R8G8B8A8_UNORM,
20996 VK_SAMPLE_COUNT_1_BIT,
20997 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
20998 VK_ATTACHMENT_STORE_OP_STORE,
20999 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
21000 VK_ATTACHMENT_STORE_OP_DONT_CARE,
21001 VK_IMAGE_LAYOUT_UNDEFINED,
21002 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021003
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021004 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021005
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021006 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021007
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021008 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021009
21010 VkRenderPass rp;
21011 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
21012 ASSERT_VK_SUCCESS(err);
21013
21014 // A compatible framebuffer.
21015 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060021016 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 -060021017 ASSERT_TRUE(image.initialized());
21018
21019 VkImageViewCreateInfo ivci = {
21020 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
21021 nullptr,
21022 0,
21023 image.handle(),
21024 VK_IMAGE_VIEW_TYPE_2D,
21025 VK_FORMAT_R8G8B8A8_UNORM,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021026 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
21027 VK_COMPONENT_SWIZZLE_IDENTITY},
21028 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021029 };
21030 VkImageView view;
21031 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
21032 ASSERT_VK_SUCCESS(err);
21033
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021034 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021035 VkFramebuffer fb;
21036 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
21037 ASSERT_VK_SUCCESS(err);
21038
21039 // Record a single command buffer which uses this renderpass twice. The
21040 // bug is triggered at the beginning of the second renderpass, when the
21041 // command buffer already has a layout recorded for the attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021042 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 -070021043 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021044 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
21045 vkCmdEndRenderPass(m_commandBuffer->handle());
21046 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
21047
21048 m_errorMonitor->VerifyNotFound();
21049
21050 vkCmdEndRenderPass(m_commandBuffer->handle());
Tony Barbour552f6c02016-12-21 14:34:07 -070021051 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021052
21053 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
21054 vkDestroyRenderPass(m_device->device(), rp, nullptr);
21055 vkDestroyImageView(m_device->device(), view, nullptr);
21056}
21057
21058TEST_F(VkPositiveLayerTest, FramebufferBindingDestroyCommandPool) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021059 TEST_DESCRIPTION(
21060 "This test should pass. Create a Framebuffer and "
21061 "command buffer, bind them together, then destroy "
21062 "command pool and framebuffer and verify there are no "
21063 "errors.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021064
21065 m_errorMonitor->ExpectSuccess();
21066
Tony Barbour1fa09702017-03-16 12:09:08 -060021067 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021068
21069 // A renderpass with one color attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021070 VkAttachmentDescription attachment = {0,
21071 VK_FORMAT_R8G8B8A8_UNORM,
21072 VK_SAMPLE_COUNT_1_BIT,
21073 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
21074 VK_ATTACHMENT_STORE_OP_STORE,
21075 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
21076 VK_ATTACHMENT_STORE_OP_DONT_CARE,
21077 VK_IMAGE_LAYOUT_UNDEFINED,
21078 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021079
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021080 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021081
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021082 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021083
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021084 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021085
21086 VkRenderPass rp;
21087 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
21088 ASSERT_VK_SUCCESS(err);
21089
21090 // A compatible framebuffer.
21091 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060021092 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 -060021093 ASSERT_TRUE(image.initialized());
21094
21095 VkImageViewCreateInfo ivci = {
21096 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
21097 nullptr,
21098 0,
21099 image.handle(),
21100 VK_IMAGE_VIEW_TYPE_2D,
21101 VK_FORMAT_R8G8B8A8_UNORM,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021102 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
21103 VK_COMPONENT_SWIZZLE_IDENTITY},
21104 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021105 };
21106 VkImageView view;
21107 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
21108 ASSERT_VK_SUCCESS(err);
21109
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021110 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021111 VkFramebuffer fb;
21112 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
21113 ASSERT_VK_SUCCESS(err);
21114
21115 // Explicitly create a command buffer to bind the FB to so that we can then
21116 // destroy the command pool in order to implicitly free command buffer
21117 VkCommandPool command_pool;
21118 VkCommandPoolCreateInfo pool_create_info{};
21119 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
21120 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
21121 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
21122 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
21123
21124 VkCommandBuffer command_buffer;
21125 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
21126 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
21127 command_buffer_allocate_info.commandPool = command_pool;
21128 command_buffer_allocate_info.commandBufferCount = 1;
21129 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
21130 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
21131
21132 // Begin our cmd buffer with renderpass using our framebuffer
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021133 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 -060021134 VkCommandBufferBeginInfo begin_info{};
21135 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21136 vkBeginCommandBuffer(command_buffer, &begin_info);
21137
21138 vkCmdBeginRenderPass(command_buffer, &rpbi, VK_SUBPASS_CONTENTS_INLINE);
21139 vkCmdEndRenderPass(command_buffer);
21140 vkEndCommandBuffer(command_buffer);
21141 vkDestroyImageView(m_device->device(), view, nullptr);
21142 // Destroy command pool to implicitly free command buffer
21143 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
21144 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
21145 vkDestroyRenderPass(m_device->device(), rp, nullptr);
21146 m_errorMonitor->VerifyNotFound();
21147}
21148
21149TEST_F(VkPositiveLayerTest, RenderPassSubpassZeroTransitionsApplied) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021150 TEST_DESCRIPTION(
21151 "Ensure that CmdBeginRenderPass applies the layout "
21152 "transitions for the first subpass");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021153
21154 m_errorMonitor->ExpectSuccess();
21155
Tony Barbour1fa09702017-03-16 12:09:08 -060021156 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021157
21158 // A renderpass with one color attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021159 VkAttachmentDescription attachment = {0,
21160 VK_FORMAT_R8G8B8A8_UNORM,
21161 VK_SAMPLE_COUNT_1_BIT,
21162 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
21163 VK_ATTACHMENT_STORE_OP_STORE,
21164 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
21165 VK_ATTACHMENT_STORE_OP_DONT_CARE,
21166 VK_IMAGE_LAYOUT_UNDEFINED,
21167 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021168
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021169 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021170
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021171 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021172
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021173 VkSubpassDependency dep = {0,
21174 0,
21175 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
21176 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
21177 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
21178 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
21179 VK_DEPENDENCY_BY_REGION_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021180
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021181 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021182
21183 VkResult err;
21184 VkRenderPass rp;
21185 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
21186 ASSERT_VK_SUCCESS(err);
21187
21188 // A compatible framebuffer.
21189 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060021190 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 -060021191 ASSERT_TRUE(image.initialized());
21192
21193 VkImageViewCreateInfo ivci = {
21194 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
21195 nullptr,
21196 0,
21197 image.handle(),
21198 VK_IMAGE_VIEW_TYPE_2D,
21199 VK_FORMAT_R8G8B8A8_UNORM,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021200 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
21201 VK_COMPONENT_SWIZZLE_IDENTITY},
21202 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021203 };
21204 VkImageView view;
21205 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
21206 ASSERT_VK_SUCCESS(err);
21207
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021208 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021209 VkFramebuffer fb;
21210 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
21211 ASSERT_VK_SUCCESS(err);
21212
21213 // Record a single command buffer which issues a pipeline barrier w/
21214 // image memory barrier for the attachment. This detects the previously
21215 // missing tracking of the subpass layout by throwing a validation error
21216 // if it doesn't occur.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021217 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 -070021218 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021219 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
21220
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021221 VkImageMemoryBarrier imb = {VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
21222 nullptr,
21223 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
21224 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
21225 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
21226 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
21227 VK_QUEUE_FAMILY_IGNORED,
21228 VK_QUEUE_FAMILY_IGNORED,
21229 image.handle(),
21230 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1}};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021231 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021232 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
21233 &imb);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021234
21235 vkCmdEndRenderPass(m_commandBuffer->handle());
21236 m_errorMonitor->VerifyNotFound();
Tony Barbour552f6c02016-12-21 14:34:07 -070021237 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021238
21239 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
21240 vkDestroyRenderPass(m_device->device(), rp, nullptr);
21241 vkDestroyImageView(m_device->device(), view, nullptr);
21242}
21243
21244TEST_F(VkPositiveLayerTest, DepthStencilLayoutTransitionForDepthOnlyImageview) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021245 TEST_DESCRIPTION(
21246 "Validate that when an imageView of a depth/stencil image "
21247 "is used as a depth/stencil framebuffer attachment, the "
21248 "aspectMask is ignored and both depth and stencil image "
21249 "subresources are used.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021250
Tony Barbour1fa09702017-03-16 12:09:08 -060021251 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021252 VkFormatProperties format_properties;
21253 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_D32_SFLOAT_S8_UINT, &format_properties);
21254 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
21255 return;
21256 }
21257
21258 m_errorMonitor->ExpectSuccess();
21259
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021260 VkAttachmentDescription attachment = {0,
21261 VK_FORMAT_D32_SFLOAT_S8_UINT,
21262 VK_SAMPLE_COUNT_1_BIT,
21263 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
21264 VK_ATTACHMENT_STORE_OP_STORE,
21265 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
21266 VK_ATTACHMENT_STORE_OP_DONT_CARE,
21267 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
21268 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021269
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021270 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021271
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021272 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, &att_ref, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021273
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021274 VkSubpassDependency dep = {0,
21275 0,
21276 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
21277 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
21278 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
21279 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
21280 VK_DEPENDENCY_BY_REGION_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021281
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021282 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021283
21284 VkResult err;
21285 VkRenderPass rp;
21286 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
21287 ASSERT_VK_SUCCESS(err);
21288
21289 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060021290 image.InitNoLayout(32, 32, 1, VK_FORMAT_D32_SFLOAT_S8_UINT,
21291 0x26, // usage
21292 VK_IMAGE_TILING_OPTIMAL, 0);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021293 ASSERT_TRUE(image.initialized());
21294 image.SetLayout(0x6, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
21295
21296 VkImageViewCreateInfo ivci = {
21297 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
21298 nullptr,
21299 0,
21300 image.handle(),
21301 VK_IMAGE_VIEW_TYPE_2D,
21302 VK_FORMAT_D32_SFLOAT_S8_UINT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021303 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
21304 {0x2, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021305 };
21306 VkImageView view;
21307 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
21308 ASSERT_VK_SUCCESS(err);
21309
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021310 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021311 VkFramebuffer fb;
21312 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
21313 ASSERT_VK_SUCCESS(err);
21314
Tony Barbour552f6c02016-12-21 14:34:07 -070021315 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021316
21317 VkImageMemoryBarrier imb = {};
21318 imb.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
21319 imb.pNext = nullptr;
21320 imb.srcAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
21321 imb.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
21322 imb.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
21323 imb.newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
21324 imb.srcQueueFamilyIndex = 0;
21325 imb.dstQueueFamilyIndex = 0;
21326 imb.image = image.handle();
21327 imb.subresourceRange.aspectMask = 0x6;
21328 imb.subresourceRange.baseMipLevel = 0;
21329 imb.subresourceRange.levelCount = 0x1;
21330 imb.subresourceRange.baseArrayLayer = 0;
21331 imb.subresourceRange.layerCount = 0x1;
21332
21333 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021334 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
21335 &imb);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021336
Tony Barbour552f6c02016-12-21 14:34:07 -070021337 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021338 QueueCommandBuffer(false);
21339 m_errorMonitor->VerifyNotFound();
21340
21341 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
21342 vkDestroyRenderPass(m_device->device(), rp, nullptr);
21343 vkDestroyImageView(m_device->device(), view, nullptr);
21344}
21345
21346TEST_F(VkPositiveLayerTest, RenderPassTransitionsAttachmentUnused) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021347 TEST_DESCRIPTION(
21348 "Ensure that layout transitions work correctly without "
21349 "errors, when an attachment reference is "
21350 "VK_ATTACHMENT_UNUSED");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021351
21352 m_errorMonitor->ExpectSuccess();
21353
Tony Barbour1fa09702017-03-16 12:09:08 -060021354 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021355
21356 // A renderpass with no attachments
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021357 VkAttachmentReference att_ref = {VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021358
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021359 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021360
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021361 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 1, &subpass, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021362
21363 VkRenderPass rp;
21364 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
21365 ASSERT_VK_SUCCESS(err);
21366
21367 // A compatible framebuffer.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021368 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021369 VkFramebuffer fb;
21370 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
21371 ASSERT_VK_SUCCESS(err);
21372
21373 // Record a command buffer which just begins and ends the renderpass. The
21374 // bug manifests in BeginRenderPass.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021375 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 -070021376 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021377 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
21378 vkCmdEndRenderPass(m_commandBuffer->handle());
21379 m_errorMonitor->VerifyNotFound();
Tony Barbour552f6c02016-12-21 14:34:07 -070021380 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021381
21382 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
21383 vkDestroyRenderPass(m_device->device(), rp, nullptr);
21384}
21385
21386// This is a positive test. No errors are expected.
21387TEST_F(VkPositiveLayerTest, StencilLoadOp) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021388 TEST_DESCRIPTION(
21389 "Create a stencil-only attachment with a LOAD_OP set to "
21390 "CLEAR. stencil[Load|Store]Op used to be ignored.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021391 VkResult result = VK_SUCCESS;
Tony Barbour1fa09702017-03-16 12:09:08 -060021392 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -060021393 auto depth_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbourf887b162017-03-09 10:06:46 -070021394 if (!depth_format) {
21395 printf(" No Depth + Stencil format found. Skipped.\n");
21396 return;
21397 }
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021398 VkImageFormatProperties formatProps;
Tony Barbourf887b162017-03-09 10:06:46 -070021399 vkGetPhysicalDeviceImageFormatProperties(gpu(), depth_format, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021400 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0,
21401 &formatProps);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021402 if (formatProps.maxExtent.width < 100 || formatProps.maxExtent.height < 100) {
21403 return;
21404 }
21405
Tony Barbourf887b162017-03-09 10:06:46 -070021406 VkFormat depth_stencil_fmt = depth_format;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021407 m_depthStencil->Init(m_device, 100, 100, depth_stencil_fmt,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021408 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021409 VkAttachmentDescription att = {};
21410 VkAttachmentReference ref = {};
21411 att.format = depth_stencil_fmt;
21412 att.samples = VK_SAMPLE_COUNT_1_BIT;
21413 att.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
21414 att.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
21415 att.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
21416 att.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE;
21417 att.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
21418 att.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
21419
21420 VkClearValue clear;
21421 clear.depthStencil.depth = 1.0;
21422 clear.depthStencil.stencil = 0;
21423 ref.attachment = 0;
21424 ref.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
21425
21426 VkSubpassDescription subpass = {};
21427 subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
21428 subpass.flags = 0;
21429 subpass.inputAttachmentCount = 0;
21430 subpass.pInputAttachments = NULL;
21431 subpass.colorAttachmentCount = 0;
21432 subpass.pColorAttachments = NULL;
21433 subpass.pResolveAttachments = NULL;
21434 subpass.pDepthStencilAttachment = &ref;
21435 subpass.preserveAttachmentCount = 0;
21436 subpass.pPreserveAttachments = NULL;
21437
21438 VkRenderPass rp;
21439 VkRenderPassCreateInfo rp_info = {};
21440 rp_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
21441 rp_info.attachmentCount = 1;
21442 rp_info.pAttachments = &att;
21443 rp_info.subpassCount = 1;
21444 rp_info.pSubpasses = &subpass;
21445 result = vkCreateRenderPass(device(), &rp_info, NULL, &rp);
21446 ASSERT_VK_SUCCESS(result);
21447
21448 VkImageView *depthView = m_depthStencil->BindInfo();
21449 VkFramebufferCreateInfo fb_info = {};
21450 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
21451 fb_info.pNext = NULL;
21452 fb_info.renderPass = rp;
21453 fb_info.attachmentCount = 1;
21454 fb_info.pAttachments = depthView;
21455 fb_info.width = 100;
21456 fb_info.height = 100;
21457 fb_info.layers = 1;
21458 VkFramebuffer fb;
21459 result = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
21460 ASSERT_VK_SUCCESS(result);
21461
21462 VkRenderPassBeginInfo rpbinfo = {};
21463 rpbinfo.clearValueCount = 1;
21464 rpbinfo.pClearValues = &clear;
21465 rpbinfo.pNext = NULL;
21466 rpbinfo.renderPass = rp;
21467 rpbinfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
21468 rpbinfo.renderArea.extent.width = 100;
21469 rpbinfo.renderArea.extent.height = 100;
21470 rpbinfo.renderArea.offset.x = 0;
21471 rpbinfo.renderArea.offset.y = 0;
21472 rpbinfo.framebuffer = fb;
21473
21474 VkFence fence = {};
21475 VkFenceCreateInfo fence_ci = {};
21476 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
21477 fence_ci.pNext = nullptr;
21478 fence_ci.flags = 0;
21479 result = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fence);
21480 ASSERT_VK_SUCCESS(result);
21481
21482 m_commandBuffer->BeginCommandBuffer();
21483 m_commandBuffer->BeginRenderPass(rpbinfo);
21484 m_commandBuffer->EndRenderPass();
21485 m_commandBuffer->EndCommandBuffer();
21486 m_commandBuffer->QueueCommandBuffer(fence);
21487
21488 VkImageObj destImage(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060021489 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 -070021490 VK_IMAGE_TILING_OPTIMAL, 0);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021491 VkImageMemoryBarrier barrier = {};
21492 VkImageSubresourceRange range;
21493 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
21494 barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
21495 barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT;
21496 barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
21497 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
21498 barrier.image = m_depthStencil->handle();
21499 range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
21500 range.baseMipLevel = 0;
21501 range.levelCount = 1;
21502 range.baseArrayLayer = 0;
21503 range.layerCount = 1;
21504 barrier.subresourceRange = range;
21505 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
21506 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
21507 cmdbuf.BeginCommandBuffer();
21508 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 -070021509 &barrier);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021510 barrier.srcAccessMask = 0;
21511 barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
21512 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
21513 barrier.image = destImage.handle();
21514 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
21515 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 -070021516 &barrier);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021517 VkImageCopy cregion;
21518 cregion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
21519 cregion.srcSubresource.mipLevel = 0;
21520 cregion.srcSubresource.baseArrayLayer = 0;
21521 cregion.srcSubresource.layerCount = 1;
21522 cregion.srcOffset.x = 0;
21523 cregion.srcOffset.y = 0;
21524 cregion.srcOffset.z = 0;
21525 cregion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
21526 cregion.dstSubresource.mipLevel = 0;
21527 cregion.dstSubresource.baseArrayLayer = 0;
21528 cregion.dstSubresource.layerCount = 1;
21529 cregion.dstOffset.x = 0;
21530 cregion.dstOffset.y = 0;
21531 cregion.dstOffset.z = 0;
21532 cregion.extent.width = 100;
21533 cregion.extent.height = 100;
21534 cregion.extent.depth = 1;
21535 cmdbuf.CopyImage(m_depthStencil->handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, destImage.handle(),
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021536 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &cregion);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021537 cmdbuf.EndCommandBuffer();
21538
21539 VkSubmitInfo submit_info;
21540 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21541 submit_info.pNext = NULL;
21542 submit_info.waitSemaphoreCount = 0;
21543 submit_info.pWaitSemaphores = NULL;
21544 submit_info.pWaitDstStageMask = NULL;
21545 submit_info.commandBufferCount = 1;
21546 submit_info.pCommandBuffers = &cmdbuf.handle();
21547 submit_info.signalSemaphoreCount = 0;
21548 submit_info.pSignalSemaphores = NULL;
21549
21550 m_errorMonitor->ExpectSuccess();
21551 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
21552 m_errorMonitor->VerifyNotFound();
21553
21554 vkQueueWaitIdle(m_device->m_queue);
21555 vkDestroyFence(m_device->device(), fence, nullptr);
21556 vkDestroyRenderPass(m_device->device(), rp, nullptr);
21557 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
21558}
21559
21560// This is a positive test. No errors should be generated.
Mike Weiblene4e225d2017-03-07 23:15:43 -070021561TEST_F(VkPositiveLayerTest, BarrierLayoutToImageUsage) {
21562 TEST_DESCRIPTION("Ensure barriers' new and old VkImageLayout are compatible with their images' VkImageUsageFlags");
21563
21564 m_errorMonitor->ExpectSuccess();
21565
Tony Barbour1fa09702017-03-16 12:09:08 -060021566 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -060021567 auto depth_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbour9357d542017-03-24 15:42:21 -060021568 if (!depth_format) {
21569 printf(" No Depth + Stencil format found. Skipped.\n");
21570 return;
21571 }
Mike Weiblene4e225d2017-03-07 23:15:43 -070021572 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21573
21574 VkImageMemoryBarrier img_barrier = {};
21575 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
21576 img_barrier.pNext = NULL;
21577 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
21578 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
21579 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
21580 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
21581 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
21582 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
21583 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
21584 img_barrier.subresourceRange.baseArrayLayer = 0;
21585 img_barrier.subresourceRange.baseMipLevel = 0;
21586 img_barrier.subresourceRange.layerCount = 1;
21587 img_barrier.subresourceRange.levelCount = 1;
21588
21589 {
21590 VkImageObj img_color(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060021591 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 -070021592 ASSERT_TRUE(img_color.initialized());
21593
21594 VkImageObj img_ds1(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060021595 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 -070021596 ASSERT_TRUE(img_ds1.initialized());
21597
21598 VkImageObj img_ds2(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060021599 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 -070021600 ASSERT_TRUE(img_ds2.initialized());
21601
21602 VkImageObj img_xfer_src(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060021603 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 -070021604 ASSERT_TRUE(img_xfer_src.initialized());
21605
21606 VkImageObj img_xfer_dst(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060021607 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 -070021608 ASSERT_TRUE(img_xfer_dst.initialized());
21609
21610 VkImageObj img_sampled(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060021611 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 -070021612 ASSERT_TRUE(img_sampled.initialized());
21613
21614 VkImageObj img_input(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060021615 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 -070021616 ASSERT_TRUE(img_input.initialized());
21617
21618 const struct {
21619 VkImageObj &image_obj;
21620 VkImageLayout old_layout;
21621 VkImageLayout new_layout;
21622 } buffer_layouts[] = {
21623 // clang-format off
21624 {img_color, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL},
21625 {img_ds1, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL},
21626 {img_ds2, VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL},
21627 {img_sampled, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL},
21628 {img_input, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL},
21629 {img_xfer_src, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL},
21630 {img_xfer_dst, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL},
21631 // clang-format on
21632 };
21633 const uint32_t layout_count = sizeof(buffer_layouts) / sizeof(buffer_layouts[0]);
21634
21635 m_commandBuffer->BeginCommandBuffer();
21636 for (uint32_t i = 0; i < layout_count; ++i) {
21637 img_barrier.image = buffer_layouts[i].image_obj.handle();
21638 const VkImageUsageFlags usage = buffer_layouts[i].image_obj.usage();
21639 img_barrier.subresourceRange.aspectMask = (usage == VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT)
21640 ? (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)
21641 : VK_IMAGE_ASPECT_COLOR_BIT;
21642
21643 img_barrier.oldLayout = buffer_layouts[i].old_layout;
21644 img_barrier.newLayout = buffer_layouts[i].new_layout;
21645 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT,
21646 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0, nullptr, 1, &img_barrier);
21647
21648 img_barrier.oldLayout = buffer_layouts[i].new_layout;
21649 img_barrier.newLayout = buffer_layouts[i].old_layout;
21650 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT,
21651 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0, nullptr, 1, &img_barrier);
21652 }
21653 m_commandBuffer->EndCommandBuffer();
21654
21655 img_barrier.oldLayout = VK_IMAGE_LAYOUT_GENERAL;
21656 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
21657 }
21658 m_errorMonitor->VerifyNotFound();
21659}
21660
21661// This is a positive test. No errors should be generated.
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021662TEST_F(VkPositiveLayerTest, WaitEventThenSet) {
21663 TEST_DESCRIPTION("Wait on a event then set it after the wait has been submitted.");
21664
21665 m_errorMonitor->ExpectSuccess();
Tony Barbour1fa09702017-03-16 12:09:08 -060021666 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021667
21668 VkEvent event;
21669 VkEventCreateInfo event_create_info{};
21670 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
21671 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
21672
21673 VkCommandPool command_pool;
21674 VkCommandPoolCreateInfo pool_create_info{};
21675 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
21676 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
21677 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
21678 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
21679
21680 VkCommandBuffer command_buffer;
21681 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
21682 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
21683 command_buffer_allocate_info.commandPool = command_pool;
21684 command_buffer_allocate_info.commandBufferCount = 1;
21685 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
21686 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
21687
21688 VkQueue queue = VK_NULL_HANDLE;
21689 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
21690
21691 {
21692 VkCommandBufferBeginInfo begin_info{};
21693 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21694 vkBeginCommandBuffer(command_buffer, &begin_info);
21695
21696 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 -070021697 nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021698 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
21699 vkEndCommandBuffer(command_buffer);
21700 }
21701 {
21702 VkSubmitInfo submit_info{};
21703 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21704 submit_info.commandBufferCount = 1;
21705 submit_info.pCommandBuffers = &command_buffer;
21706 submit_info.signalSemaphoreCount = 0;
21707 submit_info.pSignalSemaphores = nullptr;
21708 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
21709 }
21710 { vkSetEvent(m_device->device(), event); }
21711
21712 vkQueueWaitIdle(queue);
21713
21714 vkDestroyEvent(m_device->device(), event, nullptr);
21715 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
21716 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
21717
21718 m_errorMonitor->VerifyNotFound();
21719}
21720// This is a positive test. No errors should be generated.
21721TEST_F(VkPositiveLayerTest, QueryAndCopySecondaryCommandBuffers) {
21722 TEST_DESCRIPTION("Issue a query on a secondary command buffery and copy it on a primary.");
21723
Tony Barbour1fa09702017-03-16 12:09:08 -060021724 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021725 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021726
21727 m_errorMonitor->ExpectSuccess();
21728
21729 VkQueryPool query_pool;
21730 VkQueryPoolCreateInfo query_pool_create_info{};
21731 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
21732 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
21733 query_pool_create_info.queryCount = 1;
21734 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
21735
21736 VkCommandPool command_pool;
21737 VkCommandPoolCreateInfo pool_create_info{};
21738 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
21739 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
21740 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
21741 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
21742
21743 VkCommandBuffer command_buffer;
21744 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
21745 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
21746 command_buffer_allocate_info.commandPool = command_pool;
21747 command_buffer_allocate_info.commandBufferCount = 1;
21748 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
21749 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
21750
21751 VkCommandBuffer secondary_command_buffer;
21752 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
21753 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer);
21754
21755 VkQueue queue = VK_NULL_HANDLE;
21756 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
21757
21758 uint32_t qfi = 0;
21759 VkBufferCreateInfo buff_create_info = {};
21760 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
21761 buff_create_info.size = 1024;
21762 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
21763 buff_create_info.queueFamilyIndexCount = 1;
21764 buff_create_info.pQueueFamilyIndices = &qfi;
21765
21766 VkResult err;
21767 VkBuffer buffer;
21768 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
21769 ASSERT_VK_SUCCESS(err);
21770 VkMemoryAllocateInfo mem_alloc = {};
21771 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
21772 mem_alloc.pNext = NULL;
21773 mem_alloc.allocationSize = 1024;
21774 mem_alloc.memoryTypeIndex = 0;
21775
21776 VkMemoryRequirements memReqs;
21777 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
21778 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
21779 if (!pass) {
21780 vkDestroyBuffer(m_device->device(), buffer, NULL);
21781 return;
21782 }
21783
21784 VkDeviceMemory mem;
21785 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
21786 ASSERT_VK_SUCCESS(err);
21787 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
21788 ASSERT_VK_SUCCESS(err);
21789
21790 VkCommandBufferInheritanceInfo hinfo = {};
21791 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
21792 hinfo.renderPass = VK_NULL_HANDLE;
21793 hinfo.subpass = 0;
21794 hinfo.framebuffer = VK_NULL_HANDLE;
21795 hinfo.occlusionQueryEnable = VK_FALSE;
21796 hinfo.queryFlags = 0;
21797 hinfo.pipelineStatistics = 0;
21798
21799 {
21800 VkCommandBufferBeginInfo begin_info{};
21801 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21802 begin_info.pInheritanceInfo = &hinfo;
21803 vkBeginCommandBuffer(secondary_command_buffer, &begin_info);
21804
21805 vkCmdResetQueryPool(secondary_command_buffer, query_pool, 0, 1);
21806 vkCmdWriteTimestamp(secondary_command_buffer, VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
21807
21808 vkEndCommandBuffer(secondary_command_buffer);
21809
21810 begin_info.pInheritanceInfo = nullptr;
21811 vkBeginCommandBuffer(command_buffer, &begin_info);
21812
21813 vkCmdExecuteCommands(command_buffer, 1, &secondary_command_buffer);
21814 vkCmdCopyQueryPoolResults(command_buffer, query_pool, 0, 1, buffer, 0, 0, 0);
21815
21816 vkEndCommandBuffer(command_buffer);
21817 }
21818 {
21819 VkSubmitInfo submit_info{};
21820 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21821 submit_info.commandBufferCount = 1;
21822 submit_info.pCommandBuffers = &command_buffer;
21823 submit_info.signalSemaphoreCount = 0;
21824 submit_info.pSignalSemaphores = nullptr;
21825 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
21826 }
21827
21828 vkQueueWaitIdle(queue);
21829
21830 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
21831 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
21832 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &secondary_command_buffer);
21833 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
21834 vkDestroyBuffer(m_device->device(), buffer, NULL);
21835 vkFreeMemory(m_device->device(), mem, NULL);
21836
21837 m_errorMonitor->VerifyNotFound();
21838}
21839
21840// This is a positive test. No errors should be generated.
21841TEST_F(VkPositiveLayerTest, QueryAndCopyMultipleCommandBuffers) {
21842 TEST_DESCRIPTION("Issue a query and copy from it on a second command buffer.");
21843
Tony Barbour1fa09702017-03-16 12:09:08 -060021844 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021845 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021846
21847 m_errorMonitor->ExpectSuccess();
21848
21849 VkQueryPool query_pool;
21850 VkQueryPoolCreateInfo query_pool_create_info{};
21851 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
21852 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
21853 query_pool_create_info.queryCount = 1;
21854 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
21855
21856 VkCommandPool command_pool;
21857 VkCommandPoolCreateInfo pool_create_info{};
21858 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
21859 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
21860 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
21861 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
21862
21863 VkCommandBuffer command_buffer[2];
21864 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
21865 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
21866 command_buffer_allocate_info.commandPool = command_pool;
21867 command_buffer_allocate_info.commandBufferCount = 2;
21868 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
21869 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
21870
21871 VkQueue queue = VK_NULL_HANDLE;
21872 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
21873
21874 uint32_t qfi = 0;
21875 VkBufferCreateInfo buff_create_info = {};
21876 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
21877 buff_create_info.size = 1024;
21878 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
21879 buff_create_info.queueFamilyIndexCount = 1;
21880 buff_create_info.pQueueFamilyIndices = &qfi;
21881
21882 VkResult err;
21883 VkBuffer buffer;
21884 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
21885 ASSERT_VK_SUCCESS(err);
21886 VkMemoryAllocateInfo mem_alloc = {};
21887 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
21888 mem_alloc.pNext = NULL;
21889 mem_alloc.allocationSize = 1024;
21890 mem_alloc.memoryTypeIndex = 0;
21891
21892 VkMemoryRequirements memReqs;
21893 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
21894 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
21895 if (!pass) {
21896 vkDestroyBuffer(m_device->device(), buffer, NULL);
21897 return;
21898 }
21899
21900 VkDeviceMemory mem;
21901 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
21902 ASSERT_VK_SUCCESS(err);
21903 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
21904 ASSERT_VK_SUCCESS(err);
21905
21906 {
21907 VkCommandBufferBeginInfo begin_info{};
21908 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21909 vkBeginCommandBuffer(command_buffer[0], &begin_info);
21910
21911 vkCmdResetQueryPool(command_buffer[0], query_pool, 0, 1);
21912 vkCmdWriteTimestamp(command_buffer[0], VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
21913
21914 vkEndCommandBuffer(command_buffer[0]);
21915
21916 vkBeginCommandBuffer(command_buffer[1], &begin_info);
21917
21918 vkCmdCopyQueryPoolResults(command_buffer[1], query_pool, 0, 1, buffer, 0, 0, 0);
21919
21920 vkEndCommandBuffer(command_buffer[1]);
21921 }
21922 {
21923 VkSubmitInfo submit_info{};
21924 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21925 submit_info.commandBufferCount = 2;
21926 submit_info.pCommandBuffers = command_buffer;
21927 submit_info.signalSemaphoreCount = 0;
21928 submit_info.pSignalSemaphores = nullptr;
21929 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
21930 }
21931
21932 vkQueueWaitIdle(queue);
21933
21934 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
21935 vkFreeCommandBuffers(m_device->device(), command_pool, 2, command_buffer);
21936 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
21937 vkDestroyBuffer(m_device->device(), buffer, NULL);
21938 vkFreeMemory(m_device->device(), mem, NULL);
21939
21940 m_errorMonitor->VerifyNotFound();
21941}
21942
Tony Barbourc46924f2016-11-04 11:49:52 -060021943TEST_F(VkLayerTest, ResetEventThenSet) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021944 TEST_DESCRIPTION("Reset an event then set it after the reset has been submitted.");
21945
Tony Barbour1fa09702017-03-16 12:09:08 -060021946 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021947 VkEvent event;
21948 VkEventCreateInfo event_create_info{};
21949 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
21950 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
21951
21952 VkCommandPool command_pool;
21953 VkCommandPoolCreateInfo pool_create_info{};
21954 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
21955 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
21956 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
21957 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
21958
21959 VkCommandBuffer command_buffer;
21960 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
21961 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
21962 command_buffer_allocate_info.commandPool = command_pool;
21963 command_buffer_allocate_info.commandBufferCount = 1;
21964 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
21965 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
21966
21967 VkQueue queue = VK_NULL_HANDLE;
21968 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
21969
21970 {
21971 VkCommandBufferBeginInfo begin_info{};
21972 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21973 vkBeginCommandBuffer(command_buffer, &begin_info);
21974
21975 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021976 vkEndCommandBuffer(command_buffer);
21977 }
21978 {
21979 VkSubmitInfo submit_info{};
21980 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21981 submit_info.commandBufferCount = 1;
21982 submit_info.pCommandBuffers = &command_buffer;
21983 submit_info.signalSemaphoreCount = 0;
21984 submit_info.pSignalSemaphores = nullptr;
21985 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
21986 }
21987 {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021988 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
21989 "that is already in use by a "
21990 "command buffer.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021991 vkSetEvent(m_device->device(), event);
21992 m_errorMonitor->VerifyFound();
21993 }
21994
21995 vkQueueWaitIdle(queue);
21996
21997 vkDestroyEvent(m_device->device(), event, nullptr);
21998 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
21999 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
22000}
22001
22002// This is a positive test. No errors should be generated.
22003TEST_F(VkPositiveLayerTest, TwoFencesThreeFrames) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022004 TEST_DESCRIPTION(
22005 "Two command buffers with two separate fences are each "
22006 "run through a Submit & WaitForFences cycle 3 times. This "
22007 "previously revealed a bug so running this positive test "
22008 "to prevent a regression.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022009 m_errorMonitor->ExpectSuccess();
22010
Tony Barbour1fa09702017-03-16 12:09:08 -060022011 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022012 VkQueue queue = VK_NULL_HANDLE;
22013 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
22014
22015 static const uint32_t NUM_OBJECTS = 2;
22016 static const uint32_t NUM_FRAMES = 3;
22017 VkCommandBuffer cmd_buffers[NUM_OBJECTS] = {};
22018 VkFence fences[NUM_OBJECTS] = {};
22019
22020 VkCommandPool cmd_pool;
22021 VkCommandPoolCreateInfo cmd_pool_ci = {};
22022 cmd_pool_ci.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
22023 cmd_pool_ci.queueFamilyIndex = m_device->graphics_queue_node_index_;
22024 cmd_pool_ci.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
22025 VkResult err = vkCreateCommandPool(m_device->device(), &cmd_pool_ci, nullptr, &cmd_pool);
22026 ASSERT_VK_SUCCESS(err);
22027
22028 VkCommandBufferAllocateInfo cmd_buf_info = {};
22029 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
22030 cmd_buf_info.commandPool = cmd_pool;
22031 cmd_buf_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
22032 cmd_buf_info.commandBufferCount = 1;
22033
22034 VkFenceCreateInfo fence_ci = {};
22035 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
22036 fence_ci.pNext = nullptr;
22037 fence_ci.flags = 0;
22038
22039 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
22040 err = vkAllocateCommandBuffers(m_device->device(), &cmd_buf_info, &cmd_buffers[i]);
22041 ASSERT_VK_SUCCESS(err);
22042 err = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fences[i]);
22043 ASSERT_VK_SUCCESS(err);
22044 }
22045
22046 for (uint32_t frame = 0; frame < NUM_FRAMES; ++frame) {
22047 for (uint32_t obj = 0; obj < NUM_OBJECTS; ++obj) {
22048 // Create empty cmd buffer
22049 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
22050 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22051
22052 err = vkBeginCommandBuffer(cmd_buffers[obj], &cmdBufBeginDesc);
22053 ASSERT_VK_SUCCESS(err);
22054 err = vkEndCommandBuffer(cmd_buffers[obj]);
22055 ASSERT_VK_SUCCESS(err);
22056
22057 VkSubmitInfo submit_info = {};
22058 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22059 submit_info.commandBufferCount = 1;
22060 submit_info.pCommandBuffers = &cmd_buffers[obj];
22061 // Submit cmd buffer and wait for fence
22062 err = vkQueueSubmit(queue, 1, &submit_info, fences[obj]);
22063 ASSERT_VK_SUCCESS(err);
22064 err = vkWaitForFences(m_device->device(), 1, &fences[obj], VK_TRUE, UINT64_MAX);
22065 ASSERT_VK_SUCCESS(err);
22066 err = vkResetFences(m_device->device(), 1, &fences[obj]);
22067 ASSERT_VK_SUCCESS(err);
22068 }
22069 }
22070 m_errorMonitor->VerifyNotFound();
22071 vkDestroyCommandPool(m_device->device(), cmd_pool, NULL);
22072 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
22073 vkDestroyFence(m_device->device(), fences[i], nullptr);
22074 }
22075}
22076// This is a positive test. No errors should be generated.
22077TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWI) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022078 TEST_DESCRIPTION(
22079 "Two command buffers, each in a separate QueueSubmit call "
22080 "submitted on separate queues followed by a QueueWaitIdle.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022081
Tony Barbour1fa09702017-03-16 12:09:08 -060022082 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022083 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022084
22085 m_errorMonitor->ExpectSuccess();
22086
22087 VkSemaphore semaphore;
22088 VkSemaphoreCreateInfo semaphore_create_info{};
22089 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
22090 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
22091
22092 VkCommandPool command_pool;
22093 VkCommandPoolCreateInfo pool_create_info{};
22094 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
22095 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
22096 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
22097 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
22098
22099 VkCommandBuffer command_buffer[2];
22100 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
22101 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
22102 command_buffer_allocate_info.commandPool = command_pool;
22103 command_buffer_allocate_info.commandBufferCount = 2;
22104 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
22105 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
22106
22107 VkQueue queue = VK_NULL_HANDLE;
22108 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
22109
22110 {
22111 VkCommandBufferBeginInfo begin_info{};
22112 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22113 vkBeginCommandBuffer(command_buffer[0], &begin_info);
22114
22115 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 -070022116 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022117
22118 VkViewport viewport{};
22119 viewport.maxDepth = 1.0f;
22120 viewport.minDepth = 0.0f;
22121 viewport.width = 512;
22122 viewport.height = 512;
22123 viewport.x = 0;
22124 viewport.y = 0;
22125 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
22126 vkEndCommandBuffer(command_buffer[0]);
22127 }
22128 {
22129 VkCommandBufferBeginInfo begin_info{};
22130 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22131 vkBeginCommandBuffer(command_buffer[1], &begin_info);
22132
22133 VkViewport viewport{};
22134 viewport.maxDepth = 1.0f;
22135 viewport.minDepth = 0.0f;
22136 viewport.width = 512;
22137 viewport.height = 512;
22138 viewport.x = 0;
22139 viewport.y = 0;
22140 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
22141 vkEndCommandBuffer(command_buffer[1]);
22142 }
22143 {
22144 VkSubmitInfo submit_info{};
22145 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22146 submit_info.commandBufferCount = 1;
22147 submit_info.pCommandBuffers = &command_buffer[0];
22148 submit_info.signalSemaphoreCount = 1;
22149 submit_info.pSignalSemaphores = &semaphore;
22150 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
22151 }
22152 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022153 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022154 VkSubmitInfo submit_info{};
22155 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22156 submit_info.commandBufferCount = 1;
22157 submit_info.pCommandBuffers = &command_buffer[1];
22158 submit_info.waitSemaphoreCount = 1;
22159 submit_info.pWaitSemaphores = &semaphore;
22160 submit_info.pWaitDstStageMask = flags;
22161 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
22162 }
22163
22164 vkQueueWaitIdle(m_device->m_queue);
22165
22166 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
22167 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
22168 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
22169
22170 m_errorMonitor->VerifyNotFound();
22171}
22172
22173// This is a positive test. No errors should be generated.
22174TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWIFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022175 TEST_DESCRIPTION(
22176 "Two command buffers, each in a separate QueueSubmit call "
22177 "submitted on separate queues, the second having a fence"
22178 "followed by a QueueWaitIdle.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022179
Tony Barbour1fa09702017-03-16 12:09:08 -060022180 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022181 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022182
22183 m_errorMonitor->ExpectSuccess();
22184
22185 VkFence fence;
22186 VkFenceCreateInfo fence_create_info{};
22187 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
22188 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
22189
22190 VkSemaphore semaphore;
22191 VkSemaphoreCreateInfo semaphore_create_info{};
22192 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
22193 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
22194
22195 VkCommandPool command_pool;
22196 VkCommandPoolCreateInfo pool_create_info{};
22197 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
22198 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
22199 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
22200 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
22201
22202 VkCommandBuffer command_buffer[2];
22203 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
22204 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
22205 command_buffer_allocate_info.commandPool = command_pool;
22206 command_buffer_allocate_info.commandBufferCount = 2;
22207 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
22208 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
22209
22210 VkQueue queue = VK_NULL_HANDLE;
22211 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
22212
22213 {
22214 VkCommandBufferBeginInfo begin_info{};
22215 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22216 vkBeginCommandBuffer(command_buffer[0], &begin_info);
22217
22218 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 -070022219 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022220
22221 VkViewport viewport{};
22222 viewport.maxDepth = 1.0f;
22223 viewport.minDepth = 0.0f;
22224 viewport.width = 512;
22225 viewport.height = 512;
22226 viewport.x = 0;
22227 viewport.y = 0;
22228 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
22229 vkEndCommandBuffer(command_buffer[0]);
22230 }
22231 {
22232 VkCommandBufferBeginInfo begin_info{};
22233 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22234 vkBeginCommandBuffer(command_buffer[1], &begin_info);
22235
22236 VkViewport viewport{};
22237 viewport.maxDepth = 1.0f;
22238 viewport.minDepth = 0.0f;
22239 viewport.width = 512;
22240 viewport.height = 512;
22241 viewport.x = 0;
22242 viewport.y = 0;
22243 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
22244 vkEndCommandBuffer(command_buffer[1]);
22245 }
22246 {
22247 VkSubmitInfo submit_info{};
22248 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22249 submit_info.commandBufferCount = 1;
22250 submit_info.pCommandBuffers = &command_buffer[0];
22251 submit_info.signalSemaphoreCount = 1;
22252 submit_info.pSignalSemaphores = &semaphore;
22253 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
22254 }
22255 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022256 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022257 VkSubmitInfo submit_info{};
22258 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22259 submit_info.commandBufferCount = 1;
22260 submit_info.pCommandBuffers = &command_buffer[1];
22261 submit_info.waitSemaphoreCount = 1;
22262 submit_info.pWaitSemaphores = &semaphore;
22263 submit_info.pWaitDstStageMask = flags;
22264 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
22265 }
22266
22267 vkQueueWaitIdle(m_device->m_queue);
22268
22269 vkDestroyFence(m_device->device(), fence, nullptr);
22270 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
22271 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
22272 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
22273
22274 m_errorMonitor->VerifyNotFound();
22275}
22276
22277// This is a positive test. No errors should be generated.
22278TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceTwoWFF) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022279 TEST_DESCRIPTION(
22280 "Two command buffers, each in a separate QueueSubmit call "
22281 "submitted on separate queues, the second having a fence"
22282 "followed by two consecutive WaitForFences calls on the same fence.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022283
Tony Barbour1fa09702017-03-16 12:09:08 -060022284 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022285 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022286
22287 m_errorMonitor->ExpectSuccess();
22288
22289 VkFence fence;
22290 VkFenceCreateInfo fence_create_info{};
22291 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
22292 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
22293
22294 VkSemaphore semaphore;
22295 VkSemaphoreCreateInfo semaphore_create_info{};
22296 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
22297 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
22298
22299 VkCommandPool command_pool;
22300 VkCommandPoolCreateInfo pool_create_info{};
22301 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
22302 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
22303 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
22304 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
22305
22306 VkCommandBuffer command_buffer[2];
22307 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
22308 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
22309 command_buffer_allocate_info.commandPool = command_pool;
22310 command_buffer_allocate_info.commandBufferCount = 2;
22311 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
22312 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
22313
22314 VkQueue queue = VK_NULL_HANDLE;
22315 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
22316
22317 {
22318 VkCommandBufferBeginInfo begin_info{};
22319 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22320 vkBeginCommandBuffer(command_buffer[0], &begin_info);
22321
22322 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 -070022323 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022324
22325 VkViewport viewport{};
22326 viewport.maxDepth = 1.0f;
22327 viewport.minDepth = 0.0f;
22328 viewport.width = 512;
22329 viewport.height = 512;
22330 viewport.x = 0;
22331 viewport.y = 0;
22332 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
22333 vkEndCommandBuffer(command_buffer[0]);
22334 }
22335 {
22336 VkCommandBufferBeginInfo begin_info{};
22337 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22338 vkBeginCommandBuffer(command_buffer[1], &begin_info);
22339
22340 VkViewport viewport{};
22341 viewport.maxDepth = 1.0f;
22342 viewport.minDepth = 0.0f;
22343 viewport.width = 512;
22344 viewport.height = 512;
22345 viewport.x = 0;
22346 viewport.y = 0;
22347 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
22348 vkEndCommandBuffer(command_buffer[1]);
22349 }
22350 {
22351 VkSubmitInfo submit_info{};
22352 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22353 submit_info.commandBufferCount = 1;
22354 submit_info.pCommandBuffers = &command_buffer[0];
22355 submit_info.signalSemaphoreCount = 1;
22356 submit_info.pSignalSemaphores = &semaphore;
22357 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
22358 }
22359 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022360 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022361 VkSubmitInfo submit_info{};
22362 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22363 submit_info.commandBufferCount = 1;
22364 submit_info.pCommandBuffers = &command_buffer[1];
22365 submit_info.waitSemaphoreCount = 1;
22366 submit_info.pWaitSemaphores = &semaphore;
22367 submit_info.pWaitDstStageMask = flags;
22368 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
22369 }
22370
22371 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
22372 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
22373
22374 vkDestroyFence(m_device->device(), fence, nullptr);
22375 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
22376 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
22377 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
22378
22379 m_errorMonitor->VerifyNotFound();
22380}
22381
22382TEST_F(VkPositiveLayerTest, TwoQueuesEnsureCorrectRetirementWithWorkStolen) {
Tony Barbour1fa09702017-03-16 12:09:08 -060022383 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022384 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070022385 printf(" Test requires two queues, skipping\n");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022386 return;
22387 }
22388
22389 VkResult err;
22390
22391 m_errorMonitor->ExpectSuccess();
22392
22393 VkQueue q0 = m_device->m_queue;
22394 VkQueue q1 = nullptr;
22395 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &q1);
22396 ASSERT_NE(q1, nullptr);
22397
22398 // An (empty) command buffer. We must have work in the first submission --
22399 // the layer treats unfenced work differently from fenced work.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022400 VkCommandPoolCreateInfo cpci = {VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, nullptr, 0, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022401 VkCommandPool pool;
22402 err = vkCreateCommandPool(m_device->device(), &cpci, nullptr, &pool);
22403 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022404 VkCommandBufferAllocateInfo cbai = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, nullptr, pool,
22405 VK_COMMAND_BUFFER_LEVEL_PRIMARY, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022406 VkCommandBuffer cb;
22407 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &cb);
22408 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022409 VkCommandBufferBeginInfo cbbi = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022410 err = vkBeginCommandBuffer(cb, &cbbi);
22411 ASSERT_VK_SUCCESS(err);
22412 err = vkEndCommandBuffer(cb);
22413 ASSERT_VK_SUCCESS(err);
22414
22415 // A semaphore
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022416 VkSemaphoreCreateInfo sci = {VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022417 VkSemaphore s;
22418 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s);
22419 ASSERT_VK_SUCCESS(err);
22420
22421 // First submission, to q0
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022422 VkSubmitInfo s0 = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &cb, 1, &s};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022423
22424 err = vkQueueSubmit(q0, 1, &s0, VK_NULL_HANDLE);
22425 ASSERT_VK_SUCCESS(err);
22426
22427 // Second submission, to q1, waiting on s
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022428 VkFlags waitmask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; // doesn't really matter what this value is.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022429 VkSubmitInfo s1 = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 1, &s, &waitmask, 0, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022430
22431 err = vkQueueSubmit(q1, 1, &s1, VK_NULL_HANDLE);
22432 ASSERT_VK_SUCCESS(err);
22433
22434 // Wait for q0 idle
22435 err = vkQueueWaitIdle(q0);
22436 ASSERT_VK_SUCCESS(err);
22437
22438 // Command buffer should have been completed (it was on q0); reset the pool.
22439 vkFreeCommandBuffers(m_device->device(), pool, 1, &cb);
22440
22441 m_errorMonitor->VerifyNotFound();
22442
22443 // Force device completely idle and clean up resources
22444 vkDeviceWaitIdle(m_device->device());
22445 vkDestroyCommandPool(m_device->device(), pool, nullptr);
22446 vkDestroySemaphore(m_device->device(), s, nullptr);
22447}
22448
22449// This is a positive test. No errors should be generated.
22450TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022451 TEST_DESCRIPTION(
22452 "Two command buffers, each in a separate QueueSubmit call "
22453 "submitted on separate queues, the second having a fence, "
22454 "followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022455
Tony Barbour1fa09702017-03-16 12:09:08 -060022456 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022457 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022458
22459 m_errorMonitor->ExpectSuccess();
22460
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022461 VkFence fence;
22462 VkFenceCreateInfo fence_create_info{};
22463 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
22464 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
22465
22466 VkSemaphore semaphore;
22467 VkSemaphoreCreateInfo semaphore_create_info{};
22468 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
22469 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
22470
22471 VkCommandPool command_pool;
22472 VkCommandPoolCreateInfo pool_create_info{};
22473 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
22474 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
22475 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
22476 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
22477
22478 VkCommandBuffer command_buffer[2];
22479 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
22480 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
22481 command_buffer_allocate_info.commandPool = command_pool;
22482 command_buffer_allocate_info.commandBufferCount = 2;
22483 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
22484 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
22485
22486 VkQueue queue = VK_NULL_HANDLE;
22487 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
22488
22489 {
22490 VkCommandBufferBeginInfo begin_info{};
22491 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22492 vkBeginCommandBuffer(command_buffer[0], &begin_info);
22493
22494 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 -070022495 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022496
22497 VkViewport viewport{};
22498 viewport.maxDepth = 1.0f;
22499 viewport.minDepth = 0.0f;
22500 viewport.width = 512;
22501 viewport.height = 512;
22502 viewport.x = 0;
22503 viewport.y = 0;
22504 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
22505 vkEndCommandBuffer(command_buffer[0]);
22506 }
22507 {
22508 VkCommandBufferBeginInfo begin_info{};
22509 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22510 vkBeginCommandBuffer(command_buffer[1], &begin_info);
22511
22512 VkViewport viewport{};
22513 viewport.maxDepth = 1.0f;
22514 viewport.minDepth = 0.0f;
22515 viewport.width = 512;
22516 viewport.height = 512;
22517 viewport.x = 0;
22518 viewport.y = 0;
22519 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
22520 vkEndCommandBuffer(command_buffer[1]);
22521 }
22522 {
22523 VkSubmitInfo submit_info{};
22524 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22525 submit_info.commandBufferCount = 1;
22526 submit_info.pCommandBuffers = &command_buffer[0];
22527 submit_info.signalSemaphoreCount = 1;
22528 submit_info.pSignalSemaphores = &semaphore;
22529 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
22530 }
22531 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022532 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022533 VkSubmitInfo submit_info{};
22534 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22535 submit_info.commandBufferCount = 1;
22536 submit_info.pCommandBuffers = &command_buffer[1];
22537 submit_info.waitSemaphoreCount = 1;
22538 submit_info.pWaitSemaphores = &semaphore;
22539 submit_info.pWaitDstStageMask = flags;
22540 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
22541 }
22542
22543 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
22544
22545 vkDestroyFence(m_device->device(), fence, nullptr);
22546 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
22547 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
22548 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
22549
22550 m_errorMonitor->VerifyNotFound();
22551}
22552
22553// This is a positive test. No errors should be generated.
22554TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueWithSemaphoreAndOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022555 TEST_DESCRIPTION(
22556 "Two command buffers, each in a separate QueueSubmit call "
22557 "on the same queue, sharing a signal/wait semaphore, the "
22558 "second having a fence, "
22559 "followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022560
22561 m_errorMonitor->ExpectSuccess();
22562
Tony Barbour1fa09702017-03-16 12:09:08 -060022563 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022564 VkFence fence;
22565 VkFenceCreateInfo fence_create_info{};
22566 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
22567 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
22568
22569 VkSemaphore semaphore;
22570 VkSemaphoreCreateInfo semaphore_create_info{};
22571 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
22572 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
22573
22574 VkCommandPool command_pool;
22575 VkCommandPoolCreateInfo pool_create_info{};
22576 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
22577 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
22578 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
22579 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
22580
22581 VkCommandBuffer command_buffer[2];
22582 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
22583 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
22584 command_buffer_allocate_info.commandPool = command_pool;
22585 command_buffer_allocate_info.commandBufferCount = 2;
22586 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
22587 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
22588
22589 {
22590 VkCommandBufferBeginInfo begin_info{};
22591 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22592 vkBeginCommandBuffer(command_buffer[0], &begin_info);
22593
22594 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 -070022595 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022596
22597 VkViewport viewport{};
22598 viewport.maxDepth = 1.0f;
22599 viewport.minDepth = 0.0f;
22600 viewport.width = 512;
22601 viewport.height = 512;
22602 viewport.x = 0;
22603 viewport.y = 0;
22604 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
22605 vkEndCommandBuffer(command_buffer[0]);
22606 }
22607 {
22608 VkCommandBufferBeginInfo begin_info{};
22609 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22610 vkBeginCommandBuffer(command_buffer[1], &begin_info);
22611
22612 VkViewport viewport{};
22613 viewport.maxDepth = 1.0f;
22614 viewport.minDepth = 0.0f;
22615 viewport.width = 512;
22616 viewport.height = 512;
22617 viewport.x = 0;
22618 viewport.y = 0;
22619 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
22620 vkEndCommandBuffer(command_buffer[1]);
22621 }
22622 {
22623 VkSubmitInfo submit_info{};
22624 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22625 submit_info.commandBufferCount = 1;
22626 submit_info.pCommandBuffers = &command_buffer[0];
22627 submit_info.signalSemaphoreCount = 1;
22628 submit_info.pSignalSemaphores = &semaphore;
22629 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
22630 }
22631 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022632 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022633 VkSubmitInfo submit_info{};
22634 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22635 submit_info.commandBufferCount = 1;
22636 submit_info.pCommandBuffers = &command_buffer[1];
22637 submit_info.waitSemaphoreCount = 1;
22638 submit_info.pWaitSemaphores = &semaphore;
22639 submit_info.pWaitDstStageMask = flags;
22640 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
22641 }
22642
22643 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
22644
22645 vkDestroyFence(m_device->device(), fence, nullptr);
22646 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
22647 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
22648 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
22649
22650 m_errorMonitor->VerifyNotFound();
22651}
22652
22653// This is a positive test. No errors should be generated.
22654TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueNullQueueSubmitWithFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022655 TEST_DESCRIPTION(
22656 "Two command buffers, each in a separate QueueSubmit call "
22657 "on the same queue, no fences, followed by a third QueueSubmit with NO "
22658 "SubmitInfos but with a fence, followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022659
22660 m_errorMonitor->ExpectSuccess();
22661
Tony Barbour1fa09702017-03-16 12:09:08 -060022662 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022663 VkFence fence;
22664 VkFenceCreateInfo fence_create_info{};
22665 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
22666 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
22667
22668 VkCommandPool command_pool;
22669 VkCommandPoolCreateInfo pool_create_info{};
22670 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
22671 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
22672 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
22673 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
22674
22675 VkCommandBuffer command_buffer[2];
22676 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
22677 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
22678 command_buffer_allocate_info.commandPool = command_pool;
22679 command_buffer_allocate_info.commandBufferCount = 2;
22680 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
22681 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
22682
22683 {
22684 VkCommandBufferBeginInfo begin_info{};
22685 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22686 vkBeginCommandBuffer(command_buffer[0], &begin_info);
22687
22688 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 -070022689 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022690
22691 VkViewport viewport{};
22692 viewport.maxDepth = 1.0f;
22693 viewport.minDepth = 0.0f;
22694 viewport.width = 512;
22695 viewport.height = 512;
22696 viewport.x = 0;
22697 viewport.y = 0;
22698 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
22699 vkEndCommandBuffer(command_buffer[0]);
22700 }
22701 {
22702 VkCommandBufferBeginInfo begin_info{};
22703 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22704 vkBeginCommandBuffer(command_buffer[1], &begin_info);
22705
22706 VkViewport viewport{};
22707 viewport.maxDepth = 1.0f;
22708 viewport.minDepth = 0.0f;
22709 viewport.width = 512;
22710 viewport.height = 512;
22711 viewport.x = 0;
22712 viewport.y = 0;
22713 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
22714 vkEndCommandBuffer(command_buffer[1]);
22715 }
22716 {
22717 VkSubmitInfo submit_info{};
22718 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22719 submit_info.commandBufferCount = 1;
22720 submit_info.pCommandBuffers = &command_buffer[0];
22721 submit_info.signalSemaphoreCount = 0;
22722 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
22723 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
22724 }
22725 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022726 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022727 VkSubmitInfo submit_info{};
22728 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22729 submit_info.commandBufferCount = 1;
22730 submit_info.pCommandBuffers = &command_buffer[1];
22731 submit_info.waitSemaphoreCount = 0;
22732 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
22733 submit_info.pWaitDstStageMask = flags;
22734 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
22735 }
22736
22737 vkQueueSubmit(m_device->m_queue, 0, NULL, fence);
22738
22739 VkResult err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
22740 ASSERT_VK_SUCCESS(err);
22741
22742 vkDestroyFence(m_device->device(), fence, nullptr);
22743 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
22744 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
22745
22746 m_errorMonitor->VerifyNotFound();
22747}
22748
22749// This is a positive test. No errors should be generated.
22750TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022751 TEST_DESCRIPTION(
22752 "Two command buffers, each in a separate QueueSubmit call "
22753 "on the same queue, the second having a fence, followed "
22754 "by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022755
22756 m_errorMonitor->ExpectSuccess();
22757
Tony Barbour1fa09702017-03-16 12:09:08 -060022758 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022759 VkFence fence;
22760 VkFenceCreateInfo fence_create_info{};
22761 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
22762 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
22763
22764 VkCommandPool command_pool;
22765 VkCommandPoolCreateInfo pool_create_info{};
22766 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
22767 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
22768 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
22769 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
22770
22771 VkCommandBuffer command_buffer[2];
22772 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
22773 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
22774 command_buffer_allocate_info.commandPool = command_pool;
22775 command_buffer_allocate_info.commandBufferCount = 2;
22776 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
22777 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
22778
22779 {
22780 VkCommandBufferBeginInfo begin_info{};
22781 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22782 vkBeginCommandBuffer(command_buffer[0], &begin_info);
22783
22784 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 -070022785 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022786
22787 VkViewport viewport{};
22788 viewport.maxDepth = 1.0f;
22789 viewport.minDepth = 0.0f;
22790 viewport.width = 512;
22791 viewport.height = 512;
22792 viewport.x = 0;
22793 viewport.y = 0;
22794 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
22795 vkEndCommandBuffer(command_buffer[0]);
22796 }
22797 {
22798 VkCommandBufferBeginInfo begin_info{};
22799 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22800 vkBeginCommandBuffer(command_buffer[1], &begin_info);
22801
22802 VkViewport viewport{};
22803 viewport.maxDepth = 1.0f;
22804 viewport.minDepth = 0.0f;
22805 viewport.width = 512;
22806 viewport.height = 512;
22807 viewport.x = 0;
22808 viewport.y = 0;
22809 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
22810 vkEndCommandBuffer(command_buffer[1]);
22811 }
22812 {
22813 VkSubmitInfo submit_info{};
22814 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22815 submit_info.commandBufferCount = 1;
22816 submit_info.pCommandBuffers = &command_buffer[0];
22817 submit_info.signalSemaphoreCount = 0;
22818 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
22819 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
22820 }
22821 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022822 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022823 VkSubmitInfo submit_info{};
22824 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22825 submit_info.commandBufferCount = 1;
22826 submit_info.pCommandBuffers = &command_buffer[1];
22827 submit_info.waitSemaphoreCount = 0;
22828 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
22829 submit_info.pWaitDstStageMask = flags;
22830 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
22831 }
22832
22833 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
22834
22835 vkDestroyFence(m_device->device(), fence, nullptr);
22836 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
22837 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
22838
22839 m_errorMonitor->VerifyNotFound();
22840}
22841
22842// This is a positive test. No errors should be generated.
22843TEST_F(VkPositiveLayerTest, TwoSubmitInfosWithSemaphoreOneQueueSubmitsOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022844 TEST_DESCRIPTION(
22845 "Two command buffers each in a separate SubmitInfo sent in a single "
22846 "QueueSubmit call followed by a WaitForFences call.");
Tony Barbour1fa09702017-03-16 12:09:08 -060022847 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022848
22849 m_errorMonitor->ExpectSuccess();
22850
22851 VkFence fence;
22852 VkFenceCreateInfo fence_create_info{};
22853 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
22854 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
22855
22856 VkSemaphore semaphore;
22857 VkSemaphoreCreateInfo semaphore_create_info{};
22858 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
22859 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
22860
22861 VkCommandPool command_pool;
22862 VkCommandPoolCreateInfo pool_create_info{};
22863 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
22864 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
22865 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
22866 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
22867
22868 VkCommandBuffer command_buffer[2];
22869 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
22870 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
22871 command_buffer_allocate_info.commandPool = command_pool;
22872 command_buffer_allocate_info.commandBufferCount = 2;
22873 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
22874 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
22875
22876 {
22877 VkCommandBufferBeginInfo begin_info{};
22878 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22879 vkBeginCommandBuffer(command_buffer[0], &begin_info);
22880
22881 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 -070022882 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022883
22884 VkViewport viewport{};
22885 viewport.maxDepth = 1.0f;
22886 viewport.minDepth = 0.0f;
22887 viewport.width = 512;
22888 viewport.height = 512;
22889 viewport.x = 0;
22890 viewport.y = 0;
22891 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
22892 vkEndCommandBuffer(command_buffer[0]);
22893 }
22894 {
22895 VkCommandBufferBeginInfo begin_info{};
22896 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22897 vkBeginCommandBuffer(command_buffer[1], &begin_info);
22898
22899 VkViewport viewport{};
22900 viewport.maxDepth = 1.0f;
22901 viewport.minDepth = 0.0f;
22902 viewport.width = 512;
22903 viewport.height = 512;
22904 viewport.x = 0;
22905 viewport.y = 0;
22906 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
22907 vkEndCommandBuffer(command_buffer[1]);
22908 }
22909 {
22910 VkSubmitInfo submit_info[2];
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022911 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022912
22913 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22914 submit_info[0].pNext = NULL;
22915 submit_info[0].commandBufferCount = 1;
22916 submit_info[0].pCommandBuffers = &command_buffer[0];
22917 submit_info[0].signalSemaphoreCount = 1;
22918 submit_info[0].pSignalSemaphores = &semaphore;
22919 submit_info[0].waitSemaphoreCount = 0;
22920 submit_info[0].pWaitSemaphores = NULL;
22921 submit_info[0].pWaitDstStageMask = 0;
22922
22923 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22924 submit_info[1].pNext = NULL;
22925 submit_info[1].commandBufferCount = 1;
22926 submit_info[1].pCommandBuffers = &command_buffer[1];
22927 submit_info[1].waitSemaphoreCount = 1;
22928 submit_info[1].pWaitSemaphores = &semaphore;
22929 submit_info[1].pWaitDstStageMask = flags;
22930 submit_info[1].signalSemaphoreCount = 0;
22931 submit_info[1].pSignalSemaphores = NULL;
22932 vkQueueSubmit(m_device->m_queue, 2, &submit_info[0], fence);
22933 }
22934
22935 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
22936
22937 vkDestroyFence(m_device->device(), fence, nullptr);
22938 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
22939 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
22940 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
22941
22942 m_errorMonitor->VerifyNotFound();
22943}
22944
22945TEST_F(VkPositiveLayerTest, RenderPassSecondaryCommandBuffersMultipleTimes) {
22946 m_errorMonitor->ExpectSuccess();
22947
Tony Barbour1fa09702017-03-16 12:09:08 -060022948 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022949 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
22950
Tony Barbour552f6c02016-12-21 14:34:07 -070022951 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022952
22953 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
22954 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
22955 m_errorMonitor->VerifyNotFound();
22956 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
22957 m_errorMonitor->VerifyNotFound();
22958 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
22959 m_errorMonitor->VerifyNotFound();
22960
22961 m_commandBuffer->EndCommandBuffer();
22962 m_errorMonitor->VerifyNotFound();
22963}
22964
22965TEST_F(VkPositiveLayerTest, ValidRenderPassAttachmentLayoutWithLoadOp) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022966 TEST_DESCRIPTION(
22967 "Positive test where we create a renderpass with an "
22968 "attachment that uses LOAD_OP_CLEAR, the first subpass "
22969 "has a valid layout, and a second subpass then uses a "
22970 "valid *READ_ONLY* layout.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022971 m_errorMonitor->ExpectSuccess();
Tony Barbour1fa09702017-03-16 12:09:08 -060022972 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -060022973 auto depth_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbourf887b162017-03-09 10:06:46 -070022974 if (!depth_format) {
22975 printf(" No Depth + Stencil format found. Skipped.\n");
22976 return;
22977 }
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022978
22979 VkAttachmentReference attach[2] = {};
22980 attach[0].attachment = 0;
22981 attach[0].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
22982 attach[1].attachment = 0;
22983 attach[1].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
22984 VkSubpassDescription subpasses[2] = {};
22985 // First subpass clears DS attach on load
22986 subpasses[0].pDepthStencilAttachment = &attach[0];
22987 // 2nd subpass reads in DS as input attachment
22988 subpasses[1].inputAttachmentCount = 1;
22989 subpasses[1].pInputAttachments = &attach[1];
22990 VkAttachmentDescription attach_desc = {};
Tony Barbourf887b162017-03-09 10:06:46 -070022991 attach_desc.format = depth_format;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022992 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
22993 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
22994 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
22995 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
22996 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
22997 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
22998 attach_desc.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
22999 VkRenderPassCreateInfo rpci = {};
23000 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
23001 rpci.attachmentCount = 1;
23002 rpci.pAttachments = &attach_desc;
23003 rpci.subpassCount = 2;
23004 rpci.pSubpasses = subpasses;
23005
23006 // Now create RenderPass and verify no errors
23007 VkRenderPass rp;
23008 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
23009 m_errorMonitor->VerifyNotFound();
23010
23011 vkDestroyRenderPass(m_device->device(), rp, NULL);
23012}
23013
Tobin Ehlis01103de2017-02-16 13:22:47 -070023014TEST_F(VkPositiveLayerTest, RenderPassDepthStencilLayoutTransition) {
23015 TEST_DESCRIPTION(
23016 "Create a render pass with depth-stencil attachment where layout transition "
23017 "from UNDEFINED TO DS_READ_ONLY_OPTIMAL is set by render pass and verify that "
23018 "transition has correctly occurred at queue submit time with no validation errors.");
23019
Tony Barbour1fa09702017-03-16 12:09:08 -060023020 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -060023021 auto depth_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbourf887b162017-03-09 10:06:46 -070023022 if (!depth_format) {
23023 printf(" No Depth + Stencil format found. Skipped.\n");
23024 return;
23025 }
Tobin Ehlis01103de2017-02-16 13:22:47 -070023026 VkImageFormatProperties format_props;
Tony Barbourf887b162017-03-09 10:06:46 -070023027 vkGetPhysicalDeviceImageFormatProperties(gpu(), depth_format, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
Tobin Ehlis01103de2017-02-16 13:22:47 -070023028 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, 0, &format_props);
23029 if (format_props.maxExtent.width < 32 || format_props.maxExtent.height < 32) {
Tony Barbourf887b162017-03-09 10:06:46 -070023030 printf("Depth extent too small, RenderPassDepthStencilLayoutTransition skipped.\n");
Tobin Ehlis01103de2017-02-16 13:22:47 -070023031 return;
23032 }
23033
23034 m_errorMonitor->ExpectSuccess();
Tobin Ehlis01103de2017-02-16 13:22:47 -070023035 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
23036
23037 // A renderpass with one depth/stencil attachment.
23038 VkAttachmentDescription attachment = {0,
Tony Barbourf887b162017-03-09 10:06:46 -070023039 depth_format,
Tobin Ehlis01103de2017-02-16 13:22:47 -070023040 VK_SAMPLE_COUNT_1_BIT,
23041 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
23042 VK_ATTACHMENT_STORE_OP_DONT_CARE,
23043 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
23044 VK_ATTACHMENT_STORE_OP_DONT_CARE,
23045 VK_IMAGE_LAYOUT_UNDEFINED,
23046 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
23047
23048 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
23049
23050 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, &att_ref, 0, nullptr};
23051
23052 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
23053
23054 VkRenderPass rp;
23055 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
23056 ASSERT_VK_SUCCESS(err);
23057 // A compatible ds image.
23058 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060023059 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 -070023060 ASSERT_TRUE(image.initialized());
23061
23062 VkImageViewCreateInfo ivci = {
23063 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
23064 nullptr,
23065 0,
23066 image.handle(),
23067 VK_IMAGE_VIEW_TYPE_2D,
Tony Barbourf887b162017-03-09 10:06:46 -070023068 depth_format,
Tobin Ehlis01103de2017-02-16 13:22:47 -070023069 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
23070 VK_COMPONENT_SWIZZLE_IDENTITY},
23071 {VK_IMAGE_ASPECT_DEPTH_BIT, 0, 1, 0, 1},
23072 };
23073 VkImageView view;
23074 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
23075 ASSERT_VK_SUCCESS(err);
23076
23077 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
23078 VkFramebuffer fb;
23079 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
23080 ASSERT_VK_SUCCESS(err);
23081
23082 VkRenderPassBeginInfo rpbi = {VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb, {{0, 0}, {32, 32}}, 0, nullptr};
23083 m_commandBuffer->BeginCommandBuffer();
23084 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
23085 vkCmdEndRenderPass(m_commandBuffer->handle());
23086 m_commandBuffer->EndCommandBuffer();
23087 QueueCommandBuffer(false);
23088 m_errorMonitor->VerifyNotFound();
23089
23090 // Cleanup
23091 vkDestroyImageView(m_device->device(), view, NULL);
23092 vkDestroyRenderPass(m_device->device(), rp, NULL);
23093 vkDestroyFramebuffer(m_device->device(), fb, NULL);
23094}
23095
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023096TEST_F(VkPositiveLayerTest, CreatePipelineAttribMatrixType) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023097 TEST_DESCRIPTION(
23098 "Test that pipeline validation accepts matrices passed "
23099 "as vertex attributes");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023100 m_errorMonitor->ExpectSuccess();
23101
Tony Barbour1fa09702017-03-16 12:09:08 -060023102 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023103 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
23104
23105 VkVertexInputBindingDescription input_binding;
23106 memset(&input_binding, 0, sizeof(input_binding));
23107
23108 VkVertexInputAttributeDescription input_attribs[2];
23109 memset(input_attribs, 0, sizeof(input_attribs));
23110
23111 for (int i = 0; i < 2; i++) {
23112 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
23113 input_attribs[i].location = i;
23114 }
23115
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023116 char const *vsSource =
23117 "#version 450\n"
23118 "\n"
23119 "layout(location=0) in mat2x4 x;\n"
23120 "out gl_PerVertex {\n"
23121 " vec4 gl_Position;\n"
23122 "};\n"
23123 "void main(){\n"
23124 " gl_Position = x[0] + x[1];\n"
23125 "}\n";
23126 char const *fsSource =
23127 "#version 450\n"
23128 "\n"
23129 "layout(location=0) out vec4 color;\n"
23130 "void main(){\n"
23131 " color = vec4(1);\n"
23132 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023133
23134 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
23135 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
23136
23137 VkPipelineObj pipe(m_device);
23138 pipe.AddColorAttachment();
23139 pipe.AddShader(&vs);
23140 pipe.AddShader(&fs);
23141
23142 pipe.AddVertexInputBindings(&input_binding, 1);
23143 pipe.AddVertexInputAttribs(input_attribs, 2);
23144
23145 VkDescriptorSetObj descriptorSet(m_device);
23146 descriptorSet.AppendDummy();
23147 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
23148
23149 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
23150
23151 /* expect success */
23152 m_errorMonitor->VerifyNotFound();
23153}
23154
23155TEST_F(VkPositiveLayerTest, CreatePipelineAttribArrayType) {
23156 m_errorMonitor->ExpectSuccess();
23157
Tony Barbour1fa09702017-03-16 12:09:08 -060023158 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023159 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
23160
23161 VkVertexInputBindingDescription input_binding;
23162 memset(&input_binding, 0, sizeof(input_binding));
23163
23164 VkVertexInputAttributeDescription input_attribs[2];
23165 memset(input_attribs, 0, sizeof(input_attribs));
23166
23167 for (int i = 0; i < 2; i++) {
23168 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
23169 input_attribs[i].location = i;
23170 }
23171
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023172 char const *vsSource =
23173 "#version 450\n"
23174 "\n"
23175 "layout(location=0) in vec4 x[2];\n"
23176 "out gl_PerVertex {\n"
23177 " vec4 gl_Position;\n"
23178 "};\n"
23179 "void main(){\n"
23180 " gl_Position = x[0] + x[1];\n"
23181 "}\n";
23182 char const *fsSource =
23183 "#version 450\n"
23184 "\n"
23185 "layout(location=0) out vec4 color;\n"
23186 "void main(){\n"
23187 " color = vec4(1);\n"
23188 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023189
23190 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
23191 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
23192
23193 VkPipelineObj pipe(m_device);
23194 pipe.AddColorAttachment();
23195 pipe.AddShader(&vs);
23196 pipe.AddShader(&fs);
23197
23198 pipe.AddVertexInputBindings(&input_binding, 1);
23199 pipe.AddVertexInputAttribs(input_attribs, 2);
23200
23201 VkDescriptorSetObj descriptorSet(m_device);
23202 descriptorSet.AppendDummy();
23203 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
23204
23205 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
23206
23207 m_errorMonitor->VerifyNotFound();
23208}
23209
23210TEST_F(VkPositiveLayerTest, CreatePipelineAttribComponents) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023211 TEST_DESCRIPTION(
23212 "Test that pipeline validation accepts consuming a vertex attribute "
23213 "through multiple vertex shader inputs, each consuming a different "
23214 "subset of the components.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023215 m_errorMonitor->ExpectSuccess();
23216
Tony Barbour1fa09702017-03-16 12:09:08 -060023217 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023218 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
23219
23220 VkVertexInputBindingDescription input_binding;
23221 memset(&input_binding, 0, sizeof(input_binding));
23222
23223 VkVertexInputAttributeDescription input_attribs[3];
23224 memset(input_attribs, 0, sizeof(input_attribs));
23225
23226 for (int i = 0; i < 3; i++) {
23227 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
23228 input_attribs[i].location = i;
23229 }
23230
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023231 char const *vsSource =
23232 "#version 450\n"
23233 "\n"
23234 "layout(location=0) in vec4 x;\n"
23235 "layout(location=1) in vec3 y1;\n"
23236 "layout(location=1, component=3) in float y2;\n"
23237 "layout(location=2) in vec4 z;\n"
23238 "out gl_PerVertex {\n"
23239 " vec4 gl_Position;\n"
23240 "};\n"
23241 "void main(){\n"
23242 " gl_Position = x + vec4(y1, y2) + z;\n"
23243 "}\n";
23244 char const *fsSource =
23245 "#version 450\n"
23246 "\n"
23247 "layout(location=0) out vec4 color;\n"
23248 "void main(){\n"
23249 " color = vec4(1);\n"
23250 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023251
23252 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
23253 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
23254
23255 VkPipelineObj pipe(m_device);
23256 pipe.AddColorAttachment();
23257 pipe.AddShader(&vs);
23258 pipe.AddShader(&fs);
23259
23260 pipe.AddVertexInputBindings(&input_binding, 1);
23261 pipe.AddVertexInputAttribs(input_attribs, 3);
23262
23263 VkDescriptorSetObj descriptorSet(m_device);
23264 descriptorSet.AppendDummy();
23265 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
23266
23267 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
23268
23269 m_errorMonitor->VerifyNotFound();
23270}
23271
23272TEST_F(VkPositiveLayerTest, CreatePipelineSimplePositive) {
23273 m_errorMonitor->ExpectSuccess();
23274
Tony Barbour1fa09702017-03-16 12:09:08 -060023275 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023276 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
23277
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023278 char const *vsSource =
23279 "#version 450\n"
23280 "out gl_PerVertex {\n"
23281 " vec4 gl_Position;\n"
23282 "};\n"
23283 "void main(){\n"
23284 " gl_Position = vec4(0);\n"
23285 "}\n";
23286 char const *fsSource =
23287 "#version 450\n"
23288 "\n"
23289 "layout(location=0) out vec4 color;\n"
23290 "void main(){\n"
23291 " color = vec4(1);\n"
23292 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023293
23294 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
23295 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
23296
23297 VkPipelineObj pipe(m_device);
23298 pipe.AddColorAttachment();
23299 pipe.AddShader(&vs);
23300 pipe.AddShader(&fs);
23301
23302 VkDescriptorSetObj descriptorSet(m_device);
23303 descriptorSet.AppendDummy();
23304 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
23305
23306 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
23307
23308 m_errorMonitor->VerifyNotFound();
23309}
23310
23311TEST_F(VkPositiveLayerTest, CreatePipelineRelaxedTypeMatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023312 TEST_DESCRIPTION(
23313 "Test that pipeline validation accepts the relaxed type matching rules "
23314 "set out in 14.1.3: fundamental type must match, and producer side must "
23315 "have at least as many components");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023316 m_errorMonitor->ExpectSuccess();
23317
23318 // VK 1.0.8 Specification, 14.1.3 "Additionally,..." block
23319
Tony Barbour1fa09702017-03-16 12:09:08 -060023320 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023321 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
23322
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023323 char const *vsSource =
23324 "#version 450\n"
23325 "out gl_PerVertex {\n"
23326 " vec4 gl_Position;\n"
23327 "};\n"
23328 "layout(location=0) out vec3 x;\n"
23329 "layout(location=1) out ivec3 y;\n"
23330 "layout(location=2) out vec3 z;\n"
23331 "void main(){\n"
23332 " gl_Position = vec4(0);\n"
23333 " x = vec3(0); y = ivec3(0); z = vec3(0);\n"
23334 "}\n";
23335 char const *fsSource =
23336 "#version 450\n"
23337 "\n"
23338 "layout(location=0) out vec4 color;\n"
23339 "layout(location=0) in float x;\n"
23340 "layout(location=1) flat in int y;\n"
23341 "layout(location=2) in vec2 z;\n"
23342 "void main(){\n"
23343 " color = vec4(1 + x + y + z.x);\n"
23344 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023345
23346 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
23347 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
23348
23349 VkPipelineObj pipe(m_device);
23350 pipe.AddColorAttachment();
23351 pipe.AddShader(&vs);
23352 pipe.AddShader(&fs);
23353
23354 VkDescriptorSetObj descriptorSet(m_device);
23355 descriptorSet.AppendDummy();
23356 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
23357
23358 VkResult err = VK_SUCCESS;
23359 err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
23360 ASSERT_VK_SUCCESS(err);
23361
23362 m_errorMonitor->VerifyNotFound();
23363}
23364
23365TEST_F(VkPositiveLayerTest, CreatePipelineTessPerVertex) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023366 TEST_DESCRIPTION(
23367 "Test that pipeline validation accepts per-vertex variables "
23368 "passed between the TCS and TES stages");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023369 m_errorMonitor->ExpectSuccess();
23370
Tony Barbour1fa09702017-03-16 12:09:08 -060023371 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023372 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
23373
23374 if (!m_device->phy().features().tessellationShader) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070023375 printf(" Device does not support tessellation shaders; skipped.\n");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023376 return;
23377 }
23378
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023379 char const *vsSource =
23380 "#version 450\n"
23381 "void main(){}\n";
23382 char const *tcsSource =
23383 "#version 450\n"
23384 "layout(location=0) out int x[];\n"
23385 "layout(vertices=3) out;\n"
23386 "void main(){\n"
23387 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
23388 " gl_TessLevelInner[0] = 1;\n"
23389 " x[gl_InvocationID] = gl_InvocationID;\n"
23390 "}\n";
23391 char const *tesSource =
23392 "#version 450\n"
23393 "layout(triangles, equal_spacing, cw) in;\n"
23394 "layout(location=0) in int x[];\n"
23395 "out gl_PerVertex { vec4 gl_Position; };\n"
23396 "void main(){\n"
23397 " gl_Position.xyz = gl_TessCoord;\n"
23398 " gl_Position.w = x[0] + x[1] + x[2];\n"
23399 "}\n";
23400 char const *fsSource =
23401 "#version 450\n"
23402 "layout(location=0) out vec4 color;\n"
23403 "void main(){\n"
23404 " color = vec4(1);\n"
23405 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023406
23407 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
23408 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
23409 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
23410 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
23411
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023412 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
23413 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023414
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023415 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023416
23417 VkPipelineObj pipe(m_device);
23418 pipe.SetInputAssembly(&iasci);
23419 pipe.SetTessellation(&tsci);
23420 pipe.AddColorAttachment();
23421 pipe.AddShader(&vs);
23422 pipe.AddShader(&tcs);
23423 pipe.AddShader(&tes);
23424 pipe.AddShader(&fs);
23425
23426 VkDescriptorSetObj descriptorSet(m_device);
23427 descriptorSet.AppendDummy();
23428 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
23429
23430 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
23431
23432 m_errorMonitor->VerifyNotFound();
23433}
23434
23435TEST_F(VkPositiveLayerTest, CreatePipelineGeometryInputBlockPositive) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023436 TEST_DESCRIPTION(
23437 "Test that pipeline validation accepts a user-defined "
23438 "interface block passed into the geometry shader. This "
23439 "is interesting because the 'extra' array level is not "
23440 "present on the member type, but on the block instance.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023441 m_errorMonitor->ExpectSuccess();
23442
Tony Barbour1fa09702017-03-16 12:09:08 -060023443 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023444 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
23445
23446 if (!m_device->phy().features().geometryShader) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070023447 printf(" Device does not support geometry shaders; skipped.\n");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023448 return;
23449 }
23450
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023451 char const *vsSource =
23452 "#version 450\n"
23453 "layout(location=0) out VertexData { vec4 x; } vs_out;\n"
23454 "void main(){\n"
23455 " vs_out.x = vec4(1);\n"
23456 "}\n";
23457 char const *gsSource =
23458 "#version 450\n"
23459 "layout(triangles) in;\n"
23460 "layout(triangle_strip, max_vertices=3) out;\n"
23461 "layout(location=0) in VertexData { vec4 x; } gs_in[];\n"
23462 "out gl_PerVertex { vec4 gl_Position; };\n"
23463 "void main() {\n"
23464 " gl_Position = gs_in[0].x;\n"
23465 " EmitVertex();\n"
23466 "}\n";
23467 char const *fsSource =
23468 "#version 450\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 gs(m_device, gsSource, VK_SHADER_STAGE_GEOMETRY_BIT, this);
23476 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
23477
23478 VkPipelineObj pipe(m_device);
23479 pipe.AddColorAttachment();
23480 pipe.AddShader(&vs);
23481 pipe.AddShader(&gs);
23482 pipe.AddShader(&fs);
23483
23484 VkDescriptorSetObj descriptorSet(m_device);
23485 descriptorSet.AppendDummy();
23486 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
23487
23488 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
23489
23490 m_errorMonitor->VerifyNotFound();
23491}
23492
23493TEST_F(VkPositiveLayerTest, CreatePipeline64BitAttributesPositive) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023494 TEST_DESCRIPTION(
23495 "Test that pipeline validation accepts basic use of 64bit vertex "
23496 "attributes. This is interesting because they consume multiple "
23497 "locations.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023498 m_errorMonitor->ExpectSuccess();
23499
Tony Barbour1fa09702017-03-16 12:09:08 -060023500 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023501 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
23502
23503 if (!m_device->phy().features().shaderFloat64) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070023504 printf(" Device does not support 64bit vertex attributes; skipped.\n");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023505 return;
23506 }
23507
23508 VkVertexInputBindingDescription input_bindings[1];
23509 memset(input_bindings, 0, sizeof(input_bindings));
23510
23511 VkVertexInputAttributeDescription input_attribs[4];
23512 memset(input_attribs, 0, sizeof(input_attribs));
23513 input_attribs[0].location = 0;
23514 input_attribs[0].offset = 0;
23515 input_attribs[0].format = VK_FORMAT_R64G64B64A64_SFLOAT;
23516 input_attribs[1].location = 2;
23517 input_attribs[1].offset = 32;
23518 input_attribs[1].format = VK_FORMAT_R64G64B64A64_SFLOAT;
23519 input_attribs[2].location = 4;
23520 input_attribs[2].offset = 64;
23521 input_attribs[2].format = VK_FORMAT_R64G64B64A64_SFLOAT;
23522 input_attribs[3].location = 6;
23523 input_attribs[3].offset = 96;
23524 input_attribs[3].format = VK_FORMAT_R64G64B64A64_SFLOAT;
23525
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023526 char const *vsSource =
23527 "#version 450\n"
23528 "\n"
23529 "layout(location=0) in dmat4 x;\n"
23530 "out gl_PerVertex {\n"
23531 " vec4 gl_Position;\n"
23532 "};\n"
23533 "void main(){\n"
23534 " gl_Position = vec4(x[0][0]);\n"
23535 "}\n";
23536 char const *fsSource =
23537 "#version 450\n"
23538 "\n"
23539 "layout(location=0) out vec4 color;\n"
23540 "void main(){\n"
23541 " color = vec4(1);\n"
23542 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023543
23544 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
23545 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
23546
23547 VkPipelineObj pipe(m_device);
23548 pipe.AddColorAttachment();
23549 pipe.AddShader(&vs);
23550 pipe.AddShader(&fs);
23551
23552 pipe.AddVertexInputBindings(input_bindings, 1);
23553 pipe.AddVertexInputAttribs(input_attribs, 4);
23554
23555 VkDescriptorSetObj descriptorSet(m_device);
23556 descriptorSet.AppendDummy();
23557 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
23558
23559 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
23560
23561 m_errorMonitor->VerifyNotFound();
23562}
23563
23564TEST_F(VkPositiveLayerTest, CreatePipelineInputAttachmentPositive) {
23565 TEST_DESCRIPTION("Positive test for a correctly matched input attachment");
23566 m_errorMonitor->ExpectSuccess();
23567
Tony Barbour1fa09702017-03-16 12:09:08 -060023568 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023569
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023570 char const *vsSource =
23571 "#version 450\n"
23572 "\n"
23573 "out gl_PerVertex {\n"
23574 " vec4 gl_Position;\n"
23575 "};\n"
23576 "void main(){\n"
23577 " gl_Position = vec4(1);\n"
23578 "}\n";
23579 char const *fsSource =
23580 "#version 450\n"
23581 "\n"
23582 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
23583 "layout(location=0) out vec4 color;\n"
23584 "void main() {\n"
23585 " color = subpassLoad(x);\n"
23586 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023587
23588 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
23589 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
23590
23591 VkPipelineObj pipe(m_device);
23592 pipe.AddShader(&vs);
23593 pipe.AddShader(&fs);
23594 pipe.AddColorAttachment();
23595 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
23596
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023597 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
23598 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023599 VkDescriptorSetLayout dsl;
23600 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
23601 ASSERT_VK_SUCCESS(err);
23602
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023603 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023604 VkPipelineLayout pl;
23605 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
23606 ASSERT_VK_SUCCESS(err);
23607
23608 VkAttachmentDescription descs[2] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023609 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
23610 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
23611 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
23612 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
23613 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 -060023614 };
23615 VkAttachmentReference color = {
23616 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
23617 };
23618 VkAttachmentReference input = {
23619 1, VK_IMAGE_LAYOUT_GENERAL,
23620 };
23621
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023622 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023623
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023624 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023625 VkRenderPass rp;
23626 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
23627 ASSERT_VK_SUCCESS(err);
23628
23629 // should be OK. would go wrong here if it's going to...
23630 pipe.CreateVKPipeline(pl, rp);
23631
23632 m_errorMonitor->VerifyNotFound();
23633
23634 vkDestroyRenderPass(m_device->device(), rp, nullptr);
23635 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
23636 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
23637}
23638
23639TEST_F(VkPositiveLayerTest, CreateComputePipelineMissingDescriptorUnusedPositive) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023640 TEST_DESCRIPTION(
23641 "Test that pipeline validation accepts a compute pipeline which declares a "
23642 "descriptor-backed resource which is not provided, but the shader does not "
23643 "statically use it. This is interesting because it requires compute pipelines "
23644 "to have a proper descriptor use walk, which they didn't for some time.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023645 m_errorMonitor->ExpectSuccess();
23646
Tony Barbour1fa09702017-03-16 12:09:08 -060023647 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023648
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023649 char const *csSource =
23650 "#version 450\n"
23651 "\n"
23652 "layout(local_size_x=1) in;\n"
23653 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
23654 "void main(){\n"
23655 " // x is not used.\n"
23656 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023657
23658 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
23659
23660 VkDescriptorSetObj descriptorSet(m_device);
23661 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
23662
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023663 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
23664 nullptr,
23665 0,
23666 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
23667 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
23668 descriptorSet.GetPipelineLayout(),
23669 VK_NULL_HANDLE,
23670 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023671
23672 VkPipeline pipe;
23673 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
23674
23675 m_errorMonitor->VerifyNotFound();
23676
23677 if (err == VK_SUCCESS) {
23678 vkDestroyPipeline(m_device->device(), pipe, nullptr);
23679 }
23680}
23681
23682TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsSampler) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023683 TEST_DESCRIPTION(
23684 "Test that pipeline validation accepts a shader consuming only the "
23685 "sampler portion of a combined image + sampler");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023686 m_errorMonitor->ExpectSuccess();
23687
Tony Barbour1fa09702017-03-16 12:09:08 -060023688 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023689
23690 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023691 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
23692 {1, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
23693 {2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023694 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023695 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023696 VkDescriptorSetLayout dsl;
23697 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
23698 ASSERT_VK_SUCCESS(err);
23699
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023700 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023701 VkPipelineLayout pl;
23702 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
23703 ASSERT_VK_SUCCESS(err);
23704
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023705 char const *csSource =
23706 "#version 450\n"
23707 "\n"
23708 "layout(local_size_x=1) in;\n"
23709 "layout(set=0, binding=0) uniform sampler s;\n"
23710 "layout(set=0, binding=1) uniform texture2D t;\n"
23711 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
23712 "void main() {\n"
23713 " x = texture(sampler2D(t, s), vec2(0));\n"
23714 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023715 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
23716
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023717 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
23718 nullptr,
23719 0,
23720 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
23721 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
23722 pl,
23723 VK_NULL_HANDLE,
23724 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023725
23726 VkPipeline pipe;
23727 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
23728
23729 m_errorMonitor->VerifyNotFound();
23730
23731 if (err == VK_SUCCESS) {
23732 vkDestroyPipeline(m_device->device(), pipe, nullptr);
23733 }
23734
23735 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
23736 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
23737}
23738
23739TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsImage) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023740 TEST_DESCRIPTION(
23741 "Test that pipeline validation accepts a shader consuming only the "
23742 "image portion of a combined image + sampler");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023743 m_errorMonitor->ExpectSuccess();
23744
Tony Barbour1fa09702017-03-16 12:09:08 -060023745 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023746
23747 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023748 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
23749 {1, VK_DESCRIPTOR_TYPE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
23750 {2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023751 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023752 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023753 VkDescriptorSetLayout dsl;
23754 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
23755 ASSERT_VK_SUCCESS(err);
23756
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023757 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023758 VkPipelineLayout pl;
23759 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
23760 ASSERT_VK_SUCCESS(err);
23761
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023762 char const *csSource =
23763 "#version 450\n"
23764 "\n"
23765 "layout(local_size_x=1) in;\n"
23766 "layout(set=0, binding=0) uniform texture2D t;\n"
23767 "layout(set=0, binding=1) uniform sampler s;\n"
23768 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
23769 "void main() {\n"
23770 " x = texture(sampler2D(t, s), vec2(0));\n"
23771 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023772 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
23773
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023774 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
23775 nullptr,
23776 0,
23777 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
23778 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
23779 pl,
23780 VK_NULL_HANDLE,
23781 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023782
23783 VkPipeline pipe;
23784 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
23785
23786 m_errorMonitor->VerifyNotFound();
23787
23788 if (err == VK_SUCCESS) {
23789 vkDestroyPipeline(m_device->device(), pipe, nullptr);
23790 }
23791
23792 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
23793 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
23794}
23795
23796TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsBoth) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023797 TEST_DESCRIPTION(
23798 "Test that pipeline validation accepts a shader consuming "
23799 "both the sampler and the image of a combined image+sampler "
23800 "but via separate variables");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023801 m_errorMonitor->ExpectSuccess();
23802
Tony Barbour1fa09702017-03-16 12:09:08 -060023803 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023804
23805 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023806 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
23807 {1, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023808 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023809 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 2, bindings};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023810 VkDescriptorSetLayout dsl;
23811 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
23812 ASSERT_VK_SUCCESS(err);
23813
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023814 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023815 VkPipelineLayout pl;
23816 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
23817 ASSERT_VK_SUCCESS(err);
23818
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023819 char const *csSource =
23820 "#version 450\n"
23821 "\n"
23822 "layout(local_size_x=1) in;\n"
23823 "layout(set=0, binding=0) uniform texture2D t;\n"
23824 "layout(set=0, binding=0) uniform sampler s; // both binding 0!\n"
23825 "layout(set=0, binding=1) buffer block { vec4 x; };\n"
23826 "void main() {\n"
23827 " x = texture(sampler2D(t, s), vec2(0));\n"
23828 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023829 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
23830
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023831 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
23832 nullptr,
23833 0,
23834 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
23835 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
23836 pl,
23837 VK_NULL_HANDLE,
23838 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023839
23840 VkPipeline pipe;
23841 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
23842
23843 m_errorMonitor->VerifyNotFound();
23844
23845 if (err == VK_SUCCESS) {
23846 vkDestroyPipeline(m_device->device(), pipe, nullptr);
23847 }
23848
23849 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
23850 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
23851}
23852
Tony Barbour3ed87a02017-03-15 16:19:02 -060023853TEST_F(VkPositiveLayerTest, Maintenance1Tests) {
Mark Lobodzinskidf784fc2017-03-14 09:18:40 -060023854 TEST_DESCRIPTION("Validate various special cases for the Maintenance1_KHR extension");
23855
Tony Barbour3ed87a02017-03-15 16:19:02 -060023856 device_extension_names.push_back(VK_KHR_MAINTENANCE1_EXTENSION_NAME);
Tony Barbour73c0f352017-03-16 15:55:38 -060023857 InitFramework(instance_layer_names, instance_extension_names, device_extension_names, myDbgFunc, m_errorMonitor);
Tony Barbour3ed87a02017-03-15 16:19:02 -060023858
Mark Lobodzinskidf784fc2017-03-14 09:18:40 -060023859 // Ensure that extension is available and enabled.
23860 uint32_t extension_count = 0;
23861 bool supports_maintenance1_extension = false;
23862 VkResult err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, nullptr);
23863 ASSERT_VK_SUCCESS(err);
23864 if (extension_count > 0) {
23865 std::vector<VkExtensionProperties> available_extensions(extension_count);
23866
23867 err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, &available_extensions[0]);
23868 ASSERT_VK_SUCCESS(err);
23869 for (const auto &extension_props : available_extensions) {
23870 if (strcmp(extension_props.extensionName, VK_KHR_MAINTENANCE1_EXTENSION_NAME) == 0) {
23871 supports_maintenance1_extension = true;
23872 }
23873 }
23874 }
23875
23876 // Proceed if extension is supported by hardware
23877 if (!supports_maintenance1_extension) {
23878 printf(" Maintenance1 Extension not supported, skipping tests\n");
23879 return;
23880 }
Mark Lobodzinskidf784fc2017-03-14 09:18:40 -060023881
23882 m_errorMonitor->ExpectSuccess();
Dave Houlton8e0fe7a2017-03-30 10:32:10 -060023883 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskidf784fc2017-03-14 09:18:40 -060023884 VkCommandBuffer cmd_buf;
23885 VkCommandBufferAllocateInfo alloc_info;
23886 alloc_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
23887 alloc_info.pNext = NULL;
23888 alloc_info.commandBufferCount = 1;
Mike Schuchardt06304c22017-03-01 17:09:09 -070023889 alloc_info.commandPool = m_commandPool->handle();
Mark Lobodzinskidf784fc2017-03-14 09:18:40 -060023890 alloc_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
23891 vkAllocateCommandBuffers(m_device->device(), &alloc_info, &cmd_buf);
23892
23893 VkCommandBufferBeginInfo cb_binfo;
23894 cb_binfo.pNext = NULL;
23895 cb_binfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
23896 cb_binfo.pInheritanceInfo = VK_NULL_HANDLE;
23897 cb_binfo.flags = 0;
23898 vkBeginCommandBuffer(cmd_buf, &cb_binfo);
23899 // Set Negative height, should give error if Maintenance 1 is not enabled
23900 VkViewport viewport = {0, 0, 16, -16, 0, 1};
23901 vkCmdSetViewport(cmd_buf, 0, 1, &viewport);
23902 vkEndCommandBuffer(cmd_buf);
23903
23904 m_errorMonitor->VerifyNotFound();
23905}
23906
Mark Lobodzinski35ecad32017-03-27 13:09:07 -060023907TEST_F(VkLayerTest, DuplicateValidPNextStructures) {
23908 TEST_DESCRIPTION("Create a pNext chain containing valid strutures, but with a duplicate structure type");
23909
23910 ASSERT_NO_FATAL_FAILURE(Init());
23911
23912 uint32_t extension_count = 0;
23913 VkResult err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, nullptr);
23914 ASSERT_VK_SUCCESS(err);
23915
23916 if (extension_count > 0) {
23917 std::vector<VkExtensionProperties> available_extensions(extension_count);
23918 err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, &available_extensions[0]);
23919 ASSERT_VK_SUCCESS(err);
23920
23921 for (const auto &extension_props : available_extensions) {
23922 if (strcmp(extension_props.extensionName, VK_NV_DEDICATED_ALLOCATION_EXTENSION_NAME) == 0) {
23923 // Create two pNext structures which by themselves would be valid
23924 VkDedicatedAllocationBufferCreateInfoNV dedicated_buffer_create_info = {};
23925 VkDedicatedAllocationBufferCreateInfoNV dedicated_buffer_create_info_2 = {};
23926 dedicated_buffer_create_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_BUFFER_CREATE_INFO_NV;
23927 dedicated_buffer_create_info.pNext = &dedicated_buffer_create_info_2;
23928 dedicated_buffer_create_info.dedicatedAllocation = VK_TRUE;
23929
23930 dedicated_buffer_create_info_2.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_BUFFER_CREATE_INFO_NV;
23931 dedicated_buffer_create_info_2.pNext = nullptr;
23932 dedicated_buffer_create_info_2.dedicatedAllocation = VK_TRUE;
23933
23934 uint32_t queue_family_index = 0;
23935 VkBufferCreateInfo buffer_create_info = {};
23936 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
23937 buffer_create_info.pNext = &dedicated_buffer_create_info;
23938 buffer_create_info.size = 1024;
23939 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
23940 buffer_create_info.queueFamilyIndexCount = 1;
23941 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
23942
23943 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "chain contains duplicate structure types");
23944 VkBuffer buffer;
23945 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
23946 m_errorMonitor->VerifyFound();
23947 }
23948 }
23949 }
23950}
23951
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023952TEST_F(VkPositiveLayerTest, ValidStructPNext) {
23953 TEST_DESCRIPTION("Verify that a valid pNext value is handled correctly");
23954
Tony Barbour1fa09702017-03-16 12:09:08 -060023955 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023956
23957 // Positive test to check parameter_validation and unique_objects support
23958 // for NV_dedicated_allocation
23959 uint32_t extension_count = 0;
23960 bool supports_nv_dedicated_allocation = false;
23961 VkResult err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, nullptr);
23962 ASSERT_VK_SUCCESS(err);
23963
23964 if (extension_count > 0) {
23965 std::vector<VkExtensionProperties> available_extensions(extension_count);
23966
23967 err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, &available_extensions[0]);
23968 ASSERT_VK_SUCCESS(err);
23969
23970 for (const auto &extension_props : available_extensions) {
23971 if (strcmp(extension_props.extensionName, VK_NV_DEDICATED_ALLOCATION_EXTENSION_NAME) == 0) {
23972 supports_nv_dedicated_allocation = true;
23973 }
23974 }
23975 }
23976
23977 if (supports_nv_dedicated_allocation) {
23978 m_errorMonitor->ExpectSuccess();
23979
23980 VkDedicatedAllocationBufferCreateInfoNV dedicated_buffer_create_info = {};
23981 dedicated_buffer_create_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_BUFFER_CREATE_INFO_NV;
23982 dedicated_buffer_create_info.pNext = nullptr;
23983 dedicated_buffer_create_info.dedicatedAllocation = VK_TRUE;
23984
23985 uint32_t queue_family_index = 0;
23986 VkBufferCreateInfo buffer_create_info = {};
23987 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
23988 buffer_create_info.pNext = &dedicated_buffer_create_info;
23989 buffer_create_info.size = 1024;
23990 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
23991 buffer_create_info.queueFamilyIndexCount = 1;
23992 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
23993
23994 VkBuffer buffer;
Karl Schultz47dd59d2017-01-20 13:19:20 -070023995 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023996 ASSERT_VK_SUCCESS(err);
23997
23998 VkMemoryRequirements memory_reqs;
23999 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
24000
24001 VkDedicatedAllocationMemoryAllocateInfoNV dedicated_memory_info = {};
24002 dedicated_memory_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_MEMORY_ALLOCATE_INFO_NV;
24003 dedicated_memory_info.pNext = nullptr;
24004 dedicated_memory_info.buffer = buffer;
24005 dedicated_memory_info.image = VK_NULL_HANDLE;
24006
24007 VkMemoryAllocateInfo memory_info = {};
24008 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
24009 memory_info.pNext = &dedicated_memory_info;
24010 memory_info.allocationSize = memory_reqs.size;
24011
24012 bool pass;
24013 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
24014 ASSERT_TRUE(pass);
24015
24016 VkDeviceMemory buffer_memory;
24017 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
24018 ASSERT_VK_SUCCESS(err);
24019
24020 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
24021 ASSERT_VK_SUCCESS(err);
24022
24023 vkDestroyBuffer(m_device->device(), buffer, NULL);
24024 vkFreeMemory(m_device->device(), buffer_memory, NULL);
24025
24026 m_errorMonitor->VerifyNotFound();
24027 }
24028}
24029
24030TEST_F(VkPositiveLayerTest, PSOPolygonModeValid) {
24031 VkResult err;
24032
24033 TEST_DESCRIPTION("Verify that using a solid polygon fill mode works correctly.");
24034
Tony Barbour1fa09702017-03-16 12:09:08 -060024035 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024036 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
24037
24038 std::vector<const char *> device_extension_names;
24039 auto features = m_device->phy().features();
24040 // Artificially disable support for non-solid fill modes
24041 features.fillModeNonSolid = false;
24042 // The sacrificial device object
24043 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
24044
24045 VkRenderpassObj render_pass(&test_device);
24046
24047 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
24048 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
24049 pipeline_layout_ci.setLayoutCount = 0;
24050 pipeline_layout_ci.pSetLayouts = NULL;
24051
24052 VkPipelineLayout pipeline_layout;
24053 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
24054 ASSERT_VK_SUCCESS(err);
24055
24056 VkPipelineRasterizationStateCreateInfo rs_ci = {};
24057 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
24058 rs_ci.pNext = nullptr;
24059 rs_ci.lineWidth = 1.0f;
24060 rs_ci.rasterizerDiscardEnable = true;
24061
24062 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
24063 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
24064
24065 // Set polygonMode=FILL. No error is expected
24066 m_errorMonitor->ExpectSuccess();
24067 {
24068 VkPipelineObj pipe(&test_device);
24069 pipe.AddShader(&vs);
24070 pipe.AddShader(&fs);
24071 pipe.AddColorAttachment();
24072 // Set polygonMode to a good value
24073 rs_ci.polygonMode = VK_POLYGON_MODE_FILL;
24074 pipe.SetRasterization(&rs_ci);
24075 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
24076 }
24077 m_errorMonitor->VerifyNotFound();
24078
24079 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
24080}
24081
Dave Houlton1150cf52017-04-27 14:38:11 -060024082TEST_F(VkPositiveLayerTest, LongSemaphoreChain) {
Chris Forbes94196952017-04-06 16:30:59 -070024083 m_errorMonitor->ExpectSuccess();
24084
24085 ASSERT_NO_FATAL_FAILURE(Init());
24086 VkResult err;
24087
24088 std::vector<VkSemaphore> semaphores;
24089
24090 const int chainLength = 32768;
24091 VkPipelineStageFlags flags = VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT;
24092
24093 for (int i = 0; i < chainLength; i++) {
Dave Houlton1150cf52017-04-27 14:38:11 -060024094 VkSemaphoreCreateInfo sci = {VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0};
Chris Forbes94196952017-04-06 16:30:59 -070024095 VkSemaphore semaphore;
24096 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &semaphore);
24097 ASSERT_VK_SUCCESS(err);
24098
24099 semaphores.push_back(semaphore);
24100
Chris Forbesfc50aaa2017-05-01 10:20:17 -070024101 VkSubmitInfo si = {VK_STRUCTURE_TYPE_SUBMIT_INFO,
24102 nullptr,
24103 semaphores.size() > 1 ? 1u : 0u,
24104 semaphores.size() > 1 ? &semaphores[semaphores.size() - 2] : nullptr,
24105 &flags,
24106 0,
24107 nullptr,
24108 1,
24109 &semaphores[semaphores.size() - 1]};
Chris Forbes94196952017-04-06 16:30:59 -070024110 err = vkQueueSubmit(m_device->m_queue, 1, &si, VK_NULL_HANDLE);
24111 ASSERT_VK_SUCCESS(err);
24112 }
24113
Dave Houlton1150cf52017-04-27 14:38:11 -060024114 VkFenceCreateInfo fci = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0};
Chris Forbes94196952017-04-06 16:30:59 -070024115 VkFence fence;
24116 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
24117 ASSERT_VK_SUCCESS(err);
Dave Houlton1150cf52017-04-27 14:38:11 -060024118 VkSubmitInfo si = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 1, &semaphores.back(), &flags, 0, nullptr, 0, nullptr};
Chris Forbes94196952017-04-06 16:30:59 -070024119 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
24120 ASSERT_VK_SUCCESS(err);
24121
24122 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
24123
Dave Houlton1150cf52017-04-27 14:38:11 -060024124 for (auto semaphore : semaphores) vkDestroySemaphore(m_device->device(), semaphore, nullptr);
Chris Forbes94196952017-04-06 16:30:59 -070024125
24126 vkDestroyFence(m_device->device(), fence, nullptr);
24127
24128 m_errorMonitor->VerifyNotFound();
24129}
24130
Mike Stroyanca855662017-05-02 11:06:27 -060024131extern "C" void *ReleaseNullFence(void *arg) {
24132 struct thread_data_struct *data = (struct thread_data_struct *)arg;
24133
24134 for (int i = 0; i < 40000; i++) {
24135 vkDestroyFence(data->device, VK_NULL_HANDLE, NULL);
24136 if (data->bailout) {
24137 break;
24138 }
24139 }
24140 return NULL;
24141}
24142
24143TEST_F(VkPositiveLayerTest, ThreadNullFenceCollision) {
24144 test_platform_thread thread;
24145
24146 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "THREADING ERROR");
24147
24148 ASSERT_NO_FATAL_FAILURE(Init());
24149
24150 struct thread_data_struct data;
24151 data.device = m_device->device();
24152 data.bailout = false;
24153 m_errorMonitor->SetBailout(&data.bailout);
24154
24155 // Call vkDestroyFence of VK_NULL_HANDLE repeatedly using multiple threads.
24156 // There should be no validation error from collision of that non-object.
24157 test_platform_thread_create(&thread, ReleaseNullFence, (void *)&data);
24158 for (int i = 0; i < 40000; i++) {
24159 vkDestroyFence(m_device->device(), VK_NULL_HANDLE, NULL);
24160 }
24161 test_platform_thread_join(thread, NULL);
24162
24163 m_errorMonitor->SetBailout(NULL);
24164
24165 m_errorMonitor->VerifyNotFound();
24166}
24167
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070024168#if 0 // A few devices have issues with this test so disabling for now
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024169TEST_F(VkPositiveLayerTest, LongFenceChain)
24170{
24171 m_errorMonitor->ExpectSuccess();
24172
Tony Barbour1fa09702017-03-16 12:09:08 -060024173 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024174 VkResult err;
24175
24176 std::vector<VkFence> fences;
24177
24178 const int chainLength = 32768;
24179
24180 for (int i = 0; i < chainLength; i++) {
24181 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
24182 VkFence fence;
24183 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
24184 ASSERT_VK_SUCCESS(err);
24185
24186 fences.push_back(fence);
24187
24188 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr,
24189 0, nullptr, 0, nullptr };
24190 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
24191 ASSERT_VK_SUCCESS(err);
24192
24193 }
24194
24195 // BOOM, stack overflow.
24196 vkWaitForFences(m_device->device(), 1, &fences.back(), VK_TRUE, UINT64_MAX);
24197
24198 for (auto fence : fences)
24199 vkDestroyFence(m_device->device(), fence, nullptr);
24200
24201 m_errorMonitor->VerifyNotFound();
24202}
24203#endif
24204
Cody Northrop1242dfd2016-07-13 17:24:59 -060024205#if defined(ANDROID) && defined(VALIDATION_APK)
Cody Northropb94529f2017-04-05 13:05:51 -060024206const char *appTag = "VulkanLayerValidationTests";
Cody Northrop1242dfd2016-07-13 17:24:59 -060024207static bool initialized = false;
24208static bool active = false;
24209
24210// Convert Intents to argv
24211// Ported from Hologram sample, only difference is flexible key
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024212std::vector<std::string> get_args(android_app &app, const char *intent_extra_data_key) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060024213 std::vector<std::string> args;
24214 JavaVM &vm = *app.activity->vm;
24215 JNIEnv *p_env;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070024216 if (vm.AttachCurrentThread(&p_env, nullptr) != JNI_OK) return args;
Cody Northrop1242dfd2016-07-13 17:24:59 -060024217
24218 JNIEnv &env = *p_env;
24219 jobject activity = app.activity->clazz;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024220 jmethodID get_intent_method = env.GetMethodID(env.GetObjectClass(activity), "getIntent", "()Landroid/content/Intent;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060024221 jobject intent = env.CallObjectMethod(activity, get_intent_method);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024222 jmethodID get_string_extra_method =
24223 env.GetMethodID(env.GetObjectClass(intent), "getStringExtra", "(Ljava/lang/String;)Ljava/lang/String;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060024224 jvalue get_string_extra_args;
24225 get_string_extra_args.l = env.NewStringUTF(intent_extra_data_key);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024226 jstring extra_str = static_cast<jstring>(env.CallObjectMethodA(intent, get_string_extra_method, &get_string_extra_args));
Cody Northrop1242dfd2016-07-13 17:24:59 -060024227
24228 std::string args_str;
24229 if (extra_str) {
24230 const char *extra_utf = env.GetStringUTFChars(extra_str, nullptr);
24231 args_str = extra_utf;
24232 env.ReleaseStringUTFChars(extra_str, extra_utf);
24233 env.DeleteLocalRef(extra_str);
24234 }
24235
24236 env.DeleteLocalRef(get_string_extra_args.l);
24237 env.DeleteLocalRef(intent);
24238 vm.DetachCurrentThread();
24239
24240 // split args_str
24241 std::stringstream ss(args_str);
24242 std::string arg;
24243 while (std::getline(ss, arg, ' ')) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070024244 if (!arg.empty()) args.push_back(arg);
Cody Northrop1242dfd2016-07-13 17:24:59 -060024245 }
24246
24247 return args;
24248}
24249
Dave Houlton11dcd5e2017-04-25 16:00:10 -060024250void addFullTestCommentIfPresent(const ::testing::TestInfo &test_info, std::string &error_message) {
24251 const char *const type_param = test_info.type_param();
24252 const char *const value_param = test_info.value_param();
Cody Northropb94529f2017-04-05 13:05:51 -060024253
24254 if (type_param != NULL || value_param != NULL) {
24255 error_message.append(", where ");
24256 if (type_param != NULL) {
Dave Houlton11dcd5e2017-04-25 16:00:10 -060024257 error_message.append("TypeParam = ").append(type_param);
24258 if (value_param != NULL) error_message.append(" and ");
Cody Northropb94529f2017-04-05 13:05:51 -060024259 }
24260 if (value_param != NULL) {
24261 error_message.append("GetParam() = ").append(value_param);
24262 }
24263 }
24264}
24265
24266// Inspired by https://github.com/google/googletest/blob/master/googletest/docs/AdvancedGuide.md
24267class LogcatPrinter : public ::testing::EmptyTestEventListener {
24268 // Called before a test starts.
Dave Houlton11dcd5e2017-04-25 16:00:10 -060024269 virtual void OnTestStart(const ::testing::TestInfo &test_info) {
Cody Northropb94529f2017-04-05 13:05:51 -060024270 __android_log_print(ANDROID_LOG_INFO, appTag, "[ RUN ] %s.%s", test_info.test_case_name(), test_info.name());
24271 }
24272
24273 // Called after a failed assertion or a SUCCEED() invocation.
Dave Houlton11dcd5e2017-04-25 16:00:10 -060024274 virtual void OnTestPartResult(const ::testing::TestPartResult &result) {
Cody Northropb94529f2017-04-05 13:05:51 -060024275 // If the test part succeeded, we don't need to do anything.
Dave Houlton11dcd5e2017-04-25 16:00:10 -060024276 if (result.type() == ::testing::TestPartResult::kSuccess) return;
Cody Northropb94529f2017-04-05 13:05:51 -060024277
Dave Houlton11dcd5e2017-04-25 16:00:10 -060024278 __android_log_print(ANDROID_LOG_INFO, appTag, "%s in %s:%d %s", result.failed() ? "*** Failure" : "Success",
24279 result.file_name(), result.line_number(), result.summary());
Cody Northropb94529f2017-04-05 13:05:51 -060024280 }
24281
24282 // Called after a test ends.
Dave Houlton11dcd5e2017-04-25 16:00:10 -060024283 virtual void OnTestEnd(const ::testing::TestInfo &info) {
Cody Northropb94529f2017-04-05 13:05:51 -060024284 std::string result;
24285 if (info.result()->Passed()) {
24286 result.append("[ OK ]");
24287 } else {
24288 result.append("[ FAILED ]");
24289 }
24290 result.append(info.test_case_name()).append(".").append(info.name());
Dave Houlton11dcd5e2017-04-25 16:00:10 -060024291 if (info.result()->Failed()) addFullTestCommentIfPresent(info, result);
Cody Northropb94529f2017-04-05 13:05:51 -060024292
24293 if (::testing::GTEST_FLAG(print_time)) {
24294 std::ostringstream os;
24295 os << info.result()->elapsed_time();
24296 result.append(" (").append(os.str()).append(" ms)");
24297 }
24298
24299 __android_log_print(ANDROID_LOG_INFO, appTag, "%s", result.c_str());
24300 };
24301};
24302
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024303static int32_t processInput(struct android_app *app, AInputEvent *event) { return 0; }
Cody Northrop1242dfd2016-07-13 17:24:59 -060024304
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024305static void processCommand(struct android_app *app, int32_t cmd) {
24306 switch (cmd) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070024307 case APP_CMD_INIT_WINDOW: {
24308 if (app->window) {
24309 initialized = true;
24310 }
24311 break;
Cody Northrop1242dfd2016-07-13 17:24:59 -060024312 }
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070024313 case APP_CMD_GAINED_FOCUS: {
24314 active = true;
24315 break;
24316 }
24317 case APP_CMD_LOST_FOCUS: {
24318 active = false;
24319 break;
24320 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060024321 }
24322}
24323
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024324void android_main(struct android_app *app) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060024325 app_dummy();
24326
Cody Northrop1242dfd2016-07-13 17:24:59 -060024327 int vulkanSupport = InitVulkan();
24328 if (vulkanSupport == 0) {
24329 __android_log_print(ANDROID_LOG_INFO, appTag, "==== FAILED ==== No Vulkan support found");
24330 return;
24331 }
24332
24333 app->onAppCmd = processCommand;
24334 app->onInputEvent = processInput;
24335
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024336 while (1) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060024337 int events;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024338 struct android_poll_source *source;
24339 while (ALooper_pollAll(active ? 0 : -1, NULL, &events, (void **)&source) >= 0) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060024340 if (source) {
24341 source->process(app, source);
24342 }
24343
24344 if (app->destroyRequested != 0) {
24345 VkTestFramework::Finish();
24346 return;
24347 }
24348 }
24349
24350 if (initialized && active) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024351 // Use the following key to send arguments to gtest, i.e.
24352 // --es args "--gtest_filter=-VkLayerTest.foo"
24353 const char key[] = "args";
24354 std::vector<std::string> args = get_args(*app, key);
Cody Northrop1242dfd2016-07-13 17:24:59 -060024355
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024356 std::string filter = "";
24357 if (args.size() > 0) {
24358 __android_log_print(ANDROID_LOG_INFO, appTag, "Intent args = %s", args[0].c_str());
24359 filter += args[0];
24360 } else {
24361 __android_log_print(ANDROID_LOG_INFO, appTag, "No Intent args detected");
24362 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060024363
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024364 int argc = 2;
24365 char *argv[] = {(char *)"foo", (char *)filter.c_str()};
24366 __android_log_print(ANDROID_LOG_DEBUG, appTag, "filter = %s", argv[1]);
Cody Northrop1242dfd2016-07-13 17:24:59 -060024367
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024368 // Route output to files until we can override the gtest output
24369 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/out.txt", "w", stdout);
24370 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/err.txt", "w", stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060024371
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024372 ::testing::InitGoogleTest(&argc, argv);
Cody Northropb94529f2017-04-05 13:05:51 -060024373
Dave Houlton11dcd5e2017-04-25 16:00:10 -060024374 ::testing::TestEventListeners &listeners = ::testing::UnitTest::GetInstance()->listeners();
Cody Northropb94529f2017-04-05 13:05:51 -060024375 listeners.Append(new LogcatPrinter);
24376
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024377 VkTestFramework::InitArgs(&argc, argv);
24378 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Cody Northrop1242dfd2016-07-13 17:24:59 -060024379
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024380 int result = RUN_ALL_TESTS();
Cody Northrop1242dfd2016-07-13 17:24:59 -060024381
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024382 if (result != 0) {
24383 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests FAILED ====");
24384 } else {
24385 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests PASSED ====");
24386 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060024387
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024388 VkTestFramework::Finish();
Cody Northrop1242dfd2016-07-13 17:24:59 -060024389
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024390 fclose(stdout);
24391 fclose(stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060024392
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024393 ANativeActivity_finish(app->activity);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024394 return;
Cody Northrop1242dfd2016-07-13 17:24:59 -060024395 }
24396 }
24397}
24398#endif
24399
Tony Barbour300a6082015-04-07 13:44:53 -060024400int main(int argc, char **argv) {
24401 int result;
24402
Cody Northrop8e54a402016-03-08 22:25:52 -070024403#ifdef ANDROID
24404 int vulkanSupport = InitVulkan();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070024405 if (vulkanSupport == 0) return 1;
Cody Northrop8e54a402016-03-08 22:25:52 -070024406#endif
24407
Tony Barbour300a6082015-04-07 13:44:53 -060024408 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -060024409 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour300a6082015-04-07 13:44:53 -060024410
24411 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
24412
24413 result = RUN_ALL_TESTS();
24414
Tony Barbour6918cd52015-04-09 12:58:51 -060024415 VkTestFramework::Finish();
Tony Barbour300a6082015-04-07 13:44:53 -060024416 return result;
24417}