blob: 054ffe4c72ed67b8318e8ddfe234e5094c4b83dd [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
Chris Forbes05054022017-05-17 16:29:06 -07001138 features.fillModeNonSolid = VK_FALSE;
Cortd889ff92016-07-27 09:51:27 -07001139 // 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;
Chris Forbes05054022017-05-17 16:29:06 -07001157 rs_ci.rasterizerDiscardEnable = VK_TRUE;
Cortd889ff92016-07-27 09:51:27 -07001158
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
Chris Forbes9480ae92017-05-17 17:14:34 -07007546TEST_F(VkLayerTest, SecondaryCommandBufferRerecorded) {
7547 ASSERT_NO_FATAL_FAILURE(Init());
7548
7549 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dummy");
7550
7551 // A pool we can reset in.
7552 VkCommandPoolObj pool(m_device, m_device->graphics_queue_node_index_,
7553 VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT);
7554 VkCommandBufferObj secondary(m_device, &pool,
7555 VK_COMMAND_BUFFER_LEVEL_SECONDARY);
7556
7557 secondary.begin();
7558 secondary.end();
7559
7560 m_commandBuffer->begin();
7561 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary.handle());
7562
7563 // rerecording of secondary
7564 secondary.reset(); // masks our ability to catch this!
7565 secondary.begin();
7566 secondary.end();
7567
7568 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary.handle());
7569 m_commandBuffer->end();
7570
7571 // submit
7572 m_commandBuffer->QueueCommandBuffer(false);
7573 m_errorMonitor->VerifyFound();
7574}
7575
Karl Schultz6addd812016-02-02 17:17:23 -07007576TEST_F(VkLayerTest, CommandBufferResetErrors) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007577 // Cause error due to Begin while recording CB
7578 // Then cause 2 errors for attempting to reset CB w/o having
7579 // VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT set for the pool from
7580 // which CBs were allocated. Note that this bit is off by default.
Mike Weiblencce7ec72016-10-17 19:33:05 -06007581 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call Begin on command buffer");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007582
Tony Barbour1fa09702017-03-16 12:09:08 -06007583 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007584
7585 // Calls AllocateCommandBuffers
7586 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
7587
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07007588 // Force the failure by setting the Renderpass and Framebuffer fields with (fake) data
Jon Ashburnf19916e2016-01-11 13:12:43 -07007589 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07007590 cmd_buf_hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
7591 VkCommandBufferBeginInfo cmd_buf_info = {};
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007592 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
7593 cmd_buf_info.pNext = NULL;
7594 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007595 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007596
7597 // Begin CB to transition to recording state
7598 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
7599 // Can't re-begin. This should trigger error
7600 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007601 m_errorMonitor->VerifyFound();
7602
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07007603 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00093);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007604 VkCommandBufferResetFlags flags = 0; // Don't care about flags for this test
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007605 // Reset attempt will trigger error due to incorrect CommandPool state
7606 vkResetCommandBuffer(commandBuffer.GetBufferHandle(), flags);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007607 m_errorMonitor->VerifyFound();
7608
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07007609 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00105);
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007610 // Transition CB to RECORDED state
7611 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
7612 // Now attempting to Begin will implicitly reset, which triggers error
7613 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007614 m_errorMonitor->VerifyFound();
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007615}
7616
Karl Schultz6addd812016-02-02 17:17:23 -07007617TEST_F(VkLayerTest, InvalidPipelineCreateState) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007618 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07007619 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007620
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07007621 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7622 "Invalid Pipeline CreateInfo State: Vertex Shader required");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007623
Tony Barbour1fa09702017-03-16 12:09:08 -06007624 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06007625 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06007626
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007627 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007628 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7629 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06007630
7631 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007632 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7633 ds_pool_ci.pNext = NULL;
7634 ds_pool_ci.maxSets = 1;
7635 ds_pool_ci.poolSizeCount = 1;
7636 ds_pool_ci.pPoolSizes = &ds_type_count;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06007637
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007638 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007639 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007640 ASSERT_VK_SUCCESS(err);
7641
Tony Barboureb254902015-07-15 12:50:33 -06007642 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007643 dsl_binding.binding = 0;
7644 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7645 dsl_binding.descriptorCount = 1;
7646 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7647 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007648
Tony Barboureb254902015-07-15 12:50:33 -06007649 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007650 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7651 ds_layout_ci.pNext = NULL;
7652 ds_layout_ci.bindingCount = 1;
7653 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06007654
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007655 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007656 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007657 ASSERT_VK_SUCCESS(err);
7658
7659 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007660 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007661 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007662 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007663 alloc_info.descriptorPool = ds_pool;
7664 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007665 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007666 ASSERT_VK_SUCCESS(err);
7667
Tony Barboureb254902015-07-15 12:50:33 -06007668 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007669 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7670 pipeline_layout_ci.setLayoutCount = 1;
7671 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007672
7673 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007674 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007675 ASSERT_VK_SUCCESS(err);
7676
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007677 VkViewport vp = {}; // Just need dummy vp to point to
7678 VkRect2D sc = {}; // dummy scissor to point to
Tobin Ehlise68360f2015-10-01 11:15:13 -06007679
7680 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007681 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7682 vp_state_ci.scissorCount = 1;
7683 vp_state_ci.pScissors = &sc;
7684 vp_state_ci.viewportCount = 1;
7685 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007686
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007687 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7688 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7689 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7690 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7691 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7692 rs_state_ci.depthClampEnable = VK_FALSE;
Rene Lindsayae4977b2017-01-23 14:55:54 -07007693 rs_state_ci.rasterizerDiscardEnable = VK_TRUE;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007694 rs_state_ci.depthBiasEnable = VK_FALSE;
Rene Lindsayae4977b2017-01-23 14:55:54 -07007695 rs_state_ci.lineWidth = 1.0f;
7696
7697 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7698 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7699 vi_ci.pNext = nullptr;
7700 vi_ci.vertexBindingDescriptionCount = 0;
7701 vi_ci.pVertexBindingDescriptions = nullptr;
7702 vi_ci.vertexAttributeDescriptionCount = 0;
7703 vi_ci.pVertexAttributeDescriptions = nullptr;
7704
7705 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7706 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7707 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7708
7709 VkPipelineShaderStageCreateInfo shaderStages[2];
7710 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7711
7712 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7713 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Dave Houlton59a20702017-02-02 17:26:23 -07007714 shaderStages[0] = fs.GetStageCreateInfo(); // should be: vs.GetStageCreateInfo();
Rene Lindsayae4977b2017-01-23 14:55:54 -07007715 shaderStages[1] = fs.GetStageCreateInfo();
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007716
Tony Barboureb254902015-07-15 12:50:33 -06007717 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007718 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7719 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007720 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007721 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7722 gp_ci.layout = pipeline_layout;
7723 gp_ci.renderPass = renderPass();
Rene Lindsayae4977b2017-01-23 14:55:54 -07007724 gp_ci.pVertexInputState = &vi_ci;
7725 gp_ci.pInputAssemblyState = &ia_ci;
7726
7727 gp_ci.stageCount = 1;
7728 gp_ci.pStages = shaderStages;
Tony Barboureb254902015-07-15 12:50:33 -06007729
7730 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007731 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7732 pc_ci.initialDataSize = 0;
7733 pc_ci.pInitialData = 0;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007734
7735 VkPipeline pipeline;
Jon Ashburnc669cc62015-07-09 15:02:25 -06007736 VkPipelineCache pipelineCache;
7737
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007738 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Jon Ashburnc669cc62015-07-09 15:02:25 -06007739 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007740 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007741 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007742
Chia-I Wuf7458c52015-10-26 21:10:41 +08007743 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7744 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7745 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7746 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007747}
Rene Lindsayae4977b2017-01-23 14:55:54 -07007748
Tobin Ehlis912df022015-09-17 08:46:18 -06007749/*// TODO : This test should be good, but needs Tess support in compiler to run
7750TEST_F(VkLayerTest, InvalidPatchControlPoints)
7751{
7752 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis912df022015-09-17 08:46:18 -06007753 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007754
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07007755 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07007756 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH
7757primitive ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007758
Tony Barbour1fa09702017-03-16 12:09:08 -06007759 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis912df022015-09-17 08:46:18 -06007760 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis912df022015-09-17 08:46:18 -06007761
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007762 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis912df022015-09-17 08:46:18 -06007763 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007764 ds_type_count.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007765
7766 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7767 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7768 ds_pool_ci.pNext = NULL;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007769 ds_pool_ci.poolSizeCount = 1;
7770 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis912df022015-09-17 08:46:18 -06007771
7772 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07007773 err = vkCreateDescriptorPool(m_device->device(),
7774VK_DESCRIPTOR_POOL_USAGE_NON_FREE, 1, &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis912df022015-09-17 08:46:18 -06007775 ASSERT_VK_SUCCESS(err);
7776
7777 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08007778 dsl_binding.binding = 0;
Tobin Ehlis912df022015-09-17 08:46:18 -06007779 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08007780 dsl_binding.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007781 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7782 dsl_binding.pImmutableSamplers = NULL;
7783
7784 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007785 ds_layout_ci.sType =
7786VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06007787 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007788 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07007789 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis912df022015-09-17 08:46:18 -06007790
7791 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007792 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
7793&ds_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06007794 ASSERT_VK_SUCCESS(err);
7795
7796 VkDescriptorSet descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07007797 err = vkAllocateDescriptorSets(m_device->device(), ds_pool,
7798VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet);
Tobin Ehlis912df022015-09-17 08:46:18 -06007799 ASSERT_VK_SUCCESS(err);
7800
7801 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007802 pipeline_layout_ci.sType =
7803VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06007804 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007805 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007806 pipeline_layout_ci.pSetLayouts = &ds_layout;
7807
7808 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007809 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
7810&pipeline_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06007811 ASSERT_VK_SUCCESS(err);
7812
7813 VkPipelineShaderStageCreateInfo shaderStages[3];
7814 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
7815
Karl Schultz6addd812016-02-02 17:17:23 -07007816 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT,
7817this);
Tobin Ehlis912df022015-09-17 08:46:18 -06007818 // Just using VS txt for Tess shaders as we don't care about functionality
Karl Schultz6addd812016-02-02 17:17:23 -07007819 VkShaderObj
7820tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
7821this);
7822 VkShaderObj
7823te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT,
7824this);
Tobin Ehlis912df022015-09-17 08:46:18 -06007825
Karl Schultz6addd812016-02-02 17:17:23 -07007826 shaderStages[0].sType =
7827VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007828 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007829 shaderStages[0].shader = vs.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07007830 shaderStages[1].sType =
7831VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007832 shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007833 shaderStages[1].shader = tc.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07007834 shaderStages[2].sType =
7835VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007836 shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007837 shaderStages[2].shader = te.handle();
7838
7839 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007840 iaCI.sType =
7841VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Chia-I Wu515eb8f2015-10-31 00:31:16 +08007842 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST;
Tobin Ehlis912df022015-09-17 08:46:18 -06007843
7844 VkPipelineTessellationStateCreateInfo tsCI = {};
7845 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
7846 tsCI.patchControlPoints = 0; // This will cause an error
7847
7848 VkGraphicsPipelineCreateInfo gp_ci = {};
7849 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7850 gp_ci.pNext = NULL;
7851 gp_ci.stageCount = 3;
7852 gp_ci.pStages = shaderStages;
7853 gp_ci.pVertexInputState = NULL;
7854 gp_ci.pInputAssemblyState = &iaCI;
7855 gp_ci.pTessellationState = &tsCI;
7856 gp_ci.pViewportState = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007857 gp_ci.pRasterizationState = NULL;
Tobin Ehlis912df022015-09-17 08:46:18 -06007858 gp_ci.pMultisampleState = NULL;
7859 gp_ci.pDepthStencilState = NULL;
7860 gp_ci.pColorBlendState = NULL;
7861 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7862 gp_ci.layout = pipeline_layout;
7863 gp_ci.renderPass = renderPass();
7864
7865 VkPipelineCacheCreateInfo pc_ci = {};
7866 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7867 pc_ci.pNext = NULL;
7868 pc_ci.initialSize = 0;
7869 pc_ci.initialData = 0;
7870 pc_ci.maxSize = 0;
7871
7872 VkPipeline pipeline;
7873 VkPipelineCache pipelineCache;
7874
Karl Schultz6addd812016-02-02 17:17:23 -07007875 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL,
7876&pipelineCache);
Tobin Ehlis912df022015-09-17 08:46:18 -06007877 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07007878 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
7879&gp_ci, NULL, &pipeline);
Tobin Ehlis912df022015-09-17 08:46:18 -06007880
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007881 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007882
Chia-I Wuf7458c52015-10-26 21:10:41 +08007883 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7884 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7885 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7886 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis912df022015-09-17 08:46:18 -06007887}
7888*/
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007889
Mark Lobodzinski510aa5c2016-12-19 07:59:10 -07007890TEST_F(VkLayerTest, PSOViewportScissorCountTests) {
Karl Schultz6addd812016-02-02 17:17:23 -07007891 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007892
Mark Lobodzinski510aa5c2016-12-19 07:59:10 -07007893 TEST_DESCRIPTION("Test various cases of viewport and scissor count validation");
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007894
Tony Barbour1fa09702017-03-16 12:09:08 -06007895 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007896 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007897
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007898 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007899 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7900 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007901
7902 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007903 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7904 ds_pool_ci.maxSets = 1;
7905 ds_pool_ci.poolSizeCount = 1;
7906 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007907
7908 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007909 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007910 ASSERT_VK_SUCCESS(err);
7911
7912 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007913 dsl_binding.binding = 0;
7914 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7915 dsl_binding.descriptorCount = 1;
7916 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007917
7918 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007919 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7920 ds_layout_ci.bindingCount = 1;
7921 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007922
7923 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007924 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007925 ASSERT_VK_SUCCESS(err);
7926
7927 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007928 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007929 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007930 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007931 alloc_info.descriptorPool = ds_pool;
7932 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007933 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007934 ASSERT_VK_SUCCESS(err);
7935
7936 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007937 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7938 pipeline_layout_ci.setLayoutCount = 1;
7939 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007940
7941 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007942 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007943 ASSERT_VK_SUCCESS(err);
7944
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007945 VkViewport vp = {};
Tobin Ehlise68360f2015-10-01 11:15:13 -06007946 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007947 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
Mark Lobodzinski510aa5c2016-12-19 07:59:10 -07007948 vp_state_ci.scissorCount = 1;
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007949 vp_state_ci.viewportCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -07007950 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007951
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007952 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7953 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7954 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7955 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7956 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7957 rs_state_ci.depthClampEnable = VK_FALSE;
7958 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
7959 rs_state_ci.depthBiasEnable = VK_FALSE;
7960
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007961 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7962 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7963 vi_ci.pNext = nullptr;
7964 vi_ci.vertexBindingDescriptionCount = 0;
7965 vi_ci.pVertexBindingDescriptions = nullptr;
7966 vi_ci.vertexAttributeDescriptionCount = 0;
7967 vi_ci.pVertexAttributeDescriptions = nullptr;
7968
7969 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7970 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7971 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7972
7973 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
7974 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
7975 pipe_ms_state_ci.pNext = NULL;
7976 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
7977 pipe_ms_state_ci.sampleShadingEnable = 0;
7978 pipe_ms_state_ci.minSampleShading = 1.0;
7979 pipe_ms_state_ci.pSampleMask = NULL;
7980
Cody Northropeb3a6c12015-10-05 14:44:45 -06007981 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007982 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007983
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007984 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07007985 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chia-I Wu28e06912015-10-31 00:31:16 +08007986 shaderStages[0] = vs.GetStageCreateInfo();
7987 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007988
7989 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007990 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7991 gp_ci.stageCount = 2;
7992 gp_ci.pStages = shaderStages;
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007993 gp_ci.pVertexInputState = &vi_ci;
7994 gp_ci.pInputAssemblyState = &ia_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007995 gp_ci.pViewportState = &vp_state_ci;
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007996 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007997 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007998 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7999 gp_ci.layout = pipeline_layout;
8000 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06008001
8002 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008003 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008004
8005 VkPipeline pipeline;
8006 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008007 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008008 ASSERT_VK_SUCCESS(err);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008009
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07008010 if (!m_device->phy().features().multiViewport) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07008011 printf(" MultiViewport feature is disabled -- skipping enabled-state checks.\n");
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07008012
8013 // Check case where multiViewport is disabled and viewport count is not 1
8014 // We check scissor/viewport simultaneously since separating them would trigger the mismatch error, 1434.
8015 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01430);
8016 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01431);
8017 vp_state_ci.scissorCount = 0;
8018 vp_state_ci.viewportCount = 0;
8019 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
8020 m_errorMonitor->VerifyFound();
8021 } else {
8022 if (m_device->props.limits.maxViewports == 1) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07008023 printf(" Device limit maxViewports is 1, skipping tests that require higher limits.\n");
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07008024 } else {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07008025 printf(" MultiViewport feature is enabled -- skipping disabled-state checks.\n");
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07008026
8027 // Check is that viewportcount and scissorcount match
8028 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01434);
8029 vp_state_ci.scissorCount = 1;
8030 vp_state_ci.viewportCount = m_device->props.limits.maxViewports;
8031 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
8032 m_errorMonitor->VerifyFound();
8033
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07008034 // Check case where multiViewport is enabled and viewport count is greater than max
8035 // We check scissor/viewport simultaneously since separating them would trigger the mismatch error, 1434.
8036 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01432);
8037 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01433);
8038 vp_state_ci.scissorCount = m_device->props.limits.maxViewports + 1;
8039 vp_state_ci.viewportCount = m_device->props.limits.maxViewports + 1;
8040 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
8041 m_errorMonitor->VerifyFound();
8042 }
8043 }
Tobin Ehlise68360f2015-10-01 11:15:13 -06008044
Chia-I Wuf7458c52015-10-26 21:10:41 +08008045 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
8046 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8047 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8048 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008049}
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07008050
8051// 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
8052// set dynamically.
Karl Schultz6addd812016-02-02 17:17:23 -07008053TEST_F(VkLayerTest, PSOViewportStateNotSet) {
Karl Schultz6addd812016-02-02 17:17:23 -07008054 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008055
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07008056 TEST_DESCRIPTION("Create a graphics pipeline with rasterization enabled but no viewport state.");
8057
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07008058 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02113);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008059
Tony Barbour1fa09702017-03-16 12:09:08 -06008060 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlise68360f2015-10-01 11:15:13 -06008061 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06008062
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008063 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008064 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8065 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008066
8067 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008068 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8069 ds_pool_ci.maxSets = 1;
8070 ds_pool_ci.poolSizeCount = 1;
8071 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008072
8073 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008074 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008075 ASSERT_VK_SUCCESS(err);
8076
8077 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008078 dsl_binding.binding = 0;
8079 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8080 dsl_binding.descriptorCount = 1;
8081 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008082
8083 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008084 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8085 ds_layout_ci.bindingCount = 1;
8086 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008087
8088 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008089 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008090 ASSERT_VK_SUCCESS(err);
8091
8092 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008093 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008094 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008095 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008096 alloc_info.descriptorPool = ds_pool;
8097 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008098 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008099 ASSERT_VK_SUCCESS(err);
8100
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07008101 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
8102 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
8103 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
8104
8105 VkPipelineVertexInputStateCreateInfo vi_ci = {};
8106 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
8107 vi_ci.pNext = nullptr;
8108 vi_ci.vertexBindingDescriptionCount = 0;
8109 vi_ci.pVertexBindingDescriptions = nullptr;
8110 vi_ci.vertexAttributeDescriptionCount = 0;
8111 vi_ci.pVertexAttributeDescriptions = nullptr;
8112
8113 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
8114 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
8115 pipe_ms_state_ci.pNext = NULL;
8116 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
8117 pipe_ms_state_ci.sampleShadingEnable = 0;
8118 pipe_ms_state_ci.minSampleShading = 1.0;
8119 pipe_ms_state_ci.pSampleMask = NULL;
8120
Tobin Ehlise68360f2015-10-01 11:15:13 -06008121 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008122 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8123 pipeline_layout_ci.setLayoutCount = 1;
8124 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008125
8126 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008127 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008128 ASSERT_VK_SUCCESS(err);
8129
8130 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
8131 // Set scissor as dynamic to avoid second error
8132 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008133 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
8134 dyn_state_ci.dynamicStateCount = 1;
8135 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008136
Cody Northropeb3a6c12015-10-05 14:44:45 -06008137 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07008138 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06008139
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008140 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07008141 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
8142 // 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 +08008143 shaderStages[0] = vs.GetStageCreateInfo();
8144 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06008145
Karl Schultzdfdb8d42016-03-08 10:30:21 -07008146 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
8147 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
8148 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
8149 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
8150 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
8151 rs_state_ci.depthClampEnable = VK_FALSE;
8152 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
8153 rs_state_ci.depthBiasEnable = VK_FALSE;
8154
Tobin Ehlise68360f2015-10-01 11:15:13 -06008155 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008156 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8157 gp_ci.stageCount = 2;
8158 gp_ci.pStages = shaderStages;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07008159 gp_ci.pRasterizationState = &rs_state_ci;
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07008160 // Not setting VP state w/o dynamic vp state should cause validation error
8161 gp_ci.pViewportState = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -07008162 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07008163 gp_ci.pVertexInputState = &vi_ci;
8164 gp_ci.pInputAssemblyState = &ia_ci;
8165 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07008166 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
8167 gp_ci.layout = pipeline_layout;
8168 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06008169
8170 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008171 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008172
8173 VkPipeline pipeline;
8174 VkPipelineCache pipelineCache;
8175
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008176 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008177 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008178 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008179
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008180 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06008181
Chia-I Wuf7458c52015-10-26 21:10:41 +08008182 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
8183 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8184 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8185 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008186}
Mark Lobodzinski73169e22016-12-16 14:01:17 -07008187
8188// Create PSO w/o non-zero viewportCount but no viewport data, then run second test where dynamic scissor count doesn't match PSO
8189// scissor count
Karl Schultz6addd812016-02-02 17:17:23 -07008190TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch) {
8191 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008192
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07008193 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02110);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008194
Tony Barbour1fa09702017-03-16 12:09:08 -06008195 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12008196
8197 if (!m_device->phy().features().multiViewport) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07008198 printf(" Device does not support multiple viewports/scissors; skipped.\n");
Chris Forbesc08a6ca2016-07-28 14:14:07 +12008199 return;
8200 }
8201
Tobin Ehlise68360f2015-10-01 11:15:13 -06008202 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06008203
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008204 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008205 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8206 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008207
8208 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008209 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8210 ds_pool_ci.maxSets = 1;
8211 ds_pool_ci.poolSizeCount = 1;
8212 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008213
8214 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008215 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008216 ASSERT_VK_SUCCESS(err);
8217
8218 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008219 dsl_binding.binding = 0;
8220 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8221 dsl_binding.descriptorCount = 1;
8222 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008223
8224 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008225 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8226 ds_layout_ci.bindingCount = 1;
8227 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008228
8229 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008230 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008231 ASSERT_VK_SUCCESS(err);
8232
8233 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008234 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008235 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008236 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008237 alloc_info.descriptorPool = ds_pool;
8238 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008239 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008240 ASSERT_VK_SUCCESS(err);
8241
8242 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008243 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8244 pipeline_layout_ci.setLayoutCount = 1;
8245 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008246
8247 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008248 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008249 ASSERT_VK_SUCCESS(err);
8250
8251 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008252 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
8253 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008254 vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error
Karl Schultz6addd812016-02-02 17:17:23 -07008255 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008256 vp_state_ci.pScissors = NULL; // Scissor is dynamic (below) so this won't cause error
Tobin Ehlise68360f2015-10-01 11:15:13 -06008257
8258 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
8259 // Set scissor as dynamic to avoid that error
8260 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008261 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
8262 dyn_state_ci.dynamicStateCount = 1;
8263 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008264
Mark Lobodzinski73169e22016-12-16 14:01:17 -07008265 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
8266 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
8267 pipe_ms_state_ci.pNext = NULL;
8268 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
8269 pipe_ms_state_ci.sampleShadingEnable = 0;
8270 pipe_ms_state_ci.minSampleShading = 1.0;
8271 pipe_ms_state_ci.pSampleMask = NULL;
8272
Cody Northropeb3a6c12015-10-05 14:44:45 -06008273 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07008274 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06008275
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008276 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski73169e22016-12-16 14:01:17 -07008277 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
8278 // 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 +08008279 shaderStages[0] = vs.GetStageCreateInfo();
8280 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06008281
Cody Northropf6622dc2015-10-06 10:33:21 -06008282 VkPipelineVertexInputStateCreateInfo vi_ci = {};
8283 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
8284 vi_ci.pNext = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008285 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06008286 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008287 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06008288 vi_ci.pVertexAttributeDescriptions = nullptr;
8289
8290 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
8291 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
8292 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
8293
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008294 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008295 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Mark Lobodzinski73169e22016-12-16 14:01:17 -07008296 rs_ci.lineWidth = m_device->props.limits.lineWidthRange[0];
Cody Northropf6622dc2015-10-06 10:33:21 -06008297 rs_ci.pNext = nullptr;
8298
Mark Youngc89c6312016-03-31 16:03:20 -06008299 VkPipelineColorBlendAttachmentState att = {};
8300 att.blendEnable = VK_FALSE;
8301 att.colorWriteMask = 0xf;
8302
Cody Northropf6622dc2015-10-06 10:33:21 -06008303 VkPipelineColorBlendStateCreateInfo cb_ci = {};
8304 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
8305 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06008306 cb_ci.attachmentCount = 1;
8307 cb_ci.pAttachments = &att;
Cody Northropf6622dc2015-10-06 10:33:21 -06008308
Tobin Ehlise68360f2015-10-01 11:15:13 -06008309 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008310 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8311 gp_ci.stageCount = 2;
8312 gp_ci.pStages = shaderStages;
8313 gp_ci.pVertexInputState = &vi_ci;
8314 gp_ci.pInputAssemblyState = &ia_ci;
8315 gp_ci.pViewportState = &vp_state_ci;
8316 gp_ci.pRasterizationState = &rs_ci;
8317 gp_ci.pColorBlendState = &cb_ci;
8318 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski73169e22016-12-16 14:01:17 -07008319 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07008320 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
8321 gp_ci.layout = pipeline_layout;
8322 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06008323
8324 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008325 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008326
8327 VkPipeline pipeline;
8328 VkPipelineCache pipelineCache;
8329
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008330 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008331 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008332 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008333
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008334 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008335
Tobin Ehlisd332f282015-10-02 11:00:56 -06008336 // Now hit second fail case where we set scissor w/ different count than PSO
Karl Schultz6addd812016-02-02 17:17:23 -07008337 // First need to successfully create the PSO from above by setting
8338 // pViewports
Mike Weiblen95dd0f92016-10-19 12:28:27 -06008339 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 -07008340
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008341 VkViewport vp = {}; // Just need dummy vp to point to
Karl Schultz6addd812016-02-02 17:17:23 -07008342 vp_state_ci.pViewports = &vp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008343 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07008344 ASSERT_VK_SUCCESS(err);
Tony Barbour552f6c02016-12-21 14:34:07 -07008345 m_commandBuffer->BeginCommandBuffer();
8346 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008347 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008348 VkRect2D scissors[1] = {}; // don't care about data
Karl Schultz6addd812016-02-02 17:17:23 -07008349 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12008350 vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 1, 1, scissors);
Karl Schultz6addd812016-02-02 17:17:23 -07008351 Draw(1, 0, 0, 0);
8352
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008353 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07008354
8355 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
8356 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8357 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8358 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008359 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07008360}
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008361
8362// 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 -07008363// viewportCount
8364TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch) {
8365 VkResult err;
8366
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07008367 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02111);
Karl Schultz6addd812016-02-02 17:17:23 -07008368
Tony Barbour1fa09702017-03-16 12:09:08 -06008369 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12008370
8371 if (!m_device->phy().features().multiViewport) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07008372 printf(" Device does not support multiple viewports/scissors; skipped.\n");
Chris Forbesc08a6ca2016-07-28 14:14:07 +12008373 return;
8374 }
8375
Karl Schultz6addd812016-02-02 17:17:23 -07008376 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8377
8378 VkDescriptorPoolSize ds_type_count = {};
8379 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8380 ds_type_count.descriptorCount = 1;
8381
8382 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8383 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8384 ds_pool_ci.maxSets = 1;
8385 ds_pool_ci.poolSizeCount = 1;
8386 ds_pool_ci.pPoolSizes = &ds_type_count;
8387
8388 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008389 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Karl Schultz6addd812016-02-02 17:17:23 -07008390 ASSERT_VK_SUCCESS(err);
8391
8392 VkDescriptorSetLayoutBinding dsl_binding = {};
8393 dsl_binding.binding = 0;
8394 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8395 dsl_binding.descriptorCount = 1;
8396 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8397
8398 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8399 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8400 ds_layout_ci.bindingCount = 1;
8401 ds_layout_ci.pBindings = &dsl_binding;
8402
8403 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008404 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07008405 ASSERT_VK_SUCCESS(err);
8406
8407 VkDescriptorSet descriptorSet;
8408 VkDescriptorSetAllocateInfo alloc_info = {};
8409 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8410 alloc_info.descriptorSetCount = 1;
8411 alloc_info.descriptorPool = ds_pool;
8412 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008413 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Karl Schultz6addd812016-02-02 17:17:23 -07008414 ASSERT_VK_SUCCESS(err);
8415
8416 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
8417 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8418 pipeline_layout_ci.setLayoutCount = 1;
8419 pipeline_layout_ci.pSetLayouts = &ds_layout;
8420
8421 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008422 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07008423 ASSERT_VK_SUCCESS(err);
8424
8425 VkPipelineViewportStateCreateInfo vp_state_ci = {};
8426 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
8427 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008428 vp_state_ci.pScissors = NULL; // Null scissor w/ count of 1 should cause error
Karl Schultz6addd812016-02-02 17:17:23 -07008429 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008430 vp_state_ci.pViewports = NULL; // vp is dynamic (below) so this won't cause error
Karl Schultz6addd812016-02-02 17:17:23 -07008431
8432 VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT;
8433 // Set scissor as dynamic to avoid that error
8434 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
8435 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
8436 dyn_state_ci.dynamicStateCount = 1;
8437 dyn_state_ci.pDynamicStates = &vp_state;
8438
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008439 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
8440 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
8441 pipe_ms_state_ci.pNext = NULL;
8442 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
8443 pipe_ms_state_ci.sampleShadingEnable = 0;
8444 pipe_ms_state_ci.minSampleShading = 1.0;
8445 pipe_ms_state_ci.pSampleMask = NULL;
8446
Karl Schultz6addd812016-02-02 17:17:23 -07008447 VkPipelineShaderStageCreateInfo shaderStages[2];
8448 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
8449
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008450 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008451 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
8452 // 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 -07008453 shaderStages[0] = vs.GetStageCreateInfo();
8454 shaderStages[1] = fs.GetStageCreateInfo();
8455
8456 VkPipelineVertexInputStateCreateInfo vi_ci = {};
8457 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
8458 vi_ci.pNext = nullptr;
8459 vi_ci.vertexBindingDescriptionCount = 0;
8460 vi_ci.pVertexBindingDescriptions = nullptr;
8461 vi_ci.vertexAttributeDescriptionCount = 0;
8462 vi_ci.pVertexAttributeDescriptions = nullptr;
8463
8464 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
8465 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
8466 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
8467
8468 VkPipelineRasterizationStateCreateInfo rs_ci = {};
8469 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008470 rs_ci.lineWidth = m_device->props.limits.lineWidthRange[0];
Karl Schultz6addd812016-02-02 17:17:23 -07008471 rs_ci.pNext = nullptr;
8472
Mark Youngc89c6312016-03-31 16:03:20 -06008473 VkPipelineColorBlendAttachmentState att = {};
8474 att.blendEnable = VK_FALSE;
8475 att.colorWriteMask = 0xf;
8476
Karl Schultz6addd812016-02-02 17:17:23 -07008477 VkPipelineColorBlendStateCreateInfo cb_ci = {};
8478 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
8479 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06008480 cb_ci.attachmentCount = 1;
8481 cb_ci.pAttachments = &att;
Karl Schultz6addd812016-02-02 17:17:23 -07008482
8483 VkGraphicsPipelineCreateInfo gp_ci = {};
8484 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8485 gp_ci.stageCount = 2;
8486 gp_ci.pStages = shaderStages;
8487 gp_ci.pVertexInputState = &vi_ci;
8488 gp_ci.pInputAssemblyState = &ia_ci;
8489 gp_ci.pViewportState = &vp_state_ci;
8490 gp_ci.pRasterizationState = &rs_ci;
8491 gp_ci.pColorBlendState = &cb_ci;
8492 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008493 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07008494 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
8495 gp_ci.layout = pipeline_layout;
8496 gp_ci.renderPass = renderPass();
8497
8498 VkPipelineCacheCreateInfo pc_ci = {};
8499 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
8500
8501 VkPipeline pipeline;
8502 VkPipelineCache pipelineCache;
8503
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008504 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Karl Schultz6addd812016-02-02 17:17:23 -07008505 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008506 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07008507
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008508 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07008509
8510 // Now hit second fail case where we set scissor w/ different count than PSO
8511 // First need to successfully create the PSO from above by setting
8512 // pViewports
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07008513 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8514 "Dynamic viewport(s) 0 are used by pipeline state object, ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008515
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008516 VkRect2D sc = {}; // Just need dummy vp to point to
Tobin Ehlisd332f282015-10-02 11:00:56 -06008517 vp_state_ci.pScissors = &sc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008518 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06008519 ASSERT_VK_SUCCESS(err);
Tony Barbour552f6c02016-12-21 14:34:07 -07008520 m_commandBuffer->BeginCommandBuffer();
8521 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008522 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008523 VkViewport viewports[1] = {};
8524 viewports[0].width = 8;
8525 viewports[0].height = 8;
Tobin Ehlisd332f282015-10-02 11:00:56 -06008526 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12008527 vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 1, 1, viewports);
Tobin Ehlisd332f282015-10-02 11:00:56 -06008528 Draw(1, 0, 0, 0);
8529
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008530 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06008531
Chia-I Wuf7458c52015-10-26 21:10:41 +08008532 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
8533 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8534 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8535 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008536 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008537}
8538
Mark Young7394fdd2016-03-31 14:56:43 -06008539TEST_F(VkLayerTest, PSOLineWidthInvalid) {
8540 VkResult err;
8541
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008542 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06008543
Tony Barbour1fa09702017-03-16 12:09:08 -06008544 ASSERT_NO_FATAL_FAILURE(Init());
Mark Young7394fdd2016-03-31 14:56:43 -06008545 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8546
8547 VkDescriptorPoolSize ds_type_count = {};
8548 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8549 ds_type_count.descriptorCount = 1;
8550
8551 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8552 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8553 ds_pool_ci.maxSets = 1;
8554 ds_pool_ci.poolSizeCount = 1;
8555 ds_pool_ci.pPoolSizes = &ds_type_count;
8556
8557 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008558 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Young7394fdd2016-03-31 14:56:43 -06008559 ASSERT_VK_SUCCESS(err);
8560
8561 VkDescriptorSetLayoutBinding dsl_binding = {};
8562 dsl_binding.binding = 0;
8563 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8564 dsl_binding.descriptorCount = 1;
8565 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8566
8567 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8568 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8569 ds_layout_ci.bindingCount = 1;
8570 ds_layout_ci.pBindings = &dsl_binding;
8571
8572 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008573 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06008574 ASSERT_VK_SUCCESS(err);
8575
8576 VkDescriptorSet descriptorSet;
8577 VkDescriptorSetAllocateInfo alloc_info = {};
8578 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8579 alloc_info.descriptorSetCount = 1;
8580 alloc_info.descriptorPool = ds_pool;
8581 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008582 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Young7394fdd2016-03-31 14:56:43 -06008583 ASSERT_VK_SUCCESS(err);
8584
8585 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
8586 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8587 pipeline_layout_ci.setLayoutCount = 1;
8588 pipeline_layout_ci.pSetLayouts = &ds_layout;
8589
8590 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008591 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06008592 ASSERT_VK_SUCCESS(err);
8593
8594 VkPipelineViewportStateCreateInfo vp_state_ci = {};
8595 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
8596 vp_state_ci.scissorCount = 1;
8597 vp_state_ci.pScissors = NULL;
8598 vp_state_ci.viewportCount = 1;
8599 vp_state_ci.pViewports = NULL;
8600
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008601 VkDynamicState dynamic_states[3] = {VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR, VK_DYNAMIC_STATE_LINE_WIDTH};
Mark Young7394fdd2016-03-31 14:56:43 -06008602 // Set scissor as dynamic to avoid that error
8603 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
8604 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
8605 dyn_state_ci.dynamicStateCount = 2;
8606 dyn_state_ci.pDynamicStates = dynamic_states;
8607
8608 VkPipelineShaderStageCreateInfo shaderStages[2];
8609 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
8610
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008611 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
8612 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT,
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008613 this); // TODO - We shouldn't need a fragment shader
8614 // but add it to be able to run on more devices
Mark Young7394fdd2016-03-31 14:56:43 -06008615 shaderStages[0] = vs.GetStageCreateInfo();
8616 shaderStages[1] = fs.GetStageCreateInfo();
8617
8618 VkPipelineVertexInputStateCreateInfo vi_ci = {};
8619 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
8620 vi_ci.pNext = nullptr;
8621 vi_ci.vertexBindingDescriptionCount = 0;
8622 vi_ci.pVertexBindingDescriptions = nullptr;
8623 vi_ci.vertexAttributeDescriptionCount = 0;
8624 vi_ci.pVertexAttributeDescriptions = nullptr;
8625
8626 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
8627 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
8628 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
8629
8630 VkPipelineRasterizationStateCreateInfo rs_ci = {};
8631 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
8632 rs_ci.pNext = nullptr;
Rene Lindsay144e4842017-01-20 14:27:15 -07008633 rs_ci.rasterizerDiscardEnable = VK_TRUE;
Mark Young7394fdd2016-03-31 14:56:43 -06008634
Mark Young47107952016-05-02 15:59:55 -06008635 // Check too low (line width of -1.0f).
8636 rs_ci.lineWidth = -1.0f;
Mark Young7394fdd2016-03-31 14:56:43 -06008637
8638 VkPipelineColorBlendAttachmentState att = {};
8639 att.blendEnable = VK_FALSE;
8640 att.colorWriteMask = 0xf;
8641
8642 VkPipelineColorBlendStateCreateInfo cb_ci = {};
8643 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
8644 cb_ci.pNext = nullptr;
8645 cb_ci.attachmentCount = 1;
8646 cb_ci.pAttachments = &att;
8647
8648 VkGraphicsPipelineCreateInfo gp_ci = {};
8649 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8650 gp_ci.stageCount = 2;
8651 gp_ci.pStages = shaderStages;
8652 gp_ci.pVertexInputState = &vi_ci;
8653 gp_ci.pInputAssemblyState = &ia_ci;
8654 gp_ci.pViewportState = &vp_state_ci;
8655 gp_ci.pRasterizationState = &rs_ci;
8656 gp_ci.pColorBlendState = &cb_ci;
8657 gp_ci.pDynamicState = &dyn_state_ci;
8658 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
8659 gp_ci.layout = pipeline_layout;
8660 gp_ci.renderPass = renderPass();
8661
8662 VkPipelineCacheCreateInfo pc_ci = {};
8663 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
8664
8665 VkPipeline pipeline;
8666 VkPipelineCache pipelineCache;
8667
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008668 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06008669 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008670 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06008671
8672 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06008673 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06008674
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008675 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06008676
8677 // Check too high (line width of 65536.0f).
8678 rs_ci.lineWidth = 65536.0f;
8679
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008680 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06008681 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008682 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06008683
8684 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06008685 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06008686
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008687 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06008688
8689 dyn_state_ci.dynamicStateCount = 3;
8690
8691 rs_ci.lineWidth = 1.0f;
8692
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008693 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06008694 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008695 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tony Barbour552f6c02016-12-21 14:34:07 -07008696 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008697 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06008698
8699 // Check too low with dynamic setting.
Mark Young47107952016-05-02 15:59:55 -06008700 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), -1.0f);
Mark Young7394fdd2016-03-31 14:56:43 -06008701 m_errorMonitor->VerifyFound();
8702
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008703 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06008704
8705 // Check too high with dynamic setting.
8706 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), 65536.0f);
8707 m_errorMonitor->VerifyFound();
Tony Barbour552f6c02016-12-21 14:34:07 -07008708 m_commandBuffer->EndCommandBuffer();
Mark Young7394fdd2016-03-31 14:56:43 -06008709
8710 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
8711 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8712 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8713 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008714 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06008715}
8716
Jeremy Hayes37f0cdd2017-05-04 18:08:49 -06008717TEST_F(VkLayerTest, VALIDATION_ERROR_01407) {
8718 TEST_DESCRIPTION("Test VALIDATION_ERROR_01407: binding must be less than VkPhysicalDeviceLimits::maxVertexInputBindings");
8719
8720 ASSERT_NO_FATAL_FAILURE(Init());
8721 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8722
8723 VkPipelineCache pipeline_cache;
8724 {
8725 VkPipelineCacheCreateInfo create_info{};
8726 create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
8727
8728 VkResult err = vkCreatePipelineCache(m_device->device(), &create_info, nullptr, &pipeline_cache);
8729 ASSERT_VK_SUCCESS(err);
8730 }
8731
8732 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
8733 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
8734
8735 VkPipelineShaderStageCreateInfo stages[2]{{}};
8736 stages[0] = vs.GetStageCreateInfo();
8737 stages[1] = fs.GetStageCreateInfo();
8738
8739 // Test when binding is greater than or equal to VkPhysicalDeviceLimits::maxVertexInputBindings.
8740 VkVertexInputBindingDescription vertex_input_binding_description{};
8741 vertex_input_binding_description.binding = m_device->props.limits.maxVertexInputBindings;
8742
8743 VkPipelineVertexInputStateCreateInfo vertex_input_state{};
8744 vertex_input_state.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
8745 vertex_input_state.pNext = nullptr;
8746 vertex_input_state.vertexBindingDescriptionCount = 1;
8747 vertex_input_state.pVertexBindingDescriptions = &vertex_input_binding_description;
8748 vertex_input_state.vertexAttributeDescriptionCount = 0;
8749 vertex_input_state.pVertexAttributeDescriptions = nullptr;
8750
8751 VkPipelineInputAssemblyStateCreateInfo input_assembly_state{};
8752 input_assembly_state.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
8753 input_assembly_state.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
8754
8755 VkViewport viewport{};
8756 VkPipelineViewportStateCreateInfo viewport_state{};
8757 viewport_state.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
8758 viewport_state.scissorCount = 1;
8759 viewport_state.viewportCount = 1;
8760 viewport_state.pViewports = &viewport;
8761
8762 VkPipelineMultisampleStateCreateInfo multisample_state{};
8763 multisample_state.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
8764 multisample_state.pNext = nullptr;
8765 multisample_state.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
8766 multisample_state.sampleShadingEnable = 0;
8767 multisample_state.minSampleShading = 1.0;
8768 multisample_state.pSampleMask = nullptr;
8769
8770 VkPipelineRasterizationStateCreateInfo rasterization_state{};
8771 rasterization_state.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
8772 rasterization_state.polygonMode = VK_POLYGON_MODE_FILL;
8773 rasterization_state.cullMode = VK_CULL_MODE_BACK_BIT;
8774 rasterization_state.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
8775 rasterization_state.depthClampEnable = VK_FALSE;
8776 rasterization_state.rasterizerDiscardEnable = VK_FALSE;
8777 rasterization_state.depthBiasEnable = VK_FALSE;
8778
8779 VkPipelineLayout pipeline_layout;
8780 {
8781 VkPipelineLayoutCreateInfo create_info{};
8782 create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8783 create_info.setLayoutCount = 0;
8784 create_info.pSetLayouts = nullptr;
8785
8786 VkResult err = vkCreatePipelineLayout(m_device->device(), &create_info, nullptr, &pipeline_layout);
8787 ASSERT_VK_SUCCESS(err);
8788 }
8789
8790 {
8791 VkGraphicsPipelineCreateInfo create_info{};
8792 create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8793 create_info.stageCount = 2;
8794 create_info.pStages = stages;
8795 create_info.pVertexInputState = &vertex_input_state;
8796 create_info.pInputAssemblyState = &input_assembly_state;
8797 create_info.pViewportState = &viewport_state;
8798 create_info.pMultisampleState = &multisample_state;
8799 create_info.pRasterizationState = &rasterization_state;
8800 create_info.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
8801 create_info.layout = pipeline_layout;
8802 create_info.renderPass = renderPass();
8803
8804 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01407);
8805 VkPipeline pipeline;
8806 vkCreateGraphicsPipelines(m_device->device(), pipeline_cache, 1, &create_info, nullptr, &pipeline);
8807 m_errorMonitor->VerifyFound();
8808 }
8809
8810 vkDestroyPipelineCache(m_device->device(), pipeline_cache, nullptr);
8811 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
8812}
8813
8814TEST_F(VkLayerTest, VALIDATION_ERROR_01408) {
8815 TEST_DESCRIPTION(
8816 "Test VALIDATION_ERROR_01408: stride must be less than or equal to VkPhysicalDeviceLimits::maxVertexInputBindingStride");
8817
8818 ASSERT_NO_FATAL_FAILURE(Init());
8819 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8820
8821 VkPipelineCache pipeline_cache;
8822 {
8823 VkPipelineCacheCreateInfo create_info{};
8824 create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
8825
8826 VkResult err = vkCreatePipelineCache(m_device->device(), &create_info, nullptr, &pipeline_cache);
8827 ASSERT_VK_SUCCESS(err);
8828 }
8829
8830 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
8831 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
8832
8833 VkPipelineShaderStageCreateInfo stages[2]{{}};
8834 stages[0] = vs.GetStageCreateInfo();
8835 stages[1] = fs.GetStageCreateInfo();
8836
8837 // Test when stride is greater than VkPhysicalDeviceLimits::maxVertexInputBindingStride.
8838 VkVertexInputBindingDescription vertex_input_binding_description{};
8839 vertex_input_binding_description.stride = m_device->props.limits.maxVertexInputBindingStride + 1;
8840
8841 VkPipelineVertexInputStateCreateInfo vertex_input_state{};
8842 vertex_input_state.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
8843 vertex_input_state.pNext = nullptr;
8844 vertex_input_state.vertexBindingDescriptionCount = 1;
8845 vertex_input_state.pVertexBindingDescriptions = &vertex_input_binding_description;
8846 vertex_input_state.vertexAttributeDescriptionCount = 0;
8847 vertex_input_state.pVertexAttributeDescriptions = nullptr;
8848
8849 VkPipelineInputAssemblyStateCreateInfo input_assembly_state{};
8850 input_assembly_state.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
8851 input_assembly_state.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
8852
8853 VkViewport viewport{};
8854 VkPipelineViewportStateCreateInfo viewport_state{};
8855 viewport_state.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
8856 viewport_state.scissorCount = 1;
8857 viewport_state.viewportCount = 1;
8858 viewport_state.pViewports = &viewport;
8859
8860 VkPipelineMultisampleStateCreateInfo multisample_state{};
8861 multisample_state.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
8862 multisample_state.pNext = nullptr;
8863 multisample_state.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
8864 multisample_state.sampleShadingEnable = 0;
8865 multisample_state.minSampleShading = 1.0;
8866 multisample_state.pSampleMask = nullptr;
8867
8868 VkPipelineRasterizationStateCreateInfo rasterization_state{};
8869 rasterization_state.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
8870 rasterization_state.polygonMode = VK_POLYGON_MODE_FILL;
8871 rasterization_state.cullMode = VK_CULL_MODE_BACK_BIT;
8872 rasterization_state.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
8873 rasterization_state.depthClampEnable = VK_FALSE;
8874 rasterization_state.rasterizerDiscardEnable = VK_FALSE;
8875 rasterization_state.depthBiasEnable = VK_FALSE;
8876
8877 VkPipelineLayout pipeline_layout;
8878 {
8879 VkPipelineLayoutCreateInfo create_info{};
8880 create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8881 create_info.setLayoutCount = 0;
8882 create_info.pSetLayouts = nullptr;
8883
8884 VkResult err = vkCreatePipelineLayout(m_device->device(), &create_info, nullptr, &pipeline_layout);
8885 ASSERT_VK_SUCCESS(err);
8886 }
8887
8888 {
8889 VkGraphicsPipelineCreateInfo create_info{};
8890 create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8891 create_info.stageCount = 2;
8892 create_info.pStages = stages;
8893 create_info.pVertexInputState = &vertex_input_state;
8894 create_info.pInputAssemblyState = &input_assembly_state;
8895 create_info.pViewportState = &viewport_state;
8896 create_info.pMultisampleState = &multisample_state;
8897 create_info.pRasterizationState = &rasterization_state;
8898 create_info.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
8899 create_info.layout = pipeline_layout;
8900 create_info.renderPass = renderPass();
8901
8902 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01408);
8903 VkPipeline pipeline;
8904 vkCreateGraphicsPipelines(m_device->device(), pipeline_cache, 1, &create_info, nullptr, &pipeline);
8905 m_errorMonitor->VerifyFound();
8906 }
8907
8908 vkDestroyPipelineCache(m_device->device(), pipeline_cache, nullptr);
8909 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
8910}
8911
Jeremy Hayes091e1ab2017-05-04 18:10:28 -06008912TEST_F(VkLayerTest, VALIDATION_ERROR_01410) {
8913 TEST_DESCRIPTION("Test VALIDATION_ERROR_01410: location must be less than VkPhysicalDeviceLimits::maxVertexInputAttributes");
8914
8915 ASSERT_NO_FATAL_FAILURE(Init());
8916 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8917
8918 VkPipelineCache pipeline_cache;
8919 {
8920 VkPipelineCacheCreateInfo create_info{};
8921 create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
8922
8923 VkResult err = vkCreatePipelineCache(m_device->device(), &create_info, nullptr, &pipeline_cache);
8924 ASSERT_VK_SUCCESS(err);
8925 }
8926
8927 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
8928 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
8929
8930 VkPipelineShaderStageCreateInfo stages[2]{{}};
8931 stages[0] = vs.GetStageCreateInfo();
8932 stages[1] = fs.GetStageCreateInfo();
8933
8934 // Test when location is greater than or equal to VkPhysicalDeviceLimits::maxVertexInputAttributes.
8935 VkVertexInputAttributeDescription vertex_input_attribute_description{};
8936 vertex_input_attribute_description.location = m_device->props.limits.maxVertexInputAttributes;
8937
8938 VkPipelineVertexInputStateCreateInfo vertex_input_state{};
8939 vertex_input_state.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
8940 vertex_input_state.pNext = nullptr;
8941 vertex_input_state.vertexBindingDescriptionCount = 0;
8942 vertex_input_state.pVertexBindingDescriptions = nullptr;
8943 vertex_input_state.vertexAttributeDescriptionCount = 1;
8944 vertex_input_state.pVertexAttributeDescriptions = &vertex_input_attribute_description;
8945
8946 VkPipelineInputAssemblyStateCreateInfo input_assembly_state{};
8947 input_assembly_state.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
8948 input_assembly_state.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
8949
8950 VkViewport viewport{};
8951 VkPipelineViewportStateCreateInfo viewport_state{};
8952 viewport_state.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
8953 viewport_state.scissorCount = 1;
8954 viewport_state.viewportCount = 1;
8955 viewport_state.pViewports = &viewport;
8956
8957 VkPipelineMultisampleStateCreateInfo multisample_state{};
8958 multisample_state.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
8959 multisample_state.pNext = nullptr;
8960 multisample_state.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
8961 multisample_state.sampleShadingEnable = 0;
8962 multisample_state.minSampleShading = 1.0;
8963 multisample_state.pSampleMask = nullptr;
8964
8965 VkPipelineRasterizationStateCreateInfo rasterization_state{};
8966 rasterization_state.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
8967 rasterization_state.polygonMode = VK_POLYGON_MODE_FILL;
8968 rasterization_state.cullMode = VK_CULL_MODE_BACK_BIT;
8969 rasterization_state.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
8970 rasterization_state.depthClampEnable = VK_FALSE;
8971 rasterization_state.rasterizerDiscardEnable = VK_FALSE;
8972 rasterization_state.depthBiasEnable = VK_FALSE;
8973
8974 VkPipelineLayout pipeline_layout;
8975 {
8976 VkPipelineLayoutCreateInfo create_info{};
8977 create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8978 create_info.setLayoutCount = 0;
8979 create_info.pSetLayouts = nullptr;
8980
8981 VkResult err = vkCreatePipelineLayout(m_device->device(), &create_info, nullptr, &pipeline_layout);
8982 ASSERT_VK_SUCCESS(err);
8983 }
8984
8985 {
8986 VkGraphicsPipelineCreateInfo create_info{};
8987 create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8988 create_info.stageCount = 2;
8989 create_info.pStages = stages;
8990 create_info.pVertexInputState = &vertex_input_state;
8991 create_info.pInputAssemblyState = &input_assembly_state;
8992 create_info.pViewportState = &viewport_state;
8993 create_info.pMultisampleState = &multisample_state;
8994 create_info.pRasterizationState = &rasterization_state;
8995 create_info.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
8996 create_info.layout = pipeline_layout;
8997 create_info.renderPass = renderPass();
8998
8999 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01410);
9000 VkPipeline pipeline;
9001 vkCreateGraphicsPipelines(m_device->device(), pipeline_cache, 1, &create_info, nullptr, &pipeline);
9002 m_errorMonitor->VerifyFound();
9003 }
9004
9005 vkDestroyPipelineCache(m_device->device(), pipeline_cache, nullptr);
9006 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
9007}
9008
9009TEST_F(VkLayerTest, VALIDATION_ERROR_01411) {
9010 TEST_DESCRIPTION("Test VALIDATION_ERROR_01411: binding must be less than VkPhysicalDeviceLimits::maxVertexInputBindings");
9011
9012 ASSERT_NO_FATAL_FAILURE(Init());
9013 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9014
9015 VkPipelineCache pipeline_cache;
9016 {
9017 VkPipelineCacheCreateInfo create_info{};
9018 create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
9019
9020 VkResult err = vkCreatePipelineCache(m_device->device(), &create_info, nullptr, &pipeline_cache);
9021 ASSERT_VK_SUCCESS(err);
9022 }
9023
9024 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9025 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
9026
9027 VkPipelineShaderStageCreateInfo stages[2]{{}};
9028 stages[0] = vs.GetStageCreateInfo();
9029 stages[1] = fs.GetStageCreateInfo();
9030
9031 // Test when binding is greater than or equal to VkPhysicalDeviceLimits::maxVertexInputBindings.
9032 VkVertexInputAttributeDescription vertex_input_attribute_description{};
9033 vertex_input_attribute_description.binding = m_device->props.limits.maxVertexInputBindings;
9034
9035 VkPipelineVertexInputStateCreateInfo vertex_input_state{};
9036 vertex_input_state.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
9037 vertex_input_state.pNext = nullptr;
9038 vertex_input_state.vertexBindingDescriptionCount = 0;
9039 vertex_input_state.pVertexBindingDescriptions = nullptr;
9040 vertex_input_state.vertexAttributeDescriptionCount = 1;
9041 vertex_input_state.pVertexAttributeDescriptions = &vertex_input_attribute_description;
9042
9043 VkPipelineInputAssemblyStateCreateInfo input_assembly_state{};
9044 input_assembly_state.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
9045 input_assembly_state.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
9046
9047 VkViewport viewport{};
9048 VkPipelineViewportStateCreateInfo viewport_state{};
9049 viewport_state.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
9050 viewport_state.scissorCount = 1;
9051 viewport_state.viewportCount = 1;
9052 viewport_state.pViewports = &viewport;
9053
9054 VkPipelineMultisampleStateCreateInfo multisample_state{};
9055 multisample_state.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
9056 multisample_state.pNext = nullptr;
9057 multisample_state.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
9058 multisample_state.sampleShadingEnable = 0;
9059 multisample_state.minSampleShading = 1.0;
9060 multisample_state.pSampleMask = nullptr;
9061
9062 VkPipelineRasterizationStateCreateInfo rasterization_state{};
9063 rasterization_state.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
9064 rasterization_state.polygonMode = VK_POLYGON_MODE_FILL;
9065 rasterization_state.cullMode = VK_CULL_MODE_BACK_BIT;
9066 rasterization_state.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
9067 rasterization_state.depthClampEnable = VK_FALSE;
9068 rasterization_state.rasterizerDiscardEnable = VK_FALSE;
9069 rasterization_state.depthBiasEnable = VK_FALSE;
9070
9071 VkPipelineLayout pipeline_layout;
9072 {
9073 VkPipelineLayoutCreateInfo create_info{};
9074 create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9075 create_info.setLayoutCount = 0;
9076 create_info.pSetLayouts = nullptr;
9077
9078 VkResult err = vkCreatePipelineLayout(m_device->device(), &create_info, nullptr, &pipeline_layout);
9079 ASSERT_VK_SUCCESS(err);
9080 }
9081
9082 {
9083 VkGraphicsPipelineCreateInfo create_info{};
9084 create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
9085 create_info.stageCount = 2;
9086 create_info.pStages = stages;
9087 create_info.pVertexInputState = &vertex_input_state;
9088 create_info.pInputAssemblyState = &input_assembly_state;
9089 create_info.pViewportState = &viewport_state;
9090 create_info.pMultisampleState = &multisample_state;
9091 create_info.pRasterizationState = &rasterization_state;
9092 create_info.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
9093 create_info.layout = pipeline_layout;
9094 create_info.renderPass = renderPass();
9095
9096 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01411);
9097 VkPipeline pipeline;
9098 vkCreateGraphicsPipelines(m_device->device(), pipeline_cache, 1, &create_info, nullptr, &pipeline);
9099 m_errorMonitor->VerifyFound();
9100 }
9101
9102 vkDestroyPipelineCache(m_device->device(), pipeline_cache, nullptr);
9103 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
9104}
9105
9106TEST_F(VkLayerTest, VALIDATION_ERROR_01412) {
9107 TEST_DESCRIPTION(
9108 "Test VALIDATION_ERROR_01412: offset must be less than or equal to VkPhysicalDeviceLimits::maxVertexInputAttributeOffset");
9109
9110 ASSERT_NO_FATAL_FAILURE(Init());
9111 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9112
9113 VkPipelineCache pipeline_cache;
9114 {
9115 VkPipelineCacheCreateInfo create_info{};
9116 create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
9117
9118 VkResult err = vkCreatePipelineCache(m_device->device(), &create_info, nullptr, &pipeline_cache);
9119 ASSERT_VK_SUCCESS(err);
9120 }
9121
9122 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9123 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
9124
9125 VkPipelineShaderStageCreateInfo stages[2]{{}};
9126 stages[0] = vs.GetStageCreateInfo();
9127 stages[1] = fs.GetStageCreateInfo();
9128
9129 // Test when offset is greater than maximum.
9130 VkVertexInputAttributeDescription vertex_input_attribute_description{};
9131 vertex_input_attribute_description.offset = m_device->props.limits.maxVertexInputAttributeOffset + 1;
9132
9133 VkPipelineVertexInputStateCreateInfo vertex_input_state{};
9134 vertex_input_state.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
9135 vertex_input_state.pNext = nullptr;
9136 vertex_input_state.vertexBindingDescriptionCount = 0;
9137 vertex_input_state.pVertexBindingDescriptions = nullptr;
9138 vertex_input_state.vertexAttributeDescriptionCount = 1;
9139 vertex_input_state.pVertexAttributeDescriptions = &vertex_input_attribute_description;
9140
9141 VkPipelineInputAssemblyStateCreateInfo input_assembly_state{};
9142 input_assembly_state.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
9143 input_assembly_state.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
9144
9145 VkViewport viewport{};
9146 VkPipelineViewportStateCreateInfo viewport_state{};
9147 viewport_state.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
9148 viewport_state.scissorCount = 1;
9149 viewport_state.viewportCount = 1;
9150 viewport_state.pViewports = &viewport;
9151
9152 VkPipelineMultisampleStateCreateInfo multisample_state{};
9153 multisample_state.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
9154 multisample_state.pNext = nullptr;
9155 multisample_state.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
9156 multisample_state.sampleShadingEnable = 0;
9157 multisample_state.minSampleShading = 1.0;
9158 multisample_state.pSampleMask = nullptr;
9159
9160 VkPipelineRasterizationStateCreateInfo rasterization_state{};
9161 rasterization_state.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
9162 rasterization_state.polygonMode = VK_POLYGON_MODE_FILL;
9163 rasterization_state.cullMode = VK_CULL_MODE_BACK_BIT;
9164 rasterization_state.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
9165 rasterization_state.depthClampEnable = VK_FALSE;
9166 rasterization_state.rasterizerDiscardEnable = VK_FALSE;
9167 rasterization_state.depthBiasEnable = VK_FALSE;
9168
9169 VkPipelineLayout pipeline_layout;
9170 {
9171 VkPipelineLayoutCreateInfo create_info{};
9172 create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9173 create_info.setLayoutCount = 0;
9174 create_info.pSetLayouts = nullptr;
9175
9176 VkResult err = vkCreatePipelineLayout(m_device->device(), &create_info, nullptr, &pipeline_layout);
9177 ASSERT_VK_SUCCESS(err);
9178 }
9179
9180 {
9181 VkGraphicsPipelineCreateInfo create_info{};
9182 create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
9183 create_info.stageCount = 2;
9184 create_info.pStages = stages;
9185 create_info.pVertexInputState = &vertex_input_state;
9186 create_info.pInputAssemblyState = &input_assembly_state;
9187 create_info.pViewportState = &viewport_state;
9188 create_info.pMultisampleState = &multisample_state;
9189 create_info.pRasterizationState = &rasterization_state;
9190 create_info.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
9191 create_info.layout = pipeline_layout;
9192 create_info.renderPass = renderPass();
9193
9194 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01412);
9195 VkPipeline pipeline;
9196 vkCreateGraphicsPipelines(m_device->device(), pipeline_cache, 1, &create_info, nullptr, &pipeline);
9197 m_errorMonitor->VerifyFound();
9198 }
9199
9200 vkDestroyPipelineCache(m_device->device(), pipeline_cache, nullptr);
9201 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
9202}
9203
Karl Schultz6addd812016-02-02 17:17:23 -07009204TEST_F(VkLayerTest, NullRenderPass) {
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06009205 // Bind a NULL RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009206 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mike Schuchardt0b1f2f82016-12-28 15:11:20 -07009207 "vkCmdBeginRenderPass: required parameter pRenderPassBegin specified as NULL");
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06009208
Tony Barbour1fa09702017-03-16 12:09:08 -06009209 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06009210 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06009211
Tony Barbour552f6c02016-12-21 14:34:07 -07009212 m_commandBuffer->BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07009213 // Don't care about RenderPass handle b/c error should be flagged before
9214 // that
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009215 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06009216
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009217 m_errorMonitor->VerifyFound();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06009218}
9219
Karl Schultz6addd812016-02-02 17:17:23 -07009220TEST_F(VkLayerTest, RenderPassWithinRenderPass) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009221 // Bind a BeginRenderPass within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009222 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9223 "It is invalid to issue this call inside an active render pass");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009224
Tony Barbour1fa09702017-03-16 12:09:08 -06009225 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009226 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009227
Tony Barbour552f6c02016-12-21 14:34:07 -07009228 m_commandBuffer->BeginCommandBuffer();
9229 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Karl Schultz6addd812016-02-02 17:17:23 -07009230 // Just create a dummy Renderpass that's non-NULL so we can get to the
9231 // proper error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009232 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009233
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009234 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009235}
9236
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06009237TEST_F(VkLayerTest, RenderPassClearOpMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009238 TEST_DESCRIPTION(
9239 "Begin a renderPass where clearValueCount is less than"
9240 "the number of renderPass attachments that use loadOp"
9241 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06009242
Tony Barbour1fa09702017-03-16 12:09:08 -06009243 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06009244 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9245
9246 // Create a renderPass with a single attachment that uses loadOp CLEAR
9247 VkAttachmentReference attach = {};
9248 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
9249 VkSubpassDescription subpass = {};
Cort Stratton7547f772017-05-04 15:18:52 -07009250 subpass.colorAttachmentCount = 1;
9251 subpass.pColorAttachments = &attach;
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06009252 VkRenderPassCreateInfo rpci = {};
9253 rpci.subpassCount = 1;
9254 rpci.pSubpasses = &subpass;
9255 rpci.attachmentCount = 1;
9256 VkAttachmentDescription attach_desc = {};
Rene Lindsay4bf0e4c2017-01-31 14:20:34 -07009257 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06009258 // Set loadOp to CLEAR
9259 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
9260 rpci.pAttachments = &attach_desc;
9261 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
9262 VkRenderPass rp;
9263 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
9264
9265 VkCommandBufferInheritanceInfo hinfo = {};
9266 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
9267 hinfo.renderPass = VK_NULL_HANDLE;
9268 hinfo.subpass = 0;
9269 hinfo.framebuffer = VK_NULL_HANDLE;
9270 hinfo.occlusionQueryEnable = VK_FALSE;
9271 hinfo.queryFlags = 0;
9272 hinfo.pipelineStatistics = 0;
9273 VkCommandBufferBeginInfo info = {};
9274 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
9275 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
9276 info.pInheritanceInfo = &hinfo;
9277
9278 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
9279 VkRenderPassBeginInfo rp_begin = {};
9280 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
9281 rp_begin.pNext = NULL;
9282 rp_begin.renderPass = renderPass();
9283 rp_begin.framebuffer = framebuffer();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009284 rp_begin.clearValueCount = 0; // Should be 1
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06009285
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07009286 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00442);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06009287
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009288 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06009289
9290 m_errorMonitor->VerifyFound();
Mark Lobodzinski5c70ebd2016-06-09 13:45:00 -06009291
9292 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06009293}
9294
Slawomir Cygan0808f392016-11-28 17:53:23 +01009295TEST_F(VkLayerTest, RenderPassClearOpTooManyValues) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009296 TEST_DESCRIPTION(
9297 "Begin a renderPass where clearValueCount is greater than"
9298 "the number of renderPass attachments that use loadOp"
9299 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
Slawomir Cygan0808f392016-11-28 17:53:23 +01009300
Tony Barbour1fa09702017-03-16 12:09:08 -06009301 ASSERT_NO_FATAL_FAILURE(Init());
Slawomir Cygan0808f392016-11-28 17:53:23 +01009302 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9303
9304 // Create a renderPass with a single attachment that uses loadOp CLEAR
9305 VkAttachmentReference attach = {};
9306 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
9307 VkSubpassDescription subpass = {};
Cort Stratton7547f772017-05-04 15:18:52 -07009308 subpass.colorAttachmentCount = 1;
9309 subpass.pColorAttachments = &attach;
Slawomir Cygan0808f392016-11-28 17:53:23 +01009310 VkRenderPassCreateInfo rpci = {};
9311 rpci.subpassCount = 1;
9312 rpci.pSubpasses = &subpass;
9313 rpci.attachmentCount = 1;
9314 VkAttachmentDescription attach_desc = {};
9315 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
9316 // Set loadOp to CLEAR
9317 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
9318 rpci.pAttachments = &attach_desc;
9319 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
9320 VkRenderPass rp;
9321 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
9322
9323 VkCommandBufferBeginInfo info = {};
9324 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
9325 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
9326
9327 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
9328 VkRenderPassBeginInfo rp_begin = {};
9329 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
9330 rp_begin.pNext = NULL;
9331 rp_begin.renderPass = renderPass();
9332 rp_begin.framebuffer = framebuffer();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009333 rp_begin.clearValueCount = 2; // Should be 1
Slawomir Cygan0808f392016-11-28 17:53:23 +01009334
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07009335 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
9336 " has a clearValueCount of"
9337 " 2 but only first 1 entries in pClearValues array are used");
Slawomir Cygan0808f392016-11-28 17:53:23 +01009338
9339 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
9340
9341 m_errorMonitor->VerifyFound();
9342
9343 vkDestroyRenderPass(m_device->device(), rp, NULL);
9344}
9345
Cody Northrop3bb4d962016-05-09 16:15:57 -06009346TEST_F(VkLayerTest, EndCommandBufferWithinRenderPass) {
Cody Northrop3bb4d962016-05-09 16:15:57 -06009347 TEST_DESCRIPTION("End a command buffer with an active render pass");
9348
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009349 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9350 "It is invalid to issue this call inside an active render pass");
Cody Northrop3bb4d962016-05-09 16:15:57 -06009351
Tony Barbour1fa09702017-03-16 12:09:08 -06009352 ASSERT_NO_FATAL_FAILURE(Init());
Cody Northrop3bb4d962016-05-09 16:15:57 -06009353 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9354
Tony Barbour552f6c02016-12-21 14:34:07 -07009355 m_commandBuffer->BeginCommandBuffer();
9356 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
9357 vkEndCommandBuffer(m_commandBuffer->handle());
Cody Northrop3bb4d962016-05-09 16:15:57 -06009358
9359 m_errorMonitor->VerifyFound();
9360
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009361 // TODO: Add test for VK_COMMAND_BUFFER_LEVEL_SECONDARY
9362 // TODO: Add test for VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT
Cody Northrop3bb4d962016-05-09 16:15:57 -06009363}
9364
Karl Schultz6addd812016-02-02 17:17:23 -07009365TEST_F(VkLayerTest, FillBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009366 // Call CmdFillBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009367 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9368 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009369
Tony Barbour1fa09702017-03-16 12:09:08 -06009370 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009371 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009372
Tony Barbour552f6c02016-12-21 14:34:07 -07009373 m_commandBuffer->BeginCommandBuffer();
9374 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009375
9376 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009377 vk_testing::Buffer dstBuffer;
9378 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009379
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009380 m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009381
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009382 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009383}
9384
Karl Schultz6addd812016-02-02 17:17:23 -07009385TEST_F(VkLayerTest, UpdateBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009386 // Call CmdUpdateBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009387 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9388 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009389
Tony Barbour1fa09702017-03-16 12:09:08 -06009390 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009391 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009392
Tony Barbour552f6c02016-12-21 14:34:07 -07009393 m_commandBuffer->BeginCommandBuffer();
9394 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009395
9396 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009397 vk_testing::Buffer dstBuffer;
9398 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009399
Karl Schultz6addd812016-02-02 17:17:23 -07009400 VkDeviceSize dstOffset = 0;
Rene Lindsay32d26902017-02-02 16:49:24 -07009401 uint32_t Data[] = {1, 2, 3, 4, 5, 6, 7, 8};
9402 VkDeviceSize dataSize = sizeof(Data) / sizeof(uint32_t);
9403 vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(), dstOffset, dataSize, &Data);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009404
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009405 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009406}
9407
Karl Schultz6addd812016-02-02 17:17:23 -07009408TEST_F(VkLayerTest, ClearColorImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009409 // Call CmdClearColorImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009410 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9411 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009412
Tony Barbour1fa09702017-03-16 12:09:08 -06009413 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009414 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009415
Tony Barbour552f6c02016-12-21 14:34:07 -07009416 m_commandBuffer->BeginCommandBuffer();
9417 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009418
Michael Lentine0a369f62016-02-03 16:51:46 -06009419 VkClearColorValue clear_color;
9420 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
Karl Schultz6addd812016-02-02 17:17:23 -07009421 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
9422 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
9423 const int32_t tex_width = 32;
9424 const int32_t tex_height = 32;
9425 VkImageCreateInfo image_create_info = {};
9426 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
9427 image_create_info.pNext = NULL;
9428 image_create_info.imageType = VK_IMAGE_TYPE_2D;
9429 image_create_info.format = tex_format;
9430 image_create_info.extent.width = tex_width;
9431 image_create_info.extent.height = tex_height;
9432 image_create_info.extent.depth = 1;
9433 image_create_info.mipLevels = 1;
9434 image_create_info.arrayLayers = 1;
9435 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
9436 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
Jeremy Hayesa3d5c7b2017-03-07 16:01:52 -07009437 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009438
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009439 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009440 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009441
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009442 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009443
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009444 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009445
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009446 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009447}
9448
Karl Schultz6addd812016-02-02 17:17:23 -07009449TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009450 // Call CmdClearDepthStencilImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009451 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9452 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009453
Tony Barbour1fa09702017-03-16 12:09:08 -06009454 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009455 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009456
Dave Houlton1d2022c2017-03-29 11:43:58 -06009457 auto depth_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbourf887b162017-03-09 10:06:46 -07009458 if (!depth_format) {
9459 printf(" No Depth + Stencil format found. Skipped.\n");
9460 return;
9461 }
9462
Tony Barbour552f6c02016-12-21 14:34:07 -07009463 m_commandBuffer->BeginCommandBuffer();
9464 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009465
9466 VkClearDepthStencilValue clear_value = {0};
Dustin Gravesa2e5c942016-02-11 18:28:06 -07009467 VkMemoryPropertyFlags reqs = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07009468 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
9469 image_create_info.imageType = VK_IMAGE_TYPE_2D;
Tony Barbourf887b162017-03-09 10:06:46 -07009470 image_create_info.format = depth_format;
Karl Schultz6addd812016-02-02 17:17:23 -07009471 image_create_info.extent.width = 64;
9472 image_create_info.extent.height = 64;
9473 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
9474 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009475
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009476 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009477 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009478
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009479 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009480
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07009481 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_value, 1,
9482 &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009483
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009484 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009485}
9486
Karl Schultz6addd812016-02-02 17:17:23 -07009487TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass) {
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06009488 // Call CmdClearAttachmentss outside of an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07009489 VkResult err;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009490
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009491 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9492 "vkCmdClearAttachments(): This call "
9493 "must be issued inside an active "
9494 "render pass");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009495
Tony Barbour1fa09702017-03-16 12:09:08 -06009496 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009497 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009498
9499 // Start no RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009500 err = m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009501 ASSERT_VK_SUCCESS(err);
9502
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06009503 VkClearAttachment color_attachment;
9504 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9505 color_attachment.clearValue.color.float32[0] = 0;
9506 color_attachment.clearValue.color.float32[1] = 0;
9507 color_attachment.clearValue.color.float32[2] = 0;
9508 color_attachment.clearValue.color.float32[3] = 0;
9509 color_attachment.colorAttachment = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07009510 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009511 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009512
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009513 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009514}
9515
Chris Forbes3b97e932016-09-07 11:29:24 +12009516TEST_F(VkLayerTest, RenderPassExcessiveNextSubpass) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009517 TEST_DESCRIPTION(
9518 "Test that an error is produced when CmdNextSubpass is "
9519 "called too many times in a renderpass instance");
Chris Forbes3b97e932016-09-07 11:29:24 +12009520
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009521 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9522 "vkCmdNextSubpass(): Attempted to advance "
9523 "beyond final subpass");
Chris Forbes3b97e932016-09-07 11:29:24 +12009524
Tony Barbour1fa09702017-03-16 12:09:08 -06009525 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes3b97e932016-09-07 11:29:24 +12009526 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9527
Tony Barbour552f6c02016-12-21 14:34:07 -07009528 m_commandBuffer->BeginCommandBuffer();
9529 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes3b97e932016-09-07 11:29:24 +12009530
9531 // error here.
9532 vkCmdNextSubpass(m_commandBuffer->GetBufferHandle(), VK_SUBPASS_CONTENTS_INLINE);
9533 m_errorMonitor->VerifyFound();
9534
Tony Barbour552f6c02016-12-21 14:34:07 -07009535 m_commandBuffer->EndRenderPass();
9536 m_commandBuffer->EndCommandBuffer();
Chris Forbes3b97e932016-09-07 11:29:24 +12009537}
9538
Chris Forbes6d624702016-09-07 13:57:05 +12009539TEST_F(VkLayerTest, RenderPassEndedBeforeFinalSubpass) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009540 TEST_DESCRIPTION(
9541 "Test that an error is produced when CmdEndRenderPass is "
9542 "called before the final subpass has been reached");
Chris Forbes6d624702016-09-07 13:57:05 +12009543
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009544 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9545 "vkCmdEndRenderPass(): Called before reaching "
9546 "final subpass");
Chris Forbes6d624702016-09-07 13:57:05 +12009547
Tony Barbour1fa09702017-03-16 12:09:08 -06009548 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009549 VkSubpassDescription sd[2] = {{0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr},
9550 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr}};
Chris Forbes6d624702016-09-07 13:57:05 +12009551
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009552 VkRenderPassCreateInfo rcpi = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 2, sd, 0, nullptr};
Chris Forbes6d624702016-09-07 13:57:05 +12009553
9554 VkRenderPass rp;
9555 VkResult err = vkCreateRenderPass(m_device->device(), &rcpi, nullptr, &rp);
9556 ASSERT_VK_SUCCESS(err);
9557
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009558 VkFramebufferCreateInfo fbci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 16, 16, 1};
Chris Forbes6d624702016-09-07 13:57:05 +12009559
9560 VkFramebuffer fb;
9561 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
9562 ASSERT_VK_SUCCESS(err);
9563
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009564 m_commandBuffer->BeginCommandBuffer(); // no implicit RP begin
Chris Forbes6d624702016-09-07 13:57:05 +12009565
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009566 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 +12009567
9568 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
9569
9570 // Error here.
9571 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
9572 m_errorMonitor->VerifyFound();
9573
9574 // Clean up.
9575 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
9576 vkDestroyRenderPass(m_device->device(), rp, nullptr);
9577}
9578
Karl Schultz9e66a292016-04-21 15:57:51 -06009579TEST_F(VkLayerTest, BufferMemoryBarrierNoBuffer) {
9580 // Try to add a buffer memory barrier with no buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009581 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9582 "required parameter pBufferMemoryBarriers[0].buffer specified as VK_NULL_HANDLE");
Karl Schultz9e66a292016-04-21 15:57:51 -06009583
Tony Barbour1fa09702017-03-16 12:09:08 -06009584 ASSERT_NO_FATAL_FAILURE(Init());
Tony Barbour552f6c02016-12-21 14:34:07 -07009585 m_commandBuffer->BeginCommandBuffer();
Karl Schultz9e66a292016-04-21 15:57:51 -06009586
9587 VkBufferMemoryBarrier buf_barrier = {};
9588 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
9589 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
9590 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
9591 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
9592 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
9593 buf_barrier.buffer = VK_NULL_HANDLE;
9594 buf_barrier.offset = 0;
9595 buf_barrier.size = VK_WHOLE_SIZE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009596 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9597 nullptr, 1, &buf_barrier, 0, nullptr);
Karl Schultz9e66a292016-04-21 15:57:51 -06009598
9599 m_errorMonitor->VerifyFound();
9600}
9601
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009602TEST_F(VkLayerTest, InvalidBarriers) {
9603 TEST_DESCRIPTION("A variety of ways to get VK_INVALID_BARRIER ");
9604
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009605 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Barriers cannot be set during subpass");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009606
Tony Barbour1fa09702017-03-16 12:09:08 -06009607 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -06009608 auto depth_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbourf887b162017-03-09 10:06:46 -07009609 if (!depth_format) {
9610 printf(" No Depth + Stencil format found. Skipped.\n");
9611 return;
9612 }
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009613 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9614
9615 VkMemoryBarrier mem_barrier = {};
9616 mem_barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER;
9617 mem_barrier.pNext = NULL;
9618 mem_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
9619 mem_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
Tony Barbour552f6c02016-12-21 14:34:07 -07009620 m_commandBuffer->BeginCommandBuffer();
9621 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009622 // BeginCommandBuffer() starts a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009623 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 1,
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009624 &mem_barrier, 0, nullptr, 0, nullptr);
9625 m_errorMonitor->VerifyFound();
9626
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009627 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image Layout cannot be transitioned to UNDEFINED");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009628 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06009629 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 -06009630 ASSERT_TRUE(image.initialized());
9631 VkImageMemoryBarrier img_barrier = {};
9632 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
9633 img_barrier.pNext = NULL;
9634 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
9635 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
Mark Lobodzinski95512b72017-05-10 12:21:30 -06009636 img_barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009637 // New layout can't be UNDEFINED
9638 img_barrier.newLayout = VK_IMAGE_LAYOUT_UNDEFINED;
9639 img_barrier.image = image.handle();
9640 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
9641 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
9642 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9643 img_barrier.subresourceRange.baseArrayLayer = 0;
9644 img_barrier.subresourceRange.baseMipLevel = 0;
9645 img_barrier.subresourceRange.layerCount = 1;
9646 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009647 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9648 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009649 m_errorMonitor->VerifyFound();
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009650
Mark Lobodzinski95512b72017-05-10 12:21:30 -06009651 // Transition image to color attachment optimal
9652 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
9653 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
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_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinski95512b72017-05-10 12:21:30 -06009657
Mark Lobodzinski45daf6e2017-05-10 13:19:02 -06009658 // Try to change layout in a renderpass
9659 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02080);
9660 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9661 nullptr, 0, nullptr, 1, &img_barrier);
9662 m_errorMonitor->VerifyFound();
9663
9664 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
Mark Lobodzinski95512b72017-05-10 12:21:30 -06009665 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the baseArrayLayer");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009666 // baseArrayLayer + layerCount must be <= image's arrayLayers
9667 img_barrier.subresourceRange.baseArrayLayer = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009668 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9669 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009670 m_errorMonitor->VerifyFound();
9671 img_barrier.subresourceRange.baseArrayLayer = 0;
9672
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009673 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the baseMipLevel");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009674 // baseMipLevel + levelCount must be <= image's mipLevels
9675 img_barrier.subresourceRange.baseMipLevel = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009676 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9677 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009678 m_errorMonitor->VerifyFound();
9679 img_barrier.subresourceRange.baseMipLevel = 0;
9680
Mike Weiblen7053aa32017-01-25 15:21:10 -07009681 // levelCount must be non-zero.
9682 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
9683 img_barrier.subresourceRange.levelCount = 0;
9684 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9685 nullptr, 0, nullptr, 1, &img_barrier);
9686 m_errorMonitor->VerifyFound();
9687 img_barrier.subresourceRange.levelCount = 1;
9688
9689 // layerCount must be non-zero.
9690 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00769);
9691 img_barrier.subresourceRange.layerCount = 0;
9692 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9693 nullptr, 0, nullptr, 1, &img_barrier);
9694 m_errorMonitor->VerifyFound();
9695 img_barrier.subresourceRange.layerCount = 1;
9696
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009697 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 -06009698 vk_testing::Buffer buffer;
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07009699 VkMemoryPropertyFlags mem_reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
9700 buffer.init_as_src_and_dst(*m_device, 256, mem_reqs);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009701 VkBufferMemoryBarrier buf_barrier = {};
9702 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
9703 buf_barrier.pNext = NULL;
9704 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
9705 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
9706 buf_barrier.buffer = buffer.handle();
9707 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
9708 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
9709 buf_barrier.offset = 0;
9710 buf_barrier.size = VK_WHOLE_SIZE;
9711 // Can't send buffer barrier during a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009712 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9713 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009714 m_errorMonitor->VerifyFound();
9715 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
9716
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009717 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which is not less than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009718 buf_barrier.offset = 257;
9719 // Offset greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009720 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9721 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009722 m_errorMonitor->VerifyFound();
9723 buf_barrier.offset = 0;
9724
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009725 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "whose sum is greater than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009726 buf_barrier.size = 257;
9727 // Size greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009728 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9729 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009730 m_errorMonitor->VerifyFound();
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009731
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009732 // Now exercise barrier aspect bit errors, first DS
Tobin Ehlis99ab0d22017-04-26 16:53:52 -06009733 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00741);
9734 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00302);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009735 VkDepthStencilObj ds_image(m_device);
Tony Barbourf887b162017-03-09 10:06:46 -07009736 ds_image.Init(m_device, 128, 128, depth_format);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009737 ASSERT_TRUE(ds_image.initialized());
Tobin Ehlis15684a02016-07-21 14:55:26 -06009738 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
9739 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009740 img_barrier.image = ds_image.handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07009741
9742 // Not having DEPTH or STENCIL set is an error
Rene Lindsay4834cba2017-02-02 17:18:56 -07009743 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009744 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9745 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009746 m_errorMonitor->VerifyFound();
Dave Houltonfbf52152017-01-06 12:55:29 -07009747
Tobin Ehlis99ab0d22017-04-26 16:53:52 -06009748 // Having only one of depth or stencil set for DS image is an error
9749 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00302);
9750 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT;
9751 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9752 nullptr, 0, nullptr, 1, &img_barrier);
9753 m_errorMonitor->VerifyFound();
9754
9755 // Having anything other than DEPTH and STENCIL is an error
9756 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00741);
Dave Houltonfbf52152017-01-06 12:55:29 -07009757 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT | VK_IMAGE_ASPECT_COLOR_BIT;
9758 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9759 nullptr, 0, nullptr, 1, &img_barrier);
9760 m_errorMonitor->VerifyFound();
9761
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009762 // Now test depth-only
9763 VkFormatProperties format_props;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009764 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D16_UNORM, &format_props);
9765 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009766 VkDepthStencilObj d_image(m_device);
9767 d_image.Init(m_device, 128, 128, VK_FORMAT_D16_UNORM);
9768 ASSERT_TRUE(d_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009769 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06009770 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009771 img_barrier.image = d_image.handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07009772
9773 // DEPTH bit must be set
9774 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9775 "Depth-only image formats must have the VK_IMAGE_ASPECT_DEPTH_BIT set.");
Rene Lindsay4834cba2017-02-02 17:18:56 -07009776 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Dave Houltonfbf52152017-01-06 12:55:29 -07009777 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
9778 0, nullptr, 0, nullptr, 1, &img_barrier);
9779 m_errorMonitor->VerifyFound();
9780
9781 // No bits other than DEPTH may be set
9782 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9783 "Depth-only image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT set.");
9784 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009785 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
9786 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009787 m_errorMonitor->VerifyFound();
9788 }
Dave Houltonfbf52152017-01-06 12:55:29 -07009789
9790 // Now test stencil-only
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009791 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_S8_UINT, &format_props);
9792 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009793 VkDepthStencilObj s_image(m_device);
9794 s_image.Init(m_device, 128, 128, VK_FORMAT_S8_UINT);
9795 ASSERT_TRUE(s_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009796 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06009797 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009798 img_barrier.image = s_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06009799 // Use of COLOR aspect on depth image is error
Dave Houltonf3229d52017-02-21 15:59:08 -07009800 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9801 "Stencil-only image formats must have the VK_IMAGE_ASPECT_STENCIL_BIT set.");
Tobin Ehlis15684a02016-07-21 14:55:26 -06009802 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009803 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
9804 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009805 m_errorMonitor->VerifyFound();
9806 }
Dave Houltonfbf52152017-01-06 12:55:29 -07009807
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009808 // Finally test color
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009809 VkImageObj c_image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06009810 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 -06009811 ASSERT_TRUE(c_image.initialized());
9812 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
9813 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
9814 img_barrier.image = c_image.handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07009815
9816 // COLOR bit must be set
9817 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9818 "Color image formats must have the VK_IMAGE_ASPECT_COLOR_BIT set.");
Rene Lindsay4834cba2017-02-02 17:18:56 -07009819 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Dave Houltonfbf52152017-01-06 12:55:29 -07009820 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9821 nullptr, 0, nullptr, 1, &img_barrier);
9822 m_errorMonitor->VerifyFound();
9823
9824 // No bits other than COLOR may be set
9825 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9826 "Color image formats must have ONLY the VK_IMAGE_ASPECT_COLOR_BIT set.");
9827 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009828 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9829 nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009830 m_errorMonitor->VerifyFound();
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07009831
Mike Weiblene6e01172017-03-07 22:18:40 -07009832 // A barrier's new and old VkImageLayout must be compatible with an image's VkImageUsageFlags.
9833 {
9834 VkImageObj img_color(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06009835 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 -07009836 ASSERT_TRUE(img_color.initialized());
9837
9838 VkImageObj img_ds(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06009839 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 -07009840 ASSERT_TRUE(img_ds.initialized());
9841
9842 VkImageObj img_xfer_src(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06009843 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 -07009844 ASSERT_TRUE(img_xfer_src.initialized());
9845
9846 VkImageObj img_xfer_dst(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06009847 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 -07009848 ASSERT_TRUE(img_xfer_dst.initialized());
9849
9850 VkImageObj img_sampled(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06009851 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 -07009852 ASSERT_TRUE(img_sampled.initialized());
9853
9854 VkImageObj img_input(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06009855 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 -07009856 ASSERT_TRUE(img_input.initialized());
9857
9858 const struct {
9859 VkImageObj &image_obj;
9860 VkImageLayout bad_layout;
9861 UNIQUE_VALIDATION_ERROR_CODE msg_code;
9862 } bad_buffer_layouts[] = {
9863 // clang-format off
9864 // images _without_ VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT
9865 {img_ds, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VALIDATION_ERROR_00303},
9866 {img_xfer_src, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VALIDATION_ERROR_00303},
9867 {img_xfer_dst, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VALIDATION_ERROR_00303},
9868 {img_sampled, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VALIDATION_ERROR_00303},
9869 {img_input, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VALIDATION_ERROR_00303},
9870 // images _without_ VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT
9871 {img_color, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, VALIDATION_ERROR_00304},
9872 {img_xfer_src, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, VALIDATION_ERROR_00304},
9873 {img_xfer_dst, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, VALIDATION_ERROR_00304},
9874 {img_sampled, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, VALIDATION_ERROR_00304},
9875 {img_input, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, VALIDATION_ERROR_00304},
9876 {img_color, VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL, VALIDATION_ERROR_00305},
9877 {img_xfer_src, VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL, VALIDATION_ERROR_00305},
9878 {img_xfer_dst, VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL, VALIDATION_ERROR_00305},
9879 {img_sampled, VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL, VALIDATION_ERROR_00305},
9880 {img_input, VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL, VALIDATION_ERROR_00305},
9881 // images _without_ VK_IMAGE_USAGE_SAMPLED_BIT or VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT
9882 {img_color, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VALIDATION_ERROR_00306},
9883 {img_ds, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VALIDATION_ERROR_00306},
9884 {img_xfer_src, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VALIDATION_ERROR_00306},
9885 {img_xfer_dst, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VALIDATION_ERROR_00306},
9886 // images _without_ VK_IMAGE_USAGE_TRANSFER_SRC_BIT
9887 {img_color, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VALIDATION_ERROR_00307},
9888 {img_ds, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VALIDATION_ERROR_00307},
9889 {img_xfer_dst, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VALIDATION_ERROR_00307},
9890 {img_sampled, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VALIDATION_ERROR_00307},
9891 {img_input, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VALIDATION_ERROR_00307},
9892 // images _without_ VK_IMAGE_USAGE_TRANSFER_DST_BIT
9893 {img_color, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VALIDATION_ERROR_00308},
9894 {img_ds, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VALIDATION_ERROR_00308},
9895 {img_xfer_src, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VALIDATION_ERROR_00308},
9896 {img_sampled, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VALIDATION_ERROR_00308},
9897 {img_input, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VALIDATION_ERROR_00308},
9898 // clang-format on
9899 };
9900 const uint32_t layout_count = sizeof(bad_buffer_layouts) / sizeof(bad_buffer_layouts[0]);
9901
9902 for (uint32_t i = 0; i < layout_count; ++i) {
9903 img_barrier.image = bad_buffer_layouts[i].image_obj.handle();
9904 const VkImageUsageFlags usage = bad_buffer_layouts[i].image_obj.usage();
9905 img_barrier.subresourceRange.aspectMask = (usage == VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT)
9906 ? (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)
9907 : VK_IMAGE_ASPECT_COLOR_BIT;
9908
9909 img_barrier.oldLayout = bad_buffer_layouts[i].bad_layout;
9910 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
9911 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_buffer_layouts[i].msg_code);
9912 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT,
9913 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0, nullptr, 1, &img_barrier);
9914 m_errorMonitor->VerifyFound();
9915
9916 img_barrier.oldLayout = VK_IMAGE_LAYOUT_GENERAL;
9917 img_barrier.newLayout = bad_buffer_layouts[i].bad_layout;
9918 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_buffer_layouts[i].msg_code);
9919 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT,
9920 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0, nullptr, 1, &img_barrier);
9921 m_errorMonitor->VerifyFound();
9922 }
9923
9924 img_barrier.oldLayout = VK_IMAGE_LAYOUT_GENERAL;
9925 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
9926 }
9927
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07009928 // Attempt to mismatch barriers/waitEvents calls with incompatible queues
9929
9930 // Create command pool with incompatible queueflags
9931 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
Mike Schuchardt06304c22017-03-01 17:09:09 -07009932 uint32_t queue_family_index = m_device->QueueFamilyWithoutCapabilities(VK_QUEUE_COMPUTE_BIT);
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07009933 if (queue_family_index == UINT32_MAX) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07009934 printf(" No non-compute queue found; skipped.\n");
Mike Weiblene6e01172017-03-07 22:18:40 -07009935 return; // NOTE: this exits the test function!
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07009936 }
9937 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02513);
9938
9939 VkCommandPool command_pool;
9940 VkCommandPoolCreateInfo pool_create_info{};
9941 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
9942 pool_create_info.queueFamilyIndex = queue_family_index;
9943 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
9944 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
9945
9946 // Allocate a command buffer
9947 VkCommandBuffer bad_command_buffer;
9948 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
9949 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
9950 command_buffer_allocate_info.commandPool = command_pool;
9951 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
9952 command_buffer_allocate_info.commandBufferCount = 1;
9953 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &bad_command_buffer));
9954
9955 VkCommandBufferBeginInfo cbbi = {};
9956 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
9957 vkBeginCommandBuffer(bad_command_buffer, &cbbi);
9958 buf_barrier.offset = 0;
9959 buf_barrier.size = VK_WHOLE_SIZE;
9960 vkCmdPipelineBarrier(bad_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1,
9961 &buf_barrier, 0, nullptr);
9962 m_errorMonitor->VerifyFound();
9963
9964 if ((queue_props[queue_family_index].queueFlags & VK_QUEUE_GRAPHICS_BIT) == 0) {
9965 vkEndCommandBuffer(bad_command_buffer);
9966 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07009967 printf(" The non-compute queue does not support graphics; skipped.\n");
Mike Weiblene6e01172017-03-07 22:18:40 -07009968 return; // NOTE: this exits the test function!
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07009969 }
9970 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02510);
9971 VkEvent event;
9972 VkEventCreateInfo event_create_info{};
9973 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
9974 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
9975 vkCmdWaitEvents(bad_command_buffer, 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, nullptr, 0,
9976 nullptr, 0, nullptr);
9977 m_errorMonitor->VerifyFound();
9978
9979 vkEndCommandBuffer(bad_command_buffer);
9980 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009981}
9982
Chris Forbes50223732017-05-01 09:43:35 -07009983TEST_F(VkPositiveLayerTest, LayoutFromPresentWithoutAccessMemoryRead) {
9984 // Transition an image away from PRESENT_SRC_KHR without ACCESS_MEMORY_READ
9985 // in srcAccessMask.
Tony Barbour18ba25c2016-09-29 13:42:40 -06009986
Chris Forbes50223732017-05-01 09:43:35 -07009987 // The required behavior here was a bit unclear in earlier versions of the
9988 // spec, but there is no memory dependency required here, so this should
9989 // work without warnings.
9990
9991 m_errorMonitor->ExpectSuccess();
Tony Barbour1fa09702017-03-16 12:09:08 -06009992 ASSERT_NO_FATAL_FAILURE(Init());
Tony Barbour18ba25c2016-09-29 13:42:40 -06009993 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06009994 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 -07009995 VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbour18ba25c2016-09-29 13:42:40 -06009996 ASSERT_TRUE(image.initialized());
9997
9998 VkImageMemoryBarrier barrier = {};
9999 VkImageSubresourceRange range;
10000 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
Tony Barbour18ba25c2016-09-29 13:42:40 -060010001 barrier.srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
Chris Forbes50223732017-05-01 09:43:35 -070010002 barrier.dstAccessMask = 0;
Tony Barbour18ba25c2016-09-29 13:42:40 -060010003 barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10004 barrier.newLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
10005 barrier.image = image.handle();
10006 range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10007 range.baseMipLevel = 0;
10008 range.levelCount = 1;
10009 range.baseArrayLayer = 0;
10010 range.layerCount = 1;
10011 barrier.subresourceRange = range;
10012 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
10013 cmdbuf.BeginCommandBuffer();
10014 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
10015 &barrier);
10016 barrier.oldLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
10017 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
10018 barrier.srcAccessMask = 0;
10019 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
10020 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
10021 &barrier);
10022
Chris Forbes50223732017-05-01 09:43:35 -070010023 m_errorMonitor->VerifyNotFound();
Tony Barbour18ba25c2016-09-29 13:42:40 -060010024}
10025
Karl Schultz6addd812016-02-02 17:17:23 -070010026TEST_F(VkLayerTest, IdxBufferAlignmentError) {
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010027 // Bind a BeginRenderPass within an active RenderPass
Tony Barbour1fa09702017-03-16 12:09:08 -060010028 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010029 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010030
Jeremy Hayes483d95d2017-03-08 11:03:01 -070010031 uint32_t const indices[] = {0};
10032 VkBufferCreateInfo buf_info = {};
10033 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
10034 buf_info.size = 1024;
10035 buf_info.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
10036 buf_info.queueFamilyIndexCount = 1;
10037 buf_info.pQueueFamilyIndices = indices;
10038
10039 VkBuffer buffer;
10040 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
10041 ASSERT_VK_SUCCESS(err);
10042
10043 VkMemoryRequirements requirements;
10044 vkGetBufferMemoryRequirements(m_device->device(), buffer, &requirements);
10045
10046 VkMemoryAllocateInfo alloc_info{};
10047 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10048 alloc_info.pNext = NULL;
10049 alloc_info.memoryTypeIndex = 0;
10050 alloc_info.allocationSize = requirements.size;
10051 bool pass = m_device->phy().set_memory_type(requirements.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
10052 ASSERT_TRUE(pass);
10053
10054 VkDeviceMemory memory;
10055 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &memory);
10056 ASSERT_VK_SUCCESS(err);
10057
10058 err = vkBindBufferMemory(m_device->device(), buffer, memory, 0);
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010059 ASSERT_VK_SUCCESS(err);
10060
Tony Barbour552f6c02016-12-21 14:34:07 -070010061 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010062 ASSERT_VK_SUCCESS(err);
Jeremy Hayes483d95d2017-03-08 11:03:01 -070010063
Karl Schultz6addd812016-02-02 17:17:23 -070010064 // vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
10065 // VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010066 // Should error before calling to driver so don't care about actual data
Jeremy Hayes483d95d2017-03-08 11:03:01 -070010067 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdBindIndexBuffer() offset (0x7) does not fall on ");
10068 vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), buffer, 7, VK_INDEX_TYPE_UINT16);
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010069 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010070
Jeremy Hayes483d95d2017-03-08 11:03:01 -070010071 vkFreeMemory(m_device->device(), memory, NULL);
10072 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010073}
10074
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -070010075TEST_F(VkLayerTest, InvalidQueueFamilyIndex) {
10076 // Create an out-of-range queueFamilyIndex
Tony Barbour1fa09702017-03-16 12:09:08 -060010077 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -070010078 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10079 VkBufferCreateInfo buffCI = {};
10080 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
10081 buffCI.size = 1024;
Mark Lobodzinski4761d212017-02-28 13:12:44 -070010082 buffCI.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
Jeremy Hayes8a43a0d2017-03-09 11:27:52 -070010083 buffCI.queueFamilyIndexCount = 2;
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -070010084 // Introduce failure by specifying invalid queue_family_index
Mark Lobodzinski4761d212017-02-28 13:12:44 -070010085 uint32_t qfi[2];
10086 qfi[0] = 777;
Jeremy Hayes8a43a0d2017-03-09 11:27:52 -070010087 qfi[1] = 0;
Mark Lobodzinski4761d212017-02-28 13:12:44 -070010088
10089 buffCI.pQueueFamilyIndices = qfi;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010090 buffCI.sharingMode = VK_SHARING_MODE_CONCURRENT; // qfi only matters in CONCURRENT mode
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -070010091
10092 VkBuffer ib;
Jeremy Hayes8a43a0d2017-03-09 11:27:52 -070010093 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Petr Kraus97291752017-05-11 01:05:16 +020010094 "vkCreateBuffer: pCreateInfo->pQueueFamilyIndices[0] (= 777) is not one of the queue "
10095 "families given via VkDeviceQueueCreateInfo structures when the device was created.");
Mark Lobodzinski1f9ebb72017-05-11 15:25:51 -060010096 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010097 m_errorMonitor->VerifyFound();
Mark Lobodzinski4761d212017-02-28 13:12:44 -070010098
10099 if (m_device->queue_props.size() > 2) {
Tony Barbour75db7402017-03-09 14:51:36 -070010100 VkBuffer ib2;
Mark Lobodzinski4761d212017-02-28 13:12:44 -070010101 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which was not created allowing concurrent");
10102
10103 // Create buffer shared to queue families 1 and 2, but submitted on queue family 0
10104 buffCI.queueFamilyIndexCount = 2;
10105 qfi[0] = 1;
10106 qfi[1] = 2;
Tony Barbour75db7402017-03-09 14:51:36 -070010107 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib2);
Mark Lobodzinski4761d212017-02-28 13:12:44 -070010108 VkDeviceMemory mem;
10109 VkMemoryRequirements mem_reqs;
Tony Barbour75db7402017-03-09 14:51:36 -070010110 vkGetBufferMemoryRequirements(m_device->device(), ib2, &mem_reqs);
Mark Lobodzinski4761d212017-02-28 13:12:44 -070010111
10112 VkMemoryAllocateInfo alloc_info = {};
10113 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10114 alloc_info.allocationSize = 1024;
10115 bool pass = false;
10116 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
10117 if (!pass) {
Tony Barbour75db7402017-03-09 14:51:36 -070010118 vkDestroyBuffer(m_device->device(), ib2, NULL);
Mark Lobodzinski4761d212017-02-28 13:12:44 -070010119 return;
10120 }
10121 vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
Tony Barbour75db7402017-03-09 14:51:36 -070010122 vkBindBufferMemory(m_device->device(), ib2, mem, 0);
Mark Lobodzinski4761d212017-02-28 13:12:44 -070010123
10124 m_commandBuffer->begin();
Tony Barbour75db7402017-03-09 14:51:36 -070010125 vkCmdFillBuffer(m_commandBuffer->handle(), ib2, 0, 16, 5);
Mark Lobodzinski4761d212017-02-28 13:12:44 -070010126 m_commandBuffer->end();
10127 QueueCommandBuffer(false);
10128 m_errorMonitor->VerifyFound();
Tony Barbour75db7402017-03-09 14:51:36 -070010129 vkDestroyBuffer(m_device->device(), ib2, NULL);
10130 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski4761d212017-02-28 13:12:44 -070010131 }
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -070010132}
10133
Karl Schultz6addd812016-02-02 17:17:23 -070010134TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010135 TEST_DESCRIPTION(
10136 "Attempt vkCmdExecuteCommands with a primary command buffer"
10137 " (should only be secondary)");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010138
Tony Barbour1fa09702017-03-16 12:09:08 -060010139 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -060010140 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -060010141
Chris Forbesf29a84f2016-10-06 18:39:28 +130010142 // An empty primary command buffer
10143 VkCommandBufferObj cb(m_device, m_commandPool);
10144 cb.BeginCommandBuffer();
10145 cb.EndCommandBuffer();
Tobin Ehlis0c94db02016-07-19 10:49:32 -060010146
Chris Forbesf29a84f2016-10-06 18:39:28 +130010147 m_commandBuffer->BeginCommandBuffer();
10148 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
10149 VkCommandBuffer handle = cb.handle();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -060010150
Chris Forbesf29a84f2016-10-06 18:39:28 +130010151 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdExecuteCommands() called w/ Primary Cmd Buffer ");
10152 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &handle);
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010153 m_errorMonitor->VerifyFound();
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070010154
Tobin Ehlis6d4d1d52017-04-05 12:06:10 -060010155 m_errorMonitor->SetUnexpectedError("All elements of pCommandBuffers must not be in the pending state");
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -060010156}
10157
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010158TEST_F(VkLayerTest, DSUsageBitsErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010159 TEST_DESCRIPTION(
10160 "Attempt to update descriptor sets for images and buffers "
10161 "that do not have correct usage bits sets.");
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010162 VkResult err;
10163
Tony Barbour1fa09702017-03-16 12:09:08 -060010164 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010165 VkDescriptorPoolSize ds_type_count[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
10166 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
10167 ds_type_count[i].type = VkDescriptorType(i);
10168 ds_type_count[i].descriptorCount = 1;
10169 }
10170 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10171 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10172 ds_pool_ci.pNext = NULL;
10173 ds_pool_ci.maxSets = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
10174 ds_pool_ci.poolSizeCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
10175 ds_pool_ci.pPoolSizes = ds_type_count;
10176
10177 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010178 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010179 ASSERT_VK_SUCCESS(err);
10180
10181 // Create 10 layouts where each has a single descriptor of different type
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010182 VkDescriptorSetLayoutBinding dsl_binding[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010183 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
10184 dsl_binding[i].binding = 0;
10185 dsl_binding[i].descriptorType = VkDescriptorType(i);
10186 dsl_binding[i].descriptorCount = 1;
10187 dsl_binding[i].stageFlags = VK_SHADER_STAGE_ALL;
10188 dsl_binding[i].pImmutableSamplers = NULL;
10189 }
10190
10191 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10192 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10193 ds_layout_ci.pNext = NULL;
10194 ds_layout_ci.bindingCount = 1;
10195 VkDescriptorSetLayout ds_layouts[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
10196 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
10197 ds_layout_ci.pBindings = dsl_binding + i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010198 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, ds_layouts + i);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010199 ASSERT_VK_SUCCESS(err);
10200 }
10201 VkDescriptorSet descriptor_sets[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
10202 VkDescriptorSetAllocateInfo alloc_info = {};
10203 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10204 alloc_info.descriptorSetCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
10205 alloc_info.descriptorPool = ds_pool;
10206 alloc_info.pSetLayouts = ds_layouts;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010207 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010208 ASSERT_VK_SUCCESS(err);
10209
10210 // Create a buffer & bufferView to be used for invalid updates
10211 VkBufferCreateInfo buff_ci = {};
10212 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Tony Barbour415497c2017-01-24 10:06:09 -070010213 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010214 buff_ci.size = 256;
10215 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
Tony Barbour415497c2017-01-24 10:06:09 -070010216 VkBuffer buffer, storage_texel_buffer;
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010217 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
10218 ASSERT_VK_SUCCESS(err);
Tony Barbour415497c2017-01-24 10:06:09 -070010219
10220 // Create another buffer to use in testing the UNIFORM_TEXEL_BUFFER case
10221 buff_ci.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
10222 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &storage_texel_buffer);
10223 ASSERT_VK_SUCCESS(err);
10224
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -070010225 VkMemoryRequirements mem_reqs;
10226 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
10227 VkMemoryAllocateInfo mem_alloc_info = {};
10228 mem_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10229 mem_alloc_info.pNext = NULL;
10230 mem_alloc_info.memoryTypeIndex = 0;
10231 mem_alloc_info.allocationSize = mem_reqs.size;
10232 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc_info, 0);
10233 if (!pass) {
10234 vkDestroyBuffer(m_device->device(), buffer, NULL);
10235 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10236 return;
10237 }
10238 VkDeviceMemory mem;
10239 err = vkAllocateMemory(m_device->device(), &mem_alloc_info, NULL, &mem);
10240 ASSERT_VK_SUCCESS(err);
10241 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
10242 ASSERT_VK_SUCCESS(err);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010243
10244 VkBufferViewCreateInfo buff_view_ci = {};
10245 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
10246 buff_view_ci.buffer = buffer;
10247 buff_view_ci.format = VK_FORMAT_R8_UNORM;
10248 buff_view_ci.range = VK_WHOLE_SIZE;
10249 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010250 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010251 ASSERT_VK_SUCCESS(err);
10252
Tony Barbour415497c2017-01-24 10:06:09 -070010253 // Now get resources / view for storage_texel_buffer
10254 vkGetBufferMemoryRequirements(m_device->device(), storage_texel_buffer, &mem_reqs);
10255 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc_info, 0);
10256 if (!pass) {
10257 vkDestroyBuffer(m_device->device(), buffer, NULL);
10258 vkDestroyBufferView(m_device->device(), buff_view, NULL);
10259 vkFreeMemory(m_device->device(), mem, NULL);
10260 vkDestroyBuffer(m_device->device(), storage_texel_buffer, NULL);
10261 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10262 return;
10263 }
10264 VkDeviceMemory storage_texel_buffer_mem;
10265 VkBufferView storage_texel_buffer_view;
10266 err = vkAllocateMemory(m_device->device(), &mem_alloc_info, NULL, &storage_texel_buffer_mem);
10267 ASSERT_VK_SUCCESS(err);
10268 err = vkBindBufferMemory(m_device->device(), storage_texel_buffer, storage_texel_buffer_mem, 0);
10269 ASSERT_VK_SUCCESS(err);
10270 buff_view_ci.buffer = storage_texel_buffer;
10271 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &storage_texel_buffer_view);
10272 ASSERT_VK_SUCCESS(err);
10273
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010274 // Create an image to be used for invalid updates
Tony Barbour4b4a4222017-01-24 11:46:34 -070010275 // Find a format / tiling for COLOR_ATTACHMENT
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010276 VkImageCreateInfo image_ci = {};
Tony Barbour4b4a4222017-01-24 11:46:34 -070010277 image_ci.format = VK_FORMAT_UNDEFINED;
10278 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
10279 VkFormat format = static_cast<VkFormat>(f);
10280 VkFormatProperties fProps = m_device->format_properties(format);
10281 if (fProps.linearTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) {
10282 image_ci.format = format;
10283 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
10284 break;
10285 } else if (fProps.optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) {
10286 image_ci.format = format;
10287 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
10288 break;
10289 }
10290 }
10291 if (image_ci.format == VK_FORMAT_UNDEFINED) {
10292 return;
10293 }
10294
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010295 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10296 image_ci.imageType = VK_IMAGE_TYPE_2D;
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010297 image_ci.extent.width = 64;
10298 image_ci.extent.height = 64;
10299 image_ci.extent.depth = 1;
10300 image_ci.mipLevels = 1;
10301 image_ci.arrayLayers = 1;
10302 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010303 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
Tony Barbour4b4a4222017-01-24 11:46:34 -070010304 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010305 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
10306 VkImage image;
10307 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
10308 ASSERT_VK_SUCCESS(err);
10309 // Bind memory to image
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010310 VkDeviceMemory image_mem;
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -070010311
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010312 VkMemoryAllocateInfo mem_alloc = {};
10313 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10314 mem_alloc.pNext = NULL;
10315 mem_alloc.allocationSize = 0;
10316 mem_alloc.memoryTypeIndex = 0;
10317 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
10318 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010319 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010320 ASSERT_TRUE(pass);
10321 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
10322 ASSERT_VK_SUCCESS(err);
10323 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
10324 ASSERT_VK_SUCCESS(err);
10325 // Now create view for image
10326 VkImageViewCreateInfo image_view_ci = {};
10327 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
10328 image_view_ci.image = image;
Tony Barbour4b4a4222017-01-24 11:46:34 -070010329 image_view_ci.format = image_ci.format;
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010330 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
10331 image_view_ci.subresourceRange.layerCount = 1;
10332 image_view_ci.subresourceRange.baseArrayLayer = 0;
10333 image_view_ci.subresourceRange.levelCount = 1;
10334 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10335 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010336 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010337 ASSERT_VK_SUCCESS(err);
10338
10339 VkDescriptorBufferInfo buff_info = {};
10340 buff_info.buffer = buffer;
10341 VkDescriptorImageInfo img_info = {};
10342 img_info.imageView = image_view;
10343 VkWriteDescriptorSet descriptor_write = {};
10344 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10345 descriptor_write.dstBinding = 0;
10346 descriptor_write.descriptorCount = 1;
10347 descriptor_write.pTexelBufferView = &buff_view;
10348 descriptor_write.pBufferInfo = &buff_info;
10349 descriptor_write.pImageInfo = &img_info;
10350
10351 // These error messages align with VkDescriptorType struct
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -070010352 UNIQUE_VALIDATION_ERROR_CODE error_codes[] = {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010353 VALIDATION_ERROR_00943, // placeholder, no error for SAMPLER descriptor
10354 VALIDATION_ERROR_00943, // COMBINED_IMAGE_SAMPLER
10355 VALIDATION_ERROR_00943, // SAMPLED_IMAGE
10356 VALIDATION_ERROR_00943, // STORAGE_IMAGE
10357 VALIDATION_ERROR_00950, // UNIFORM_TEXEL_BUFFER
10358 VALIDATION_ERROR_00951, // STORAGE_TEXEL_BUFFER
10359 VALIDATION_ERROR_00946, // UNIFORM_BUFFER
10360 VALIDATION_ERROR_00947, // STORAGE_BUFFER
10361 VALIDATION_ERROR_00946, // UNIFORM_BUFFER_DYNAMIC
10362 VALIDATION_ERROR_00947, // STORAGE_BUFFER_DYNAMIC
10363 VALIDATION_ERROR_00943 // INPUT_ATTACHMENT
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -070010364 };
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010365 // Start loop at 1 as SAMPLER desc type has no usage bit error
10366 for (uint32_t i = 1; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
Tony Barbour415497c2017-01-24 10:06:09 -070010367 if (VkDescriptorType(i) == VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER) {
10368 // Now check for UNIFORM_TEXEL_BUFFER using storage_texel_buffer_view
10369 descriptor_write.pTexelBufferView = &storage_texel_buffer_view;
10370 }
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010371 descriptor_write.descriptorType = VkDescriptorType(i);
10372 descriptor_write.dstSet = descriptor_sets[i];
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -070010373 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_codes[i]);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010374
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010375 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010376
10377 m_errorMonitor->VerifyFound();
10378 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[i], NULL);
Tony Barbour415497c2017-01-24 10:06:09 -070010379 if (VkDescriptorType(i) == VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER) {
10380 descriptor_write.pTexelBufferView = &buff_view;
10381 }
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010382 }
Tony Barbour415497c2017-01-24 10:06:09 -070010383
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010384 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[0], NULL);
10385 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -060010386 vkFreeMemory(m_device->device(), image_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010387 vkDestroyImageView(m_device->device(), image_view, NULL);
10388 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tony Barbour415497c2017-01-24 10:06:09 -070010389 vkDestroyBuffer(m_device->device(), storage_texel_buffer, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010390 vkDestroyBufferView(m_device->device(), buff_view, NULL);
Tony Barbour415497c2017-01-24 10:06:09 -070010391 vkDestroyBufferView(m_device->device(), storage_texel_buffer_view, NULL);
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -070010392 vkFreeMemory(m_device->device(), mem, NULL);
Tony Barbour415497c2017-01-24 10:06:09 -070010393 vkFreeMemory(m_device->device(), storage_texel_buffer_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010394 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10395}
10396
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010397TEST_F(VkLayerTest, DSBufferInfoErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010398 TEST_DESCRIPTION(
10399 "Attempt to update buffer descriptor set that has incorrect "
10400 "parameters in VkDescriptorBufferInfo struct. This includes:\n"
Jeremy Hayesd1a6a822017-03-09 14:39:45 -070010401 "1. offset value greater than or equal to buffer size\n"
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010402 "2. range value of 0\n"
10403 "3. range value greater than buffer (size - offset)");
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010404 VkResult err;
10405
Tony Barbour1fa09702017-03-16 12:09:08 -060010406 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010407 VkDescriptorPoolSize ds_type_count = {};
10408 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10409 ds_type_count.descriptorCount = 1;
10410
10411 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10412 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10413 ds_pool_ci.pNext = NULL;
Jeremy Hayesd1a6a822017-03-09 14:39:45 -070010414 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010415 ds_pool_ci.maxSets = 1;
10416 ds_pool_ci.poolSizeCount = 1;
10417 ds_pool_ci.pPoolSizes = &ds_type_count;
10418
10419 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010420 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010421 ASSERT_VK_SUCCESS(err);
10422
10423 // Create layout with single uniform buffer descriptor
10424 VkDescriptorSetLayoutBinding dsl_binding = {};
10425 dsl_binding.binding = 0;
10426 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10427 dsl_binding.descriptorCount = 1;
10428 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10429 dsl_binding.pImmutableSamplers = NULL;
10430
10431 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10432 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10433 ds_layout_ci.pNext = NULL;
10434 ds_layout_ci.bindingCount = 1;
10435 ds_layout_ci.pBindings = &dsl_binding;
10436 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010437 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010438 ASSERT_VK_SUCCESS(err);
10439
10440 VkDescriptorSet descriptor_set = {};
10441 VkDescriptorSetAllocateInfo alloc_info = {};
10442 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10443 alloc_info.descriptorSetCount = 1;
10444 alloc_info.descriptorPool = ds_pool;
10445 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010446 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010447 ASSERT_VK_SUCCESS(err);
10448
10449 // Create a buffer to be used for invalid updates
10450 VkBufferCreateInfo buff_ci = {};
10451 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
10452 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
Jeremy Hayesd1a6a822017-03-09 14:39:45 -070010453 buff_ci.size = m_device->props.limits.minUniformBufferOffsetAlignment;
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010454 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
10455 VkBuffer buffer;
10456 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
10457 ASSERT_VK_SUCCESS(err);
Jeremy Hayesd1a6a822017-03-09 14:39:45 -070010458
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010459 // Have to bind memory to buffer before descriptor update
10460 VkMemoryAllocateInfo mem_alloc = {};
10461 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10462 mem_alloc.pNext = NULL;
Jeremy Hayesd1a6a822017-03-09 14:39:45 -070010463 mem_alloc.allocationSize = buff_ci.size;
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010464 mem_alloc.memoryTypeIndex = 0;
10465
10466 VkMemoryRequirements mem_reqs;
10467 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010468 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010469 if (!pass) {
10470 vkDestroyBuffer(m_device->device(), buffer, NULL);
10471 return;
10472 }
10473
10474 VkDeviceMemory mem;
10475 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
10476 ASSERT_VK_SUCCESS(err);
10477 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
10478 ASSERT_VK_SUCCESS(err);
10479
10480 VkDescriptorBufferInfo buff_info = {};
10481 buff_info.buffer = buffer;
Jeremy Hayesd1a6a822017-03-09 14:39:45 -070010482 // Cause error due to offset out of range
10483 buff_info.offset = buff_ci.size;
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010484 buff_info.range = VK_WHOLE_SIZE;
10485 VkWriteDescriptorSet descriptor_write = {};
10486 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10487 descriptor_write.dstBinding = 0;
10488 descriptor_write.descriptorCount = 1;
10489 descriptor_write.pTexelBufferView = nullptr;
10490 descriptor_write.pBufferInfo = &buff_info;
10491 descriptor_write.pImageInfo = nullptr;
10492
10493 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10494 descriptor_write.dstSet = descriptor_set;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070010495 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00959);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010496
10497 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10498
10499 m_errorMonitor->VerifyFound();
10500 // Now cause error due to range of 0
10501 buff_info.offset = 0;
10502 buff_info.range = 0;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070010503 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00960);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010504
10505 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10506
10507 m_errorMonitor->VerifyFound();
10508 // Now cause error due to range exceeding buffer size - offset
Jeremy Hayesd1a6a822017-03-09 14:39:45 -070010509 buff_info.offset = 0;
10510 buff_info.range = buff_ci.size + 1;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070010511 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00961);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010512
10513 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10514
10515 m_errorMonitor->VerifyFound();
Mark Lobodzinski4bb54092016-07-06 14:27:19 -060010516 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010517 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10518 vkDestroyBuffer(m_device->device(), buffer, NULL);
10519 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
10520 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10521}
10522
Tobin Ehlis845887e2017-02-02 19:01:44 -070010523TEST_F(VkLayerTest, DSBufferLimitErrors) {
10524 TEST_DESCRIPTION(
10525 "Attempt to update buffer descriptor set that has VkDescriptorBufferInfo values that violate device limits.\n"
10526 "Test cases include:\n"
10527 "1. range of uniform buffer update exceeds maxUniformBufferRange\n"
10528 "2. offset of uniform buffer update is not multiple of minUniformBufferOffsetAlignment\n"
10529 "3. range of storage buffer update exceeds maxStorageBufferRange\n"
10530 "4. offset of storage buffer update is not multiple of minStorageBufferOffsetAlignment");
10531 VkResult err;
10532
Tony Barbour1fa09702017-03-16 12:09:08 -060010533 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis845887e2017-02-02 19:01:44 -070010534 VkDescriptorPoolSize ds_type_count[2] = {};
10535 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10536 ds_type_count[0].descriptorCount = 1;
10537 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
10538 ds_type_count[1].descriptorCount = 1;
10539
10540 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10541 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10542 ds_pool_ci.pNext = NULL;
10543 ds_pool_ci.maxSets = 1;
10544 ds_pool_ci.poolSizeCount = 2;
10545 ds_pool_ci.pPoolSizes = ds_type_count;
10546
10547 VkDescriptorPool ds_pool;
10548 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
10549 ASSERT_VK_SUCCESS(err);
10550
10551 // Create layout with single uniform buffer & single storage buffer descriptor
10552 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
10553 dsl_binding[0].binding = 0;
10554 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10555 dsl_binding[0].descriptorCount = 1;
10556 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
10557 dsl_binding[0].pImmutableSamplers = NULL;
10558 dsl_binding[1].binding = 1;
10559 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
10560 dsl_binding[1].descriptorCount = 1;
10561 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
10562 dsl_binding[1].pImmutableSamplers = NULL;
10563
10564 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10565 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10566 ds_layout_ci.pNext = NULL;
10567 ds_layout_ci.bindingCount = 2;
10568 ds_layout_ci.pBindings = dsl_binding;
10569 VkDescriptorSetLayout ds_layout;
10570 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
10571 ASSERT_VK_SUCCESS(err);
10572
10573 VkDescriptorSet descriptor_set = {};
10574 VkDescriptorSetAllocateInfo alloc_info = {};
10575 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10576 alloc_info.descriptorSetCount = 1;
10577 alloc_info.descriptorPool = ds_pool;
10578 alloc_info.pSetLayouts = &ds_layout;
10579 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
10580 ASSERT_VK_SUCCESS(err);
10581
10582 // Create a buffer to be used for invalid updates
10583 auto max_ub_range = m_device->props.limits.maxUniformBufferRange;
10584 auto min_ub_align = m_device->props.limits.minUniformBufferOffsetAlignment;
10585 auto max_sb_range = m_device->props.limits.maxStorageBufferRange;
10586 auto min_sb_align = m_device->props.limits.minStorageBufferOffsetAlignment;
10587 VkBufferCreateInfo ub_ci = {};
10588 ub_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
10589 ub_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
10590 ub_ci.size = max_ub_range + 128; // Make buffer bigger than range limit
10591 ub_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
10592 VkBuffer uniform_buffer;
10593 err = vkCreateBuffer(m_device->device(), &ub_ci, NULL, &uniform_buffer);
10594 ASSERT_VK_SUCCESS(err);
10595 VkBufferCreateInfo sb_ci = {};
10596 sb_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
10597 sb_ci.usage = VK_BUFFER_USAGE_STORAGE_BUFFER_BIT;
10598 sb_ci.size = max_sb_range + 128; // Make buffer bigger than range limit
10599 sb_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
10600 VkBuffer storage_buffer;
10601 err = vkCreateBuffer(m_device->device(), &sb_ci, NULL, &storage_buffer);
10602 ASSERT_VK_SUCCESS(err);
10603 // Have to bind memory to buffer before descriptor update
10604 VkMemoryAllocateInfo mem_alloc = {};
10605 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10606 mem_alloc.pNext = NULL;
10607 mem_alloc.allocationSize = ub_ci.size + sb_ci.size + 1024; // additional buffer for offset
10608 mem_alloc.memoryTypeIndex = 0;
10609
Cort Stratton77a0d592017-02-17 13:14:13 -080010610 VkMemoryRequirements ub_mem_reqs, sb_mem_reqs;
10611 vkGetBufferMemoryRequirements(m_device->device(), uniform_buffer, &ub_mem_reqs);
10612 bool pass = m_device->phy().set_memory_type(ub_mem_reqs.memoryTypeBits, &mem_alloc, 0);
10613 vkGetBufferMemoryRequirements(m_device->device(), storage_buffer, &sb_mem_reqs);
10614 pass &= m_device->phy().set_memory_type(sb_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis845887e2017-02-02 19:01:44 -070010615 if (!pass) {
Tobin Ehlis15c83792017-02-07 10:09:33 -070010616 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Tobin Ehlis845887e2017-02-02 19:01:44 -070010617 vkDestroyBuffer(m_device->device(), uniform_buffer, NULL);
Tobin Ehlis15c83792017-02-07 10:09:33 -070010618 vkDestroyBuffer(m_device->device(), storage_buffer, NULL);
10619 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis845887e2017-02-02 19:01:44 -070010620 return;
10621 }
10622
10623 VkDeviceMemory mem;
10624 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlis15c83792017-02-07 10:09:33 -070010625 if (VK_SUCCESS != err) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070010626 printf(" Failed to allocate memory in DSBufferLimitErrors; skipped.\n");
Tobin Ehlis15c83792017-02-07 10:09:33 -070010627 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10628 vkDestroyBuffer(m_device->device(), uniform_buffer, NULL);
10629 vkDestroyBuffer(m_device->device(), storage_buffer, NULL);
10630 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10631 return;
10632 }
Tobin Ehlis845887e2017-02-02 19:01:44 -070010633 ASSERT_VK_SUCCESS(err);
10634 err = vkBindBufferMemory(m_device->device(), uniform_buffer, mem, 0);
10635 ASSERT_VK_SUCCESS(err);
Cort Stratton77a0d592017-02-17 13:14:13 -080010636 auto sb_offset = (ub_ci.size + sb_mem_reqs.alignment - 1) & ~(sb_mem_reqs.alignment - 1);
Tobin Ehlis845887e2017-02-02 19:01:44 -070010637 err = vkBindBufferMemory(m_device->device(), storage_buffer, mem, sb_offset);
10638 ASSERT_VK_SUCCESS(err);
10639
10640 VkDescriptorBufferInfo buff_info = {};
10641 buff_info.buffer = uniform_buffer;
10642 buff_info.range = ub_ci.size; // This will exceed limit
10643 VkWriteDescriptorSet descriptor_write = {};
10644 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10645 descriptor_write.dstBinding = 0;
10646 descriptor_write.descriptorCount = 1;
10647 descriptor_write.pTexelBufferView = nullptr;
10648 descriptor_write.pBufferInfo = &buff_info;
10649 descriptor_write.pImageInfo = nullptr;
10650
10651 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10652 descriptor_write.dstSet = descriptor_set;
Tony Barbour02d08552017-03-24 16:36:01 -060010653 if (max_ub_range != UINT32_MAX) {
10654 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00948);
10655 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10656 m_errorMonitor->VerifyFound();
10657 }
Tobin Ehlis845887e2017-02-02 19:01:44 -070010658 // Reduce size of range to acceptable limit & cause offset error
10659 buff_info.range = max_ub_range;
10660 buff_info.offset = min_ub_align - 1;
10661 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00944);
10662 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10663 m_errorMonitor->VerifyFound();
10664
10665 // Now break storage updates
10666 buff_info.buffer = storage_buffer;
10667 buff_info.range = sb_ci.size; // This will exceed limit
10668 buff_info.offset = 0; // Reset offset for this update
10669
10670 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
10671 descriptor_write.dstBinding = 1;
Tony Barbour02d08552017-03-24 16:36:01 -060010672 if (max_ub_range != UINT32_MAX) {
10673 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00949);
10674 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10675 m_errorMonitor->VerifyFound();
10676 }
Tobin Ehlis845887e2017-02-02 19:01:44 -070010677
10678 // Reduce size of range to acceptable limit & cause offset error
10679 buff_info.range = max_sb_range;
10680 buff_info.offset = min_sb_align - 1;
10681 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00945);
10682 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10683 m_errorMonitor->VerifyFound();
10684
10685 vkFreeMemory(m_device->device(), mem, NULL);
10686 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10687 vkDestroyBuffer(m_device->device(), uniform_buffer, NULL);
10688 vkDestroyBuffer(m_device->device(), storage_buffer, NULL);
10689 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10690}
10691
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010692TEST_F(VkLayerTest, DSAspectBitsErrors) {
10693 // TODO : Initially only catching case where DEPTH & STENCIL aspect bits
10694 // are set, but could expand this test to hit more cases.
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010695 TEST_DESCRIPTION(
10696 "Attempt to update descriptor sets for images "
10697 "that do not have correct aspect bits sets.");
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010698 VkResult err;
10699
Tony Barbour1fa09702017-03-16 12:09:08 -060010700 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -060010701 auto depth_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbourf887b162017-03-09 10:06:46 -070010702 if (!depth_format) {
10703 printf(" No Depth + Stencil format found. Skipped.\n");
10704 return;
10705 }
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010706 VkDescriptorPoolSize ds_type_count = {};
10707 ds_type_count.type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
10708 ds_type_count.descriptorCount = 1;
10709
10710 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10711 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10712 ds_pool_ci.pNext = NULL;
Jeremy Hayes293c7ed2017-03-09 14:47:07 -070010713 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010714 ds_pool_ci.maxSets = 5;
10715 ds_pool_ci.poolSizeCount = 1;
10716 ds_pool_ci.pPoolSizes = &ds_type_count;
10717
10718 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010719 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010720 ASSERT_VK_SUCCESS(err);
10721
10722 VkDescriptorSetLayoutBinding dsl_binding = {};
10723 dsl_binding.binding = 0;
10724 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
10725 dsl_binding.descriptorCount = 1;
10726 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10727 dsl_binding.pImmutableSamplers = NULL;
10728
10729 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10730 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10731 ds_layout_ci.pNext = NULL;
10732 ds_layout_ci.bindingCount = 1;
10733 ds_layout_ci.pBindings = &dsl_binding;
10734 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010735 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010736 ASSERT_VK_SUCCESS(err);
10737
10738 VkDescriptorSet descriptor_set = {};
10739 VkDescriptorSetAllocateInfo alloc_info = {};
10740 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10741 alloc_info.descriptorSetCount = 1;
10742 alloc_info.descriptorPool = ds_pool;
10743 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010744 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010745 ASSERT_VK_SUCCESS(err);
10746
10747 // Create an image to be used for invalid updates
10748 VkImageCreateInfo image_ci = {};
10749 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10750 image_ci.imageType = VK_IMAGE_TYPE_2D;
Tony Barbourf887b162017-03-09 10:06:46 -070010751 image_ci.format = depth_format;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010752 image_ci.extent.width = 64;
10753 image_ci.extent.height = 64;
10754 image_ci.extent.depth = 1;
10755 image_ci.mipLevels = 1;
10756 image_ci.arrayLayers = 1;
10757 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Young2d1fa302017-03-02 10:13:09 -070010758 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010759 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
10760 image_ci.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
10761 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
10762 VkImage image;
10763 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
10764 ASSERT_VK_SUCCESS(err);
10765 // Bind memory to image
10766 VkMemoryRequirements mem_reqs;
10767 VkDeviceMemory image_mem;
10768 bool pass;
10769 VkMemoryAllocateInfo mem_alloc = {};
10770 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10771 mem_alloc.pNext = NULL;
10772 mem_alloc.allocationSize = 0;
10773 mem_alloc.memoryTypeIndex = 0;
10774 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
10775 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010776 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010777 ASSERT_TRUE(pass);
10778 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
10779 ASSERT_VK_SUCCESS(err);
10780 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
10781 ASSERT_VK_SUCCESS(err);
10782 // Now create view for image
10783 VkImageViewCreateInfo image_view_ci = {};
10784 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
10785 image_view_ci.image = image;
Tony Barbourf887b162017-03-09 10:06:46 -070010786 image_view_ci.format = depth_format;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010787 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
10788 image_view_ci.subresourceRange.layerCount = 1;
10789 image_view_ci.subresourceRange.baseArrayLayer = 0;
10790 image_view_ci.subresourceRange.levelCount = 1;
10791 // Setting both depth & stencil aspect bits is illegal for descriptor
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010792 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010793
10794 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010795 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010796 ASSERT_VK_SUCCESS(err);
10797
10798 VkDescriptorImageInfo img_info = {};
10799 img_info.imageView = image_view;
10800 VkWriteDescriptorSet descriptor_write = {};
10801 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10802 descriptor_write.dstBinding = 0;
10803 descriptor_write.descriptorCount = 1;
10804 descriptor_write.pTexelBufferView = NULL;
10805 descriptor_write.pBufferInfo = NULL;
10806 descriptor_write.pImageInfo = &img_info;
10807 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
10808 descriptor_write.dstSet = descriptor_set;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010809 const char *error_msg =
10810 " please only set either VK_IMAGE_ASPECT_DEPTH_BIT "
10811 "or VK_IMAGE_ASPECT_STENCIL_BIT ";
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010812 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msg);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010813
10814 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10815
10816 m_errorMonitor->VerifyFound();
10817 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10818 vkDestroyImage(m_device->device(), image, NULL);
10819 vkFreeMemory(m_device->device(), image_mem, NULL);
10820 vkDestroyImageView(m_device->device(), image_view, NULL);
10821 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
10822 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10823}
10824
Karl Schultz6addd812016-02-02 17:17:23 -070010825TEST_F(VkLayerTest, DSTypeMismatch) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010826 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Karl Schultz6addd812016-02-02 17:17:23 -070010827 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010828
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010829 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10830 " binding #0 with type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER but update "
10831 "type is VK_DESCRIPTOR_TYPE_SAMPLER");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010832
Tony Barbour1fa09702017-03-16 12:09:08 -060010833 ASSERT_NO_FATAL_FAILURE(Init());
Karl Schultz6addd812016-02-02 17:17:23 -070010834 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010835 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010836 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10837 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010838
10839 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010840 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10841 ds_pool_ci.pNext = NULL;
10842 ds_pool_ci.maxSets = 1;
10843 ds_pool_ci.poolSizeCount = 1;
10844 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060010845
Tobin Ehlis3b780662015-05-28 12:11:26 -060010846 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010847 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010848 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -060010849 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010850 dsl_binding.binding = 0;
10851 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10852 dsl_binding.descriptorCount = 1;
10853 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10854 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010855
Tony Barboureb254902015-07-15 12:50:33 -060010856 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010857 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10858 ds_layout_ci.pNext = NULL;
10859 ds_layout_ci.bindingCount = 1;
10860 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010861
Tobin Ehlis3b780662015-05-28 12:11:26 -060010862 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010863 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010864 ASSERT_VK_SUCCESS(err);
10865
10866 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010867 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010868 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010869 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010870 alloc_info.descriptorPool = ds_pool;
10871 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010872 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010873 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010874
Tobin Ehlis30db8f82016-05-05 08:19:48 -060010875 VkSamplerCreateInfo sampler_ci = {};
10876 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10877 sampler_ci.pNext = NULL;
10878 sampler_ci.magFilter = VK_FILTER_NEAREST;
10879 sampler_ci.minFilter = VK_FILTER_NEAREST;
10880 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10881 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10882 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10883 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10884 sampler_ci.mipLodBias = 1.0;
10885 sampler_ci.anisotropyEnable = VK_FALSE;
10886 sampler_ci.maxAnisotropy = 1;
10887 sampler_ci.compareEnable = VK_FALSE;
10888 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10889 sampler_ci.minLod = 1.0;
10890 sampler_ci.maxLod = 1.0;
10891 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10892 sampler_ci.unnormalizedCoordinates = VK_FALSE;
10893 VkSampler sampler;
10894 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
10895 ASSERT_VK_SUCCESS(err);
10896
10897 VkDescriptorImageInfo info = {};
10898 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010899
10900 VkWriteDescriptorSet descriptor_write;
10901 memset(&descriptor_write, 0, sizeof(descriptor_write));
10902 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010903 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010904 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010905 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010906 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060010907 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010908
10909 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10910
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010911 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010912
Chia-I Wuf7458c52015-10-26 21:10:41 +080010913 vkDestroySampler(m_device->device(), sampler, NULL);
10914 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10915 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010916}
10917
Karl Schultz6addd812016-02-02 17:17:23 -070010918TEST_F(VkLayerTest, DSUpdateOutOfBounds) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010919 // For overlapping Update, have arrayIndex exceed that of layout
Karl Schultz6addd812016-02-02 17:17:23 -070010920 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010921
Tobin Ehlisf922ef82016-11-30 10:19:14 -070010922 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00938);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010923
Tony Barbour1fa09702017-03-16 12:09:08 -060010924 ASSERT_NO_FATAL_FAILURE(Init());
Karl Schultz6addd812016-02-02 17:17:23 -070010925 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010926 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010927 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10928 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010929
10930 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010931 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10932 ds_pool_ci.pNext = NULL;
10933 ds_pool_ci.maxSets = 1;
10934 ds_pool_ci.poolSizeCount = 1;
10935 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060010936
Tobin Ehlis3b780662015-05-28 12:11:26 -060010937 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010938 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010939 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010940
Tony Barboureb254902015-07-15 12:50:33 -060010941 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010942 dsl_binding.binding = 0;
10943 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10944 dsl_binding.descriptorCount = 1;
10945 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10946 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -060010947
10948 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010949 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10950 ds_layout_ci.pNext = NULL;
10951 ds_layout_ci.bindingCount = 1;
10952 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010953
Tobin Ehlis3b780662015-05-28 12:11:26 -060010954 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010955 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010956 ASSERT_VK_SUCCESS(err);
10957
10958 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010959 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010960 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010961 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010962 alloc_info.descriptorPool = ds_pool;
10963 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010964 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010965 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010966
Jeremy Hayesd5b95db2017-03-09 15:24:24 -070010967 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
10968
Tobin Ehlis30db8f82016-05-05 08:19:48 -060010969 // Correctly update descriptor to avoid "NOT_UPDATED" error
10970 VkDescriptorBufferInfo buff_info = {};
Jeremy Hayesd5b95db2017-03-09 15:24:24 -070010971 buff_info.buffer = buffer_test.GetBuffer();
Tobin Ehlis30db8f82016-05-05 08:19:48 -060010972 buff_info.offset = 0;
10973 buff_info.range = 1024;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010974
10975 VkWriteDescriptorSet descriptor_write;
10976 memset(&descriptor_write, 0, sizeof(descriptor_write));
10977 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010978 descriptor_write.dstSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010979 descriptor_write.dstArrayElement = 1; /* This index out of bounds for the update */
Chia-I Wud50a7d72015-10-26 20:48:51 +080010980 descriptor_write.descriptorCount = 1;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -060010981 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10982 descriptor_write.pBufferInfo = &buff_info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010983
10984 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10985
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010986 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010987
Chia-I Wuf7458c52015-10-26 21:10:41 +080010988 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10989 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010990}
10991
Karl Schultz6addd812016-02-02 17:17:23 -070010992TEST_F(VkLayerTest, InvalidDSUpdateIndex) {
Tobin Ehlisc8d352d2016-11-21 10:33:40 -070010993 // Create layout w/ count of 1 and attempt update to that layout w/ binding index 2
Karl Schultz6addd812016-02-02 17:17:23 -070010994 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010995
Tobin Ehlisc8d352d2016-11-21 10:33:40 -070010996 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00936);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010997
Tony Barbour1fa09702017-03-16 12:09:08 -060010998 ASSERT_NO_FATAL_FAILURE(Init());
Karl Schultz6addd812016-02-02 17:17:23 -070010999 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011000 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011001 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11002 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011003
11004 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011005 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11006 ds_pool_ci.pNext = NULL;
11007 ds_pool_ci.maxSets = 1;
11008 ds_pool_ci.poolSizeCount = 1;
11009 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060011010
Tobin Ehlis3b780662015-05-28 12:11:26 -060011011 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011012 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011013 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011014
Tony Barboureb254902015-07-15 12:50:33 -060011015 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011016 dsl_binding.binding = 0;
11017 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11018 dsl_binding.descriptorCount = 1;
11019 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11020 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -060011021
11022 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011023 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11024 ds_layout_ci.pNext = NULL;
11025 ds_layout_ci.bindingCount = 1;
11026 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011027 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011028 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011029 ASSERT_VK_SUCCESS(err);
11030
11031 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011032 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011033 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011034 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011035 alloc_info.descriptorPool = ds_pool;
11036 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011037 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011038 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011039
Tony Barboureb254902015-07-15 12:50:33 -060011040 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011041 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11042 sampler_ci.pNext = NULL;
11043 sampler_ci.magFilter = VK_FILTER_NEAREST;
11044 sampler_ci.minFilter = VK_FILTER_NEAREST;
11045 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11046 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11047 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11048 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11049 sampler_ci.mipLodBias = 1.0;
11050 sampler_ci.anisotropyEnable = VK_FALSE;
11051 sampler_ci.maxAnisotropy = 1;
11052 sampler_ci.compareEnable = VK_FALSE;
11053 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11054 sampler_ci.minLod = 1.0;
11055 sampler_ci.maxLod = 1.0;
11056 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11057 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -060011058
Tobin Ehlis3b780662015-05-28 12:11:26 -060011059 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011060 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011061 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011062
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060011063 VkDescriptorImageInfo info = {};
11064 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011065
11066 VkWriteDescriptorSet descriptor_write;
11067 memset(&descriptor_write, 0, sizeof(descriptor_write));
11068 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011069 descriptor_write.dstSet = descriptorSet;
11070 descriptor_write.dstBinding = 2;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011071 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011072 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011073 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060011074 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011075
11076 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11077
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011078 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011079
Chia-I Wuf7458c52015-10-26 21:10:41 +080011080 vkDestroySampler(m_device->device(), sampler, NULL);
11081 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11082 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060011083}
11084
Tobin Ehlise202b2d2016-11-21 10:36:16 -070011085TEST_F(VkLayerTest, DSUpdateEmptyBinding) {
11086 // Create layout w/ empty binding and attempt to update it
11087 VkResult err;
11088
Tony Barbour1fa09702017-03-16 12:09:08 -060011089 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlise202b2d2016-11-21 10:36:16 -070011090
11091 VkDescriptorPoolSize ds_type_count = {};
11092 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
11093 ds_type_count.descriptorCount = 1;
11094
11095 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11096 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11097 ds_pool_ci.pNext = NULL;
11098 ds_pool_ci.maxSets = 1;
11099 ds_pool_ci.poolSizeCount = 1;
11100 ds_pool_ci.pPoolSizes = &ds_type_count;
11101
11102 VkDescriptorPool ds_pool;
11103 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
11104 ASSERT_VK_SUCCESS(err);
11105
11106 VkDescriptorSetLayoutBinding dsl_binding = {};
11107 dsl_binding.binding = 0;
11108 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
11109 dsl_binding.descriptorCount = 0;
11110 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11111 dsl_binding.pImmutableSamplers = NULL;
11112
11113 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11114 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11115 ds_layout_ci.pNext = NULL;
11116 ds_layout_ci.bindingCount = 1;
11117 ds_layout_ci.pBindings = &dsl_binding;
11118 VkDescriptorSetLayout ds_layout;
11119 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
11120 ASSERT_VK_SUCCESS(err);
11121
11122 VkDescriptorSet descriptor_set;
11123 VkDescriptorSetAllocateInfo alloc_info = {};
11124 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11125 alloc_info.descriptorSetCount = 1;
11126 alloc_info.descriptorPool = ds_pool;
11127 alloc_info.pSetLayouts = &ds_layout;
11128 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
11129 ASSERT_VK_SUCCESS(err);
11130
11131 VkSamplerCreateInfo sampler_ci = {};
11132 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11133 sampler_ci.magFilter = VK_FILTER_NEAREST;
11134 sampler_ci.minFilter = VK_FILTER_NEAREST;
11135 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11136 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11137 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11138 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11139 sampler_ci.mipLodBias = 1.0;
11140 sampler_ci.maxAnisotropy = 1;
11141 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11142 sampler_ci.minLod = 1.0;
11143 sampler_ci.maxLod = 1.0;
11144 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11145
11146 VkSampler sampler;
11147 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
11148 ASSERT_VK_SUCCESS(err);
11149
11150 VkDescriptorImageInfo info = {};
11151 info.sampler = sampler;
11152
11153 VkWriteDescriptorSet descriptor_write;
11154 memset(&descriptor_write, 0, sizeof(descriptor_write));
11155 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11156 descriptor_write.dstSet = descriptor_set;
11157 descriptor_write.dstBinding = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011158 descriptor_write.descriptorCount = 1; // Lie here to avoid parameter_validation error
Tobin Ehlise202b2d2016-11-21 10:36:16 -070011159 // This is the wrong type, but empty binding error will be flagged first
11160 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
11161 descriptor_write.pImageInfo = &info;
11162
11163 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02348);
11164 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11165 m_errorMonitor->VerifyFound();
11166
11167 vkDestroySampler(m_device->device(), sampler, NULL);
11168 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11169 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11170}
11171
Karl Schultz6addd812016-02-02 17:17:23 -070011172TEST_F(VkLayerTest, InvalidDSUpdateStruct) {
11173 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_*
11174 // types
11175 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011176
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011177 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 -060011178
Tony Barbour1fa09702017-03-16 12:09:08 -060011179 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011180
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011181 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011182 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11183 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011184
11185 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011186 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11187 ds_pool_ci.pNext = NULL;
11188 ds_pool_ci.maxSets = 1;
11189 ds_pool_ci.poolSizeCount = 1;
11190 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060011191
Tobin Ehlis3b780662015-05-28 12:11:26 -060011192 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011193 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011194 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -060011195 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011196 dsl_binding.binding = 0;
11197 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11198 dsl_binding.descriptorCount = 1;
11199 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11200 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011201
Tony Barboureb254902015-07-15 12:50:33 -060011202 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011203 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11204 ds_layout_ci.pNext = NULL;
11205 ds_layout_ci.bindingCount = 1;
11206 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060011207
Tobin Ehlis3b780662015-05-28 12:11:26 -060011208 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011209 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011210 ASSERT_VK_SUCCESS(err);
11211
11212 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011213 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011214 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011215 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011216 alloc_info.descriptorPool = ds_pool;
11217 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011218 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011219 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011220
Tony Barboureb254902015-07-15 12:50:33 -060011221 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011222 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11223 sampler_ci.pNext = NULL;
11224 sampler_ci.magFilter = VK_FILTER_NEAREST;
11225 sampler_ci.minFilter = VK_FILTER_NEAREST;
11226 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11227 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11228 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11229 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11230 sampler_ci.mipLodBias = 1.0;
11231 sampler_ci.anisotropyEnable = VK_FALSE;
11232 sampler_ci.maxAnisotropy = 1;
11233 sampler_ci.compareEnable = VK_FALSE;
11234 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11235 sampler_ci.minLod = 1.0;
11236 sampler_ci.maxLod = 1.0;
11237 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11238 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011239 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011240 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011241 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011242
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060011243 VkDescriptorImageInfo info = {};
11244 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011245
11246 VkWriteDescriptorSet descriptor_write;
11247 memset(&descriptor_write, 0, sizeof(descriptor_write));
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011248 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011249 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011250 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011251 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011252 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060011253 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011254
11255 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11256
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011257 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011258
Chia-I Wuf7458c52015-10-26 21:10:41 +080011259 vkDestroySampler(m_device->device(), sampler, NULL);
11260 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11261 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060011262}
11263
Karl Schultz6addd812016-02-02 17:17:23 -070011264TEST_F(VkLayerTest, SampleDescriptorUpdateError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011265 // Create a single Sampler descriptor and send it an invalid Sampler
Karl Schultz6addd812016-02-02 17:17:23 -070011266 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011267
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070011268 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00942);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011269
Tony Barbour1fa09702017-03-16 12:09:08 -060011270 ASSERT_NO_FATAL_FAILURE(Init());
Karl Schultz6addd812016-02-02 17:17:23 -070011271 // TODO : Farm Descriptor setup code to helper function(s) to reduce copied
11272 // code
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011273 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011274 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
11275 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011276
11277 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011278 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11279 ds_pool_ci.pNext = NULL;
11280 ds_pool_ci.maxSets = 1;
11281 ds_pool_ci.poolSizeCount = 1;
11282 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011283
11284 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011285 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011286 ASSERT_VK_SUCCESS(err);
11287
11288 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011289 dsl_binding.binding = 0;
11290 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
11291 dsl_binding.descriptorCount = 1;
11292 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11293 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011294
11295 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011296 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11297 ds_layout_ci.pNext = NULL;
11298 ds_layout_ci.bindingCount = 1;
11299 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011300 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011301 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011302 ASSERT_VK_SUCCESS(err);
11303
11304 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011305 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011306 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011307 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011308 alloc_info.descriptorPool = ds_pool;
11309 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011310 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011311 ASSERT_VK_SUCCESS(err);
11312
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011313 VkSampler sampler = (VkSampler)((size_t)0xbaadbeef); // Sampler with invalid handle
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011314
11315 VkDescriptorImageInfo descriptor_info;
11316 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
11317 descriptor_info.sampler = sampler;
11318
11319 VkWriteDescriptorSet descriptor_write;
11320 memset(&descriptor_write, 0, sizeof(descriptor_write));
11321 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011322 descriptor_write.dstSet = descriptorSet;
11323 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011324 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011325 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
11326 descriptor_write.pImageInfo = &descriptor_info;
11327
11328 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11329
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011330 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011331
Chia-I Wuf7458c52015-10-26 21:10:41 +080011332 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11333 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011334}
11335
Karl Schultz6addd812016-02-02 17:17:23 -070011336TEST_F(VkLayerTest, ImageViewDescriptorUpdateError) {
11337 // Create a single combined Image/Sampler descriptor and send it an invalid
11338 // imageView
11339 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011340
Karl Schultzf78bcdd2016-11-30 12:36:01 -070011341 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00943);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011342
Tony Barbour1fa09702017-03-16 12:09:08 -060011343 ASSERT_NO_FATAL_FAILURE(Init());
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011344 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011345 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11346 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011347
11348 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011349 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11350 ds_pool_ci.pNext = NULL;
11351 ds_pool_ci.maxSets = 1;
11352 ds_pool_ci.poolSizeCount = 1;
11353 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011354
11355 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011356 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011357 ASSERT_VK_SUCCESS(err);
11358
11359 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011360 dsl_binding.binding = 0;
11361 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11362 dsl_binding.descriptorCount = 1;
11363 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11364 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011365
11366 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011367 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11368 ds_layout_ci.pNext = NULL;
11369 ds_layout_ci.bindingCount = 1;
11370 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011371 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011372 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011373 ASSERT_VK_SUCCESS(err);
11374
11375 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011376 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011377 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011378 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011379 alloc_info.descriptorPool = ds_pool;
11380 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011381 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011382 ASSERT_VK_SUCCESS(err);
11383
11384 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011385 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11386 sampler_ci.pNext = NULL;
11387 sampler_ci.magFilter = VK_FILTER_NEAREST;
11388 sampler_ci.minFilter = VK_FILTER_NEAREST;
11389 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11390 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11391 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11392 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11393 sampler_ci.mipLodBias = 1.0;
11394 sampler_ci.anisotropyEnable = VK_FALSE;
11395 sampler_ci.maxAnisotropy = 1;
11396 sampler_ci.compareEnable = VK_FALSE;
11397 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11398 sampler_ci.minLod = 1.0;
11399 sampler_ci.maxLod = 1.0;
11400 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11401 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011402
11403 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011404 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011405 ASSERT_VK_SUCCESS(err);
11406
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011407 VkImageView view = (VkImageView)((size_t)0xbaadbeef); // invalid imageView object
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011408
11409 VkDescriptorImageInfo descriptor_info;
11410 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
11411 descriptor_info.sampler = sampler;
11412 descriptor_info.imageView = view;
11413
11414 VkWriteDescriptorSet descriptor_write;
11415 memset(&descriptor_write, 0, sizeof(descriptor_write));
11416 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011417 descriptor_write.dstSet = descriptorSet;
11418 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011419 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011420 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11421 descriptor_write.pImageInfo = &descriptor_info;
11422
11423 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11424
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011425 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011426
Chia-I Wuf7458c52015-10-26 21:10:41 +080011427 vkDestroySampler(m_device->device(), sampler, NULL);
11428 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11429 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011430}
11431
Karl Schultz6addd812016-02-02 17:17:23 -070011432TEST_F(VkLayerTest, CopyDescriptorUpdateErrors) {
11433 // Create DS w/ layout of 2 types, write update 1 and attempt to copy-update
11434 // into the other
11435 VkResult err;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011436
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011437 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11438 " binding #1 with type "
11439 "VK_DESCRIPTOR_TYPE_SAMPLER. Types do "
11440 "not match.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011441
Tony Barbour1fa09702017-03-16 12:09:08 -060011442 ASSERT_NO_FATAL_FAILURE(Init());
Karl Schultz6addd812016-02-02 17:17:23 -070011443 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011444 VkDescriptorPoolSize ds_type_count[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011445 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11446 ds_type_count[0].descriptorCount = 1;
11447 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
11448 ds_type_count[1].descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011449
11450 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011451 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11452 ds_pool_ci.pNext = NULL;
11453 ds_pool_ci.maxSets = 1;
11454 ds_pool_ci.poolSizeCount = 2;
11455 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011456
11457 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011458 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis04356f92015-10-27 16:35:27 -060011459 ASSERT_VK_SUCCESS(err);
11460 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011461 dsl_binding[0].binding = 0;
11462 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11463 dsl_binding[0].descriptorCount = 1;
11464 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
11465 dsl_binding[0].pImmutableSamplers = NULL;
11466 dsl_binding[1].binding = 1;
11467 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
11468 dsl_binding[1].descriptorCount = 1;
11469 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
11470 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011471
11472 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011473 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11474 ds_layout_ci.pNext = NULL;
11475 ds_layout_ci.bindingCount = 2;
11476 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011477
11478 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011479 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis04356f92015-10-27 16:35:27 -060011480 ASSERT_VK_SUCCESS(err);
11481
11482 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011483 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011484 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011485 alloc_info.descriptorSetCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011486 alloc_info.descriptorPool = ds_pool;
11487 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011488 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis04356f92015-10-27 16:35:27 -060011489 ASSERT_VK_SUCCESS(err);
11490
11491 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011492 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11493 sampler_ci.pNext = NULL;
11494 sampler_ci.magFilter = VK_FILTER_NEAREST;
11495 sampler_ci.minFilter = VK_FILTER_NEAREST;
11496 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11497 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11498 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11499 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11500 sampler_ci.mipLodBias = 1.0;
11501 sampler_ci.anisotropyEnable = VK_FALSE;
11502 sampler_ci.maxAnisotropy = 1;
11503 sampler_ci.compareEnable = VK_FALSE;
11504 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11505 sampler_ci.minLod = 1.0;
11506 sampler_ci.maxLod = 1.0;
11507 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11508 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011509
11510 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011511 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis04356f92015-10-27 16:35:27 -060011512 ASSERT_VK_SUCCESS(err);
11513
11514 VkDescriptorImageInfo info = {};
11515 info.sampler = sampler;
11516
11517 VkWriteDescriptorSet descriptor_write;
11518 memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet));
11519 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011520 descriptor_write.dstSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011521 descriptor_write.dstBinding = 1; // SAMPLER binding from layout above
Chia-I Wud50a7d72015-10-26 20:48:51 +080011522 descriptor_write.descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011523 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
11524 descriptor_write.pImageInfo = &info;
11525 // This write update should succeed
11526 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11527 // Now perform a copy update that fails due to type mismatch
11528 VkCopyDescriptorSet copy_ds_update;
11529 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
11530 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
11531 copy_ds_update.srcSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011532 copy_ds_update.srcBinding = 1; // Copy from SAMPLER binding
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011533 copy_ds_update.dstSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011534 copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding
11535 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -060011536 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
11537
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011538 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -060011539 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011540 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 -060011541 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
11542 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
11543 copy_ds_update.srcSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011544 copy_ds_update.srcBinding = 3; // ERROR : Invalid binding for matching layout
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011545 copy_ds_update.dstSet = descriptorSet;
11546 copy_ds_update.dstBinding = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011547 copy_ds_update.descriptorCount = 1; // Copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -060011548 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
11549
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011550 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011551
Tobin Ehlis04356f92015-10-27 16:35:27 -060011552 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011553 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11554 " binding#1 with offset index of 1 plus "
11555 "update array offset of 0 and update of "
11556 "5 descriptors oversteps total number "
11557 "of descriptors in set: 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011558
Tobin Ehlis04356f92015-10-27 16:35:27 -060011559 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
11560 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
11561 copy_ds_update.srcSet = descriptorSet;
11562 copy_ds_update.srcBinding = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011563 copy_ds_update.dstSet = descriptorSet;
11564 copy_ds_update.dstBinding = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011565 copy_ds_update.descriptorCount = 5; // ERROR copy 5 descriptors (out of bounds for layout)
Tobin Ehlis04356f92015-10-27 16:35:27 -060011566 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
11567
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011568 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -060011569
Chia-I Wuf7458c52015-10-26 21:10:41 +080011570 vkDestroySampler(m_device->device(), sampler, NULL);
11571 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11572 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis04356f92015-10-27 16:35:27 -060011573}
11574
Karl Schultz6addd812016-02-02 17:17:23 -070011575TEST_F(VkLayerTest, NumSamplesMismatch) {
11576 // Create CommandBuffer where MSAA samples doesn't match RenderPass
11577 // sampleCount
11578 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011579
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011580 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Num samples mismatch! ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011581
Tony Barbour1fa09702017-03-16 12:09:08 -060011582 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis3b780662015-05-28 12:11:26 -060011583 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011584 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -060011585 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011586 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011587
11588 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011589 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11590 ds_pool_ci.pNext = NULL;
11591 ds_pool_ci.maxSets = 1;
11592 ds_pool_ci.poolSizeCount = 1;
11593 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060011594
Tobin Ehlis3b780662015-05-28 12:11:26 -060011595 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011596 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011597 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011598
Tony Barboureb254902015-07-15 12:50:33 -060011599 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +080011600 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -060011601 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +080011602 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011603 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11604 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011605
Tony Barboureb254902015-07-15 12:50:33 -060011606 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11607 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11608 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011609 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -070011610 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060011611
Tobin Ehlis3b780662015-05-28 12:11:26 -060011612 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011613 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011614 ASSERT_VK_SUCCESS(err);
11615
11616 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011617 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011618 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011619 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011620 alloc_info.descriptorPool = ds_pool;
11621 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011622 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011623 ASSERT_VK_SUCCESS(err);
11624
Tony Barboureb254902015-07-15 12:50:33 -060011625 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011626 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070011627 pipe_ms_state_ci.pNext = NULL;
11628 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
11629 pipe_ms_state_ci.sampleShadingEnable = 0;
11630 pipe_ms_state_ci.minSampleShading = 1.0;
11631 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011632
Tony Barboureb254902015-07-15 12:50:33 -060011633 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011634 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11635 pipeline_layout_ci.pNext = NULL;
11636 pipeline_layout_ci.setLayoutCount = 1;
11637 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011638
11639 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011640 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011641 ASSERT_VK_SUCCESS(err);
11642
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011643 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011644 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 -060011645 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011646 VkPipelineObj pipe(m_device);
11647 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060011648 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -060011649 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011650 pipe.SetMSAA(&pipe_ms_state_ci);
11651 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis3b780662015-05-28 12:11:26 -060011652
Tony Barbour552f6c02016-12-21 14:34:07 -070011653 m_commandBuffer->BeginCommandBuffer();
11654 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011655 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis3b780662015-05-28 12:11:26 -060011656
Rene Lindsay3bdc7a42017-01-06 13:20:15 -070011657 VkViewport viewport = {0, 0, 16, 16, 0, 1};
11658 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
11659 VkRect2D scissor = {{0, 0}, {16, 16}};
11660 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
11661
Mark Young29927482016-05-04 14:38:51 -060011662 // Render triangle (the error should trigger on the attempt to draw).
11663 Draw(3, 1, 0, 0);
11664
11665 // Finalize recording of the command buffer
Tony Barbour552f6c02016-12-21 14:34:07 -070011666 m_commandBuffer->EndRenderPass();
11667 m_commandBuffer->EndCommandBuffer();
Mark Young29927482016-05-04 14:38:51 -060011668
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011669 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011670
Chia-I Wuf7458c52015-10-26 21:10:41 +080011671 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11672 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11673 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060011674}
Mark Young29927482016-05-04 14:38:51 -060011675
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011676TEST_F(VkLayerTest, RenderPassIncompatible) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011677 TEST_DESCRIPTION(
11678 "Hit RenderPass incompatible cases. "
11679 "Initial case is drawing with an active renderpass that's "
11680 "not compatible with the bound pipeline state object's creation renderpass");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011681 VkResult err;
11682
Tony Barbour1fa09702017-03-16 12:09:08 -060011683 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011684 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11685
11686 VkDescriptorSetLayoutBinding dsl_binding = {};
11687 dsl_binding.binding = 0;
11688 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11689 dsl_binding.descriptorCount = 1;
11690 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11691 dsl_binding.pImmutableSamplers = NULL;
11692
11693 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11694 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11695 ds_layout_ci.pNext = NULL;
11696 ds_layout_ci.bindingCount = 1;
11697 ds_layout_ci.pBindings = &dsl_binding;
11698
11699 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011700 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011701 ASSERT_VK_SUCCESS(err);
11702
11703 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11704 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11705 pipeline_layout_ci.pNext = NULL;
11706 pipeline_layout_ci.setLayoutCount = 1;
11707 pipeline_layout_ci.pSetLayouts = &ds_layout;
11708
11709 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011710 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011711 ASSERT_VK_SUCCESS(err);
11712
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011713 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011714 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 -060011715 // but add it to be able to run on more devices
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011716 // Create a renderpass that will be incompatible with default renderpass
11717 VkAttachmentReference attach = {};
Cort Stratton7547f772017-05-04 15:18:52 -070011718 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011719 VkAttachmentReference color_att = {};
Cort Stratton7547f772017-05-04 15:18:52 -070011720 color_att.layout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011721 VkSubpassDescription subpass = {};
11722 subpass.inputAttachmentCount = 1;
11723 subpass.pInputAttachments = &attach;
11724 subpass.colorAttachmentCount = 1;
11725 subpass.pColorAttachments = &color_att;
11726 VkRenderPassCreateInfo rpci = {};
11727 rpci.subpassCount = 1;
11728 rpci.pSubpasses = &subpass;
11729 rpci.attachmentCount = 1;
11730 VkAttachmentDescription attach_desc = {};
11731 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Cody Northropbd16af12016-06-21 09:25:48 -060011732 // Format incompatible with PSO RP color attach format B8G8R8A8_UNORM
11733 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011734 rpci.pAttachments = &attach_desc;
11735 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
11736 VkRenderPass rp;
11737 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11738 VkPipelineObj pipe(m_device);
11739 pipe.AddShader(&vs);
11740 pipe.AddShader(&fs);
11741 pipe.AddColorAttachment();
11742 VkViewport view_port = {};
11743 m_viewports.push_back(view_port);
11744 pipe.SetViewport(m_viewports);
11745 VkRect2D rect = {};
11746 m_scissors.push_back(rect);
11747 pipe.SetScissor(m_scissors);
11748 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11749
11750 VkCommandBufferInheritanceInfo cbii = {};
11751 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
11752 cbii.renderPass = rp;
11753 cbii.subpass = 0;
11754 VkCommandBufferBeginInfo cbbi = {};
11755 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
11756 cbbi.pInheritanceInfo = &cbii;
11757 vkBeginCommandBuffer(m_commandBuffer->handle(), &cbbi);
11758 VkRenderPassBeginInfo rpbi = {};
11759 rpbi.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
11760 rpbi.framebuffer = m_framebuffer;
11761 rpbi.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011762 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
11763 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011764
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011765 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is incompatible w/ gfx pipeline ");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011766 // Render triangle (the error should trigger on the attempt to draw).
11767 Draw(3, 1, 0, 0);
11768
11769 // Finalize recording of the command buffer
Tony Barbour552f6c02016-12-21 14:34:07 -070011770 m_commandBuffer->EndRenderPass();
11771 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011772
11773 m_errorMonitor->VerifyFound();
11774
11775 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11776 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11777 vkDestroyRenderPass(m_device->device(), rp, NULL);
11778}
11779
Mark Youngc89c6312016-03-31 16:03:20 -060011780TEST_F(VkLayerTest, NumBlendAttachMismatch) {
11781 // Create Pipeline where the number of blend attachments doesn't match the
11782 // number of color attachments. In this case, we don't add any color
11783 // blend attachments even though we have a color attachment.
11784 VkResult err;
11785
Tobin Ehlis974c0d92017-02-01 13:31:22 -070011786 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02109);
Mark Youngc89c6312016-03-31 16:03:20 -060011787
Tony Barbour1fa09702017-03-16 12:09:08 -060011788 ASSERT_NO_FATAL_FAILURE(Init());
Mark Youngc89c6312016-03-31 16:03:20 -060011789 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11790 VkDescriptorPoolSize ds_type_count = {};
11791 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11792 ds_type_count.descriptorCount = 1;
11793
11794 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11795 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11796 ds_pool_ci.pNext = NULL;
11797 ds_pool_ci.maxSets = 1;
11798 ds_pool_ci.poolSizeCount = 1;
11799 ds_pool_ci.pPoolSizes = &ds_type_count;
11800
11801 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011802 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Youngc89c6312016-03-31 16:03:20 -060011803 ASSERT_VK_SUCCESS(err);
11804
11805 VkDescriptorSetLayoutBinding dsl_binding = {};
11806 dsl_binding.binding = 0;
11807 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11808 dsl_binding.descriptorCount = 1;
11809 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11810 dsl_binding.pImmutableSamplers = NULL;
11811
11812 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11813 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11814 ds_layout_ci.pNext = NULL;
11815 ds_layout_ci.bindingCount = 1;
11816 ds_layout_ci.pBindings = &dsl_binding;
11817
11818 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011819 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Youngc89c6312016-03-31 16:03:20 -060011820 ASSERT_VK_SUCCESS(err);
11821
11822 VkDescriptorSet descriptorSet;
11823 VkDescriptorSetAllocateInfo alloc_info = {};
11824 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11825 alloc_info.descriptorSetCount = 1;
11826 alloc_info.descriptorPool = ds_pool;
11827 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011828 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Youngc89c6312016-03-31 16:03:20 -060011829 ASSERT_VK_SUCCESS(err);
11830
11831 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011832 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Youngc89c6312016-03-31 16:03:20 -060011833 pipe_ms_state_ci.pNext = NULL;
11834 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
11835 pipe_ms_state_ci.sampleShadingEnable = 0;
11836 pipe_ms_state_ci.minSampleShading = 1.0;
11837 pipe_ms_state_ci.pSampleMask = NULL;
11838
11839 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11840 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11841 pipeline_layout_ci.pNext = NULL;
11842 pipeline_layout_ci.setLayoutCount = 1;
11843 pipeline_layout_ci.pSetLayouts = &ds_layout;
11844
11845 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011846 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Youngc89c6312016-03-31 16:03:20 -060011847 ASSERT_VK_SUCCESS(err);
11848
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011849 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011850 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 -060011851 // but add it to be able to run on more devices
Mark Youngc89c6312016-03-31 16:03:20 -060011852 VkPipelineObj pipe(m_device);
11853 pipe.AddShader(&vs);
11854 pipe.AddShader(&fs);
11855 pipe.SetMSAA(&pipe_ms_state_ci);
11856 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011857 m_errorMonitor->VerifyFound();
Mark Youngc89c6312016-03-31 16:03:20 -060011858
11859 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11860 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11861 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11862}
Mark Young29927482016-05-04 14:38:51 -060011863
Mark Muellerd4914412016-06-13 17:52:06 -060011864TEST_F(VkLayerTest, MissingClearAttachment) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011865 TEST_DESCRIPTION(
11866 "Points to a wrong colorAttachment index in a VkClearAttachment "
11867 "structure passed to vkCmdClearAttachments");
Tony Barbour1fa09702017-03-16 12:09:08 -060011868 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070011869 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01114);
Mark Muellerd4914412016-06-13 17:52:06 -060011870
11871 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailCmdClearAttachments);
11872 m_errorMonitor->VerifyFound();
11873}
11874
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070011875TEST_F(VkLayerTest, CmdClearAttachmentTests) {
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070011876 TEST_DESCRIPTION("Various tests for validating usage of vkCmdClearAttachments");
11877 VkResult err;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011878
Tony Barbour1fa09702017-03-16 12:09:08 -060011879 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011880 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060011881
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011882 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011883 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11884 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011885
11886 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011887 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11888 ds_pool_ci.pNext = NULL;
11889 ds_pool_ci.maxSets = 1;
11890 ds_pool_ci.poolSizeCount = 1;
11891 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060011892
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011893 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011894 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011895 ASSERT_VK_SUCCESS(err);
11896
Tony Barboureb254902015-07-15 12:50:33 -060011897 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011898 dsl_binding.binding = 0;
11899 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11900 dsl_binding.descriptorCount = 1;
11901 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11902 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011903
Tony Barboureb254902015-07-15 12:50:33 -060011904 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011905 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11906 ds_layout_ci.pNext = NULL;
11907 ds_layout_ci.bindingCount = 1;
11908 ds_layout_ci.pBindings = &dsl_binding;
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011909
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011910 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011911 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011912 ASSERT_VK_SUCCESS(err);
11913
11914 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011915 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011916 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011917 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011918 alloc_info.descriptorPool = ds_pool;
11919 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011920 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011921 ASSERT_VK_SUCCESS(err);
11922
Tony Barboureb254902015-07-15 12:50:33 -060011923 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011924 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070011925 pipe_ms_state_ci.pNext = NULL;
11926 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
11927 pipe_ms_state_ci.sampleShadingEnable = 0;
11928 pipe_ms_state_ci.minSampleShading = 1.0;
11929 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011930
Tony Barboureb254902015-07-15 12:50:33 -060011931 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011932 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11933 pipeline_layout_ci.pNext = NULL;
11934 pipeline_layout_ci.setLayoutCount = 1;
11935 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011936
11937 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011938 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011939 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011940
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011941 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -060011942 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -070011943 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011944 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011945
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011946 VkPipelineObj pipe(m_device);
11947 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060011948 pipe.AddShader(&fs);
Jeremy Hayes7332f342017-03-09 15:54:12 -070011949 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011950 pipe.SetMSAA(&pipe_ms_state_ci);
11951 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060011952
Tony Barbour552f6c02016-12-21 14:34:07 -070011953 m_commandBuffer->BeginCommandBuffer();
11954 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011955
Karl Schultz6addd812016-02-02 17:17:23 -070011956 // Main thing we care about for this test is that the VkImage obj we're
11957 // clearing matches Color Attachment of FB
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011958 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -060011959 VkClearAttachment color_attachment;
11960 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11961 color_attachment.clearValue.color.float32[0] = 1.0;
11962 color_attachment.clearValue.color.float32[1] = 1.0;
11963 color_attachment.clearValue.color.float32[2] = 1.0;
11964 color_attachment.clearValue.color.float32[3] = 1.0;
11965 color_attachment.colorAttachment = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011966 VkClearRect clear_rect = {{{0, 0}, {(uint32_t)m_width, (uint32_t)m_height}}};
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011967
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070011968 // Call for full-sized FB Color attachment prior to issuing a Draw
11969 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070011970 "vkCmdClearAttachments() issued on command buffer object ");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011971 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070011972 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011973
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070011974 clear_rect.rect.extent.width = renderPassBeginInfo().renderArea.extent.width + 4;
11975 clear_rect.rect.extent.height = clear_rect.rect.extent.height / 2;
11976 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01115);
11977 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
11978 m_errorMonitor->VerifyFound();
11979
11980 clear_rect.rect.extent.width = (uint32_t)m_width / 2;
11981 clear_rect.layerCount = 2;
11982 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01116);
11983 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011984 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011985
Chia-I Wuf7458c52015-10-26 21:10:41 +080011986 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11987 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11988 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011989}
11990
Karl Schultz6addd812016-02-02 17:17:23 -070011991TEST_F(VkLayerTest, VtxBufferBadIndex) {
11992 VkResult err;
Tobin Ehlis502480b2015-06-24 15:53:07 -060011993
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011994 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11995 "but no vertex buffers are attached to this Pipeline State Object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011996
Tony Barbour1fa09702017-03-16 12:09:08 -060011997 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisd332f282015-10-02 11:00:56 -060011998 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlis502480b2015-06-24 15:53:07 -060011999 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060012000
Chia-I Wu1b99bb22015-10-27 19:25:11 +080012001 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012002 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12003 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060012004
12005 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012006 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12007 ds_pool_ci.pNext = NULL;
12008 ds_pool_ci.maxSets = 1;
12009 ds_pool_ci.poolSizeCount = 1;
12010 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060012011
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060012012 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012013 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis502480b2015-06-24 15:53:07 -060012014 ASSERT_VK_SUCCESS(err);
12015
Tony Barboureb254902015-07-15 12:50:33 -060012016 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012017 dsl_binding.binding = 0;
12018 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12019 dsl_binding.descriptorCount = 1;
12020 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
12021 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060012022
Tony Barboureb254902015-07-15 12:50:33 -060012023 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012024 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12025 ds_layout_ci.pNext = NULL;
12026 ds_layout_ci.bindingCount = 1;
12027 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060012028
Tobin Ehlis502480b2015-06-24 15:53:07 -060012029 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012030 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060012031 ASSERT_VK_SUCCESS(err);
12032
12033 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012034 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080012035 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070012036 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060012037 alloc_info.descriptorPool = ds_pool;
12038 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012039 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis502480b2015-06-24 15:53:07 -060012040 ASSERT_VK_SUCCESS(err);
12041
Tony Barboureb254902015-07-15 12:50:33 -060012042 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012043 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070012044 pipe_ms_state_ci.pNext = NULL;
12045 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
12046 pipe_ms_state_ci.sampleShadingEnable = 0;
12047 pipe_ms_state_ci.minSampleShading = 1.0;
12048 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060012049
Tony Barboureb254902015-07-15 12:50:33 -060012050 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012051 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12052 pipeline_layout_ci.pNext = NULL;
12053 pipeline_layout_ci.setLayoutCount = 1;
12054 pipeline_layout_ci.pSetLayouts = &ds_layout;
12055 VkPipelineLayout pipeline_layout;
Tobin Ehlis502480b2015-06-24 15:53:07 -060012056
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012057 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060012058 ASSERT_VK_SUCCESS(err);
12059
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012060 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012061 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 -060012062 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -060012063 VkPipelineObj pipe(m_device);
12064 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060012065 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -060012066 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060012067 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -060012068 pipe.SetViewport(m_viewports);
12069 pipe.SetScissor(m_scissors);
Tony Barbour62e1a5b2015-08-06 10:16:07 -060012070 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060012071
Tony Barbour552f6c02016-12-21 14:34:07 -070012072 m_commandBuffer->BeginCommandBuffer();
12073 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012074 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisf7bf4502015-09-09 15:12:35 -060012075 // Don't care about actual data, just need to get to draw to flag error
12076 static const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012077 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), (const void *)&vbo_data);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012078 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -060012079 Draw(1, 0, 0, 0);
Tobin Ehlis502480b2015-06-24 15:53:07 -060012080
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012081 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060012082
Chia-I Wuf7458c52015-10-26 21:10:41 +080012083 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12084 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12085 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis502480b2015-06-24 15:53:07 -060012086}
Mark Muellerdfe37552016-07-07 14:47:42 -060012087
Mark Mueller2ee294f2016-08-04 12:59:48 -060012088TEST_F(VkLayerTest, MismatchCountQueueCreateRequestedFeature) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012089 TEST_DESCRIPTION(
12090 "Use an invalid count in a vkEnumeratePhysicalDevices call."
12091 "Use invalid Queue Family Index in vkCreateDevice");
Tony Barbour1fa09702017-03-16 12:09:08 -060012092 ASSERT_NO_FATAL_FAILURE(Init());
Mark Mueller2ee294f2016-08-04 12:59:48 -060012093
Mark Mueller880fce52016-08-17 15:23:23 -060012094 // The following test fails with recent NVidia drivers.
12095 // By the time core_validation is reached, the NVidia
12096 // driver has sanitized the invalid condition and core_validation
12097 // is not introduced to the failure condition. This is not the case
12098 // with AMD and Mesa drivers. Futher investigation is required
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012099 // uint32_t count = static_cast<uint32_t>(~0);
12100 // VkPhysicalDevice physical_device;
12101 // vkEnumeratePhysicalDevices(instance(), &count, &physical_device);
12102 // m_errorMonitor->VerifyFound();
Mark Mueller2ee294f2016-08-04 12:59:48 -060012103
Mark Mueller2ee294f2016-08-04 12:59:48 -060012104 float queue_priority = 0.0;
Mark Mueller2ee294f2016-08-04 12:59:48 -060012105 VkDeviceQueueCreateInfo queue_create_info = {};
12106 queue_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
12107 queue_create_info.queueCount = 1;
12108 queue_create_info.pQueuePriorities = &queue_priority;
12109 queue_create_info.queueFamilyIndex = static_cast<uint32_t>(~0);
12110
12111 VkPhysicalDeviceFeatures features = m_device->phy().features();
12112 VkDevice testDevice;
12113 VkDeviceCreateInfo device_create_info = {};
12114 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
12115 device_create_info.queueCreateInfoCount = 1;
12116 device_create_info.pQueueCreateInfos = &queue_create_info;
12117 device_create_info.pEnabledFeatures = &features;
Jeremy Hayesb26fd042017-03-10 09:13:22 -070012118
Petr Kraus56ed9192017-05-08 23:45:36 +020012119 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00054);
Jeremy Hayes17fd3662017-03-17 11:51:11 -060012120 // The following unexpected error is coming from the LunarG loader. Do not make it a desired message because platforms that do
12121 // not use the LunarG loader (e.g. Android) will not see the message and the test will fail.
12122 m_errorMonitor->SetUnexpectedError("Failed to create device chain.");
Mark Mueller2ee294f2016-08-04 12:59:48 -060012123 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
12124 m_errorMonitor->VerifyFound();
12125
12126 queue_create_info.queueFamilyIndex = 1;
12127
12128 unsigned feature_count = sizeof(VkPhysicalDeviceFeatures) / sizeof(VkBool32);
12129 VkBool32 *feature_array = reinterpret_cast<VkBool32 *>(&features);
12130 for (unsigned i = 0; i < feature_count; i++) {
12131 if (VK_FALSE == feature_array[i]) {
12132 feature_array[i] = VK_TRUE;
Mark Mueller2ee294f2016-08-04 12:59:48 -060012133 device_create_info.pEnabledFeatures = &features;
Jeremy Hayesb26fd042017-03-10 09:13:22 -070012134 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12135 "While calling vkCreateDevice(), requesting feature #");
Jeremy Hayes17fd3662017-03-17 11:51:11 -060012136 // The following unexpected error is coming from the LunarG loader. Do not make it a desired message because platforms
12137 // that do not use the LunarG loader (e.g. Android) will not see the message and the test will fail.
12138 m_errorMonitor->SetUnexpectedError("Failed to create device chain.");
Jeremy Hayesb26fd042017-03-10 09:13:22 -070012139 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12140 "You requested features that are unavailable on this device. You should first "
12141 "query feature availability by calling vkGetPhysicalDeviceFeatures().");
Mark Mueller2ee294f2016-08-04 12:59:48 -060012142 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
12143 m_errorMonitor->VerifyFound();
12144 break;
12145 }
12146 }
12147}
12148
Tobin Ehlis16edf082016-11-21 12:33:49 -070012149TEST_F(VkLayerTest, InvalidQueryPoolCreate) {
12150 TEST_DESCRIPTION("Attempt to create a query pool for PIPELINE_STATISTICS without enabling pipeline stats for the device.");
12151
Tony Barbour1fa09702017-03-16 12:09:08 -060012152 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis16edf082016-11-21 12:33:49 -070012153
12154 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
12155 std::vector<VkDeviceQueueCreateInfo> queue_info;
12156 queue_info.reserve(queue_props.size());
12157 std::vector<std::vector<float>> queue_priorities;
12158 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
12159 VkDeviceQueueCreateInfo qi{};
12160 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
12161 qi.queueFamilyIndex = i;
12162 qi.queueCount = queue_props[i].queueCount;
12163 queue_priorities.emplace_back(qi.queueCount, 0.0f);
12164 qi.pQueuePriorities = queue_priorities[i].data();
12165 queue_info.push_back(qi);
12166 }
12167
12168 std::vector<const char *> device_extension_names;
12169
12170 VkDevice local_device;
12171 VkDeviceCreateInfo device_create_info = {};
12172 auto features = m_device->phy().features();
12173 // Intentionally disable pipeline stats
12174 features.pipelineStatisticsQuery = VK_FALSE;
12175 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
12176 device_create_info.pNext = NULL;
12177 device_create_info.queueCreateInfoCount = queue_info.size();
12178 device_create_info.pQueueCreateInfos = queue_info.data();
12179 device_create_info.enabledLayerCount = 0;
12180 device_create_info.ppEnabledLayerNames = NULL;
12181 device_create_info.pEnabledFeatures = &features;
12182 VkResult err = vkCreateDevice(gpu(), &device_create_info, nullptr, &local_device);
12183 ASSERT_VK_SUCCESS(err);
12184
12185 VkQueryPoolCreateInfo qpci{};
12186 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
12187 qpci.queryType = VK_QUERY_TYPE_PIPELINE_STATISTICS;
12188 qpci.queryCount = 1;
12189 VkQueryPool query_pool;
12190
12191 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01006);
12192 vkCreateQueryPool(local_device, &qpci, nullptr, &query_pool);
12193 m_errorMonitor->VerifyFound();
12194
12195 vkDestroyDevice(local_device, nullptr);
12196}
12197
Mark Mueller2ee294f2016-08-04 12:59:48 -060012198TEST_F(VkLayerTest, InvalidQueueIndexInvalidQuery) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012199 TEST_DESCRIPTION(
12200 "Use an invalid queue index in a vkCmdWaitEvents call."
12201 "End a command buffer with a query still in progress.");
Mark Mueller2ee294f2016-08-04 12:59:48 -060012202
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012203 const char *invalid_queue_index =
12204 "was created with sharingMode of VK_SHARING_MODE_EXCLUSIVE. If one "
12205 "of src- or dstQueueFamilyIndex is VK_QUEUE_FAMILY_IGNORED, both "
12206 "must be.";
Mark Mueller2ee294f2016-08-04 12:59:48 -060012207
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012208 const char *invalid_query = "Ending command buffer with in progress query: queryPool 0x";
Mark Mueller2ee294f2016-08-04 12:59:48 -060012209
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012210 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queue_index);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012211
Tony Barbour1fa09702017-03-16 12:09:08 -060012212 ASSERT_NO_FATAL_FAILURE(Init());
Mark Mueller2ee294f2016-08-04 12:59:48 -060012213
12214 VkEvent event;
12215 VkEventCreateInfo event_create_info{};
12216 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
12217 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
12218
Mark Mueller2ee294f2016-08-04 12:59:48 -060012219 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012220 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012221
Tony Barbour552f6c02016-12-21 14:34:07 -070012222 m_commandBuffer->BeginCommandBuffer();
Mark Mueller2ee294f2016-08-04 12:59:48 -060012223
12224 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060012225 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 -060012226 ASSERT_TRUE(image.initialized());
12227 VkImageMemoryBarrier img_barrier = {};
12228 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
12229 img_barrier.pNext = NULL;
12230 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
12231 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
12232 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
12233 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
12234 img_barrier.image = image.handle();
12235 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
Mark Lobodzinski2a74c5c2016-08-17 13:26:28 -060012236
12237 // QueueFamilyIndex must be VK_QUEUE_FAMILY_IGNORED, this verifies
12238 // that layer validation catches the case when it is not.
12239 img_barrier.dstQueueFamilyIndex = 0;
Mark Mueller2ee294f2016-08-04 12:59:48 -060012240 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12241 img_barrier.subresourceRange.baseArrayLayer = 0;
12242 img_barrier.subresourceRange.baseMipLevel = 0;
12243 img_barrier.subresourceRange.layerCount = 1;
12244 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012245 vkCmdWaitEvents(m_commandBuffer->handle(), 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0,
12246 nullptr, 0, nullptr, 1, &img_barrier);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012247 m_errorMonitor->VerifyFound();
12248
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012249 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_query);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012250
12251 VkQueryPool query_pool;
12252 VkQueryPoolCreateInfo query_pool_create_info = {};
12253 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
12254 query_pool_create_info.queryType = VK_QUERY_TYPE_OCCLUSION;
12255 query_pool_create_info.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012256 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012257
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012258 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0 /*startQuery*/, 1 /*queryCount*/);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012259 vkCmdBeginQuery(m_commandBuffer->handle(), query_pool, 0, 0);
12260
12261 vkEndCommandBuffer(m_commandBuffer->handle());
12262 m_errorMonitor->VerifyFound();
12263
12264 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
12265 vkDestroyEvent(m_device->device(), event, nullptr);
12266}
12267
Mark Muellerdfe37552016-07-07 14:47:42 -060012268TEST_F(VkLayerTest, VertexBufferInvalid) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012269 TEST_DESCRIPTION(
12270 "Submit a command buffer using deleted vertex buffer, "
12271 "delete a buffer twice, use an invalid offset for each "
12272 "buffer type, and attempt to bind a null buffer");
Mark Muellerdfe37552016-07-07 14:47:42 -060012273
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012274 const char *deleted_buffer_in_command_buffer =
12275 "Cannot submit cmd buffer "
12276 "using deleted buffer ";
12277 const char *invalid_offset_message =
12278 "vkBindBufferMemory(): "
12279 "memoryOffset is 0x";
12280 const char *invalid_storage_buffer_offset_message =
12281 "vkBindBufferMemory(): "
12282 "storage memoryOffset "
12283 "is 0x";
12284 const char *invalid_texel_buffer_offset_message =
12285 "vkBindBufferMemory(): "
12286 "texel memoryOffset "
12287 "is 0x";
12288 const char *invalid_uniform_buffer_offset_message =
12289 "vkBindBufferMemory(): "
12290 "uniform memoryOffset "
12291 "is 0x";
Mark Muellerdfe37552016-07-07 14:47:42 -060012292
Tony Barbour1fa09702017-03-16 12:09:08 -060012293 ASSERT_NO_FATAL_FAILURE(Init());
Mark Muellerdfe37552016-07-07 14:47:42 -060012294 ASSERT_NO_FATAL_FAILURE(InitViewport());
12295 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12296
12297 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012298 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -060012299 pipe_ms_state_ci.pNext = NULL;
12300 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
12301 pipe_ms_state_ci.sampleShadingEnable = 0;
12302 pipe_ms_state_ci.minSampleShading = 1.0;
12303 pipe_ms_state_ci.pSampleMask = nullptr;
12304
12305 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12306 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12307 VkPipelineLayout pipeline_layout;
12308
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012309 VkResult err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, nullptr, &pipeline_layout);
Mark Muellerdfe37552016-07-07 14:47:42 -060012310 ASSERT_VK_SUCCESS(err);
12311
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012312 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
12313 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Muellerdfe37552016-07-07 14:47:42 -060012314 VkPipelineObj pipe(m_device);
12315 pipe.AddShader(&vs);
12316 pipe.AddShader(&fs);
12317 pipe.AddColorAttachment();
12318 pipe.SetMSAA(&pipe_ms_state_ci);
12319 pipe.SetViewport(m_viewports);
12320 pipe.SetScissor(m_scissors);
12321 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12322
Tony Barbour552f6c02016-12-21 14:34:07 -070012323 m_commandBuffer->BeginCommandBuffer();
12324 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012325 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Muellerdfe37552016-07-07 14:47:42 -060012326
12327 {
12328 // Create and bind a vertex buffer in a reduced scope, which will cause
12329 // it to be deleted upon leaving this scope
12330 const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012331 VkVerticesObj draw_verticies(m_device, 1, 1, sizeof(vbo_data), 3, vbo_data);
Mark Muellerdfe37552016-07-07 14:47:42 -060012332 draw_verticies.BindVertexBuffers(m_commandBuffer->handle());
12333 draw_verticies.AddVertexInputToPipe(pipe);
12334 }
12335
12336 Draw(1, 0, 0, 0);
12337
Tony Barbour552f6c02016-12-21 14:34:07 -070012338 m_commandBuffer->EndRenderPass();
12339 m_commandBuffer->EndCommandBuffer();
Mark Muellerdfe37552016-07-07 14:47:42 -060012340
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012341 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, deleted_buffer_in_command_buffer);
Mark Muellerdfe37552016-07-07 14:47:42 -060012342 QueueCommandBuffer(false);
12343 m_errorMonitor->VerifyFound();
12344
12345 {
12346 // Create and bind a vertex buffer in a reduced scope, and delete it
12347 // twice, the second through the destructor
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012348 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eDoubleDelete);
Karl Schultzf78bcdd2016-11-30 12:36:01 -070012349 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00680);
Mark Muellerdfe37552016-07-07 14:47:42 -060012350 buffer_test.TestDoubleDestroy();
12351 }
12352 m_errorMonitor->VerifyFound();
12353
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012354 m_errorMonitor->SetUnexpectedError("value of pCreateInfo->usage must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012355 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidMemoryOffset)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060012356 // Create and bind a memory buffer with an invalid offset.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012357 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_offset_message);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012358 m_errorMonitor->SetUnexpectedError(
12359 "If buffer was created with the VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT or VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT, "
12360 "memoryOffset must be a multiple of VkPhysicalDeviceLimits::minTexelBufferOffsetAlignment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012361 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidMemoryOffset);
12362 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012363 m_errorMonitor->VerifyFound();
12364 }
12365
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012366 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset,
12367 VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060012368 // Create and bind a memory buffer with an invalid offset again,
12369 // but look for a texel buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012370 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_texel_buffer_offset_message);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012371 m_errorMonitor->SetUnexpectedError(
12372 "memoryOffset must be an integer multiple of the alignment member of the VkMemoryRequirements structure returned from "
12373 "a call to vkGetBufferMemoryRequirements with buffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012374 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
12375 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012376 m_errorMonitor->VerifyFound();
12377 }
12378
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012379 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060012380 // Create and bind a memory buffer with an invalid offset again, but
12381 // look for a uniform buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012382 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_uniform_buffer_offset_message);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012383 m_errorMonitor->SetUnexpectedError(
12384 "memoryOffset must be an integer multiple of the alignment member of the VkMemoryRequirements structure returned from "
12385 "a call to vkGetBufferMemoryRequirements with buffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012386 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
12387 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012388 m_errorMonitor->VerifyFound();
12389 }
12390
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012391 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060012392 // Create and bind a memory buffer with an invalid offset again, but
12393 // look for a storage buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012394 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_storage_buffer_offset_message);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012395 m_errorMonitor->SetUnexpectedError(
12396 "memoryOffset must be an integer multiple of the alignment member of the VkMemoryRequirements structure returned from "
12397 "a call to vkGetBufferMemoryRequirements with buffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012398 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
12399 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012400 m_errorMonitor->VerifyFound();
12401 }
12402
12403 {
12404 // Attempt to bind a null buffer.
Karl Schultzf78bcdd2016-11-30 12:36:01 -070012405 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00799);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012406 m_errorMonitor->SetUnexpectedError("required parameter memory specified as VK_NULL_HANDLE");
12407 m_errorMonitor->SetUnexpectedError("memory must be a valid VkDeviceMemory handle");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012408 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eBindNullBuffer);
12409 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012410 m_errorMonitor->VerifyFound();
12411 }
12412
12413 {
12414 // Attempt to use an invalid handle to delete a buffer.
Karl Schultzf78bcdd2016-11-30 12:36:01 -070012415 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00622);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012416 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eFreeInvalidHandle);
12417 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012418 }
12419 m_errorMonitor->VerifyFound();
12420
12421 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12422}
12423
Tony Barbourff1351e2017-05-10 11:14:03 -060012424TEST_F(VkLayerTest, BadVertexBufferOffset) {
12425 TEST_DESCRIPTION("Submit an offset past the end of a vertex buffer");
12426
12427 ASSERT_NO_FATAL_FAILURE(Init());
12428 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12429 static const float vbo_data[3] = {1.f, 0.f, 1.f};
Tony Barboure94224e2017-05-11 15:22:43 -060012430 VkConstantBufferObj vbo(m_device, 3, sizeof(float), (const void *)&vbo_data);
Tony Barbourff1351e2017-05-10 11:14:03 -060012431 m_commandBuffer->BeginCommandBuffer();
12432 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
12433 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01417);
Tony Barboure94224e2017-05-11 15:22:43 -060012434 BindVertexBuffer(&vbo, (VkDeviceSize)(3 * sizeof(float)), 1); // Offset at the end of the buffer
Tony Barbourff1351e2017-05-10 11:14:03 -060012435 m_errorMonitor->VerifyFound();
12436}
12437
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012438// INVALID_IMAGE_LAYOUT tests (one other case is hit by MapMemWithoutHostVisibleBit and not here)
12439TEST_F(VkLayerTest, InvalidImageLayout) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012440 TEST_DESCRIPTION(
12441 "Hit all possible validation checks associated with the "
12442 "DRAWSTATE_INVALID_IMAGE_LAYOUT enum. Generally these involve having"
12443 "images in the wrong layout when they're copied or transitioned.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012444 // 3 in ValidateCmdBufImageLayouts
12445 // * -1 Attempt to submit cmd buf w/ deleted image
12446 // * -2 Cmd buf submit of image w/ layout not matching first use w/ subresource
12447 // * -3 Cmd buf submit of image w/ layout not matching first use w/o subresource
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012448
Tony Barbour1fa09702017-03-16 12:09:08 -060012449 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -060012450 auto depth_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbourf887b162017-03-09 10:06:46 -070012451 if (!depth_format) {
12452 printf(" No Depth + Stencil format found. Skipped.\n");
12453 return;
12454 }
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012455 // Create src & dst images to use for copy operations
12456 VkImage src_image;
12457 VkImage dst_image;
Cort3b021012016-12-07 12:00:57 -080012458 VkImage depth_image;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012459
12460 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
12461 const int32_t tex_width = 32;
12462 const int32_t tex_height = 32;
12463
12464 VkImageCreateInfo image_create_info = {};
12465 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
12466 image_create_info.pNext = NULL;
12467 image_create_info.imageType = VK_IMAGE_TYPE_2D;
12468 image_create_info.format = tex_format;
12469 image_create_info.extent.width = tex_width;
12470 image_create_info.extent.height = tex_height;
12471 image_create_info.extent.depth = 1;
12472 image_create_info.mipLevels = 1;
12473 image_create_info.arrayLayers = 4;
12474 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
12475 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
12476 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Cort3b021012016-12-07 12:00:57 -080012477 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012478 image_create_info.flags = 0;
12479
12480 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &src_image);
12481 ASSERT_VK_SUCCESS(err);
Cort3b021012016-12-07 12:00:57 -080012482 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012483 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dst_image);
12484 ASSERT_VK_SUCCESS(err);
Cort3b021012016-12-07 12:00:57 -080012485 image_create_info.format = VK_FORMAT_D32_SFLOAT;
12486 image_create_info.usage |= VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
12487 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &depth_image);
12488 ASSERT_VK_SUCCESS(err);
12489
12490 // Allocate memory
12491 VkMemoryRequirements img_mem_reqs = {};
Cort530cf382016-12-08 09:59:47 -080012492 VkMemoryAllocateInfo mem_alloc = {};
Cort3b021012016-12-07 12:00:57 -080012493 VkDeviceMemory src_image_mem, dst_image_mem, depth_image_mem;
Cort530cf382016-12-08 09:59:47 -080012494 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
12495 mem_alloc.pNext = NULL;
12496 mem_alloc.allocationSize = 0;
12497 mem_alloc.memoryTypeIndex = 0;
Cort3b021012016-12-07 12:00:57 -080012498
12499 vkGetImageMemoryRequirements(m_device->device(), src_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080012500 mem_alloc.allocationSize = img_mem_reqs.size;
12501 bool pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080012502 ASSERT_TRUE(pass);
Cort530cf382016-12-08 09:59:47 -080012503 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &src_image_mem);
Cort3b021012016-12-07 12:00:57 -080012504 ASSERT_VK_SUCCESS(err);
12505
12506 vkGetImageMemoryRequirements(m_device->device(), dst_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080012507 mem_alloc.allocationSize = img_mem_reqs.size;
12508 pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080012509 ASSERT_VK_SUCCESS(err);
Cort530cf382016-12-08 09:59:47 -080012510 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &dst_image_mem);
Cort3b021012016-12-07 12:00:57 -080012511 ASSERT_VK_SUCCESS(err);
12512
12513 vkGetImageMemoryRequirements(m_device->device(), depth_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080012514 mem_alloc.allocationSize = img_mem_reqs.size;
12515 pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080012516 ASSERT_VK_SUCCESS(err);
Cort530cf382016-12-08 09:59:47 -080012517 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &depth_image_mem);
Cort3b021012016-12-07 12:00:57 -080012518 ASSERT_VK_SUCCESS(err);
12519
12520 err = vkBindImageMemory(m_device->device(), src_image, src_image_mem, 0);
12521 ASSERT_VK_SUCCESS(err);
12522 err = vkBindImageMemory(m_device->device(), dst_image, dst_image_mem, 0);
12523 ASSERT_VK_SUCCESS(err);
12524 err = vkBindImageMemory(m_device->device(), depth_image, depth_image_mem, 0);
12525 ASSERT_VK_SUCCESS(err);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012526
Tony Barbour552f6c02016-12-21 14:34:07 -070012527 m_commandBuffer->BeginCommandBuffer();
Cort530cf382016-12-08 09:59:47 -080012528 VkImageCopy copy_region;
12529 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12530 copy_region.srcSubresource.mipLevel = 0;
12531 copy_region.srcSubresource.baseArrayLayer = 0;
12532 copy_region.srcSubresource.layerCount = 1;
12533 copy_region.srcOffset.x = 0;
12534 copy_region.srcOffset.y = 0;
12535 copy_region.srcOffset.z = 0;
12536 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12537 copy_region.dstSubresource.mipLevel = 0;
12538 copy_region.dstSubresource.baseArrayLayer = 0;
12539 copy_region.dstSubresource.layerCount = 1;
12540 copy_region.dstOffset.x = 0;
12541 copy_region.dstOffset.y = 0;
12542 copy_region.dstOffset.z = 0;
12543 copy_region.extent.width = 1;
12544 copy_region.extent.height = 1;
12545 copy_region.extent.depth = 1;
12546
Mark Lobodzinski91c28262017-03-22 13:06:12 -060012547 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
12548 "layout should be VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL instead of GENERAL.");
12549 m_errorMonitor->SetUnexpectedError("layout should be VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL instead of GENERAL.");
Tobin Ehlis74cc6822017-03-14 16:16:51 -060012550
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();
Tobin Ehlise35b66a2017-03-15 12:18:31 -060012553 // The first call hits the expected WARNING and skips the call down the chain, so call a second time to call down chain and
12554 // update layer state
Mark Lobodzinski91c28262017-03-22 13:06:12 -060012555 m_errorMonitor->SetUnexpectedError("layout should be VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL instead of GENERAL.");
12556 m_errorMonitor->SetUnexpectedError("layout should be VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL instead of GENERAL.");
Tobin Ehlise35b66a2017-03-15 12:18:31 -060012557 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 -060012558 // Now cause error due to src image layout changing
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012559 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski91c28262017-03-22 13:06:12 -060012560 "with specific layout VK_IMAGE_LAYOUT_UNDEFINED that "
12561 "doesn't match the actual current layout VK_IMAGE_LAYOUT_GENERAL.");
Mark Lobodzinskic61e1da2017-05-15 16:18:13 -060012562 m_errorMonitor->SetUnexpectedError("is VK_IMAGE_LAYOUT_UNDEFINED but can only be VK_IMAGE_LAYOUT");
Cort530cf382016-12-08 09:59:47 -080012563 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 -060012564 m_errorMonitor->VerifyFound();
12565 // Final src error is due to bad layout type
Tobin Ehlis74cc6822017-03-14 16:16:51 -060012566 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski91c28262017-03-22 13:06:12 -060012567 "is VK_IMAGE_LAYOUT_UNDEFINED but can only be "
Tobin Ehlis74cc6822017-03-14 16:16:51 -060012568 "VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL or VK_IMAGE_LAYOUT_GENERAL.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012569 m_errorMonitor->SetUnexpectedError(
Mark Lobodzinski91c28262017-03-22 13:06:12 -060012570 "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 -080012571 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 -060012572 m_errorMonitor->VerifyFound();
12573 // Now verify same checks for dst
Mark Lobodzinski91c28262017-03-22 13:06:12 -060012574 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
12575 "layout should be VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL instead of GENERAL.");
12576 m_errorMonitor->SetUnexpectedError("layout should be VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL instead of GENERAL.");
Cort530cf382016-12-08 09:59:47 -080012577 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 -060012578 m_errorMonitor->VerifyFound();
12579 // Now cause error due to src image layout changing
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012580 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski91c28262017-03-22 13:06:12 -060012581 "with specific layout VK_IMAGE_LAYOUT_UNDEFINED that doesn't match "
Tobin Ehlis74cc6822017-03-14 16:16:51 -060012582 "the actual current layout VK_IMAGE_LAYOUT_GENERAL.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012583 m_errorMonitor->SetUnexpectedError(
Mark Lobodzinski91c28262017-03-22 13:06:12 -060012584 "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 -080012585 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 -060012586 m_errorMonitor->VerifyFound();
Tobin Ehlis74cc6822017-03-14 16:16:51 -060012587 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski91c28262017-03-22 13:06:12 -060012588 "is VK_IMAGE_LAYOUT_UNDEFINED but can only be VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL "
12589 "or VK_IMAGE_LAYOUT_GENERAL.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012590 m_errorMonitor->SetUnexpectedError(
Mark Lobodzinski91c28262017-03-22 13:06:12 -060012591 "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 -080012592 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 -060012593 m_errorMonitor->VerifyFound();
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010012594
Cort3b021012016-12-07 12:00:57 -080012595 // Convert dst and depth images to TRANSFER_DST for subsequent tests
12596 VkImageMemoryBarrier transfer_dst_image_barrier[1] = {};
12597 transfer_dst_image_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
12598 transfer_dst_image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
12599 transfer_dst_image_barrier[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
12600 transfer_dst_image_barrier[0].srcAccessMask = 0;
12601 transfer_dst_image_barrier[0].dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
12602 transfer_dst_image_barrier[0].image = dst_image;
12603 transfer_dst_image_barrier[0].subresourceRange.layerCount = image_create_info.arrayLayers;
12604 transfer_dst_image_barrier[0].subresourceRange.levelCount = image_create_info.mipLevels;
12605 transfer_dst_image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12606 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
12607 NULL, 0, NULL, 1, transfer_dst_image_barrier);
12608 transfer_dst_image_barrier[0].image = depth_image;
12609 transfer_dst_image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
12610 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
12611 NULL, 0, NULL, 1, transfer_dst_image_barrier);
12612
12613 // Cause errors due to clearing with invalid image layouts
Cort530cf382016-12-08 09:59:47 -080012614 VkClearColorValue color_clear_value = {};
12615 VkImageSubresourceRange clear_range;
12616 clear_range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12617 clear_range.baseMipLevel = 0;
12618 clear_range.baseArrayLayer = 0;
12619 clear_range.layerCount = 1;
12620 clear_range.levelCount = 1;
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010012621
Cort3b021012016-12-07 12:00:57 -080012622 // Fail due to explicitly prohibited layout for color clear (only GENERAL and TRANSFER_DST are permitted).
12623 // Since the image is currently not in UNDEFINED layout, this will emit two errors.
12624 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01086);
12625 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01085);
Cort530cf382016-12-08 09:59:47 -080012626 m_commandBuffer->ClearColorImage(dst_image, VK_IMAGE_LAYOUT_UNDEFINED, &color_clear_value, 1, &clear_range);
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010012627 m_errorMonitor->VerifyFound();
Cort3b021012016-12-07 12:00:57 -080012628 // Fail due to provided layout not matching actual current layout for color clear.
12629 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01085);
Cort530cf382016-12-08 09:59:47 -080012630 m_commandBuffer->ClearColorImage(dst_image, VK_IMAGE_LAYOUT_GENERAL, &color_clear_value, 1, &clear_range);
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010012631 m_errorMonitor->VerifyFound();
Cort3b021012016-12-07 12:00:57 -080012632
Cort530cf382016-12-08 09:59:47 -080012633 VkClearDepthStencilValue depth_clear_value = {};
12634 clear_range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Cort3b021012016-12-07 12:00:57 -080012635
12636 // Fail due to explicitly prohibited layout for depth clear (only GENERAL and TRANSFER_DST are permitted).
12637 // Since the image is currently not in UNDEFINED layout, this will emit two errors.
12638 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01101);
12639 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01100);
Cort530cf382016-12-08 09:59:47 -080012640 m_commandBuffer->ClearDepthStencilImage(depth_image, VK_IMAGE_LAYOUT_UNDEFINED, &depth_clear_value, 1, &clear_range);
Cort3b021012016-12-07 12:00:57 -080012641 m_errorMonitor->VerifyFound();
12642 // Fail due to provided layout not matching actual current layout for depth clear.
12643 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01100);
Cort530cf382016-12-08 09:59:47 -080012644 m_commandBuffer->ClearDepthStencilImage(depth_image, VK_IMAGE_LAYOUT_GENERAL, &depth_clear_value, 1, &clear_range);
Cort3b021012016-12-07 12:00:57 -080012645 m_errorMonitor->VerifyFound();
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010012646
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012647 // Now cause error due to bad image layout transition in PipelineBarrier
12648 VkImageMemoryBarrier image_barrier[1] = {};
Cort3b021012016-12-07 12:00:57 -080012649 image_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012650 image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
Cort3b021012016-12-07 12:00:57 -080012651 image_barrier[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012652 image_barrier[0].image = src_image;
Cort3b021012016-12-07 12:00:57 -080012653 image_barrier[0].subresourceRange.layerCount = image_create_info.arrayLayers;
12654 image_barrier[0].subresourceRange.levelCount = image_create_info.mipLevels;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012655 image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012656 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski91c28262017-03-22 13:06:12 -060012657 "you cannot transition the layout of aspect 1 from "
12658 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL when current layout is "
12659 "VK_IMAGE_LAYOUT_GENERAL.");
Mike Weiblen62d08a32017-03-07 22:18:27 -070012660 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00305);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012661 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
12662 NULL, 0, NULL, 1, image_barrier);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012663 m_errorMonitor->VerifyFound();
12664
12665 // Finally some layout errors at RenderPass create time
12666 // Just hacking in specific state to get to the errors we want so don't copy this unless you know what you're doing.
12667 VkAttachmentReference attach = {};
12668 // perf warning for GENERAL layout w/ non-DS input attachment
12669 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
12670 VkSubpassDescription subpass = {};
12671 subpass.inputAttachmentCount = 1;
12672 subpass.pInputAttachments = &attach;
12673 VkRenderPassCreateInfo rpci = {};
12674 rpci.subpassCount = 1;
12675 rpci.pSubpasses = &subpass;
12676 rpci.attachmentCount = 1;
12677 VkAttachmentDescription attach_desc = {};
12678 attach_desc.format = VK_FORMAT_UNDEFINED;
12679 rpci.pAttachments = &attach_desc;
Tobin Ehlis1efce022016-05-11 10:40:34 -060012680 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012681 VkRenderPass rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012682 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
12683 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012684 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12685 m_errorMonitor->VerifyFound();
12686 // error w/ non-general layout
12687 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
12688
12689 m_errorMonitor->SetDesiredFailureMsg(
12690 VK_DEBUG_REPORT_ERROR_BIT_EXT,
12691 "Layout for input attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be READ_ONLY_OPTIMAL or GENERAL.");
12692 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12693 m_errorMonitor->VerifyFound();
12694 subpass.inputAttachmentCount = 0;
12695 subpass.colorAttachmentCount = 1;
12696 subpass.pColorAttachments = &attach;
12697 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
12698 // perf warning for GENERAL layout on color attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012699 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
12700 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012701 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12702 m_errorMonitor->VerifyFound();
12703 // error w/ non-color opt or GENERAL layout for color attachment
12704 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
12705 m_errorMonitor->SetDesiredFailureMsg(
12706 VK_DEBUG_REPORT_ERROR_BIT_EXT,
12707 "Layout for color attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.");
12708 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12709 m_errorMonitor->VerifyFound();
12710 subpass.colorAttachmentCount = 0;
12711 subpass.pDepthStencilAttachment = &attach;
12712 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
12713 // perf warning for GENERAL layout on DS attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012714 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
12715 "GENERAL layout for depth attachment may not give optimal performance.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012716 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12717 m_errorMonitor->VerifyFound();
12718 // error w/ non-ds opt or GENERAL layout for color attachment
12719 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012720 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12721 "Layout for depth attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be "
12722 "DEPTH_STENCIL_ATTACHMENT_OPTIMAL, DEPTH_STENCIL_READ_ONLY_OPTIMAL or GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012723 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12724 m_errorMonitor->VerifyFound();
Tobin Ehlis1efce022016-05-11 10:40:34 -060012725 // For this error we need a valid renderpass so create default one
12726 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
12727 attach.attachment = 0;
Tony Barbourf887b162017-03-09 10:06:46 -070012728 attach_desc.format = depth_format;
Tobin Ehlis1efce022016-05-11 10:40:34 -060012729 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
12730 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
12731 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
12732 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
12733 // Can't do a CLEAR load on READ_ONLY initialLayout
12734 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
12735 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
12736 attach_desc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012737 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski91c28262017-03-22 13:06:12 -060012738 "with invalid first layout VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL");
Tobin Ehlis1efce022016-05-11 10:40:34 -060012739 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12740 m_errorMonitor->VerifyFound();
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012741
Cort3b021012016-12-07 12:00:57 -080012742 vkFreeMemory(m_device->device(), src_image_mem, NULL);
12743 vkFreeMemory(m_device->device(), dst_image_mem, NULL);
12744 vkFreeMemory(m_device->device(), depth_image_mem, NULL);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012745 vkDestroyImage(m_device->device(), src_image, NULL);
12746 vkDestroyImage(m_device->device(), dst_image, NULL);
Cort3b021012016-12-07 12:00:57 -080012747 vkDestroyImage(m_device->device(), depth_image, NULL);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012748}
Tobin Ehlisd8d89182016-07-18 20:13:11 -060012749
Tobin Ehlise0936662016-10-11 08:10:51 -060012750TEST_F(VkLayerTest, InvalidStorageImageLayout) {
12751 TEST_DESCRIPTION("Attempt to update a STORAGE_IMAGE descriptor w/o GENERAL layout.");
12752 VkResult err;
12753
Tony Barbour1fa09702017-03-16 12:09:08 -060012754 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlise0936662016-10-11 08:10:51 -060012755
12756 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
12757 VkImageTiling tiling;
12758 VkFormatProperties format_properties;
12759 vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties);
12760 if (format_properties.linearTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
12761 tiling = VK_IMAGE_TILING_LINEAR;
12762 } else if (format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
12763 tiling = VK_IMAGE_TILING_OPTIMAL;
12764 } else {
Dave Houlton584d51e2017-02-16 12:52:54 -070012765 printf(" Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; skipped.\n");
Tobin Ehlise0936662016-10-11 08:10:51 -060012766 return;
12767 }
12768
12769 VkDescriptorPoolSize ds_type = {};
12770 ds_type.type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
12771 ds_type.descriptorCount = 1;
12772
12773 VkDescriptorPoolCreateInfo ds_pool_ci = {};
12774 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12775 ds_pool_ci.maxSets = 1;
12776 ds_pool_ci.poolSizeCount = 1;
12777 ds_pool_ci.pPoolSizes = &ds_type;
12778 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
12779
12780 VkDescriptorPool ds_pool;
12781 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
12782 ASSERT_VK_SUCCESS(err);
12783
12784 VkDescriptorSetLayoutBinding dsl_binding = {};
12785 dsl_binding.binding = 0;
12786 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
12787 dsl_binding.descriptorCount = 1;
12788 dsl_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12789 dsl_binding.pImmutableSamplers = NULL;
12790
12791 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
12792 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12793 ds_layout_ci.pNext = NULL;
12794 ds_layout_ci.bindingCount = 1;
12795 ds_layout_ci.pBindings = &dsl_binding;
12796
12797 VkDescriptorSetLayout ds_layout;
12798 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
12799 ASSERT_VK_SUCCESS(err);
12800
12801 VkDescriptorSetAllocateInfo alloc_info = {};
12802 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12803 alloc_info.descriptorSetCount = 1;
12804 alloc_info.descriptorPool = ds_pool;
12805 alloc_info.pSetLayouts = &ds_layout;
12806 VkDescriptorSet descriptor_set;
12807 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
12808 ASSERT_VK_SUCCESS(err);
12809
12810 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12811 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12812 pipeline_layout_ci.pNext = NULL;
12813 pipeline_layout_ci.setLayoutCount = 1;
12814 pipeline_layout_ci.pSetLayouts = &ds_layout;
12815 VkPipelineLayout pipeline_layout;
12816 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
12817 ASSERT_VK_SUCCESS(err);
12818
12819 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060012820 image.Init(32, 32, 1, tex_format, VK_IMAGE_USAGE_STORAGE_BIT, tiling, 0);
Tobin Ehlise0936662016-10-11 08:10:51 -060012821 ASSERT_TRUE(image.initialized());
12822 VkImageView view = image.targetView(tex_format);
12823
12824 VkDescriptorImageInfo image_info = {};
12825 image_info.imageView = view;
12826 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
12827
12828 VkWriteDescriptorSet descriptor_write = {};
12829 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12830 descriptor_write.dstSet = descriptor_set;
12831 descriptor_write.dstBinding = 0;
12832 descriptor_write.descriptorCount = 1;
12833 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
12834 descriptor_write.pImageInfo = &image_info;
12835
12836 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12837 " of VK_DESCRIPTOR_TYPE_STORAGE_IMAGE type is being updated with layout "
12838 "VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL but according to spec ");
12839 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
12840 m_errorMonitor->VerifyFound();
12841
12842 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12843 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12844 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
12845 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
12846}
12847
Chris Forbes3fa68552017-05-18 14:34:05 -070012848TEST_F(VkLayerTest, NonSimultaneousSecondaryMarksPrimary) {
Tony Barbour1fa09702017-03-16 12:09:08 -060012849 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes3fa68552017-05-18 14:34:05 -070012850 const char *simultaneous_use_message =
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012851 "does not have VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set and "
12852 "will cause primary command buffer";
Mark Mueller93b938f2016-08-18 10:27:40 -060012853
Chris Forbes3fa68552017-05-18 14:34:05 -070012854 VkCommandBufferObj secondary(m_device, m_commandPool, VK_COMMAND_BUFFER_LEVEL_SECONDARY);
Mark Mueller93b938f2016-08-18 10:27:40 -060012855
Chris Forbes3fa68552017-05-18 14:34:05 -070012856 secondary.begin();
12857 secondary.end();
Rene Lindsay24cf6c52017-01-04 12:06:59 -070012858
Chris Forbes3fa68552017-05-18 14:34:05 -070012859 VkCommandBufferBeginInfo cbbi = {
12860 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
12861 VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT, nullptr,
12862 };
Mark Mueller93b938f2016-08-18 10:27:40 -060012863
Chris Forbes3fa68552017-05-18 14:34:05 -070012864 m_commandBuffer->begin(&cbbi);
12865 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, simultaneous_use_message);
12866 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary.handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060012867 m_errorMonitor->VerifyFound();
Chris Forbes3fa68552017-05-18 14:34:05 -070012868 m_commandBuffer->end();
12869}
Mark Mueller93b938f2016-08-18 10:27:40 -060012870
Chris Forbes3fa68552017-05-18 14:34:05 -070012871TEST_F(VkLayerTest, SimultaneousUseSecondaryTwoExecutes) {
12872 ASSERT_NO_FATAL_FAILURE(Init());
Mark Mueller93b938f2016-08-18 10:27:40 -060012873
Chris Forbes3fa68552017-05-18 14:34:05 -070012874 const char *simultaneous_use_message = "without VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set!";
Mark Mueller4042b652016-09-05 22:52:21 -060012875
Chris Forbes3fa68552017-05-18 14:34:05 -070012876 VkCommandBufferObj secondary(m_device, m_commandPool, VK_COMMAND_BUFFER_LEVEL_SECONDARY);
12877
12878 VkCommandBufferInheritanceInfo inh = {
12879 VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO, nullptr,
12880 };
12881 VkCommandBufferBeginInfo cbbi = {
12882 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
12883 0, &inh
12884 };
12885
12886 secondary.begin(&cbbi);
12887 secondary.end();
12888
12889 m_commandBuffer->begin();
12890 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary.handle());
12891 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, simultaneous_use_message);
12892 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary.handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060012893 m_errorMonitor->VerifyFound();
Chris Forbes3fa68552017-05-18 14:34:05 -070012894 m_commandBuffer->end();
12895}
Rene Lindsay24cf6c52017-01-04 12:06:59 -070012896
Chris Forbes3fa68552017-05-18 14:34:05 -070012897TEST_F(VkLayerTest, SimultaneousUseSecondarySingleExecute) {
12898 ASSERT_NO_FATAL_FAILURE(Init());
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012899
Chris Forbes3fa68552017-05-18 14:34:05 -070012900 // variation on previous test executing the same CB twice in the same
12901 // CmdExecuteCommands call
12902
12903 const char *simultaneous_use_message = "without VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set!";
12904
12905 VkCommandBufferObj secondary(m_device, m_commandPool, VK_COMMAND_BUFFER_LEVEL_SECONDARY);
12906
12907 VkCommandBufferInheritanceInfo inh = {
12908 VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO, nullptr,
12909 };
12910 VkCommandBufferBeginInfo cbbi = {
12911 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
12912 0, &inh
12913 };
12914
12915 secondary.begin(&cbbi);
12916 secondary.end();
12917
12918 m_commandBuffer->begin();
12919 VkCommandBuffer cbs[] = { secondary.handle(), secondary.handle() };
12920 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, simultaneous_use_message);
12921 vkCmdExecuteCommands(m_commandBuffer->handle(), 2, cbs);
12922 m_errorMonitor->VerifyFound();
12923 m_commandBuffer->end();
Mark Mueller93b938f2016-08-18 10:27:40 -060012924}
12925
Tony Barbour626994c2017-02-08 15:29:37 -070012926TEST_F(VkLayerTest, SimultaneousUseOneShot) {
12927 TEST_DESCRIPTION(
12928 "Submit the same command buffer twice in one submit looking for simultaneous use and one time submit"
12929 "errors");
12930 const char *simultaneous_use_message = "is already in use and is not marked for simultaneous use";
12931 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 -060012932 ASSERT_NO_FATAL_FAILURE(Init());
Tony Barbour626994c2017-02-08 15:29:37 -070012933
12934 VkCommandBuffer cmd_bufs[2];
12935 VkCommandBufferAllocateInfo alloc_info;
12936 alloc_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
12937 alloc_info.pNext = NULL;
12938 alloc_info.commandBufferCount = 2;
Mike Schuchardt06304c22017-03-01 17:09:09 -070012939 alloc_info.commandPool = m_commandPool->handle();
Tony Barbour626994c2017-02-08 15:29:37 -070012940 alloc_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
12941 vkAllocateCommandBuffers(m_device->device(), &alloc_info, cmd_bufs);
12942
12943 VkCommandBufferBeginInfo cb_binfo;
12944 cb_binfo.pNext = NULL;
12945 cb_binfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
12946 cb_binfo.pInheritanceInfo = VK_NULL_HANDLE;
12947 cb_binfo.flags = 0;
12948 vkBeginCommandBuffer(cmd_bufs[0], &cb_binfo);
12949 VkViewport viewport = {0, 0, 16, 16, 0, 1};
12950 vkCmdSetViewport(cmd_bufs[0], 0, 1, &viewport);
12951 vkEndCommandBuffer(cmd_bufs[0]);
12952 VkCommandBuffer duplicates[2] = {cmd_bufs[0], cmd_bufs[0]};
12953
12954 VkSubmitInfo submit_info = {};
12955 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12956 submit_info.commandBufferCount = 2;
12957 submit_info.pCommandBuffers = duplicates;
12958 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, simultaneous_use_message);
12959 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12960 m_errorMonitor->VerifyFound();
12961 vkQueueWaitIdle(m_device->m_queue);
12962
12963 // Set one time use and now look for one time submit
12964 duplicates[0] = duplicates[1] = cmd_bufs[1];
12965 cb_binfo.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT | VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
12966 vkBeginCommandBuffer(cmd_bufs[1], &cb_binfo);
12967 vkCmdSetViewport(cmd_bufs[1], 0, 1, &viewport);
12968 vkEndCommandBuffer(cmd_bufs[1]);
12969 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, one_shot_message);
12970 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12971 m_errorMonitor->VerifyFound();
12972 vkQueueWaitIdle(m_device->m_queue);
12973}
12974
Tobin Ehlisb093da82017-01-19 12:05:27 -070012975TEST_F(VkLayerTest, StageMaskGsTsEnabled) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012976 TEST_DESCRIPTION(
12977 "Attempt to use a stageMask w/ geometry shader and tesselation shader bits enabled when those features are "
12978 "disabled on the device.");
Tobin Ehlisb093da82017-01-19 12:05:27 -070012979
Tony Barbour1fa09702017-03-16 12:09:08 -060012980 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisb093da82017-01-19 12:05:27 -070012981 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12982
12983 std::vector<const char *> device_extension_names;
12984 auto features = m_device->phy().features();
12985 // Make sure gs & ts are disabled
12986 features.geometryShader = false;
12987 features.tessellationShader = false;
12988 // The sacrificial device object
12989 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
12990
12991 VkCommandPoolCreateInfo pool_create_info{};
12992 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
12993 pool_create_info.queueFamilyIndex = test_device.graphics_queue_node_index_;
12994
12995 VkCommandPool command_pool;
12996 vkCreateCommandPool(test_device.handle(), &pool_create_info, nullptr, &command_pool);
12997
12998 VkCommandBufferAllocateInfo cmd = {};
12999 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
13000 cmd.pNext = NULL;
13001 cmd.commandPool = command_pool;
13002 cmd.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
13003 cmd.commandBufferCount = 1;
13004
13005 VkCommandBuffer cmd_buffer;
13006 VkResult err = vkAllocateCommandBuffers(test_device.handle(), &cmd, &cmd_buffer);
13007 ASSERT_VK_SUCCESS(err);
13008
13009 VkEvent event;
13010 VkEventCreateInfo evci = {};
13011 evci.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
13012 VkResult result = vkCreateEvent(test_device.handle(), &evci, NULL, &event);
13013 ASSERT_VK_SUCCESS(result);
13014
13015 VkCommandBufferBeginInfo cbbi = {};
13016 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
13017 vkBeginCommandBuffer(cmd_buffer, &cbbi);
13018 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00230);
13019 vkCmdSetEvent(cmd_buffer, event, VK_PIPELINE_STAGE_GEOMETRY_SHADER_BIT);
13020 m_errorMonitor->VerifyFound();
13021
13022 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00231);
13023 vkCmdSetEvent(cmd_buffer, event, VK_PIPELINE_STAGE_TESSELLATION_CONTROL_SHADER_BIT);
13024 m_errorMonitor->VerifyFound();
13025
13026 vkDestroyEvent(test_device.handle(), event, NULL);
13027 vkDestroyCommandPool(test_device.handle(), command_pool, NULL);
13028}
13029
Chris Forbesd70103a2017-04-13 11:34:09 -070013030TEST_F(VkLayerTest, EventInUseDestroyedSignaled) {
Tony Barbour1fa09702017-03-16 12:09:08 -060013031 ASSERT_NO_FATAL_FAILURE(Init());
Mark Mueller917f6bc2016-08-30 10:57:19 -060013032 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13033
Tony Barbour552f6c02016-12-21 14:34:07 -070013034 m_commandBuffer->BeginCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060013035
13036 VkEvent event;
13037 VkEventCreateInfo event_create_info = {};
13038 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
13039 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013040 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Mueller917f6bc2016-08-30 10:57:19 -060013041
Tony Barbour552f6c02016-12-21 14:34:07 -070013042 m_commandBuffer->EndCommandBuffer();
Mark Muellerc8d441e2016-08-23 17:36:00 -060013043 vkDestroyEvent(m_device->device(), event, nullptr);
13044
13045 VkSubmitInfo submit_info = {};
13046 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
13047 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013048 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Lobodzinskife4be302017-02-14 13:08:15 -070013049 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is invalid because bound");
Mark Muellerc8d441e2016-08-23 17:36:00 -060013050 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
13051 m_errorMonitor->VerifyFound();
Chris Forbesd70103a2017-04-13 11:34:09 -070013052}
Mark Muellerc8d441e2016-08-23 17:36:00 -060013053
Chris Forbesd70103a2017-04-13 11:34:09 -070013054TEST_F(VkLayerTest, InUseDestroyedSignaled) {
13055 TEST_DESCRIPTION(
13056 "Use vkCmdExecuteCommands with invalid state "
13057 "in primary and secondary command buffers. "
13058 "Delete objects that are inuse. Call VkQueueSubmit "
13059 "with an event that has been deleted.");
Mark Muellerc8d441e2016-08-23 17:36:00 -060013060
Chris Forbesd70103a2017-04-13 11:34:09 -070013061 ASSERT_NO_FATAL_FAILURE(Init());
13062 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13063
13064 m_errorMonitor->ExpectSuccess();
Mark Muellerc8d441e2016-08-23 17:36:00 -060013065
Mark Mueller917f6bc2016-08-30 10:57:19 -060013066 VkSemaphoreCreateInfo semaphore_create_info = {};
13067 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
13068 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013069 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller917f6bc2016-08-30 10:57:19 -060013070 VkFenceCreateInfo fence_create_info = {};
13071 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
13072 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013073 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller917f6bc2016-08-30 10:57:19 -060013074
13075 VkDescriptorPoolSize descriptor_pool_type_count = {};
Mark Mueller4042b652016-09-05 22:52:21 -060013076 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060013077 descriptor_pool_type_count.descriptorCount = 1;
13078
13079 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
13080 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
13081 descriptor_pool_create_info.maxSets = 1;
13082 descriptor_pool_create_info.poolSizeCount = 1;
13083 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013084 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Mark Mueller917f6bc2016-08-30 10:57:19 -060013085
13086 VkDescriptorPool descriptorset_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013087 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
Mark Mueller917f6bc2016-08-30 10:57:19 -060013088
13089 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
Mark Mueller4042b652016-09-05 22:52:21 -060013090 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060013091 descriptorset_layout_binding.descriptorCount = 1;
13092 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
13093
13094 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013095 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060013096 descriptorset_layout_create_info.bindingCount = 1;
13097 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
13098
13099 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013100 ASSERT_VK_SUCCESS(
13101 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060013102
13103 VkDescriptorSet descriptorset;
13104 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013105 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060013106 descriptorset_allocate_info.descriptorSetCount = 1;
13107 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
13108 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013109 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
Mark Mueller917f6bc2016-08-30 10:57:19 -060013110
Mark Mueller4042b652016-09-05 22:52:21 -060013111 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
13112
13113 VkDescriptorBufferInfo buffer_info = {};
13114 buffer_info.buffer = buffer_test.GetBuffer();
13115 buffer_info.offset = 0;
13116 buffer_info.range = 1024;
13117
13118 VkWriteDescriptorSet write_descriptor_set = {};
13119 write_descriptor_set.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
13120 write_descriptor_set.dstSet = descriptorset;
13121 write_descriptor_set.descriptorCount = 1;
13122 write_descriptor_set.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
13123 write_descriptor_set.pBufferInfo = &buffer_info;
13124
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013125 vkUpdateDescriptorSets(m_device->device(), 1, &write_descriptor_set, 0, nullptr);
Mark Mueller4042b652016-09-05 22:52:21 -060013126
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013127 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
13128 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Mueller917f6bc2016-08-30 10:57:19 -060013129
13130 VkPipelineObj pipe(m_device);
13131 pipe.AddColorAttachment();
13132 pipe.AddShader(&vs);
13133 pipe.AddShader(&fs);
13134
13135 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013136 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060013137 pipeline_layout_create_info.setLayoutCount = 1;
13138 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
13139
13140 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013141 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060013142
13143 pipe.CreateVKPipeline(pipeline_layout, m_renderPass);
13144
Chris Forbesd70103a2017-04-13 11:34:09 -070013145 VkEvent event;
13146 VkEventCreateInfo event_create_info = {};
13147 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
13148 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
13149
Tony Barbour552f6c02016-12-21 14:34:07 -070013150 m_commandBuffer->BeginCommandBuffer();
Chris Forbesd70103a2017-04-13 11:34:09 -070013151
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013152 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Muellerc8d441e2016-08-23 17:36:00 -060013153
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013154 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
13155 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
13156 &descriptorset, 0, NULL);
Mark Mueller917f6bc2016-08-30 10:57:19 -060013157
Tony Barbour552f6c02016-12-21 14:34:07 -070013158 m_commandBuffer->EndCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060013159
Chris Forbesd70103a2017-04-13 11:34:09 -070013160 VkSubmitInfo submit_info = {};
13161 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
13162 submit_info.commandBufferCount = 1;
13163 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller917f6bc2016-08-30 10:57:19 -060013164 submit_info.signalSemaphoreCount = 1;
13165 submit_info.pSignalSemaphores = &semaphore;
13166 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013167 m_errorMonitor->Reset(); // resume logmsg processing
Mark Muellerc8d441e2016-08-23 17:36:00 -060013168
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070013169 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00213);
Mark Mueller917f6bc2016-08-30 10:57:19 -060013170 vkDestroyEvent(m_device->device(), event, nullptr);
13171 m_errorMonitor->VerifyFound();
13172
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070013173 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00199);
Mark Mueller917f6bc2016-08-30 10:57:19 -060013174 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
13175 m_errorMonitor->VerifyFound();
13176
Jeremy Hayes08369882017-02-02 10:31:06 -070013177 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Fence 0x");
Mark Mueller917f6bc2016-08-30 10:57:19 -060013178 vkDestroyFence(m_device->device(), fence, nullptr);
13179 m_errorMonitor->VerifyFound();
13180
Tobin Ehlis122207b2016-09-01 08:50:06 -070013181 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070013182 m_errorMonitor->SetUnexpectedError("If semaphore is not VK_NULL_HANDLE, semaphore must be a valid VkSemaphore handle");
13183 m_errorMonitor->SetUnexpectedError("Unable to remove Semaphore obj");
Mark Mueller917f6bc2016-08-30 10:57:19 -060013184 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070013185 m_errorMonitor->SetUnexpectedError("If fence is not VK_NULL_HANDLE, fence must be a valid VkFence handle");
13186 m_errorMonitor->SetUnexpectedError("Unable to remove Fence obj");
Mark Mueller917f6bc2016-08-30 10:57:19 -060013187 vkDestroyFence(m_device->device(), fence, nullptr);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070013188 m_errorMonitor->SetUnexpectedError("If event is not VK_NULL_HANDLE, event must be a valid VkEvent handle");
13189 m_errorMonitor->SetUnexpectedError("Unable to remove Event obj");
Mark Mueller917f6bc2016-08-30 10:57:19 -060013190 vkDestroyEvent(m_device->device(), event, nullptr);
13191 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013192 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
Mark Mueller917f6bc2016-08-30 10:57:19 -060013193 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13194}
13195
Tobin Ehlis2adda372016-09-01 08:51:06 -070013196TEST_F(VkLayerTest, QueryPoolInUseDestroyedSignaled) {
13197 TEST_DESCRIPTION("Delete in-use query pool.");
13198
Tony Barbour1fa09702017-03-16 12:09:08 -060013199 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis2adda372016-09-01 08:51:06 -070013200 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13201
13202 VkQueryPool query_pool;
13203 VkQueryPoolCreateInfo query_pool_ci{};
13204 query_pool_ci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
13205 query_pool_ci.queryType = VK_QUERY_TYPE_TIMESTAMP;
13206 query_pool_ci.queryCount = 1;
13207 vkCreateQueryPool(m_device->device(), &query_pool_ci, nullptr, &query_pool);
Tony Barbour552f6c02016-12-21 14:34:07 -070013208 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis2adda372016-09-01 08:51:06 -070013209 // Reset query pool to create binding with cmd buffer
13210 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0, 1);
13211
Tony Barbour552f6c02016-12-21 14:34:07 -070013212 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis2adda372016-09-01 08:51:06 -070013213
13214 VkSubmitInfo submit_info = {};
13215 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
13216 submit_info.commandBufferCount = 1;
13217 submit_info.pCommandBuffers = &m_commandBuffer->handle();
13218 // Submit cmd buffer and then destroy query pool while in-flight
13219 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
13220
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070013221 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01012);
Tobin Ehlis2adda372016-09-01 08:51:06 -070013222 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
13223 m_errorMonitor->VerifyFound();
13224
13225 vkQueueWaitIdle(m_device->m_queue);
13226 // Now that cmd buffer done we can safely destroy query_pool
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070013227 m_errorMonitor->SetUnexpectedError("If queryPool is not VK_NULL_HANDLE, queryPool must be a valid VkQueryPool handle");
Mark Lobodzinski74597792017-04-11 15:43:49 -060013228 m_errorMonitor->SetUnexpectedError("Unable to remove QueryPool obj");
Tobin Ehlis2adda372016-09-01 08:51:06 -070013229 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
13230}
13231
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060013232TEST_F(VkLayerTest, PipelineInUseDestroyedSignaled) {
13233 TEST_DESCRIPTION("Delete in-use pipeline.");
13234
Tony Barbour1fa09702017-03-16 12:09:08 -060013235 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060013236 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13237
13238 // Empty pipeline layout used for binding PSO
13239 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
13240 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13241 pipeline_layout_ci.setLayoutCount = 0;
13242 pipeline_layout_ci.pSetLayouts = NULL;
13243
13244 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013245 VkResult err = vkCreatePipelineLayout(m_device->handle(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060013246 ASSERT_VK_SUCCESS(err);
13247
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070013248 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00555);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060013249 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013250 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
13251 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060013252 // Store pipeline handle so we can actually delete it before test finishes
13253 VkPipeline delete_this_pipeline;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013254 { // Scope pipeline so it will be auto-deleted
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060013255 VkPipelineObj pipe(m_device);
13256 pipe.AddShader(&vs);
13257 pipe.AddShader(&fs);
13258 pipe.AddColorAttachment();
13259 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13260 delete_this_pipeline = pipe.handle();
13261
Tony Barbour552f6c02016-12-21 14:34:07 -070013262 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060013263 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013264 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060013265
Tony Barbour552f6c02016-12-21 14:34:07 -070013266 m_commandBuffer->EndCommandBuffer();
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060013267
13268 VkSubmitInfo submit_info = {};
13269 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
13270 submit_info.commandBufferCount = 1;
13271 submit_info.pCommandBuffers = &m_commandBuffer->handle();
13272 // Submit cmd buffer and then pipeline destroyed while in-flight
13273 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013274 } // Pipeline deletion triggered here
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060013275 m_errorMonitor->VerifyFound();
13276 // Make sure queue finished and then actually delete pipeline
13277 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070013278 m_errorMonitor->SetUnexpectedError("If pipeline is not VK_NULL_HANDLE, pipeline must be a valid VkPipeline handle");
13279 m_errorMonitor->SetUnexpectedError("Unable to remove Pipeline obj");
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060013280 vkDestroyPipeline(m_device->handle(), delete_this_pipeline, nullptr);
13281 vkDestroyPipelineLayout(m_device->handle(), pipeline_layout, nullptr);
13282}
13283
Tobin Ehlis7d965da2016-09-19 16:15:45 -060013284TEST_F(VkLayerTest, ImageViewInUseDestroyedSignaled) {
13285 TEST_DESCRIPTION("Delete in-use imageView.");
13286
Tony Barbour1fa09702017-03-16 12:09:08 -060013287 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis7d965da2016-09-19 16:15:45 -060013288 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13289
13290 VkDescriptorPoolSize ds_type_count;
13291 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
13292 ds_type_count.descriptorCount = 1;
13293
13294 VkDescriptorPoolCreateInfo ds_pool_ci = {};
13295 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
13296 ds_pool_ci.maxSets = 1;
13297 ds_pool_ci.poolSizeCount = 1;
13298 ds_pool_ci.pPoolSizes = &ds_type_count;
13299
13300 VkDescriptorPool ds_pool;
13301 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
13302 ASSERT_VK_SUCCESS(err);
13303
13304 VkSamplerCreateInfo sampler_ci = {};
13305 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
13306 sampler_ci.pNext = NULL;
13307 sampler_ci.magFilter = VK_FILTER_NEAREST;
13308 sampler_ci.minFilter = VK_FILTER_NEAREST;
13309 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
13310 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
13311 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
13312 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
13313 sampler_ci.mipLodBias = 1.0;
13314 sampler_ci.anisotropyEnable = VK_FALSE;
13315 sampler_ci.maxAnisotropy = 1;
13316 sampler_ci.compareEnable = VK_FALSE;
13317 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
13318 sampler_ci.minLod = 1.0;
13319 sampler_ci.maxLod = 1.0;
13320 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
13321 sampler_ci.unnormalizedCoordinates = VK_FALSE;
13322 VkSampler sampler;
13323
13324 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
13325 ASSERT_VK_SUCCESS(err);
13326
13327 VkDescriptorSetLayoutBinding layout_binding;
13328 layout_binding.binding = 0;
13329 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
13330 layout_binding.descriptorCount = 1;
13331 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
13332 layout_binding.pImmutableSamplers = NULL;
13333
13334 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
13335 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
13336 ds_layout_ci.bindingCount = 1;
13337 ds_layout_ci.pBindings = &layout_binding;
13338 VkDescriptorSetLayout ds_layout;
13339 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
13340 ASSERT_VK_SUCCESS(err);
13341
13342 VkDescriptorSetAllocateInfo alloc_info = {};
13343 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
13344 alloc_info.descriptorSetCount = 1;
13345 alloc_info.descriptorPool = ds_pool;
13346 alloc_info.pSetLayouts = &ds_layout;
13347 VkDescriptorSet descriptor_set;
13348 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
13349 ASSERT_VK_SUCCESS(err);
13350
13351 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
13352 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13353 pipeline_layout_ci.pNext = NULL;
13354 pipeline_layout_ci.setLayoutCount = 1;
13355 pipeline_layout_ci.pSetLayouts = &ds_layout;
13356
13357 VkPipelineLayout pipeline_layout;
13358 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
13359 ASSERT_VK_SUCCESS(err);
13360
13361 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060013362 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 -060013363 ASSERT_TRUE(image.initialized());
13364
13365 VkImageView view;
13366 VkImageViewCreateInfo ivci = {};
13367 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
13368 ivci.image = image.handle();
13369 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
13370 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
13371 ivci.subresourceRange.layerCount = 1;
13372 ivci.subresourceRange.baseMipLevel = 0;
13373 ivci.subresourceRange.levelCount = 1;
13374 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
13375
13376 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
13377 ASSERT_VK_SUCCESS(err);
13378
13379 VkDescriptorImageInfo image_info{};
13380 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
13381 image_info.imageView = view;
13382 image_info.sampler = sampler;
13383
13384 VkWriteDescriptorSet descriptor_write = {};
13385 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
13386 descriptor_write.dstSet = descriptor_set;
13387 descriptor_write.dstBinding = 0;
13388 descriptor_write.descriptorCount = 1;
13389 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
13390 descriptor_write.pImageInfo = &image_info;
13391
13392 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
13393
13394 // Create PSO to use the sampler
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013395 char const *vsSource =
13396 "#version 450\n"
13397 "\n"
13398 "out gl_PerVertex { \n"
13399 " vec4 gl_Position;\n"
13400 "};\n"
13401 "void main(){\n"
13402 " gl_Position = vec4(1);\n"
13403 "}\n";
13404 char const *fsSource =
13405 "#version 450\n"
13406 "\n"
13407 "layout(set=0, binding=0) uniform sampler2D s;\n"
13408 "layout(location=0) out vec4 x;\n"
13409 "void main(){\n"
13410 " x = texture(s, vec2(1));\n"
13411 "}\n";
Tobin Ehlis7d965da2016-09-19 16:15:45 -060013412 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13413 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13414 VkPipelineObj pipe(m_device);
13415 pipe.AddShader(&vs);
13416 pipe.AddShader(&fs);
13417 pipe.AddColorAttachment();
13418 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13419
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070013420 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00776);
Tobin Ehlis7d965da2016-09-19 16:15:45 -060013421
Tony Barbour552f6c02016-12-21 14:34:07 -070013422 m_commandBuffer->BeginCommandBuffer();
13423 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis7d965da2016-09-19 16:15:45 -060013424 // Bind pipeline to cmd buffer
13425 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
13426 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
13427 &descriptor_set, 0, nullptr);
Rene Lindsaya8880622017-01-18 13:12:59 -070013428
13429 VkViewport viewport = {0, 0, 16, 16, 0, 1};
13430 VkRect2D scissor = {{0, 0}, {16, 16}};
13431 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
13432 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
13433
Tobin Ehlis7d965da2016-09-19 16:15:45 -060013434 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070013435 m_commandBuffer->EndRenderPass();
13436 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis7d965da2016-09-19 16:15:45 -060013437 // Submit cmd buffer then destroy sampler
13438 VkSubmitInfo submit_info = {};
13439 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
13440 submit_info.commandBufferCount = 1;
13441 submit_info.pCommandBuffers = &m_commandBuffer->handle();
13442 // Submit cmd buffer and then destroy imageView while in-flight
13443 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
13444
13445 vkDestroyImageView(m_device->device(), view, nullptr);
13446 m_errorMonitor->VerifyFound();
13447 vkQueueWaitIdle(m_device->m_queue);
13448 // Now we can actually destroy imageView
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070013449 m_errorMonitor->SetUnexpectedError("If imageView is not VK_NULL_HANDLE, imageView must be a valid VkImageView handle");
Mark Lobodzinski74597792017-04-11 15:43:49 -060013450 m_errorMonitor->SetUnexpectedError("Unable to remove ImageView obj");
Tobin Ehlis7d965da2016-09-19 16:15:45 -060013451 vkDestroyImageView(m_device->device(), view, NULL);
13452 vkDestroySampler(m_device->device(), sampler, nullptr);
13453 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
13454 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
13455 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
13456}
13457
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060013458TEST_F(VkLayerTest, BufferViewInUseDestroyedSignaled) {
13459 TEST_DESCRIPTION("Delete in-use bufferView.");
13460
Tony Barbour1fa09702017-03-16 12:09:08 -060013461 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060013462 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13463
13464 VkDescriptorPoolSize ds_type_count;
13465 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
13466 ds_type_count.descriptorCount = 1;
13467
13468 VkDescriptorPoolCreateInfo ds_pool_ci = {};
13469 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
13470 ds_pool_ci.maxSets = 1;
13471 ds_pool_ci.poolSizeCount = 1;
13472 ds_pool_ci.pPoolSizes = &ds_type_count;
13473
13474 VkDescriptorPool ds_pool;
13475 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
13476 ASSERT_VK_SUCCESS(err);
13477
13478 VkDescriptorSetLayoutBinding layout_binding;
13479 layout_binding.binding = 0;
13480 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
13481 layout_binding.descriptorCount = 1;
13482 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
13483 layout_binding.pImmutableSamplers = NULL;
13484
13485 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
13486 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
13487 ds_layout_ci.bindingCount = 1;
13488 ds_layout_ci.pBindings = &layout_binding;
13489 VkDescriptorSetLayout ds_layout;
13490 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
13491 ASSERT_VK_SUCCESS(err);
13492
13493 VkDescriptorSetAllocateInfo alloc_info = {};
13494 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
13495 alloc_info.descriptorSetCount = 1;
13496 alloc_info.descriptorPool = ds_pool;
13497 alloc_info.pSetLayouts = &ds_layout;
13498 VkDescriptorSet descriptor_set;
13499 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
13500 ASSERT_VK_SUCCESS(err);
13501
13502 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
13503 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13504 pipeline_layout_ci.pNext = NULL;
13505 pipeline_layout_ci.setLayoutCount = 1;
13506 pipeline_layout_ci.pSetLayouts = &ds_layout;
13507
13508 VkPipelineLayout pipeline_layout;
13509 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
13510 ASSERT_VK_SUCCESS(err);
13511
13512 VkBuffer buffer;
13513 uint32_t queue_family_index = 0;
13514 VkBufferCreateInfo buffer_create_info = {};
13515 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
13516 buffer_create_info.size = 1024;
13517 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
13518 buffer_create_info.queueFamilyIndexCount = 1;
13519 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
13520
13521 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
13522 ASSERT_VK_SUCCESS(err);
13523
13524 VkMemoryRequirements memory_reqs;
13525 VkDeviceMemory buffer_memory;
13526
13527 VkMemoryAllocateInfo memory_info = {};
13528 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
13529 memory_info.allocationSize = 0;
13530 memory_info.memoryTypeIndex = 0;
13531
13532 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
13533 memory_info.allocationSize = memory_reqs.size;
13534 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
13535 ASSERT_TRUE(pass);
13536
13537 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
13538 ASSERT_VK_SUCCESS(err);
13539 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
13540 ASSERT_VK_SUCCESS(err);
13541
13542 VkBufferView view;
13543 VkBufferViewCreateInfo bvci = {};
13544 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
13545 bvci.buffer = buffer;
13546 bvci.format = VK_FORMAT_R8_UNORM;
13547 bvci.range = VK_WHOLE_SIZE;
13548
13549 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
13550 ASSERT_VK_SUCCESS(err);
13551
13552 VkWriteDescriptorSet descriptor_write = {};
13553 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
13554 descriptor_write.dstSet = descriptor_set;
13555 descriptor_write.dstBinding = 0;
13556 descriptor_write.descriptorCount = 1;
13557 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
13558 descriptor_write.pTexelBufferView = &view;
13559
13560 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
13561
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013562 char const *vsSource =
13563 "#version 450\n"
13564 "\n"
13565 "out gl_PerVertex { \n"
13566 " vec4 gl_Position;\n"
13567 "};\n"
13568 "void main(){\n"
13569 " gl_Position = vec4(1);\n"
13570 "}\n";
13571 char const *fsSource =
13572 "#version 450\n"
13573 "\n"
13574 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
13575 "layout(location=0) out vec4 x;\n"
13576 "void main(){\n"
13577 " x = imageLoad(s, 0);\n"
13578 "}\n";
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060013579 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13580 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13581 VkPipelineObj pipe(m_device);
13582 pipe.AddShader(&vs);
13583 pipe.AddShader(&fs);
13584 pipe.AddColorAttachment();
13585 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13586
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070013587 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00701);
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060013588
Tony Barbour552f6c02016-12-21 14:34:07 -070013589 m_commandBuffer->BeginCommandBuffer();
13590 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060013591 VkViewport viewport = {0, 0, 16, 16, 0, 1};
13592 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
13593 VkRect2D scissor = {{0, 0}, {16, 16}};
13594 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
13595 // Bind pipeline to cmd buffer
13596 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
13597 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
13598 &descriptor_set, 0, nullptr);
13599 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070013600 m_commandBuffer->EndRenderPass();
13601 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060013602
13603 VkSubmitInfo submit_info = {};
13604 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
13605 submit_info.commandBufferCount = 1;
13606 submit_info.pCommandBuffers = &m_commandBuffer->handle();
13607 // Submit cmd buffer and then destroy bufferView while in-flight
13608 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
13609
13610 vkDestroyBufferView(m_device->device(), view, nullptr);
13611 m_errorMonitor->VerifyFound();
13612 vkQueueWaitIdle(m_device->m_queue);
13613 // Now we can actually destroy bufferView
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070013614 m_errorMonitor->SetUnexpectedError("If bufferView is not VK_NULL_HANDLE, bufferView must be a valid VkBufferView handle");
Mark Lobodzinski74597792017-04-11 15:43:49 -060013615 m_errorMonitor->SetUnexpectedError("Unable to remove BufferView obj");
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060013616 vkDestroyBufferView(m_device->device(), view, NULL);
13617 vkDestroyBuffer(m_device->device(), buffer, NULL);
13618 vkFreeMemory(m_device->device(), buffer_memory, NULL);
13619 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
13620 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
13621 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
13622}
13623
Tobin Ehlis209532e2016-09-07 13:52:18 -060013624TEST_F(VkLayerTest, SamplerInUseDestroyedSignaled) {
13625 TEST_DESCRIPTION("Delete in-use sampler.");
13626
Tony Barbour1fa09702017-03-16 12:09:08 -060013627 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis209532e2016-09-07 13:52:18 -060013628 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13629
13630 VkDescriptorPoolSize ds_type_count;
13631 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
13632 ds_type_count.descriptorCount = 1;
13633
13634 VkDescriptorPoolCreateInfo ds_pool_ci = {};
13635 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
13636 ds_pool_ci.maxSets = 1;
13637 ds_pool_ci.poolSizeCount = 1;
13638 ds_pool_ci.pPoolSizes = &ds_type_count;
13639
13640 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013641 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis209532e2016-09-07 13:52:18 -060013642 ASSERT_VK_SUCCESS(err);
13643
13644 VkSamplerCreateInfo sampler_ci = {};
13645 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
13646 sampler_ci.pNext = NULL;
13647 sampler_ci.magFilter = VK_FILTER_NEAREST;
13648 sampler_ci.minFilter = VK_FILTER_NEAREST;
13649 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
13650 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
13651 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
13652 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
13653 sampler_ci.mipLodBias = 1.0;
13654 sampler_ci.anisotropyEnable = VK_FALSE;
13655 sampler_ci.maxAnisotropy = 1;
13656 sampler_ci.compareEnable = VK_FALSE;
13657 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
13658 sampler_ci.minLod = 1.0;
13659 sampler_ci.maxLod = 1.0;
13660 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
13661 sampler_ci.unnormalizedCoordinates = VK_FALSE;
13662 VkSampler sampler;
13663
13664 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
13665 ASSERT_VK_SUCCESS(err);
13666
13667 VkDescriptorSetLayoutBinding layout_binding;
13668 layout_binding.binding = 0;
Tobin Ehlis94fc0ad2016-09-19 16:23:01 -060013669 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
Tobin Ehlis209532e2016-09-07 13:52:18 -060013670 layout_binding.descriptorCount = 1;
13671 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
13672 layout_binding.pImmutableSamplers = NULL;
13673
13674 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
13675 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
13676 ds_layout_ci.bindingCount = 1;
13677 ds_layout_ci.pBindings = &layout_binding;
13678 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013679 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060013680 ASSERT_VK_SUCCESS(err);
13681
13682 VkDescriptorSetAllocateInfo alloc_info = {};
13683 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
13684 alloc_info.descriptorSetCount = 1;
13685 alloc_info.descriptorPool = ds_pool;
13686 alloc_info.pSetLayouts = &ds_layout;
13687 VkDescriptorSet descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013688 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis209532e2016-09-07 13:52:18 -060013689 ASSERT_VK_SUCCESS(err);
13690
13691 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
13692 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13693 pipeline_layout_ci.pNext = NULL;
13694 pipeline_layout_ci.setLayoutCount = 1;
13695 pipeline_layout_ci.pSetLayouts = &ds_layout;
13696
13697 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013698 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060013699 ASSERT_VK_SUCCESS(err);
13700
13701 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060013702 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 -060013703 ASSERT_TRUE(image.initialized());
13704
13705 VkImageView view;
13706 VkImageViewCreateInfo ivci = {};
13707 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
13708 ivci.image = image.handle();
13709 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
13710 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
13711 ivci.subresourceRange.layerCount = 1;
13712 ivci.subresourceRange.baseMipLevel = 0;
13713 ivci.subresourceRange.levelCount = 1;
13714 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
13715
13716 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
13717 ASSERT_VK_SUCCESS(err);
13718
13719 VkDescriptorImageInfo image_info{};
13720 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
13721 image_info.imageView = view;
13722 image_info.sampler = sampler;
13723
13724 VkWriteDescriptorSet descriptor_write = {};
13725 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
13726 descriptor_write.dstSet = descriptor_set;
13727 descriptor_write.dstBinding = 0;
13728 descriptor_write.descriptorCount = 1;
13729 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
13730 descriptor_write.pImageInfo = &image_info;
13731
13732 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
13733
13734 // Create PSO to use the sampler
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013735 char const *vsSource =
13736 "#version 450\n"
13737 "\n"
13738 "out gl_PerVertex { \n"
13739 " vec4 gl_Position;\n"
13740 "};\n"
13741 "void main(){\n"
13742 " gl_Position = vec4(1);\n"
13743 "}\n";
13744 char const *fsSource =
13745 "#version 450\n"
13746 "\n"
13747 "layout(set=0, binding=0) uniform sampler2D s;\n"
13748 "layout(location=0) out vec4 x;\n"
13749 "void main(){\n"
13750 " x = texture(s, vec2(1));\n"
13751 "}\n";
Tobin Ehlis209532e2016-09-07 13:52:18 -060013752 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13753 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13754 VkPipelineObj pipe(m_device);
13755 pipe.AddShader(&vs);
13756 pipe.AddShader(&fs);
13757 pipe.AddColorAttachment();
13758 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13759
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070013760 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00837);
Tobin Ehlis209532e2016-09-07 13:52:18 -060013761
Tony Barbour552f6c02016-12-21 14:34:07 -070013762 m_commandBuffer->BeginCommandBuffer();
13763 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis209532e2016-09-07 13:52:18 -060013764 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013765 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
13766 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
13767 &descriptor_set, 0, nullptr);
Rene Lindsay4da11732017-01-13 14:42:10 -070013768
13769 VkViewport viewport = {0, 0, 16, 16, 0, 1};
13770 VkRect2D scissor = {{0, 0}, {16, 16}};
13771 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
13772 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
13773
Tobin Ehlis209532e2016-09-07 13:52:18 -060013774 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070013775 m_commandBuffer->EndRenderPass();
13776 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis209532e2016-09-07 13:52:18 -060013777 // Submit cmd buffer then destroy sampler
13778 VkSubmitInfo submit_info = {};
13779 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
13780 submit_info.commandBufferCount = 1;
13781 submit_info.pCommandBuffers = &m_commandBuffer->handle();
13782 // Submit cmd buffer and then destroy sampler while in-flight
13783 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
13784
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013785 vkDestroySampler(m_device->device(), sampler, nullptr); // Destroyed too soon
Tobin Ehlis209532e2016-09-07 13:52:18 -060013786 m_errorMonitor->VerifyFound();
13787 vkQueueWaitIdle(m_device->m_queue);
Rene Lindsay4da11732017-01-13 14:42:10 -070013788
Tobin Ehlis209532e2016-09-07 13:52:18 -060013789 // Now we can actually destroy sampler
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070013790 m_errorMonitor->SetUnexpectedError("If sampler is not VK_NULL_HANDLE, sampler must be a valid VkSampler handle");
13791 m_errorMonitor->SetUnexpectedError("Unable to remove Sampler obj");
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013792 vkDestroySampler(m_device->device(), sampler, NULL); // Destroyed for real
Tobin Ehlis209532e2016-09-07 13:52:18 -060013793 vkDestroyImageView(m_device->device(), view, NULL);
13794 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
13795 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
13796 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
13797}
13798
Mark Mueller1cd9f412016-08-25 13:23:52 -060013799TEST_F(VkLayerTest, QueueForwardProgressFenceWait) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013800 TEST_DESCRIPTION(
13801 "Call VkQueueSubmit with a semaphore that is already "
13802 "signaled but not waited on by the queue. Wait on a "
13803 "fence that has not yet been submitted to a queue.");
Mark Mueller96a56d52016-08-24 10:28:05 -060013804
Tony Barbour1fa09702017-03-16 12:09:08 -060013805 ASSERT_NO_FATAL_FAILURE(Init());
Mark Mueller96a56d52016-08-24 10:28:05 -060013806 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13807
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013808 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 -070013809 const char *invalid_fence_wait_message =
13810 " which has not been submitted on a Queue or during "
13811 "acquire next image.";
Mark Mueller96a56d52016-08-24 10:28:05 -060013812
Chris Forbese98aec12017-05-18 12:50:14 -070013813 VkCommandBufferObj cb1(m_device, m_commandPool);
13814 cb1.begin();
13815 cb1.end();
Mark Mueller96a56d52016-08-24 10:28:05 -060013816
13817 VkSemaphoreCreateInfo semaphore_create_info = {};
13818 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
13819 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013820 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller96a56d52016-08-24 10:28:05 -060013821 VkSubmitInfo submit_info = {};
13822 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
13823 submit_info.commandBufferCount = 1;
Chris Forbese98aec12017-05-18 12:50:14 -070013824 submit_info.pCommandBuffers = &cb1.handle();
Mark Mueller96a56d52016-08-24 10:28:05 -060013825 submit_info.signalSemaphoreCount = 1;
13826 submit_info.pSignalSemaphores = &semaphore;
13827 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Chris Forbese98aec12017-05-18 12:50:14 -070013828
Tony Barbour552f6c02016-12-21 14:34:07 -070013829 m_commandBuffer->BeginCommandBuffer();
13830 m_commandBuffer->EndCommandBuffer();
Chris Forbese98aec12017-05-18 12:50:14 -070013831 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013832 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, queue_forward_progress_message);
Mark Mueller96a56d52016-08-24 10:28:05 -060013833 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
13834 m_errorMonitor->VerifyFound();
13835
Mark Mueller1cd9f412016-08-25 13:23:52 -060013836 VkFenceCreateInfo fence_create_info = {};
13837 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
13838 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013839 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller1cd9f412016-08-25 13:23:52 -060013840
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013841 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, invalid_fence_wait_message);
Mark Mueller1cd9f412016-08-25 13:23:52 -060013842 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
13843 m_errorMonitor->VerifyFound();
13844
Mark Mueller4042b652016-09-05 22:52:21 -060013845 vkDeviceWaitIdle(m_device->device());
Mark Mueller1cd9f412016-08-25 13:23:52 -060013846 vkDestroyFence(m_device->device(), fence, nullptr);
Mark Mueller96a56d52016-08-24 10:28:05 -060013847 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
13848}
13849
Tobin Ehlis4af23302016-07-19 10:50:30 -060013850TEST_F(VkLayerTest, FramebufferIncompatible) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013851 TEST_DESCRIPTION(
13852 "Bind a secondary command buffer with with a framebuffer "
13853 "that does not match the framebuffer for the active "
13854 "renderpass.");
Tony Barbour1fa09702017-03-16 12:09:08 -060013855 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis4af23302016-07-19 10:50:30 -060013856 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13857
13858 // A renderpass with one color attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013859 VkAttachmentDescription attachment = {0,
13860 VK_FORMAT_B8G8R8A8_UNORM,
13861 VK_SAMPLE_COUNT_1_BIT,
13862 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
13863 VK_ATTACHMENT_STORE_OP_STORE,
13864 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
13865 VK_ATTACHMENT_STORE_OP_DONT_CARE,
13866 VK_IMAGE_LAYOUT_UNDEFINED,
13867 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013868
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013869 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013870
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013871 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013872
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013873 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013874
13875 VkRenderPass rp;
13876 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
13877 ASSERT_VK_SUCCESS(err);
13878
13879 // A compatible framebuffer.
13880 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060013881 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 -060013882 ASSERT_TRUE(image.initialized());
13883
13884 VkImageViewCreateInfo ivci = {
13885 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
13886 nullptr,
13887 0,
13888 image.handle(),
13889 VK_IMAGE_VIEW_TYPE_2D,
13890 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013891 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
13892 VK_COMPONENT_SWIZZLE_IDENTITY},
Tobin Ehlis4af23302016-07-19 10:50:30 -060013893 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
13894 };
13895 VkImageView view;
13896 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
13897 ASSERT_VK_SUCCESS(err);
13898
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013899 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013900 VkFramebuffer fb;
13901 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
13902 ASSERT_VK_SUCCESS(err);
13903
13904 VkCommandBufferAllocateInfo cbai = {};
13905 cbai.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mike Schuchardt06304c22017-03-01 17:09:09 -070013906 cbai.commandPool = m_commandPool->handle();
Tobin Ehlis4af23302016-07-19 10:50:30 -060013907 cbai.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
13908 cbai.commandBufferCount = 1;
13909
13910 VkCommandBuffer sec_cb;
13911 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &sec_cb);
13912 ASSERT_VK_SUCCESS(err);
13913 VkCommandBufferBeginInfo cbbi = {};
13914 VkCommandBufferInheritanceInfo cbii = {};
Chris Forbes98420382016-11-28 17:56:51 +130013915 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Tobin Ehlis4af23302016-07-19 10:50:30 -060013916 cbii.renderPass = renderPass();
13917 cbii.framebuffer = fb;
13918 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
13919 cbbi.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013920 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 -060013921 cbbi.pInheritanceInfo = &cbii;
13922 vkBeginCommandBuffer(sec_cb, &cbbi);
13923 vkEndCommandBuffer(sec_cb);
13924
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013925 VkCommandBufferBeginInfo cbbi2 = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, 0, nullptr};
Chris Forbes3400bc52016-09-13 18:10:34 +120013926 vkBeginCommandBuffer(m_commandBuffer->GetBufferHandle(), &cbbi2);
13927 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Tobin Ehlis4af23302016-07-19 10:50:30 -060013928
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013929 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060013930 " that is not the same as the primary command buffer's current active framebuffer ");
Tobin Ehlis4af23302016-07-19 10:50:30 -060013931 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &sec_cb);
13932 m_errorMonitor->VerifyFound();
13933 // Cleanup
13934 vkDestroyImageView(m_device->device(), view, NULL);
13935 vkDestroyRenderPass(m_device->device(), rp, NULL);
13936 vkDestroyFramebuffer(m_device->device(), fb, NULL);
13937}
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013938
13939TEST_F(VkLayerTest, ColorBlendLogicOpTests) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013940 TEST_DESCRIPTION(
13941 "If logicOp is available on the device, set it to an "
13942 "invalid value. If logicOp is not available, attempt to "
13943 "use it and verify that we see the correct error.");
Tony Barbour1fa09702017-03-16 12:09:08 -060013944 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013945 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13946
13947 auto features = m_device->phy().features();
13948 // Set the expected error depending on whether or not logicOp available
13949 if (VK_FALSE == features.logicOp) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013950 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13951 "If logic operations feature not "
13952 "enabled, logicOpEnable must be "
13953 "VK_FALSE");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013954 } else {
Chris Forbes34797bc2016-10-03 15:28:49 +130013955 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "pColorBlendState->logicOp (16)");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013956 }
13957 // Create a pipeline using logicOp
13958 VkResult err;
13959
13960 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
13961 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13962
13963 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013964 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013965 ASSERT_VK_SUCCESS(err);
13966
13967 VkPipelineViewportStateCreateInfo vp_state_ci = {};
13968 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
13969 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013970 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013971 vp_state_ci.pViewports = &vp;
13972 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013973 VkRect2D scissors = {}; // Dummy scissors to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013974 vp_state_ci.pScissors = &scissors;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013975
13976 VkPipelineShaderStageCreateInfo shaderStages[2];
13977 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
13978
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013979 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
13980 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013981 shaderStages[0] = vs.GetStageCreateInfo();
13982 shaderStages[1] = fs.GetStageCreateInfo();
13983
13984 VkPipelineVertexInputStateCreateInfo vi_ci = {};
13985 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
13986
13987 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
13988 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
13989 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
13990
13991 VkPipelineRasterizationStateCreateInfo rs_ci = {};
13992 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbes14088512016-10-03 14:28:00 +130013993 rs_ci.lineWidth = 1.0f;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013994
13995 VkPipelineColorBlendAttachmentState att = {};
13996 att.blendEnable = VK_FALSE;
13997 att.colorWriteMask = 0xf;
13998
13999 VkPipelineColorBlendStateCreateInfo cb_ci = {};
14000 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
14001 // Enable logicOp & set logicOp to value 1 beyond allowed entries
14002 cb_ci.logicOpEnable = VK_TRUE;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014003 cb_ci.logicOp = VK_LOGIC_OP_RANGE_SIZE; // This should cause an error
Tobin Ehlis52b504f2016-07-19 13:25:12 -060014004 cb_ci.attachmentCount = 1;
14005 cb_ci.pAttachments = &att;
14006
Chris Forbes8aeacbf2016-10-03 14:25:08 +130014007 VkPipelineMultisampleStateCreateInfo ms_ci = {};
14008 ms_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
14009 ms_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
14010
Tobin Ehlis52b504f2016-07-19 13:25:12 -060014011 VkGraphicsPipelineCreateInfo gp_ci = {};
14012 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
14013 gp_ci.stageCount = 2;
14014 gp_ci.pStages = shaderStages;
14015 gp_ci.pVertexInputState = &vi_ci;
14016 gp_ci.pInputAssemblyState = &ia_ci;
14017 gp_ci.pViewportState = &vp_state_ci;
14018 gp_ci.pRasterizationState = &rs_ci;
14019 gp_ci.pColorBlendState = &cb_ci;
Chris Forbes8aeacbf2016-10-03 14:25:08 +130014020 gp_ci.pMultisampleState = &ms_ci;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060014021 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
14022 gp_ci.layout = pipeline_layout;
14023 gp_ci.renderPass = renderPass();
14024
14025 VkPipelineCacheCreateInfo pc_ci = {};
14026 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
14027
14028 VkPipeline pipeline;
14029 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014030 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060014031 ASSERT_VK_SUCCESS(err);
14032
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014033 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060014034 m_errorMonitor->VerifyFound();
14035 if (VK_SUCCESS == err) {
14036 vkDestroyPipeline(m_device->device(), pipeline, NULL);
14037 }
Tobin Ehlis52b504f2016-07-19 13:25:12 -060014038 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
14039 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
14040}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060014041
Mike Stroyanaccf7692015-05-12 16:00:45 -060014042#if GTEST_IS_THREADSAFE
14043struct thread_data_struct {
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014044 VkCommandBuffer commandBuffer;
Mike Stroyanca855662017-05-02 11:06:27 -060014045 VkDevice device;
Mike Stroyanaccf7692015-05-12 16:00:45 -060014046 VkEvent event;
14047 bool bailout;
14048};
14049
Karl Schultz6addd812016-02-02 17:17:23 -070014050extern "C" void *AddToCommandBuffer(void *arg) {
14051 struct thread_data_struct *data = (struct thread_data_struct *)arg;
Mike Stroyanaccf7692015-05-12 16:00:45 -060014052
Mike Stroyana6d14942016-07-13 15:10:05 -060014053 for (int i = 0; i < 80000; i++) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014054 vkCmdSetEvent(data->commandBuffer, data->event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mike Stroyanaccf7692015-05-12 16:00:45 -060014055 if (data->bailout) {
14056 break;
14057 }
14058 }
14059 return NULL;
14060}
14061
Karl Schultz6addd812016-02-02 17:17:23 -070014062TEST_F(VkLayerTest, ThreadCommandBufferCollision) {
Mike Stroyan4268d1f2015-07-13 14:45:35 -060014063 test_platform_thread thread;
Mike Stroyanaccf7692015-05-12 16:00:45 -060014064
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014065 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "THREADING ERROR");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014066
Tony Barbour1fa09702017-03-16 12:09:08 -060014067 ASSERT_NO_FATAL_FAILURE(Init());
Mike Stroyanaccf7692015-05-12 16:00:45 -060014068 ASSERT_NO_FATAL_FAILURE(InitViewport());
14069 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14070
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014071 // Calls AllocateCommandBuffers
14072 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060014073
14074 // Avoid creating RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014075 commandBuffer.BeginCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060014076
14077 VkEventCreateInfo event_info;
14078 VkEvent event;
Mike Stroyanaccf7692015-05-12 16:00:45 -060014079 VkResult err;
14080
14081 memset(&event_info, 0, sizeof(event_info));
14082 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
14083
Chia-I Wuf7458c52015-10-26 21:10:41 +080014084 err = vkCreateEvent(device(), &event_info, NULL, &event);
Mike Stroyanaccf7692015-05-12 16:00:45 -060014085 ASSERT_VK_SUCCESS(err);
14086
Mike Stroyanaccf7692015-05-12 16:00:45 -060014087 err = vkResetEvent(device(), event);
14088 ASSERT_VK_SUCCESS(err);
14089
14090 struct thread_data_struct data;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014091 data.commandBuffer = commandBuffer.GetBufferHandle();
Mike Stroyanaccf7692015-05-12 16:00:45 -060014092 data.event = event;
14093 data.bailout = false;
14094 m_errorMonitor->SetBailout(&data.bailout);
Mike Stroyana6d14942016-07-13 15:10:05 -060014095
14096 // First do some correct operations using multiple threads.
14097 // Add many entries to command buffer from another thread.
14098 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
14099 // Make non-conflicting calls from this thread at the same time.
14100 for (int i = 0; i < 80000; i++) {
Mike Stroyand6343902016-07-14 08:56:16 -060014101 uint32_t count;
14102 vkEnumeratePhysicalDevices(instance(), &count, NULL);
Mike Stroyana6d14942016-07-13 15:10:05 -060014103 }
14104 test_platform_thread_join(thread, NULL);
14105
14106 // Then do some incorrect operations using multiple threads.
Mike Stroyanaccf7692015-05-12 16:00:45 -060014107 // Add many entries to command buffer from another thread.
Mike Stroyan4268d1f2015-07-13 14:45:35 -060014108 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyanaccf7692015-05-12 16:00:45 -060014109 // Add many entries to command buffer from this thread at the same time.
14110 AddToCommandBuffer(&data);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060014111
Mike Stroyan4268d1f2015-07-13 14:45:35 -060014112 test_platform_thread_join(thread, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014113 commandBuffer.EndCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060014114
Mike Stroyan10b8cb72016-01-22 15:22:03 -070014115 m_errorMonitor->SetBailout(NULL);
14116
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014117 m_errorMonitor->VerifyFound();
Mike Stroyanaccf7692015-05-12 16:00:45 -060014118
Chia-I Wuf7458c52015-10-26 21:10:41 +080014119 vkDestroyEvent(device(), event, NULL);
Mike Stroyanaccf7692015-05-12 16:00:45 -060014120}
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014121#endif // GTEST_IS_THREADSAFE
Mark Lobodzinski209b5292015-09-17 09:44:05 -060014122
Karl Schultz6addd812016-02-02 17:17:23 -070014123TEST_F(VkLayerTest, InvalidSPIRVCodeSize) {
Mark Lobodzinskid742b312017-05-09 16:26:27 -060014124 TEST_DESCRIPTION("Test that errors are produced for a spirv modules with invalid code sizes");
Chris Forbes1cc79542016-07-20 11:13:44 +120014125
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014126 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014127
Tony Barbour1fa09702017-03-16 12:09:08 -060014128 ASSERT_NO_FATAL_FAILURE(Init());
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014129 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14130
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014131 VkShaderModule module;
14132 VkShaderModuleCreateInfo moduleCreateInfo;
14133 struct icd_spv_header spv;
14134
14135 spv.magic = ICD_SPV_MAGIC;
14136 spv.version = ICD_SPV_VERSION;
14137 spv.gen_magic = 0;
14138
14139 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
14140 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070014141 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014142 moduleCreateInfo.codeSize = 4;
14143 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080014144 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014145
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014146 m_errorMonitor->VerifyFound();
Mark Lobodzinskid742b312017-05-09 16:26:27 -060014147
14148 char const *vsSource =
14149 "#version 450\n"
14150 "\n"
14151 "layout(location=0) out float x;\n"
14152 "out gl_PerVertex {\n"
14153 " vec4 gl_Position;\n"
14154 "};\n"
14155 "void main(){\n"
14156 " gl_Position = vec4(1);\n"
14157 " x = 0;\n"
14158 "}\n";
14159
14160 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02816);
14161 std::vector<unsigned int> shader;
14162 VkShaderModuleCreateInfo module_create_info;
14163 VkShaderModule shader_module;
14164 module_create_info.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
14165 module_create_info.pNext = NULL;
14166 this->GLSLtoSPV(VK_SHADER_STAGE_VERTEX_BIT, vsSource, shader);
14167 module_create_info.pCode = shader.data();
14168 // Introduce failure by making codeSize a non-multiple of 4
14169 module_create_info.codeSize = shader.size() * sizeof(unsigned int) - 1;
14170 module_create_info.flags = 0;
14171 vkCreateShaderModule(m_device->handle(), &module_create_info, NULL, &shader_module);
14172
14173 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014174}
14175
Karl Schultz6addd812016-02-02 17:17:23 -070014176TEST_F(VkLayerTest, InvalidSPIRVMagic) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014177 TEST_DESCRIPTION(
14178 "Test that an error is produced for a spirv module "
14179 "with a bad magic number");
Chris Forbes1cc79542016-07-20 11:13:44 +120014180
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014181 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V magic number");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014182
Tony Barbour1fa09702017-03-16 12:09:08 -060014183 ASSERT_NO_FATAL_FAILURE(Init());
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014184 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14185
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014186 VkShaderModule module;
14187 VkShaderModuleCreateInfo moduleCreateInfo;
14188 struct icd_spv_header spv;
14189
14190 spv.magic = ~ICD_SPV_MAGIC;
14191 spv.version = ICD_SPV_VERSION;
14192 spv.gen_magic = 0;
14193
14194 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
14195 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070014196 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Mark Lobodzinskid742b312017-05-09 16:26:27 -060014197 moduleCreateInfo.codeSize = sizeof(spv) + 16;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014198 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080014199 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014200
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014201 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014202}
14203
Chris Forbesb4afd0f2016-04-04 10:48:35 +120014204#if 0
14205// Not currently covered by SPIRV-Tools validator
Karl Schultz6addd812016-02-02 17:17:23 -070014206TEST_F(VkLayerTest, InvalidSPIRVVersion) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070014207 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +120014208 "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014209
Tony Barbour1fa09702017-03-16 12:09:08 -060014210 ASSERT_NO_FATAL_FAILURE(Init());
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014211 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14212
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014213 VkShaderModule module;
14214 VkShaderModuleCreateInfo moduleCreateInfo;
14215 struct icd_spv_header spv;
14216
14217 spv.magic = ICD_SPV_MAGIC;
14218 spv.version = ~ICD_SPV_VERSION;
14219 spv.gen_magic = 0;
14220
14221 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
14222 moduleCreateInfo.pNext = NULL;
14223
Karl Schultz6addd812016-02-02 17:17:23 -070014224 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014225 moduleCreateInfo.codeSize = sizeof(spv) + 10;
14226 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080014227 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014228
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014229 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014230}
Chris Forbesb4afd0f2016-04-04 10:48:35 +120014231#endif
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014232
Karl Schultz6addd812016-02-02 17:17:23 -070014233TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014234 TEST_DESCRIPTION(
14235 "Test that a warning is produced for a vertex output that "
14236 "is not consumed by the fragment stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014237 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "not consumed by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014238
Tony Barbour1fa09702017-03-16 12:09:08 -060014239 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014240 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes9f7ff632015-05-25 11:13:08 +120014241
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014242 char const *vsSource =
14243 "#version 450\n"
14244 "\n"
14245 "layout(location=0) out float x;\n"
14246 "out gl_PerVertex {\n"
14247 " vec4 gl_Position;\n"
14248 "};\n"
14249 "void main(){\n"
14250 " gl_Position = vec4(1);\n"
14251 " x = 0;\n"
14252 "}\n";
14253 char const *fsSource =
14254 "#version 450\n"
14255 "\n"
14256 "layout(location=0) out vec4 color;\n"
14257 "void main(){\n"
14258 " color = vec4(1);\n"
14259 "}\n";
Chris Forbes9f7ff632015-05-25 11:13:08 +120014260
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014261 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14262 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes9f7ff632015-05-25 11:13:08 +120014263
14264 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014265 pipe.AddColorAttachment();
Chris Forbes9f7ff632015-05-25 11:13:08 +120014266 pipe.AddShader(&vs);
14267 pipe.AddShader(&fs);
14268
Chris Forbes9f7ff632015-05-25 11:13:08 +120014269 VkDescriptorSetObj descriptorSet(m_device);
14270 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014271 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes9f7ff632015-05-25 11:13:08 +120014272
Tony Barbour5781e8f2015-08-04 16:23:11 -060014273 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes9f7ff632015-05-25 11:13:08 +120014274
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014275 m_errorMonitor->VerifyFound();
Chris Forbes9f7ff632015-05-25 11:13:08 +120014276}
Chris Forbes9f7ff632015-05-25 11:13:08 +120014277
Mark Mueller098c9cb2016-09-08 09:01:57 -060014278TEST_F(VkLayerTest, CreatePipelineCheckShaderBadSpecialization) {
14279 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
14280
Tony Barbour1fa09702017-03-16 12:09:08 -060014281 ASSERT_NO_FATAL_FAILURE(Init());
Mark Mueller098c9cb2016-09-08 09:01:57 -060014282 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14283
14284 const char *bad_specialization_message =
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014285 "Specialization entry 0 (for constant id 0) references memory outside provided specialization data ";
Mark Mueller098c9cb2016-09-08 09:01:57 -060014286
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014287 char const *vsSource =
14288 "#version 450\n"
14289 "\n"
14290 "out gl_PerVertex {\n"
14291 " vec4 gl_Position;\n"
14292 "};\n"
14293 "void main(){\n"
14294 " gl_Position = vec4(1);\n"
14295 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060014296
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014297 char const *fsSource =
14298 "#version 450\n"
14299 "\n"
14300 "layout (constant_id = 0) const float r = 0.0f;\n"
14301 "layout(location = 0) out vec4 uFragColor;\n"
14302 "void main(){\n"
14303 " uFragColor = vec4(r,1,0,1);\n"
14304 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060014305
14306 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14307 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14308
14309 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
14310 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
14311
14312 VkPipelineLayout pipeline_layout;
14313 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
14314
14315 VkPipelineViewportStateCreateInfo vp_state_create_info = {};
14316 vp_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
14317 vp_state_create_info.viewportCount = 1;
14318 VkViewport viewport = {};
14319 vp_state_create_info.pViewports = &viewport;
14320 vp_state_create_info.scissorCount = 1;
14321 VkRect2D scissors = {};
14322 vp_state_create_info.pScissors = &scissors;
14323
14324 VkDynamicState scissor_state = VK_DYNAMIC_STATE_SCISSOR;
14325
14326 VkPipelineDynamicStateCreateInfo pipeline_dynamic_state_create_info = {};
14327 pipeline_dynamic_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
14328 pipeline_dynamic_state_create_info.dynamicStateCount = 1;
14329 pipeline_dynamic_state_create_info.pDynamicStates = &scissor_state;
14330
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014331 VkPipelineShaderStageCreateInfo shader_stage_create_info[2] = {vs.GetStageCreateInfo(), fs.GetStageCreateInfo()};
Mark Mueller098c9cb2016-09-08 09:01:57 -060014332
14333 VkPipelineVertexInputStateCreateInfo vertex_input_create_info = {};
14334 vertex_input_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
14335
14336 VkPipelineInputAssemblyStateCreateInfo input_assembly_create_info = {};
14337 input_assembly_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
14338 input_assembly_create_info.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
14339
14340 VkPipelineRasterizationStateCreateInfo rasterization_state_create_info = {};
14341 rasterization_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
14342 rasterization_state_create_info.pNext = nullptr;
14343 rasterization_state_create_info.lineWidth = 1.0f;
14344 rasterization_state_create_info.rasterizerDiscardEnable = true;
14345
14346 VkPipelineColorBlendAttachmentState color_blend_attachment_state = {};
14347 color_blend_attachment_state.blendEnable = VK_FALSE;
14348 color_blend_attachment_state.colorWriteMask = 0xf;
14349
14350 VkPipelineColorBlendStateCreateInfo color_blend_state_create_info = {};
14351 color_blend_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
14352 color_blend_state_create_info.attachmentCount = 1;
14353 color_blend_state_create_info.pAttachments = &color_blend_attachment_state;
14354
14355 VkGraphicsPipelineCreateInfo graphicspipe_create_info = {};
14356 graphicspipe_create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
14357 graphicspipe_create_info.stageCount = 2;
14358 graphicspipe_create_info.pStages = shader_stage_create_info;
14359 graphicspipe_create_info.pVertexInputState = &vertex_input_create_info;
14360 graphicspipe_create_info.pInputAssemblyState = &input_assembly_create_info;
14361 graphicspipe_create_info.pViewportState = &vp_state_create_info;
14362 graphicspipe_create_info.pRasterizationState = &rasterization_state_create_info;
14363 graphicspipe_create_info.pColorBlendState = &color_blend_state_create_info;
14364 graphicspipe_create_info.pDynamicState = &pipeline_dynamic_state_create_info;
14365 graphicspipe_create_info.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
14366 graphicspipe_create_info.layout = pipeline_layout;
14367 graphicspipe_create_info.renderPass = renderPass();
14368
14369 VkPipelineCacheCreateInfo pipeline_cache_create_info = {};
14370 pipeline_cache_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
14371
14372 VkPipelineCache pipelineCache;
14373 ASSERT_VK_SUCCESS(vkCreatePipelineCache(m_device->device(), &pipeline_cache_create_info, nullptr, &pipelineCache));
14374
14375 // This structure maps constant ids to data locations.
14376 const VkSpecializationMapEntry entry =
14377 // id, offset, size
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014378 {0, 4, sizeof(uint32_t)}; // Challenge core validation by using a bogus offset.
Mark Mueller098c9cb2016-09-08 09:01:57 -060014379
14380 uint32_t data = 1;
14381
14382 // Set up the info describing spec map and data
14383 const VkSpecializationInfo specialization_info = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014384 1, &entry, 1 * sizeof(float), &data,
Mark Mueller098c9cb2016-09-08 09:01:57 -060014385 };
14386 shader_stage_create_info[0].pSpecializationInfo = &specialization_info;
14387
14388 VkPipeline pipeline;
14389 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_specialization_message);
14390 vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &graphicspipe_create_info, nullptr, &pipeline);
14391 m_errorMonitor->VerifyFound();
14392
14393 vkDestroyPipelineCache(m_device->device(), pipelineCache, nullptr);
14394 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
14395}
14396
14397TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorTypeMismatch) {
14398 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
14399
Tony Barbour1fa09702017-03-16 12:09:08 -060014400 ASSERT_NO_FATAL_FAILURE(Init());
Mark Mueller098c9cb2016-09-08 09:01:57 -060014401 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14402
14403 const char *descriptor_type_mismatch_message = "Type mismatch on descriptor slot 0.0 (used as type ";
14404
14405 VkDescriptorPoolSize descriptor_pool_type_count[2] = {};
14406 descriptor_pool_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
14407 descriptor_pool_type_count[0].descriptorCount = 1;
14408 descriptor_pool_type_count[1].type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
14409 descriptor_pool_type_count[1].descriptorCount = 1;
14410
14411 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
14412 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
14413 descriptor_pool_create_info.maxSets = 1;
14414 descriptor_pool_create_info.poolSizeCount = 2;
14415 descriptor_pool_create_info.pPoolSizes = descriptor_pool_type_count;
14416 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
14417
14418 VkDescriptorPool descriptorset_pool;
14419 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
14420
14421 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
14422 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
14423 descriptorset_layout_binding.descriptorCount = 1;
14424 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
Cody Northropa6484fd2017-03-10 14:13:49 -070014425 descriptorset_layout_binding.pImmutableSamplers = nullptr;
Mark Mueller098c9cb2016-09-08 09:01:57 -060014426
14427 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
14428 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
14429 descriptorset_layout_create_info.bindingCount = 1;
14430 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
14431
14432 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014433 ASSERT_VK_SUCCESS(
14434 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller098c9cb2016-09-08 09:01:57 -060014435
14436 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
14437 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
14438 descriptorset_allocate_info.descriptorSetCount = 1;
14439 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
14440 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
14441 VkDescriptorSet descriptorset;
14442 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
14443
14444 // Challenge core_validation with a non uniform buffer type.
14445 VkBufferTest storage_buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT);
14446
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014447 char const *vsSource =
14448 "#version 450\n"
14449 "\n"
14450 "layout (std140, set = 0, binding = 0) uniform buf {\n"
14451 " mat4 mvp;\n"
14452 "} ubuf;\n"
14453 "out gl_PerVertex {\n"
14454 " vec4 gl_Position;\n"
14455 "};\n"
14456 "void main(){\n"
14457 " gl_Position = ubuf.mvp * vec4(1);\n"
14458 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060014459
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014460 char const *fsSource =
14461 "#version 450\n"
14462 "\n"
14463 "layout(location = 0) out vec4 uFragColor;\n"
14464 "void main(){\n"
14465 " uFragColor = vec4(0,1,0,1);\n"
14466 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060014467
14468 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14469 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14470
14471 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
14472 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
14473 pipeline_layout_create_info.setLayoutCount = 1;
14474 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
14475
14476 VkPipelineLayout pipeline_layout;
14477 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
14478
14479 VkPipelineObj pipe(m_device);
14480 pipe.AddColorAttachment();
14481 pipe.AddShader(&vs);
14482 pipe.AddShader(&fs);
14483
14484 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_type_mismatch_message);
14485 pipe.CreateVKPipeline(pipeline_layout, renderPass());
14486 m_errorMonitor->VerifyFound();
14487
14488 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
14489 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
14490 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
14491}
14492
14493TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorNotAccessible) {
14494 TEST_DESCRIPTION(
14495 "Create a pipeline in which a descriptor used by a shader stage does not include that stage in its stageFlags.");
14496
Tony Barbour1fa09702017-03-16 12:09:08 -060014497 ASSERT_NO_FATAL_FAILURE(Init());
Mark Mueller098c9cb2016-09-08 09:01:57 -060014498 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14499
14500 const char *descriptor_not_accessible_message = "Shader uses descriptor slot 0.0 (used as type ";
14501
14502 VkDescriptorPoolSize descriptor_pool_type_count = {};
14503 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
14504 descriptor_pool_type_count.descriptorCount = 1;
14505
14506 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
14507 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
14508 descriptor_pool_create_info.maxSets = 1;
14509 descriptor_pool_create_info.poolSizeCount = 1;
14510 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
14511 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
14512
14513 VkDescriptorPool descriptorset_pool;
14514 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
14515
14516 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
14517 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
14518 descriptorset_layout_binding.descriptorCount = 1;
14519 // Intentionally make the uniform buffer inaccessible to the vertex shader to challenge core_validation
14520 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
Cody Northropa6484fd2017-03-10 14:13:49 -070014521 descriptorset_layout_binding.pImmutableSamplers = nullptr;
Mark Mueller098c9cb2016-09-08 09:01:57 -060014522
14523 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
14524 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
14525 descriptorset_layout_create_info.bindingCount = 1;
14526 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
14527
14528 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014529 ASSERT_VK_SUCCESS(
14530 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller098c9cb2016-09-08 09:01:57 -060014531
14532 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
14533 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
14534 descriptorset_allocate_info.descriptorSetCount = 1;
14535 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
14536 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
14537 VkDescriptorSet descriptorset;
14538 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
14539
14540 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
14541
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014542 char const *vsSource =
14543 "#version 450\n"
14544 "\n"
14545 "layout (std140, set = 0, binding = 0) uniform buf {\n"
14546 " mat4 mvp;\n"
14547 "} ubuf;\n"
14548 "out gl_PerVertex {\n"
14549 " vec4 gl_Position;\n"
14550 "};\n"
14551 "void main(){\n"
14552 " gl_Position = ubuf.mvp * vec4(1);\n"
14553 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060014554
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014555 char const *fsSource =
14556 "#version 450\n"
14557 "\n"
14558 "layout(location = 0) out vec4 uFragColor;\n"
14559 "void main(){\n"
14560 " uFragColor = vec4(0,1,0,1);\n"
14561 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060014562
14563 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14564 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14565
14566 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
14567 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
14568 pipeline_layout_create_info.setLayoutCount = 1;
14569 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
14570
14571 VkPipelineLayout pipeline_layout;
14572 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
14573
14574 VkPipelineObj pipe(m_device);
14575 pipe.AddColorAttachment();
14576 pipe.AddShader(&vs);
14577 pipe.AddShader(&fs);
14578
14579 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_not_accessible_message);
14580 pipe.CreateVKPipeline(pipeline_layout, renderPass());
14581 m_errorMonitor->VerifyFound();
14582
14583 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
14584 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
14585 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
14586}
14587
14588TEST_F(VkLayerTest, CreatePipelineCheckShaderPushConstantNotAccessible) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014589 TEST_DESCRIPTION(
14590 "Create a graphics pipleine in which a push constant range containing a push constant block member is not "
14591 "accessible from the current shader stage.");
Mark Mueller098c9cb2016-09-08 09:01:57 -060014592
Tony Barbour1fa09702017-03-16 12:09:08 -060014593 ASSERT_NO_FATAL_FAILURE(Init());
Mark Mueller098c9cb2016-09-08 09:01:57 -060014594 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14595
14596 const char *push_constant_not_accessible_message =
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014597 "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 -060014598
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014599 char const *vsSource =
14600 "#version 450\n"
14601 "\n"
14602 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
14603 "out gl_PerVertex {\n"
14604 " vec4 gl_Position;\n"
14605 "};\n"
14606 "void main(){\n"
14607 " gl_Position = vec4(consts.x);\n"
14608 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060014609
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014610 char const *fsSource =
14611 "#version 450\n"
14612 "\n"
14613 "layout(location = 0) out vec4 uFragColor;\n"
14614 "void main(){\n"
14615 " uFragColor = vec4(0,1,0,1);\n"
14616 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060014617
14618 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14619 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14620
14621 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
14622 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
14623
14624 // Set up a push constant range
14625 VkPushConstantRange push_constant_ranges = {};
14626 // Set to the wrong stage to challenge core_validation
14627 push_constant_ranges.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
14628 push_constant_ranges.size = 4;
14629
14630 pipeline_layout_create_info.pPushConstantRanges = &push_constant_ranges;
14631 pipeline_layout_create_info.pushConstantRangeCount = 1;
14632
14633 VkPipelineLayout pipeline_layout;
14634 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
14635
14636 VkPipelineObj pipe(m_device);
14637 pipe.AddColorAttachment();
14638 pipe.AddShader(&vs);
14639 pipe.AddShader(&fs);
14640
14641 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, push_constant_not_accessible_message);
14642 pipe.CreateVKPipeline(pipeline_layout, renderPass());
14643 m_errorMonitor->VerifyFound();
14644
14645 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
14646}
14647
14648TEST_F(VkLayerTest, CreatePipelineCheckShaderNotEnabled) {
14649 TEST_DESCRIPTION(
14650 "Create a graphics pipeline in which a capability declared by the shader requires a feature not enabled on the device.");
14651
Tony Barbour1fa09702017-03-16 12:09:08 -060014652 ASSERT_NO_FATAL_FAILURE(Init());
Mark Mueller098c9cb2016-09-08 09:01:57 -060014653 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14654
14655 const char *feature_not_enabled_message =
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014656 "Shader requires VkPhysicalDeviceFeatures::shaderFloat64 but is not enabled on the device";
Mark Mueller098c9cb2016-09-08 09:01:57 -060014657
14658 // Some awkward steps are required to test with custom device features.
14659 std::vector<const char *> device_extension_names;
14660 auto features = m_device->phy().features();
14661 // Disable support for 64 bit floats
14662 features.shaderFloat64 = false;
14663 // The sacrificial device object
14664 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
14665
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014666 char const *vsSource =
14667 "#version 450\n"
14668 "\n"
14669 "out gl_PerVertex {\n"
14670 " vec4 gl_Position;\n"
14671 "};\n"
14672 "void main(){\n"
14673 " gl_Position = vec4(1);\n"
14674 "}\n";
14675 char const *fsSource =
14676 "#version 450\n"
14677 "\n"
14678 "layout(location=0) out vec4 color;\n"
14679 "void main(){\n"
14680 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
14681 " color = vec4(green);\n"
14682 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060014683
14684 VkShaderObj vs(&test_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14685 VkShaderObj fs(&test_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14686
14687 VkRenderpassObj render_pass(&test_device);
Mark Mueller098c9cb2016-09-08 09:01:57 -060014688
14689 VkPipelineObj pipe(&test_device);
14690 pipe.AddColorAttachment();
14691 pipe.AddShader(&vs);
14692 pipe.AddShader(&fs);
14693
14694 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
14695 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
14696 VkPipelineLayout pipeline_layout;
14697 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(test_device.device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
14698
14699 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, feature_not_enabled_message);
14700 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
14701 m_errorMonitor->VerifyFound();
14702
14703 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, nullptr);
14704}
14705
Mark Lobodzinski20832822017-03-24 14:49:45 -060014706TEST_F(VkLayerTest, CreateShaderModuleCheckBadCapability) {
14707 TEST_DESCRIPTION("Create a shader in which a capability declared by the shader is not supported.");
14708 // Note that this failure message comes from spirv-tools, specifically the validator.
Mark Mueller098c9cb2016-09-08 09:01:57 -060014709
Tony Barbour1fa09702017-03-16 12:09:08 -060014710 ASSERT_NO_FATAL_FAILURE(Init());
Mark Mueller098c9cb2016-09-08 09:01:57 -060014711 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14712
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014713 char const *vsSource =
14714 "#version 450\n"
14715 "\n"
14716 "out gl_PerVertex {\n"
14717 " vec4 gl_Position;\n"
14718 "};\n"
14719 "layout(xfb_buffer = 1) out;"
14720 "void main(){\n"
14721 " gl_Position = vec4(1);\n"
14722 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060014723
Mark Lobodzinski20832822017-03-24 14:49:45 -060014724 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Capability value 53 is not allowed by Vulkan");
Mark Mueller098c9cb2016-09-08 09:01:57 -060014725
Mark Lobodzinski20832822017-03-24 14:49:45 -060014726 std::vector<unsigned int> spv;
14727 VkShaderModuleCreateInfo module_create_info;
14728 VkShaderModule shader_module;
14729 module_create_info.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
14730 module_create_info.pNext = NULL;
14731 this->GLSLtoSPV(VK_SHADER_STAGE_VERTEX_BIT, vsSource, spv);
14732 module_create_info.pCode = spv.data();
14733 module_create_info.codeSize = spv.size() * sizeof(unsigned int);
14734 module_create_info.flags = 0;
Mark Mueller098c9cb2016-09-08 09:01:57 -060014735
Mark Lobodzinski20832822017-03-24 14:49:45 -060014736 vkCreateShaderModule(m_device->handle(), &module_create_info, NULL, &shader_module);
Mark Mueller098c9cb2016-09-08 09:01:57 -060014737
Mark Lobodzinski20832822017-03-24 14:49:45 -060014738 m_errorMonitor->VerifyFound();
Mark Mueller098c9cb2016-09-08 09:01:57 -060014739}
14740
Karl Schultz6addd812016-02-02 17:17:23 -070014741TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014742 TEST_DESCRIPTION(
14743 "Test that an error is produced for a fragment shader input "
14744 "which is not present in the outputs of the previous stage");
Chris Forbes1cc79542016-07-20 11:13:44 +120014745
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014746 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014747
Tony Barbour1fa09702017-03-16 12:09:08 -060014748 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014749 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes59cb88d2015-05-25 11:13:13 +120014750
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014751 char const *vsSource =
14752 "#version 450\n"
14753 "\n"
14754 "out gl_PerVertex {\n"
14755 " vec4 gl_Position;\n"
14756 "};\n"
14757 "void main(){\n"
14758 " gl_Position = vec4(1);\n"
14759 "}\n";
14760 char const *fsSource =
14761 "#version 450\n"
14762 "\n"
14763 "layout(location=0) in float x;\n"
14764 "layout(location=0) out vec4 color;\n"
14765 "void main(){\n"
14766 " color = vec4(x);\n"
14767 "}\n";
Chris Forbes59cb88d2015-05-25 11:13:13 +120014768
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014769 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14770 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes59cb88d2015-05-25 11:13:13 +120014771
14772 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014773 pipe.AddColorAttachment();
Chris Forbes59cb88d2015-05-25 11:13:13 +120014774 pipe.AddShader(&vs);
14775 pipe.AddShader(&fs);
14776
Chris Forbes59cb88d2015-05-25 11:13:13 +120014777 VkDescriptorSetObj descriptorSet(m_device);
14778 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014779 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes59cb88d2015-05-25 11:13:13 +120014780
Tony Barbour5781e8f2015-08-04 16:23:11 -060014781 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes59cb88d2015-05-25 11:13:13 +120014782
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014783 m_errorMonitor->VerifyFound();
Chris Forbes59cb88d2015-05-25 11:13:13 +120014784}
14785
Karl Schultz6addd812016-02-02 17:17:23 -070014786TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvidedInBlock) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014787 TEST_DESCRIPTION(
14788 "Test that an error is produced for a fragment shader input "
14789 "within an interace block, which is not present in the outputs "
14790 "of the previous stage.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014791 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Chris Forbesa3e85f62016-01-15 14:53:11 +130014792
Tony Barbour1fa09702017-03-16 12:09:08 -060014793 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbesa3e85f62016-01-15 14:53:11 +130014794 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14795
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014796 char const *vsSource =
14797 "#version 450\n"
14798 "\n"
14799 "out gl_PerVertex {\n"
14800 " vec4 gl_Position;\n"
14801 "};\n"
14802 "void main(){\n"
14803 " gl_Position = vec4(1);\n"
14804 "}\n";
14805 char const *fsSource =
14806 "#version 450\n"
14807 "\n"
14808 "in block { layout(location=0) float x; } ins;\n"
14809 "layout(location=0) out vec4 color;\n"
14810 "void main(){\n"
14811 " color = vec4(ins.x);\n"
14812 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130014813
14814 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14815 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14816
14817 VkPipelineObj pipe(m_device);
14818 pipe.AddColorAttachment();
14819 pipe.AddShader(&vs);
14820 pipe.AddShader(&fs);
14821
14822 VkDescriptorSetObj descriptorSet(m_device);
14823 descriptorSet.AppendDummy();
14824 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14825
14826 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14827
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014828 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130014829}
14830
Karl Schultz6addd812016-02-02 17:17:23 -070014831TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchArraySize) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014832 TEST_DESCRIPTION(
14833 "Test that an error is produced for mismatched array sizes "
14834 "across the vertex->fragment shader interface");
14835 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14836 "Type mismatch on location 0.0: 'ptr to "
14837 "output arr[2] of float32' vs 'ptr to "
14838 "input arr[1] of float32'");
Chris Forbes0036fd12016-01-26 14:19:49 +130014839
Tony Barbour1fa09702017-03-16 12:09:08 -060014840 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes0036fd12016-01-26 14:19:49 +130014841 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14842
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014843 char const *vsSource =
14844 "#version 450\n"
14845 "\n"
14846 "layout(location=0) out float x[2];\n"
14847 "out gl_PerVertex {\n"
14848 " vec4 gl_Position;\n"
14849 "};\n"
14850 "void main(){\n"
14851 " x[0] = 0; x[1] = 0;\n"
14852 " gl_Position = vec4(1);\n"
14853 "}\n";
14854 char const *fsSource =
14855 "#version 450\n"
14856 "\n"
14857 "layout(location=0) in float x[1];\n"
14858 "layout(location=0) out vec4 color;\n"
14859 "void main(){\n"
14860 " color = vec4(x[0]);\n"
14861 "}\n";
Chris Forbes0036fd12016-01-26 14:19:49 +130014862
14863 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14864 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14865
14866 VkPipelineObj pipe(m_device);
14867 pipe.AddColorAttachment();
14868 pipe.AddShader(&vs);
14869 pipe.AddShader(&fs);
14870
14871 VkDescriptorSetObj descriptorSet(m_device);
14872 descriptorSet.AppendDummy();
14873 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14874
14875 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14876
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014877 m_errorMonitor->VerifyFound();
Chris Forbes0036fd12016-01-26 14:19:49 +130014878}
14879
Karl Schultz6addd812016-02-02 17:17:23 -070014880TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014881 TEST_DESCRIPTION(
14882 "Test that an error is produced for mismatched types across "
14883 "the vertex->fragment shader interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014884 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014885
Tony Barbour1fa09702017-03-16 12:09:08 -060014886 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014887 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesb56af562015-05-25 11:13:17 +120014888
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014889 char const *vsSource =
14890 "#version 450\n"
14891 "\n"
14892 "layout(location=0) out int x;\n"
14893 "out gl_PerVertex {\n"
14894 " vec4 gl_Position;\n"
14895 "};\n"
14896 "void main(){\n"
14897 " x = 0;\n"
14898 " gl_Position = vec4(1);\n"
14899 "}\n";
14900 char const *fsSource =
14901 "#version 450\n"
14902 "\n"
14903 "layout(location=0) in float x;\n" /* VS writes int */
14904 "layout(location=0) out vec4 color;\n"
14905 "void main(){\n"
14906 " color = vec4(x);\n"
14907 "}\n";
Chris Forbesb56af562015-05-25 11:13:17 +120014908
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014909 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14910 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesb56af562015-05-25 11:13:17 +120014911
14912 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014913 pipe.AddColorAttachment();
Chris Forbesb56af562015-05-25 11:13:17 +120014914 pipe.AddShader(&vs);
14915 pipe.AddShader(&fs);
14916
Chris Forbesb56af562015-05-25 11:13:17 +120014917 VkDescriptorSetObj descriptorSet(m_device);
14918 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014919 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesb56af562015-05-25 11:13:17 +120014920
Tony Barbour5781e8f2015-08-04 16:23:11 -060014921 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesb56af562015-05-25 11:13:17 +120014922
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014923 m_errorMonitor->VerifyFound();
Chris Forbesb56af562015-05-25 11:13:17 +120014924}
14925
Karl Schultz6addd812016-02-02 17:17:23 -070014926TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchInBlock) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014927 TEST_DESCRIPTION(
14928 "Test that an error is produced for mismatched types across "
14929 "the vertex->fragment shader interface, when the variable is contained within "
14930 "an interface block");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014931 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Chris Forbesa3e85f62016-01-15 14:53:11 +130014932
Tony Barbour1fa09702017-03-16 12:09:08 -060014933 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbesa3e85f62016-01-15 14:53:11 +130014934 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14935
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014936 char const *vsSource =
14937 "#version 450\n"
14938 "\n"
14939 "out block { layout(location=0) int x; } outs;\n"
14940 "out gl_PerVertex {\n"
14941 " vec4 gl_Position;\n"
14942 "};\n"
14943 "void main(){\n"
14944 " outs.x = 0;\n"
14945 " gl_Position = vec4(1);\n"
14946 "}\n";
14947 char const *fsSource =
14948 "#version 450\n"
14949 "\n"
14950 "in block { layout(location=0) float x; } ins;\n" /* VS writes int */
14951 "layout(location=0) out vec4 color;\n"
14952 "void main(){\n"
14953 " color = vec4(ins.x);\n"
14954 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130014955
14956 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14957 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14958
14959 VkPipelineObj pipe(m_device);
14960 pipe.AddColorAttachment();
14961 pipe.AddShader(&vs);
14962 pipe.AddShader(&fs);
14963
14964 VkDescriptorSetObj descriptorSet(m_device);
14965 descriptorSet.AppendDummy();
14966 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14967
14968 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14969
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014970 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130014971}
14972
14973TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByLocation) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014974 TEST_DESCRIPTION(
14975 "Test that an error is produced for location mismatches across "
14976 "the vertex->fragment shader interface; This should manifest as a not-written/not-consumed "
14977 "pair, but flushes out broken walking of the interfaces");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014978 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 +130014979
Tony Barbour1fa09702017-03-16 12:09:08 -060014980 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbese9928822016-02-17 14:44:52 +130014981 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14982
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014983 char const *vsSource =
14984 "#version 450\n"
14985 "\n"
14986 "out block { layout(location=1) float x; } outs;\n"
14987 "out gl_PerVertex {\n"
14988 " vec4 gl_Position;\n"
14989 "};\n"
14990 "void main(){\n"
14991 " outs.x = 0;\n"
14992 " gl_Position = vec4(1);\n"
14993 "}\n";
14994 char const *fsSource =
14995 "#version 450\n"
14996 "\n"
14997 "in block { layout(location=0) float x; } ins;\n"
14998 "layout(location=0) out vec4 color;\n"
14999 "void main(){\n"
15000 " color = vec4(ins.x);\n"
15001 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130015002
15003 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15004 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15005
15006 VkPipelineObj pipe(m_device);
15007 pipe.AddColorAttachment();
15008 pipe.AddShader(&vs);
15009 pipe.AddShader(&fs);
15010
15011 VkDescriptorSetObj descriptorSet(m_device);
15012 descriptorSet.AppendDummy();
15013 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15014
15015 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15016
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015017 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130015018}
15019
15020TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByComponent) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015021 TEST_DESCRIPTION(
15022 "Test that an error is produced for component mismatches across the "
15023 "vertex->fragment shader interface. It's not enough to have the same set of locations in "
15024 "use; matching is defined in terms of spirv variables.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015025 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 +130015026
Tony Barbour1fa09702017-03-16 12:09:08 -060015027 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbese9928822016-02-17 14:44:52 +130015028 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15029
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015030 char const *vsSource =
15031 "#version 450\n"
15032 "\n"
15033 "out block { layout(location=0, component=0) float x; } outs;\n"
15034 "out gl_PerVertex {\n"
15035 " vec4 gl_Position;\n"
15036 "};\n"
15037 "void main(){\n"
15038 " outs.x = 0;\n"
15039 " gl_Position = vec4(1);\n"
15040 "}\n";
15041 char const *fsSource =
15042 "#version 450\n"
15043 "\n"
15044 "in block { layout(location=0, component=1) float x; } ins;\n"
15045 "layout(location=0) out vec4 color;\n"
15046 "void main(){\n"
15047 " color = vec4(ins.x);\n"
15048 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130015049
15050 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15051 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15052
15053 VkPipelineObj pipe(m_device);
15054 pipe.AddColorAttachment();
15055 pipe.AddShader(&vs);
15056 pipe.AddShader(&fs);
15057
15058 VkDescriptorSetObj descriptorSet(m_device);
15059 descriptorSet.AppendDummy();
15060 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15061
15062 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15063
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015064 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130015065}
15066
Chris Forbes1f3b0152016-11-30 12:48:40 +130015067TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByPrecision) {
15068 TEST_DESCRIPTION("Test that the RelaxedPrecision decoration is validated to match");
15069
Tony Barbour1fa09702017-03-16 12:09:08 -060015070 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes1f3b0152016-11-30 12:48:40 +130015071 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15072
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015073 char const *vsSource =
15074 "#version 450\n"
15075 "layout(location=0) out mediump float x;\n"
15076 "void main() { gl_Position = vec4(0); x = 1.0; }\n";
15077 char const *fsSource =
15078 "#version 450\n"
15079 "layout(location=0) in highp float x;\n"
15080 "layout(location=0) out vec4 color;\n"
15081 "void main() { color = vec4(x); }\n";
Chris Forbes1f3b0152016-11-30 12:48:40 +130015082
15083 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15084 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15085
15086 VkPipelineObj pipe(m_device);
15087 pipe.AddColorAttachment();
15088 pipe.AddShader(&vs);
15089 pipe.AddShader(&fs);
15090
15091 VkDescriptorSetObj descriptorSet(m_device);
15092 descriptorSet.AppendDummy();
15093 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15094
15095 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "differ in precision");
15096
15097 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15098
15099 m_errorMonitor->VerifyFound();
15100}
15101
Chris Forbes870a39e2016-11-30 12:55:56 +130015102TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByPrecisionBlock) {
15103 TEST_DESCRIPTION("Test that the RelaxedPrecision decoration is validated to match");
15104
Tony Barbour1fa09702017-03-16 12:09:08 -060015105 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes870a39e2016-11-30 12:55:56 +130015106 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15107
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015108 char const *vsSource =
15109 "#version 450\n"
15110 "out block { layout(location=0) mediump float x; };\n"
15111 "void main() { gl_Position = vec4(0); x = 1.0; }\n";
15112 char const *fsSource =
15113 "#version 450\n"
15114 "in block { layout(location=0) highp float x; };\n"
15115 "layout(location=0) out vec4 color;\n"
15116 "void main() { color = vec4(x); }\n";
Chris Forbes870a39e2016-11-30 12:55:56 +130015117
15118 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15119 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15120
15121 VkPipelineObj pipe(m_device);
15122 pipe.AddColorAttachment();
15123 pipe.AddShader(&vs);
15124 pipe.AddShader(&fs);
15125
15126 VkDescriptorSetObj descriptorSet(m_device);
15127 descriptorSet.AppendDummy();
15128 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15129
15130 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "differ in precision");
15131
15132 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15133
15134 m_errorMonitor->VerifyFound();
15135}
15136
Karl Schultz6addd812016-02-02 17:17:23 -070015137TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015138 TEST_DESCRIPTION(
15139 "Test that a warning is produced for a vertex attribute which is "
15140 "not consumed by the vertex shader");
Mike Weiblencce7ec72016-10-17 19:33:05 -060015141 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015142
Tony Barbour1fa09702017-03-16 12:09:08 -060015143 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060015144 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesde136e02015-05-25 11:13:28 +120015145
15146 VkVertexInputBindingDescription input_binding;
15147 memset(&input_binding, 0, sizeof(input_binding));
15148
15149 VkVertexInputAttributeDescription input_attrib;
15150 memset(&input_attrib, 0, sizeof(input_attrib));
15151 input_attrib.format = VK_FORMAT_R32_SFLOAT;
15152
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015153 char const *vsSource =
15154 "#version 450\n"
15155 "\n"
15156 "out gl_PerVertex {\n"
15157 " vec4 gl_Position;\n"
15158 "};\n"
15159 "void main(){\n"
15160 " gl_Position = vec4(1);\n"
15161 "}\n";
15162 char const *fsSource =
15163 "#version 450\n"
15164 "\n"
15165 "layout(location=0) out vec4 color;\n"
15166 "void main(){\n"
15167 " color = vec4(1);\n"
15168 "}\n";
Chris Forbesde136e02015-05-25 11:13:28 +120015169
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060015170 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15171 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesde136e02015-05-25 11:13:28 +120015172
15173 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080015174 pipe.AddColorAttachment();
Chris Forbesde136e02015-05-25 11:13:28 +120015175 pipe.AddShader(&vs);
15176 pipe.AddShader(&fs);
15177
15178 pipe.AddVertexInputBindings(&input_binding, 1);
15179 pipe.AddVertexInputAttribs(&input_attrib, 1);
15180
Chris Forbesde136e02015-05-25 11:13:28 +120015181 VkDescriptorSetObj descriptorSet(m_device);
15182 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015183 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesde136e02015-05-25 11:13:28 +120015184
Tony Barbour5781e8f2015-08-04 16:23:11 -060015185 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesde136e02015-05-25 11:13:28 +120015186
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015187 m_errorMonitor->VerifyFound();
Chris Forbesde136e02015-05-25 11:13:28 +120015188}
15189
Karl Schultz6addd812016-02-02 17:17:23 -070015190TEST_F(VkLayerTest, CreatePipelineAttribLocationMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015191 TEST_DESCRIPTION(
15192 "Test that a warning is produced for a location mismatch on "
15193 "vertex attributes. This flushes out bad behavior in the interface walker");
Mike Weiblencce7ec72016-10-17 19:33:05 -060015194 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Chris Forbes7d83cd52016-01-15 11:32:03 +130015195
Tony Barbour1fa09702017-03-16 12:09:08 -060015196 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes7d83cd52016-01-15 11:32:03 +130015197 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15198
15199 VkVertexInputBindingDescription input_binding;
15200 memset(&input_binding, 0, sizeof(input_binding));
15201
15202 VkVertexInputAttributeDescription input_attrib;
15203 memset(&input_attrib, 0, sizeof(input_attrib));
15204 input_attrib.format = VK_FORMAT_R32_SFLOAT;
15205
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015206 char const *vsSource =
15207 "#version 450\n"
15208 "\n"
15209 "layout(location=1) in float x;\n"
15210 "out gl_PerVertex {\n"
15211 " vec4 gl_Position;\n"
15212 "};\n"
15213 "void main(){\n"
15214 " gl_Position = vec4(x);\n"
15215 "}\n";
15216 char const *fsSource =
15217 "#version 450\n"
15218 "\n"
15219 "layout(location=0) out vec4 color;\n"
15220 "void main(){\n"
15221 " color = vec4(1);\n"
15222 "}\n";
Chris Forbes7d83cd52016-01-15 11:32:03 +130015223
15224 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15225 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15226
15227 VkPipelineObj pipe(m_device);
15228 pipe.AddColorAttachment();
15229 pipe.AddShader(&vs);
15230 pipe.AddShader(&fs);
15231
15232 pipe.AddVertexInputBindings(&input_binding, 1);
15233 pipe.AddVertexInputAttribs(&input_attrib, 1);
15234
15235 VkDescriptorSetObj descriptorSet(m_device);
15236 descriptorSet.AppendDummy();
15237 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15238
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070015239 m_errorMonitor->SetUnexpectedError("Vertex shader consumes input at location 1 but not provided");
Chris Forbes7d83cd52016-01-15 11:32:03 +130015240 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15241
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015242 m_errorMonitor->VerifyFound();
Chris Forbes7d83cd52016-01-15 11:32:03 +130015243}
15244
Karl Schultz6addd812016-02-02 17:17:23 -070015245TEST_F(VkLayerTest, CreatePipelineAttribNotProvided) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015246 TEST_DESCRIPTION(
15247 "Test that an error is produced for a vertex shader input which is not "
15248 "provided by a vertex attribute");
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070015249 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15250 "Vertex shader consumes input at location 0 but not provided");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015251
Tony Barbour1fa09702017-03-16 12:09:08 -060015252 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060015253 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes62e8e502015-05-25 11:13:29 +120015254
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015255 char const *vsSource =
15256 "#version 450\n"
15257 "\n"
15258 "layout(location=0) in vec4 x;\n" /* not provided */
15259 "out gl_PerVertex {\n"
15260 " vec4 gl_Position;\n"
15261 "};\n"
15262 "void main(){\n"
15263 " gl_Position = x;\n"
15264 "}\n";
15265 char const *fsSource =
15266 "#version 450\n"
15267 "\n"
15268 "layout(location=0) out vec4 color;\n"
15269 "void main(){\n"
15270 " color = vec4(1);\n"
15271 "}\n";
Chris Forbes62e8e502015-05-25 11:13:29 +120015272
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060015273 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15274 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes62e8e502015-05-25 11:13:29 +120015275
15276 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080015277 pipe.AddColorAttachment();
Chris Forbes62e8e502015-05-25 11:13:29 +120015278 pipe.AddShader(&vs);
15279 pipe.AddShader(&fs);
15280
Chris Forbes62e8e502015-05-25 11:13:29 +120015281 VkDescriptorSetObj descriptorSet(m_device);
15282 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015283 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes62e8e502015-05-25 11:13:29 +120015284
Tony Barbour5781e8f2015-08-04 16:23:11 -060015285 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes62e8e502015-05-25 11:13:29 +120015286
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015287 m_errorMonitor->VerifyFound();
Chris Forbes62e8e502015-05-25 11:13:29 +120015288}
15289
Karl Schultz6addd812016-02-02 17:17:23 -070015290TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015291 TEST_DESCRIPTION(
15292 "Test that an error is produced for a mismatch between the "
15293 "fundamental type (float/int/uint) of an attribute and the "
15294 "vertex shader input that consumes it");
Mike Weiblen15bd38e2016-10-03 19:19:41 -060015295 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 -060015296
Tony Barbour1fa09702017-03-16 12:09:08 -060015297 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060015298 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc97d98e2015-05-25 11:13:31 +120015299
15300 VkVertexInputBindingDescription input_binding;
15301 memset(&input_binding, 0, sizeof(input_binding));
15302
15303 VkVertexInputAttributeDescription input_attrib;
15304 memset(&input_attrib, 0, sizeof(input_attrib));
15305 input_attrib.format = VK_FORMAT_R32_SFLOAT;
15306
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015307 char const *vsSource =
15308 "#version 450\n"
15309 "\n"
15310 "layout(location=0) in int x;\n" /* attrib provided float */
15311 "out gl_PerVertex {\n"
15312 " vec4 gl_Position;\n"
15313 "};\n"
15314 "void main(){\n"
15315 " gl_Position = vec4(x);\n"
15316 "}\n";
15317 char const *fsSource =
15318 "#version 450\n"
15319 "\n"
15320 "layout(location=0) out vec4 color;\n"
15321 "void main(){\n"
15322 " color = vec4(1);\n"
15323 "}\n";
Chris Forbesc97d98e2015-05-25 11:13:31 +120015324
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060015325 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15326 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc97d98e2015-05-25 11:13:31 +120015327
15328 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080015329 pipe.AddColorAttachment();
Chris Forbesc97d98e2015-05-25 11:13:31 +120015330 pipe.AddShader(&vs);
15331 pipe.AddShader(&fs);
15332
15333 pipe.AddVertexInputBindings(&input_binding, 1);
15334 pipe.AddVertexInputAttribs(&input_attrib, 1);
15335
Chris Forbesc97d98e2015-05-25 11:13:31 +120015336 VkDescriptorSetObj descriptorSet(m_device);
15337 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015338 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesc97d98e2015-05-25 11:13:31 +120015339
Tony Barbour5781e8f2015-08-04 16:23:11 -060015340 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc97d98e2015-05-25 11:13:31 +120015341
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015342 m_errorMonitor->VerifyFound();
Chris Forbesc97d98e2015-05-25 11:13:31 +120015343}
15344
Chris Forbesc68b43c2016-04-06 11:18:47 +120015345TEST_F(VkLayerTest, CreatePipelineDuplicateStage) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015346 TEST_DESCRIPTION(
15347 "Test that an error is produced for a pipeline containing multiple "
15348 "shaders for the same stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015349 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15350 "Multiple shaders provided for stage VK_SHADER_STAGE_VERTEX_BIT");
Chris Forbesc68b43c2016-04-06 11:18:47 +120015351
Tony Barbour1fa09702017-03-16 12:09:08 -060015352 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbesc68b43c2016-04-06 11:18:47 +120015353 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15354
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015355 char const *vsSource =
15356 "#version 450\n"
15357 "\n"
15358 "out gl_PerVertex {\n"
15359 " vec4 gl_Position;\n"
15360 "};\n"
15361 "void main(){\n"
15362 " gl_Position = vec4(1);\n"
15363 "}\n";
15364 char const *fsSource =
15365 "#version 450\n"
15366 "\n"
15367 "layout(location=0) out vec4 color;\n"
15368 "void main(){\n"
15369 " color = vec4(1);\n"
15370 "}\n";
Chris Forbesc68b43c2016-04-06 11:18:47 +120015371
15372 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15373 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15374
15375 VkPipelineObj pipe(m_device);
15376 pipe.AddColorAttachment();
15377 pipe.AddShader(&vs);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015378 pipe.AddShader(&vs); // intentionally duplicate vertex shader attachment
Chris Forbesc68b43c2016-04-06 11:18:47 +120015379 pipe.AddShader(&fs);
15380
15381 VkDescriptorSetObj descriptorSet(m_device);
15382 descriptorSet.AppendDummy();
15383 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15384
15385 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15386
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015387 m_errorMonitor->VerifyFound();
Chris Forbesc68b43c2016-04-06 11:18:47 +120015388}
15389
Chris Forbes82ff92a2016-09-09 10:50:24 +120015390TEST_F(VkLayerTest, CreatePipelineMissingEntrypoint) {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070015391 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "No entrypoint found named `foo`");
Chris Forbes82ff92a2016-09-09 10:50:24 +120015392
Tony Barbour1fa09702017-03-16 12:09:08 -060015393 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes82ff92a2016-09-09 10:50:24 +120015394 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15395
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015396 char const *vsSource =
15397 "#version 450\n"
15398 "out gl_PerVertex {\n"
15399 " vec4 gl_Position;\n"
15400 "};\n"
15401 "void main(){\n"
15402 " gl_Position = vec4(0);\n"
15403 "}\n";
15404 char const *fsSource =
15405 "#version 450\n"
15406 "\n"
15407 "layout(location=0) out vec4 color;\n"
15408 "void main(){\n"
15409 " color = vec4(1);\n"
15410 "}\n";
Chris Forbes82ff92a2016-09-09 10:50:24 +120015411
15412 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15413 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this, "foo");
15414
15415 VkPipelineObj pipe(m_device);
15416 pipe.AddColorAttachment();
15417 pipe.AddShader(&vs);
15418 pipe.AddShader(&fs);
15419
15420 VkDescriptorSetObj descriptorSet(m_device);
15421 descriptorSet.AppendDummy();
15422 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15423
15424 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15425
15426 m_errorMonitor->VerifyFound();
15427}
15428
Chris Forbesae9d8cd2016-09-13 16:32:57 +120015429TEST_F(VkLayerTest, CreatePipelineDepthStencilRequired) {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070015430 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15431 "pDepthStencilState is NULL when rasterization is enabled and subpass "
15432 "uses a depth/stencil attachment");
Chris Forbesae9d8cd2016-09-13 16:32:57 +120015433
Tony Barbour1fa09702017-03-16 12:09:08 -060015434 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbesae9d8cd2016-09-13 16:32:57 +120015435 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15436
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015437 char const *vsSource =
15438 "#version 450\n"
15439 "void main(){ gl_Position = vec4(0); }\n";
15440 char const *fsSource =
15441 "#version 450\n"
15442 "\n"
15443 "layout(location=0) out vec4 color;\n"
15444 "void main(){\n"
15445 " color = vec4(1);\n"
15446 "}\n";
Chris Forbesae9d8cd2016-09-13 16:32:57 +120015447
15448 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15449 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15450
15451 VkPipelineObj pipe(m_device);
15452 pipe.AddColorAttachment();
15453 pipe.AddShader(&vs);
15454 pipe.AddShader(&fs);
15455
15456 VkDescriptorSetObj descriptorSet(m_device);
15457 descriptorSet.AppendDummy();
15458 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15459
15460 VkAttachmentDescription attachments[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070015461 {
15462 0, VK_FORMAT_B8G8R8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
15463 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_UNDEFINED,
15464 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
Chris Forbesae9d8cd2016-09-13 16:32:57 +120015465 },
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070015466 {
15467 0, VK_FORMAT_D16_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
15468 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_UNDEFINED,
15469 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
Chris Forbesae9d8cd2016-09-13 16:32:57 +120015470 },
15471 };
15472 VkAttachmentReference refs[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070015473 {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL}, {1, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL},
Chris Forbesae9d8cd2016-09-13 16:32:57 +120015474 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070015475 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &refs[0], nullptr, &refs[1], 0, nullptr};
15476 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesae9d8cd2016-09-13 16:32:57 +120015477 VkRenderPass rp;
15478 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
15479 ASSERT_VK_SUCCESS(err);
15480
15481 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), rp);
15482
15483 m_errorMonitor->VerifyFound();
15484
15485 vkDestroyRenderPass(m_device->device(), rp, nullptr);
15486}
15487
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015488TEST_F(VkLayerTest, CreatePipelineTessPatchDecorationMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015489 TEST_DESCRIPTION(
15490 "Test that an error is produced for a variable output from "
15491 "the TCS without the patch decoration, but consumed in the TES "
15492 "with the decoration.");
15493 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15494 "is per-vertex in tessellation control shader stage "
15495 "but per-patch in tessellation evaluation shader stage");
Chris Forbesa0193bc2016-04-04 19:19:47 +120015496
Tony Barbour1fa09702017-03-16 12:09:08 -060015497 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbesa0193bc2016-04-04 19:19:47 +120015498 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15499
Chris Forbesc1e852d2016-04-04 19:26:42 +120015500 if (!m_device->phy().features().tessellationShader) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070015501 printf(" Device does not support tessellation shaders; skipped.\n");
Chris Forbesc1e852d2016-04-04 19:26:42 +120015502 return;
15503 }
15504
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015505 char const *vsSource =
15506 "#version 450\n"
15507 "void main(){}\n";
15508 char const *tcsSource =
15509 "#version 450\n"
15510 "layout(location=0) out int x[];\n"
15511 "layout(vertices=3) out;\n"
15512 "void main(){\n"
15513 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
15514 " gl_TessLevelInner[0] = 1;\n"
15515 " x[gl_InvocationID] = gl_InvocationID;\n"
15516 "}\n";
15517 char const *tesSource =
15518 "#version 450\n"
15519 "layout(triangles, equal_spacing, cw) in;\n"
15520 "layout(location=0) patch in int x;\n"
15521 "out gl_PerVertex { vec4 gl_Position; };\n"
15522 "void main(){\n"
15523 " gl_Position.xyz = gl_TessCoord;\n"
15524 " gl_Position.w = x;\n"
15525 "}\n";
15526 char const *fsSource =
15527 "#version 450\n"
15528 "layout(location=0) out vec4 color;\n"
15529 "void main(){\n"
15530 " color = vec4(1);\n"
15531 "}\n";
Chris Forbesa0193bc2016-04-04 19:19:47 +120015532
15533 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15534 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
15535 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
15536 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15537
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015538 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
15539 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Chris Forbesa0193bc2016-04-04 19:19:47 +120015540
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015541 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Chris Forbesa0193bc2016-04-04 19:19:47 +120015542
15543 VkPipelineObj pipe(m_device);
15544 pipe.SetInputAssembly(&iasci);
15545 pipe.SetTessellation(&tsci);
15546 pipe.AddColorAttachment();
15547 pipe.AddShader(&vs);
15548 pipe.AddShader(&tcs);
15549 pipe.AddShader(&tes);
15550 pipe.AddShader(&fs);
15551
15552 VkDescriptorSetObj descriptorSet(m_device);
15553 descriptorSet.AppendDummy();
15554 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15555
15556 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15557
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015558 m_errorMonitor->VerifyFound();
Chris Forbesa0193bc2016-04-04 19:19:47 +120015559}
15560
Cort Stratton2bcca1b2017-05-05 16:02:35 -070015561TEST_F(VkLayerTest, CreatePipelineTessErrors) {
15562 TEST_DESCRIPTION("Test various errors when creating a graphics pipeline with tessellation stages active.");
15563
15564 ASSERT_NO_FATAL_FAILURE(Init());
15565 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15566
15567 if (!m_device->phy().features().tessellationShader) {
15568 printf(" Device does not support tessellation shaders; skipped.\n");
15569 return;
15570 }
15571
15572 char const *vsSource =
15573 "#version 450\n"
15574 "void main(){}\n";
15575 char const *tcsSource =
15576 "#version 450\n"
15577 "layout(vertices=3) out;\n"
15578 "void main(){\n"
15579 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
15580 " gl_TessLevelInner[0] = 1;\n"
15581 "}\n";
15582 char const *tesSource =
15583 "#version 450\n"
15584 "layout(triangles, equal_spacing, cw) in;\n"
15585 "out gl_PerVertex { vec4 gl_Position; };\n"
15586 "void main(){\n"
15587 " gl_Position.xyz = gl_TessCoord;\n"
15588 " gl_Position.w = 0;\n"
15589 "}\n";
15590 char const *fsSource =
15591 "#version 450\n"
15592 "layout(location=0) out vec4 color;\n"
15593 "void main(){\n"
15594 " color = vec4(1);\n"
15595 "}\n";
15596
15597 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15598 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
15599 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
15600 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15601
15602 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
15603 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
15604
15605 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
15606
15607 VkDescriptorSetObj descriptorSet(m_device);
15608 descriptorSet.AppendDummy();
15609 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15610
15611 {
15612 VkPipelineObj pipe(m_device);
15613 VkPipelineInputAssemblyStateCreateInfo iasci_bad = iasci;
15614 iasci_bad.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST; // otherwise we get a failure about invalid topology
15615 pipe.SetInputAssembly(&iasci_bad);
15616 pipe.AddColorAttachment();
15617 pipe.AddShader(&vs);
15618 pipe.AddShader(&fs);
15619
15620 // Pass a tess control shader without a tess eval shader
15621 pipe.AddShader(&tcs);
15622 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00534);
15623 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15624 m_errorMonitor->VerifyFound();
15625 }
15626
15627 {
15628 VkPipelineObj pipe(m_device);
15629 VkPipelineInputAssemblyStateCreateInfo iasci_bad = iasci;
15630 iasci_bad.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST; // otherwise we get a failure about invalid topology
15631 pipe.SetInputAssembly(&iasci_bad);
15632 pipe.AddColorAttachment();
15633 pipe.AddShader(&vs);
15634 pipe.AddShader(&fs);
15635
15636 // Pass a tess eval shader without a tess control shader
15637 pipe.AddShader(&tes);
15638 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00535);
15639 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15640 m_errorMonitor->VerifyFound();
15641 }
15642
15643 {
15644 VkPipelineObj pipe(m_device);
15645 pipe.SetInputAssembly(&iasci);
15646 pipe.AddColorAttachment();
15647 pipe.AddShader(&vs);
15648 pipe.AddShader(&fs);
15649
15650 // Pass patch topology without tessellation shaders
15651 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02100);
15652 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15653 m_errorMonitor->VerifyFound();
15654
15655 pipe.AddShader(&tcs);
15656 pipe.AddShader(&tes);
15657 // Pass a NULL pTessellationState (with active tessellation shader stages)
15658 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00536);
15659 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15660 m_errorMonitor->VerifyFound();
15661
15662 // Pass an invalid pTessellationState (bad sType)
15663 VkPipelineTessellationStateCreateInfo tsci_bad = tsci;
15664 tsci_bad.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
15665 pipe.SetTessellation(&tsci_bad);
15666 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01427);
15667 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15668 m_errorMonitor->VerifyFound();
15669 // Pass out-of-range patchControlPoints
15670 tsci_bad = tsci;
15671 tsci_bad.patchControlPoints = 0;
15672 pipe.SetTessellation(&tsci);
15673 pipe.SetTessellation(&tsci_bad);
15674 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01426);
15675 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15676 m_errorMonitor->VerifyFound();
15677 tsci_bad.patchControlPoints = m_device->props.limits.maxTessellationPatchSize + 1;
15678 pipe.SetTessellation(&tsci_bad);
15679 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01426);
15680 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15681 m_errorMonitor->VerifyFound();
15682 pipe.SetTessellation(&tsci);
15683
15684 // Pass an invalid primitive topology
15685 VkPipelineInputAssemblyStateCreateInfo iasci_bad = iasci;
15686 iasci_bad.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
15687 pipe.SetInputAssembly(&iasci_bad);
15688 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02099);
15689 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15690 m_errorMonitor->VerifyFound();
15691 pipe.SetInputAssembly(&iasci);
15692 }
15693}
15694
Karl Schultz6addd812016-02-02 17:17:23 -070015695TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015696 TEST_DESCRIPTION(
15697 "Test that an error is produced for a vertex attribute setup where multiple "
15698 "bindings provide the same location");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015699 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15700 "Duplicate vertex input binding descriptions for binding 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015701
Tony Barbour1fa09702017-03-16 12:09:08 -060015702 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060015703 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes280ba2c2015-06-12 11:16:41 +120015704
15705 /* Two binding descriptions for binding 0 */
15706 VkVertexInputBindingDescription input_bindings[2];
15707 memset(input_bindings, 0, sizeof(input_bindings));
15708
15709 VkVertexInputAttributeDescription input_attrib;
15710 memset(&input_attrib, 0, sizeof(input_attrib));
15711 input_attrib.format = VK_FORMAT_R32_SFLOAT;
15712
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015713 char const *vsSource =
15714 "#version 450\n"
15715 "\n"
15716 "layout(location=0) in float x;\n" /* attrib provided float */
15717 "out gl_PerVertex {\n"
15718 " vec4 gl_Position;\n"
15719 "};\n"
15720 "void main(){\n"
15721 " gl_Position = vec4(x);\n"
15722 "}\n";
15723 char const *fsSource =
15724 "#version 450\n"
15725 "\n"
15726 "layout(location=0) out vec4 color;\n"
15727 "void main(){\n"
15728 " color = vec4(1);\n"
15729 "}\n";
Chris Forbes280ba2c2015-06-12 11:16:41 +120015730
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060015731 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15732 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes280ba2c2015-06-12 11:16:41 +120015733
15734 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080015735 pipe.AddColorAttachment();
Chris Forbes280ba2c2015-06-12 11:16:41 +120015736 pipe.AddShader(&vs);
15737 pipe.AddShader(&fs);
15738
15739 pipe.AddVertexInputBindings(input_bindings, 2);
15740 pipe.AddVertexInputAttribs(&input_attrib, 1);
15741
Chris Forbes280ba2c2015-06-12 11:16:41 +120015742 VkDescriptorSetObj descriptorSet(m_device);
15743 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015744 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes280ba2c2015-06-12 11:16:41 +120015745
Tony Barbour5781e8f2015-08-04 16:23:11 -060015746 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes280ba2c2015-06-12 11:16:41 +120015747
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015748 m_errorMonitor->VerifyFound();
Chris Forbes280ba2c2015-06-12 11:16:41 +120015749}
Chris Forbes8f68b562015-05-25 11:13:32 +120015750
Karl Schultz6addd812016-02-02 17:17:23 -070015751TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015752 TEST_DESCRIPTION(
15753 "Test that an error is produced for a fragment shader which does not "
15754 "provide an output for one of the pipeline's color attachments");
Mike Weiblencce7ec72016-10-17 19:33:05 -060015755 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attachment 0 not written by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015756
Tony Barbour1fa09702017-03-16 12:09:08 -060015757 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120015758
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015759 char const *vsSource =
15760 "#version 450\n"
15761 "\n"
15762 "out gl_PerVertex {\n"
15763 " vec4 gl_Position;\n"
15764 "};\n"
15765 "void main(){\n"
15766 " gl_Position = vec4(1);\n"
15767 "}\n";
15768 char const *fsSource =
15769 "#version 450\n"
15770 "\n"
15771 "void main(){\n"
15772 "}\n";
Chris Forbes4d6d1e52015-05-25 11:13:40 +120015773
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060015774 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15775 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120015776
15777 VkPipelineObj pipe(m_device);
15778 pipe.AddShader(&vs);
15779 pipe.AddShader(&fs);
15780
Chia-I Wu08accc62015-07-07 11:50:03 +080015781 /* set up CB 0, not written */
15782 pipe.AddColorAttachment();
15783 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120015784
Chris Forbes4d6d1e52015-05-25 11:13:40 +120015785 VkDescriptorSetObj descriptorSet(m_device);
15786 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015787 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120015788
Tony Barbour5781e8f2015-08-04 16:23:11 -060015789 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120015790
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015791 m_errorMonitor->VerifyFound();
Chris Forbes4d6d1e52015-05-25 11:13:40 +120015792}
15793
Karl Schultz6addd812016-02-02 17:17:23 -070015794TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015795 TEST_DESCRIPTION(
15796 "Test that a warning is produced for a fragment shader which provides a spurious "
15797 "output with no matching attachment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015798 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060015799 "fragment shader writes to output location 1 with no matching attachment");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015800
Tony Barbour1fa09702017-03-16 12:09:08 -060015801 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120015802
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015803 char const *vsSource =
15804 "#version 450\n"
15805 "\n"
15806 "out gl_PerVertex {\n"
15807 " vec4 gl_Position;\n"
15808 "};\n"
15809 "void main(){\n"
15810 " gl_Position = vec4(1);\n"
15811 "}\n";
15812 char const *fsSource =
15813 "#version 450\n"
15814 "\n"
15815 "layout(location=0) out vec4 x;\n"
15816 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
15817 "void main(){\n"
15818 " x = vec4(1);\n"
15819 " y = vec4(1);\n"
15820 "}\n";
Chris Forbesf3fffaa2015-05-25 11:13:43 +120015821
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060015822 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15823 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120015824
15825 VkPipelineObj pipe(m_device);
15826 pipe.AddShader(&vs);
15827 pipe.AddShader(&fs);
15828
Chia-I Wu08accc62015-07-07 11:50:03 +080015829 /* set up CB 0, not written */
15830 pipe.AddColorAttachment();
15831 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120015832 /* FS writes CB 1, but we don't configure it */
15833
Chris Forbesf3fffaa2015-05-25 11:13:43 +120015834 VkDescriptorSetObj descriptorSet(m_device);
15835 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015836 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120015837
Tony Barbour5781e8f2015-08-04 16:23:11 -060015838 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120015839
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015840 m_errorMonitor->VerifyFound();
Chris Forbesf3fffaa2015-05-25 11:13:43 +120015841}
15842
Karl Schultz6addd812016-02-02 17:17:23 -070015843TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015844 TEST_DESCRIPTION(
15845 "Test that an error is produced for a mismatch between the fundamental "
15846 "type of an fragment shader output variable, and the format of the corresponding attachment");
Mike Weiblencce7ec72016-10-17 19:33:05 -060015847 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "does not match fragment shader output type");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015848
Tony Barbour1fa09702017-03-16 12:09:08 -060015849 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbesa36d69e2015-05-25 11:13:44 +120015850
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015851 char const *vsSource =
15852 "#version 450\n"
15853 "\n"
15854 "out gl_PerVertex {\n"
15855 " vec4 gl_Position;\n"
15856 "};\n"
15857 "void main(){\n"
15858 " gl_Position = vec4(1);\n"
15859 "}\n";
15860 char const *fsSource =
15861 "#version 450\n"
15862 "\n"
15863 "layout(location=0) out ivec4 x;\n" /* not UNORM */
15864 "void main(){\n"
15865 " x = ivec4(1);\n"
15866 "}\n";
Chris Forbesa36d69e2015-05-25 11:13:44 +120015867
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060015868 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15869 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa36d69e2015-05-25 11:13:44 +120015870
15871 VkPipelineObj pipe(m_device);
15872 pipe.AddShader(&vs);
15873 pipe.AddShader(&fs);
15874
Chia-I Wu08accc62015-07-07 11:50:03 +080015875 /* set up CB 0; type is UNORM by default */
15876 pipe.AddColorAttachment();
15877 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa36d69e2015-05-25 11:13:44 +120015878
Chris Forbesa36d69e2015-05-25 11:13:44 +120015879 VkDescriptorSetObj descriptorSet(m_device);
15880 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015881 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesa36d69e2015-05-25 11:13:44 +120015882
Tony Barbour5781e8f2015-08-04 16:23:11 -060015883 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa36d69e2015-05-25 11:13:44 +120015884
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015885 m_errorMonitor->VerifyFound();
Chris Forbesa36d69e2015-05-25 11:13:44 +120015886}
Chris Forbes7b1b8932015-06-05 14:43:36 +120015887
Karl Schultz6addd812016-02-02 17:17:23 -070015888TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015889 TEST_DESCRIPTION(
15890 "Test that an error is produced for a shader consuming a uniform "
15891 "block which has no corresponding binding in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015892 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in pipeline layout");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015893
Tony Barbour1fa09702017-03-16 12:09:08 -060015894 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes556c76c2015-08-14 12:04:59 +120015895
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015896 char const *vsSource =
15897 "#version 450\n"
15898 "\n"
15899 "out gl_PerVertex {\n"
15900 " vec4 gl_Position;\n"
15901 "};\n"
15902 "void main(){\n"
15903 " gl_Position = vec4(1);\n"
15904 "}\n";
15905 char const *fsSource =
15906 "#version 450\n"
15907 "\n"
15908 "layout(location=0) out vec4 x;\n"
15909 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
15910 "void main(){\n"
15911 " x = vec4(bar.y);\n"
15912 "}\n";
Chris Forbes556c76c2015-08-14 12:04:59 +120015913
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060015914 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15915 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes556c76c2015-08-14 12:04:59 +120015916
Chris Forbes556c76c2015-08-14 12:04:59 +120015917 VkPipelineObj pipe(m_device);
15918 pipe.AddShader(&vs);
15919 pipe.AddShader(&fs);
15920
15921 /* set up CB 0; type is UNORM by default */
15922 pipe.AddColorAttachment();
15923 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15924
15925 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015926 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes556c76c2015-08-14 12:04:59 +120015927
15928 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15929
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015930 m_errorMonitor->VerifyFound();
Chris Forbes556c76c2015-08-14 12:04:59 +120015931}
15932
Chris Forbes5c59e902016-02-26 16:56:09 +130015933TEST_F(VkLayerTest, CreatePipelinePushConstantsNotInLayout) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015934 TEST_DESCRIPTION(
15935 "Test that an error is produced for a shader consuming push constants "
15936 "which are not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015937 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in layout");
Chris Forbes5c59e902016-02-26 16:56:09 +130015938
Tony Barbour1fa09702017-03-16 12:09:08 -060015939 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes5c59e902016-02-26 16:56:09 +130015940
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015941 char const *vsSource =
15942 "#version 450\n"
15943 "\n"
15944 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
15945 "out gl_PerVertex {\n"
15946 " vec4 gl_Position;\n"
15947 "};\n"
15948 "void main(){\n"
15949 " gl_Position = vec4(consts.x);\n"
15950 "}\n";
15951 char const *fsSource =
15952 "#version 450\n"
15953 "\n"
15954 "layout(location=0) out vec4 x;\n"
15955 "void main(){\n"
15956 " x = vec4(1);\n"
15957 "}\n";
Chris Forbes5c59e902016-02-26 16:56:09 +130015958
15959 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15960 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15961
15962 VkPipelineObj pipe(m_device);
15963 pipe.AddShader(&vs);
15964 pipe.AddShader(&fs);
15965
15966 /* set up CB 0; type is UNORM by default */
15967 pipe.AddColorAttachment();
15968 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15969
15970 VkDescriptorSetObj descriptorSet(m_device);
15971 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15972
15973 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15974
15975 /* should have generated an error -- no push constant ranges provided! */
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015976 m_errorMonitor->VerifyFound();
Chris Forbes5c59e902016-02-26 16:56:09 +130015977}
15978
Chris Forbes3fb17902016-08-22 14:57:55 +120015979TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissing) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015980 TEST_DESCRIPTION(
15981 "Test that an error is produced for a shader consuming an input attachment "
15982 "which is not included in the subpass description");
Chris Forbes3fb17902016-08-22 14:57:55 +120015983 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15984 "consumes input attachment index 0 but not provided in subpass");
15985
Tony Barbour1fa09702017-03-16 12:09:08 -060015986 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes3fb17902016-08-22 14:57:55 +120015987
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015988 char const *vsSource =
15989 "#version 450\n"
15990 "\n"
15991 "out gl_PerVertex {\n"
15992 " vec4 gl_Position;\n"
15993 "};\n"
15994 "void main(){\n"
15995 " gl_Position = vec4(1);\n"
15996 "}\n";
15997 char const *fsSource =
15998 "#version 450\n"
15999 "\n"
16000 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
16001 "layout(location=0) out vec4 color;\n"
16002 "void main() {\n"
16003 " color = subpassLoad(x);\n"
16004 "}\n";
Chris Forbes3fb17902016-08-22 14:57:55 +120016005
16006 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
16007 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
16008
16009 VkPipelineObj pipe(m_device);
16010 pipe.AddShader(&vs);
16011 pipe.AddShader(&fs);
16012 pipe.AddColorAttachment();
16013 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16014
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016015 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
16016 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes3fb17902016-08-22 14:57:55 +120016017 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016018 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes3fb17902016-08-22 14:57:55 +120016019 ASSERT_VK_SUCCESS(err);
16020
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016021 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes3fb17902016-08-22 14:57:55 +120016022 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016023 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes3fb17902016-08-22 14:57:55 +120016024 ASSERT_VK_SUCCESS(err);
16025
16026 // error here.
16027 pipe.CreateVKPipeline(pl, renderPass());
16028
16029 m_errorMonitor->VerifyFound();
16030
16031 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
16032 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
16033}
16034
Chris Forbes5a9a0472016-08-22 16:02:09 +120016035TEST_F(VkLayerTest, CreatePipelineInputAttachmentTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016036 TEST_DESCRIPTION(
16037 "Test that an error is produced for a shader consuming an input attachment "
16038 "with a format having a different fundamental type");
Chris Forbes5a9a0472016-08-22 16:02:09 +120016039 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16040 "input attachment 0 format of VK_FORMAT_R8G8B8A8_UINT does not match");
16041
Tony Barbour1fa09702017-03-16 12:09:08 -060016042 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes5a9a0472016-08-22 16:02:09 +120016043
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016044 char const *vsSource =
16045 "#version 450\n"
16046 "\n"
16047 "out gl_PerVertex {\n"
16048 " vec4 gl_Position;\n"
16049 "};\n"
16050 "void main(){\n"
16051 " gl_Position = vec4(1);\n"
16052 "}\n";
16053 char const *fsSource =
16054 "#version 450\n"
16055 "\n"
16056 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
16057 "layout(location=0) out vec4 color;\n"
16058 "void main() {\n"
16059 " color = subpassLoad(x);\n"
16060 "}\n";
Chris Forbes5a9a0472016-08-22 16:02:09 +120016061
16062 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
16063 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
16064
16065 VkPipelineObj pipe(m_device);
16066 pipe.AddShader(&vs);
16067 pipe.AddShader(&fs);
16068 pipe.AddColorAttachment();
16069 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16070
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016071 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
16072 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes5a9a0472016-08-22 16:02:09 +120016073 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016074 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120016075 ASSERT_VK_SUCCESS(err);
16076
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016077 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120016078 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016079 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120016080 ASSERT_VK_SUCCESS(err);
16081
16082 VkAttachmentDescription descs[2] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016083 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
16084 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
16085 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
16086 {0, VK_FORMAT_R8G8B8A8_UINT, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
16087 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 +120016088 };
16089 VkAttachmentReference color = {
16090 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
16091 };
16092 VkAttachmentReference input = {
16093 1, VK_IMAGE_LAYOUT_GENERAL,
16094 };
16095
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016096 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120016097
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016098 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120016099 VkRenderPass rp;
16100 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
16101 ASSERT_VK_SUCCESS(err);
16102
16103 // error here.
16104 pipe.CreateVKPipeline(pl, rp);
16105
16106 m_errorMonitor->VerifyFound();
16107
16108 vkDestroyRenderPass(m_device->device(), rp, nullptr);
16109 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
16110 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
16111}
16112
Chris Forbes541f7b02016-08-22 15:30:27 +120016113TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissingArray) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016114 TEST_DESCRIPTION(
16115 "Test that an error is produced for a shader consuming an input attachment "
16116 "which is not included in the subpass description -- array case");
Chris Forbes541f7b02016-08-22 15:30:27 +120016117 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Rene Lindsay07b60af2017-01-10 15:57:55 -070016118 "consumes input attachment index 0 but not provided in subpass");
Chris Forbes541f7b02016-08-22 15:30:27 +120016119
Tony Barbour1fa09702017-03-16 12:09:08 -060016120 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes541f7b02016-08-22 15:30:27 +120016121
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016122 char const *vsSource =
16123 "#version 450\n"
16124 "\n"
16125 "out gl_PerVertex {\n"
16126 " vec4 gl_Position;\n"
16127 "};\n"
16128 "void main(){\n"
16129 " gl_Position = vec4(1);\n"
16130 "}\n";
16131 char const *fsSource =
16132 "#version 450\n"
16133 "\n"
16134 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput xs[1];\n"
16135 "layout(location=0) out vec4 color;\n"
16136 "void main() {\n"
16137 " color = subpassLoad(xs[0]);\n"
16138 "}\n";
Chris Forbes541f7b02016-08-22 15:30:27 +120016139
16140 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
16141 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
16142
16143 VkPipelineObj pipe(m_device);
16144 pipe.AddShader(&vs);
16145 pipe.AddShader(&fs);
16146 pipe.AddColorAttachment();
16147 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16148
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016149 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 2, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
16150 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes541f7b02016-08-22 15:30:27 +120016151 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016152 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes541f7b02016-08-22 15:30:27 +120016153 ASSERT_VK_SUCCESS(err);
16154
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016155 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes541f7b02016-08-22 15:30:27 +120016156 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016157 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes541f7b02016-08-22 15:30:27 +120016158 ASSERT_VK_SUCCESS(err);
16159
16160 // error here.
16161 pipe.CreateVKPipeline(pl, renderPass());
16162
16163 m_errorMonitor->VerifyFound();
16164
16165 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
16166 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
16167}
16168
Chris Forbes10eb9ae2016-05-31 16:09:42 +120016169TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptor) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016170 TEST_DESCRIPTION(
16171 "Test that an error is produced for a compute pipeline consuming a "
16172 "descriptor which is not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016173 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Shader uses descriptor slot 0.0");
Chris Forbes10eb9ae2016-05-31 16:09:42 +120016174
Tony Barbour1fa09702017-03-16 12:09:08 -060016175 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes10eb9ae2016-05-31 16:09:42 +120016176
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016177 char const *csSource =
16178 "#version 450\n"
16179 "\n"
16180 "layout(local_size_x=1) in;\n"
16181 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
16182 "void main(){\n"
16183 " x = vec4(1);\n"
16184 "}\n";
Chris Forbes10eb9ae2016-05-31 16:09:42 +120016185
16186 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
16187
16188 VkDescriptorSetObj descriptorSet(m_device);
16189 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
16190
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016191 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
16192 nullptr,
16193 0,
16194 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
16195 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
16196 descriptorSet.GetPipelineLayout(),
16197 VK_NULL_HANDLE,
16198 -1};
Chris Forbes10eb9ae2016-05-31 16:09:42 +120016199
16200 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016201 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes10eb9ae2016-05-31 16:09:42 +120016202
16203 m_errorMonitor->VerifyFound();
16204
16205 if (err == VK_SUCCESS) {
16206 vkDestroyPipeline(m_device->device(), pipe, nullptr);
16207 }
16208}
16209
Chris Forbes22a9b092016-07-19 14:34:05 +120016210TEST_F(VkLayerTest, CreateComputePipelineDescriptorTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016211 TEST_DESCRIPTION(
16212 "Test that an error is produced for a pipeline consuming a "
16213 "descriptor-backed resource of a mismatched type");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016214 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16215 "but descriptor of type VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER");
Chris Forbes22a9b092016-07-19 14:34:05 +120016216
Tony Barbour1fa09702017-03-16 12:09:08 -060016217 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes22a9b092016-07-19 14:34:05 +120016218
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016219 VkDescriptorSetLayoutBinding binding = {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr};
16220 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &binding};
Chris Forbes22a9b092016-07-19 14:34:05 +120016221 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016222 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes22a9b092016-07-19 14:34:05 +120016223 ASSERT_VK_SUCCESS(err);
16224
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016225 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes22a9b092016-07-19 14:34:05 +120016226 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016227 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes22a9b092016-07-19 14:34:05 +120016228 ASSERT_VK_SUCCESS(err);
16229
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016230 char const *csSource =
16231 "#version 450\n"
16232 "\n"
16233 "layout(local_size_x=1) in;\n"
16234 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
16235 "void main() {\n"
16236 " x.x = 1.0f;\n"
16237 "}\n";
Chris Forbes22a9b092016-07-19 14:34:05 +120016238 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
16239
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016240 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
16241 nullptr,
16242 0,
16243 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
16244 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
16245 pl,
16246 VK_NULL_HANDLE,
16247 -1};
Chris Forbes22a9b092016-07-19 14:34:05 +120016248
16249 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016250 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes22a9b092016-07-19 14:34:05 +120016251
16252 m_errorMonitor->VerifyFound();
16253
16254 if (err == VK_SUCCESS) {
16255 vkDestroyPipeline(m_device->device(), pipe, nullptr);
16256 }
16257
16258 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
16259 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
16260}
16261
Chris Forbes50020592016-07-27 13:52:41 +120016262TEST_F(VkLayerTest, DrawTimeImageViewTypeMismatchWithPipeline) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016263 TEST_DESCRIPTION(
16264 "Test that an error is produced when an image view type "
16265 "does not match the dimensionality declared in the shader");
Chris Forbes50020592016-07-27 13:52:41 +120016266
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016267 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 +120016268
Tony Barbour1fa09702017-03-16 12:09:08 -060016269 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes50020592016-07-27 13:52:41 +120016270 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16271
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016272 char const *vsSource =
16273 "#version 450\n"
16274 "\n"
16275 "out gl_PerVertex { vec4 gl_Position; };\n"
16276 "void main() { gl_Position = vec4(0); }\n";
16277 char const *fsSource =
16278 "#version 450\n"
16279 "\n"
16280 "layout(set=0, binding=0) uniform sampler3D s;\n"
16281 "layout(location=0) out vec4 color;\n"
16282 "void main() {\n"
16283 " color = texture(s, vec3(0));\n"
16284 "}\n";
Chris Forbes50020592016-07-27 13:52:41 +120016285 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
16286 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
16287
16288 VkPipelineObj pipe(m_device);
16289 pipe.AddShader(&vs);
16290 pipe.AddShader(&fs);
16291 pipe.AddColorAttachment();
16292
16293 VkTextureObj texture(m_device, nullptr);
16294 VkSamplerObj sampler(m_device);
16295
16296 VkDescriptorSetObj descriptorSet(m_device);
16297 descriptorSet.AppendSamplerTexture(&sampler, &texture);
16298 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
16299
16300 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
16301 ASSERT_VK_SUCCESS(err);
16302
Tony Barbour552f6c02016-12-21 14:34:07 -070016303 m_commandBuffer->BeginCommandBuffer();
16304 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes50020592016-07-27 13:52:41 +120016305
16306 m_commandBuffer->BindPipeline(pipe);
16307 m_commandBuffer->BindDescriptorSet(descriptorSet);
16308
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016309 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes50020592016-07-27 13:52:41 +120016310 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016311 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes50020592016-07-27 13:52:41 +120016312 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16313
16314 // error produced here.
16315 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
16316
16317 m_errorMonitor->VerifyFound();
16318
Tony Barbour552f6c02016-12-21 14:34:07 -070016319 m_commandBuffer->EndRenderPass();
16320 m_commandBuffer->EndCommandBuffer();
Chris Forbes50020592016-07-27 13:52:41 +120016321}
16322
Chris Forbes5533bfc2016-07-27 14:12:34 +120016323TEST_F(VkLayerTest, DrawTimeImageMultisampleMismatchWithPipeline) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016324 TEST_DESCRIPTION(
16325 "Test that an error is produced when a multisampled images "
16326 "are consumed via singlesample images types in the shader, or vice versa.");
Chris Forbes5533bfc2016-07-27 14:12:34 +120016327
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016328 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "requires bound image to have multiple samples");
Chris Forbes5533bfc2016-07-27 14:12:34 +120016329
Tony Barbour1fa09702017-03-16 12:09:08 -060016330 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes5533bfc2016-07-27 14:12:34 +120016331 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16332
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016333 char const *vsSource =
16334 "#version 450\n"
16335 "\n"
16336 "out gl_PerVertex { vec4 gl_Position; };\n"
16337 "void main() { gl_Position = vec4(0); }\n";
16338 char const *fsSource =
16339 "#version 450\n"
16340 "\n"
16341 "layout(set=0, binding=0) uniform sampler2DMS s;\n"
16342 "layout(location=0) out vec4 color;\n"
16343 "void main() {\n"
16344 " color = texelFetch(s, ivec2(0), 0);\n"
16345 "}\n";
Chris Forbes5533bfc2016-07-27 14:12:34 +120016346 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
16347 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
16348
16349 VkPipelineObj pipe(m_device);
16350 pipe.AddShader(&vs);
16351 pipe.AddShader(&fs);
16352 pipe.AddColorAttachment();
16353
16354 VkTextureObj texture(m_device, nullptr);
16355 VkSamplerObj sampler(m_device);
16356
16357 VkDescriptorSetObj descriptorSet(m_device);
16358 descriptorSet.AppendSamplerTexture(&sampler, &texture);
16359 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
16360
16361 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
16362 ASSERT_VK_SUCCESS(err);
16363
Tony Barbour552f6c02016-12-21 14:34:07 -070016364 m_commandBuffer->BeginCommandBuffer();
16365 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes5533bfc2016-07-27 14:12:34 +120016366
16367 m_commandBuffer->BindPipeline(pipe);
16368 m_commandBuffer->BindDescriptorSet(descriptorSet);
16369
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016370 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes5533bfc2016-07-27 14:12:34 +120016371 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016372 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes5533bfc2016-07-27 14:12:34 +120016373 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16374
16375 // error produced here.
16376 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
16377
16378 m_errorMonitor->VerifyFound();
16379
Tony Barbour552f6c02016-12-21 14:34:07 -070016380 m_commandBuffer->EndRenderPass();
16381 m_commandBuffer->EndCommandBuffer();
Chris Forbes5533bfc2016-07-27 14:12:34 +120016382}
16383
Mark Youngc48c4c12016-04-11 14:26:49 -060016384TEST_F(VkLayerTest, CreateImageLimitsViolationMaxWidth) {
Tony Barbour1fa09702017-03-16 12:09:08 -060016385 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060016386
Jeremy Hayesbb63cc12017-03-20 15:33:01 -060016387 VkFormat const format = VK_FORMAT_B8G8R8A8_UNORM;
16388 {
16389 VkFormatProperties properties;
16390 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), format, &properties);
16391 if (properties.optimalTilingFeatures == 0) {
16392 printf(" Image format not supported; skipped.\n");
16393 return;
16394 }
16395 }
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060016396
Jeremy Hayesbb63cc12017-03-20 15:33:01 -060016397 VkImageCreateInfo info = {};
16398 info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16399 info.pNext = NULL;
16400 info.imageType = VK_IMAGE_TYPE_2D;
16401 info.format = format;
16402 info.extent.height = 32;
16403 info.extent.depth = 1;
16404 info.mipLevels = 1;
16405 info.arrayLayers = 1;
16406 info.samples = VK_SAMPLE_COUNT_1_BIT;
16407 info.tiling = VK_IMAGE_TILING_OPTIMAL;
16408 info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
16409 info.flags = 0;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060016410
16411 // Introduce error by sending down a bogus width extent
Jeremy Hayesbb63cc12017-03-20 15:33:01 -060016412 {
16413 VkImageFormatProperties properties;
16414 auto const result = vkGetPhysicalDeviceImageFormatProperties(m_device->phy().handle(), info.format, info.imageType,
16415 info.tiling, info.usage, info.flags, &properties);
16416 ASSERT_VK_SUCCESS(result);
16417 info.extent.width = properties.maxExtent.width + 1;
16418 }
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060016419
Jeremy Hayesbb63cc12017-03-20 15:33:01 -060016420 VkImage image;
16421 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
16422 vkCreateImage(m_device->device(), &info, NULL, &image);
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016423 m_errorMonitor->VerifyFound();
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060016424}
16425
Mark Youngc48c4c12016-04-11 14:26:49 -060016426TEST_F(VkLayerTest, CreateImageLimitsViolationMinWidth) {
Tony Barbour1fa09702017-03-16 12:09:08 -060016427 ASSERT_NO_FATAL_FAILURE(Init());
Mark Youngc48c4c12016-04-11 14:26:49 -060016428
Jeremy Hayesbb63cc12017-03-20 15:33:01 -060016429 VkFormat const format = VK_FORMAT_B8G8R8A8_UNORM;
16430 {
16431 VkFormatProperties properties;
16432 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), format, &properties);
16433 if (properties.optimalTilingFeatures == 0) {
16434 printf(" Image format not supported; skipped.\n");
16435 return;
16436 }
16437 }
Mark Youngc48c4c12016-04-11 14:26:49 -060016438
Jeremy Hayesbb63cc12017-03-20 15:33:01 -060016439 VkImageCreateInfo info = {};
16440 info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16441 info.pNext = NULL;
16442 info.imageType = VK_IMAGE_TYPE_2D;
16443 info.format = format;
16444 info.extent.height = 32;
16445 info.extent.depth = 1;
16446 info.mipLevels = 1;
16447 info.arrayLayers = 1;
16448 info.samples = VK_SAMPLE_COUNT_1_BIT;
16449 info.tiling = VK_IMAGE_TILING_OPTIMAL;
16450 info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
16451 info.flags = 0;
Mark Youngc48c4c12016-04-11 14:26:49 -060016452
16453 // Introduce error by sending down a bogus width extent
Jeremy Hayesbb63cc12017-03-20 15:33:01 -060016454 info.extent.width = 0;
Mark Youngc48c4c12016-04-11 14:26:49 -060016455
Jeremy Hayesbb63cc12017-03-20 15:33:01 -060016456 VkImage image;
Tobin Ehlisa55b1d42017-04-04 12:23:48 -060016457 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02917);
Jeremy Hayesbb63cc12017-03-20 15:33:01 -060016458 m_errorMonitor->SetUnexpectedError("parameter pCreateInfo->extent.width must be greater than 0");
16459 vkCreateImage(m_device->device(), &info, NULL, &image);
Mark Youngc48c4c12016-04-11 14:26:49 -060016460 m_errorMonitor->VerifyFound();
16461}
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -070016462
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060016463TEST_F(VkLayerTest, AttachmentDescriptionUndefinedFormat) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016464 TEST_DESCRIPTION(
16465 "Create a render pass with an attachment description "
16466 "format set to VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060016467
Tony Barbour1fa09702017-03-16 12:09:08 -060016468 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060016469 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16470
Jeremy Hayes632e0ab2017-02-09 13:32:28 -070016471 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "format is VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060016472
16473 VkAttachmentReference color_attach = {};
16474 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
16475 color_attach.attachment = 0;
16476 VkSubpassDescription subpass = {};
16477 subpass.colorAttachmentCount = 1;
16478 subpass.pColorAttachments = &color_attach;
16479
16480 VkRenderPassCreateInfo rpci = {};
16481 rpci.subpassCount = 1;
16482 rpci.pSubpasses = &subpass;
16483 rpci.attachmentCount = 1;
16484 VkAttachmentDescription attach_desc = {};
16485 attach_desc.format = VK_FORMAT_UNDEFINED;
16486 rpci.pAttachments = &attach_desc;
16487 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
16488 VkRenderPass rp;
16489 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
16490
16491 m_errorMonitor->VerifyFound();
16492
16493 if (result == VK_SUCCESS) {
16494 vkDestroyRenderPass(m_device->device(), rp, NULL);
16495 }
16496}
16497
Karl Schultz6addd812016-02-02 17:17:23 -070016498TEST_F(VkLayerTest, InvalidImageView) {
Tony Barbour1fa09702017-03-16 12:09:08 -060016499 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehliscde08892015-09-22 10:11:37 -060016500
Mike Stroyana3082432015-09-25 13:39:21 -060016501 // Create an image and try to create a view with bad baseMipLevel
Karl Schultz6addd812016-02-02 17:17:23 -070016502 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
16503 const int32_t tex_width = 32;
16504 const int32_t tex_height = 32;
Tobin Ehliscde08892015-09-22 10:11:37 -060016505
16506 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016507 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16508 image_create_info.pNext = NULL;
16509 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16510 image_create_info.format = tex_format;
16511 image_create_info.extent.width = tex_width;
16512 image_create_info.extent.height = tex_height;
16513 image_create_info.extent.depth = 1;
16514 image_create_info.mipLevels = 1;
16515 image_create_info.arrayLayers = 1;
16516 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16517 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16518 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
16519 image_create_info.flags = 0;
Tobin Ehliscde08892015-09-22 10:11:37 -060016520
Jeremy Hayesa1ffc2b2017-03-10 16:05:37 -070016521 VkImage image;
16522 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehliscde08892015-09-22 10:11:37 -060016523 ASSERT_VK_SUCCESS(err);
16524
Jeremy Hayesa1ffc2b2017-03-10 16:05:37 -070016525 VkMemoryRequirements requirements;
16526 vkGetImageMemoryRequirements(m_device->device(), image, &requirements);
16527
16528 VkMemoryAllocateInfo alloc_info{};
16529 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16530 alloc_info.pNext = NULL;
16531 alloc_info.memoryTypeIndex = 0;
16532 alloc_info.allocationSize = requirements.size;
16533 bool pass = m_device->phy().set_memory_type(requirements.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
16534 ASSERT_TRUE(pass);
16535
16536 VkDeviceMemory memory;
16537 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &memory);
16538 ASSERT_VK_SUCCESS(err);
16539
16540 err = vkBindImageMemory(m_device->device(), image, memory, 0);
16541
Tobin Ehliscde08892015-09-22 10:11:37 -060016542 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130016543 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070016544 image_view_create_info.image = image;
16545 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
16546 image_view_create_info.format = tex_format;
16547 image_view_create_info.subresourceRange.layerCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016548 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
Karl Schultz6addd812016-02-02 17:17:23 -070016549 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016550 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehliscde08892015-09-22 10:11:37 -060016551
16552 VkImageView view;
Jeremy Hayesa1ffc2b2017-03-10 16:05:37 -070016553 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016554 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016555 m_errorMonitor->VerifyFound();
Jeremy Hayesa1ffc2b2017-03-10 16:05:37 -070016556
16557 vkFreeMemory(m_device->device(), memory, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -060016558 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehliscde08892015-09-22 10:11:37 -060016559}
Mike Stroyana3082432015-09-25 13:39:21 -060016560
Mark Youngd339ba32016-05-30 13:28:35 -060016561TEST_F(VkLayerTest, CreateImageViewNoMemoryBoundToImage) {
16562 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -060016563 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -060016564 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -060016565
Tony Barbour1fa09702017-03-16 12:09:08 -060016566 ASSERT_NO_FATAL_FAILURE(Init());
Mark Youngd339ba32016-05-30 13:28:35 -060016567
16568 // Create an image and try to create a view with no memory backing the image
16569 VkImage image;
16570
16571 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
16572 const int32_t tex_width = 32;
16573 const int32_t tex_height = 32;
16574
16575 VkImageCreateInfo image_create_info = {};
16576 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16577 image_create_info.pNext = NULL;
16578 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16579 image_create_info.format = tex_format;
16580 image_create_info.extent.width = tex_width;
16581 image_create_info.extent.height = tex_height;
16582 image_create_info.extent.depth = 1;
16583 image_create_info.mipLevels = 1;
16584 image_create_info.arrayLayers = 1;
16585 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16586 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16587 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
16588 image_create_info.flags = 0;
16589
16590 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
16591 ASSERT_VK_SUCCESS(err);
16592
16593 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130016594 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Mark Youngd339ba32016-05-30 13:28:35 -060016595 image_view_create_info.image = image;
16596 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
16597 image_view_create_info.format = tex_format;
16598 image_view_create_info.subresourceRange.layerCount = 1;
16599 image_view_create_info.subresourceRange.baseMipLevel = 0;
16600 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016601 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -060016602
16603 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016604 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Youngd339ba32016-05-30 13:28:35 -060016605
16606 m_errorMonitor->VerifyFound();
16607 vkDestroyImage(m_device->device(), image, NULL);
16608 // If last error is success, it still created the view, so delete it.
16609 if (err == VK_SUCCESS) {
16610 vkDestroyImageView(m_device->device(), view, NULL);
16611 }
Mark Youngd339ba32016-05-30 13:28:35 -060016612}
16613
Karl Schultz6addd812016-02-02 17:17:23 -070016614TEST_F(VkLayerTest, InvalidImageViewAspect) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016615 TEST_DESCRIPTION("Create an image and try to create a view with an invalid aspectMask");
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070016616 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00741);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016617
Tony Barbour1fa09702017-03-16 12:09:08 -060016618 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060016619
Karl Schultz6addd812016-02-02 17:17:23 -070016620 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060016621 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060016622 image.Init(32, 32, 1, tex_format, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_LINEAR, 0);
Tobin Ehlis1f567a22016-05-25 16:15:18 -060016623 ASSERT_TRUE(image.initialized());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060016624
16625 VkImageViewCreateInfo image_view_create_info = {};
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060016626 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060016627 image_view_create_info.image = image.handle();
Karl Schultz6addd812016-02-02 17:17:23 -070016628 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
16629 image_view_create_info.format = tex_format;
16630 image_view_create_info.subresourceRange.baseMipLevel = 0;
16631 image_view_create_info.subresourceRange.levelCount = 1;
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060016632 image_view_create_info.subresourceRange.layerCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070016633 // Cause an error by setting an invalid image aspect
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016634 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060016635
16636 VkImageView view;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060016637 vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060016638
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016639 m_errorMonitor->VerifyFound();
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060016640}
16641
Mike Weiblena1e13f42017-02-09 21:25:59 -070016642TEST_F(VkLayerTest, ExerciseGetImageSubresourceLayout) {
16643 TEST_DESCRIPTION("Test vkGetImageSubresourceLayout() valid usages");
16644
Tony Barbour1fa09702017-03-16 12:09:08 -060016645 ASSERT_NO_FATAL_FAILURE(Init());
Mike Weiblena1e13f42017-02-09 21:25:59 -070016646 VkSubresourceLayout subres_layout = {};
16647
16648 // VU 00732: image must have been created with tiling equal to VK_IMAGE_TILING_LINEAR
16649 {
16650 const VkImageTiling tiling = VK_IMAGE_TILING_OPTIMAL; // ERROR: violates VU 00732
16651 VkImageObj img(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060016652 img.InitNoLayout(32, 32, 1, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, tiling);
Mike Weiblena1e13f42017-02-09 21:25:59 -070016653 ASSERT_TRUE(img.initialized());
16654
16655 VkImageSubresource subres = {};
16656 subres.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16657 subres.mipLevel = 0;
16658 subres.arrayLayer = 0;
16659
16660 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00732);
16661 vkGetImageSubresourceLayout(m_device->device(), img.image(), &subres, &subres_layout);
16662 m_errorMonitor->VerifyFound();
16663 }
16664
16665 // VU 00733: The aspectMask member of pSubresource must only have a single bit set
16666 {
16667 VkImageObj img(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060016668 img.InitNoLayout(32, 32, 1, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
Mike Weiblena1e13f42017-02-09 21:25:59 -070016669 ASSERT_TRUE(img.initialized());
16670
16671 VkImageSubresource subres = {};
16672 subres.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_METADATA_BIT; // ERROR: triggers VU 00733
16673 subres.mipLevel = 0;
16674 subres.arrayLayer = 0;
16675
16676 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00733);
16677 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00741);
16678 vkGetImageSubresourceLayout(m_device->device(), img.image(), &subres, &subres_layout);
16679 m_errorMonitor->VerifyFound();
16680 }
16681
16682 // 00739 mipLevel must be less than the mipLevels specified in VkImageCreateInfo when the image was created
16683 {
16684 VkImageObj img(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060016685 img.InitNoLayout(32, 32, 1, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
Mike Weiblena1e13f42017-02-09 21:25:59 -070016686 ASSERT_TRUE(img.initialized());
16687
16688 VkImageSubresource subres = {};
16689 subres.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16690 subres.mipLevel = 1; // ERROR: triggers VU 00739
16691 subres.arrayLayer = 0;
16692
16693 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00739);
16694 vkGetImageSubresourceLayout(m_device->device(), img.image(), &subres, &subres_layout);
16695 m_errorMonitor->VerifyFound();
16696 }
16697
16698 // 00740 arrayLayer must be less than the arrayLayers specified in VkImageCreateInfo when the image was created
16699 {
16700 VkImageObj img(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060016701 img.InitNoLayout(32, 32, 1, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
Mike Weiblena1e13f42017-02-09 21:25:59 -070016702 ASSERT_TRUE(img.initialized());
16703
16704 VkImageSubresource subres = {};
16705 subres.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16706 subres.mipLevel = 0;
16707 subres.arrayLayer = 1; // ERROR: triggers VU 00740
16708
16709 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00740);
16710 vkGetImageSubresourceLayout(m_device->device(), img.image(), &subres, &subres_layout);
16711 m_errorMonitor->VerifyFound();
16712 }
16713}
16714
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016715TEST_F(VkLayerTest, CopyImageLayerCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -070016716 VkResult err;
16717 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016718
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070016719 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01198);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016720
Tony Barbour1fa09702017-03-16 12:09:08 -060016721 ASSERT_NO_FATAL_FAILURE(Init());
Mike Stroyana3082432015-09-25 13:39:21 -060016722
16723 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070016724 VkImage srcImage;
16725 VkImage dstImage;
16726 VkDeviceMemory srcMem;
16727 VkDeviceMemory destMem;
16728 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016729
16730 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016731 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16732 image_create_info.pNext = NULL;
16733 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16734 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16735 image_create_info.extent.width = 32;
16736 image_create_info.extent.height = 32;
16737 image_create_info.extent.depth = 1;
16738 image_create_info.mipLevels = 1;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016739 image_create_info.arrayLayers = 4;
Karl Schultz6addd812016-02-02 17:17:23 -070016740 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16741 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16742 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16743 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016744
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016745 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016746 ASSERT_VK_SUCCESS(err);
16747
Mark Lobodzinski867787a2016-10-14 11:49:55 -060016748 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016749 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016750 ASSERT_VK_SUCCESS(err);
16751
16752 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016753 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016754 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16755 memAlloc.pNext = NULL;
16756 memAlloc.allocationSize = 0;
16757 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016758
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060016759 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016760 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016761 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016762 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016763 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016764 ASSERT_VK_SUCCESS(err);
16765
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016766 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016767 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016768 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016769 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016770 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016771 ASSERT_VK_SUCCESS(err);
16772
16773 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16774 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016775 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016776 ASSERT_VK_SUCCESS(err);
16777
Tony Barbour552f6c02016-12-21 14:34:07 -070016778 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060016779 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016780 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016781 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060016782 copyRegion.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016783 copyRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060016784 copyRegion.srcOffset.x = 0;
16785 copyRegion.srcOffset.y = 0;
16786 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016787 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016788 copyRegion.dstSubresource.mipLevel = 0;
16789 copyRegion.dstSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016790 // Introduce failure by forcing the dst layerCount to differ from src
16791 copyRegion.dstSubresource.layerCount = 3;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016792 copyRegion.dstOffset.x = 0;
16793 copyRegion.dstOffset.y = 0;
16794 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016795 copyRegion.extent.width = 1;
16796 copyRegion.extent.height = 1;
16797 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016798 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070016799 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060016800
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016801 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060016802
Chia-I Wuf7458c52015-10-26 21:10:41 +080016803 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016804 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016805 vkFreeMemory(m_device->device(), srcMem, NULL);
16806 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016807}
16808
Tony Barbourd6673642016-05-05 14:46:39 -060016809TEST_F(VkLayerTest, ImageLayerUnsupportedFormat) {
Tony Barbourd6673642016-05-05 14:46:39 -060016810 TEST_DESCRIPTION("Creating images with unsuported formats ");
16811
Tony Barbour1fa09702017-03-16 12:09:08 -060016812 ASSERT_NO_FATAL_FAILURE(Init());
Tony Barbourd6673642016-05-05 14:46:39 -060016813 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourd6673642016-05-05 14:46:39 -060016814
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060016815 // Create image with unsupported format - Expect FORMAT_UNSUPPORTED
Chris Forbesf4d8e332016-11-28 17:51:10 +130016816 VkImageCreateInfo image_create_info = {};
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060016817 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060016818 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16819 image_create_info.format = VK_FORMAT_UNDEFINED;
16820 image_create_info.extent.width = 32;
16821 image_create_info.extent.height = 32;
16822 image_create_info.extent.depth = 1;
16823 image_create_info.mipLevels = 1;
16824 image_create_info.arrayLayers = 1;
16825 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16826 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16827 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060016828
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016829 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16830 "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED");
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060016831
Jeremy Hayes96dcd812017-03-14 14:04:19 -060016832 VkImage image;
16833 vkCreateImage(m_device->handle(), &image_create_info, NULL, &image);
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060016834 m_errorMonitor->VerifyFound();
16835
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060016836 // Look for a format that is COMPLETELY unsupported with this hardware
Jeremy Hayes96dcd812017-03-14 14:04:19 -060016837 VkFormat unsupported = VK_FORMAT_UNDEFINED;
Tony Barbourd6673642016-05-05 14:46:39 -060016838 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
16839 VkFormat format = static_cast<VkFormat>(f);
16840 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016841 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Tony Barbourd6673642016-05-05 14:46:39 -060016842 unsupported = format;
16843 break;
16844 }
16845 }
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060016846
Tony Barbourd6673642016-05-05 14:46:39 -060016847 if (unsupported != VK_FORMAT_UNDEFINED) {
Tony Barbourd6673642016-05-05 14:46:39 -060016848 image_create_info.format = unsupported;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016849 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is an unsupported format");
Tony Barbourd6673642016-05-05 14:46:39 -060016850
Jeremy Hayes96dcd812017-03-14 14:04:19 -060016851 vkCreateImage(m_device->handle(), &image_create_info, NULL, &image);
Tony Barbourd6673642016-05-05 14:46:39 -060016852 m_errorMonitor->VerifyFound();
16853 }
16854}
16855
16856TEST_F(VkLayerTest, ImageLayerViewTests) {
Tony Barbourd6673642016-05-05 14:46:39 -060016857 TEST_DESCRIPTION("Passing bad parameters to CreateImageView");
16858
Tony Barbour1fa09702017-03-16 12:09:08 -060016859 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -060016860 auto depth_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbourf887b162017-03-09 10:06:46 -070016861 if (!depth_format) {
16862 return;
16863 }
Tony Barbourd6673642016-05-05 14:46:39 -060016864
16865 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060016866 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 -060016867 VK_IMAGE_TILING_OPTIMAL, 0);
16868 ASSERT_TRUE(image.initialized());
16869
16870 VkImageView imgView;
16871 VkImageViewCreateInfo imgViewInfo = {};
16872 imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
16873 imgViewInfo.image = image.handle();
16874 imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
16875 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
16876 imgViewInfo.subresourceRange.layerCount = 1;
16877 imgViewInfo.subresourceRange.baseMipLevel = 0;
16878 imgViewInfo.subresourceRange.levelCount = 1;
16879 imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16880
Jeremy Hayes2ffbaa72017-03-14 17:05:50 -060016881 // View can't have baseMipLevel >= image's mipLevels - Expect VIEW_CREATE_ERROR
Tony Barbourd6673642016-05-05 14:46:39 -060016882 imgViewInfo.subresourceRange.baseMipLevel = 1;
Jeremy Hayes2ffbaa72017-03-14 17:05:50 -060016883 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
Tony Barbourd6673642016-05-05 14:46:39 -060016884 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
16885 m_errorMonitor->VerifyFound();
16886 imgViewInfo.subresourceRange.baseMipLevel = 0;
16887
Tony Barbourd6673642016-05-05 14:46:39 -060016888 // View's levelCount can't be 0 - Expect VIEW_CREATE_ERROR
16889 imgViewInfo.subresourceRange.levelCount = 0;
Jeremy Hayes2ffbaa72017-03-14 17:05:50 -060016890 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
Tony Barbourd6673642016-05-05 14:46:39 -060016891 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
16892 m_errorMonitor->VerifyFound();
16893 imgViewInfo.subresourceRange.levelCount = 1;
16894
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060016895 // View's levelCount can't be > image's mipLevels - Expect VIEW_CREATE_ERROR
16896 imgViewInfo.subresourceRange.levelCount = 2;
16897 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
16898 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
16899 m_errorMonitor->VerifyFound();
16900 imgViewInfo.subresourceRange.levelCount = 1;
16901
16902 // View can't have baseArrayLayer >= image's arraySize - Expect VIEW_CREATE_ERROR
16903 imgViewInfo.subresourceRange.baseArrayLayer = 1;
16904 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00769);
16905 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
16906 m_errorMonitor->VerifyFound();
16907 imgViewInfo.subresourceRange.baseArrayLayer = 0;
16908
Jeremy Hayes2ffbaa72017-03-14 17:05:50 -060016909 // View's layerCount can't be 0 - Expect VIEW_CREATE_ERROR
16910 imgViewInfo.subresourceRange.layerCount = 0;
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060016911 m_errorMonitor->SetDesiredFailureMsg(
16912 VK_DEBUG_REPORT_ERROR_BIT_EXT,
16913 "if pCreateInfo->viewType is VK_IMAGE_TYPE_2D, pCreateInfo->subresourceRange.layerCount must be 1");
Tony Barbourd6673642016-05-05 14:46:39 -060016914 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
16915 m_errorMonitor->VerifyFound();
16916 imgViewInfo.subresourceRange.layerCount = 1;
16917
Tony Barbourd6673642016-05-05 14:46:39 -060016918 // Can't use depth format for view into color image - Expect INVALID_FORMAT
Tony Barbourf887b162017-03-09 10:06:46 -070016919 imgViewInfo.format = depth_format;
Jeremy Hayes2ffbaa72017-03-14 17:05:50 -060016920 m_errorMonitor->SetDesiredFailureMsg(
16921 VK_DEBUG_REPORT_ERROR_BIT_EXT,
16922 "Formats MUST be IDENTICAL unless VK_IMAGE_CREATE_MUTABLE_FORMAT BIT was set on image creation.");
Tony Barbourd6673642016-05-05 14:46:39 -060016923 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
16924 m_errorMonitor->VerifyFound();
16925 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
16926
Tony Barbourd6673642016-05-05 14:46:39 -060016927 // Same compatibility class but no MUTABLE_FORMAT bit - Expect
16928 // VIEW_CREATE_ERROR
16929 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UINT;
Jeremy Hayes2ffbaa72017-03-14 17:05:50 -060016930 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02172);
Tony Barbourd6673642016-05-05 14:46:39 -060016931 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
16932 m_errorMonitor->VerifyFound();
16933 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
16934
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060016935 // TODO: Update framework to easily passing mutable flag into ImageObj init
16936 // For now just allowing image for this one test to not have memory bound
Jeremy Hayes5a7cf2e2017-01-06 15:23:27 -070016937 // TODO: The following line is preventing the intended validation from occurring because of the way the error monitor works.
16938 // m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16939 // " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Tony Barbourd6673642016-05-05 14:46:39 -060016940 // Have MUTABLE_FORMAT bit but not in same compatibility class - Expect
16941 // VIEW_CREATE_ERROR
16942 VkImageCreateInfo mutImgInfo = image.create_info();
16943 VkImage mutImage;
16944 mutImgInfo.format = VK_FORMAT_R8_UINT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016945 assert(m_device->format_properties(VK_FORMAT_R8_UINT).optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
Tony Barbourd6673642016-05-05 14:46:39 -060016946 mutImgInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
16947 mutImgInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Jeremy Hayes2ffbaa72017-03-14 17:05:50 -060016948 VkResult ret = vkCreateImage(m_device->handle(), &mutImgInfo, NULL, &mutImage);
Tony Barbourd6673642016-05-05 14:46:39 -060016949 ASSERT_VK_SUCCESS(ret);
Jeremy Hayes2ffbaa72017-03-14 17:05:50 -060016950
16951 VkMemoryRequirements requirements;
16952 vkGetImageMemoryRequirements(m_device->device(), mutImage, &requirements);
16953
16954 VkMemoryAllocateInfo alloc_info{};
16955 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16956 alloc_info.pNext = NULL;
16957 alloc_info.memoryTypeIndex = 0;
16958 alloc_info.allocationSize = requirements.size;
16959 bool pass = m_device->phy().set_memory_type(requirements.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
16960 ASSERT_TRUE(pass);
16961
16962 VkDeviceMemory memory;
16963 ret = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &memory);
16964 ASSERT_VK_SUCCESS(ret);
16965
16966 ret = vkBindImageMemory(m_device->device(), mutImage, memory, 0);
16967 ASSERT_VK_SUCCESS(ret);
16968
Tony Barbourd6673642016-05-05 14:46:39 -060016969 imgViewInfo.image = mutImage;
Jeremy Hayes2ffbaa72017-03-14 17:05:50 -060016970 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02171);
Tony Barbourd6673642016-05-05 14:46:39 -060016971 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
16972 m_errorMonitor->VerifyFound();
16973 imgViewInfo.image = image.handle();
Jeremy Hayes2ffbaa72017-03-14 17:05:50 -060016974
16975 vkFreeMemory(m_device->device(), memory, NULL);
Tony Barbourd6673642016-05-05 14:46:39 -060016976 vkDestroyImage(m_device->handle(), mutImage, NULL);
16977}
16978
Dave Houlton75967fc2017-03-06 17:21:16 -070016979TEST_F(VkLayerTest, CompressedImageMipCopyTests) {
16980 TEST_DESCRIPTION("Image/Buffer copies for higher mip levels");
16981
Tony Barbour1fa09702017-03-16 12:09:08 -060016982 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton75967fc2017-03-06 17:21:16 -070016983
Jamie Madill35127872017-03-15 16:17:46 -040016984 VkPhysicalDeviceFeatures device_features = {};
Dave Houlton75967fc2017-03-06 17:21:16 -070016985 ASSERT_NO_FATAL_FAILURE(GetPhysicalDeviceFeatures(&device_features));
16986 VkFormat compressed_format = VK_FORMAT_UNDEFINED;
16987 if (device_features.textureCompressionBC) {
16988 compressed_format = VK_FORMAT_BC3_SRGB_BLOCK;
16989 } else if (device_features.textureCompressionETC2) {
16990 compressed_format = VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK;
16991 } else if (device_features.textureCompressionASTC_LDR) {
16992 compressed_format = VK_FORMAT_ASTC_4x4_UNORM_BLOCK;
16993 } else {
16994 printf(" No compressed formats supported - CompressedImageMipCopyTests skipped.\n");
16995 return;
16996 }
16997
16998 VkImageCreateInfo ci;
16999 ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17000 ci.pNext = NULL;
17001 ci.flags = 0;
17002 ci.imageType = VK_IMAGE_TYPE_2D;
17003 ci.format = compressed_format;
17004 ci.extent = {32, 32, 1};
17005 ci.mipLevels = 6;
17006 ci.arrayLayers = 1;
17007 ci.samples = VK_SAMPLE_COUNT_1_BIT;
17008 ci.tiling = VK_IMAGE_TILING_OPTIMAL;
17009 ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
17010 ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
17011 ci.queueFamilyIndexCount = 0;
17012 ci.pQueueFamilyIndices = NULL;
17013 ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
17014
17015 VkImageObj image(m_device);
17016 image.init(&ci);
17017 ASSERT_TRUE(image.initialized());
17018
17019 VkImageObj odd_image(m_device);
17020 ci.extent = {31, 32, 1}; // Mips are [31,32] [15,16] [7,8] [3,4], [1,2] [1,1]
17021 odd_image.init(&ci);
17022 ASSERT_TRUE(odd_image.initialized());
17023
17024 // Allocate buffers
17025 VkMemoryPropertyFlags reqs = 0;
17026 vk_testing::Buffer buffer_1024, buffer_64, buffer_16, buffer_8;
17027 buffer_1024.init_as_src_and_dst(*m_device, 1024, reqs);
17028 buffer_64.init_as_src_and_dst(*m_device, 64, reqs);
17029 buffer_16.init_as_src_and_dst(*m_device, 16, reqs);
17030 buffer_8.init_as_src_and_dst(*m_device, 8, reqs);
17031
17032 VkBufferImageCopy region = {};
17033 region.bufferRowLength = 0;
17034 region.bufferImageHeight = 0;
17035 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17036 region.imageSubresource.layerCount = 1;
17037 region.imageOffset = {0, 0, 0};
17038 region.bufferOffset = 0;
17039
17040 // start recording
17041 m_commandBuffer->BeginCommandBuffer();
17042
17043 // Mip level copies that work - 5 levels
17044 m_errorMonitor->ExpectSuccess();
17045
17046 // Mip 0 should fit in 1k buffer - 1k texels @ 1b each
17047 region.imageExtent = {32, 32, 1};
17048 region.imageSubresource.mipLevel = 0;
17049 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_1024.handle(), 1,
17050 &region);
17051 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_1024.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17052 &region);
17053
17054 // Mip 2 should fit in 64b buffer - 64 texels @ 1b each
17055 region.imageExtent = {8, 8, 1};
17056 region.imageSubresource.mipLevel = 2;
17057 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_64.handle(), 1,
17058 &region);
17059 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17060 &region);
17061
17062 // Mip 3 should fit in 16b buffer - 16 texels @ 1b each
17063 region.imageExtent = {4, 4, 1};
17064 region.imageSubresource.mipLevel = 3;
17065 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
17066 &region);
17067 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17068 &region);
17069
17070 // Mip 4&5 should fit in 16b buffer with no complaint - 4 & 1 texels @ 1b each
17071 region.imageExtent = {2, 2, 1};
17072 region.imageSubresource.mipLevel = 4;
17073 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
17074 &region);
17075 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17076 &region);
17077
17078 region.imageExtent = {1, 1, 1};
17079 region.imageSubresource.mipLevel = 5;
17080 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
17081 &region);
17082 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17083 &region);
17084 m_errorMonitor->VerifyNotFound();
17085
17086 // Buffer must accomodate a full compressed block, regardless of texel count
17087 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01246);
17088 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_8.handle(), 1,
17089 &region);
17090 m_errorMonitor->VerifyFound();
17091 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01227);
17092 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_8.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17093 &region);
17094 m_errorMonitor->VerifyFound();
17095
17096 // Copy width < compressed block size, but not the full mip width
17097 region.imageExtent = {1, 2, 1};
17098 region.imageSubresource.mipLevel = 4;
17099 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01275);
17100 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
17101 &region);
17102 m_errorMonitor->VerifyFound();
17103 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01275);
17104 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17105 &region);
17106 m_errorMonitor->VerifyFound();
17107
17108 // Copy height < compressed block size but not the full mip height
17109 region.imageExtent = {2, 1, 1};
17110 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01276);
17111 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
17112 &region);
17113 m_errorMonitor->VerifyFound();
17114 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01276);
17115 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17116 &region);
17117 m_errorMonitor->VerifyFound();
17118
17119 // Offsets must be multiple of compressed block size
17120 region.imageOffset = {1, 1, 0};
17121 region.imageExtent = {1, 1, 1};
17122 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01273);
17123 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
17124 &region);
17125 m_errorMonitor->VerifyFound();
17126 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01273);
17127 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17128 &region);
17129 m_errorMonitor->VerifyFound();
17130
17131 // Offset + extent width = mip width - should succeed
17132 region.imageOffset = {4, 4, 0};
17133 region.imageExtent = {3, 4, 1};
17134 region.imageSubresource.mipLevel = 2;
17135 m_errorMonitor->ExpectSuccess();
17136 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), odd_image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
17137 &region);
17138 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), odd_image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17139 &region);
17140 m_errorMonitor->VerifyNotFound();
17141
17142 // Offset + extent width > mip width, but still within the final compressed block - should succeed
17143 region.imageExtent = {4, 4, 1};
17144 m_errorMonitor->ExpectSuccess();
17145 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), odd_image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
17146 &region);
17147 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), odd_image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17148 &region);
17149 m_errorMonitor->VerifyNotFound();
17150
17151 // Offset + extent width < mip width and not a multiple of block width - should fail
17152 region.imageExtent = {3, 3, 1};
17153 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01276);
17154 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), odd_image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
17155 &region);
17156 m_errorMonitor->VerifyFound();
17157 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01276);
17158 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), odd_image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17159 &region);
17160 m_errorMonitor->VerifyFound();
17161}
17162
Dave Houlton59a20702017-02-02 17:26:23 -070017163TEST_F(VkLayerTest, ImageBufferCopyTests) {
17164 TEST_DESCRIPTION("Image to buffer and buffer to image tests");
17165
Tony Barbour1fa09702017-03-16 12:09:08 -060017166 ASSERT_NO_FATAL_FAILURE(Init());
Tony Barbourf887b162017-03-09 10:06:46 -070017167 VkFormatProperties format_props = m_device->format_properties(VK_FORMAT_D24_UNORM_S8_UINT);
17168 if (!(format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT)) {
17169 printf(" VK_FORMAT_D24_UNORM_S8_UINT not supported. Skipped.\n");
17170 return;
17171 }
Dave Houlton584d51e2017-02-16 12:52:54 -070017172
17173 // Bail if any dimension of transfer granularity is 0.
17174 auto index = m_device->graphics_queue_node_index_;
17175 auto queue_family_properties = m_device->phy().queue_properties();
17176 if ((queue_family_properties[index].minImageTransferGranularity.depth == 0) ||
17177 (queue_family_properties[index].minImageTransferGranularity.width == 0) ||
17178 (queue_family_properties[index].minImageTransferGranularity.height == 0)) {
17179 printf(" Subresource copies are disallowed when xfer granularity (x|y|z) is 0. Skipped.\n");
17180 return;
17181 }
17182
Dave Houlton59a20702017-02-02 17:26:23 -070017183 VkImageObj image_64k(m_device); // 128^2 texels, 64k
17184 VkImageObj image_16k(m_device); // 64^2 texels, 16k
17185 VkImageObj image_16k_depth(m_device); // 64^2 texels, depth, 16k
Dave Houltonf3229d52017-02-21 15:59:08 -070017186 VkImageObj ds_image_4D_1S(m_device); // 256^2 texels, 512kb (256k depth, 64k stencil, 192k pack)
17187 VkImageObj ds_image_3D_1S(m_device); // 256^2 texels, 256kb (192k depth, 64k stencil)
17188 VkImageObj ds_image_2D(m_device); // 256^2 texels, 128k (128k depth)
17189 VkImageObj ds_image_1S(m_device); // 256^2 texels, 64k (64k stencil)
17190
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017191 image_64k.Init(128, 128, 1, VK_FORMAT_R8G8B8A8_UINT,
Dave Houlton59a20702017-02-02 17:26:23 -070017192 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
17193 VK_IMAGE_TILING_OPTIMAL, 0);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017194 image_16k.Init(64, 64, 1, VK_FORMAT_R8G8B8A8_UINT,
Dave Houlton59a20702017-02-02 17:26:23 -070017195 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
17196 VK_IMAGE_TILING_OPTIMAL, 0);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017197 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 -070017198 VK_IMAGE_TILING_OPTIMAL, 0);
Dave Houlton59a20702017-02-02 17:26:23 -070017199 ASSERT_TRUE(image_64k.initialized());
17200 ASSERT_TRUE(image_16k.initialized());
17201 ASSERT_TRUE(image_16k_depth.initialized());
Dave Houlton59a20702017-02-02 17:26:23 -070017202
Dave Houltonf3229d52017-02-21 15:59:08 -070017203 // Verify all needed Depth/Stencil formats are supported
17204 bool missing_ds_support = false;
17205 VkFormatProperties props = {0, 0, 0};
17206 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D32_SFLOAT_S8_UINT, &props);
17207 missing_ds_support |= (props.bufferFeatures == 0 && props.linearTilingFeatures == 0 && props.optimalTilingFeatures == 0);
17208 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D24_UNORM_S8_UINT, &props);
17209 missing_ds_support |= (props.bufferFeatures == 0 && props.linearTilingFeatures == 0 && props.optimalTilingFeatures == 0);
17210 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D16_UNORM, &props);
17211 missing_ds_support |= (props.bufferFeatures == 0 && props.linearTilingFeatures == 0 && props.optimalTilingFeatures == 0);
17212 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_S8_UINT, &props);
17213 missing_ds_support |= (props.bufferFeatures == 0 && props.linearTilingFeatures == 0 && props.optimalTilingFeatures == 0);
17214
17215 if (!missing_ds_support) {
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017216 ds_image_4D_1S.Init(
17217 256, 256, 1, VK_FORMAT_D32_SFLOAT_S8_UINT,
Dave Houltonf3229d52017-02-21 15:59:08 -070017218 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
17219 VK_IMAGE_TILING_OPTIMAL, 0);
17220 ASSERT_TRUE(ds_image_4D_1S.initialized());
17221
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017222 ds_image_3D_1S.Init(
17223 256, 256, 1, VK_FORMAT_D24_UNORM_S8_UINT,
Dave Houltonf3229d52017-02-21 15:59:08 -070017224 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
17225 VK_IMAGE_TILING_OPTIMAL, 0);
17226 ASSERT_TRUE(ds_image_3D_1S.initialized());
17227
Dave Houlton11dcd5e2017-04-25 16:00:10 -060017228 ds_image_2D.Init(
17229 256, 256, 1, VK_FORMAT_D16_UNORM,
17230 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
17231 VK_IMAGE_TILING_OPTIMAL, 0);
Dave Houltonf3229d52017-02-21 15:59:08 -070017232 ASSERT_TRUE(ds_image_2D.initialized());
17233
Dave Houlton11dcd5e2017-04-25 16:00:10 -060017234 ds_image_1S.Init(
17235 256, 256, 1, VK_FORMAT_S8_UINT,
17236 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
17237 VK_IMAGE_TILING_OPTIMAL, 0);
Dave Houltonf3229d52017-02-21 15:59:08 -070017238 ASSERT_TRUE(ds_image_1S.initialized());
17239 }
17240
17241 // Allocate buffers
17242 vk_testing::Buffer buffer_256k, buffer_128k, buffer_64k, buffer_16k;
Dave Houlton59a20702017-02-02 17:26:23 -070017243 VkMemoryPropertyFlags reqs = 0;
Dave Houltonf3229d52017-02-21 15:59:08 -070017244 buffer_256k.init_as_src_and_dst(*m_device, 262144, reqs); // 256k
17245 buffer_128k.init_as_src_and_dst(*m_device, 131072, reqs); // 128k
17246 buffer_64k.init_as_src_and_dst(*m_device, 65536, reqs); // 64k
17247 buffer_16k.init_as_src_and_dst(*m_device, 16384, reqs); // 16k
Dave Houlton59a20702017-02-02 17:26:23 -070017248
17249 VkBufferImageCopy region = {};
17250 region.bufferRowLength = 0;
17251 region.bufferImageHeight = 0;
17252 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17253 region.imageSubresource.layerCount = 1;
17254 region.imageOffset = {0, 0, 0};
17255 region.imageExtent = {64, 64, 1};
17256 region.bufferOffset = 0;
17257
17258 // attempt copies before putting command buffer in recording state
17259 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01240);
17260 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64k.handle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17261 &region);
17262 m_errorMonitor->VerifyFound();
17263
17264 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01258);
17265 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_64k.handle(), 1,
17266 &region);
17267 m_errorMonitor->VerifyFound();
17268
17269 // start recording
17270 m_commandBuffer->BeginCommandBuffer();
17271
17272 // successful copies
17273 m_errorMonitor->ExpectSuccess();
17274 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
17275 &region);
17276 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16k.handle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17277 &region);
17278 region.imageOffset.x = 16; // 16k copy, offset requires larger image
17279 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
17280 &region);
17281 region.imageExtent.height = 78; // > 16k copy requires larger buffer & image
17282 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64k.handle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17283 &region);
17284 region.imageOffset.x = 0;
17285 region.imageExtent.height = 64;
17286 region.bufferOffset = 256; // 16k copy with buffer offset, requires larger buffer
17287 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_64k.handle(), 1,
17288 &region);
17289 m_errorMonitor->VerifyNotFound();
17290
Dave Houlton9dae7ec2017-03-01 16:23:25 -070017291 // image/buffer too small (extent too large) on copy to image
Dave Houlton59a20702017-02-02 17:26:23 -070017292 region.imageExtent = {65, 64, 1};
17293 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01227); // buffer too small
17294 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16k.handle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17295 &region);
17296 m_errorMonitor->VerifyFound();
17297
17298 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01228); // image too small
17299 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64k.handle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17300 &region);
17301 m_errorMonitor->VerifyFound();
17302
17303 // image/buffer too small (offset) on copy to image
17304 region.imageExtent = {64, 64, 1};
17305 region.imageOffset = {0, 4, 0};
17306 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01227); // buffer too small
17307 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16k.handle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17308 &region);
17309 m_errorMonitor->VerifyFound();
17310
17311 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01228); // image too small
17312 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64k.handle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17313 &region);
17314 m_errorMonitor->VerifyFound();
17315
17316 // image/buffer too small on copy to buffer
17317 region.imageExtent = {64, 64, 1};
17318 region.imageOffset = {0, 0, 0};
Mark Lobodzinski80871462017-02-16 10:37:27 -070017319 region.bufferOffset = 4;
Dave Houlton59a20702017-02-02 17:26:23 -070017320 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01246); // buffer too small
17321 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
17322 &region);
17323 m_errorMonitor->VerifyFound();
17324
17325 region.imageExtent = {64, 65, 1};
17326 region.bufferOffset = 0;
17327 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01245); // image too small
17328 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_64k.handle(), 1,
17329 &region);
17330 m_errorMonitor->VerifyFound();
17331
17332 // buffer size ok but rowlength causes loose packing
17333 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01246);
17334 region.imageExtent = {64, 64, 1};
17335 region.bufferRowLength = 68;
17336 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
17337 &region);
17338 m_errorMonitor->VerifyFound();
17339
Dave Houlton9dae7ec2017-03-01 16:23:25 -070017340 // An extent with zero area should produce a warning, but no error
17341 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT | VK_DEBUG_REPORT_ERROR_BIT_EXT, "} has zero area");
17342 region.imageExtent.width = 0;
17343 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
17344 &region);
17345 m_errorMonitor->VerifyFound();
17346
Dave Houlton59a20702017-02-02 17:26:23 -070017347 // aspect bits
17348 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01280); // more than 1 aspect bit set
17349 region.imageExtent = {64, 64, 1};
17350 region.bufferRowLength = 0;
17351 region.bufferImageHeight = 0;
17352 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
17353 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_depth.handle(), VK_IMAGE_LAYOUT_GENERAL,
17354 buffer_16k.handle(), 1, &region);
17355 m_errorMonitor->VerifyFound();
17356
17357 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01279); // mis-matched aspect
17358 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
17359 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
17360 &region);
17361 m_errorMonitor->VerifyFound();
17362
17363 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01279); // different mis-matched aspect
17364 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17365 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_depth.handle(), VK_IMAGE_LAYOUT_GENERAL,
17366 buffer_16k.handle(), 1, &region);
17367 m_errorMonitor->VerifyFound();
17368
Dave Houltonf3229d52017-02-21 15:59:08 -070017369 // Test Depth/Stencil copies
17370 if (missing_ds_support) {
17371 printf(" Depth / Stencil formats unsupported - skipping D/S tests.\n");
17372 } else {
17373 VkBufferImageCopy ds_region = {};
17374 ds_region.bufferOffset = 0;
17375 ds_region.bufferRowLength = 0;
17376 ds_region.bufferImageHeight = 0;
17377 ds_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
17378 ds_region.imageSubresource.mipLevel = 0;
17379 ds_region.imageSubresource.baseArrayLayer = 0;
17380 ds_region.imageSubresource.layerCount = 1;
17381 ds_region.imageOffset = {0, 0, 0};
17382 ds_region.imageExtent = {256, 256, 1};
17383
17384 // Depth copies that should succeed
17385 m_errorMonitor->ExpectSuccess(); // Extract 4b depth per texel, pack into 256k buffer
17386 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_4D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
17387 buffer_256k.handle(), 1, &ds_region);
17388 m_errorMonitor->VerifyNotFound();
17389
17390 m_errorMonitor->ExpectSuccess(); // Extract 3b depth per texel, pack (loose) into 256k buffer
17391 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_3D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
17392 buffer_256k.handle(), 1, &ds_region);
17393 m_errorMonitor->VerifyNotFound();
17394
17395 m_errorMonitor->ExpectSuccess(); // Copy 2b depth per texel, into 128k buffer
17396 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_2D.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
17397 buffer_128k.handle(), 1, &ds_region);
17398 m_errorMonitor->VerifyNotFound();
17399
17400 // Depth copies that should fail
17401 ds_region.bufferOffset = 4;
17402 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17403 VALIDATION_ERROR_01246); // Extract 4b depth per texel, pack into 256k buffer
17404 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_4D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
17405 buffer_256k.handle(), 1, &ds_region);
17406 m_errorMonitor->VerifyFound();
17407
17408 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17409 VALIDATION_ERROR_01246); // Extract 3b depth per texel, pack (loose) into 256k buffer
17410 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_3D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
17411 buffer_256k.handle(), 1, &ds_region);
17412 m_errorMonitor->VerifyFound();
17413
17414 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17415 VALIDATION_ERROR_01246); // Copy 2b depth per texel, into 128k buffer
17416 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_2D.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
17417 buffer_128k.handle(), 1, &ds_region);
17418 m_errorMonitor->VerifyFound();
17419
17420 // Stencil copies that should succeed
17421 ds_region.bufferOffset = 0;
17422 ds_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT;
17423 m_errorMonitor->ExpectSuccess(); // Extract 1b stencil per texel, pack into 64k buffer
17424 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_4D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
17425 buffer_64k.handle(), 1, &ds_region);
17426 m_errorMonitor->VerifyNotFound();
17427
17428 m_errorMonitor->ExpectSuccess(); // Extract 1b stencil per texel, pack into 64k buffer
17429 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_3D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
17430 buffer_64k.handle(), 1, &ds_region);
17431 m_errorMonitor->VerifyNotFound();
17432
17433 m_errorMonitor->ExpectSuccess(); // Copy 1b depth per texel, into 64k buffer
17434 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
17435 buffer_64k.handle(), 1, &ds_region);
17436 m_errorMonitor->VerifyNotFound();
17437
17438 // Stencil copies that should fail
17439 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17440 VALIDATION_ERROR_01246); // Extract 1b stencil per texel, pack into 64k buffer
17441 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_4D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
17442 buffer_16k.handle(), 1, &ds_region);
17443 m_errorMonitor->VerifyFound();
17444
17445 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17446 VALIDATION_ERROR_01246); // Extract 1b stencil per texel, pack into 64k buffer
17447 ds_region.bufferRowLength = 260;
17448 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_3D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
17449 buffer_64k.handle(), 1, &ds_region);
17450 m_errorMonitor->VerifyFound();
17451
17452 ds_region.bufferRowLength = 0;
17453 ds_region.bufferOffset = 4;
17454 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17455 VALIDATION_ERROR_01246); // Copy 1b depth per texel, into 64k buffer
17456 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
17457 buffer_64k.handle(), 1, &ds_region);
17458 m_errorMonitor->VerifyFound();
17459 }
17460
Dave Houlton584d51e2017-02-16 12:52:54 -070017461 // Test compressed formats, if supported
Jamie Madill35127872017-03-15 16:17:46 -040017462 VkPhysicalDeviceFeatures device_features = {};
Dave Houlton584d51e2017-02-16 12:52:54 -070017463 ASSERT_NO_FATAL_FAILURE(GetPhysicalDeviceFeatures(&device_features));
Dave Houltonf3229d52017-02-21 15:59:08 -070017464 if (!(device_features.textureCompressionBC || device_features.textureCompressionETC2 ||
17465 device_features.textureCompressionASTC_LDR)) {
17466 printf(" No compressed formats supported - block compression tests skipped.\n");
17467 } else {
Dave Houlton67e9b532017-03-02 17:00:10 -070017468 VkImageObj image_16k_4x4comp(m_device); // 128^2 texels as 32^2 compressed (4x4) blocks, 16k
17469 VkImageObj image_NPOT_4x4comp(m_device); // 130^2 texels as 33^2 compressed (4x4) blocks
Dave Houlton584d51e2017-02-16 12:52:54 -070017470 if (device_features.textureCompressionBC) {
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017471 image_16k_4x4comp.Init(128, 128, 1, VK_FORMAT_BC3_SRGB_BLOCK, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_OPTIMAL,
17472 0);
17473 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 -070017474 0);
Dave Houlton584d51e2017-02-16 12:52:54 -070017475 } else if (device_features.textureCompressionETC2) {
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017476 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 -070017477 VK_IMAGE_TILING_OPTIMAL, 0);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017478 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 -070017479 VK_IMAGE_TILING_OPTIMAL, 0);
Dave Houlton584d51e2017-02-16 12:52:54 -070017480 } else {
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017481 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 -070017482 VK_IMAGE_TILING_OPTIMAL, 0);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017483 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 -070017484 VK_IMAGE_TILING_OPTIMAL, 0);
Dave Houlton584d51e2017-02-16 12:52:54 -070017485 }
17486 ASSERT_TRUE(image_16k_4x4comp.initialized());
Dave Houlton59a20702017-02-02 17:26:23 -070017487
Dave Houlton584d51e2017-02-16 12:52:54 -070017488 // Just fits
17489 m_errorMonitor->ExpectSuccess();
17490 region.imageExtent = {128, 128, 1};
17491 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
17492 buffer_16k.handle(), 1, &region);
17493 m_errorMonitor->VerifyNotFound();
Dave Houlton59a20702017-02-02 17:26:23 -070017494
Dave Houlton584d51e2017-02-16 12:52:54 -070017495 // with offset, too big for buffer
17496 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01246);
17497 region.bufferOffset = 16;
17498 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
17499 buffer_16k.handle(), 1, &region);
17500 m_errorMonitor->VerifyFound();
Dave Houlton67e9b532017-03-02 17:00:10 -070017501 region.bufferOffset = 0;
Dave Houlton59a20702017-02-02 17:26:23 -070017502
Dave Houlton67e9b532017-03-02 17:00:10 -070017503 // extents that are not a multiple of compressed block size
17504 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01275);
17505 region.imageExtent.width = 66;
17506 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_NPOT_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
17507 buffer_16k.handle(), 1, &region);
17508 m_errorMonitor->VerifyFound();
17509 region.imageExtent.width = 128;
17510
17511 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01276);
Dave Houlton9dae7ec2017-03-01 16:23:25 -070017512 region.imageExtent.height = 2;
Dave Houlton67e9b532017-03-02 17:00:10 -070017513 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_NPOT_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
17514 buffer_16k.handle(), 1, &region);
17515 m_errorMonitor->VerifyFound();
17516 region.imageExtent.height = 128;
17517
17518 // TODO: All available compressed formats are 2D, with block depth of 1. Unable to provoke VU_01277.
17519
17520 // non-multiple extents are allowed if at the far edge of a non-block-multiple image - these should pass
17521 m_errorMonitor->ExpectSuccess();
17522 region.imageExtent.width = 66;
17523 region.imageOffset.x = 64;
17524 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_NPOT_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
17525 buffer_16k.handle(), 1, &region);
17526 region.imageExtent.width = 16;
17527 region.imageOffset.x = 0;
17528 region.imageExtent.height = 2;
17529 region.imageOffset.y = 128;
17530 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_NPOT_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
Dave Houlton9dae7ec2017-03-01 16:23:25 -070017531 buffer_16k.handle(), 1, &region);
17532 m_errorMonitor->VerifyNotFound();
Dave Houlton67e9b532017-03-02 17:00:10 -070017533 region.imageOffset = {0, 0, 0};
Dave Houlton9dae7ec2017-03-01 16:23:25 -070017534
Dave Houlton584d51e2017-02-16 12:52:54 -070017535 // buffer offset must be a multiple of texel block size (16)
17536 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01274);
17537 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01263);
17538 region.imageExtent = {64, 64, 1};
17539 region.bufferOffset = 24;
17540 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
17541 buffer_16k.handle(), 1, &region);
17542 m_errorMonitor->VerifyFound();
Dave Houlton59a20702017-02-02 17:26:23 -070017543
Dave Houlton584d51e2017-02-16 12:52:54 -070017544 // rowlength not a multiple of block width (4)
17545 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01271);
17546 region.bufferOffset = 0;
17547 region.bufferRowLength = 130;
17548 region.bufferImageHeight = 0;
17549 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
17550 buffer_64k.handle(), 1, &region);
17551 m_errorMonitor->VerifyFound();
Dave Houlton59a20702017-02-02 17:26:23 -070017552
Dave Houlton584d51e2017-02-16 12:52:54 -070017553 // imageheight not a multiple of block height (4)
17554 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01272);
17555 region.bufferRowLength = 0;
17556 region.bufferImageHeight = 130;
17557 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
17558 buffer_64k.handle(), 1, &region);
17559 m_errorMonitor->VerifyFound();
Dave Houlton584d51e2017-02-16 12:52:54 -070017560 }
Dave Houlton59a20702017-02-02 17:26:23 -070017561}
17562
Tony Barbourd6673642016-05-05 14:46:39 -060017563TEST_F(VkLayerTest, MiscImageLayerTests) {
Mark Lobodzinskie6911292017-02-15 14:38:51 -070017564 TEST_DESCRIPTION("Image-related tests that don't belong elsewhare");
Tony Barbourd6673642016-05-05 14:46:39 -060017565
Tony Barbour1fa09702017-03-16 12:09:08 -060017566 ASSERT_NO_FATAL_FAILURE(Init());
Tony Barbourd6673642016-05-05 14:46:39 -060017567
Rene Lindsay135204f2016-12-22 17:11:09 -070017568 // TODO: Ideally we should check if a format is supported, before using it.
Tony Barbourd6673642016-05-05 14:46:39 -060017569 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017570 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 -070017571 VK_IMAGE_TILING_OPTIMAL, 0); // 64bpp
Tony Barbourd6673642016-05-05 14:46:39 -060017572 ASSERT_TRUE(image.initialized());
Tony Barbourd6673642016-05-05 14:46:39 -060017573 vk_testing::Buffer buffer;
17574 VkMemoryPropertyFlags reqs = 0;
Rene Lindsay135204f2016-12-22 17:11:09 -070017575 buffer.init_as_src(*m_device, 128 * 128 * 8, reqs);
Tony Barbourd6673642016-05-05 14:46:39 -060017576 VkBufferImageCopy region = {};
17577 region.bufferRowLength = 128;
17578 region.bufferImageHeight = 128;
17579 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17580 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
Mark Lobodzinski3702e932016-11-22 11:40:48 -070017581 region.imageSubresource.layerCount = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060017582 region.imageExtent.height = 4;
17583 region.imageExtent.width = 4;
17584 region.imageExtent.depth = 1;
Rene Lindsay135204f2016-12-22 17:11:09 -070017585
17586 VkImageObj image2(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017587 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 -070017588 VK_IMAGE_TILING_OPTIMAL, 0); // 16bpp
Rene Lindsay135204f2016-12-22 17:11:09 -070017589 ASSERT_TRUE(image2.initialized());
17590 vk_testing::Buffer buffer2;
17591 VkMemoryPropertyFlags reqs2 = 0;
17592 buffer2.init_as_src(*m_device, 128 * 128 * 2, reqs2);
17593 VkBufferImageCopy region2 = {};
17594 region2.bufferRowLength = 128;
17595 region2.bufferImageHeight = 128;
17596 region2.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17597 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
17598 region2.imageSubresource.layerCount = 1;
17599 region2.imageExtent.height = 4;
17600 region2.imageExtent.width = 4;
17601 region2.imageExtent.depth = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060017602 m_commandBuffer->BeginCommandBuffer();
Tony Barbourd6673642016-05-05 14:46:39 -060017603
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070017604 // Image must have offset.z of 0 and extent.depth of 1
17605 // Introduce failure by setting imageExtent.depth to 0
17606 region.imageExtent.depth = 0;
Dave Houlton59a20702017-02-02 17:26:23 -070017607 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01747);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070017608 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017609 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070017610 m_errorMonitor->VerifyFound();
17611
17612 region.imageExtent.depth = 1;
17613
17614 // Image must have offset.z of 0 and extent.depth of 1
17615 // Introduce failure by setting imageOffset.z to 4
Dave Houlton9dae7ec2017-03-01 16:23:25 -070017616 // Note: Also (unavoidably) triggers 'region exceeds image' #1228
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070017617 region.imageOffset.z = 4;
Dave Houlton59a20702017-02-02 17:26:23 -070017618 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01747);
Dave Houlton9dae7ec2017-03-01 16:23:25 -070017619 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01228);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070017620 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017621 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070017622 m_errorMonitor->VerifyFound();
17623
17624 region.imageOffset.z = 0;
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060017625 // BufferOffset must be a multiple of the calling command's VkImage parameter's texel size
17626 // Introduce failure by setting bufferOffset to 1 and 1/2 texels
Rene Lindsay135204f2016-12-22 17:11:09 -070017627 region.bufferOffset = 4;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070017628 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01263);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017629 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
17630 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060017631 m_errorMonitor->VerifyFound();
17632
17633 // BufferOffset must be a multiple of 4
17634 // Introduce failure by setting bufferOffset to a value not divisible by 4
Rene Lindsay135204f2016-12-22 17:11:09 -070017635 region2.bufferOffset = 6;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070017636 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01264);
Rene Lindsay135204f2016-12-22 17:11:09 -070017637 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer2.handle(), image2.handle(),
17638 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region2);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060017639 m_errorMonitor->VerifyFound();
17640
17641 // BufferRowLength must be 0, or greater than or equal to the width member of imageExtent
17642 region.bufferOffset = 0;
17643 region.imageExtent.height = 128;
17644 region.imageExtent.width = 128;
17645 // Introduce failure by setting bufferRowLength > 0 but less than width
17646 region.bufferRowLength = 64;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070017647 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01265);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017648 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
17649 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060017650 m_errorMonitor->VerifyFound();
17651
17652 // BufferImageHeight must be 0, or greater than or equal to the height member of imageExtent
17653 region.bufferRowLength = 128;
17654 // Introduce failure by setting bufferRowHeight > 0 but less than height
17655 region.bufferImageHeight = 64;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070017656 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01266);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017657 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
17658 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060017659 m_errorMonitor->VerifyFound();
17660
17661 region.bufferImageHeight = 128;
Tony Barbourd6673642016-05-05 14:46:39 -060017662 VkImageObj intImage1(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017663 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 -070017664 VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbourd6673642016-05-05 14:46:39 -060017665 VkImageObj intImage2(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017666 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 -070017667 VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbourd6673642016-05-05 14:46:39 -060017668 VkImageBlit blitRegion = {};
17669 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17670 blitRegion.srcSubresource.baseArrayLayer = 0;
17671 blitRegion.srcSubresource.layerCount = 1;
17672 blitRegion.srcSubresource.mipLevel = 0;
17673 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17674 blitRegion.dstSubresource.baseArrayLayer = 0;
17675 blitRegion.dstSubresource.layerCount = 1;
17676 blitRegion.dstSubresource.mipLevel = 0;
17677
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060017678 // Look for NULL-blit warning
Jeremy Hayesf8e749f2017-03-15 09:40:27 -060017679 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
17680 "vkCmdBlitImage: pRegions[0].srcOffsets specify a zero-volume area.");
17681 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
17682 "vkCmdBlitImage: pRegions[0].dstOffsets specify a zero-volume area.");
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017683 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.Layout(), intImage2.handle(),
17684 intImage2.Layout(), 1, &blitRegion, VK_FILTER_LINEAR);
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060017685 m_errorMonitor->VerifyFound();
17686
Mark Lobodzinskic386ecb2017-02-02 16:12:37 -070017687 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00769);
Tony Barbourd6673642016-05-05 14:46:39 -060017688 VkImageMemoryBarrier img_barrier;
17689 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
17690 img_barrier.pNext = NULL;
17691 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
17692 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
17693 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
17694 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
17695 img_barrier.image = image.handle();
17696 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
17697 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
17698 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17699 img_barrier.subresourceRange.baseArrayLayer = 0;
17700 img_barrier.subresourceRange.baseMipLevel = 0;
Tony Barbourd6673642016-05-05 14:46:39 -060017701 img_barrier.subresourceRange.layerCount = 0;
17702 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017703 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
17704 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbourd6673642016-05-05 14:46:39 -060017705 m_errorMonitor->VerifyFound();
17706 img_barrier.subresourceRange.layerCount = 1;
17707}
17708
17709TEST_F(VkLayerTest, ImageFormatLimits) {
Tony Barbourd6673642016-05-05 14:46:39 -060017710 TEST_DESCRIPTION("Exceed the limits of image format ");
17711
Tony Barbour1fa09702017-03-16 12:09:08 -060017712 ASSERT_NO_FATAL_FAILURE(Init());
Jeremy Hayesbb63cc12017-03-20 15:33:01 -060017713
17714 VkFormat const format = VK_FORMAT_B8G8R8A8_UNORM;
17715 {
17716 VkFormatProperties properties;
17717 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), format, &properties);
17718 if (properties.linearTilingFeatures == 0) {
17719 printf(" Image format not supported; skipped.\n");
17720 return;
17721 }
17722 }
17723
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017724 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Tony Barbourd6673642016-05-05 14:46:39 -060017725 VkImageCreateInfo image_create_info = {};
17726 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17727 image_create_info.pNext = NULL;
17728 image_create_info.imageType = VK_IMAGE_TYPE_2D;
Jeremy Hayesbb63cc12017-03-20 15:33:01 -060017729 image_create_info.format = format;
Tony Barbourd6673642016-05-05 14:46:39 -060017730 image_create_info.extent.width = 32;
17731 image_create_info.extent.height = 32;
17732 image_create_info.extent.depth = 1;
17733 image_create_info.mipLevels = 1;
17734 image_create_info.arrayLayers = 1;
17735 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
17736 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
17737 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
17738 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
17739 image_create_info.flags = 0;
17740
17741 VkImage nullImg;
17742 VkImageFormatProperties imgFmtProps;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017743 vkGetPhysicalDeviceImageFormatProperties(gpu(), image_create_info.format, image_create_info.imageType, image_create_info.tiling,
17744 image_create_info.usage, image_create_info.flags, &imgFmtProps);
Rene Lindsayef5bc012017-01-06 15:38:00 -070017745 image_create_info.extent.width = imgFmtProps.maxExtent.width + 1;
Tony Barbourd6673642016-05-05 14:46:39 -060017746 // Expect INVALID_FORMAT_LIMITS_VIOLATION
17747 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
17748 m_errorMonitor->VerifyFound();
Rene Lindsayef5bc012017-01-06 15:38:00 -070017749 image_create_info.extent.width = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060017750
Tony Barbour0907e362017-03-09 15:05:30 -070017751 uint32_t maxDim =
17752 std::max(std::max(image_create_info.extent.width, image_create_info.extent.height), image_create_info.extent.depth);
17753 // If max mip levels exceeds image extents, skip the max mip levels test
17754 if ((imgFmtProps.maxMipLevels + 1) <= (floor(log2(maxDim)) + 1)) {
17755 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
17756 image_create_info.mipLevels = imgFmtProps.maxMipLevels + 1;
17757 // Expect INVALID_FORMAT_LIMITS_VIOLATION
17758 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
17759 m_errorMonitor->VerifyFound();
17760 image_create_info.mipLevels = 1;
17761 }
Tony Barbourd6673642016-05-05 14:46:39 -060017762
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017763 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060017764 image_create_info.arrayLayers = imgFmtProps.maxArrayLayers + 1;
17765 // Expect INVALID_FORMAT_LIMITS_VIOLATION
17766 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
17767 m_errorMonitor->VerifyFound();
17768 image_create_info.arrayLayers = 1;
17769
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017770 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is not supported by format");
Tony Barbourd6673642016-05-05 14:46:39 -060017771 int samples = imgFmtProps.sampleCounts >> 1;
17772 image_create_info.samples = (VkSampleCountFlagBits)samples;
17773 // Expect INVALID_FORMAT_LIMITS_VIOLATION
17774 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
17775 m_errorMonitor->VerifyFound();
17776 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
17777
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017778 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17779 "pCreateInfo->initialLayout, must be "
17780 "VK_IMAGE_LAYOUT_UNDEFINED or "
17781 "VK_IMAGE_LAYOUT_PREINITIALIZED");
Tony Barbourd6673642016-05-05 14:46:39 -060017782 image_create_info.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
17783 // Expect INVALID_LAYOUT
17784 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
17785 m_errorMonitor->VerifyFound();
17786 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
17787}
17788
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017789TEST_F(VkLayerTest, CopyImageSrcSizeExceeded) {
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017790 // Image copy with source region specified greater than src image size
Tony Barbour1fa09702017-03-16 12:09:08 -060017791 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017792
Dave Houltonfc1a4052017-04-27 14:32:45 -060017793 // Create images with full mip chain
17794 VkImageCreateInfo ci;
17795 ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17796 ci.pNext = NULL;
17797 ci.flags = 0;
17798 ci.imageType = VK_IMAGE_TYPE_3D;
17799 ci.format = VK_FORMAT_R8G8B8A8_UNORM;
17800 ci.extent = {32, 32, 8};
17801 ci.mipLevels = 6;
17802 ci.arrayLayers = 1;
17803 ci.samples = VK_SAMPLE_COUNT_1_BIT;
17804 ci.tiling = VK_IMAGE_TILING_OPTIMAL;
17805 ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
17806 ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
17807 ci.queueFamilyIndexCount = 0;
17808 ci.pQueueFamilyIndices = NULL;
17809 ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
17810
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017811 VkImageObj src_image(m_device);
Dave Houltonfc1a4052017-04-27 14:32:45 -060017812 src_image.init(&ci);
17813 ASSERT_TRUE(src_image.initialized());
17814
17815 // Dest image with one more mip level
17816 ci.extent = {64, 64, 16};
17817 ci.mipLevels = 7;
17818 ci.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017819 VkImageObj dst_image(m_device);
Dave Houltonfc1a4052017-04-27 14:32:45 -060017820 dst_image.init(&ci);
17821 ASSERT_TRUE(dst_image.initialized());
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017822
Tony Barbour552f6c02016-12-21 14:34:07 -070017823 m_commandBuffer->BeginCommandBuffer();
Dave Houltonfc1a4052017-04-27 14:32:45 -060017824
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017825 VkImageCopy copy_region;
Dave Houltonfc1a4052017-04-27 14:32:45 -060017826 copy_region.extent = {32, 32, 8};
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017827 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017828 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Dave Houltoncee81d02017-05-02 11:00:10 -060017829 copy_region.srcSubresource.mipLevel = 0;
17830 copy_region.dstSubresource.mipLevel = 0;
Dave Houltonfc1a4052017-04-27 14:32:45 -060017831 copy_region.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017832 copy_region.dstSubresource.baseArrayLayer = 0;
Dave Houltonfc1a4052017-04-27 14:32:45 -060017833 copy_region.srcSubresource.layerCount = 1;
17834 copy_region.dstSubresource.layerCount = 1;
17835 copy_region.srcOffset = {0, 0, 0};
17836 copy_region.dstOffset = {0, 0, 0};
17837
17838 m_errorMonitor->ExpectSuccess();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017839 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
17840 &copy_region);
Dave Houltonfc1a4052017-04-27 14:32:45 -060017841 m_errorMonitor->VerifyNotFound();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017842
Dave Houltonfc1a4052017-04-27 14:32:45 -060017843 // Source exceeded in x-dim, VU 01202
17844 copy_region.srcOffset.x = 4;
17845 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01175); // General "contained within" VU
17846 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01202);
17847 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
17848 &copy_region);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017849 m_errorMonitor->VerifyFound();
Dave Houltonfc1a4052017-04-27 14:32:45 -060017850
17851 // Source exceeded in y-dim, VU 01203
17852 copy_region.srcOffset.x = 0;
17853 copy_region.extent.height = 48;
17854 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01175);
17855 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01203);
17856 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
17857 &copy_region);
17858 m_errorMonitor->VerifyFound();
17859
17860 // Source exceeded in z-dim, VU 01204
17861 copy_region.extent = {4, 4, 4};
17862 copy_region.srcSubresource.mipLevel = 2;
17863 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01175);
17864 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01204);
17865 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
17866 &copy_region);
17867 m_errorMonitor->VerifyFound();
17868
17869 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017870}
17871
17872TEST_F(VkLayerTest, CopyImageDstSizeExceeded) {
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017873 // Image copy with dest region specified greater than dest image size
Tony Barbour1fa09702017-03-16 12:09:08 -060017874 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017875
Dave Houltonfc1a4052017-04-27 14:32:45 -060017876 // Create images with full mip chain
17877 VkImageCreateInfo ci;
17878 ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17879 ci.pNext = NULL;
17880 ci.flags = 0;
17881 ci.imageType = VK_IMAGE_TYPE_3D;
17882 ci.format = VK_FORMAT_R8G8B8A8_UNORM;
17883 ci.extent = {32, 32, 8};
17884 ci.mipLevels = 6;
17885 ci.arrayLayers = 1;
17886 ci.samples = VK_SAMPLE_COUNT_1_BIT;
17887 ci.tiling = VK_IMAGE_TILING_OPTIMAL;
17888 ci.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
17889 ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
17890 ci.queueFamilyIndexCount = 0;
17891 ci.pQueueFamilyIndices = NULL;
17892 ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
17893
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017894 VkImageObj dst_image(m_device);
Dave Houltonfc1a4052017-04-27 14:32:45 -060017895 dst_image.init(&ci);
17896 ASSERT_TRUE(dst_image.initialized());
17897
17898 // Src image with one more mip level
17899 ci.extent = {64, 64, 16};
17900 ci.mipLevels = 7;
17901 ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
17902 VkImageObj src_image(m_device);
17903 src_image.init(&ci);
17904 ASSERT_TRUE(src_image.initialized());
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017905
Tony Barbour552f6c02016-12-21 14:34:07 -070017906 m_commandBuffer->BeginCommandBuffer();
Dave Houltonfc1a4052017-04-27 14:32:45 -060017907
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017908 VkImageCopy copy_region;
Dave Houltonfc1a4052017-04-27 14:32:45 -060017909 copy_region.extent = {32, 32, 8};
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017910 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017911 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Dave Houltoncee81d02017-05-02 11:00:10 -060017912 copy_region.srcSubresource.mipLevel = 0;
17913 copy_region.dstSubresource.mipLevel = 0;
Dave Houltonfc1a4052017-04-27 14:32:45 -060017914 copy_region.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017915 copy_region.dstSubresource.baseArrayLayer = 0;
Dave Houltonfc1a4052017-04-27 14:32:45 -060017916 copy_region.srcSubresource.layerCount = 1;
17917 copy_region.dstSubresource.layerCount = 1;
17918 copy_region.srcOffset = {0, 0, 0};
17919 copy_region.dstOffset = {0, 0, 0};
17920
17921 m_errorMonitor->ExpectSuccess();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017922 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
17923 &copy_region);
Dave Houltonfc1a4052017-04-27 14:32:45 -060017924 m_errorMonitor->VerifyNotFound();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017925
Dave Houltonfc1a4052017-04-27 14:32:45 -060017926 // Dest exceeded in x-dim, VU 01205
17927 copy_region.dstOffset.x = 4;
17928 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01176); // General "contained within" VU
17929 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01205);
17930 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
17931 &copy_region);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017932 m_errorMonitor->VerifyFound();
Dave Houltonfc1a4052017-04-27 14:32:45 -060017933
17934 // Dest exceeded in y-dim, VU 01206
17935 copy_region.dstOffset.x = 0;
17936 copy_region.extent.height = 48;
17937 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01176);
17938 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01206);
17939 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
17940 &copy_region);
17941 m_errorMonitor->VerifyFound();
17942
17943 // Dest exceeded in z-dim, VU 01207
17944 copy_region.extent = {4, 4, 4};
17945 copy_region.dstSubresource.mipLevel = 2;
17946 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01176);
17947 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01207);
17948 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
17949 &copy_region);
17950 m_errorMonitor->VerifyFound();
17951
17952 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017953}
17954
Karl Schultz6addd812016-02-02 17:17:23 -070017955TEST_F(VkLayerTest, CopyImageFormatSizeMismatch) {
Karl Schultzbdb75952016-04-19 11:36:49 -060017956 VkResult err;
17957 bool pass;
17958
17959 // Create color images with different format sizes and try to copy between them
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070017960 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01184);
Karl Schultzbdb75952016-04-19 11:36:49 -060017961
Tony Barbour1fa09702017-03-16 12:09:08 -060017962 ASSERT_NO_FATAL_FAILURE(Init());
Karl Schultzbdb75952016-04-19 11:36:49 -060017963
17964 // Create two images of different types and try to copy between them
17965 VkImage srcImage;
17966 VkImage dstImage;
17967 VkDeviceMemory srcMem;
17968 VkDeviceMemory destMem;
17969 VkMemoryRequirements memReqs;
17970
17971 VkImageCreateInfo image_create_info = {};
17972 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17973 image_create_info.pNext = NULL;
17974 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17975 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
17976 image_create_info.extent.width = 32;
17977 image_create_info.extent.height = 32;
17978 image_create_info.extent.depth = 1;
17979 image_create_info.mipLevels = 1;
17980 image_create_info.arrayLayers = 1;
17981 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
17982 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
17983 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
17984 image_create_info.flags = 0;
17985
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017986 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060017987 ASSERT_VK_SUCCESS(err);
17988
17989 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
17990 // Introduce failure by creating second image with a different-sized format.
17991 image_create_info.format = VK_FORMAT_R5G5B5A1_UNORM_PACK16;
Tobin Ehlis6d4d1d52017-04-05 12:06:10 -060017992 VkFormatProperties properties;
17993 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), image_create_info.format, &properties);
17994 if (properties.optimalTilingFeatures == 0) {
17995 printf(" Image format not supported; skipped.\n");
17996 return;
17997 }
Karl Schultzbdb75952016-04-19 11:36:49 -060017998
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017999 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060018000 ASSERT_VK_SUCCESS(err);
18001
18002 // Allocate memory
18003 VkMemoryAllocateInfo memAlloc = {};
18004 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18005 memAlloc.pNext = NULL;
18006 memAlloc.allocationSize = 0;
18007 memAlloc.memoryTypeIndex = 0;
18008
18009 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
18010 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018011 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060018012 ASSERT_TRUE(pass);
18013 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
18014 ASSERT_VK_SUCCESS(err);
18015
18016 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
18017 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018018 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060018019 ASSERT_TRUE(pass);
18020 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
18021 ASSERT_VK_SUCCESS(err);
18022
18023 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
18024 ASSERT_VK_SUCCESS(err);
18025 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
18026 ASSERT_VK_SUCCESS(err);
18027
Tony Barbour552f6c02016-12-21 14:34:07 -070018028 m_commandBuffer->BeginCommandBuffer();
Karl Schultzbdb75952016-04-19 11:36:49 -060018029 VkImageCopy copyRegion;
18030 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
18031 copyRegion.srcSubresource.mipLevel = 0;
18032 copyRegion.srcSubresource.baseArrayLayer = 0;
18033 copyRegion.srcSubresource.layerCount = 0;
18034 copyRegion.srcOffset.x = 0;
18035 copyRegion.srcOffset.y = 0;
18036 copyRegion.srcOffset.z = 0;
18037 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
18038 copyRegion.dstSubresource.mipLevel = 0;
18039 copyRegion.dstSubresource.baseArrayLayer = 0;
18040 copyRegion.dstSubresource.layerCount = 0;
18041 copyRegion.dstOffset.x = 0;
18042 copyRegion.dstOffset.y = 0;
18043 copyRegion.dstOffset.z = 0;
18044 copyRegion.extent.width = 1;
18045 copyRegion.extent.height = 1;
18046 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018047 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070018048 m_commandBuffer->EndCommandBuffer();
Karl Schultzbdb75952016-04-19 11:36:49 -060018049
18050 m_errorMonitor->VerifyFound();
18051
18052 vkDestroyImage(m_device->device(), srcImage, NULL);
18053 vkDestroyImage(m_device->device(), dstImage, NULL);
18054 vkFreeMemory(m_device->device(), srcMem, NULL);
18055 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060018056}
18057
Karl Schultz6addd812016-02-02 17:17:23 -070018058TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch) {
18059 VkResult err;
18060 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060018061
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018062 // Create a depth image and a depth/stencil image and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018063 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
18064 "vkCmdCopyImage called with unmatched source and dest image depth");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060018065
Tony Barbour1fa09702017-03-16 12:09:08 -060018066 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -060018067 auto depth_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbourf887b162017-03-09 10:06:46 -070018068 if (!depth_format) {
18069 return;
18070 }
Mike Stroyana3082432015-09-25 13:39:21 -060018071
18072 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070018073 VkImage srcImage;
18074 VkImage dstImage;
18075 VkDeviceMemory srcMem;
18076 VkDeviceMemory destMem;
18077 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060018078
18079 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070018080 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
18081 image_create_info.pNext = NULL;
18082 image_create_info.imageType = VK_IMAGE_TYPE_2D;
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018083 image_create_info.format = VK_FORMAT_D32_SFLOAT;
Karl Schultz6addd812016-02-02 17:17:23 -070018084 image_create_info.extent.width = 32;
18085 image_create_info.extent.height = 32;
18086 image_create_info.extent.depth = 1;
18087 image_create_info.mipLevels = 1;
18088 image_create_info.arrayLayers = 1;
18089 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Youngad61f4b2017-04-07 08:59:56 -060018090 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Karl Schultz6addd812016-02-02 17:17:23 -070018091 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
18092 image_create_info.flags = 0;
Tobin Ehlis6d4d1d52017-04-05 12:06:10 -060018093 VkFormatProperties properties;
18094 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), image_create_info.format, &properties);
18095 if (properties.optimalTilingFeatures == 0) {
18096 printf(" Image format not supported; skipped.\n");
18097 return;
18098 }
Mike Stroyana3082432015-09-25 13:39:21 -060018099
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018100 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060018101 ASSERT_VK_SUCCESS(err);
18102
Karl Schultzbdb75952016-04-19 11:36:49 -060018103 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
18104
Mark Lobodzinskidb117632016-03-31 10:45:56 -060018105 // Introduce failure by creating second image with a depth/stencil format
Karl Schultz6addd812016-02-02 17:17:23 -070018106 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Tony Barbourf887b162017-03-09 10:06:46 -070018107 image_create_info.format = depth_format;
Mark Lobodzinski867787a2016-10-14 11:49:55 -060018108 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060018109
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018110 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060018111 ASSERT_VK_SUCCESS(err);
18112
18113 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018114 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070018115 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18116 memAlloc.pNext = NULL;
18117 memAlloc.allocationSize = 0;
18118 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018119
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060018120 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060018121 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018122 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060018123 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018124 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060018125 ASSERT_VK_SUCCESS(err);
18126
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018127 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060018128 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018129 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060018130 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018131 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060018132 ASSERT_VK_SUCCESS(err);
18133
18134 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
18135 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018136 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060018137 ASSERT_VK_SUCCESS(err);
18138
Tony Barbour552f6c02016-12-21 14:34:07 -070018139 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060018140 VkImageCopy copyRegion;
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018141 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060018142 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060018143 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018144 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018145 copyRegion.srcOffset.x = 0;
18146 copyRegion.srcOffset.y = 0;
18147 copyRegion.srcOffset.z = 0;
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018148 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018149 copyRegion.dstSubresource.mipLevel = 0;
18150 copyRegion.dstSubresource.baseArrayLayer = 0;
18151 copyRegion.dstSubresource.layerCount = 0;
18152 copyRegion.dstOffset.x = 0;
18153 copyRegion.dstOffset.y = 0;
18154 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018155 copyRegion.extent.width = 1;
18156 copyRegion.extent.height = 1;
18157 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018158 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070018159 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060018160
Chris Forbes8f36a8a2016-04-07 13:21:07 +120018161 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060018162
Chia-I Wuf7458c52015-10-26 21:10:41 +080018163 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018164 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080018165 vkFreeMemory(m_device->device(), srcMem, NULL);
18166 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060018167}
18168
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018169TEST_F(VkLayerTest, CopyImageSampleCountMismatch) {
18170 TEST_DESCRIPTION("Image copies with sample count mis-matches");
Dave Houlton33c22b72017-02-28 13:16:02 -070018171
Mark Lobodzinski77e590c2017-03-17 12:05:16 -060018172 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton33c22b72017-02-28 13:16:02 -070018173
18174 VkImageFormatProperties image_format_properties;
18175 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
18176 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT, 0,
18177 &image_format_properties);
18178
18179 if ((0 == (VK_SAMPLE_COUNT_2_BIT & image_format_properties.sampleCounts)) ||
18180 (0 == (VK_SAMPLE_COUNT_4_BIT & image_format_properties.sampleCounts))) {
18181 printf(" Image multi-sample support not found; skipped.\n");
18182 return;
18183 }
18184
18185 VkImageCreateInfo ci;
18186 ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
18187 ci.pNext = NULL;
18188 ci.flags = 0;
18189 ci.imageType = VK_IMAGE_TYPE_2D;
18190 ci.format = VK_FORMAT_R8G8B8A8_UNORM;
18191 ci.extent = {128, 128, 1};
18192 ci.mipLevels = 1;
18193 ci.arrayLayers = 1;
18194 ci.samples = VK_SAMPLE_COUNT_1_BIT;
18195 ci.tiling = VK_IMAGE_TILING_OPTIMAL;
18196 ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
18197 ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
18198 ci.queueFamilyIndexCount = 0;
18199 ci.pQueueFamilyIndices = NULL;
18200 ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
18201
18202 VkImageObj image1(m_device);
18203 image1.init(&ci);
18204 ASSERT_TRUE(image1.initialized());
18205
18206 ci.samples = VK_SAMPLE_COUNT_2_BIT;
18207 VkImageObj image2(m_device);
18208 image2.init(&ci);
18209 ASSERT_TRUE(image2.initialized());
18210
18211 ci.samples = VK_SAMPLE_COUNT_4_BIT;
18212 VkImageObj image4(m_device);
18213 image4.init(&ci);
18214 ASSERT_TRUE(image4.initialized());
18215
18216 m_commandBuffer->BeginCommandBuffer();
18217
18218 VkImageCopy copyRegion;
18219 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
18220 copyRegion.srcSubresource.mipLevel = 0;
18221 copyRegion.srcSubresource.baseArrayLayer = 0;
18222 copyRegion.srcSubresource.layerCount = 1;
18223 copyRegion.srcOffset = {0, 0, 0};
18224 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
18225 copyRegion.dstSubresource.mipLevel = 0;
18226 copyRegion.dstSubresource.baseArrayLayer = 0;
18227 copyRegion.dstSubresource.layerCount = 1;
18228 copyRegion.dstOffset = {0, 0, 0};
18229 copyRegion.extent = {128, 128, 1};
18230
18231 // Copy a single sample image to/from a multi-sample image
18232 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01185);
18233 vkCmdCopyImage(m_commandBuffer->GetBufferHandle(), image1.handle(), VK_IMAGE_LAYOUT_GENERAL, image4.handle(),
18234 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
18235 m_errorMonitor->VerifyFound();
18236
18237 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01185);
18238 vkCmdCopyImage(m_commandBuffer->GetBufferHandle(), image2.handle(), VK_IMAGE_LAYOUT_GENERAL, image1.handle(),
18239 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
18240 m_errorMonitor->VerifyFound();
18241
18242 // Copy between multi-sample images with different sample counts
18243 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01185);
18244 vkCmdCopyImage(m_commandBuffer->GetBufferHandle(), image2.handle(), VK_IMAGE_LAYOUT_GENERAL, image4.handle(),
18245 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
18246 m_errorMonitor->VerifyFound();
18247
18248 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01185);
18249 vkCmdCopyImage(m_commandBuffer->GetBufferHandle(), image4.handle(), VK_IMAGE_LAYOUT_GENERAL, image2.handle(),
18250 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
18251 m_errorMonitor->VerifyFound();
18252
18253 m_commandBuffer->EndCommandBuffer();
18254}
18255
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018256TEST_F(VkLayerTest, CopyImageAspectMismatch) {
18257 TEST_DESCRIPTION("Image copies with aspect mask errors");
Mark Lobodzinski77e590c2017-03-17 12:05:16 -060018258 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -060018259 auto ds_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbour9357d542017-03-24 15:42:21 -060018260 if (!ds_format) {
18261 return;
18262 }
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018263
Tobin Ehlis6d4d1d52017-04-05 12:06:10 -060018264 VkFormatProperties properties;
18265 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D32_SFLOAT, &properties);
18266 if (properties.optimalTilingFeatures == 0) {
18267 printf(" Image format VK_FORMAT_D32_SFLOAT not supported; skipped.\n");
18268 return;
18269 }
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018270 VkImageObj color_image(m_device), ds_image(m_device), depth_image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060018271 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 -060018272 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 -060018273 VK_IMAGE_TILING_OPTIMAL, 0);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060018274 ds_image.Init(128, 128, 1, ds_format, VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
18275 VK_IMAGE_TILING_OPTIMAL, 0);
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018276 ASSERT_TRUE(color_image.initialized());
18277 ASSERT_TRUE(depth_image.initialized());
18278 ASSERT_TRUE(ds_image.initialized());
18279
18280 VkImageCopy copyRegion;
18281 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
18282 copyRegion.srcSubresource.mipLevel = 0;
18283 copyRegion.srcSubresource.baseArrayLayer = 0;
18284 copyRegion.srcSubresource.layerCount = 1;
18285 copyRegion.srcOffset = {0, 0, 0};
18286 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
18287 copyRegion.dstSubresource.mipLevel = 0;
18288 copyRegion.dstSubresource.baseArrayLayer = 0;
18289 copyRegion.dstSubresource.layerCount = 1;
18290 copyRegion.dstOffset = {64, 0, 0};
18291 copyRegion.extent = {64, 128, 1};
18292
18293 // Submitting command before command buffer is in recording state
Dave Houlton3c9fca72017-03-27 17:25:54 -060018294 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
18295 "You must call vkBeginCommandBuffer"); // VALIDATION_ERROR_01192);
18296 vkCmdCopyImage(m_commandBuffer->GetBufferHandle(), depth_image.handle(), VK_IMAGE_LAYOUT_GENERAL, depth_image.handle(),
18297 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018298 m_errorMonitor->VerifyFound();
18299
18300 m_commandBuffer->BeginCommandBuffer();
18301
18302 // Src and dest aspect masks don't match
18303 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT;
18304 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01197);
Dave Houlton3c9fca72017-03-27 17:25:54 -060018305 vkCmdCopyImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, ds_image.handle(),
18306 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018307 m_errorMonitor->VerifyFound();
18308 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
18309
18310 // Illegal combinations of aspect bits - VU 01221
Dave Houlton3c9fca72017-03-27 17:25:54 -060018311 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT; // color must be alone
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018312 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT;
18313 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01221);
18314 // These aspect/format mismatches are redundant but unavoidable here
18315 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01200);
18316 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01201);
Dave Houlton3c9fca72017-03-27 17:25:54 -060018317 vkCmdCopyImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_GENERAL, color_image.handle(),
18318 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018319 m_errorMonitor->VerifyFound();
18320 // Metadata aspect is illegal - VU 01222
18321 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
18322 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
18323 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01222);
18324 // These aspect/format mismatches are redundant but unavoidable here
Dave Houlton3c9fca72017-03-27 17:25:54 -060018325 vkCmdCopyImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_GENERAL, color_image.handle(),
18326 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018327 m_errorMonitor->VerifyFound();
18328
18329 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
18330 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
18331
18332 // Aspect mask doesn't match source image format - VU 01200
18333 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01200);
18334 // Again redundant but unavoidable when provoking vu01200 w/o vu01201
18335 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "unmatched source and dest image depth/stencil formats");
18336 vkCmdCopyImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_GENERAL, depth_image.handle(),
18337 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
18338 m_errorMonitor->VerifyFound();
18339
18340 // Aspect mask doesn't match dest image format - VU 01201
18341 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
18342 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
18343 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01201);
18344 // Again redundant but unavoidable when provoking vu01201 w/o vu01200
18345 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "unmatched source and dest image depth/stencil formats");
18346 vkCmdCopyImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_GENERAL, depth_image.handle(),
18347 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
18348 m_errorMonitor->VerifyFound();
18349
18350 m_commandBuffer->EndCommandBuffer();
18351}
18352
Karl Schultz6addd812016-02-02 17:17:23 -070018353TEST_F(VkLayerTest, ResolveImageLowSampleCount) {
18354 VkResult err;
18355 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060018356
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018357 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
18358 "vkCmdResolveImage called with source sample count less than 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060018359
Tony Barbour1fa09702017-03-16 12:09:08 -060018360 ASSERT_NO_FATAL_FAILURE(Init());
Mike Stroyana3082432015-09-25 13:39:21 -060018361
18362 // Create two images of sample count 1 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070018363 VkImage srcImage;
18364 VkImage dstImage;
18365 VkDeviceMemory srcMem;
18366 VkDeviceMemory destMem;
18367 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060018368
18369 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070018370 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
18371 image_create_info.pNext = NULL;
18372 image_create_info.imageType = VK_IMAGE_TYPE_2D;
18373 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
18374 image_create_info.extent.width = 32;
18375 image_create_info.extent.height = 1;
18376 image_create_info.extent.depth = 1;
18377 image_create_info.mipLevels = 1;
18378 image_create_info.arrayLayers = 1;
18379 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
18380 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
18381 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
18382 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018383
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018384 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060018385 ASSERT_VK_SUCCESS(err);
18386
Karl Schultz6addd812016-02-02 17:17:23 -070018387 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060018388
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018389 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060018390 ASSERT_VK_SUCCESS(err);
18391
18392 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018393 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070018394 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18395 memAlloc.pNext = NULL;
18396 memAlloc.allocationSize = 0;
18397 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018398
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060018399 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060018400 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018401 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060018402 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018403 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060018404 ASSERT_VK_SUCCESS(err);
18405
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018406 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060018407 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018408 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060018409 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018410 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060018411 ASSERT_VK_SUCCESS(err);
18412
18413 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
18414 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018415 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060018416 ASSERT_VK_SUCCESS(err);
18417
Tony Barbour552f6c02016-12-21 14:34:07 -070018418 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060018419 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070018420 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
18421 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060018422 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080018423 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060018424 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060018425 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130018426 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060018427 resolveRegion.srcOffset.x = 0;
18428 resolveRegion.srcOffset.y = 0;
18429 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080018430 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018431 resolveRegion.dstSubresource.mipLevel = 0;
18432 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130018433 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018434 resolveRegion.dstOffset.x = 0;
18435 resolveRegion.dstOffset.y = 0;
18436 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018437 resolveRegion.extent.width = 1;
18438 resolveRegion.extent.height = 1;
18439 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018440 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070018441 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060018442
Chris Forbes8f36a8a2016-04-07 13:21:07 +120018443 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060018444
Chia-I Wuf7458c52015-10-26 21:10:41 +080018445 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018446 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080018447 vkFreeMemory(m_device->device(), srcMem, NULL);
18448 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060018449}
18450
Karl Schultz6addd812016-02-02 17:17:23 -070018451TEST_F(VkLayerTest, ResolveImageHighSampleCount) {
18452 VkResult err;
18453 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060018454
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018455 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
18456 "vkCmdResolveImage called with dest sample count greater than 1.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060018457
Tony Barbour1fa09702017-03-16 12:09:08 -060018458 ASSERT_NO_FATAL_FAILURE(Init());
Mike Stroyana3082432015-09-25 13:39:21 -060018459
Chris Forbesa7530692016-05-08 12:35:39 +120018460 // Create two images of sample count 4 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070018461 VkImage srcImage;
18462 VkImage dstImage;
18463 VkDeviceMemory srcMem;
18464 VkDeviceMemory destMem;
18465 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060018466
18467 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070018468 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
18469 image_create_info.pNext = NULL;
18470 image_create_info.imageType = VK_IMAGE_TYPE_2D;
18471 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
18472 image_create_info.extent.width = 32;
18473 image_create_info.extent.height = 1;
18474 image_create_info.extent.depth = 1;
18475 image_create_info.mipLevels = 1;
18476 image_create_info.arrayLayers = 1;
Chris Forbesa7530692016-05-08 12:35:39 +120018477 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070018478 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
18479 // Note: Some implementations expect color attachment usage for any
18480 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018481 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070018482 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018483
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018484 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060018485 ASSERT_VK_SUCCESS(err);
18486
Karl Schultz6addd812016-02-02 17:17:23 -070018487 // Note: Some implementations expect color attachment usage for any
18488 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018489 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060018490
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018491 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060018492 ASSERT_VK_SUCCESS(err);
18493
18494 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018495 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070018496 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18497 memAlloc.pNext = NULL;
18498 memAlloc.allocationSize = 0;
18499 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018500
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060018501 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060018502 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018503 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060018504 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018505 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060018506 ASSERT_VK_SUCCESS(err);
18507
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018508 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060018509 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018510 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060018511 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018512 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060018513 ASSERT_VK_SUCCESS(err);
18514
18515 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
18516 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018517 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060018518 ASSERT_VK_SUCCESS(err);
18519
Tony Barbour552f6c02016-12-21 14:34:07 -070018520 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060018521 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070018522 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
18523 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060018524 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080018525 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060018526 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060018527 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130018528 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060018529 resolveRegion.srcOffset.x = 0;
18530 resolveRegion.srcOffset.y = 0;
18531 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080018532 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018533 resolveRegion.dstSubresource.mipLevel = 0;
18534 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130018535 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018536 resolveRegion.dstOffset.x = 0;
18537 resolveRegion.dstOffset.y = 0;
18538 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018539 resolveRegion.extent.width = 1;
18540 resolveRegion.extent.height = 1;
18541 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018542 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070018543 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060018544
Chris Forbes8f36a8a2016-04-07 13:21:07 +120018545 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060018546
Chia-I Wuf7458c52015-10-26 21:10:41 +080018547 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018548 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080018549 vkFreeMemory(m_device->device(), srcMem, NULL);
18550 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060018551}
18552
Karl Schultz6addd812016-02-02 17:17:23 -070018553TEST_F(VkLayerTest, ResolveImageFormatMismatch) {
18554 VkResult err;
18555 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060018556
Mark Lobodzinski50fbef12017-02-06 15:31:33 -070018557 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018558 "vkCmdResolveImage called with unmatched source and dest formats.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060018559
Tony Barbour1fa09702017-03-16 12:09:08 -060018560 ASSERT_NO_FATAL_FAILURE(Init());
Mike Stroyana3082432015-09-25 13:39:21 -060018561
18562 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070018563 VkImage srcImage;
18564 VkImage dstImage;
18565 VkDeviceMemory srcMem;
18566 VkDeviceMemory destMem;
18567 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060018568
18569 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070018570 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
18571 image_create_info.pNext = NULL;
18572 image_create_info.imageType = VK_IMAGE_TYPE_2D;
18573 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
18574 image_create_info.extent.width = 32;
18575 image_create_info.extent.height = 1;
18576 image_create_info.extent.depth = 1;
18577 image_create_info.mipLevels = 1;
18578 image_create_info.arrayLayers = 1;
18579 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
18580 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
18581 // Note: Some implementations expect color attachment usage for any
18582 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018583 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070018584 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018585
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018586 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060018587 ASSERT_VK_SUCCESS(err);
18588
Karl Schultz6addd812016-02-02 17:17:23 -070018589 // Set format to something other than source image
18590 image_create_info.format = VK_FORMAT_R32_SFLOAT;
18591 // Note: Some implementations expect color attachment usage for any
18592 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018593 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070018594 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060018595
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018596 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060018597 ASSERT_VK_SUCCESS(err);
18598
18599 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018600 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070018601 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18602 memAlloc.pNext = NULL;
18603 memAlloc.allocationSize = 0;
18604 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018605
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060018606 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060018607 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018608 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060018609 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018610 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060018611 ASSERT_VK_SUCCESS(err);
18612
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018613 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060018614 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018615 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060018616 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018617 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060018618 ASSERT_VK_SUCCESS(err);
18619
18620 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
18621 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018622 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060018623 ASSERT_VK_SUCCESS(err);
18624
Tony Barbour552f6c02016-12-21 14:34:07 -070018625 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060018626 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070018627 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
18628 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060018629 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080018630 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060018631 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060018632 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130018633 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060018634 resolveRegion.srcOffset.x = 0;
18635 resolveRegion.srcOffset.y = 0;
18636 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080018637 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018638 resolveRegion.dstSubresource.mipLevel = 0;
18639 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130018640 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018641 resolveRegion.dstOffset.x = 0;
18642 resolveRegion.dstOffset.y = 0;
18643 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018644 resolveRegion.extent.width = 1;
18645 resolveRegion.extent.height = 1;
18646 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018647 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070018648 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060018649
Chris Forbes8f36a8a2016-04-07 13:21:07 +120018650 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060018651
Chia-I Wuf7458c52015-10-26 21:10:41 +080018652 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018653 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080018654 vkFreeMemory(m_device->device(), srcMem, NULL);
18655 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060018656}
18657
Karl Schultz6addd812016-02-02 17:17:23 -070018658TEST_F(VkLayerTest, ResolveImageTypeMismatch) {
18659 VkResult err;
18660 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060018661
Mark Lobodzinski50fbef12017-02-06 15:31:33 -070018662 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018663 "vkCmdResolveImage called with unmatched source and dest image types.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060018664
Tony Barbour1fa09702017-03-16 12:09:08 -060018665 ASSERT_NO_FATAL_FAILURE(Init());
Mike Stroyana3082432015-09-25 13:39:21 -060018666
18667 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070018668 VkImage srcImage;
18669 VkImage dstImage;
18670 VkDeviceMemory srcMem;
18671 VkDeviceMemory destMem;
18672 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060018673
18674 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070018675 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
18676 image_create_info.pNext = NULL;
18677 image_create_info.imageType = VK_IMAGE_TYPE_2D;
18678 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
18679 image_create_info.extent.width = 32;
18680 image_create_info.extent.height = 1;
18681 image_create_info.extent.depth = 1;
18682 image_create_info.mipLevels = 1;
18683 image_create_info.arrayLayers = 1;
18684 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
18685 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
18686 // Note: Some implementations expect color attachment usage for any
18687 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018688 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070018689 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018690
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018691 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060018692 ASSERT_VK_SUCCESS(err);
18693
Karl Schultz6addd812016-02-02 17:17:23 -070018694 image_create_info.imageType = VK_IMAGE_TYPE_1D;
18695 // Note: Some implementations expect color attachment usage for any
18696 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018697 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070018698 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060018699
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018700 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060018701 ASSERT_VK_SUCCESS(err);
18702
18703 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018704 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070018705 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18706 memAlloc.pNext = NULL;
18707 memAlloc.allocationSize = 0;
18708 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018709
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060018710 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060018711 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018712 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060018713 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018714 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060018715 ASSERT_VK_SUCCESS(err);
18716
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018717 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060018718 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018719 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060018720 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018721 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060018722 ASSERT_VK_SUCCESS(err);
18723
18724 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
18725 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018726 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060018727 ASSERT_VK_SUCCESS(err);
18728
Tony Barbour552f6c02016-12-21 14:34:07 -070018729 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060018730 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070018731 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
18732 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060018733 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080018734 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060018735 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060018736 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130018737 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060018738 resolveRegion.srcOffset.x = 0;
18739 resolveRegion.srcOffset.y = 0;
18740 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080018741 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018742 resolveRegion.dstSubresource.mipLevel = 0;
18743 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130018744 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018745 resolveRegion.dstOffset.x = 0;
18746 resolveRegion.dstOffset.y = 0;
18747 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018748 resolveRegion.extent.width = 1;
18749 resolveRegion.extent.height = 1;
18750 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018751 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070018752 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060018753
Chris Forbes8f36a8a2016-04-07 13:21:07 +120018754 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060018755
Chia-I Wuf7458c52015-10-26 21:10:41 +080018756 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018757 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080018758 vkFreeMemory(m_device->device(), srcMem, NULL);
18759 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060018760}
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018761
Karl Schultz6addd812016-02-02 17:17:23 -070018762TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018763 // Create a single Image descriptor and cause it to first hit an error due
Karl Schultz6addd812016-02-02 17:17:23 -070018764 // to using a DS format, then cause it to hit error due to COLOR_BIT not
18765 // set in aspect
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018766 // The image format check comes 2nd in validation so we trigger it first,
18767 // then when we cause aspect fail next, bad format check will be preempted
Karl Schultz6addd812016-02-02 17:17:23 -070018768 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018769
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018770 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
18771 "Combination depth/stencil image formats can have only the ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060018772
Tony Barbour1fa09702017-03-16 12:09:08 -060018773 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -060018774 auto depth_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbourf887b162017-03-09 10:06:46 -070018775 if (!depth_format) {
18776 return;
18777 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060018778
Chia-I Wu1b99bb22015-10-27 19:25:11 +080018779 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070018780 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
18781 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018782
18783 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070018784 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
18785 ds_pool_ci.pNext = NULL;
18786 ds_pool_ci.maxSets = 1;
18787 ds_pool_ci.poolSizeCount = 1;
18788 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018789
18790 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018791 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018792 ASSERT_VK_SUCCESS(err);
18793
18794 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070018795 dsl_binding.binding = 0;
18796 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
18797 dsl_binding.descriptorCount = 1;
18798 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
18799 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018800
18801 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070018802 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
18803 ds_layout_ci.pNext = NULL;
18804 ds_layout_ci.bindingCount = 1;
18805 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018806 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018807 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018808 ASSERT_VK_SUCCESS(err);
18809
18810 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018811 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080018812 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070018813 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018814 alloc_info.descriptorPool = ds_pool;
18815 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018816 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018817 ASSERT_VK_SUCCESS(err);
18818
Karl Schultz6addd812016-02-02 17:17:23 -070018819 VkImage image_bad;
18820 VkImage image_good;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018821 // One bad format and one good format for Color attachment
Tony Barbourf887b162017-03-09 10:06:46 -070018822 const VkFormat tex_format_bad = depth_format;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018823 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
Karl Schultz6addd812016-02-02 17:17:23 -070018824 const int32_t tex_width = 32;
18825 const int32_t tex_height = 32;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018826
18827 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070018828 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
18829 image_create_info.pNext = NULL;
18830 image_create_info.imageType = VK_IMAGE_TYPE_2D;
18831 image_create_info.format = tex_format_bad;
18832 image_create_info.extent.width = tex_width;
18833 image_create_info.extent.height = tex_height;
18834 image_create_info.extent.depth = 1;
18835 image_create_info.mipLevels = 1;
18836 image_create_info.arrayLayers = 1;
18837 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
18838 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018839 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070018840 image_create_info.flags = 0;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018841
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018842 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018843 ASSERT_VK_SUCCESS(err);
18844 image_create_info.format = tex_format_good;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018845 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
18846 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_good);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018847 ASSERT_VK_SUCCESS(err);
18848
Rene Lindsayf1e89c82016-12-28 13:18:31 -070018849 // ---Bind image memory---
18850 VkMemoryRequirements img_mem_reqs;
18851 vkGetImageMemoryRequirements(m_device->device(), image_bad, &img_mem_reqs);
18852 VkMemoryAllocateInfo image_alloc_info = {};
18853 image_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18854 image_alloc_info.pNext = NULL;
18855 image_alloc_info.memoryTypeIndex = 0;
18856 image_alloc_info.allocationSize = img_mem_reqs.size;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018857 bool pass =
18858 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 -070018859 ASSERT_TRUE(pass);
18860 VkDeviceMemory mem;
18861 err = vkAllocateMemory(m_device->device(), &image_alloc_info, NULL, &mem);
18862 ASSERT_VK_SUCCESS(err);
18863 err = vkBindImageMemory(m_device->device(), image_bad, mem, 0);
18864 ASSERT_VK_SUCCESS(err);
18865 // -----------------------
18866
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018867 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130018868 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070018869 image_view_create_info.image = image_bad;
18870 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
18871 image_view_create_info.format = tex_format_bad;
18872 image_view_create_info.subresourceRange.baseArrayLayer = 0;
18873 image_view_create_info.subresourceRange.baseMipLevel = 0;
18874 image_view_create_info.subresourceRange.layerCount = 1;
18875 image_view_create_info.subresourceRange.levelCount = 1;
Rene Lindsayf1e89c82016-12-28 13:18:31 -070018876 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018877
18878 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018879 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060018880
Chris Forbes8f36a8a2016-04-07 13:21:07 +120018881 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018882
Chia-I Wuf7458c52015-10-26 21:10:41 +080018883 vkDestroyImage(m_device->device(), image_bad, NULL);
18884 vkDestroyImage(m_device->device(), image_good, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080018885 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
18886 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Rene Lindsayf1e89c82016-12-28 13:18:31 -070018887
18888 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018889}
Tobin Ehlis6e23d772016-05-19 11:08:34 -060018890
18891TEST_F(VkLayerTest, ClearImageErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018892 TEST_DESCRIPTION(
18893 "Call ClearColorImage w/ a depth|stencil image and "
18894 "ClearDepthStencilImage with a color image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060018895
Tony Barbour1fa09702017-03-16 12:09:08 -060018896 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -060018897 auto depth_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbourf887b162017-03-09 10:06:46 -070018898 if (!depth_format) {
18899 return;
18900 }
Tobin Ehlis6e23d772016-05-19 11:08:34 -060018901 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18902
Tony Barbour552f6c02016-12-21 14:34:07 -070018903 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis6e23d772016-05-19 11:08:34 -060018904
18905 // Color image
18906 VkClearColorValue clear_color;
18907 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
18908 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
18909 const VkFormat color_format = VK_FORMAT_B8G8R8A8_UNORM;
18910 const int32_t img_width = 32;
18911 const int32_t img_height = 32;
18912 VkImageCreateInfo image_create_info = {};
18913 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
18914 image_create_info.pNext = NULL;
18915 image_create_info.imageType = VK_IMAGE_TYPE_2D;
18916 image_create_info.format = color_format;
18917 image_create_info.extent.width = img_width;
18918 image_create_info.extent.height = img_height;
18919 image_create_info.extent.depth = 1;
18920 image_create_info.mipLevels = 1;
18921 image_create_info.arrayLayers = 1;
18922 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
18923 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
18924 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
18925
18926 vk_testing::Image color_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018927 color_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060018928
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018929 const VkImageSubresourceRange color_range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060018930
18931 // Depth/Stencil image
18932 VkClearDepthStencilValue clear_value = {0};
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018933 reqs = 0; // don't need HOST_VISIBLE DS image
Tobin Ehlis6e23d772016-05-19 11:08:34 -060018934 VkImageCreateInfo ds_image_create_info = vk_testing::Image::create_info();
18935 ds_image_create_info.imageType = VK_IMAGE_TYPE_2D;
Tony Barbourf887b162017-03-09 10:06:46 -070018936 ds_image_create_info.format = depth_format;
Tobin Ehlis6e23d772016-05-19 11:08:34 -060018937 ds_image_create_info.extent.width = 64;
18938 ds_image_create_info.extent.height = 64;
18939 ds_image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Rene Lindsaya1fc64a2016-12-27 15:18:54 -070018940 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 -060018941
18942 vk_testing::Image ds_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018943 ds_image.init(*m_device, (const VkImageCreateInfo &)ds_image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060018944
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018945 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 -060018946
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018947 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060018948
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018949 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tobin Ehlis6e23d772016-05-19 11:08:34 -060018950 &color_range);
18951
18952 m_errorMonitor->VerifyFound();
18953
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018954 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
18955 "vkCmdClearColorImage called with "
18956 "image created without "
18957 "VK_IMAGE_USAGE_TRANSFER_DST_BIT");
Tony Barbour26434b92016-06-02 09:43:50 -060018958
Rene Lindsaya1fc64a2016-12-27 15:18:54 -070018959 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tony Barbour26434b92016-06-02 09:43:50 -060018960 &color_range);
18961
18962 m_errorMonitor->VerifyFound();
18963
Tobin Ehlis6e23d772016-05-19 11:08:34 -060018964 // Call CmdClearDepthStencilImage with color image
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018965 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
18966 "vkCmdClearDepthStencilImage called without a depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060018967
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018968 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
18969 &clear_value, 1, &ds_range);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060018970
18971 m_errorMonitor->VerifyFound();
18972}
Tobin Ehliscde08892015-09-22 10:11:37 -060018973
Mike Schuchardt35fece12017-03-07 14:40:28 -070018974TEST_F(VkLayerTest, CommandQueueFlags) {
18975 TEST_DESCRIPTION(
18976 "Allocate a command buffer on a queue that does not support graphics and try to issue a "
18977 "graphics-only command");
18978
18979 ASSERT_NO_FATAL_FAILURE(Init());
18980
18981 uint32_t queueFamilyIndex = m_device->QueueFamilyWithoutCapabilities(VK_QUEUE_GRAPHICS_BIT);
Dave Houlton3c9fca72017-03-27 17:25:54 -060018982 if (queueFamilyIndex == UINT32_MAX) {
Mike Schuchardt35fece12017-03-07 14:40:28 -070018983 printf(" Non-graphics queue family not found; skipped.\n");
18984 return;
18985 } else {
18986 // Create command pool on a non-graphics queue
18987 VkCommandPoolObj command_pool(m_device, queueFamilyIndex);
18988
18989 // Setup command buffer on pool
18990 VkCommandBufferObj command_buffer(m_device, &command_pool);
18991 command_buffer.BeginCommandBuffer();
18992
18993 // Issue a graphics only command
18994 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01446);
18995 VkViewport viewport = {0, 0, 16, 16, 0, 1};
18996 command_buffer.SetViewport(0, 1, &viewport);
18997 m_errorMonitor->VerifyFound();
18998 }
18999}
19000
Mark Lobodzinskib8359282017-05-16 09:17:51 -060019001TEST_F(VkLayerTest, ExecuteUnrecordedCBs) {
19002 TEST_DESCRIPTION(
19003 "Attempt vkCmdExecuteCommands and then QueueSubmit with an unrecorded secondary and primary command buffer, respectively");
19004
19005 ASSERT_NO_FATAL_FAILURE(Init());
19006 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19007 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00155);
19008 // Allocate a secondary command buffer
19009 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
19010 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19011 command_buffer_allocate_info.commandPool = m_commandPool->handle();
19012 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
19013 command_buffer_allocate_info.commandBufferCount = 1;
19014 VkCommandBuffer secondary_command_buffer;
19015 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
19016 VkCommandBufferBeginInfo command_buffer_begin_info = {};
19017 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19018 command_buffer_begin_info.flags =
19019 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
19020 command_buffer_begin_info.pInheritanceInfo = nullptr;
19021
19022 // Now update primary cmd buffer to execute unrecorded secondary
19023 VkResult err = vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
19024 ASSERT_VK_SUCCESS(err);
19025 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
19026 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
19027 vkCmdEndRenderPass(m_commandBuffer->handle());
19028 err = vkEndCommandBuffer(m_commandBuffer->handle());
19029 ASSERT_VK_SUCCESS(err);
19030 m_errorMonitor->VerifyFound();
19031
19032 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00134);
19033 // Allocate a primary command buffer
19034 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19035 command_buffer_allocate_info.commandBufferCount = 1;
19036 VkCommandBuffer primary_command_buffer;
19037 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &primary_command_buffer));
19038
19039 // And submit the unrecorded command buffer
19040 VkSubmitInfo submit_info = {};
19041 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19042 submit_info.commandBufferCount = 1;
19043 submit_info.pCommandBuffers = &primary_command_buffer;
19044 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
19045 m_errorMonitor->VerifyFound();
19046}
19047
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019048// WSI Enabled Tests
19049//
Chris Forbes09368e42016-10-13 11:59:22 +130019050#if 0
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019051TEST_F(VkWsiEnabledLayerTest, TestEnabledWsi) {
19052
19053#if defined(VK_USE_PLATFORM_XCB_KHR)
19054 VkSurfaceKHR surface = VK_NULL_HANDLE;
19055
19056 VkResult err;
19057 bool pass;
19058 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
19059 VkSwapchainCreateInfoKHR swapchain_create_info = {};
19060 // uint32_t swapchain_image_count = 0;
19061 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
19062 // uint32_t image_index = 0;
19063 // VkPresentInfoKHR present_info = {};
19064
Tony Barbour1fa09702017-03-16 12:09:08 -060019065 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019066
19067 // Use the create function from one of the VK_KHR_*_surface extension in
19068 // order to create a surface, testing all known errors in the process,
19069 // before successfully creating a surface:
19070 // First, try to create a surface without a VkXcbSurfaceCreateInfoKHR:
19071 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo specified as NULL");
19072 err = vkCreateXcbSurfaceKHR(instance(), NULL, NULL, &surface);
19073 pass = (err != VK_SUCCESS);
19074 ASSERT_TRUE(pass);
19075 m_errorMonitor->VerifyFound();
19076
19077 // Next, try to create a surface with the wrong
19078 // VkXcbSurfaceCreateInfoKHR::sType:
19079 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
19080 xcb_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
19081 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
19082 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
19083 pass = (err != VK_SUCCESS);
19084 ASSERT_TRUE(pass);
19085 m_errorMonitor->VerifyFound();
19086
19087 // Create a native window, and then correctly create a surface:
19088 xcb_connection_t *connection;
19089 xcb_screen_t *screen;
19090 xcb_window_t xcb_window;
19091 xcb_intern_atom_reply_t *atom_wm_delete_window;
19092
19093 const xcb_setup_t *setup;
19094 xcb_screen_iterator_t iter;
19095 int scr;
19096 uint32_t value_mask, value_list[32];
19097 int width = 1;
19098 int height = 1;
19099
19100 connection = xcb_connect(NULL, &scr);
19101 ASSERT_TRUE(connection != NULL);
19102 setup = xcb_get_setup(connection);
19103 iter = xcb_setup_roots_iterator(setup);
19104 while (scr-- > 0)
19105 xcb_screen_next(&iter);
19106 screen = iter.data;
19107
19108 xcb_window = xcb_generate_id(connection);
19109
19110 value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
19111 value_list[0] = screen->black_pixel;
19112 value_list[1] = XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_STRUCTURE_NOTIFY;
19113
19114 xcb_create_window(connection, XCB_COPY_FROM_PARENT, xcb_window, screen->root, 0, 0, width, height, 0,
19115 XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual, value_mask, value_list);
19116
19117 /* Magic code that will send notification when window is destroyed */
19118 xcb_intern_atom_cookie_t cookie = xcb_intern_atom(connection, 1, 12, "WM_PROTOCOLS");
19119 xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply(connection, cookie, 0);
19120
19121 xcb_intern_atom_cookie_t cookie2 = xcb_intern_atom(connection, 0, 16, "WM_DELETE_WINDOW");
19122 atom_wm_delete_window = xcb_intern_atom_reply(connection, cookie2, 0);
19123 xcb_change_property(connection, XCB_PROP_MODE_REPLACE, xcb_window, (*reply).atom, 4, 32, 1, &(*atom_wm_delete_window).atom);
19124 free(reply);
19125
19126 xcb_map_window(connection, xcb_window);
19127
19128 // Force the x/y coordinates to 100,100 results are identical in consecutive
19129 // runs
19130 const uint32_t coords[] = { 100, 100 };
19131 xcb_configure_window(connection, xcb_window, XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, coords);
19132
19133 // Finally, try to correctly create a surface:
19134 xcb_create_info.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
19135 xcb_create_info.pNext = NULL;
19136 xcb_create_info.flags = 0;
19137 xcb_create_info.connection = connection;
19138 xcb_create_info.window = xcb_window;
19139 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
19140 pass = (err == VK_SUCCESS);
19141 ASSERT_TRUE(pass);
19142
19143 // Check if surface supports presentation:
19144
19145 // 1st, do so without having queried the queue families:
19146 VkBool32 supported = false;
19147 // TODO: Get the following error to come out:
19148 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
19149 "called before calling the vkGetPhysicalDeviceQueueFamilyProperties "
19150 "function");
19151 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
19152 pass = (err != VK_SUCCESS);
19153 // ASSERT_TRUE(pass);
19154 // m_errorMonitor->VerifyFound();
19155
19156 // Next, query a queue family index that's too large:
19157 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
19158 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 100000, surface, &supported);
19159 pass = (err != VK_SUCCESS);
19160 ASSERT_TRUE(pass);
19161 m_errorMonitor->VerifyFound();
19162
19163 // Finally, do so correctly:
19164 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
19165 // SUPPORTED
19166 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
19167 pass = (err == VK_SUCCESS);
19168 ASSERT_TRUE(pass);
19169
19170 // Before proceeding, try to create a swapchain without having called
19171 // vkGetPhysicalDeviceSurfaceCapabilitiesKHR():
19172 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
19173 swapchain_create_info.pNext = NULL;
19174 swapchain_create_info.flags = 0;
19175 swapchain_create_info.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
19176 swapchain_create_info.surface = surface;
19177 swapchain_create_info.imageArrayLayers = 1;
19178 swapchain_create_info.preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
19179 swapchain_create_info.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
19180 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
19181 "called before calling vkGetPhysicalDeviceSurfaceCapabilitiesKHR().");
19182 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
19183 pass = (err != VK_SUCCESS);
19184 ASSERT_TRUE(pass);
19185 m_errorMonitor->VerifyFound();
19186
19187 // Get the surface capabilities:
19188 VkSurfaceCapabilitiesKHR surface_capabilities;
19189
19190 // Do so correctly (only error logged by this entrypoint is if the
19191 // extension isn't enabled):
19192 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &surface_capabilities);
19193 pass = (err == VK_SUCCESS);
19194 ASSERT_TRUE(pass);
19195
19196 // Get the surface formats:
19197 uint32_t surface_format_count;
19198
19199 // First, try without a pointer to surface_format_count:
19200 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSurfaceFormatCount "
19201 "specified as NULL");
19202 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, NULL, NULL);
19203 pass = (err == VK_SUCCESS);
19204 ASSERT_TRUE(pass);
19205 m_errorMonitor->VerifyFound();
19206
19207 // Next, call with a non-NULL pSurfaceFormats, even though we haven't
19208 // correctly done a 1st try (to get the count):
19209 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
19210 surface_format_count = 0;
19211 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, (VkSurfaceFormatKHR *)&surface_format_count);
19212 pass = (err == VK_SUCCESS);
19213 ASSERT_TRUE(pass);
19214 m_errorMonitor->VerifyFound();
19215
19216 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
19217 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
19218 pass = (err == VK_SUCCESS);
19219 ASSERT_TRUE(pass);
19220
19221 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
19222 VkSurfaceFormatKHR *surface_formats = (VkSurfaceFormatKHR *)malloc(surface_format_count * sizeof(VkSurfaceFormatKHR));
19223
19224 // Next, do a 2nd try with surface_format_count being set too high:
19225 surface_format_count += 5;
19226 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
19227 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
19228 pass = (err == VK_SUCCESS);
19229 ASSERT_TRUE(pass);
19230 m_errorMonitor->VerifyFound();
19231
19232 // Finally, do a correct 1st and 2nd try:
19233 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
19234 pass = (err == VK_SUCCESS);
19235 ASSERT_TRUE(pass);
19236 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
19237 pass = (err == VK_SUCCESS);
19238 ASSERT_TRUE(pass);
19239
19240 // Get the surface present modes:
19241 uint32_t surface_present_mode_count;
19242
19243 // First, try without a pointer to surface_format_count:
19244 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pPresentModeCount "
19245 "specified as NULL");
19246
19247 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, NULL, NULL);
19248 pass = (err == VK_SUCCESS);
19249 ASSERT_TRUE(pass);
19250 m_errorMonitor->VerifyFound();
19251
19252 // Next, call with a non-NULL VkPresentModeKHR, even though we haven't
19253 // correctly done a 1st try (to get the count):
19254 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
19255 surface_present_mode_count = 0;
19256 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count,
19257 (VkPresentModeKHR *)&surface_present_mode_count);
19258 pass = (err == VK_SUCCESS);
19259 ASSERT_TRUE(pass);
19260 m_errorMonitor->VerifyFound();
19261
19262 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
19263 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
19264 pass = (err == VK_SUCCESS);
19265 ASSERT_TRUE(pass);
19266
19267 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
19268 VkPresentModeKHR *surface_present_modes = (VkPresentModeKHR *)malloc(surface_present_mode_count * sizeof(VkPresentModeKHR));
19269
19270 // Next, do a 2nd try with surface_format_count being set too high:
19271 surface_present_mode_count += 5;
19272 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
19273 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
19274 pass = (err == VK_SUCCESS);
19275 ASSERT_TRUE(pass);
19276 m_errorMonitor->VerifyFound();
19277
19278 // Finally, do a correct 1st and 2nd try:
19279 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
19280 pass = (err == VK_SUCCESS);
19281 ASSERT_TRUE(pass);
19282 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
19283 pass = (err == VK_SUCCESS);
19284 ASSERT_TRUE(pass);
19285
19286 // Create a swapchain:
19287
19288 // First, try without a pointer to swapchain_create_info:
19289 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo "
19290 "specified as NULL");
19291
19292 err = vkCreateSwapchainKHR(m_device->device(), NULL, NULL, &swapchain);
19293 pass = (err != VK_SUCCESS);
19294 ASSERT_TRUE(pass);
19295 m_errorMonitor->VerifyFound();
19296
19297 // Next, call with a non-NULL swapchain_create_info, that has the wrong
19298 // sType:
19299 swapchain_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
19300 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
19301
19302 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
19303 pass = (err != VK_SUCCESS);
19304 ASSERT_TRUE(pass);
19305 m_errorMonitor->VerifyFound();
19306
19307 // Next, call with a NULL swapchain pointer:
19308 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
19309 swapchain_create_info.pNext = NULL;
19310 swapchain_create_info.flags = 0;
19311 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSwapchain "
19312 "specified as NULL");
19313
19314 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, NULL);
19315 pass = (err != VK_SUCCESS);
19316 ASSERT_TRUE(pass);
19317 m_errorMonitor->VerifyFound();
19318
19319 // TODO: Enhance swapchain layer so that
19320 // swapchain_create_info.queueFamilyIndexCount is checked against something?
19321
19322 // Next, call with a queue family index that's too large:
19323 uint32_t queueFamilyIndex[2] = { 100000, 0 };
19324 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
19325 swapchain_create_info.queueFamilyIndexCount = 2;
19326 swapchain_create_info.pQueueFamilyIndices = queueFamilyIndex;
19327 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
19328 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
19329 pass = (err != VK_SUCCESS);
19330 ASSERT_TRUE(pass);
19331 m_errorMonitor->VerifyFound();
19332
19333 // Next, call a queueFamilyIndexCount that's too small for CONCURRENT:
19334 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
19335 swapchain_create_info.queueFamilyIndexCount = 1;
19336 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
19337 "but with a bad value(s) for pCreateInfo->queueFamilyIndexCount or "
19338 "pCreateInfo->pQueueFamilyIndices).");
19339 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
19340 pass = (err != VK_SUCCESS);
19341 ASSERT_TRUE(pass);
19342 m_errorMonitor->VerifyFound();
19343
19344 // Next, call with an invalid imageSharingMode:
19345 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_MAX_ENUM;
19346 swapchain_create_info.queueFamilyIndexCount = 1;
19347 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
19348 "called with a non-supported pCreateInfo->imageSharingMode (i.e.");
19349 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
19350 pass = (err != VK_SUCCESS);
19351 ASSERT_TRUE(pass);
19352 m_errorMonitor->VerifyFound();
19353 // Fix for the future:
19354 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
19355 // SUPPORTED
19356 swapchain_create_info.queueFamilyIndexCount = 0;
19357 queueFamilyIndex[0] = 0;
19358 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
19359
19360 // TODO: CONTINUE TESTING VALIDATION OF vkCreateSwapchainKHR() ...
19361 // Get the images from a swapchain:
19362 // Acquire an image from a swapchain:
19363 // Present an image to a swapchain:
19364 // Destroy the swapchain:
19365
19366 // TODOs:
19367 //
19368 // - Try destroying the device without first destroying the swapchain
19369 //
19370 // - Try destroying the device without first destroying the surface
19371 //
19372 // - Try destroying the surface without first destroying the swapchain
19373
19374 // Destroy the surface:
19375 vkDestroySurfaceKHR(instance(), surface, NULL);
19376
19377 // Tear down the window:
19378 xcb_destroy_window(connection, xcb_window);
19379 xcb_disconnect(connection);
19380
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019381#else // VK_USE_PLATFORM_XCB_KHR
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019382 return;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019383#endif // VK_USE_PLATFORM_XCB_KHR
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019384}
Chris Forbes09368e42016-10-13 11:59:22 +130019385#endif
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019386
19387//
19388// POSITIVE VALIDATION TESTS
19389//
19390// These tests do not expect to encounter ANY validation errors pass only if this is true
19391
Mark Lobodzinski781aeb52017-02-22 10:57:53 -070019392TEST_F(VkPositiveLayerTest, SecondaryCommandBufferClearColorAttachments) {
19393 TEST_DESCRIPTION("Create a secondary command buffer and record a CmdClearAttachments call into it");
Tony Barbour1fa09702017-03-16 12:09:08 -060019394 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski781aeb52017-02-22 10:57:53 -070019395 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19396
19397 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
19398 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mike Schuchardt06304c22017-03-01 17:09:09 -070019399 command_buffer_allocate_info.commandPool = m_commandPool->handle();
Mark Lobodzinski781aeb52017-02-22 10:57:53 -070019400 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
19401 command_buffer_allocate_info.commandBufferCount = 1;
19402
19403 VkCommandBuffer secondary_command_buffer;
19404 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
19405 VkCommandBufferBeginInfo command_buffer_begin_info = {};
19406 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
19407 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
19408 command_buffer_inheritance_info.renderPass = m_renderPass;
19409 command_buffer_inheritance_info.framebuffer = m_framebuffer;
19410
19411 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19412 command_buffer_begin_info.flags =
19413 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
19414 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
19415
19416 vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
19417 VkClearAttachment color_attachment;
19418 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
19419 color_attachment.clearValue.color.float32[0] = 0;
19420 color_attachment.clearValue.color.float32[1] = 0;
19421 color_attachment.clearValue.color.float32[2] = 0;
19422 color_attachment.clearValue.color.float32[3] = 0;
19423 color_attachment.colorAttachment = 0;
19424 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
19425 vkCmdClearAttachments(secondary_command_buffer, 1, &color_attachment, 1, &clear_rect);
19426}
19427
Tobin Ehlise0006882016-11-03 10:14:28 -060019428TEST_F(VkPositiveLayerTest, SecondaryCommandBufferImageLayoutTransitions) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019429 TEST_DESCRIPTION(
19430 "Perform an image layout transition in a secondary command buffer followed "
19431 "by a transition in the primary.");
Tobin Ehlise0006882016-11-03 10:14:28 -060019432 VkResult err;
19433 m_errorMonitor->ExpectSuccess();
Tony Barbour1fa09702017-03-16 12:09:08 -060019434 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -060019435 auto depth_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbourf887b162017-03-09 10:06:46 -070019436 if (!depth_format) {
19437 return;
19438 }
Tobin Ehlise0006882016-11-03 10:14:28 -060019439 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19440 // Allocate a secondary and primary cmd buffer
19441 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
19442 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mike Schuchardt06304c22017-03-01 17:09:09 -070019443 command_buffer_allocate_info.commandPool = m_commandPool->handle();
Tobin Ehlise0006882016-11-03 10:14:28 -060019444 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
19445 command_buffer_allocate_info.commandBufferCount = 1;
19446
19447 VkCommandBuffer secondary_command_buffer;
19448 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
19449 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19450 VkCommandBuffer primary_command_buffer;
19451 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &primary_command_buffer));
19452 VkCommandBufferBeginInfo command_buffer_begin_info = {};
19453 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
19454 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
19455 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19456 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
19457 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
19458
19459 err = vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
19460 ASSERT_VK_SUCCESS(err);
19461 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060019462 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 -060019463 ASSERT_TRUE(image.initialized());
19464 VkImageMemoryBarrier img_barrier = {};
19465 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
19466 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
19467 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
19468 img_barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
19469 img_barrier.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19470 img_barrier.image = image.handle();
19471 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
19472 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
19473 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
19474 img_barrier.subresourceRange.baseArrayLayer = 0;
19475 img_barrier.subresourceRange.baseMipLevel = 0;
19476 img_barrier.subresourceRange.layerCount = 1;
19477 img_barrier.subresourceRange.levelCount = 1;
19478 vkCmdPipelineBarrier(secondary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr,
19479 0, nullptr, 1, &img_barrier);
19480 err = vkEndCommandBuffer(secondary_command_buffer);
19481 ASSERT_VK_SUCCESS(err);
19482
19483 // Now update primary cmd buffer to execute secondary and transitions image
19484 command_buffer_begin_info.pInheritanceInfo = nullptr;
19485 err = vkBeginCommandBuffer(primary_command_buffer, &command_buffer_begin_info);
19486 ASSERT_VK_SUCCESS(err);
19487 vkCmdExecuteCommands(primary_command_buffer, 1, &secondary_command_buffer);
19488 VkImageMemoryBarrier img_barrier2 = {};
19489 img_barrier2.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
19490 img_barrier2.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
19491 img_barrier2.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
19492 img_barrier2.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19493 img_barrier2.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19494 img_barrier2.image = image.handle();
19495 img_barrier2.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
19496 img_barrier2.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
19497 img_barrier2.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
19498 img_barrier2.subresourceRange.baseArrayLayer = 0;
19499 img_barrier2.subresourceRange.baseMipLevel = 0;
19500 img_barrier2.subresourceRange.layerCount = 1;
19501 img_barrier2.subresourceRange.levelCount = 1;
19502 vkCmdPipelineBarrier(primary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
19503 nullptr, 1, &img_barrier2);
19504 err = vkEndCommandBuffer(primary_command_buffer);
19505 ASSERT_VK_SUCCESS(err);
19506 VkSubmitInfo submit_info = {};
19507 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19508 submit_info.commandBufferCount = 1;
19509 submit_info.pCommandBuffers = &primary_command_buffer;
19510 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
19511 ASSERT_VK_SUCCESS(err);
19512 m_errorMonitor->VerifyNotFound();
19513 err = vkDeviceWaitIdle(m_device->device());
19514 ASSERT_VK_SUCCESS(err);
Mike Schuchardt06304c22017-03-01 17:09:09 -070019515 vkFreeCommandBuffers(m_device->device(), m_commandPool->handle(), 1, &secondary_command_buffer);
19516 vkFreeCommandBuffers(m_device->device(), m_commandPool->handle(), 1, &primary_command_buffer);
Tobin Ehlise0006882016-11-03 10:14:28 -060019517}
19518
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019519// This is a positive test. No failures are expected.
19520TEST_F(VkPositiveLayerTest, IgnoreUnrelatedDescriptor) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019521 TEST_DESCRIPTION(
19522 "Ensure that the vkUpdateDescriptorSets validation code "
19523 "is ignoring VkWriteDescriptorSet members that are not "
19524 "related to the descriptor type specified by "
19525 "VkWriteDescriptorSet::descriptorType. Correct "
19526 "validation behavior will result in the test running to "
19527 "completion without validation errors.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019528
19529 const uintptr_t invalid_ptr = 0xcdcdcdcd;
19530
Tony Barbour1fa09702017-03-16 12:09:08 -060019531 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019532
19533 // Image Case
19534 {
19535 m_errorMonitor->ExpectSuccess();
19536
19537 VkImage image;
19538 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
19539 const int32_t tex_width = 32;
19540 const int32_t tex_height = 32;
19541 VkImageCreateInfo image_create_info = {};
19542 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
19543 image_create_info.pNext = NULL;
19544 image_create_info.imageType = VK_IMAGE_TYPE_2D;
19545 image_create_info.format = tex_format;
19546 image_create_info.extent.width = tex_width;
19547 image_create_info.extent.height = tex_height;
19548 image_create_info.extent.depth = 1;
19549 image_create_info.mipLevels = 1;
19550 image_create_info.arrayLayers = 1;
19551 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
19552 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
19553 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
19554 image_create_info.flags = 0;
19555 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
19556 ASSERT_VK_SUCCESS(err);
19557
19558 VkMemoryRequirements memory_reqs;
19559 VkDeviceMemory image_memory;
19560 bool pass;
19561 VkMemoryAllocateInfo memory_info = {};
19562 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
19563 memory_info.pNext = NULL;
19564 memory_info.allocationSize = 0;
19565 memory_info.memoryTypeIndex = 0;
19566 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
19567 memory_info.allocationSize = memory_reqs.size;
19568 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
19569 ASSERT_TRUE(pass);
19570 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
19571 ASSERT_VK_SUCCESS(err);
19572 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
19573 ASSERT_VK_SUCCESS(err);
19574
19575 VkImageViewCreateInfo image_view_create_info = {};
19576 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
19577 image_view_create_info.image = image;
19578 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
19579 image_view_create_info.format = tex_format;
19580 image_view_create_info.subresourceRange.layerCount = 1;
19581 image_view_create_info.subresourceRange.baseMipLevel = 0;
19582 image_view_create_info.subresourceRange.levelCount = 1;
19583 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
19584
19585 VkImageView view;
19586 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
19587 ASSERT_VK_SUCCESS(err);
19588
19589 VkDescriptorPoolSize ds_type_count = {};
19590 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
19591 ds_type_count.descriptorCount = 1;
19592
19593 VkDescriptorPoolCreateInfo ds_pool_ci = {};
19594 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
19595 ds_pool_ci.pNext = NULL;
19596 ds_pool_ci.maxSets = 1;
19597 ds_pool_ci.poolSizeCount = 1;
19598 ds_pool_ci.pPoolSizes = &ds_type_count;
19599
19600 VkDescriptorPool ds_pool;
19601 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
19602 ASSERT_VK_SUCCESS(err);
19603
19604 VkDescriptorSetLayoutBinding dsl_binding = {};
19605 dsl_binding.binding = 0;
19606 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
19607 dsl_binding.descriptorCount = 1;
19608 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
19609 dsl_binding.pImmutableSamplers = NULL;
19610
19611 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
19612 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
19613 ds_layout_ci.pNext = NULL;
19614 ds_layout_ci.bindingCount = 1;
19615 ds_layout_ci.pBindings = &dsl_binding;
19616 VkDescriptorSetLayout ds_layout;
19617 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
19618 ASSERT_VK_SUCCESS(err);
19619
19620 VkDescriptorSet descriptor_set;
19621 VkDescriptorSetAllocateInfo alloc_info = {};
19622 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
19623 alloc_info.descriptorSetCount = 1;
19624 alloc_info.descriptorPool = ds_pool;
19625 alloc_info.pSetLayouts = &ds_layout;
19626 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
19627 ASSERT_VK_SUCCESS(err);
19628
19629 VkDescriptorImageInfo image_info = {};
19630 image_info.imageView = view;
19631 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
19632
19633 VkWriteDescriptorSet descriptor_write;
19634 memset(&descriptor_write, 0, sizeof(descriptor_write));
19635 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
19636 descriptor_write.dstSet = descriptor_set;
19637 descriptor_write.dstBinding = 0;
19638 descriptor_write.descriptorCount = 1;
19639 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
19640 descriptor_write.pImageInfo = &image_info;
19641
19642 // Set pBufferInfo and pTexelBufferView to invalid values, which should
19643 // be
19644 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE.
19645 // This will most likely produce a crash if the parameter_validation
19646 // layer
19647 // does not correctly ignore pBufferInfo.
19648 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
19649 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
19650
19651 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
19652
19653 m_errorMonitor->VerifyNotFound();
19654
19655 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
19656 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
19657 vkDestroyImageView(m_device->device(), view, NULL);
19658 vkDestroyImage(m_device->device(), image, NULL);
19659 vkFreeMemory(m_device->device(), image_memory, NULL);
19660 }
19661
19662 // Buffer Case
19663 {
19664 m_errorMonitor->ExpectSuccess();
19665
19666 VkBuffer buffer;
19667 uint32_t queue_family_index = 0;
19668 VkBufferCreateInfo buffer_create_info = {};
19669 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
19670 buffer_create_info.size = 1024;
19671 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
19672 buffer_create_info.queueFamilyIndexCount = 1;
19673 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
19674
19675 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
19676 ASSERT_VK_SUCCESS(err);
19677
19678 VkMemoryRequirements memory_reqs;
19679 VkDeviceMemory buffer_memory;
19680 bool pass;
19681 VkMemoryAllocateInfo memory_info = {};
19682 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
19683 memory_info.pNext = NULL;
19684 memory_info.allocationSize = 0;
19685 memory_info.memoryTypeIndex = 0;
19686
19687 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
19688 memory_info.allocationSize = memory_reqs.size;
19689 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
19690 ASSERT_TRUE(pass);
19691
19692 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
19693 ASSERT_VK_SUCCESS(err);
19694 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
19695 ASSERT_VK_SUCCESS(err);
19696
19697 VkDescriptorPoolSize ds_type_count = {};
19698 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
19699 ds_type_count.descriptorCount = 1;
19700
19701 VkDescriptorPoolCreateInfo ds_pool_ci = {};
19702 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
19703 ds_pool_ci.pNext = NULL;
19704 ds_pool_ci.maxSets = 1;
19705 ds_pool_ci.poolSizeCount = 1;
19706 ds_pool_ci.pPoolSizes = &ds_type_count;
19707
19708 VkDescriptorPool ds_pool;
19709 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
19710 ASSERT_VK_SUCCESS(err);
19711
19712 VkDescriptorSetLayoutBinding dsl_binding = {};
19713 dsl_binding.binding = 0;
19714 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
19715 dsl_binding.descriptorCount = 1;
19716 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
19717 dsl_binding.pImmutableSamplers = NULL;
19718
19719 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
19720 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
19721 ds_layout_ci.pNext = NULL;
19722 ds_layout_ci.bindingCount = 1;
19723 ds_layout_ci.pBindings = &dsl_binding;
19724 VkDescriptorSetLayout ds_layout;
19725 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
19726 ASSERT_VK_SUCCESS(err);
19727
19728 VkDescriptorSet descriptor_set;
19729 VkDescriptorSetAllocateInfo alloc_info = {};
19730 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
19731 alloc_info.descriptorSetCount = 1;
19732 alloc_info.descriptorPool = ds_pool;
19733 alloc_info.pSetLayouts = &ds_layout;
19734 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
19735 ASSERT_VK_SUCCESS(err);
19736
19737 VkDescriptorBufferInfo buffer_info = {};
19738 buffer_info.buffer = buffer;
19739 buffer_info.offset = 0;
19740 buffer_info.range = 1024;
19741
19742 VkWriteDescriptorSet descriptor_write;
19743 memset(&descriptor_write, 0, sizeof(descriptor_write));
19744 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
19745 descriptor_write.dstSet = descriptor_set;
19746 descriptor_write.dstBinding = 0;
19747 descriptor_write.descriptorCount = 1;
19748 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
19749 descriptor_write.pBufferInfo = &buffer_info;
19750
19751 // Set pImageInfo and pTexelBufferView to invalid values, which should
19752 // be
19753 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER.
19754 // This will most likely produce a crash if the parameter_validation
19755 // layer
19756 // does not correctly ignore pImageInfo.
19757 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
19758 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
19759
19760 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
19761
19762 m_errorMonitor->VerifyNotFound();
19763
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019764 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
19765 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
19766 vkDestroyBuffer(m_device->device(), buffer, NULL);
19767 vkFreeMemory(m_device->device(), buffer_memory, NULL);
19768 }
19769
19770 // Texel Buffer Case
19771 {
19772 m_errorMonitor->ExpectSuccess();
19773
19774 VkBuffer buffer;
19775 uint32_t queue_family_index = 0;
19776 VkBufferCreateInfo buffer_create_info = {};
19777 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
19778 buffer_create_info.size = 1024;
19779 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
19780 buffer_create_info.queueFamilyIndexCount = 1;
19781 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
19782
19783 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
19784 ASSERT_VK_SUCCESS(err);
19785
19786 VkMemoryRequirements memory_reqs;
19787 VkDeviceMemory buffer_memory;
19788 bool pass;
19789 VkMemoryAllocateInfo memory_info = {};
19790 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
19791 memory_info.pNext = NULL;
19792 memory_info.allocationSize = 0;
19793 memory_info.memoryTypeIndex = 0;
19794
19795 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
19796 memory_info.allocationSize = memory_reqs.size;
19797 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
19798 ASSERT_TRUE(pass);
19799
19800 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
19801 ASSERT_VK_SUCCESS(err);
19802 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
19803 ASSERT_VK_SUCCESS(err);
19804
19805 VkBufferViewCreateInfo buff_view_ci = {};
19806 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
19807 buff_view_ci.buffer = buffer;
19808 buff_view_ci.format = VK_FORMAT_R8_UNORM;
19809 buff_view_ci.range = VK_WHOLE_SIZE;
19810 VkBufferView buffer_view;
19811 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buffer_view);
19812
19813 VkDescriptorPoolSize ds_type_count = {};
19814 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
19815 ds_type_count.descriptorCount = 1;
19816
19817 VkDescriptorPoolCreateInfo ds_pool_ci = {};
19818 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
19819 ds_pool_ci.pNext = NULL;
19820 ds_pool_ci.maxSets = 1;
19821 ds_pool_ci.poolSizeCount = 1;
19822 ds_pool_ci.pPoolSizes = &ds_type_count;
19823
19824 VkDescriptorPool ds_pool;
19825 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
19826 ASSERT_VK_SUCCESS(err);
19827
19828 VkDescriptorSetLayoutBinding dsl_binding = {};
19829 dsl_binding.binding = 0;
19830 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
19831 dsl_binding.descriptorCount = 1;
19832 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
19833 dsl_binding.pImmutableSamplers = NULL;
19834
19835 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
19836 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
19837 ds_layout_ci.pNext = NULL;
19838 ds_layout_ci.bindingCount = 1;
19839 ds_layout_ci.pBindings = &dsl_binding;
19840 VkDescriptorSetLayout ds_layout;
19841 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
19842 ASSERT_VK_SUCCESS(err);
19843
19844 VkDescriptorSet descriptor_set;
19845 VkDescriptorSetAllocateInfo alloc_info = {};
19846 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
19847 alloc_info.descriptorSetCount = 1;
19848 alloc_info.descriptorPool = ds_pool;
19849 alloc_info.pSetLayouts = &ds_layout;
19850 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
19851 ASSERT_VK_SUCCESS(err);
19852
19853 VkWriteDescriptorSet descriptor_write;
19854 memset(&descriptor_write, 0, sizeof(descriptor_write));
19855 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
19856 descriptor_write.dstSet = descriptor_set;
19857 descriptor_write.dstBinding = 0;
19858 descriptor_write.descriptorCount = 1;
19859 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
19860 descriptor_write.pTexelBufferView = &buffer_view;
19861
19862 // Set pImageInfo and pBufferInfo to invalid values, which should be
19863 // ignored for descriptorType ==
19864 // VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER.
19865 // This will most likely produce a crash if the parameter_validation
19866 // layer
19867 // does not correctly ignore pImageInfo and pBufferInfo.
19868 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
19869 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
19870
19871 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
19872
19873 m_errorMonitor->VerifyNotFound();
19874
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019875 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
19876 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
19877 vkDestroyBufferView(m_device->device(), buffer_view, NULL);
19878 vkDestroyBuffer(m_device->device(), buffer, NULL);
19879 vkFreeMemory(m_device->device(), buffer_memory, NULL);
19880 }
19881}
19882
Tobin Ehlis8893af82017-05-08 12:52:25 -060019883TEST_F(VkPositiveLayerTest, ImmutableSamplerOnlyDescriptor) {
19884 TEST_DESCRIPTION(
19885 "Bind a DescriptorSet with only an immutable sampler"
19886 "and make sure that we don't warn for no update.");
19887
19888 ASSERT_NO_FATAL_FAILURE(Init());
19889 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19890
19891 VkDescriptorPoolSize ds_type_count = {};
19892 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
19893 ds_type_count.descriptorCount = 1;
19894
19895 VkDescriptorPoolCreateInfo ds_pool_ci = {};
19896 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
19897 ds_pool_ci.maxSets = 1;
19898 ds_pool_ci.poolSizeCount = 1;
19899 ds_pool_ci.pPoolSizes = &ds_type_count;
19900
19901 VkDescriptorPool ds_pool;
19902 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
19903 ASSERT_VK_SUCCESS(err);
19904
19905 VkSamplerCreateInfo sampler_ci = {};
19906 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
19907 sampler_ci.pNext = NULL;
19908 sampler_ci.magFilter = VK_FILTER_NEAREST;
19909 sampler_ci.minFilter = VK_FILTER_NEAREST;
19910 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
19911 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
19912 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
19913 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
19914 sampler_ci.mipLodBias = 1.0;
19915 sampler_ci.anisotropyEnable = VK_FALSE;
19916 sampler_ci.maxAnisotropy = 1;
19917 sampler_ci.compareEnable = VK_FALSE;
19918 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
19919 sampler_ci.minLod = 1.0;
19920 sampler_ci.maxLod = 1.0;
19921 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
19922 sampler_ci.unnormalizedCoordinates = VK_FALSE;
19923 VkSampler sampler;
19924
19925 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
19926 ASSERT_VK_SUCCESS(err);
19927
19928 VkDescriptorSetLayoutBinding layout_binding = {};
19929 layout_binding.binding = 0;
19930 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
19931 layout_binding.descriptorCount = 1;
19932 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
19933 layout_binding.pImmutableSamplers = static_cast<VkSampler *>(&sampler);
19934
19935 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
19936 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
19937 ds_layout_ci.bindingCount = 1;
19938 ds_layout_ci.pBindings = &layout_binding;
19939 VkDescriptorSetLayout ds_layout;
19940 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
19941 ASSERT_VK_SUCCESS(err);
19942
19943 VkDescriptorSetAllocateInfo alloc_info = {};
19944 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
19945 alloc_info.descriptorSetCount = 1;
19946 alloc_info.descriptorPool = ds_pool;
19947 alloc_info.pSetLayouts = &ds_layout;
19948 VkDescriptorSet descriptor_set;
19949 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
19950 ASSERT_VK_SUCCESS(err);
19951
19952 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
19953 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
19954 pipeline_layout_ci.pNext = NULL;
19955 pipeline_layout_ci.setLayoutCount = 1;
19956 pipeline_layout_ci.pSetLayouts = &ds_layout;
19957
19958 VkPipelineLayout pipeline_layout;
19959 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
19960 ASSERT_VK_SUCCESS(err);
19961
19962 m_errorMonitor->ExpectSuccess();
19963 m_commandBuffer->BeginCommandBuffer();
19964 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
19965
19966 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
19967 &descriptor_set, 0, nullptr);
19968 m_errorMonitor->VerifyNotFound();
19969
19970 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
19971 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
19972 vkDestroySampler(m_device->device(), sampler, NULL);
19973 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
19974}
19975
Tobin Ehlisf7428442016-10-25 07:58:24 -060019976TEST_F(VkLayerTest, DuplicateDescriptorBinding) {
19977 TEST_DESCRIPTION("Create a descriptor set layout with a duplicate binding number.");
19978
Tony Barbour1fa09702017-03-16 12:09:08 -060019979 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisf7428442016-10-25 07:58:24 -060019980 // Create layout where two binding #s are "1"
19981 static const uint32_t NUM_BINDINGS = 3;
19982 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
19983 dsl_binding[0].binding = 1;
19984 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
19985 dsl_binding[0].descriptorCount = 1;
19986 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
19987 dsl_binding[0].pImmutableSamplers = NULL;
19988 dsl_binding[1].binding = 0;
19989 dsl_binding[1].descriptorCount = 1;
19990 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
19991 dsl_binding[1].descriptorCount = 1;
19992 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
19993 dsl_binding[1].pImmutableSamplers = NULL;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019994 dsl_binding[2].binding = 1; // Duplicate binding should cause error
Tobin Ehlisf7428442016-10-25 07:58:24 -060019995 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
19996 dsl_binding[2].descriptorCount = 1;
19997 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
19998 dsl_binding[2].pImmutableSamplers = NULL;
19999
20000 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
20001 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
20002 ds_layout_ci.pNext = NULL;
20003 ds_layout_ci.bindingCount = NUM_BINDINGS;
20004 ds_layout_ci.pBindings = dsl_binding;
20005 VkDescriptorSetLayout ds_layout;
20006 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02345);
20007 vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
20008 m_errorMonitor->VerifyFound();
20009}
20010
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060020011TEST_F(VkLayerTest, ViewportAndScissorBoundsChecking) {
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060020012 TEST_DESCRIPTION("Verify errors are detected on misuse of SetViewport and SetScissor.");
20013
Tony Barbour1fa09702017-03-16 12:09:08 -060020014 ASSERT_NO_FATAL_FAILURE(Init());
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060020015
Tony Barbour552f6c02016-12-21 14:34:07 -070020016 m_commandBuffer->BeginCommandBuffer();
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060020017
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060020018 const VkPhysicalDeviceLimits &limits = m_device->props.limits;
20019
20020 {
20021 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01448);
20022 VkViewport viewport = {0, 0, static_cast<float>(limits.maxViewportDimensions[0] + 1), 16, 0, 1};
20023 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
20024 m_errorMonitor->VerifyFound();
20025 }
20026
20027 {
20028 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01449);
20029 VkViewport viewport = {0, 0, 16, static_cast<float>(limits.maxViewportDimensions[1] + 1), 0, 1};
20030 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
20031 m_errorMonitor->VerifyFound();
20032 }
20033
20034 {
20035 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
20036 VkViewport viewport = {limits.viewportBoundsRange[0] - 1, 0, 16, 16, 0, 1};
20037 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
20038 m_errorMonitor->VerifyFound();
20039 }
20040
20041 {
20042 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
20043 VkViewport viewport = {0, limits.viewportBoundsRange[0] - 1, 16, 16, 0, 1};
20044 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
20045 m_errorMonitor->VerifyFound();
20046 }
20047
20048 {
20049 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01451);
20050 VkViewport viewport = {limits.viewportBoundsRange[1], 0, 16, 16, 0, 1};
20051 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
20052 m_errorMonitor->VerifyFound();
20053 }
20054
20055 {
20056 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01452);
20057 VkViewport viewport = {0, limits.viewportBoundsRange[1], 16, 16, 0, 1};
20058 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
20059 m_errorMonitor->VerifyFound();
20060 }
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060020061
20062 {
20063 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
20064 VkRect2D scissor = {{-1, 0}, {16, 16}};
20065 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
20066 m_errorMonitor->VerifyFound();
20067 }
20068
20069 {
20070 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
20071 VkRect2D scissor = {{0, -2}, {16, 16}};
20072 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
20073 m_errorMonitor->VerifyFound();
20074 }
20075
20076 {
20077 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01490);
20078 VkRect2D scissor = {{100, 100}, {INT_MAX, 16}};
20079 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
20080 m_errorMonitor->VerifyFound();
20081 }
20082
20083 {
20084 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01491);
20085 VkRect2D scissor = {{100, 100}, {16, INT_MAX}};
20086 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
20087 m_errorMonitor->VerifyFound();
20088 }
20089
Tony Barbour552f6c02016-12-21 14:34:07 -070020090 m_commandBuffer->EndCommandBuffer();
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060020091}
20092
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020093// This is a positive test. No failures are expected.
20094TEST_F(VkPositiveLayerTest, EmptyDescriptorUpdateTest) {
20095 TEST_DESCRIPTION("Update last descriptor in a set that includes an empty binding");
20096 VkResult err;
20097
Tony Barbour1fa09702017-03-16 12:09:08 -060020098 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020099 m_errorMonitor->ExpectSuccess();
20100 VkDescriptorPoolSize ds_type_count = {};
20101 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
20102 ds_type_count.descriptorCount = 2;
20103
20104 VkDescriptorPoolCreateInfo ds_pool_ci = {};
20105 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
20106 ds_pool_ci.pNext = NULL;
20107 ds_pool_ci.maxSets = 1;
20108 ds_pool_ci.poolSizeCount = 1;
20109 ds_pool_ci.pPoolSizes = &ds_type_count;
20110
20111 VkDescriptorPool ds_pool;
20112 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
20113 ASSERT_VK_SUCCESS(err);
20114
20115 // Create layout with two uniform buffer descriptors w/ empty binding between them
20116 static const uint32_t NUM_BINDINGS = 3;
20117 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
20118 dsl_binding[0].binding = 0;
20119 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
20120 dsl_binding[0].descriptorCount = 1;
20121 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
20122 dsl_binding[0].pImmutableSamplers = NULL;
20123 dsl_binding[1].binding = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020124 dsl_binding[1].descriptorCount = 0; // empty binding
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020125 dsl_binding[2].binding = 2;
20126 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
20127 dsl_binding[2].descriptorCount = 1;
20128 dsl_binding[2].stageFlags = VK_SHADER_STAGE_ALL;
20129 dsl_binding[2].pImmutableSamplers = NULL;
20130
20131 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
20132 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
20133 ds_layout_ci.pNext = NULL;
20134 ds_layout_ci.bindingCount = NUM_BINDINGS;
20135 ds_layout_ci.pBindings = dsl_binding;
20136 VkDescriptorSetLayout ds_layout;
20137 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
20138 ASSERT_VK_SUCCESS(err);
20139
20140 VkDescriptorSet descriptor_set = {};
20141 VkDescriptorSetAllocateInfo alloc_info = {};
20142 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
20143 alloc_info.descriptorSetCount = 1;
20144 alloc_info.descriptorPool = ds_pool;
20145 alloc_info.pSetLayouts = &ds_layout;
20146 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
20147 ASSERT_VK_SUCCESS(err);
20148
20149 // Create a buffer to be used for update
20150 VkBufferCreateInfo buff_ci = {};
20151 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
20152 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
20153 buff_ci.size = 256;
20154 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
20155 VkBuffer buffer;
20156 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
20157 ASSERT_VK_SUCCESS(err);
20158 // Have to bind memory to buffer before descriptor update
20159 VkMemoryAllocateInfo mem_alloc = {};
20160 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
20161 mem_alloc.pNext = NULL;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020162 mem_alloc.allocationSize = 512; // one allocation for both buffers
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020163 mem_alloc.memoryTypeIndex = 0;
20164
20165 VkMemoryRequirements mem_reqs;
20166 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
20167 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
20168 if (!pass) {
20169 vkDestroyBuffer(m_device->device(), buffer, NULL);
20170 return;
20171 }
20172
20173 VkDeviceMemory mem;
20174 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
20175 ASSERT_VK_SUCCESS(err);
20176 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
20177 ASSERT_VK_SUCCESS(err);
20178
20179 // Only update the descriptor at binding 2
20180 VkDescriptorBufferInfo buff_info = {};
20181 buff_info.buffer = buffer;
20182 buff_info.offset = 0;
20183 buff_info.range = VK_WHOLE_SIZE;
20184 VkWriteDescriptorSet descriptor_write = {};
20185 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
20186 descriptor_write.dstBinding = 2;
20187 descriptor_write.descriptorCount = 1;
20188 descriptor_write.pTexelBufferView = nullptr;
20189 descriptor_write.pBufferInfo = &buff_info;
20190 descriptor_write.pImageInfo = nullptr;
20191 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
20192 descriptor_write.dstSet = descriptor_set;
20193
20194 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
20195
20196 m_errorMonitor->VerifyNotFound();
20197 // Cleanup
20198 vkFreeMemory(m_device->device(), mem, NULL);
20199 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
20200 vkDestroyBuffer(m_device->device(), buffer, NULL);
20201 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
20202}
20203
20204// This is a positive test. No failures are expected.
20205TEST_F(VkPositiveLayerTest, TestAliasedMemoryTracking) {
20206 VkResult err;
20207 bool pass;
20208
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020209 TEST_DESCRIPTION(
20210 "Create a buffer, allocate memory, bind memory, destroy "
20211 "the buffer, create an image, and bind the same memory to "
20212 "it");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020213
20214 m_errorMonitor->ExpectSuccess();
20215
Tony Barbour1fa09702017-03-16 12:09:08 -060020216 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020217
20218 VkBuffer buffer;
20219 VkImage image;
20220 VkDeviceMemory mem;
20221 VkMemoryRequirements mem_reqs;
20222
20223 VkBufferCreateInfo buf_info = {};
20224 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
20225 buf_info.pNext = NULL;
20226 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
20227 buf_info.size = 256;
20228 buf_info.queueFamilyIndexCount = 0;
20229 buf_info.pQueueFamilyIndices = NULL;
20230 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
20231 buf_info.flags = 0;
20232 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
20233 ASSERT_VK_SUCCESS(err);
20234
20235 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
20236
20237 VkMemoryAllocateInfo alloc_info = {};
20238 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
20239 alloc_info.pNext = NULL;
20240 alloc_info.memoryTypeIndex = 0;
Dave Houlton9dae7ec2017-03-01 16:23:25 -070020241
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020242 // Ensure memory is big enough for both bindings
20243 alloc_info.allocationSize = 0x10000;
20244
20245 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
20246 if (!pass) {
20247 vkDestroyBuffer(m_device->device(), buffer, NULL);
20248 return;
20249 }
20250
20251 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
20252 ASSERT_VK_SUCCESS(err);
20253
20254 uint8_t *pData;
20255 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
20256 ASSERT_VK_SUCCESS(err);
20257
20258 memset(pData, 0xCADECADE, static_cast<size_t>(mem_reqs.size));
20259
20260 vkUnmapMemory(m_device->device(), mem);
20261
20262 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
20263 ASSERT_VK_SUCCESS(err);
20264
20265 // NOW, destroy the buffer. Obviously, the resource no longer occupies this
20266 // memory. In fact, it was never used by the GPU.
20267 // Just be be sure, wait for idle.
20268 vkDestroyBuffer(m_device->device(), buffer, NULL);
20269 vkDeviceWaitIdle(m_device->device());
20270
Tobin Ehlis6a005702016-12-28 15:25:56 -070020271 // Use optimal as some platforms report linear support but then fail image creation
20272 VkImageTiling image_tiling = VK_IMAGE_TILING_OPTIMAL;
20273 VkImageFormatProperties image_format_properties;
20274 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D, image_tiling,
20275 VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0, &image_format_properties);
20276 if (image_format_properties.maxExtent.width == 0) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070020277 printf(" Image format not supported; skipped.\n");
Tobin Ehlis6a005702016-12-28 15:25:56 -070020278 vkFreeMemory(m_device->device(), mem, NULL);
20279 return;
20280 }
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020281 VkImageCreateInfo image_create_info = {};
20282 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
20283 image_create_info.pNext = NULL;
20284 image_create_info.imageType = VK_IMAGE_TYPE_2D;
20285 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
20286 image_create_info.extent.width = 64;
20287 image_create_info.extent.height = 64;
20288 image_create_info.extent.depth = 1;
20289 image_create_info.mipLevels = 1;
20290 image_create_info.arrayLayers = 1;
20291 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis6a005702016-12-28 15:25:56 -070020292 image_create_info.tiling = image_tiling;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020293 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
20294 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
20295 image_create_info.queueFamilyIndexCount = 0;
20296 image_create_info.pQueueFamilyIndices = NULL;
20297 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
20298 image_create_info.flags = 0;
20299
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020300 /* Create a mappable image. It will be the texture if linear images are ok
Dave Houlton9dae7ec2017-03-01 16:23:25 -070020301 * to be textures or it will be the staging image if they are not.
20302 */
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020303 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
20304 ASSERT_VK_SUCCESS(err);
20305
20306 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
20307
Tobin Ehlis6a005702016-12-28 15:25:56 -070020308 VkMemoryAllocateInfo mem_alloc = {};
20309 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
20310 mem_alloc.pNext = NULL;
20311 mem_alloc.allocationSize = 0;
20312 mem_alloc.memoryTypeIndex = 0;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020313 mem_alloc.allocationSize = mem_reqs.size;
20314
20315 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
20316 if (!pass) {
Tobin Ehlis6a005702016-12-28 15:25:56 -070020317 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020318 vkDestroyImage(m_device->device(), image, NULL);
20319 return;
20320 }
20321
20322 // VALIDATION FAILURE:
20323 err = vkBindImageMemory(m_device->device(), image, mem, 0);
20324 ASSERT_VK_SUCCESS(err);
20325
20326 m_errorMonitor->VerifyNotFound();
20327
20328 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020329 vkDestroyImage(m_device->device(), image, NULL);
20330}
20331
Tony Barbourab713912017-02-02 14:17:35 -070020332// This is a positive test. No failures are expected.
20333TEST_F(VkPositiveLayerTest, TestDestroyFreeNullHandles) {
20334 VkResult err;
20335
20336 TEST_DESCRIPTION(
20337 "Call all applicable destroy and free routines with NULL"
20338 "handles, expecting no validation errors");
20339
20340 m_errorMonitor->ExpectSuccess();
20341
Tony Barbour1fa09702017-03-16 12:09:08 -060020342 ASSERT_NO_FATAL_FAILURE(Init());
Tony Barbourab713912017-02-02 14:17:35 -070020343 vkDestroyBuffer(m_device->device(), VK_NULL_HANDLE, NULL);
20344 vkDestroyBufferView(m_device->device(), VK_NULL_HANDLE, NULL);
20345 vkDestroyCommandPool(m_device->device(), VK_NULL_HANDLE, NULL);
20346 vkDestroyDescriptorPool(m_device->device(), VK_NULL_HANDLE, NULL);
20347 vkDestroyDescriptorSetLayout(m_device->device(), VK_NULL_HANDLE, NULL);
20348 vkDestroyDevice(VK_NULL_HANDLE, NULL);
20349 vkDestroyEvent(m_device->device(), VK_NULL_HANDLE, NULL);
20350 vkDestroyFence(m_device->device(), VK_NULL_HANDLE, NULL);
20351 vkDestroyFramebuffer(m_device->device(), VK_NULL_HANDLE, NULL);
20352 vkDestroyImage(m_device->device(), VK_NULL_HANDLE, NULL);
20353 vkDestroyImageView(m_device->device(), VK_NULL_HANDLE, NULL);
20354 vkDestroyInstance(VK_NULL_HANDLE, NULL);
20355 vkDestroyPipeline(m_device->device(), VK_NULL_HANDLE, NULL);
20356 vkDestroyPipelineCache(m_device->device(), VK_NULL_HANDLE, NULL);
20357 vkDestroyPipelineLayout(m_device->device(), VK_NULL_HANDLE, NULL);
20358 vkDestroyQueryPool(m_device->device(), VK_NULL_HANDLE, NULL);
20359 vkDestroyRenderPass(m_device->device(), VK_NULL_HANDLE, NULL);
20360 vkDestroySampler(m_device->device(), VK_NULL_HANDLE, NULL);
20361 vkDestroySemaphore(m_device->device(), VK_NULL_HANDLE, NULL);
20362 vkDestroyShaderModule(m_device->device(), VK_NULL_HANDLE, NULL);
20363
20364 VkCommandPool command_pool;
20365 VkCommandPoolCreateInfo pool_create_info{};
20366 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20367 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20368 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20369 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20370 VkCommandBuffer command_buffers[3] = {};
20371 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20372 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20373 command_buffer_allocate_info.commandPool = command_pool;
20374 command_buffer_allocate_info.commandBufferCount = 1;
20375 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20376 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffers[1]);
20377 vkFreeCommandBuffers(m_device->device(), command_pool, 3, command_buffers);
20378 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20379
20380 VkDescriptorPoolSize ds_type_count = {};
20381 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
20382 ds_type_count.descriptorCount = 1;
20383
20384 VkDescriptorPoolCreateInfo ds_pool_ci = {};
20385 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
20386 ds_pool_ci.pNext = NULL;
20387 ds_pool_ci.maxSets = 1;
20388 ds_pool_ci.poolSizeCount = 1;
20389 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
20390 ds_pool_ci.pPoolSizes = &ds_type_count;
20391
20392 VkDescriptorPool ds_pool;
20393 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
20394 ASSERT_VK_SUCCESS(err);
20395
20396 VkDescriptorSetLayoutBinding dsl_binding = {};
20397 dsl_binding.binding = 2;
20398 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
20399 dsl_binding.descriptorCount = 1;
20400 dsl_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
20401 dsl_binding.pImmutableSamplers = NULL;
20402 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
20403 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
20404 ds_layout_ci.pNext = NULL;
20405 ds_layout_ci.bindingCount = 1;
20406 ds_layout_ci.pBindings = &dsl_binding;
20407 VkDescriptorSetLayout ds_layout;
20408 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
20409 ASSERT_VK_SUCCESS(err);
20410
20411 VkDescriptorSet descriptor_sets[3] = {};
20412 VkDescriptorSetAllocateInfo alloc_info = {};
20413 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
20414 alloc_info.descriptorSetCount = 1;
20415 alloc_info.descriptorPool = ds_pool;
20416 alloc_info.pSetLayouts = &ds_layout;
20417 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_sets[1]);
20418 ASSERT_VK_SUCCESS(err);
20419 vkFreeDescriptorSets(m_device->device(), ds_pool, 3, descriptor_sets);
20420 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
20421 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
20422
20423 vkFreeMemory(m_device->device(), VK_NULL_HANDLE, NULL);
20424
20425 m_errorMonitor->VerifyNotFound();
20426}
20427
Tony Barbour626994c2017-02-08 15:29:37 -070020428TEST_F(VkPositiveLayerTest, QueueSubmitSemaphoresAndLayoutTracking) {
Tony Barboure0c5cc92017-02-08 13:53:39 -070020429 TEST_DESCRIPTION("Submit multiple command buffers with chained semaphore signals and layout transitions");
Tony Barbour626994c2017-02-08 15:29:37 -070020430
20431 m_errorMonitor->ExpectSuccess();
20432
Tony Barbour1fa09702017-03-16 12:09:08 -060020433 ASSERT_NO_FATAL_FAILURE(Init());
Tony Barbour626994c2017-02-08 15:29:37 -070020434 VkCommandBuffer cmd_bufs[4];
20435 VkCommandBufferAllocateInfo alloc_info;
20436 alloc_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20437 alloc_info.pNext = NULL;
20438 alloc_info.commandBufferCount = 4;
Mike Schuchardt06304c22017-03-01 17:09:09 -070020439 alloc_info.commandPool = m_commandPool->handle();
Tony Barbour626994c2017-02-08 15:29:37 -070020440 alloc_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20441 vkAllocateCommandBuffers(m_device->device(), &alloc_info, cmd_bufs);
20442 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060020443 image.Init(128, 128, 1, VK_FORMAT_B8G8R8A8_UNORM,
Mike Weiblen62d08a32017-03-07 22:18:27 -070020444 (VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT),
20445 VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbour626994c2017-02-08 15:29:37 -070020446 ASSERT_TRUE(image.initialized());
20447 VkCommandBufferBeginInfo cb_binfo;
20448 cb_binfo.pNext = NULL;
20449 cb_binfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20450 cb_binfo.pInheritanceInfo = VK_NULL_HANDLE;
20451 cb_binfo.flags = 0;
20452 // Use 4 command buffers, each with an image layout transition, ColorAO->General->ColorAO->TransferSrc->TransferDst
20453 vkBeginCommandBuffer(cmd_bufs[0], &cb_binfo);
20454 VkImageMemoryBarrier img_barrier = {};
20455 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
20456 img_barrier.pNext = NULL;
20457 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
20458 img_barrier.dstAccessMask = VK_ACCESS_HOST_WRITE_BIT;
20459 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
20460 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
20461 img_barrier.image = image.handle();
20462 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
20463 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
20464 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
20465 img_barrier.subresourceRange.baseArrayLayer = 0;
20466 img_barrier.subresourceRange.baseMipLevel = 0;
20467 img_barrier.subresourceRange.layerCount = 1;
20468 img_barrier.subresourceRange.levelCount = 1;
20469 vkCmdPipelineBarrier(cmd_bufs[0], VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 0, nullptr, 0, nullptr, 1,
20470 &img_barrier);
20471 vkEndCommandBuffer(cmd_bufs[0]);
20472 vkBeginCommandBuffer(cmd_bufs[1], &cb_binfo);
20473 img_barrier.oldLayout = VK_IMAGE_LAYOUT_GENERAL;
20474 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
20475 vkCmdPipelineBarrier(cmd_bufs[1], VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 0, nullptr, 0, nullptr, 1,
20476 &img_barrier);
20477 vkEndCommandBuffer(cmd_bufs[1]);
20478 vkBeginCommandBuffer(cmd_bufs[2], &cb_binfo);
20479 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
20480 img_barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
20481 vkCmdPipelineBarrier(cmd_bufs[2], VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 0, nullptr, 0, nullptr, 1,
20482 &img_barrier);
20483 vkEndCommandBuffer(cmd_bufs[2]);
20484 vkBeginCommandBuffer(cmd_bufs[3], &cb_binfo);
20485 img_barrier.oldLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
20486 img_barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
20487 vkCmdPipelineBarrier(cmd_bufs[3], VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 0, nullptr, 0, nullptr, 1,
20488 &img_barrier);
20489 vkEndCommandBuffer(cmd_bufs[3]);
20490
20491 // Submit 4 command buffers in 3 submits, with submits 2 and 3 waiting for semaphores from submits 1 and 2
20492 VkSemaphore semaphore1, semaphore2;
20493 VkSemaphoreCreateInfo semaphore_create_info{};
20494 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
20495 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore1);
20496 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore2);
20497 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
20498 VkSubmitInfo submit_info[3];
20499 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20500 submit_info[0].pNext = nullptr;
20501 submit_info[0].commandBufferCount = 1;
20502 submit_info[0].pCommandBuffers = &cmd_bufs[0];
20503 submit_info[0].signalSemaphoreCount = 1;
20504 submit_info[0].pSignalSemaphores = &semaphore1;
20505 submit_info[0].waitSemaphoreCount = 0;
20506 submit_info[0].pWaitDstStageMask = nullptr;
20507 submit_info[0].pWaitDstStageMask = flags;
20508 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20509 submit_info[1].pNext = nullptr;
20510 submit_info[1].commandBufferCount = 1;
20511 submit_info[1].pCommandBuffers = &cmd_bufs[1];
20512 submit_info[1].waitSemaphoreCount = 1;
20513 submit_info[1].pWaitSemaphores = &semaphore1;
20514 submit_info[1].signalSemaphoreCount = 1;
20515 submit_info[1].pSignalSemaphores = &semaphore2;
20516 submit_info[1].pWaitDstStageMask = flags;
20517 submit_info[2].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20518 submit_info[2].pNext = nullptr;
20519 submit_info[2].commandBufferCount = 2;
20520 submit_info[2].pCommandBuffers = &cmd_bufs[2];
20521 submit_info[2].waitSemaphoreCount = 1;
20522 submit_info[2].pWaitSemaphores = &semaphore2;
20523 submit_info[2].signalSemaphoreCount = 0;
20524 submit_info[2].pSignalSemaphores = nullptr;
20525 submit_info[2].pWaitDstStageMask = flags;
20526 vkQueueSubmit(m_device->m_queue, 3, submit_info, VK_NULL_HANDLE);
20527 vkQueueWaitIdle(m_device->m_queue);
20528
20529 vkDestroySemaphore(m_device->device(), semaphore1, NULL);
20530 vkDestroySemaphore(m_device->device(), semaphore2, NULL);
20531 m_errorMonitor->VerifyNotFound();
20532}
20533
Tobin Ehlis953e8392016-11-17 10:54:13 -070020534TEST_F(VkPositiveLayerTest, DynamicOffsetWithInactiveBinding) {
20535 // Create a descriptorSet w/ dynamic descriptors where 1 binding is inactive
20536 // We previously had a bug where dynamic offset of inactive bindings was still being used
20537 VkResult err;
20538 m_errorMonitor->ExpectSuccess();
20539
Tony Barbour1fa09702017-03-16 12:09:08 -060020540 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis953e8392016-11-17 10:54:13 -070020541 ASSERT_NO_FATAL_FAILURE(InitViewport());
20542 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20543
20544 VkDescriptorPoolSize ds_type_count = {};
20545 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
20546 ds_type_count.descriptorCount = 3;
20547
20548 VkDescriptorPoolCreateInfo ds_pool_ci = {};
20549 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
20550 ds_pool_ci.pNext = NULL;
20551 ds_pool_ci.maxSets = 1;
20552 ds_pool_ci.poolSizeCount = 1;
20553 ds_pool_ci.pPoolSizes = &ds_type_count;
20554
20555 VkDescriptorPool ds_pool;
20556 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
20557 ASSERT_VK_SUCCESS(err);
20558
20559 const uint32_t BINDING_COUNT = 3;
20560 VkDescriptorSetLayoutBinding dsl_binding[BINDING_COUNT] = {};
Tobin Ehlis0050fba2016-11-30 10:22:02 -070020561 dsl_binding[0].binding = 2;
Tobin Ehlis953e8392016-11-17 10:54:13 -070020562 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
20563 dsl_binding[0].descriptorCount = 1;
20564 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
20565 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis0050fba2016-11-30 10:22:02 -070020566 dsl_binding[1].binding = 0;
Tobin Ehlis953e8392016-11-17 10:54:13 -070020567 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
20568 dsl_binding[1].descriptorCount = 1;
20569 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
20570 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis0050fba2016-11-30 10:22:02 -070020571 dsl_binding[2].binding = 1;
Tobin Ehlis953e8392016-11-17 10:54:13 -070020572 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
20573 dsl_binding[2].descriptorCount = 1;
20574 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
20575 dsl_binding[2].pImmutableSamplers = NULL;
20576
20577 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
20578 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
20579 ds_layout_ci.pNext = NULL;
20580 ds_layout_ci.bindingCount = BINDING_COUNT;
20581 ds_layout_ci.pBindings = dsl_binding;
20582 VkDescriptorSetLayout ds_layout;
20583 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
20584 ASSERT_VK_SUCCESS(err);
20585
20586 VkDescriptorSet descriptor_set;
20587 VkDescriptorSetAllocateInfo alloc_info = {};
20588 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
20589 alloc_info.descriptorSetCount = 1;
20590 alloc_info.descriptorPool = ds_pool;
20591 alloc_info.pSetLayouts = &ds_layout;
20592 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
20593 ASSERT_VK_SUCCESS(err);
20594
20595 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
20596 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
20597 pipeline_layout_ci.pNext = NULL;
20598 pipeline_layout_ci.setLayoutCount = 1;
20599 pipeline_layout_ci.pSetLayouts = &ds_layout;
20600
20601 VkPipelineLayout pipeline_layout;
20602 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
20603 ASSERT_VK_SUCCESS(err);
20604
20605 // Create two buffers to update the descriptors with
20606 // The first will be 2k and used for bindings 0 & 1, the second is 1k for binding 2
20607 uint32_t qfi = 0;
20608 VkBufferCreateInfo buffCI = {};
20609 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
20610 buffCI.size = 2048;
20611 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
20612 buffCI.queueFamilyIndexCount = 1;
20613 buffCI.pQueueFamilyIndices = &qfi;
20614
20615 VkBuffer dyub1;
20616 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub1);
20617 ASSERT_VK_SUCCESS(err);
20618 // buffer2
20619 buffCI.size = 1024;
20620 VkBuffer dyub2;
20621 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub2);
20622 ASSERT_VK_SUCCESS(err);
20623 // Allocate memory and bind to buffers
20624 VkMemoryAllocateInfo mem_alloc[2] = {};
20625 mem_alloc[0].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
20626 mem_alloc[0].pNext = NULL;
20627 mem_alloc[0].memoryTypeIndex = 0;
20628 mem_alloc[1].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
20629 mem_alloc[1].pNext = NULL;
20630 mem_alloc[1].memoryTypeIndex = 0;
20631
20632 VkMemoryRequirements mem_reqs1;
20633 vkGetBufferMemoryRequirements(m_device->device(), dyub1, &mem_reqs1);
20634 VkMemoryRequirements mem_reqs2;
20635 vkGetBufferMemoryRequirements(m_device->device(), dyub2, &mem_reqs2);
20636 mem_alloc[0].allocationSize = mem_reqs1.size;
20637 bool pass = m_device->phy().set_memory_type(mem_reqs1.memoryTypeBits, &mem_alloc[0], 0);
20638 mem_alloc[1].allocationSize = mem_reqs2.size;
20639 pass &= m_device->phy().set_memory_type(mem_reqs2.memoryTypeBits, &mem_alloc[1], 0);
20640 if (!pass) {
20641 vkDestroyBuffer(m_device->device(), dyub1, NULL);
20642 vkDestroyBuffer(m_device->device(), dyub2, NULL);
20643 return;
20644 }
20645
20646 VkDeviceMemory mem1;
20647 err = vkAllocateMemory(m_device->device(), &mem_alloc[0], NULL, &mem1);
20648 ASSERT_VK_SUCCESS(err);
20649 err = vkBindBufferMemory(m_device->device(), dyub1, mem1, 0);
20650 ASSERT_VK_SUCCESS(err);
20651 VkDeviceMemory mem2;
20652 err = vkAllocateMemory(m_device->device(), &mem_alloc[1], NULL, &mem2);
20653 ASSERT_VK_SUCCESS(err);
20654 err = vkBindBufferMemory(m_device->device(), dyub2, mem2, 0);
20655 ASSERT_VK_SUCCESS(err);
20656 // Update descriptors
20657 VkDescriptorBufferInfo buff_info[BINDING_COUNT] = {};
20658 buff_info[0].buffer = dyub1;
20659 buff_info[0].offset = 0;
20660 buff_info[0].range = 256;
20661 buff_info[1].buffer = dyub1;
20662 buff_info[1].offset = 256;
20663 buff_info[1].range = 512;
20664 buff_info[2].buffer = dyub2;
20665 buff_info[2].offset = 0;
20666 buff_info[2].range = 512;
20667
20668 VkWriteDescriptorSet descriptor_write;
20669 memset(&descriptor_write, 0, sizeof(descriptor_write));
20670 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
20671 descriptor_write.dstSet = descriptor_set;
20672 descriptor_write.dstBinding = 0;
20673 descriptor_write.descriptorCount = BINDING_COUNT;
20674 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
20675 descriptor_write.pBufferInfo = buff_info;
20676
20677 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
20678
Tony Barbour552f6c02016-12-21 14:34:07 -070020679 m_commandBuffer->BeginCommandBuffer();
20680 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis953e8392016-11-17 10:54:13 -070020681
20682 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020683 char const *vsSource =
20684 "#version 450\n"
20685 "\n"
20686 "out gl_PerVertex { \n"
20687 " vec4 gl_Position;\n"
20688 "};\n"
20689 "void main(){\n"
20690 " gl_Position = vec4(1);\n"
20691 "}\n";
20692 char const *fsSource =
20693 "#version 450\n"
20694 "\n"
20695 "layout(location=0) out vec4 x;\n"
20696 "layout(set=0) layout(binding=0) uniform foo1 { int x; int y; } bar1;\n"
20697 "layout(set=0) layout(binding=2) uniform foo2 { int x; int y; } bar2;\n"
20698 "void main(){\n"
20699 " x = vec4(bar1.y) + vec4(bar2.y);\n"
20700 "}\n";
Tobin Ehlis953e8392016-11-17 10:54:13 -070020701 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
20702 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
20703 VkPipelineObj pipe(m_device);
20704 pipe.SetViewport(m_viewports);
20705 pipe.SetScissor(m_scissors);
20706 pipe.AddShader(&vs);
20707 pipe.AddShader(&fs);
20708 pipe.AddColorAttachment();
20709 pipe.CreateVKPipeline(pipeline_layout, renderPass());
20710
20711 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
20712 // This update should succeed, but offset of inactive binding 1 oversteps binding 2 buffer size
20713 // we used to have a bug in this case.
20714 uint32_t dyn_off[BINDING_COUNT] = {0, 1024, 256};
20715 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
20716 &descriptor_set, BINDING_COUNT, dyn_off);
20717 Draw(1, 0, 0, 0);
20718 m_errorMonitor->VerifyNotFound();
20719
20720 vkDestroyBuffer(m_device->device(), dyub1, NULL);
20721 vkDestroyBuffer(m_device->device(), dyub2, NULL);
20722 vkFreeMemory(m_device->device(), mem1, NULL);
20723 vkFreeMemory(m_device->device(), mem2, NULL);
20724
20725 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
20726 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
20727 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
20728}
20729
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020730TEST_F(VkPositiveLayerTest, NonCoherentMemoryMapping) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020731 TEST_DESCRIPTION(
20732 "Ensure that validations handling of non-coherent memory "
20733 "mapping while using VK_WHOLE_SIZE does not cause access "
20734 "violations");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020735 VkResult err;
20736 uint8_t *pData;
Tony Barbour1fa09702017-03-16 12:09:08 -060020737 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020738
20739 VkDeviceMemory mem;
20740 VkMemoryRequirements mem_reqs;
20741 mem_reqs.memoryTypeBits = 0xFFFFFFFF;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070020742 const VkDeviceSize atom_size = m_device->props.limits.nonCoherentAtomSize;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020743 VkMemoryAllocateInfo alloc_info = {};
20744 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
20745 alloc_info.pNext = NULL;
20746 alloc_info.memoryTypeIndex = 0;
20747
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070020748 static const VkDeviceSize allocation_size = 32 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020749 alloc_info.allocationSize = allocation_size;
20750
20751 // Find a memory configurations WITHOUT a COHERENT bit, otherwise exit
20752 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 -070020753 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020754 if (!pass) {
20755 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020756 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
20757 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020758 if (!pass) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020759 pass = m_device->phy().set_memory_type(
20760 mem_reqs.memoryTypeBits, &alloc_info,
20761 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT | VK_MEMORY_PROPERTY_HOST_CACHED_BIT,
20762 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020763 if (!pass) {
20764 return;
20765 }
20766 }
20767 }
20768
20769 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
20770 ASSERT_VK_SUCCESS(err);
20771
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070020772 // Map/Flush/Invalidate using WHOLE_SIZE and zero offsets and entire mapped range
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020773 m_errorMonitor->ExpectSuccess();
20774 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
20775 ASSERT_VK_SUCCESS(err);
20776 VkMappedMemoryRange mmr = {};
20777 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
20778 mmr.memory = mem;
20779 mmr.offset = 0;
20780 mmr.size = VK_WHOLE_SIZE;
20781 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
20782 ASSERT_VK_SUCCESS(err);
20783 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
20784 ASSERT_VK_SUCCESS(err);
20785 m_errorMonitor->VerifyNotFound();
20786 vkUnmapMemory(m_device->device(), mem);
20787
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070020788 // Map/Flush/Invalidate using WHOLE_SIZE and an offset and entire mapped range
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020789 m_errorMonitor->ExpectSuccess();
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070020790 err = vkMapMemory(m_device->device(), mem, 5 * atom_size, VK_WHOLE_SIZE, 0, (void **)&pData);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020791 ASSERT_VK_SUCCESS(err);
20792 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
20793 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070020794 mmr.offset = 6 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020795 mmr.size = VK_WHOLE_SIZE;
20796 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
20797 ASSERT_VK_SUCCESS(err);
20798 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
20799 ASSERT_VK_SUCCESS(err);
20800 m_errorMonitor->VerifyNotFound();
20801 vkUnmapMemory(m_device->device(), mem);
20802
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070020803 // Map with offset and size
20804 // Flush/Invalidate subrange of mapped area with offset and size
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020805 m_errorMonitor->ExpectSuccess();
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070020806 err = vkMapMemory(m_device->device(), mem, 3 * atom_size, 9 * atom_size, 0, (void **)&pData);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020807 ASSERT_VK_SUCCESS(err);
20808 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
20809 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070020810 mmr.offset = 4 * atom_size;
20811 mmr.size = 2 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020812 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
20813 ASSERT_VK_SUCCESS(err);
20814 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
20815 ASSERT_VK_SUCCESS(err);
20816 m_errorMonitor->VerifyNotFound();
20817 vkUnmapMemory(m_device->device(), mem);
20818
20819 // Map without offset and flush WHOLE_SIZE with two separate offsets
20820 m_errorMonitor->ExpectSuccess();
20821 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
20822 ASSERT_VK_SUCCESS(err);
20823 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
20824 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070020825 mmr.offset = allocation_size - (4 * atom_size);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020826 mmr.size = VK_WHOLE_SIZE;
20827 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
20828 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070020829 mmr.offset = allocation_size - (6 * atom_size);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020830 mmr.size = VK_WHOLE_SIZE;
20831 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
20832 ASSERT_VK_SUCCESS(err);
20833 m_errorMonitor->VerifyNotFound();
20834 vkUnmapMemory(m_device->device(), mem);
20835
20836 vkFreeMemory(m_device->device(), mem, NULL);
20837}
20838
20839// This is a positive test. We used to expect error in this case but spec now allows it
20840TEST_F(VkPositiveLayerTest, ResetUnsignaledFence) {
20841 m_errorMonitor->ExpectSuccess();
20842 vk_testing::Fence testFence;
20843 VkFenceCreateInfo fenceInfo = {};
20844 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
20845 fenceInfo.pNext = NULL;
20846
Tony Barbour1fa09702017-03-16 12:09:08 -060020847 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020848 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020849 VkFence fences[1] = {testFence.handle()};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020850 VkResult result = vkResetFences(m_device->device(), 1, fences);
20851 ASSERT_VK_SUCCESS(result);
20852
20853 m_errorMonitor->VerifyNotFound();
20854}
20855
20856TEST_F(VkPositiveLayerTest, CommandBufferSimultaneousUseSync) {
20857 m_errorMonitor->ExpectSuccess();
20858
Tony Barbour1fa09702017-03-16 12:09:08 -060020859 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020860 VkResult err;
20861
20862 // Record (empty!) command buffer that can be submitted multiple times
20863 // simultaneously.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020864 VkCommandBufferBeginInfo cbbi = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
20865 VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020866 m_commandBuffer->BeginCommandBuffer(&cbbi);
20867 m_commandBuffer->EndCommandBuffer();
20868
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020869 VkFenceCreateInfo fci = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020870 VkFence fence;
20871 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
20872 ASSERT_VK_SUCCESS(err);
20873
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020874 VkSemaphoreCreateInfo sci = {VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020875 VkSemaphore s1, s2;
20876 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s1);
20877 ASSERT_VK_SUCCESS(err);
20878 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s2);
20879 ASSERT_VK_SUCCESS(err);
20880
20881 // Submit CB once signaling s1, with fence so we can roll forward to its retirement.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020882 VkSubmitInfo si = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &m_commandBuffer->handle(), 1, &s1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020883 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
20884 ASSERT_VK_SUCCESS(err);
20885
20886 // Submit CB again, signaling s2.
20887 si.pSignalSemaphores = &s2;
20888 err = vkQueueSubmit(m_device->m_queue, 1, &si, VK_NULL_HANDLE);
20889 ASSERT_VK_SUCCESS(err);
20890
20891 // Wait for fence.
20892 err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
20893 ASSERT_VK_SUCCESS(err);
20894
20895 // CB is still in flight from second submission, but semaphore s1 is no
20896 // longer in flight. delete it.
20897 vkDestroySemaphore(m_device->device(), s1, nullptr);
20898
20899 m_errorMonitor->VerifyNotFound();
20900
20901 // Force device idle and clean up remaining objects
20902 vkDeviceWaitIdle(m_device->device());
20903 vkDestroySemaphore(m_device->device(), s2, nullptr);
20904 vkDestroyFence(m_device->device(), fence, nullptr);
20905}
20906
20907TEST_F(VkPositiveLayerTest, FenceCreateSignaledWaitHandling) {
20908 m_errorMonitor->ExpectSuccess();
20909
Tony Barbour1fa09702017-03-16 12:09:08 -060020910 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020911 VkResult err;
20912
20913 // A fence created signaled
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020914 VkFenceCreateInfo fci1 = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, VK_FENCE_CREATE_SIGNALED_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020915 VkFence f1;
20916 err = vkCreateFence(m_device->device(), &fci1, nullptr, &f1);
20917 ASSERT_VK_SUCCESS(err);
20918
20919 // A fence created not
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020920 VkFenceCreateInfo fci2 = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020921 VkFence f2;
20922 err = vkCreateFence(m_device->device(), &fci2, nullptr, &f2);
20923 ASSERT_VK_SUCCESS(err);
20924
20925 // Submit the unsignaled fence
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020926 VkSubmitInfo si = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 0, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020927 err = vkQueueSubmit(m_device->m_queue, 1, &si, f2);
20928
20929 // Wait on both fences, with signaled first.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020930 VkFence fences[] = {f1, f2};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020931 vkWaitForFences(m_device->device(), 2, fences, VK_TRUE, UINT64_MAX);
20932
20933 // Should have both retired!
20934 vkDestroyFence(m_device->device(), f1, nullptr);
20935 vkDestroyFence(m_device->device(), f2, nullptr);
20936
20937 m_errorMonitor->VerifyNotFound();
20938}
20939
20940TEST_F(VkPositiveLayerTest, ValidUsage) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020941 TEST_DESCRIPTION(
20942 "Verify that creating an image view from an image with valid usage "
20943 "doesn't generate validation errors");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020944
Tony Barbour1fa09702017-03-16 12:09:08 -060020945 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020946
20947 m_errorMonitor->ExpectSuccess();
20948 // Verify that we can create a view with usage INPUT_ATTACHMENT
20949 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060020950 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 -060020951 ASSERT_TRUE(image.initialized());
20952 VkImageView imageView;
20953 VkImageViewCreateInfo ivci = {};
20954 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
20955 ivci.image = image.handle();
20956 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
20957 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
20958 ivci.subresourceRange.layerCount = 1;
20959 ivci.subresourceRange.baseMipLevel = 0;
20960 ivci.subresourceRange.levelCount = 1;
20961 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
20962
20963 vkCreateImageView(m_device->device(), &ivci, NULL, &imageView);
20964 m_errorMonitor->VerifyNotFound();
20965 vkDestroyImageView(m_device->device(), imageView, NULL);
20966}
20967
20968// This is a positive test. No failures are expected.
20969TEST_F(VkPositiveLayerTest, BindSparse) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020970 TEST_DESCRIPTION(
20971 "Bind 2 memory ranges to one image using vkQueueBindSparse, destroy the image"
20972 "and then free the memory");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020973
Tony Barbour1fa09702017-03-16 12:09:08 -060020974 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020975
20976 auto index = m_device->graphics_queue_node_index_;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020977 if (!(m_device->queue_props[index].queueFlags & VK_QUEUE_SPARSE_BINDING_BIT)) return;
Tony Barbour623721f2017-03-24 15:00:21 -060020978 if (!m_device->phy().features().sparseBinding) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020979
20980 m_errorMonitor->ExpectSuccess();
20981
20982 VkImage image;
20983 VkImageCreateInfo image_create_info = {};
20984 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
20985 image_create_info.pNext = NULL;
20986 image_create_info.imageType = VK_IMAGE_TYPE_2D;
20987 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
20988 image_create_info.extent.width = 64;
20989 image_create_info.extent.height = 64;
20990 image_create_info.extent.depth = 1;
20991 image_create_info.mipLevels = 1;
20992 image_create_info.arrayLayers = 1;
20993 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
20994 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
20995 image_create_info.usage = VK_IMAGE_USAGE_STORAGE_BIT;
20996 image_create_info.flags = VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
20997 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
20998 ASSERT_VK_SUCCESS(err);
20999
21000 VkMemoryRequirements memory_reqs;
21001 VkDeviceMemory memory_one, memory_two;
21002 bool pass;
21003 VkMemoryAllocateInfo memory_info = {};
21004 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
21005 memory_info.pNext = NULL;
21006 memory_info.allocationSize = 0;
21007 memory_info.memoryTypeIndex = 0;
21008 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
21009 // Find an image big enough to allow sparse mapping of 2 memory regions
21010 // Increase the image size until it is at least twice the
21011 // size of the required alignment, to ensure we can bind both
21012 // allocated memory blocks to the image on aligned offsets.
21013 while (memory_reqs.size < (memory_reqs.alignment * 2)) {
21014 vkDestroyImage(m_device->device(), image, nullptr);
21015 image_create_info.extent.width *= 2;
21016 image_create_info.extent.height *= 2;
21017 err = vkCreateImage(m_device->device(), &image_create_info, nullptr, &image);
21018 ASSERT_VK_SUCCESS(err);
21019 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
21020 }
21021 // Allocate 2 memory regions of minimum alignment size, bind one at 0, the other
21022 // at the end of the first
21023 memory_info.allocationSize = memory_reqs.alignment;
21024 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
21025 ASSERT_TRUE(pass);
21026 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_one);
21027 ASSERT_VK_SUCCESS(err);
21028 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_two);
21029 ASSERT_VK_SUCCESS(err);
21030 VkSparseMemoryBind binds[2];
21031 binds[0].flags = 0;
21032 binds[0].memory = memory_one;
21033 binds[0].memoryOffset = 0;
21034 binds[0].resourceOffset = 0;
21035 binds[0].size = memory_info.allocationSize;
21036 binds[1].flags = 0;
21037 binds[1].memory = memory_two;
21038 binds[1].memoryOffset = 0;
21039 binds[1].resourceOffset = memory_info.allocationSize;
21040 binds[1].size = memory_info.allocationSize;
21041
21042 VkSparseImageOpaqueMemoryBindInfo opaqueBindInfo;
21043 opaqueBindInfo.image = image;
21044 opaqueBindInfo.bindCount = 2;
21045 opaqueBindInfo.pBinds = binds;
21046
21047 VkFence fence = VK_NULL_HANDLE;
21048 VkBindSparseInfo bindSparseInfo = {};
21049 bindSparseInfo.sType = VK_STRUCTURE_TYPE_BIND_SPARSE_INFO;
21050 bindSparseInfo.imageOpaqueBindCount = 1;
21051 bindSparseInfo.pImageOpaqueBinds = &opaqueBindInfo;
21052
21053 vkQueueBindSparse(m_device->m_queue, 1, &bindSparseInfo, fence);
21054 vkQueueWaitIdle(m_device->m_queue);
21055 vkDestroyImage(m_device->device(), image, NULL);
21056 vkFreeMemory(m_device->device(), memory_one, NULL);
21057 vkFreeMemory(m_device->device(), memory_two, NULL);
21058 m_errorMonitor->VerifyNotFound();
21059}
21060
21061TEST_F(VkPositiveLayerTest, RenderPassInitialLayoutUndefined) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021062 TEST_DESCRIPTION(
21063 "Ensure that CmdBeginRenderPass with an attachment's "
21064 "initialLayout of VK_IMAGE_LAYOUT_UNDEFINED works when "
21065 "the command buffer has prior knowledge of that "
21066 "attachment's layout.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021067
21068 m_errorMonitor->ExpectSuccess();
21069
Tony Barbour1fa09702017-03-16 12:09:08 -060021070 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021071
21072 // A renderpass with one color attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021073 VkAttachmentDescription attachment = {0,
21074 VK_FORMAT_R8G8B8A8_UNORM,
21075 VK_SAMPLE_COUNT_1_BIT,
21076 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
21077 VK_ATTACHMENT_STORE_OP_STORE,
21078 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
21079 VK_ATTACHMENT_STORE_OP_DONT_CARE,
21080 VK_IMAGE_LAYOUT_UNDEFINED,
21081 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021082
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021083 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021084
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021085 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021086
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021087 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021088
21089 VkRenderPass rp;
21090 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
21091 ASSERT_VK_SUCCESS(err);
21092
21093 // A compatible framebuffer.
21094 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060021095 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 -060021096 ASSERT_TRUE(image.initialized());
21097
21098 VkImageViewCreateInfo ivci = {
21099 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
21100 nullptr,
21101 0,
21102 image.handle(),
21103 VK_IMAGE_VIEW_TYPE_2D,
21104 VK_FORMAT_R8G8B8A8_UNORM,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021105 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
21106 VK_COMPONENT_SWIZZLE_IDENTITY},
21107 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021108 };
21109 VkImageView view;
21110 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
21111 ASSERT_VK_SUCCESS(err);
21112
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021113 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021114 VkFramebuffer fb;
21115 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
21116 ASSERT_VK_SUCCESS(err);
21117
21118 // Record a single command buffer which uses this renderpass twice. The
21119 // bug is triggered at the beginning of the second renderpass, when the
21120 // command buffer already has a layout recorded for the attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021121 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 -070021122 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021123 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
21124 vkCmdEndRenderPass(m_commandBuffer->handle());
21125 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
21126
21127 m_errorMonitor->VerifyNotFound();
21128
21129 vkCmdEndRenderPass(m_commandBuffer->handle());
Tony Barbour552f6c02016-12-21 14:34:07 -070021130 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021131
21132 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
21133 vkDestroyRenderPass(m_device->device(), rp, nullptr);
21134 vkDestroyImageView(m_device->device(), view, nullptr);
21135}
21136
21137TEST_F(VkPositiveLayerTest, FramebufferBindingDestroyCommandPool) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021138 TEST_DESCRIPTION(
21139 "This test should pass. Create a Framebuffer and "
21140 "command buffer, bind them together, then destroy "
21141 "command pool and framebuffer and verify there are no "
21142 "errors.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021143
21144 m_errorMonitor->ExpectSuccess();
21145
Tony Barbour1fa09702017-03-16 12:09:08 -060021146 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021147
21148 // A renderpass with one color attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021149 VkAttachmentDescription attachment = {0,
21150 VK_FORMAT_R8G8B8A8_UNORM,
21151 VK_SAMPLE_COUNT_1_BIT,
21152 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
21153 VK_ATTACHMENT_STORE_OP_STORE,
21154 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
21155 VK_ATTACHMENT_STORE_OP_DONT_CARE,
21156 VK_IMAGE_LAYOUT_UNDEFINED,
21157 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021158
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021159 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021160
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021161 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021162
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021163 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021164
21165 VkRenderPass rp;
21166 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
21167 ASSERT_VK_SUCCESS(err);
21168
21169 // A compatible framebuffer.
21170 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060021171 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 -060021172 ASSERT_TRUE(image.initialized());
21173
21174 VkImageViewCreateInfo ivci = {
21175 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
21176 nullptr,
21177 0,
21178 image.handle(),
21179 VK_IMAGE_VIEW_TYPE_2D,
21180 VK_FORMAT_R8G8B8A8_UNORM,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021181 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
21182 VK_COMPONENT_SWIZZLE_IDENTITY},
21183 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021184 };
21185 VkImageView view;
21186 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
21187 ASSERT_VK_SUCCESS(err);
21188
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021189 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021190 VkFramebuffer fb;
21191 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
21192 ASSERT_VK_SUCCESS(err);
21193
21194 // Explicitly create a command buffer to bind the FB to so that we can then
21195 // destroy the command pool in order to implicitly free command buffer
21196 VkCommandPool command_pool;
21197 VkCommandPoolCreateInfo pool_create_info{};
21198 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
21199 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
21200 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
21201 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
21202
21203 VkCommandBuffer command_buffer;
21204 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
21205 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
21206 command_buffer_allocate_info.commandPool = command_pool;
21207 command_buffer_allocate_info.commandBufferCount = 1;
21208 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
21209 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
21210
21211 // Begin our cmd buffer with renderpass using our framebuffer
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021212 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 -060021213 VkCommandBufferBeginInfo begin_info{};
21214 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21215 vkBeginCommandBuffer(command_buffer, &begin_info);
21216
21217 vkCmdBeginRenderPass(command_buffer, &rpbi, VK_SUBPASS_CONTENTS_INLINE);
21218 vkCmdEndRenderPass(command_buffer);
21219 vkEndCommandBuffer(command_buffer);
21220 vkDestroyImageView(m_device->device(), view, nullptr);
21221 // Destroy command pool to implicitly free command buffer
21222 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
21223 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
21224 vkDestroyRenderPass(m_device->device(), rp, nullptr);
21225 m_errorMonitor->VerifyNotFound();
21226}
21227
21228TEST_F(VkPositiveLayerTest, RenderPassSubpassZeroTransitionsApplied) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021229 TEST_DESCRIPTION(
21230 "Ensure that CmdBeginRenderPass applies the layout "
21231 "transitions for the first subpass");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021232
21233 m_errorMonitor->ExpectSuccess();
21234
Tony Barbour1fa09702017-03-16 12:09:08 -060021235 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021236
21237 // A renderpass with one color attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021238 VkAttachmentDescription attachment = {0,
21239 VK_FORMAT_R8G8B8A8_UNORM,
21240 VK_SAMPLE_COUNT_1_BIT,
21241 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
21242 VK_ATTACHMENT_STORE_OP_STORE,
21243 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
21244 VK_ATTACHMENT_STORE_OP_DONT_CARE,
21245 VK_IMAGE_LAYOUT_UNDEFINED,
21246 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021247
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021248 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021249
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021250 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021251
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021252 VkSubpassDependency dep = {0,
21253 0,
21254 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
21255 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
21256 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
21257 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
21258 VK_DEPENDENCY_BY_REGION_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021259
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021260 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021261
21262 VkResult err;
21263 VkRenderPass rp;
21264 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
21265 ASSERT_VK_SUCCESS(err);
21266
21267 // A compatible framebuffer.
21268 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060021269 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 -060021270 ASSERT_TRUE(image.initialized());
21271
21272 VkImageViewCreateInfo ivci = {
21273 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
21274 nullptr,
21275 0,
21276 image.handle(),
21277 VK_IMAGE_VIEW_TYPE_2D,
21278 VK_FORMAT_R8G8B8A8_UNORM,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021279 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
21280 VK_COMPONENT_SWIZZLE_IDENTITY},
21281 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021282 };
21283 VkImageView view;
21284 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
21285 ASSERT_VK_SUCCESS(err);
21286
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021287 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021288 VkFramebuffer fb;
21289 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
21290 ASSERT_VK_SUCCESS(err);
21291
21292 // Record a single command buffer which issues a pipeline barrier w/
21293 // image memory barrier for the attachment. This detects the previously
21294 // missing tracking of the subpass layout by throwing a validation error
21295 // if it doesn't occur.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021296 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 -070021297 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021298 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
21299
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021300 VkImageMemoryBarrier imb = {VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
21301 nullptr,
21302 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
21303 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
21304 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
21305 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
21306 VK_QUEUE_FAMILY_IGNORED,
21307 VK_QUEUE_FAMILY_IGNORED,
21308 image.handle(),
21309 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1}};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021310 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021311 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
21312 &imb);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021313
21314 vkCmdEndRenderPass(m_commandBuffer->handle());
21315 m_errorMonitor->VerifyNotFound();
Tony Barbour552f6c02016-12-21 14:34:07 -070021316 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021317
21318 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
21319 vkDestroyRenderPass(m_device->device(), rp, nullptr);
21320 vkDestroyImageView(m_device->device(), view, nullptr);
21321}
21322
21323TEST_F(VkPositiveLayerTest, DepthStencilLayoutTransitionForDepthOnlyImageview) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021324 TEST_DESCRIPTION(
21325 "Validate that when an imageView of a depth/stencil image "
21326 "is used as a depth/stencil framebuffer attachment, the "
21327 "aspectMask is ignored and both depth and stencil image "
21328 "subresources are used.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021329
Tony Barbour1fa09702017-03-16 12:09:08 -060021330 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021331 VkFormatProperties format_properties;
21332 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_D32_SFLOAT_S8_UINT, &format_properties);
21333 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
21334 return;
21335 }
21336
21337 m_errorMonitor->ExpectSuccess();
21338
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021339 VkAttachmentDescription attachment = {0,
21340 VK_FORMAT_D32_SFLOAT_S8_UINT,
21341 VK_SAMPLE_COUNT_1_BIT,
21342 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
21343 VK_ATTACHMENT_STORE_OP_STORE,
21344 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
21345 VK_ATTACHMENT_STORE_OP_DONT_CARE,
21346 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
21347 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021348
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021349 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021350
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021351 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, &att_ref, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021352
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021353 VkSubpassDependency dep = {0,
21354 0,
21355 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
21356 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
21357 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
21358 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
21359 VK_DEPENDENCY_BY_REGION_BIT};
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, 1, &attachment, 1, &subpass, 1, &dep};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021362
21363 VkResult err;
21364 VkRenderPass rp;
21365 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
21366 ASSERT_VK_SUCCESS(err);
21367
21368 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060021369 image.InitNoLayout(32, 32, 1, VK_FORMAT_D32_SFLOAT_S8_UINT,
21370 0x26, // usage
21371 VK_IMAGE_TILING_OPTIMAL, 0);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021372 ASSERT_TRUE(image.initialized());
21373 image.SetLayout(0x6, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
21374
21375 VkImageViewCreateInfo ivci = {
21376 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
21377 nullptr,
21378 0,
21379 image.handle(),
21380 VK_IMAGE_VIEW_TYPE_2D,
21381 VK_FORMAT_D32_SFLOAT_S8_UINT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021382 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
21383 {0x2, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021384 };
21385 VkImageView view;
21386 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
21387 ASSERT_VK_SUCCESS(err);
21388
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021389 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021390 VkFramebuffer fb;
21391 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
21392 ASSERT_VK_SUCCESS(err);
21393
Tony Barbour552f6c02016-12-21 14:34:07 -070021394 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021395
21396 VkImageMemoryBarrier imb = {};
21397 imb.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
21398 imb.pNext = nullptr;
21399 imb.srcAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
21400 imb.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
21401 imb.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
21402 imb.newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
21403 imb.srcQueueFamilyIndex = 0;
21404 imb.dstQueueFamilyIndex = 0;
21405 imb.image = image.handle();
21406 imb.subresourceRange.aspectMask = 0x6;
21407 imb.subresourceRange.baseMipLevel = 0;
21408 imb.subresourceRange.levelCount = 0x1;
21409 imb.subresourceRange.baseArrayLayer = 0;
21410 imb.subresourceRange.layerCount = 0x1;
21411
21412 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021413 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
21414 &imb);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021415
Tony Barbour552f6c02016-12-21 14:34:07 -070021416 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021417 QueueCommandBuffer(false);
21418 m_errorMonitor->VerifyNotFound();
21419
21420 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
21421 vkDestroyRenderPass(m_device->device(), rp, nullptr);
21422 vkDestroyImageView(m_device->device(), view, nullptr);
21423}
21424
21425TEST_F(VkPositiveLayerTest, RenderPassTransitionsAttachmentUnused) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021426 TEST_DESCRIPTION(
21427 "Ensure that layout transitions work correctly without "
21428 "errors, when an attachment reference is "
21429 "VK_ATTACHMENT_UNUSED");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021430
21431 m_errorMonitor->ExpectSuccess();
21432
Tony Barbour1fa09702017-03-16 12:09:08 -060021433 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021434
21435 // A renderpass with no attachments
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021436 VkAttachmentReference att_ref = {VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021437
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021438 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021439
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021440 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 1, &subpass, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021441
21442 VkRenderPass rp;
21443 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
21444 ASSERT_VK_SUCCESS(err);
21445
21446 // A compatible framebuffer.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021447 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021448 VkFramebuffer fb;
21449 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
21450 ASSERT_VK_SUCCESS(err);
21451
21452 // Record a command buffer which just begins and ends the renderpass. The
21453 // bug manifests in BeginRenderPass.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021454 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 -070021455 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021456 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
21457 vkCmdEndRenderPass(m_commandBuffer->handle());
21458 m_errorMonitor->VerifyNotFound();
Tony Barbour552f6c02016-12-21 14:34:07 -070021459 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021460
21461 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
21462 vkDestroyRenderPass(m_device->device(), rp, nullptr);
21463}
21464
21465// This is a positive test. No errors are expected.
21466TEST_F(VkPositiveLayerTest, StencilLoadOp) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021467 TEST_DESCRIPTION(
21468 "Create a stencil-only attachment with a LOAD_OP set to "
21469 "CLEAR. stencil[Load|Store]Op used to be ignored.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021470 VkResult result = VK_SUCCESS;
Tony Barbour1fa09702017-03-16 12:09:08 -060021471 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -060021472 auto depth_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbourf887b162017-03-09 10:06:46 -070021473 if (!depth_format) {
21474 printf(" No Depth + Stencil format found. Skipped.\n");
21475 return;
21476 }
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021477 VkImageFormatProperties formatProps;
Tony Barbourf887b162017-03-09 10:06:46 -070021478 vkGetPhysicalDeviceImageFormatProperties(gpu(), depth_format, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021479 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0,
21480 &formatProps);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021481 if (formatProps.maxExtent.width < 100 || formatProps.maxExtent.height < 100) {
21482 return;
21483 }
21484
Tony Barbourf887b162017-03-09 10:06:46 -070021485 VkFormat depth_stencil_fmt = depth_format;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021486 m_depthStencil->Init(m_device, 100, 100, depth_stencil_fmt,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021487 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021488 VkAttachmentDescription att = {};
21489 VkAttachmentReference ref = {};
21490 att.format = depth_stencil_fmt;
21491 att.samples = VK_SAMPLE_COUNT_1_BIT;
21492 att.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
21493 att.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
21494 att.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
21495 att.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE;
21496 att.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
21497 att.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
21498
21499 VkClearValue clear;
21500 clear.depthStencil.depth = 1.0;
21501 clear.depthStencil.stencil = 0;
21502 ref.attachment = 0;
21503 ref.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
21504
21505 VkSubpassDescription subpass = {};
21506 subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
21507 subpass.flags = 0;
21508 subpass.inputAttachmentCount = 0;
21509 subpass.pInputAttachments = NULL;
21510 subpass.colorAttachmentCount = 0;
21511 subpass.pColorAttachments = NULL;
21512 subpass.pResolveAttachments = NULL;
21513 subpass.pDepthStencilAttachment = &ref;
21514 subpass.preserveAttachmentCount = 0;
21515 subpass.pPreserveAttachments = NULL;
21516
21517 VkRenderPass rp;
21518 VkRenderPassCreateInfo rp_info = {};
21519 rp_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
21520 rp_info.attachmentCount = 1;
21521 rp_info.pAttachments = &att;
21522 rp_info.subpassCount = 1;
21523 rp_info.pSubpasses = &subpass;
21524 result = vkCreateRenderPass(device(), &rp_info, NULL, &rp);
21525 ASSERT_VK_SUCCESS(result);
21526
21527 VkImageView *depthView = m_depthStencil->BindInfo();
21528 VkFramebufferCreateInfo fb_info = {};
21529 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
21530 fb_info.pNext = NULL;
21531 fb_info.renderPass = rp;
21532 fb_info.attachmentCount = 1;
21533 fb_info.pAttachments = depthView;
21534 fb_info.width = 100;
21535 fb_info.height = 100;
21536 fb_info.layers = 1;
21537 VkFramebuffer fb;
21538 result = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
21539 ASSERT_VK_SUCCESS(result);
21540
21541 VkRenderPassBeginInfo rpbinfo = {};
21542 rpbinfo.clearValueCount = 1;
21543 rpbinfo.pClearValues = &clear;
21544 rpbinfo.pNext = NULL;
21545 rpbinfo.renderPass = rp;
21546 rpbinfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
21547 rpbinfo.renderArea.extent.width = 100;
21548 rpbinfo.renderArea.extent.height = 100;
21549 rpbinfo.renderArea.offset.x = 0;
21550 rpbinfo.renderArea.offset.y = 0;
21551 rpbinfo.framebuffer = fb;
21552
21553 VkFence fence = {};
21554 VkFenceCreateInfo fence_ci = {};
21555 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
21556 fence_ci.pNext = nullptr;
21557 fence_ci.flags = 0;
21558 result = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fence);
21559 ASSERT_VK_SUCCESS(result);
21560
21561 m_commandBuffer->BeginCommandBuffer();
21562 m_commandBuffer->BeginRenderPass(rpbinfo);
21563 m_commandBuffer->EndRenderPass();
21564 m_commandBuffer->EndCommandBuffer();
21565 m_commandBuffer->QueueCommandBuffer(fence);
21566
21567 VkImageObj destImage(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060021568 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 -070021569 VK_IMAGE_TILING_OPTIMAL, 0);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021570 VkImageMemoryBarrier barrier = {};
21571 VkImageSubresourceRange range;
21572 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
21573 barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
21574 barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT;
21575 barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
21576 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
21577 barrier.image = m_depthStencil->handle();
21578 range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
21579 range.baseMipLevel = 0;
21580 range.levelCount = 1;
21581 range.baseArrayLayer = 0;
21582 range.layerCount = 1;
21583 barrier.subresourceRange = range;
21584 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
21585 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
21586 cmdbuf.BeginCommandBuffer();
21587 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 -070021588 &barrier);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021589 barrier.srcAccessMask = 0;
21590 barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
21591 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
21592 barrier.image = destImage.handle();
21593 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
21594 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 -070021595 &barrier);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021596 VkImageCopy cregion;
21597 cregion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
21598 cregion.srcSubresource.mipLevel = 0;
21599 cregion.srcSubresource.baseArrayLayer = 0;
21600 cregion.srcSubresource.layerCount = 1;
21601 cregion.srcOffset.x = 0;
21602 cregion.srcOffset.y = 0;
21603 cregion.srcOffset.z = 0;
21604 cregion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
21605 cregion.dstSubresource.mipLevel = 0;
21606 cregion.dstSubresource.baseArrayLayer = 0;
21607 cregion.dstSubresource.layerCount = 1;
21608 cregion.dstOffset.x = 0;
21609 cregion.dstOffset.y = 0;
21610 cregion.dstOffset.z = 0;
21611 cregion.extent.width = 100;
21612 cregion.extent.height = 100;
21613 cregion.extent.depth = 1;
21614 cmdbuf.CopyImage(m_depthStencil->handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, destImage.handle(),
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021615 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &cregion);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021616 cmdbuf.EndCommandBuffer();
21617
21618 VkSubmitInfo submit_info;
21619 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21620 submit_info.pNext = NULL;
21621 submit_info.waitSemaphoreCount = 0;
21622 submit_info.pWaitSemaphores = NULL;
21623 submit_info.pWaitDstStageMask = NULL;
21624 submit_info.commandBufferCount = 1;
21625 submit_info.pCommandBuffers = &cmdbuf.handle();
21626 submit_info.signalSemaphoreCount = 0;
21627 submit_info.pSignalSemaphores = NULL;
21628
21629 m_errorMonitor->ExpectSuccess();
21630 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
21631 m_errorMonitor->VerifyNotFound();
21632
21633 vkQueueWaitIdle(m_device->m_queue);
21634 vkDestroyFence(m_device->device(), fence, nullptr);
21635 vkDestroyRenderPass(m_device->device(), rp, nullptr);
21636 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
21637}
21638
21639// This is a positive test. No errors should be generated.
Mike Weiblene4e225d2017-03-07 23:15:43 -070021640TEST_F(VkPositiveLayerTest, BarrierLayoutToImageUsage) {
21641 TEST_DESCRIPTION("Ensure barriers' new and old VkImageLayout are compatible with their images' VkImageUsageFlags");
21642
21643 m_errorMonitor->ExpectSuccess();
21644
Tony Barbour1fa09702017-03-16 12:09:08 -060021645 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -060021646 auto depth_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbour9357d542017-03-24 15:42:21 -060021647 if (!depth_format) {
21648 printf(" No Depth + Stencil format found. Skipped.\n");
21649 return;
21650 }
Mike Weiblene4e225d2017-03-07 23:15:43 -070021651 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21652
21653 VkImageMemoryBarrier img_barrier = {};
21654 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
21655 img_barrier.pNext = NULL;
21656 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
21657 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
21658 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
21659 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
21660 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
21661 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
21662 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
21663 img_barrier.subresourceRange.baseArrayLayer = 0;
21664 img_barrier.subresourceRange.baseMipLevel = 0;
21665 img_barrier.subresourceRange.layerCount = 1;
21666 img_barrier.subresourceRange.levelCount = 1;
21667
21668 {
21669 VkImageObj img_color(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060021670 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 -070021671 ASSERT_TRUE(img_color.initialized());
21672
21673 VkImageObj img_ds1(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060021674 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 -070021675 ASSERT_TRUE(img_ds1.initialized());
21676
21677 VkImageObj img_ds2(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060021678 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 -070021679 ASSERT_TRUE(img_ds2.initialized());
21680
21681 VkImageObj img_xfer_src(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060021682 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 -070021683 ASSERT_TRUE(img_xfer_src.initialized());
21684
21685 VkImageObj img_xfer_dst(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060021686 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 -070021687 ASSERT_TRUE(img_xfer_dst.initialized());
21688
21689 VkImageObj img_sampled(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060021690 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 -070021691 ASSERT_TRUE(img_sampled.initialized());
21692
21693 VkImageObj img_input(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060021694 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 -070021695 ASSERT_TRUE(img_input.initialized());
21696
21697 const struct {
21698 VkImageObj &image_obj;
21699 VkImageLayout old_layout;
21700 VkImageLayout new_layout;
21701 } buffer_layouts[] = {
21702 // clang-format off
21703 {img_color, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL},
21704 {img_ds1, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL},
21705 {img_ds2, VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL},
21706 {img_sampled, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL},
21707 {img_input, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL},
21708 {img_xfer_src, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL},
21709 {img_xfer_dst, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL},
21710 // clang-format on
21711 };
21712 const uint32_t layout_count = sizeof(buffer_layouts) / sizeof(buffer_layouts[0]);
21713
21714 m_commandBuffer->BeginCommandBuffer();
21715 for (uint32_t i = 0; i < layout_count; ++i) {
21716 img_barrier.image = buffer_layouts[i].image_obj.handle();
21717 const VkImageUsageFlags usage = buffer_layouts[i].image_obj.usage();
21718 img_barrier.subresourceRange.aspectMask = (usage == VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT)
21719 ? (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)
21720 : VK_IMAGE_ASPECT_COLOR_BIT;
21721
21722 img_barrier.oldLayout = buffer_layouts[i].old_layout;
21723 img_barrier.newLayout = buffer_layouts[i].new_layout;
21724 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT,
21725 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0, nullptr, 1, &img_barrier);
21726
21727 img_barrier.oldLayout = buffer_layouts[i].new_layout;
21728 img_barrier.newLayout = buffer_layouts[i].old_layout;
21729 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT,
21730 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0, nullptr, 1, &img_barrier);
21731 }
21732 m_commandBuffer->EndCommandBuffer();
21733
21734 img_barrier.oldLayout = VK_IMAGE_LAYOUT_GENERAL;
21735 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
21736 }
21737 m_errorMonitor->VerifyNotFound();
21738}
21739
21740// This is a positive test. No errors should be generated.
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021741TEST_F(VkPositiveLayerTest, WaitEventThenSet) {
21742 TEST_DESCRIPTION("Wait on a event then set it after the wait has been submitted.");
21743
21744 m_errorMonitor->ExpectSuccess();
Tony Barbour1fa09702017-03-16 12:09:08 -060021745 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021746
21747 VkEvent event;
21748 VkEventCreateInfo event_create_info{};
21749 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
21750 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
21751
21752 VkCommandPool command_pool;
21753 VkCommandPoolCreateInfo pool_create_info{};
21754 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
21755 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
21756 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
21757 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
21758
21759 VkCommandBuffer command_buffer;
21760 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
21761 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
21762 command_buffer_allocate_info.commandPool = command_pool;
21763 command_buffer_allocate_info.commandBufferCount = 1;
21764 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
21765 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
21766
21767 VkQueue queue = VK_NULL_HANDLE;
21768 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
21769
21770 {
21771 VkCommandBufferBeginInfo begin_info{};
21772 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21773 vkBeginCommandBuffer(command_buffer, &begin_info);
21774
21775 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 -070021776 nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021777 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
21778 vkEndCommandBuffer(command_buffer);
21779 }
21780 {
21781 VkSubmitInfo submit_info{};
21782 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21783 submit_info.commandBufferCount = 1;
21784 submit_info.pCommandBuffers = &command_buffer;
21785 submit_info.signalSemaphoreCount = 0;
21786 submit_info.pSignalSemaphores = nullptr;
21787 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
21788 }
21789 { vkSetEvent(m_device->device(), event); }
21790
21791 vkQueueWaitIdle(queue);
21792
21793 vkDestroyEvent(m_device->device(), event, nullptr);
21794 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
21795 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
21796
21797 m_errorMonitor->VerifyNotFound();
21798}
21799// This is a positive test. No errors should be generated.
21800TEST_F(VkPositiveLayerTest, QueryAndCopySecondaryCommandBuffers) {
21801 TEST_DESCRIPTION("Issue a query on a secondary command buffery and copy it on a primary.");
21802
Tony Barbour1fa09702017-03-16 12:09:08 -060021803 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021804 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021805
21806 m_errorMonitor->ExpectSuccess();
21807
21808 VkQueryPool query_pool;
21809 VkQueryPoolCreateInfo query_pool_create_info{};
21810 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
21811 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
21812 query_pool_create_info.queryCount = 1;
21813 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
21814
21815 VkCommandPool command_pool;
21816 VkCommandPoolCreateInfo pool_create_info{};
21817 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
21818 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
21819 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
21820 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
21821
21822 VkCommandBuffer command_buffer;
21823 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
21824 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
21825 command_buffer_allocate_info.commandPool = command_pool;
21826 command_buffer_allocate_info.commandBufferCount = 1;
21827 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
21828 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
21829
21830 VkCommandBuffer secondary_command_buffer;
21831 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
21832 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer);
21833
21834 VkQueue queue = VK_NULL_HANDLE;
21835 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
21836
21837 uint32_t qfi = 0;
21838 VkBufferCreateInfo buff_create_info = {};
21839 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
21840 buff_create_info.size = 1024;
21841 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
21842 buff_create_info.queueFamilyIndexCount = 1;
21843 buff_create_info.pQueueFamilyIndices = &qfi;
21844
21845 VkResult err;
21846 VkBuffer buffer;
21847 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
21848 ASSERT_VK_SUCCESS(err);
21849 VkMemoryAllocateInfo mem_alloc = {};
21850 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
21851 mem_alloc.pNext = NULL;
21852 mem_alloc.allocationSize = 1024;
21853 mem_alloc.memoryTypeIndex = 0;
21854
21855 VkMemoryRequirements memReqs;
21856 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
21857 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
21858 if (!pass) {
21859 vkDestroyBuffer(m_device->device(), buffer, NULL);
21860 return;
21861 }
21862
21863 VkDeviceMemory mem;
21864 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
21865 ASSERT_VK_SUCCESS(err);
21866 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
21867 ASSERT_VK_SUCCESS(err);
21868
21869 VkCommandBufferInheritanceInfo hinfo = {};
21870 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
21871 hinfo.renderPass = VK_NULL_HANDLE;
21872 hinfo.subpass = 0;
21873 hinfo.framebuffer = VK_NULL_HANDLE;
21874 hinfo.occlusionQueryEnable = VK_FALSE;
21875 hinfo.queryFlags = 0;
21876 hinfo.pipelineStatistics = 0;
21877
21878 {
21879 VkCommandBufferBeginInfo begin_info{};
21880 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21881 begin_info.pInheritanceInfo = &hinfo;
21882 vkBeginCommandBuffer(secondary_command_buffer, &begin_info);
21883
21884 vkCmdResetQueryPool(secondary_command_buffer, query_pool, 0, 1);
21885 vkCmdWriteTimestamp(secondary_command_buffer, VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
21886
21887 vkEndCommandBuffer(secondary_command_buffer);
21888
21889 begin_info.pInheritanceInfo = nullptr;
21890 vkBeginCommandBuffer(command_buffer, &begin_info);
21891
21892 vkCmdExecuteCommands(command_buffer, 1, &secondary_command_buffer);
21893 vkCmdCopyQueryPoolResults(command_buffer, query_pool, 0, 1, buffer, 0, 0, 0);
21894
21895 vkEndCommandBuffer(command_buffer);
21896 }
21897 {
21898 VkSubmitInfo submit_info{};
21899 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21900 submit_info.commandBufferCount = 1;
21901 submit_info.pCommandBuffers = &command_buffer;
21902 submit_info.signalSemaphoreCount = 0;
21903 submit_info.pSignalSemaphores = nullptr;
21904 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
21905 }
21906
21907 vkQueueWaitIdle(queue);
21908
21909 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
21910 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
21911 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &secondary_command_buffer);
21912 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
21913 vkDestroyBuffer(m_device->device(), buffer, NULL);
21914 vkFreeMemory(m_device->device(), mem, NULL);
21915
21916 m_errorMonitor->VerifyNotFound();
21917}
21918
21919// This is a positive test. No errors should be generated.
21920TEST_F(VkPositiveLayerTest, QueryAndCopyMultipleCommandBuffers) {
21921 TEST_DESCRIPTION("Issue a query and copy from it on a second command buffer.");
21922
Tony Barbour1fa09702017-03-16 12:09:08 -060021923 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021924 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021925
21926 m_errorMonitor->ExpectSuccess();
21927
21928 VkQueryPool query_pool;
21929 VkQueryPoolCreateInfo query_pool_create_info{};
21930 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
21931 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
21932 query_pool_create_info.queryCount = 1;
21933 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
21934
21935 VkCommandPool command_pool;
21936 VkCommandPoolCreateInfo pool_create_info{};
21937 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
21938 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
21939 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
21940 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
21941
21942 VkCommandBuffer command_buffer[2];
21943 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
21944 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
21945 command_buffer_allocate_info.commandPool = command_pool;
21946 command_buffer_allocate_info.commandBufferCount = 2;
21947 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
21948 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
21949
21950 VkQueue queue = VK_NULL_HANDLE;
21951 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
21952
21953 uint32_t qfi = 0;
21954 VkBufferCreateInfo buff_create_info = {};
21955 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
21956 buff_create_info.size = 1024;
21957 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
21958 buff_create_info.queueFamilyIndexCount = 1;
21959 buff_create_info.pQueueFamilyIndices = &qfi;
21960
21961 VkResult err;
21962 VkBuffer buffer;
21963 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
21964 ASSERT_VK_SUCCESS(err);
21965 VkMemoryAllocateInfo mem_alloc = {};
21966 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
21967 mem_alloc.pNext = NULL;
21968 mem_alloc.allocationSize = 1024;
21969 mem_alloc.memoryTypeIndex = 0;
21970
21971 VkMemoryRequirements memReqs;
21972 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
21973 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
21974 if (!pass) {
21975 vkDestroyBuffer(m_device->device(), buffer, NULL);
21976 return;
21977 }
21978
21979 VkDeviceMemory mem;
21980 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
21981 ASSERT_VK_SUCCESS(err);
21982 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
21983 ASSERT_VK_SUCCESS(err);
21984
21985 {
21986 VkCommandBufferBeginInfo begin_info{};
21987 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21988 vkBeginCommandBuffer(command_buffer[0], &begin_info);
21989
21990 vkCmdResetQueryPool(command_buffer[0], query_pool, 0, 1);
21991 vkCmdWriteTimestamp(command_buffer[0], VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
21992
21993 vkEndCommandBuffer(command_buffer[0]);
21994
21995 vkBeginCommandBuffer(command_buffer[1], &begin_info);
21996
21997 vkCmdCopyQueryPoolResults(command_buffer[1], query_pool, 0, 1, buffer, 0, 0, 0);
21998
21999 vkEndCommandBuffer(command_buffer[1]);
22000 }
22001 {
22002 VkSubmitInfo submit_info{};
22003 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22004 submit_info.commandBufferCount = 2;
22005 submit_info.pCommandBuffers = command_buffer;
22006 submit_info.signalSemaphoreCount = 0;
22007 submit_info.pSignalSemaphores = nullptr;
22008 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
22009 }
22010
22011 vkQueueWaitIdle(queue);
22012
22013 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
22014 vkFreeCommandBuffers(m_device->device(), command_pool, 2, command_buffer);
22015 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
22016 vkDestroyBuffer(m_device->device(), buffer, NULL);
22017 vkFreeMemory(m_device->device(), mem, NULL);
22018
22019 m_errorMonitor->VerifyNotFound();
22020}
22021
Tony Barbourc46924f2016-11-04 11:49:52 -060022022TEST_F(VkLayerTest, ResetEventThenSet) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022023 TEST_DESCRIPTION("Reset an event then set it after the reset has been submitted.");
22024
Tony Barbour1fa09702017-03-16 12:09:08 -060022025 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022026 VkEvent event;
22027 VkEventCreateInfo event_create_info{};
22028 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
22029 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
22030
22031 VkCommandPool command_pool;
22032 VkCommandPoolCreateInfo pool_create_info{};
22033 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
22034 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
22035 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
22036 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
22037
22038 VkCommandBuffer command_buffer;
22039 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
22040 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
22041 command_buffer_allocate_info.commandPool = command_pool;
22042 command_buffer_allocate_info.commandBufferCount = 1;
22043 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
22044 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
22045
22046 VkQueue queue = VK_NULL_HANDLE;
22047 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
22048
22049 {
22050 VkCommandBufferBeginInfo begin_info{};
22051 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22052 vkBeginCommandBuffer(command_buffer, &begin_info);
22053
22054 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022055 vkEndCommandBuffer(command_buffer);
22056 }
22057 {
22058 VkSubmitInfo submit_info{};
22059 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22060 submit_info.commandBufferCount = 1;
22061 submit_info.pCommandBuffers = &command_buffer;
22062 submit_info.signalSemaphoreCount = 0;
22063 submit_info.pSignalSemaphores = nullptr;
22064 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
22065 }
22066 {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022067 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
22068 "that is already in use by a "
22069 "command buffer.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022070 vkSetEvent(m_device->device(), event);
22071 m_errorMonitor->VerifyFound();
22072 }
22073
22074 vkQueueWaitIdle(queue);
22075
22076 vkDestroyEvent(m_device->device(), event, nullptr);
22077 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
22078 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
22079}
22080
22081// This is a positive test. No errors should be generated.
22082TEST_F(VkPositiveLayerTest, TwoFencesThreeFrames) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022083 TEST_DESCRIPTION(
22084 "Two command buffers with two separate fences are each "
22085 "run through a Submit & WaitForFences cycle 3 times. This "
22086 "previously revealed a bug so running this positive test "
22087 "to prevent a regression.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022088 m_errorMonitor->ExpectSuccess();
22089
Tony Barbour1fa09702017-03-16 12:09:08 -060022090 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022091 VkQueue queue = VK_NULL_HANDLE;
22092 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
22093
22094 static const uint32_t NUM_OBJECTS = 2;
22095 static const uint32_t NUM_FRAMES = 3;
22096 VkCommandBuffer cmd_buffers[NUM_OBJECTS] = {};
22097 VkFence fences[NUM_OBJECTS] = {};
22098
22099 VkCommandPool cmd_pool;
22100 VkCommandPoolCreateInfo cmd_pool_ci = {};
22101 cmd_pool_ci.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
22102 cmd_pool_ci.queueFamilyIndex = m_device->graphics_queue_node_index_;
22103 cmd_pool_ci.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
22104 VkResult err = vkCreateCommandPool(m_device->device(), &cmd_pool_ci, nullptr, &cmd_pool);
22105 ASSERT_VK_SUCCESS(err);
22106
22107 VkCommandBufferAllocateInfo cmd_buf_info = {};
22108 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
22109 cmd_buf_info.commandPool = cmd_pool;
22110 cmd_buf_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
22111 cmd_buf_info.commandBufferCount = 1;
22112
22113 VkFenceCreateInfo fence_ci = {};
22114 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
22115 fence_ci.pNext = nullptr;
22116 fence_ci.flags = 0;
22117
22118 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
22119 err = vkAllocateCommandBuffers(m_device->device(), &cmd_buf_info, &cmd_buffers[i]);
22120 ASSERT_VK_SUCCESS(err);
22121 err = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fences[i]);
22122 ASSERT_VK_SUCCESS(err);
22123 }
22124
22125 for (uint32_t frame = 0; frame < NUM_FRAMES; ++frame) {
22126 for (uint32_t obj = 0; obj < NUM_OBJECTS; ++obj) {
22127 // Create empty cmd buffer
22128 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
22129 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22130
22131 err = vkBeginCommandBuffer(cmd_buffers[obj], &cmdBufBeginDesc);
22132 ASSERT_VK_SUCCESS(err);
22133 err = vkEndCommandBuffer(cmd_buffers[obj]);
22134 ASSERT_VK_SUCCESS(err);
22135
22136 VkSubmitInfo submit_info = {};
22137 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22138 submit_info.commandBufferCount = 1;
22139 submit_info.pCommandBuffers = &cmd_buffers[obj];
22140 // Submit cmd buffer and wait for fence
22141 err = vkQueueSubmit(queue, 1, &submit_info, fences[obj]);
22142 ASSERT_VK_SUCCESS(err);
22143 err = vkWaitForFences(m_device->device(), 1, &fences[obj], VK_TRUE, UINT64_MAX);
22144 ASSERT_VK_SUCCESS(err);
22145 err = vkResetFences(m_device->device(), 1, &fences[obj]);
22146 ASSERT_VK_SUCCESS(err);
22147 }
22148 }
22149 m_errorMonitor->VerifyNotFound();
22150 vkDestroyCommandPool(m_device->device(), cmd_pool, NULL);
22151 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
22152 vkDestroyFence(m_device->device(), fences[i], nullptr);
22153 }
22154}
22155// This is a positive test. No errors should be generated.
22156TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWI) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022157 TEST_DESCRIPTION(
22158 "Two command buffers, each in a separate QueueSubmit call "
22159 "submitted on separate queues followed by a QueueWaitIdle.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022160
Tony Barbour1fa09702017-03-16 12:09:08 -060022161 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022162 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022163
22164 m_errorMonitor->ExpectSuccess();
22165
22166 VkSemaphore semaphore;
22167 VkSemaphoreCreateInfo semaphore_create_info{};
22168 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
22169 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
22170
22171 VkCommandPool command_pool;
22172 VkCommandPoolCreateInfo pool_create_info{};
22173 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
22174 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
22175 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
22176 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
22177
22178 VkCommandBuffer command_buffer[2];
22179 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
22180 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
22181 command_buffer_allocate_info.commandPool = command_pool;
22182 command_buffer_allocate_info.commandBufferCount = 2;
22183 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
22184 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
22185
22186 VkQueue queue = VK_NULL_HANDLE;
22187 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
22188
22189 {
22190 VkCommandBufferBeginInfo begin_info{};
22191 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22192 vkBeginCommandBuffer(command_buffer[0], &begin_info);
22193
22194 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 -070022195 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022196
22197 VkViewport viewport{};
22198 viewport.maxDepth = 1.0f;
22199 viewport.minDepth = 0.0f;
22200 viewport.width = 512;
22201 viewport.height = 512;
22202 viewport.x = 0;
22203 viewport.y = 0;
22204 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
22205 vkEndCommandBuffer(command_buffer[0]);
22206 }
22207 {
22208 VkCommandBufferBeginInfo begin_info{};
22209 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22210 vkBeginCommandBuffer(command_buffer[1], &begin_info);
22211
22212 VkViewport viewport{};
22213 viewport.maxDepth = 1.0f;
22214 viewport.minDepth = 0.0f;
22215 viewport.width = 512;
22216 viewport.height = 512;
22217 viewport.x = 0;
22218 viewport.y = 0;
22219 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
22220 vkEndCommandBuffer(command_buffer[1]);
22221 }
22222 {
22223 VkSubmitInfo submit_info{};
22224 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22225 submit_info.commandBufferCount = 1;
22226 submit_info.pCommandBuffers = &command_buffer[0];
22227 submit_info.signalSemaphoreCount = 1;
22228 submit_info.pSignalSemaphores = &semaphore;
22229 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
22230 }
22231 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022232 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022233 VkSubmitInfo submit_info{};
22234 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22235 submit_info.commandBufferCount = 1;
22236 submit_info.pCommandBuffers = &command_buffer[1];
22237 submit_info.waitSemaphoreCount = 1;
22238 submit_info.pWaitSemaphores = &semaphore;
22239 submit_info.pWaitDstStageMask = flags;
22240 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
22241 }
22242
22243 vkQueueWaitIdle(m_device->m_queue);
22244
22245 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
22246 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
22247 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
22248
22249 m_errorMonitor->VerifyNotFound();
22250}
22251
22252// This is a positive test. No errors should be generated.
22253TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWIFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022254 TEST_DESCRIPTION(
22255 "Two command buffers, each in a separate QueueSubmit call "
22256 "submitted on separate queues, the second having a fence"
22257 "followed by a QueueWaitIdle.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022258
Tony Barbour1fa09702017-03-16 12:09:08 -060022259 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022260 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022261
22262 m_errorMonitor->ExpectSuccess();
22263
22264 VkFence fence;
22265 VkFenceCreateInfo fence_create_info{};
22266 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
22267 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
22268
22269 VkSemaphore semaphore;
22270 VkSemaphoreCreateInfo semaphore_create_info{};
22271 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
22272 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
22273
22274 VkCommandPool command_pool;
22275 VkCommandPoolCreateInfo pool_create_info{};
22276 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
22277 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
22278 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
22279 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
22280
22281 VkCommandBuffer command_buffer[2];
22282 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
22283 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
22284 command_buffer_allocate_info.commandPool = command_pool;
22285 command_buffer_allocate_info.commandBufferCount = 2;
22286 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
22287 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
22288
22289 VkQueue queue = VK_NULL_HANDLE;
22290 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
22291
22292 {
22293 VkCommandBufferBeginInfo begin_info{};
22294 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22295 vkBeginCommandBuffer(command_buffer[0], &begin_info);
22296
22297 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 -070022298 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022299
22300 VkViewport viewport{};
22301 viewport.maxDepth = 1.0f;
22302 viewport.minDepth = 0.0f;
22303 viewport.width = 512;
22304 viewport.height = 512;
22305 viewport.x = 0;
22306 viewport.y = 0;
22307 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
22308 vkEndCommandBuffer(command_buffer[0]);
22309 }
22310 {
22311 VkCommandBufferBeginInfo begin_info{};
22312 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22313 vkBeginCommandBuffer(command_buffer[1], &begin_info);
22314
22315 VkViewport viewport{};
22316 viewport.maxDepth = 1.0f;
22317 viewport.minDepth = 0.0f;
22318 viewport.width = 512;
22319 viewport.height = 512;
22320 viewport.x = 0;
22321 viewport.y = 0;
22322 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
22323 vkEndCommandBuffer(command_buffer[1]);
22324 }
22325 {
22326 VkSubmitInfo submit_info{};
22327 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22328 submit_info.commandBufferCount = 1;
22329 submit_info.pCommandBuffers = &command_buffer[0];
22330 submit_info.signalSemaphoreCount = 1;
22331 submit_info.pSignalSemaphores = &semaphore;
22332 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
22333 }
22334 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022335 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022336 VkSubmitInfo submit_info{};
22337 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22338 submit_info.commandBufferCount = 1;
22339 submit_info.pCommandBuffers = &command_buffer[1];
22340 submit_info.waitSemaphoreCount = 1;
22341 submit_info.pWaitSemaphores = &semaphore;
22342 submit_info.pWaitDstStageMask = flags;
22343 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
22344 }
22345
22346 vkQueueWaitIdle(m_device->m_queue);
22347
22348 vkDestroyFence(m_device->device(), fence, nullptr);
22349 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
22350 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
22351 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
22352
22353 m_errorMonitor->VerifyNotFound();
22354}
22355
22356// This is a positive test. No errors should be generated.
22357TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceTwoWFF) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022358 TEST_DESCRIPTION(
22359 "Two command buffers, each in a separate QueueSubmit call "
22360 "submitted on separate queues, the second having a fence"
22361 "followed by two consecutive WaitForFences calls on the same fence.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022362
Tony Barbour1fa09702017-03-16 12:09:08 -060022363 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022364 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022365
22366 m_errorMonitor->ExpectSuccess();
22367
22368 VkFence fence;
22369 VkFenceCreateInfo fence_create_info{};
22370 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
22371 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
22372
22373 VkSemaphore semaphore;
22374 VkSemaphoreCreateInfo semaphore_create_info{};
22375 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
22376 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
22377
22378 VkCommandPool command_pool;
22379 VkCommandPoolCreateInfo pool_create_info{};
22380 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
22381 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
22382 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
22383 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
22384
22385 VkCommandBuffer command_buffer[2];
22386 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
22387 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
22388 command_buffer_allocate_info.commandPool = command_pool;
22389 command_buffer_allocate_info.commandBufferCount = 2;
22390 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
22391 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
22392
22393 VkQueue queue = VK_NULL_HANDLE;
22394 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
22395
22396 {
22397 VkCommandBufferBeginInfo begin_info{};
22398 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22399 vkBeginCommandBuffer(command_buffer[0], &begin_info);
22400
22401 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 -070022402 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022403
22404 VkViewport viewport{};
22405 viewport.maxDepth = 1.0f;
22406 viewport.minDepth = 0.0f;
22407 viewport.width = 512;
22408 viewport.height = 512;
22409 viewport.x = 0;
22410 viewport.y = 0;
22411 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
22412 vkEndCommandBuffer(command_buffer[0]);
22413 }
22414 {
22415 VkCommandBufferBeginInfo begin_info{};
22416 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22417 vkBeginCommandBuffer(command_buffer[1], &begin_info);
22418
22419 VkViewport viewport{};
22420 viewport.maxDepth = 1.0f;
22421 viewport.minDepth = 0.0f;
22422 viewport.width = 512;
22423 viewport.height = 512;
22424 viewport.x = 0;
22425 viewport.y = 0;
22426 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
22427 vkEndCommandBuffer(command_buffer[1]);
22428 }
22429 {
22430 VkSubmitInfo submit_info{};
22431 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22432 submit_info.commandBufferCount = 1;
22433 submit_info.pCommandBuffers = &command_buffer[0];
22434 submit_info.signalSemaphoreCount = 1;
22435 submit_info.pSignalSemaphores = &semaphore;
22436 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
22437 }
22438 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022439 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022440 VkSubmitInfo submit_info{};
22441 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22442 submit_info.commandBufferCount = 1;
22443 submit_info.pCommandBuffers = &command_buffer[1];
22444 submit_info.waitSemaphoreCount = 1;
22445 submit_info.pWaitSemaphores = &semaphore;
22446 submit_info.pWaitDstStageMask = flags;
22447 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
22448 }
22449
22450 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
22451 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
22452
22453 vkDestroyFence(m_device->device(), fence, nullptr);
22454 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
22455 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
22456 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
22457
22458 m_errorMonitor->VerifyNotFound();
22459}
22460
22461TEST_F(VkPositiveLayerTest, TwoQueuesEnsureCorrectRetirementWithWorkStolen) {
Tony Barbour1fa09702017-03-16 12:09:08 -060022462 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022463 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070022464 printf(" Test requires two queues, skipping\n");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022465 return;
22466 }
22467
22468 VkResult err;
22469
22470 m_errorMonitor->ExpectSuccess();
22471
22472 VkQueue q0 = m_device->m_queue;
22473 VkQueue q1 = nullptr;
22474 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &q1);
22475 ASSERT_NE(q1, nullptr);
22476
22477 // An (empty) command buffer. We must have work in the first submission --
22478 // the layer treats unfenced work differently from fenced work.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022479 VkCommandPoolCreateInfo cpci = {VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, nullptr, 0, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022480 VkCommandPool pool;
22481 err = vkCreateCommandPool(m_device->device(), &cpci, nullptr, &pool);
22482 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022483 VkCommandBufferAllocateInfo cbai = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, nullptr, pool,
22484 VK_COMMAND_BUFFER_LEVEL_PRIMARY, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022485 VkCommandBuffer cb;
22486 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &cb);
22487 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022488 VkCommandBufferBeginInfo cbbi = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022489 err = vkBeginCommandBuffer(cb, &cbbi);
22490 ASSERT_VK_SUCCESS(err);
22491 err = vkEndCommandBuffer(cb);
22492 ASSERT_VK_SUCCESS(err);
22493
22494 // A semaphore
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022495 VkSemaphoreCreateInfo sci = {VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022496 VkSemaphore s;
22497 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s);
22498 ASSERT_VK_SUCCESS(err);
22499
22500 // First submission, to q0
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022501 VkSubmitInfo s0 = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &cb, 1, &s};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022502
22503 err = vkQueueSubmit(q0, 1, &s0, VK_NULL_HANDLE);
22504 ASSERT_VK_SUCCESS(err);
22505
22506 // Second submission, to q1, waiting on s
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022507 VkFlags waitmask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; // doesn't really matter what this value is.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022508 VkSubmitInfo s1 = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 1, &s, &waitmask, 0, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022509
22510 err = vkQueueSubmit(q1, 1, &s1, VK_NULL_HANDLE);
22511 ASSERT_VK_SUCCESS(err);
22512
22513 // Wait for q0 idle
22514 err = vkQueueWaitIdle(q0);
22515 ASSERT_VK_SUCCESS(err);
22516
22517 // Command buffer should have been completed (it was on q0); reset the pool.
22518 vkFreeCommandBuffers(m_device->device(), pool, 1, &cb);
22519
22520 m_errorMonitor->VerifyNotFound();
22521
22522 // Force device completely idle and clean up resources
22523 vkDeviceWaitIdle(m_device->device());
22524 vkDestroyCommandPool(m_device->device(), pool, nullptr);
22525 vkDestroySemaphore(m_device->device(), s, nullptr);
22526}
22527
22528// This is a positive test. No errors should be generated.
22529TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022530 TEST_DESCRIPTION(
22531 "Two command buffers, each in a separate QueueSubmit call "
22532 "submitted on separate queues, the second having a fence, "
22533 "followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022534
Tony Barbour1fa09702017-03-16 12:09:08 -060022535 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022536 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022537
22538 m_errorMonitor->ExpectSuccess();
22539
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022540 VkFence fence;
22541 VkFenceCreateInfo fence_create_info{};
22542 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
22543 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
22544
22545 VkSemaphore semaphore;
22546 VkSemaphoreCreateInfo semaphore_create_info{};
22547 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
22548 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
22549
22550 VkCommandPool command_pool;
22551 VkCommandPoolCreateInfo pool_create_info{};
22552 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
22553 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
22554 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
22555 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
22556
22557 VkCommandBuffer command_buffer[2];
22558 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
22559 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
22560 command_buffer_allocate_info.commandPool = command_pool;
22561 command_buffer_allocate_info.commandBufferCount = 2;
22562 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
22563 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
22564
22565 VkQueue queue = VK_NULL_HANDLE;
22566 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
22567
22568 {
22569 VkCommandBufferBeginInfo begin_info{};
22570 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22571 vkBeginCommandBuffer(command_buffer[0], &begin_info);
22572
22573 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 -070022574 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022575
22576 VkViewport viewport{};
22577 viewport.maxDepth = 1.0f;
22578 viewport.minDepth = 0.0f;
22579 viewport.width = 512;
22580 viewport.height = 512;
22581 viewport.x = 0;
22582 viewport.y = 0;
22583 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
22584 vkEndCommandBuffer(command_buffer[0]);
22585 }
22586 {
22587 VkCommandBufferBeginInfo begin_info{};
22588 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22589 vkBeginCommandBuffer(command_buffer[1], &begin_info);
22590
22591 VkViewport viewport{};
22592 viewport.maxDepth = 1.0f;
22593 viewport.minDepth = 0.0f;
22594 viewport.width = 512;
22595 viewport.height = 512;
22596 viewport.x = 0;
22597 viewport.y = 0;
22598 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
22599 vkEndCommandBuffer(command_buffer[1]);
22600 }
22601 {
22602 VkSubmitInfo submit_info{};
22603 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22604 submit_info.commandBufferCount = 1;
22605 submit_info.pCommandBuffers = &command_buffer[0];
22606 submit_info.signalSemaphoreCount = 1;
22607 submit_info.pSignalSemaphores = &semaphore;
22608 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
22609 }
22610 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022611 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022612 VkSubmitInfo submit_info{};
22613 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22614 submit_info.commandBufferCount = 1;
22615 submit_info.pCommandBuffers = &command_buffer[1];
22616 submit_info.waitSemaphoreCount = 1;
22617 submit_info.pWaitSemaphores = &semaphore;
22618 submit_info.pWaitDstStageMask = flags;
22619 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
22620 }
22621
22622 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
22623
22624 vkDestroyFence(m_device->device(), fence, nullptr);
22625 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
22626 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
22627 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
22628
22629 m_errorMonitor->VerifyNotFound();
22630}
22631
22632// This is a positive test. No errors should be generated.
22633TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueWithSemaphoreAndOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022634 TEST_DESCRIPTION(
22635 "Two command buffers, each in a separate QueueSubmit call "
22636 "on the same queue, sharing a signal/wait semaphore, the "
22637 "second having a fence, "
22638 "followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022639
22640 m_errorMonitor->ExpectSuccess();
22641
Tony Barbour1fa09702017-03-16 12:09:08 -060022642 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022643 VkFence fence;
22644 VkFenceCreateInfo fence_create_info{};
22645 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
22646 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
22647
22648 VkSemaphore semaphore;
22649 VkSemaphoreCreateInfo semaphore_create_info{};
22650 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
22651 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
22652
22653 VkCommandPool command_pool;
22654 VkCommandPoolCreateInfo pool_create_info{};
22655 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
22656 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
22657 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
22658 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
22659
22660 VkCommandBuffer command_buffer[2];
22661 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
22662 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
22663 command_buffer_allocate_info.commandPool = command_pool;
22664 command_buffer_allocate_info.commandBufferCount = 2;
22665 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
22666 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
22667
22668 {
22669 VkCommandBufferBeginInfo begin_info{};
22670 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22671 vkBeginCommandBuffer(command_buffer[0], &begin_info);
22672
22673 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 -070022674 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022675
22676 VkViewport viewport{};
22677 viewport.maxDepth = 1.0f;
22678 viewport.minDepth = 0.0f;
22679 viewport.width = 512;
22680 viewport.height = 512;
22681 viewport.x = 0;
22682 viewport.y = 0;
22683 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
22684 vkEndCommandBuffer(command_buffer[0]);
22685 }
22686 {
22687 VkCommandBufferBeginInfo begin_info{};
22688 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22689 vkBeginCommandBuffer(command_buffer[1], &begin_info);
22690
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[1], 0, 1, &viewport);
22699 vkEndCommandBuffer(command_buffer[1]);
22700 }
22701 {
22702 VkSubmitInfo submit_info{};
22703 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22704 submit_info.commandBufferCount = 1;
22705 submit_info.pCommandBuffers = &command_buffer[0];
22706 submit_info.signalSemaphoreCount = 1;
22707 submit_info.pSignalSemaphores = &semaphore;
22708 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
22709 }
22710 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022711 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022712 VkSubmitInfo submit_info{};
22713 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22714 submit_info.commandBufferCount = 1;
22715 submit_info.pCommandBuffers = &command_buffer[1];
22716 submit_info.waitSemaphoreCount = 1;
22717 submit_info.pWaitSemaphores = &semaphore;
22718 submit_info.pWaitDstStageMask = flags;
22719 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
22720 }
22721
22722 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
22723
22724 vkDestroyFence(m_device->device(), fence, nullptr);
22725 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
22726 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
22727 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
22728
22729 m_errorMonitor->VerifyNotFound();
22730}
22731
22732// This is a positive test. No errors should be generated.
22733TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueNullQueueSubmitWithFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022734 TEST_DESCRIPTION(
22735 "Two command buffers, each in a separate QueueSubmit call "
22736 "on the same queue, no fences, followed by a third QueueSubmit with NO "
22737 "SubmitInfos but with a fence, followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022738
22739 m_errorMonitor->ExpectSuccess();
22740
Tony Barbour1fa09702017-03-16 12:09:08 -060022741 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022742 VkFence fence;
22743 VkFenceCreateInfo fence_create_info{};
22744 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
22745 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
22746
22747 VkCommandPool command_pool;
22748 VkCommandPoolCreateInfo pool_create_info{};
22749 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
22750 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
22751 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
22752 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
22753
22754 VkCommandBuffer command_buffer[2];
22755 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
22756 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
22757 command_buffer_allocate_info.commandPool = command_pool;
22758 command_buffer_allocate_info.commandBufferCount = 2;
22759 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
22760 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
22761
22762 {
22763 VkCommandBufferBeginInfo begin_info{};
22764 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22765 vkBeginCommandBuffer(command_buffer[0], &begin_info);
22766
22767 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 -070022768 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022769
22770 VkViewport viewport{};
22771 viewport.maxDepth = 1.0f;
22772 viewport.minDepth = 0.0f;
22773 viewport.width = 512;
22774 viewport.height = 512;
22775 viewport.x = 0;
22776 viewport.y = 0;
22777 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
22778 vkEndCommandBuffer(command_buffer[0]);
22779 }
22780 {
22781 VkCommandBufferBeginInfo begin_info{};
22782 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22783 vkBeginCommandBuffer(command_buffer[1], &begin_info);
22784
22785 VkViewport viewport{};
22786 viewport.maxDepth = 1.0f;
22787 viewport.minDepth = 0.0f;
22788 viewport.width = 512;
22789 viewport.height = 512;
22790 viewport.x = 0;
22791 viewport.y = 0;
22792 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
22793 vkEndCommandBuffer(command_buffer[1]);
22794 }
22795 {
22796 VkSubmitInfo submit_info{};
22797 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22798 submit_info.commandBufferCount = 1;
22799 submit_info.pCommandBuffers = &command_buffer[0];
22800 submit_info.signalSemaphoreCount = 0;
22801 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
22802 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
22803 }
22804 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022805 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022806 VkSubmitInfo submit_info{};
22807 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22808 submit_info.commandBufferCount = 1;
22809 submit_info.pCommandBuffers = &command_buffer[1];
22810 submit_info.waitSemaphoreCount = 0;
22811 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
22812 submit_info.pWaitDstStageMask = flags;
22813 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
22814 }
22815
22816 vkQueueSubmit(m_device->m_queue, 0, NULL, fence);
22817
22818 VkResult err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
22819 ASSERT_VK_SUCCESS(err);
22820
22821 vkDestroyFence(m_device->device(), fence, nullptr);
22822 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
22823 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
22824
22825 m_errorMonitor->VerifyNotFound();
22826}
22827
22828// This is a positive test. No errors should be generated.
22829TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022830 TEST_DESCRIPTION(
22831 "Two command buffers, each in a separate QueueSubmit call "
22832 "on the same queue, the second having a fence, followed "
22833 "by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022834
22835 m_errorMonitor->ExpectSuccess();
22836
Tony Barbour1fa09702017-03-16 12:09:08 -060022837 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022838 VkFence fence;
22839 VkFenceCreateInfo fence_create_info{};
22840 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
22841 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
22842
22843 VkCommandPool command_pool;
22844 VkCommandPoolCreateInfo pool_create_info{};
22845 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
22846 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
22847 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
22848 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
22849
22850 VkCommandBuffer command_buffer[2];
22851 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
22852 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
22853 command_buffer_allocate_info.commandPool = command_pool;
22854 command_buffer_allocate_info.commandBufferCount = 2;
22855 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
22856 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
22857
22858 {
22859 VkCommandBufferBeginInfo begin_info{};
22860 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22861 vkBeginCommandBuffer(command_buffer[0], &begin_info);
22862
22863 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 -070022864 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022865
22866 VkViewport viewport{};
22867 viewport.maxDepth = 1.0f;
22868 viewport.minDepth = 0.0f;
22869 viewport.width = 512;
22870 viewport.height = 512;
22871 viewport.x = 0;
22872 viewport.y = 0;
22873 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
22874 vkEndCommandBuffer(command_buffer[0]);
22875 }
22876 {
22877 VkCommandBufferBeginInfo begin_info{};
22878 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22879 vkBeginCommandBuffer(command_buffer[1], &begin_info);
22880
22881 VkViewport viewport{};
22882 viewport.maxDepth = 1.0f;
22883 viewport.minDepth = 0.0f;
22884 viewport.width = 512;
22885 viewport.height = 512;
22886 viewport.x = 0;
22887 viewport.y = 0;
22888 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
22889 vkEndCommandBuffer(command_buffer[1]);
22890 }
22891 {
22892 VkSubmitInfo submit_info{};
22893 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22894 submit_info.commandBufferCount = 1;
22895 submit_info.pCommandBuffers = &command_buffer[0];
22896 submit_info.signalSemaphoreCount = 0;
22897 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
22898 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
22899 }
22900 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022901 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022902 VkSubmitInfo submit_info{};
22903 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22904 submit_info.commandBufferCount = 1;
22905 submit_info.pCommandBuffers = &command_buffer[1];
22906 submit_info.waitSemaphoreCount = 0;
22907 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
22908 submit_info.pWaitDstStageMask = flags;
22909 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
22910 }
22911
22912 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
22913
22914 vkDestroyFence(m_device->device(), fence, nullptr);
22915 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
22916 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
22917
22918 m_errorMonitor->VerifyNotFound();
22919}
22920
22921// This is a positive test. No errors should be generated.
22922TEST_F(VkPositiveLayerTest, TwoSubmitInfosWithSemaphoreOneQueueSubmitsOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022923 TEST_DESCRIPTION(
22924 "Two command buffers each in a separate SubmitInfo sent in a single "
22925 "QueueSubmit call followed by a WaitForFences call.");
Tony Barbour1fa09702017-03-16 12:09:08 -060022926 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022927
22928 m_errorMonitor->ExpectSuccess();
22929
22930 VkFence fence;
22931 VkFenceCreateInfo fence_create_info{};
22932 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
22933 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
22934
22935 VkSemaphore semaphore;
22936 VkSemaphoreCreateInfo semaphore_create_info{};
22937 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
22938 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
22939
22940 VkCommandPool command_pool;
22941 VkCommandPoolCreateInfo pool_create_info{};
22942 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
22943 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
22944 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
22945 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
22946
22947 VkCommandBuffer command_buffer[2];
22948 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
22949 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
22950 command_buffer_allocate_info.commandPool = command_pool;
22951 command_buffer_allocate_info.commandBufferCount = 2;
22952 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
22953 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
22954
22955 {
22956 VkCommandBufferBeginInfo begin_info{};
22957 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22958 vkBeginCommandBuffer(command_buffer[0], &begin_info);
22959
22960 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 -070022961 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022962
22963 VkViewport viewport{};
22964 viewport.maxDepth = 1.0f;
22965 viewport.minDepth = 0.0f;
22966 viewport.width = 512;
22967 viewport.height = 512;
22968 viewport.x = 0;
22969 viewport.y = 0;
22970 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
22971 vkEndCommandBuffer(command_buffer[0]);
22972 }
22973 {
22974 VkCommandBufferBeginInfo begin_info{};
22975 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22976 vkBeginCommandBuffer(command_buffer[1], &begin_info);
22977
22978 VkViewport viewport{};
22979 viewport.maxDepth = 1.0f;
22980 viewport.minDepth = 0.0f;
22981 viewport.width = 512;
22982 viewport.height = 512;
22983 viewport.x = 0;
22984 viewport.y = 0;
22985 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
22986 vkEndCommandBuffer(command_buffer[1]);
22987 }
22988 {
22989 VkSubmitInfo submit_info[2];
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022990 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022991
22992 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22993 submit_info[0].pNext = NULL;
22994 submit_info[0].commandBufferCount = 1;
22995 submit_info[0].pCommandBuffers = &command_buffer[0];
22996 submit_info[0].signalSemaphoreCount = 1;
22997 submit_info[0].pSignalSemaphores = &semaphore;
22998 submit_info[0].waitSemaphoreCount = 0;
22999 submit_info[0].pWaitSemaphores = NULL;
23000 submit_info[0].pWaitDstStageMask = 0;
23001
23002 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
23003 submit_info[1].pNext = NULL;
23004 submit_info[1].commandBufferCount = 1;
23005 submit_info[1].pCommandBuffers = &command_buffer[1];
23006 submit_info[1].waitSemaphoreCount = 1;
23007 submit_info[1].pWaitSemaphores = &semaphore;
23008 submit_info[1].pWaitDstStageMask = flags;
23009 submit_info[1].signalSemaphoreCount = 0;
23010 submit_info[1].pSignalSemaphores = NULL;
23011 vkQueueSubmit(m_device->m_queue, 2, &submit_info[0], fence);
23012 }
23013
23014 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
23015
23016 vkDestroyFence(m_device->device(), fence, nullptr);
23017 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
23018 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
23019 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
23020
23021 m_errorMonitor->VerifyNotFound();
23022}
23023
23024TEST_F(VkPositiveLayerTest, RenderPassSecondaryCommandBuffersMultipleTimes) {
23025 m_errorMonitor->ExpectSuccess();
23026
Tony Barbour1fa09702017-03-16 12:09:08 -060023027 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023028 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
23029
Tony Barbour552f6c02016-12-21 14:34:07 -070023030 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023031
23032 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
23033 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
23034 m_errorMonitor->VerifyNotFound();
23035 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
23036 m_errorMonitor->VerifyNotFound();
23037 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
23038 m_errorMonitor->VerifyNotFound();
23039
23040 m_commandBuffer->EndCommandBuffer();
23041 m_errorMonitor->VerifyNotFound();
23042}
23043
23044TEST_F(VkPositiveLayerTest, ValidRenderPassAttachmentLayoutWithLoadOp) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023045 TEST_DESCRIPTION(
23046 "Positive test where we create a renderpass with an "
23047 "attachment that uses LOAD_OP_CLEAR, the first subpass "
23048 "has a valid layout, and a second subpass then uses a "
23049 "valid *READ_ONLY* layout.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023050 m_errorMonitor->ExpectSuccess();
Tony Barbour1fa09702017-03-16 12:09:08 -060023051 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -060023052 auto depth_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbourf887b162017-03-09 10:06:46 -070023053 if (!depth_format) {
23054 printf(" No Depth + Stencil format found. Skipped.\n");
23055 return;
23056 }
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023057
23058 VkAttachmentReference attach[2] = {};
23059 attach[0].attachment = 0;
23060 attach[0].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
23061 attach[1].attachment = 0;
23062 attach[1].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
23063 VkSubpassDescription subpasses[2] = {};
23064 // First subpass clears DS attach on load
23065 subpasses[0].pDepthStencilAttachment = &attach[0];
23066 // 2nd subpass reads in DS as input attachment
23067 subpasses[1].inputAttachmentCount = 1;
23068 subpasses[1].pInputAttachments = &attach[1];
23069 VkAttachmentDescription attach_desc = {};
Tony Barbourf887b162017-03-09 10:06:46 -070023070 attach_desc.format = depth_format;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023071 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
23072 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
23073 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
23074 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
23075 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
23076 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
23077 attach_desc.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
23078 VkRenderPassCreateInfo rpci = {};
23079 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
23080 rpci.attachmentCount = 1;
23081 rpci.pAttachments = &attach_desc;
23082 rpci.subpassCount = 2;
23083 rpci.pSubpasses = subpasses;
23084
23085 // Now create RenderPass and verify no errors
23086 VkRenderPass rp;
23087 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
23088 m_errorMonitor->VerifyNotFound();
23089
23090 vkDestroyRenderPass(m_device->device(), rp, NULL);
23091}
23092
Tobin Ehlis01103de2017-02-16 13:22:47 -070023093TEST_F(VkPositiveLayerTest, RenderPassDepthStencilLayoutTransition) {
23094 TEST_DESCRIPTION(
23095 "Create a render pass with depth-stencil attachment where layout transition "
23096 "from UNDEFINED TO DS_READ_ONLY_OPTIMAL is set by render pass and verify that "
23097 "transition has correctly occurred at queue submit time with no validation errors.");
23098
Tony Barbour1fa09702017-03-16 12:09:08 -060023099 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -060023100 auto depth_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbourf887b162017-03-09 10:06:46 -070023101 if (!depth_format) {
23102 printf(" No Depth + Stencil format found. Skipped.\n");
23103 return;
23104 }
Tobin Ehlis01103de2017-02-16 13:22:47 -070023105 VkImageFormatProperties format_props;
Tony Barbourf887b162017-03-09 10:06:46 -070023106 vkGetPhysicalDeviceImageFormatProperties(gpu(), depth_format, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
Tobin Ehlis01103de2017-02-16 13:22:47 -070023107 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, 0, &format_props);
23108 if (format_props.maxExtent.width < 32 || format_props.maxExtent.height < 32) {
Tony Barbourf887b162017-03-09 10:06:46 -070023109 printf("Depth extent too small, RenderPassDepthStencilLayoutTransition skipped.\n");
Tobin Ehlis01103de2017-02-16 13:22:47 -070023110 return;
23111 }
23112
23113 m_errorMonitor->ExpectSuccess();
Tobin Ehlis01103de2017-02-16 13:22:47 -070023114 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
23115
23116 // A renderpass with one depth/stencil attachment.
23117 VkAttachmentDescription attachment = {0,
Tony Barbourf887b162017-03-09 10:06:46 -070023118 depth_format,
Tobin Ehlis01103de2017-02-16 13:22:47 -070023119 VK_SAMPLE_COUNT_1_BIT,
23120 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
23121 VK_ATTACHMENT_STORE_OP_DONT_CARE,
23122 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
23123 VK_ATTACHMENT_STORE_OP_DONT_CARE,
23124 VK_IMAGE_LAYOUT_UNDEFINED,
23125 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
23126
23127 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
23128
23129 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, &att_ref, 0, nullptr};
23130
23131 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
23132
23133 VkRenderPass rp;
23134 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
23135 ASSERT_VK_SUCCESS(err);
23136 // A compatible ds image.
23137 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060023138 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 -070023139 ASSERT_TRUE(image.initialized());
23140
23141 VkImageViewCreateInfo ivci = {
23142 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
23143 nullptr,
23144 0,
23145 image.handle(),
23146 VK_IMAGE_VIEW_TYPE_2D,
Tony Barbourf887b162017-03-09 10:06:46 -070023147 depth_format,
Tobin Ehlis01103de2017-02-16 13:22:47 -070023148 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
23149 VK_COMPONENT_SWIZZLE_IDENTITY},
23150 {VK_IMAGE_ASPECT_DEPTH_BIT, 0, 1, 0, 1},
23151 };
23152 VkImageView view;
23153 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
23154 ASSERT_VK_SUCCESS(err);
23155
23156 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
23157 VkFramebuffer fb;
23158 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
23159 ASSERT_VK_SUCCESS(err);
23160
23161 VkRenderPassBeginInfo rpbi = {VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb, {{0, 0}, {32, 32}}, 0, nullptr};
23162 m_commandBuffer->BeginCommandBuffer();
23163 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
23164 vkCmdEndRenderPass(m_commandBuffer->handle());
23165 m_commandBuffer->EndCommandBuffer();
23166 QueueCommandBuffer(false);
23167 m_errorMonitor->VerifyNotFound();
23168
23169 // Cleanup
23170 vkDestroyImageView(m_device->device(), view, NULL);
23171 vkDestroyRenderPass(m_device->device(), rp, NULL);
23172 vkDestroyFramebuffer(m_device->device(), fb, NULL);
23173}
23174
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023175TEST_F(VkPositiveLayerTest, CreatePipelineAttribMatrixType) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023176 TEST_DESCRIPTION(
23177 "Test that pipeline validation accepts matrices passed "
23178 "as vertex attributes");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023179 m_errorMonitor->ExpectSuccess();
23180
Tony Barbour1fa09702017-03-16 12:09:08 -060023181 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023182 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
23183
23184 VkVertexInputBindingDescription input_binding;
23185 memset(&input_binding, 0, sizeof(input_binding));
23186
23187 VkVertexInputAttributeDescription input_attribs[2];
23188 memset(input_attribs, 0, sizeof(input_attribs));
23189
23190 for (int i = 0; i < 2; i++) {
23191 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
23192 input_attribs[i].location = i;
23193 }
23194
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023195 char const *vsSource =
23196 "#version 450\n"
23197 "\n"
23198 "layout(location=0) in mat2x4 x;\n"
23199 "out gl_PerVertex {\n"
23200 " vec4 gl_Position;\n"
23201 "};\n"
23202 "void main(){\n"
23203 " gl_Position = x[0] + x[1];\n"
23204 "}\n";
23205 char const *fsSource =
23206 "#version 450\n"
23207 "\n"
23208 "layout(location=0) out vec4 color;\n"
23209 "void main(){\n"
23210 " color = vec4(1);\n"
23211 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023212
23213 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
23214 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
23215
23216 VkPipelineObj pipe(m_device);
23217 pipe.AddColorAttachment();
23218 pipe.AddShader(&vs);
23219 pipe.AddShader(&fs);
23220
23221 pipe.AddVertexInputBindings(&input_binding, 1);
23222 pipe.AddVertexInputAttribs(input_attribs, 2);
23223
23224 VkDescriptorSetObj descriptorSet(m_device);
23225 descriptorSet.AppendDummy();
23226 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
23227
23228 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
23229
23230 /* expect success */
23231 m_errorMonitor->VerifyNotFound();
23232}
23233
23234TEST_F(VkPositiveLayerTest, CreatePipelineAttribArrayType) {
23235 m_errorMonitor->ExpectSuccess();
23236
Tony Barbour1fa09702017-03-16 12:09:08 -060023237 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023238 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
23239
23240 VkVertexInputBindingDescription input_binding;
23241 memset(&input_binding, 0, sizeof(input_binding));
23242
23243 VkVertexInputAttributeDescription input_attribs[2];
23244 memset(input_attribs, 0, sizeof(input_attribs));
23245
23246 for (int i = 0; i < 2; i++) {
23247 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
23248 input_attribs[i].location = i;
23249 }
23250
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023251 char const *vsSource =
23252 "#version 450\n"
23253 "\n"
23254 "layout(location=0) in vec4 x[2];\n"
23255 "out gl_PerVertex {\n"
23256 " vec4 gl_Position;\n"
23257 "};\n"
23258 "void main(){\n"
23259 " gl_Position = x[0] + x[1];\n"
23260 "}\n";
23261 char const *fsSource =
23262 "#version 450\n"
23263 "\n"
23264 "layout(location=0) out vec4 color;\n"
23265 "void main(){\n"
23266 " color = vec4(1);\n"
23267 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023268
23269 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
23270 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
23271
23272 VkPipelineObj pipe(m_device);
23273 pipe.AddColorAttachment();
23274 pipe.AddShader(&vs);
23275 pipe.AddShader(&fs);
23276
23277 pipe.AddVertexInputBindings(&input_binding, 1);
23278 pipe.AddVertexInputAttribs(input_attribs, 2);
23279
23280 VkDescriptorSetObj descriptorSet(m_device);
23281 descriptorSet.AppendDummy();
23282 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
23283
23284 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
23285
23286 m_errorMonitor->VerifyNotFound();
23287}
23288
23289TEST_F(VkPositiveLayerTest, CreatePipelineAttribComponents) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023290 TEST_DESCRIPTION(
23291 "Test that pipeline validation accepts consuming a vertex attribute "
23292 "through multiple vertex shader inputs, each consuming a different "
23293 "subset of the components.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023294 m_errorMonitor->ExpectSuccess();
23295
Tony Barbour1fa09702017-03-16 12:09:08 -060023296 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023297 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
23298
23299 VkVertexInputBindingDescription input_binding;
23300 memset(&input_binding, 0, sizeof(input_binding));
23301
23302 VkVertexInputAttributeDescription input_attribs[3];
23303 memset(input_attribs, 0, sizeof(input_attribs));
23304
23305 for (int i = 0; i < 3; i++) {
23306 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
23307 input_attribs[i].location = i;
23308 }
23309
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023310 char const *vsSource =
23311 "#version 450\n"
23312 "\n"
23313 "layout(location=0) in vec4 x;\n"
23314 "layout(location=1) in vec3 y1;\n"
23315 "layout(location=1, component=3) in float y2;\n"
23316 "layout(location=2) in vec4 z;\n"
23317 "out gl_PerVertex {\n"
23318 " vec4 gl_Position;\n"
23319 "};\n"
23320 "void main(){\n"
23321 " gl_Position = x + vec4(y1, y2) + z;\n"
23322 "}\n";
23323 char const *fsSource =
23324 "#version 450\n"
23325 "\n"
23326 "layout(location=0) out vec4 color;\n"
23327 "void main(){\n"
23328 " color = vec4(1);\n"
23329 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023330
23331 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
23332 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
23333
23334 VkPipelineObj pipe(m_device);
23335 pipe.AddColorAttachment();
23336 pipe.AddShader(&vs);
23337 pipe.AddShader(&fs);
23338
23339 pipe.AddVertexInputBindings(&input_binding, 1);
23340 pipe.AddVertexInputAttribs(input_attribs, 3);
23341
23342 VkDescriptorSetObj descriptorSet(m_device);
23343 descriptorSet.AppendDummy();
23344 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
23345
23346 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
23347
23348 m_errorMonitor->VerifyNotFound();
23349}
23350
23351TEST_F(VkPositiveLayerTest, CreatePipelineSimplePositive) {
23352 m_errorMonitor->ExpectSuccess();
23353
Tony Barbour1fa09702017-03-16 12:09:08 -060023354 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023355 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
23356
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023357 char const *vsSource =
23358 "#version 450\n"
23359 "out gl_PerVertex {\n"
23360 " vec4 gl_Position;\n"
23361 "};\n"
23362 "void main(){\n"
23363 " gl_Position = vec4(0);\n"
23364 "}\n";
23365 char const *fsSource =
23366 "#version 450\n"
23367 "\n"
23368 "layout(location=0) out vec4 color;\n"
23369 "void main(){\n"
23370 " color = vec4(1);\n"
23371 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023372
23373 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
23374 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
23375
23376 VkPipelineObj pipe(m_device);
23377 pipe.AddColorAttachment();
23378 pipe.AddShader(&vs);
23379 pipe.AddShader(&fs);
23380
23381 VkDescriptorSetObj descriptorSet(m_device);
23382 descriptorSet.AppendDummy();
23383 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
23384
23385 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
23386
23387 m_errorMonitor->VerifyNotFound();
23388}
23389
23390TEST_F(VkPositiveLayerTest, CreatePipelineRelaxedTypeMatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023391 TEST_DESCRIPTION(
23392 "Test that pipeline validation accepts the relaxed type matching rules "
23393 "set out in 14.1.3: fundamental type must match, and producer side must "
23394 "have at least as many components");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023395 m_errorMonitor->ExpectSuccess();
23396
23397 // VK 1.0.8 Specification, 14.1.3 "Additionally,..." block
23398
Tony Barbour1fa09702017-03-16 12:09:08 -060023399 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023400 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
23401
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023402 char const *vsSource =
23403 "#version 450\n"
23404 "out gl_PerVertex {\n"
23405 " vec4 gl_Position;\n"
23406 "};\n"
23407 "layout(location=0) out vec3 x;\n"
23408 "layout(location=1) out ivec3 y;\n"
23409 "layout(location=2) out vec3 z;\n"
23410 "void main(){\n"
23411 " gl_Position = vec4(0);\n"
23412 " x = vec3(0); y = ivec3(0); z = vec3(0);\n"
23413 "}\n";
23414 char const *fsSource =
23415 "#version 450\n"
23416 "\n"
23417 "layout(location=0) out vec4 color;\n"
23418 "layout(location=0) in float x;\n"
23419 "layout(location=1) flat in int y;\n"
23420 "layout(location=2) in vec2 z;\n"
23421 "void main(){\n"
23422 " color = vec4(1 + x + y + z.x);\n"
23423 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023424
23425 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
23426 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
23427
23428 VkPipelineObj pipe(m_device);
23429 pipe.AddColorAttachment();
23430 pipe.AddShader(&vs);
23431 pipe.AddShader(&fs);
23432
23433 VkDescriptorSetObj descriptorSet(m_device);
23434 descriptorSet.AppendDummy();
23435 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
23436
23437 VkResult err = VK_SUCCESS;
23438 err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
23439 ASSERT_VK_SUCCESS(err);
23440
23441 m_errorMonitor->VerifyNotFound();
23442}
23443
23444TEST_F(VkPositiveLayerTest, CreatePipelineTessPerVertex) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023445 TEST_DESCRIPTION(
23446 "Test that pipeline validation accepts per-vertex variables "
23447 "passed between the TCS and TES stages");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023448 m_errorMonitor->ExpectSuccess();
23449
Tony Barbour1fa09702017-03-16 12:09:08 -060023450 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023451 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
23452
23453 if (!m_device->phy().features().tessellationShader) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070023454 printf(" Device does not support tessellation shaders; skipped.\n");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023455 return;
23456 }
23457
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023458 char const *vsSource =
23459 "#version 450\n"
23460 "void main(){}\n";
23461 char const *tcsSource =
23462 "#version 450\n"
23463 "layout(location=0) out int x[];\n"
23464 "layout(vertices=3) out;\n"
23465 "void main(){\n"
23466 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
23467 " gl_TessLevelInner[0] = 1;\n"
23468 " x[gl_InvocationID] = gl_InvocationID;\n"
23469 "}\n";
23470 char const *tesSource =
23471 "#version 450\n"
23472 "layout(triangles, equal_spacing, cw) in;\n"
23473 "layout(location=0) in int x[];\n"
23474 "out gl_PerVertex { vec4 gl_Position; };\n"
23475 "void main(){\n"
23476 " gl_Position.xyz = gl_TessCoord;\n"
23477 " gl_Position.w = x[0] + x[1] + x[2];\n"
23478 "}\n";
23479 char const *fsSource =
23480 "#version 450\n"
23481 "layout(location=0) out vec4 color;\n"
23482 "void main(){\n"
23483 " color = vec4(1);\n"
23484 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023485
23486 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
23487 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
23488 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
23489 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
23490
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023491 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
23492 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023493
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023494 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023495
23496 VkPipelineObj pipe(m_device);
23497 pipe.SetInputAssembly(&iasci);
23498 pipe.SetTessellation(&tsci);
23499 pipe.AddColorAttachment();
23500 pipe.AddShader(&vs);
23501 pipe.AddShader(&tcs);
23502 pipe.AddShader(&tes);
23503 pipe.AddShader(&fs);
23504
23505 VkDescriptorSetObj descriptorSet(m_device);
23506 descriptorSet.AppendDummy();
23507 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
23508
23509 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
23510
23511 m_errorMonitor->VerifyNotFound();
23512}
23513
23514TEST_F(VkPositiveLayerTest, CreatePipelineGeometryInputBlockPositive) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023515 TEST_DESCRIPTION(
23516 "Test that pipeline validation accepts a user-defined "
23517 "interface block passed into the geometry shader. This "
23518 "is interesting because the 'extra' array level is not "
23519 "present on the member type, but on the block instance.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023520 m_errorMonitor->ExpectSuccess();
23521
Tony Barbour1fa09702017-03-16 12:09:08 -060023522 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023523 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
23524
23525 if (!m_device->phy().features().geometryShader) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070023526 printf(" Device does not support geometry shaders; skipped.\n");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023527 return;
23528 }
23529
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023530 char const *vsSource =
23531 "#version 450\n"
23532 "layout(location=0) out VertexData { vec4 x; } vs_out;\n"
23533 "void main(){\n"
23534 " vs_out.x = vec4(1);\n"
23535 "}\n";
23536 char const *gsSource =
23537 "#version 450\n"
23538 "layout(triangles) in;\n"
23539 "layout(triangle_strip, max_vertices=3) out;\n"
23540 "layout(location=0) in VertexData { vec4 x; } gs_in[];\n"
23541 "out gl_PerVertex { vec4 gl_Position; };\n"
23542 "void main() {\n"
23543 " gl_Position = gs_in[0].x;\n"
23544 " EmitVertex();\n"
23545 "}\n";
23546 char const *fsSource =
23547 "#version 450\n"
23548 "layout(location=0) out vec4 color;\n"
23549 "void main(){\n"
23550 " color = vec4(1);\n"
23551 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023552
23553 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
23554 VkShaderObj gs(m_device, gsSource, VK_SHADER_STAGE_GEOMETRY_BIT, this);
23555 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
23556
23557 VkPipelineObj pipe(m_device);
23558 pipe.AddColorAttachment();
23559 pipe.AddShader(&vs);
23560 pipe.AddShader(&gs);
23561 pipe.AddShader(&fs);
23562
23563 VkDescriptorSetObj descriptorSet(m_device);
23564 descriptorSet.AppendDummy();
23565 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
23566
23567 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
23568
23569 m_errorMonitor->VerifyNotFound();
23570}
23571
23572TEST_F(VkPositiveLayerTest, CreatePipeline64BitAttributesPositive) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023573 TEST_DESCRIPTION(
23574 "Test that pipeline validation accepts basic use of 64bit vertex "
23575 "attributes. This is interesting because they consume multiple "
23576 "locations.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023577 m_errorMonitor->ExpectSuccess();
23578
Tony Barbour1fa09702017-03-16 12:09:08 -060023579 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023580 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
23581
23582 if (!m_device->phy().features().shaderFloat64) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070023583 printf(" Device does not support 64bit vertex attributes; skipped.\n");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023584 return;
23585 }
23586
23587 VkVertexInputBindingDescription input_bindings[1];
23588 memset(input_bindings, 0, sizeof(input_bindings));
23589
23590 VkVertexInputAttributeDescription input_attribs[4];
23591 memset(input_attribs, 0, sizeof(input_attribs));
23592 input_attribs[0].location = 0;
23593 input_attribs[0].offset = 0;
23594 input_attribs[0].format = VK_FORMAT_R64G64B64A64_SFLOAT;
23595 input_attribs[1].location = 2;
23596 input_attribs[1].offset = 32;
23597 input_attribs[1].format = VK_FORMAT_R64G64B64A64_SFLOAT;
23598 input_attribs[2].location = 4;
23599 input_attribs[2].offset = 64;
23600 input_attribs[2].format = VK_FORMAT_R64G64B64A64_SFLOAT;
23601 input_attribs[3].location = 6;
23602 input_attribs[3].offset = 96;
23603 input_attribs[3].format = VK_FORMAT_R64G64B64A64_SFLOAT;
23604
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023605 char const *vsSource =
23606 "#version 450\n"
23607 "\n"
23608 "layout(location=0) in dmat4 x;\n"
23609 "out gl_PerVertex {\n"
23610 " vec4 gl_Position;\n"
23611 "};\n"
23612 "void main(){\n"
23613 " gl_Position = vec4(x[0][0]);\n"
23614 "}\n";
23615 char const *fsSource =
23616 "#version 450\n"
23617 "\n"
23618 "layout(location=0) out vec4 color;\n"
23619 "void main(){\n"
23620 " color = vec4(1);\n"
23621 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023622
23623 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
23624 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
23625
23626 VkPipelineObj pipe(m_device);
23627 pipe.AddColorAttachment();
23628 pipe.AddShader(&vs);
23629 pipe.AddShader(&fs);
23630
23631 pipe.AddVertexInputBindings(input_bindings, 1);
23632 pipe.AddVertexInputAttribs(input_attribs, 4);
23633
23634 VkDescriptorSetObj descriptorSet(m_device);
23635 descriptorSet.AppendDummy();
23636 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
23637
23638 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
23639
23640 m_errorMonitor->VerifyNotFound();
23641}
23642
23643TEST_F(VkPositiveLayerTest, CreatePipelineInputAttachmentPositive) {
23644 TEST_DESCRIPTION("Positive test for a correctly matched input attachment");
23645 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 *vsSource =
23650 "#version 450\n"
23651 "\n"
23652 "out gl_PerVertex {\n"
23653 " vec4 gl_Position;\n"
23654 "};\n"
23655 "void main(){\n"
23656 " gl_Position = vec4(1);\n"
23657 "}\n";
23658 char const *fsSource =
23659 "#version 450\n"
23660 "\n"
23661 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
23662 "layout(location=0) out vec4 color;\n"
23663 "void main() {\n"
23664 " color = subpassLoad(x);\n"
23665 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023666
23667 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
23668 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
23669
23670 VkPipelineObj pipe(m_device);
23671 pipe.AddShader(&vs);
23672 pipe.AddShader(&fs);
23673 pipe.AddColorAttachment();
23674 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
23675
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023676 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
23677 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023678 VkDescriptorSetLayout dsl;
23679 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
23680 ASSERT_VK_SUCCESS(err);
23681
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023682 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023683 VkPipelineLayout pl;
23684 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
23685 ASSERT_VK_SUCCESS(err);
23686
23687 VkAttachmentDescription descs[2] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023688 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
23689 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
23690 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
23691 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
23692 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 -060023693 };
23694 VkAttachmentReference color = {
23695 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
23696 };
23697 VkAttachmentReference input = {
23698 1, VK_IMAGE_LAYOUT_GENERAL,
23699 };
23700
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023701 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023702
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023703 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023704 VkRenderPass rp;
23705 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
23706 ASSERT_VK_SUCCESS(err);
23707
23708 // should be OK. would go wrong here if it's going to...
23709 pipe.CreateVKPipeline(pl, rp);
23710
23711 m_errorMonitor->VerifyNotFound();
23712
23713 vkDestroyRenderPass(m_device->device(), rp, nullptr);
23714 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
23715 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
23716}
23717
23718TEST_F(VkPositiveLayerTest, CreateComputePipelineMissingDescriptorUnusedPositive) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023719 TEST_DESCRIPTION(
23720 "Test that pipeline validation accepts a compute pipeline which declares a "
23721 "descriptor-backed resource which is not provided, but the shader does not "
23722 "statically use it. This is interesting because it requires compute pipelines "
23723 "to have a proper descriptor use walk, which they didn't for some time.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023724 m_errorMonitor->ExpectSuccess();
23725
Tony Barbour1fa09702017-03-16 12:09:08 -060023726 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023727
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023728 char const *csSource =
23729 "#version 450\n"
23730 "\n"
23731 "layout(local_size_x=1) in;\n"
23732 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
23733 "void main(){\n"
23734 " // x is not used.\n"
23735 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023736
23737 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
23738
23739 VkDescriptorSetObj descriptorSet(m_device);
23740 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
23741
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023742 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
23743 nullptr,
23744 0,
23745 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
23746 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
23747 descriptorSet.GetPipelineLayout(),
23748 VK_NULL_HANDLE,
23749 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023750
23751 VkPipeline pipe;
23752 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
23753
23754 m_errorMonitor->VerifyNotFound();
23755
23756 if (err == VK_SUCCESS) {
23757 vkDestroyPipeline(m_device->device(), pipe, nullptr);
23758 }
23759}
23760
23761TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsSampler) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023762 TEST_DESCRIPTION(
23763 "Test that pipeline validation accepts a shader consuming only the "
23764 "sampler portion of a combined image + sampler");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023765 m_errorMonitor->ExpectSuccess();
23766
Tony Barbour1fa09702017-03-16 12:09:08 -060023767 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023768
23769 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023770 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
23771 {1, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
23772 {2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023773 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023774 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023775 VkDescriptorSetLayout dsl;
23776 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
23777 ASSERT_VK_SUCCESS(err);
23778
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023779 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023780 VkPipelineLayout pl;
23781 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
23782 ASSERT_VK_SUCCESS(err);
23783
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023784 char const *csSource =
23785 "#version 450\n"
23786 "\n"
23787 "layout(local_size_x=1) in;\n"
23788 "layout(set=0, binding=0) uniform sampler s;\n"
23789 "layout(set=0, binding=1) uniform texture2D t;\n"
23790 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
23791 "void main() {\n"
23792 " x = texture(sampler2D(t, s), vec2(0));\n"
23793 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023794 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
23795
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023796 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
23797 nullptr,
23798 0,
23799 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
23800 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
23801 pl,
23802 VK_NULL_HANDLE,
23803 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023804
23805 VkPipeline pipe;
23806 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
23807
23808 m_errorMonitor->VerifyNotFound();
23809
23810 if (err == VK_SUCCESS) {
23811 vkDestroyPipeline(m_device->device(), pipe, nullptr);
23812 }
23813
23814 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
23815 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
23816}
23817
23818TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsImage) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023819 TEST_DESCRIPTION(
23820 "Test that pipeline validation accepts a shader consuming only the "
23821 "image portion of a combined image + sampler");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023822 m_errorMonitor->ExpectSuccess();
23823
Tony Barbour1fa09702017-03-16 12:09:08 -060023824 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023825
23826 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023827 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
23828 {1, VK_DESCRIPTOR_TYPE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
23829 {2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023830 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023831 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023832 VkDescriptorSetLayout dsl;
23833 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
23834 ASSERT_VK_SUCCESS(err);
23835
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023836 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023837 VkPipelineLayout pl;
23838 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
23839 ASSERT_VK_SUCCESS(err);
23840
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023841 char const *csSource =
23842 "#version 450\n"
23843 "\n"
23844 "layout(local_size_x=1) in;\n"
23845 "layout(set=0, binding=0) uniform texture2D t;\n"
23846 "layout(set=0, binding=1) uniform sampler s;\n"
23847 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
23848 "void main() {\n"
23849 " x = texture(sampler2D(t, s), vec2(0));\n"
23850 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023851 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
23852
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023853 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
23854 nullptr,
23855 0,
23856 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
23857 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
23858 pl,
23859 VK_NULL_HANDLE,
23860 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023861
23862 VkPipeline pipe;
23863 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
23864
23865 m_errorMonitor->VerifyNotFound();
23866
23867 if (err == VK_SUCCESS) {
23868 vkDestroyPipeline(m_device->device(), pipe, nullptr);
23869 }
23870
23871 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
23872 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
23873}
23874
23875TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsBoth) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023876 TEST_DESCRIPTION(
23877 "Test that pipeline validation accepts a shader consuming "
23878 "both the sampler and the image of a combined image+sampler "
23879 "but via separate variables");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023880 m_errorMonitor->ExpectSuccess();
23881
Tony Barbour1fa09702017-03-16 12:09:08 -060023882 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023883
23884 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023885 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
23886 {1, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023887 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023888 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 2, bindings};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023889 VkDescriptorSetLayout dsl;
23890 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
23891 ASSERT_VK_SUCCESS(err);
23892
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023893 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023894 VkPipelineLayout pl;
23895 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
23896 ASSERT_VK_SUCCESS(err);
23897
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023898 char const *csSource =
23899 "#version 450\n"
23900 "\n"
23901 "layout(local_size_x=1) in;\n"
23902 "layout(set=0, binding=0) uniform texture2D t;\n"
23903 "layout(set=0, binding=0) uniform sampler s; // both binding 0!\n"
23904 "layout(set=0, binding=1) buffer block { vec4 x; };\n"
23905 "void main() {\n"
23906 " x = texture(sampler2D(t, s), vec2(0));\n"
23907 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023908 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
23909
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023910 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
23911 nullptr,
23912 0,
23913 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
23914 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
23915 pl,
23916 VK_NULL_HANDLE,
23917 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023918
23919 VkPipeline pipe;
23920 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
23921
23922 m_errorMonitor->VerifyNotFound();
23923
23924 if (err == VK_SUCCESS) {
23925 vkDestroyPipeline(m_device->device(), pipe, nullptr);
23926 }
23927
23928 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
23929 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
23930}
23931
Tony Barbour3ed87a02017-03-15 16:19:02 -060023932TEST_F(VkPositiveLayerTest, Maintenance1Tests) {
Mark Lobodzinskidf784fc2017-03-14 09:18:40 -060023933 TEST_DESCRIPTION("Validate various special cases for the Maintenance1_KHR extension");
23934
Tony Barbour3ed87a02017-03-15 16:19:02 -060023935 device_extension_names.push_back(VK_KHR_MAINTENANCE1_EXTENSION_NAME);
Tony Barbour73c0f352017-03-16 15:55:38 -060023936 InitFramework(instance_layer_names, instance_extension_names, device_extension_names, myDbgFunc, m_errorMonitor);
Tony Barbour3ed87a02017-03-15 16:19:02 -060023937
Mark Lobodzinskidf784fc2017-03-14 09:18:40 -060023938 // Ensure that extension is available and enabled.
23939 uint32_t extension_count = 0;
23940 bool supports_maintenance1_extension = false;
23941 VkResult err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, nullptr);
23942 ASSERT_VK_SUCCESS(err);
23943 if (extension_count > 0) {
23944 std::vector<VkExtensionProperties> available_extensions(extension_count);
23945
23946 err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, &available_extensions[0]);
23947 ASSERT_VK_SUCCESS(err);
23948 for (const auto &extension_props : available_extensions) {
23949 if (strcmp(extension_props.extensionName, VK_KHR_MAINTENANCE1_EXTENSION_NAME) == 0) {
23950 supports_maintenance1_extension = true;
23951 }
23952 }
23953 }
23954
23955 // Proceed if extension is supported by hardware
23956 if (!supports_maintenance1_extension) {
23957 printf(" Maintenance1 Extension not supported, skipping tests\n");
23958 return;
23959 }
Mark Lobodzinskidf784fc2017-03-14 09:18:40 -060023960
23961 m_errorMonitor->ExpectSuccess();
Dave Houlton8e0fe7a2017-03-30 10:32:10 -060023962 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskidf784fc2017-03-14 09:18:40 -060023963 VkCommandBuffer cmd_buf;
23964 VkCommandBufferAllocateInfo alloc_info;
23965 alloc_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
23966 alloc_info.pNext = NULL;
23967 alloc_info.commandBufferCount = 1;
Mike Schuchardt06304c22017-03-01 17:09:09 -070023968 alloc_info.commandPool = m_commandPool->handle();
Mark Lobodzinskidf784fc2017-03-14 09:18:40 -060023969 alloc_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
23970 vkAllocateCommandBuffers(m_device->device(), &alloc_info, &cmd_buf);
23971
23972 VkCommandBufferBeginInfo cb_binfo;
23973 cb_binfo.pNext = NULL;
23974 cb_binfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
23975 cb_binfo.pInheritanceInfo = VK_NULL_HANDLE;
23976 cb_binfo.flags = 0;
23977 vkBeginCommandBuffer(cmd_buf, &cb_binfo);
23978 // Set Negative height, should give error if Maintenance 1 is not enabled
23979 VkViewport viewport = {0, 0, 16, -16, 0, 1};
23980 vkCmdSetViewport(cmd_buf, 0, 1, &viewport);
23981 vkEndCommandBuffer(cmd_buf);
23982
23983 m_errorMonitor->VerifyNotFound();
23984}
23985
Mark Lobodzinski35ecad32017-03-27 13:09:07 -060023986TEST_F(VkLayerTest, DuplicateValidPNextStructures) {
23987 TEST_DESCRIPTION("Create a pNext chain containing valid strutures, but with a duplicate structure type");
23988
23989 ASSERT_NO_FATAL_FAILURE(Init());
23990
23991 uint32_t extension_count = 0;
23992 VkResult err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, nullptr);
23993 ASSERT_VK_SUCCESS(err);
23994
23995 if (extension_count > 0) {
23996 std::vector<VkExtensionProperties> available_extensions(extension_count);
23997 err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, &available_extensions[0]);
23998 ASSERT_VK_SUCCESS(err);
23999
24000 for (const auto &extension_props : available_extensions) {
24001 if (strcmp(extension_props.extensionName, VK_NV_DEDICATED_ALLOCATION_EXTENSION_NAME) == 0) {
24002 // Create two pNext structures which by themselves would be valid
24003 VkDedicatedAllocationBufferCreateInfoNV dedicated_buffer_create_info = {};
24004 VkDedicatedAllocationBufferCreateInfoNV dedicated_buffer_create_info_2 = {};
24005 dedicated_buffer_create_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_BUFFER_CREATE_INFO_NV;
24006 dedicated_buffer_create_info.pNext = &dedicated_buffer_create_info_2;
24007 dedicated_buffer_create_info.dedicatedAllocation = VK_TRUE;
24008
24009 dedicated_buffer_create_info_2.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_BUFFER_CREATE_INFO_NV;
24010 dedicated_buffer_create_info_2.pNext = nullptr;
24011 dedicated_buffer_create_info_2.dedicatedAllocation = VK_TRUE;
24012
24013 uint32_t queue_family_index = 0;
24014 VkBufferCreateInfo buffer_create_info = {};
24015 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
24016 buffer_create_info.pNext = &dedicated_buffer_create_info;
24017 buffer_create_info.size = 1024;
24018 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
24019 buffer_create_info.queueFamilyIndexCount = 1;
24020 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
24021
24022 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "chain contains duplicate structure types");
24023 VkBuffer buffer;
24024 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
24025 m_errorMonitor->VerifyFound();
24026 }
24027 }
24028 }
24029}
24030
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024031TEST_F(VkPositiveLayerTest, ValidStructPNext) {
24032 TEST_DESCRIPTION("Verify that a valid pNext value is handled correctly");
24033
Tony Barbour1fa09702017-03-16 12:09:08 -060024034 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024035
24036 // Positive test to check parameter_validation and unique_objects support
24037 // for NV_dedicated_allocation
24038 uint32_t extension_count = 0;
24039 bool supports_nv_dedicated_allocation = false;
24040 VkResult err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, nullptr);
24041 ASSERT_VK_SUCCESS(err);
24042
24043 if (extension_count > 0) {
24044 std::vector<VkExtensionProperties> available_extensions(extension_count);
24045
24046 err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, &available_extensions[0]);
24047 ASSERT_VK_SUCCESS(err);
24048
24049 for (const auto &extension_props : available_extensions) {
24050 if (strcmp(extension_props.extensionName, VK_NV_DEDICATED_ALLOCATION_EXTENSION_NAME) == 0) {
24051 supports_nv_dedicated_allocation = true;
24052 }
24053 }
24054 }
24055
24056 if (supports_nv_dedicated_allocation) {
24057 m_errorMonitor->ExpectSuccess();
24058
24059 VkDedicatedAllocationBufferCreateInfoNV dedicated_buffer_create_info = {};
24060 dedicated_buffer_create_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_BUFFER_CREATE_INFO_NV;
24061 dedicated_buffer_create_info.pNext = nullptr;
24062 dedicated_buffer_create_info.dedicatedAllocation = VK_TRUE;
24063
24064 uint32_t queue_family_index = 0;
24065 VkBufferCreateInfo buffer_create_info = {};
24066 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
24067 buffer_create_info.pNext = &dedicated_buffer_create_info;
24068 buffer_create_info.size = 1024;
24069 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
24070 buffer_create_info.queueFamilyIndexCount = 1;
24071 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
24072
24073 VkBuffer buffer;
Karl Schultz47dd59d2017-01-20 13:19:20 -070024074 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024075 ASSERT_VK_SUCCESS(err);
24076
24077 VkMemoryRequirements memory_reqs;
24078 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
24079
24080 VkDedicatedAllocationMemoryAllocateInfoNV dedicated_memory_info = {};
24081 dedicated_memory_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_MEMORY_ALLOCATE_INFO_NV;
24082 dedicated_memory_info.pNext = nullptr;
24083 dedicated_memory_info.buffer = buffer;
24084 dedicated_memory_info.image = VK_NULL_HANDLE;
24085
24086 VkMemoryAllocateInfo memory_info = {};
24087 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
24088 memory_info.pNext = &dedicated_memory_info;
24089 memory_info.allocationSize = memory_reqs.size;
24090
24091 bool pass;
24092 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
24093 ASSERT_TRUE(pass);
24094
24095 VkDeviceMemory buffer_memory;
24096 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
24097 ASSERT_VK_SUCCESS(err);
24098
24099 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
24100 ASSERT_VK_SUCCESS(err);
24101
24102 vkDestroyBuffer(m_device->device(), buffer, NULL);
24103 vkFreeMemory(m_device->device(), buffer_memory, NULL);
24104
24105 m_errorMonitor->VerifyNotFound();
24106 }
24107}
24108
24109TEST_F(VkPositiveLayerTest, PSOPolygonModeValid) {
24110 VkResult err;
24111
24112 TEST_DESCRIPTION("Verify that using a solid polygon fill mode works correctly.");
24113
Tony Barbour1fa09702017-03-16 12:09:08 -060024114 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024115 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
24116
24117 std::vector<const char *> device_extension_names;
24118 auto features = m_device->phy().features();
24119 // Artificially disable support for non-solid fill modes
24120 features.fillModeNonSolid = false;
24121 // The sacrificial device object
24122 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
24123
24124 VkRenderpassObj render_pass(&test_device);
24125
24126 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
24127 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
24128 pipeline_layout_ci.setLayoutCount = 0;
24129 pipeline_layout_ci.pSetLayouts = NULL;
24130
24131 VkPipelineLayout pipeline_layout;
24132 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
24133 ASSERT_VK_SUCCESS(err);
24134
24135 VkPipelineRasterizationStateCreateInfo rs_ci = {};
24136 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
24137 rs_ci.pNext = nullptr;
24138 rs_ci.lineWidth = 1.0f;
24139 rs_ci.rasterizerDiscardEnable = true;
24140
24141 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
24142 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
24143
24144 // Set polygonMode=FILL. No error is expected
24145 m_errorMonitor->ExpectSuccess();
24146 {
24147 VkPipelineObj pipe(&test_device);
24148 pipe.AddShader(&vs);
24149 pipe.AddShader(&fs);
24150 pipe.AddColorAttachment();
24151 // Set polygonMode to a good value
24152 rs_ci.polygonMode = VK_POLYGON_MODE_FILL;
24153 pipe.SetRasterization(&rs_ci);
24154 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
24155 }
24156 m_errorMonitor->VerifyNotFound();
24157
24158 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
24159}
24160
Dave Houlton1150cf52017-04-27 14:38:11 -060024161TEST_F(VkPositiveLayerTest, LongSemaphoreChain) {
Chris Forbes94196952017-04-06 16:30:59 -070024162 m_errorMonitor->ExpectSuccess();
24163
24164 ASSERT_NO_FATAL_FAILURE(Init());
24165 VkResult err;
24166
24167 std::vector<VkSemaphore> semaphores;
24168
24169 const int chainLength = 32768;
24170 VkPipelineStageFlags flags = VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT;
24171
24172 for (int i = 0; i < chainLength; i++) {
Dave Houlton1150cf52017-04-27 14:38:11 -060024173 VkSemaphoreCreateInfo sci = {VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0};
Chris Forbes94196952017-04-06 16:30:59 -070024174 VkSemaphore semaphore;
24175 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &semaphore);
24176 ASSERT_VK_SUCCESS(err);
24177
24178 semaphores.push_back(semaphore);
24179
Chris Forbesfc50aaa2017-05-01 10:20:17 -070024180 VkSubmitInfo si = {VK_STRUCTURE_TYPE_SUBMIT_INFO,
24181 nullptr,
24182 semaphores.size() > 1 ? 1u : 0u,
24183 semaphores.size() > 1 ? &semaphores[semaphores.size() - 2] : nullptr,
24184 &flags,
24185 0,
24186 nullptr,
24187 1,
24188 &semaphores[semaphores.size() - 1]};
Chris Forbes94196952017-04-06 16:30:59 -070024189 err = vkQueueSubmit(m_device->m_queue, 1, &si, VK_NULL_HANDLE);
24190 ASSERT_VK_SUCCESS(err);
24191 }
24192
Dave Houlton1150cf52017-04-27 14:38:11 -060024193 VkFenceCreateInfo fci = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0};
Chris Forbes94196952017-04-06 16:30:59 -070024194 VkFence fence;
24195 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
24196 ASSERT_VK_SUCCESS(err);
Dave Houlton1150cf52017-04-27 14:38:11 -060024197 VkSubmitInfo si = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 1, &semaphores.back(), &flags, 0, nullptr, 0, nullptr};
Chris Forbes94196952017-04-06 16:30:59 -070024198 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
24199 ASSERT_VK_SUCCESS(err);
24200
24201 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
24202
Dave Houlton1150cf52017-04-27 14:38:11 -060024203 for (auto semaphore : semaphores) vkDestroySemaphore(m_device->device(), semaphore, nullptr);
Chris Forbes94196952017-04-06 16:30:59 -070024204
24205 vkDestroyFence(m_device->device(), fence, nullptr);
24206
24207 m_errorMonitor->VerifyNotFound();
24208}
24209
Mike Stroyanca855662017-05-02 11:06:27 -060024210extern "C" void *ReleaseNullFence(void *arg) {
24211 struct thread_data_struct *data = (struct thread_data_struct *)arg;
24212
24213 for (int i = 0; i < 40000; i++) {
24214 vkDestroyFence(data->device, VK_NULL_HANDLE, NULL);
24215 if (data->bailout) {
24216 break;
24217 }
24218 }
24219 return NULL;
24220}
24221
24222TEST_F(VkPositiveLayerTest, ThreadNullFenceCollision) {
24223 test_platform_thread thread;
24224
24225 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "THREADING ERROR");
24226
24227 ASSERT_NO_FATAL_FAILURE(Init());
24228
24229 struct thread_data_struct data;
24230 data.device = m_device->device();
24231 data.bailout = false;
24232 m_errorMonitor->SetBailout(&data.bailout);
24233
24234 // Call vkDestroyFence of VK_NULL_HANDLE repeatedly using multiple threads.
24235 // There should be no validation error from collision of that non-object.
24236 test_platform_thread_create(&thread, ReleaseNullFence, (void *)&data);
24237 for (int i = 0; i < 40000; i++) {
24238 vkDestroyFence(m_device->device(), VK_NULL_HANDLE, NULL);
24239 }
24240 test_platform_thread_join(thread, NULL);
24241
24242 m_errorMonitor->SetBailout(NULL);
24243
24244 m_errorMonitor->VerifyNotFound();
24245}
24246
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070024247#if 0 // A few devices have issues with this test so disabling for now
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024248TEST_F(VkPositiveLayerTest, LongFenceChain)
24249{
24250 m_errorMonitor->ExpectSuccess();
24251
Tony Barbour1fa09702017-03-16 12:09:08 -060024252 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024253 VkResult err;
24254
24255 std::vector<VkFence> fences;
24256
24257 const int chainLength = 32768;
24258
24259 for (int i = 0; i < chainLength; i++) {
24260 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
24261 VkFence fence;
24262 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
24263 ASSERT_VK_SUCCESS(err);
24264
24265 fences.push_back(fence);
24266
24267 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr,
24268 0, nullptr, 0, nullptr };
24269 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
24270 ASSERT_VK_SUCCESS(err);
24271
24272 }
24273
24274 // BOOM, stack overflow.
24275 vkWaitForFences(m_device->device(), 1, &fences.back(), VK_TRUE, UINT64_MAX);
24276
24277 for (auto fence : fences)
24278 vkDestroyFence(m_device->device(), fence, nullptr);
24279
24280 m_errorMonitor->VerifyNotFound();
24281}
24282#endif
24283
Cody Northrop1242dfd2016-07-13 17:24:59 -060024284#if defined(ANDROID) && defined(VALIDATION_APK)
Cody Northropb94529f2017-04-05 13:05:51 -060024285const char *appTag = "VulkanLayerValidationTests";
Cody Northrop1242dfd2016-07-13 17:24:59 -060024286static bool initialized = false;
24287static bool active = false;
24288
24289// Convert Intents to argv
24290// Ported from Hologram sample, only difference is flexible key
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024291std::vector<std::string> get_args(android_app &app, const char *intent_extra_data_key) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060024292 std::vector<std::string> args;
24293 JavaVM &vm = *app.activity->vm;
24294 JNIEnv *p_env;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070024295 if (vm.AttachCurrentThread(&p_env, nullptr) != JNI_OK) return args;
Cody Northrop1242dfd2016-07-13 17:24:59 -060024296
24297 JNIEnv &env = *p_env;
24298 jobject activity = app.activity->clazz;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024299 jmethodID get_intent_method = env.GetMethodID(env.GetObjectClass(activity), "getIntent", "()Landroid/content/Intent;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060024300 jobject intent = env.CallObjectMethod(activity, get_intent_method);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024301 jmethodID get_string_extra_method =
24302 env.GetMethodID(env.GetObjectClass(intent), "getStringExtra", "(Ljava/lang/String;)Ljava/lang/String;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060024303 jvalue get_string_extra_args;
24304 get_string_extra_args.l = env.NewStringUTF(intent_extra_data_key);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024305 jstring extra_str = static_cast<jstring>(env.CallObjectMethodA(intent, get_string_extra_method, &get_string_extra_args));
Cody Northrop1242dfd2016-07-13 17:24:59 -060024306
24307 std::string args_str;
24308 if (extra_str) {
24309 const char *extra_utf = env.GetStringUTFChars(extra_str, nullptr);
24310 args_str = extra_utf;
24311 env.ReleaseStringUTFChars(extra_str, extra_utf);
24312 env.DeleteLocalRef(extra_str);
24313 }
24314
24315 env.DeleteLocalRef(get_string_extra_args.l);
24316 env.DeleteLocalRef(intent);
24317 vm.DetachCurrentThread();
24318
24319 // split args_str
24320 std::stringstream ss(args_str);
24321 std::string arg;
24322 while (std::getline(ss, arg, ' ')) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070024323 if (!arg.empty()) args.push_back(arg);
Cody Northrop1242dfd2016-07-13 17:24:59 -060024324 }
24325
24326 return args;
24327}
24328
Dave Houlton11dcd5e2017-04-25 16:00:10 -060024329void addFullTestCommentIfPresent(const ::testing::TestInfo &test_info, std::string &error_message) {
24330 const char *const type_param = test_info.type_param();
24331 const char *const value_param = test_info.value_param();
Cody Northropb94529f2017-04-05 13:05:51 -060024332
24333 if (type_param != NULL || value_param != NULL) {
24334 error_message.append(", where ");
24335 if (type_param != NULL) {
Dave Houlton11dcd5e2017-04-25 16:00:10 -060024336 error_message.append("TypeParam = ").append(type_param);
24337 if (value_param != NULL) error_message.append(" and ");
Cody Northropb94529f2017-04-05 13:05:51 -060024338 }
24339 if (value_param != NULL) {
24340 error_message.append("GetParam() = ").append(value_param);
24341 }
24342 }
24343}
24344
24345// Inspired by https://github.com/google/googletest/blob/master/googletest/docs/AdvancedGuide.md
24346class LogcatPrinter : public ::testing::EmptyTestEventListener {
24347 // Called before a test starts.
Dave Houlton11dcd5e2017-04-25 16:00:10 -060024348 virtual void OnTestStart(const ::testing::TestInfo &test_info) {
Cody Northropb94529f2017-04-05 13:05:51 -060024349 __android_log_print(ANDROID_LOG_INFO, appTag, "[ RUN ] %s.%s", test_info.test_case_name(), test_info.name());
24350 }
24351
24352 // Called after a failed assertion or a SUCCEED() invocation.
Dave Houlton11dcd5e2017-04-25 16:00:10 -060024353 virtual void OnTestPartResult(const ::testing::TestPartResult &result) {
Cody Northropb94529f2017-04-05 13:05:51 -060024354 // If the test part succeeded, we don't need to do anything.
Dave Houlton11dcd5e2017-04-25 16:00:10 -060024355 if (result.type() == ::testing::TestPartResult::kSuccess) return;
Cody Northropb94529f2017-04-05 13:05:51 -060024356
Dave Houlton11dcd5e2017-04-25 16:00:10 -060024357 __android_log_print(ANDROID_LOG_INFO, appTag, "%s in %s:%d %s", result.failed() ? "*** Failure" : "Success",
24358 result.file_name(), result.line_number(), result.summary());
Cody Northropb94529f2017-04-05 13:05:51 -060024359 }
24360
24361 // Called after a test ends.
Dave Houlton11dcd5e2017-04-25 16:00:10 -060024362 virtual void OnTestEnd(const ::testing::TestInfo &info) {
Cody Northropb94529f2017-04-05 13:05:51 -060024363 std::string result;
24364 if (info.result()->Passed()) {
24365 result.append("[ OK ]");
24366 } else {
24367 result.append("[ FAILED ]");
24368 }
24369 result.append(info.test_case_name()).append(".").append(info.name());
Dave Houlton11dcd5e2017-04-25 16:00:10 -060024370 if (info.result()->Failed()) addFullTestCommentIfPresent(info, result);
Cody Northropb94529f2017-04-05 13:05:51 -060024371
24372 if (::testing::GTEST_FLAG(print_time)) {
24373 std::ostringstream os;
24374 os << info.result()->elapsed_time();
24375 result.append(" (").append(os.str()).append(" ms)");
24376 }
24377
24378 __android_log_print(ANDROID_LOG_INFO, appTag, "%s", result.c_str());
24379 };
24380};
24381
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024382static int32_t processInput(struct android_app *app, AInputEvent *event) { return 0; }
Cody Northrop1242dfd2016-07-13 17:24:59 -060024383
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024384static void processCommand(struct android_app *app, int32_t cmd) {
24385 switch (cmd) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070024386 case APP_CMD_INIT_WINDOW: {
24387 if (app->window) {
24388 initialized = true;
24389 }
24390 break;
Cody Northrop1242dfd2016-07-13 17:24:59 -060024391 }
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070024392 case APP_CMD_GAINED_FOCUS: {
24393 active = true;
24394 break;
24395 }
24396 case APP_CMD_LOST_FOCUS: {
24397 active = false;
24398 break;
24399 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060024400 }
24401}
24402
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024403void android_main(struct android_app *app) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060024404 app_dummy();
24405
Cody Northrop1242dfd2016-07-13 17:24:59 -060024406 int vulkanSupport = InitVulkan();
24407 if (vulkanSupport == 0) {
24408 __android_log_print(ANDROID_LOG_INFO, appTag, "==== FAILED ==== No Vulkan support found");
24409 return;
24410 }
24411
24412 app->onAppCmd = processCommand;
24413 app->onInputEvent = processInput;
24414
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024415 while (1) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060024416 int events;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024417 struct android_poll_source *source;
24418 while (ALooper_pollAll(active ? 0 : -1, NULL, &events, (void **)&source) >= 0) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060024419 if (source) {
24420 source->process(app, source);
24421 }
24422
24423 if (app->destroyRequested != 0) {
24424 VkTestFramework::Finish();
24425 return;
24426 }
24427 }
24428
24429 if (initialized && active) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024430 // Use the following key to send arguments to gtest, i.e.
24431 // --es args "--gtest_filter=-VkLayerTest.foo"
24432 const char key[] = "args";
24433 std::vector<std::string> args = get_args(*app, key);
Cody Northrop1242dfd2016-07-13 17:24:59 -060024434
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024435 std::string filter = "";
24436 if (args.size() > 0) {
24437 __android_log_print(ANDROID_LOG_INFO, appTag, "Intent args = %s", args[0].c_str());
24438 filter += args[0];
24439 } else {
24440 __android_log_print(ANDROID_LOG_INFO, appTag, "No Intent args detected");
24441 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060024442
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024443 int argc = 2;
24444 char *argv[] = {(char *)"foo", (char *)filter.c_str()};
24445 __android_log_print(ANDROID_LOG_DEBUG, appTag, "filter = %s", argv[1]);
Cody Northrop1242dfd2016-07-13 17:24:59 -060024446
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024447 // Route output to files until we can override the gtest output
24448 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/out.txt", "w", stdout);
24449 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/err.txt", "w", stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060024450
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024451 ::testing::InitGoogleTest(&argc, argv);
Cody Northropb94529f2017-04-05 13:05:51 -060024452
Dave Houlton11dcd5e2017-04-25 16:00:10 -060024453 ::testing::TestEventListeners &listeners = ::testing::UnitTest::GetInstance()->listeners();
Cody Northropb94529f2017-04-05 13:05:51 -060024454 listeners.Append(new LogcatPrinter);
24455
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024456 VkTestFramework::InitArgs(&argc, argv);
24457 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Cody Northrop1242dfd2016-07-13 17:24:59 -060024458
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024459 int result = RUN_ALL_TESTS();
Cody Northrop1242dfd2016-07-13 17:24:59 -060024460
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024461 if (result != 0) {
24462 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests FAILED ====");
24463 } else {
24464 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests PASSED ====");
24465 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060024466
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024467 VkTestFramework::Finish();
Cody Northrop1242dfd2016-07-13 17:24:59 -060024468
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024469 fclose(stdout);
24470 fclose(stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060024471
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024472 ANativeActivity_finish(app->activity);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024473 return;
Cody Northrop1242dfd2016-07-13 17:24:59 -060024474 }
24475 }
24476}
24477#endif
24478
Tony Barbour300a6082015-04-07 13:44:53 -060024479int main(int argc, char **argv) {
24480 int result;
24481
Cody Northrop8e54a402016-03-08 22:25:52 -070024482#ifdef ANDROID
24483 int vulkanSupport = InitVulkan();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070024484 if (vulkanSupport == 0) return 1;
Cody Northrop8e54a402016-03-08 22:25:52 -070024485#endif
24486
Tony Barbour300a6082015-04-07 13:44:53 -060024487 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -060024488 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour300a6082015-04-07 13:44:53 -060024489
24490 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
24491
24492 result = RUN_ALL_TESTS();
24493
Tony Barbour6918cd52015-04-09 12:58:51 -060024494 VkTestFramework::Finish();
Tony Barbour300a6082015-04-07 13:44:53 -060024495 return result;
24496}