blob: 5cef8dde9c5bf23594f283b83fd2c4552c43531a [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
1060TEST_F(VkLayerTest, FailedReturnValue) {
1061 TEST_DESCRIPTION("Check for a message describing a VkResult failure code");
1062
Tony Barbour1fa09702017-03-16 12:09:08 -06001063 ASSERT_NO_FATAL_FAILURE(Init());
Dustin Gravesfce74c02016-05-10 11:42:58 -06001064
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001065 // Find an unsupported image format
1066 VkFormat unsupported = VK_FORMAT_UNDEFINED;
1067 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
1068 VkFormat format = static_cast<VkFormat>(f);
1069 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001070 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001071 unsupported = format;
1072 break;
1073 }
1074 }
1075
1076 if (unsupported != VK_FORMAT_UNDEFINED) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001077 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
1078 "the requested format is not supported on this device");
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001079 // Specify an unsupported VkFormat value to generate a
1080 // VK_ERROR_FORMAT_NOT_SUPPORTED return code
1081 // Expected to trigger a warning from
1082 // parameter_validation::validate_result
1083 VkImageFormatProperties image_format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001084 VkResult err = vkGetPhysicalDeviceImageFormatProperties(gpu(), unsupported, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
1085 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, 0, &image_format_properties);
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001086 ASSERT_TRUE(err == VK_ERROR_FORMAT_NOT_SUPPORTED);
1087 m_errorMonitor->VerifyFound();
1088 }
Dustin Gravesfce74c02016-05-10 11:42:58 -06001089}
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001090
1091TEST_F(VkLayerTest, UpdateBufferAlignment) {
1092 TEST_DESCRIPTION("Check alignment parameters for vkCmdUpdateBuffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001093 uint32_t updateData[] = {1, 2, 3, 4, 5, 6, 7, 8};
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001094
Tony Barbour1fa09702017-03-16 12:09:08 -06001095 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001096
1097 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1098 vk_testing::Buffer buffer;
1099 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
1100
Tony Barbour552f6c02016-12-21 14:34:07 -07001101 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001102 // Introduce failure by using dstOffset that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001103 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001104 m_commandBuffer->UpdateBuffer(buffer.handle(), 1, 4, updateData);
1105 m_errorMonitor->VerifyFound();
1106
1107 // Introduce failure by using dataSize 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->UpdateBuffer(buffer.handle(), 0, 6, updateData);
1110 m_errorMonitor->VerifyFound();
1111
1112 // Introduce failure by using dataSize that is < 0
1113 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001114 "must be greater than zero and less than or equal to 65536");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001115 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, -44, updateData);
1116 m_errorMonitor->VerifyFound();
1117
1118 // Introduce failure by using dataSize that is > 65536
1119 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001120 "must be greater than zero and less than or equal to 65536");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001121 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 80000, updateData);
1122 m_errorMonitor->VerifyFound();
1123
Tony Barbour552f6c02016-12-21 14:34:07 -07001124 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001125}
1126
1127TEST_F(VkLayerTest, FillBufferAlignment) {
1128 TEST_DESCRIPTION("Check alignment parameters for vkCmdFillBuffer");
1129
Tony Barbour1fa09702017-03-16 12:09:08 -06001130 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001131
1132 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1133 vk_testing::Buffer buffer;
1134 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
1135
Tony Barbour552f6c02016-12-21 14:34:07 -07001136 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001137
1138 // Introduce failure by using dstOffset that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001139 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001140 m_commandBuffer->FillBuffer(buffer.handle(), 1, 4, 0x11111111);
1141 m_errorMonitor->VerifyFound();
1142
1143 // Introduce failure by using size that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001144 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001145 m_commandBuffer->FillBuffer(buffer.handle(), 0, 6, 0x11111111);
1146 m_errorMonitor->VerifyFound();
1147
1148 // Introduce failure by using size that is zero
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001149 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must be greater than zero");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001150 m_commandBuffer->FillBuffer(buffer.handle(), 0, 0, 0x11111111);
1151 m_errorMonitor->VerifyFound();
1152
Tony Barbour552f6c02016-12-21 14:34:07 -07001153 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001154}
Dustin Graves40f35822016-06-23 11:12:53 -06001155
Cortd889ff92016-07-27 09:51:27 -07001156TEST_F(VkLayerTest, PSOPolygonModeInvalid) {
1157 VkResult err;
1158
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001159 TEST_DESCRIPTION(
1160 "Attempt to use a non-solid polygon fill mode in a "
1161 "pipeline when this feature is not enabled.");
Cortd889ff92016-07-27 09:51:27 -07001162
Tony Barbour1fa09702017-03-16 12:09:08 -06001163 ASSERT_NO_FATAL_FAILURE(Init());
Cortd889ff92016-07-27 09:51:27 -07001164 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1165
1166 std::vector<const char *> device_extension_names;
1167 auto features = m_device->phy().features();
1168 // Artificially disable support for non-solid fill modes
1169 features.fillModeNonSolid = false;
1170 // The sacrificial device object
1171 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
1172
1173 VkRenderpassObj render_pass(&test_device);
1174
1175 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1176 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1177 pipeline_layout_ci.setLayoutCount = 0;
1178 pipeline_layout_ci.pSetLayouts = NULL;
1179
1180 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001181 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Cortd889ff92016-07-27 09:51:27 -07001182 ASSERT_VK_SUCCESS(err);
1183
1184 VkPipelineRasterizationStateCreateInfo rs_ci = {};
1185 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
1186 rs_ci.pNext = nullptr;
1187 rs_ci.lineWidth = 1.0f;
1188 rs_ci.rasterizerDiscardEnable = true;
1189
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001190 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
1191 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Cortd889ff92016-07-27 09:51:27 -07001192
Mark Lobodzinski5e644732016-08-15 16:51:19 -06001193 // Set polygonMode to unsupported value POINT, should fail
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001194 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1195 "polygonMode cannot be VK_POLYGON_MODE_POINT or VK_POLYGON_MODE_LINE");
Cortd889ff92016-07-27 09:51:27 -07001196 {
1197 VkPipelineObj pipe(&test_device);
1198 pipe.AddShader(&vs);
1199 pipe.AddShader(&fs);
1200 pipe.AddColorAttachment();
1201 // Introduce failure by setting unsupported polygon mode
1202 rs_ci.polygonMode = VK_POLYGON_MODE_POINT;
1203 pipe.SetRasterization(&rs_ci);
1204 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
1205 }
1206 m_errorMonitor->VerifyFound();
1207
1208 // Try again with polygonMode=LINE, should fail
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001209 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1210 "polygonMode cannot be VK_POLYGON_MODE_POINT or VK_POLYGON_MODE_LINE");
Cortd889ff92016-07-27 09:51:27 -07001211 {
1212 VkPipelineObj pipe(&test_device);
1213 pipe.AddShader(&vs);
1214 pipe.AddShader(&fs);
1215 pipe.AddColorAttachment();
1216 // Introduce failure by setting unsupported polygon mode
1217 rs_ci.polygonMode = VK_POLYGON_MODE_LINE;
1218 pipe.SetRasterization(&rs_ci);
1219 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
1220 }
1221 m_errorMonitor->VerifyFound();
1222
Cortd889ff92016-07-27 09:51:27 -07001223 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
1224}
1225
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001226#if 0
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001227TEST_F(VkLayerTest, CallResetCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001228{
1229 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001230 VkFenceCreateInfo fenceInfo = {};
1231 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1232 fenceInfo.pNext = NULL;
1233 fenceInfo.flags = 0;
1234
Mike Weiblencce7ec72016-10-17 19:33:05 -06001235 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Resetting command buffer");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001236
Tony Barbour1fa09702017-03-16 12:09:08 -06001237 ASSERT_NO_FATAL_FAILURE(Init());
Tony Barbourc1eb1a52015-07-20 13:00:10 -06001238
1239 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1240 vk_testing::Buffer buffer;
1241 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001242
Tony Barbourfe3351b2015-07-28 10:17:20 -06001243 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001244 m_commandBuffer->FillBuffer(buffer.handle(), 0, 4, 0x11111111);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001245 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001246
1247 testFence.init(*m_device, fenceInfo);
1248
1249 // Bypass framework since it does the waits automatically
1250 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001251 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001252 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1253 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001254 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001255 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001256 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001257 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001258 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001259 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001260 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001261
1262 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001263 ASSERT_VK_SUCCESS( err );
1264
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001265 // Introduce failure by calling begin again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001266 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001267
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001268 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001269}
1270
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001271TEST_F(VkLayerTest, CallBeginCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001272{
1273 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001274 VkFenceCreateInfo fenceInfo = {};
1275 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1276 fenceInfo.pNext = NULL;
1277 fenceInfo.flags = 0;
1278
Mike Weiblencce7ec72016-10-17 19:33:05 -06001279 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Calling vkBeginCommandBuffer() on active command buffer");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001280
Tony Barbour1fa09702017-03-16 12:09:08 -06001281 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001282 ASSERT_NO_FATAL_FAILURE(InitViewport());
1283 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1284
Tony Barbourfe3351b2015-07-28 10:17:20 -06001285 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001286 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001287 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001288
1289 testFence.init(*m_device, fenceInfo);
1290
1291 // Bypass framework since it does the waits automatically
1292 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001293 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001294 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1295 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001296 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001297 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001298 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001299 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001300 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001301 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001302 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001303
1304 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001305 ASSERT_VK_SUCCESS( err );
1306
Jon Ashburnf19916e2016-01-11 13:12:43 -07001307 VkCommandBufferInheritanceInfo hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001308 VkCommandBufferBeginInfo info = {};
1309 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
1310 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001311 info.renderPass = VK_NULL_HANDLE;
1312 info.subpass = 0;
1313 info.framebuffer = VK_NULL_HANDLE;
Chia-I Wub8d47ae2015-11-11 10:18:12 +08001314 info.occlusionQueryEnable = VK_FALSE;
1315 info.queryFlags = 0;
1316 info.pipelineStatistics = 0;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001317
1318 // Introduce failure by calling BCB again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001319 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001320
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001321 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001322}
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001323#endif
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001324
Mark Lobodzinski833bb552016-12-15 07:41:13 -07001325TEST_F(VkLayerTest, SparseBindingImageBufferCreate) {
1326 TEST_DESCRIPTION("Create buffer/image with sparse attributes but without the sparse_binding bit set");
1327
Tony Barbour1fa09702017-03-16 12:09:08 -06001328 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski833bb552016-12-15 07:41:13 -07001329
1330 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00669);
1331 VkBuffer buffer;
1332 VkBufferCreateInfo buf_info = {};
1333 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1334 buf_info.pNext = NULL;
1335 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
1336 buf_info.size = 2048;
1337 buf_info.queueFamilyIndexCount = 0;
1338 buf_info.pQueueFamilyIndices = NULL;
1339 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1340 buf_info.flags = VK_BUFFER_CREATE_SPARSE_RESIDENCY_BIT;
1341 vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1342 m_errorMonitor->VerifyFound();
1343
1344 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02160);
1345 VkImage image;
1346 VkImageCreateInfo image_create_info = {};
1347 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1348 image_create_info.pNext = NULL;
1349 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1350 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1351 image_create_info.extent.width = 512;
1352 image_create_info.extent.height = 64;
1353 image_create_info.extent.depth = 1;
1354 image_create_info.mipLevels = 1;
1355 image_create_info.arrayLayers = 1;
1356 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1357 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
1358 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1359 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1360 image_create_info.queueFamilyIndexCount = 0;
1361 image_create_info.pQueueFamilyIndices = NULL;
1362 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1363 image_create_info.flags = VK_BUFFER_CREATE_SPARSE_ALIASED_BIT;
1364 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1365 m_errorMonitor->VerifyFound();
1366}
1367
Dave Houlton829c0d82017-01-24 15:09:17 -07001368TEST_F(VkLayerTest, SparseResidencyImageCreateUnsupportedTypes) {
1369 TEST_DESCRIPTION("Create images with sparse residency with unsupported types");
1370
1371 // Determine which device feature are available
Dave Houlton0ba0fdf2017-03-29 12:05:26 -06001372 VkPhysicalDeviceFeatures device_features = {};
Dave Houlton8e0fe7a2017-03-30 10:32:10 -06001373 ASSERT_NO_FATAL_FAILURE(
1374 InitFramework(instance_layer_names, instance_extension_names, device_extension_names, myDbgFunc, m_errorMonitor));
Dave Houlton0ba0fdf2017-03-29 12:05:26 -06001375 ASSERT_NO_FATAL_FAILURE(GetPhysicalDeviceFeatures(&device_features));
Dave Houlton829c0d82017-01-24 15:09:17 -07001376
Dave Houlton8e0fe7a2017-03-30 10:32:10 -06001377 // Mask out device features we don't want and initialize device state
Dave Houlton0ba0fdf2017-03-29 12:05:26 -06001378 device_features.sparseResidencyImage2D = VK_FALSE;
1379 device_features.sparseResidencyImage3D = VK_FALSE;
Dave Houlton8e0fe7a2017-03-30 10:32:10 -06001380 ASSERT_NO_FATAL_FAILURE(InitState(&device_features));
Dave Houlton829c0d82017-01-24 15:09:17 -07001381
1382 VkImage image = VK_NULL_HANDLE;
1383 VkResult result = VK_RESULT_MAX_ENUM;
1384 VkImageCreateInfo image_create_info = {};
1385 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1386 image_create_info.pNext = NULL;
1387 image_create_info.imageType = VK_IMAGE_TYPE_1D;
1388 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1389 image_create_info.extent.width = 512;
1390 image_create_info.extent.height = 1;
1391 image_create_info.extent.depth = 1;
1392 image_create_info.mipLevels = 1;
1393 image_create_info.arrayLayers = 1;
1394 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1395 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
1396 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1397 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1398 image_create_info.queueFamilyIndexCount = 0;
1399 image_create_info.pQueueFamilyIndices = NULL;
1400 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1401 image_create_info.flags = VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT | VK_BUFFER_CREATE_SPARSE_BINDING_BIT;
1402
1403 // 1D image w/ sparse residency is an error
1404 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02352);
1405 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1406 m_errorMonitor->VerifyFound();
1407 if (VK_SUCCESS == result) {
1408 vkDestroyImage(m_device->device(), image, NULL);
1409 image = VK_NULL_HANDLE;
1410 }
1411
1412 // 2D image w/ sparse residency when feature isn't available
1413 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1414 image_create_info.extent.height = 64;
1415 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02144);
1416 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1417 m_errorMonitor->VerifyFound();
1418 if (VK_SUCCESS == result) {
1419 vkDestroyImage(m_device->device(), image, NULL);
1420 image = VK_NULL_HANDLE;
1421 }
1422
1423 // 3D image w/ sparse residency when feature isn't available
1424 image_create_info.imageType = VK_IMAGE_TYPE_3D;
1425 image_create_info.extent.depth = 8;
1426 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02145);
1427 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1428 m_errorMonitor->VerifyFound();
1429 if (VK_SUCCESS == result) {
1430 vkDestroyImage(m_device->device(), image, NULL);
1431 image = VK_NULL_HANDLE;
1432 }
1433}
1434
1435TEST_F(VkLayerTest, SparseResidencyImageCreateUnsupportedSamples) {
1436 TEST_DESCRIPTION("Create images with sparse residency with unsupported tiling or sample counts");
1437
1438 // Determine which device feature are available
Dave Houlton0ba0fdf2017-03-29 12:05:26 -06001439 VkPhysicalDeviceFeatures device_features = {};
Dave Houlton8e0fe7a2017-03-30 10:32:10 -06001440 ASSERT_NO_FATAL_FAILURE(
1441 InitFramework(instance_layer_names, instance_extension_names, device_extension_names, myDbgFunc, m_errorMonitor));
Dave Houlton0ba0fdf2017-03-29 12:05:26 -06001442 ASSERT_NO_FATAL_FAILURE(GetPhysicalDeviceFeatures(&device_features));
Dave Houlton829c0d82017-01-24 15:09:17 -07001443
Dave Houlton0ba0fdf2017-03-29 12:05:26 -06001444 // These tests require that the device support sparse residency for 2D images
1445 if (VK_TRUE != device_features.sparseResidencyImage2D) {
1446 printf(" Test requires unsupported SparseResidencyImage2D feature. Skipped.\n");
Dave Houlton829c0d82017-01-24 15:09:17 -07001447 return;
1448 }
1449
Dave Houlton8e0fe7a2017-03-30 10:32:10 -06001450 // Mask out device features we don't want and initialize device state
Dave Houlton0ba0fdf2017-03-29 12:05:26 -06001451 device_features.sparseResidency2Samples = VK_FALSE;
1452 device_features.sparseResidency4Samples = VK_FALSE;
1453 device_features.sparseResidency8Samples = VK_FALSE;
1454 device_features.sparseResidency16Samples = VK_FALSE;
Dave Houlton8e0fe7a2017-03-30 10:32:10 -06001455 ASSERT_NO_FATAL_FAILURE(InitState(&device_features));
Dave Houlton829c0d82017-01-24 15:09:17 -07001456
1457 VkImage image = VK_NULL_HANDLE;
1458 VkResult result = VK_RESULT_MAX_ENUM;
1459 VkImageCreateInfo image_create_info = {};
1460 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1461 image_create_info.pNext = NULL;
1462 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1463 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1464 image_create_info.extent.width = 64;
1465 image_create_info.extent.height = 64;
1466 image_create_info.extent.depth = 1;
1467 image_create_info.mipLevels = 1;
1468 image_create_info.arrayLayers = 1;
1469 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1470 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1471 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1472 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1473 image_create_info.queueFamilyIndexCount = 0;
1474 image_create_info.pQueueFamilyIndices = NULL;
1475 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1476 image_create_info.flags = VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT | VK_BUFFER_CREATE_SPARSE_BINDING_BIT;
1477
1478 // 2D image w/ sparse residency and linear tiling is an error
1479 m_errorMonitor->SetDesiredFailureMsg(
1480 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1481 "VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT then image tiling of VK_IMAGE_TILING_LINEAR is not supported");
1482 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1483 m_errorMonitor->VerifyFound();
1484 if (VK_SUCCESS == result) {
1485 vkDestroyImage(m_device->device(), image, NULL);
1486 image = VK_NULL_HANDLE;
1487 }
1488 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
1489
1490 // Multi-sample image w/ sparse residency when feature isn't available (4 flavors)
1491 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
1492 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02146);
1493 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1494 m_errorMonitor->VerifyFound();
1495 if (VK_SUCCESS == result) {
1496 vkDestroyImage(m_device->device(), image, NULL);
1497 image = VK_NULL_HANDLE;
1498 }
1499
1500 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
1501 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02147);
1502 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1503 m_errorMonitor->VerifyFound();
1504 if (VK_SUCCESS == result) {
1505 vkDestroyImage(m_device->device(), image, NULL);
1506 image = VK_NULL_HANDLE;
1507 }
1508
1509 image_create_info.samples = VK_SAMPLE_COUNT_8_BIT;
1510 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02148);
1511 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1512 m_errorMonitor->VerifyFound();
1513 if (VK_SUCCESS == result) {
1514 vkDestroyImage(m_device->device(), image, NULL);
1515 image = VK_NULL_HANDLE;
1516 }
1517
1518 image_create_info.samples = VK_SAMPLE_COUNT_16_BIT;
1519 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02149);
1520 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1521 m_errorMonitor->VerifyFound();
1522 if (VK_SUCCESS == result) {
1523 vkDestroyImage(m_device->device(), image, NULL);
1524 image = VK_NULL_HANDLE;
1525 }
1526}
1527
Tobin Ehlisf11be982016-05-11 13:52:53 -06001528TEST_F(VkLayerTest, InvalidMemoryAliasing) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001529 TEST_DESCRIPTION(
1530 "Create a buffer and image, allocate memory, and bind the "
1531 "buffer and image to memory such that they will alias.");
Tobin Ehlisf11be982016-05-11 13:52:53 -06001532 VkResult err;
1533 bool pass;
Tony Barbour1fa09702017-03-16 12:09:08 -06001534 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisf11be982016-05-11 13:52:53 -06001535
Tobin Ehlis077ded32016-05-12 17:39:13 -06001536 VkBuffer buffer, buffer2;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001537 VkImage image;
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001538 VkImage image2;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001539 VkDeviceMemory mem; // buffer will be bound first
1540 VkDeviceMemory mem_img; // image bound first
Tobin Ehlis077ded32016-05-12 17:39:13 -06001541 VkMemoryRequirements buff_mem_reqs, img_mem_reqs;
Rene Lindsayd14f5572016-12-16 14:57:18 -07001542 VkMemoryRequirements buff_mem_reqs2, img_mem_reqs2;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001543
1544 VkBufferCreateInfo buf_info = {};
1545 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1546 buf_info.pNext = NULL;
1547 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1548 buf_info.size = 256;
1549 buf_info.queueFamilyIndexCount = 0;
1550 buf_info.pQueueFamilyIndices = NULL;
1551 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1552 buf_info.flags = 0;
1553 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1554 ASSERT_VK_SUCCESS(err);
1555
Tobin Ehlis077ded32016-05-12 17:39:13 -06001556 vkGetBufferMemoryRequirements(m_device->device(), buffer, &buff_mem_reqs);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001557
1558 VkImageCreateInfo image_create_info = {};
1559 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1560 image_create_info.pNext = NULL;
1561 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1562 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1563 image_create_info.extent.width = 64;
1564 image_create_info.extent.height = 64;
1565 image_create_info.extent.depth = 1;
1566 image_create_info.mipLevels = 1;
1567 image_create_info.arrayLayers = 1;
1568 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis12a4b5e2016-08-08 12:33:11 -06001569 // Image tiling must be optimal to trigger error when aliasing linear buffer
1570 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001571 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1572 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1573 image_create_info.queueFamilyIndexCount = 0;
1574 image_create_info.pQueueFamilyIndices = NULL;
1575 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1576 image_create_info.flags = 0;
1577
Tobin Ehlisf11be982016-05-11 13:52:53 -06001578 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1579 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001580 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
1581 ASSERT_VK_SUCCESS(err);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001582
Tobin Ehlis077ded32016-05-12 17:39:13 -06001583 vkGetImageMemoryRequirements(m_device->device(), image, &img_mem_reqs);
1584
1585 VkMemoryAllocateInfo alloc_info = {};
1586 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1587 alloc_info.pNext = NULL;
1588 alloc_info.memoryTypeIndex = 0;
1589 // Ensure memory is big enough for both bindings
1590 alloc_info.allocationSize = buff_mem_reqs.size + img_mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001591 pass = m_device->phy().set_memory_type(buff_mem_reqs.memoryTypeBits & img_mem_reqs.memoryTypeBits, &alloc_info,
1592 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001593 if (!pass) {
Tobin Ehlis077ded32016-05-12 17:39:13 -06001594 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001595 vkDestroyImage(m_device->device(), image, NULL);
Mark Lobodzinskid2d2d4c2017-02-16 11:51:58 -07001596 vkDestroyImage(m_device->device(), image2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001597 return;
1598 }
Tobin Ehlis077ded32016-05-12 17:39:13 -06001599 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1600 ASSERT_VK_SUCCESS(err);
1601 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
1602 ASSERT_VK_SUCCESS(err);
1603
Rene Lindsayd14f5572016-12-16 14:57:18 -07001604 vkGetImageMemoryRequirements(m_device->device(), image2, &img_mem_reqs2);
1605
Tobin Ehlis32b2bbc2016-12-13 17:33:41 -07001606 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " is aliased with linear buffer 0x");
Tobin Ehlis077ded32016-05-12 17:39:13 -06001607 // VALIDATION FAILURE due to image mapping overlapping buffer mapping
Tobin Ehlisf11be982016-05-11 13:52:53 -06001608 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1609 m_errorMonitor->VerifyFound();
1610
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001611 // Now correctly bind image2 to second mem allocation before incorrectly
Tobin Ehlis077ded32016-05-12 17:39:13 -06001612 // aliasing buffer2
1613 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer2);
1614 ASSERT_VK_SUCCESS(err);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001615 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem_img);
1616 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001617 err = vkBindImageMemory(m_device->device(), image2, mem_img, 0);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001618 ASSERT_VK_SUCCESS(err);
Tobin Ehlis32b2bbc2016-12-13 17:33:41 -07001619 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "is aliased with non-linear image 0x");
Rene Lindsayd14f5572016-12-16 14:57:18 -07001620 vkGetBufferMemoryRequirements(m_device->device(), buffer2, &buff_mem_reqs2);
Tobin Ehlis077ded32016-05-12 17:39:13 -06001621 err = vkBindBufferMemory(m_device->device(), buffer2, mem_img, 0);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001622 m_errorMonitor->VerifyFound();
1623
1624 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlis077ded32016-05-12 17:39:13 -06001625 vkDestroyBuffer(m_device->device(), buffer2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001626 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001627 vkDestroyImage(m_device->device(), image2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001628 vkFreeMemory(m_device->device(), mem, NULL);
1629 vkFreeMemory(m_device->device(), mem_img, NULL);
1630}
1631
Tobin Ehlis35372522016-05-12 08:32:31 -06001632TEST_F(VkLayerTest, InvalidMemoryMapping) {
1633 TEST_DESCRIPTION("Attempt to map memory in a number of incorrect ways");
1634 VkResult err;
1635 bool pass;
Tony Barbour1fa09702017-03-16 12:09:08 -06001636 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis35372522016-05-12 08:32:31 -06001637
1638 VkBuffer buffer;
1639 VkDeviceMemory mem;
1640 VkMemoryRequirements mem_reqs;
1641
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001642 const VkDeviceSize atom_size = m_device->props.limits.nonCoherentAtomSize;
1643
Tobin Ehlis35372522016-05-12 08:32:31 -06001644 VkBufferCreateInfo buf_info = {};
1645 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1646 buf_info.pNext = NULL;
1647 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1648 buf_info.size = 256;
1649 buf_info.queueFamilyIndexCount = 0;
1650 buf_info.pQueueFamilyIndices = NULL;
1651 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1652 buf_info.flags = 0;
1653 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1654 ASSERT_VK_SUCCESS(err);
1655
1656 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
1657 VkMemoryAllocateInfo alloc_info = {};
1658 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1659 alloc_info.pNext = NULL;
1660 alloc_info.memoryTypeIndex = 0;
1661
1662 // Ensure memory is big enough for both bindings
1663 static const VkDeviceSize allocation_size = 0x10000;
1664 alloc_info.allocationSize = allocation_size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001665 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 -06001666 if (!pass) {
1667 vkDestroyBuffer(m_device->device(), buffer, NULL);
1668 return;
1669 }
1670 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1671 ASSERT_VK_SUCCESS(err);
1672
1673 uint8_t *pData;
1674 // Attempt to map memory size 0 is invalid
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001675 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 -06001676 err = vkMapMemory(m_device->device(), mem, 0, 0, 0, (void **)&pData);
1677 m_errorMonitor->VerifyFound();
1678 // Map memory twice
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001679 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001680 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001681 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1682 "VkMapMemory: Attempting to map memory on an already-mapped object ");
1683 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001684 m_errorMonitor->VerifyFound();
1685
1686 // Unmap the memory to avoid re-map error
1687 vkUnmapMemory(m_device->device(), mem);
1688 // overstep allocation with VK_WHOLE_SIZE
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001689 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1690 " with size of VK_WHOLE_SIZE oversteps total array size 0x");
1691 err = vkMapMemory(m_device->device(), mem, allocation_size + 1, VK_WHOLE_SIZE, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001692 m_errorMonitor->VerifyFound();
1693 // overstep allocation w/o VK_WHOLE_SIZE
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001694 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " oversteps total array size 0x");
1695 err = vkMapMemory(m_device->device(), mem, 1, allocation_size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001696 m_errorMonitor->VerifyFound();
1697 // Now error due to unmapping memory that's not mapped
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001698 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Unmapping Memory without memory being mapped: ");
Tobin Ehlis35372522016-05-12 08:32:31 -06001699 vkUnmapMemory(m_device->device(), mem);
1700 m_errorMonitor->VerifyFound();
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001701
Tobin Ehlis35372522016-05-12 08:32:31 -06001702 // Now map memory and cause errors due to flushing invalid ranges
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001703 err = vkMapMemory(m_device->device(), mem, 4 * atom_size, VK_WHOLE_SIZE, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001704 ASSERT_VK_SUCCESS(err);
1705 VkMappedMemoryRange mmr = {};
Chris Forbes3aec0892016-06-13 10:29:26 +12001706 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
Tobin Ehlis35372522016-05-12 08:32:31 -06001707 mmr.memory = mem;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001708 mmr.offset = atom_size; // Error b/c offset less than offset of mapped mem
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001709 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00642);
Tobin Ehlis35372522016-05-12 08:32:31 -06001710 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1711 m_errorMonitor->VerifyFound();
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001712
Tobin Ehlis35372522016-05-12 08:32:31 -06001713 // Now flush range that oversteps mapped range
1714 vkUnmapMemory(m_device->device(), mem);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001715 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001716 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001717 mmr.offset = atom_size;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001718 mmr.size = 4 * atom_size; // Flushing bounds exceed mapped bounds
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001719 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00642);
1720 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1721 m_errorMonitor->VerifyFound();
1722
1723 // Now flush range with VK_WHOLE_SIZE that oversteps offset
1724 vkUnmapMemory(m_device->device(), mem);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001725 err = vkMapMemory(m_device->device(), mem, 2 * atom_size, 4 * atom_size, 0, (void **)&pData);
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001726 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001727 mmr.offset = atom_size;
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001728 mmr.size = VK_WHOLE_SIZE;
1729 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00643);
Tobin Ehlis35372522016-05-12 08:32:31 -06001730 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1731 m_errorMonitor->VerifyFound();
1732
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001733#if 0 // Planning discussion with working group on this validation check.
Mark Lobodzinski3826a4f2016-11-15 09:38:51 -07001734 // Some platforms have an atomsize of 1 which makes the test meaningless
1735 if (atom_size > 3) {
1736 // Now with an offset NOT a multiple of the device limit
1737 vkUnmapMemory(m_device->device(), mem);
1738 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
1739 ASSERT_VK_SUCCESS(err);
1740 mmr.offset = 3; // Not a multiple of atom_size
1741 mmr.size = VK_WHOLE_SIZE;
1742 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00644);
1743 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1744 m_errorMonitor->VerifyFound();
1745
1746 // Now with a size NOT a multiple of the device limit
1747 vkUnmapMemory(m_device->device(), mem);
1748 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
1749 ASSERT_VK_SUCCESS(err);
1750 mmr.offset = atom_size;
1751 mmr.size = 2 * atom_size + 1; // Not a multiple of atom_size
1752 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00645);
1753 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1754 m_errorMonitor->VerifyFound();
1755 }
Tony Barboure3975eb2016-12-15 14:52:44 -07001756#endif
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001757 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
1758 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Tobin Ehlis35372522016-05-12 08:32:31 -06001759 if (!pass) {
1760 vkFreeMemory(m_device->device(), mem, NULL);
1761 vkDestroyBuffer(m_device->device(), buffer, NULL);
1762 return;
1763 }
1764 // TODO : If we can get HOST_VISIBLE w/o HOST_COHERENT we can test cases of
1765 // MEMTRACK_INVALID_MAP in validateAndCopyNoncoherentMemoryToDriver()
1766
1767 vkDestroyBuffer(m_device->device(), buffer, NULL);
1768 vkFreeMemory(m_device->device(), mem, NULL);
1769}
1770
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001771#if 0 // disabled until PV gets real extension enable checks
Ian Elliott1c32c772016-04-28 14:47:13 -06001772TEST_F(VkLayerTest, EnableWsiBeforeUse) {
1773 VkResult err;
1774 bool pass;
1775
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001776 // FIXME: After we turn on this code for non-Linux platforms, uncomment the
1777 // following declaration (which is temporarily being moved below):
1778 // VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott1c32c772016-04-28 14:47:13 -06001779 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001780 VkSwapchainCreateInfoKHR swapchain_create_info = {VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR};
Ian Elliott1c32c772016-04-28 14:47:13 -06001781 uint32_t swapchain_image_count = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001782 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
Ian Elliott1c32c772016-04-28 14:47:13 -06001783 uint32_t image_index = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001784 // VkPresentInfoKHR present_info = {};
Ian Elliott1c32c772016-04-28 14:47:13 -06001785
Tony Barbour1fa09702017-03-16 12:09:08 -06001786 ASSERT_NO_FATAL_FAILURE(Init());
Ian Elliott1c32c772016-04-28 14:47:13 -06001787
Ian Elliott3f06ce52016-04-29 14:46:21 -06001788#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
1789#if defined(VK_USE_PLATFORM_ANDROID_KHR)
1790 // Use the functions from the VK_KHR_android_surface extension without
1791 // enabling that extension:
1792
1793 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001794 VkAndroidSurfaceCreateInfoKHR android_create_info = {VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001795 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1796 err = vkCreateAndroidSurfaceKHR(instance(), &android_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001797 pass = (err != VK_SUCCESS);
1798 ASSERT_TRUE(pass);
1799 m_errorMonitor->VerifyFound();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001800#endif // VK_USE_PLATFORM_ANDROID_KHR
Ian Elliott3f06ce52016-04-29 14:46:21 -06001801
Ian Elliott3f06ce52016-04-29 14:46:21 -06001802#if defined(VK_USE_PLATFORM_MIR_KHR)
1803 // Use the functions from the VK_KHR_mir_surface extension without enabling
1804 // that extension:
1805
1806 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001807 VkMirSurfaceCreateInfoKHR mir_create_info = {VK_STRUCTURE_TYPE_MIR_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001808 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott3f06ce52016-04-29 14:46:21 -06001809 err = vkCreateMirSurfaceKHR(instance(), &mir_create_info, NULL, &surface);
1810 pass = (err != VK_SUCCESS);
1811 ASSERT_TRUE(pass);
1812 m_errorMonitor->VerifyFound();
1813
1814 // Tell whether an mir_connection supports presentation:
1815 MirConnection *mir_connection = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001816 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1817 vkGetPhysicalDeviceMirPresentationSupportKHR(gpu(), 0, mir_connection, visual_id);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001818 m_errorMonitor->VerifyFound();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001819#endif // VK_USE_PLATFORM_MIR_KHR
Ian Elliott3f06ce52016-04-29 14:46:21 -06001820
Ian Elliott3f06ce52016-04-29 14:46:21 -06001821#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
1822 // Use the functions from the VK_KHR_wayland_surface extension without
1823 // enabling that extension:
1824
1825 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001826 VkWaylandSurfaceCreateInfoKHR wayland_create_info = {VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001827 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1828 err = vkCreateWaylandSurfaceKHR(instance(), &wayland_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001829 pass = (err != VK_SUCCESS);
1830 ASSERT_TRUE(pass);
1831 m_errorMonitor->VerifyFound();
1832
1833 // Tell whether an wayland_display supports presentation:
1834 struct wl_display wayland_display = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001835 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1836 vkGetPhysicalDeviceWaylandPresentationSupportKHR(gpu(), 0, &wayland_display);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001837 m_errorMonitor->VerifyFound();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001838#endif // VK_USE_PLATFORM_WAYLAND_KHR
1839#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott3f06ce52016-04-29 14:46:21 -06001840
Ian Elliott3f06ce52016-04-29 14:46:21 -06001841#if defined(VK_USE_PLATFORM_WIN32_KHR)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001842 // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1843 // TO NON-LINUX PLATFORMS:
1844 VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott3f06ce52016-04-29 14:46:21 -06001845 // Use the functions from the VK_KHR_win32_surface extension without
1846 // enabling that extension:
1847
1848 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001849 VkWin32SurfaceCreateInfoKHR win32_create_info = {VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001850 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1851 err = vkCreateWin32SurfaceKHR(instance(), &win32_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001852 pass = (err != VK_SUCCESS);
1853 ASSERT_TRUE(pass);
1854 m_errorMonitor->VerifyFound();
1855
1856 // Tell whether win32 supports presentation:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001857 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott489eec02016-05-05 14:12:44 -06001858 vkGetPhysicalDeviceWin32PresentationSupportKHR(gpu(), 0);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001859 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001860// Set this (for now, until all platforms are supported and tested):
1861#define NEED_TO_TEST_THIS_ON_PLATFORM
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001862#endif // VK_USE_PLATFORM_WIN32_KHR
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07001863#if defined(VK_USE_PLATFORM_XCB_KHR) || defined(VK_USE_PLATFORM_XLIB_KHR)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001864 // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1865 // TO NON-LINUX PLATFORMS:
1866 VkSurfaceKHR surface = VK_NULL_HANDLE;
Tony Barbour2e7bd402016-11-14 14:46:33 -07001867#endif
1868#if defined(VK_USE_PLATFORM_XCB_KHR)
Ian Elliott1c32c772016-04-28 14:47:13 -06001869 // Use the functions from the VK_KHR_xcb_surface extension without enabling
1870 // that extension:
1871
1872 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001873 VkXcbSurfaceCreateInfoKHR xcb_create_info = {VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001874 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001875 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
1876 pass = (err != VK_SUCCESS);
1877 ASSERT_TRUE(pass);
1878 m_errorMonitor->VerifyFound();
1879
1880 // Tell whether an xcb_visualid_t supports presentation:
Ian Elliott3f06ce52016-04-29 14:46:21 -06001881 xcb_connection_t *xcb_connection = NULL;
Ian Elliott1c32c772016-04-28 14:47:13 -06001882 xcb_visualid_t visual_id = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001883 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1884 vkGetPhysicalDeviceXcbPresentationSupportKHR(gpu(), 0, xcb_connection, visual_id);
Ian Elliott1c32c772016-04-28 14:47:13 -06001885 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001886// Set this (for now, until all platforms are supported and tested):
1887#define NEED_TO_TEST_THIS_ON_PLATFORM
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001888#endif // VK_USE_PLATFORM_XCB_KHR
Ian Elliott1c32c772016-04-28 14:47:13 -06001889
Ian Elliott12630812016-04-29 14:35:43 -06001890#if defined(VK_USE_PLATFORM_XLIB_KHR)
1891 // Use the functions from the VK_KHR_xlib_surface extension without enabling
1892 // that extension:
1893
1894 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001895 VkXlibSurfaceCreateInfoKHR xlib_create_info = {VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001896 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06001897 err = vkCreateXlibSurfaceKHR(instance(), &xlib_create_info, NULL, &surface);
1898 pass = (err != VK_SUCCESS);
1899 ASSERT_TRUE(pass);
1900 m_errorMonitor->VerifyFound();
1901
1902 // Tell whether an Xlib VisualID supports presentation:
1903 Display *dpy = NULL;
1904 VisualID visual = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001905 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06001906 vkGetPhysicalDeviceXlibPresentationSupportKHR(gpu(), 0, dpy, visual);
1907 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001908// Set this (for now, until all platforms are supported and tested):
1909#define NEED_TO_TEST_THIS_ON_PLATFORM
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001910#endif // VK_USE_PLATFORM_XLIB_KHR
Ian Elliott12630812016-04-29 14:35:43 -06001911
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001912// Use the functions from the VK_KHR_surface extension without enabling
1913// that extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06001914
Ian Elliott489eec02016-05-05 14:12:44 -06001915#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001916 // Destroy a surface:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001917 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001918 vkDestroySurfaceKHR(instance(), surface, NULL);
1919 m_errorMonitor->VerifyFound();
1920
1921 // Check if surface supports presentation:
1922 VkBool32 supported = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001923 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001924 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
1925 pass = (err != VK_SUCCESS);
1926 ASSERT_TRUE(pass);
1927 m_errorMonitor->VerifyFound();
1928
1929 // Check surface capabilities:
1930 VkSurfaceCapabilitiesKHR capabilities = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001931 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1932 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &capabilities);
Ian Elliott1c32c772016-04-28 14:47:13 -06001933 pass = (err != VK_SUCCESS);
1934 ASSERT_TRUE(pass);
1935 m_errorMonitor->VerifyFound();
1936
1937 // Check surface formats:
1938 uint32_t format_count = 0;
1939 VkSurfaceFormatKHR *formats = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001940 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1941 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &format_count, formats);
Ian Elliott1c32c772016-04-28 14:47:13 -06001942 pass = (err != VK_SUCCESS);
1943 ASSERT_TRUE(pass);
1944 m_errorMonitor->VerifyFound();
1945
1946 // Check surface present modes:
1947 uint32_t present_mode_count = 0;
1948 VkSurfaceFormatKHR *present_modes = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001949 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1950 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &present_mode_count, present_modes);
Ian Elliott1c32c772016-04-28 14:47:13 -06001951 pass = (err != VK_SUCCESS);
1952 ASSERT_TRUE(pass);
1953 m_errorMonitor->VerifyFound();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001954#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001955
Ian Elliott1c32c772016-04-28 14:47:13 -06001956 // Use the functions from the VK_KHR_swapchain extension without enabling
1957 // that extension:
1958
1959 // Create a swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001960 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001961 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
1962 swapchain_create_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001963 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
Ian Elliott1c32c772016-04-28 14:47:13 -06001964 pass = (err != VK_SUCCESS);
1965 ASSERT_TRUE(pass);
1966 m_errorMonitor->VerifyFound();
1967
1968 // Get the images from the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001969 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1970 err = vkGetSwapchainImagesKHR(m_device->device(), swapchain, &swapchain_image_count, NULL);
Ian Elliott1c32c772016-04-28 14:47:13 -06001971 pass = (err != VK_SUCCESS);
1972 ASSERT_TRUE(pass);
1973 m_errorMonitor->VerifyFound();
1974
Chris Forbeseb7d5502016-09-13 18:19:21 +12001975 // Add a fence to avoid (justifiable) error about not providing fence OR semaphore
1976 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
1977 VkFence fence;
1978 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
1979
Ian Elliott1c32c772016-04-28 14:47:13 -06001980 // Try to acquire an image:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001981 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Chris Forbeseb7d5502016-09-13 18:19:21 +12001982 err = vkAcquireNextImageKHR(m_device->device(), swapchain, 0, VK_NULL_HANDLE, fence, &image_index);
Ian Elliott1c32c772016-04-28 14:47:13 -06001983 pass = (err != VK_SUCCESS);
1984 ASSERT_TRUE(pass);
1985 m_errorMonitor->VerifyFound();
1986
Chris Forbeseb7d5502016-09-13 18:19:21 +12001987 vkDestroyFence(m_device->device(), fence, nullptr);
1988
Ian Elliott1c32c772016-04-28 14:47:13 -06001989 // Try to present an image:
Ian Elliott2c1daf52016-05-12 09:41:46 -06001990 //
1991 // NOTE: Currently can't test this because a real swapchain is needed (as
1992 // opposed to the fake one we created) in order for the layer to lookup the
1993 // VkDevice used to enable the extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06001994
1995 // Destroy the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001996 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001997 vkDestroySwapchainKHR(m_device->device(), swapchain, NULL);
1998 m_errorMonitor->VerifyFound();
1999}
Chris Forbes09368e42016-10-13 11:59:22 +13002000#endif
Ian Elliott1c32c772016-04-28 14:47:13 -06002001
Karl Schultz6addd812016-02-02 17:17:23 -07002002TEST_F(VkLayerTest, MapMemWithoutHostVisibleBit) {
2003 VkResult err;
2004 bool pass;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002005
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002006 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2007 "Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002008
Tony Barbour1fa09702017-03-16 12:09:08 -06002009 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002010
2011 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07002012 VkImage image;
2013 VkDeviceMemory mem;
2014 VkMemoryRequirements mem_reqs;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002015
Karl Schultz6addd812016-02-02 17:17:23 -07002016 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2017 const int32_t tex_width = 32;
2018 const int32_t tex_height = 32;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002019
Tony Barboureb254902015-07-15 12:50:33 -06002020 VkImageCreateInfo image_create_info = {};
2021 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07002022 image_create_info.pNext = NULL;
2023 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2024 image_create_info.format = tex_format;
2025 image_create_info.extent.width = tex_width;
2026 image_create_info.extent.height = tex_height;
2027 image_create_info.extent.depth = 1;
2028 image_create_info.mipLevels = 1;
2029 image_create_info.arrayLayers = 1;
2030 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2031 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2032 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2033 image_create_info.flags = 0;
Chris Forbese65e4d02016-09-13 17:39:18 +12002034 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002035
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002036 VkMemoryAllocateInfo mem_alloc = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002037 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07002038 mem_alloc.pNext = NULL;
2039 mem_alloc.allocationSize = 0;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002040
Chia-I Wuf7458c52015-10-26 21:10:41 +08002041 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002042 ASSERT_VK_SUCCESS(err);
2043
Karl Schultz6addd812016-02-02 17:17:23 -07002044 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002045
Mark Lobodzinski23065352015-05-29 09:32:35 -05002046 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002047
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002048 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 -07002049 if (!pass) { // If we can't find any unmappable memory this test doesn't
2050 // make sense
Chia-I Wuf7458c52015-10-26 21:10:41 +08002051 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbour02fdc7d2015-08-04 16:13:01 -06002052 return;
Mike Stroyand1c84a52015-08-18 14:40:24 -06002053 }
Mike Stroyan713b2d72015-08-04 10:49:29 -06002054
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002055 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002056 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002057 ASSERT_VK_SUCCESS(err);
2058
2059 // Try to bind free memory that has been freed
Tony Barbour67e99152015-07-10 14:10:27 -06002060 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002061 ASSERT_VK_SUCCESS(err);
2062
2063 // Map memory as if to initialize the image
2064 void *mappedAddress = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002065 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, &mappedAddress);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002066
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002067 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002068
Chia-I Wuf7458c52015-10-26 21:10:41 +08002069 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06002070 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002071}
2072
Karl Schultz6addd812016-02-02 17:17:23 -07002073TEST_F(VkLayerTest, RebindMemory) {
2074 VkResult err;
2075 bool pass;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002076
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002077 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which has already been bound to mem object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002078
Tony Barbour1fa09702017-03-16 12:09:08 -06002079 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002080
2081 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07002082 VkImage image;
2083 VkDeviceMemory mem1;
2084 VkDeviceMemory mem2;
2085 VkMemoryRequirements mem_reqs;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002086
Karl Schultz6addd812016-02-02 17:17:23 -07002087 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2088 const int32_t tex_width = 32;
2089 const int32_t tex_height = 32;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002090
Tony Barboureb254902015-07-15 12:50:33 -06002091 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002092 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2093 image_create_info.pNext = NULL;
2094 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2095 image_create_info.format = tex_format;
2096 image_create_info.extent.width = tex_width;
2097 image_create_info.extent.height = tex_height;
2098 image_create_info.extent.depth = 1;
2099 image_create_info.mipLevels = 1;
2100 image_create_info.arrayLayers = 1;
2101 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2102 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2103 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2104 image_create_info.flags = 0;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002105
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002106 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002107 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2108 mem_alloc.pNext = NULL;
2109 mem_alloc.allocationSize = 0;
2110 mem_alloc.memoryTypeIndex = 0;
Tony Barboureb254902015-07-15 12:50:33 -06002111
Karl Schultz6addd812016-02-02 17:17:23 -07002112 // Introduce failure, do NOT set memProps to
2113 // VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
Tony Barboureb254902015-07-15 12:50:33 -06002114 mem_alloc.memoryTypeIndex = 1;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002115 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002116 ASSERT_VK_SUCCESS(err);
2117
Karl Schultz6addd812016-02-02 17:17:23 -07002118 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002119
2120 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002121 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002122 ASSERT_TRUE(pass);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002123
2124 // allocate 2 memory objects
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002125 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem1);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002126 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002127 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem2);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002128 ASSERT_VK_SUCCESS(err);
2129
2130 // Bind first memory object to Image object
Tony Barbour67e99152015-07-10 14:10:27 -06002131 err = vkBindImageMemory(m_device->device(), image, mem1, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002132 ASSERT_VK_SUCCESS(err);
2133
Karl Schultz6addd812016-02-02 17:17:23 -07002134 // Introduce validation failure, try to bind a different memory object to
2135 // the same image object
Tony Barbour67e99152015-07-10 14:10:27 -06002136 err = vkBindImageMemory(m_device->device(), image, mem2, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002137
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002138 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002139
Chia-I Wuf7458c52015-10-26 21:10:41 +08002140 vkDestroyImage(m_device->device(), image, NULL);
2141 vkFreeMemory(m_device->device(), mem1, NULL);
2142 vkFreeMemory(m_device->device(), mem2, NULL);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002143}
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002144
Karl Schultz6addd812016-02-02 17:17:23 -07002145TEST_F(VkLayerTest, SubmitSignaledFence) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002146 vk_testing::Fence testFence;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002147
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002148 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2149 "submitted in SIGNALED state. Fences "
2150 "must be reset before being submitted");
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002151
2152 VkFenceCreateInfo fenceInfo = {};
Tony Barbour0b4d9562015-04-09 10:48:04 -06002153 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2154 fenceInfo.pNext = NULL;
2155 fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
Tony Barbour300a6082015-04-07 13:44:53 -06002156
Tony Barbour1fa09702017-03-16 12:09:08 -06002157 ASSERT_NO_FATAL_FAILURE(Init());
Tony Barbour300a6082015-04-07 13:44:53 -06002158 ASSERT_NO_FATAL_FAILURE(InitViewport());
2159 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2160
Tony Barbour552f6c02016-12-21 14:34:07 -07002161 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002162 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbour552f6c02016-12-21 14:34:07 -07002163 m_commandBuffer->EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -06002164
2165 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002166
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002167 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08002168 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2169 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002170 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002171 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07002172 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002173 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002174 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08002175 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002176 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06002177
2178 vkQueueSubmit(m_device->m_queue, 1, &submit_info, testFence.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07002179 vkQueueWaitIdle(m_device->m_queue);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002180
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002181 m_errorMonitor->VerifyFound();
Tony Barbour0b4d9562015-04-09 10:48:04 -06002182}
Chris Forbes4e44c912016-06-16 10:20:00 +12002183
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002184TEST_F(VkLayerTest, InvalidUsageBits) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002185 TEST_DESCRIPTION(
2186 "Specify wrong usage for image then create conflicting view of image "
2187 "Initialize buffer with wrong usage then perform copy expecting errors "
2188 "from both the image and the buffer (2 calls)");
Mark Lobodzinski33826372017-04-13 11:10:11 -06002189 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid usage flag for Image ");
Tobin Ehlis41376e12015-07-03 08:45:14 -06002190
Tony Barbour1fa09702017-03-16 12:09:08 -06002191 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -06002192 auto format = FindSupportedDepthStencilFormat(gpu());
Tony Barbourf887b162017-03-09 10:06:46 -07002193 if (!format) {
2194 printf(" No Depth + Stencil format found. Skipped.\n");
2195 return;
2196 }
Chris Forbesd2b5fe42016-11-28 18:00:00 +13002197
Tony Barbourf92621a2016-05-02 14:28:12 -06002198 VkImageObj image(m_device);
Tony Barbour75d79f02016-08-30 09:39:07 -06002199 // Initialize image with USAGE_TRANSIENT_ATTACHMENT
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06002200 image.Init(128, 128, 1, format, VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Karl Schultzb5bc11e2016-05-04 08:36:08 -06002201 ASSERT_TRUE(image.initialized());
Tobin Ehlis41376e12015-07-03 08:45:14 -06002202
Tony Barbourf92621a2016-05-02 14:28:12 -06002203 VkImageView dsv;
2204 VkImageViewCreateInfo dsvci = {};
2205 dsvci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
2206 dsvci.image = image.handle();
2207 dsvci.viewType = VK_IMAGE_VIEW_TYPE_2D;
Chris Forbesd2b5fe42016-11-28 18:00:00 +13002208 dsvci.format = format;
Tony Barbourf92621a2016-05-02 14:28:12 -06002209 dsvci.subresourceRange.layerCount = 1;
2210 dsvci.subresourceRange.baseMipLevel = 0;
2211 dsvci.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002212 dsvci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis41376e12015-07-03 08:45:14 -06002213
Tony Barbourf92621a2016-05-02 14:28:12 -06002214 // Create a view with depth / stencil aspect for image with different usage
2215 vkCreateImageView(m_device->device(), &dsvci, NULL, &dsv);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002216
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002217 m_errorMonitor->VerifyFound();
Tony Barbourf92621a2016-05-02 14:28:12 -06002218
2219 // Initialize buffer with TRANSFER_DST usage
2220 vk_testing::Buffer buffer;
2221 VkMemoryPropertyFlags reqs = 0;
2222 buffer.init_as_dst(*m_device, 128 * 128, reqs);
2223 VkBufferImageCopy region = {};
2224 region.bufferRowLength = 128;
2225 region.bufferImageHeight = 128;
Mark Lobodzinski80871462017-02-16 10:37:27 -07002226 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Tony Barbourf92621a2016-05-02 14:28:12 -06002227 region.imageSubresource.layerCount = 1;
2228 region.imageExtent.height = 16;
2229 region.imageExtent.width = 16;
2230 region.imageExtent.depth = 1;
2231
Mark Lobodzinski80871462017-02-16 10:37:27 -07002232 // Buffer usage not set to TRANSFER_SRC and image usage not set to TRANSFER_DST
Tony Barbour552f6c02016-12-21 14:34:07 -07002233 m_commandBuffer->BeginCommandBuffer();
Tony Barbourf92621a2016-05-02 14:28:12 -06002234
Chris Forbesda581202016-10-06 18:25:26 +13002235 // two separate errors from this call:
Mark Lobodzinski33826372017-04-13 11:10:11 -06002236 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image should have VK_IMAGE_USAGE_TRANSFER_DST_BIT");
2237 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 +13002238
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002239 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
2240 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourf92621a2016-05-02 14:28:12 -06002241 m_errorMonitor->VerifyFound();
Tobin Ehlis41376e12015-07-03 08:45:14 -06002242}
Tony Barbour75d79f02016-08-30 09:39:07 -06002243
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002244TEST_F(VkLayerTest, LeakAnObject) {
2245 VkResult err;
2246
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002247 TEST_DESCRIPTION("Create a fence and destroy its device without first destroying the fence.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002248
2249 // Note that we have to create a new device since destroying the
2250 // framework's device causes Teardown() to fail and just calling Teardown
2251 // will destroy the errorMonitor.
2252
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002253 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "has not been destroyed.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002254
Tony Barbour1fa09702017-03-16 12:09:08 -06002255 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002256
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002257 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002258 std::vector<VkDeviceQueueCreateInfo> queue_info;
2259 queue_info.reserve(queue_props.size());
2260 std::vector<std::vector<float>> queue_priorities;
2261 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
2262 VkDeviceQueueCreateInfo qi = {};
2263 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
2264 qi.pNext = NULL;
2265 qi.queueFamilyIndex = i;
2266 qi.queueCount = queue_props[i].queueCount;
2267 queue_priorities.emplace_back(qi.queueCount, 0.0f);
2268 qi.pQueuePriorities = queue_priorities[i].data();
2269 queue_info.push_back(qi);
2270 }
2271
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002272 std::vector<const char *> device_extension_names;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002273
2274 // The sacrificial device object
2275 VkDevice testDevice;
2276 VkDeviceCreateInfo device_create_info = {};
2277 auto features = m_device->phy().features();
2278 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
2279 device_create_info.pNext = NULL;
2280 device_create_info.queueCreateInfoCount = queue_info.size();
2281 device_create_info.pQueueCreateInfos = queue_info.data();
Tony Barbour4c70d102016-08-08 16:06:56 -06002282 device_create_info.enabledLayerCount = 0;
2283 device_create_info.ppEnabledLayerNames = NULL;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002284 device_create_info.pEnabledFeatures = &features;
2285 err = vkCreateDevice(gpu(), &device_create_info, NULL, &testDevice);
2286 ASSERT_VK_SUCCESS(err);
2287
2288 VkFence fence;
2289 VkFenceCreateInfo fence_create_info = {};
2290 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2291 fence_create_info.pNext = NULL;
2292 fence_create_info.flags = 0;
2293 err = vkCreateFence(testDevice, &fence_create_info, NULL, &fence);
2294 ASSERT_VK_SUCCESS(err);
2295
2296 // Induce failure by not calling vkDestroyFence
2297 vkDestroyDevice(testDevice, NULL);
2298 m_errorMonitor->VerifyFound();
2299}
2300
2301TEST_F(VkLayerTest, InvalidCommandPoolConsistency) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002302 TEST_DESCRIPTION(
2303 "Allocate command buffers from one command pool and "
2304 "attempt to delete them from another.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002305
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002306 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeCommandBuffers is attempting to free Command Buffer");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002307
Tony Barbour1fa09702017-03-16 12:09:08 -06002308 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002309 VkCommandPool command_pool_one;
2310 VkCommandPool command_pool_two;
2311
2312 VkCommandPoolCreateInfo pool_create_info{};
2313 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
2314 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
2315 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
2316
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002317 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002318
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002319 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002320
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002321 VkCommandBuffer cb;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002322 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002323 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002324 command_buffer_allocate_info.commandPool = command_pool_one;
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002325 command_buffer_allocate_info.commandBufferCount = 1;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002326 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002327 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &cb);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002328
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002329 vkFreeCommandBuffers(m_device->device(), command_pool_two, 1, &cb);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002330
2331 m_errorMonitor->VerifyFound();
2332
2333 vkDestroyCommandPool(m_device->device(), command_pool_one, NULL);
2334 vkDestroyCommandPool(m_device->device(), command_pool_two, NULL);
2335}
2336
2337TEST_F(VkLayerTest, InvalidDescriptorPoolConsistency) {
2338 VkResult err;
2339
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002340 TEST_DESCRIPTION(
2341 "Allocate descriptor sets from one DS pool and "
2342 "attempt to delete them from another.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002343
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002344 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeDescriptorSets is attempting to free descriptorSet");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002345
Tony Barbour1fa09702017-03-16 12:09:08 -06002346 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002347 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2348
2349 VkDescriptorPoolSize ds_type_count = {};
2350 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
2351 ds_type_count.descriptorCount = 1;
2352
2353 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2354 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2355 ds_pool_ci.pNext = NULL;
2356 ds_pool_ci.flags = 0;
2357 ds_pool_ci.maxSets = 1;
2358 ds_pool_ci.poolSizeCount = 1;
2359 ds_pool_ci.pPoolSizes = &ds_type_count;
2360
2361 VkDescriptorPool ds_pool_one;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002362 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002363 ASSERT_VK_SUCCESS(err);
2364
2365 // Create a second descriptor pool
2366 VkDescriptorPool ds_pool_two;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002367 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002368 ASSERT_VK_SUCCESS(err);
2369
2370 VkDescriptorSetLayoutBinding dsl_binding = {};
2371 dsl_binding.binding = 0;
2372 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
2373 dsl_binding.descriptorCount = 1;
2374 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2375 dsl_binding.pImmutableSamplers = NULL;
2376
2377 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2378 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2379 ds_layout_ci.pNext = NULL;
2380 ds_layout_ci.bindingCount = 1;
2381 ds_layout_ci.pBindings = &dsl_binding;
2382
2383 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002384 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002385 ASSERT_VK_SUCCESS(err);
2386
2387 VkDescriptorSet descriptorSet;
2388 VkDescriptorSetAllocateInfo alloc_info = {};
2389 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
2390 alloc_info.descriptorSetCount = 1;
2391 alloc_info.descriptorPool = ds_pool_one;
2392 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002393 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002394 ASSERT_VK_SUCCESS(err);
2395
2396 err = vkFreeDescriptorSets(m_device->device(), ds_pool_two, 1, &descriptorSet);
2397
2398 m_errorMonitor->VerifyFound();
2399
2400 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2401 vkDestroyDescriptorPool(m_device->device(), ds_pool_one, NULL);
2402 vkDestroyDescriptorPool(m_device->device(), ds_pool_two, NULL);
2403}
2404
2405TEST_F(VkLayerTest, CreateUnknownObject) {
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002406 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00788);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002407
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002408 TEST_DESCRIPTION("Pass an invalid image object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002409
Tony Barbour1fa09702017-03-16 12:09:08 -06002410 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002411
2412 // Pass bogus handle into GetImageMemoryRequirements
2413 VkMemoryRequirements mem_reqs;
2414 uint64_t fakeImageHandle = 0xCADECADE;
2415 VkImage fauxImage = reinterpret_cast<VkImage &>(fakeImageHandle);
2416
2417 vkGetImageMemoryRequirements(m_device->device(), fauxImage, &mem_reqs);
2418
2419 m_errorMonitor->VerifyFound();
2420}
2421
Mike Schuchardt17838902017-02-21 09:48:06 -07002422TEST_F(VkLayerTest, UseObjectWithWrongDevice) {
2423 TEST_DESCRIPTION(
2424 "Try to destroy a render pass object using a device other than the one it was created on. "
2425 "This should generate a distinct error from the invalid handle error.");
2426 // Create first device and renderpass
Tony Barbour1fa09702017-03-16 12:09:08 -06002427 ASSERT_NO_FATAL_FAILURE(Init());
Mike Schuchardt17838902017-02-21 09:48:06 -07002428 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2429
2430 // Create second device
2431 float priorities[] = {1.0f};
2432 VkDeviceQueueCreateInfo queue_info{};
2433 queue_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
2434 queue_info.pNext = NULL;
2435 queue_info.flags = 0;
2436 queue_info.queueFamilyIndex = 0;
2437 queue_info.queueCount = 1;
2438 queue_info.pQueuePriorities = &priorities[0];
2439
2440 VkDeviceCreateInfo device_create_info = {};
2441 auto features = m_device->phy().features();
2442 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
2443 device_create_info.pNext = NULL;
2444 device_create_info.queueCreateInfoCount = 1;
2445 device_create_info.pQueueCreateInfos = &queue_info;
2446 device_create_info.enabledLayerCount = 0;
2447 device_create_info.ppEnabledLayerNames = NULL;
2448 device_create_info.pEnabledFeatures = &features;
2449
2450 VkDevice second_device;
2451 ASSERT_VK_SUCCESS(vkCreateDevice(gpu(), &device_create_info, NULL, &second_device));
2452
2453 // Try to destroy the renderpass from the first device using the second device
2454 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00399);
2455 vkDestroyRenderPass(second_device, m_renderPass, NULL);
2456 m_errorMonitor->VerifyFound();
2457
2458 vkDestroyDevice(second_device, NULL);
2459}
2460
Karl Schultz6addd812016-02-02 17:17:23 -07002461TEST_F(VkLayerTest, PipelineNotBound) {
2462 VkResult err;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002463
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002464 TEST_DESCRIPTION("Pass in an invalid pipeline object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002465
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002466 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00601);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002467
Tony Barbour1fa09702017-03-16 12:09:08 -06002468 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002469 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002470
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002471 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002472 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2473 ds_type_count.descriptorCount = 1;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002474
2475 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002476 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2477 ds_pool_ci.pNext = NULL;
2478 ds_pool_ci.maxSets = 1;
2479 ds_pool_ci.poolSizeCount = 1;
2480 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002481
2482 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002483 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002484 ASSERT_VK_SUCCESS(err);
2485
2486 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002487 dsl_binding.binding = 0;
2488 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2489 dsl_binding.descriptorCount = 1;
2490 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2491 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002492
2493 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002494 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2495 ds_layout_ci.pNext = NULL;
2496 ds_layout_ci.bindingCount = 1;
2497 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002498
2499 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002500 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002501 ASSERT_VK_SUCCESS(err);
2502
2503 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002504 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002505 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07002506 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002507 alloc_info.descriptorPool = ds_pool;
2508 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002509 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002510 ASSERT_VK_SUCCESS(err);
2511
2512 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002513 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2514 pipeline_layout_ci.pNext = NULL;
2515 pipeline_layout_ci.setLayoutCount = 1;
2516 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002517
2518 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002519 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002520 ASSERT_VK_SUCCESS(err);
2521
Mark Youngad779052016-01-06 14:26:04 -07002522 VkPipeline badPipeline = (VkPipeline)((size_t)0xbaadb1be);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002523
Tony Barbour552f6c02016-12-21 14:34:07 -07002524 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002525 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002526
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002527 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002528
Chia-I Wuf7458c52015-10-26 21:10:41 +08002529 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2530 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2531 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002532}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002533
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002534TEST_F(VkLayerTest, BindImageInvalidMemoryType) {
2535 VkResult err;
2536
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002537 TEST_DESCRIPTION(
2538 "Test validation check for an invalid memory type index "
2539 "during bind[Buffer|Image]Memory time");
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002540
Tony Barbour1fa09702017-03-16 12:09:08 -06002541 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002542
2543 // Create an image, allocate memory, set a bad typeIndex and then try to
2544 // bind it
2545 VkImage image;
2546 VkDeviceMemory mem;
2547 VkMemoryRequirements mem_reqs;
2548 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2549 const int32_t tex_width = 32;
2550 const int32_t tex_height = 32;
2551
2552 VkImageCreateInfo image_create_info = {};
2553 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2554 image_create_info.pNext = NULL;
2555 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2556 image_create_info.format = tex_format;
2557 image_create_info.extent.width = tex_width;
2558 image_create_info.extent.height = tex_height;
2559 image_create_info.extent.depth = 1;
2560 image_create_info.mipLevels = 1;
2561 image_create_info.arrayLayers = 1;
2562 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2563 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2564 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2565 image_create_info.flags = 0;
2566
2567 VkMemoryAllocateInfo mem_alloc = {};
2568 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2569 mem_alloc.pNext = NULL;
2570 mem_alloc.allocationSize = 0;
2571 mem_alloc.memoryTypeIndex = 0;
2572
2573 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
2574 ASSERT_VK_SUCCESS(err);
2575
2576 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
2577 mem_alloc.allocationSize = mem_reqs.size;
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002578
2579 // Introduce Failure, select invalid TypeIndex
2580 VkPhysicalDeviceMemoryProperties memory_info;
2581
2582 vkGetPhysicalDeviceMemoryProperties(gpu(), &memory_info);
2583 unsigned int i;
2584 for (i = 0; i < memory_info.memoryTypeCount; i++) {
2585 if ((mem_reqs.memoryTypeBits & (1 << i)) == 0) {
2586 mem_alloc.memoryTypeIndex = i;
2587 break;
2588 }
2589 }
2590 if (i >= memory_info.memoryTypeCount) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07002591 printf(" No invalid memory type index could be found; skipped.\n");
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002592 vkDestroyImage(m_device->device(), image, NULL);
2593 return;
2594 }
2595
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002596 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 -06002597
2598 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
2599 ASSERT_VK_SUCCESS(err);
2600
2601 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2602 (void)err;
2603
2604 m_errorMonitor->VerifyFound();
2605
2606 vkDestroyImage(m_device->device(), image, NULL);
2607 vkFreeMemory(m_device->device(), mem, NULL);
2608}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002609
Karl Schultz6addd812016-02-02 17:17:23 -07002610TEST_F(VkLayerTest, BindInvalidMemory) {
2611 VkResult err;
2612 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002613
Tony Barbour1fa09702017-03-16 12:09:08 -06002614 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisec598302015-09-15 15:02:17 -06002615
Cortf801b982017-01-17 18:10:21 -08002616 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
Cort Strattonde748202017-02-17 12:50:01 -08002617 const int32_t tex_width = 256;
2618 const int32_t tex_height = 256;
Tobin Ehlisec598302015-09-15 15:02:17 -06002619
2620 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002621 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2622 image_create_info.pNext = NULL;
2623 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2624 image_create_info.format = tex_format;
2625 image_create_info.extent.width = tex_width;
2626 image_create_info.extent.height = tex_height;
2627 image_create_info.extent.depth = 1;
2628 image_create_info.mipLevels = 1;
2629 image_create_info.arrayLayers = 1;
2630 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Cort Strattonf1d8a4a2017-01-28 14:17:04 -08002631 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Karl Schultz6addd812016-02-02 17:17:23 -07002632 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2633 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002634
Cortf801b982017-01-17 18:10:21 -08002635 VkBufferCreateInfo buffer_create_info = {};
2636 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
2637 buffer_create_info.pNext = NULL;
2638 buffer_create_info.flags = 0;
Cort Strattonde748202017-02-17 12:50:01 -08002639 buffer_create_info.size = 4 * 1024 * 1024;
2640 buffer_create_info.usage = VK_BUFFER_USAGE_VERTEX_BUFFER_BIT;
Cortf801b982017-01-17 18:10:21 -08002641 buffer_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
Tobin Ehlisec598302015-09-15 15:02:17 -06002642
Cortf801b982017-01-17 18:10:21 -08002643 // Create an image/buffer, allocate memory, free it, and then try to bind it
2644 {
2645 VkImage image = VK_NULL_HANDLE;
2646 VkBuffer buffer = VK_NULL_HANDLE;
2647 err = vkCreateImage(device(), &image_create_info, NULL, &image);
2648 ASSERT_VK_SUCCESS(err);
2649 err = vkCreateBuffer(device(), &buffer_create_info, NULL, &buffer);
2650 ASSERT_VK_SUCCESS(err);
2651 VkMemoryRequirements image_mem_reqs = {}, buffer_mem_reqs = {};
2652 vkGetImageMemoryRequirements(device(), image, &image_mem_reqs);
2653 vkGetBufferMemoryRequirements(device(), buffer, &buffer_mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002654
Cortf801b982017-01-17 18:10:21 -08002655 VkMemoryAllocateInfo image_mem_alloc = {}, buffer_mem_alloc = {};
2656 image_mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2657 image_mem_alloc.allocationSize = image_mem_reqs.size;
2658 pass = m_device->phy().set_memory_type(image_mem_reqs.memoryTypeBits, &image_mem_alloc, 0);
2659 ASSERT_TRUE(pass);
2660 buffer_mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2661 buffer_mem_alloc.allocationSize = buffer_mem_reqs.size;
2662 pass = m_device->phy().set_memory_type(buffer_mem_reqs.memoryTypeBits, &buffer_mem_alloc, 0);
2663 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002664
Cortf801b982017-01-17 18:10:21 -08002665 VkDeviceMemory image_mem = VK_NULL_HANDLE, buffer_mem = VK_NULL_HANDLE;
2666 err = vkAllocateMemory(device(), &image_mem_alloc, NULL, &image_mem);
2667 ASSERT_VK_SUCCESS(err);
2668 err = vkAllocateMemory(device(), &buffer_mem_alloc, NULL, &buffer_mem);
2669 ASSERT_VK_SUCCESS(err);
Tobin Ehlisec598302015-09-15 15:02:17 -06002670
Cortf801b982017-01-17 18:10:21 -08002671 vkFreeMemory(device(), image_mem, NULL);
2672 vkFreeMemory(device(), buffer_mem, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002673
Cortf801b982017-01-17 18:10:21 -08002674 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00809);
2675 err = vkBindImageMemory(device(), image, image_mem, 0);
2676 (void)err; // This may very well return an error.
2677 m_errorMonitor->VerifyFound();
Tobin Ehlisec598302015-09-15 15:02:17 -06002678
Cortf801b982017-01-17 18:10:21 -08002679 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00800);
2680 err = vkBindBufferMemory(device(), buffer, buffer_mem, 0);
2681 (void)err; // This may very well return an error.
2682 m_errorMonitor->VerifyFound();
Tobin Ehlisec598302015-09-15 15:02:17 -06002683
Cortf801b982017-01-17 18:10:21 -08002684 vkDestroyImage(m_device->device(), image, NULL);
2685 vkDestroyBuffer(m_device->device(), buffer, NULL);
2686 }
Cort Strattonc21601b2017-01-28 14:16:16 -08002687
2688 // Try to bind memory to an object that already has a memory binding
2689 {
2690 VkImage image = VK_NULL_HANDLE;
2691 err = vkCreateImage(device(), &image_create_info, NULL, &image);
2692 ASSERT_VK_SUCCESS(err);
2693 VkBuffer buffer = VK_NULL_HANDLE;
2694 err = vkCreateBuffer(device(), &buffer_create_info, NULL, &buffer);
2695 ASSERT_VK_SUCCESS(err);
2696 VkMemoryRequirements image_mem_reqs = {}, buffer_mem_reqs = {};
2697 vkGetImageMemoryRequirements(device(), image, &image_mem_reqs);
2698 vkGetBufferMemoryRequirements(device(), buffer, &buffer_mem_reqs);
2699 VkMemoryAllocateInfo image_alloc_info = {}, buffer_alloc_info = {};
2700 image_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2701 image_alloc_info.allocationSize = image_mem_reqs.size;
2702 buffer_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2703 buffer_alloc_info.allocationSize = buffer_mem_reqs.size;
2704 pass = m_device->phy().set_memory_type(image_mem_reqs.memoryTypeBits, &image_alloc_info, 0);
2705 ASSERT_TRUE(pass);
2706 pass = m_device->phy().set_memory_type(buffer_mem_reqs.memoryTypeBits, &buffer_alloc_info, 0);
2707 ASSERT_TRUE(pass);
2708 VkDeviceMemory image_mem, buffer_mem;
2709 err = vkAllocateMemory(device(), &image_alloc_info, NULL, &image_mem);
2710 ASSERT_VK_SUCCESS(err);
2711 err = vkAllocateMemory(device(), &buffer_alloc_info, NULL, &buffer_mem);
2712 ASSERT_VK_SUCCESS(err);
2713
2714 err = vkBindImageMemory(device(), image, image_mem, 0);
2715 ASSERT_VK_SUCCESS(err);
2716 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00803);
2717 err = vkBindImageMemory(device(), image, image_mem, 0);
2718 (void)err; // This may very well return an error.
2719 m_errorMonitor->VerifyFound();
2720
2721 err = vkBindBufferMemory(device(), buffer, buffer_mem, 0);
2722 ASSERT_VK_SUCCESS(err);
2723 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00791);
2724 err = vkBindBufferMemory(device(), buffer, buffer_mem, 0);
2725 (void)err; // This may very well return an error.
2726 m_errorMonitor->VerifyFound();
2727
2728 vkFreeMemory(device(), image_mem, NULL);
2729 vkFreeMemory(device(), buffer_mem, NULL);
2730 vkDestroyImage(device(), image, NULL);
2731 vkDestroyBuffer(device(), buffer, NULL);
2732 }
Cort Strattonf1d8a4a2017-01-28 14:17:04 -08002733
Cort Strattonde748202017-02-17 12:50:01 -08002734 // Try to bind memory to an object with an invalid memoryOffset
Cort6c7dff72017-01-27 18:34:50 -08002735 {
2736 VkImage image = VK_NULL_HANDLE;
2737 err = vkCreateImage(device(), &image_create_info, NULL, &image);
2738 ASSERT_VK_SUCCESS(err);
2739 VkBuffer buffer = VK_NULL_HANDLE;
2740 err = vkCreateBuffer(device(), &buffer_create_info, NULL, &buffer);
2741 ASSERT_VK_SUCCESS(err);
2742 VkMemoryRequirements image_mem_reqs = {}, buffer_mem_reqs = {};
2743 vkGetImageMemoryRequirements(device(), image, &image_mem_reqs);
2744 vkGetBufferMemoryRequirements(device(), buffer, &buffer_mem_reqs);
2745 VkMemoryAllocateInfo image_alloc_info = {}, buffer_alloc_info = {};
2746 image_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Cort Strattonde748202017-02-17 12:50:01 -08002747 // Leave some extra space for alignment wiggle room
2748 image_alloc_info.allocationSize = image_mem_reqs.size + image_mem_reqs.alignment;
Cort6c7dff72017-01-27 18:34:50 -08002749 buffer_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Cort Strattonde748202017-02-17 12:50:01 -08002750 buffer_alloc_info.allocationSize = buffer_mem_reqs.size + buffer_mem_reqs.alignment;
Cort6c7dff72017-01-27 18:34:50 -08002751 pass = m_device->phy().set_memory_type(image_mem_reqs.memoryTypeBits, &image_alloc_info, 0);
2752 ASSERT_TRUE(pass);
2753 pass = m_device->phy().set_memory_type(buffer_mem_reqs.memoryTypeBits, &buffer_alloc_info, 0);
2754 ASSERT_TRUE(pass);
2755 VkDeviceMemory image_mem, buffer_mem;
2756 err = vkAllocateMemory(device(), &image_alloc_info, NULL, &image_mem);
2757 ASSERT_VK_SUCCESS(err);
2758 err = vkAllocateMemory(device(), &buffer_alloc_info, NULL, &buffer_mem);
2759 ASSERT_VK_SUCCESS(err);
2760
Cort Strattonde748202017-02-17 12:50:01 -08002761 // Test unaligned memory offset
2762 {
2763 if (image_mem_reqs.alignment > 1) {
2764 VkDeviceSize image_offset = 1;
2765 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02178);
2766 err = vkBindImageMemory(device(), image, image_mem, image_offset);
2767 (void)err; // This may very well return an error.
2768 m_errorMonitor->VerifyFound();
2769 }
Cort6c7dff72017-01-27 18:34:50 -08002770
Cort Strattonde748202017-02-17 12:50:01 -08002771 if (buffer_mem_reqs.alignment > 1) {
2772 VkDeviceSize buffer_offset = 1;
2773 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02174);
2774 err = vkBindBufferMemory(device(), buffer, buffer_mem, buffer_offset);
2775 (void)err; // This may very well return an error.
2776 m_errorMonitor->VerifyFound();
2777 }
2778 }
2779
2780 // Test memory offsets outside the memory allocation
2781 {
2782 VkDeviceSize image_offset =
2783 (image_alloc_info.allocationSize + image_mem_reqs.alignment) & ~(image_mem_reqs.alignment - 1);
2784 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00805);
2785 err = vkBindImageMemory(device(), image, image_mem, image_offset);
2786 (void)err; // This may very well return an error.
2787 m_errorMonitor->VerifyFound();
2788
2789 VkDeviceSize buffer_offset =
2790 (buffer_alloc_info.allocationSize + buffer_mem_reqs.alignment) & ~(buffer_mem_reqs.alignment - 1);
2791 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00793);
2792 err = vkBindBufferMemory(device(), buffer, buffer_mem, buffer_offset);
2793 (void)err; // This may very well return an error.
2794 m_errorMonitor->VerifyFound();
2795 }
2796
2797 // Test memory offsets within the memory allocation, but which leave too little memory for
2798 // the resource.
2799 {
2800 VkDeviceSize image_offset = (image_mem_reqs.size - 1) & ~(image_mem_reqs.alignment - 1);
Tony Barbour02d08552017-03-24 16:36:01 -06002801 if ((image_offset > 0) && (image_mem_reqs.size < (image_alloc_info.allocationSize - image_mem_reqs.alignment))) {
Cort Strattonde748202017-02-17 12:50:01 -08002802 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02179);
2803 err = vkBindImageMemory(device(), image, image_mem, image_offset);
2804 (void)err; // This may very well return an error.
2805 m_errorMonitor->VerifyFound();
2806 }
2807
2808 VkDeviceSize buffer_offset = (buffer_mem_reqs.size - 1) & ~(buffer_mem_reqs.alignment - 1);
2809 if (buffer_offset > 0) {
2810 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02175);
2811 err = vkBindBufferMemory(device(), buffer, buffer_mem, buffer_offset);
2812 (void)err; // This may very well return an error.
2813 m_errorMonitor->VerifyFound();
2814 }
2815 }
Cort6c7dff72017-01-27 18:34:50 -08002816
2817 vkFreeMemory(device(), image_mem, NULL);
2818 vkFreeMemory(device(), buffer_mem, NULL);
2819 vkDestroyImage(device(), image, NULL);
2820 vkDestroyBuffer(device(), buffer, NULL);
2821 }
2822
Cort Stratton4c38bb52017-01-28 13:33:10 -08002823 // Try to bind memory to an object with an invalid memory type
2824 {
2825 VkImage image = VK_NULL_HANDLE;
2826 err = vkCreateImage(device(), &image_create_info, NULL, &image);
2827 ASSERT_VK_SUCCESS(err);
2828 VkBuffer buffer = VK_NULL_HANDLE;
2829 err = vkCreateBuffer(device(), &buffer_create_info, NULL, &buffer);
2830 ASSERT_VK_SUCCESS(err);
2831 VkMemoryRequirements image_mem_reqs = {}, buffer_mem_reqs = {};
2832 vkGetImageMemoryRequirements(device(), image, &image_mem_reqs);
2833 vkGetBufferMemoryRequirements(device(), buffer, &buffer_mem_reqs);
2834 VkMemoryAllocateInfo image_alloc_info = {}, buffer_alloc_info = {};
2835 image_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2836 image_alloc_info.allocationSize = image_mem_reqs.size;
2837 buffer_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2838 buffer_alloc_info.allocationSize = buffer_mem_reqs.size;
Cort Strattonccc90e32017-02-04 13:47:42 -08002839 // Create a mask of available memory types *not* supported by these resources,
2840 // and try to use one of them.
Cort Stratton4c38bb52017-01-28 13:33:10 -08002841 VkPhysicalDeviceMemoryProperties memory_properties = {};
2842 vkGetPhysicalDeviceMemoryProperties(m_device->phy().handle(), &memory_properties);
Cort Strattonccc90e32017-02-04 13:47:42 -08002843 VkDeviceMemory image_mem, buffer_mem;
2844
Cort Stratton4c38bb52017-01-28 13:33:10 -08002845 uint32_t image_unsupported_mem_type_bits = ((1 << memory_properties.memoryTypeCount) - 1) & ~image_mem_reqs.memoryTypeBits;
Cort Strattonccc90e32017-02-04 13:47:42 -08002846 if (image_unsupported_mem_type_bits != 0) {
Dave Houlton584d51e2017-02-16 12:52:54 -07002847 pass = m_device->phy().set_memory_type(image_unsupported_mem_type_bits, &image_alloc_info, 0);
2848 ASSERT_TRUE(pass);
2849 err = vkAllocateMemory(device(), &image_alloc_info, NULL, &image_mem);
2850 ASSERT_VK_SUCCESS(err);
2851 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00806);
2852 err = vkBindImageMemory(device(), image, image_mem, 0);
2853 (void)err; // This may very well return an error.
2854 m_errorMonitor->VerifyFound();
2855 vkFreeMemory(device(), image_mem, NULL);
Cort Strattonccc90e32017-02-04 13:47:42 -08002856 }
2857
Cort Stratton4c38bb52017-01-28 13:33:10 -08002858 uint32_t buffer_unsupported_mem_type_bits =
2859 ((1 << memory_properties.memoryTypeCount) - 1) & ~buffer_mem_reqs.memoryTypeBits;
Cort Strattonccc90e32017-02-04 13:47:42 -08002860 if (buffer_unsupported_mem_type_bits != 0) {
Dave Houlton584d51e2017-02-16 12:52:54 -07002861 pass = m_device->phy().set_memory_type(buffer_unsupported_mem_type_bits, &buffer_alloc_info, 0);
2862 ASSERT_TRUE(pass);
2863 err = vkAllocateMemory(device(), &buffer_alloc_info, NULL, &buffer_mem);
2864 ASSERT_VK_SUCCESS(err);
2865 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00797);
2866 err = vkBindBufferMemory(device(), buffer, buffer_mem, 0);
2867 (void)err; // This may very well return an error.
2868 m_errorMonitor->VerifyFound();
2869 vkFreeMemory(device(), buffer_mem, NULL);
Cort Strattonccc90e32017-02-04 13:47:42 -08002870 }
Cort Stratton4c38bb52017-01-28 13:33:10 -08002871
Cort Stratton4c38bb52017-01-28 13:33:10 -08002872 vkDestroyImage(device(), image, NULL);
2873 vkDestroyBuffer(device(), buffer, NULL);
2874 }
2875
Cort Strattonf1d8a4a2017-01-28 14:17:04 -08002876 // Try to bind memory to an image created with sparse memory flags
2877 {
2878 VkImageCreateInfo sparse_image_create_info = image_create_info;
2879 sparse_image_create_info.flags |= VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
2880 VkImageFormatProperties image_format_properties = {};
2881 err = vkGetPhysicalDeviceImageFormatProperties(m_device->phy().handle(), sparse_image_create_info.format,
2882 sparse_image_create_info.imageType, sparse_image_create_info.tiling,
2883 sparse_image_create_info.usage, sparse_image_create_info.flags,
2884 &image_format_properties);
2885 if (!m_device->phy().features().sparseResidencyImage2D || err == VK_ERROR_FORMAT_NOT_SUPPORTED) {
2886 // most likely means sparse formats aren't supported here; skip this test.
2887 } else {
2888 ASSERT_VK_SUCCESS(err);
2889 if (image_format_properties.maxExtent.width == 0) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07002890 printf(" Sparse image format not supported; skipped.\n");
Cort Strattonf1d8a4a2017-01-28 14:17:04 -08002891 return;
2892 } else {
2893 VkImage sparse_image = VK_NULL_HANDLE;
2894 err = vkCreateImage(m_device->device(), &sparse_image_create_info, NULL, &sparse_image);
2895 ASSERT_VK_SUCCESS(err);
2896 VkMemoryRequirements sparse_mem_reqs = {};
2897 vkGetImageMemoryRequirements(m_device->device(), sparse_image, &sparse_mem_reqs);
2898 if (sparse_mem_reqs.memoryTypeBits != 0) {
2899 VkMemoryAllocateInfo sparse_mem_alloc = {};
2900 sparse_mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2901 sparse_mem_alloc.pNext = NULL;
2902 sparse_mem_alloc.allocationSize = sparse_mem_reqs.size;
2903 sparse_mem_alloc.memoryTypeIndex = 0;
2904 pass = m_device->phy().set_memory_type(sparse_mem_reqs.memoryTypeBits, &sparse_mem_alloc, 0);
2905 ASSERT_TRUE(pass);
2906 VkDeviceMemory sparse_mem = VK_NULL_HANDLE;
2907 err = vkAllocateMemory(m_device->device(), &sparse_mem_alloc, NULL, &sparse_mem);
2908 ASSERT_VK_SUCCESS(err);
2909 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00804);
2910 err = vkBindImageMemory(m_device->device(), sparse_image, sparse_mem, 0);
2911 // This may very well return an error.
2912 (void)err;
2913 m_errorMonitor->VerifyFound();
2914 vkFreeMemory(m_device->device(), sparse_mem, NULL);
2915 }
2916 vkDestroyImage(m_device->device(), sparse_image, NULL);
2917 }
2918 }
2919 }
2920
2921 // Try to bind memory to a buffer created with sparse memory flags
2922 {
2923 VkBufferCreateInfo sparse_buffer_create_info = buffer_create_info;
2924 sparse_buffer_create_info.flags |= VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
2925 if (!m_device->phy().features().sparseResidencyBuffer) {
2926 // most likely means sparse formats aren't supported here; skip this test.
2927 } else {
2928 VkBuffer sparse_buffer = VK_NULL_HANDLE;
2929 err = vkCreateBuffer(m_device->device(), &sparse_buffer_create_info, NULL, &sparse_buffer);
2930 ASSERT_VK_SUCCESS(err);
2931 VkMemoryRequirements sparse_mem_reqs = {};
2932 vkGetBufferMemoryRequirements(m_device->device(), sparse_buffer, &sparse_mem_reqs);
2933 if (sparse_mem_reqs.memoryTypeBits != 0) {
2934 VkMemoryAllocateInfo sparse_mem_alloc = {};
2935 sparse_mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2936 sparse_mem_alloc.pNext = NULL;
2937 sparse_mem_alloc.allocationSize = sparse_mem_reqs.size;
2938 sparse_mem_alloc.memoryTypeIndex = 0;
2939 pass = m_device->phy().set_memory_type(sparse_mem_reqs.memoryTypeBits, &sparse_mem_alloc, 0);
2940 ASSERT_TRUE(pass);
2941 VkDeviceMemory sparse_mem = VK_NULL_HANDLE;
2942 err = vkAllocateMemory(m_device->device(), &sparse_mem_alloc, NULL, &sparse_mem);
2943 ASSERT_VK_SUCCESS(err);
2944 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00792);
2945 err = vkBindBufferMemory(m_device->device(), sparse_buffer, sparse_mem, 0);
2946 // This may very well return an error.
2947 (void)err;
2948 m_errorMonitor->VerifyFound();
2949 vkFreeMemory(m_device->device(), sparse_mem, NULL);
2950 }
2951 vkDestroyBuffer(m_device->device(), sparse_buffer, NULL);
2952 }
2953 }
Tobin Ehlisec598302015-09-15 15:02:17 -06002954}
2955
Karl Schultz6addd812016-02-02 17:17:23 -07002956TEST_F(VkLayerTest, BindMemoryToDestroyedObject) {
2957 VkResult err;
2958 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002959
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002960 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00808);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002961
Tony Barbour1fa09702017-03-16 12:09:08 -06002962 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisec598302015-09-15 15:02:17 -06002963
Karl Schultz6addd812016-02-02 17:17:23 -07002964 // Create an image object, allocate memory, destroy the object and then try
2965 // to bind it
2966 VkImage image;
2967 VkDeviceMemory mem;
2968 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06002969
Karl Schultz6addd812016-02-02 17:17:23 -07002970 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2971 const int32_t tex_width = 32;
2972 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06002973
2974 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002975 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2976 image_create_info.pNext = NULL;
2977 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2978 image_create_info.format = tex_format;
2979 image_create_info.extent.width = tex_width;
2980 image_create_info.extent.height = tex_height;
2981 image_create_info.extent.depth = 1;
2982 image_create_info.mipLevels = 1;
2983 image_create_info.arrayLayers = 1;
2984 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2985 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2986 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2987 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002988
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002989 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002990 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2991 mem_alloc.pNext = NULL;
2992 mem_alloc.allocationSize = 0;
2993 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002994
Chia-I Wuf7458c52015-10-26 21:10:41 +08002995 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06002996 ASSERT_VK_SUCCESS(err);
2997
Karl Schultz6addd812016-02-02 17:17:23 -07002998 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002999
3000 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003001 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06003002 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06003003
3004 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003005 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06003006 ASSERT_VK_SUCCESS(err);
3007
3008 // Introduce validation failure, destroy Image object before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08003009 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06003010 ASSERT_VK_SUCCESS(err);
3011
3012 // Now Try to bind memory to this destroyed object
3013 err = vkBindImageMemory(m_device->device(), image, mem, 0);
3014 // This may very well return an error.
Karl Schultz6addd812016-02-02 17:17:23 -07003015 (void)err;
Tobin Ehlisec598302015-09-15 15:02:17 -06003016
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003017 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06003018
Chia-I Wuf7458c52015-10-26 21:10:41 +08003019 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003020}
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003021
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -07003022TEST_F(VkLayerTest, CreatePipelineBadVertexAttributeFormat) {
3023 TEST_DESCRIPTION("Test that pipeline validation catches invalid vertex attribute formats");
3024
Tony Barbour1fa09702017-03-16 12:09:08 -06003025 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -07003026 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3027
3028 VkVertexInputBindingDescription input_binding;
3029 memset(&input_binding, 0, sizeof(input_binding));
3030
3031 VkVertexInputAttributeDescription input_attribs;
3032 memset(&input_attribs, 0, sizeof(input_attribs));
3033
3034 // Pick a really bad format for this purpose and make sure it should fail
3035 input_attribs.format = VK_FORMAT_BC2_UNORM_BLOCK;
3036 VkFormatProperties format_props = m_device->format_properties(input_attribs.format);
3037 if ((format_props.bufferFeatures & VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT) != 0) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07003038 printf(" Format unsuitable for test; skipped.\n");
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -07003039 return;
3040 }
3041
3042 input_attribs.location = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003043 char const *vsSource =
3044 "#version 450\n"
3045 "\n"
3046 "out gl_PerVertex {\n"
3047 " vec4 gl_Position;\n"
3048 "};\n"
3049 "void main(){\n"
3050 " gl_Position = vec4(1);\n"
3051 "}\n";
3052 char const *fsSource =
3053 "#version 450\n"
3054 "\n"
3055 "layout(location=0) out vec4 color;\n"
3056 "void main(){\n"
3057 " color = vec4(1);\n"
3058 "}\n";
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -07003059
3060 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01413);
3061 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
3062 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
3063
3064 VkPipelineObj pipe(m_device);
3065 pipe.AddColorAttachment();
3066 pipe.AddShader(&vs);
3067 pipe.AddShader(&fs);
3068
3069 pipe.AddVertexInputBindings(&input_binding, 1);
3070 pipe.AddVertexInputAttribs(&input_attribs, 1);
3071
3072 VkDescriptorSetObj descriptorSet(m_device);
3073 descriptorSet.AppendDummy();
3074 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
3075
3076 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
3077
3078 m_errorMonitor->VerifyFound();
3079}
3080
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003081TEST_F(VkLayerTest, ImageSampleCounts) {
Jeremy Hayes0d104082017-02-21 10:24:16 -07003082 TEST_DESCRIPTION("Use bad sample counts in image transfer calls to trigger validation errors.");
Tony Barbour1fa09702017-03-16 12:09:08 -06003083 ASSERT_NO_FATAL_FAILURE(Init(nullptr, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT));
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003084
3085 VkMemoryPropertyFlags reqs = 0;
3086 VkImageCreateInfo image_create_info = {};
3087 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3088 image_create_info.pNext = NULL;
3089 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3090 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
3091 image_create_info.extent.width = 256;
3092 image_create_info.extent.height = 256;
3093 image_create_info.extent.depth = 1;
3094 image_create_info.mipLevels = 1;
3095 image_create_info.arrayLayers = 1;
3096 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
3097 image_create_info.flags = 0;
3098
3099 VkImageBlit blit_region = {};
3100 blit_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3101 blit_region.srcSubresource.baseArrayLayer = 0;
3102 blit_region.srcSubresource.layerCount = 1;
3103 blit_region.srcSubresource.mipLevel = 0;
3104 blit_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3105 blit_region.dstSubresource.baseArrayLayer = 0;
3106 blit_region.dstSubresource.layerCount = 1;
3107 blit_region.dstSubresource.mipLevel = 0;
3108
3109 // Create two images, the source with sampleCount = 2, and attempt to blit
3110 // between them
3111 {
3112 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003113 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003114 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003115 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003116 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003117 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003118 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003119 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003120 m_commandBuffer->BeginCommandBuffer();
Jeremy Hayes0d104082017-02-21 10:24:16 -07003121 m_errorMonitor->SetDesiredFailureMsg(
3122 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3123 "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 -06003124 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3125 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003126 m_errorMonitor->VerifyFound();
3127 m_commandBuffer->EndCommandBuffer();
3128 }
3129
3130 // Create two images, the dest with sampleCount = 4, and attempt to blit
3131 // between them
3132 {
3133 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003134 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003135 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003136 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003137 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003138 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003139 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003140 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003141 m_commandBuffer->BeginCommandBuffer();
Jeremy Hayes0d104082017-02-21 10:24:16 -07003142 m_errorMonitor->SetDesiredFailureMsg(
3143 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3144 "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 -06003145 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3146 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003147 m_errorMonitor->VerifyFound();
3148 m_commandBuffer->EndCommandBuffer();
3149 }
3150
3151 VkBufferImageCopy copy_region = {};
3152 copy_region.bufferRowLength = 128;
3153 copy_region.bufferImageHeight = 128;
3154 copy_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3155 copy_region.imageSubresource.layerCount = 1;
3156 copy_region.imageExtent.height = 64;
3157 copy_region.imageExtent.width = 64;
3158 copy_region.imageExtent.depth = 1;
3159
3160 // Create src buffer and dst image with sampleCount = 4 and attempt to copy
3161 // buffer to image
3162 {
3163 vk_testing::Buffer src_buffer;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003164 src_buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
3165 image_create_info.samples = VK_SAMPLE_COUNT_8_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003166 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003167 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003168 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003169 m_commandBuffer->BeginCommandBuffer();
Jeremy Hayes0d104082017-02-21 10:24:16 -07003170 m_errorMonitor->SetDesiredFailureMsg(
3171 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3172 "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 -06003173 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), src_buffer.handle(), dst_image.handle(),
3174 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &copy_region);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003175 m_errorMonitor->VerifyFound();
3176 m_commandBuffer->EndCommandBuffer();
3177 }
3178
3179 // Create dst buffer and src image with sampleCount = 2 and attempt to copy
3180 // image to buffer
3181 {
3182 vk_testing::Buffer dst_buffer;
3183 dst_buffer.init_as_dst(*m_device, 128 * 128 * 4, reqs);
3184 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003185 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003186 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003187 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003188 m_commandBuffer->BeginCommandBuffer();
Jeremy Hayes0d104082017-02-21 10:24:16 -07003189 m_errorMonitor->SetDesiredFailureMsg(
3190 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3191 "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 -06003192 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003193 dst_buffer.handle(), 1, &copy_region);
3194 m_errorMonitor->VerifyFound();
3195 m_commandBuffer->EndCommandBuffer();
3196 }
3197}
3198
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003199TEST_F(VkLayerTest, BlitImageFormats) {
Tony Barbour1fa09702017-03-16 12:09:08 -06003200 ASSERT_NO_FATAL_FAILURE(Init());
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003201
3202 VkImageObj src_image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06003203 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 -06003204 VkImageObj dst_image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06003205 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 -06003206 VkImageObj dst_image2(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06003207 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 -06003208
3209 VkImageBlit blitRegion = {};
3210 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3211 blitRegion.srcSubresource.baseArrayLayer = 0;
3212 blitRegion.srcSubresource.layerCount = 1;
3213 blitRegion.srcSubresource.mipLevel = 0;
3214 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3215 blitRegion.dstSubresource.baseArrayLayer = 0;
3216 blitRegion.dstSubresource.layerCount = 1;
3217 blitRegion.dstSubresource.mipLevel = 0;
3218
Dave Houlton34df4cb2016-12-01 16:43:06 -07003219 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02191);
3220
3221 // TODO: there are 9 permutations of signed, unsigned, & other for source and dest
3222 // this test is only checking 2 of them at the moment
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003223
3224 // Unsigned int vs not an int
Tony Barbour552f6c02016-12-21 14:34:07 -07003225 m_commandBuffer->BeginCommandBuffer();
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06003226 vkCmdBlitImage(m_commandBuffer->handle(), src_image.image(), src_image.Layout(), dst_image.image(), dst_image.Layout(), 1,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003227 &blitRegion, VK_FILTER_NEAREST);
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003228
3229 m_errorMonitor->VerifyFound();
3230
Dave Houlton34df4cb2016-12-01 16:43:06 -07003231 // Test should generate 2 VU failures
3232 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02190);
3233 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02191);
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003234
3235 // Unsigned int vs signed int
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06003236 vkCmdBlitImage(m_commandBuffer->handle(), src_image.image(), src_image.Layout(), dst_image2.image(), dst_image2.Layout(), 1,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003237 &blitRegion, VK_FILTER_NEAREST);
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003238
Dave Houlton34df4cb2016-12-01 16:43:06 -07003239 // TODO: Note that this only verifies that at least one of the VU enums was found
3240 // 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 -06003241 m_errorMonitor->VerifyFound();
3242
Tony Barbour552f6c02016-12-21 14:34:07 -07003243 m_commandBuffer->EndCommandBuffer();
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003244}
3245
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003246TEST_F(VkLayerTest, DSImageTransferGranularityTests) {
3247 VkResult err;
3248 bool pass;
3249
3250 TEST_DESCRIPTION("Tests for validaiton of Queue Family property minImageTransferGranularity.");
Tony Barbour1fa09702017-03-16 12:09:08 -06003251 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003252
3253 // If w/d/h granularity is 1, test is not meaningful
3254 // TODO: When virtual device limits are available, create a set of limits for this test that
3255 // will always have a granularity of > 1 for w, h, and d
3256 auto index = m_device->graphics_queue_node_index_;
3257 auto queue_family_properties = m_device->phy().queue_properties();
3258
3259 if ((queue_family_properties[index].minImageTransferGranularity.depth < 4) ||
3260 (queue_family_properties[index].minImageTransferGranularity.width < 4) ||
3261 (queue_family_properties[index].minImageTransferGranularity.height < 4)) {
3262 return;
3263 }
3264
3265 // Create two images of different types and try to copy between them
3266 VkImage srcImage;
3267 VkImage dstImage;
3268 VkDeviceMemory srcMem;
3269 VkDeviceMemory destMem;
3270 VkMemoryRequirements memReqs;
3271
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003272 VkImageCreateInfo image_create_info = {};
3273 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3274 image_create_info.pNext = NULL;
3275 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3276 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
3277 image_create_info.extent.width = 32;
3278 image_create_info.extent.height = 32;
3279 image_create_info.extent.depth = 1;
3280 image_create_info.mipLevels = 1;
3281 image_create_info.arrayLayers = 4;
3282 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
3283 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
3284 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
3285 image_create_info.flags = 0;
3286
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003287 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003288 ASSERT_VK_SUCCESS(err);
3289
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003290 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003291 ASSERT_VK_SUCCESS(err);
3292
3293 // Allocate memory
3294 VkMemoryAllocateInfo memAlloc = {};
3295 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
3296 memAlloc.pNext = NULL;
3297 memAlloc.allocationSize = 0;
3298 memAlloc.memoryTypeIndex = 0;
3299
3300 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
3301 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003302 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003303 ASSERT_TRUE(pass);
3304 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
3305 ASSERT_VK_SUCCESS(err);
3306
3307 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
3308 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003309 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003310 ASSERT_VK_SUCCESS(err);
3311 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
3312 ASSERT_VK_SUCCESS(err);
3313
3314 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
3315 ASSERT_VK_SUCCESS(err);
3316 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
3317 ASSERT_VK_SUCCESS(err);
3318
Tony Barbour552f6c02016-12-21 14:34:07 -07003319 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003320 VkImageCopy copyRegion;
3321 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3322 copyRegion.srcSubresource.mipLevel = 0;
3323 copyRegion.srcSubresource.baseArrayLayer = 0;
3324 copyRegion.srcSubresource.layerCount = 1;
3325 copyRegion.srcOffset.x = 0;
3326 copyRegion.srcOffset.y = 0;
3327 copyRegion.srcOffset.z = 0;
3328 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3329 copyRegion.dstSubresource.mipLevel = 0;
3330 copyRegion.dstSubresource.baseArrayLayer = 0;
3331 copyRegion.dstSubresource.layerCount = 1;
3332 copyRegion.dstOffset.x = 0;
3333 copyRegion.dstOffset.y = 0;
3334 copyRegion.dstOffset.z = 0;
3335 copyRegion.extent.width = 1;
3336 copyRegion.extent.height = 1;
3337 copyRegion.extent.depth = 1;
3338
3339 // Introduce failure by setting srcOffset to a bad granularity value
3340 copyRegion.srcOffset.y = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003341 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3342 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003343 m_errorMonitor->VerifyFound();
3344
3345 // Introduce failure by setting extent to a bad granularity value
3346 copyRegion.srcOffset.y = 0;
3347 copyRegion.extent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003348 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3349 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003350 m_errorMonitor->VerifyFound();
3351
3352 // Now do some buffer/image copies
3353 vk_testing::Buffer buffer;
3354 VkMemoryPropertyFlags reqs = 0;
3355 buffer.init_as_dst(*m_device, 128 * 128, reqs);
3356 VkBufferImageCopy region = {};
3357 region.bufferOffset = 0;
3358 region.bufferRowLength = 3;
3359 region.bufferImageHeight = 128;
3360 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3361 region.imageSubresource.layerCount = 1;
3362 region.imageExtent.height = 16;
3363 region.imageExtent.width = 16;
3364 region.imageExtent.depth = 1;
3365 region.imageOffset.x = 0;
3366 region.imageOffset.y = 0;
3367 region.imageOffset.z = 0;
3368
3369 // Introduce failure by setting bufferRowLength to a bad granularity value
3370 region.bufferRowLength = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003371 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3372 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
3373 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003374 m_errorMonitor->VerifyFound();
3375 region.bufferRowLength = 128;
3376
3377 // Introduce failure by setting bufferOffset to a bad granularity value
3378 region.bufferOffset = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003379 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3380 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
3381 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003382 m_errorMonitor->VerifyFound();
3383 region.bufferOffset = 0;
3384
3385 // Introduce failure by setting bufferImageHeight to a bad granularity value
3386 region.bufferImageHeight = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003387 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3388 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
3389 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003390 m_errorMonitor->VerifyFound();
3391 region.bufferImageHeight = 128;
3392
3393 // Introduce failure by setting imageExtent to a bad granularity value
3394 region.imageExtent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003395 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3396 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
3397 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003398 m_errorMonitor->VerifyFound();
3399 region.imageExtent.width = 16;
3400
3401 // Introduce failure by setting imageOffset to a bad granularity value
3402 region.imageOffset.z = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003403 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3404 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
3405 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003406 m_errorMonitor->VerifyFound();
3407
Tony Barbour552f6c02016-12-21 14:34:07 -07003408 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003409
3410 vkDestroyImage(m_device->device(), srcImage, NULL);
3411 vkDestroyImage(m_device->device(), dstImage, NULL);
3412 vkFreeMemory(m_device->device(), srcMem, NULL);
3413 vkFreeMemory(m_device->device(), destMem, NULL);
3414}
3415
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003416TEST_F(VkLayerTest, MismatchedQueueFamiliesOnSubmit) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003417 TEST_DESCRIPTION(
3418 "Submit command buffer created using one queue family and "
3419 "attempt to submit them on a queue created in a different "
3420 "queue family.");
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003421
Tony Barbour1fa09702017-03-16 12:09:08 -06003422 ASSERT_NO_FATAL_FAILURE(Init());
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07003423
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003424 // This test is meaningless unless we have multiple queue families
3425 auto queue_family_properties = m_device->phy().queue_properties();
3426 if (queue_family_properties.size() < 2) {
3427 return;
3428 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003429 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is being submitted on queue ");
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003430 // Get safe index of another queue family
3431 uint32_t other_queue_family = (m_device->graphics_queue_node_index_ == 0) ? 1 : 0;
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003432 VkQueue other_queue;
3433 vkGetDeviceQueue(m_device->device(), other_queue_family, 0, &other_queue);
3434
3435 // Record an empty cmd buffer
3436 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
3437 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3438 vkBeginCommandBuffer(m_commandBuffer->handle(), &cmdBufBeginDesc);
3439 vkEndCommandBuffer(m_commandBuffer->handle());
3440
3441 // And submit on the wrong queue
3442 VkSubmitInfo submit_info = {};
3443 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3444 submit_info.commandBufferCount = 1;
3445 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Tobin Ehlisfd213ea2016-08-10 17:10:46 -06003446 vkQueueSubmit(other_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003447
3448 m_errorMonitor->VerifyFound();
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003449}
3450
Chris Forbes4c24a922016-11-16 08:59:10 +13003451TEST_F(VkLayerTest, RenderPassAttachmentIndexOutOfRange) {
Tony Barbour1fa09702017-03-16 12:09:08 -06003452 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes4c24a922016-11-16 08:59:10 +13003453
Chris Forbes2d9b2a82016-11-21 10:45:39 +13003454 // There are no attachments, but refer to attachment 0.
3455 VkAttachmentReference ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbes4c24a922016-11-16 08:59:10 +13003456 VkSubpassDescription subpasses[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003457 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &ref, nullptr, nullptr, 0, nullptr},
Chris Forbes4c24a922016-11-16 08:59:10 +13003458 };
3459
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003460 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 1, subpasses, 0, nullptr};
Chris Forbes4c24a922016-11-16 08:59:10 +13003461 VkRenderPass rp;
3462
Chris Forbes2d9b2a82016-11-21 10:45:39 +13003463 // "... must be less than the total number of attachments ..."
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003464 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00325);
Chris Forbes4c24a922016-11-16 08:59:10 +13003465 vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3466 m_errorMonitor->VerifyFound();
3467}
3468
Chris Forbesa58c4522016-09-28 15:19:39 +13003469TEST_F(VkLayerTest, RenderPassPipelineSubpassMismatch) {
3470 TEST_DESCRIPTION("Use a pipeline for the wrong subpass in a render pass instance");
Tony Barbour1fa09702017-03-16 12:09:08 -06003471 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbesa58c4522016-09-28 15:19:39 +13003472
3473 // A renderpass with two subpasses, both writing the same attachment.
3474 VkAttachmentDescription attach[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003475 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3476 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_UNDEFINED,
3477 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesa58c4522016-09-28 15:19:39 +13003478 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003479 VkAttachmentReference ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbesa58c4522016-09-28 15:19:39 +13003480 VkSubpassDescription subpasses[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003481 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &ref, nullptr, nullptr, 0, nullptr},
3482 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &ref, nullptr, nullptr, 0, nullptr},
Chris Forbesa58c4522016-09-28 15:19:39 +13003483 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003484 VkSubpassDependency dep = {0,
3485 1,
3486 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
3487 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
3488 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
3489 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
3490 VK_DEPENDENCY_BY_REGION_BIT};
3491 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, attach, 2, subpasses, 1, &dep};
Chris Forbesa58c4522016-09-28 15:19:39 +13003492 VkRenderPass rp;
3493 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3494 ASSERT_VK_SUCCESS(err);
3495
3496 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06003497 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 +13003498 VkImageView imageView = image.targetView(VK_FORMAT_R8G8B8A8_UNORM);
3499
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003500 VkFramebufferCreateInfo fbci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &imageView, 32, 32, 1};
Chris Forbesa58c4522016-09-28 15:19:39 +13003501 VkFramebuffer fb;
3502 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
3503 ASSERT_VK_SUCCESS(err);
3504
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003505 char const *vsSource =
3506 "#version 450\n"
3507 "void main() { gl_Position = vec4(1); }\n";
3508 char const *fsSource =
3509 "#version 450\n"
3510 "layout(location=0) out vec4 color;\n"
3511 "void main() { color = vec4(1); }\n";
Chris Forbesa58c4522016-09-28 15:19:39 +13003512
3513 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
3514 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
3515 VkPipelineObj pipe(m_device);
3516 pipe.AddColorAttachment();
3517 pipe.AddShader(&vs);
3518 pipe.AddShader(&fs);
3519 VkViewport view_port = {};
3520 m_viewports.push_back(view_port);
3521 pipe.SetViewport(m_viewports);
3522 VkRect2D rect = {};
3523 m_scissors.push_back(rect);
3524 pipe.SetScissor(m_scissors);
3525
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003526 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 0, nullptr, 0, nullptr};
Chris Forbesa58c4522016-09-28 15:19:39 +13003527 VkPipelineLayout pl;
3528 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
3529 ASSERT_VK_SUCCESS(err);
3530 pipe.CreateVKPipeline(pl, rp);
3531
Tony Barbour552f6c02016-12-21 14:34:07 -07003532 m_commandBuffer->BeginCommandBuffer();
Chris Forbesa58c4522016-09-28 15:19:39 +13003533
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003534 VkRenderPassBeginInfo rpbi = {VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO,
3535 nullptr,
3536 rp,
3537 fb,
3538 {{
3539 0, 0,
3540 },
3541 {32, 32}},
3542 0,
3543 nullptr};
Chris Forbesa58c4522016-09-28 15:19:39 +13003544
3545 // subtest 1: bind in the wrong subpass
3546 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
3547 vkCmdNextSubpass(m_commandBuffer->handle(), VK_SUBPASS_CONTENTS_INLINE);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003548 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 +13003549 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
3550 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
3551 m_errorMonitor->VerifyFound();
3552
3553 vkCmdEndRenderPass(m_commandBuffer->handle());
3554
3555 // subtest 2: bind in correct subpass, then transition to next subpass
3556 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
3557 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
3558 vkCmdNextSubpass(m_commandBuffer->handle(), VK_SUBPASS_CONTENTS_INLINE);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003559 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 +13003560 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
3561 m_errorMonitor->VerifyFound();
3562
3563 vkCmdEndRenderPass(m_commandBuffer->handle());
3564
Tony Barbour552f6c02016-12-21 14:34:07 -07003565 m_commandBuffer->EndCommandBuffer();
Chris Forbesa58c4522016-09-28 15:19:39 +13003566
3567 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
3568 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
3569 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3570}
3571
Tony Barbour4e919972016-08-09 13:27:40 -06003572TEST_F(VkLayerTest, RenderPassInvalidRenderArea) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003573 TEST_DESCRIPTION(
3574 "Generate INVALID_RENDER_AREA error by beginning renderpass"
3575 "with extent outside of framebuffer");
Tony Barbour1fa09702017-03-16 12:09:08 -06003576 ASSERT_NO_FATAL_FAILURE(Init());
Tony Barbour4e919972016-08-09 13:27:40 -06003577 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3578
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003579 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3580 "Cannot execute a render pass with renderArea "
3581 "not within the bound of the framebuffer.");
Tony Barbour4e919972016-08-09 13:27:40 -06003582
3583 // Framebuffer for render target is 256x256, exceed that for INVALID_RENDER_AREA
3584 m_renderPassBeginInfo.renderArea.extent.width = 257;
3585 m_renderPassBeginInfo.renderArea.extent.height = 257;
Tony Barbour552f6c02016-12-21 14:34:07 -07003586 m_commandBuffer->BeginCommandBuffer();
3587 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tony Barbour4e919972016-08-09 13:27:40 -06003588 m_errorMonitor->VerifyFound();
3589}
3590
3591TEST_F(VkLayerTest, DisabledIndependentBlend) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003592 TEST_DESCRIPTION(
3593 "Generate INDEPENDENT_BLEND by disabling independent "
3594 "blend and then specifying different blend states for two "
3595 "attachements");
Cody Northrop5703cc72016-08-19 09:57:10 -06003596 VkPhysicalDeviceFeatures features = {};
3597 features.independentBlend = VK_FALSE;
Tony Barbour1fa09702017-03-16 12:09:08 -06003598 ASSERT_NO_FATAL_FAILURE(Init(&features));
Tony Barbour4e919972016-08-09 13:27:40 -06003599
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003600 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3601 "Invalid Pipeline CreateInfo: If independent blend feature not "
3602 "enabled, all elements of pAttachments must be identical");
Tony Barbour4e919972016-08-09 13:27:40 -06003603
Cody Northropc31a84f2016-08-22 10:41:47 -06003604 VkDescriptorSetObj descriptorSet(m_device);
3605 descriptorSet.AppendDummy();
3606 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Tony Barbour4e919972016-08-09 13:27:40 -06003607
Cody Northropc31a84f2016-08-22 10:41:47 -06003608 VkPipelineObj pipeline(m_device);
Tony Barbour0ace59a2017-02-06 13:38:36 -07003609 // Create a renderPass with two color attachments
3610 VkAttachmentReference attachments[2] = {};
3611 attachments[0].layout = VK_IMAGE_LAYOUT_GENERAL;
Tony Barbourffd60bd2017-03-09 12:04:55 -07003612 attachments[1].attachment = 1;
Tony Barbour0ace59a2017-02-06 13:38:36 -07003613 attachments[1].layout = VK_IMAGE_LAYOUT_GENERAL;
3614
3615 VkSubpassDescription subpass = {};
3616 subpass.pColorAttachments = attachments;
3617 subpass.colorAttachmentCount = 2;
3618
3619 VkRenderPassCreateInfo rpci = {};
3620 rpci.subpassCount = 1;
3621 rpci.pSubpasses = &subpass;
Tony Barbourffd60bd2017-03-09 12:04:55 -07003622 rpci.attachmentCount = 2;
Tony Barbour0ace59a2017-02-06 13:38:36 -07003623
Tony Barbourffd60bd2017-03-09 12:04:55 -07003624 VkAttachmentDescription attach_desc[2] = {};
3625 attach_desc[0].format = VK_FORMAT_B8G8R8A8_UNORM;
3626 attach_desc[0].samples = VK_SAMPLE_COUNT_1_BIT;
3627 attach_desc[0].initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
3628 attach_desc[0].finalLayout = VK_IMAGE_LAYOUT_GENERAL;
3629 attach_desc[1].format = VK_FORMAT_B8G8R8A8_UNORM;
3630 attach_desc[1].samples = VK_SAMPLE_COUNT_1_BIT;
3631 attach_desc[1].initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
3632 attach_desc[1].finalLayout = VK_IMAGE_LAYOUT_GENERAL;
Tony Barbour0ace59a2017-02-06 13:38:36 -07003633
Tony Barbourffd60bd2017-03-09 12:04:55 -07003634 rpci.pAttachments = attach_desc;
Tony Barbour0ace59a2017-02-06 13:38:36 -07003635 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3636
3637 VkRenderPass renderpass;
3638 vkCreateRenderPass(m_device->device(), &rpci, NULL, &renderpass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003639 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Cody Northropc31a84f2016-08-22 10:41:47 -06003640 pipeline.AddShader(&vs);
Cody Northrop5703cc72016-08-19 09:57:10 -06003641
Cody Northropc31a84f2016-08-22 10:41:47 -06003642 VkPipelineColorBlendAttachmentState att_state1 = {}, att_state2 = {};
3643 att_state1.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3644 att_state1.blendEnable = VK_TRUE;
3645 att_state2.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3646 att_state2.blendEnable = VK_FALSE;
3647 pipeline.AddColorAttachment(0, &att_state1);
3648 pipeline.AddColorAttachment(1, &att_state2);
Tony Barbour0ace59a2017-02-06 13:38:36 -07003649 pipeline.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderpass);
Cody Northropc31a84f2016-08-22 10:41:47 -06003650 m_errorMonitor->VerifyFound();
Tony Barbour0ace59a2017-02-06 13:38:36 -07003651 vkDestroyRenderPass(m_device->device(), renderpass, NULL);
Tony Barbour4e919972016-08-09 13:27:40 -06003652}
3653
Mike Weiblen40b160e2017-02-06 19:21:52 -07003654// Is the Pipeline compatible with the expectations of the Renderpass/subpasses?
3655TEST_F(VkLayerTest, PipelineRenderpassCompatibility) {
3656 TEST_DESCRIPTION(
3657 "Create a graphics pipeline that is incompatible with the requirements "
3658 "of its contained Renderpass/subpasses.");
Tony Barbour1fa09702017-03-16 12:09:08 -06003659 ASSERT_NO_FATAL_FAILURE(Init());
Mike Weiblen40b160e2017-02-06 19:21:52 -07003660
3661 VkDescriptorSetObj ds_obj(m_device);
3662 ds_obj.AppendDummy();
3663 ds_obj.CreateVKDescriptorSet(m_commandBuffer);
3664
3665 VkShaderObj vs_obj(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
3666
3667 VkPipelineColorBlendAttachmentState att_state1 = {};
3668 att_state1.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3669 att_state1.blendEnable = VK_TRUE;
3670
3671 VkRenderpassObj rp_obj(m_device);
3672
3673 {
3674 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02116);
3675 VkPipelineObj pipeline(m_device);
3676 pipeline.AddShader(&vs_obj);
3677 pipeline.AddColorAttachment(0, &att_state1);
3678
3679 VkGraphicsPipelineCreateInfo info = {};
3680 pipeline.InitGraphicsPipelineCreateInfo(&info);
3681 info.pColorBlendState = nullptr;
3682
3683 pipeline.CreateVKPipeline(ds_obj.GetPipelineLayout(), rp_obj.handle(), &info);
3684 m_errorMonitor->VerifyFound();
3685 }
3686}
3687
Cort Stratton7547f772017-05-04 15:18:52 -07003688TEST_F(VkLayerTest, CreateRenderPassAttachments) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003689 TEST_DESCRIPTION(
Cort Stratton7547f772017-05-04 15:18:52 -07003690 "Ensure that CreateRenderPass produces the expected validation errors "
3691 "when a subpass's attachments violate the valid usage conditions.");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003692
Tony Barbour1fa09702017-03-16 12:09:08 -06003693 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003694
Cort Stratton7547f772017-05-04 15:18:52 -07003695 std::vector<VkAttachmentDescription> attachments = {
3696 // input attachments
3697 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3698 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_GENERAL,
3699 VK_IMAGE_LAYOUT_GENERAL},
3700 // color attachments
3701 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3702 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3703 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3704 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3705 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3706 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3707 // depth attachment
3708 {0, VK_FORMAT_D24_UNORM_S8_UINT, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3709 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
3710 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL},
3711 // resolve attachment
3712 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3713 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3714 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3715 // preserve attachments
3716 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3717 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3718 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3719 };
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003720
Cort Stratton7547f772017-05-04 15:18:52 -07003721 std::vector<VkAttachmentReference> input = {
3722 {0, VK_IMAGE_LAYOUT_GENERAL},
3723 };
3724 std::vector<VkAttachmentReference> color = {
3725 {1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL}, {2, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3726 };
3727 VkAttachmentReference depth = {3, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
3728 std::vector<VkAttachmentReference> resolve = {
3729 {4, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL}, {VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3730 };
3731 std::vector<uint32_t> preserve = {5};
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003732
Cort Stratton7547f772017-05-04 15:18:52 -07003733 VkSubpassDescription subpass = {0,
3734 VK_PIPELINE_BIND_POINT_GRAPHICS,
3735 (uint32_t)input.size(),
3736 input.data(),
3737 (uint32_t)color.size(),
3738 color.data(),
3739 resolve.data(),
3740 &depth,
3741 (uint32_t)preserve.size(),
3742 preserve.data()};
3743
3744 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO,
3745 nullptr,
3746 0,
3747 (uint32_t)attachments.size(),
3748 attachments.data(),
3749 1,
3750 &subpass,
3751 0,
3752 nullptr};
3753
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003754 VkRenderPass rp;
Cort Stratton7547f772017-05-04 15:18:52 -07003755 VkResult err;
3756 // Test too many color attachments
3757 {
3758 std::vector<VkAttachmentReference> too_many_colors(m_device->props.limits.maxColorAttachments + 1, color[0]);
3759 subpass.colorAttachmentCount = (uint32_t)too_many_colors.size();
3760 subpass.pColorAttachments = too_many_colors.data();
3761 subpass.pResolveAttachments = NULL;
3762 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00348);
3763 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3764 m_errorMonitor->VerifyFound();
3765 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
3766 subpass.colorAttachmentCount = (uint32_t)color.size();
3767 subpass.pColorAttachments = color.data();
3768 subpass.pResolveAttachments = resolve.data();
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003769 }
Cort Stratton7547f772017-05-04 15:18:52 -07003770 // Test sample count mismatch between color buffers
3771 attachments[subpass.pColorAttachments[1].attachment].samples = VK_SAMPLE_COUNT_8_BIT;
3772 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00337);
3773 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
Chris Forbesc5389742016-06-29 11:49:23 +12003774 m_errorMonitor->VerifyFound();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003775 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
Cort Stratton7547f772017-05-04 15:18:52 -07003776 attachments[subpass.pColorAttachments[1].attachment].samples = attachments[subpass.pColorAttachments[0].attachment].samples;
3777 // Test sample count mismatch between color buffers and depth buffer
3778 attachments[subpass.pDepthStencilAttachment->attachment].samples = VK_SAMPLE_COUNT_8_BIT;
3779 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00337);
3780 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
Chris Forbesc5389742016-06-29 11:49:23 +12003781 m_errorMonitor->VerifyFound();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003782 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
Cort Stratton7547f772017-05-04 15:18:52 -07003783 attachments[subpass.pDepthStencilAttachment->attachment].samples = attachments[subpass.pColorAttachments[0].attachment].samples;
3784 // Test resolve attachment with UNUSED color attachment
3785 color[0].attachment = VK_ATTACHMENT_UNUSED;
3786 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00350);
3787 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
Chris Forbes3f128ef2016-06-29 14:58:53 +12003788 m_errorMonitor->VerifyFound();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003789 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
Cort Stratton7547f772017-05-04 15:18:52 -07003790 color[0].attachment = 1;
3791 // Test resolve from a single-sampled color attachment
3792 attachments[subpass.pColorAttachments[0].attachment].samples = VK_SAMPLE_COUNT_1_BIT;
3793 attachments[subpass.pColorAttachments[1].attachment].samples = VK_SAMPLE_COUNT_1_BIT; // avoid mismatch (00337)
3794 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00351);
3795 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3796 m_errorMonitor->VerifyFound();
3797 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
3798 attachments[subpass.pColorAttachments[0].attachment].samples = VK_SAMPLE_COUNT_4_BIT;
3799 attachments[subpass.pColorAttachments[1].attachment].samples = VK_SAMPLE_COUNT_4_BIT;
3800 // Test resolve to a multi-sampled resolve attachment
3801 attachments[subpass.pResolveAttachments[0].attachment].samples = VK_SAMPLE_COUNT_4_BIT;
3802 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00352);
3803 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3804 m_errorMonitor->VerifyFound();
3805 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
3806 attachments[subpass.pResolveAttachments[0].attachment].samples = VK_SAMPLE_COUNT_1_BIT;
3807 // Test with color/resolve format mismatch
3808 attachments[subpass.pColorAttachments[0].attachment].format = VK_FORMAT_R8G8B8A8_SRGB;
3809 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00353);
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 attachments[subpass.pColorAttachments[0].attachment].format = attachments[subpass.pResolveAttachments[0].attachment].format;
3814 // Test for UNUSED preserve attachments
3815 preserve[0] = VK_ATTACHMENT_UNUSED;
3816 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00356);
3817 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3818 m_errorMonitor->VerifyFound();
3819 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
3820 preserve[0] = 5;
3821 // Test for preserve attachments used elsewhere in the subpass
3822 color[0].attachment = preserve[0];
3823 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00357);
3824 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3825 m_errorMonitor->VerifyFound();
3826 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
3827 color[0].attachment = 1;
3828 // test for layout mismatch between input attachment and color attachment
3829 input[0].attachment = color[0].attachment;
3830 input[0].layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
3831 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00358);
3832 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3833 m_errorMonitor->VerifyFound();
3834 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
3835 input[0].attachment = 0;
3836 input[0].layout = VK_IMAGE_LAYOUT_GENERAL;
3837 // test for layout mismatch between input attachment and depth attachment
3838 input[0].attachment = depth.attachment;
3839 input[0].layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
3840 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00358);
3841 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3842 m_errorMonitor->VerifyFound();
3843 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
3844 input[0].attachment = 0;
3845 input[0].layout = VK_IMAGE_LAYOUT_GENERAL;
3846 // Test for attachment used first as input with loadOp=CLEAR
3847 {
3848 std::vector<VkSubpassDescription> subpasses = {subpass, subpass, subpass};
3849 subpasses[0].inputAttachmentCount = 0;
3850 subpasses[1].inputAttachmentCount = 0;
3851 attachments[input[0].attachment].loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
3852 VkRenderPassCreateInfo rpci_multipass = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO,
3853 nullptr,
3854 0,
3855 (uint32_t)attachments.size(),
3856 attachments.data(),
3857 (uint32_t)subpasses.size(),
3858 subpasses.data(),
3859 0,
3860 nullptr};
3861 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00349);
3862 err = vkCreateRenderPass(m_device->device(), &rpci_multipass, nullptr, &rp);
3863 m_errorMonitor->VerifyFound();
3864 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
3865 attachments[input[0].attachment].loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
3866 }
Chris Forbes3f128ef2016-06-29 14:58:53 +12003867}
3868
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003869TEST_F(VkLayerTest, FramebufferCreateErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003870 TEST_DESCRIPTION(
3871 "Hit errors when attempting to create a framebuffer :\n"
3872 " 1. Mismatch between framebuffer & renderPass attachmentCount\n"
3873 " 2. Use a color image as depthStencil attachment\n"
3874 " 3. Mismatch framebuffer & renderPass attachment formats\n"
3875 " 4. Mismatch framebuffer & renderPass attachment #samples\n"
3876 " 5. Framebuffer attachment w/ non-1 mip-levels\n"
3877 " 6. Framebuffer attachment where dimensions don't match\n"
Cort Stratton8133ec22017-04-27 16:25:03 +02003878 " 7. Framebuffer attachment where dimensions don't match\n"
3879 " 8. Framebuffer attachment w/o identity swizzle\n"
3880 " 9. framebuffer dimensions exceed physical device limits\n");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003881
Tony Barbour1fa09702017-03-16 12:09:08 -06003882 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003883 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3884
Cort Stratton8133ec22017-04-27 16:25:03 +02003885 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00404);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003886
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003887 // Create a renderPass with a single color attachment
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003888 VkAttachmentReference attach = {};
3889 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
3890 VkSubpassDescription subpass = {};
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003891 subpass.pColorAttachments = &attach;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003892 VkRenderPassCreateInfo rpci = {};
3893 rpci.subpassCount = 1;
3894 rpci.pSubpasses = &subpass;
3895 rpci.attachmentCount = 1;
3896 VkAttachmentDescription attach_desc = {};
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003897 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003898 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003899 rpci.pAttachments = &attach_desc;
3900 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3901 VkRenderPass rp;
3902 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3903 ASSERT_VK_SUCCESS(err);
3904
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003905 VkImageView ivs[2];
3906 ivs[0] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
3907 ivs[1] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003908 VkFramebufferCreateInfo fb_info = {};
3909 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
3910 fb_info.pNext = NULL;
3911 fb_info.renderPass = rp;
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003912 // Set mis-matching attachmentCount
3913 fb_info.attachmentCount = 2;
3914 fb_info.pAttachments = ivs;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003915 fb_info.width = 100;
3916 fb_info.height = 100;
3917 fb_info.layers = 1;
3918
3919 VkFramebuffer fb;
3920 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3921
3922 m_errorMonitor->VerifyFound();
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003923 if (err == VK_SUCCESS) {
3924 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3925 }
3926 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003927
3928 // Create a renderPass with a depth-stencil attachment created with
3929 // IMAGE_USAGE_COLOR_ATTACHMENT
3930 // Add our color attachment to pDepthStencilAttachment
3931 subpass.pDepthStencilAttachment = &attach;
3932 subpass.pColorAttachments = NULL;
3933 VkRenderPass rp_ds;
3934 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp_ds);
3935 ASSERT_VK_SUCCESS(err);
3936 // Set correct attachment count, but attachment has COLOR usage bit set
3937 fb_info.attachmentCount = 1;
3938 fb_info.renderPass = rp_ds;
3939
Cort Stratton8133ec22017-04-27 16:25:03 +02003940 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00406);
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003941 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3942
3943 m_errorMonitor->VerifyFound();
3944 if (err == VK_SUCCESS) {
3945 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3946 }
3947 vkDestroyRenderPass(m_device->device(), rp_ds, NULL);
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003948
3949 // Create new renderpass with alternate attachment format from fb
3950 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
3951 subpass.pDepthStencilAttachment = NULL;
3952 subpass.pColorAttachments = &attach;
3953 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3954 ASSERT_VK_SUCCESS(err);
3955
3956 // Cause error due to mis-matched formats between rp & fb
3957 // rp attachment 0 now has RGBA8 but corresponding fb attach is BGRA8
3958 fb_info.renderPass = rp;
Cort Stratton8133ec22017-04-27 16:25:03 +02003959 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00408);
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003960 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3961
3962 m_errorMonitor->VerifyFound();
3963 if (err == VK_SUCCESS) {
3964 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3965 }
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003966 vkDestroyRenderPass(m_device->device(), rp, NULL);
3967
3968 // Create new renderpass with alternate sample count from fb
3969 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
3970 attach_desc.samples = VK_SAMPLE_COUNT_4_BIT;
3971 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3972 ASSERT_VK_SUCCESS(err);
3973
3974 // Cause error due to mis-matched sample count between rp & fb
3975 fb_info.renderPass = rp;
Cort Stratton8133ec22017-04-27 16:25:03 +02003976 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00409);
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003977 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3978
3979 m_errorMonitor->VerifyFound();
3980 if (err == VK_SUCCESS) {
3981 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3982 }
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003983
3984 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003985
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06003986 {
3987 // Create an image with 2 mip levels.
3988 VkImageObj image(m_device);
3989 image.Init(128, 128, 2, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
3990 ASSERT_TRUE(image.initialized());
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003991
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06003992 // Create a image view with two mip levels.
3993 VkImageView view;
3994 VkImageViewCreateInfo ivci = {};
3995 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
3996 ivci.image = image.handle();
3997 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
3998 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
3999 ivci.subresourceRange.layerCount = 1;
4000 ivci.subresourceRange.baseMipLevel = 0;
4001 // Set level count to 2 (only 1 is allowed for FB attachment)
4002 ivci.subresourceRange.levelCount = 2;
4003 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4004 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
4005 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6cfda642016-06-22 16:12:58 -06004006
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06004007 // Re-create renderpass to have matching sample count
4008 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
4009 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
4010 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6cfda642016-06-22 16:12:58 -06004011
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06004012 fb_info.renderPass = rp;
4013 fb_info.pAttachments = &view;
Cort Stratton8133ec22017-04-27 16:25:03 +02004014 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00411);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06004015 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4016
4017 m_errorMonitor->VerifyFound();
4018 if (err == VK_SUCCESS) {
4019 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4020 }
4021 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis6cfda642016-06-22 16:12:58 -06004022 }
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06004023
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06004024 // Update view to original color buffer and grow FB dimensions too big
4025 fb_info.pAttachments = ivs;
4026 fb_info.height = 1024;
4027 fb_info.width = 1024;
4028 fb_info.layers = 2;
Cort Stratton8133ec22017-04-27 16:25:03 +02004029 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00410);
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06004030 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4031
4032 m_errorMonitor->VerifyFound();
4033 if (err == VK_SUCCESS) {
4034 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4035 }
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06004036
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06004037 {
4038 // Create an image with one mip level.
4039 VkImageObj image(m_device);
4040 image.Init(128, 128, 1, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
4041 ASSERT_TRUE(image.initialized());
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06004042
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06004043 // Create view attachment with non-identity swizzle
4044 VkImageView view;
4045 VkImageViewCreateInfo ivci = {};
4046 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
4047 ivci.image = image.handle();
4048 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
4049 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
4050 ivci.subresourceRange.layerCount = 1;
4051 ivci.subresourceRange.baseMipLevel = 0;
4052 ivci.subresourceRange.levelCount = 1;
4053 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4054 ivci.components.r = VK_COMPONENT_SWIZZLE_G;
4055 ivci.components.g = VK_COMPONENT_SWIZZLE_R;
4056 ivci.components.b = VK_COMPONENT_SWIZZLE_A;
4057 ivci.components.a = VK_COMPONENT_SWIZZLE_B;
4058 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
4059 ASSERT_VK_SUCCESS(err);
4060
4061 fb_info.pAttachments = &view;
4062 fb_info.height = 100;
4063 fb_info.width = 100;
4064 fb_info.layers = 1;
4065
Cort Stratton8133ec22017-04-27 16:25:03 +02004066 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00412);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06004067 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4068
4069 m_errorMonitor->VerifyFound();
4070 if (err == VK_SUCCESS) {
4071 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4072 }
4073 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06004074 }
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06004075
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004076 // reset attachment to color attachment
4077 fb_info.pAttachments = ivs;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004078
4079 // Request fb that exceeds max width
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004080 fb_info.width = m_device->props.limits.maxFramebufferWidth + 1;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004081 fb_info.height = 100;
4082 fb_info.layers = 1;
4083 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00413);
Cort Stratton8133ec22017-04-27 16:25:03 +02004084 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00410);
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004085 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
Cort Stratton8133ec22017-04-27 16:25:03 +02004086 m_errorMonitor->VerifyFound();
4087 if (err == VK_SUCCESS) {
4088 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4089 }
4090 // and width=0
4091 fb_info.width = 0;
4092 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02806);
4093 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004094 m_errorMonitor->VerifyFound();
4095 if (err == VK_SUCCESS) {
4096 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4097 }
4098
4099 // Request fb that exceeds max height
4100 fb_info.width = 100;
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004101 fb_info.height = m_device->props.limits.maxFramebufferHeight + 1;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004102 fb_info.layers = 1;
4103 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00414);
Cort Stratton8133ec22017-04-27 16:25:03 +02004104 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00410);
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004105 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
Cort Stratton8133ec22017-04-27 16:25:03 +02004106 m_errorMonitor->VerifyFound();
4107 if (err == VK_SUCCESS) {
4108 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4109 }
4110 // and height=0
4111 fb_info.height = 0;
4112 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02807);
4113 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004114 m_errorMonitor->VerifyFound();
4115 if (err == VK_SUCCESS) {
4116 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4117 }
4118
4119 // Request fb that exceeds max layers
4120 fb_info.width = 100;
4121 fb_info.height = 100;
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004122 fb_info.layers = m_device->props.limits.maxFramebufferLayers + 1;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004123 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00415);
Cort Stratton8133ec22017-04-27 16:25:03 +02004124 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00410);
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004125 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
Cort Stratton8133ec22017-04-27 16:25:03 +02004126 m_errorMonitor->VerifyFound();
4127 if (err == VK_SUCCESS) {
4128 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4129 }
4130 // and layers=0
4131 fb_info.layers = 0;
4132 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02808);
4133 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004134 m_errorMonitor->VerifyFound();
4135 if (err == VK_SUCCESS) {
4136 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4137 }
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06004138
Tobin Ehlis6cfda642016-06-22 16:12:58 -06004139 vkDestroyRenderPass(m_device->device(), rp, NULL);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004140}
4141
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004142TEST_F(VkLayerTest, DynamicDepthBiasNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004143 TEST_DESCRIPTION(
4144 "Run a simple draw calls to validate failure when Depth Bias dynamic "
4145 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004146
Tony Barbour1fa09702017-03-16 12:09:08 -06004147 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004148 // Dynamic depth bias
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004149 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic depth bias state not set for this command buffer");
4150 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBias);
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004151 m_errorMonitor->VerifyFound();
4152}
4153
4154TEST_F(VkLayerTest, DynamicLineWidthNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004155 TEST_DESCRIPTION(
4156 "Run a simple draw calls to validate failure when Line Width dynamic "
4157 "state is required but not correctly bound.");
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004158
Tony Barbour1fa09702017-03-16 12:09:08 -06004159 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004160 // Dynamic line width
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004161 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic line width state not set for this command buffer");
4162 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailLineWidth);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004163 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004164}
4165
4166TEST_F(VkLayerTest, DynamicViewportNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004167 TEST_DESCRIPTION(
4168 "Run a simple draw calls to validate failure when Viewport dynamic "
4169 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004170
Tony Barbour1fa09702017-03-16 12:09:08 -06004171 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004172 // Dynamic viewport state
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07004173 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4174 "Dynamic viewport(s) 0 are used by pipeline state object, but were not provided");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004175 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailViewport);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004176 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004177}
4178
4179TEST_F(VkLayerTest, DynamicScissorNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004180 TEST_DESCRIPTION(
4181 "Run a simple draw calls to validate failure when Scissor dynamic "
4182 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004183
Tony Barbour1fa09702017-03-16 12:09:08 -06004184 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004185 // Dynamic scissor state
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07004186 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4187 "Dynamic scissor(s) 0 are used by pipeline state object, but were not provided");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004188 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailScissor);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004189 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004190}
4191
Cortd713fe82016-07-27 09:51:27 -07004192TEST_F(VkLayerTest, DynamicBlendConstantsNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004193 TEST_DESCRIPTION(
4194 "Run a simple draw calls to validate failure when Blend Constants "
4195 "dynamic state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004196
Tony Barbour1fa09702017-03-16 12:09:08 -06004197 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis21c88352016-05-26 06:15:45 -06004198 // Dynamic blend constant state
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004199 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4200 "Dynamic blend constants state not set for this command buffer");
4201 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailBlend);
Tobin Ehlis21c88352016-05-26 06:15:45 -06004202 m_errorMonitor->VerifyFound();
4203}
4204
4205TEST_F(VkLayerTest, DynamicDepthBoundsNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004206 TEST_DESCRIPTION(
4207 "Run a simple draw calls to validate failure when Depth Bounds dynamic "
4208 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004209
Tony Barbour1fa09702017-03-16 12:09:08 -06004210 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis21c88352016-05-26 06:15:45 -06004211 if (!m_device->phy().features().depthBounds) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07004212 printf(" Device does not support depthBounds test; skipped.\n");
Tobin Ehlis21c88352016-05-26 06:15:45 -06004213 return;
4214 }
4215 // Dynamic depth bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004216 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4217 "Dynamic depth bounds state not set for this command buffer");
4218 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBounds);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004219 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004220}
4221
4222TEST_F(VkLayerTest, DynamicStencilReadNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004223 TEST_DESCRIPTION(
4224 "Run a simple draw calls to validate failure when Stencil Read dynamic "
4225 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004226
Tony Barbour1fa09702017-03-16 12:09:08 -06004227 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004228 // Dynamic stencil read mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004229 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4230 "Dynamic stencil read mask state not set for this command buffer");
4231 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReadMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004232 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004233}
4234
4235TEST_F(VkLayerTest, DynamicStencilWriteNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004236 TEST_DESCRIPTION(
4237 "Run a simple draw calls to validate failure when Stencil Write dynamic"
4238 " state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004239
Tony Barbour1fa09702017-03-16 12:09:08 -06004240 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004241 // Dynamic stencil write mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004242 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4243 "Dynamic stencil write mask state not set for this command buffer");
4244 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilWriteMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004245 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004246}
4247
4248TEST_F(VkLayerTest, DynamicStencilRefNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004249 TEST_DESCRIPTION(
4250 "Run a simple draw calls to validate failure when Stencil Ref dynamic "
4251 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004252
Tony Barbour1fa09702017-03-16 12:09:08 -06004253 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004254 // Dynamic stencil reference
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004255 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4256 "Dynamic stencil reference state not set for this command buffer");
4257 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReference);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004258 m_errorMonitor->VerifyFound();
Tobin Ehlis963a4042015-09-29 08:18:34 -06004259}
4260
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06004261TEST_F(VkLayerTest, IndexBufferNotBound) {
4262 TEST_DESCRIPTION("Run an indexed draw call without an index buffer bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004263
Tony Barbour1fa09702017-03-16 12:09:08 -06004264 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004265 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4266 "Index buffer object not bound to this command buffer when Indexed ");
4267 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailIndexBuffer);
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06004268 m_errorMonitor->VerifyFound();
4269}
4270
Karl Schultz6addd812016-02-02 17:17:23 -07004271TEST_F(VkLayerTest, CommandBufferTwoSubmits) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004272 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4273 "was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has "
4274 "been submitted");
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004275
Tony Barbour1fa09702017-03-16 12:09:08 -06004276 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004277 ASSERT_NO_FATAL_FAILURE(InitViewport());
4278 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4279
Karl Schultz6addd812016-02-02 17:17:23 -07004280 // We luck out b/c by default the framework creates CB w/ the
4281 // VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set
Tony Barbour552f6c02016-12-21 14:34:07 -07004282 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004283 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbour552f6c02016-12-21 14:34:07 -07004284 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004285
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004286 // Bypass framework since it does the waits automatically
4287 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06004288 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08004289 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4290 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004291 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06004292 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07004293 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004294 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004295 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08004296 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06004297 submit_info.pSignalSemaphores = NULL;
4298
Chris Forbes40028e22016-06-13 09:59:34 +12004299 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Karl Schultz6addd812016-02-02 17:17:23 -07004300 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski89cad1a2016-11-11 15:51:31 -07004301 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004302
Karl Schultz6addd812016-02-02 17:17:23 -07004303 // Cause validation error by re-submitting cmd buffer that should only be
4304 // submitted once
Chris Forbes40028e22016-06-13 09:59:34 +12004305 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski89cad1a2016-11-11 15:51:31 -07004306 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004307
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004308 m_errorMonitor->VerifyFound();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004309}
4310
Karl Schultz6addd812016-02-02 17:17:23 -07004311TEST_F(VkLayerTest, AllocDescriptorFromEmptyPool) {
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004312 TEST_DESCRIPTION("Attempt to allocate more sets and descriptors than descriptor pool has available.");
Karl Schultz6addd812016-02-02 17:17:23 -07004313 VkResult err;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004314
Tony Barbour1fa09702017-03-16 12:09:08 -06004315 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004316 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004317
Karl Schultz6addd812016-02-02 17:17:23 -07004318 // Create Pool w/ 1 Sampler descriptor, but try to alloc Uniform Buffer
4319 // descriptor from it
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004320 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004321 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004322 ds_type_count.descriptorCount = 2;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004323
4324 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004325 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4326 ds_pool_ci.pNext = NULL;
4327 ds_pool_ci.flags = 0;
4328 ds_pool_ci.maxSets = 1;
4329 ds_pool_ci.poolSizeCount = 1;
4330 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004331
4332 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004333 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004334 ASSERT_VK_SUCCESS(err);
4335
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004336 VkDescriptorSetLayoutBinding dsl_binding_samp = {};
4337 dsl_binding_samp.binding = 0;
4338 dsl_binding_samp.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
4339 dsl_binding_samp.descriptorCount = 1;
4340 dsl_binding_samp.stageFlags = VK_SHADER_STAGE_ALL;
4341 dsl_binding_samp.pImmutableSamplers = NULL;
4342
4343 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4344 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4345 ds_layout_ci.pNext = NULL;
4346 ds_layout_ci.bindingCount = 1;
4347 ds_layout_ci.pBindings = &dsl_binding_samp;
4348
4349 VkDescriptorSetLayout ds_layout_samp;
4350 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_samp);
4351 ASSERT_VK_SUCCESS(err);
4352
4353 // Try to allocate 2 sets when pool only has 1 set
4354 VkDescriptorSet descriptor_sets[2];
4355 VkDescriptorSetLayout set_layouts[2] = {ds_layout_samp, ds_layout_samp};
4356 VkDescriptorSetAllocateInfo alloc_info = {};
4357 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4358 alloc_info.descriptorSetCount = 2;
4359 alloc_info.descriptorPool = ds_pool;
4360 alloc_info.pSetLayouts = set_layouts;
4361 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00911);
4362 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
4363 m_errorMonitor->VerifyFound();
4364
4365 alloc_info.descriptorSetCount = 1;
4366 // Create layout w/ descriptor type not available in pool
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004367 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004368 dsl_binding.binding = 0;
4369 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4370 dsl_binding.descriptorCount = 1;
4371 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4372 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004373
Karl Schultz6addd812016-02-02 17:17:23 -07004374 ds_layout_ci.bindingCount = 1;
4375 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004376
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004377 VkDescriptorSetLayout ds_layout_ub;
4378 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_ub);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004379 ASSERT_VK_SUCCESS(err);
4380
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004381 VkDescriptorSet descriptor_set;
Jon Ashburnf19916e2016-01-11 13:12:43 -07004382 alloc_info.descriptorSetCount = 1;
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004383 alloc_info.pSetLayouts = &ds_layout_ub;
4384 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00912);
4385 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004386
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004387 m_errorMonitor->VerifyFound();
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004388
Karl Schultz2825ab92016-12-02 08:23:14 -07004389 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_samp, NULL);
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004390 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_ub, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +08004391 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004392}
4393
Karl Schultz6addd812016-02-02 17:17:23 -07004394TEST_F(VkLayerTest, FreeDescriptorFromOneShotPool) {
4395 VkResult err;
Tobin Ehlise735c692015-10-08 13:13:50 -06004396
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07004397 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00922);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004398
Tony Barbour1fa09702017-03-16 12:09:08 -06004399 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlise735c692015-10-08 13:13:50 -06004400 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise735c692015-10-08 13:13:50 -06004401
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004402 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004403 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4404 ds_type_count.descriptorCount = 1;
Tobin Ehlise735c692015-10-08 13:13:50 -06004405
4406 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004407 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4408 ds_pool_ci.pNext = NULL;
4409 ds_pool_ci.maxSets = 1;
4410 ds_pool_ci.poolSizeCount = 1;
4411 ds_pool_ci.flags = 0;
4412 // Not specifying VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT means
4413 // app can only call vkResetDescriptorPool on this pool.;
4414 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise735c692015-10-08 13:13:50 -06004415
4416 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004417 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise735c692015-10-08 13:13:50 -06004418 ASSERT_VK_SUCCESS(err);
4419
4420 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004421 dsl_binding.binding = 0;
4422 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4423 dsl_binding.descriptorCount = 1;
4424 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4425 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise735c692015-10-08 13:13:50 -06004426
4427 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004428 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4429 ds_layout_ci.pNext = NULL;
4430 ds_layout_ci.bindingCount = 1;
4431 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise735c692015-10-08 13:13:50 -06004432
4433 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004434 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise735c692015-10-08 13:13:50 -06004435 ASSERT_VK_SUCCESS(err);
4436
4437 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004438 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08004439 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07004440 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06004441 alloc_info.descriptorPool = ds_pool;
4442 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004443 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise735c692015-10-08 13:13:50 -06004444 ASSERT_VK_SUCCESS(err);
4445
4446 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004447 m_errorMonitor->VerifyFound();
Tobin Ehlise735c692015-10-08 13:13:50 -06004448
Chia-I Wuf7458c52015-10-26 21:10:41 +08004449 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4450 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise735c692015-10-08 13:13:50 -06004451}
4452
Karl Schultz6addd812016-02-02 17:17:23 -07004453TEST_F(VkLayerTest, InvalidDescriptorPool) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004454 // Attempt to clear Descriptor Pool with bad object.
4455 // ObjectTracker should catch this.
Cody Northropc31a84f2016-08-22 10:41:47 -06004456
Tony Barbour1fa09702017-03-16 12:09:08 -06004457 ASSERT_NO_FATAL_FAILURE(Init());
Karl Schultzf78bcdd2016-11-30 12:36:01 -07004458 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00930);
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004459 uint64_t fake_pool_handle = 0xbaad6001;
4460 VkDescriptorPool bad_pool = reinterpret_cast<VkDescriptorPool &>(fake_pool_handle);
4461 vkResetDescriptorPool(device(), bad_pool, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -06004462 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004463}
4464
Karl Schultzf78bcdd2016-11-30 12:36:01 -07004465TEST_F(VkLayerTest, InvalidDescriptorSet) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004466 // Attempt to bind an invalid Descriptor Set to a valid Command Buffer
4467 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004468 // Create a valid cmd buffer
Karl Schultzbdb75952016-04-19 11:36:49 -06004469 // call vkCmdBindDescriptorSets w/ false Descriptor Set
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004470
4471 uint64_t fake_set_handle = 0xbaad6001;
4472 VkDescriptorSet bad_set = reinterpret_cast<VkDescriptorSet &>(fake_set_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06004473 VkResult err;
Karl Schultzf78bcdd2016-11-30 12:36:01 -07004474 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00982);
Karl Schultzbdb75952016-04-19 11:36:49 -06004475
Tony Barbour1fa09702017-03-16 12:09:08 -06004476 ASSERT_NO_FATAL_FAILURE(Init());
Karl Schultzbdb75952016-04-19 11:36:49 -06004477
4478 VkDescriptorSetLayoutBinding layout_bindings[1] = {};
4479 layout_bindings[0].binding = 0;
4480 layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4481 layout_bindings[0].descriptorCount = 1;
4482 layout_bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
4483 layout_bindings[0].pImmutableSamplers = NULL;
4484
4485 VkDescriptorSetLayout descriptor_set_layout;
4486 VkDescriptorSetLayoutCreateInfo dslci = {};
4487 dslci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4488 dslci.pNext = NULL;
4489 dslci.bindingCount = 1;
4490 dslci.pBindings = layout_bindings;
4491 err = vkCreateDescriptorSetLayout(device(), &dslci, NULL, &descriptor_set_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06004492 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06004493
4494 VkPipelineLayout pipeline_layout;
4495 VkPipelineLayoutCreateInfo plci = {};
4496 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4497 plci.pNext = NULL;
4498 plci.setLayoutCount = 1;
4499 plci.pSetLayouts = &descriptor_set_layout;
4500 err = vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06004501 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06004502
Tony Barbour552f6c02016-12-21 14:34:07 -07004503 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004504 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &bad_set, 0,
4505 NULL);
Karl Schultzbdb75952016-04-19 11:36:49 -06004506 m_errorMonitor->VerifyFound();
Tony Barbour552f6c02016-12-21 14:34:07 -07004507 m_commandBuffer->EndCommandBuffer();
Karl Schultzbdb75952016-04-19 11:36:49 -06004508 vkDestroyPipelineLayout(device(), pipeline_layout, NULL);
4509 vkDestroyDescriptorSetLayout(device(), descriptor_set_layout, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004510}
4511
Karl Schultz6addd812016-02-02 17:17:23 -07004512TEST_F(VkLayerTest, InvalidDescriptorSetLayout) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004513 // Attempt to create a Pipeline Layout with an invalid Descriptor Set Layout.
4514 // ObjectTracker should catch this.
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004515 uint64_t fake_layout_handle = 0xbaad6001;
4516 VkDescriptorSetLayout bad_layout = reinterpret_cast<VkDescriptorSetLayout &>(fake_layout_handle);
Karl Schultzf78bcdd2016-11-30 12:36:01 -07004517 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00875);
Tony Barbour1fa09702017-03-16 12:09:08 -06004518 ASSERT_NO_FATAL_FAILURE(Init());
Karl Schultzbdb75952016-04-19 11:36:49 -06004519 VkPipelineLayout pipeline_layout;
4520 VkPipelineLayoutCreateInfo plci = {};
4521 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4522 plci.pNext = NULL;
4523 plci.setLayoutCount = 1;
4524 plci.pSetLayouts = &bad_layout;
4525 vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
4526
4527 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004528}
4529
Mark Muellerd4914412016-06-13 17:52:06 -06004530TEST_F(VkLayerTest, WriteDescriptorSetIntegrityCheck) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004531 TEST_DESCRIPTION(
4532 "This test verifies some requirements of chapter 13.2.3 of the Vulkan Spec "
4533 "1) A uniform buffer update must have a valid buffer index."
4534 "2) When using an array of descriptors in a single WriteDescriptor,"
4535 " the descriptor types and stageflags must all be the same."
4536 "3) Immutable Sampler state must match across descriptors");
Mark Muellerd4914412016-06-13 17:52:06 -06004537
Mike Weiblena6666382017-01-05 15:16:11 -07004538 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00941);
Mark Muellerd4914412016-06-13 17:52:06 -06004539
Tony Barbour1fa09702017-03-16 12:09:08 -06004540 ASSERT_NO_FATAL_FAILURE(Init());
Mark Muellerd4914412016-06-13 17:52:06 -06004541 VkDescriptorPoolSize ds_type_count[4] = {};
4542 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4543 ds_type_count[0].descriptorCount = 1;
Tony Barboure132c5f2016-12-12 11:50:20 -07004544 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Muellerd4914412016-06-13 17:52:06 -06004545 ds_type_count[1].descriptorCount = 1;
Tony Barboure132c5f2016-12-12 11:50:20 -07004546 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Muellerd4914412016-06-13 17:52:06 -06004547 ds_type_count[2].descriptorCount = 1;
4548 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
4549 ds_type_count[3].descriptorCount = 1;
4550
4551 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4552 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4553 ds_pool_ci.maxSets = 1;
4554 ds_pool_ci.poolSizeCount = sizeof(ds_type_count) / sizeof(VkDescriptorPoolSize);
4555 ds_pool_ci.pPoolSizes = ds_type_count;
4556
4557 VkDescriptorPool ds_pool;
4558 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
4559 ASSERT_VK_SUCCESS(err);
4560
Mark Muellerb9896722016-06-16 09:54:29 -06004561 VkDescriptorSetLayoutBinding layout_binding[3] = {};
Mark Muellerd4914412016-06-13 17:52:06 -06004562 layout_binding[0].binding = 0;
4563 layout_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4564 layout_binding[0].descriptorCount = 1;
4565 layout_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
4566 layout_binding[0].pImmutableSamplers = NULL;
4567
4568 layout_binding[1].binding = 1;
4569 layout_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
4570 layout_binding[1].descriptorCount = 1;
4571 layout_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4572 layout_binding[1].pImmutableSamplers = NULL;
4573
4574 VkSamplerCreateInfo sampler_ci = {};
4575 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
4576 sampler_ci.pNext = NULL;
4577 sampler_ci.magFilter = VK_FILTER_NEAREST;
4578 sampler_ci.minFilter = VK_FILTER_NEAREST;
4579 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
4580 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4581 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4582 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4583 sampler_ci.mipLodBias = 1.0;
4584 sampler_ci.anisotropyEnable = VK_FALSE;
4585 sampler_ci.maxAnisotropy = 1;
4586 sampler_ci.compareEnable = VK_FALSE;
4587 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
4588 sampler_ci.minLod = 1.0;
4589 sampler_ci.maxLod = 1.0;
4590 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
4591 sampler_ci.unnormalizedCoordinates = VK_FALSE;
4592 VkSampler sampler;
4593
4594 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
4595 ASSERT_VK_SUCCESS(err);
4596
4597 layout_binding[2].binding = 2;
4598 layout_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
4599 layout_binding[2].descriptorCount = 1;
4600 layout_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4601 layout_binding[2].pImmutableSamplers = static_cast<VkSampler *>(&sampler);
4602
Mark Muellerd4914412016-06-13 17:52:06 -06004603 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4604 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4605 ds_layout_ci.bindingCount = sizeof(layout_binding) / sizeof(VkDescriptorSetLayoutBinding);
4606 ds_layout_ci.pBindings = layout_binding;
4607 VkDescriptorSetLayout ds_layout;
4608 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
4609 ASSERT_VK_SUCCESS(err);
4610
4611 VkDescriptorSetAllocateInfo alloc_info = {};
4612 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4613 alloc_info.descriptorSetCount = 1;
4614 alloc_info.descriptorPool = ds_pool;
4615 alloc_info.pSetLayouts = &ds_layout;
4616 VkDescriptorSet descriptorSet;
4617 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
4618 ASSERT_VK_SUCCESS(err);
4619
4620 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4621 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4622 pipeline_layout_ci.pNext = NULL;
4623 pipeline_layout_ci.setLayoutCount = 1;
4624 pipeline_layout_ci.pSetLayouts = &ds_layout;
4625
4626 VkPipelineLayout pipeline_layout;
4627 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4628 ASSERT_VK_SUCCESS(err);
4629
Mark Mueller5c838ce2016-06-16 09:54:29 -06004630 VkWriteDescriptorSet descriptor_write = {};
Mark Muellerd4914412016-06-13 17:52:06 -06004631 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4632 descriptor_write.dstSet = descriptorSet;
4633 descriptor_write.dstBinding = 0;
4634 descriptor_write.descriptorCount = 1;
4635 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4636
Mark Mueller5c838ce2016-06-16 09:54:29 -06004637 // 1) The uniform buffer is intentionally invalid here
Mark Muellerd4914412016-06-13 17:52:06 -06004638 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4639 m_errorMonitor->VerifyFound();
4640
4641 // Create a buffer to update the descriptor with
4642 uint32_t qfi = 0;
4643 VkBufferCreateInfo buffCI = {};
4644 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4645 buffCI.size = 1024;
4646 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
4647 buffCI.queueFamilyIndexCount = 1;
4648 buffCI.pQueueFamilyIndices = &qfi;
4649
4650 VkBuffer dyub;
4651 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
4652 ASSERT_VK_SUCCESS(err);
Mark Muellerd4914412016-06-13 17:52:06 -06004653
Tony Barboure132c5f2016-12-12 11:50:20 -07004654 VkDeviceMemory mem;
4655 VkMemoryRequirements mem_reqs;
4656 vkGetBufferMemoryRequirements(m_device->device(), dyub, &mem_reqs);
4657
4658 VkMemoryAllocateInfo mem_alloc_info = {};
4659 mem_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4660 mem_alloc_info.allocationSize = mem_reqs.size;
4661 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
4662 err = vkAllocateMemory(m_device->device(), &mem_alloc_info, NULL, &mem);
4663 ASSERT_VK_SUCCESS(err);
4664
4665 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
4666 ASSERT_VK_SUCCESS(err);
4667
4668 VkDescriptorBufferInfo buffInfo[2] = {};
4669 buffInfo[0].buffer = dyub;
4670 buffInfo[0].offset = 0;
4671 buffInfo[0].range = 1024;
4672 buffInfo[1].buffer = dyub;
4673 buffInfo[1].offset = 0;
4674 buffInfo[1].range = 1024;
4675 descriptor_write.pBufferInfo = buffInfo;
Mark Muellerd4914412016-06-13 17:52:06 -06004676 descriptor_write.descriptorCount = 2;
4677
Mark Mueller5c838ce2016-06-16 09:54:29 -06004678 // 2) The stateFlags don't match between the first and second descriptor
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07004679 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00938);
Mark Muellerd4914412016-06-13 17:52:06 -06004680 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4681 m_errorMonitor->VerifyFound();
4682
Mark Mueller5c838ce2016-06-16 09:54:29 -06004683 // 3) The second descriptor has a null_ptr pImmutableSamplers and
4684 // the third descriptor contains an immutable sampler
Mark Muellerd4914412016-06-13 17:52:06 -06004685 descriptor_write.dstBinding = 1;
4686 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Mueller5c838ce2016-06-16 09:54:29 -06004687
Mark Mueller5c838ce2016-06-16 09:54:29 -06004688 // Make pImageInfo index non-null to avoid complaints of it missing
4689 VkDescriptorImageInfo imageInfo = {};
4690 imageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
4691 descriptor_write.pImageInfo = &imageInfo;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07004692 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00938);
Mark Muellerd4914412016-06-13 17:52:06 -06004693 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4694 m_errorMonitor->VerifyFound();
4695
Mark Muellerd4914412016-06-13 17:52:06 -06004696 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tony Barboure132c5f2016-12-12 11:50:20 -07004697 vkFreeMemory(m_device->device(), mem, NULL);
Mark Muellerd4914412016-06-13 17:52:06 -06004698 vkDestroySampler(m_device->device(), sampler, NULL);
4699 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4700 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4701 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4702}
4703
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004704TEST_F(VkLayerTest, InvalidCmdBufferBufferDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004705 TEST_DESCRIPTION(
4706 "Attempt to draw with a command buffer that is invalid "
4707 "due to a buffer dependency being destroyed.");
Tony Barbour1fa09702017-03-16 12:09:08 -06004708 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004709
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004710 VkBuffer buffer;
4711 VkDeviceMemory mem;
4712 VkMemoryRequirements mem_reqs;
4713
4714 VkBufferCreateInfo buf_info = {};
4715 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes3d5882f2016-09-16 17:37:17 +12004716 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004717 buf_info.size = 256;
4718 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
4719 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
4720 ASSERT_VK_SUCCESS(err);
4721
4722 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
4723
4724 VkMemoryAllocateInfo alloc_info = {};
4725 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4726 alloc_info.allocationSize = 256;
4727 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004728 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 -06004729 if (!pass) {
4730 vkDestroyBuffer(m_device->device(), buffer, NULL);
4731 return;
4732 }
4733 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
4734 ASSERT_VK_SUCCESS(err);
4735
4736 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
4737 ASSERT_VK_SUCCESS(err);
4738
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004739 m_commandBuffer->BeginCommandBuffer();
Chris Forbes3d5882f2016-09-16 17:37:17 +12004740 vkCmdFillBuffer(m_commandBuffer->GetBufferHandle(), buffer, 0, VK_WHOLE_SIZE, 0);
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004741 m_commandBuffer->EndCommandBuffer();
4742
Mark Lobodzinski33826372017-04-13 11:10:11 -06004743 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound Buffer ");
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004744 // Destroy buffer dependency prior to submit to cause ERROR
4745 vkDestroyBuffer(m_device->device(), buffer, NULL);
4746
4747 VkSubmitInfo submit_info = {};
4748 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4749 submit_info.commandBufferCount = 1;
4750 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4751 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4752
4753 m_errorMonitor->VerifyFound();
Rene Lindsayab6c5cd2016-12-20 14:05:37 -07004754 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004755 vkFreeMemory(m_device->handle(), mem, NULL);
4756}
4757
Tobin Ehlisea413442016-09-28 10:23:59 -06004758TEST_F(VkLayerTest, InvalidCmdBufferBufferViewDestroyed) {
4759 TEST_DESCRIPTION("Delete bufferView bound to cmd buffer, then attempt to submit cmd buffer.");
4760
Tony Barbour1fa09702017-03-16 12:09:08 -06004761 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisea413442016-09-28 10:23:59 -06004762 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4763
4764 VkDescriptorPoolSize ds_type_count;
4765 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4766 ds_type_count.descriptorCount = 1;
4767
4768 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4769 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4770 ds_pool_ci.maxSets = 1;
4771 ds_pool_ci.poolSizeCount = 1;
4772 ds_pool_ci.pPoolSizes = &ds_type_count;
4773
4774 VkDescriptorPool ds_pool;
4775 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
4776 ASSERT_VK_SUCCESS(err);
4777
4778 VkDescriptorSetLayoutBinding layout_binding;
4779 layout_binding.binding = 0;
4780 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4781 layout_binding.descriptorCount = 1;
4782 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4783 layout_binding.pImmutableSamplers = NULL;
4784
4785 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4786 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4787 ds_layout_ci.bindingCount = 1;
4788 ds_layout_ci.pBindings = &layout_binding;
4789 VkDescriptorSetLayout ds_layout;
4790 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
4791 ASSERT_VK_SUCCESS(err);
4792
4793 VkDescriptorSetAllocateInfo alloc_info = {};
4794 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4795 alloc_info.descriptorSetCount = 1;
4796 alloc_info.descriptorPool = ds_pool;
4797 alloc_info.pSetLayouts = &ds_layout;
4798 VkDescriptorSet descriptor_set;
4799 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
4800 ASSERT_VK_SUCCESS(err);
4801
4802 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4803 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4804 pipeline_layout_ci.pNext = NULL;
4805 pipeline_layout_ci.setLayoutCount = 1;
4806 pipeline_layout_ci.pSetLayouts = &ds_layout;
4807
4808 VkPipelineLayout pipeline_layout;
4809 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4810 ASSERT_VK_SUCCESS(err);
4811
4812 VkBuffer buffer;
4813 uint32_t queue_family_index = 0;
4814 VkBufferCreateInfo buffer_create_info = {};
4815 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4816 buffer_create_info.size = 1024;
4817 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
4818 buffer_create_info.queueFamilyIndexCount = 1;
4819 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
4820
4821 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
4822 ASSERT_VK_SUCCESS(err);
4823
4824 VkMemoryRequirements memory_reqs;
4825 VkDeviceMemory buffer_memory;
4826
4827 VkMemoryAllocateInfo memory_info = {};
4828 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4829 memory_info.allocationSize = 0;
4830 memory_info.memoryTypeIndex = 0;
4831
4832 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
4833 memory_info.allocationSize = memory_reqs.size;
4834 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
4835 ASSERT_TRUE(pass);
4836
4837 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
4838 ASSERT_VK_SUCCESS(err);
4839 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
4840 ASSERT_VK_SUCCESS(err);
4841
4842 VkBufferView view;
4843 VkBufferViewCreateInfo bvci = {};
4844 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
4845 bvci.buffer = buffer;
4846 bvci.format = VK_FORMAT_R8_UNORM;
4847 bvci.range = VK_WHOLE_SIZE;
4848
4849 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
4850 ASSERT_VK_SUCCESS(err);
4851
4852 VkWriteDescriptorSet descriptor_write = {};
4853 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4854 descriptor_write.dstSet = descriptor_set;
4855 descriptor_write.dstBinding = 0;
4856 descriptor_write.descriptorCount = 1;
4857 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4858 descriptor_write.pTexelBufferView = &view;
4859
4860 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4861
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004862 char const *vsSource =
4863 "#version 450\n"
4864 "\n"
4865 "out gl_PerVertex { \n"
4866 " vec4 gl_Position;\n"
4867 "};\n"
4868 "void main(){\n"
4869 " gl_Position = vec4(1);\n"
4870 "}\n";
4871 char const *fsSource =
4872 "#version 450\n"
4873 "\n"
4874 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
4875 "layout(location=0) out vec4 x;\n"
4876 "void main(){\n"
4877 " x = imageLoad(s, 0);\n"
4878 "}\n";
Tobin Ehlisea413442016-09-28 10:23:59 -06004879 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4880 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
4881 VkPipelineObj pipe(m_device);
4882 pipe.AddShader(&vs);
4883 pipe.AddShader(&fs);
4884 pipe.AddColorAttachment();
4885 pipe.CreateVKPipeline(pipeline_layout, renderPass());
4886
Mark Lobodzinski33826372017-04-13 11:10:11 -06004887 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound BufferView ");
Tobin Ehlisea413442016-09-28 10:23:59 -06004888
Tony Barbour552f6c02016-12-21 14:34:07 -07004889 m_commandBuffer->BeginCommandBuffer();
4890 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
4891
Tobin Ehlisea413442016-09-28 10:23:59 -06004892 VkViewport viewport = {0, 0, 16, 16, 0, 1};
4893 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
4894 VkRect2D scissor = {{0, 0}, {16, 16}};
4895 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
4896 // Bind pipeline to cmd buffer
4897 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
4898 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
4899 &descriptor_set, 0, nullptr);
4900 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07004901 m_commandBuffer->EndRenderPass();
4902 m_commandBuffer->EndCommandBuffer();
Tobin Ehlisea413442016-09-28 10:23:59 -06004903
4904 // Delete BufferView in order to invalidate cmd buffer
4905 vkDestroyBufferView(m_device->device(), view, NULL);
4906 // Now attempt submit of cmd buffer
4907 VkSubmitInfo submit_info = {};
4908 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4909 submit_info.commandBufferCount = 1;
4910 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4911 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4912 m_errorMonitor->VerifyFound();
4913
4914 // Clean-up
4915 vkDestroyBuffer(m_device->device(), buffer, NULL);
4916 vkFreeMemory(m_device->device(), buffer_memory, NULL);
4917 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4918 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4919 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4920}
4921
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004922TEST_F(VkLayerTest, InvalidCmdBufferImageDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004923 TEST_DESCRIPTION(
4924 "Attempt to draw with a command buffer that is invalid "
4925 "due to an image dependency being destroyed.");
Tony Barbour1fa09702017-03-16 12:09:08 -06004926 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004927
4928 VkImage image;
4929 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4930 VkImageCreateInfo image_create_info = {};
4931 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4932 image_create_info.pNext = NULL;
4933 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4934 image_create_info.format = tex_format;
4935 image_create_info.extent.width = 32;
4936 image_create_info.extent.height = 32;
4937 image_create_info.extent.depth = 1;
4938 image_create_info.mipLevels = 1;
4939 image_create_info.arrayLayers = 1;
4940 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
4941 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004942 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004943 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004944 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004945 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004946 // Have to bind memory to image before recording cmd in cmd buffer using it
4947 VkMemoryRequirements mem_reqs;
4948 VkDeviceMemory image_mem;
4949 bool pass;
4950 VkMemoryAllocateInfo mem_alloc = {};
4951 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4952 mem_alloc.pNext = NULL;
4953 mem_alloc.memoryTypeIndex = 0;
4954 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
4955 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004956 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004957 ASSERT_TRUE(pass);
4958 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
4959 ASSERT_VK_SUCCESS(err);
4960 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
4961 ASSERT_VK_SUCCESS(err);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004962
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004963 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis764d7072016-07-01 12:54:29 -06004964 VkClearColorValue ccv;
4965 ccv.float32[0] = 1.0f;
4966 ccv.float32[1] = 1.0f;
4967 ccv.float32[2] = 1.0f;
4968 ccv.float32[3] = 1.0f;
4969 VkImageSubresourceRange isr = {};
4970 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004971 isr.baseArrayLayer = 0;
4972 isr.baseMipLevel = 0;
Tobin Ehlis764d7072016-07-01 12:54:29 -06004973 isr.layerCount = 1;
4974 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004975 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004976 m_commandBuffer->EndCommandBuffer();
4977
Mark Lobodzinski33826372017-04-13 11:10:11 -06004978 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound Image ");
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004979 // Destroy image dependency prior to submit to cause ERROR
4980 vkDestroyImage(m_device->device(), image, NULL);
4981
4982 VkSubmitInfo submit_info = {};
4983 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4984 submit_info.commandBufferCount = 1;
4985 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4986 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4987
4988 m_errorMonitor->VerifyFound();
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004989 vkFreeMemory(m_device->device(), image_mem, nullptr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004990}
4991
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004992TEST_F(VkLayerTest, InvalidCmdBufferFramebufferImageDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004993 TEST_DESCRIPTION(
4994 "Attempt to draw with a command buffer that is invalid "
4995 "due to a framebuffer image dependency being destroyed.");
Tony Barbour1fa09702017-03-16 12:09:08 -06004996 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004997 VkFormatProperties format_properties;
4998 VkResult err = VK_SUCCESS;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004999 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
5000 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005001 return;
5002 }
5003
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005004 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5005
5006 VkImageCreateInfo image_ci = {};
5007 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5008 image_ci.pNext = NULL;
5009 image_ci.imageType = VK_IMAGE_TYPE_2D;
5010 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
5011 image_ci.extent.width = 32;
5012 image_ci.extent.height = 32;
5013 image_ci.extent.depth = 1;
5014 image_ci.mipLevels = 1;
5015 image_ci.arrayLayers = 1;
5016 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
5017 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005018 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT;
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005019 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
5020 image_ci.flags = 0;
5021 VkImage image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005022 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005023
5024 VkMemoryRequirements memory_reqs;
5025 VkDeviceMemory image_memory;
5026 bool pass;
5027 VkMemoryAllocateInfo memory_info = {};
5028 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5029 memory_info.pNext = NULL;
5030 memory_info.allocationSize = 0;
5031 memory_info.memoryTypeIndex = 0;
5032 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5033 memory_info.allocationSize = memory_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005034 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005035 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005036 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005037 ASSERT_VK_SUCCESS(err);
5038 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5039 ASSERT_VK_SUCCESS(err);
5040
5041 VkImageViewCreateInfo ivci = {
5042 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
5043 nullptr,
5044 0,
5045 image,
5046 VK_IMAGE_VIEW_TYPE_2D,
5047 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005048 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005049 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
5050 };
5051 VkImageView view;
5052 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
5053 ASSERT_VK_SUCCESS(err);
5054
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005055 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 32, 32, 1};
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005056 VkFramebuffer fb;
5057 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
5058 ASSERT_VK_SUCCESS(err);
5059
5060 // Just use default renderpass with our framebuffer
5061 m_renderPassBeginInfo.framebuffer = fb;
Jeremy Hayesba817e12017-03-03 15:51:11 -07005062 m_renderPassBeginInfo.renderArea.extent.width = 32;
5063 m_renderPassBeginInfo.renderArea.extent.height = 32;
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005064 // Create Null cmd buffer for submit
Tony Barbour552f6c02016-12-21 14:34:07 -07005065 m_commandBuffer->BeginCommandBuffer();
5066 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
5067 m_commandBuffer->EndRenderPass();
5068 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005069 // Destroy image attached to framebuffer to invalidate cmd buffer
5070 vkDestroyImage(m_device->device(), image, NULL);
5071 // Now attempt to submit cmd buffer and verify error
Mark Lobodzinski33826372017-04-13 11:10:11 -06005072 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound Image ");
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005073 QueueCommandBuffer(false);
5074 m_errorMonitor->VerifyFound();
5075
5076 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
5077 vkDestroyImageView(m_device->device(), view, nullptr);
5078 vkFreeMemory(m_device->device(), image_memory, nullptr);
5079}
5080
Tobin Ehlisb329f992016-10-12 13:20:29 -06005081TEST_F(VkLayerTest, FramebufferInUseDestroyedSignaled) {
5082 TEST_DESCRIPTION("Delete in-use framebuffer.");
Tony Barbour1fa09702017-03-16 12:09:08 -06005083 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisb329f992016-10-12 13:20:29 -06005084 VkFormatProperties format_properties;
5085 VkResult err = VK_SUCCESS;
5086 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
5087
Tobin Ehlisb329f992016-10-12 13:20:29 -06005088 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5089
5090 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06005091 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 -06005092 ASSERT_TRUE(image.initialized());
5093 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
5094
5095 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
5096 VkFramebuffer fb;
5097 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
5098 ASSERT_VK_SUCCESS(err);
5099
5100 // Just use default renderpass with our framebuffer
5101 m_renderPassBeginInfo.framebuffer = fb;
5102 // Create Null cmd buffer for submit
Tony Barbour552f6c02016-12-21 14:34:07 -07005103 m_commandBuffer->BeginCommandBuffer();
5104 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
5105 m_commandBuffer->EndRenderPass();
5106 m_commandBuffer->EndCommandBuffer();
Tobin Ehlisb329f992016-10-12 13:20:29 -06005107 // Submit cmd buffer to put it in-flight
5108 VkSubmitInfo submit_info = {};
5109 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5110 submit_info.commandBufferCount = 1;
5111 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5112 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5113 // Destroy framebuffer while in-flight
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07005114 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00422);
Tobin Ehlisb329f992016-10-12 13:20:29 -06005115 vkDestroyFramebuffer(m_device->device(), fb, NULL);
5116 m_errorMonitor->VerifyFound();
5117 // Wait for queue to complete so we can safely destroy everything
5118 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005119 m_errorMonitor->SetUnexpectedError("If framebuffer is not VK_NULL_HANDLE, framebuffer must be a valid VkFramebuffer handle");
5120 m_errorMonitor->SetUnexpectedError("Unable to remove Framebuffer obj");
Tobin Ehlisb329f992016-10-12 13:20:29 -06005121 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
5122}
5123
Tobin Ehlis88becd72016-09-21 14:33:41 -06005124TEST_F(VkLayerTest, FramebufferImageInUseDestroyedSignaled) {
5125 TEST_DESCRIPTION("Delete in-use image that's child of framebuffer.");
Tony Barbour1fa09702017-03-16 12:09:08 -06005126 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis88becd72016-09-21 14:33:41 -06005127 VkFormatProperties format_properties;
5128 VkResult err = VK_SUCCESS;
5129 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
Tobin Ehlis88becd72016-09-21 14:33:41 -06005130
Tobin Ehlis88becd72016-09-21 14:33:41 -06005131 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5132
5133 VkImageCreateInfo image_ci = {};
5134 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5135 image_ci.pNext = NULL;
5136 image_ci.imageType = VK_IMAGE_TYPE_2D;
5137 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
5138 image_ci.extent.width = 256;
5139 image_ci.extent.height = 256;
5140 image_ci.extent.depth = 1;
5141 image_ci.mipLevels = 1;
5142 image_ci.arrayLayers = 1;
5143 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
5144 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisc8ca0312016-09-22 07:30:05 -06005145 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Tobin Ehlis88becd72016-09-21 14:33:41 -06005146 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
5147 image_ci.flags = 0;
5148 VkImage image;
5149 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
5150
5151 VkMemoryRequirements memory_reqs;
5152 VkDeviceMemory image_memory;
5153 bool pass;
5154 VkMemoryAllocateInfo memory_info = {};
5155 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5156 memory_info.pNext = NULL;
5157 memory_info.allocationSize = 0;
5158 memory_info.memoryTypeIndex = 0;
5159 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5160 memory_info.allocationSize = memory_reqs.size;
5161 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
5162 ASSERT_TRUE(pass);
5163 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
5164 ASSERT_VK_SUCCESS(err);
5165 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5166 ASSERT_VK_SUCCESS(err);
5167
5168 VkImageViewCreateInfo ivci = {
5169 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
5170 nullptr,
5171 0,
5172 image,
5173 VK_IMAGE_VIEW_TYPE_2D,
5174 VK_FORMAT_B8G8R8A8_UNORM,
5175 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
5176 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
5177 };
5178 VkImageView view;
5179 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
5180 ASSERT_VK_SUCCESS(err);
5181
5182 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
5183 VkFramebuffer fb;
5184 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
5185 ASSERT_VK_SUCCESS(err);
5186
5187 // Just use default renderpass with our framebuffer
5188 m_renderPassBeginInfo.framebuffer = fb;
5189 // Create Null cmd buffer for submit
Tony Barbour552f6c02016-12-21 14:34:07 -07005190 m_commandBuffer->BeginCommandBuffer();
5191 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
5192 m_commandBuffer->EndRenderPass();
5193 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis88becd72016-09-21 14:33:41 -06005194 // Submit cmd buffer to put it (and attached imageView) in-flight
5195 VkSubmitInfo submit_info = {};
5196 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5197 submit_info.commandBufferCount = 1;
5198 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5199 // Submit cmd buffer to put framebuffer and children in-flight
5200 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5201 // Destroy image attached to framebuffer while in-flight
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07005202 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00743);
Tobin Ehlis88becd72016-09-21 14:33:41 -06005203 vkDestroyImage(m_device->device(), image, NULL);
5204 m_errorMonitor->VerifyFound();
5205 // Wait for queue to complete so we can safely destroy image and other objects
5206 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005207 m_errorMonitor->SetUnexpectedError("If image is not VK_NULL_HANDLE, image must be a valid VkImage handle");
5208 m_errorMonitor->SetUnexpectedError("Unable to remove Image obj");
Tobin Ehlis88becd72016-09-21 14:33:41 -06005209 vkDestroyImage(m_device->device(), image, NULL);
5210 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
5211 vkDestroyImageView(m_device->device(), view, nullptr);
5212 vkFreeMemory(m_device->device(), image_memory, nullptr);
5213}
5214
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005215TEST_F(VkLayerTest, RenderPassInUseDestroyedSignaled) {
5216 TEST_DESCRIPTION("Delete in-use renderPass.");
5217
Tony Barbour1fa09702017-03-16 12:09:08 -06005218 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005219 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5220
5221 // Create simple renderpass
5222 VkAttachmentReference attach = {};
5223 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
5224 VkSubpassDescription subpass = {};
Dave Houlton756e6742017-03-23 14:33:22 -06005225 subpass.colorAttachmentCount = 1;
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005226 subpass.pColorAttachments = &attach;
5227 VkRenderPassCreateInfo rpci = {};
5228 rpci.subpassCount = 1;
5229 rpci.pSubpasses = &subpass;
5230 rpci.attachmentCount = 1;
5231 VkAttachmentDescription attach_desc = {};
5232 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
5233 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
5234 rpci.pAttachments = &attach_desc;
5235 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
5236 VkRenderPass rp;
5237 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
5238 ASSERT_VK_SUCCESS(err);
5239
5240 // Create a pipeline that uses the given renderpass
5241 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5242 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5243
5244 VkPipelineLayout pipeline_layout;
5245 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
5246 ASSERT_VK_SUCCESS(err);
5247
5248 VkPipelineViewportStateCreateInfo vp_state_ci = {};
5249 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
5250 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005251 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005252 vp_state_ci.pViewports = &vp;
5253 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005254 VkRect2D scissors = {}; // Dummy scissors to point to
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005255 vp_state_ci.pScissors = &scissors;
5256
5257 VkPipelineShaderStageCreateInfo shaderStages[2];
5258 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
5259
5260 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005261 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 -06005262 // but add it to be able to run on more devices
5263 shaderStages[0] = vs.GetStageCreateInfo();
5264 shaderStages[1] = fs.GetStageCreateInfo();
5265
5266 VkPipelineVertexInputStateCreateInfo vi_ci = {};
5267 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
5268
5269 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
5270 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
5271 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
5272
5273 VkPipelineRasterizationStateCreateInfo rs_ci = {};
5274 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
5275 rs_ci.rasterizerDiscardEnable = true;
5276 rs_ci.lineWidth = 1.0f;
5277
5278 VkPipelineColorBlendAttachmentState att = {};
5279 att.blendEnable = VK_FALSE;
5280 att.colorWriteMask = 0xf;
5281
5282 VkPipelineColorBlendStateCreateInfo cb_ci = {};
5283 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
5284 cb_ci.attachmentCount = 1;
5285 cb_ci.pAttachments = &att;
5286
5287 VkGraphicsPipelineCreateInfo gp_ci = {};
5288 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
5289 gp_ci.stageCount = 2;
5290 gp_ci.pStages = shaderStages;
5291 gp_ci.pVertexInputState = &vi_ci;
5292 gp_ci.pInputAssemblyState = &ia_ci;
5293 gp_ci.pViewportState = &vp_state_ci;
5294 gp_ci.pRasterizationState = &rs_ci;
5295 gp_ci.pColorBlendState = &cb_ci;
5296 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
5297 gp_ci.layout = pipeline_layout;
5298 gp_ci.renderPass = rp;
5299
5300 VkPipelineCacheCreateInfo pc_ci = {};
5301 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
5302
Dave Houlton756e6742017-03-23 14:33:22 -06005303 m_errorMonitor->ExpectSuccess();
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005304 VkPipeline pipeline;
5305 VkPipelineCache pipe_cache;
5306 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipe_cache);
5307 ASSERT_VK_SUCCESS(err);
5308
5309 err = vkCreateGraphicsPipelines(m_device->device(), pipe_cache, 1, &gp_ci, NULL, &pipeline);
5310 ASSERT_VK_SUCCESS(err);
Dave Houlton756e6742017-03-23 14:33:22 -06005311
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005312 // Bind pipeline to cmd buffer, will also bind renderpass
5313 m_commandBuffer->BeginCommandBuffer();
5314 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
5315 m_commandBuffer->EndCommandBuffer();
5316
5317 VkSubmitInfo submit_info = {};
5318 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5319 submit_info.commandBufferCount = 1;
5320 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5321 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Dave Houlton756e6742017-03-23 14:33:22 -06005322 m_errorMonitor->VerifyNotFound();
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005323
5324 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00393);
5325 vkDestroyRenderPass(m_device->device(), rp, nullptr);
5326 m_errorMonitor->VerifyFound();
5327
5328 // Wait for queue to complete so we can safely destroy everything
5329 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005330 m_errorMonitor->SetUnexpectedError("If renderPass is not VK_NULL_HANDLE, renderPass must be a valid VkRenderPass handle");
Mark Lobodzinski74597792017-04-11 15:43:49 -06005331 m_errorMonitor->SetUnexpectedError("Unable to remove RenderPass obj");
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005332 vkDestroyRenderPass(m_device->device(), rp, nullptr);
5333 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
5334 vkDestroyPipelineCache(m_device->device(), pipe_cache, nullptr);
5335 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
5336}
5337
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005338TEST_F(VkLayerTest, ImageMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005339 TEST_DESCRIPTION("Attempt to draw with an image which has not had memory bound to it.");
Tony Barbour1fa09702017-03-16 12:09:08 -06005340 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005341
5342 VkImage image;
5343 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5344 VkImageCreateInfo image_create_info = {};
5345 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5346 image_create_info.pNext = NULL;
5347 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5348 image_create_info.format = tex_format;
5349 image_create_info.extent.width = 32;
5350 image_create_info.extent.height = 32;
5351 image_create_info.extent.depth = 1;
5352 image_create_info.mipLevels = 1;
5353 image_create_info.arrayLayers = 1;
5354 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5355 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005356 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005357 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005358 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005359 ASSERT_VK_SUCCESS(err);
5360 // Have to bind memory to image before recording cmd in cmd buffer using it
5361 VkMemoryRequirements mem_reqs;
5362 VkDeviceMemory image_mem;
5363 bool pass;
5364 VkMemoryAllocateInfo mem_alloc = {};
5365 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5366 mem_alloc.pNext = NULL;
5367 mem_alloc.memoryTypeIndex = 0;
5368 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
5369 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005370 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005371 ASSERT_TRUE(pass);
5372 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
5373 ASSERT_VK_SUCCESS(err);
5374
Tobin Ehlisfed999f2016-09-21 15:09:45 -06005375 // Introduce error, do not call vkBindImageMemory(m_device->device(), image, image_mem, 0);
5376 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005377 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005378
5379 m_commandBuffer->BeginCommandBuffer();
5380 VkClearColorValue ccv;
5381 ccv.float32[0] = 1.0f;
5382 ccv.float32[1] = 1.0f;
5383 ccv.float32[2] = 1.0f;
5384 ccv.float32[3] = 1.0f;
5385 VkImageSubresourceRange isr = {};
5386 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
5387 isr.baseArrayLayer = 0;
5388 isr.baseMipLevel = 0;
5389 isr.layerCount = 1;
5390 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005391 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005392 m_commandBuffer->EndCommandBuffer();
5393
5394 m_errorMonitor->VerifyFound();
5395 vkDestroyImage(m_device->device(), image, NULL);
5396 vkFreeMemory(m_device->device(), image_mem, nullptr);
5397}
5398
5399TEST_F(VkLayerTest, BufferMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005400 TEST_DESCRIPTION("Attempt to copy from a buffer which has not had memory bound to it.");
Tony Barbour1fa09702017-03-16 12:09:08 -06005401 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005402
5403 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06005404 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 -06005405 VK_IMAGE_TILING_OPTIMAL, 0);
5406 ASSERT_TRUE(image.initialized());
5407
5408 VkBuffer buffer;
5409 VkDeviceMemory mem;
5410 VkMemoryRequirements mem_reqs;
5411
5412 VkBufferCreateInfo buf_info = {};
5413 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes8d260dd2016-09-16 17:42:42 +12005414 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski80871462017-02-16 10:37:27 -07005415 buf_info.size = 1024;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005416 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
5417 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
5418 ASSERT_VK_SUCCESS(err);
5419
5420 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
5421
5422 VkMemoryAllocateInfo alloc_info = {};
5423 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Mark Lobodzinski80871462017-02-16 10:37:27 -07005424 alloc_info.allocationSize = 1024;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005425 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005426 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 -06005427 if (!pass) {
5428 vkDestroyBuffer(m_device->device(), buffer, NULL);
5429 return;
5430 }
5431 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
5432 ASSERT_VK_SUCCESS(err);
5433
Tobin Ehlisfed999f2016-09-21 15:09:45 -06005434 // Introduce failure by not calling vkBindBufferMemory(m_device->device(), buffer, mem, 0);
5435 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005436 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005437 VkBufferImageCopy region = {};
Mark Lobodzinski80871462017-02-16 10:37:27 -07005438 region.bufferRowLength = 16;
5439 region.bufferImageHeight = 16;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005440 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
5441
5442 region.imageSubresource.layerCount = 1;
5443 region.imageExtent.height = 4;
5444 region.imageExtent.width = 4;
5445 region.imageExtent.depth = 1;
5446 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005447 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer, image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
5448 &region);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005449 m_commandBuffer->EndCommandBuffer();
5450
5451 m_errorMonitor->VerifyFound();
5452
5453 vkDestroyBuffer(m_device->device(), buffer, NULL);
5454 vkFreeMemory(m_device->handle(), mem, NULL);
5455}
5456
Tobin Ehlis85940f52016-07-07 16:57:21 -06005457TEST_F(VkLayerTest, InvalidCmdBufferEventDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005458 TEST_DESCRIPTION(
5459 "Attempt to draw with a command buffer that is invalid "
5460 "due to an event dependency being destroyed.");
Tony Barbour1fa09702017-03-16 12:09:08 -06005461 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis85940f52016-07-07 16:57:21 -06005462
5463 VkEvent event;
5464 VkEventCreateInfo evci = {};
5465 evci.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
5466 VkResult result = vkCreateEvent(m_device->device(), &evci, NULL, &event);
5467 ASSERT_VK_SUCCESS(result);
5468
5469 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005470 vkCmdSetEvent(m_commandBuffer->GetBufferHandle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Tobin Ehlis85940f52016-07-07 16:57:21 -06005471 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 Event ");
Tobin Ehlis85940f52016-07-07 16:57:21 -06005474 // Destroy event dependency prior to submit to cause ERROR
5475 vkDestroyEvent(m_device->device(), event, 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 Ehlisdbea7552016-07-08 14:33:31 -06005486TEST_F(VkLayerTest, InvalidCmdBufferQueryPoolDestroyed) {
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 query pool dependency being destroyed.");
Tony Barbour1fa09702017-03-16 12:09:08 -06005490 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisdbea7552016-07-08 14:33:31 -06005491
5492 VkQueryPool query_pool;
5493 VkQueryPoolCreateInfo qpci{};
5494 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
5495 qpci.queryType = VK_QUERY_TYPE_TIMESTAMP;
5496 qpci.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005497 VkResult result = vkCreateQueryPool(m_device->device(), &qpci, nullptr, &query_pool);
Tobin Ehlisdbea7552016-07-08 14:33:31 -06005498 ASSERT_VK_SUCCESS(result);
5499
5500 m_commandBuffer->BeginCommandBuffer();
5501 vkCmdResetQueryPool(m_commandBuffer->GetBufferHandle(), query_pool, 0, 1);
5502 m_commandBuffer->EndCommandBuffer();
5503
Mark Lobodzinski33826372017-04-13 11:10:11 -06005504 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound QueryPool ");
Tobin Ehlisdbea7552016-07-08 14:33:31 -06005505 // Destroy query pool dependency prior to submit to cause ERROR
5506 vkDestroyQueryPool(m_device->device(), query_pool, NULL);
5507
5508 VkSubmitInfo submit_info = {};
5509 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5510 submit_info.commandBufferCount = 1;
5511 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5512 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5513
5514 m_errorMonitor->VerifyFound();
5515}
5516
Tobin Ehlis24130d92016-07-08 15:50:53 -06005517TEST_F(VkLayerTest, InvalidCmdBufferPipelineDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005518 TEST_DESCRIPTION(
5519 "Attempt to draw with a command buffer that is invalid "
5520 "due to a pipeline dependency being destroyed.");
Tony Barbour1fa09702017-03-16 12:09:08 -06005521 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis24130d92016-07-08 15:50:53 -06005522 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5523
5524 VkResult err;
5525
5526 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5527 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5528
5529 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005530 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis24130d92016-07-08 15:50:53 -06005531 ASSERT_VK_SUCCESS(err);
5532
5533 VkPipelineViewportStateCreateInfo vp_state_ci = {};
5534 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
5535 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005536 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -06005537 vp_state_ci.pViewports = &vp;
Tobin Ehlis24130d92016-07-08 15:50:53 -06005538 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005539 VkRect2D scissors = {}; // Dummy scissors to point to
Tobin Ehlis24130d92016-07-08 15:50:53 -06005540 vp_state_ci.pScissors = &scissors;
Tobin Ehlis24130d92016-07-08 15:50:53 -06005541
5542 VkPipelineShaderStageCreateInfo shaderStages[2];
5543 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
5544
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005545 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005546 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 -06005547 // but add it to be able to run on more devices
Tobin Ehlis24130d92016-07-08 15:50:53 -06005548 shaderStages[0] = vs.GetStageCreateInfo();
5549 shaderStages[1] = fs.GetStageCreateInfo();
5550
5551 VkPipelineVertexInputStateCreateInfo vi_ci = {};
5552 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
5553
5554 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
5555 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
5556 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
5557
5558 VkPipelineRasterizationStateCreateInfo rs_ci = {};
5559 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbese06ba252016-09-16 17:48:53 +12005560 rs_ci.rasterizerDiscardEnable = true;
5561 rs_ci.lineWidth = 1.0f;
Tobin Ehlis24130d92016-07-08 15:50:53 -06005562
5563 VkPipelineColorBlendAttachmentState att = {};
5564 att.blendEnable = VK_FALSE;
5565 att.colorWriteMask = 0xf;
5566
5567 VkPipelineColorBlendStateCreateInfo cb_ci = {};
5568 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
5569 cb_ci.attachmentCount = 1;
5570 cb_ci.pAttachments = &att;
5571
5572 VkGraphicsPipelineCreateInfo gp_ci = {};
5573 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
5574 gp_ci.stageCount = 2;
5575 gp_ci.pStages = shaderStages;
5576 gp_ci.pVertexInputState = &vi_ci;
5577 gp_ci.pInputAssemblyState = &ia_ci;
5578 gp_ci.pViewportState = &vp_state_ci;
5579 gp_ci.pRasterizationState = &rs_ci;
5580 gp_ci.pColorBlendState = &cb_ci;
Tobin Ehlis24130d92016-07-08 15:50:53 -06005581 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
5582 gp_ci.layout = pipeline_layout;
5583 gp_ci.renderPass = renderPass();
5584
5585 VkPipelineCacheCreateInfo pc_ci = {};
5586 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
5587
5588 VkPipeline pipeline;
5589 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005590 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis24130d92016-07-08 15:50:53 -06005591 ASSERT_VK_SUCCESS(err);
5592
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005593 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06005594 ASSERT_VK_SUCCESS(err);
5595
5596 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005597 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06005598 m_commandBuffer->EndCommandBuffer();
5599 // Now destroy pipeline in order to cause error when submitting
5600 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
5601
Mark Lobodzinski33826372017-04-13 11:10:11 -06005602 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound Pipeline ");
Tobin Ehlis24130d92016-07-08 15:50:53 -06005603
5604 VkSubmitInfo submit_info = {};
5605 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5606 submit_info.commandBufferCount = 1;
5607 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5608 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5609
5610 m_errorMonitor->VerifyFound();
5611 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
5612 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5613}
5614
Tobin Ehlis31289162016-08-17 14:57:58 -06005615TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetBufferDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005616 TEST_DESCRIPTION(
5617 "Attempt to draw with a command buffer that is invalid "
5618 "due to a bound descriptor set with a buffer dependency "
5619 "being destroyed.");
Tony Barbour1fa09702017-03-16 12:09:08 -06005620 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis31289162016-08-17 14:57:58 -06005621 ASSERT_NO_FATAL_FAILURE(InitViewport());
5622 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5623
5624 VkDescriptorPoolSize ds_type_count = {};
5625 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5626 ds_type_count.descriptorCount = 1;
5627
5628 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5629 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5630 ds_pool_ci.pNext = NULL;
5631 ds_pool_ci.maxSets = 1;
5632 ds_pool_ci.poolSizeCount = 1;
5633 ds_pool_ci.pPoolSizes = &ds_type_count;
5634
5635 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005636 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis31289162016-08-17 14:57:58 -06005637 ASSERT_VK_SUCCESS(err);
5638
5639 VkDescriptorSetLayoutBinding dsl_binding = {};
5640 dsl_binding.binding = 0;
5641 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5642 dsl_binding.descriptorCount = 1;
5643 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5644 dsl_binding.pImmutableSamplers = NULL;
5645
5646 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5647 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5648 ds_layout_ci.pNext = NULL;
5649 ds_layout_ci.bindingCount = 1;
5650 ds_layout_ci.pBindings = &dsl_binding;
5651 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005652 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06005653 ASSERT_VK_SUCCESS(err);
5654
5655 VkDescriptorSet descriptorSet;
5656 VkDescriptorSetAllocateInfo alloc_info = {};
5657 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5658 alloc_info.descriptorSetCount = 1;
5659 alloc_info.descriptorPool = ds_pool;
5660 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005661 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis31289162016-08-17 14:57:58 -06005662 ASSERT_VK_SUCCESS(err);
5663
5664 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5665 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5666 pipeline_layout_ci.pNext = NULL;
5667 pipeline_layout_ci.setLayoutCount = 1;
5668 pipeline_layout_ci.pSetLayouts = &ds_layout;
5669
5670 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005671 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06005672 ASSERT_VK_SUCCESS(err);
5673
5674 // Create a buffer to update the descriptor with
5675 uint32_t qfi = 0;
5676 VkBufferCreateInfo buffCI = {};
5677 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
5678 buffCI.size = 1024;
5679 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
5680 buffCI.queueFamilyIndexCount = 1;
5681 buffCI.pQueueFamilyIndices = &qfi;
5682
5683 VkBuffer buffer;
5684 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &buffer);
5685 ASSERT_VK_SUCCESS(err);
5686 // Allocate memory and bind to buffer so we can make it to the appropriate
5687 // error
5688 VkMemoryAllocateInfo mem_alloc = {};
5689 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5690 mem_alloc.pNext = NULL;
5691 mem_alloc.allocationSize = 1024;
5692 mem_alloc.memoryTypeIndex = 0;
5693
5694 VkMemoryRequirements memReqs;
5695 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005696 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis31289162016-08-17 14:57:58 -06005697 if (!pass) {
5698 vkDestroyBuffer(m_device->device(), buffer, NULL);
5699 return;
5700 }
5701
5702 VkDeviceMemory mem;
5703 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
5704 ASSERT_VK_SUCCESS(err);
5705 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
5706 ASSERT_VK_SUCCESS(err);
5707 // Correctly update descriptor to avoid "NOT_UPDATED" error
5708 VkDescriptorBufferInfo buffInfo = {};
5709 buffInfo.buffer = buffer;
5710 buffInfo.offset = 0;
5711 buffInfo.range = 1024;
5712
5713 VkWriteDescriptorSet descriptor_write;
5714 memset(&descriptor_write, 0, sizeof(descriptor_write));
5715 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5716 descriptor_write.dstSet = descriptorSet;
5717 descriptor_write.dstBinding = 0;
5718 descriptor_write.descriptorCount = 1;
5719 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5720 descriptor_write.pBufferInfo = &buffInfo;
5721
5722 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5723
5724 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005725 char const *vsSource =
5726 "#version 450\n"
5727 "\n"
5728 "out gl_PerVertex { \n"
5729 " vec4 gl_Position;\n"
5730 "};\n"
5731 "void main(){\n"
5732 " gl_Position = vec4(1);\n"
5733 "}\n";
5734 char const *fsSource =
5735 "#version 450\n"
5736 "\n"
5737 "layout(location=0) out vec4 x;\n"
5738 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
5739 "void main(){\n"
5740 " x = vec4(bar.y);\n"
5741 "}\n";
Tobin Ehlis31289162016-08-17 14:57:58 -06005742 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5743 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5744 VkPipelineObj pipe(m_device);
5745 pipe.AddShader(&vs);
5746 pipe.AddShader(&fs);
5747 pipe.AddColorAttachment();
5748 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5749
Tony Barbour552f6c02016-12-21 14:34:07 -07005750 m_commandBuffer->BeginCommandBuffer();
5751 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005752 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5753 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5754 &descriptorSet, 0, NULL);
Rene Lindsay0583ac92017-01-16 14:29:10 -07005755
5756 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &m_viewports[0]);
5757 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &m_scissors[0]);
5758
Tobin Ehlis31289162016-08-17 14:57:58 -06005759 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005760 m_commandBuffer->EndRenderPass();
5761 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski33826372017-04-13 11:10:11 -06005762 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound Buffer ");
Tobin Ehlis31289162016-08-17 14:57:58 -06005763 // Destroy buffer should invalidate the cmd buffer, causing error on submit
5764 vkDestroyBuffer(m_device->device(), buffer, NULL);
5765 // Attempt to submit cmd buffer
5766 VkSubmitInfo submit_info = {};
5767 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5768 submit_info.commandBufferCount = 1;
5769 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5770 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5771 m_errorMonitor->VerifyFound();
5772 // Cleanup
5773 vkFreeMemory(m_device->device(), mem, NULL);
5774
5775 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5776 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5777 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5778}
5779
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005780TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetImageSamplerDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005781 TEST_DESCRIPTION(
5782 "Attempt to draw with a command buffer that is invalid "
5783 "due to a bound descriptor sets with a combined image "
5784 "sampler having their image, sampler, and descriptor set "
5785 "each respectively destroyed and then attempting to "
5786 "submit associated cmd buffers. Attempt to destroy a "
5787 "DescriptorSet that is in use.");
Tony Barbour1fa09702017-03-16 12:09:08 -06005788 ASSERT_NO_FATAL_FAILURE(Init(nullptr, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT));
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005789 ASSERT_NO_FATAL_FAILURE(InitViewport());
5790 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5791
5792 VkDescriptorPoolSize ds_type_count = {};
5793 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5794 ds_type_count.descriptorCount = 1;
5795
5796 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5797 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5798 ds_pool_ci.pNext = NULL;
Rene Lindsayed88b732017-01-27 15:55:29 -07005799 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005800 ds_pool_ci.maxSets = 1;
5801 ds_pool_ci.poolSizeCount = 1;
5802 ds_pool_ci.pPoolSizes = &ds_type_count;
5803
5804 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005805 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005806 ASSERT_VK_SUCCESS(err);
5807
5808 VkDescriptorSetLayoutBinding dsl_binding = {};
5809 dsl_binding.binding = 0;
5810 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5811 dsl_binding.descriptorCount = 1;
5812 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5813 dsl_binding.pImmutableSamplers = NULL;
5814
5815 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5816 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5817 ds_layout_ci.pNext = NULL;
5818 ds_layout_ci.bindingCount = 1;
5819 ds_layout_ci.pBindings = &dsl_binding;
5820 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005821 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005822 ASSERT_VK_SUCCESS(err);
5823
5824 VkDescriptorSet descriptorSet;
5825 VkDescriptorSetAllocateInfo alloc_info = {};
5826 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5827 alloc_info.descriptorSetCount = 1;
5828 alloc_info.descriptorPool = ds_pool;
5829 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005830 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005831 ASSERT_VK_SUCCESS(err);
5832
5833 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5834 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5835 pipeline_layout_ci.pNext = NULL;
5836 pipeline_layout_ci.setLayoutCount = 1;
5837 pipeline_layout_ci.pSetLayouts = &ds_layout;
5838
5839 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005840 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005841 ASSERT_VK_SUCCESS(err);
5842
5843 // Create images to update the descriptor with
5844 VkImage image;
5845 VkImage image2;
5846 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5847 const int32_t tex_width = 32;
5848 const int32_t tex_height = 32;
5849 VkImageCreateInfo image_create_info = {};
5850 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5851 image_create_info.pNext = NULL;
5852 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5853 image_create_info.format = tex_format;
5854 image_create_info.extent.width = tex_width;
5855 image_create_info.extent.height = tex_height;
5856 image_create_info.extent.depth = 1;
5857 image_create_info.mipLevels = 1;
5858 image_create_info.arrayLayers = 1;
5859 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5860 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
5861 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5862 image_create_info.flags = 0;
5863 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
5864 ASSERT_VK_SUCCESS(err);
5865 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
5866 ASSERT_VK_SUCCESS(err);
5867
5868 VkMemoryRequirements memory_reqs;
5869 VkDeviceMemory image_memory;
5870 bool pass;
5871 VkMemoryAllocateInfo memory_info = {};
5872 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5873 memory_info.pNext = NULL;
5874 memory_info.allocationSize = 0;
5875 memory_info.memoryTypeIndex = 0;
5876 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5877 // Allocate enough memory for both images
5878 memory_info.allocationSize = memory_reqs.size * 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005879 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005880 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005881 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005882 ASSERT_VK_SUCCESS(err);
5883 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5884 ASSERT_VK_SUCCESS(err);
5885 // Bind second image to memory right after first image
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005886 err = vkBindImageMemory(m_device->device(), image2, image_memory, memory_reqs.size);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005887 ASSERT_VK_SUCCESS(err);
5888
5889 VkImageViewCreateInfo image_view_create_info = {};
5890 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5891 image_view_create_info.image = image;
5892 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5893 image_view_create_info.format = tex_format;
5894 image_view_create_info.subresourceRange.layerCount = 1;
5895 image_view_create_info.subresourceRange.baseMipLevel = 0;
5896 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005897 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005898
5899 VkImageView view;
5900 VkImageView view2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005901 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005902 ASSERT_VK_SUCCESS(err);
5903 image_view_create_info.image = image2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005904 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view2);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005905 ASSERT_VK_SUCCESS(err);
5906 // Create Samplers
5907 VkSamplerCreateInfo sampler_ci = {};
5908 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5909 sampler_ci.pNext = NULL;
5910 sampler_ci.magFilter = VK_FILTER_NEAREST;
5911 sampler_ci.minFilter = VK_FILTER_NEAREST;
5912 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5913 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5914 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5915 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5916 sampler_ci.mipLodBias = 1.0;
5917 sampler_ci.anisotropyEnable = VK_FALSE;
5918 sampler_ci.maxAnisotropy = 1;
5919 sampler_ci.compareEnable = VK_FALSE;
5920 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5921 sampler_ci.minLod = 1.0;
5922 sampler_ci.maxLod = 1.0;
5923 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5924 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5925 VkSampler sampler;
5926 VkSampler sampler2;
5927 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5928 ASSERT_VK_SUCCESS(err);
5929 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler2);
5930 ASSERT_VK_SUCCESS(err);
5931 // Update descriptor with image and sampler
5932 VkDescriptorImageInfo img_info = {};
5933 img_info.sampler = sampler;
5934 img_info.imageView = view;
5935 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5936
5937 VkWriteDescriptorSet descriptor_write;
5938 memset(&descriptor_write, 0, sizeof(descriptor_write));
5939 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5940 descriptor_write.dstSet = descriptorSet;
5941 descriptor_write.dstBinding = 0;
5942 descriptor_write.descriptorCount = 1;
5943 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5944 descriptor_write.pImageInfo = &img_info;
5945
5946 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5947
5948 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005949 char const *vsSource =
5950 "#version 450\n"
5951 "\n"
5952 "out gl_PerVertex { \n"
5953 " vec4 gl_Position;\n"
5954 "};\n"
5955 "void main(){\n"
5956 " gl_Position = vec4(1);\n"
5957 "}\n";
5958 char const *fsSource =
5959 "#version 450\n"
5960 "\n"
5961 "layout(set=0, binding=0) uniform sampler2D s;\n"
5962 "layout(location=0) out vec4 x;\n"
5963 "void main(){\n"
5964 " x = texture(s, vec2(1));\n"
5965 "}\n";
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005966 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5967 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5968 VkPipelineObj pipe(m_device);
5969 pipe.AddShader(&vs);
5970 pipe.AddShader(&fs);
5971 pipe.AddColorAttachment();
5972 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5973
5974 // First error case is destroying sampler prior to cmd buffer submission
Mark Lobodzinski33826372017-04-13 11:10:11 -06005975 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is invalid because bound Sampler");
Tony Barbour552f6c02016-12-21 14:34:07 -07005976 m_commandBuffer->BeginCommandBuffer();
5977 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 VkViewport viewport = {0, 0, 16, 16, 0, 1};
5982 VkRect2D scissor = {{0, 0}, {16, 16}};
5983 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
5984 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005985 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005986 m_commandBuffer->EndRenderPass();
5987 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005988 // Destroy sampler invalidates the cmd buffer, causing error on submit
5989 vkDestroySampler(m_device->device(), sampler, NULL);
5990 // Attempt to submit cmd buffer
5991 VkSubmitInfo submit_info = {};
5992 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5993 submit_info.commandBufferCount = 1;
5994 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5995 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5996 m_errorMonitor->VerifyFound();
Rene Lindsaya31285f2017-01-11 16:35:53 -07005997
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005998 // Now re-update descriptor with valid sampler and delete image
5999 img_info.sampler = sampler2;
6000 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Rene Lindsayed88b732017-01-27 15:55:29 -07006001
6002 VkCommandBufferBeginInfo info = {};
6003 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
6004 info.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
6005
Mark Lobodzinski33826372017-04-13 11:10:11 -06006006 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound Image ");
Rene Lindsayed88b732017-01-27 15:55:29 -07006007 m_commandBuffer->BeginCommandBuffer(&info);
Tony Barbour552f6c02016-12-21 14:34:07 -07006008 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006009 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
6010 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6011 &descriptorSet, 0, NULL);
Rene Lindsaya31285f2017-01-11 16:35:53 -07006012 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
6013 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06006014 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07006015 m_commandBuffer->EndRenderPass();
6016 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06006017 // Destroy image invalidates the cmd buffer, causing error on submit
6018 vkDestroyImage(m_device->device(), image, NULL);
6019 // Attempt to submit cmd buffer
6020 submit_info = {};
6021 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6022 submit_info.commandBufferCount = 1;
6023 submit_info.pCommandBuffers = &m_commandBuffer->handle();
6024 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
6025 m_errorMonitor->VerifyFound();
6026 // Now update descriptor to be valid, but then free descriptor
6027 img_info.imageView = view2;
6028 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Rene Lindsayed88b732017-01-27 15:55:29 -07006029 m_commandBuffer->BeginCommandBuffer(&info);
Tony Barbour552f6c02016-12-21 14:34:07 -07006030 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006031 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
6032 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6033 &descriptorSet, 0, NULL);
Rene Lindsaya31285f2017-01-11 16:35:53 -07006034 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
6035 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06006036 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07006037 m_commandBuffer->EndRenderPass();
6038 m_commandBuffer->EndCommandBuffer();
Tony Barbourc373c012017-01-26 10:53:28 -07006039 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Dave Houltonfbf52152017-01-06 12:55:29 -07006040
6041 // Immediately try to destroy the descriptor set in the active command buffer - failure expected
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006042 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call vkFreeDescriptorSets() on descriptor set 0x");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06006043 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Mark Mueller917f6bc2016-08-30 10:57:19 -06006044 m_errorMonitor->VerifyFound();
Dave Houltonfbf52152017-01-06 12:55:29 -07006045
6046 // Try again once the queue is idle - should succeed w/o error
Dave Houltond5507dd2017-01-24 15:29:02 -07006047 // 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 -07006048 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07006049 m_errorMonitor->SetUnexpectedError(
6050 "pDescriptorSets must be a pointer to an array of descriptorSetCount VkDescriptorSet handles, each element of which must "
6051 "either be a valid handle or VK_NULL_HANDLE");
Mark Lobodzinski74597792017-04-11 15:43:49 -06006052 m_errorMonitor->SetUnexpectedError("Unable to remove DescriptorSet obj");
Dave Houltonfbf52152017-01-06 12:55:29 -07006053 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
6054
6055 // Attempt to submit cmd buffer containing the freed descriptor set
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06006056 submit_info = {};
6057 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6058 submit_info.commandBufferCount = 1;
6059 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Lobodzinski33826372017-04-13 11:10:11 -06006060 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound DescriptorSet ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06006061 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
6062 m_errorMonitor->VerifyFound();
Dave Houltonfbf52152017-01-06 12:55:29 -07006063
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06006064 // Cleanup
6065 vkFreeMemory(m_device->device(), image_memory, NULL);
6066 vkDestroySampler(m_device->device(), sampler2, NULL);
6067 vkDestroyImage(m_device->device(), image2, NULL);
6068 vkDestroyImageView(m_device->device(), view, NULL);
6069 vkDestroyImageView(m_device->device(), view2, NULL);
6070 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6071 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6072 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6073}
6074
Tobin Ehlisaabbcd02017-04-13 14:15:21 -06006075TEST_F(VkLayerTest, ImageDescriptorLayoutMismatch) {
6076 TEST_DESCRIPTION("Update an image sampler with a layout that doesn't match the actual image layout at the image is used.");
6077 ASSERT_NO_FATAL_FAILURE(Init(nullptr, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT));
6078 ASSERT_NO_FATAL_FAILURE(InitViewport());
6079 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6080
6081 VkDescriptorPoolSize ds_type_count = {};
6082 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6083 ds_type_count.descriptorCount = 1;
6084
6085 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6086 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6087 ds_pool_ci.pNext = NULL;
6088 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
6089 ds_pool_ci.maxSets = 1;
6090 ds_pool_ci.poolSizeCount = 1;
6091 ds_pool_ci.pPoolSizes = &ds_type_count;
6092
6093 VkDescriptorPool ds_pool;
6094 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
6095 ASSERT_VK_SUCCESS(err);
6096
6097 VkDescriptorSetLayoutBinding dsl_binding = {};
6098 dsl_binding.binding = 0;
6099 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6100 dsl_binding.descriptorCount = 1;
6101 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6102 dsl_binding.pImmutableSamplers = NULL;
6103
6104 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6105 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6106 ds_layout_ci.pNext = NULL;
6107 ds_layout_ci.bindingCount = 1;
6108 ds_layout_ci.pBindings = &dsl_binding;
6109 VkDescriptorSetLayout ds_layout;
6110 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
6111 ASSERT_VK_SUCCESS(err);
6112
6113 VkDescriptorSet descriptorSet;
6114 VkDescriptorSetAllocateInfo alloc_info = {};
6115 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6116 alloc_info.descriptorSetCount = 1;
6117 alloc_info.descriptorPool = ds_pool;
6118 alloc_info.pSetLayouts = &ds_layout;
6119 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
6120 ASSERT_VK_SUCCESS(err);
6121
6122 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6123 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6124 pipeline_layout_ci.pNext = NULL;
6125 pipeline_layout_ci.setLayoutCount = 1;
6126 pipeline_layout_ci.pSetLayouts = &ds_layout;
6127
6128 VkPipelineLayout pipeline_layout;
6129 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
6130 ASSERT_VK_SUCCESS(err);
6131
6132 // Create images to update the descriptor with
6133 const VkFormat format = VK_FORMAT_B8G8R8A8_UNORM;
6134 VkImageObj image(m_device);
6135 image.Init(32, 32, 1, format, VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VK_IMAGE_TILING_OPTIMAL,
6136 0);
6137 ASSERT_TRUE(image.initialized());
6138
6139 VkImageViewCreateInfo image_view_create_info = {};
6140 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
6141 image_view_create_info.image = image.handle();
6142 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
6143 image_view_create_info.format = format;
6144 image_view_create_info.subresourceRange.layerCount = 1;
6145 image_view_create_info.subresourceRange.baseMipLevel = 0;
6146 image_view_create_info.subresourceRange.levelCount = 1;
6147 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
6148
6149 VkImageView view;
6150 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
6151 ASSERT_VK_SUCCESS(err);
6152 // Create Sampler
6153 VkSamplerCreateInfo sampler_ci = {};
6154 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
6155 sampler_ci.pNext = NULL;
6156 sampler_ci.magFilter = VK_FILTER_NEAREST;
6157 sampler_ci.minFilter = VK_FILTER_NEAREST;
6158 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
6159 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6160 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6161 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6162 sampler_ci.mipLodBias = 1.0;
6163 sampler_ci.anisotropyEnable = VK_FALSE;
6164 sampler_ci.maxAnisotropy = 1;
6165 sampler_ci.compareEnable = VK_FALSE;
6166 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
6167 sampler_ci.minLod = 1.0;
6168 sampler_ci.maxLod = 1.0;
6169 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
6170 sampler_ci.unnormalizedCoordinates = VK_FALSE;
6171 VkSampler sampler;
6172 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
6173 ASSERT_VK_SUCCESS(err);
6174 // Update descriptor with image and sampler
6175 VkDescriptorImageInfo img_info = {};
6176 img_info.sampler = sampler;
6177 img_info.imageView = view;
6178 // This should cause a mis-match. Actual layout at use time is SHADER_RO
6179 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
6180
6181 VkWriteDescriptorSet descriptor_write;
6182 memset(&descriptor_write, 0, sizeof(descriptor_write));
6183 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6184 descriptor_write.dstSet = descriptorSet;
6185 descriptor_write.dstBinding = 0;
6186 descriptor_write.descriptorCount = 1;
6187 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6188 descriptor_write.pImageInfo = &img_info;
6189
6190 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6191
6192 // Create PSO to be used for draw-time errors below
6193 char const *vsSource =
6194 "#version 450\n"
6195 "\n"
6196 "out gl_PerVertex { \n"
6197 " vec4 gl_Position;\n"
6198 "};\n"
6199 "void main(){\n"
6200 " gl_Position = vec4(1);\n"
6201 "}\n";
6202 char const *fsSource =
6203 "#version 450\n"
6204 "\n"
6205 "layout(set=0, binding=0) uniform sampler2D s;\n"
6206 "layout(location=0) out vec4 x;\n"
6207 "void main(){\n"
6208 " x = texture(s, vec2(1));\n"
6209 "}\n";
6210 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6211 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
6212 VkPipelineObj pipe(m_device);
6213 pipe.AddShader(&vs);
6214 pipe.AddShader(&fs);
6215 pipe.AddColorAttachment();
6216 pipe.CreateVKPipeline(pipeline_layout, renderPass());
6217
6218 VkCommandBufferObj cmd_buf(m_device, m_commandPool);
6219 cmd_buf.BeginCommandBuffer();
6220 cmd_buf.BeginRenderPass(m_renderPassBeginInfo);
6221 // record layout different than actual descriptor layout of SHADER_RO
6222 image.SetLayout(&cmd_buf, VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL);
6223 vkCmdBindPipeline(cmd_buf.handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
6224 vkCmdBindDescriptorSets(cmd_buf.handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &descriptorSet, 0, NULL);
6225 VkViewport viewport = {0, 0, 16, 16, 0, 1};
6226 VkRect2D scissor = {{0, 0}, {16, 16}};
6227 vkCmdSetViewport(cmd_buf.handle(), 0, 1, &viewport);
6228 vkCmdSetScissor(cmd_buf.handle(), 0, 1, &scissor);
6229 // At draw time the update layout will mis-match the actual layout
6230 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6231 " with specific layout VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL that doesn't match the "
6232 "actual current layout VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL.");
6233 m_errorMonitor->SetDesiredFailureMsg(
6234 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6235 " Image layout specified at vkUpdateDescriptorSets() time doesn't match actual image layout at time descriptor is used.");
6236 cmd_buf.Draw(1, 0, 0, 0);
6237 m_errorMonitor->VerifyFound();
6238 cmd_buf.EndRenderPass();
6239 cmd_buf.EndCommandBuffer();
6240 // Submit cmd buffer
6241 VkSubmitInfo submit_info = {};
6242 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6243 submit_info.commandBufferCount = 1;
6244 submit_info.pCommandBuffers = &cmd_buf.handle();
6245 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
6246 vkQueueWaitIdle(m_device->m_queue);
6247 // Cleanup
6248 vkDestroySampler(m_device->device(), sampler, NULL);
6249 vkDestroyImageView(m_device->device(), view, NULL);
6250 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6251 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6252 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6253}
6254
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006255TEST_F(VkLayerTest, DescriptorPoolInUseDestroyedSignaled) {
6256 TEST_DESCRIPTION("Delete a DescriptorPool with a DescriptorSet that is in use.");
Tony Barbour1fa09702017-03-16 12:09:08 -06006257 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006258 ASSERT_NO_FATAL_FAILURE(InitViewport());
6259 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6260
6261 VkDescriptorPoolSize ds_type_count = {};
6262 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6263 ds_type_count.descriptorCount = 1;
6264
6265 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6266 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6267 ds_pool_ci.pNext = NULL;
6268 ds_pool_ci.maxSets = 1;
6269 ds_pool_ci.poolSizeCount = 1;
6270 ds_pool_ci.pPoolSizes = &ds_type_count;
6271
6272 VkDescriptorPool ds_pool;
6273 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
6274 ASSERT_VK_SUCCESS(err);
6275
6276 VkDescriptorSetLayoutBinding dsl_binding = {};
6277 dsl_binding.binding = 0;
6278 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6279 dsl_binding.descriptorCount = 1;
6280 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6281 dsl_binding.pImmutableSamplers = NULL;
6282
6283 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6284 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6285 ds_layout_ci.pNext = NULL;
6286 ds_layout_ci.bindingCount = 1;
6287 ds_layout_ci.pBindings = &dsl_binding;
6288 VkDescriptorSetLayout ds_layout;
6289 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
6290 ASSERT_VK_SUCCESS(err);
6291
6292 VkDescriptorSet descriptor_set;
6293 VkDescriptorSetAllocateInfo alloc_info = {};
6294 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6295 alloc_info.descriptorSetCount = 1;
6296 alloc_info.descriptorPool = ds_pool;
6297 alloc_info.pSetLayouts = &ds_layout;
6298 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
6299 ASSERT_VK_SUCCESS(err);
6300
6301 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6302 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6303 pipeline_layout_ci.pNext = NULL;
6304 pipeline_layout_ci.setLayoutCount = 1;
6305 pipeline_layout_ci.pSetLayouts = &ds_layout;
6306
6307 VkPipelineLayout pipeline_layout;
6308 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
6309 ASSERT_VK_SUCCESS(err);
6310
6311 // Create image to update the descriptor with
6312 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06006313 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 -06006314 ASSERT_TRUE(image.initialized());
6315
6316 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
6317 // Create Sampler
6318 VkSamplerCreateInfo sampler_ci = {};
6319 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
6320 sampler_ci.pNext = NULL;
6321 sampler_ci.magFilter = VK_FILTER_NEAREST;
6322 sampler_ci.minFilter = VK_FILTER_NEAREST;
6323 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
6324 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6325 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6326 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6327 sampler_ci.mipLodBias = 1.0;
6328 sampler_ci.anisotropyEnable = VK_FALSE;
6329 sampler_ci.maxAnisotropy = 1;
6330 sampler_ci.compareEnable = VK_FALSE;
6331 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
6332 sampler_ci.minLod = 1.0;
6333 sampler_ci.maxLod = 1.0;
6334 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
6335 sampler_ci.unnormalizedCoordinates = VK_FALSE;
6336 VkSampler sampler;
6337 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
6338 ASSERT_VK_SUCCESS(err);
6339 // Update descriptor with image and sampler
6340 VkDescriptorImageInfo img_info = {};
6341 img_info.sampler = sampler;
6342 img_info.imageView = view;
6343 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
6344
6345 VkWriteDescriptorSet descriptor_write;
6346 memset(&descriptor_write, 0, sizeof(descriptor_write));
6347 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6348 descriptor_write.dstSet = descriptor_set;
6349 descriptor_write.dstBinding = 0;
6350 descriptor_write.descriptorCount = 1;
6351 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6352 descriptor_write.pImageInfo = &img_info;
6353
6354 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6355
6356 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006357 char const *vsSource =
6358 "#version 450\n"
6359 "\n"
6360 "out gl_PerVertex { \n"
6361 " vec4 gl_Position;\n"
6362 "};\n"
6363 "void main(){\n"
6364 " gl_Position = vec4(1);\n"
6365 "}\n";
6366 char const *fsSource =
6367 "#version 450\n"
6368 "\n"
6369 "layout(set=0, binding=0) uniform sampler2D s;\n"
6370 "layout(location=0) out vec4 x;\n"
6371 "void main(){\n"
6372 " x = texture(s, vec2(1));\n"
6373 "}\n";
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006374 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6375 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
6376 VkPipelineObj pipe(m_device);
6377 pipe.AddShader(&vs);
6378 pipe.AddShader(&fs);
6379 pipe.AddColorAttachment();
6380 pipe.CreateVKPipeline(pipeline_layout, renderPass());
6381
Tony Barbour552f6c02016-12-21 14:34:07 -07006382 m_commandBuffer->BeginCommandBuffer();
6383 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006384 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
6385 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6386 &descriptor_set, 0, NULL);
Rene Lindsaye353a072017-01-16 11:07:28 -07006387
6388 VkViewport viewport = {0, 0, 16, 16, 0, 1};
6389 VkRect2D scissor = {{0, 0}, {16, 16}};
6390 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
6391 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
6392
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006393 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07006394 m_commandBuffer->EndRenderPass();
6395 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006396 // Submit cmd buffer to put pool in-flight
6397 VkSubmitInfo submit_info = {};
6398 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6399 submit_info.commandBufferCount = 1;
6400 submit_info.pCommandBuffers = &m_commandBuffer->handle();
6401 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
6402 // Destroy pool while in-flight, causing error
Mark Lobodzinski33826372017-04-13 11:10:11 -06006403 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete DescriptorPool ");
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006404 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6405 m_errorMonitor->VerifyFound();
6406 vkQueueWaitIdle(m_device->m_queue);
6407 // Cleanup
6408 vkDestroySampler(m_device->device(), sampler, NULL);
6409 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6410 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07006411 m_errorMonitor->SetUnexpectedError(
6412 "If descriptorPool is not VK_NULL_HANDLE, descriptorPool must be a valid VkDescriptorPool handle");
Mark Lobodzinski74597792017-04-11 15:43:49 -06006413 m_errorMonitor->SetUnexpectedError("Unable to remove DescriptorPool obj");
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006414 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Rene Lindsaye353a072017-01-16 11:07:28 -07006415 // TODO : It seems Validation layers think ds_pool was already destroyed, even though it wasn't?
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006416}
6417
Tobin Ehlis50a095d2016-09-21 17:32:49 -06006418TEST_F(VkLayerTest, DescriptorImageUpdateNoMemoryBound) {
6419 TEST_DESCRIPTION("Attempt an image descriptor set update where image's bound memory has been freed.");
Tony Barbour1fa09702017-03-16 12:09:08 -06006420 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis50a095d2016-09-21 17:32:49 -06006421 ASSERT_NO_FATAL_FAILURE(InitViewport());
6422 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6423
6424 VkDescriptorPoolSize ds_type_count = {};
6425 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6426 ds_type_count.descriptorCount = 1;
6427
6428 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6429 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6430 ds_pool_ci.pNext = NULL;
6431 ds_pool_ci.maxSets = 1;
6432 ds_pool_ci.poolSizeCount = 1;
6433 ds_pool_ci.pPoolSizes = &ds_type_count;
6434
6435 VkDescriptorPool ds_pool;
6436 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
6437 ASSERT_VK_SUCCESS(err);
6438
6439 VkDescriptorSetLayoutBinding dsl_binding = {};
6440 dsl_binding.binding = 0;
6441 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6442 dsl_binding.descriptorCount = 1;
6443 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6444 dsl_binding.pImmutableSamplers = NULL;
6445
6446 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6447 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6448 ds_layout_ci.pNext = NULL;
6449 ds_layout_ci.bindingCount = 1;
6450 ds_layout_ci.pBindings = &dsl_binding;
6451 VkDescriptorSetLayout ds_layout;
6452 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
6453 ASSERT_VK_SUCCESS(err);
6454
6455 VkDescriptorSet descriptorSet;
6456 VkDescriptorSetAllocateInfo alloc_info = {};
6457 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6458 alloc_info.descriptorSetCount = 1;
6459 alloc_info.descriptorPool = ds_pool;
6460 alloc_info.pSetLayouts = &ds_layout;
6461 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
6462 ASSERT_VK_SUCCESS(err);
6463
6464 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6465 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6466 pipeline_layout_ci.pNext = NULL;
6467 pipeline_layout_ci.setLayoutCount = 1;
6468 pipeline_layout_ci.pSetLayouts = &ds_layout;
6469
6470 VkPipelineLayout pipeline_layout;
6471 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
6472 ASSERT_VK_SUCCESS(err);
6473
6474 // Create images to update the descriptor with
6475 VkImage image;
6476 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
6477 const int32_t tex_width = 32;
6478 const int32_t tex_height = 32;
6479 VkImageCreateInfo image_create_info = {};
6480 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6481 image_create_info.pNext = NULL;
6482 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6483 image_create_info.format = tex_format;
6484 image_create_info.extent.width = tex_width;
6485 image_create_info.extent.height = tex_height;
6486 image_create_info.extent.depth = 1;
6487 image_create_info.mipLevels = 1;
6488 image_create_info.arrayLayers = 1;
6489 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
6490 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
6491 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
6492 image_create_info.flags = 0;
6493 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
6494 ASSERT_VK_SUCCESS(err);
6495 // Initially bind memory to avoid error at bind view time. We'll break binding before update.
6496 VkMemoryRequirements memory_reqs;
6497 VkDeviceMemory image_memory;
6498 bool pass;
6499 VkMemoryAllocateInfo memory_info = {};
6500 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6501 memory_info.pNext = NULL;
6502 memory_info.allocationSize = 0;
6503 memory_info.memoryTypeIndex = 0;
6504 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
6505 // Allocate enough memory for image
6506 memory_info.allocationSize = memory_reqs.size;
6507 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
6508 ASSERT_TRUE(pass);
6509 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
6510 ASSERT_VK_SUCCESS(err);
6511 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
6512 ASSERT_VK_SUCCESS(err);
6513
6514 VkImageViewCreateInfo image_view_create_info = {};
6515 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
6516 image_view_create_info.image = image;
6517 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
6518 image_view_create_info.format = tex_format;
6519 image_view_create_info.subresourceRange.layerCount = 1;
6520 image_view_create_info.subresourceRange.baseMipLevel = 0;
6521 image_view_create_info.subresourceRange.levelCount = 1;
6522 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
6523
6524 VkImageView view;
6525 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
6526 ASSERT_VK_SUCCESS(err);
6527 // Create Samplers
6528 VkSamplerCreateInfo sampler_ci = {};
6529 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
6530 sampler_ci.pNext = NULL;
6531 sampler_ci.magFilter = VK_FILTER_NEAREST;
6532 sampler_ci.minFilter = VK_FILTER_NEAREST;
6533 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
6534 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6535 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6536 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6537 sampler_ci.mipLodBias = 1.0;
6538 sampler_ci.anisotropyEnable = VK_FALSE;
6539 sampler_ci.maxAnisotropy = 1;
6540 sampler_ci.compareEnable = VK_FALSE;
6541 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
6542 sampler_ci.minLod = 1.0;
6543 sampler_ci.maxLod = 1.0;
6544 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
6545 sampler_ci.unnormalizedCoordinates = VK_FALSE;
6546 VkSampler sampler;
6547 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
6548 ASSERT_VK_SUCCESS(err);
6549 // Update descriptor with image and sampler
6550 VkDescriptorImageInfo img_info = {};
6551 img_info.sampler = sampler;
6552 img_info.imageView = view;
6553 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
6554
6555 VkWriteDescriptorSet descriptor_write;
6556 memset(&descriptor_write, 0, sizeof(descriptor_write));
6557 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6558 descriptor_write.dstSet = descriptorSet;
6559 descriptor_write.dstBinding = 0;
6560 descriptor_write.descriptorCount = 1;
6561 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6562 descriptor_write.pImageInfo = &img_info;
6563 // Break memory binding and attempt update
6564 vkFreeMemory(m_device->device(), image_memory, nullptr);
6565 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006566 " previously bound memory was freed. Memory must not be freed prior to this operation.");
Tobin Ehlis50a095d2016-09-21 17:32:49 -06006567 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6568 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
6569 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6570 m_errorMonitor->VerifyFound();
6571 // Cleanup
6572 vkDestroyImage(m_device->device(), image, NULL);
6573 vkDestroySampler(m_device->device(), sampler, NULL);
6574 vkDestroyImageView(m_device->device(), view, NULL);
6575 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6576 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6577 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6578}
6579
Karl Schultz6addd812016-02-02 17:17:23 -07006580TEST_F(VkLayerTest, InvalidPipeline) {
Karl Schultzbdb75952016-04-19 11:36:49 -06006581 // Attempt to bind an invalid Pipeline to a valid Command Buffer
6582 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06006583 // Create a valid cmd buffer
6584 // call vkCmdBindPipeline w/ false Pipeline
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06006585 uint64_t fake_pipeline_handle = 0xbaad6001;
6586 VkPipeline bad_pipeline = reinterpret_cast<VkPipeline &>(fake_pipeline_handle);
Tony Barbour1fa09702017-03-16 12:09:08 -06006587 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes4dbf70f2016-09-16 17:58:00 +12006588 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6589
Karl Schultzf78bcdd2016-11-30 12:36:01 -07006590 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00601);
Tony Barbour552f6c02016-12-21 14:34:07 -07006591 m_commandBuffer->BeginCommandBuffer();
6592 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006593 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, bad_pipeline);
Karl Schultzbdb75952016-04-19 11:36:49 -06006594 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12006595
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06006596 // Now issue a draw call with no pipeline bound
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006597 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 -06006598 Draw(1, 0, 0, 0);
6599 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12006600
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06006601 // Finally same check once more but with Dispatch/Compute
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006602 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 -07006603 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); // must be outside renderpass
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06006604 vkCmdDispatch(m_commandBuffer->GetBufferHandle(), 0, 0, 0);
6605 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06006606}
6607
Karl Schultz6addd812016-02-02 17:17:23 -07006608TEST_F(VkLayerTest, DescriptorSetNotUpdated) {
Tobin Ehlis5a5f5ef2016-08-17 13:56:55 -06006609 TEST_DESCRIPTION("Bind a descriptor set that hasn't been updated.");
Karl Schultz6addd812016-02-02 17:17:23 -07006610 VkResult err;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006611
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006612 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " bound but it was never updated. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006613
Tony Barbour1fa09702017-03-16 12:09:08 -06006614 ASSERT_NO_FATAL_FAILURE(Init());
Mike Stroyan713b2d72015-08-04 10:49:29 -06006615 ASSERT_NO_FATAL_FAILURE(InitViewport());
6616 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006617 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006618 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6619 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06006620
6621 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006622 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6623 ds_pool_ci.pNext = NULL;
6624 ds_pool_ci.maxSets = 1;
6625 ds_pool_ci.poolSizeCount = 1;
6626 ds_pool_ci.pPoolSizes = &ds_type_count;
Mike Stroyan713b2d72015-08-04 10:49:29 -06006627
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006628 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006629 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006630 ASSERT_VK_SUCCESS(err);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006631
Tony Barboureb254902015-07-15 12:50:33 -06006632 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006633 dsl_binding.binding = 0;
6634 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6635 dsl_binding.descriptorCount = 1;
6636 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6637 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006638
Tony Barboureb254902015-07-15 12:50:33 -06006639 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006640 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6641 ds_layout_ci.pNext = NULL;
6642 ds_layout_ci.bindingCount = 1;
6643 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006644 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006645 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006646 ASSERT_VK_SUCCESS(err);
6647
6648 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006649 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006650 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006651 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006652 alloc_info.descriptorPool = ds_pool;
6653 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006654 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006655 ASSERT_VK_SUCCESS(err);
6656
Tony Barboureb254902015-07-15 12:50:33 -06006657 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006658 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6659 pipeline_layout_ci.pNext = NULL;
6660 pipeline_layout_ci.setLayoutCount = 1;
6661 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006662
6663 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006664 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006665 ASSERT_VK_SUCCESS(err);
6666
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006667 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06006668 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07006669 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006670 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006671
Tony Barbourc95e4ac2015-08-04 17:05:26 -06006672 VkPipelineObj pipe(m_device);
6673 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06006674 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06006675 pipe.AddColorAttachment();
Tony Barbourc95e4ac2015-08-04 17:05:26 -06006676 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06006677
Tony Barbour552f6c02016-12-21 14:34:07 -07006678 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006679 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
6680 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6681 &descriptorSet, 0, NULL);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006682
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006683 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06006684
Chia-I Wuf7458c52015-10-26 21:10:41 +08006685 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6686 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6687 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006688}
6689
Karl Schultz6addd812016-02-02 17:17:23 -07006690TEST_F(VkLayerTest, InvalidBufferViewObject) {
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006691 // Create a single TEXEL_BUFFER descriptor and send it an invalid bufferView
Karl Schultz6addd812016-02-02 17:17:23 -07006692 VkResult err;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006693
Karl Schultzf78bcdd2016-11-30 12:36:01 -07006694 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00940);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006695
Tony Barbour1fa09702017-03-16 12:09:08 -06006696 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006697 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006698 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
6699 ds_type_count.descriptorCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006700
6701 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006702 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6703 ds_pool_ci.pNext = NULL;
6704 ds_pool_ci.maxSets = 1;
6705 ds_pool_ci.poolSizeCount = 1;
6706 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006707
6708 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006709 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006710 ASSERT_VK_SUCCESS(err);
6711
6712 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006713 dsl_binding.binding = 0;
6714 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
6715 dsl_binding.descriptorCount = 1;
6716 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6717 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006718
6719 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006720 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6721 ds_layout_ci.pNext = NULL;
6722 ds_layout_ci.bindingCount = 1;
6723 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006724 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006725 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006726 ASSERT_VK_SUCCESS(err);
6727
6728 VkDescriptorSet descriptorSet;
6729 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006730 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006731 alloc_info.descriptorSetCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006732 alloc_info.descriptorPool = ds_pool;
6733 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006734 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006735 ASSERT_VK_SUCCESS(err);
6736
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006737 VkBufferView view = (VkBufferView)((size_t)0xbaadbeef); // invalid bufferView object
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006738 VkWriteDescriptorSet descriptor_write;
6739 memset(&descriptor_write, 0, sizeof(descriptor_write));
6740 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6741 descriptor_write.dstSet = descriptorSet;
6742 descriptor_write.dstBinding = 0;
6743 descriptor_write.descriptorCount = 1;
6744 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
6745 descriptor_write.pTexelBufferView = &view;
6746
6747 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6748
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006749 m_errorMonitor->VerifyFound();
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006750
6751 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6752 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6753}
6754
Mark Youngd339ba32016-05-30 13:28:35 -06006755TEST_F(VkLayerTest, CreateBufferViewNoMemoryBoundToBuffer) {
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006756 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 -06006757
6758 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06006759 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006760 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -06006761
Tony Barbour1fa09702017-03-16 12:09:08 -06006762 ASSERT_NO_FATAL_FAILURE(Init());
Mark Youngd339ba32016-05-30 13:28:35 -06006763
6764 // Create a buffer with no bound memory and then attempt to create
6765 // a buffer view.
6766 VkBufferCreateInfo buff_ci = {};
6767 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes4538d242016-09-13 18:13:58 +12006768 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -06006769 buff_ci.size = 256;
6770 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
6771 VkBuffer buffer;
6772 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
6773 ASSERT_VK_SUCCESS(err);
6774
6775 VkBufferViewCreateInfo buff_view_ci = {};
6776 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
6777 buff_view_ci.buffer = buffer;
6778 buff_view_ci.format = VK_FORMAT_R8_UNORM;
6779 buff_view_ci.range = VK_WHOLE_SIZE;
6780 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006781 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Mark Youngd339ba32016-05-30 13:28:35 -06006782
6783 m_errorMonitor->VerifyFound();
6784 vkDestroyBuffer(m_device->device(), buffer, NULL);
6785 // If last error is success, it still created the view, so delete it.
6786 if (err == VK_SUCCESS) {
6787 vkDestroyBufferView(m_device->device(), buff_view, NULL);
6788 }
6789}
6790
Karl Schultz6addd812016-02-02 17:17:23 -07006791TEST_F(VkLayerTest, InvalidDynamicOffsetCases) {
6792 // Create a descriptorSet w/ dynamic descriptor and then hit 3 offset error
6793 // cases:
Tobin Ehlisf6585052015-12-17 11:48:42 -07006794 // 1. No dynamicOffset supplied
6795 // 2. Too many dynamicOffsets supplied
6796 // 3. Dynamic offset oversteps buffer being updated
Karl Schultz6addd812016-02-02 17:17:23 -07006797 VkResult err;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006798 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6799 " requires 1 dynamicOffsets, but only "
6800 "0 dynamicOffsets are left in "
6801 "pDynamicOffsets ");
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006802
Tony Barbour1fa09702017-03-16 12:09:08 -06006803 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006804 ASSERT_NO_FATAL_FAILURE(InitViewport());
6805 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6806
6807 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006808 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6809 ds_type_count.descriptorCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006810
6811 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006812 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6813 ds_pool_ci.pNext = NULL;
6814 ds_pool_ci.maxSets = 1;
6815 ds_pool_ci.poolSizeCount = 1;
6816 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006817
6818 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006819 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006820 ASSERT_VK_SUCCESS(err);
6821
6822 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006823 dsl_binding.binding = 0;
6824 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6825 dsl_binding.descriptorCount = 1;
6826 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6827 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006828
6829 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006830 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6831 ds_layout_ci.pNext = NULL;
6832 ds_layout_ci.bindingCount = 1;
6833 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006834 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006835 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006836 ASSERT_VK_SUCCESS(err);
6837
6838 VkDescriptorSet descriptorSet;
6839 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006840 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006841 alloc_info.descriptorSetCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006842 alloc_info.descriptorPool = ds_pool;
6843 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006844 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006845 ASSERT_VK_SUCCESS(err);
6846
6847 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006848 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6849 pipeline_layout_ci.pNext = NULL;
6850 pipeline_layout_ci.setLayoutCount = 1;
6851 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006852
6853 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006854 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006855 ASSERT_VK_SUCCESS(err);
6856
6857 // Create a buffer to update the descriptor with
6858 uint32_t qfi = 0;
6859 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006860 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6861 buffCI.size = 1024;
6862 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6863 buffCI.queueFamilyIndexCount = 1;
6864 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006865
6866 VkBuffer dyub;
6867 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6868 ASSERT_VK_SUCCESS(err);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006869 // Allocate memory and bind to buffer so we can make it to the appropriate
6870 // error
6871 VkMemoryAllocateInfo mem_alloc = {};
6872 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6873 mem_alloc.pNext = NULL;
6874 mem_alloc.allocationSize = 1024;
Chris Forbesb6116cc2016-05-08 11:39:59 +12006875 mem_alloc.memoryTypeIndex = 0;
6876
6877 VkMemoryRequirements memReqs;
6878 vkGetBufferMemoryRequirements(m_device->device(), dyub, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006879 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Chris Forbesb6116cc2016-05-08 11:39:59 +12006880 if (!pass) {
6881 vkDestroyBuffer(m_device->device(), dyub, NULL);
6882 return;
6883 }
6884
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006885 VkDeviceMemory mem;
6886 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
6887 ASSERT_VK_SUCCESS(err);
6888 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
6889 ASSERT_VK_SUCCESS(err);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006890 // Correctly update descriptor to avoid "NOT_UPDATED" error
6891 VkDescriptorBufferInfo buffInfo = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006892 buffInfo.buffer = dyub;
6893 buffInfo.offset = 0;
6894 buffInfo.range = 1024;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006895
6896 VkWriteDescriptorSet descriptor_write;
6897 memset(&descriptor_write, 0, sizeof(descriptor_write));
6898 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6899 descriptor_write.dstSet = descriptorSet;
6900 descriptor_write.dstBinding = 0;
6901 descriptor_write.descriptorCount = 1;
6902 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6903 descriptor_write.pBufferInfo = &buffInfo;
6904
6905 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6906
Tony Barbour552f6c02016-12-21 14:34:07 -07006907 m_commandBuffer->BeginCommandBuffer();
6908 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006909 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6910 &descriptorSet, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006911 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07006912 uint32_t pDynOff[2] = {512, 756};
6913 // Now cause error b/c too many dynOffsets in array for # of dyn descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006914 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6915 "Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but ");
6916 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6917 &descriptorSet, 2, pDynOff);
Chris Forbes7b342802016-04-07 13:20:10 +12006918 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07006919 // Finally cause error due to dynamicOffset being too big
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006920 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6921 " dynamic offset 512 combined with "
6922 "offset 0 and range 1024 that "
6923 "oversteps the buffer size of 1024");
Tobin Ehlisf6585052015-12-17 11:48:42 -07006924 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006925 char const *vsSource =
6926 "#version 450\n"
6927 "\n"
6928 "out gl_PerVertex { \n"
6929 " vec4 gl_Position;\n"
6930 "};\n"
6931 "void main(){\n"
6932 " gl_Position = vec4(1);\n"
6933 "}\n";
6934 char const *fsSource =
6935 "#version 450\n"
6936 "\n"
6937 "layout(location=0) out vec4 x;\n"
6938 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
6939 "void main(){\n"
6940 " x = vec4(bar.y);\n"
6941 "}\n";
Tobin Ehlisf6585052015-12-17 11:48:42 -07006942 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6943 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
6944 VkPipelineObj pipe(m_device);
6945 pipe.AddShader(&vs);
6946 pipe.AddShader(&fs);
6947 pipe.AddColorAttachment();
6948 pipe.CreateVKPipeline(pipeline_layout, renderPass());
6949
Rene Lindsayacbf5e62016-12-15 18:47:11 -07006950 VkViewport viewport = {0, 0, 16, 16, 0, 1};
6951 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
6952 VkRect2D scissor = {{0, 0}, {16, 16}};
6953 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
6954
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006955 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07006956 // This update should succeed, but offset size of 512 will overstep buffer
6957 // /w range 1024 & size 1024
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006958 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6959 &descriptorSet, 1, pDynOff);
Tobin Ehlisf6585052015-12-17 11:48:42 -07006960 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006961 m_errorMonitor->VerifyFound();
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006962
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006963 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis512098e2016-05-05 09:06:12 -06006964 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006965
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006966 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06006967 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006968 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6969}
6970
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006971TEST_F(VkLayerTest, DescriptorBufferUpdateNoMemoryBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006972 TEST_DESCRIPTION(
6973 "Attempt to update a descriptor with a non-sparse buffer "
6974 "that doesn't have memory bound");
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006975 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06006976 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006977 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Tobin Ehlisfed999f2016-09-21 15:09:45 -06006978 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6979 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006980
Tony Barbour1fa09702017-03-16 12:09:08 -06006981 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006982 ASSERT_NO_FATAL_FAILURE(InitViewport());
6983 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6984
6985 VkDescriptorPoolSize ds_type_count = {};
6986 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6987 ds_type_count.descriptorCount = 1;
6988
6989 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6990 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6991 ds_pool_ci.pNext = NULL;
6992 ds_pool_ci.maxSets = 1;
6993 ds_pool_ci.poolSizeCount = 1;
6994 ds_pool_ci.pPoolSizes = &ds_type_count;
6995
6996 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006997 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006998 ASSERT_VK_SUCCESS(err);
6999
7000 VkDescriptorSetLayoutBinding dsl_binding = {};
7001 dsl_binding.binding = 0;
7002 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
7003 dsl_binding.descriptorCount = 1;
7004 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7005 dsl_binding.pImmutableSamplers = NULL;
7006
7007 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7008 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7009 ds_layout_ci.pNext = NULL;
7010 ds_layout_ci.bindingCount = 1;
7011 ds_layout_ci.pBindings = &dsl_binding;
7012 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007013 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06007014 ASSERT_VK_SUCCESS(err);
7015
7016 VkDescriptorSet descriptorSet;
7017 VkDescriptorSetAllocateInfo alloc_info = {};
7018 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7019 alloc_info.descriptorSetCount = 1;
7020 alloc_info.descriptorPool = ds_pool;
7021 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007022 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06007023 ASSERT_VK_SUCCESS(err);
7024
7025 // Create a buffer to update the descriptor with
7026 uint32_t qfi = 0;
7027 VkBufferCreateInfo buffCI = {};
7028 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
7029 buffCI.size = 1024;
7030 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
7031 buffCI.queueFamilyIndexCount = 1;
7032 buffCI.pQueueFamilyIndices = &qfi;
7033
7034 VkBuffer dyub;
7035 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
7036 ASSERT_VK_SUCCESS(err);
7037
7038 // Attempt to update descriptor without binding memory to it
7039 VkDescriptorBufferInfo buffInfo = {};
7040 buffInfo.buffer = dyub;
7041 buffInfo.offset = 0;
7042 buffInfo.range = 1024;
7043
7044 VkWriteDescriptorSet descriptor_write;
7045 memset(&descriptor_write, 0, sizeof(descriptor_write));
7046 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
7047 descriptor_write.dstSet = descriptorSet;
7048 descriptor_write.dstBinding = 0;
7049 descriptor_write.descriptorCount = 1;
7050 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
7051 descriptor_write.pBufferInfo = &buffInfo;
7052
7053 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
7054 m_errorMonitor->VerifyFound();
7055
7056 vkDestroyBuffer(m_device->device(), dyub, NULL);
7057 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7058 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
7059}
7060
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07007061TEST_F(VkLayerTest, InvalidPushConstants) {
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07007062 VkResult err;
Tony Barbour1fa09702017-03-16 12:09:08 -06007063 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07007064 ASSERT_NO_FATAL_FAILURE(InitViewport());
7065 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7066
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007067 VkPipelineLayout pipeline_layout;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07007068 VkPushConstantRange pc_range = {};
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07007069 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7070 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7071 pipeline_layout_ci.pushConstantRangeCount = 1;
7072 pipeline_layout_ci.pPushConstantRanges = &pc_range;
7073
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007074 //
7075 // Check for invalid push constant ranges in pipeline layouts.
7076 //
7077 struct PipelineLayoutTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06007078 VkPushConstantRange const range;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007079 char const *msg;
7080 };
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07007081
Karl Schultzc81037d2016-05-12 08:11:23 -06007082 const uint32_t too_big = m_device->props.limits.maxPushConstantsSize + 0x4;
7083 const std::array<PipelineLayoutTestCase, 10> range_tests = {{
7084 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0},
7085 "vkCreatePipelineLayout() call has push constants index 0 with "
7086 "size 0."},
7087 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
7088 "vkCreatePipelineLayout() call has push constants index 0 with "
7089 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06007090 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Karl Schultzc81037d2016-05-12 08:11:23 -06007091 "vkCreatePipelineLayout() call has push constants index 0 with "
7092 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06007093 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 0},
Karl Schultzc81037d2016-05-12 08:11:23 -06007094 "vkCreatePipelineLayout() call has push constants index 0 with "
7095 "size 0."},
7096 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
7097 "vkCreatePipelineLayout() call has push constants index 0 with "
7098 "offset 1. Offset must"},
7099 {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big},
7100 "vkCreatePipelineLayout() call has push constants index 0 "
7101 "with offset "},
7102 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big},
7103 "vkCreatePipelineLayout() call has push constants "
7104 "index 0 with offset "},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06007105 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06007106 "vkCreatePipelineLayout() call has push constants index 0 "
7107 "with offset "},
7108 {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020},
7109 "vkCreatePipelineLayout() call has push "
7110 "constants index 0 with offset "},
7111 {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0},
7112 "vkCreatePipelineLayout() call has push "
7113 "constants index 0 with offset "},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007114 }};
7115
7116 // Check for invalid offset and size
Karl Schultzc81037d2016-05-12 08:11:23 -06007117 for (const auto &iter : range_tests) {
7118 pc_range = iter.range;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007119 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
7120 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007121 m_errorMonitor->VerifyFound();
7122 if (VK_SUCCESS == err) {
7123 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7124 }
7125 }
7126
7127 // Check for invalid stage flag
7128 pc_range.offset = 0;
7129 pc_range.size = 16;
7130 pc_range.stageFlags = 0;
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06007131 m_errorMonitor->SetDesiredFailureMsg(
7132 VK_DEBUG_REPORT_ERROR_BIT_EXT,
7133 "vkCreatePipelineLayout: value of pCreateInfo->pPushConstantRanges[0].stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007134 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007135 m_errorMonitor->VerifyFound();
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007136 if (VK_SUCCESS == err) {
7137 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7138 }
7139
Karl Schultzc59b72d2017-02-24 15:45:05 -07007140 // Check for duplicate stage flags in a list of push constant ranges.
7141 // A shader can only have one push constant block and that block is mapped
7142 // to the push constant range that has that shader's stage flag set.
7143 // The shader's stage flag can only appear once in all the ranges, so the
7144 // implementation can find the one and only range to map it to.
Karl Schultzc81037d2016-05-12 08:11:23 -06007145 const uint32_t ranges_per_test = 5;
Karl Schultzc59b72d2017-02-24 15:45:05 -07007146 struct DuplicateStageFlagsTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06007147 VkPushConstantRange const ranges[ranges_per_test];
Jeremy Hayesde6d96c2017-02-01 15:22:32 -07007148 std::vector<char const *> const msg;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007149 };
Karl Schultzc59b72d2017-02-24 15:45:05 -07007150 // Overlapping ranges are OK, but a stage flag can appear only once.
7151 const std::array<DuplicateStageFlagsTestCase, 3> duplicate_stageFlags_tests = {
7152 {
7153 {{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
7154 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
7155 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
7156 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007157 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzc59b72d2017-02-24 15:45:05 -07007158 {
7159 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 0 and 1.",
7160 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 0 and 2.",
7161 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 0 and 3.",
7162 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 0 and 4.",
7163 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 1 and 2.",
7164 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 1 and 3.",
7165 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 1 and 4.",
7166 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 2 and 3.",
7167 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 2 and 4.",
7168 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 3 and 4.",
7169 }},
7170 {{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
7171 {VK_SHADER_STAGE_GEOMETRY_BIT, 0, 4},
7172 {VK_SHADER_STAGE_FRAGMENT_BIT, 0, 4},
7173 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
7174 {VK_SHADER_STAGE_GEOMETRY_BIT, 0, 4}},
7175 {
7176 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 0 and 3.",
7177 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 1 and 4.",
7178 }},
7179 {{{VK_SHADER_STAGE_FRAGMENT_BIT, 0, 4},
7180 {VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 4},
7181 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
7182 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
7183 {VK_SHADER_STAGE_GEOMETRY_BIT, 0, 4}},
7184 {
7185 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 2 and 3.",
7186 }},
7187 },
7188 };
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007189
Karl Schultzc59b72d2017-02-24 15:45:05 -07007190 for (const auto &iter : duplicate_stageFlags_tests) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007191 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
Karl Schultzc81037d2016-05-12 08:11:23 -06007192 pipeline_layout_ci.pushConstantRangeCount = ranges_per_test;
Karl Schultzc59b72d2017-02-24 15:45:05 -07007193 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg.begin(), iter.msg.end());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007194 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007195 m_errorMonitor->VerifyFound();
7196 if (VK_SUCCESS == err) {
7197 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7198 }
7199 }
7200
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007201 //
7202 // CmdPushConstants tests
7203 //
7204
Karl Schultzc59b72d2017-02-24 15:45:05 -07007205 // Setup a pipeline layout with ranges: [0,16) [64,80)
Karl Schultzc81037d2016-05-12 08:11:23 -06007206 const VkPushConstantRange pc_range2[] = {
Karl Schultzc59b72d2017-02-24 15:45:05 -07007207 {VK_SHADER_STAGE_VERTEX_BIT, 64, 16}, {VK_SHADER_STAGE_FRAGMENT_BIT, 0, 16},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007208 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007209 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range2) / sizeof(VkPushConstantRange);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007210 pipeline_layout_ci.pPushConstantRanges = pc_range2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007211 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07007212 ASSERT_VK_SUCCESS(err);
Karl Schultzc59b72d2017-02-24 15:45:05 -07007213
7214 const uint8_t dummy_values[100] = {};
7215
7216 m_commandBuffer->BeginCommandBuffer();
7217 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007218
7219 // Check for invalid stage flag
Karl Schultzc59b72d2017-02-24 15:45:05 -07007220 // Note that VU 00996 isn't reached due to parameter validation
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06007221 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdPushConstants: value of stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007222 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, 0, 0, 16, dummy_values);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007223 m_errorMonitor->VerifyFound();
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007224
Karl Schultzc59b72d2017-02-24 15:45:05 -07007225 m_errorMonitor->ExpectSuccess();
7226 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, VK_SHADER_STAGE_FRAGMENT_BIT, 0, 16, dummy_values);
7227 m_errorMonitor->VerifyNotFound();
7228 m_errorMonitor->ExpectSuccess();
7229 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, VK_SHADER_STAGE_VERTEX_BIT, 64, 16, dummy_values);
7230 m_errorMonitor->VerifyNotFound();
7231 const std::array<VkPushConstantRange, 6> cmd_range_tests = {{
7232 {VK_SHADER_STAGE_FRAGMENT_BIT, 64, 16},
7233 {VK_SHADER_STAGE_VERTEX_BIT, 0, 16},
7234 {VK_SHADER_STAGE_GEOMETRY_BIT, 0, 16},
7235 {VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT, 0, 16},
7236 {VK_SHADER_STAGE_VERTEX_BIT, 24, 16},
7237 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06007238 }};
Karl Schultzc59b72d2017-02-24 15:45:05 -07007239 for (const auto &iter : cmd_range_tests) {
7240 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00988);
7241 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.stageFlags, iter.offset, iter.size,
7242 dummy_values);
Karl Schultzc81037d2016-05-12 08:11:23 -06007243 m_errorMonitor->VerifyFound();
7244 }
Karl Schultzc81037d2016-05-12 08:11:23 -06007245
Tony Barbour552f6c02016-12-21 14:34:07 -07007246 m_commandBuffer->EndRenderPass();
7247 m_commandBuffer->EndCommandBuffer();
Karl Schultzc59b72d2017-02-24 15:45:05 -07007248 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07007249}
7250
Karl Schultz6addd812016-02-02 17:17:23 -07007251TEST_F(VkLayerTest, DescriptorSetCompatibility) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07007252 // Test various desriptorSet errors with bad binding combinations
Karl Schultz6addd812016-02-02 17:17:23 -07007253 VkResult err;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007254
Tony Barbour1fa09702017-03-16 12:09:08 -06007255 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis559c6382015-11-05 09:52:49 -07007256 ASSERT_NO_FATAL_FAILURE(InitViewport());
7257 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7258
7259 static const uint32_t NUM_DESCRIPTOR_TYPES = 5;
7260 VkDescriptorPoolSize ds_type_count[NUM_DESCRIPTOR_TYPES] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007261 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7262 ds_type_count[0].descriptorCount = 10;
7263 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
7264 ds_type_count[1].descriptorCount = 2;
7265 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
7266 ds_type_count[2].descriptorCount = 2;
7267 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_SAMPLER;
7268 ds_type_count[3].descriptorCount = 5;
7269 // TODO : LunarG ILO driver currently asserts in desc.c w/ INPUT_ATTACHMENT
7270 // type
7271 // ds_type_count[4].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
7272 ds_type_count[4].type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
7273 ds_type_count[4].descriptorCount = 2;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007274
7275 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007276 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7277 ds_pool_ci.pNext = NULL;
7278 ds_pool_ci.maxSets = 5;
7279 ds_pool_ci.poolSizeCount = NUM_DESCRIPTOR_TYPES;
7280 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007281
7282 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007283 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007284 ASSERT_VK_SUCCESS(err);
7285
7286 static const uint32_t MAX_DS_TYPES_IN_LAYOUT = 2;
7287 VkDescriptorSetLayoutBinding dsl_binding[MAX_DS_TYPES_IN_LAYOUT] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007288 dsl_binding[0].binding = 0;
7289 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7290 dsl_binding[0].descriptorCount = 5;
7291 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
7292 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007293
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007294 // Create layout identical to set0 layout but w/ different stageFlags
7295 VkDescriptorSetLayoutBinding dsl_fs_stage_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007296 dsl_fs_stage_only.binding = 0;
7297 dsl_fs_stage_only.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7298 dsl_fs_stage_only.descriptorCount = 5;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007299 dsl_fs_stage_only.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; // Different stageFlags to cause error at
7300 // bind time
Karl Schultz6addd812016-02-02 17:17:23 -07007301 dsl_fs_stage_only.pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007302 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007303 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7304 ds_layout_ci.pNext = NULL;
7305 ds_layout_ci.bindingCount = 1;
7306 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007307 static const uint32_t NUM_LAYOUTS = 4;
7308 VkDescriptorSetLayout ds_layout[NUM_LAYOUTS] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007309 VkDescriptorSetLayout ds_layout_fs_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007310 // Create 4 unique layouts for full pipelineLayout, and 1 special fs-only
7311 // layout for error case
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007312 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[0]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007313 ASSERT_VK_SUCCESS(err);
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07007314 ds_layout_ci.pBindings = &dsl_fs_stage_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007315 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007316 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007317 dsl_binding[0].binding = 0;
7318 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007319 dsl_binding[0].descriptorCount = 2;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07007320 dsl_binding[1].binding = 1;
7321 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
7322 dsl_binding[1].descriptorCount = 2;
7323 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
7324 dsl_binding[1].pImmutableSamplers = NULL;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07007325 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007326 ds_layout_ci.bindingCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007327 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[1]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007328 ASSERT_VK_SUCCESS(err);
7329 dsl_binding[0].binding = 0;
7330 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007331 dsl_binding[0].descriptorCount = 5;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007332 ds_layout_ci.bindingCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007333 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[2]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007334 ASSERT_VK_SUCCESS(err);
7335 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007336 dsl_binding[0].descriptorCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007337 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[3]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007338 ASSERT_VK_SUCCESS(err);
7339
7340 static const uint32_t NUM_SETS = 4;
7341 VkDescriptorSet descriptorSet[NUM_SETS] = {};
7342 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007343 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007344 alloc_info.descriptorSetCount = NUM_LAYOUTS;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007345 alloc_info.descriptorPool = ds_pool;
7346 alloc_info.pSetLayouts = ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007347 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptorSet);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007348 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007349 VkDescriptorSet ds0_fs_only = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07007350 alloc_info.descriptorSetCount = 1;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007351 alloc_info.pSetLayouts = &ds_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007352 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &ds0_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007353 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007354
7355 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007356 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7357 pipeline_layout_ci.pNext = NULL;
7358 pipeline_layout_ci.setLayoutCount = NUM_LAYOUTS;
7359 pipeline_layout_ci.pSetLayouts = ds_layout;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007360
7361 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007362 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007363 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007364 // Create pipelineLayout with only one setLayout
7365 pipeline_layout_ci.setLayoutCount = 1;
7366 VkPipelineLayout single_pipe_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007367 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &single_pipe_layout);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007368 ASSERT_VK_SUCCESS(err);
7369 // Create pipelineLayout with 2 descriptor setLayout at index 0
7370 pipeline_layout_ci.pSetLayouts = &ds_layout[3];
7371 VkPipelineLayout pipe_layout_one_desc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007372 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_one_desc);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007373 ASSERT_VK_SUCCESS(err);
7374 // Create pipelineLayout with 5 SAMPLER descriptor setLayout at index 0
7375 pipeline_layout_ci.pSetLayouts = &ds_layout[2];
7376 VkPipelineLayout pipe_layout_five_samp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007377 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_five_samp);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007378 ASSERT_VK_SUCCESS(err);
7379 // Create pipelineLayout with UB type, but stageFlags for FS only
7380 pipeline_layout_ci.pSetLayouts = &ds_layout_fs_only;
7381 VkPipelineLayout pipe_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007382 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007383 ASSERT_VK_SUCCESS(err);
7384 // Create pipelineLayout w/ incompatible set0 layout, but set1 is fine
7385 VkDescriptorSetLayout pl_bad_s0[2] = {};
7386 pl_bad_s0[0] = ds_layout_fs_only;
7387 pl_bad_s0[1] = ds_layout[1];
7388 pipeline_layout_ci.setLayoutCount = 2;
7389 pipeline_layout_ci.pSetLayouts = pl_bad_s0;
7390 VkPipelineLayout pipe_layout_bad_set0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007391 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_bad_set0);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007392 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007393
Tobin Ehlis88452832015-12-03 09:40:56 -07007394 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007395 char const *vsSource =
7396 "#version 450\n"
7397 "\n"
7398 "out gl_PerVertex {\n"
7399 " vec4 gl_Position;\n"
7400 "};\n"
7401 "void main(){\n"
7402 " gl_Position = vec4(1);\n"
7403 "}\n";
7404 char const *fsSource =
7405 "#version 450\n"
7406 "\n"
7407 "layout(location=0) out vec4 x;\n"
7408 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
7409 "void main(){\n"
7410 " x = vec4(bar.y);\n"
7411 "}\n";
Tobin Ehlis88452832015-12-03 09:40:56 -07007412 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
7413 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007414 VkPipelineObj pipe(m_device);
7415 pipe.AddShader(&vs);
7416 pipe.AddShader(&fs);
Tobin Ehlis88452832015-12-03 09:40:56 -07007417 pipe.AddColorAttachment();
7418 pipe.CreateVKPipeline(pipe_layout_fs_only, renderPass());
Tobin Ehlis559c6382015-11-05 09:52:49 -07007419
Tony Barbour552f6c02016-12-21 14:34:07 -07007420 m_commandBuffer->BeginCommandBuffer();
7421 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis88452832015-12-03 09:40:56 -07007422
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007423 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07007424 // NOTE : I believe LunarG ilo driver has bug (LX#189) that requires binding
7425 // of PSO
7426 // here before binding DSs. Otherwise we assert in cmd_copy_dset_data() of
7427 // cmd_pipeline.c
7428 // due to the fact that cmd_alloc_dset_data() has not been called in
7429 // cmd_bind_graphics_pipeline()
7430 // TODO : Want to cause various binding incompatibility issues here to test
7431 // DrawState
Tobin Ehlis559c6382015-11-05 09:52:49 -07007432 // First cause various verify_layout_compatibility() fails
7433 // Second disturb early and late sets and verify INFO msgs
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007434 // verify_set_layout_compatibility fail cases:
7435 // 1. invalid VkPipelineLayout (layout) passed into vkCmdBindDescriptorSets
Karl Schultzf78bcdd2016-11-30 12:36:01 -07007436 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00981);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007437 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
7438 (VkPipelineLayout)((size_t)0xbaadb1be), 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007439 m_errorMonitor->VerifyFound();
7440
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007441 // 2. layoutIndex exceeds # of layouts in layout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007442 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempting to bind set to index 1");
7443 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, single_pipe_layout, 0, 2,
7444 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007445 m_errorMonitor->VerifyFound();
7446
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007447 vkDestroyPipelineLayout(m_device->device(), single_pipe_layout, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07007448 // 3. Pipeline setLayout[0] has 2 descriptors, but set being bound has 5
7449 // descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007450 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has 2 descriptors, but DescriptorSetLayout ");
7451 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_one_desc, 0, 1,
7452 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007453 m_errorMonitor->VerifyFound();
7454
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007455 vkDestroyPipelineLayout(m_device->device(), pipe_layout_one_desc, NULL);
7456 // 4. same # of descriptors but mismatch in type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007457 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is type 'VK_DESCRIPTOR_TYPE_SAMPLER' but binding ");
7458 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_five_samp, 0, 1,
7459 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007460 m_errorMonitor->VerifyFound();
7461
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007462 vkDestroyPipelineLayout(m_device->device(), pipe_layout_five_samp, NULL);
7463 // 5. same # of descriptors but mismatch in stageFlags
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007464 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7465 " has stageFlags 16 but binding 0 for DescriptorSetLayout ");
7466 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
7467 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007468 m_errorMonitor->VerifyFound();
7469
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007470 // Cause INFO messages due to disturbing previously bound Sets
7471 // First bind sets 0 & 1
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007472 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
7473 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007474 // 1. Disturb bound set0 by re-binding set1 w/ updated pipelineLayout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007475 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " previously bound as set #0 was disturbed ");
7476 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
7477 &descriptorSet[1], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007478 m_errorMonitor->VerifyFound();
7479
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007480 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
7481 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007482 // 2. Disturb set after last bound set
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007483 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
7484 " newly bound as set #0 so set #1 and "
7485 "any subsequent sets were disturbed ");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007486 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
7487 &ds0_fs_only, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007488 m_errorMonitor->VerifyFound();
7489
Tobin Ehlis10fad692016-07-07 12:00:36 -06007490 // Now that we're done actively using the pipelineLayout that gfx pipeline
7491 // was created with, we should be able to delete it. Do that now to verify
7492 // that validation obeys pipelineLayout lifetime
7493 vkDestroyPipelineLayout(m_device->device(), pipe_layout_fs_only, NULL);
7494
Tobin Ehlis88452832015-12-03 09:40:56 -07007495 // Cause draw-time errors due to PSO incompatibilities
Karl Schultz6addd812016-02-02 17:17:23 -07007496 // 1. Error due to not binding required set (we actually use same code as
7497 // above to disturb set0)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007498 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
7499 &descriptorSet[0], 0, NULL);
7500 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
7501 &descriptorSet[1], 0, NULL);
7502 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 -07007503
7504 VkViewport viewport = {0, 0, 16, 16, 0, 1};
7505 VkRect2D scissor = {{0, 0}, {16, 16}};
7506 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
7507 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
7508
Tobin Ehlis88452832015-12-03 09:40:56 -07007509 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007510 m_errorMonitor->VerifyFound();
7511
Tobin Ehlis991d45a2016-01-06 08:48:41 -07007512 vkDestroyPipelineLayout(m_device->device(), pipe_layout_bad_set0, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07007513 // 2. Error due to bound set not being compatible with PSO's
7514 // VkPipelineLayout (diff stageFlags in this case)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007515 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
7516 &descriptorSet[0], 0, NULL);
7517 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " bound as set #0 is not compatible with ");
Tobin Ehlis88452832015-12-03 09:40:56 -07007518 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007519 m_errorMonitor->VerifyFound();
7520
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007521 // Remaining clean-up
Karl Schultz6addd812016-02-02 17:17:23 -07007522 for (uint32_t i = 0; i < NUM_LAYOUTS; ++i) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007523 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout[i], NULL);
7524 }
7525 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_fs_only, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007526 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7527 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
7528}
Tobin Ehlis559c6382015-11-05 09:52:49 -07007529
Karl Schultz6addd812016-02-02 17:17:23 -07007530TEST_F(VkLayerTest, NoBeginCommandBuffer) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007531 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7532 "You must call vkBeginCommandBuffer() before this call to ");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007533
Tony Barbour1fa09702017-03-16 12:09:08 -06007534 ASSERT_NO_FATAL_FAILURE(Init());
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007535 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007536 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007537 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007538
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007539 m_errorMonitor->VerifyFound();
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007540}
7541
Karl Schultz6addd812016-02-02 17:17:23 -07007542TEST_F(VkLayerTest, SecondaryCommandBufferNullRenderpass) {
7543 VkResult err;
7544 VkCommandBuffer draw_cmd;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007545
Karl Schultzf78bcdd2016-11-30 12:36:01 -07007546 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00110);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007547
Tony Barbour1fa09702017-03-16 12:09:08 -06007548 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06007549
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007550 VkCommandBufferAllocateInfo cmd = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007551 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06007552 cmd.pNext = NULL;
Mike Schuchardt06304c22017-03-01 17:09:09 -07007553 cmd.commandPool = m_commandPool->handle();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007554 cmd.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007555 cmd.commandBufferCount = 1;
Cody Northropb4569702015-08-04 17:35:57 -06007556
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007557 err = vkAllocateCommandBuffers(m_device->device(), &cmd, &draw_cmd);
Mike Stroyand1c84a52015-08-18 14:40:24 -06007558 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06007559
7560 // Force the failure by not setting the Renderpass and Framebuffer fields
Jon Ashburnf19916e2016-01-11 13:12:43 -07007561 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Rene Lindsay65072a92017-01-23 11:38:10 -07007562 cmd_buf_hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
7563
7564 VkCommandBufferBeginInfo cmd_buf_info = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007565 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06007566 cmd_buf_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007567 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 -07007568 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06007569
7570 // The error should be caught by validation of the BeginCommandBuffer call
7571 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
7572
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007573 m_errorMonitor->VerifyFound();
Mike Schuchardt06304c22017-03-01 17:09:09 -07007574 vkFreeCommandBuffers(m_device->device(), m_commandPool->handle(), 1, &draw_cmd);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06007575}
7576
Karl Schultz6addd812016-02-02 17:17:23 -07007577TEST_F(VkLayerTest, CommandBufferResetErrors) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007578 // Cause error due to Begin while recording CB
7579 // Then cause 2 errors for attempting to reset CB w/o having
7580 // VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT set for the pool from
7581 // which CBs were allocated. Note that this bit is off by default.
Mike Weiblencce7ec72016-10-17 19:33:05 -06007582 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call Begin on command buffer");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007583
Tony Barbour1fa09702017-03-16 12:09:08 -06007584 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007585
7586 // Calls AllocateCommandBuffers
7587 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
7588
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07007589 // Force the failure by setting the Renderpass and Framebuffer fields with (fake) data
Jon Ashburnf19916e2016-01-11 13:12:43 -07007590 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07007591 cmd_buf_hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
7592 VkCommandBufferBeginInfo cmd_buf_info = {};
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007593 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
7594 cmd_buf_info.pNext = NULL;
7595 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007596 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007597
7598 // Begin CB to transition to recording state
7599 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
7600 // Can't re-begin. This should trigger error
7601 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007602 m_errorMonitor->VerifyFound();
7603
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07007604 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00093);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007605 VkCommandBufferResetFlags flags = 0; // Don't care about flags for this test
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007606 // Reset attempt will trigger error due to incorrect CommandPool state
7607 vkResetCommandBuffer(commandBuffer.GetBufferHandle(), flags);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007608 m_errorMonitor->VerifyFound();
7609
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07007610 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00105);
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007611 // Transition CB to RECORDED state
7612 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
7613 // Now attempting to Begin will implicitly reset, which triggers error
7614 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007615 m_errorMonitor->VerifyFound();
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007616}
7617
Karl Schultz6addd812016-02-02 17:17:23 -07007618TEST_F(VkLayerTest, InvalidPipelineCreateState) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007619 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07007620 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007621
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07007622 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7623 "Invalid Pipeline CreateInfo State: Vertex Shader required");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007624
Tony Barbour1fa09702017-03-16 12:09:08 -06007625 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06007626 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06007627
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007628 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007629 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7630 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06007631
7632 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007633 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7634 ds_pool_ci.pNext = NULL;
7635 ds_pool_ci.maxSets = 1;
7636 ds_pool_ci.poolSizeCount = 1;
7637 ds_pool_ci.pPoolSizes = &ds_type_count;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06007638
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007639 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007640 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007641 ASSERT_VK_SUCCESS(err);
7642
Tony Barboureb254902015-07-15 12:50:33 -06007643 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007644 dsl_binding.binding = 0;
7645 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7646 dsl_binding.descriptorCount = 1;
7647 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7648 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007649
Tony Barboureb254902015-07-15 12:50:33 -06007650 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007651 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7652 ds_layout_ci.pNext = NULL;
7653 ds_layout_ci.bindingCount = 1;
7654 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06007655
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007656 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007657 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007658 ASSERT_VK_SUCCESS(err);
7659
7660 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007661 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007662 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007663 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007664 alloc_info.descriptorPool = ds_pool;
7665 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007666 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007667 ASSERT_VK_SUCCESS(err);
7668
Tony Barboureb254902015-07-15 12:50:33 -06007669 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007670 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7671 pipeline_layout_ci.setLayoutCount = 1;
7672 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007673
7674 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007675 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007676 ASSERT_VK_SUCCESS(err);
7677
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007678 VkViewport vp = {}; // Just need dummy vp to point to
7679 VkRect2D sc = {}; // dummy scissor to point to
Tobin Ehlise68360f2015-10-01 11:15:13 -06007680
7681 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007682 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7683 vp_state_ci.scissorCount = 1;
7684 vp_state_ci.pScissors = &sc;
7685 vp_state_ci.viewportCount = 1;
7686 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007687
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007688 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7689 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7690 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7691 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7692 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7693 rs_state_ci.depthClampEnable = VK_FALSE;
Rene Lindsayae4977b2017-01-23 14:55:54 -07007694 rs_state_ci.rasterizerDiscardEnable = VK_TRUE;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007695 rs_state_ci.depthBiasEnable = VK_FALSE;
Rene Lindsayae4977b2017-01-23 14:55:54 -07007696 rs_state_ci.lineWidth = 1.0f;
7697
7698 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7699 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7700 vi_ci.pNext = nullptr;
7701 vi_ci.vertexBindingDescriptionCount = 0;
7702 vi_ci.pVertexBindingDescriptions = nullptr;
7703 vi_ci.vertexAttributeDescriptionCount = 0;
7704 vi_ci.pVertexAttributeDescriptions = nullptr;
7705
7706 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7707 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7708 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7709
7710 VkPipelineShaderStageCreateInfo shaderStages[2];
7711 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7712
7713 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7714 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Dave Houlton59a20702017-02-02 17:26:23 -07007715 shaderStages[0] = fs.GetStageCreateInfo(); // should be: vs.GetStageCreateInfo();
Rene Lindsayae4977b2017-01-23 14:55:54 -07007716 shaderStages[1] = fs.GetStageCreateInfo();
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007717
Tony Barboureb254902015-07-15 12:50:33 -06007718 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007719 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7720 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007721 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007722 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7723 gp_ci.layout = pipeline_layout;
7724 gp_ci.renderPass = renderPass();
Rene Lindsayae4977b2017-01-23 14:55:54 -07007725 gp_ci.pVertexInputState = &vi_ci;
7726 gp_ci.pInputAssemblyState = &ia_ci;
7727
7728 gp_ci.stageCount = 1;
7729 gp_ci.pStages = shaderStages;
Tony Barboureb254902015-07-15 12:50:33 -06007730
7731 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007732 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7733 pc_ci.initialDataSize = 0;
7734 pc_ci.pInitialData = 0;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007735
7736 VkPipeline pipeline;
Jon Ashburnc669cc62015-07-09 15:02:25 -06007737 VkPipelineCache pipelineCache;
7738
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007739 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Jon Ashburnc669cc62015-07-09 15:02:25 -06007740 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007741 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007742 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007743
Chia-I Wuf7458c52015-10-26 21:10:41 +08007744 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7745 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7746 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7747 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007748}
Rene Lindsayae4977b2017-01-23 14:55:54 -07007749
Tobin Ehlis912df022015-09-17 08:46:18 -06007750/*// TODO : This test should be good, but needs Tess support in compiler to run
7751TEST_F(VkLayerTest, InvalidPatchControlPoints)
7752{
7753 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis912df022015-09-17 08:46:18 -06007754 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007755
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07007756 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07007757 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH
7758primitive ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007759
Tony Barbour1fa09702017-03-16 12:09:08 -06007760 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis912df022015-09-17 08:46:18 -06007761 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis912df022015-09-17 08:46:18 -06007762
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007763 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis912df022015-09-17 08:46:18 -06007764 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007765 ds_type_count.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007766
7767 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7768 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7769 ds_pool_ci.pNext = NULL;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007770 ds_pool_ci.poolSizeCount = 1;
7771 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis912df022015-09-17 08:46:18 -06007772
7773 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07007774 err = vkCreateDescriptorPool(m_device->device(),
7775VK_DESCRIPTOR_POOL_USAGE_NON_FREE, 1, &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis912df022015-09-17 08:46:18 -06007776 ASSERT_VK_SUCCESS(err);
7777
7778 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08007779 dsl_binding.binding = 0;
Tobin Ehlis912df022015-09-17 08:46:18 -06007780 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08007781 dsl_binding.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007782 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7783 dsl_binding.pImmutableSamplers = NULL;
7784
7785 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007786 ds_layout_ci.sType =
7787VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06007788 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007789 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07007790 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis912df022015-09-17 08:46:18 -06007791
7792 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007793 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
7794&ds_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06007795 ASSERT_VK_SUCCESS(err);
7796
7797 VkDescriptorSet descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07007798 err = vkAllocateDescriptorSets(m_device->device(), ds_pool,
7799VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet);
Tobin Ehlis912df022015-09-17 08:46:18 -06007800 ASSERT_VK_SUCCESS(err);
7801
7802 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007803 pipeline_layout_ci.sType =
7804VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06007805 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007806 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007807 pipeline_layout_ci.pSetLayouts = &ds_layout;
7808
7809 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007810 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
7811&pipeline_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06007812 ASSERT_VK_SUCCESS(err);
7813
7814 VkPipelineShaderStageCreateInfo shaderStages[3];
7815 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
7816
Karl Schultz6addd812016-02-02 17:17:23 -07007817 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT,
7818this);
Tobin Ehlis912df022015-09-17 08:46:18 -06007819 // Just using VS txt for Tess shaders as we don't care about functionality
Karl Schultz6addd812016-02-02 17:17:23 -07007820 VkShaderObj
7821tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
7822this);
7823 VkShaderObj
7824te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT,
7825this);
Tobin Ehlis912df022015-09-17 08:46:18 -06007826
Karl Schultz6addd812016-02-02 17:17:23 -07007827 shaderStages[0].sType =
7828VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007829 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007830 shaderStages[0].shader = vs.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07007831 shaderStages[1].sType =
7832VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007833 shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007834 shaderStages[1].shader = tc.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07007835 shaderStages[2].sType =
7836VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007837 shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007838 shaderStages[2].shader = te.handle();
7839
7840 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007841 iaCI.sType =
7842VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Chia-I Wu515eb8f2015-10-31 00:31:16 +08007843 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST;
Tobin Ehlis912df022015-09-17 08:46:18 -06007844
7845 VkPipelineTessellationStateCreateInfo tsCI = {};
7846 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
7847 tsCI.patchControlPoints = 0; // This will cause an error
7848
7849 VkGraphicsPipelineCreateInfo gp_ci = {};
7850 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7851 gp_ci.pNext = NULL;
7852 gp_ci.stageCount = 3;
7853 gp_ci.pStages = shaderStages;
7854 gp_ci.pVertexInputState = NULL;
7855 gp_ci.pInputAssemblyState = &iaCI;
7856 gp_ci.pTessellationState = &tsCI;
7857 gp_ci.pViewportState = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007858 gp_ci.pRasterizationState = NULL;
Tobin Ehlis912df022015-09-17 08:46:18 -06007859 gp_ci.pMultisampleState = NULL;
7860 gp_ci.pDepthStencilState = NULL;
7861 gp_ci.pColorBlendState = NULL;
7862 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7863 gp_ci.layout = pipeline_layout;
7864 gp_ci.renderPass = renderPass();
7865
7866 VkPipelineCacheCreateInfo pc_ci = {};
7867 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7868 pc_ci.pNext = NULL;
7869 pc_ci.initialSize = 0;
7870 pc_ci.initialData = 0;
7871 pc_ci.maxSize = 0;
7872
7873 VkPipeline pipeline;
7874 VkPipelineCache pipelineCache;
7875
Karl Schultz6addd812016-02-02 17:17:23 -07007876 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL,
7877&pipelineCache);
Tobin Ehlis912df022015-09-17 08:46:18 -06007878 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07007879 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
7880&gp_ci, NULL, &pipeline);
Tobin Ehlis912df022015-09-17 08:46:18 -06007881
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007882 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007883
Chia-I Wuf7458c52015-10-26 21:10:41 +08007884 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7885 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7886 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7887 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis912df022015-09-17 08:46:18 -06007888}
7889*/
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007890
Mark Lobodzinski510aa5c2016-12-19 07:59:10 -07007891TEST_F(VkLayerTest, PSOViewportScissorCountTests) {
Karl Schultz6addd812016-02-02 17:17:23 -07007892 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007893
Mark Lobodzinski510aa5c2016-12-19 07:59:10 -07007894 TEST_DESCRIPTION("Test various cases of viewport and scissor count validation");
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007895
Tony Barbour1fa09702017-03-16 12:09:08 -06007896 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007897 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007898
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007899 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007900 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7901 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007902
7903 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007904 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7905 ds_pool_ci.maxSets = 1;
7906 ds_pool_ci.poolSizeCount = 1;
7907 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007908
7909 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007910 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007911 ASSERT_VK_SUCCESS(err);
7912
7913 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007914 dsl_binding.binding = 0;
7915 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7916 dsl_binding.descriptorCount = 1;
7917 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007918
7919 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007920 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7921 ds_layout_ci.bindingCount = 1;
7922 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007923
7924 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007925 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007926 ASSERT_VK_SUCCESS(err);
7927
7928 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007929 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007930 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007931 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007932 alloc_info.descriptorPool = ds_pool;
7933 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007934 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007935 ASSERT_VK_SUCCESS(err);
7936
7937 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007938 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7939 pipeline_layout_ci.setLayoutCount = 1;
7940 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007941
7942 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007943 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007944 ASSERT_VK_SUCCESS(err);
7945
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007946 VkViewport vp = {};
Tobin Ehlise68360f2015-10-01 11:15:13 -06007947 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007948 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
Mark Lobodzinski510aa5c2016-12-19 07:59:10 -07007949 vp_state_ci.scissorCount = 1;
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007950 vp_state_ci.viewportCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -07007951 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007952
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007953 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7954 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7955 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7956 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7957 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7958 rs_state_ci.depthClampEnable = VK_FALSE;
7959 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
7960 rs_state_ci.depthBiasEnable = VK_FALSE;
7961
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007962 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7963 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7964 vi_ci.pNext = nullptr;
7965 vi_ci.vertexBindingDescriptionCount = 0;
7966 vi_ci.pVertexBindingDescriptions = nullptr;
7967 vi_ci.vertexAttributeDescriptionCount = 0;
7968 vi_ci.pVertexAttributeDescriptions = nullptr;
7969
7970 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7971 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7972 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7973
7974 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
7975 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
7976 pipe_ms_state_ci.pNext = NULL;
7977 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
7978 pipe_ms_state_ci.sampleShadingEnable = 0;
7979 pipe_ms_state_ci.minSampleShading = 1.0;
7980 pipe_ms_state_ci.pSampleMask = NULL;
7981
Cody Northropeb3a6c12015-10-05 14:44:45 -06007982 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007983 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007984
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007985 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07007986 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chia-I Wu28e06912015-10-31 00:31:16 +08007987 shaderStages[0] = vs.GetStageCreateInfo();
7988 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007989
7990 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007991 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7992 gp_ci.stageCount = 2;
7993 gp_ci.pStages = shaderStages;
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007994 gp_ci.pVertexInputState = &vi_ci;
7995 gp_ci.pInputAssemblyState = &ia_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007996 gp_ci.pViewportState = &vp_state_ci;
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007997 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007998 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007999 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
8000 gp_ci.layout = pipeline_layout;
8001 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06008002
8003 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008004 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008005
8006 VkPipeline pipeline;
8007 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008008 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008009 ASSERT_VK_SUCCESS(err);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008010
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07008011 if (!m_device->phy().features().multiViewport) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07008012 printf(" MultiViewport feature is disabled -- skipping enabled-state checks.\n");
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07008013
8014 // Check case where multiViewport is disabled and viewport count is not 1
8015 // We check scissor/viewport simultaneously since separating them would trigger the mismatch error, 1434.
8016 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01430);
8017 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01431);
8018 vp_state_ci.scissorCount = 0;
8019 vp_state_ci.viewportCount = 0;
8020 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
8021 m_errorMonitor->VerifyFound();
8022 } else {
8023 if (m_device->props.limits.maxViewports == 1) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07008024 printf(" Device limit maxViewports is 1, skipping tests that require higher limits.\n");
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07008025 } else {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07008026 printf(" MultiViewport feature is enabled -- skipping disabled-state checks.\n");
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07008027
8028 // Check is that viewportcount and scissorcount match
8029 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01434);
8030 vp_state_ci.scissorCount = 1;
8031 vp_state_ci.viewportCount = m_device->props.limits.maxViewports;
8032 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
8033 m_errorMonitor->VerifyFound();
8034
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07008035 // Check case where multiViewport is enabled and viewport count is greater than max
8036 // We check scissor/viewport simultaneously since separating them would trigger the mismatch error, 1434.
8037 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01432);
8038 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01433);
8039 vp_state_ci.scissorCount = m_device->props.limits.maxViewports + 1;
8040 vp_state_ci.viewportCount = m_device->props.limits.maxViewports + 1;
8041 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
8042 m_errorMonitor->VerifyFound();
8043 }
8044 }
Tobin Ehlise68360f2015-10-01 11:15:13 -06008045
Chia-I Wuf7458c52015-10-26 21:10:41 +08008046 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
8047 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8048 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8049 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008050}
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07008051
8052// 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
8053// set dynamically.
Karl Schultz6addd812016-02-02 17:17:23 -07008054TEST_F(VkLayerTest, PSOViewportStateNotSet) {
Karl Schultz6addd812016-02-02 17:17:23 -07008055 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008056
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07008057 TEST_DESCRIPTION("Create a graphics pipeline with rasterization enabled but no viewport state.");
8058
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07008059 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02113);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008060
Tony Barbour1fa09702017-03-16 12:09:08 -06008061 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlise68360f2015-10-01 11:15:13 -06008062 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06008063
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008064 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008065 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8066 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008067
8068 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008069 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8070 ds_pool_ci.maxSets = 1;
8071 ds_pool_ci.poolSizeCount = 1;
8072 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008073
8074 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008075 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008076 ASSERT_VK_SUCCESS(err);
8077
8078 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008079 dsl_binding.binding = 0;
8080 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8081 dsl_binding.descriptorCount = 1;
8082 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008083
8084 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008085 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8086 ds_layout_ci.bindingCount = 1;
8087 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008088
8089 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008090 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008091 ASSERT_VK_SUCCESS(err);
8092
8093 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008094 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008095 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008096 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008097 alloc_info.descriptorPool = ds_pool;
8098 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008099 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008100 ASSERT_VK_SUCCESS(err);
8101
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07008102 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
8103 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
8104 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
8105
8106 VkPipelineVertexInputStateCreateInfo vi_ci = {};
8107 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
8108 vi_ci.pNext = nullptr;
8109 vi_ci.vertexBindingDescriptionCount = 0;
8110 vi_ci.pVertexBindingDescriptions = nullptr;
8111 vi_ci.vertexAttributeDescriptionCount = 0;
8112 vi_ci.pVertexAttributeDescriptions = nullptr;
8113
8114 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
8115 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
8116 pipe_ms_state_ci.pNext = NULL;
8117 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
8118 pipe_ms_state_ci.sampleShadingEnable = 0;
8119 pipe_ms_state_ci.minSampleShading = 1.0;
8120 pipe_ms_state_ci.pSampleMask = NULL;
8121
Tobin Ehlise68360f2015-10-01 11:15:13 -06008122 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008123 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8124 pipeline_layout_ci.setLayoutCount = 1;
8125 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008126
8127 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008128 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008129 ASSERT_VK_SUCCESS(err);
8130
8131 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
8132 // Set scissor as dynamic to avoid second error
8133 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008134 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
8135 dyn_state_ci.dynamicStateCount = 1;
8136 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008137
Cody Northropeb3a6c12015-10-05 14:44:45 -06008138 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07008139 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06008140
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008141 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07008142 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
8143 // 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 +08008144 shaderStages[0] = vs.GetStageCreateInfo();
8145 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06008146
Karl Schultzdfdb8d42016-03-08 10:30:21 -07008147 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
8148 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
8149 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
8150 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
8151 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
8152 rs_state_ci.depthClampEnable = VK_FALSE;
8153 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
8154 rs_state_ci.depthBiasEnable = VK_FALSE;
8155
Tobin Ehlise68360f2015-10-01 11:15:13 -06008156 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008157 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8158 gp_ci.stageCount = 2;
8159 gp_ci.pStages = shaderStages;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07008160 gp_ci.pRasterizationState = &rs_state_ci;
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07008161 // Not setting VP state w/o dynamic vp state should cause validation error
8162 gp_ci.pViewportState = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -07008163 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07008164 gp_ci.pVertexInputState = &vi_ci;
8165 gp_ci.pInputAssemblyState = &ia_ci;
8166 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07008167 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
8168 gp_ci.layout = pipeline_layout;
8169 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06008170
8171 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008172 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008173
8174 VkPipeline pipeline;
8175 VkPipelineCache pipelineCache;
8176
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008177 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008178 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008179 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008180
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008181 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06008182
Chia-I Wuf7458c52015-10-26 21:10:41 +08008183 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
8184 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8185 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8186 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008187}
Mark Lobodzinski73169e22016-12-16 14:01:17 -07008188
8189// Create PSO w/o non-zero viewportCount but no viewport data, then run second test where dynamic scissor count doesn't match PSO
8190// scissor count
Karl Schultz6addd812016-02-02 17:17:23 -07008191TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch) {
8192 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008193
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07008194 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02110);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008195
Tony Barbour1fa09702017-03-16 12:09:08 -06008196 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12008197
8198 if (!m_device->phy().features().multiViewport) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07008199 printf(" Device does not support multiple viewports/scissors; skipped.\n");
Chris Forbesc08a6ca2016-07-28 14:14:07 +12008200 return;
8201 }
8202
Tobin Ehlise68360f2015-10-01 11:15:13 -06008203 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06008204
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008205 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008206 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8207 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008208
8209 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008210 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8211 ds_pool_ci.maxSets = 1;
8212 ds_pool_ci.poolSizeCount = 1;
8213 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008214
8215 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008216 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008217 ASSERT_VK_SUCCESS(err);
8218
8219 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008220 dsl_binding.binding = 0;
8221 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8222 dsl_binding.descriptorCount = 1;
8223 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008224
8225 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008226 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8227 ds_layout_ci.bindingCount = 1;
8228 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008229
8230 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008231 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008232 ASSERT_VK_SUCCESS(err);
8233
8234 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008235 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008236 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008237 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008238 alloc_info.descriptorPool = ds_pool;
8239 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008240 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008241 ASSERT_VK_SUCCESS(err);
8242
8243 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008244 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8245 pipeline_layout_ci.setLayoutCount = 1;
8246 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008247
8248 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008249 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008250 ASSERT_VK_SUCCESS(err);
8251
8252 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008253 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
8254 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008255 vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error
Karl Schultz6addd812016-02-02 17:17:23 -07008256 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008257 vp_state_ci.pScissors = NULL; // Scissor is dynamic (below) so this won't cause error
Tobin Ehlise68360f2015-10-01 11:15:13 -06008258
8259 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
8260 // Set scissor as dynamic to avoid that error
8261 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008262 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
8263 dyn_state_ci.dynamicStateCount = 1;
8264 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008265
Mark Lobodzinski73169e22016-12-16 14:01:17 -07008266 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
8267 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
8268 pipe_ms_state_ci.pNext = NULL;
8269 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
8270 pipe_ms_state_ci.sampleShadingEnable = 0;
8271 pipe_ms_state_ci.minSampleShading = 1.0;
8272 pipe_ms_state_ci.pSampleMask = NULL;
8273
Cody Northropeb3a6c12015-10-05 14:44:45 -06008274 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07008275 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06008276
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008277 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski73169e22016-12-16 14:01:17 -07008278 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
8279 // 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 +08008280 shaderStages[0] = vs.GetStageCreateInfo();
8281 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06008282
Cody Northropf6622dc2015-10-06 10:33:21 -06008283 VkPipelineVertexInputStateCreateInfo vi_ci = {};
8284 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
8285 vi_ci.pNext = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008286 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06008287 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008288 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06008289 vi_ci.pVertexAttributeDescriptions = nullptr;
8290
8291 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
8292 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
8293 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
8294
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008295 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008296 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Mark Lobodzinski73169e22016-12-16 14:01:17 -07008297 rs_ci.lineWidth = m_device->props.limits.lineWidthRange[0];
Cody Northropf6622dc2015-10-06 10:33:21 -06008298 rs_ci.pNext = nullptr;
8299
Mark Youngc89c6312016-03-31 16:03:20 -06008300 VkPipelineColorBlendAttachmentState att = {};
8301 att.blendEnable = VK_FALSE;
8302 att.colorWriteMask = 0xf;
8303
Cody Northropf6622dc2015-10-06 10:33:21 -06008304 VkPipelineColorBlendStateCreateInfo cb_ci = {};
8305 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
8306 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06008307 cb_ci.attachmentCount = 1;
8308 cb_ci.pAttachments = &att;
Cody Northropf6622dc2015-10-06 10:33:21 -06008309
Tobin Ehlise68360f2015-10-01 11:15:13 -06008310 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008311 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8312 gp_ci.stageCount = 2;
8313 gp_ci.pStages = shaderStages;
8314 gp_ci.pVertexInputState = &vi_ci;
8315 gp_ci.pInputAssemblyState = &ia_ci;
8316 gp_ci.pViewportState = &vp_state_ci;
8317 gp_ci.pRasterizationState = &rs_ci;
8318 gp_ci.pColorBlendState = &cb_ci;
8319 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski73169e22016-12-16 14:01:17 -07008320 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07008321 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
8322 gp_ci.layout = pipeline_layout;
8323 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06008324
8325 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008326 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008327
8328 VkPipeline pipeline;
8329 VkPipelineCache pipelineCache;
8330
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008331 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008332 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008333 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008334
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008335 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008336
Tobin Ehlisd332f282015-10-02 11:00:56 -06008337 // Now hit second fail case where we set scissor w/ different count than PSO
Karl Schultz6addd812016-02-02 17:17:23 -07008338 // First need to successfully create the PSO from above by setting
8339 // pViewports
Mike Weiblen95dd0f92016-10-19 12:28:27 -06008340 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 -07008341
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008342 VkViewport vp = {}; // Just need dummy vp to point to
Karl Schultz6addd812016-02-02 17:17:23 -07008343 vp_state_ci.pViewports = &vp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008344 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07008345 ASSERT_VK_SUCCESS(err);
Tony Barbour552f6c02016-12-21 14:34:07 -07008346 m_commandBuffer->BeginCommandBuffer();
8347 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008348 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008349 VkRect2D scissors[1] = {}; // don't care about data
Karl Schultz6addd812016-02-02 17:17:23 -07008350 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12008351 vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 1, 1, scissors);
Karl Schultz6addd812016-02-02 17:17:23 -07008352 Draw(1, 0, 0, 0);
8353
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008354 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07008355
8356 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
8357 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8358 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8359 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008360 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07008361}
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008362
8363// 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 -07008364// viewportCount
8365TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch) {
8366 VkResult err;
8367
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07008368 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02111);
Karl Schultz6addd812016-02-02 17:17:23 -07008369
Tony Barbour1fa09702017-03-16 12:09:08 -06008370 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12008371
8372 if (!m_device->phy().features().multiViewport) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07008373 printf(" Device does not support multiple viewports/scissors; skipped.\n");
Chris Forbesc08a6ca2016-07-28 14:14:07 +12008374 return;
8375 }
8376
Karl Schultz6addd812016-02-02 17:17:23 -07008377 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8378
8379 VkDescriptorPoolSize ds_type_count = {};
8380 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8381 ds_type_count.descriptorCount = 1;
8382
8383 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8384 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8385 ds_pool_ci.maxSets = 1;
8386 ds_pool_ci.poolSizeCount = 1;
8387 ds_pool_ci.pPoolSizes = &ds_type_count;
8388
8389 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008390 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Karl Schultz6addd812016-02-02 17:17:23 -07008391 ASSERT_VK_SUCCESS(err);
8392
8393 VkDescriptorSetLayoutBinding dsl_binding = {};
8394 dsl_binding.binding = 0;
8395 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8396 dsl_binding.descriptorCount = 1;
8397 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8398
8399 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8400 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8401 ds_layout_ci.bindingCount = 1;
8402 ds_layout_ci.pBindings = &dsl_binding;
8403
8404 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008405 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07008406 ASSERT_VK_SUCCESS(err);
8407
8408 VkDescriptorSet descriptorSet;
8409 VkDescriptorSetAllocateInfo alloc_info = {};
8410 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8411 alloc_info.descriptorSetCount = 1;
8412 alloc_info.descriptorPool = ds_pool;
8413 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008414 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Karl Schultz6addd812016-02-02 17:17:23 -07008415 ASSERT_VK_SUCCESS(err);
8416
8417 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
8418 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8419 pipeline_layout_ci.setLayoutCount = 1;
8420 pipeline_layout_ci.pSetLayouts = &ds_layout;
8421
8422 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008423 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07008424 ASSERT_VK_SUCCESS(err);
8425
8426 VkPipelineViewportStateCreateInfo vp_state_ci = {};
8427 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
8428 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008429 vp_state_ci.pScissors = NULL; // Null scissor w/ count of 1 should cause error
Karl Schultz6addd812016-02-02 17:17:23 -07008430 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008431 vp_state_ci.pViewports = NULL; // vp is dynamic (below) so this won't cause error
Karl Schultz6addd812016-02-02 17:17:23 -07008432
8433 VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT;
8434 // Set scissor as dynamic to avoid that error
8435 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
8436 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
8437 dyn_state_ci.dynamicStateCount = 1;
8438 dyn_state_ci.pDynamicStates = &vp_state;
8439
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008440 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
8441 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
8442 pipe_ms_state_ci.pNext = NULL;
8443 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
8444 pipe_ms_state_ci.sampleShadingEnable = 0;
8445 pipe_ms_state_ci.minSampleShading = 1.0;
8446 pipe_ms_state_ci.pSampleMask = NULL;
8447
Karl Schultz6addd812016-02-02 17:17:23 -07008448 VkPipelineShaderStageCreateInfo shaderStages[2];
8449 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
8450
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008451 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008452 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
8453 // 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 -07008454 shaderStages[0] = vs.GetStageCreateInfo();
8455 shaderStages[1] = fs.GetStageCreateInfo();
8456
8457 VkPipelineVertexInputStateCreateInfo vi_ci = {};
8458 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
8459 vi_ci.pNext = nullptr;
8460 vi_ci.vertexBindingDescriptionCount = 0;
8461 vi_ci.pVertexBindingDescriptions = nullptr;
8462 vi_ci.vertexAttributeDescriptionCount = 0;
8463 vi_ci.pVertexAttributeDescriptions = nullptr;
8464
8465 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
8466 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
8467 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
8468
8469 VkPipelineRasterizationStateCreateInfo rs_ci = {};
8470 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008471 rs_ci.lineWidth = m_device->props.limits.lineWidthRange[0];
Karl Schultz6addd812016-02-02 17:17:23 -07008472 rs_ci.pNext = nullptr;
8473
Mark Youngc89c6312016-03-31 16:03:20 -06008474 VkPipelineColorBlendAttachmentState att = {};
8475 att.blendEnable = VK_FALSE;
8476 att.colorWriteMask = 0xf;
8477
Karl Schultz6addd812016-02-02 17:17:23 -07008478 VkPipelineColorBlendStateCreateInfo cb_ci = {};
8479 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
8480 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06008481 cb_ci.attachmentCount = 1;
8482 cb_ci.pAttachments = &att;
Karl Schultz6addd812016-02-02 17:17:23 -07008483
8484 VkGraphicsPipelineCreateInfo gp_ci = {};
8485 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8486 gp_ci.stageCount = 2;
8487 gp_ci.pStages = shaderStages;
8488 gp_ci.pVertexInputState = &vi_ci;
8489 gp_ci.pInputAssemblyState = &ia_ci;
8490 gp_ci.pViewportState = &vp_state_ci;
8491 gp_ci.pRasterizationState = &rs_ci;
8492 gp_ci.pColorBlendState = &cb_ci;
8493 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008494 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07008495 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
8496 gp_ci.layout = pipeline_layout;
8497 gp_ci.renderPass = renderPass();
8498
8499 VkPipelineCacheCreateInfo pc_ci = {};
8500 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
8501
8502 VkPipeline pipeline;
8503 VkPipelineCache pipelineCache;
8504
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008505 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Karl Schultz6addd812016-02-02 17:17:23 -07008506 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008507 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07008508
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008509 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07008510
8511 // Now hit second fail case where we set scissor w/ different count than PSO
8512 // First need to successfully create the PSO from above by setting
8513 // pViewports
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07008514 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8515 "Dynamic viewport(s) 0 are used by pipeline state object, ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008516
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008517 VkRect2D sc = {}; // Just need dummy vp to point to
Tobin Ehlisd332f282015-10-02 11:00:56 -06008518 vp_state_ci.pScissors = &sc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008519 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06008520 ASSERT_VK_SUCCESS(err);
Tony Barbour552f6c02016-12-21 14:34:07 -07008521 m_commandBuffer->BeginCommandBuffer();
8522 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008523 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008524 VkViewport viewports[1] = {};
8525 viewports[0].width = 8;
8526 viewports[0].height = 8;
Tobin Ehlisd332f282015-10-02 11:00:56 -06008527 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12008528 vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 1, 1, viewports);
Tobin Ehlisd332f282015-10-02 11:00:56 -06008529 Draw(1, 0, 0, 0);
8530
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008531 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06008532
Chia-I Wuf7458c52015-10-26 21:10:41 +08008533 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
8534 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8535 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8536 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008537 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008538}
8539
Mark Young7394fdd2016-03-31 14:56:43 -06008540TEST_F(VkLayerTest, PSOLineWidthInvalid) {
8541 VkResult err;
8542
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008543 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06008544
Tony Barbour1fa09702017-03-16 12:09:08 -06008545 ASSERT_NO_FATAL_FAILURE(Init());
Mark Young7394fdd2016-03-31 14:56:43 -06008546 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8547
8548 VkDescriptorPoolSize ds_type_count = {};
8549 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8550 ds_type_count.descriptorCount = 1;
8551
8552 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8553 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8554 ds_pool_ci.maxSets = 1;
8555 ds_pool_ci.poolSizeCount = 1;
8556 ds_pool_ci.pPoolSizes = &ds_type_count;
8557
8558 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008559 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Young7394fdd2016-03-31 14:56:43 -06008560 ASSERT_VK_SUCCESS(err);
8561
8562 VkDescriptorSetLayoutBinding dsl_binding = {};
8563 dsl_binding.binding = 0;
8564 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8565 dsl_binding.descriptorCount = 1;
8566 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8567
8568 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8569 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8570 ds_layout_ci.bindingCount = 1;
8571 ds_layout_ci.pBindings = &dsl_binding;
8572
8573 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008574 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06008575 ASSERT_VK_SUCCESS(err);
8576
8577 VkDescriptorSet descriptorSet;
8578 VkDescriptorSetAllocateInfo alloc_info = {};
8579 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8580 alloc_info.descriptorSetCount = 1;
8581 alloc_info.descriptorPool = ds_pool;
8582 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008583 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Young7394fdd2016-03-31 14:56:43 -06008584 ASSERT_VK_SUCCESS(err);
8585
8586 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
8587 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8588 pipeline_layout_ci.setLayoutCount = 1;
8589 pipeline_layout_ci.pSetLayouts = &ds_layout;
8590
8591 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008592 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06008593 ASSERT_VK_SUCCESS(err);
8594
8595 VkPipelineViewportStateCreateInfo vp_state_ci = {};
8596 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
8597 vp_state_ci.scissorCount = 1;
8598 vp_state_ci.pScissors = NULL;
8599 vp_state_ci.viewportCount = 1;
8600 vp_state_ci.pViewports = NULL;
8601
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008602 VkDynamicState dynamic_states[3] = {VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR, VK_DYNAMIC_STATE_LINE_WIDTH};
Mark Young7394fdd2016-03-31 14:56:43 -06008603 // Set scissor as dynamic to avoid that error
8604 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
8605 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
8606 dyn_state_ci.dynamicStateCount = 2;
8607 dyn_state_ci.pDynamicStates = dynamic_states;
8608
8609 VkPipelineShaderStageCreateInfo shaderStages[2];
8610 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
8611
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008612 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
8613 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT,
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008614 this); // TODO - We shouldn't need a fragment shader
8615 // but add it to be able to run on more devices
Mark Young7394fdd2016-03-31 14:56:43 -06008616 shaderStages[0] = vs.GetStageCreateInfo();
8617 shaderStages[1] = fs.GetStageCreateInfo();
8618
8619 VkPipelineVertexInputStateCreateInfo vi_ci = {};
8620 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
8621 vi_ci.pNext = nullptr;
8622 vi_ci.vertexBindingDescriptionCount = 0;
8623 vi_ci.pVertexBindingDescriptions = nullptr;
8624 vi_ci.vertexAttributeDescriptionCount = 0;
8625 vi_ci.pVertexAttributeDescriptions = nullptr;
8626
8627 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
8628 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
8629 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
8630
8631 VkPipelineRasterizationStateCreateInfo rs_ci = {};
8632 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
8633 rs_ci.pNext = nullptr;
Rene Lindsay144e4842017-01-20 14:27:15 -07008634 rs_ci.rasterizerDiscardEnable = VK_TRUE;
Mark Young7394fdd2016-03-31 14:56:43 -06008635
Mark Young47107952016-05-02 15:59:55 -06008636 // Check too low (line width of -1.0f).
8637 rs_ci.lineWidth = -1.0f;
Mark Young7394fdd2016-03-31 14:56:43 -06008638
8639 VkPipelineColorBlendAttachmentState att = {};
8640 att.blendEnable = VK_FALSE;
8641 att.colorWriteMask = 0xf;
8642
8643 VkPipelineColorBlendStateCreateInfo cb_ci = {};
8644 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
8645 cb_ci.pNext = nullptr;
8646 cb_ci.attachmentCount = 1;
8647 cb_ci.pAttachments = &att;
8648
8649 VkGraphicsPipelineCreateInfo gp_ci = {};
8650 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8651 gp_ci.stageCount = 2;
8652 gp_ci.pStages = shaderStages;
8653 gp_ci.pVertexInputState = &vi_ci;
8654 gp_ci.pInputAssemblyState = &ia_ci;
8655 gp_ci.pViewportState = &vp_state_ci;
8656 gp_ci.pRasterizationState = &rs_ci;
8657 gp_ci.pColorBlendState = &cb_ci;
8658 gp_ci.pDynamicState = &dyn_state_ci;
8659 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
8660 gp_ci.layout = pipeline_layout;
8661 gp_ci.renderPass = renderPass();
8662
8663 VkPipelineCacheCreateInfo pc_ci = {};
8664 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
8665
8666 VkPipeline pipeline;
8667 VkPipelineCache pipelineCache;
8668
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008669 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06008670 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008671 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06008672
8673 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06008674 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06008675
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008676 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06008677
8678 // Check too high (line width of 65536.0f).
8679 rs_ci.lineWidth = 65536.0f;
8680
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008681 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06008682 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008683 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06008684
8685 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06008686 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06008687
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008688 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06008689
8690 dyn_state_ci.dynamicStateCount = 3;
8691
8692 rs_ci.lineWidth = 1.0f;
8693
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008694 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06008695 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008696 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tony Barbour552f6c02016-12-21 14:34:07 -07008697 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008698 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06008699
8700 // Check too low with dynamic setting.
Mark Young47107952016-05-02 15:59:55 -06008701 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), -1.0f);
Mark Young7394fdd2016-03-31 14:56:43 -06008702 m_errorMonitor->VerifyFound();
8703
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008704 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06008705
8706 // Check too high with dynamic setting.
8707 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), 65536.0f);
8708 m_errorMonitor->VerifyFound();
Tony Barbour552f6c02016-12-21 14:34:07 -07008709 m_commandBuffer->EndCommandBuffer();
Mark Young7394fdd2016-03-31 14:56:43 -06008710
8711 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
8712 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8713 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8714 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008715 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06008716}
8717
Jeremy Hayes37f0cdd2017-05-04 18:08:49 -06008718TEST_F(VkLayerTest, VALIDATION_ERROR_01407) {
8719 TEST_DESCRIPTION("Test VALIDATION_ERROR_01407: binding must be less than VkPhysicalDeviceLimits::maxVertexInputBindings");
8720
8721 ASSERT_NO_FATAL_FAILURE(Init());
8722 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8723
8724 VkPipelineCache pipeline_cache;
8725 {
8726 VkPipelineCacheCreateInfo create_info{};
8727 create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
8728
8729 VkResult err = vkCreatePipelineCache(m_device->device(), &create_info, nullptr, &pipeline_cache);
8730 ASSERT_VK_SUCCESS(err);
8731 }
8732
8733 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
8734 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
8735
8736 VkPipelineShaderStageCreateInfo stages[2]{{}};
8737 stages[0] = vs.GetStageCreateInfo();
8738 stages[1] = fs.GetStageCreateInfo();
8739
8740 // Test when binding is greater than or equal to VkPhysicalDeviceLimits::maxVertexInputBindings.
8741 VkVertexInputBindingDescription vertex_input_binding_description{};
8742 vertex_input_binding_description.binding = m_device->props.limits.maxVertexInputBindings;
8743
8744 VkPipelineVertexInputStateCreateInfo vertex_input_state{};
8745 vertex_input_state.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
8746 vertex_input_state.pNext = nullptr;
8747 vertex_input_state.vertexBindingDescriptionCount = 1;
8748 vertex_input_state.pVertexBindingDescriptions = &vertex_input_binding_description;
8749 vertex_input_state.vertexAttributeDescriptionCount = 0;
8750 vertex_input_state.pVertexAttributeDescriptions = nullptr;
8751
8752 VkPipelineInputAssemblyStateCreateInfo input_assembly_state{};
8753 input_assembly_state.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
8754 input_assembly_state.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
8755
8756 VkViewport viewport{};
8757 VkPipelineViewportStateCreateInfo viewport_state{};
8758 viewport_state.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
8759 viewport_state.scissorCount = 1;
8760 viewport_state.viewportCount = 1;
8761 viewport_state.pViewports = &viewport;
8762
8763 VkPipelineMultisampleStateCreateInfo multisample_state{};
8764 multisample_state.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
8765 multisample_state.pNext = nullptr;
8766 multisample_state.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
8767 multisample_state.sampleShadingEnable = 0;
8768 multisample_state.minSampleShading = 1.0;
8769 multisample_state.pSampleMask = nullptr;
8770
8771 VkPipelineRasterizationStateCreateInfo rasterization_state{};
8772 rasterization_state.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
8773 rasterization_state.polygonMode = VK_POLYGON_MODE_FILL;
8774 rasterization_state.cullMode = VK_CULL_MODE_BACK_BIT;
8775 rasterization_state.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
8776 rasterization_state.depthClampEnable = VK_FALSE;
8777 rasterization_state.rasterizerDiscardEnable = VK_FALSE;
8778 rasterization_state.depthBiasEnable = VK_FALSE;
8779
8780 VkPipelineLayout pipeline_layout;
8781 {
8782 VkPipelineLayoutCreateInfo create_info{};
8783 create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8784 create_info.setLayoutCount = 0;
8785 create_info.pSetLayouts = nullptr;
8786
8787 VkResult err = vkCreatePipelineLayout(m_device->device(), &create_info, nullptr, &pipeline_layout);
8788 ASSERT_VK_SUCCESS(err);
8789 }
8790
8791 {
8792 VkGraphicsPipelineCreateInfo create_info{};
8793 create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8794 create_info.stageCount = 2;
8795 create_info.pStages = stages;
8796 create_info.pVertexInputState = &vertex_input_state;
8797 create_info.pInputAssemblyState = &input_assembly_state;
8798 create_info.pViewportState = &viewport_state;
8799 create_info.pMultisampleState = &multisample_state;
8800 create_info.pRasterizationState = &rasterization_state;
8801 create_info.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
8802 create_info.layout = pipeline_layout;
8803 create_info.renderPass = renderPass();
8804
8805 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01407);
8806 VkPipeline pipeline;
8807 vkCreateGraphicsPipelines(m_device->device(), pipeline_cache, 1, &create_info, nullptr, &pipeline);
8808 m_errorMonitor->VerifyFound();
8809 }
8810
8811 vkDestroyPipelineCache(m_device->device(), pipeline_cache, nullptr);
8812 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
8813}
8814
8815TEST_F(VkLayerTest, VALIDATION_ERROR_01408) {
8816 TEST_DESCRIPTION(
8817 "Test VALIDATION_ERROR_01408: stride must be less than or equal to VkPhysicalDeviceLimits::maxVertexInputBindingStride");
8818
8819 ASSERT_NO_FATAL_FAILURE(Init());
8820 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8821
8822 VkPipelineCache pipeline_cache;
8823 {
8824 VkPipelineCacheCreateInfo create_info{};
8825 create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
8826
8827 VkResult err = vkCreatePipelineCache(m_device->device(), &create_info, nullptr, &pipeline_cache);
8828 ASSERT_VK_SUCCESS(err);
8829 }
8830
8831 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
8832 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
8833
8834 VkPipelineShaderStageCreateInfo stages[2]{{}};
8835 stages[0] = vs.GetStageCreateInfo();
8836 stages[1] = fs.GetStageCreateInfo();
8837
8838 // Test when stride is greater than VkPhysicalDeviceLimits::maxVertexInputBindingStride.
8839 VkVertexInputBindingDescription vertex_input_binding_description{};
8840 vertex_input_binding_description.stride = m_device->props.limits.maxVertexInputBindingStride + 1;
8841
8842 VkPipelineVertexInputStateCreateInfo vertex_input_state{};
8843 vertex_input_state.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
8844 vertex_input_state.pNext = nullptr;
8845 vertex_input_state.vertexBindingDescriptionCount = 1;
8846 vertex_input_state.pVertexBindingDescriptions = &vertex_input_binding_description;
8847 vertex_input_state.vertexAttributeDescriptionCount = 0;
8848 vertex_input_state.pVertexAttributeDescriptions = nullptr;
8849
8850 VkPipelineInputAssemblyStateCreateInfo input_assembly_state{};
8851 input_assembly_state.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
8852 input_assembly_state.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
8853
8854 VkViewport viewport{};
8855 VkPipelineViewportStateCreateInfo viewport_state{};
8856 viewport_state.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
8857 viewport_state.scissorCount = 1;
8858 viewport_state.viewportCount = 1;
8859 viewport_state.pViewports = &viewport;
8860
8861 VkPipelineMultisampleStateCreateInfo multisample_state{};
8862 multisample_state.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
8863 multisample_state.pNext = nullptr;
8864 multisample_state.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
8865 multisample_state.sampleShadingEnable = 0;
8866 multisample_state.minSampleShading = 1.0;
8867 multisample_state.pSampleMask = nullptr;
8868
8869 VkPipelineRasterizationStateCreateInfo rasterization_state{};
8870 rasterization_state.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
8871 rasterization_state.polygonMode = VK_POLYGON_MODE_FILL;
8872 rasterization_state.cullMode = VK_CULL_MODE_BACK_BIT;
8873 rasterization_state.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
8874 rasterization_state.depthClampEnable = VK_FALSE;
8875 rasterization_state.rasterizerDiscardEnable = VK_FALSE;
8876 rasterization_state.depthBiasEnable = VK_FALSE;
8877
8878 VkPipelineLayout pipeline_layout;
8879 {
8880 VkPipelineLayoutCreateInfo create_info{};
8881 create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8882 create_info.setLayoutCount = 0;
8883 create_info.pSetLayouts = nullptr;
8884
8885 VkResult err = vkCreatePipelineLayout(m_device->device(), &create_info, nullptr, &pipeline_layout);
8886 ASSERT_VK_SUCCESS(err);
8887 }
8888
8889 {
8890 VkGraphicsPipelineCreateInfo create_info{};
8891 create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8892 create_info.stageCount = 2;
8893 create_info.pStages = stages;
8894 create_info.pVertexInputState = &vertex_input_state;
8895 create_info.pInputAssemblyState = &input_assembly_state;
8896 create_info.pViewportState = &viewport_state;
8897 create_info.pMultisampleState = &multisample_state;
8898 create_info.pRasterizationState = &rasterization_state;
8899 create_info.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
8900 create_info.layout = pipeline_layout;
8901 create_info.renderPass = renderPass();
8902
8903 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01408);
8904 VkPipeline pipeline;
8905 vkCreateGraphicsPipelines(m_device->device(), pipeline_cache, 1, &create_info, nullptr, &pipeline);
8906 m_errorMonitor->VerifyFound();
8907 }
8908
8909 vkDestroyPipelineCache(m_device->device(), pipeline_cache, nullptr);
8910 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
8911}
8912
Jeremy Hayes091e1ab2017-05-04 18:10:28 -06008913TEST_F(VkLayerTest, VALIDATION_ERROR_01410) {
8914 TEST_DESCRIPTION("Test VALIDATION_ERROR_01410: location must be less than VkPhysicalDeviceLimits::maxVertexInputAttributes");
8915
8916 ASSERT_NO_FATAL_FAILURE(Init());
8917 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8918
8919 VkPipelineCache pipeline_cache;
8920 {
8921 VkPipelineCacheCreateInfo create_info{};
8922 create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
8923
8924 VkResult err = vkCreatePipelineCache(m_device->device(), &create_info, nullptr, &pipeline_cache);
8925 ASSERT_VK_SUCCESS(err);
8926 }
8927
8928 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
8929 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
8930
8931 VkPipelineShaderStageCreateInfo stages[2]{{}};
8932 stages[0] = vs.GetStageCreateInfo();
8933 stages[1] = fs.GetStageCreateInfo();
8934
8935 // Test when location is greater than or equal to VkPhysicalDeviceLimits::maxVertexInputAttributes.
8936 VkVertexInputAttributeDescription vertex_input_attribute_description{};
8937 vertex_input_attribute_description.location = m_device->props.limits.maxVertexInputAttributes;
8938
8939 VkPipelineVertexInputStateCreateInfo vertex_input_state{};
8940 vertex_input_state.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
8941 vertex_input_state.pNext = nullptr;
8942 vertex_input_state.vertexBindingDescriptionCount = 0;
8943 vertex_input_state.pVertexBindingDescriptions = nullptr;
8944 vertex_input_state.vertexAttributeDescriptionCount = 1;
8945 vertex_input_state.pVertexAttributeDescriptions = &vertex_input_attribute_description;
8946
8947 VkPipelineInputAssemblyStateCreateInfo input_assembly_state{};
8948 input_assembly_state.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
8949 input_assembly_state.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
8950
8951 VkViewport viewport{};
8952 VkPipelineViewportStateCreateInfo viewport_state{};
8953 viewport_state.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
8954 viewport_state.scissorCount = 1;
8955 viewport_state.viewportCount = 1;
8956 viewport_state.pViewports = &viewport;
8957
8958 VkPipelineMultisampleStateCreateInfo multisample_state{};
8959 multisample_state.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
8960 multisample_state.pNext = nullptr;
8961 multisample_state.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
8962 multisample_state.sampleShadingEnable = 0;
8963 multisample_state.minSampleShading = 1.0;
8964 multisample_state.pSampleMask = nullptr;
8965
8966 VkPipelineRasterizationStateCreateInfo rasterization_state{};
8967 rasterization_state.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
8968 rasterization_state.polygonMode = VK_POLYGON_MODE_FILL;
8969 rasterization_state.cullMode = VK_CULL_MODE_BACK_BIT;
8970 rasterization_state.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
8971 rasterization_state.depthClampEnable = VK_FALSE;
8972 rasterization_state.rasterizerDiscardEnable = VK_FALSE;
8973 rasterization_state.depthBiasEnable = VK_FALSE;
8974
8975 VkPipelineLayout pipeline_layout;
8976 {
8977 VkPipelineLayoutCreateInfo create_info{};
8978 create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8979 create_info.setLayoutCount = 0;
8980 create_info.pSetLayouts = nullptr;
8981
8982 VkResult err = vkCreatePipelineLayout(m_device->device(), &create_info, nullptr, &pipeline_layout);
8983 ASSERT_VK_SUCCESS(err);
8984 }
8985
8986 {
8987 VkGraphicsPipelineCreateInfo create_info{};
8988 create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8989 create_info.stageCount = 2;
8990 create_info.pStages = stages;
8991 create_info.pVertexInputState = &vertex_input_state;
8992 create_info.pInputAssemblyState = &input_assembly_state;
8993 create_info.pViewportState = &viewport_state;
8994 create_info.pMultisampleState = &multisample_state;
8995 create_info.pRasterizationState = &rasterization_state;
8996 create_info.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
8997 create_info.layout = pipeline_layout;
8998 create_info.renderPass = renderPass();
8999
9000 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01410);
9001 VkPipeline pipeline;
9002 vkCreateGraphicsPipelines(m_device->device(), pipeline_cache, 1, &create_info, nullptr, &pipeline);
9003 m_errorMonitor->VerifyFound();
9004 }
9005
9006 vkDestroyPipelineCache(m_device->device(), pipeline_cache, nullptr);
9007 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
9008}
9009
9010TEST_F(VkLayerTest, VALIDATION_ERROR_01411) {
9011 TEST_DESCRIPTION("Test VALIDATION_ERROR_01411: binding must be less than VkPhysicalDeviceLimits::maxVertexInputBindings");
9012
9013 ASSERT_NO_FATAL_FAILURE(Init());
9014 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9015
9016 VkPipelineCache pipeline_cache;
9017 {
9018 VkPipelineCacheCreateInfo create_info{};
9019 create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
9020
9021 VkResult err = vkCreatePipelineCache(m_device->device(), &create_info, nullptr, &pipeline_cache);
9022 ASSERT_VK_SUCCESS(err);
9023 }
9024
9025 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9026 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
9027
9028 VkPipelineShaderStageCreateInfo stages[2]{{}};
9029 stages[0] = vs.GetStageCreateInfo();
9030 stages[1] = fs.GetStageCreateInfo();
9031
9032 // Test when binding is greater than or equal to VkPhysicalDeviceLimits::maxVertexInputBindings.
9033 VkVertexInputAttributeDescription vertex_input_attribute_description{};
9034 vertex_input_attribute_description.binding = m_device->props.limits.maxVertexInputBindings;
9035
9036 VkPipelineVertexInputStateCreateInfo vertex_input_state{};
9037 vertex_input_state.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
9038 vertex_input_state.pNext = nullptr;
9039 vertex_input_state.vertexBindingDescriptionCount = 0;
9040 vertex_input_state.pVertexBindingDescriptions = nullptr;
9041 vertex_input_state.vertexAttributeDescriptionCount = 1;
9042 vertex_input_state.pVertexAttributeDescriptions = &vertex_input_attribute_description;
9043
9044 VkPipelineInputAssemblyStateCreateInfo input_assembly_state{};
9045 input_assembly_state.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
9046 input_assembly_state.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
9047
9048 VkViewport viewport{};
9049 VkPipelineViewportStateCreateInfo viewport_state{};
9050 viewport_state.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
9051 viewport_state.scissorCount = 1;
9052 viewport_state.viewportCount = 1;
9053 viewport_state.pViewports = &viewport;
9054
9055 VkPipelineMultisampleStateCreateInfo multisample_state{};
9056 multisample_state.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
9057 multisample_state.pNext = nullptr;
9058 multisample_state.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
9059 multisample_state.sampleShadingEnable = 0;
9060 multisample_state.minSampleShading = 1.0;
9061 multisample_state.pSampleMask = nullptr;
9062
9063 VkPipelineRasterizationStateCreateInfo rasterization_state{};
9064 rasterization_state.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
9065 rasterization_state.polygonMode = VK_POLYGON_MODE_FILL;
9066 rasterization_state.cullMode = VK_CULL_MODE_BACK_BIT;
9067 rasterization_state.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
9068 rasterization_state.depthClampEnable = VK_FALSE;
9069 rasterization_state.rasterizerDiscardEnable = VK_FALSE;
9070 rasterization_state.depthBiasEnable = VK_FALSE;
9071
9072 VkPipelineLayout pipeline_layout;
9073 {
9074 VkPipelineLayoutCreateInfo create_info{};
9075 create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9076 create_info.setLayoutCount = 0;
9077 create_info.pSetLayouts = nullptr;
9078
9079 VkResult err = vkCreatePipelineLayout(m_device->device(), &create_info, nullptr, &pipeline_layout);
9080 ASSERT_VK_SUCCESS(err);
9081 }
9082
9083 {
9084 VkGraphicsPipelineCreateInfo create_info{};
9085 create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
9086 create_info.stageCount = 2;
9087 create_info.pStages = stages;
9088 create_info.pVertexInputState = &vertex_input_state;
9089 create_info.pInputAssemblyState = &input_assembly_state;
9090 create_info.pViewportState = &viewport_state;
9091 create_info.pMultisampleState = &multisample_state;
9092 create_info.pRasterizationState = &rasterization_state;
9093 create_info.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
9094 create_info.layout = pipeline_layout;
9095 create_info.renderPass = renderPass();
9096
9097 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01411);
9098 VkPipeline pipeline;
9099 vkCreateGraphicsPipelines(m_device->device(), pipeline_cache, 1, &create_info, nullptr, &pipeline);
9100 m_errorMonitor->VerifyFound();
9101 }
9102
9103 vkDestroyPipelineCache(m_device->device(), pipeline_cache, nullptr);
9104 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
9105}
9106
9107TEST_F(VkLayerTest, VALIDATION_ERROR_01412) {
9108 TEST_DESCRIPTION(
9109 "Test VALIDATION_ERROR_01412: offset must be less than or equal to VkPhysicalDeviceLimits::maxVertexInputAttributeOffset");
9110
9111 ASSERT_NO_FATAL_FAILURE(Init());
9112 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9113
9114 VkPipelineCache pipeline_cache;
9115 {
9116 VkPipelineCacheCreateInfo create_info{};
9117 create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
9118
9119 VkResult err = vkCreatePipelineCache(m_device->device(), &create_info, nullptr, &pipeline_cache);
9120 ASSERT_VK_SUCCESS(err);
9121 }
9122
9123 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9124 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
9125
9126 VkPipelineShaderStageCreateInfo stages[2]{{}};
9127 stages[0] = vs.GetStageCreateInfo();
9128 stages[1] = fs.GetStageCreateInfo();
9129
9130 // Test when offset is greater than maximum.
9131 VkVertexInputAttributeDescription vertex_input_attribute_description{};
9132 vertex_input_attribute_description.offset = m_device->props.limits.maxVertexInputAttributeOffset + 1;
9133
9134 VkPipelineVertexInputStateCreateInfo vertex_input_state{};
9135 vertex_input_state.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
9136 vertex_input_state.pNext = nullptr;
9137 vertex_input_state.vertexBindingDescriptionCount = 0;
9138 vertex_input_state.pVertexBindingDescriptions = nullptr;
9139 vertex_input_state.vertexAttributeDescriptionCount = 1;
9140 vertex_input_state.pVertexAttributeDescriptions = &vertex_input_attribute_description;
9141
9142 VkPipelineInputAssemblyStateCreateInfo input_assembly_state{};
9143 input_assembly_state.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
9144 input_assembly_state.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
9145
9146 VkViewport viewport{};
9147 VkPipelineViewportStateCreateInfo viewport_state{};
9148 viewport_state.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
9149 viewport_state.scissorCount = 1;
9150 viewport_state.viewportCount = 1;
9151 viewport_state.pViewports = &viewport;
9152
9153 VkPipelineMultisampleStateCreateInfo multisample_state{};
9154 multisample_state.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
9155 multisample_state.pNext = nullptr;
9156 multisample_state.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
9157 multisample_state.sampleShadingEnable = 0;
9158 multisample_state.minSampleShading = 1.0;
9159 multisample_state.pSampleMask = nullptr;
9160
9161 VkPipelineRasterizationStateCreateInfo rasterization_state{};
9162 rasterization_state.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
9163 rasterization_state.polygonMode = VK_POLYGON_MODE_FILL;
9164 rasterization_state.cullMode = VK_CULL_MODE_BACK_BIT;
9165 rasterization_state.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
9166 rasterization_state.depthClampEnable = VK_FALSE;
9167 rasterization_state.rasterizerDiscardEnable = VK_FALSE;
9168 rasterization_state.depthBiasEnable = VK_FALSE;
9169
9170 VkPipelineLayout pipeline_layout;
9171 {
9172 VkPipelineLayoutCreateInfo create_info{};
9173 create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9174 create_info.setLayoutCount = 0;
9175 create_info.pSetLayouts = nullptr;
9176
9177 VkResult err = vkCreatePipelineLayout(m_device->device(), &create_info, nullptr, &pipeline_layout);
9178 ASSERT_VK_SUCCESS(err);
9179 }
9180
9181 {
9182 VkGraphicsPipelineCreateInfo create_info{};
9183 create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
9184 create_info.stageCount = 2;
9185 create_info.pStages = stages;
9186 create_info.pVertexInputState = &vertex_input_state;
9187 create_info.pInputAssemblyState = &input_assembly_state;
9188 create_info.pViewportState = &viewport_state;
9189 create_info.pMultisampleState = &multisample_state;
9190 create_info.pRasterizationState = &rasterization_state;
9191 create_info.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
9192 create_info.layout = pipeline_layout;
9193 create_info.renderPass = renderPass();
9194
9195 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01412);
9196 VkPipeline pipeline;
9197 vkCreateGraphicsPipelines(m_device->device(), pipeline_cache, 1, &create_info, nullptr, &pipeline);
9198 m_errorMonitor->VerifyFound();
9199 }
9200
9201 vkDestroyPipelineCache(m_device->device(), pipeline_cache, nullptr);
9202 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
9203}
9204
Karl Schultz6addd812016-02-02 17:17:23 -07009205TEST_F(VkLayerTest, NullRenderPass) {
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06009206 // Bind a NULL RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009207 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mike Schuchardt0b1f2f82016-12-28 15:11:20 -07009208 "vkCmdBeginRenderPass: required parameter pRenderPassBegin specified as NULL");
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06009209
Tony Barbour1fa09702017-03-16 12:09:08 -06009210 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06009211 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06009212
Tony Barbour552f6c02016-12-21 14:34:07 -07009213 m_commandBuffer->BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07009214 // Don't care about RenderPass handle b/c error should be flagged before
9215 // that
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009216 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06009217
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009218 m_errorMonitor->VerifyFound();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06009219}
9220
Karl Schultz6addd812016-02-02 17:17:23 -07009221TEST_F(VkLayerTest, RenderPassWithinRenderPass) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009222 // Bind a BeginRenderPass within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009223 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9224 "It is invalid to issue this call inside an active render pass");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009225
Tony Barbour1fa09702017-03-16 12:09:08 -06009226 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009227 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009228
Tony Barbour552f6c02016-12-21 14:34:07 -07009229 m_commandBuffer->BeginCommandBuffer();
9230 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Karl Schultz6addd812016-02-02 17:17:23 -07009231 // Just create a dummy Renderpass that's non-NULL so we can get to the
9232 // proper error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009233 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009234
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009235 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009236}
9237
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06009238TEST_F(VkLayerTest, RenderPassClearOpMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009239 TEST_DESCRIPTION(
9240 "Begin a renderPass where clearValueCount is less than"
9241 "the number of renderPass attachments that use loadOp"
9242 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06009243
Tony Barbour1fa09702017-03-16 12:09:08 -06009244 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06009245 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9246
9247 // Create a renderPass with a single attachment that uses loadOp CLEAR
9248 VkAttachmentReference attach = {};
9249 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
9250 VkSubpassDescription subpass = {};
Cort Stratton7547f772017-05-04 15:18:52 -07009251 subpass.colorAttachmentCount = 1;
9252 subpass.pColorAttachments = &attach;
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06009253 VkRenderPassCreateInfo rpci = {};
9254 rpci.subpassCount = 1;
9255 rpci.pSubpasses = &subpass;
9256 rpci.attachmentCount = 1;
9257 VkAttachmentDescription attach_desc = {};
Rene Lindsay4bf0e4c2017-01-31 14:20:34 -07009258 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06009259 // Set loadOp to CLEAR
9260 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
9261 rpci.pAttachments = &attach_desc;
9262 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
9263 VkRenderPass rp;
9264 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
9265
9266 VkCommandBufferInheritanceInfo hinfo = {};
9267 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
9268 hinfo.renderPass = VK_NULL_HANDLE;
9269 hinfo.subpass = 0;
9270 hinfo.framebuffer = VK_NULL_HANDLE;
9271 hinfo.occlusionQueryEnable = VK_FALSE;
9272 hinfo.queryFlags = 0;
9273 hinfo.pipelineStatistics = 0;
9274 VkCommandBufferBeginInfo info = {};
9275 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
9276 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
9277 info.pInheritanceInfo = &hinfo;
9278
9279 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
9280 VkRenderPassBeginInfo rp_begin = {};
9281 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
9282 rp_begin.pNext = NULL;
9283 rp_begin.renderPass = renderPass();
9284 rp_begin.framebuffer = framebuffer();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009285 rp_begin.clearValueCount = 0; // Should be 1
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06009286
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07009287 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00442);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06009288
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009289 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06009290
9291 m_errorMonitor->VerifyFound();
Mark Lobodzinski5c70ebd2016-06-09 13:45:00 -06009292
9293 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06009294}
9295
Slawomir Cygan0808f392016-11-28 17:53:23 +01009296TEST_F(VkLayerTest, RenderPassClearOpTooManyValues) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009297 TEST_DESCRIPTION(
9298 "Begin a renderPass where clearValueCount is greater than"
9299 "the number of renderPass attachments that use loadOp"
9300 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
Slawomir Cygan0808f392016-11-28 17:53:23 +01009301
Tony Barbour1fa09702017-03-16 12:09:08 -06009302 ASSERT_NO_FATAL_FAILURE(Init());
Slawomir Cygan0808f392016-11-28 17:53:23 +01009303 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9304
9305 // Create a renderPass with a single attachment that uses loadOp CLEAR
9306 VkAttachmentReference attach = {};
9307 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
9308 VkSubpassDescription subpass = {};
Cort Stratton7547f772017-05-04 15:18:52 -07009309 subpass.colorAttachmentCount = 1;
9310 subpass.pColorAttachments = &attach;
Slawomir Cygan0808f392016-11-28 17:53:23 +01009311 VkRenderPassCreateInfo rpci = {};
9312 rpci.subpassCount = 1;
9313 rpci.pSubpasses = &subpass;
9314 rpci.attachmentCount = 1;
9315 VkAttachmentDescription attach_desc = {};
9316 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
9317 // Set loadOp to CLEAR
9318 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
9319 rpci.pAttachments = &attach_desc;
9320 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
9321 VkRenderPass rp;
9322 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
9323
9324 VkCommandBufferBeginInfo info = {};
9325 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
9326 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
9327
9328 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
9329 VkRenderPassBeginInfo rp_begin = {};
9330 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
9331 rp_begin.pNext = NULL;
9332 rp_begin.renderPass = renderPass();
9333 rp_begin.framebuffer = framebuffer();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009334 rp_begin.clearValueCount = 2; // Should be 1
Slawomir Cygan0808f392016-11-28 17:53:23 +01009335
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07009336 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
9337 " has a clearValueCount of"
9338 " 2 but only first 1 entries in pClearValues array are used");
Slawomir Cygan0808f392016-11-28 17:53:23 +01009339
9340 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
9341
9342 m_errorMonitor->VerifyFound();
9343
9344 vkDestroyRenderPass(m_device->device(), rp, NULL);
9345}
9346
Cody Northrop3bb4d962016-05-09 16:15:57 -06009347TEST_F(VkLayerTest, EndCommandBufferWithinRenderPass) {
Cody Northrop3bb4d962016-05-09 16:15:57 -06009348 TEST_DESCRIPTION("End a command buffer with an active render pass");
9349
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009350 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9351 "It is invalid to issue this call inside an active render pass");
Cody Northrop3bb4d962016-05-09 16:15:57 -06009352
Tony Barbour1fa09702017-03-16 12:09:08 -06009353 ASSERT_NO_FATAL_FAILURE(Init());
Cody Northrop3bb4d962016-05-09 16:15:57 -06009354 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9355
Tony Barbour552f6c02016-12-21 14:34:07 -07009356 m_commandBuffer->BeginCommandBuffer();
9357 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
9358 vkEndCommandBuffer(m_commandBuffer->handle());
Cody Northrop3bb4d962016-05-09 16:15:57 -06009359
9360 m_errorMonitor->VerifyFound();
9361
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009362 // TODO: Add test for VK_COMMAND_BUFFER_LEVEL_SECONDARY
9363 // TODO: Add test for VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT
Cody Northrop3bb4d962016-05-09 16:15:57 -06009364}
9365
Karl Schultz6addd812016-02-02 17:17:23 -07009366TEST_F(VkLayerTest, FillBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009367 // Call CmdFillBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009368 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9369 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009370
Tony Barbour1fa09702017-03-16 12:09:08 -06009371 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009372 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009373
Tony Barbour552f6c02016-12-21 14:34:07 -07009374 m_commandBuffer->BeginCommandBuffer();
9375 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009376
9377 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009378 vk_testing::Buffer dstBuffer;
9379 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009380
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009381 m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009382
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009383 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009384}
9385
Karl Schultz6addd812016-02-02 17:17:23 -07009386TEST_F(VkLayerTest, UpdateBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009387 // Call CmdUpdateBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009388 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9389 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009390
Tony Barbour1fa09702017-03-16 12:09:08 -06009391 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009392 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009393
Tony Barbour552f6c02016-12-21 14:34:07 -07009394 m_commandBuffer->BeginCommandBuffer();
9395 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009396
9397 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009398 vk_testing::Buffer dstBuffer;
9399 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009400
Karl Schultz6addd812016-02-02 17:17:23 -07009401 VkDeviceSize dstOffset = 0;
Rene Lindsay32d26902017-02-02 16:49:24 -07009402 uint32_t Data[] = {1, 2, 3, 4, 5, 6, 7, 8};
9403 VkDeviceSize dataSize = sizeof(Data) / sizeof(uint32_t);
9404 vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(), dstOffset, dataSize, &Data);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009405
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009406 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009407}
9408
Karl Schultz6addd812016-02-02 17:17:23 -07009409TEST_F(VkLayerTest, ClearColorImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009410 // Call CmdClearColorImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009411 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9412 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009413
Tony Barbour1fa09702017-03-16 12:09:08 -06009414 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009415 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009416
Tony Barbour552f6c02016-12-21 14:34:07 -07009417 m_commandBuffer->BeginCommandBuffer();
9418 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009419
Michael Lentine0a369f62016-02-03 16:51:46 -06009420 VkClearColorValue clear_color;
9421 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
Karl Schultz6addd812016-02-02 17:17:23 -07009422 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
9423 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
9424 const int32_t tex_width = 32;
9425 const int32_t tex_height = 32;
9426 VkImageCreateInfo image_create_info = {};
9427 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
9428 image_create_info.pNext = NULL;
9429 image_create_info.imageType = VK_IMAGE_TYPE_2D;
9430 image_create_info.format = tex_format;
9431 image_create_info.extent.width = tex_width;
9432 image_create_info.extent.height = tex_height;
9433 image_create_info.extent.depth = 1;
9434 image_create_info.mipLevels = 1;
9435 image_create_info.arrayLayers = 1;
9436 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
9437 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
Jeremy Hayesa3d5c7b2017-03-07 16:01:52 -07009438 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009439
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009440 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009441 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009442
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009443 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009444
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009445 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009446
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009447 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009448}
9449
Karl Schultz6addd812016-02-02 17:17:23 -07009450TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009451 // Call CmdClearDepthStencilImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009452 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9453 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009454
Tony Barbour1fa09702017-03-16 12:09:08 -06009455 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009456 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009457
Dave Houlton1d2022c2017-03-29 11:43:58 -06009458 auto depth_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbourf887b162017-03-09 10:06:46 -07009459 if (!depth_format) {
9460 printf(" No Depth + Stencil format found. Skipped.\n");
9461 return;
9462 }
9463
Tony Barbour552f6c02016-12-21 14:34:07 -07009464 m_commandBuffer->BeginCommandBuffer();
9465 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009466
9467 VkClearDepthStencilValue clear_value = {0};
Dustin Gravesa2e5c942016-02-11 18:28:06 -07009468 VkMemoryPropertyFlags reqs = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07009469 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
9470 image_create_info.imageType = VK_IMAGE_TYPE_2D;
Tony Barbourf887b162017-03-09 10:06:46 -07009471 image_create_info.format = depth_format;
Karl Schultz6addd812016-02-02 17:17:23 -07009472 image_create_info.extent.width = 64;
9473 image_create_info.extent.height = 64;
9474 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
9475 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009476
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009477 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009478 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009479
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009480 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009481
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07009482 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_value, 1,
9483 &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009484
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009485 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009486}
9487
Karl Schultz6addd812016-02-02 17:17:23 -07009488TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass) {
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06009489 // Call CmdClearAttachmentss outside of an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07009490 VkResult err;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009491
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009492 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9493 "vkCmdClearAttachments(): This call "
9494 "must be issued inside an active "
9495 "render pass");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009496
Tony Barbour1fa09702017-03-16 12:09:08 -06009497 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009498 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009499
9500 // Start no RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009501 err = m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009502 ASSERT_VK_SUCCESS(err);
9503
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06009504 VkClearAttachment color_attachment;
9505 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9506 color_attachment.clearValue.color.float32[0] = 0;
9507 color_attachment.clearValue.color.float32[1] = 0;
9508 color_attachment.clearValue.color.float32[2] = 0;
9509 color_attachment.clearValue.color.float32[3] = 0;
9510 color_attachment.colorAttachment = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07009511 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009512 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009513
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009514 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009515}
9516
Chris Forbes3b97e932016-09-07 11:29:24 +12009517TEST_F(VkLayerTest, RenderPassExcessiveNextSubpass) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009518 TEST_DESCRIPTION(
9519 "Test that an error is produced when CmdNextSubpass is "
9520 "called too many times in a renderpass instance");
Chris Forbes3b97e932016-09-07 11:29:24 +12009521
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009522 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9523 "vkCmdNextSubpass(): Attempted to advance "
9524 "beyond final subpass");
Chris Forbes3b97e932016-09-07 11:29:24 +12009525
Tony Barbour1fa09702017-03-16 12:09:08 -06009526 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes3b97e932016-09-07 11:29:24 +12009527 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9528
Tony Barbour552f6c02016-12-21 14:34:07 -07009529 m_commandBuffer->BeginCommandBuffer();
9530 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes3b97e932016-09-07 11:29:24 +12009531
9532 // error here.
9533 vkCmdNextSubpass(m_commandBuffer->GetBufferHandle(), VK_SUBPASS_CONTENTS_INLINE);
9534 m_errorMonitor->VerifyFound();
9535
Tony Barbour552f6c02016-12-21 14:34:07 -07009536 m_commandBuffer->EndRenderPass();
9537 m_commandBuffer->EndCommandBuffer();
Chris Forbes3b97e932016-09-07 11:29:24 +12009538}
9539
Chris Forbes6d624702016-09-07 13:57:05 +12009540TEST_F(VkLayerTest, RenderPassEndedBeforeFinalSubpass) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009541 TEST_DESCRIPTION(
9542 "Test that an error is produced when CmdEndRenderPass is "
9543 "called before the final subpass has been reached");
Chris Forbes6d624702016-09-07 13:57:05 +12009544
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009545 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9546 "vkCmdEndRenderPass(): Called before reaching "
9547 "final subpass");
Chris Forbes6d624702016-09-07 13:57:05 +12009548
Tony Barbour1fa09702017-03-16 12:09:08 -06009549 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009550 VkSubpassDescription sd[2] = {{0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr},
9551 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr}};
Chris Forbes6d624702016-09-07 13:57:05 +12009552
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009553 VkRenderPassCreateInfo rcpi = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 2, sd, 0, nullptr};
Chris Forbes6d624702016-09-07 13:57:05 +12009554
9555 VkRenderPass rp;
9556 VkResult err = vkCreateRenderPass(m_device->device(), &rcpi, nullptr, &rp);
9557 ASSERT_VK_SUCCESS(err);
9558
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009559 VkFramebufferCreateInfo fbci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 16, 16, 1};
Chris Forbes6d624702016-09-07 13:57:05 +12009560
9561 VkFramebuffer fb;
9562 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
9563 ASSERT_VK_SUCCESS(err);
9564
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009565 m_commandBuffer->BeginCommandBuffer(); // no implicit RP begin
Chris Forbes6d624702016-09-07 13:57:05 +12009566
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009567 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 +12009568
9569 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
9570
9571 // Error here.
9572 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
9573 m_errorMonitor->VerifyFound();
9574
9575 // Clean up.
9576 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
9577 vkDestroyRenderPass(m_device->device(), rp, nullptr);
9578}
9579
Karl Schultz9e66a292016-04-21 15:57:51 -06009580TEST_F(VkLayerTest, BufferMemoryBarrierNoBuffer) {
9581 // Try to add a buffer memory barrier with no buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009582 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9583 "required parameter pBufferMemoryBarriers[0].buffer specified as VK_NULL_HANDLE");
Karl Schultz9e66a292016-04-21 15:57:51 -06009584
Tony Barbour1fa09702017-03-16 12:09:08 -06009585 ASSERT_NO_FATAL_FAILURE(Init());
Tony Barbour552f6c02016-12-21 14:34:07 -07009586 m_commandBuffer->BeginCommandBuffer();
Karl Schultz9e66a292016-04-21 15:57:51 -06009587
9588 VkBufferMemoryBarrier buf_barrier = {};
9589 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
9590 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
9591 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
9592 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
9593 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
9594 buf_barrier.buffer = VK_NULL_HANDLE;
9595 buf_barrier.offset = 0;
9596 buf_barrier.size = VK_WHOLE_SIZE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009597 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9598 nullptr, 1, &buf_barrier, 0, nullptr);
Karl Schultz9e66a292016-04-21 15:57:51 -06009599
9600 m_errorMonitor->VerifyFound();
9601}
9602
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009603TEST_F(VkLayerTest, InvalidBarriers) {
9604 TEST_DESCRIPTION("A variety of ways to get VK_INVALID_BARRIER ");
9605
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009606 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Barriers cannot be set during subpass");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009607
Tony Barbour1fa09702017-03-16 12:09:08 -06009608 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -06009609 auto depth_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbourf887b162017-03-09 10:06:46 -07009610 if (!depth_format) {
9611 printf(" No Depth + Stencil format found. Skipped.\n");
9612 return;
9613 }
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009614 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9615
9616 VkMemoryBarrier mem_barrier = {};
9617 mem_barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER;
9618 mem_barrier.pNext = NULL;
9619 mem_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
9620 mem_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
Tony Barbour552f6c02016-12-21 14:34:07 -07009621 m_commandBuffer->BeginCommandBuffer();
9622 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009623 // BeginCommandBuffer() starts a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009624 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 1,
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009625 &mem_barrier, 0, nullptr, 0, nullptr);
9626 m_errorMonitor->VerifyFound();
9627
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009628 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image Layout cannot be transitioned to UNDEFINED");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009629 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06009630 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 -06009631 ASSERT_TRUE(image.initialized());
9632 VkImageMemoryBarrier img_barrier = {};
9633 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
9634 img_barrier.pNext = NULL;
9635 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
9636 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
9637 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
9638 // New layout can't be UNDEFINED
9639 img_barrier.newLayout = VK_IMAGE_LAYOUT_UNDEFINED;
9640 img_barrier.image = image.handle();
9641 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
9642 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
9643 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9644 img_barrier.subresourceRange.baseArrayLayer = 0;
9645 img_barrier.subresourceRange.baseMipLevel = 0;
9646 img_barrier.subresourceRange.layerCount = 1;
9647 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009648 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9649 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009650 m_errorMonitor->VerifyFound();
9651 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
9652
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009653 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9654 "Subresource must have the sum of the "
9655 "baseArrayLayer");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009656 // baseArrayLayer + layerCount must be <= image's arrayLayers
9657 img_barrier.subresourceRange.baseArrayLayer = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009658 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9659 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009660 m_errorMonitor->VerifyFound();
9661 img_barrier.subresourceRange.baseArrayLayer = 0;
9662
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009663 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the baseMipLevel");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009664 // baseMipLevel + levelCount must be <= image's mipLevels
9665 img_barrier.subresourceRange.baseMipLevel = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009666 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9667 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009668 m_errorMonitor->VerifyFound();
9669 img_barrier.subresourceRange.baseMipLevel = 0;
9670
Mike Weiblen7053aa32017-01-25 15:21:10 -07009671 // levelCount must be non-zero.
9672 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
9673 img_barrier.subresourceRange.levelCount = 0;
9674 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9675 nullptr, 0, nullptr, 1, &img_barrier);
9676 m_errorMonitor->VerifyFound();
9677 img_barrier.subresourceRange.levelCount = 1;
9678
9679 // layerCount must be non-zero.
9680 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00769);
9681 img_barrier.subresourceRange.layerCount = 0;
9682 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9683 nullptr, 0, nullptr, 1, &img_barrier);
9684 m_errorMonitor->VerifyFound();
9685 img_barrier.subresourceRange.layerCount = 1;
9686
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009687 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 -06009688 vk_testing::Buffer buffer;
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07009689 VkMemoryPropertyFlags mem_reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
9690 buffer.init_as_src_and_dst(*m_device, 256, mem_reqs);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009691 VkBufferMemoryBarrier buf_barrier = {};
9692 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
9693 buf_barrier.pNext = NULL;
9694 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
9695 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
9696 buf_barrier.buffer = buffer.handle();
9697 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
9698 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
9699 buf_barrier.offset = 0;
9700 buf_barrier.size = VK_WHOLE_SIZE;
9701 // Can't send buffer barrier during a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009702 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9703 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009704 m_errorMonitor->VerifyFound();
9705 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
9706
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009707 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which is not less than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009708 buf_barrier.offset = 257;
9709 // Offset greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009710 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9711 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009712 m_errorMonitor->VerifyFound();
9713 buf_barrier.offset = 0;
9714
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009715 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "whose sum is greater than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009716 buf_barrier.size = 257;
9717 // Size greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009718 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9719 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009720 m_errorMonitor->VerifyFound();
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009721
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009722 // Now exercise barrier aspect bit errors, first DS
Tobin Ehlis99ab0d22017-04-26 16:53:52 -06009723 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00741);
9724 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00302);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009725 VkDepthStencilObj ds_image(m_device);
Tony Barbourf887b162017-03-09 10:06:46 -07009726 ds_image.Init(m_device, 128, 128, depth_format);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009727 ASSERT_TRUE(ds_image.initialized());
Tobin Ehlis15684a02016-07-21 14:55:26 -06009728 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
9729 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009730 img_barrier.image = ds_image.handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07009731
9732 // Not having DEPTH or STENCIL set is an error
Rene Lindsay4834cba2017-02-02 17:18:56 -07009733 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009734 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9735 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009736 m_errorMonitor->VerifyFound();
Dave Houltonfbf52152017-01-06 12:55:29 -07009737
Tobin Ehlis99ab0d22017-04-26 16:53:52 -06009738 // Having only one of depth or stencil set for DS image is an error
9739 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00302);
9740 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT;
9741 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9742 nullptr, 0, nullptr, 1, &img_barrier);
9743 m_errorMonitor->VerifyFound();
9744
9745 // Having anything other than DEPTH and STENCIL is an error
9746 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00741);
Dave Houltonfbf52152017-01-06 12:55:29 -07009747 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT | VK_IMAGE_ASPECT_COLOR_BIT;
9748 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9749 nullptr, 0, nullptr, 1, &img_barrier);
9750 m_errorMonitor->VerifyFound();
9751
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009752 // Now test depth-only
9753 VkFormatProperties format_props;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009754 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D16_UNORM, &format_props);
9755 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009756 VkDepthStencilObj d_image(m_device);
9757 d_image.Init(m_device, 128, 128, VK_FORMAT_D16_UNORM);
9758 ASSERT_TRUE(d_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009759 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06009760 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009761 img_barrier.image = d_image.handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07009762
9763 // DEPTH bit must be set
9764 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9765 "Depth-only image formats must have the VK_IMAGE_ASPECT_DEPTH_BIT set.");
Rene Lindsay4834cba2017-02-02 17:18:56 -07009766 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Dave Houltonfbf52152017-01-06 12:55:29 -07009767 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
9768 0, nullptr, 0, nullptr, 1, &img_barrier);
9769 m_errorMonitor->VerifyFound();
9770
9771 // No bits other than DEPTH may be set
9772 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9773 "Depth-only image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT set.");
9774 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009775 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
9776 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009777 m_errorMonitor->VerifyFound();
9778 }
Dave Houltonfbf52152017-01-06 12:55:29 -07009779
9780 // Now test stencil-only
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009781 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_S8_UINT, &format_props);
9782 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009783 VkDepthStencilObj s_image(m_device);
9784 s_image.Init(m_device, 128, 128, VK_FORMAT_S8_UINT);
9785 ASSERT_TRUE(s_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009786 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06009787 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009788 img_barrier.image = s_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06009789 // Use of COLOR aspect on depth image is error
Dave Houltonf3229d52017-02-21 15:59:08 -07009790 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9791 "Stencil-only image formats must have the VK_IMAGE_ASPECT_STENCIL_BIT set.");
Tobin Ehlis15684a02016-07-21 14:55:26 -06009792 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009793 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
9794 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009795 m_errorMonitor->VerifyFound();
9796 }
Dave Houltonfbf52152017-01-06 12:55:29 -07009797
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009798 // Finally test color
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009799 VkImageObj c_image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06009800 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 -06009801 ASSERT_TRUE(c_image.initialized());
9802 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
9803 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
9804 img_barrier.image = c_image.handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07009805
9806 // COLOR bit must be set
9807 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9808 "Color image formats must have the VK_IMAGE_ASPECT_COLOR_BIT set.");
Rene Lindsay4834cba2017-02-02 17:18:56 -07009809 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Dave Houltonfbf52152017-01-06 12:55:29 -07009810 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9811 nullptr, 0, nullptr, 1, &img_barrier);
9812 m_errorMonitor->VerifyFound();
9813
9814 // No bits other than COLOR may be set
9815 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9816 "Color image formats must have ONLY the VK_IMAGE_ASPECT_COLOR_BIT set.");
9817 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009818 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9819 nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009820 m_errorMonitor->VerifyFound();
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07009821
Mike Weiblene6e01172017-03-07 22:18:40 -07009822 // A barrier's new and old VkImageLayout must be compatible with an image's VkImageUsageFlags.
9823 {
9824 VkImageObj img_color(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06009825 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 -07009826 ASSERT_TRUE(img_color.initialized());
9827
9828 VkImageObj img_ds(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06009829 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 -07009830 ASSERT_TRUE(img_ds.initialized());
9831
9832 VkImageObj img_xfer_src(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06009833 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 -07009834 ASSERT_TRUE(img_xfer_src.initialized());
9835
9836 VkImageObj img_xfer_dst(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06009837 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 -07009838 ASSERT_TRUE(img_xfer_dst.initialized());
9839
9840 VkImageObj img_sampled(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06009841 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 -07009842 ASSERT_TRUE(img_sampled.initialized());
9843
9844 VkImageObj img_input(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06009845 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 -07009846 ASSERT_TRUE(img_input.initialized());
9847
9848 const struct {
9849 VkImageObj &image_obj;
9850 VkImageLayout bad_layout;
9851 UNIQUE_VALIDATION_ERROR_CODE msg_code;
9852 } bad_buffer_layouts[] = {
9853 // clang-format off
9854 // images _without_ VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT
9855 {img_ds, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VALIDATION_ERROR_00303},
9856 {img_xfer_src, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VALIDATION_ERROR_00303},
9857 {img_xfer_dst, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VALIDATION_ERROR_00303},
9858 {img_sampled, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VALIDATION_ERROR_00303},
9859 {img_input, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VALIDATION_ERROR_00303},
9860 // images _without_ VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT
9861 {img_color, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, VALIDATION_ERROR_00304},
9862 {img_xfer_src, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, VALIDATION_ERROR_00304},
9863 {img_xfer_dst, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, VALIDATION_ERROR_00304},
9864 {img_sampled, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, VALIDATION_ERROR_00304},
9865 {img_input, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, VALIDATION_ERROR_00304},
9866 {img_color, VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL, VALIDATION_ERROR_00305},
9867 {img_xfer_src, VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL, VALIDATION_ERROR_00305},
9868 {img_xfer_dst, VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL, VALIDATION_ERROR_00305},
9869 {img_sampled, VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL, VALIDATION_ERROR_00305},
9870 {img_input, VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL, VALIDATION_ERROR_00305},
9871 // images _without_ VK_IMAGE_USAGE_SAMPLED_BIT or VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT
9872 {img_color, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VALIDATION_ERROR_00306},
9873 {img_ds, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VALIDATION_ERROR_00306},
9874 {img_xfer_src, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VALIDATION_ERROR_00306},
9875 {img_xfer_dst, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VALIDATION_ERROR_00306},
9876 // images _without_ VK_IMAGE_USAGE_TRANSFER_SRC_BIT
9877 {img_color, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VALIDATION_ERROR_00307},
9878 {img_ds, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VALIDATION_ERROR_00307},
9879 {img_xfer_dst, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VALIDATION_ERROR_00307},
9880 {img_sampled, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VALIDATION_ERROR_00307},
9881 {img_input, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VALIDATION_ERROR_00307},
9882 // images _without_ VK_IMAGE_USAGE_TRANSFER_DST_BIT
9883 {img_color, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VALIDATION_ERROR_00308},
9884 {img_ds, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VALIDATION_ERROR_00308},
9885 {img_xfer_src, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VALIDATION_ERROR_00308},
9886 {img_sampled, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VALIDATION_ERROR_00308},
9887 {img_input, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VALIDATION_ERROR_00308},
9888 // clang-format on
9889 };
9890 const uint32_t layout_count = sizeof(bad_buffer_layouts) / sizeof(bad_buffer_layouts[0]);
9891
9892 for (uint32_t i = 0; i < layout_count; ++i) {
9893 img_barrier.image = bad_buffer_layouts[i].image_obj.handle();
9894 const VkImageUsageFlags usage = bad_buffer_layouts[i].image_obj.usage();
9895 img_barrier.subresourceRange.aspectMask = (usage == VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT)
9896 ? (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)
9897 : VK_IMAGE_ASPECT_COLOR_BIT;
9898
9899 img_barrier.oldLayout = bad_buffer_layouts[i].bad_layout;
9900 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
9901 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_buffer_layouts[i].msg_code);
9902 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT,
9903 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0, nullptr, 1, &img_barrier);
9904 m_errorMonitor->VerifyFound();
9905
9906 img_barrier.oldLayout = VK_IMAGE_LAYOUT_GENERAL;
9907 img_barrier.newLayout = bad_buffer_layouts[i].bad_layout;
9908 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_buffer_layouts[i].msg_code);
9909 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT,
9910 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0, nullptr, 1, &img_barrier);
9911 m_errorMonitor->VerifyFound();
9912 }
9913
9914 img_barrier.oldLayout = VK_IMAGE_LAYOUT_GENERAL;
9915 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
9916 }
9917
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07009918 // Attempt to mismatch barriers/waitEvents calls with incompatible queues
9919
9920 // Create command pool with incompatible queueflags
9921 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
Mike Schuchardt06304c22017-03-01 17:09:09 -07009922 uint32_t queue_family_index = m_device->QueueFamilyWithoutCapabilities(VK_QUEUE_COMPUTE_BIT);
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07009923 if (queue_family_index == UINT32_MAX) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07009924 printf(" No non-compute queue found; skipped.\n");
Mike Weiblene6e01172017-03-07 22:18:40 -07009925 return; // NOTE: this exits the test function!
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07009926 }
9927 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02513);
9928
9929 VkCommandPool command_pool;
9930 VkCommandPoolCreateInfo pool_create_info{};
9931 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
9932 pool_create_info.queueFamilyIndex = queue_family_index;
9933 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
9934 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
9935
9936 // Allocate a command buffer
9937 VkCommandBuffer bad_command_buffer;
9938 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
9939 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
9940 command_buffer_allocate_info.commandPool = command_pool;
9941 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
9942 command_buffer_allocate_info.commandBufferCount = 1;
9943 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &bad_command_buffer));
9944
9945 VkCommandBufferBeginInfo cbbi = {};
9946 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
9947 vkBeginCommandBuffer(bad_command_buffer, &cbbi);
9948 buf_barrier.offset = 0;
9949 buf_barrier.size = VK_WHOLE_SIZE;
9950 vkCmdPipelineBarrier(bad_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1,
9951 &buf_barrier, 0, nullptr);
9952 m_errorMonitor->VerifyFound();
9953
9954 if ((queue_props[queue_family_index].queueFlags & VK_QUEUE_GRAPHICS_BIT) == 0) {
9955 vkEndCommandBuffer(bad_command_buffer);
9956 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07009957 printf(" The non-compute queue does not support graphics; skipped.\n");
Mike Weiblene6e01172017-03-07 22:18:40 -07009958 return; // NOTE: this exits the test function!
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07009959 }
9960 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02510);
9961 VkEvent event;
9962 VkEventCreateInfo event_create_info{};
9963 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
9964 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
9965 vkCmdWaitEvents(bad_command_buffer, 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, nullptr, 0,
9966 nullptr, 0, nullptr);
9967 m_errorMonitor->VerifyFound();
9968
9969 vkEndCommandBuffer(bad_command_buffer);
9970 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009971}
9972
Chris Forbes50223732017-05-01 09:43:35 -07009973TEST_F(VkPositiveLayerTest, LayoutFromPresentWithoutAccessMemoryRead) {
9974 // Transition an image away from PRESENT_SRC_KHR without ACCESS_MEMORY_READ
9975 // in srcAccessMask.
Tony Barbour18ba25c2016-09-29 13:42:40 -06009976
Chris Forbes50223732017-05-01 09:43:35 -07009977 // The required behavior here was a bit unclear in earlier versions of the
9978 // spec, but there is no memory dependency required here, so this should
9979 // work without warnings.
9980
9981 m_errorMonitor->ExpectSuccess();
Tony Barbour1fa09702017-03-16 12:09:08 -06009982 ASSERT_NO_FATAL_FAILURE(Init());
Tony Barbour18ba25c2016-09-29 13:42:40 -06009983 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06009984 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 -07009985 VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbour18ba25c2016-09-29 13:42:40 -06009986 ASSERT_TRUE(image.initialized());
9987
9988 VkImageMemoryBarrier barrier = {};
9989 VkImageSubresourceRange range;
9990 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
Tony Barbour18ba25c2016-09-29 13:42:40 -06009991 barrier.srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
Chris Forbes50223732017-05-01 09:43:35 -07009992 barrier.dstAccessMask = 0;
Tony Barbour18ba25c2016-09-29 13:42:40 -06009993 barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
9994 barrier.newLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
9995 barrier.image = image.handle();
9996 range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9997 range.baseMipLevel = 0;
9998 range.levelCount = 1;
9999 range.baseArrayLayer = 0;
10000 range.layerCount = 1;
10001 barrier.subresourceRange = range;
10002 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
10003 cmdbuf.BeginCommandBuffer();
10004 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
10005 &barrier);
10006 barrier.oldLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
10007 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
10008 barrier.srcAccessMask = 0;
10009 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
10010 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
10011 &barrier);
10012
Chris Forbes50223732017-05-01 09:43:35 -070010013 m_errorMonitor->VerifyNotFound();
Tony Barbour18ba25c2016-09-29 13:42:40 -060010014}
10015
Karl Schultz6addd812016-02-02 17:17:23 -070010016TEST_F(VkLayerTest, IdxBufferAlignmentError) {
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010017 // Bind a BeginRenderPass within an active RenderPass
Tony Barbour1fa09702017-03-16 12:09:08 -060010018 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010019 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010020
Jeremy Hayes483d95d2017-03-08 11:03:01 -070010021 uint32_t const indices[] = {0};
10022 VkBufferCreateInfo buf_info = {};
10023 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
10024 buf_info.size = 1024;
10025 buf_info.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
10026 buf_info.queueFamilyIndexCount = 1;
10027 buf_info.pQueueFamilyIndices = indices;
10028
10029 VkBuffer buffer;
10030 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
10031 ASSERT_VK_SUCCESS(err);
10032
10033 VkMemoryRequirements requirements;
10034 vkGetBufferMemoryRequirements(m_device->device(), buffer, &requirements);
10035
10036 VkMemoryAllocateInfo alloc_info{};
10037 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10038 alloc_info.pNext = NULL;
10039 alloc_info.memoryTypeIndex = 0;
10040 alloc_info.allocationSize = requirements.size;
10041 bool pass = m_device->phy().set_memory_type(requirements.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
10042 ASSERT_TRUE(pass);
10043
10044 VkDeviceMemory memory;
10045 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &memory);
10046 ASSERT_VK_SUCCESS(err);
10047
10048 err = vkBindBufferMemory(m_device->device(), buffer, memory, 0);
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010049 ASSERT_VK_SUCCESS(err);
10050
Tony Barbour552f6c02016-12-21 14:34:07 -070010051 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010052 ASSERT_VK_SUCCESS(err);
Jeremy Hayes483d95d2017-03-08 11:03:01 -070010053
Karl Schultz6addd812016-02-02 17:17:23 -070010054 // vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
10055 // VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010056 // Should error before calling to driver so don't care about actual data
Jeremy Hayes483d95d2017-03-08 11:03:01 -070010057 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdBindIndexBuffer() offset (0x7) does not fall on ");
10058 vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), buffer, 7, VK_INDEX_TYPE_UINT16);
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010059 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010060
Jeremy Hayes483d95d2017-03-08 11:03:01 -070010061 vkFreeMemory(m_device->device(), memory, NULL);
10062 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010063}
10064
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -070010065TEST_F(VkLayerTest, InvalidQueueFamilyIndex) {
10066 // Create an out-of-range queueFamilyIndex
Tony Barbour1fa09702017-03-16 12:09:08 -060010067 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -070010068 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10069 VkBufferCreateInfo buffCI = {};
10070 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
10071 buffCI.size = 1024;
Mark Lobodzinski4761d212017-02-28 13:12:44 -070010072 buffCI.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
Jeremy Hayes8a43a0d2017-03-09 11:27:52 -070010073 buffCI.queueFamilyIndexCount = 2;
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -070010074 // Introduce failure by specifying invalid queue_family_index
Mark Lobodzinski4761d212017-02-28 13:12:44 -070010075 uint32_t qfi[2];
10076 qfi[0] = 777;
Jeremy Hayes8a43a0d2017-03-09 11:27:52 -070010077 qfi[1] = 0;
Mark Lobodzinski4761d212017-02-28 13:12:44 -070010078
10079 buffCI.pQueueFamilyIndices = qfi;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010080 buffCI.sharingMode = VK_SHARING_MODE_CONCURRENT; // qfi only matters in CONCURRENT mode
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -070010081
10082 VkBuffer ib;
Jeremy Hayes8a43a0d2017-03-09 11:27:52 -070010083 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10084 "vkCreateBuffer: pCreateInfo->pQueueFamilyIndices[0] (777) must be one of the indices "
10085 "specified when the device was created, via the VkDeviceQueueCreateInfo structure.");
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -070010086 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010087 m_errorMonitor->VerifyFound();
Mark Lobodzinski4761d212017-02-28 13:12:44 -070010088
10089 if (m_device->queue_props.size() > 2) {
Tony Barbour75db7402017-03-09 14:51:36 -070010090 VkBuffer ib2;
Mark Lobodzinski4761d212017-02-28 13:12:44 -070010091 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which was not created allowing concurrent");
10092
10093 // Create buffer shared to queue families 1 and 2, but submitted on queue family 0
10094 buffCI.queueFamilyIndexCount = 2;
10095 qfi[0] = 1;
10096 qfi[1] = 2;
Tony Barbour75db7402017-03-09 14:51:36 -070010097 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib2);
Mark Lobodzinski4761d212017-02-28 13:12:44 -070010098 VkDeviceMemory mem;
10099 VkMemoryRequirements mem_reqs;
Tony Barbour75db7402017-03-09 14:51:36 -070010100 vkGetBufferMemoryRequirements(m_device->device(), ib2, &mem_reqs);
Mark Lobodzinski4761d212017-02-28 13:12:44 -070010101
10102 VkMemoryAllocateInfo alloc_info = {};
10103 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10104 alloc_info.allocationSize = 1024;
10105 bool pass = false;
10106 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
10107 if (!pass) {
Tony Barbour75db7402017-03-09 14:51:36 -070010108 vkDestroyBuffer(m_device->device(), ib2, NULL);
Mark Lobodzinski4761d212017-02-28 13:12:44 -070010109 return;
10110 }
10111 vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
Tony Barbour75db7402017-03-09 14:51:36 -070010112 vkBindBufferMemory(m_device->device(), ib2, mem, 0);
Mark Lobodzinski4761d212017-02-28 13:12:44 -070010113
10114 m_commandBuffer->begin();
Tony Barbour75db7402017-03-09 14:51:36 -070010115 vkCmdFillBuffer(m_commandBuffer->handle(), ib2, 0, 16, 5);
Mark Lobodzinski4761d212017-02-28 13:12:44 -070010116 m_commandBuffer->end();
10117 QueueCommandBuffer(false);
10118 m_errorMonitor->VerifyFound();
Tony Barbour75db7402017-03-09 14:51:36 -070010119 vkDestroyBuffer(m_device->device(), ib2, NULL);
10120 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski4761d212017-02-28 13:12:44 -070010121 }
10122
Tony Barbourdf4c0042016-06-01 15:55:43 -060010123 vkDestroyBuffer(m_device->device(), ib, NULL);
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -070010124}
10125
Karl Schultz6addd812016-02-02 17:17:23 -070010126TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010127 TEST_DESCRIPTION(
10128 "Attempt vkCmdExecuteCommands with a primary command buffer"
10129 " (should only be secondary)");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010130
Tony Barbour1fa09702017-03-16 12:09:08 -060010131 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -060010132 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -060010133
Chris Forbesf29a84f2016-10-06 18:39:28 +130010134 // An empty primary command buffer
10135 VkCommandBufferObj cb(m_device, m_commandPool);
10136 cb.BeginCommandBuffer();
10137 cb.EndCommandBuffer();
Tobin Ehlis0c94db02016-07-19 10:49:32 -060010138
Chris Forbesf29a84f2016-10-06 18:39:28 +130010139 m_commandBuffer->BeginCommandBuffer();
10140 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
10141 VkCommandBuffer handle = cb.handle();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -060010142
Chris Forbesf29a84f2016-10-06 18:39:28 +130010143 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdExecuteCommands() called w/ Primary Cmd Buffer ");
10144 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &handle);
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010145 m_errorMonitor->VerifyFound();
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070010146
Tobin Ehlis6d4d1d52017-04-05 12:06:10 -060010147 m_errorMonitor->SetUnexpectedError("All elements of pCommandBuffers must not be in the pending state");
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -060010148}
10149
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010150TEST_F(VkLayerTest, DSUsageBitsErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010151 TEST_DESCRIPTION(
10152 "Attempt to update descriptor sets for images and buffers "
10153 "that do not have correct usage bits sets.");
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010154 VkResult err;
10155
Tony Barbour1fa09702017-03-16 12:09:08 -060010156 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010157 VkDescriptorPoolSize ds_type_count[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
10158 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
10159 ds_type_count[i].type = VkDescriptorType(i);
10160 ds_type_count[i].descriptorCount = 1;
10161 }
10162 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10163 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10164 ds_pool_ci.pNext = NULL;
10165 ds_pool_ci.maxSets = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
10166 ds_pool_ci.poolSizeCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
10167 ds_pool_ci.pPoolSizes = ds_type_count;
10168
10169 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010170 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010171 ASSERT_VK_SUCCESS(err);
10172
10173 // Create 10 layouts where each has a single descriptor of different type
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010174 VkDescriptorSetLayoutBinding dsl_binding[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010175 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
10176 dsl_binding[i].binding = 0;
10177 dsl_binding[i].descriptorType = VkDescriptorType(i);
10178 dsl_binding[i].descriptorCount = 1;
10179 dsl_binding[i].stageFlags = VK_SHADER_STAGE_ALL;
10180 dsl_binding[i].pImmutableSamplers = NULL;
10181 }
10182
10183 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10184 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10185 ds_layout_ci.pNext = NULL;
10186 ds_layout_ci.bindingCount = 1;
10187 VkDescriptorSetLayout ds_layouts[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
10188 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
10189 ds_layout_ci.pBindings = dsl_binding + i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010190 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, ds_layouts + i);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010191 ASSERT_VK_SUCCESS(err);
10192 }
10193 VkDescriptorSet descriptor_sets[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
10194 VkDescriptorSetAllocateInfo alloc_info = {};
10195 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10196 alloc_info.descriptorSetCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
10197 alloc_info.descriptorPool = ds_pool;
10198 alloc_info.pSetLayouts = ds_layouts;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010199 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010200 ASSERT_VK_SUCCESS(err);
10201
10202 // Create a buffer & bufferView to be used for invalid updates
10203 VkBufferCreateInfo buff_ci = {};
10204 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Tony Barbour415497c2017-01-24 10:06:09 -070010205 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010206 buff_ci.size = 256;
10207 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
Tony Barbour415497c2017-01-24 10:06:09 -070010208 VkBuffer buffer, storage_texel_buffer;
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010209 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
10210 ASSERT_VK_SUCCESS(err);
Tony Barbour415497c2017-01-24 10:06:09 -070010211
10212 // Create another buffer to use in testing the UNIFORM_TEXEL_BUFFER case
10213 buff_ci.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
10214 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &storage_texel_buffer);
10215 ASSERT_VK_SUCCESS(err);
10216
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -070010217 VkMemoryRequirements mem_reqs;
10218 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
10219 VkMemoryAllocateInfo mem_alloc_info = {};
10220 mem_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10221 mem_alloc_info.pNext = NULL;
10222 mem_alloc_info.memoryTypeIndex = 0;
10223 mem_alloc_info.allocationSize = mem_reqs.size;
10224 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc_info, 0);
10225 if (!pass) {
10226 vkDestroyBuffer(m_device->device(), buffer, NULL);
10227 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10228 return;
10229 }
10230 VkDeviceMemory mem;
10231 err = vkAllocateMemory(m_device->device(), &mem_alloc_info, NULL, &mem);
10232 ASSERT_VK_SUCCESS(err);
10233 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
10234 ASSERT_VK_SUCCESS(err);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010235
10236 VkBufferViewCreateInfo buff_view_ci = {};
10237 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
10238 buff_view_ci.buffer = buffer;
10239 buff_view_ci.format = VK_FORMAT_R8_UNORM;
10240 buff_view_ci.range = VK_WHOLE_SIZE;
10241 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010242 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010243 ASSERT_VK_SUCCESS(err);
10244
Tony Barbour415497c2017-01-24 10:06:09 -070010245 // Now get resources / view for storage_texel_buffer
10246 vkGetBufferMemoryRequirements(m_device->device(), storage_texel_buffer, &mem_reqs);
10247 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc_info, 0);
10248 if (!pass) {
10249 vkDestroyBuffer(m_device->device(), buffer, NULL);
10250 vkDestroyBufferView(m_device->device(), buff_view, NULL);
10251 vkFreeMemory(m_device->device(), mem, NULL);
10252 vkDestroyBuffer(m_device->device(), storage_texel_buffer, NULL);
10253 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10254 return;
10255 }
10256 VkDeviceMemory storage_texel_buffer_mem;
10257 VkBufferView storage_texel_buffer_view;
10258 err = vkAllocateMemory(m_device->device(), &mem_alloc_info, NULL, &storage_texel_buffer_mem);
10259 ASSERT_VK_SUCCESS(err);
10260 err = vkBindBufferMemory(m_device->device(), storage_texel_buffer, storage_texel_buffer_mem, 0);
10261 ASSERT_VK_SUCCESS(err);
10262 buff_view_ci.buffer = storage_texel_buffer;
10263 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &storage_texel_buffer_view);
10264 ASSERT_VK_SUCCESS(err);
10265
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010266 // Create an image to be used for invalid updates
Tony Barbour4b4a4222017-01-24 11:46:34 -070010267 // Find a format / tiling for COLOR_ATTACHMENT
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010268 VkImageCreateInfo image_ci = {};
Tony Barbour4b4a4222017-01-24 11:46:34 -070010269 image_ci.format = VK_FORMAT_UNDEFINED;
10270 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
10271 VkFormat format = static_cast<VkFormat>(f);
10272 VkFormatProperties fProps = m_device->format_properties(format);
10273 if (fProps.linearTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) {
10274 image_ci.format = format;
10275 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
10276 break;
10277 } else if (fProps.optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) {
10278 image_ci.format = format;
10279 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
10280 break;
10281 }
10282 }
10283 if (image_ci.format == VK_FORMAT_UNDEFINED) {
10284 return;
10285 }
10286
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010287 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10288 image_ci.imageType = VK_IMAGE_TYPE_2D;
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010289 image_ci.extent.width = 64;
10290 image_ci.extent.height = 64;
10291 image_ci.extent.depth = 1;
10292 image_ci.mipLevels = 1;
10293 image_ci.arrayLayers = 1;
10294 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010295 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
Tony Barbour4b4a4222017-01-24 11:46:34 -070010296 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010297 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
10298 VkImage image;
10299 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
10300 ASSERT_VK_SUCCESS(err);
10301 // Bind memory to image
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010302 VkDeviceMemory image_mem;
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -070010303
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010304 VkMemoryAllocateInfo mem_alloc = {};
10305 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10306 mem_alloc.pNext = NULL;
10307 mem_alloc.allocationSize = 0;
10308 mem_alloc.memoryTypeIndex = 0;
10309 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
10310 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010311 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010312 ASSERT_TRUE(pass);
10313 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
10314 ASSERT_VK_SUCCESS(err);
10315 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
10316 ASSERT_VK_SUCCESS(err);
10317 // Now create view for image
10318 VkImageViewCreateInfo image_view_ci = {};
10319 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
10320 image_view_ci.image = image;
Tony Barbour4b4a4222017-01-24 11:46:34 -070010321 image_view_ci.format = image_ci.format;
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010322 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
10323 image_view_ci.subresourceRange.layerCount = 1;
10324 image_view_ci.subresourceRange.baseArrayLayer = 0;
10325 image_view_ci.subresourceRange.levelCount = 1;
10326 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10327 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010328 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010329 ASSERT_VK_SUCCESS(err);
10330
10331 VkDescriptorBufferInfo buff_info = {};
10332 buff_info.buffer = buffer;
10333 VkDescriptorImageInfo img_info = {};
10334 img_info.imageView = image_view;
10335 VkWriteDescriptorSet descriptor_write = {};
10336 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10337 descriptor_write.dstBinding = 0;
10338 descriptor_write.descriptorCount = 1;
10339 descriptor_write.pTexelBufferView = &buff_view;
10340 descriptor_write.pBufferInfo = &buff_info;
10341 descriptor_write.pImageInfo = &img_info;
10342
10343 // These error messages align with VkDescriptorType struct
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -070010344 UNIQUE_VALIDATION_ERROR_CODE error_codes[] = {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010345 VALIDATION_ERROR_00943, // placeholder, no error for SAMPLER descriptor
10346 VALIDATION_ERROR_00943, // COMBINED_IMAGE_SAMPLER
10347 VALIDATION_ERROR_00943, // SAMPLED_IMAGE
10348 VALIDATION_ERROR_00943, // STORAGE_IMAGE
10349 VALIDATION_ERROR_00950, // UNIFORM_TEXEL_BUFFER
10350 VALIDATION_ERROR_00951, // STORAGE_TEXEL_BUFFER
10351 VALIDATION_ERROR_00946, // UNIFORM_BUFFER
10352 VALIDATION_ERROR_00947, // STORAGE_BUFFER
10353 VALIDATION_ERROR_00946, // UNIFORM_BUFFER_DYNAMIC
10354 VALIDATION_ERROR_00947, // STORAGE_BUFFER_DYNAMIC
10355 VALIDATION_ERROR_00943 // INPUT_ATTACHMENT
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -070010356 };
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010357 // Start loop at 1 as SAMPLER desc type has no usage bit error
10358 for (uint32_t i = 1; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
Tony Barbour415497c2017-01-24 10:06:09 -070010359 if (VkDescriptorType(i) == VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER) {
10360 // Now check for UNIFORM_TEXEL_BUFFER using storage_texel_buffer_view
10361 descriptor_write.pTexelBufferView = &storage_texel_buffer_view;
10362 }
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010363 descriptor_write.descriptorType = VkDescriptorType(i);
10364 descriptor_write.dstSet = descriptor_sets[i];
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -070010365 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_codes[i]);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010366
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010367 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010368
10369 m_errorMonitor->VerifyFound();
10370 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[i], NULL);
Tony Barbour415497c2017-01-24 10:06:09 -070010371 if (VkDescriptorType(i) == VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER) {
10372 descriptor_write.pTexelBufferView = &buff_view;
10373 }
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010374 }
Tony Barbour415497c2017-01-24 10:06:09 -070010375
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010376 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[0], NULL);
10377 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -060010378 vkFreeMemory(m_device->device(), image_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010379 vkDestroyImageView(m_device->device(), image_view, NULL);
10380 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tony Barbour415497c2017-01-24 10:06:09 -070010381 vkDestroyBuffer(m_device->device(), storage_texel_buffer, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010382 vkDestroyBufferView(m_device->device(), buff_view, NULL);
Tony Barbour415497c2017-01-24 10:06:09 -070010383 vkDestroyBufferView(m_device->device(), storage_texel_buffer_view, NULL);
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -070010384 vkFreeMemory(m_device->device(), mem, NULL);
Tony Barbour415497c2017-01-24 10:06:09 -070010385 vkFreeMemory(m_device->device(), storage_texel_buffer_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010386 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10387}
10388
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010389TEST_F(VkLayerTest, DSBufferInfoErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010390 TEST_DESCRIPTION(
10391 "Attempt to update buffer descriptor set that has incorrect "
10392 "parameters in VkDescriptorBufferInfo struct. This includes:\n"
Jeremy Hayesd1a6a822017-03-09 14:39:45 -070010393 "1. offset value greater than or equal to buffer size\n"
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010394 "2. range value of 0\n"
10395 "3. range value greater than buffer (size - offset)");
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010396 VkResult err;
10397
Tony Barbour1fa09702017-03-16 12:09:08 -060010398 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010399 VkDescriptorPoolSize ds_type_count = {};
10400 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10401 ds_type_count.descriptorCount = 1;
10402
10403 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10404 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10405 ds_pool_ci.pNext = NULL;
Jeremy Hayesd1a6a822017-03-09 14:39:45 -070010406 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010407 ds_pool_ci.maxSets = 1;
10408 ds_pool_ci.poolSizeCount = 1;
10409 ds_pool_ci.pPoolSizes = &ds_type_count;
10410
10411 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010412 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010413 ASSERT_VK_SUCCESS(err);
10414
10415 // Create layout with single uniform buffer descriptor
10416 VkDescriptorSetLayoutBinding dsl_binding = {};
10417 dsl_binding.binding = 0;
10418 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10419 dsl_binding.descriptorCount = 1;
10420 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10421 dsl_binding.pImmutableSamplers = NULL;
10422
10423 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10424 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10425 ds_layout_ci.pNext = NULL;
10426 ds_layout_ci.bindingCount = 1;
10427 ds_layout_ci.pBindings = &dsl_binding;
10428 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010429 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010430 ASSERT_VK_SUCCESS(err);
10431
10432 VkDescriptorSet descriptor_set = {};
10433 VkDescriptorSetAllocateInfo alloc_info = {};
10434 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10435 alloc_info.descriptorSetCount = 1;
10436 alloc_info.descriptorPool = ds_pool;
10437 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010438 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010439 ASSERT_VK_SUCCESS(err);
10440
10441 // Create a buffer to be used for invalid updates
10442 VkBufferCreateInfo buff_ci = {};
10443 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
10444 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
Jeremy Hayesd1a6a822017-03-09 14:39:45 -070010445 buff_ci.size = m_device->props.limits.minUniformBufferOffsetAlignment;
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010446 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
10447 VkBuffer buffer;
10448 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
10449 ASSERT_VK_SUCCESS(err);
Jeremy Hayesd1a6a822017-03-09 14:39:45 -070010450
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010451 // Have to bind memory to buffer before descriptor update
10452 VkMemoryAllocateInfo mem_alloc = {};
10453 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10454 mem_alloc.pNext = NULL;
Jeremy Hayesd1a6a822017-03-09 14:39:45 -070010455 mem_alloc.allocationSize = buff_ci.size;
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010456 mem_alloc.memoryTypeIndex = 0;
10457
10458 VkMemoryRequirements mem_reqs;
10459 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010460 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010461 if (!pass) {
10462 vkDestroyBuffer(m_device->device(), buffer, NULL);
10463 return;
10464 }
10465
10466 VkDeviceMemory mem;
10467 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
10468 ASSERT_VK_SUCCESS(err);
10469 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
10470 ASSERT_VK_SUCCESS(err);
10471
10472 VkDescriptorBufferInfo buff_info = {};
10473 buff_info.buffer = buffer;
Jeremy Hayesd1a6a822017-03-09 14:39:45 -070010474 // Cause error due to offset out of range
10475 buff_info.offset = buff_ci.size;
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010476 buff_info.range = VK_WHOLE_SIZE;
10477 VkWriteDescriptorSet descriptor_write = {};
10478 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10479 descriptor_write.dstBinding = 0;
10480 descriptor_write.descriptorCount = 1;
10481 descriptor_write.pTexelBufferView = nullptr;
10482 descriptor_write.pBufferInfo = &buff_info;
10483 descriptor_write.pImageInfo = nullptr;
10484
10485 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10486 descriptor_write.dstSet = descriptor_set;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070010487 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00959);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010488
10489 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10490
10491 m_errorMonitor->VerifyFound();
10492 // Now cause error due to range of 0
10493 buff_info.offset = 0;
10494 buff_info.range = 0;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070010495 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00960);
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 exceeding buffer size - offset
Jeremy Hayesd1a6a822017-03-09 14:39:45 -070010501 buff_info.offset = 0;
10502 buff_info.range = buff_ci.size + 1;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070010503 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00961);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010504
10505 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10506
10507 m_errorMonitor->VerifyFound();
Mark Lobodzinski4bb54092016-07-06 14:27:19 -060010508 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010509 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10510 vkDestroyBuffer(m_device->device(), buffer, NULL);
10511 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
10512 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10513}
10514
Tobin Ehlis845887e2017-02-02 19:01:44 -070010515TEST_F(VkLayerTest, DSBufferLimitErrors) {
10516 TEST_DESCRIPTION(
10517 "Attempt to update buffer descriptor set that has VkDescriptorBufferInfo values that violate device limits.\n"
10518 "Test cases include:\n"
10519 "1. range of uniform buffer update exceeds maxUniformBufferRange\n"
10520 "2. offset of uniform buffer update is not multiple of minUniformBufferOffsetAlignment\n"
10521 "3. range of storage buffer update exceeds maxStorageBufferRange\n"
10522 "4. offset of storage buffer update is not multiple of minStorageBufferOffsetAlignment");
10523 VkResult err;
10524
Tony Barbour1fa09702017-03-16 12:09:08 -060010525 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis845887e2017-02-02 19:01:44 -070010526 VkDescriptorPoolSize ds_type_count[2] = {};
10527 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10528 ds_type_count[0].descriptorCount = 1;
10529 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
10530 ds_type_count[1].descriptorCount = 1;
10531
10532 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10533 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10534 ds_pool_ci.pNext = NULL;
10535 ds_pool_ci.maxSets = 1;
10536 ds_pool_ci.poolSizeCount = 2;
10537 ds_pool_ci.pPoolSizes = ds_type_count;
10538
10539 VkDescriptorPool ds_pool;
10540 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
10541 ASSERT_VK_SUCCESS(err);
10542
10543 // Create layout with single uniform buffer & single storage buffer descriptor
10544 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
10545 dsl_binding[0].binding = 0;
10546 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10547 dsl_binding[0].descriptorCount = 1;
10548 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
10549 dsl_binding[0].pImmutableSamplers = NULL;
10550 dsl_binding[1].binding = 1;
10551 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
10552 dsl_binding[1].descriptorCount = 1;
10553 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
10554 dsl_binding[1].pImmutableSamplers = NULL;
10555
10556 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10557 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10558 ds_layout_ci.pNext = NULL;
10559 ds_layout_ci.bindingCount = 2;
10560 ds_layout_ci.pBindings = dsl_binding;
10561 VkDescriptorSetLayout ds_layout;
10562 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
10563 ASSERT_VK_SUCCESS(err);
10564
10565 VkDescriptorSet descriptor_set = {};
10566 VkDescriptorSetAllocateInfo alloc_info = {};
10567 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10568 alloc_info.descriptorSetCount = 1;
10569 alloc_info.descriptorPool = ds_pool;
10570 alloc_info.pSetLayouts = &ds_layout;
10571 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
10572 ASSERT_VK_SUCCESS(err);
10573
10574 // Create a buffer to be used for invalid updates
10575 auto max_ub_range = m_device->props.limits.maxUniformBufferRange;
10576 auto min_ub_align = m_device->props.limits.minUniformBufferOffsetAlignment;
10577 auto max_sb_range = m_device->props.limits.maxStorageBufferRange;
10578 auto min_sb_align = m_device->props.limits.minStorageBufferOffsetAlignment;
10579 VkBufferCreateInfo ub_ci = {};
10580 ub_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
10581 ub_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
10582 ub_ci.size = max_ub_range + 128; // Make buffer bigger than range limit
10583 ub_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
10584 VkBuffer uniform_buffer;
10585 err = vkCreateBuffer(m_device->device(), &ub_ci, NULL, &uniform_buffer);
10586 ASSERT_VK_SUCCESS(err);
10587 VkBufferCreateInfo sb_ci = {};
10588 sb_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
10589 sb_ci.usage = VK_BUFFER_USAGE_STORAGE_BUFFER_BIT;
10590 sb_ci.size = max_sb_range + 128; // Make buffer bigger than range limit
10591 sb_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
10592 VkBuffer storage_buffer;
10593 err = vkCreateBuffer(m_device->device(), &sb_ci, NULL, &storage_buffer);
10594 ASSERT_VK_SUCCESS(err);
10595 // Have to bind memory to buffer before descriptor update
10596 VkMemoryAllocateInfo mem_alloc = {};
10597 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10598 mem_alloc.pNext = NULL;
10599 mem_alloc.allocationSize = ub_ci.size + sb_ci.size + 1024; // additional buffer for offset
10600 mem_alloc.memoryTypeIndex = 0;
10601
Cort Stratton77a0d592017-02-17 13:14:13 -080010602 VkMemoryRequirements ub_mem_reqs, sb_mem_reqs;
10603 vkGetBufferMemoryRequirements(m_device->device(), uniform_buffer, &ub_mem_reqs);
10604 bool pass = m_device->phy().set_memory_type(ub_mem_reqs.memoryTypeBits, &mem_alloc, 0);
10605 vkGetBufferMemoryRequirements(m_device->device(), storage_buffer, &sb_mem_reqs);
10606 pass &= m_device->phy().set_memory_type(sb_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis845887e2017-02-02 19:01:44 -070010607 if (!pass) {
Tobin Ehlis15c83792017-02-07 10:09:33 -070010608 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Tobin Ehlis845887e2017-02-02 19:01:44 -070010609 vkDestroyBuffer(m_device->device(), uniform_buffer, NULL);
Tobin Ehlis15c83792017-02-07 10:09:33 -070010610 vkDestroyBuffer(m_device->device(), storage_buffer, NULL);
10611 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis845887e2017-02-02 19:01:44 -070010612 return;
10613 }
10614
10615 VkDeviceMemory mem;
10616 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlis15c83792017-02-07 10:09:33 -070010617 if (VK_SUCCESS != err) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070010618 printf(" Failed to allocate memory in DSBufferLimitErrors; skipped.\n");
Tobin Ehlis15c83792017-02-07 10:09:33 -070010619 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10620 vkDestroyBuffer(m_device->device(), uniform_buffer, NULL);
10621 vkDestroyBuffer(m_device->device(), storage_buffer, NULL);
10622 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10623 return;
10624 }
Tobin Ehlis845887e2017-02-02 19:01:44 -070010625 ASSERT_VK_SUCCESS(err);
10626 err = vkBindBufferMemory(m_device->device(), uniform_buffer, mem, 0);
10627 ASSERT_VK_SUCCESS(err);
Cort Stratton77a0d592017-02-17 13:14:13 -080010628 auto sb_offset = (ub_ci.size + sb_mem_reqs.alignment - 1) & ~(sb_mem_reqs.alignment - 1);
Tobin Ehlis845887e2017-02-02 19:01:44 -070010629 err = vkBindBufferMemory(m_device->device(), storage_buffer, mem, sb_offset);
10630 ASSERT_VK_SUCCESS(err);
10631
10632 VkDescriptorBufferInfo buff_info = {};
10633 buff_info.buffer = uniform_buffer;
10634 buff_info.range = ub_ci.size; // This will exceed limit
10635 VkWriteDescriptorSet descriptor_write = {};
10636 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10637 descriptor_write.dstBinding = 0;
10638 descriptor_write.descriptorCount = 1;
10639 descriptor_write.pTexelBufferView = nullptr;
10640 descriptor_write.pBufferInfo = &buff_info;
10641 descriptor_write.pImageInfo = nullptr;
10642
10643 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10644 descriptor_write.dstSet = descriptor_set;
Tony Barbour02d08552017-03-24 16:36:01 -060010645 if (max_ub_range != UINT32_MAX) {
10646 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00948);
10647 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10648 m_errorMonitor->VerifyFound();
10649 }
Tobin Ehlis845887e2017-02-02 19:01:44 -070010650 // Reduce size of range to acceptable limit & cause offset error
10651 buff_info.range = max_ub_range;
10652 buff_info.offset = min_ub_align - 1;
10653 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00944);
10654 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10655 m_errorMonitor->VerifyFound();
10656
10657 // Now break storage updates
10658 buff_info.buffer = storage_buffer;
10659 buff_info.range = sb_ci.size; // This will exceed limit
10660 buff_info.offset = 0; // Reset offset for this update
10661
10662 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
10663 descriptor_write.dstBinding = 1;
Tony Barbour02d08552017-03-24 16:36:01 -060010664 if (max_ub_range != UINT32_MAX) {
10665 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00949);
10666 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10667 m_errorMonitor->VerifyFound();
10668 }
Tobin Ehlis845887e2017-02-02 19:01:44 -070010669
10670 // Reduce size of range to acceptable limit & cause offset error
10671 buff_info.range = max_sb_range;
10672 buff_info.offset = min_sb_align - 1;
10673 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00945);
10674 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10675 m_errorMonitor->VerifyFound();
10676
10677 vkFreeMemory(m_device->device(), mem, NULL);
10678 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10679 vkDestroyBuffer(m_device->device(), uniform_buffer, NULL);
10680 vkDestroyBuffer(m_device->device(), storage_buffer, NULL);
10681 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10682}
10683
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010684TEST_F(VkLayerTest, DSAspectBitsErrors) {
10685 // TODO : Initially only catching case where DEPTH & STENCIL aspect bits
10686 // are set, but could expand this test to hit more cases.
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010687 TEST_DESCRIPTION(
10688 "Attempt to update descriptor sets for images "
10689 "that do not have correct aspect bits sets.");
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010690 VkResult err;
10691
Tony Barbour1fa09702017-03-16 12:09:08 -060010692 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -060010693 auto depth_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbourf887b162017-03-09 10:06:46 -070010694 if (!depth_format) {
10695 printf(" No Depth + Stencil format found. Skipped.\n");
10696 return;
10697 }
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010698 VkDescriptorPoolSize ds_type_count = {};
10699 ds_type_count.type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
10700 ds_type_count.descriptorCount = 1;
10701
10702 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10703 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10704 ds_pool_ci.pNext = NULL;
Jeremy Hayes293c7ed2017-03-09 14:47:07 -070010705 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010706 ds_pool_ci.maxSets = 5;
10707 ds_pool_ci.poolSizeCount = 1;
10708 ds_pool_ci.pPoolSizes = &ds_type_count;
10709
10710 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010711 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010712 ASSERT_VK_SUCCESS(err);
10713
10714 VkDescriptorSetLayoutBinding dsl_binding = {};
10715 dsl_binding.binding = 0;
10716 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
10717 dsl_binding.descriptorCount = 1;
10718 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10719 dsl_binding.pImmutableSamplers = NULL;
10720
10721 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10722 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10723 ds_layout_ci.pNext = NULL;
10724 ds_layout_ci.bindingCount = 1;
10725 ds_layout_ci.pBindings = &dsl_binding;
10726 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010727 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010728 ASSERT_VK_SUCCESS(err);
10729
10730 VkDescriptorSet descriptor_set = {};
10731 VkDescriptorSetAllocateInfo alloc_info = {};
10732 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10733 alloc_info.descriptorSetCount = 1;
10734 alloc_info.descriptorPool = ds_pool;
10735 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010736 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010737 ASSERT_VK_SUCCESS(err);
10738
10739 // Create an image to be used for invalid updates
10740 VkImageCreateInfo image_ci = {};
10741 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10742 image_ci.imageType = VK_IMAGE_TYPE_2D;
Tony Barbourf887b162017-03-09 10:06:46 -070010743 image_ci.format = depth_format;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010744 image_ci.extent.width = 64;
10745 image_ci.extent.height = 64;
10746 image_ci.extent.depth = 1;
10747 image_ci.mipLevels = 1;
10748 image_ci.arrayLayers = 1;
10749 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Young2d1fa302017-03-02 10:13:09 -070010750 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010751 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
10752 image_ci.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
10753 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
10754 VkImage image;
10755 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
10756 ASSERT_VK_SUCCESS(err);
10757 // Bind memory to image
10758 VkMemoryRequirements mem_reqs;
10759 VkDeviceMemory image_mem;
10760 bool pass;
10761 VkMemoryAllocateInfo mem_alloc = {};
10762 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10763 mem_alloc.pNext = NULL;
10764 mem_alloc.allocationSize = 0;
10765 mem_alloc.memoryTypeIndex = 0;
10766 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
10767 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010768 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010769 ASSERT_TRUE(pass);
10770 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
10771 ASSERT_VK_SUCCESS(err);
10772 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
10773 ASSERT_VK_SUCCESS(err);
10774 // Now create view for image
10775 VkImageViewCreateInfo image_view_ci = {};
10776 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
10777 image_view_ci.image = image;
Tony Barbourf887b162017-03-09 10:06:46 -070010778 image_view_ci.format = depth_format;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010779 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
10780 image_view_ci.subresourceRange.layerCount = 1;
10781 image_view_ci.subresourceRange.baseArrayLayer = 0;
10782 image_view_ci.subresourceRange.levelCount = 1;
10783 // Setting both depth & stencil aspect bits is illegal for descriptor
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010784 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010785
10786 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010787 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010788 ASSERT_VK_SUCCESS(err);
10789
10790 VkDescriptorImageInfo img_info = {};
10791 img_info.imageView = image_view;
10792 VkWriteDescriptorSet descriptor_write = {};
10793 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10794 descriptor_write.dstBinding = 0;
10795 descriptor_write.descriptorCount = 1;
10796 descriptor_write.pTexelBufferView = NULL;
10797 descriptor_write.pBufferInfo = NULL;
10798 descriptor_write.pImageInfo = &img_info;
10799 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
10800 descriptor_write.dstSet = descriptor_set;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010801 const char *error_msg =
10802 " please only set either VK_IMAGE_ASPECT_DEPTH_BIT "
10803 "or VK_IMAGE_ASPECT_STENCIL_BIT ";
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010804 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msg);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010805
10806 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10807
10808 m_errorMonitor->VerifyFound();
10809 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10810 vkDestroyImage(m_device->device(), image, NULL);
10811 vkFreeMemory(m_device->device(), image_mem, NULL);
10812 vkDestroyImageView(m_device->device(), image_view, NULL);
10813 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
10814 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10815}
10816
Karl Schultz6addd812016-02-02 17:17:23 -070010817TEST_F(VkLayerTest, DSTypeMismatch) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010818 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Karl Schultz6addd812016-02-02 17:17:23 -070010819 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010820
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010821 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10822 " binding #0 with type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER but update "
10823 "type is VK_DESCRIPTOR_TYPE_SAMPLER");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010824
Tony Barbour1fa09702017-03-16 12:09:08 -060010825 ASSERT_NO_FATAL_FAILURE(Init());
Karl Schultz6addd812016-02-02 17:17:23 -070010826 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010827 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010828 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10829 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010830
10831 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010832 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10833 ds_pool_ci.pNext = NULL;
10834 ds_pool_ci.maxSets = 1;
10835 ds_pool_ci.poolSizeCount = 1;
10836 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060010837
Tobin Ehlis3b780662015-05-28 12:11:26 -060010838 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010839 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010840 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -060010841 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010842 dsl_binding.binding = 0;
10843 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10844 dsl_binding.descriptorCount = 1;
10845 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10846 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010847
Tony Barboureb254902015-07-15 12:50:33 -060010848 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010849 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10850 ds_layout_ci.pNext = NULL;
10851 ds_layout_ci.bindingCount = 1;
10852 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010853
Tobin Ehlis3b780662015-05-28 12:11:26 -060010854 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010855 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010856 ASSERT_VK_SUCCESS(err);
10857
10858 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010859 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010860 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010861 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010862 alloc_info.descriptorPool = ds_pool;
10863 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010864 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010865 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010866
Tobin Ehlis30db8f82016-05-05 08:19:48 -060010867 VkSamplerCreateInfo sampler_ci = {};
10868 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10869 sampler_ci.pNext = NULL;
10870 sampler_ci.magFilter = VK_FILTER_NEAREST;
10871 sampler_ci.minFilter = VK_FILTER_NEAREST;
10872 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10873 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10874 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10875 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10876 sampler_ci.mipLodBias = 1.0;
10877 sampler_ci.anisotropyEnable = VK_FALSE;
10878 sampler_ci.maxAnisotropy = 1;
10879 sampler_ci.compareEnable = VK_FALSE;
10880 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10881 sampler_ci.minLod = 1.0;
10882 sampler_ci.maxLod = 1.0;
10883 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10884 sampler_ci.unnormalizedCoordinates = VK_FALSE;
10885 VkSampler sampler;
10886 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
10887 ASSERT_VK_SUCCESS(err);
10888
10889 VkDescriptorImageInfo info = {};
10890 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010891
10892 VkWriteDescriptorSet descriptor_write;
10893 memset(&descriptor_write, 0, sizeof(descriptor_write));
10894 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010895 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010896 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010897 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010898 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060010899 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010900
10901 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10902
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010903 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010904
Chia-I Wuf7458c52015-10-26 21:10:41 +080010905 vkDestroySampler(m_device->device(), sampler, NULL);
10906 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10907 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010908}
10909
Karl Schultz6addd812016-02-02 17:17:23 -070010910TEST_F(VkLayerTest, DSUpdateOutOfBounds) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010911 // For overlapping Update, have arrayIndex exceed that of layout
Karl Schultz6addd812016-02-02 17:17:23 -070010912 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010913
Tobin Ehlisf922ef82016-11-30 10:19:14 -070010914 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00938);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010915
Tony Barbour1fa09702017-03-16 12:09:08 -060010916 ASSERT_NO_FATAL_FAILURE(Init());
Karl Schultz6addd812016-02-02 17:17:23 -070010917 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010918 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010919 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10920 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010921
10922 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010923 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10924 ds_pool_ci.pNext = NULL;
10925 ds_pool_ci.maxSets = 1;
10926 ds_pool_ci.poolSizeCount = 1;
10927 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060010928
Tobin Ehlis3b780662015-05-28 12:11:26 -060010929 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010930 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010931 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010932
Tony Barboureb254902015-07-15 12:50:33 -060010933 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010934 dsl_binding.binding = 0;
10935 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10936 dsl_binding.descriptorCount = 1;
10937 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10938 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -060010939
10940 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010941 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10942 ds_layout_ci.pNext = NULL;
10943 ds_layout_ci.bindingCount = 1;
10944 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010945
Tobin Ehlis3b780662015-05-28 12:11:26 -060010946 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010947 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010948 ASSERT_VK_SUCCESS(err);
10949
10950 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010951 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010952 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010953 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010954 alloc_info.descriptorPool = ds_pool;
10955 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010956 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010957 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010958
Jeremy Hayesd5b95db2017-03-09 15:24:24 -070010959 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
10960
Tobin Ehlis30db8f82016-05-05 08:19:48 -060010961 // Correctly update descriptor to avoid "NOT_UPDATED" error
10962 VkDescriptorBufferInfo buff_info = {};
Jeremy Hayesd5b95db2017-03-09 15:24:24 -070010963 buff_info.buffer = buffer_test.GetBuffer();
Tobin Ehlis30db8f82016-05-05 08:19:48 -060010964 buff_info.offset = 0;
10965 buff_info.range = 1024;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010966
10967 VkWriteDescriptorSet descriptor_write;
10968 memset(&descriptor_write, 0, sizeof(descriptor_write));
10969 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010970 descriptor_write.dstSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010971 descriptor_write.dstArrayElement = 1; /* This index out of bounds for the update */
Chia-I Wud50a7d72015-10-26 20:48:51 +080010972 descriptor_write.descriptorCount = 1;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -060010973 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10974 descriptor_write.pBufferInfo = &buff_info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010975
10976 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10977
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010978 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010979
Chia-I Wuf7458c52015-10-26 21:10:41 +080010980 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10981 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010982}
10983
Karl Schultz6addd812016-02-02 17:17:23 -070010984TEST_F(VkLayerTest, InvalidDSUpdateIndex) {
Tobin Ehlisc8d352d2016-11-21 10:33:40 -070010985 // Create layout w/ count of 1 and attempt update to that layout w/ binding index 2
Karl Schultz6addd812016-02-02 17:17:23 -070010986 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010987
Tobin Ehlisc8d352d2016-11-21 10:33:40 -070010988 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00936);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010989
Tony Barbour1fa09702017-03-16 12:09:08 -060010990 ASSERT_NO_FATAL_FAILURE(Init());
Karl Schultz6addd812016-02-02 17:17:23 -070010991 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010992 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010993 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10994 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010995
10996 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010997 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10998 ds_pool_ci.pNext = NULL;
10999 ds_pool_ci.maxSets = 1;
11000 ds_pool_ci.poolSizeCount = 1;
11001 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060011002
Tobin Ehlis3b780662015-05-28 12:11:26 -060011003 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011004 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011005 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011006
Tony Barboureb254902015-07-15 12:50:33 -060011007 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011008 dsl_binding.binding = 0;
11009 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11010 dsl_binding.descriptorCount = 1;
11011 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11012 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -060011013
11014 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011015 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11016 ds_layout_ci.pNext = NULL;
11017 ds_layout_ci.bindingCount = 1;
11018 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011019 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011020 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011021 ASSERT_VK_SUCCESS(err);
11022
11023 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011024 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011025 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011026 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011027 alloc_info.descriptorPool = ds_pool;
11028 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011029 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011030 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011031
Tony Barboureb254902015-07-15 12:50:33 -060011032 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011033 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11034 sampler_ci.pNext = NULL;
11035 sampler_ci.magFilter = VK_FILTER_NEAREST;
11036 sampler_ci.minFilter = VK_FILTER_NEAREST;
11037 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11038 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11039 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11040 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11041 sampler_ci.mipLodBias = 1.0;
11042 sampler_ci.anisotropyEnable = VK_FALSE;
11043 sampler_ci.maxAnisotropy = 1;
11044 sampler_ci.compareEnable = VK_FALSE;
11045 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11046 sampler_ci.minLod = 1.0;
11047 sampler_ci.maxLod = 1.0;
11048 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11049 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -060011050
Tobin Ehlis3b780662015-05-28 12:11:26 -060011051 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011052 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011053 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011054
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060011055 VkDescriptorImageInfo info = {};
11056 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011057
11058 VkWriteDescriptorSet descriptor_write;
11059 memset(&descriptor_write, 0, sizeof(descriptor_write));
11060 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011061 descriptor_write.dstSet = descriptorSet;
11062 descriptor_write.dstBinding = 2;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011063 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011064 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011065 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060011066 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011067
11068 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11069
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011070 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011071
Chia-I Wuf7458c52015-10-26 21:10:41 +080011072 vkDestroySampler(m_device->device(), sampler, NULL);
11073 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11074 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060011075}
11076
Tobin Ehlise202b2d2016-11-21 10:36:16 -070011077TEST_F(VkLayerTest, DSUpdateEmptyBinding) {
11078 // Create layout w/ empty binding and attempt to update it
11079 VkResult err;
11080
Tony Barbour1fa09702017-03-16 12:09:08 -060011081 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlise202b2d2016-11-21 10:36:16 -070011082
11083 VkDescriptorPoolSize ds_type_count = {};
11084 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
11085 ds_type_count.descriptorCount = 1;
11086
11087 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11088 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11089 ds_pool_ci.pNext = NULL;
11090 ds_pool_ci.maxSets = 1;
11091 ds_pool_ci.poolSizeCount = 1;
11092 ds_pool_ci.pPoolSizes = &ds_type_count;
11093
11094 VkDescriptorPool ds_pool;
11095 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
11096 ASSERT_VK_SUCCESS(err);
11097
11098 VkDescriptorSetLayoutBinding dsl_binding = {};
11099 dsl_binding.binding = 0;
11100 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
11101 dsl_binding.descriptorCount = 0;
11102 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11103 dsl_binding.pImmutableSamplers = NULL;
11104
11105 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11106 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11107 ds_layout_ci.pNext = NULL;
11108 ds_layout_ci.bindingCount = 1;
11109 ds_layout_ci.pBindings = &dsl_binding;
11110 VkDescriptorSetLayout ds_layout;
11111 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
11112 ASSERT_VK_SUCCESS(err);
11113
11114 VkDescriptorSet descriptor_set;
11115 VkDescriptorSetAllocateInfo alloc_info = {};
11116 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11117 alloc_info.descriptorSetCount = 1;
11118 alloc_info.descriptorPool = ds_pool;
11119 alloc_info.pSetLayouts = &ds_layout;
11120 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
11121 ASSERT_VK_SUCCESS(err);
11122
11123 VkSamplerCreateInfo sampler_ci = {};
11124 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11125 sampler_ci.magFilter = VK_FILTER_NEAREST;
11126 sampler_ci.minFilter = VK_FILTER_NEAREST;
11127 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11128 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11129 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11130 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11131 sampler_ci.mipLodBias = 1.0;
11132 sampler_ci.maxAnisotropy = 1;
11133 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11134 sampler_ci.minLod = 1.0;
11135 sampler_ci.maxLod = 1.0;
11136 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11137
11138 VkSampler sampler;
11139 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
11140 ASSERT_VK_SUCCESS(err);
11141
11142 VkDescriptorImageInfo info = {};
11143 info.sampler = sampler;
11144
11145 VkWriteDescriptorSet descriptor_write;
11146 memset(&descriptor_write, 0, sizeof(descriptor_write));
11147 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11148 descriptor_write.dstSet = descriptor_set;
11149 descriptor_write.dstBinding = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011150 descriptor_write.descriptorCount = 1; // Lie here to avoid parameter_validation error
Tobin Ehlise202b2d2016-11-21 10:36:16 -070011151 // This is the wrong type, but empty binding error will be flagged first
11152 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
11153 descriptor_write.pImageInfo = &info;
11154
11155 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02348);
11156 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11157 m_errorMonitor->VerifyFound();
11158
11159 vkDestroySampler(m_device->device(), sampler, NULL);
11160 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11161 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11162}
11163
Karl Schultz6addd812016-02-02 17:17:23 -070011164TEST_F(VkLayerTest, InvalidDSUpdateStruct) {
11165 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_*
11166 // types
11167 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011168
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011169 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 -060011170
Tony Barbour1fa09702017-03-16 12:09:08 -060011171 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011172
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011173 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011174 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11175 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011176
11177 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011178 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11179 ds_pool_ci.pNext = NULL;
11180 ds_pool_ci.maxSets = 1;
11181 ds_pool_ci.poolSizeCount = 1;
11182 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060011183
Tobin Ehlis3b780662015-05-28 12:11:26 -060011184 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011185 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011186 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -060011187 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011188 dsl_binding.binding = 0;
11189 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11190 dsl_binding.descriptorCount = 1;
11191 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11192 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011193
Tony Barboureb254902015-07-15 12:50:33 -060011194 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011195 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11196 ds_layout_ci.pNext = NULL;
11197 ds_layout_ci.bindingCount = 1;
11198 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060011199
Tobin Ehlis3b780662015-05-28 12:11:26 -060011200 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011201 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011202 ASSERT_VK_SUCCESS(err);
11203
11204 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011205 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011206 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011207 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011208 alloc_info.descriptorPool = ds_pool;
11209 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011210 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011211 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011212
Tony Barboureb254902015-07-15 12:50:33 -060011213 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011214 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11215 sampler_ci.pNext = NULL;
11216 sampler_ci.magFilter = VK_FILTER_NEAREST;
11217 sampler_ci.minFilter = VK_FILTER_NEAREST;
11218 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11219 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11220 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11221 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11222 sampler_ci.mipLodBias = 1.0;
11223 sampler_ci.anisotropyEnable = VK_FALSE;
11224 sampler_ci.maxAnisotropy = 1;
11225 sampler_ci.compareEnable = VK_FALSE;
11226 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11227 sampler_ci.minLod = 1.0;
11228 sampler_ci.maxLod = 1.0;
11229 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11230 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011231 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011232 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011233 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011234
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060011235 VkDescriptorImageInfo info = {};
11236 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011237
11238 VkWriteDescriptorSet descriptor_write;
11239 memset(&descriptor_write, 0, sizeof(descriptor_write));
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011240 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011241 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011242 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011243 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011244 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060011245 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011246
11247 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11248
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011249 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011250
Chia-I Wuf7458c52015-10-26 21:10:41 +080011251 vkDestroySampler(m_device->device(), sampler, NULL);
11252 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11253 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060011254}
11255
Karl Schultz6addd812016-02-02 17:17:23 -070011256TEST_F(VkLayerTest, SampleDescriptorUpdateError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011257 // Create a single Sampler descriptor and send it an invalid Sampler
Karl Schultz6addd812016-02-02 17:17:23 -070011258 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011259
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070011260 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00942);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011261
Tony Barbour1fa09702017-03-16 12:09:08 -060011262 ASSERT_NO_FATAL_FAILURE(Init());
Karl Schultz6addd812016-02-02 17:17:23 -070011263 // TODO : Farm Descriptor setup code to helper function(s) to reduce copied
11264 // code
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011265 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011266 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
11267 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011268
11269 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011270 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11271 ds_pool_ci.pNext = NULL;
11272 ds_pool_ci.maxSets = 1;
11273 ds_pool_ci.poolSizeCount = 1;
11274 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011275
11276 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011277 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011278 ASSERT_VK_SUCCESS(err);
11279
11280 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011281 dsl_binding.binding = 0;
11282 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
11283 dsl_binding.descriptorCount = 1;
11284 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11285 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011286
11287 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011288 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11289 ds_layout_ci.pNext = NULL;
11290 ds_layout_ci.bindingCount = 1;
11291 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011292 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011293 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011294 ASSERT_VK_SUCCESS(err);
11295
11296 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011297 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011298 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011299 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011300 alloc_info.descriptorPool = ds_pool;
11301 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011302 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011303 ASSERT_VK_SUCCESS(err);
11304
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011305 VkSampler sampler = (VkSampler)((size_t)0xbaadbeef); // Sampler with invalid handle
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011306
11307 VkDescriptorImageInfo descriptor_info;
11308 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
11309 descriptor_info.sampler = sampler;
11310
11311 VkWriteDescriptorSet descriptor_write;
11312 memset(&descriptor_write, 0, sizeof(descriptor_write));
11313 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011314 descriptor_write.dstSet = descriptorSet;
11315 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011316 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011317 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
11318 descriptor_write.pImageInfo = &descriptor_info;
11319
11320 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11321
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011322 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011323
Chia-I Wuf7458c52015-10-26 21:10:41 +080011324 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11325 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011326}
11327
Karl Schultz6addd812016-02-02 17:17:23 -070011328TEST_F(VkLayerTest, ImageViewDescriptorUpdateError) {
11329 // Create a single combined Image/Sampler descriptor and send it an invalid
11330 // imageView
11331 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011332
Karl Schultzf78bcdd2016-11-30 12:36:01 -070011333 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00943);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011334
Tony Barbour1fa09702017-03-16 12:09:08 -060011335 ASSERT_NO_FATAL_FAILURE(Init());
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011336 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011337 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11338 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011339
11340 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011341 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11342 ds_pool_ci.pNext = NULL;
11343 ds_pool_ci.maxSets = 1;
11344 ds_pool_ci.poolSizeCount = 1;
11345 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011346
11347 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011348 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011349 ASSERT_VK_SUCCESS(err);
11350
11351 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011352 dsl_binding.binding = 0;
11353 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11354 dsl_binding.descriptorCount = 1;
11355 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11356 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011357
11358 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011359 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11360 ds_layout_ci.pNext = NULL;
11361 ds_layout_ci.bindingCount = 1;
11362 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011363 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011364 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011365 ASSERT_VK_SUCCESS(err);
11366
11367 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011368 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011369 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011370 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011371 alloc_info.descriptorPool = ds_pool;
11372 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011373 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011374 ASSERT_VK_SUCCESS(err);
11375
11376 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011377 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11378 sampler_ci.pNext = NULL;
11379 sampler_ci.magFilter = VK_FILTER_NEAREST;
11380 sampler_ci.minFilter = VK_FILTER_NEAREST;
11381 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11382 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11383 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11384 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11385 sampler_ci.mipLodBias = 1.0;
11386 sampler_ci.anisotropyEnable = VK_FALSE;
11387 sampler_ci.maxAnisotropy = 1;
11388 sampler_ci.compareEnable = VK_FALSE;
11389 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11390 sampler_ci.minLod = 1.0;
11391 sampler_ci.maxLod = 1.0;
11392 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11393 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011394
11395 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011396 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011397 ASSERT_VK_SUCCESS(err);
11398
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011399 VkImageView view = (VkImageView)((size_t)0xbaadbeef); // invalid imageView object
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011400
11401 VkDescriptorImageInfo descriptor_info;
11402 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
11403 descriptor_info.sampler = sampler;
11404 descriptor_info.imageView = view;
11405
11406 VkWriteDescriptorSet descriptor_write;
11407 memset(&descriptor_write, 0, sizeof(descriptor_write));
11408 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011409 descriptor_write.dstSet = descriptorSet;
11410 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011411 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011412 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11413 descriptor_write.pImageInfo = &descriptor_info;
11414
11415 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11416
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011417 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011418
Chia-I Wuf7458c52015-10-26 21:10:41 +080011419 vkDestroySampler(m_device->device(), sampler, NULL);
11420 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11421 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011422}
11423
Karl Schultz6addd812016-02-02 17:17:23 -070011424TEST_F(VkLayerTest, CopyDescriptorUpdateErrors) {
11425 // Create DS w/ layout of 2 types, write update 1 and attempt to copy-update
11426 // into the other
11427 VkResult err;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011428
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011429 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11430 " binding #1 with type "
11431 "VK_DESCRIPTOR_TYPE_SAMPLER. Types do "
11432 "not match.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011433
Tony Barbour1fa09702017-03-16 12:09:08 -060011434 ASSERT_NO_FATAL_FAILURE(Init());
Karl Schultz6addd812016-02-02 17:17:23 -070011435 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011436 VkDescriptorPoolSize ds_type_count[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011437 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11438 ds_type_count[0].descriptorCount = 1;
11439 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
11440 ds_type_count[1].descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011441
11442 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011443 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11444 ds_pool_ci.pNext = NULL;
11445 ds_pool_ci.maxSets = 1;
11446 ds_pool_ci.poolSizeCount = 2;
11447 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011448
11449 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011450 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis04356f92015-10-27 16:35:27 -060011451 ASSERT_VK_SUCCESS(err);
11452 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011453 dsl_binding[0].binding = 0;
11454 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11455 dsl_binding[0].descriptorCount = 1;
11456 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
11457 dsl_binding[0].pImmutableSamplers = NULL;
11458 dsl_binding[1].binding = 1;
11459 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
11460 dsl_binding[1].descriptorCount = 1;
11461 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
11462 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011463
11464 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011465 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11466 ds_layout_ci.pNext = NULL;
11467 ds_layout_ci.bindingCount = 2;
11468 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011469
11470 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011471 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis04356f92015-10-27 16:35:27 -060011472 ASSERT_VK_SUCCESS(err);
11473
11474 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011475 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011476 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011477 alloc_info.descriptorSetCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011478 alloc_info.descriptorPool = ds_pool;
11479 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011480 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis04356f92015-10-27 16:35:27 -060011481 ASSERT_VK_SUCCESS(err);
11482
11483 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011484 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11485 sampler_ci.pNext = NULL;
11486 sampler_ci.magFilter = VK_FILTER_NEAREST;
11487 sampler_ci.minFilter = VK_FILTER_NEAREST;
11488 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11489 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11490 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11491 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11492 sampler_ci.mipLodBias = 1.0;
11493 sampler_ci.anisotropyEnable = VK_FALSE;
11494 sampler_ci.maxAnisotropy = 1;
11495 sampler_ci.compareEnable = VK_FALSE;
11496 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11497 sampler_ci.minLod = 1.0;
11498 sampler_ci.maxLod = 1.0;
11499 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11500 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011501
11502 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011503 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis04356f92015-10-27 16:35:27 -060011504 ASSERT_VK_SUCCESS(err);
11505
11506 VkDescriptorImageInfo info = {};
11507 info.sampler = sampler;
11508
11509 VkWriteDescriptorSet descriptor_write;
11510 memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet));
11511 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011512 descriptor_write.dstSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011513 descriptor_write.dstBinding = 1; // SAMPLER binding from layout above
Chia-I Wud50a7d72015-10-26 20:48:51 +080011514 descriptor_write.descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011515 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
11516 descriptor_write.pImageInfo = &info;
11517 // This write update should succeed
11518 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11519 // Now perform a copy update that fails due to type mismatch
11520 VkCopyDescriptorSet copy_ds_update;
11521 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
11522 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
11523 copy_ds_update.srcSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011524 copy_ds_update.srcBinding = 1; // Copy from SAMPLER binding
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011525 copy_ds_update.dstSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011526 copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding
11527 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -060011528 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
11529
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011530 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -060011531 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011532 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 -060011533 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
11534 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
11535 copy_ds_update.srcSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011536 copy_ds_update.srcBinding = 3; // ERROR : Invalid binding for matching layout
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011537 copy_ds_update.dstSet = descriptorSet;
11538 copy_ds_update.dstBinding = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011539 copy_ds_update.descriptorCount = 1; // Copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -060011540 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
11541
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011542 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011543
Tobin Ehlis04356f92015-10-27 16:35:27 -060011544 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011545 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11546 " binding#1 with offset index of 1 plus "
11547 "update array offset of 0 and update of "
11548 "5 descriptors oversteps total number "
11549 "of descriptors in set: 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011550
Tobin Ehlis04356f92015-10-27 16:35:27 -060011551 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
11552 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
11553 copy_ds_update.srcSet = descriptorSet;
11554 copy_ds_update.srcBinding = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011555 copy_ds_update.dstSet = descriptorSet;
11556 copy_ds_update.dstBinding = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011557 copy_ds_update.descriptorCount = 5; // ERROR copy 5 descriptors (out of bounds for layout)
Tobin Ehlis04356f92015-10-27 16:35:27 -060011558 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
11559
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011560 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -060011561
Chia-I Wuf7458c52015-10-26 21:10:41 +080011562 vkDestroySampler(m_device->device(), sampler, NULL);
11563 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11564 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis04356f92015-10-27 16:35:27 -060011565}
11566
Karl Schultz6addd812016-02-02 17:17:23 -070011567TEST_F(VkLayerTest, NumSamplesMismatch) {
11568 // Create CommandBuffer where MSAA samples doesn't match RenderPass
11569 // sampleCount
11570 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011571
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011572 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Num samples mismatch! ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011573
Tony Barbour1fa09702017-03-16 12:09:08 -060011574 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis3b780662015-05-28 12:11:26 -060011575 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011576 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -060011577 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011578 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011579
11580 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011581 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11582 ds_pool_ci.pNext = NULL;
11583 ds_pool_ci.maxSets = 1;
11584 ds_pool_ci.poolSizeCount = 1;
11585 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060011586
Tobin Ehlis3b780662015-05-28 12:11:26 -060011587 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011588 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011589 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011590
Tony Barboureb254902015-07-15 12:50:33 -060011591 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +080011592 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -060011593 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +080011594 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011595 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11596 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011597
Tony Barboureb254902015-07-15 12:50:33 -060011598 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11599 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11600 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011601 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -070011602 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060011603
Tobin Ehlis3b780662015-05-28 12:11:26 -060011604 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011605 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011606 ASSERT_VK_SUCCESS(err);
11607
11608 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011609 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011610 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011611 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011612 alloc_info.descriptorPool = ds_pool;
11613 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011614 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011615 ASSERT_VK_SUCCESS(err);
11616
Tony Barboureb254902015-07-15 12:50:33 -060011617 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011618 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070011619 pipe_ms_state_ci.pNext = NULL;
11620 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
11621 pipe_ms_state_ci.sampleShadingEnable = 0;
11622 pipe_ms_state_ci.minSampleShading = 1.0;
11623 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011624
Tony Barboureb254902015-07-15 12:50:33 -060011625 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011626 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11627 pipeline_layout_ci.pNext = NULL;
11628 pipeline_layout_ci.setLayoutCount = 1;
11629 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011630
11631 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011632 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011633 ASSERT_VK_SUCCESS(err);
11634
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011635 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011636 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 -060011637 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011638 VkPipelineObj pipe(m_device);
11639 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060011640 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -060011641 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011642 pipe.SetMSAA(&pipe_ms_state_ci);
11643 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis3b780662015-05-28 12:11:26 -060011644
Tony Barbour552f6c02016-12-21 14:34:07 -070011645 m_commandBuffer->BeginCommandBuffer();
11646 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011647 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis3b780662015-05-28 12:11:26 -060011648
Rene Lindsay3bdc7a42017-01-06 13:20:15 -070011649 VkViewport viewport = {0, 0, 16, 16, 0, 1};
11650 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
11651 VkRect2D scissor = {{0, 0}, {16, 16}};
11652 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
11653
Mark Young29927482016-05-04 14:38:51 -060011654 // Render triangle (the error should trigger on the attempt to draw).
11655 Draw(3, 1, 0, 0);
11656
11657 // Finalize recording of the command buffer
Tony Barbour552f6c02016-12-21 14:34:07 -070011658 m_commandBuffer->EndRenderPass();
11659 m_commandBuffer->EndCommandBuffer();
Mark Young29927482016-05-04 14:38:51 -060011660
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011661 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011662
Chia-I Wuf7458c52015-10-26 21:10:41 +080011663 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11664 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11665 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060011666}
Mark Young29927482016-05-04 14:38:51 -060011667
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011668TEST_F(VkLayerTest, RenderPassIncompatible) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011669 TEST_DESCRIPTION(
11670 "Hit RenderPass incompatible cases. "
11671 "Initial case is drawing with an active renderpass that's "
11672 "not compatible with the bound pipeline state object's creation renderpass");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011673 VkResult err;
11674
Tony Barbour1fa09702017-03-16 12:09:08 -060011675 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011676 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11677
11678 VkDescriptorSetLayoutBinding dsl_binding = {};
11679 dsl_binding.binding = 0;
11680 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11681 dsl_binding.descriptorCount = 1;
11682 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11683 dsl_binding.pImmutableSamplers = NULL;
11684
11685 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11686 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11687 ds_layout_ci.pNext = NULL;
11688 ds_layout_ci.bindingCount = 1;
11689 ds_layout_ci.pBindings = &dsl_binding;
11690
11691 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011692 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011693 ASSERT_VK_SUCCESS(err);
11694
11695 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11696 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11697 pipeline_layout_ci.pNext = NULL;
11698 pipeline_layout_ci.setLayoutCount = 1;
11699 pipeline_layout_ci.pSetLayouts = &ds_layout;
11700
11701 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011702 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011703 ASSERT_VK_SUCCESS(err);
11704
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011705 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011706 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 -060011707 // but add it to be able to run on more devices
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011708 // Create a renderpass that will be incompatible with default renderpass
11709 VkAttachmentReference attach = {};
Cort Stratton7547f772017-05-04 15:18:52 -070011710 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011711 VkAttachmentReference color_att = {};
Cort Stratton7547f772017-05-04 15:18:52 -070011712 color_att.layout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011713 VkSubpassDescription subpass = {};
11714 subpass.inputAttachmentCount = 1;
11715 subpass.pInputAttachments = &attach;
11716 subpass.colorAttachmentCount = 1;
11717 subpass.pColorAttachments = &color_att;
11718 VkRenderPassCreateInfo rpci = {};
11719 rpci.subpassCount = 1;
11720 rpci.pSubpasses = &subpass;
11721 rpci.attachmentCount = 1;
11722 VkAttachmentDescription attach_desc = {};
11723 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Cody Northropbd16af12016-06-21 09:25:48 -060011724 // Format incompatible with PSO RP color attach format B8G8R8A8_UNORM
11725 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011726 rpci.pAttachments = &attach_desc;
11727 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
11728 VkRenderPass rp;
11729 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11730 VkPipelineObj pipe(m_device);
11731 pipe.AddShader(&vs);
11732 pipe.AddShader(&fs);
11733 pipe.AddColorAttachment();
11734 VkViewport view_port = {};
11735 m_viewports.push_back(view_port);
11736 pipe.SetViewport(m_viewports);
11737 VkRect2D rect = {};
11738 m_scissors.push_back(rect);
11739 pipe.SetScissor(m_scissors);
11740 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11741
11742 VkCommandBufferInheritanceInfo cbii = {};
11743 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
11744 cbii.renderPass = rp;
11745 cbii.subpass = 0;
11746 VkCommandBufferBeginInfo cbbi = {};
11747 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
11748 cbbi.pInheritanceInfo = &cbii;
11749 vkBeginCommandBuffer(m_commandBuffer->handle(), &cbbi);
11750 VkRenderPassBeginInfo rpbi = {};
11751 rpbi.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
11752 rpbi.framebuffer = m_framebuffer;
11753 rpbi.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011754 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
11755 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011756
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011757 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is incompatible w/ gfx pipeline ");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011758 // Render triangle (the error should trigger on the attempt to draw).
11759 Draw(3, 1, 0, 0);
11760
11761 // Finalize recording of the command buffer
Tony Barbour552f6c02016-12-21 14:34:07 -070011762 m_commandBuffer->EndRenderPass();
11763 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011764
11765 m_errorMonitor->VerifyFound();
11766
11767 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11768 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11769 vkDestroyRenderPass(m_device->device(), rp, NULL);
11770}
11771
Mark Youngc89c6312016-03-31 16:03:20 -060011772TEST_F(VkLayerTest, NumBlendAttachMismatch) {
11773 // Create Pipeline where the number of blend attachments doesn't match the
11774 // number of color attachments. In this case, we don't add any color
11775 // blend attachments even though we have a color attachment.
11776 VkResult err;
11777
Tobin Ehlis974c0d92017-02-01 13:31:22 -070011778 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02109);
Mark Youngc89c6312016-03-31 16:03:20 -060011779
Tony Barbour1fa09702017-03-16 12:09:08 -060011780 ASSERT_NO_FATAL_FAILURE(Init());
Mark Youngc89c6312016-03-31 16:03:20 -060011781 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11782 VkDescriptorPoolSize ds_type_count = {};
11783 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11784 ds_type_count.descriptorCount = 1;
11785
11786 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11787 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11788 ds_pool_ci.pNext = NULL;
11789 ds_pool_ci.maxSets = 1;
11790 ds_pool_ci.poolSizeCount = 1;
11791 ds_pool_ci.pPoolSizes = &ds_type_count;
11792
11793 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011794 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Youngc89c6312016-03-31 16:03:20 -060011795 ASSERT_VK_SUCCESS(err);
11796
11797 VkDescriptorSetLayoutBinding dsl_binding = {};
11798 dsl_binding.binding = 0;
11799 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11800 dsl_binding.descriptorCount = 1;
11801 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11802 dsl_binding.pImmutableSamplers = NULL;
11803
11804 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11805 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11806 ds_layout_ci.pNext = NULL;
11807 ds_layout_ci.bindingCount = 1;
11808 ds_layout_ci.pBindings = &dsl_binding;
11809
11810 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011811 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Youngc89c6312016-03-31 16:03:20 -060011812 ASSERT_VK_SUCCESS(err);
11813
11814 VkDescriptorSet descriptorSet;
11815 VkDescriptorSetAllocateInfo alloc_info = {};
11816 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11817 alloc_info.descriptorSetCount = 1;
11818 alloc_info.descriptorPool = ds_pool;
11819 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011820 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Youngc89c6312016-03-31 16:03:20 -060011821 ASSERT_VK_SUCCESS(err);
11822
11823 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011824 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Youngc89c6312016-03-31 16:03:20 -060011825 pipe_ms_state_ci.pNext = NULL;
11826 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
11827 pipe_ms_state_ci.sampleShadingEnable = 0;
11828 pipe_ms_state_ci.minSampleShading = 1.0;
11829 pipe_ms_state_ci.pSampleMask = NULL;
11830
11831 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11832 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11833 pipeline_layout_ci.pNext = NULL;
11834 pipeline_layout_ci.setLayoutCount = 1;
11835 pipeline_layout_ci.pSetLayouts = &ds_layout;
11836
11837 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011838 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Youngc89c6312016-03-31 16:03:20 -060011839 ASSERT_VK_SUCCESS(err);
11840
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011841 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011842 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011843 // but add it to be able to run on more devices
Mark Youngc89c6312016-03-31 16:03:20 -060011844 VkPipelineObj pipe(m_device);
11845 pipe.AddShader(&vs);
11846 pipe.AddShader(&fs);
11847 pipe.SetMSAA(&pipe_ms_state_ci);
11848 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011849 m_errorMonitor->VerifyFound();
Mark Youngc89c6312016-03-31 16:03:20 -060011850
11851 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11852 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11853 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11854}
Mark Young29927482016-05-04 14:38:51 -060011855
Mark Muellerd4914412016-06-13 17:52:06 -060011856TEST_F(VkLayerTest, MissingClearAttachment) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011857 TEST_DESCRIPTION(
11858 "Points to a wrong colorAttachment index in a VkClearAttachment "
11859 "structure passed to vkCmdClearAttachments");
Tony Barbour1fa09702017-03-16 12:09:08 -060011860 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070011861 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01114);
Mark Muellerd4914412016-06-13 17:52:06 -060011862
11863 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailCmdClearAttachments);
11864 m_errorMonitor->VerifyFound();
11865}
11866
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070011867TEST_F(VkLayerTest, CmdClearAttachmentTests) {
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070011868 TEST_DESCRIPTION("Various tests for validating usage of vkCmdClearAttachments");
11869 VkResult err;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011870
Tony Barbour1fa09702017-03-16 12:09:08 -060011871 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011872 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060011873
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011874 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011875 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11876 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011877
11878 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011879 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11880 ds_pool_ci.pNext = NULL;
11881 ds_pool_ci.maxSets = 1;
11882 ds_pool_ci.poolSizeCount = 1;
11883 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060011884
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011885 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011886 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011887 ASSERT_VK_SUCCESS(err);
11888
Tony Barboureb254902015-07-15 12:50:33 -060011889 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011890 dsl_binding.binding = 0;
11891 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11892 dsl_binding.descriptorCount = 1;
11893 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11894 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011895
Tony Barboureb254902015-07-15 12:50:33 -060011896 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011897 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11898 ds_layout_ci.pNext = NULL;
11899 ds_layout_ci.bindingCount = 1;
11900 ds_layout_ci.pBindings = &dsl_binding;
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011901
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011902 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011903 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011904 ASSERT_VK_SUCCESS(err);
11905
11906 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011907 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011908 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011909 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011910 alloc_info.descriptorPool = ds_pool;
11911 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011912 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011913 ASSERT_VK_SUCCESS(err);
11914
Tony Barboureb254902015-07-15 12:50:33 -060011915 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011916 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070011917 pipe_ms_state_ci.pNext = NULL;
11918 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
11919 pipe_ms_state_ci.sampleShadingEnable = 0;
11920 pipe_ms_state_ci.minSampleShading = 1.0;
11921 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011922
Tony Barboureb254902015-07-15 12:50:33 -060011923 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011924 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11925 pipeline_layout_ci.pNext = NULL;
11926 pipeline_layout_ci.setLayoutCount = 1;
11927 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011928
11929 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011930 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011931 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011932
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011933 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -060011934 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -070011935 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011936 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011937
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011938 VkPipelineObj pipe(m_device);
11939 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060011940 pipe.AddShader(&fs);
Jeremy Hayes7332f342017-03-09 15:54:12 -070011941 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011942 pipe.SetMSAA(&pipe_ms_state_ci);
11943 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060011944
Tony Barbour552f6c02016-12-21 14:34:07 -070011945 m_commandBuffer->BeginCommandBuffer();
11946 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011947
Karl Schultz6addd812016-02-02 17:17:23 -070011948 // Main thing we care about for this test is that the VkImage obj we're
11949 // clearing matches Color Attachment of FB
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011950 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -060011951 VkClearAttachment color_attachment;
11952 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11953 color_attachment.clearValue.color.float32[0] = 1.0;
11954 color_attachment.clearValue.color.float32[1] = 1.0;
11955 color_attachment.clearValue.color.float32[2] = 1.0;
11956 color_attachment.clearValue.color.float32[3] = 1.0;
11957 color_attachment.colorAttachment = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011958 VkClearRect clear_rect = {{{0, 0}, {(uint32_t)m_width, (uint32_t)m_height}}};
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011959
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070011960 // Call for full-sized FB Color attachment prior to issuing a Draw
11961 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070011962 "vkCmdClearAttachments() issued on command buffer object ");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011963 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070011964 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011965
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070011966 clear_rect.rect.extent.width = renderPassBeginInfo().renderArea.extent.width + 4;
11967 clear_rect.rect.extent.height = clear_rect.rect.extent.height / 2;
11968 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01115);
11969 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
11970 m_errorMonitor->VerifyFound();
11971
11972 clear_rect.rect.extent.width = (uint32_t)m_width / 2;
11973 clear_rect.layerCount = 2;
11974 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01116);
11975 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011976 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011977
Chia-I Wuf7458c52015-10-26 21:10:41 +080011978 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11979 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11980 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011981}
11982
Karl Schultz6addd812016-02-02 17:17:23 -070011983TEST_F(VkLayerTest, VtxBufferBadIndex) {
11984 VkResult err;
Tobin Ehlis502480b2015-06-24 15:53:07 -060011985
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011986 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11987 "but no vertex buffers are attached to this Pipeline State Object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011988
Tony Barbour1fa09702017-03-16 12:09:08 -060011989 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisd332f282015-10-02 11:00:56 -060011990 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlis502480b2015-06-24 15:53:07 -060011991 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060011992
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011993 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011994 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11995 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011996
11997 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011998 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11999 ds_pool_ci.pNext = NULL;
12000 ds_pool_ci.maxSets = 1;
12001 ds_pool_ci.poolSizeCount = 1;
12002 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060012003
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060012004 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012005 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis502480b2015-06-24 15:53:07 -060012006 ASSERT_VK_SUCCESS(err);
12007
Tony Barboureb254902015-07-15 12:50:33 -060012008 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012009 dsl_binding.binding = 0;
12010 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12011 dsl_binding.descriptorCount = 1;
12012 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
12013 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060012014
Tony Barboureb254902015-07-15 12:50:33 -060012015 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012016 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12017 ds_layout_ci.pNext = NULL;
12018 ds_layout_ci.bindingCount = 1;
12019 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060012020
Tobin Ehlis502480b2015-06-24 15:53:07 -060012021 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012022 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060012023 ASSERT_VK_SUCCESS(err);
12024
12025 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012026 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080012027 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070012028 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060012029 alloc_info.descriptorPool = ds_pool;
12030 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012031 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis502480b2015-06-24 15:53:07 -060012032 ASSERT_VK_SUCCESS(err);
12033
Tony Barboureb254902015-07-15 12:50:33 -060012034 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012035 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070012036 pipe_ms_state_ci.pNext = NULL;
12037 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
12038 pipe_ms_state_ci.sampleShadingEnable = 0;
12039 pipe_ms_state_ci.minSampleShading = 1.0;
12040 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060012041
Tony Barboureb254902015-07-15 12:50:33 -060012042 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012043 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12044 pipeline_layout_ci.pNext = NULL;
12045 pipeline_layout_ci.setLayoutCount = 1;
12046 pipeline_layout_ci.pSetLayouts = &ds_layout;
12047 VkPipelineLayout pipeline_layout;
Tobin Ehlis502480b2015-06-24 15:53:07 -060012048
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012049 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060012050 ASSERT_VK_SUCCESS(err);
12051
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012052 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012053 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 -060012054 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -060012055 VkPipelineObj pipe(m_device);
12056 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060012057 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -060012058 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060012059 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -060012060 pipe.SetViewport(m_viewports);
12061 pipe.SetScissor(m_scissors);
Tony Barbour62e1a5b2015-08-06 10:16:07 -060012062 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060012063
Tony Barbour552f6c02016-12-21 14:34:07 -070012064 m_commandBuffer->BeginCommandBuffer();
12065 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012066 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisf7bf4502015-09-09 15:12:35 -060012067 // Don't care about actual data, just need to get to draw to flag error
12068 static const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012069 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), (const void *)&vbo_data);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012070 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -060012071 Draw(1, 0, 0, 0);
Tobin Ehlis502480b2015-06-24 15:53:07 -060012072
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012073 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060012074
Chia-I Wuf7458c52015-10-26 21:10:41 +080012075 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12076 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12077 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis502480b2015-06-24 15:53:07 -060012078}
Mark Muellerdfe37552016-07-07 14:47:42 -060012079
Mark Mueller2ee294f2016-08-04 12:59:48 -060012080TEST_F(VkLayerTest, MismatchCountQueueCreateRequestedFeature) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012081 TEST_DESCRIPTION(
12082 "Use an invalid count in a vkEnumeratePhysicalDevices call."
12083 "Use invalid Queue Family Index in vkCreateDevice");
Tony Barbour1fa09702017-03-16 12:09:08 -060012084 ASSERT_NO_FATAL_FAILURE(Init());
Mark Mueller2ee294f2016-08-04 12:59:48 -060012085
Mark Mueller880fce52016-08-17 15:23:23 -060012086 // The following test fails with recent NVidia drivers.
12087 // By the time core_validation is reached, the NVidia
12088 // driver has sanitized the invalid condition and core_validation
12089 // is not introduced to the failure condition. This is not the case
12090 // with AMD and Mesa drivers. Futher investigation is required
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012091 // uint32_t count = static_cast<uint32_t>(~0);
12092 // VkPhysicalDevice physical_device;
12093 // vkEnumeratePhysicalDevices(instance(), &count, &physical_device);
12094 // m_errorMonitor->VerifyFound();
Mark Mueller2ee294f2016-08-04 12:59:48 -060012095
Mark Mueller2ee294f2016-08-04 12:59:48 -060012096 float queue_priority = 0.0;
Mark Mueller2ee294f2016-08-04 12:59:48 -060012097 VkDeviceQueueCreateInfo queue_create_info = {};
12098 queue_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
12099 queue_create_info.queueCount = 1;
12100 queue_create_info.pQueuePriorities = &queue_priority;
12101 queue_create_info.queueFamilyIndex = static_cast<uint32_t>(~0);
12102
12103 VkPhysicalDeviceFeatures features = m_device->phy().features();
12104 VkDevice testDevice;
12105 VkDeviceCreateInfo device_create_info = {};
12106 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
12107 device_create_info.queueCreateInfoCount = 1;
12108 device_create_info.pQueueCreateInfos = &queue_create_info;
12109 device_create_info.pEnabledFeatures = &features;
Jeremy Hayesb26fd042017-03-10 09:13:22 -070012110
12111 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12112 "Invalid queue create request in vkCreateDevice(). Invalid queueFamilyIndex ");
Jeremy Hayes17fd3662017-03-17 11:51:11 -060012113 // The following unexpected error is coming from the LunarG loader. Do not make it a desired message because platforms that do
12114 // not use the LunarG loader (e.g. Android) will not see the message and the test will fail.
12115 m_errorMonitor->SetUnexpectedError("Failed to create device chain.");
Mark Mueller2ee294f2016-08-04 12:59:48 -060012116 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
12117 m_errorMonitor->VerifyFound();
12118
12119 queue_create_info.queueFamilyIndex = 1;
12120
12121 unsigned feature_count = sizeof(VkPhysicalDeviceFeatures) / sizeof(VkBool32);
12122 VkBool32 *feature_array = reinterpret_cast<VkBool32 *>(&features);
12123 for (unsigned i = 0; i < feature_count; i++) {
12124 if (VK_FALSE == feature_array[i]) {
12125 feature_array[i] = VK_TRUE;
Mark Mueller2ee294f2016-08-04 12:59:48 -060012126 device_create_info.pEnabledFeatures = &features;
Jeremy Hayesb26fd042017-03-10 09:13:22 -070012127 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12128 "While calling vkCreateDevice(), requesting feature #");
Jeremy Hayes17fd3662017-03-17 11:51:11 -060012129 // The following unexpected error is coming from the LunarG loader. Do not make it a desired message because platforms
12130 // that do not use the LunarG loader (e.g. Android) will not see the message and the test will fail.
12131 m_errorMonitor->SetUnexpectedError("Failed to create device chain.");
Jeremy Hayesb26fd042017-03-10 09:13:22 -070012132 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12133 "You requested features that are unavailable on this device. You should first "
12134 "query feature availability by calling vkGetPhysicalDeviceFeatures().");
Mark Mueller2ee294f2016-08-04 12:59:48 -060012135 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
12136 m_errorMonitor->VerifyFound();
12137 break;
12138 }
12139 }
12140}
12141
Tobin Ehlis16edf082016-11-21 12:33:49 -070012142TEST_F(VkLayerTest, InvalidQueryPoolCreate) {
12143 TEST_DESCRIPTION("Attempt to create a query pool for PIPELINE_STATISTICS without enabling pipeline stats for the device.");
12144
Tony Barbour1fa09702017-03-16 12:09:08 -060012145 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis16edf082016-11-21 12:33:49 -070012146
12147 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
12148 std::vector<VkDeviceQueueCreateInfo> queue_info;
12149 queue_info.reserve(queue_props.size());
12150 std::vector<std::vector<float>> queue_priorities;
12151 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
12152 VkDeviceQueueCreateInfo qi{};
12153 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
12154 qi.queueFamilyIndex = i;
12155 qi.queueCount = queue_props[i].queueCount;
12156 queue_priorities.emplace_back(qi.queueCount, 0.0f);
12157 qi.pQueuePriorities = queue_priorities[i].data();
12158 queue_info.push_back(qi);
12159 }
12160
12161 std::vector<const char *> device_extension_names;
12162
12163 VkDevice local_device;
12164 VkDeviceCreateInfo device_create_info = {};
12165 auto features = m_device->phy().features();
12166 // Intentionally disable pipeline stats
12167 features.pipelineStatisticsQuery = VK_FALSE;
12168 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
12169 device_create_info.pNext = NULL;
12170 device_create_info.queueCreateInfoCount = queue_info.size();
12171 device_create_info.pQueueCreateInfos = queue_info.data();
12172 device_create_info.enabledLayerCount = 0;
12173 device_create_info.ppEnabledLayerNames = NULL;
12174 device_create_info.pEnabledFeatures = &features;
12175 VkResult err = vkCreateDevice(gpu(), &device_create_info, nullptr, &local_device);
12176 ASSERT_VK_SUCCESS(err);
12177
12178 VkQueryPoolCreateInfo qpci{};
12179 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
12180 qpci.queryType = VK_QUERY_TYPE_PIPELINE_STATISTICS;
12181 qpci.queryCount = 1;
12182 VkQueryPool query_pool;
12183
12184 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01006);
12185 vkCreateQueryPool(local_device, &qpci, nullptr, &query_pool);
12186 m_errorMonitor->VerifyFound();
12187
12188 vkDestroyDevice(local_device, nullptr);
12189}
12190
Mark Mueller2ee294f2016-08-04 12:59:48 -060012191TEST_F(VkLayerTest, InvalidQueueIndexInvalidQuery) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012192 TEST_DESCRIPTION(
12193 "Use an invalid queue index in a vkCmdWaitEvents call."
12194 "End a command buffer with a query still in progress.");
Mark Mueller2ee294f2016-08-04 12:59:48 -060012195
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012196 const char *invalid_queue_index =
12197 "was created with sharingMode of VK_SHARING_MODE_EXCLUSIVE. If one "
12198 "of src- or dstQueueFamilyIndex is VK_QUEUE_FAMILY_IGNORED, both "
12199 "must be.";
Mark Mueller2ee294f2016-08-04 12:59:48 -060012200
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012201 const char *invalid_query = "Ending command buffer with in progress query: queryPool 0x";
Mark Mueller2ee294f2016-08-04 12:59:48 -060012202
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012203 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queue_index);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012204
Tony Barbour1fa09702017-03-16 12:09:08 -060012205 ASSERT_NO_FATAL_FAILURE(Init());
Mark Mueller2ee294f2016-08-04 12:59:48 -060012206
12207 VkEvent event;
12208 VkEventCreateInfo event_create_info{};
12209 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
12210 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
12211
Mark Mueller2ee294f2016-08-04 12:59:48 -060012212 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012213 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012214
Tony Barbour552f6c02016-12-21 14:34:07 -070012215 m_commandBuffer->BeginCommandBuffer();
Mark Mueller2ee294f2016-08-04 12:59:48 -060012216
12217 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060012218 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 -060012219 ASSERT_TRUE(image.initialized());
12220 VkImageMemoryBarrier img_barrier = {};
12221 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
12222 img_barrier.pNext = NULL;
12223 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
12224 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
12225 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
12226 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
12227 img_barrier.image = image.handle();
12228 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
Mark Lobodzinski2a74c5c2016-08-17 13:26:28 -060012229
12230 // QueueFamilyIndex must be VK_QUEUE_FAMILY_IGNORED, this verifies
12231 // that layer validation catches the case when it is not.
12232 img_barrier.dstQueueFamilyIndex = 0;
Mark Mueller2ee294f2016-08-04 12:59:48 -060012233 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12234 img_barrier.subresourceRange.baseArrayLayer = 0;
12235 img_barrier.subresourceRange.baseMipLevel = 0;
12236 img_barrier.subresourceRange.layerCount = 1;
12237 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012238 vkCmdWaitEvents(m_commandBuffer->handle(), 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0,
12239 nullptr, 0, nullptr, 1, &img_barrier);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012240 m_errorMonitor->VerifyFound();
12241
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012242 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_query);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012243
12244 VkQueryPool query_pool;
12245 VkQueryPoolCreateInfo query_pool_create_info = {};
12246 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
12247 query_pool_create_info.queryType = VK_QUERY_TYPE_OCCLUSION;
12248 query_pool_create_info.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012249 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012250
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012251 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0 /*startQuery*/, 1 /*queryCount*/);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012252 vkCmdBeginQuery(m_commandBuffer->handle(), query_pool, 0, 0);
12253
12254 vkEndCommandBuffer(m_commandBuffer->handle());
12255 m_errorMonitor->VerifyFound();
12256
12257 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
12258 vkDestroyEvent(m_device->device(), event, nullptr);
12259}
12260
Mark Muellerdfe37552016-07-07 14:47:42 -060012261TEST_F(VkLayerTest, VertexBufferInvalid) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012262 TEST_DESCRIPTION(
12263 "Submit a command buffer using deleted vertex buffer, "
12264 "delete a buffer twice, use an invalid offset for each "
12265 "buffer type, and attempt to bind a null buffer");
Mark Muellerdfe37552016-07-07 14:47:42 -060012266
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012267 const char *deleted_buffer_in_command_buffer =
12268 "Cannot submit cmd buffer "
12269 "using deleted buffer ";
12270 const char *invalid_offset_message =
12271 "vkBindBufferMemory(): "
12272 "memoryOffset is 0x";
12273 const char *invalid_storage_buffer_offset_message =
12274 "vkBindBufferMemory(): "
12275 "storage memoryOffset "
12276 "is 0x";
12277 const char *invalid_texel_buffer_offset_message =
12278 "vkBindBufferMemory(): "
12279 "texel memoryOffset "
12280 "is 0x";
12281 const char *invalid_uniform_buffer_offset_message =
12282 "vkBindBufferMemory(): "
12283 "uniform memoryOffset "
12284 "is 0x";
Mark Muellerdfe37552016-07-07 14:47:42 -060012285
Tony Barbour1fa09702017-03-16 12:09:08 -060012286 ASSERT_NO_FATAL_FAILURE(Init());
Mark Muellerdfe37552016-07-07 14:47:42 -060012287 ASSERT_NO_FATAL_FAILURE(InitViewport());
12288 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12289
12290 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012291 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -060012292 pipe_ms_state_ci.pNext = NULL;
12293 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
12294 pipe_ms_state_ci.sampleShadingEnable = 0;
12295 pipe_ms_state_ci.minSampleShading = 1.0;
12296 pipe_ms_state_ci.pSampleMask = nullptr;
12297
12298 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12299 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12300 VkPipelineLayout pipeline_layout;
12301
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012302 VkResult err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, nullptr, &pipeline_layout);
Mark Muellerdfe37552016-07-07 14:47:42 -060012303 ASSERT_VK_SUCCESS(err);
12304
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012305 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
12306 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Muellerdfe37552016-07-07 14:47:42 -060012307 VkPipelineObj pipe(m_device);
12308 pipe.AddShader(&vs);
12309 pipe.AddShader(&fs);
12310 pipe.AddColorAttachment();
12311 pipe.SetMSAA(&pipe_ms_state_ci);
12312 pipe.SetViewport(m_viewports);
12313 pipe.SetScissor(m_scissors);
12314 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12315
Tony Barbour552f6c02016-12-21 14:34:07 -070012316 m_commandBuffer->BeginCommandBuffer();
12317 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012318 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Muellerdfe37552016-07-07 14:47:42 -060012319
12320 {
12321 // Create and bind a vertex buffer in a reduced scope, which will cause
12322 // it to be deleted upon leaving this scope
12323 const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012324 VkVerticesObj draw_verticies(m_device, 1, 1, sizeof(vbo_data), 3, vbo_data);
Mark Muellerdfe37552016-07-07 14:47:42 -060012325 draw_verticies.BindVertexBuffers(m_commandBuffer->handle());
12326 draw_verticies.AddVertexInputToPipe(pipe);
12327 }
12328
12329 Draw(1, 0, 0, 0);
12330
Tony Barbour552f6c02016-12-21 14:34:07 -070012331 m_commandBuffer->EndRenderPass();
12332 m_commandBuffer->EndCommandBuffer();
Mark Muellerdfe37552016-07-07 14:47:42 -060012333
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012334 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, deleted_buffer_in_command_buffer);
Mark Muellerdfe37552016-07-07 14:47:42 -060012335 QueueCommandBuffer(false);
12336 m_errorMonitor->VerifyFound();
12337
12338 {
12339 // Create and bind a vertex buffer in a reduced scope, and delete it
12340 // twice, the second through the destructor
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012341 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eDoubleDelete);
Karl Schultzf78bcdd2016-11-30 12:36:01 -070012342 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00680);
Mark Muellerdfe37552016-07-07 14:47:42 -060012343 buffer_test.TestDoubleDestroy();
12344 }
12345 m_errorMonitor->VerifyFound();
12346
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012347 m_errorMonitor->SetUnexpectedError("value of pCreateInfo->usage must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012348 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidMemoryOffset)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060012349 // Create and bind a memory buffer with an invalid offset.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012350 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_offset_message);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012351 m_errorMonitor->SetUnexpectedError(
12352 "If buffer was created with the VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT or VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT, "
12353 "memoryOffset must be a multiple of VkPhysicalDeviceLimits::minTexelBufferOffsetAlignment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012354 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidMemoryOffset);
12355 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012356 m_errorMonitor->VerifyFound();
12357 }
12358
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012359 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset,
12360 VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060012361 // Create and bind a memory buffer with an invalid offset again,
12362 // but look for a texel buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012363 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_texel_buffer_offset_message);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012364 m_errorMonitor->SetUnexpectedError(
12365 "memoryOffset must be an integer multiple of the alignment member of the VkMemoryRequirements structure returned from "
12366 "a call to vkGetBufferMemoryRequirements with buffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012367 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
12368 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012369 m_errorMonitor->VerifyFound();
12370 }
12371
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012372 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060012373 // Create and bind a memory buffer with an invalid offset again, but
12374 // look for a uniform buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012375 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_uniform_buffer_offset_message);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012376 m_errorMonitor->SetUnexpectedError(
12377 "memoryOffset must be an integer multiple of the alignment member of the VkMemoryRequirements structure returned from "
12378 "a call to vkGetBufferMemoryRequirements with buffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012379 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
12380 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012381 m_errorMonitor->VerifyFound();
12382 }
12383
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012384 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060012385 // Create and bind a memory buffer with an invalid offset again, but
12386 // look for a storage buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012387 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_storage_buffer_offset_message);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012388 m_errorMonitor->SetUnexpectedError(
12389 "memoryOffset must be an integer multiple of the alignment member of the VkMemoryRequirements structure returned from "
12390 "a call to vkGetBufferMemoryRequirements with buffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012391 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
12392 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012393 m_errorMonitor->VerifyFound();
12394 }
12395
12396 {
12397 // Attempt to bind a null buffer.
Karl Schultzf78bcdd2016-11-30 12:36:01 -070012398 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00799);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012399 m_errorMonitor->SetUnexpectedError("required parameter memory specified as VK_NULL_HANDLE");
12400 m_errorMonitor->SetUnexpectedError("memory must be a valid VkDeviceMemory handle");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012401 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eBindNullBuffer);
12402 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012403 m_errorMonitor->VerifyFound();
12404 }
12405
12406 {
12407 // Attempt to use an invalid handle to delete a buffer.
Karl Schultzf78bcdd2016-11-30 12:36:01 -070012408 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00622);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012409 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eFreeInvalidHandle);
12410 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012411 }
12412 m_errorMonitor->VerifyFound();
12413
12414 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12415}
12416
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012417// INVALID_IMAGE_LAYOUT tests (one other case is hit by MapMemWithoutHostVisibleBit and not here)
12418TEST_F(VkLayerTest, InvalidImageLayout) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012419 TEST_DESCRIPTION(
12420 "Hit all possible validation checks associated with the "
12421 "DRAWSTATE_INVALID_IMAGE_LAYOUT enum. Generally these involve having"
12422 "images in the wrong layout when they're copied or transitioned.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012423 // 3 in ValidateCmdBufImageLayouts
12424 // * -1 Attempt to submit cmd buf w/ deleted image
12425 // * -2 Cmd buf submit of image w/ layout not matching first use w/ subresource
12426 // * -3 Cmd buf submit of image w/ layout not matching first use w/o subresource
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012427
Tony Barbour1fa09702017-03-16 12:09:08 -060012428 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -060012429 auto depth_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbourf887b162017-03-09 10:06:46 -070012430 if (!depth_format) {
12431 printf(" No Depth + Stencil format found. Skipped.\n");
12432 return;
12433 }
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012434 // Create src & dst images to use for copy operations
12435 VkImage src_image;
12436 VkImage dst_image;
Cort3b021012016-12-07 12:00:57 -080012437 VkImage depth_image;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012438
12439 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
12440 const int32_t tex_width = 32;
12441 const int32_t tex_height = 32;
12442
12443 VkImageCreateInfo image_create_info = {};
12444 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
12445 image_create_info.pNext = NULL;
12446 image_create_info.imageType = VK_IMAGE_TYPE_2D;
12447 image_create_info.format = tex_format;
12448 image_create_info.extent.width = tex_width;
12449 image_create_info.extent.height = tex_height;
12450 image_create_info.extent.depth = 1;
12451 image_create_info.mipLevels = 1;
12452 image_create_info.arrayLayers = 4;
12453 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
12454 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
12455 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Cort3b021012016-12-07 12:00:57 -080012456 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012457 image_create_info.flags = 0;
12458
12459 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &src_image);
12460 ASSERT_VK_SUCCESS(err);
Cort3b021012016-12-07 12:00:57 -080012461 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012462 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dst_image);
12463 ASSERT_VK_SUCCESS(err);
Cort3b021012016-12-07 12:00:57 -080012464 image_create_info.format = VK_FORMAT_D32_SFLOAT;
12465 image_create_info.usage |= VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
12466 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &depth_image);
12467 ASSERT_VK_SUCCESS(err);
12468
12469 // Allocate memory
12470 VkMemoryRequirements img_mem_reqs = {};
Cort530cf382016-12-08 09:59:47 -080012471 VkMemoryAllocateInfo mem_alloc = {};
Cort3b021012016-12-07 12:00:57 -080012472 VkDeviceMemory src_image_mem, dst_image_mem, depth_image_mem;
Cort530cf382016-12-08 09:59:47 -080012473 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
12474 mem_alloc.pNext = NULL;
12475 mem_alloc.allocationSize = 0;
12476 mem_alloc.memoryTypeIndex = 0;
Cort3b021012016-12-07 12:00:57 -080012477
12478 vkGetImageMemoryRequirements(m_device->device(), src_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080012479 mem_alloc.allocationSize = img_mem_reqs.size;
12480 bool pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080012481 ASSERT_TRUE(pass);
Cort530cf382016-12-08 09:59:47 -080012482 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &src_image_mem);
Cort3b021012016-12-07 12:00:57 -080012483 ASSERT_VK_SUCCESS(err);
12484
12485 vkGetImageMemoryRequirements(m_device->device(), dst_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080012486 mem_alloc.allocationSize = img_mem_reqs.size;
12487 pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080012488 ASSERT_VK_SUCCESS(err);
Cort530cf382016-12-08 09:59:47 -080012489 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &dst_image_mem);
Cort3b021012016-12-07 12:00:57 -080012490 ASSERT_VK_SUCCESS(err);
12491
12492 vkGetImageMemoryRequirements(m_device->device(), depth_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080012493 mem_alloc.allocationSize = img_mem_reqs.size;
12494 pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080012495 ASSERT_VK_SUCCESS(err);
Cort530cf382016-12-08 09:59:47 -080012496 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &depth_image_mem);
Cort3b021012016-12-07 12:00:57 -080012497 ASSERT_VK_SUCCESS(err);
12498
12499 err = vkBindImageMemory(m_device->device(), src_image, src_image_mem, 0);
12500 ASSERT_VK_SUCCESS(err);
12501 err = vkBindImageMemory(m_device->device(), dst_image, dst_image_mem, 0);
12502 ASSERT_VK_SUCCESS(err);
12503 err = vkBindImageMemory(m_device->device(), depth_image, depth_image_mem, 0);
12504 ASSERT_VK_SUCCESS(err);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012505
Tony Barbour552f6c02016-12-21 14:34:07 -070012506 m_commandBuffer->BeginCommandBuffer();
Cort530cf382016-12-08 09:59:47 -080012507 VkImageCopy copy_region;
12508 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12509 copy_region.srcSubresource.mipLevel = 0;
12510 copy_region.srcSubresource.baseArrayLayer = 0;
12511 copy_region.srcSubresource.layerCount = 1;
12512 copy_region.srcOffset.x = 0;
12513 copy_region.srcOffset.y = 0;
12514 copy_region.srcOffset.z = 0;
12515 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12516 copy_region.dstSubresource.mipLevel = 0;
12517 copy_region.dstSubresource.baseArrayLayer = 0;
12518 copy_region.dstSubresource.layerCount = 1;
12519 copy_region.dstOffset.x = 0;
12520 copy_region.dstOffset.y = 0;
12521 copy_region.dstOffset.z = 0;
12522 copy_region.extent.width = 1;
12523 copy_region.extent.height = 1;
12524 copy_region.extent.depth = 1;
12525
Mark Lobodzinski91c28262017-03-22 13:06:12 -060012526 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
12527 "layout should be VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL instead of GENERAL.");
12528 m_errorMonitor->SetUnexpectedError("layout should be VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL instead of GENERAL.");
Tobin Ehlis74cc6822017-03-14 16:16:51 -060012529
Cort530cf382016-12-08 09:59:47 -080012530 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 -060012531 m_errorMonitor->VerifyFound();
Tobin Ehlise35b66a2017-03-15 12:18:31 -060012532 // The first call hits the expected WARNING and skips the call down the chain, so call a second time to call down chain and
12533 // update layer state
Mark Lobodzinski91c28262017-03-22 13:06:12 -060012534 m_errorMonitor->SetUnexpectedError("layout should be VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL instead of GENERAL.");
12535 m_errorMonitor->SetUnexpectedError("layout should be VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL instead of GENERAL.");
Tobin Ehlise35b66a2017-03-15 12:18:31 -060012536 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 -060012537 // Now cause error due to src image layout changing
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012538 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski91c28262017-03-22 13:06:12 -060012539 "with specific layout VK_IMAGE_LAYOUT_UNDEFINED that "
12540 "doesn't match the actual current layout VK_IMAGE_LAYOUT_GENERAL.");
Tobin Ehlis6d4d1d52017-04-05 12:06:10 -060012541 m_errorMonitor->SetUnexpectedError("srcImageLayout must be VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL or VK_IMAGE_LAYOUT_GENERAL");
Cort530cf382016-12-08 09:59:47 -080012542 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 -060012543 m_errorMonitor->VerifyFound();
12544 // Final src error is due to bad layout type
Tobin Ehlis74cc6822017-03-14 16:16:51 -060012545 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski91c28262017-03-22 13:06:12 -060012546 "is VK_IMAGE_LAYOUT_UNDEFINED but can only be "
Tobin Ehlis74cc6822017-03-14 16:16:51 -060012547 "VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL or VK_IMAGE_LAYOUT_GENERAL.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012548 m_errorMonitor->SetUnexpectedError(
Mark Lobodzinski91c28262017-03-22 13:06:12 -060012549 "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 -080012550 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 -060012551 m_errorMonitor->VerifyFound();
12552 // Now verify same checks for dst
Mark Lobodzinski91c28262017-03-22 13:06:12 -060012553 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
12554 "layout should be VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL instead of GENERAL.");
12555 m_errorMonitor->SetUnexpectedError("layout should be VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL instead of GENERAL.");
Cort530cf382016-12-08 09:59:47 -080012556 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 -060012557 m_errorMonitor->VerifyFound();
12558 // 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 doesn't match "
Tobin Ehlis74cc6822017-03-14 16:16:51 -060012561 "the actual current layout VK_IMAGE_LAYOUT_GENERAL.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012562 m_errorMonitor->SetUnexpectedError(
Mark Lobodzinski91c28262017-03-22 13:06:12 -060012563 "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 -080012564 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 -060012565 m_errorMonitor->VerifyFound();
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 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL "
12568 "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_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, &copy_region);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012572 m_errorMonitor->VerifyFound();
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010012573
Cort3b021012016-12-07 12:00:57 -080012574 // Convert dst and depth images to TRANSFER_DST for subsequent tests
12575 VkImageMemoryBarrier transfer_dst_image_barrier[1] = {};
12576 transfer_dst_image_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
12577 transfer_dst_image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
12578 transfer_dst_image_barrier[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
12579 transfer_dst_image_barrier[0].srcAccessMask = 0;
12580 transfer_dst_image_barrier[0].dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
12581 transfer_dst_image_barrier[0].image = dst_image;
12582 transfer_dst_image_barrier[0].subresourceRange.layerCount = image_create_info.arrayLayers;
12583 transfer_dst_image_barrier[0].subresourceRange.levelCount = image_create_info.mipLevels;
12584 transfer_dst_image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12585 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
12586 NULL, 0, NULL, 1, transfer_dst_image_barrier);
12587 transfer_dst_image_barrier[0].image = depth_image;
12588 transfer_dst_image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
12589 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
12590 NULL, 0, NULL, 1, transfer_dst_image_barrier);
12591
12592 // Cause errors due to clearing with invalid image layouts
Cort530cf382016-12-08 09:59:47 -080012593 VkClearColorValue color_clear_value = {};
12594 VkImageSubresourceRange clear_range;
12595 clear_range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12596 clear_range.baseMipLevel = 0;
12597 clear_range.baseArrayLayer = 0;
12598 clear_range.layerCount = 1;
12599 clear_range.levelCount = 1;
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010012600
Cort3b021012016-12-07 12:00:57 -080012601 // Fail due to explicitly prohibited layout for color clear (only GENERAL and TRANSFER_DST are permitted).
12602 // Since the image is currently not in UNDEFINED layout, this will emit two errors.
12603 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01086);
12604 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01085);
Cort530cf382016-12-08 09:59:47 -080012605 m_commandBuffer->ClearColorImage(dst_image, VK_IMAGE_LAYOUT_UNDEFINED, &color_clear_value, 1, &clear_range);
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010012606 m_errorMonitor->VerifyFound();
Cort3b021012016-12-07 12:00:57 -080012607 // Fail due to provided layout not matching actual current layout for color clear.
12608 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01085);
Cort530cf382016-12-08 09:59:47 -080012609 m_commandBuffer->ClearColorImage(dst_image, VK_IMAGE_LAYOUT_GENERAL, &color_clear_value, 1, &clear_range);
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010012610 m_errorMonitor->VerifyFound();
Cort3b021012016-12-07 12:00:57 -080012611
Cort530cf382016-12-08 09:59:47 -080012612 VkClearDepthStencilValue depth_clear_value = {};
12613 clear_range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Cort3b021012016-12-07 12:00:57 -080012614
12615 // Fail due to explicitly prohibited layout for depth clear (only GENERAL and TRANSFER_DST are permitted).
12616 // Since the image is currently not in UNDEFINED layout, this will emit two errors.
12617 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01101);
12618 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01100);
Cort530cf382016-12-08 09:59:47 -080012619 m_commandBuffer->ClearDepthStencilImage(depth_image, VK_IMAGE_LAYOUT_UNDEFINED, &depth_clear_value, 1, &clear_range);
Cort3b021012016-12-07 12:00:57 -080012620 m_errorMonitor->VerifyFound();
12621 // Fail due to provided layout not matching actual current layout for depth clear.
12622 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01100);
Cort530cf382016-12-08 09:59:47 -080012623 m_commandBuffer->ClearDepthStencilImage(depth_image, VK_IMAGE_LAYOUT_GENERAL, &depth_clear_value, 1, &clear_range);
Cort3b021012016-12-07 12:00:57 -080012624 m_errorMonitor->VerifyFound();
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010012625
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012626 // Now cause error due to bad image layout transition in PipelineBarrier
12627 VkImageMemoryBarrier image_barrier[1] = {};
Cort3b021012016-12-07 12:00:57 -080012628 image_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012629 image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
Cort3b021012016-12-07 12:00:57 -080012630 image_barrier[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012631 image_barrier[0].image = src_image;
Cort3b021012016-12-07 12:00:57 -080012632 image_barrier[0].subresourceRange.layerCount = image_create_info.arrayLayers;
12633 image_barrier[0].subresourceRange.levelCount = image_create_info.mipLevels;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012634 image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012635 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski91c28262017-03-22 13:06:12 -060012636 "you cannot transition the layout of aspect 1 from "
12637 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL when current layout is "
12638 "VK_IMAGE_LAYOUT_GENERAL.");
Mike Weiblen62d08a32017-03-07 22:18:27 -070012639 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00305);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012640 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
12641 NULL, 0, NULL, 1, image_barrier);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012642 m_errorMonitor->VerifyFound();
12643
12644 // Finally some layout errors at RenderPass create time
12645 // Just hacking in specific state to get to the errors we want so don't copy this unless you know what you're doing.
12646 VkAttachmentReference attach = {};
12647 // perf warning for GENERAL layout w/ non-DS input attachment
12648 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
12649 VkSubpassDescription subpass = {};
12650 subpass.inputAttachmentCount = 1;
12651 subpass.pInputAttachments = &attach;
12652 VkRenderPassCreateInfo rpci = {};
12653 rpci.subpassCount = 1;
12654 rpci.pSubpasses = &subpass;
12655 rpci.attachmentCount = 1;
12656 VkAttachmentDescription attach_desc = {};
12657 attach_desc.format = VK_FORMAT_UNDEFINED;
12658 rpci.pAttachments = &attach_desc;
Tobin Ehlis1efce022016-05-11 10:40:34 -060012659 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012660 VkRenderPass rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012661 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
12662 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012663 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12664 m_errorMonitor->VerifyFound();
12665 // error w/ non-general layout
12666 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
12667
12668 m_errorMonitor->SetDesiredFailureMsg(
12669 VK_DEBUG_REPORT_ERROR_BIT_EXT,
12670 "Layout for input attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be READ_ONLY_OPTIMAL or GENERAL.");
12671 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12672 m_errorMonitor->VerifyFound();
12673 subpass.inputAttachmentCount = 0;
12674 subpass.colorAttachmentCount = 1;
12675 subpass.pColorAttachments = &attach;
12676 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
12677 // perf warning for GENERAL layout on color attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012678 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
12679 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012680 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12681 m_errorMonitor->VerifyFound();
12682 // error w/ non-color opt or GENERAL layout for color attachment
12683 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
12684 m_errorMonitor->SetDesiredFailureMsg(
12685 VK_DEBUG_REPORT_ERROR_BIT_EXT,
12686 "Layout for color attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.");
12687 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12688 m_errorMonitor->VerifyFound();
12689 subpass.colorAttachmentCount = 0;
12690 subpass.pDepthStencilAttachment = &attach;
12691 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
12692 // perf warning for GENERAL layout on DS attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012693 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
12694 "GENERAL layout for depth attachment may not give optimal performance.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012695 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12696 m_errorMonitor->VerifyFound();
12697 // error w/ non-ds opt or GENERAL layout for color attachment
12698 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012699 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12700 "Layout for depth attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be "
12701 "DEPTH_STENCIL_ATTACHMENT_OPTIMAL, DEPTH_STENCIL_READ_ONLY_OPTIMAL or GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012702 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12703 m_errorMonitor->VerifyFound();
Tobin Ehlis1efce022016-05-11 10:40:34 -060012704 // For this error we need a valid renderpass so create default one
12705 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
12706 attach.attachment = 0;
Tony Barbourf887b162017-03-09 10:06:46 -070012707 attach_desc.format = depth_format;
Tobin Ehlis1efce022016-05-11 10:40:34 -060012708 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
12709 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
12710 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
12711 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
12712 // Can't do a CLEAR load on READ_ONLY initialLayout
12713 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
12714 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
12715 attach_desc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012716 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski91c28262017-03-22 13:06:12 -060012717 "with invalid first layout VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL");
Tobin Ehlis1efce022016-05-11 10:40:34 -060012718 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12719 m_errorMonitor->VerifyFound();
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012720
Cort3b021012016-12-07 12:00:57 -080012721 vkFreeMemory(m_device->device(), src_image_mem, NULL);
12722 vkFreeMemory(m_device->device(), dst_image_mem, NULL);
12723 vkFreeMemory(m_device->device(), depth_image_mem, NULL);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012724 vkDestroyImage(m_device->device(), src_image, NULL);
12725 vkDestroyImage(m_device->device(), dst_image, NULL);
Cort3b021012016-12-07 12:00:57 -080012726 vkDestroyImage(m_device->device(), depth_image, NULL);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012727}
Tobin Ehlisd8d89182016-07-18 20:13:11 -060012728
Tobin Ehlise0936662016-10-11 08:10:51 -060012729TEST_F(VkLayerTest, InvalidStorageImageLayout) {
12730 TEST_DESCRIPTION("Attempt to update a STORAGE_IMAGE descriptor w/o GENERAL layout.");
12731 VkResult err;
12732
Tony Barbour1fa09702017-03-16 12:09:08 -060012733 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlise0936662016-10-11 08:10:51 -060012734
12735 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
12736 VkImageTiling tiling;
12737 VkFormatProperties format_properties;
12738 vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties);
12739 if (format_properties.linearTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
12740 tiling = VK_IMAGE_TILING_LINEAR;
12741 } else if (format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
12742 tiling = VK_IMAGE_TILING_OPTIMAL;
12743 } else {
Dave Houlton584d51e2017-02-16 12:52:54 -070012744 printf(" Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; skipped.\n");
Tobin Ehlise0936662016-10-11 08:10:51 -060012745 return;
12746 }
12747
12748 VkDescriptorPoolSize ds_type = {};
12749 ds_type.type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
12750 ds_type.descriptorCount = 1;
12751
12752 VkDescriptorPoolCreateInfo ds_pool_ci = {};
12753 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12754 ds_pool_ci.maxSets = 1;
12755 ds_pool_ci.poolSizeCount = 1;
12756 ds_pool_ci.pPoolSizes = &ds_type;
12757 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
12758
12759 VkDescriptorPool ds_pool;
12760 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
12761 ASSERT_VK_SUCCESS(err);
12762
12763 VkDescriptorSetLayoutBinding dsl_binding = {};
12764 dsl_binding.binding = 0;
12765 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
12766 dsl_binding.descriptorCount = 1;
12767 dsl_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12768 dsl_binding.pImmutableSamplers = NULL;
12769
12770 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
12771 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12772 ds_layout_ci.pNext = NULL;
12773 ds_layout_ci.bindingCount = 1;
12774 ds_layout_ci.pBindings = &dsl_binding;
12775
12776 VkDescriptorSetLayout ds_layout;
12777 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
12778 ASSERT_VK_SUCCESS(err);
12779
12780 VkDescriptorSetAllocateInfo alloc_info = {};
12781 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12782 alloc_info.descriptorSetCount = 1;
12783 alloc_info.descriptorPool = ds_pool;
12784 alloc_info.pSetLayouts = &ds_layout;
12785 VkDescriptorSet descriptor_set;
12786 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
12787 ASSERT_VK_SUCCESS(err);
12788
12789 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12790 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12791 pipeline_layout_ci.pNext = NULL;
12792 pipeline_layout_ci.setLayoutCount = 1;
12793 pipeline_layout_ci.pSetLayouts = &ds_layout;
12794 VkPipelineLayout pipeline_layout;
12795 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
12796 ASSERT_VK_SUCCESS(err);
12797
12798 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060012799 image.Init(32, 32, 1, tex_format, VK_IMAGE_USAGE_STORAGE_BIT, tiling, 0);
Tobin Ehlise0936662016-10-11 08:10:51 -060012800 ASSERT_TRUE(image.initialized());
12801 VkImageView view = image.targetView(tex_format);
12802
12803 VkDescriptorImageInfo image_info = {};
12804 image_info.imageView = view;
12805 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
12806
12807 VkWriteDescriptorSet descriptor_write = {};
12808 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12809 descriptor_write.dstSet = descriptor_set;
12810 descriptor_write.dstBinding = 0;
12811 descriptor_write.descriptorCount = 1;
12812 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
12813 descriptor_write.pImageInfo = &image_info;
12814
12815 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12816 " of VK_DESCRIPTOR_TYPE_STORAGE_IMAGE type is being updated with layout "
12817 "VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL but according to spec ");
12818 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
12819 m_errorMonitor->VerifyFound();
12820
12821 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12822 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12823 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
12824 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
12825}
12826
Mark Mueller93b938f2016-08-18 10:27:40 -060012827TEST_F(VkLayerTest, SimultaneousUse) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012828 TEST_DESCRIPTION(
12829 "Use vkCmdExecuteCommands with invalid state "
12830 "in primary and secondary command buffers.");
Mark Mueller93b938f2016-08-18 10:27:40 -060012831
Tony Barbour1fa09702017-03-16 12:09:08 -060012832 ASSERT_NO_FATAL_FAILURE(Init());
Mark Mueller93b938f2016-08-18 10:27:40 -060012833 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12834
Mike Weiblen95dd0f92016-10-19 12:28:27 -060012835 const char *simultaneous_use_message1 = "without VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set!";
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012836 const char *simultaneous_use_message2 =
12837 "does not have VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set and "
12838 "will cause primary command buffer";
Mark Mueller93b938f2016-08-18 10:27:40 -060012839
12840 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012841 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mike Schuchardt06304c22017-03-01 17:09:09 -070012842 command_buffer_allocate_info.commandPool = m_commandPool->handle();
Mark Mueller93b938f2016-08-18 10:27:40 -060012843 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
12844 command_buffer_allocate_info.commandBufferCount = 1;
12845
12846 VkCommandBuffer secondary_command_buffer;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012847 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
Mark Mueller93b938f2016-08-18 10:27:40 -060012848 VkCommandBufferBeginInfo command_buffer_begin_info = {};
12849 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012850 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060012851 command_buffer_inheritance_info.renderPass = m_renderPass;
12852 command_buffer_inheritance_info.framebuffer = m_framebuffer;
Rene Lindsay24cf6c52017-01-04 12:06:59 -070012853
Mark Mueller93b938f2016-08-18 10:27:40 -060012854 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012855 command_buffer_begin_info.flags =
12856 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060012857 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
12858
12859 vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
12860 vkEndCommandBuffer(secondary_command_buffer);
12861
Mark Mueller93b938f2016-08-18 10:27:40 -060012862 VkSubmitInfo submit_info = {};
12863 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12864 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012865 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller93b938f2016-08-18 10:27:40 -060012866
Mark Mueller4042b652016-09-05 22:52:21 -060012867 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012868 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
12869 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, simultaneous_use_message1);
12870 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Rene Lindsay24cf6c52017-01-04 12:06:59 -070012871 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060012872 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060012873 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
12874 vkEndCommandBuffer(m_commandBuffer->handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060012875
Dave Houltonfbf52152017-01-06 12:55:29 -070012876 m_errorMonitor->ExpectSuccess(0);
Mark Mueller93b938f2016-08-18 10:27:40 -060012877 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Dave Houltonfbf52152017-01-06 12:55:29 -070012878 m_errorMonitor->VerifyNotFound();
Mark Mueller93b938f2016-08-18 10:27:40 -060012879
Mark Mueller4042b652016-09-05 22:52:21 -060012880 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
Tobin Ehlis6d4d1d52017-04-05 12:06:10 -060012881 m_errorMonitor->SetUnexpectedError("commandBuffer must not be in the recording or pending state.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012882 m_errorMonitor->SetUnexpectedError(
12883 "If commandBuffer was allocated from a VkCommandPool which did not have the "
12884 "VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT flag set, commandBuffer must be in the initial state");
Mark Mueller93b938f2016-08-18 10:27:40 -060012885 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012886 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Mark Mueller4042b652016-09-05 22:52:21 -060012887
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012888 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, simultaneous_use_message2);
12889 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060012890 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060012891 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
12892 vkEndCommandBuffer(m_commandBuffer->handle());
Rene Lindsay24cf6c52017-01-04 12:06:59 -070012893
12894 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012895
Tobin Ehlis6d4d1d52017-04-05 12:06:10 -060012896 m_errorMonitor->SetUnexpectedError("All elements of pCommandBuffers must not be in the pending state");
Mark Mueller93b938f2016-08-18 10:27:40 -060012897}
12898
Tony Barbour626994c2017-02-08 15:29:37 -070012899TEST_F(VkLayerTest, SimultaneousUseOneShot) {
12900 TEST_DESCRIPTION(
12901 "Submit the same command buffer twice in one submit looking for simultaneous use and one time submit"
12902 "errors");
12903 const char *simultaneous_use_message = "is already in use and is not marked for simultaneous use";
12904 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 -060012905 ASSERT_NO_FATAL_FAILURE(Init());
Tony Barbour626994c2017-02-08 15:29:37 -070012906
12907 VkCommandBuffer cmd_bufs[2];
12908 VkCommandBufferAllocateInfo alloc_info;
12909 alloc_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
12910 alloc_info.pNext = NULL;
12911 alloc_info.commandBufferCount = 2;
Mike Schuchardt06304c22017-03-01 17:09:09 -070012912 alloc_info.commandPool = m_commandPool->handle();
Tony Barbour626994c2017-02-08 15:29:37 -070012913 alloc_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
12914 vkAllocateCommandBuffers(m_device->device(), &alloc_info, cmd_bufs);
12915
12916 VkCommandBufferBeginInfo cb_binfo;
12917 cb_binfo.pNext = NULL;
12918 cb_binfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
12919 cb_binfo.pInheritanceInfo = VK_NULL_HANDLE;
12920 cb_binfo.flags = 0;
12921 vkBeginCommandBuffer(cmd_bufs[0], &cb_binfo);
12922 VkViewport viewport = {0, 0, 16, 16, 0, 1};
12923 vkCmdSetViewport(cmd_bufs[0], 0, 1, &viewport);
12924 vkEndCommandBuffer(cmd_bufs[0]);
12925 VkCommandBuffer duplicates[2] = {cmd_bufs[0], cmd_bufs[0]};
12926
12927 VkSubmitInfo submit_info = {};
12928 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12929 submit_info.commandBufferCount = 2;
12930 submit_info.pCommandBuffers = duplicates;
12931 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, simultaneous_use_message);
12932 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12933 m_errorMonitor->VerifyFound();
12934 vkQueueWaitIdle(m_device->m_queue);
12935
12936 // Set one time use and now look for one time submit
12937 duplicates[0] = duplicates[1] = cmd_bufs[1];
12938 cb_binfo.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT | VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
12939 vkBeginCommandBuffer(cmd_bufs[1], &cb_binfo);
12940 vkCmdSetViewport(cmd_bufs[1], 0, 1, &viewport);
12941 vkEndCommandBuffer(cmd_bufs[1]);
12942 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, one_shot_message);
12943 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12944 m_errorMonitor->VerifyFound();
12945 vkQueueWaitIdle(m_device->m_queue);
12946}
12947
Tobin Ehlisb093da82017-01-19 12:05:27 -070012948TEST_F(VkLayerTest, StageMaskGsTsEnabled) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012949 TEST_DESCRIPTION(
12950 "Attempt to use a stageMask w/ geometry shader and tesselation shader bits enabled when those features are "
12951 "disabled on the device.");
Tobin Ehlisb093da82017-01-19 12:05:27 -070012952
Tony Barbour1fa09702017-03-16 12:09:08 -060012953 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisb093da82017-01-19 12:05:27 -070012954 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12955
12956 std::vector<const char *> device_extension_names;
12957 auto features = m_device->phy().features();
12958 // Make sure gs & ts are disabled
12959 features.geometryShader = false;
12960 features.tessellationShader = false;
12961 // The sacrificial device object
12962 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
12963
12964 VkCommandPoolCreateInfo pool_create_info{};
12965 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
12966 pool_create_info.queueFamilyIndex = test_device.graphics_queue_node_index_;
12967
12968 VkCommandPool command_pool;
12969 vkCreateCommandPool(test_device.handle(), &pool_create_info, nullptr, &command_pool);
12970
12971 VkCommandBufferAllocateInfo cmd = {};
12972 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
12973 cmd.pNext = NULL;
12974 cmd.commandPool = command_pool;
12975 cmd.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
12976 cmd.commandBufferCount = 1;
12977
12978 VkCommandBuffer cmd_buffer;
12979 VkResult err = vkAllocateCommandBuffers(test_device.handle(), &cmd, &cmd_buffer);
12980 ASSERT_VK_SUCCESS(err);
12981
12982 VkEvent event;
12983 VkEventCreateInfo evci = {};
12984 evci.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
12985 VkResult result = vkCreateEvent(test_device.handle(), &evci, NULL, &event);
12986 ASSERT_VK_SUCCESS(result);
12987
12988 VkCommandBufferBeginInfo cbbi = {};
12989 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
12990 vkBeginCommandBuffer(cmd_buffer, &cbbi);
12991 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00230);
12992 vkCmdSetEvent(cmd_buffer, event, VK_PIPELINE_STAGE_GEOMETRY_SHADER_BIT);
12993 m_errorMonitor->VerifyFound();
12994
12995 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00231);
12996 vkCmdSetEvent(cmd_buffer, event, VK_PIPELINE_STAGE_TESSELLATION_CONTROL_SHADER_BIT);
12997 m_errorMonitor->VerifyFound();
12998
12999 vkDestroyEvent(test_device.handle(), event, NULL);
13000 vkDestroyCommandPool(test_device.handle(), command_pool, NULL);
13001}
13002
Chris Forbesd70103a2017-04-13 11:34:09 -070013003TEST_F(VkLayerTest, EventInUseDestroyedSignaled) {
Tony Barbour1fa09702017-03-16 12:09:08 -060013004 ASSERT_NO_FATAL_FAILURE(Init());
Mark Mueller917f6bc2016-08-30 10:57:19 -060013005 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13006
Tony Barbour552f6c02016-12-21 14:34:07 -070013007 m_commandBuffer->BeginCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060013008
13009 VkEvent event;
13010 VkEventCreateInfo event_create_info = {};
13011 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
13012 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013013 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Mueller917f6bc2016-08-30 10:57:19 -060013014
Tony Barbour552f6c02016-12-21 14:34:07 -070013015 m_commandBuffer->EndCommandBuffer();
Mark Muellerc8d441e2016-08-23 17:36:00 -060013016 vkDestroyEvent(m_device->device(), event, nullptr);
13017
13018 VkSubmitInfo submit_info = {};
13019 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
13020 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013021 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Lobodzinskife4be302017-02-14 13:08:15 -070013022 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is invalid because bound");
Mark Muellerc8d441e2016-08-23 17:36:00 -060013023 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
13024 m_errorMonitor->VerifyFound();
Chris Forbesd70103a2017-04-13 11:34:09 -070013025}
Mark Muellerc8d441e2016-08-23 17:36:00 -060013026
Chris Forbesd70103a2017-04-13 11:34:09 -070013027TEST_F(VkLayerTest, InUseDestroyedSignaled) {
13028 TEST_DESCRIPTION(
13029 "Use vkCmdExecuteCommands with invalid state "
13030 "in primary and secondary command buffers. "
13031 "Delete objects that are inuse. Call VkQueueSubmit "
13032 "with an event that has been deleted.");
Mark Muellerc8d441e2016-08-23 17:36:00 -060013033
Chris Forbesd70103a2017-04-13 11:34:09 -070013034 ASSERT_NO_FATAL_FAILURE(Init());
13035 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13036
13037 m_errorMonitor->ExpectSuccess();
Mark Muellerc8d441e2016-08-23 17:36:00 -060013038
Mark Mueller917f6bc2016-08-30 10:57:19 -060013039 VkSemaphoreCreateInfo semaphore_create_info = {};
13040 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
13041 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013042 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller917f6bc2016-08-30 10:57:19 -060013043 VkFenceCreateInfo fence_create_info = {};
13044 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
13045 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013046 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller917f6bc2016-08-30 10:57:19 -060013047
13048 VkDescriptorPoolSize descriptor_pool_type_count = {};
Mark Mueller4042b652016-09-05 22:52:21 -060013049 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060013050 descriptor_pool_type_count.descriptorCount = 1;
13051
13052 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
13053 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
13054 descriptor_pool_create_info.maxSets = 1;
13055 descriptor_pool_create_info.poolSizeCount = 1;
13056 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013057 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Mark Mueller917f6bc2016-08-30 10:57:19 -060013058
13059 VkDescriptorPool descriptorset_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013060 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
Mark Mueller917f6bc2016-08-30 10:57:19 -060013061
13062 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
Mark Mueller4042b652016-09-05 22:52:21 -060013063 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060013064 descriptorset_layout_binding.descriptorCount = 1;
13065 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
13066
13067 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013068 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060013069 descriptorset_layout_create_info.bindingCount = 1;
13070 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
13071
13072 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013073 ASSERT_VK_SUCCESS(
13074 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060013075
13076 VkDescriptorSet descriptorset;
13077 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013078 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060013079 descriptorset_allocate_info.descriptorSetCount = 1;
13080 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
13081 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013082 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
Mark Mueller917f6bc2016-08-30 10:57:19 -060013083
Mark Mueller4042b652016-09-05 22:52:21 -060013084 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
13085
13086 VkDescriptorBufferInfo buffer_info = {};
13087 buffer_info.buffer = buffer_test.GetBuffer();
13088 buffer_info.offset = 0;
13089 buffer_info.range = 1024;
13090
13091 VkWriteDescriptorSet write_descriptor_set = {};
13092 write_descriptor_set.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
13093 write_descriptor_set.dstSet = descriptorset;
13094 write_descriptor_set.descriptorCount = 1;
13095 write_descriptor_set.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
13096 write_descriptor_set.pBufferInfo = &buffer_info;
13097
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013098 vkUpdateDescriptorSets(m_device->device(), 1, &write_descriptor_set, 0, nullptr);
Mark Mueller4042b652016-09-05 22:52:21 -060013099
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013100 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
13101 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Mueller917f6bc2016-08-30 10:57:19 -060013102
13103 VkPipelineObj pipe(m_device);
13104 pipe.AddColorAttachment();
13105 pipe.AddShader(&vs);
13106 pipe.AddShader(&fs);
13107
13108 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013109 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060013110 pipeline_layout_create_info.setLayoutCount = 1;
13111 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
13112
13113 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013114 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060013115
13116 pipe.CreateVKPipeline(pipeline_layout, m_renderPass);
13117
Chris Forbesd70103a2017-04-13 11:34:09 -070013118 VkEvent event;
13119 VkEventCreateInfo event_create_info = {};
13120 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
13121 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
13122
Tony Barbour552f6c02016-12-21 14:34:07 -070013123 m_commandBuffer->BeginCommandBuffer();
Chris Forbesd70103a2017-04-13 11:34:09 -070013124
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013125 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Muellerc8d441e2016-08-23 17:36:00 -060013126
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013127 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
13128 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
13129 &descriptorset, 0, NULL);
Mark Mueller917f6bc2016-08-30 10:57:19 -060013130
Tony Barbour552f6c02016-12-21 14:34:07 -070013131 m_commandBuffer->EndCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060013132
Chris Forbesd70103a2017-04-13 11:34:09 -070013133 VkSubmitInfo submit_info = {};
13134 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
13135 submit_info.commandBufferCount = 1;
13136 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller917f6bc2016-08-30 10:57:19 -060013137 submit_info.signalSemaphoreCount = 1;
13138 submit_info.pSignalSemaphores = &semaphore;
13139 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013140 m_errorMonitor->Reset(); // resume logmsg processing
Mark Muellerc8d441e2016-08-23 17:36:00 -060013141
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070013142 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00213);
Mark Mueller917f6bc2016-08-30 10:57:19 -060013143 vkDestroyEvent(m_device->device(), event, nullptr);
13144 m_errorMonitor->VerifyFound();
13145
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070013146 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00199);
Mark Mueller917f6bc2016-08-30 10:57:19 -060013147 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
13148 m_errorMonitor->VerifyFound();
13149
Jeremy Hayes08369882017-02-02 10:31:06 -070013150 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Fence 0x");
Mark Mueller917f6bc2016-08-30 10:57:19 -060013151 vkDestroyFence(m_device->device(), fence, nullptr);
13152 m_errorMonitor->VerifyFound();
13153
Tobin Ehlis122207b2016-09-01 08:50:06 -070013154 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070013155 m_errorMonitor->SetUnexpectedError("If semaphore is not VK_NULL_HANDLE, semaphore must be a valid VkSemaphore handle");
13156 m_errorMonitor->SetUnexpectedError("Unable to remove Semaphore obj");
Mark Mueller917f6bc2016-08-30 10:57:19 -060013157 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070013158 m_errorMonitor->SetUnexpectedError("If fence is not VK_NULL_HANDLE, fence must be a valid VkFence handle");
13159 m_errorMonitor->SetUnexpectedError("Unable to remove Fence obj");
Mark Mueller917f6bc2016-08-30 10:57:19 -060013160 vkDestroyFence(m_device->device(), fence, nullptr);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070013161 m_errorMonitor->SetUnexpectedError("If event is not VK_NULL_HANDLE, event must be a valid VkEvent handle");
13162 m_errorMonitor->SetUnexpectedError("Unable to remove Event obj");
Mark Mueller917f6bc2016-08-30 10:57:19 -060013163 vkDestroyEvent(m_device->device(), event, nullptr);
13164 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013165 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
Mark Mueller917f6bc2016-08-30 10:57:19 -060013166 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13167}
13168
Tobin Ehlis2adda372016-09-01 08:51:06 -070013169TEST_F(VkLayerTest, QueryPoolInUseDestroyedSignaled) {
13170 TEST_DESCRIPTION("Delete in-use query pool.");
13171
Tony Barbour1fa09702017-03-16 12:09:08 -060013172 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis2adda372016-09-01 08:51:06 -070013173 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13174
13175 VkQueryPool query_pool;
13176 VkQueryPoolCreateInfo query_pool_ci{};
13177 query_pool_ci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
13178 query_pool_ci.queryType = VK_QUERY_TYPE_TIMESTAMP;
13179 query_pool_ci.queryCount = 1;
13180 vkCreateQueryPool(m_device->device(), &query_pool_ci, nullptr, &query_pool);
Tony Barbour552f6c02016-12-21 14:34:07 -070013181 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis2adda372016-09-01 08:51:06 -070013182 // Reset query pool to create binding with cmd buffer
13183 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0, 1);
13184
Tony Barbour552f6c02016-12-21 14:34:07 -070013185 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis2adda372016-09-01 08:51:06 -070013186
13187 VkSubmitInfo submit_info = {};
13188 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
13189 submit_info.commandBufferCount = 1;
13190 submit_info.pCommandBuffers = &m_commandBuffer->handle();
13191 // Submit cmd buffer and then destroy query pool while in-flight
13192 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
13193
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070013194 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01012);
Tobin Ehlis2adda372016-09-01 08:51:06 -070013195 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
13196 m_errorMonitor->VerifyFound();
13197
13198 vkQueueWaitIdle(m_device->m_queue);
13199 // Now that cmd buffer done we can safely destroy query_pool
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070013200 m_errorMonitor->SetUnexpectedError("If queryPool is not VK_NULL_HANDLE, queryPool must be a valid VkQueryPool handle");
Mark Lobodzinski74597792017-04-11 15:43:49 -060013201 m_errorMonitor->SetUnexpectedError("Unable to remove QueryPool obj");
Tobin Ehlis2adda372016-09-01 08:51:06 -070013202 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
13203}
13204
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060013205TEST_F(VkLayerTest, PipelineInUseDestroyedSignaled) {
13206 TEST_DESCRIPTION("Delete in-use pipeline.");
13207
Tony Barbour1fa09702017-03-16 12:09:08 -060013208 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060013209 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13210
13211 // Empty pipeline layout used for binding PSO
13212 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
13213 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13214 pipeline_layout_ci.setLayoutCount = 0;
13215 pipeline_layout_ci.pSetLayouts = NULL;
13216
13217 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013218 VkResult err = vkCreatePipelineLayout(m_device->handle(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060013219 ASSERT_VK_SUCCESS(err);
13220
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070013221 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00555);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060013222 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013223 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
13224 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060013225 // Store pipeline handle so we can actually delete it before test finishes
13226 VkPipeline delete_this_pipeline;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013227 { // Scope pipeline so it will be auto-deleted
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060013228 VkPipelineObj pipe(m_device);
13229 pipe.AddShader(&vs);
13230 pipe.AddShader(&fs);
13231 pipe.AddColorAttachment();
13232 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13233 delete_this_pipeline = pipe.handle();
13234
Tony Barbour552f6c02016-12-21 14:34:07 -070013235 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060013236 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013237 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060013238
Tony Barbour552f6c02016-12-21 14:34:07 -070013239 m_commandBuffer->EndCommandBuffer();
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060013240
13241 VkSubmitInfo submit_info = {};
13242 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
13243 submit_info.commandBufferCount = 1;
13244 submit_info.pCommandBuffers = &m_commandBuffer->handle();
13245 // Submit cmd buffer and then pipeline destroyed while in-flight
13246 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013247 } // Pipeline deletion triggered here
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060013248 m_errorMonitor->VerifyFound();
13249 // Make sure queue finished and then actually delete pipeline
13250 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070013251 m_errorMonitor->SetUnexpectedError("If pipeline is not VK_NULL_HANDLE, pipeline must be a valid VkPipeline handle");
13252 m_errorMonitor->SetUnexpectedError("Unable to remove Pipeline obj");
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060013253 vkDestroyPipeline(m_device->handle(), delete_this_pipeline, nullptr);
13254 vkDestroyPipelineLayout(m_device->handle(), pipeline_layout, nullptr);
13255}
13256
Tobin Ehlis7d965da2016-09-19 16:15:45 -060013257TEST_F(VkLayerTest, ImageViewInUseDestroyedSignaled) {
13258 TEST_DESCRIPTION("Delete in-use imageView.");
13259
Tony Barbour1fa09702017-03-16 12:09:08 -060013260 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis7d965da2016-09-19 16:15:45 -060013261 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13262
13263 VkDescriptorPoolSize ds_type_count;
13264 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
13265 ds_type_count.descriptorCount = 1;
13266
13267 VkDescriptorPoolCreateInfo ds_pool_ci = {};
13268 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
13269 ds_pool_ci.maxSets = 1;
13270 ds_pool_ci.poolSizeCount = 1;
13271 ds_pool_ci.pPoolSizes = &ds_type_count;
13272
13273 VkDescriptorPool ds_pool;
13274 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
13275 ASSERT_VK_SUCCESS(err);
13276
13277 VkSamplerCreateInfo sampler_ci = {};
13278 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
13279 sampler_ci.pNext = NULL;
13280 sampler_ci.magFilter = VK_FILTER_NEAREST;
13281 sampler_ci.minFilter = VK_FILTER_NEAREST;
13282 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
13283 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
13284 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
13285 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
13286 sampler_ci.mipLodBias = 1.0;
13287 sampler_ci.anisotropyEnable = VK_FALSE;
13288 sampler_ci.maxAnisotropy = 1;
13289 sampler_ci.compareEnable = VK_FALSE;
13290 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
13291 sampler_ci.minLod = 1.0;
13292 sampler_ci.maxLod = 1.0;
13293 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
13294 sampler_ci.unnormalizedCoordinates = VK_FALSE;
13295 VkSampler sampler;
13296
13297 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
13298 ASSERT_VK_SUCCESS(err);
13299
13300 VkDescriptorSetLayoutBinding layout_binding;
13301 layout_binding.binding = 0;
13302 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
13303 layout_binding.descriptorCount = 1;
13304 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
13305 layout_binding.pImmutableSamplers = NULL;
13306
13307 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
13308 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
13309 ds_layout_ci.bindingCount = 1;
13310 ds_layout_ci.pBindings = &layout_binding;
13311 VkDescriptorSetLayout ds_layout;
13312 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
13313 ASSERT_VK_SUCCESS(err);
13314
13315 VkDescriptorSetAllocateInfo alloc_info = {};
13316 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
13317 alloc_info.descriptorSetCount = 1;
13318 alloc_info.descriptorPool = ds_pool;
13319 alloc_info.pSetLayouts = &ds_layout;
13320 VkDescriptorSet descriptor_set;
13321 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
13322 ASSERT_VK_SUCCESS(err);
13323
13324 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
13325 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13326 pipeline_layout_ci.pNext = NULL;
13327 pipeline_layout_ci.setLayoutCount = 1;
13328 pipeline_layout_ci.pSetLayouts = &ds_layout;
13329
13330 VkPipelineLayout pipeline_layout;
13331 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
13332 ASSERT_VK_SUCCESS(err);
13333
13334 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060013335 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 -060013336 ASSERT_TRUE(image.initialized());
13337
13338 VkImageView view;
13339 VkImageViewCreateInfo ivci = {};
13340 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
13341 ivci.image = image.handle();
13342 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
13343 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
13344 ivci.subresourceRange.layerCount = 1;
13345 ivci.subresourceRange.baseMipLevel = 0;
13346 ivci.subresourceRange.levelCount = 1;
13347 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
13348
13349 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
13350 ASSERT_VK_SUCCESS(err);
13351
13352 VkDescriptorImageInfo image_info{};
13353 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
13354 image_info.imageView = view;
13355 image_info.sampler = sampler;
13356
13357 VkWriteDescriptorSet descriptor_write = {};
13358 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
13359 descriptor_write.dstSet = descriptor_set;
13360 descriptor_write.dstBinding = 0;
13361 descriptor_write.descriptorCount = 1;
13362 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
13363 descriptor_write.pImageInfo = &image_info;
13364
13365 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
13366
13367 // Create PSO to use the sampler
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013368 char const *vsSource =
13369 "#version 450\n"
13370 "\n"
13371 "out gl_PerVertex { \n"
13372 " vec4 gl_Position;\n"
13373 "};\n"
13374 "void main(){\n"
13375 " gl_Position = vec4(1);\n"
13376 "}\n";
13377 char const *fsSource =
13378 "#version 450\n"
13379 "\n"
13380 "layout(set=0, binding=0) uniform sampler2D s;\n"
13381 "layout(location=0) out vec4 x;\n"
13382 "void main(){\n"
13383 " x = texture(s, vec2(1));\n"
13384 "}\n";
Tobin Ehlis7d965da2016-09-19 16:15:45 -060013385 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13386 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13387 VkPipelineObj pipe(m_device);
13388 pipe.AddShader(&vs);
13389 pipe.AddShader(&fs);
13390 pipe.AddColorAttachment();
13391 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13392
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070013393 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00776);
Tobin Ehlis7d965da2016-09-19 16:15:45 -060013394
Tony Barbour552f6c02016-12-21 14:34:07 -070013395 m_commandBuffer->BeginCommandBuffer();
13396 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis7d965da2016-09-19 16:15:45 -060013397 // Bind pipeline to cmd buffer
13398 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
13399 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
13400 &descriptor_set, 0, nullptr);
Rene Lindsaya8880622017-01-18 13:12:59 -070013401
13402 VkViewport viewport = {0, 0, 16, 16, 0, 1};
13403 VkRect2D scissor = {{0, 0}, {16, 16}};
13404 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
13405 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
13406
Tobin Ehlis7d965da2016-09-19 16:15:45 -060013407 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070013408 m_commandBuffer->EndRenderPass();
13409 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis7d965da2016-09-19 16:15:45 -060013410 // Submit cmd buffer then destroy sampler
13411 VkSubmitInfo submit_info = {};
13412 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
13413 submit_info.commandBufferCount = 1;
13414 submit_info.pCommandBuffers = &m_commandBuffer->handle();
13415 // Submit cmd buffer and then destroy imageView while in-flight
13416 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
13417
13418 vkDestroyImageView(m_device->device(), view, nullptr);
13419 m_errorMonitor->VerifyFound();
13420 vkQueueWaitIdle(m_device->m_queue);
13421 // Now we can actually destroy imageView
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070013422 m_errorMonitor->SetUnexpectedError("If imageView is not VK_NULL_HANDLE, imageView must be a valid VkImageView handle");
Mark Lobodzinski74597792017-04-11 15:43:49 -060013423 m_errorMonitor->SetUnexpectedError("Unable to remove ImageView obj");
Tobin Ehlis7d965da2016-09-19 16:15:45 -060013424 vkDestroyImageView(m_device->device(), view, NULL);
13425 vkDestroySampler(m_device->device(), sampler, nullptr);
13426 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
13427 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
13428 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
13429}
13430
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060013431TEST_F(VkLayerTest, BufferViewInUseDestroyedSignaled) {
13432 TEST_DESCRIPTION("Delete in-use bufferView.");
13433
Tony Barbour1fa09702017-03-16 12:09:08 -060013434 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060013435 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13436
13437 VkDescriptorPoolSize ds_type_count;
13438 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
13439 ds_type_count.descriptorCount = 1;
13440
13441 VkDescriptorPoolCreateInfo ds_pool_ci = {};
13442 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
13443 ds_pool_ci.maxSets = 1;
13444 ds_pool_ci.poolSizeCount = 1;
13445 ds_pool_ci.pPoolSizes = &ds_type_count;
13446
13447 VkDescriptorPool ds_pool;
13448 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
13449 ASSERT_VK_SUCCESS(err);
13450
13451 VkDescriptorSetLayoutBinding layout_binding;
13452 layout_binding.binding = 0;
13453 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
13454 layout_binding.descriptorCount = 1;
13455 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
13456 layout_binding.pImmutableSamplers = NULL;
13457
13458 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
13459 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
13460 ds_layout_ci.bindingCount = 1;
13461 ds_layout_ci.pBindings = &layout_binding;
13462 VkDescriptorSetLayout ds_layout;
13463 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
13464 ASSERT_VK_SUCCESS(err);
13465
13466 VkDescriptorSetAllocateInfo alloc_info = {};
13467 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
13468 alloc_info.descriptorSetCount = 1;
13469 alloc_info.descriptorPool = ds_pool;
13470 alloc_info.pSetLayouts = &ds_layout;
13471 VkDescriptorSet descriptor_set;
13472 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
13473 ASSERT_VK_SUCCESS(err);
13474
13475 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
13476 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13477 pipeline_layout_ci.pNext = NULL;
13478 pipeline_layout_ci.setLayoutCount = 1;
13479 pipeline_layout_ci.pSetLayouts = &ds_layout;
13480
13481 VkPipelineLayout pipeline_layout;
13482 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
13483 ASSERT_VK_SUCCESS(err);
13484
13485 VkBuffer buffer;
13486 uint32_t queue_family_index = 0;
13487 VkBufferCreateInfo buffer_create_info = {};
13488 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
13489 buffer_create_info.size = 1024;
13490 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
13491 buffer_create_info.queueFamilyIndexCount = 1;
13492 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
13493
13494 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
13495 ASSERT_VK_SUCCESS(err);
13496
13497 VkMemoryRequirements memory_reqs;
13498 VkDeviceMemory buffer_memory;
13499
13500 VkMemoryAllocateInfo memory_info = {};
13501 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
13502 memory_info.allocationSize = 0;
13503 memory_info.memoryTypeIndex = 0;
13504
13505 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
13506 memory_info.allocationSize = memory_reqs.size;
13507 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
13508 ASSERT_TRUE(pass);
13509
13510 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
13511 ASSERT_VK_SUCCESS(err);
13512 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
13513 ASSERT_VK_SUCCESS(err);
13514
13515 VkBufferView view;
13516 VkBufferViewCreateInfo bvci = {};
13517 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
13518 bvci.buffer = buffer;
13519 bvci.format = VK_FORMAT_R8_UNORM;
13520 bvci.range = VK_WHOLE_SIZE;
13521
13522 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
13523 ASSERT_VK_SUCCESS(err);
13524
13525 VkWriteDescriptorSet descriptor_write = {};
13526 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
13527 descriptor_write.dstSet = descriptor_set;
13528 descriptor_write.dstBinding = 0;
13529 descriptor_write.descriptorCount = 1;
13530 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
13531 descriptor_write.pTexelBufferView = &view;
13532
13533 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
13534
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013535 char const *vsSource =
13536 "#version 450\n"
13537 "\n"
13538 "out gl_PerVertex { \n"
13539 " vec4 gl_Position;\n"
13540 "};\n"
13541 "void main(){\n"
13542 " gl_Position = vec4(1);\n"
13543 "}\n";
13544 char const *fsSource =
13545 "#version 450\n"
13546 "\n"
13547 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
13548 "layout(location=0) out vec4 x;\n"
13549 "void main(){\n"
13550 " x = imageLoad(s, 0);\n"
13551 "}\n";
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060013552 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13553 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13554 VkPipelineObj pipe(m_device);
13555 pipe.AddShader(&vs);
13556 pipe.AddShader(&fs);
13557 pipe.AddColorAttachment();
13558 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13559
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070013560 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00701);
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060013561
Tony Barbour552f6c02016-12-21 14:34:07 -070013562 m_commandBuffer->BeginCommandBuffer();
13563 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060013564 VkViewport viewport = {0, 0, 16, 16, 0, 1};
13565 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
13566 VkRect2D scissor = {{0, 0}, {16, 16}};
13567 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
13568 // Bind pipeline to cmd buffer
13569 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
13570 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
13571 &descriptor_set, 0, nullptr);
13572 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070013573 m_commandBuffer->EndRenderPass();
13574 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060013575
13576 VkSubmitInfo submit_info = {};
13577 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
13578 submit_info.commandBufferCount = 1;
13579 submit_info.pCommandBuffers = &m_commandBuffer->handle();
13580 // Submit cmd buffer and then destroy bufferView while in-flight
13581 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
13582
13583 vkDestroyBufferView(m_device->device(), view, nullptr);
13584 m_errorMonitor->VerifyFound();
13585 vkQueueWaitIdle(m_device->m_queue);
13586 // Now we can actually destroy bufferView
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070013587 m_errorMonitor->SetUnexpectedError("If bufferView is not VK_NULL_HANDLE, bufferView must be a valid VkBufferView handle");
Mark Lobodzinski74597792017-04-11 15:43:49 -060013588 m_errorMonitor->SetUnexpectedError("Unable to remove BufferView obj");
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060013589 vkDestroyBufferView(m_device->device(), view, NULL);
13590 vkDestroyBuffer(m_device->device(), buffer, NULL);
13591 vkFreeMemory(m_device->device(), buffer_memory, NULL);
13592 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
13593 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
13594 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
13595}
13596
Tobin Ehlis209532e2016-09-07 13:52:18 -060013597TEST_F(VkLayerTest, SamplerInUseDestroyedSignaled) {
13598 TEST_DESCRIPTION("Delete in-use sampler.");
13599
Tony Barbour1fa09702017-03-16 12:09:08 -060013600 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis209532e2016-09-07 13:52:18 -060013601 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13602
13603 VkDescriptorPoolSize ds_type_count;
13604 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
13605 ds_type_count.descriptorCount = 1;
13606
13607 VkDescriptorPoolCreateInfo ds_pool_ci = {};
13608 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
13609 ds_pool_ci.maxSets = 1;
13610 ds_pool_ci.poolSizeCount = 1;
13611 ds_pool_ci.pPoolSizes = &ds_type_count;
13612
13613 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013614 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis209532e2016-09-07 13:52:18 -060013615 ASSERT_VK_SUCCESS(err);
13616
13617 VkSamplerCreateInfo sampler_ci = {};
13618 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
13619 sampler_ci.pNext = NULL;
13620 sampler_ci.magFilter = VK_FILTER_NEAREST;
13621 sampler_ci.minFilter = VK_FILTER_NEAREST;
13622 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
13623 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
13624 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
13625 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
13626 sampler_ci.mipLodBias = 1.0;
13627 sampler_ci.anisotropyEnable = VK_FALSE;
13628 sampler_ci.maxAnisotropy = 1;
13629 sampler_ci.compareEnable = VK_FALSE;
13630 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
13631 sampler_ci.minLod = 1.0;
13632 sampler_ci.maxLod = 1.0;
13633 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
13634 sampler_ci.unnormalizedCoordinates = VK_FALSE;
13635 VkSampler sampler;
13636
13637 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
13638 ASSERT_VK_SUCCESS(err);
13639
13640 VkDescriptorSetLayoutBinding layout_binding;
13641 layout_binding.binding = 0;
Tobin Ehlis94fc0ad2016-09-19 16:23:01 -060013642 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
Tobin Ehlis209532e2016-09-07 13:52:18 -060013643 layout_binding.descriptorCount = 1;
13644 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
13645 layout_binding.pImmutableSamplers = NULL;
13646
13647 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
13648 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
13649 ds_layout_ci.bindingCount = 1;
13650 ds_layout_ci.pBindings = &layout_binding;
13651 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013652 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060013653 ASSERT_VK_SUCCESS(err);
13654
13655 VkDescriptorSetAllocateInfo alloc_info = {};
13656 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
13657 alloc_info.descriptorSetCount = 1;
13658 alloc_info.descriptorPool = ds_pool;
13659 alloc_info.pSetLayouts = &ds_layout;
13660 VkDescriptorSet descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013661 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis209532e2016-09-07 13:52:18 -060013662 ASSERT_VK_SUCCESS(err);
13663
13664 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
13665 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13666 pipeline_layout_ci.pNext = NULL;
13667 pipeline_layout_ci.setLayoutCount = 1;
13668 pipeline_layout_ci.pSetLayouts = &ds_layout;
13669
13670 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013671 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060013672 ASSERT_VK_SUCCESS(err);
13673
13674 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060013675 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 -060013676 ASSERT_TRUE(image.initialized());
13677
13678 VkImageView view;
13679 VkImageViewCreateInfo ivci = {};
13680 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
13681 ivci.image = image.handle();
13682 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
13683 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
13684 ivci.subresourceRange.layerCount = 1;
13685 ivci.subresourceRange.baseMipLevel = 0;
13686 ivci.subresourceRange.levelCount = 1;
13687 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
13688
13689 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
13690 ASSERT_VK_SUCCESS(err);
13691
13692 VkDescriptorImageInfo image_info{};
13693 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
13694 image_info.imageView = view;
13695 image_info.sampler = sampler;
13696
13697 VkWriteDescriptorSet descriptor_write = {};
13698 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
13699 descriptor_write.dstSet = descriptor_set;
13700 descriptor_write.dstBinding = 0;
13701 descriptor_write.descriptorCount = 1;
13702 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
13703 descriptor_write.pImageInfo = &image_info;
13704
13705 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
13706
13707 // Create PSO to use the sampler
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013708 char const *vsSource =
13709 "#version 450\n"
13710 "\n"
13711 "out gl_PerVertex { \n"
13712 " vec4 gl_Position;\n"
13713 "};\n"
13714 "void main(){\n"
13715 " gl_Position = vec4(1);\n"
13716 "}\n";
13717 char const *fsSource =
13718 "#version 450\n"
13719 "\n"
13720 "layout(set=0, binding=0) uniform sampler2D s;\n"
13721 "layout(location=0) out vec4 x;\n"
13722 "void main(){\n"
13723 " x = texture(s, vec2(1));\n"
13724 "}\n";
Tobin Ehlis209532e2016-09-07 13:52:18 -060013725 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13726 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13727 VkPipelineObj pipe(m_device);
13728 pipe.AddShader(&vs);
13729 pipe.AddShader(&fs);
13730 pipe.AddColorAttachment();
13731 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13732
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070013733 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00837);
Tobin Ehlis209532e2016-09-07 13:52:18 -060013734
Tony Barbour552f6c02016-12-21 14:34:07 -070013735 m_commandBuffer->BeginCommandBuffer();
13736 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis209532e2016-09-07 13:52:18 -060013737 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013738 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
13739 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
13740 &descriptor_set, 0, nullptr);
Rene Lindsay4da11732017-01-13 14:42:10 -070013741
13742 VkViewport viewport = {0, 0, 16, 16, 0, 1};
13743 VkRect2D scissor = {{0, 0}, {16, 16}};
13744 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
13745 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
13746
Tobin Ehlis209532e2016-09-07 13:52:18 -060013747 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070013748 m_commandBuffer->EndRenderPass();
13749 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis209532e2016-09-07 13:52:18 -060013750 // Submit cmd buffer then destroy sampler
13751 VkSubmitInfo submit_info = {};
13752 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
13753 submit_info.commandBufferCount = 1;
13754 submit_info.pCommandBuffers = &m_commandBuffer->handle();
13755 // Submit cmd buffer and then destroy sampler while in-flight
13756 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
13757
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013758 vkDestroySampler(m_device->device(), sampler, nullptr); // Destroyed too soon
Tobin Ehlis209532e2016-09-07 13:52:18 -060013759 m_errorMonitor->VerifyFound();
13760 vkQueueWaitIdle(m_device->m_queue);
Rene Lindsay4da11732017-01-13 14:42:10 -070013761
Tobin Ehlis209532e2016-09-07 13:52:18 -060013762 // Now we can actually destroy sampler
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070013763 m_errorMonitor->SetUnexpectedError("If sampler is not VK_NULL_HANDLE, sampler must be a valid VkSampler handle");
13764 m_errorMonitor->SetUnexpectedError("Unable to remove Sampler obj");
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013765 vkDestroySampler(m_device->device(), sampler, NULL); // Destroyed for real
Tobin Ehlis209532e2016-09-07 13:52:18 -060013766 vkDestroyImageView(m_device->device(), view, NULL);
13767 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
13768 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
13769 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
13770}
13771
Mark Mueller1cd9f412016-08-25 13:23:52 -060013772TEST_F(VkLayerTest, QueueForwardProgressFenceWait) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013773 TEST_DESCRIPTION(
13774 "Call VkQueueSubmit with a semaphore that is already "
13775 "signaled but not waited on by the queue. Wait on a "
13776 "fence that has not yet been submitted to a queue.");
Mark Mueller96a56d52016-08-24 10:28:05 -060013777
Tony Barbour1fa09702017-03-16 12:09:08 -060013778 ASSERT_NO_FATAL_FAILURE(Init());
Mark Mueller96a56d52016-08-24 10:28:05 -060013779 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13780
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013781 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 -070013782 const char *invalid_fence_wait_message =
13783 " which has not been submitted on a Queue or during "
13784 "acquire next image.";
Mark Mueller96a56d52016-08-24 10:28:05 -060013785
Tony Barbour552f6c02016-12-21 14:34:07 -070013786 m_commandBuffer->BeginCommandBuffer();
13787 m_commandBuffer->EndCommandBuffer();
Mark Mueller96a56d52016-08-24 10:28:05 -060013788
13789 VkSemaphoreCreateInfo semaphore_create_info = {};
13790 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
13791 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013792 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller96a56d52016-08-24 10:28:05 -060013793 VkSubmitInfo submit_info = {};
13794 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
13795 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013796 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller96a56d52016-08-24 10:28:05 -060013797 submit_info.signalSemaphoreCount = 1;
13798 submit_info.pSignalSemaphores = &semaphore;
13799 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Dave Houltonfbf52152017-01-06 12:55:29 -070013800 m_errorMonitor->ExpectSuccess(0);
Mark Mueller96a56d52016-08-24 10:28:05 -060013801 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
Dave Houltonfbf52152017-01-06 12:55:29 -070013802 m_errorMonitor->VerifyNotFound();
Tony Barbour552f6c02016-12-21 14:34:07 -070013803 m_commandBuffer->BeginCommandBuffer();
13804 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013805 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, queue_forward_progress_message);
Mark Mueller96a56d52016-08-24 10:28:05 -060013806 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
13807 m_errorMonitor->VerifyFound();
13808
Mark Mueller1cd9f412016-08-25 13:23:52 -060013809 VkFenceCreateInfo fence_create_info = {};
13810 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
13811 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013812 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller1cd9f412016-08-25 13:23:52 -060013813
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013814 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, invalid_fence_wait_message);
Mark Mueller1cd9f412016-08-25 13:23:52 -060013815 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
13816 m_errorMonitor->VerifyFound();
13817
Mark Mueller4042b652016-09-05 22:52:21 -060013818 vkDeviceWaitIdle(m_device->device());
Mark Mueller1cd9f412016-08-25 13:23:52 -060013819 vkDestroyFence(m_device->device(), fence, nullptr);
Mark Mueller96a56d52016-08-24 10:28:05 -060013820 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
13821}
13822
Tobin Ehlis4af23302016-07-19 10:50:30 -060013823TEST_F(VkLayerTest, FramebufferIncompatible) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013824 TEST_DESCRIPTION(
13825 "Bind a secondary command buffer with with a framebuffer "
13826 "that does not match the framebuffer for the active "
13827 "renderpass.");
Tony Barbour1fa09702017-03-16 12:09:08 -060013828 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis4af23302016-07-19 10:50:30 -060013829 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13830
13831 // A renderpass with one color attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013832 VkAttachmentDescription attachment = {0,
13833 VK_FORMAT_B8G8R8A8_UNORM,
13834 VK_SAMPLE_COUNT_1_BIT,
13835 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
13836 VK_ATTACHMENT_STORE_OP_STORE,
13837 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
13838 VK_ATTACHMENT_STORE_OP_DONT_CARE,
13839 VK_IMAGE_LAYOUT_UNDEFINED,
13840 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013841
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013842 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013843
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013844 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013845
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013846 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013847
13848 VkRenderPass rp;
13849 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
13850 ASSERT_VK_SUCCESS(err);
13851
13852 // A compatible framebuffer.
13853 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060013854 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 -060013855 ASSERT_TRUE(image.initialized());
13856
13857 VkImageViewCreateInfo ivci = {
13858 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
13859 nullptr,
13860 0,
13861 image.handle(),
13862 VK_IMAGE_VIEW_TYPE_2D,
13863 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013864 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
13865 VK_COMPONENT_SWIZZLE_IDENTITY},
Tobin Ehlis4af23302016-07-19 10:50:30 -060013866 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
13867 };
13868 VkImageView view;
13869 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
13870 ASSERT_VK_SUCCESS(err);
13871
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013872 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013873 VkFramebuffer fb;
13874 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
13875 ASSERT_VK_SUCCESS(err);
13876
13877 VkCommandBufferAllocateInfo cbai = {};
13878 cbai.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mike Schuchardt06304c22017-03-01 17:09:09 -070013879 cbai.commandPool = m_commandPool->handle();
Tobin Ehlis4af23302016-07-19 10:50:30 -060013880 cbai.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
13881 cbai.commandBufferCount = 1;
13882
13883 VkCommandBuffer sec_cb;
13884 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &sec_cb);
13885 ASSERT_VK_SUCCESS(err);
13886 VkCommandBufferBeginInfo cbbi = {};
13887 VkCommandBufferInheritanceInfo cbii = {};
Chris Forbes98420382016-11-28 17:56:51 +130013888 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Tobin Ehlis4af23302016-07-19 10:50:30 -060013889 cbii.renderPass = renderPass();
13890 cbii.framebuffer = fb;
13891 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
13892 cbbi.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013893 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 -060013894 cbbi.pInheritanceInfo = &cbii;
13895 vkBeginCommandBuffer(sec_cb, &cbbi);
13896 vkEndCommandBuffer(sec_cb);
13897
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013898 VkCommandBufferBeginInfo cbbi2 = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, 0, nullptr};
Chris Forbes3400bc52016-09-13 18:10:34 +120013899 vkBeginCommandBuffer(m_commandBuffer->GetBufferHandle(), &cbbi2);
13900 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Tobin Ehlis4af23302016-07-19 10:50:30 -060013901
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013902 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060013903 " that is not the same as the primary command buffer's current active framebuffer ");
Tobin Ehlis4af23302016-07-19 10:50:30 -060013904 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &sec_cb);
13905 m_errorMonitor->VerifyFound();
13906 // Cleanup
13907 vkDestroyImageView(m_device->device(), view, NULL);
13908 vkDestroyRenderPass(m_device->device(), rp, NULL);
13909 vkDestroyFramebuffer(m_device->device(), fb, NULL);
13910}
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013911
13912TEST_F(VkLayerTest, ColorBlendLogicOpTests) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013913 TEST_DESCRIPTION(
13914 "If logicOp is available on the device, set it to an "
13915 "invalid value. If logicOp is not available, attempt to "
13916 "use it and verify that we see the correct error.");
Tony Barbour1fa09702017-03-16 12:09:08 -060013917 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013918 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13919
13920 auto features = m_device->phy().features();
13921 // Set the expected error depending on whether or not logicOp available
13922 if (VK_FALSE == features.logicOp) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013923 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13924 "If logic operations feature not "
13925 "enabled, logicOpEnable must be "
13926 "VK_FALSE");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013927 } else {
Chris Forbes34797bc2016-10-03 15:28:49 +130013928 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "pColorBlendState->logicOp (16)");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013929 }
13930 // Create a pipeline using logicOp
13931 VkResult err;
13932
13933 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
13934 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13935
13936 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013937 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013938 ASSERT_VK_SUCCESS(err);
13939
13940 VkPipelineViewportStateCreateInfo vp_state_ci = {};
13941 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
13942 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013943 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013944 vp_state_ci.pViewports = &vp;
13945 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013946 VkRect2D scissors = {}; // Dummy scissors to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013947 vp_state_ci.pScissors = &scissors;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013948
13949 VkPipelineShaderStageCreateInfo shaderStages[2];
13950 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
13951
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013952 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
13953 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013954 shaderStages[0] = vs.GetStageCreateInfo();
13955 shaderStages[1] = fs.GetStageCreateInfo();
13956
13957 VkPipelineVertexInputStateCreateInfo vi_ci = {};
13958 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
13959
13960 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
13961 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
13962 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
13963
13964 VkPipelineRasterizationStateCreateInfo rs_ci = {};
13965 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbes14088512016-10-03 14:28:00 +130013966 rs_ci.lineWidth = 1.0f;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013967
13968 VkPipelineColorBlendAttachmentState att = {};
13969 att.blendEnable = VK_FALSE;
13970 att.colorWriteMask = 0xf;
13971
13972 VkPipelineColorBlendStateCreateInfo cb_ci = {};
13973 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
13974 // Enable logicOp & set logicOp to value 1 beyond allowed entries
13975 cb_ci.logicOpEnable = VK_TRUE;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013976 cb_ci.logicOp = VK_LOGIC_OP_RANGE_SIZE; // This should cause an error
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013977 cb_ci.attachmentCount = 1;
13978 cb_ci.pAttachments = &att;
13979
Chris Forbes8aeacbf2016-10-03 14:25:08 +130013980 VkPipelineMultisampleStateCreateInfo ms_ci = {};
13981 ms_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
13982 ms_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
13983
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013984 VkGraphicsPipelineCreateInfo gp_ci = {};
13985 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
13986 gp_ci.stageCount = 2;
13987 gp_ci.pStages = shaderStages;
13988 gp_ci.pVertexInputState = &vi_ci;
13989 gp_ci.pInputAssemblyState = &ia_ci;
13990 gp_ci.pViewportState = &vp_state_ci;
13991 gp_ci.pRasterizationState = &rs_ci;
13992 gp_ci.pColorBlendState = &cb_ci;
Chris Forbes8aeacbf2016-10-03 14:25:08 +130013993 gp_ci.pMultisampleState = &ms_ci;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013994 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
13995 gp_ci.layout = pipeline_layout;
13996 gp_ci.renderPass = renderPass();
13997
13998 VkPipelineCacheCreateInfo pc_ci = {};
13999 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
14000
14001 VkPipeline pipeline;
14002 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014003 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060014004 ASSERT_VK_SUCCESS(err);
14005
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014006 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060014007 m_errorMonitor->VerifyFound();
14008 if (VK_SUCCESS == err) {
14009 vkDestroyPipeline(m_device->device(), pipeline, NULL);
14010 }
Tobin Ehlis52b504f2016-07-19 13:25:12 -060014011 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
14012 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
14013}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060014014
Mike Stroyanaccf7692015-05-12 16:00:45 -060014015#if GTEST_IS_THREADSAFE
14016struct thread_data_struct {
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014017 VkCommandBuffer commandBuffer;
Mike Stroyanca855662017-05-02 11:06:27 -060014018 VkDevice device;
Mike Stroyanaccf7692015-05-12 16:00:45 -060014019 VkEvent event;
14020 bool bailout;
14021};
14022
Karl Schultz6addd812016-02-02 17:17:23 -070014023extern "C" void *AddToCommandBuffer(void *arg) {
14024 struct thread_data_struct *data = (struct thread_data_struct *)arg;
Mike Stroyanaccf7692015-05-12 16:00:45 -060014025
Mike Stroyana6d14942016-07-13 15:10:05 -060014026 for (int i = 0; i < 80000; i++) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014027 vkCmdSetEvent(data->commandBuffer, data->event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mike Stroyanaccf7692015-05-12 16:00:45 -060014028 if (data->bailout) {
14029 break;
14030 }
14031 }
14032 return NULL;
14033}
14034
Karl Schultz6addd812016-02-02 17:17:23 -070014035TEST_F(VkLayerTest, ThreadCommandBufferCollision) {
Mike Stroyan4268d1f2015-07-13 14:45:35 -060014036 test_platform_thread thread;
Mike Stroyanaccf7692015-05-12 16:00:45 -060014037
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014038 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "THREADING ERROR");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014039
Tony Barbour1fa09702017-03-16 12:09:08 -060014040 ASSERT_NO_FATAL_FAILURE(Init());
Mike Stroyanaccf7692015-05-12 16:00:45 -060014041 ASSERT_NO_FATAL_FAILURE(InitViewport());
14042 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14043
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014044 // Calls AllocateCommandBuffers
14045 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060014046
14047 // Avoid creating RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014048 commandBuffer.BeginCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060014049
14050 VkEventCreateInfo event_info;
14051 VkEvent event;
Mike Stroyanaccf7692015-05-12 16:00:45 -060014052 VkResult err;
14053
14054 memset(&event_info, 0, sizeof(event_info));
14055 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
14056
Chia-I Wuf7458c52015-10-26 21:10:41 +080014057 err = vkCreateEvent(device(), &event_info, NULL, &event);
Mike Stroyanaccf7692015-05-12 16:00:45 -060014058 ASSERT_VK_SUCCESS(err);
14059
Mike Stroyanaccf7692015-05-12 16:00:45 -060014060 err = vkResetEvent(device(), event);
14061 ASSERT_VK_SUCCESS(err);
14062
14063 struct thread_data_struct data;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014064 data.commandBuffer = commandBuffer.GetBufferHandle();
Mike Stroyanaccf7692015-05-12 16:00:45 -060014065 data.event = event;
14066 data.bailout = false;
14067 m_errorMonitor->SetBailout(&data.bailout);
Mike Stroyana6d14942016-07-13 15:10:05 -060014068
14069 // First do some correct operations using multiple threads.
14070 // Add many entries to command buffer from another thread.
14071 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
14072 // Make non-conflicting calls from this thread at the same time.
14073 for (int i = 0; i < 80000; i++) {
Mike Stroyand6343902016-07-14 08:56:16 -060014074 uint32_t count;
14075 vkEnumeratePhysicalDevices(instance(), &count, NULL);
Mike Stroyana6d14942016-07-13 15:10:05 -060014076 }
14077 test_platform_thread_join(thread, NULL);
14078
14079 // Then do some incorrect operations using multiple threads.
Mike Stroyanaccf7692015-05-12 16:00:45 -060014080 // Add many entries to command buffer from another thread.
Mike Stroyan4268d1f2015-07-13 14:45:35 -060014081 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyanaccf7692015-05-12 16:00:45 -060014082 // Add many entries to command buffer from this thread at the same time.
14083 AddToCommandBuffer(&data);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060014084
Mike Stroyan4268d1f2015-07-13 14:45:35 -060014085 test_platform_thread_join(thread, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014086 commandBuffer.EndCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060014087
Mike Stroyan10b8cb72016-01-22 15:22:03 -070014088 m_errorMonitor->SetBailout(NULL);
14089
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014090 m_errorMonitor->VerifyFound();
Mike Stroyanaccf7692015-05-12 16:00:45 -060014091
Chia-I Wuf7458c52015-10-26 21:10:41 +080014092 vkDestroyEvent(device(), event, NULL);
Mike Stroyanaccf7692015-05-12 16:00:45 -060014093}
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014094#endif // GTEST_IS_THREADSAFE
Mark Lobodzinski209b5292015-09-17 09:44:05 -060014095
Karl Schultz6addd812016-02-02 17:17:23 -070014096TEST_F(VkLayerTest, InvalidSPIRVCodeSize) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014097 TEST_DESCRIPTION(
14098 "Test that an error is produced for a spirv module "
14099 "with an impossible code size");
Chris Forbes1cc79542016-07-20 11:13:44 +120014100
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014101 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014102
Tony Barbour1fa09702017-03-16 12:09:08 -060014103 ASSERT_NO_FATAL_FAILURE(Init());
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014104 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14105
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014106 VkShaderModule module;
14107 VkShaderModuleCreateInfo moduleCreateInfo;
14108 struct icd_spv_header spv;
14109
14110 spv.magic = ICD_SPV_MAGIC;
14111 spv.version = ICD_SPV_VERSION;
14112 spv.gen_magic = 0;
14113
14114 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
14115 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070014116 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014117 moduleCreateInfo.codeSize = 4;
14118 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080014119 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014120
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014121 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014122}
14123
Karl Schultz6addd812016-02-02 17:17:23 -070014124TEST_F(VkLayerTest, InvalidSPIRVMagic) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014125 TEST_DESCRIPTION(
14126 "Test that an error is produced for a spirv module "
14127 "with a bad magic number");
Chris Forbes1cc79542016-07-20 11:13:44 +120014128
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014129 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V magic number");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014130
Tony Barbour1fa09702017-03-16 12:09:08 -060014131 ASSERT_NO_FATAL_FAILURE(Init());
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014132 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14133
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014134 VkShaderModule module;
14135 VkShaderModuleCreateInfo moduleCreateInfo;
14136 struct icd_spv_header spv;
14137
14138 spv.magic = ~ICD_SPV_MAGIC;
14139 spv.version = ICD_SPV_VERSION;
14140 spv.gen_magic = 0;
14141
14142 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
14143 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070014144 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014145 moduleCreateInfo.codeSize = sizeof(spv) + 10;
14146 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080014147 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014148
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014149 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014150}
14151
Chris Forbesb4afd0f2016-04-04 10:48:35 +120014152#if 0
14153// Not currently covered by SPIRV-Tools validator
Karl Schultz6addd812016-02-02 17:17:23 -070014154TEST_F(VkLayerTest, InvalidSPIRVVersion) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070014155 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +120014156 "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014157
Tony Barbour1fa09702017-03-16 12:09:08 -060014158 ASSERT_NO_FATAL_FAILURE(Init());
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014159 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14160
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014161 VkShaderModule module;
14162 VkShaderModuleCreateInfo moduleCreateInfo;
14163 struct icd_spv_header spv;
14164
14165 spv.magic = ICD_SPV_MAGIC;
14166 spv.version = ~ICD_SPV_VERSION;
14167 spv.gen_magic = 0;
14168
14169 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
14170 moduleCreateInfo.pNext = NULL;
14171
Karl Schultz6addd812016-02-02 17:17:23 -070014172 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014173 moduleCreateInfo.codeSize = sizeof(spv) + 10;
14174 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080014175 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014176
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014177 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014178}
Chris Forbesb4afd0f2016-04-04 10:48:35 +120014179#endif
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014180
Karl Schultz6addd812016-02-02 17:17:23 -070014181TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014182 TEST_DESCRIPTION(
14183 "Test that a warning is produced for a vertex output that "
14184 "is not consumed by the fragment stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014185 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "not consumed by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014186
Tony Barbour1fa09702017-03-16 12:09:08 -060014187 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014188 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes9f7ff632015-05-25 11:13:08 +120014189
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014190 char const *vsSource =
14191 "#version 450\n"
14192 "\n"
14193 "layout(location=0) out float x;\n"
14194 "out gl_PerVertex {\n"
14195 " vec4 gl_Position;\n"
14196 "};\n"
14197 "void main(){\n"
14198 " gl_Position = vec4(1);\n"
14199 " x = 0;\n"
14200 "}\n";
14201 char const *fsSource =
14202 "#version 450\n"
14203 "\n"
14204 "layout(location=0) out vec4 color;\n"
14205 "void main(){\n"
14206 " color = vec4(1);\n"
14207 "}\n";
Chris Forbes9f7ff632015-05-25 11:13:08 +120014208
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014209 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14210 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes9f7ff632015-05-25 11:13:08 +120014211
14212 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014213 pipe.AddColorAttachment();
Chris Forbes9f7ff632015-05-25 11:13:08 +120014214 pipe.AddShader(&vs);
14215 pipe.AddShader(&fs);
14216
Chris Forbes9f7ff632015-05-25 11:13:08 +120014217 VkDescriptorSetObj descriptorSet(m_device);
14218 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014219 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes9f7ff632015-05-25 11:13:08 +120014220
Tony Barbour5781e8f2015-08-04 16:23:11 -060014221 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes9f7ff632015-05-25 11:13:08 +120014222
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014223 m_errorMonitor->VerifyFound();
Chris Forbes9f7ff632015-05-25 11:13:08 +120014224}
Chris Forbes9f7ff632015-05-25 11:13:08 +120014225
Mark Mueller098c9cb2016-09-08 09:01:57 -060014226TEST_F(VkLayerTest, CreatePipelineCheckShaderBadSpecialization) {
14227 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
14228
Tony Barbour1fa09702017-03-16 12:09:08 -060014229 ASSERT_NO_FATAL_FAILURE(Init());
Mark Mueller098c9cb2016-09-08 09:01:57 -060014230 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14231
14232 const char *bad_specialization_message =
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014233 "Specialization entry 0 (for constant id 0) references memory outside provided specialization data ";
Mark Mueller098c9cb2016-09-08 09:01:57 -060014234
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014235 char const *vsSource =
14236 "#version 450\n"
14237 "\n"
14238 "out gl_PerVertex {\n"
14239 " vec4 gl_Position;\n"
14240 "};\n"
14241 "void main(){\n"
14242 " gl_Position = vec4(1);\n"
14243 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060014244
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014245 char const *fsSource =
14246 "#version 450\n"
14247 "\n"
14248 "layout (constant_id = 0) const float r = 0.0f;\n"
14249 "layout(location = 0) out vec4 uFragColor;\n"
14250 "void main(){\n"
14251 " uFragColor = vec4(r,1,0,1);\n"
14252 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060014253
14254 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14255 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14256
14257 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
14258 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
14259
14260 VkPipelineLayout pipeline_layout;
14261 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
14262
14263 VkPipelineViewportStateCreateInfo vp_state_create_info = {};
14264 vp_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
14265 vp_state_create_info.viewportCount = 1;
14266 VkViewport viewport = {};
14267 vp_state_create_info.pViewports = &viewport;
14268 vp_state_create_info.scissorCount = 1;
14269 VkRect2D scissors = {};
14270 vp_state_create_info.pScissors = &scissors;
14271
14272 VkDynamicState scissor_state = VK_DYNAMIC_STATE_SCISSOR;
14273
14274 VkPipelineDynamicStateCreateInfo pipeline_dynamic_state_create_info = {};
14275 pipeline_dynamic_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
14276 pipeline_dynamic_state_create_info.dynamicStateCount = 1;
14277 pipeline_dynamic_state_create_info.pDynamicStates = &scissor_state;
14278
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014279 VkPipelineShaderStageCreateInfo shader_stage_create_info[2] = {vs.GetStageCreateInfo(), fs.GetStageCreateInfo()};
Mark Mueller098c9cb2016-09-08 09:01:57 -060014280
14281 VkPipelineVertexInputStateCreateInfo vertex_input_create_info = {};
14282 vertex_input_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
14283
14284 VkPipelineInputAssemblyStateCreateInfo input_assembly_create_info = {};
14285 input_assembly_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
14286 input_assembly_create_info.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
14287
14288 VkPipelineRasterizationStateCreateInfo rasterization_state_create_info = {};
14289 rasterization_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
14290 rasterization_state_create_info.pNext = nullptr;
14291 rasterization_state_create_info.lineWidth = 1.0f;
14292 rasterization_state_create_info.rasterizerDiscardEnable = true;
14293
14294 VkPipelineColorBlendAttachmentState color_blend_attachment_state = {};
14295 color_blend_attachment_state.blendEnable = VK_FALSE;
14296 color_blend_attachment_state.colorWriteMask = 0xf;
14297
14298 VkPipelineColorBlendStateCreateInfo color_blend_state_create_info = {};
14299 color_blend_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
14300 color_blend_state_create_info.attachmentCount = 1;
14301 color_blend_state_create_info.pAttachments = &color_blend_attachment_state;
14302
14303 VkGraphicsPipelineCreateInfo graphicspipe_create_info = {};
14304 graphicspipe_create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
14305 graphicspipe_create_info.stageCount = 2;
14306 graphicspipe_create_info.pStages = shader_stage_create_info;
14307 graphicspipe_create_info.pVertexInputState = &vertex_input_create_info;
14308 graphicspipe_create_info.pInputAssemblyState = &input_assembly_create_info;
14309 graphicspipe_create_info.pViewportState = &vp_state_create_info;
14310 graphicspipe_create_info.pRasterizationState = &rasterization_state_create_info;
14311 graphicspipe_create_info.pColorBlendState = &color_blend_state_create_info;
14312 graphicspipe_create_info.pDynamicState = &pipeline_dynamic_state_create_info;
14313 graphicspipe_create_info.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
14314 graphicspipe_create_info.layout = pipeline_layout;
14315 graphicspipe_create_info.renderPass = renderPass();
14316
14317 VkPipelineCacheCreateInfo pipeline_cache_create_info = {};
14318 pipeline_cache_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
14319
14320 VkPipelineCache pipelineCache;
14321 ASSERT_VK_SUCCESS(vkCreatePipelineCache(m_device->device(), &pipeline_cache_create_info, nullptr, &pipelineCache));
14322
14323 // This structure maps constant ids to data locations.
14324 const VkSpecializationMapEntry entry =
14325 // id, offset, size
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014326 {0, 4, sizeof(uint32_t)}; // Challenge core validation by using a bogus offset.
Mark Mueller098c9cb2016-09-08 09:01:57 -060014327
14328 uint32_t data = 1;
14329
14330 // Set up the info describing spec map and data
14331 const VkSpecializationInfo specialization_info = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014332 1, &entry, 1 * sizeof(float), &data,
Mark Mueller098c9cb2016-09-08 09:01:57 -060014333 };
14334 shader_stage_create_info[0].pSpecializationInfo = &specialization_info;
14335
14336 VkPipeline pipeline;
14337 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_specialization_message);
14338 vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &graphicspipe_create_info, nullptr, &pipeline);
14339 m_errorMonitor->VerifyFound();
14340
14341 vkDestroyPipelineCache(m_device->device(), pipelineCache, nullptr);
14342 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
14343}
14344
14345TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorTypeMismatch) {
14346 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
14347
Tony Barbour1fa09702017-03-16 12:09:08 -060014348 ASSERT_NO_FATAL_FAILURE(Init());
Mark Mueller098c9cb2016-09-08 09:01:57 -060014349 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14350
14351 const char *descriptor_type_mismatch_message = "Type mismatch on descriptor slot 0.0 (used as type ";
14352
14353 VkDescriptorPoolSize descriptor_pool_type_count[2] = {};
14354 descriptor_pool_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
14355 descriptor_pool_type_count[0].descriptorCount = 1;
14356 descriptor_pool_type_count[1].type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
14357 descriptor_pool_type_count[1].descriptorCount = 1;
14358
14359 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
14360 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
14361 descriptor_pool_create_info.maxSets = 1;
14362 descriptor_pool_create_info.poolSizeCount = 2;
14363 descriptor_pool_create_info.pPoolSizes = descriptor_pool_type_count;
14364 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
14365
14366 VkDescriptorPool descriptorset_pool;
14367 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
14368
14369 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
14370 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
14371 descriptorset_layout_binding.descriptorCount = 1;
14372 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
Cody Northropa6484fd2017-03-10 14:13:49 -070014373 descriptorset_layout_binding.pImmutableSamplers = nullptr;
Mark Mueller098c9cb2016-09-08 09:01:57 -060014374
14375 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
14376 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
14377 descriptorset_layout_create_info.bindingCount = 1;
14378 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
14379
14380 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014381 ASSERT_VK_SUCCESS(
14382 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller098c9cb2016-09-08 09:01:57 -060014383
14384 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
14385 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
14386 descriptorset_allocate_info.descriptorSetCount = 1;
14387 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
14388 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
14389 VkDescriptorSet descriptorset;
14390 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
14391
14392 // Challenge core_validation with a non uniform buffer type.
14393 VkBufferTest storage_buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT);
14394
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014395 char const *vsSource =
14396 "#version 450\n"
14397 "\n"
14398 "layout (std140, set = 0, binding = 0) uniform buf {\n"
14399 " mat4 mvp;\n"
14400 "} ubuf;\n"
14401 "out gl_PerVertex {\n"
14402 " vec4 gl_Position;\n"
14403 "};\n"
14404 "void main(){\n"
14405 " gl_Position = ubuf.mvp * vec4(1);\n"
14406 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060014407
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014408 char const *fsSource =
14409 "#version 450\n"
14410 "\n"
14411 "layout(location = 0) out vec4 uFragColor;\n"
14412 "void main(){\n"
14413 " uFragColor = vec4(0,1,0,1);\n"
14414 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060014415
14416 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14417 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14418
14419 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
14420 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
14421 pipeline_layout_create_info.setLayoutCount = 1;
14422 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
14423
14424 VkPipelineLayout pipeline_layout;
14425 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
14426
14427 VkPipelineObj pipe(m_device);
14428 pipe.AddColorAttachment();
14429 pipe.AddShader(&vs);
14430 pipe.AddShader(&fs);
14431
14432 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_type_mismatch_message);
14433 pipe.CreateVKPipeline(pipeline_layout, renderPass());
14434 m_errorMonitor->VerifyFound();
14435
14436 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
14437 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
14438 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
14439}
14440
14441TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorNotAccessible) {
14442 TEST_DESCRIPTION(
14443 "Create a pipeline in which a descriptor used by a shader stage does not include that stage in its stageFlags.");
14444
Tony Barbour1fa09702017-03-16 12:09:08 -060014445 ASSERT_NO_FATAL_FAILURE(Init());
Mark Mueller098c9cb2016-09-08 09:01:57 -060014446 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14447
14448 const char *descriptor_not_accessible_message = "Shader uses descriptor slot 0.0 (used as type ";
14449
14450 VkDescriptorPoolSize descriptor_pool_type_count = {};
14451 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
14452 descriptor_pool_type_count.descriptorCount = 1;
14453
14454 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
14455 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
14456 descriptor_pool_create_info.maxSets = 1;
14457 descriptor_pool_create_info.poolSizeCount = 1;
14458 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
14459 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
14460
14461 VkDescriptorPool descriptorset_pool;
14462 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
14463
14464 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
14465 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
14466 descriptorset_layout_binding.descriptorCount = 1;
14467 // Intentionally make the uniform buffer inaccessible to the vertex shader to challenge core_validation
14468 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
Cody Northropa6484fd2017-03-10 14:13:49 -070014469 descriptorset_layout_binding.pImmutableSamplers = nullptr;
Mark Mueller098c9cb2016-09-08 09:01:57 -060014470
14471 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
14472 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
14473 descriptorset_layout_create_info.bindingCount = 1;
14474 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
14475
14476 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014477 ASSERT_VK_SUCCESS(
14478 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller098c9cb2016-09-08 09:01:57 -060014479
14480 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
14481 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
14482 descriptorset_allocate_info.descriptorSetCount = 1;
14483 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
14484 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
14485 VkDescriptorSet descriptorset;
14486 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
14487
14488 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
14489
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014490 char const *vsSource =
14491 "#version 450\n"
14492 "\n"
14493 "layout (std140, set = 0, binding = 0) uniform buf {\n"
14494 " mat4 mvp;\n"
14495 "} ubuf;\n"
14496 "out gl_PerVertex {\n"
14497 " vec4 gl_Position;\n"
14498 "};\n"
14499 "void main(){\n"
14500 " gl_Position = ubuf.mvp * vec4(1);\n"
14501 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060014502
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014503 char const *fsSource =
14504 "#version 450\n"
14505 "\n"
14506 "layout(location = 0) out vec4 uFragColor;\n"
14507 "void main(){\n"
14508 " uFragColor = vec4(0,1,0,1);\n"
14509 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060014510
14511 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14512 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14513
14514 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
14515 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
14516 pipeline_layout_create_info.setLayoutCount = 1;
14517 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
14518
14519 VkPipelineLayout pipeline_layout;
14520 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
14521
14522 VkPipelineObj pipe(m_device);
14523 pipe.AddColorAttachment();
14524 pipe.AddShader(&vs);
14525 pipe.AddShader(&fs);
14526
14527 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_not_accessible_message);
14528 pipe.CreateVKPipeline(pipeline_layout, renderPass());
14529 m_errorMonitor->VerifyFound();
14530
14531 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
14532 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
14533 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
14534}
14535
14536TEST_F(VkLayerTest, CreatePipelineCheckShaderPushConstantNotAccessible) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014537 TEST_DESCRIPTION(
14538 "Create a graphics pipleine in which a push constant range containing a push constant block member is not "
14539 "accessible from the current shader stage.");
Mark Mueller098c9cb2016-09-08 09:01:57 -060014540
Tony Barbour1fa09702017-03-16 12:09:08 -060014541 ASSERT_NO_FATAL_FAILURE(Init());
Mark Mueller098c9cb2016-09-08 09:01:57 -060014542 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14543
14544 const char *push_constant_not_accessible_message =
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014545 "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 -060014546
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014547 char const *vsSource =
14548 "#version 450\n"
14549 "\n"
14550 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
14551 "out gl_PerVertex {\n"
14552 " vec4 gl_Position;\n"
14553 "};\n"
14554 "void main(){\n"
14555 " gl_Position = vec4(consts.x);\n"
14556 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060014557
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014558 char const *fsSource =
14559 "#version 450\n"
14560 "\n"
14561 "layout(location = 0) out vec4 uFragColor;\n"
14562 "void main(){\n"
14563 " uFragColor = vec4(0,1,0,1);\n"
14564 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060014565
14566 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14567 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14568
14569 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
14570 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
14571
14572 // Set up a push constant range
14573 VkPushConstantRange push_constant_ranges = {};
14574 // Set to the wrong stage to challenge core_validation
14575 push_constant_ranges.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
14576 push_constant_ranges.size = 4;
14577
14578 pipeline_layout_create_info.pPushConstantRanges = &push_constant_ranges;
14579 pipeline_layout_create_info.pushConstantRangeCount = 1;
14580
14581 VkPipelineLayout pipeline_layout;
14582 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
14583
14584 VkPipelineObj pipe(m_device);
14585 pipe.AddColorAttachment();
14586 pipe.AddShader(&vs);
14587 pipe.AddShader(&fs);
14588
14589 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, push_constant_not_accessible_message);
14590 pipe.CreateVKPipeline(pipeline_layout, renderPass());
14591 m_errorMonitor->VerifyFound();
14592
14593 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
14594}
14595
14596TEST_F(VkLayerTest, CreatePipelineCheckShaderNotEnabled) {
14597 TEST_DESCRIPTION(
14598 "Create a graphics pipeline in which a capability declared by the shader requires a feature not enabled on the device.");
14599
Tony Barbour1fa09702017-03-16 12:09:08 -060014600 ASSERT_NO_FATAL_FAILURE(Init());
Mark Mueller098c9cb2016-09-08 09:01:57 -060014601 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14602
14603 const char *feature_not_enabled_message =
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014604 "Shader requires VkPhysicalDeviceFeatures::shaderFloat64 but is not enabled on the device";
Mark Mueller098c9cb2016-09-08 09:01:57 -060014605
14606 // Some awkward steps are required to test with custom device features.
14607 std::vector<const char *> device_extension_names;
14608 auto features = m_device->phy().features();
14609 // Disable support for 64 bit floats
14610 features.shaderFloat64 = false;
14611 // The sacrificial device object
14612 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
14613
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014614 char const *vsSource =
14615 "#version 450\n"
14616 "\n"
14617 "out gl_PerVertex {\n"
14618 " vec4 gl_Position;\n"
14619 "};\n"
14620 "void main(){\n"
14621 " gl_Position = vec4(1);\n"
14622 "}\n";
14623 char const *fsSource =
14624 "#version 450\n"
14625 "\n"
14626 "layout(location=0) out vec4 color;\n"
14627 "void main(){\n"
14628 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
14629 " color = vec4(green);\n"
14630 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060014631
14632 VkShaderObj vs(&test_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14633 VkShaderObj fs(&test_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14634
14635 VkRenderpassObj render_pass(&test_device);
Mark Mueller098c9cb2016-09-08 09:01:57 -060014636
14637 VkPipelineObj pipe(&test_device);
14638 pipe.AddColorAttachment();
14639 pipe.AddShader(&vs);
14640 pipe.AddShader(&fs);
14641
14642 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
14643 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
14644 VkPipelineLayout pipeline_layout;
14645 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(test_device.device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
14646
14647 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, feature_not_enabled_message);
14648 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
14649 m_errorMonitor->VerifyFound();
14650
14651 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, nullptr);
14652}
14653
Mark Lobodzinski20832822017-03-24 14:49:45 -060014654TEST_F(VkLayerTest, CreateShaderModuleCheckBadCapability) {
14655 TEST_DESCRIPTION("Create a shader in which a capability declared by the shader is not supported.");
14656 // Note that this failure message comes from spirv-tools, specifically the validator.
Mark Mueller098c9cb2016-09-08 09:01:57 -060014657
Tony Barbour1fa09702017-03-16 12:09:08 -060014658 ASSERT_NO_FATAL_FAILURE(Init());
Mark Mueller098c9cb2016-09-08 09:01:57 -060014659 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14660
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014661 char const *vsSource =
14662 "#version 450\n"
14663 "\n"
14664 "out gl_PerVertex {\n"
14665 " vec4 gl_Position;\n"
14666 "};\n"
14667 "layout(xfb_buffer = 1) out;"
14668 "void main(){\n"
14669 " gl_Position = vec4(1);\n"
14670 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060014671
Mark Lobodzinski20832822017-03-24 14:49:45 -060014672 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Capability value 53 is not allowed by Vulkan");
Mark Mueller098c9cb2016-09-08 09:01:57 -060014673
Mark Lobodzinski20832822017-03-24 14:49:45 -060014674 std::vector<unsigned int> spv;
14675 VkShaderModuleCreateInfo module_create_info;
14676 VkShaderModule shader_module;
14677 module_create_info.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
14678 module_create_info.pNext = NULL;
14679 this->GLSLtoSPV(VK_SHADER_STAGE_VERTEX_BIT, vsSource, spv);
14680 module_create_info.pCode = spv.data();
14681 module_create_info.codeSize = spv.size() * sizeof(unsigned int);
14682 module_create_info.flags = 0;
Mark Mueller098c9cb2016-09-08 09:01:57 -060014683
Mark Lobodzinski20832822017-03-24 14:49:45 -060014684 vkCreateShaderModule(m_device->handle(), &module_create_info, NULL, &shader_module);
Mark Mueller098c9cb2016-09-08 09:01:57 -060014685
Mark Lobodzinski20832822017-03-24 14:49:45 -060014686 m_errorMonitor->VerifyFound();
Mark Mueller098c9cb2016-09-08 09:01:57 -060014687}
14688
Karl Schultz6addd812016-02-02 17:17:23 -070014689TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014690 TEST_DESCRIPTION(
14691 "Test that an error is produced for a fragment shader input "
14692 "which is not present in the outputs of the previous stage");
Chris Forbes1cc79542016-07-20 11:13:44 +120014693
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014694 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014695
Tony Barbour1fa09702017-03-16 12:09:08 -060014696 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014697 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes59cb88d2015-05-25 11:13:13 +120014698
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014699 char const *vsSource =
14700 "#version 450\n"
14701 "\n"
14702 "out gl_PerVertex {\n"
14703 " vec4 gl_Position;\n"
14704 "};\n"
14705 "void main(){\n"
14706 " gl_Position = vec4(1);\n"
14707 "}\n";
14708 char const *fsSource =
14709 "#version 450\n"
14710 "\n"
14711 "layout(location=0) in float x;\n"
14712 "layout(location=0) out vec4 color;\n"
14713 "void main(){\n"
14714 " color = vec4(x);\n"
14715 "}\n";
Chris Forbes59cb88d2015-05-25 11:13:13 +120014716
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014717 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14718 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes59cb88d2015-05-25 11:13:13 +120014719
14720 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014721 pipe.AddColorAttachment();
Chris Forbes59cb88d2015-05-25 11:13:13 +120014722 pipe.AddShader(&vs);
14723 pipe.AddShader(&fs);
14724
Chris Forbes59cb88d2015-05-25 11:13:13 +120014725 VkDescriptorSetObj descriptorSet(m_device);
14726 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014727 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes59cb88d2015-05-25 11:13:13 +120014728
Tony Barbour5781e8f2015-08-04 16:23:11 -060014729 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes59cb88d2015-05-25 11:13:13 +120014730
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014731 m_errorMonitor->VerifyFound();
Chris Forbes59cb88d2015-05-25 11:13:13 +120014732}
14733
Karl Schultz6addd812016-02-02 17:17:23 -070014734TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvidedInBlock) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014735 TEST_DESCRIPTION(
14736 "Test that an error is produced for a fragment shader input "
14737 "within an interace block, which is not present in the outputs "
14738 "of the previous stage.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014739 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Chris Forbesa3e85f62016-01-15 14:53:11 +130014740
Tony Barbour1fa09702017-03-16 12:09:08 -060014741 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbesa3e85f62016-01-15 14:53:11 +130014742 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14743
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014744 char const *vsSource =
14745 "#version 450\n"
14746 "\n"
14747 "out gl_PerVertex {\n"
14748 " vec4 gl_Position;\n"
14749 "};\n"
14750 "void main(){\n"
14751 " gl_Position = vec4(1);\n"
14752 "}\n";
14753 char const *fsSource =
14754 "#version 450\n"
14755 "\n"
14756 "in block { layout(location=0) float x; } ins;\n"
14757 "layout(location=0) out vec4 color;\n"
14758 "void main(){\n"
14759 " color = vec4(ins.x);\n"
14760 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130014761
14762 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14763 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14764
14765 VkPipelineObj pipe(m_device);
14766 pipe.AddColorAttachment();
14767 pipe.AddShader(&vs);
14768 pipe.AddShader(&fs);
14769
14770 VkDescriptorSetObj descriptorSet(m_device);
14771 descriptorSet.AppendDummy();
14772 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14773
14774 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14775
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014776 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130014777}
14778
Karl Schultz6addd812016-02-02 17:17:23 -070014779TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchArraySize) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014780 TEST_DESCRIPTION(
14781 "Test that an error is produced for mismatched array sizes "
14782 "across the vertex->fragment shader interface");
14783 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14784 "Type mismatch on location 0.0: 'ptr to "
14785 "output arr[2] of float32' vs 'ptr to "
14786 "input arr[1] of float32'");
Chris Forbes0036fd12016-01-26 14:19:49 +130014787
Tony Barbour1fa09702017-03-16 12:09:08 -060014788 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes0036fd12016-01-26 14:19:49 +130014789 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14790
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014791 char const *vsSource =
14792 "#version 450\n"
14793 "\n"
14794 "layout(location=0) out float x[2];\n"
14795 "out gl_PerVertex {\n"
14796 " vec4 gl_Position;\n"
14797 "};\n"
14798 "void main(){\n"
14799 " x[0] = 0; x[1] = 0;\n"
14800 " gl_Position = vec4(1);\n"
14801 "}\n";
14802 char const *fsSource =
14803 "#version 450\n"
14804 "\n"
14805 "layout(location=0) in float x[1];\n"
14806 "layout(location=0) out vec4 color;\n"
14807 "void main(){\n"
14808 " color = vec4(x[0]);\n"
14809 "}\n";
Chris Forbes0036fd12016-01-26 14:19:49 +130014810
14811 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14812 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14813
14814 VkPipelineObj pipe(m_device);
14815 pipe.AddColorAttachment();
14816 pipe.AddShader(&vs);
14817 pipe.AddShader(&fs);
14818
14819 VkDescriptorSetObj descriptorSet(m_device);
14820 descriptorSet.AppendDummy();
14821 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14822
14823 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14824
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014825 m_errorMonitor->VerifyFound();
Chris Forbes0036fd12016-01-26 14:19:49 +130014826}
14827
Karl Schultz6addd812016-02-02 17:17:23 -070014828TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014829 TEST_DESCRIPTION(
14830 "Test that an error is produced for mismatched types across "
14831 "the vertex->fragment shader interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014832 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014833
Tony Barbour1fa09702017-03-16 12:09:08 -060014834 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014835 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesb56af562015-05-25 11:13:17 +120014836
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014837 char const *vsSource =
14838 "#version 450\n"
14839 "\n"
14840 "layout(location=0) out int x;\n"
14841 "out gl_PerVertex {\n"
14842 " vec4 gl_Position;\n"
14843 "};\n"
14844 "void main(){\n"
14845 " x = 0;\n"
14846 " gl_Position = vec4(1);\n"
14847 "}\n";
14848 char const *fsSource =
14849 "#version 450\n"
14850 "\n"
14851 "layout(location=0) in float x;\n" /* VS writes int */
14852 "layout(location=0) out vec4 color;\n"
14853 "void main(){\n"
14854 " color = vec4(x);\n"
14855 "}\n";
Chris Forbesb56af562015-05-25 11:13:17 +120014856
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014857 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14858 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesb56af562015-05-25 11:13:17 +120014859
14860 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014861 pipe.AddColorAttachment();
Chris Forbesb56af562015-05-25 11:13:17 +120014862 pipe.AddShader(&vs);
14863 pipe.AddShader(&fs);
14864
Chris Forbesb56af562015-05-25 11:13:17 +120014865 VkDescriptorSetObj descriptorSet(m_device);
14866 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014867 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesb56af562015-05-25 11:13:17 +120014868
Tony Barbour5781e8f2015-08-04 16:23:11 -060014869 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesb56af562015-05-25 11:13:17 +120014870
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014871 m_errorMonitor->VerifyFound();
Chris Forbesb56af562015-05-25 11:13:17 +120014872}
14873
Karl Schultz6addd812016-02-02 17:17:23 -070014874TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchInBlock) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014875 TEST_DESCRIPTION(
14876 "Test that an error is produced for mismatched types across "
14877 "the vertex->fragment shader interface, when the variable is contained within "
14878 "an interface block");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014879 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Chris Forbesa3e85f62016-01-15 14:53:11 +130014880
Tony Barbour1fa09702017-03-16 12:09:08 -060014881 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbesa3e85f62016-01-15 14:53:11 +130014882 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14883
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014884 char const *vsSource =
14885 "#version 450\n"
14886 "\n"
14887 "out block { layout(location=0) int x; } outs;\n"
14888 "out gl_PerVertex {\n"
14889 " vec4 gl_Position;\n"
14890 "};\n"
14891 "void main(){\n"
14892 " outs.x = 0;\n"
14893 " gl_Position = vec4(1);\n"
14894 "}\n";
14895 char const *fsSource =
14896 "#version 450\n"
14897 "\n"
14898 "in block { layout(location=0) float x; } ins;\n" /* VS writes int */
14899 "layout(location=0) out vec4 color;\n"
14900 "void main(){\n"
14901 " color = vec4(ins.x);\n"
14902 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130014903
14904 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14905 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14906
14907 VkPipelineObj pipe(m_device);
14908 pipe.AddColorAttachment();
14909 pipe.AddShader(&vs);
14910 pipe.AddShader(&fs);
14911
14912 VkDescriptorSetObj descriptorSet(m_device);
14913 descriptorSet.AppendDummy();
14914 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14915
14916 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14917
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014918 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130014919}
14920
14921TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByLocation) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014922 TEST_DESCRIPTION(
14923 "Test that an error is produced for location mismatches across "
14924 "the vertex->fragment shader interface; This should manifest as a not-written/not-consumed "
14925 "pair, but flushes out broken walking of the interfaces");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014926 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 +130014927
Tony Barbour1fa09702017-03-16 12:09:08 -060014928 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbese9928822016-02-17 14:44:52 +130014929 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14930
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014931 char const *vsSource =
14932 "#version 450\n"
14933 "\n"
14934 "out block { layout(location=1) float x; } outs;\n"
14935 "out gl_PerVertex {\n"
14936 " vec4 gl_Position;\n"
14937 "};\n"
14938 "void main(){\n"
14939 " outs.x = 0;\n"
14940 " gl_Position = vec4(1);\n"
14941 "}\n";
14942 char const *fsSource =
14943 "#version 450\n"
14944 "\n"
14945 "in block { layout(location=0) float x; } ins;\n"
14946 "layout(location=0) out vec4 color;\n"
14947 "void main(){\n"
14948 " color = vec4(ins.x);\n"
14949 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130014950
14951 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14952 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14953
14954 VkPipelineObj pipe(m_device);
14955 pipe.AddColorAttachment();
14956 pipe.AddShader(&vs);
14957 pipe.AddShader(&fs);
14958
14959 VkDescriptorSetObj descriptorSet(m_device);
14960 descriptorSet.AppendDummy();
14961 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14962
14963 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14964
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014965 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130014966}
14967
14968TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByComponent) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014969 TEST_DESCRIPTION(
14970 "Test that an error is produced for component mismatches across the "
14971 "vertex->fragment shader interface. It's not enough to have the same set of locations in "
14972 "use; matching is defined in terms of spirv variables.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014973 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 +130014974
Tony Barbour1fa09702017-03-16 12:09:08 -060014975 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbese9928822016-02-17 14:44:52 +130014976 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14977
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014978 char const *vsSource =
14979 "#version 450\n"
14980 "\n"
14981 "out block { layout(location=0, component=0) float x; } outs;\n"
14982 "out gl_PerVertex {\n"
14983 " vec4 gl_Position;\n"
14984 "};\n"
14985 "void main(){\n"
14986 " outs.x = 0;\n"
14987 " gl_Position = vec4(1);\n"
14988 "}\n";
14989 char const *fsSource =
14990 "#version 450\n"
14991 "\n"
14992 "in block { layout(location=0, component=1) float x; } ins;\n"
14993 "layout(location=0) out vec4 color;\n"
14994 "void main(){\n"
14995 " color = vec4(ins.x);\n"
14996 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130014997
14998 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14999 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15000
15001 VkPipelineObj pipe(m_device);
15002 pipe.AddColorAttachment();
15003 pipe.AddShader(&vs);
15004 pipe.AddShader(&fs);
15005
15006 VkDescriptorSetObj descriptorSet(m_device);
15007 descriptorSet.AppendDummy();
15008 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15009
15010 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15011
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015012 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130015013}
15014
Chris Forbes1f3b0152016-11-30 12:48:40 +130015015TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByPrecision) {
15016 TEST_DESCRIPTION("Test that the RelaxedPrecision decoration is validated to match");
15017
Tony Barbour1fa09702017-03-16 12:09:08 -060015018 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes1f3b0152016-11-30 12:48:40 +130015019 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15020
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015021 char const *vsSource =
15022 "#version 450\n"
15023 "layout(location=0) out mediump float x;\n"
15024 "void main() { gl_Position = vec4(0); x = 1.0; }\n";
15025 char const *fsSource =
15026 "#version 450\n"
15027 "layout(location=0) in highp float x;\n"
15028 "layout(location=0) out vec4 color;\n"
15029 "void main() { color = vec4(x); }\n";
Chris Forbes1f3b0152016-11-30 12:48:40 +130015030
15031 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15032 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15033
15034 VkPipelineObj pipe(m_device);
15035 pipe.AddColorAttachment();
15036 pipe.AddShader(&vs);
15037 pipe.AddShader(&fs);
15038
15039 VkDescriptorSetObj descriptorSet(m_device);
15040 descriptorSet.AppendDummy();
15041 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15042
15043 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "differ in precision");
15044
15045 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15046
15047 m_errorMonitor->VerifyFound();
15048}
15049
Chris Forbes870a39e2016-11-30 12:55:56 +130015050TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByPrecisionBlock) {
15051 TEST_DESCRIPTION("Test that the RelaxedPrecision decoration is validated to match");
15052
Tony Barbour1fa09702017-03-16 12:09:08 -060015053 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes870a39e2016-11-30 12:55:56 +130015054 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15055
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015056 char const *vsSource =
15057 "#version 450\n"
15058 "out block { layout(location=0) mediump float x; };\n"
15059 "void main() { gl_Position = vec4(0); x = 1.0; }\n";
15060 char const *fsSource =
15061 "#version 450\n"
15062 "in block { layout(location=0) highp float x; };\n"
15063 "layout(location=0) out vec4 color;\n"
15064 "void main() { color = vec4(x); }\n";
Chris Forbes870a39e2016-11-30 12:55:56 +130015065
15066 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15067 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15068
15069 VkPipelineObj pipe(m_device);
15070 pipe.AddColorAttachment();
15071 pipe.AddShader(&vs);
15072 pipe.AddShader(&fs);
15073
15074 VkDescriptorSetObj descriptorSet(m_device);
15075 descriptorSet.AppendDummy();
15076 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15077
15078 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "differ in precision");
15079
15080 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15081
15082 m_errorMonitor->VerifyFound();
15083}
15084
Karl Schultz6addd812016-02-02 17:17:23 -070015085TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015086 TEST_DESCRIPTION(
15087 "Test that a warning is produced for a vertex attribute which is "
15088 "not consumed by the vertex shader");
Mike Weiblencce7ec72016-10-17 19:33:05 -060015089 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015090
Tony Barbour1fa09702017-03-16 12:09:08 -060015091 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060015092 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesde136e02015-05-25 11:13:28 +120015093
15094 VkVertexInputBindingDescription input_binding;
15095 memset(&input_binding, 0, sizeof(input_binding));
15096
15097 VkVertexInputAttributeDescription input_attrib;
15098 memset(&input_attrib, 0, sizeof(input_attrib));
15099 input_attrib.format = VK_FORMAT_R32_SFLOAT;
15100
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015101 char const *vsSource =
15102 "#version 450\n"
15103 "\n"
15104 "out gl_PerVertex {\n"
15105 " vec4 gl_Position;\n"
15106 "};\n"
15107 "void main(){\n"
15108 " gl_Position = vec4(1);\n"
15109 "}\n";
15110 char const *fsSource =
15111 "#version 450\n"
15112 "\n"
15113 "layout(location=0) out vec4 color;\n"
15114 "void main(){\n"
15115 " color = vec4(1);\n"
15116 "}\n";
Chris Forbesde136e02015-05-25 11:13:28 +120015117
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060015118 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15119 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesde136e02015-05-25 11:13:28 +120015120
15121 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080015122 pipe.AddColorAttachment();
Chris Forbesde136e02015-05-25 11:13:28 +120015123 pipe.AddShader(&vs);
15124 pipe.AddShader(&fs);
15125
15126 pipe.AddVertexInputBindings(&input_binding, 1);
15127 pipe.AddVertexInputAttribs(&input_attrib, 1);
15128
Chris Forbesde136e02015-05-25 11:13:28 +120015129 VkDescriptorSetObj descriptorSet(m_device);
15130 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015131 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesde136e02015-05-25 11:13:28 +120015132
Tony Barbour5781e8f2015-08-04 16:23:11 -060015133 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesde136e02015-05-25 11:13:28 +120015134
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015135 m_errorMonitor->VerifyFound();
Chris Forbesde136e02015-05-25 11:13:28 +120015136}
15137
Karl Schultz6addd812016-02-02 17:17:23 -070015138TEST_F(VkLayerTest, CreatePipelineAttribLocationMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015139 TEST_DESCRIPTION(
15140 "Test that a warning is produced for a location mismatch on "
15141 "vertex attributes. This flushes out bad behavior in the interface walker");
Mike Weiblencce7ec72016-10-17 19:33:05 -060015142 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Chris Forbes7d83cd52016-01-15 11:32:03 +130015143
Tony Barbour1fa09702017-03-16 12:09:08 -060015144 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes7d83cd52016-01-15 11:32:03 +130015145 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15146
15147 VkVertexInputBindingDescription input_binding;
15148 memset(&input_binding, 0, sizeof(input_binding));
15149
15150 VkVertexInputAttributeDescription input_attrib;
15151 memset(&input_attrib, 0, sizeof(input_attrib));
15152 input_attrib.format = VK_FORMAT_R32_SFLOAT;
15153
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015154 char const *vsSource =
15155 "#version 450\n"
15156 "\n"
15157 "layout(location=1) in float x;\n"
15158 "out gl_PerVertex {\n"
15159 " vec4 gl_Position;\n"
15160 "};\n"
15161 "void main(){\n"
15162 " gl_Position = vec4(x);\n"
15163 "}\n";
15164 char const *fsSource =
15165 "#version 450\n"
15166 "\n"
15167 "layout(location=0) out vec4 color;\n"
15168 "void main(){\n"
15169 " color = vec4(1);\n"
15170 "}\n";
Chris Forbes7d83cd52016-01-15 11:32:03 +130015171
15172 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15173 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15174
15175 VkPipelineObj pipe(m_device);
15176 pipe.AddColorAttachment();
15177 pipe.AddShader(&vs);
15178 pipe.AddShader(&fs);
15179
15180 pipe.AddVertexInputBindings(&input_binding, 1);
15181 pipe.AddVertexInputAttribs(&input_attrib, 1);
15182
15183 VkDescriptorSetObj descriptorSet(m_device);
15184 descriptorSet.AppendDummy();
15185 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15186
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070015187 m_errorMonitor->SetUnexpectedError("Vertex shader consumes input at location 1 but not provided");
Chris Forbes7d83cd52016-01-15 11:32:03 +130015188 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15189
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015190 m_errorMonitor->VerifyFound();
Chris Forbes7d83cd52016-01-15 11:32:03 +130015191}
15192
Karl Schultz6addd812016-02-02 17:17:23 -070015193TEST_F(VkLayerTest, CreatePipelineAttribNotProvided) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015194 TEST_DESCRIPTION(
15195 "Test that an error is produced for a vertex shader input which is not "
15196 "provided by a vertex attribute");
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070015197 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15198 "Vertex shader consumes input at location 0 but not provided");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015199
Tony Barbour1fa09702017-03-16 12:09:08 -060015200 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060015201 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes62e8e502015-05-25 11:13:29 +120015202
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015203 char const *vsSource =
15204 "#version 450\n"
15205 "\n"
15206 "layout(location=0) in vec4 x;\n" /* not provided */
15207 "out gl_PerVertex {\n"
15208 " vec4 gl_Position;\n"
15209 "};\n"
15210 "void main(){\n"
15211 " gl_Position = x;\n"
15212 "}\n";
15213 char const *fsSource =
15214 "#version 450\n"
15215 "\n"
15216 "layout(location=0) out vec4 color;\n"
15217 "void main(){\n"
15218 " color = vec4(1);\n"
15219 "}\n";
Chris Forbes62e8e502015-05-25 11:13:29 +120015220
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060015221 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15222 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes62e8e502015-05-25 11:13:29 +120015223
15224 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080015225 pipe.AddColorAttachment();
Chris Forbes62e8e502015-05-25 11:13:29 +120015226 pipe.AddShader(&vs);
15227 pipe.AddShader(&fs);
15228
Chris Forbes62e8e502015-05-25 11:13:29 +120015229 VkDescriptorSetObj descriptorSet(m_device);
15230 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015231 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes62e8e502015-05-25 11:13:29 +120015232
Tony Barbour5781e8f2015-08-04 16:23:11 -060015233 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes62e8e502015-05-25 11:13:29 +120015234
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015235 m_errorMonitor->VerifyFound();
Chris Forbes62e8e502015-05-25 11:13:29 +120015236}
15237
Karl Schultz6addd812016-02-02 17:17:23 -070015238TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015239 TEST_DESCRIPTION(
15240 "Test that an error is produced for a mismatch between the "
15241 "fundamental type (float/int/uint) of an attribute and the "
15242 "vertex shader input that consumes it");
Mike Weiblen15bd38e2016-10-03 19:19:41 -060015243 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 -060015244
Tony Barbour1fa09702017-03-16 12:09:08 -060015245 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060015246 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc97d98e2015-05-25 11:13:31 +120015247
15248 VkVertexInputBindingDescription input_binding;
15249 memset(&input_binding, 0, sizeof(input_binding));
15250
15251 VkVertexInputAttributeDescription input_attrib;
15252 memset(&input_attrib, 0, sizeof(input_attrib));
15253 input_attrib.format = VK_FORMAT_R32_SFLOAT;
15254
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015255 char const *vsSource =
15256 "#version 450\n"
15257 "\n"
15258 "layout(location=0) in int x;\n" /* attrib provided float */
15259 "out gl_PerVertex {\n"
15260 " vec4 gl_Position;\n"
15261 "};\n"
15262 "void main(){\n"
15263 " gl_Position = vec4(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 Forbesc97d98e2015-05-25 11:13:31 +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 Forbesc97d98e2015-05-25 11:13:31 +120015275
15276 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080015277 pipe.AddColorAttachment();
Chris Forbesc97d98e2015-05-25 11:13:31 +120015278 pipe.AddShader(&vs);
15279 pipe.AddShader(&fs);
15280
15281 pipe.AddVertexInputBindings(&input_binding, 1);
15282 pipe.AddVertexInputAttribs(&input_attrib, 1);
15283
Chris Forbesc97d98e2015-05-25 11:13:31 +120015284 VkDescriptorSetObj descriptorSet(m_device);
15285 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015286 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesc97d98e2015-05-25 11:13:31 +120015287
Tony Barbour5781e8f2015-08-04 16:23:11 -060015288 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc97d98e2015-05-25 11:13:31 +120015289
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015290 m_errorMonitor->VerifyFound();
Chris Forbesc97d98e2015-05-25 11:13:31 +120015291}
15292
Chris Forbesc68b43c2016-04-06 11:18:47 +120015293TEST_F(VkLayerTest, CreatePipelineDuplicateStage) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015294 TEST_DESCRIPTION(
15295 "Test that an error is produced for a pipeline containing multiple "
15296 "shaders for the same stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015297 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15298 "Multiple shaders provided for stage VK_SHADER_STAGE_VERTEX_BIT");
Chris Forbesc68b43c2016-04-06 11:18:47 +120015299
Tony Barbour1fa09702017-03-16 12:09:08 -060015300 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbesc68b43c2016-04-06 11:18:47 +120015301 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15302
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015303 char const *vsSource =
15304 "#version 450\n"
15305 "\n"
15306 "out gl_PerVertex {\n"
15307 " vec4 gl_Position;\n"
15308 "};\n"
15309 "void main(){\n"
15310 " gl_Position = vec4(1);\n"
15311 "}\n";
15312 char const *fsSource =
15313 "#version 450\n"
15314 "\n"
15315 "layout(location=0) out vec4 color;\n"
15316 "void main(){\n"
15317 " color = vec4(1);\n"
15318 "}\n";
Chris Forbesc68b43c2016-04-06 11:18:47 +120015319
15320 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15321 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15322
15323 VkPipelineObj pipe(m_device);
15324 pipe.AddColorAttachment();
15325 pipe.AddShader(&vs);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015326 pipe.AddShader(&vs); // intentionally duplicate vertex shader attachment
Chris Forbesc68b43c2016-04-06 11:18:47 +120015327 pipe.AddShader(&fs);
15328
15329 VkDescriptorSetObj descriptorSet(m_device);
15330 descriptorSet.AppendDummy();
15331 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15332
15333 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15334
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015335 m_errorMonitor->VerifyFound();
Chris Forbesc68b43c2016-04-06 11:18:47 +120015336}
15337
Chris Forbes82ff92a2016-09-09 10:50:24 +120015338TEST_F(VkLayerTest, CreatePipelineMissingEntrypoint) {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070015339 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "No entrypoint found named `foo`");
Chris Forbes82ff92a2016-09-09 10:50:24 +120015340
Tony Barbour1fa09702017-03-16 12:09:08 -060015341 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes82ff92a2016-09-09 10:50:24 +120015342 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15343
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015344 char const *vsSource =
15345 "#version 450\n"
15346 "out gl_PerVertex {\n"
15347 " vec4 gl_Position;\n"
15348 "};\n"
15349 "void main(){\n"
15350 " gl_Position = vec4(0);\n"
15351 "}\n";
15352 char const *fsSource =
15353 "#version 450\n"
15354 "\n"
15355 "layout(location=0) out vec4 color;\n"
15356 "void main(){\n"
15357 " color = vec4(1);\n"
15358 "}\n";
Chris Forbes82ff92a2016-09-09 10:50:24 +120015359
15360 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15361 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this, "foo");
15362
15363 VkPipelineObj pipe(m_device);
15364 pipe.AddColorAttachment();
15365 pipe.AddShader(&vs);
15366 pipe.AddShader(&fs);
15367
15368 VkDescriptorSetObj descriptorSet(m_device);
15369 descriptorSet.AppendDummy();
15370 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15371
15372 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15373
15374 m_errorMonitor->VerifyFound();
15375}
15376
Chris Forbesae9d8cd2016-09-13 16:32:57 +120015377TEST_F(VkLayerTest, CreatePipelineDepthStencilRequired) {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070015378 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15379 "pDepthStencilState is NULL when rasterization is enabled and subpass "
15380 "uses a depth/stencil attachment");
Chris Forbesae9d8cd2016-09-13 16:32:57 +120015381
Tony Barbour1fa09702017-03-16 12:09:08 -060015382 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbesae9d8cd2016-09-13 16:32:57 +120015383 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15384
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015385 char const *vsSource =
15386 "#version 450\n"
15387 "void main(){ gl_Position = vec4(0); }\n";
15388 char const *fsSource =
15389 "#version 450\n"
15390 "\n"
15391 "layout(location=0) out vec4 color;\n"
15392 "void main(){\n"
15393 " color = vec4(1);\n"
15394 "}\n";
Chris Forbesae9d8cd2016-09-13 16:32:57 +120015395
15396 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15397 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15398
15399 VkPipelineObj pipe(m_device);
15400 pipe.AddColorAttachment();
15401 pipe.AddShader(&vs);
15402 pipe.AddShader(&fs);
15403
15404 VkDescriptorSetObj descriptorSet(m_device);
15405 descriptorSet.AppendDummy();
15406 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15407
15408 VkAttachmentDescription attachments[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070015409 {
15410 0, VK_FORMAT_B8G8R8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
15411 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_UNDEFINED,
15412 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
Chris Forbesae9d8cd2016-09-13 16:32:57 +120015413 },
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070015414 {
15415 0, VK_FORMAT_D16_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
15416 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_UNDEFINED,
15417 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
Chris Forbesae9d8cd2016-09-13 16:32:57 +120015418 },
15419 };
15420 VkAttachmentReference refs[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070015421 {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL}, {1, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL},
Chris Forbesae9d8cd2016-09-13 16:32:57 +120015422 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070015423 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &refs[0], nullptr, &refs[1], 0, nullptr};
15424 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesae9d8cd2016-09-13 16:32:57 +120015425 VkRenderPass rp;
15426 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
15427 ASSERT_VK_SUCCESS(err);
15428
15429 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), rp);
15430
15431 m_errorMonitor->VerifyFound();
15432
15433 vkDestroyRenderPass(m_device->device(), rp, nullptr);
15434}
15435
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015436TEST_F(VkLayerTest, CreatePipelineTessPatchDecorationMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015437 TEST_DESCRIPTION(
15438 "Test that an error is produced for a variable output from "
15439 "the TCS without the patch decoration, but consumed in the TES "
15440 "with the decoration.");
15441 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15442 "is per-vertex in tessellation control shader stage "
15443 "but per-patch in tessellation evaluation shader stage");
Chris Forbesa0193bc2016-04-04 19:19:47 +120015444
Tony Barbour1fa09702017-03-16 12:09:08 -060015445 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbesa0193bc2016-04-04 19:19:47 +120015446 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15447
Chris Forbesc1e852d2016-04-04 19:26:42 +120015448 if (!m_device->phy().features().tessellationShader) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070015449 printf(" Device does not support tessellation shaders; skipped.\n");
Chris Forbesc1e852d2016-04-04 19:26:42 +120015450 return;
15451 }
15452
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015453 char const *vsSource =
15454 "#version 450\n"
15455 "void main(){}\n";
15456 char const *tcsSource =
15457 "#version 450\n"
15458 "layout(location=0) out int x[];\n"
15459 "layout(vertices=3) out;\n"
15460 "void main(){\n"
15461 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
15462 " gl_TessLevelInner[0] = 1;\n"
15463 " x[gl_InvocationID] = gl_InvocationID;\n"
15464 "}\n";
15465 char const *tesSource =
15466 "#version 450\n"
15467 "layout(triangles, equal_spacing, cw) in;\n"
15468 "layout(location=0) patch in int x;\n"
15469 "out gl_PerVertex { vec4 gl_Position; };\n"
15470 "void main(){\n"
15471 " gl_Position.xyz = gl_TessCoord;\n"
15472 " gl_Position.w = x;\n"
15473 "}\n";
15474 char const *fsSource =
15475 "#version 450\n"
15476 "layout(location=0) out vec4 color;\n"
15477 "void main(){\n"
15478 " color = vec4(1);\n"
15479 "}\n";
Chris Forbesa0193bc2016-04-04 19:19:47 +120015480
15481 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15482 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
15483 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
15484 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15485
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015486 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
15487 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Chris Forbesa0193bc2016-04-04 19:19:47 +120015488
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015489 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Chris Forbesa0193bc2016-04-04 19:19:47 +120015490
15491 VkPipelineObj pipe(m_device);
15492 pipe.SetInputAssembly(&iasci);
15493 pipe.SetTessellation(&tsci);
15494 pipe.AddColorAttachment();
15495 pipe.AddShader(&vs);
15496 pipe.AddShader(&tcs);
15497 pipe.AddShader(&tes);
15498 pipe.AddShader(&fs);
15499
15500 VkDescriptorSetObj descriptorSet(m_device);
15501 descriptorSet.AppendDummy();
15502 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15503
15504 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15505
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015506 m_errorMonitor->VerifyFound();
Chris Forbesa0193bc2016-04-04 19:19:47 +120015507}
15508
Cort Stratton2bcca1b2017-05-05 16:02:35 -070015509TEST_F(VkLayerTest, CreatePipelineTessErrors) {
15510 TEST_DESCRIPTION("Test various errors when creating a graphics pipeline with tessellation stages active.");
15511
15512 ASSERT_NO_FATAL_FAILURE(Init());
15513 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15514
15515 if (!m_device->phy().features().tessellationShader) {
15516 printf(" Device does not support tessellation shaders; skipped.\n");
15517 return;
15518 }
15519
15520 char const *vsSource =
15521 "#version 450\n"
15522 "void main(){}\n";
15523 char const *tcsSource =
15524 "#version 450\n"
15525 "layout(vertices=3) out;\n"
15526 "void main(){\n"
15527 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
15528 " gl_TessLevelInner[0] = 1;\n"
15529 "}\n";
15530 char const *tesSource =
15531 "#version 450\n"
15532 "layout(triangles, equal_spacing, cw) in;\n"
15533 "out gl_PerVertex { vec4 gl_Position; };\n"
15534 "void main(){\n"
15535 " gl_Position.xyz = gl_TessCoord;\n"
15536 " gl_Position.w = 0;\n"
15537 "}\n";
15538 char const *fsSource =
15539 "#version 450\n"
15540 "layout(location=0) out vec4 color;\n"
15541 "void main(){\n"
15542 " color = vec4(1);\n"
15543 "}\n";
15544
15545 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15546 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
15547 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
15548 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15549
15550 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
15551 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
15552
15553 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
15554
15555 VkDescriptorSetObj descriptorSet(m_device);
15556 descriptorSet.AppendDummy();
15557 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15558
15559 {
15560 VkPipelineObj pipe(m_device);
15561 VkPipelineInputAssemblyStateCreateInfo iasci_bad = iasci;
15562 iasci_bad.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST; // otherwise we get a failure about invalid topology
15563 pipe.SetInputAssembly(&iasci_bad);
15564 pipe.AddColorAttachment();
15565 pipe.AddShader(&vs);
15566 pipe.AddShader(&fs);
15567
15568 // Pass a tess control shader without a tess eval shader
15569 pipe.AddShader(&tcs);
15570 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00534);
15571 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15572 m_errorMonitor->VerifyFound();
15573 }
15574
15575 {
15576 VkPipelineObj pipe(m_device);
15577 VkPipelineInputAssemblyStateCreateInfo iasci_bad = iasci;
15578 iasci_bad.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST; // otherwise we get a failure about invalid topology
15579 pipe.SetInputAssembly(&iasci_bad);
15580 pipe.AddColorAttachment();
15581 pipe.AddShader(&vs);
15582 pipe.AddShader(&fs);
15583
15584 // Pass a tess eval shader without a tess control shader
15585 pipe.AddShader(&tes);
15586 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00535);
15587 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15588 m_errorMonitor->VerifyFound();
15589 }
15590
15591 {
15592 VkPipelineObj pipe(m_device);
15593 pipe.SetInputAssembly(&iasci);
15594 pipe.AddColorAttachment();
15595 pipe.AddShader(&vs);
15596 pipe.AddShader(&fs);
15597
15598 // Pass patch topology without tessellation shaders
15599 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02100);
15600 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15601 m_errorMonitor->VerifyFound();
15602
15603 pipe.AddShader(&tcs);
15604 pipe.AddShader(&tes);
15605 // Pass a NULL pTessellationState (with active tessellation shader stages)
15606 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00536);
15607 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15608 m_errorMonitor->VerifyFound();
15609
15610 // Pass an invalid pTessellationState (bad sType)
15611 VkPipelineTessellationStateCreateInfo tsci_bad = tsci;
15612 tsci_bad.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
15613 pipe.SetTessellation(&tsci_bad);
15614 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01427);
15615 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15616 m_errorMonitor->VerifyFound();
15617 // Pass out-of-range patchControlPoints
15618 tsci_bad = tsci;
15619 tsci_bad.patchControlPoints = 0;
15620 pipe.SetTessellation(&tsci);
15621 pipe.SetTessellation(&tsci_bad);
15622 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01426);
15623 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15624 m_errorMonitor->VerifyFound();
15625 tsci_bad.patchControlPoints = m_device->props.limits.maxTessellationPatchSize + 1;
15626 pipe.SetTessellation(&tsci_bad);
15627 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01426);
15628 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15629 m_errorMonitor->VerifyFound();
15630 pipe.SetTessellation(&tsci);
15631
15632 // Pass an invalid primitive topology
15633 VkPipelineInputAssemblyStateCreateInfo iasci_bad = iasci;
15634 iasci_bad.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
15635 pipe.SetInputAssembly(&iasci_bad);
15636 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02099);
15637 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15638 m_errorMonitor->VerifyFound();
15639 pipe.SetInputAssembly(&iasci);
15640 }
15641}
15642
Karl Schultz6addd812016-02-02 17:17:23 -070015643TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015644 TEST_DESCRIPTION(
15645 "Test that an error is produced for a vertex attribute setup where multiple "
15646 "bindings provide the same location");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015647 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15648 "Duplicate vertex input binding descriptions for binding 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015649
Tony Barbour1fa09702017-03-16 12:09:08 -060015650 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060015651 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes280ba2c2015-06-12 11:16:41 +120015652
15653 /* Two binding descriptions for binding 0 */
15654 VkVertexInputBindingDescription input_bindings[2];
15655 memset(input_bindings, 0, sizeof(input_bindings));
15656
15657 VkVertexInputAttributeDescription input_attrib;
15658 memset(&input_attrib, 0, sizeof(input_attrib));
15659 input_attrib.format = VK_FORMAT_R32_SFLOAT;
15660
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015661 char const *vsSource =
15662 "#version 450\n"
15663 "\n"
15664 "layout(location=0) in float x;\n" /* attrib provided float */
15665 "out gl_PerVertex {\n"
15666 " vec4 gl_Position;\n"
15667 "};\n"
15668 "void main(){\n"
15669 " gl_Position = vec4(x);\n"
15670 "}\n";
15671 char const *fsSource =
15672 "#version 450\n"
15673 "\n"
15674 "layout(location=0) out vec4 color;\n"
15675 "void main(){\n"
15676 " color = vec4(1);\n"
15677 "}\n";
Chris Forbes280ba2c2015-06-12 11:16:41 +120015678
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060015679 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15680 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes280ba2c2015-06-12 11:16:41 +120015681
15682 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080015683 pipe.AddColorAttachment();
Chris Forbes280ba2c2015-06-12 11:16:41 +120015684 pipe.AddShader(&vs);
15685 pipe.AddShader(&fs);
15686
15687 pipe.AddVertexInputBindings(input_bindings, 2);
15688 pipe.AddVertexInputAttribs(&input_attrib, 1);
15689
Chris Forbes280ba2c2015-06-12 11:16:41 +120015690 VkDescriptorSetObj descriptorSet(m_device);
15691 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015692 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes280ba2c2015-06-12 11:16:41 +120015693
Tony Barbour5781e8f2015-08-04 16:23:11 -060015694 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes280ba2c2015-06-12 11:16:41 +120015695
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015696 m_errorMonitor->VerifyFound();
Chris Forbes280ba2c2015-06-12 11:16:41 +120015697}
Chris Forbes8f68b562015-05-25 11:13:32 +120015698
Karl Schultz6addd812016-02-02 17:17:23 -070015699TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015700 TEST_DESCRIPTION(
15701 "Test that an error is produced for a fragment shader which does not "
15702 "provide an output for one of the pipeline's color attachments");
Mike Weiblencce7ec72016-10-17 19:33:05 -060015703 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attachment 0 not written by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015704
Tony Barbour1fa09702017-03-16 12:09:08 -060015705 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120015706
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015707 char const *vsSource =
15708 "#version 450\n"
15709 "\n"
15710 "out gl_PerVertex {\n"
15711 " vec4 gl_Position;\n"
15712 "};\n"
15713 "void main(){\n"
15714 " gl_Position = vec4(1);\n"
15715 "}\n";
15716 char const *fsSource =
15717 "#version 450\n"
15718 "\n"
15719 "void main(){\n"
15720 "}\n";
Chris Forbes4d6d1e52015-05-25 11:13:40 +120015721
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060015722 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15723 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120015724
15725 VkPipelineObj pipe(m_device);
15726 pipe.AddShader(&vs);
15727 pipe.AddShader(&fs);
15728
Chia-I Wu08accc62015-07-07 11:50:03 +080015729 /* set up CB 0, not written */
15730 pipe.AddColorAttachment();
15731 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120015732
Chris Forbes4d6d1e52015-05-25 11:13:40 +120015733 VkDescriptorSetObj descriptorSet(m_device);
15734 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015735 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120015736
Tony Barbour5781e8f2015-08-04 16:23:11 -060015737 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120015738
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015739 m_errorMonitor->VerifyFound();
Chris Forbes4d6d1e52015-05-25 11:13:40 +120015740}
15741
Karl Schultz6addd812016-02-02 17:17:23 -070015742TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015743 TEST_DESCRIPTION(
15744 "Test that a warning is produced for a fragment shader which provides a spurious "
15745 "output with no matching attachment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015746 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060015747 "fragment shader writes to output location 1 with no matching attachment");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015748
Tony Barbour1fa09702017-03-16 12:09:08 -060015749 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120015750
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015751 char const *vsSource =
15752 "#version 450\n"
15753 "\n"
15754 "out gl_PerVertex {\n"
15755 " vec4 gl_Position;\n"
15756 "};\n"
15757 "void main(){\n"
15758 " gl_Position = vec4(1);\n"
15759 "}\n";
15760 char const *fsSource =
15761 "#version 450\n"
15762 "\n"
15763 "layout(location=0) out vec4 x;\n"
15764 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
15765 "void main(){\n"
15766 " x = vec4(1);\n"
15767 " y = vec4(1);\n"
15768 "}\n";
Chris Forbesf3fffaa2015-05-25 11:13:43 +120015769
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060015770 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15771 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120015772
15773 VkPipelineObj pipe(m_device);
15774 pipe.AddShader(&vs);
15775 pipe.AddShader(&fs);
15776
Chia-I Wu08accc62015-07-07 11:50:03 +080015777 /* set up CB 0, not written */
15778 pipe.AddColorAttachment();
15779 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120015780 /* FS writes CB 1, but we don't configure it */
15781
Chris Forbesf3fffaa2015-05-25 11:13:43 +120015782 VkDescriptorSetObj descriptorSet(m_device);
15783 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015784 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120015785
Tony Barbour5781e8f2015-08-04 16:23:11 -060015786 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120015787
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015788 m_errorMonitor->VerifyFound();
Chris Forbesf3fffaa2015-05-25 11:13:43 +120015789}
15790
Karl Schultz6addd812016-02-02 17:17:23 -070015791TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015792 TEST_DESCRIPTION(
15793 "Test that an error is produced for a mismatch between the fundamental "
15794 "type of an fragment shader output variable, and the format of the corresponding attachment");
Mike Weiblencce7ec72016-10-17 19:33:05 -060015795 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "does not match fragment shader output type");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015796
Tony Barbour1fa09702017-03-16 12:09:08 -060015797 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbesa36d69e2015-05-25 11:13:44 +120015798
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015799 char const *vsSource =
15800 "#version 450\n"
15801 "\n"
15802 "out gl_PerVertex {\n"
15803 " vec4 gl_Position;\n"
15804 "};\n"
15805 "void main(){\n"
15806 " gl_Position = vec4(1);\n"
15807 "}\n";
15808 char const *fsSource =
15809 "#version 450\n"
15810 "\n"
15811 "layout(location=0) out ivec4 x;\n" /* not UNORM */
15812 "void main(){\n"
15813 " x = ivec4(1);\n"
15814 "}\n";
Chris Forbesa36d69e2015-05-25 11:13:44 +120015815
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060015816 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15817 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa36d69e2015-05-25 11:13:44 +120015818
15819 VkPipelineObj pipe(m_device);
15820 pipe.AddShader(&vs);
15821 pipe.AddShader(&fs);
15822
Chia-I Wu08accc62015-07-07 11:50:03 +080015823 /* set up CB 0; type is UNORM by default */
15824 pipe.AddColorAttachment();
15825 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa36d69e2015-05-25 11:13:44 +120015826
Chris Forbesa36d69e2015-05-25 11:13:44 +120015827 VkDescriptorSetObj descriptorSet(m_device);
15828 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015829 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesa36d69e2015-05-25 11:13:44 +120015830
Tony Barbour5781e8f2015-08-04 16:23:11 -060015831 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa36d69e2015-05-25 11:13:44 +120015832
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015833 m_errorMonitor->VerifyFound();
Chris Forbesa36d69e2015-05-25 11:13:44 +120015834}
Chris Forbes7b1b8932015-06-05 14:43:36 +120015835
Karl Schultz6addd812016-02-02 17:17:23 -070015836TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015837 TEST_DESCRIPTION(
15838 "Test that an error is produced for a shader consuming a uniform "
15839 "block which has no corresponding binding in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015840 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in pipeline layout");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015841
Tony Barbour1fa09702017-03-16 12:09:08 -060015842 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes556c76c2015-08-14 12:04:59 +120015843
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015844 char const *vsSource =
15845 "#version 450\n"
15846 "\n"
15847 "out gl_PerVertex {\n"
15848 " vec4 gl_Position;\n"
15849 "};\n"
15850 "void main(){\n"
15851 " gl_Position = vec4(1);\n"
15852 "}\n";
15853 char const *fsSource =
15854 "#version 450\n"
15855 "\n"
15856 "layout(location=0) out vec4 x;\n"
15857 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
15858 "void main(){\n"
15859 " x = vec4(bar.y);\n"
15860 "}\n";
Chris Forbes556c76c2015-08-14 12:04:59 +120015861
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060015862 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15863 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes556c76c2015-08-14 12:04:59 +120015864
Chris Forbes556c76c2015-08-14 12:04:59 +120015865 VkPipelineObj pipe(m_device);
15866 pipe.AddShader(&vs);
15867 pipe.AddShader(&fs);
15868
15869 /* set up CB 0; type is UNORM by default */
15870 pipe.AddColorAttachment();
15871 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15872
15873 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015874 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes556c76c2015-08-14 12:04:59 +120015875
15876 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15877
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015878 m_errorMonitor->VerifyFound();
Chris Forbes556c76c2015-08-14 12:04:59 +120015879}
15880
Chris Forbes5c59e902016-02-26 16:56:09 +130015881TEST_F(VkLayerTest, CreatePipelinePushConstantsNotInLayout) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015882 TEST_DESCRIPTION(
15883 "Test that an error is produced for a shader consuming push constants "
15884 "which are not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015885 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in layout");
Chris Forbes5c59e902016-02-26 16:56:09 +130015886
Tony Barbour1fa09702017-03-16 12:09:08 -060015887 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes5c59e902016-02-26 16:56:09 +130015888
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015889 char const *vsSource =
15890 "#version 450\n"
15891 "\n"
15892 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
15893 "out gl_PerVertex {\n"
15894 " vec4 gl_Position;\n"
15895 "};\n"
15896 "void main(){\n"
15897 " gl_Position = vec4(consts.x);\n"
15898 "}\n";
15899 char const *fsSource =
15900 "#version 450\n"
15901 "\n"
15902 "layout(location=0) out vec4 x;\n"
15903 "void main(){\n"
15904 " x = vec4(1);\n"
15905 "}\n";
Chris Forbes5c59e902016-02-26 16:56:09 +130015906
15907 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15908 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15909
15910 VkPipelineObj pipe(m_device);
15911 pipe.AddShader(&vs);
15912 pipe.AddShader(&fs);
15913
15914 /* set up CB 0; type is UNORM by default */
15915 pipe.AddColorAttachment();
15916 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15917
15918 VkDescriptorSetObj descriptorSet(m_device);
15919 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15920
15921 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15922
15923 /* should have generated an error -- no push constant ranges provided! */
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015924 m_errorMonitor->VerifyFound();
Chris Forbes5c59e902016-02-26 16:56:09 +130015925}
15926
Chris Forbes3fb17902016-08-22 14:57:55 +120015927TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissing) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015928 TEST_DESCRIPTION(
15929 "Test that an error is produced for a shader consuming an input attachment "
15930 "which is not included in the subpass description");
Chris Forbes3fb17902016-08-22 14:57:55 +120015931 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15932 "consumes input attachment index 0 but not provided in subpass");
15933
Tony Barbour1fa09702017-03-16 12:09:08 -060015934 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes3fb17902016-08-22 14:57:55 +120015935
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015936 char const *vsSource =
15937 "#version 450\n"
15938 "\n"
15939 "out gl_PerVertex {\n"
15940 " vec4 gl_Position;\n"
15941 "};\n"
15942 "void main(){\n"
15943 " gl_Position = vec4(1);\n"
15944 "}\n";
15945 char const *fsSource =
15946 "#version 450\n"
15947 "\n"
15948 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
15949 "layout(location=0) out vec4 color;\n"
15950 "void main() {\n"
15951 " color = subpassLoad(x);\n"
15952 "}\n";
Chris Forbes3fb17902016-08-22 14:57:55 +120015953
15954 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15955 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15956
15957 VkPipelineObj pipe(m_device);
15958 pipe.AddShader(&vs);
15959 pipe.AddShader(&fs);
15960 pipe.AddColorAttachment();
15961 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15962
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015963 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
15964 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes3fb17902016-08-22 14:57:55 +120015965 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015966 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes3fb17902016-08-22 14:57:55 +120015967 ASSERT_VK_SUCCESS(err);
15968
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015969 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes3fb17902016-08-22 14:57:55 +120015970 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015971 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes3fb17902016-08-22 14:57:55 +120015972 ASSERT_VK_SUCCESS(err);
15973
15974 // error here.
15975 pipe.CreateVKPipeline(pl, renderPass());
15976
15977 m_errorMonitor->VerifyFound();
15978
15979 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15980 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15981}
15982
Chris Forbes5a9a0472016-08-22 16:02:09 +120015983TEST_F(VkLayerTest, CreatePipelineInputAttachmentTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015984 TEST_DESCRIPTION(
15985 "Test that an error is produced for a shader consuming an input attachment "
15986 "with a format having a different fundamental type");
Chris Forbes5a9a0472016-08-22 16:02:09 +120015987 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15988 "input attachment 0 format of VK_FORMAT_R8G8B8A8_UINT does not match");
15989
Tony Barbour1fa09702017-03-16 12:09:08 -060015990 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes5a9a0472016-08-22 16:02:09 +120015991
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015992 char const *vsSource =
15993 "#version 450\n"
15994 "\n"
15995 "out gl_PerVertex {\n"
15996 " vec4 gl_Position;\n"
15997 "};\n"
15998 "void main(){\n"
15999 " gl_Position = vec4(1);\n"
16000 "}\n";
16001 char const *fsSource =
16002 "#version 450\n"
16003 "\n"
16004 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
16005 "layout(location=0) out vec4 color;\n"
16006 "void main() {\n"
16007 " color = subpassLoad(x);\n"
16008 "}\n";
Chris Forbes5a9a0472016-08-22 16:02:09 +120016009
16010 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
16011 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
16012
16013 VkPipelineObj pipe(m_device);
16014 pipe.AddShader(&vs);
16015 pipe.AddShader(&fs);
16016 pipe.AddColorAttachment();
16017 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16018
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016019 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
16020 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes5a9a0472016-08-22 16:02:09 +120016021 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016022 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120016023 ASSERT_VK_SUCCESS(err);
16024
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016025 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120016026 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016027 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120016028 ASSERT_VK_SUCCESS(err);
16029
16030 VkAttachmentDescription descs[2] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016031 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
16032 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
16033 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
16034 {0, VK_FORMAT_R8G8B8A8_UINT, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
16035 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 +120016036 };
16037 VkAttachmentReference color = {
16038 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
16039 };
16040 VkAttachmentReference input = {
16041 1, VK_IMAGE_LAYOUT_GENERAL,
16042 };
16043
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016044 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120016045
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016046 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120016047 VkRenderPass rp;
16048 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
16049 ASSERT_VK_SUCCESS(err);
16050
16051 // error here.
16052 pipe.CreateVKPipeline(pl, rp);
16053
16054 m_errorMonitor->VerifyFound();
16055
16056 vkDestroyRenderPass(m_device->device(), rp, nullptr);
16057 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
16058 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
16059}
16060
Chris Forbes541f7b02016-08-22 15:30:27 +120016061TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissingArray) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016062 TEST_DESCRIPTION(
16063 "Test that an error is produced for a shader consuming an input attachment "
16064 "which is not included in the subpass description -- array case");
Chris Forbes541f7b02016-08-22 15:30:27 +120016065 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Rene Lindsay07b60af2017-01-10 15:57:55 -070016066 "consumes input attachment index 0 but not provided in subpass");
Chris Forbes541f7b02016-08-22 15:30:27 +120016067
Tony Barbour1fa09702017-03-16 12:09:08 -060016068 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes541f7b02016-08-22 15:30:27 +120016069
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016070 char const *vsSource =
16071 "#version 450\n"
16072 "\n"
16073 "out gl_PerVertex {\n"
16074 " vec4 gl_Position;\n"
16075 "};\n"
16076 "void main(){\n"
16077 " gl_Position = vec4(1);\n"
16078 "}\n";
16079 char const *fsSource =
16080 "#version 450\n"
16081 "\n"
16082 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput xs[1];\n"
16083 "layout(location=0) out vec4 color;\n"
16084 "void main() {\n"
16085 " color = subpassLoad(xs[0]);\n"
16086 "}\n";
Chris Forbes541f7b02016-08-22 15:30:27 +120016087
16088 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
16089 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
16090
16091 VkPipelineObj pipe(m_device);
16092 pipe.AddShader(&vs);
16093 pipe.AddShader(&fs);
16094 pipe.AddColorAttachment();
16095 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16096
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016097 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 2, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
16098 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes541f7b02016-08-22 15:30:27 +120016099 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016100 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes541f7b02016-08-22 15:30:27 +120016101 ASSERT_VK_SUCCESS(err);
16102
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016103 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes541f7b02016-08-22 15:30:27 +120016104 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016105 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes541f7b02016-08-22 15:30:27 +120016106 ASSERT_VK_SUCCESS(err);
16107
16108 // error here.
16109 pipe.CreateVKPipeline(pl, renderPass());
16110
16111 m_errorMonitor->VerifyFound();
16112
16113 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
16114 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
16115}
16116
Chris Forbes10eb9ae2016-05-31 16:09:42 +120016117TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptor) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016118 TEST_DESCRIPTION(
16119 "Test that an error is produced for a compute pipeline consuming a "
16120 "descriptor which is not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016121 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Shader uses descriptor slot 0.0");
Chris Forbes10eb9ae2016-05-31 16:09:42 +120016122
Tony Barbour1fa09702017-03-16 12:09:08 -060016123 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes10eb9ae2016-05-31 16:09:42 +120016124
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016125 char const *csSource =
16126 "#version 450\n"
16127 "\n"
16128 "layout(local_size_x=1) in;\n"
16129 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
16130 "void main(){\n"
16131 " x = vec4(1);\n"
16132 "}\n";
Chris Forbes10eb9ae2016-05-31 16:09:42 +120016133
16134 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
16135
16136 VkDescriptorSetObj descriptorSet(m_device);
16137 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
16138
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016139 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
16140 nullptr,
16141 0,
16142 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
16143 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
16144 descriptorSet.GetPipelineLayout(),
16145 VK_NULL_HANDLE,
16146 -1};
Chris Forbes10eb9ae2016-05-31 16:09:42 +120016147
16148 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016149 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes10eb9ae2016-05-31 16:09:42 +120016150
16151 m_errorMonitor->VerifyFound();
16152
16153 if (err == VK_SUCCESS) {
16154 vkDestroyPipeline(m_device->device(), pipe, nullptr);
16155 }
16156}
16157
Chris Forbes22a9b092016-07-19 14:34:05 +120016158TEST_F(VkLayerTest, CreateComputePipelineDescriptorTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016159 TEST_DESCRIPTION(
16160 "Test that an error is produced for a pipeline consuming a "
16161 "descriptor-backed resource of a mismatched type");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016162 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16163 "but descriptor of type VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER");
Chris Forbes22a9b092016-07-19 14:34:05 +120016164
Tony Barbour1fa09702017-03-16 12:09:08 -060016165 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes22a9b092016-07-19 14:34:05 +120016166
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016167 VkDescriptorSetLayoutBinding binding = {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr};
16168 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &binding};
Chris Forbes22a9b092016-07-19 14:34:05 +120016169 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016170 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes22a9b092016-07-19 14:34:05 +120016171 ASSERT_VK_SUCCESS(err);
16172
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016173 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes22a9b092016-07-19 14:34:05 +120016174 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016175 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes22a9b092016-07-19 14:34:05 +120016176 ASSERT_VK_SUCCESS(err);
16177
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016178 char const *csSource =
16179 "#version 450\n"
16180 "\n"
16181 "layout(local_size_x=1) in;\n"
16182 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
16183 "void main() {\n"
16184 " x.x = 1.0f;\n"
16185 "}\n";
Chris Forbes22a9b092016-07-19 14:34:05 +120016186 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
16187
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016188 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
16189 nullptr,
16190 0,
16191 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
16192 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
16193 pl,
16194 VK_NULL_HANDLE,
16195 -1};
Chris Forbes22a9b092016-07-19 14:34:05 +120016196
16197 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016198 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes22a9b092016-07-19 14:34:05 +120016199
16200 m_errorMonitor->VerifyFound();
16201
16202 if (err == VK_SUCCESS) {
16203 vkDestroyPipeline(m_device->device(), pipe, nullptr);
16204 }
16205
16206 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
16207 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
16208}
16209
Chris Forbes50020592016-07-27 13:52:41 +120016210TEST_F(VkLayerTest, DrawTimeImageViewTypeMismatchWithPipeline) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016211 TEST_DESCRIPTION(
16212 "Test that an error is produced when an image view type "
16213 "does not match the dimensionality declared in the shader");
Chris Forbes50020592016-07-27 13:52:41 +120016214
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016215 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 +120016216
Tony Barbour1fa09702017-03-16 12:09:08 -060016217 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes50020592016-07-27 13:52:41 +120016218 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16219
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016220 char const *vsSource =
16221 "#version 450\n"
16222 "\n"
16223 "out gl_PerVertex { vec4 gl_Position; };\n"
16224 "void main() { gl_Position = vec4(0); }\n";
16225 char const *fsSource =
16226 "#version 450\n"
16227 "\n"
16228 "layout(set=0, binding=0) uniform sampler3D s;\n"
16229 "layout(location=0) out vec4 color;\n"
16230 "void main() {\n"
16231 " color = texture(s, vec3(0));\n"
16232 "}\n";
Chris Forbes50020592016-07-27 13:52:41 +120016233 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
16234 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
16235
16236 VkPipelineObj pipe(m_device);
16237 pipe.AddShader(&vs);
16238 pipe.AddShader(&fs);
16239 pipe.AddColorAttachment();
16240
16241 VkTextureObj texture(m_device, nullptr);
16242 VkSamplerObj sampler(m_device);
16243
16244 VkDescriptorSetObj descriptorSet(m_device);
16245 descriptorSet.AppendSamplerTexture(&sampler, &texture);
16246 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
16247
16248 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
16249 ASSERT_VK_SUCCESS(err);
16250
Tony Barbour552f6c02016-12-21 14:34:07 -070016251 m_commandBuffer->BeginCommandBuffer();
16252 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes50020592016-07-27 13:52:41 +120016253
16254 m_commandBuffer->BindPipeline(pipe);
16255 m_commandBuffer->BindDescriptorSet(descriptorSet);
16256
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016257 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes50020592016-07-27 13:52:41 +120016258 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016259 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes50020592016-07-27 13:52:41 +120016260 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16261
16262 // error produced here.
16263 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
16264
16265 m_errorMonitor->VerifyFound();
16266
Tony Barbour552f6c02016-12-21 14:34:07 -070016267 m_commandBuffer->EndRenderPass();
16268 m_commandBuffer->EndCommandBuffer();
Chris Forbes50020592016-07-27 13:52:41 +120016269}
16270
Chris Forbes5533bfc2016-07-27 14:12:34 +120016271TEST_F(VkLayerTest, DrawTimeImageMultisampleMismatchWithPipeline) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016272 TEST_DESCRIPTION(
16273 "Test that an error is produced when a multisampled images "
16274 "are consumed via singlesample images types in the shader, or vice versa.");
Chris Forbes5533bfc2016-07-27 14:12:34 +120016275
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016276 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "requires bound image to have multiple samples");
Chris Forbes5533bfc2016-07-27 14:12:34 +120016277
Tony Barbour1fa09702017-03-16 12:09:08 -060016278 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes5533bfc2016-07-27 14:12:34 +120016279 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16280
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016281 char const *vsSource =
16282 "#version 450\n"
16283 "\n"
16284 "out gl_PerVertex { vec4 gl_Position; };\n"
16285 "void main() { gl_Position = vec4(0); }\n";
16286 char const *fsSource =
16287 "#version 450\n"
16288 "\n"
16289 "layout(set=0, binding=0) uniform sampler2DMS s;\n"
16290 "layout(location=0) out vec4 color;\n"
16291 "void main() {\n"
16292 " color = texelFetch(s, ivec2(0), 0);\n"
16293 "}\n";
Chris Forbes5533bfc2016-07-27 14:12:34 +120016294 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
16295 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
16296
16297 VkPipelineObj pipe(m_device);
16298 pipe.AddShader(&vs);
16299 pipe.AddShader(&fs);
16300 pipe.AddColorAttachment();
16301
16302 VkTextureObj texture(m_device, nullptr);
16303 VkSamplerObj sampler(m_device);
16304
16305 VkDescriptorSetObj descriptorSet(m_device);
16306 descriptorSet.AppendSamplerTexture(&sampler, &texture);
16307 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
16308
16309 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
16310 ASSERT_VK_SUCCESS(err);
16311
Tony Barbour552f6c02016-12-21 14:34:07 -070016312 m_commandBuffer->BeginCommandBuffer();
16313 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes5533bfc2016-07-27 14:12:34 +120016314
16315 m_commandBuffer->BindPipeline(pipe);
16316 m_commandBuffer->BindDescriptorSet(descriptorSet);
16317
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016318 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes5533bfc2016-07-27 14:12:34 +120016319 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016320 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes5533bfc2016-07-27 14:12:34 +120016321 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16322
16323 // error produced here.
16324 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
16325
16326 m_errorMonitor->VerifyFound();
16327
Tony Barbour552f6c02016-12-21 14:34:07 -070016328 m_commandBuffer->EndRenderPass();
16329 m_commandBuffer->EndCommandBuffer();
Chris Forbes5533bfc2016-07-27 14:12:34 +120016330}
16331
Mark Youngc48c4c12016-04-11 14:26:49 -060016332TEST_F(VkLayerTest, CreateImageLimitsViolationMaxWidth) {
Tony Barbour1fa09702017-03-16 12:09:08 -060016333 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060016334
Jeremy Hayesbb63cc12017-03-20 15:33:01 -060016335 VkFormat const format = VK_FORMAT_B8G8R8A8_UNORM;
16336 {
16337 VkFormatProperties properties;
16338 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), format, &properties);
16339 if (properties.optimalTilingFeatures == 0) {
16340 printf(" Image format not supported; skipped.\n");
16341 return;
16342 }
16343 }
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060016344
Jeremy Hayesbb63cc12017-03-20 15:33:01 -060016345 VkImageCreateInfo info = {};
16346 info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16347 info.pNext = NULL;
16348 info.imageType = VK_IMAGE_TYPE_2D;
16349 info.format = format;
16350 info.extent.height = 32;
16351 info.extent.depth = 1;
16352 info.mipLevels = 1;
16353 info.arrayLayers = 1;
16354 info.samples = VK_SAMPLE_COUNT_1_BIT;
16355 info.tiling = VK_IMAGE_TILING_OPTIMAL;
16356 info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
16357 info.flags = 0;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060016358
16359 // Introduce error by sending down a bogus width extent
Jeremy Hayesbb63cc12017-03-20 15:33:01 -060016360 {
16361 VkImageFormatProperties properties;
16362 auto const result = vkGetPhysicalDeviceImageFormatProperties(m_device->phy().handle(), info.format, info.imageType,
16363 info.tiling, info.usage, info.flags, &properties);
16364 ASSERT_VK_SUCCESS(result);
16365 info.extent.width = properties.maxExtent.width + 1;
16366 }
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060016367
Jeremy Hayesbb63cc12017-03-20 15:33:01 -060016368 VkImage image;
16369 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
16370 vkCreateImage(m_device->device(), &info, NULL, &image);
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016371 m_errorMonitor->VerifyFound();
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060016372}
16373
Mark Youngc48c4c12016-04-11 14:26:49 -060016374TEST_F(VkLayerTest, CreateImageLimitsViolationMinWidth) {
Tony Barbour1fa09702017-03-16 12:09:08 -060016375 ASSERT_NO_FATAL_FAILURE(Init());
Mark Youngc48c4c12016-04-11 14:26:49 -060016376
Jeremy Hayesbb63cc12017-03-20 15:33:01 -060016377 VkFormat const format = VK_FORMAT_B8G8R8A8_UNORM;
16378 {
16379 VkFormatProperties properties;
16380 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), format, &properties);
16381 if (properties.optimalTilingFeatures == 0) {
16382 printf(" Image format not supported; skipped.\n");
16383 return;
16384 }
16385 }
Mark Youngc48c4c12016-04-11 14:26:49 -060016386
Jeremy Hayesbb63cc12017-03-20 15:33:01 -060016387 VkImageCreateInfo info = {};
16388 info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16389 info.pNext = NULL;
16390 info.imageType = VK_IMAGE_TYPE_2D;
16391 info.format = format;
16392 info.extent.height = 32;
16393 info.extent.depth = 1;
16394 info.mipLevels = 1;
16395 info.arrayLayers = 1;
16396 info.samples = VK_SAMPLE_COUNT_1_BIT;
16397 info.tiling = VK_IMAGE_TILING_OPTIMAL;
16398 info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
16399 info.flags = 0;
Mark Youngc48c4c12016-04-11 14:26:49 -060016400
16401 // Introduce error by sending down a bogus width extent
Jeremy Hayesbb63cc12017-03-20 15:33:01 -060016402 info.extent.width = 0;
Mark Youngc48c4c12016-04-11 14:26:49 -060016403
Jeremy Hayesbb63cc12017-03-20 15:33:01 -060016404 VkImage image;
Tobin Ehlisa55b1d42017-04-04 12:23:48 -060016405 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02917);
Jeremy Hayesbb63cc12017-03-20 15:33:01 -060016406 m_errorMonitor->SetUnexpectedError("parameter pCreateInfo->extent.width must be greater than 0");
16407 vkCreateImage(m_device->device(), &info, NULL, &image);
Mark Youngc48c4c12016-04-11 14:26:49 -060016408 m_errorMonitor->VerifyFound();
16409}
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -070016410
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060016411TEST_F(VkLayerTest, AttachmentDescriptionUndefinedFormat) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016412 TEST_DESCRIPTION(
16413 "Create a render pass with an attachment description "
16414 "format set to VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060016415
Tony Barbour1fa09702017-03-16 12:09:08 -060016416 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060016417 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16418
Jeremy Hayes632e0ab2017-02-09 13:32:28 -070016419 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "format is VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060016420
16421 VkAttachmentReference color_attach = {};
16422 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
16423 color_attach.attachment = 0;
16424 VkSubpassDescription subpass = {};
16425 subpass.colorAttachmentCount = 1;
16426 subpass.pColorAttachments = &color_attach;
16427
16428 VkRenderPassCreateInfo rpci = {};
16429 rpci.subpassCount = 1;
16430 rpci.pSubpasses = &subpass;
16431 rpci.attachmentCount = 1;
16432 VkAttachmentDescription attach_desc = {};
16433 attach_desc.format = VK_FORMAT_UNDEFINED;
16434 rpci.pAttachments = &attach_desc;
16435 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
16436 VkRenderPass rp;
16437 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
16438
16439 m_errorMonitor->VerifyFound();
16440
16441 if (result == VK_SUCCESS) {
16442 vkDestroyRenderPass(m_device->device(), rp, NULL);
16443 }
16444}
16445
Karl Schultz6addd812016-02-02 17:17:23 -070016446TEST_F(VkLayerTest, InvalidImageView) {
Tony Barbour1fa09702017-03-16 12:09:08 -060016447 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehliscde08892015-09-22 10:11:37 -060016448
Mike Stroyana3082432015-09-25 13:39:21 -060016449 // Create an image and try to create a view with bad baseMipLevel
Karl Schultz6addd812016-02-02 17:17:23 -070016450 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
16451 const int32_t tex_width = 32;
16452 const int32_t tex_height = 32;
Tobin Ehliscde08892015-09-22 10:11:37 -060016453
16454 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016455 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16456 image_create_info.pNext = NULL;
16457 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16458 image_create_info.format = tex_format;
16459 image_create_info.extent.width = tex_width;
16460 image_create_info.extent.height = tex_height;
16461 image_create_info.extent.depth = 1;
16462 image_create_info.mipLevels = 1;
16463 image_create_info.arrayLayers = 1;
16464 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16465 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16466 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
16467 image_create_info.flags = 0;
Tobin Ehliscde08892015-09-22 10:11:37 -060016468
Jeremy Hayesa1ffc2b2017-03-10 16:05:37 -070016469 VkImage image;
16470 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehliscde08892015-09-22 10:11:37 -060016471 ASSERT_VK_SUCCESS(err);
16472
Jeremy Hayesa1ffc2b2017-03-10 16:05:37 -070016473 VkMemoryRequirements requirements;
16474 vkGetImageMemoryRequirements(m_device->device(), image, &requirements);
16475
16476 VkMemoryAllocateInfo alloc_info{};
16477 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16478 alloc_info.pNext = NULL;
16479 alloc_info.memoryTypeIndex = 0;
16480 alloc_info.allocationSize = requirements.size;
16481 bool pass = m_device->phy().set_memory_type(requirements.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
16482 ASSERT_TRUE(pass);
16483
16484 VkDeviceMemory memory;
16485 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &memory);
16486 ASSERT_VK_SUCCESS(err);
16487
16488 err = vkBindImageMemory(m_device->device(), image, memory, 0);
16489
Tobin Ehliscde08892015-09-22 10:11:37 -060016490 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130016491 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070016492 image_view_create_info.image = image;
16493 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
16494 image_view_create_info.format = tex_format;
16495 image_view_create_info.subresourceRange.layerCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016496 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
Karl Schultz6addd812016-02-02 17:17:23 -070016497 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016498 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehliscde08892015-09-22 10:11:37 -060016499
16500 VkImageView view;
Jeremy Hayesa1ffc2b2017-03-10 16:05:37 -070016501 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016502 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016503 m_errorMonitor->VerifyFound();
Jeremy Hayesa1ffc2b2017-03-10 16:05:37 -070016504
16505 vkFreeMemory(m_device->device(), memory, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -060016506 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehliscde08892015-09-22 10:11:37 -060016507}
Mike Stroyana3082432015-09-25 13:39:21 -060016508
Mark Youngd339ba32016-05-30 13:28:35 -060016509TEST_F(VkLayerTest, CreateImageViewNoMemoryBoundToImage) {
16510 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -060016511 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -060016512 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -060016513
Tony Barbour1fa09702017-03-16 12:09:08 -060016514 ASSERT_NO_FATAL_FAILURE(Init());
Mark Youngd339ba32016-05-30 13:28:35 -060016515
16516 // Create an image and try to create a view with no memory backing the image
16517 VkImage image;
16518
16519 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
16520 const int32_t tex_width = 32;
16521 const int32_t tex_height = 32;
16522
16523 VkImageCreateInfo image_create_info = {};
16524 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16525 image_create_info.pNext = NULL;
16526 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16527 image_create_info.format = tex_format;
16528 image_create_info.extent.width = tex_width;
16529 image_create_info.extent.height = tex_height;
16530 image_create_info.extent.depth = 1;
16531 image_create_info.mipLevels = 1;
16532 image_create_info.arrayLayers = 1;
16533 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16534 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16535 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
16536 image_create_info.flags = 0;
16537
16538 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
16539 ASSERT_VK_SUCCESS(err);
16540
16541 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130016542 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Mark Youngd339ba32016-05-30 13:28:35 -060016543 image_view_create_info.image = image;
16544 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
16545 image_view_create_info.format = tex_format;
16546 image_view_create_info.subresourceRange.layerCount = 1;
16547 image_view_create_info.subresourceRange.baseMipLevel = 0;
16548 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016549 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -060016550
16551 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016552 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Youngd339ba32016-05-30 13:28:35 -060016553
16554 m_errorMonitor->VerifyFound();
16555 vkDestroyImage(m_device->device(), image, NULL);
16556 // If last error is success, it still created the view, so delete it.
16557 if (err == VK_SUCCESS) {
16558 vkDestroyImageView(m_device->device(), view, NULL);
16559 }
Mark Youngd339ba32016-05-30 13:28:35 -060016560}
16561
Karl Schultz6addd812016-02-02 17:17:23 -070016562TEST_F(VkLayerTest, InvalidImageViewAspect) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016563 TEST_DESCRIPTION("Create an image and try to create a view with an invalid aspectMask");
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070016564 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00741);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016565
Tony Barbour1fa09702017-03-16 12:09:08 -060016566 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060016567
Karl Schultz6addd812016-02-02 17:17:23 -070016568 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060016569 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060016570 image.Init(32, 32, 1, tex_format, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_LINEAR, 0);
Tobin Ehlis1f567a22016-05-25 16:15:18 -060016571 ASSERT_TRUE(image.initialized());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060016572
16573 VkImageViewCreateInfo image_view_create_info = {};
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060016574 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060016575 image_view_create_info.image = image.handle();
Karl Schultz6addd812016-02-02 17:17:23 -070016576 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
16577 image_view_create_info.format = tex_format;
16578 image_view_create_info.subresourceRange.baseMipLevel = 0;
16579 image_view_create_info.subresourceRange.levelCount = 1;
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060016580 image_view_create_info.subresourceRange.layerCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070016581 // Cause an error by setting an invalid image aspect
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016582 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060016583
16584 VkImageView view;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060016585 vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060016586
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016587 m_errorMonitor->VerifyFound();
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060016588}
16589
Mike Weiblena1e13f42017-02-09 21:25:59 -070016590TEST_F(VkLayerTest, ExerciseGetImageSubresourceLayout) {
16591 TEST_DESCRIPTION("Test vkGetImageSubresourceLayout() valid usages");
16592
Tony Barbour1fa09702017-03-16 12:09:08 -060016593 ASSERT_NO_FATAL_FAILURE(Init());
Mike Weiblena1e13f42017-02-09 21:25:59 -070016594 VkSubresourceLayout subres_layout = {};
16595
16596 // VU 00732: image must have been created with tiling equal to VK_IMAGE_TILING_LINEAR
16597 {
16598 const VkImageTiling tiling = VK_IMAGE_TILING_OPTIMAL; // ERROR: violates VU 00732
16599 VkImageObj img(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060016600 img.InitNoLayout(32, 32, 1, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, tiling);
Mike Weiblena1e13f42017-02-09 21:25:59 -070016601 ASSERT_TRUE(img.initialized());
16602
16603 VkImageSubresource subres = {};
16604 subres.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16605 subres.mipLevel = 0;
16606 subres.arrayLayer = 0;
16607
16608 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00732);
16609 vkGetImageSubresourceLayout(m_device->device(), img.image(), &subres, &subres_layout);
16610 m_errorMonitor->VerifyFound();
16611 }
16612
16613 // VU 00733: The aspectMask member of pSubresource must only have a single bit set
16614 {
16615 VkImageObj img(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060016616 img.InitNoLayout(32, 32, 1, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
Mike Weiblena1e13f42017-02-09 21:25:59 -070016617 ASSERT_TRUE(img.initialized());
16618
16619 VkImageSubresource subres = {};
16620 subres.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_METADATA_BIT; // ERROR: triggers VU 00733
16621 subres.mipLevel = 0;
16622 subres.arrayLayer = 0;
16623
16624 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00733);
16625 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00741);
16626 vkGetImageSubresourceLayout(m_device->device(), img.image(), &subres, &subres_layout);
16627 m_errorMonitor->VerifyFound();
16628 }
16629
16630 // 00739 mipLevel must be less than the mipLevels specified in VkImageCreateInfo when the image was created
16631 {
16632 VkImageObj img(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060016633 img.InitNoLayout(32, 32, 1, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
Mike Weiblena1e13f42017-02-09 21:25:59 -070016634 ASSERT_TRUE(img.initialized());
16635
16636 VkImageSubresource subres = {};
16637 subres.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16638 subres.mipLevel = 1; // ERROR: triggers VU 00739
16639 subres.arrayLayer = 0;
16640
16641 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00739);
16642 vkGetImageSubresourceLayout(m_device->device(), img.image(), &subres, &subres_layout);
16643 m_errorMonitor->VerifyFound();
16644 }
16645
16646 // 00740 arrayLayer must be less than the arrayLayers specified in VkImageCreateInfo when the image was created
16647 {
16648 VkImageObj img(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060016649 img.InitNoLayout(32, 32, 1, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
Mike Weiblena1e13f42017-02-09 21:25:59 -070016650 ASSERT_TRUE(img.initialized());
16651
16652 VkImageSubresource subres = {};
16653 subres.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16654 subres.mipLevel = 0;
16655 subres.arrayLayer = 1; // ERROR: triggers VU 00740
16656
16657 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00740);
16658 vkGetImageSubresourceLayout(m_device->device(), img.image(), &subres, &subres_layout);
16659 m_errorMonitor->VerifyFound();
16660 }
16661}
16662
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016663TEST_F(VkLayerTest, CopyImageLayerCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -070016664 VkResult err;
16665 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016666
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070016667 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01198);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016668
Tony Barbour1fa09702017-03-16 12:09:08 -060016669 ASSERT_NO_FATAL_FAILURE(Init());
Mike Stroyana3082432015-09-25 13:39:21 -060016670
16671 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070016672 VkImage srcImage;
16673 VkImage dstImage;
16674 VkDeviceMemory srcMem;
16675 VkDeviceMemory destMem;
16676 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016677
16678 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016679 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16680 image_create_info.pNext = NULL;
16681 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16682 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16683 image_create_info.extent.width = 32;
16684 image_create_info.extent.height = 32;
16685 image_create_info.extent.depth = 1;
16686 image_create_info.mipLevels = 1;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016687 image_create_info.arrayLayers = 4;
Karl Schultz6addd812016-02-02 17:17:23 -070016688 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16689 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16690 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16691 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016692
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016693 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016694 ASSERT_VK_SUCCESS(err);
16695
Mark Lobodzinski867787a2016-10-14 11:49:55 -060016696 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016697 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016698 ASSERT_VK_SUCCESS(err);
16699
16700 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016701 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016702 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16703 memAlloc.pNext = NULL;
16704 memAlloc.allocationSize = 0;
16705 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016706
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060016707 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016708 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016709 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016710 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016711 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016712 ASSERT_VK_SUCCESS(err);
16713
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016714 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016715 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016716 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016717 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016718 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016719 ASSERT_VK_SUCCESS(err);
16720
16721 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16722 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016723 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016724 ASSERT_VK_SUCCESS(err);
16725
Tony Barbour552f6c02016-12-21 14:34:07 -070016726 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060016727 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016728 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016729 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060016730 copyRegion.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016731 copyRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060016732 copyRegion.srcOffset.x = 0;
16733 copyRegion.srcOffset.y = 0;
16734 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016735 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016736 copyRegion.dstSubresource.mipLevel = 0;
16737 copyRegion.dstSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016738 // Introduce failure by forcing the dst layerCount to differ from src
16739 copyRegion.dstSubresource.layerCount = 3;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016740 copyRegion.dstOffset.x = 0;
16741 copyRegion.dstOffset.y = 0;
16742 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016743 copyRegion.extent.width = 1;
16744 copyRegion.extent.height = 1;
16745 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016746 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070016747 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060016748
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016749 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060016750
Chia-I Wuf7458c52015-10-26 21:10:41 +080016751 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016752 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016753 vkFreeMemory(m_device->device(), srcMem, NULL);
16754 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016755}
16756
Tony Barbourd6673642016-05-05 14:46:39 -060016757TEST_F(VkLayerTest, ImageLayerUnsupportedFormat) {
Tony Barbourd6673642016-05-05 14:46:39 -060016758 TEST_DESCRIPTION("Creating images with unsuported formats ");
16759
Tony Barbour1fa09702017-03-16 12:09:08 -060016760 ASSERT_NO_FATAL_FAILURE(Init());
Tony Barbourd6673642016-05-05 14:46:39 -060016761 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourd6673642016-05-05 14:46:39 -060016762
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060016763 // Create image with unsupported format - Expect FORMAT_UNSUPPORTED
Chris Forbesf4d8e332016-11-28 17:51:10 +130016764 VkImageCreateInfo image_create_info = {};
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060016765 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060016766 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16767 image_create_info.format = VK_FORMAT_UNDEFINED;
16768 image_create_info.extent.width = 32;
16769 image_create_info.extent.height = 32;
16770 image_create_info.extent.depth = 1;
16771 image_create_info.mipLevels = 1;
16772 image_create_info.arrayLayers = 1;
16773 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16774 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16775 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060016776
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016777 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16778 "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED");
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060016779
Jeremy Hayes96dcd812017-03-14 14:04:19 -060016780 VkImage image;
16781 vkCreateImage(m_device->handle(), &image_create_info, NULL, &image);
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060016782 m_errorMonitor->VerifyFound();
16783
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060016784 // Look for a format that is COMPLETELY unsupported with this hardware
Jeremy Hayes96dcd812017-03-14 14:04:19 -060016785 VkFormat unsupported = VK_FORMAT_UNDEFINED;
Tony Barbourd6673642016-05-05 14:46:39 -060016786 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
16787 VkFormat format = static_cast<VkFormat>(f);
16788 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016789 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Tony Barbourd6673642016-05-05 14:46:39 -060016790 unsupported = format;
16791 break;
16792 }
16793 }
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060016794
Tony Barbourd6673642016-05-05 14:46:39 -060016795 if (unsupported != VK_FORMAT_UNDEFINED) {
Tony Barbourd6673642016-05-05 14:46:39 -060016796 image_create_info.format = unsupported;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016797 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is an unsupported format");
Tony Barbourd6673642016-05-05 14:46:39 -060016798
Jeremy Hayes96dcd812017-03-14 14:04:19 -060016799 vkCreateImage(m_device->handle(), &image_create_info, NULL, &image);
Tony Barbourd6673642016-05-05 14:46:39 -060016800 m_errorMonitor->VerifyFound();
16801 }
16802}
16803
16804TEST_F(VkLayerTest, ImageLayerViewTests) {
Tony Barbourd6673642016-05-05 14:46:39 -060016805 TEST_DESCRIPTION("Passing bad parameters to CreateImageView");
16806
Tony Barbour1fa09702017-03-16 12:09:08 -060016807 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -060016808 auto depth_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbourf887b162017-03-09 10:06:46 -070016809 if (!depth_format) {
16810 return;
16811 }
Tony Barbourd6673642016-05-05 14:46:39 -060016812
16813 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060016814 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 -060016815 VK_IMAGE_TILING_OPTIMAL, 0);
16816 ASSERT_TRUE(image.initialized());
16817
16818 VkImageView imgView;
16819 VkImageViewCreateInfo imgViewInfo = {};
16820 imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
16821 imgViewInfo.image = image.handle();
16822 imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
16823 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
16824 imgViewInfo.subresourceRange.layerCount = 1;
16825 imgViewInfo.subresourceRange.baseMipLevel = 0;
16826 imgViewInfo.subresourceRange.levelCount = 1;
16827 imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16828
Jeremy Hayes2ffbaa72017-03-14 17:05:50 -060016829 // View can't have baseMipLevel >= image's mipLevels - Expect VIEW_CREATE_ERROR
Tony Barbourd6673642016-05-05 14:46:39 -060016830 imgViewInfo.subresourceRange.baseMipLevel = 1;
Jeremy Hayes2ffbaa72017-03-14 17:05:50 -060016831 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
Tony Barbourd6673642016-05-05 14:46:39 -060016832 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
16833 m_errorMonitor->VerifyFound();
16834 imgViewInfo.subresourceRange.baseMipLevel = 0;
16835
Tony Barbourd6673642016-05-05 14:46:39 -060016836 // View's levelCount can't be 0 - Expect VIEW_CREATE_ERROR
16837 imgViewInfo.subresourceRange.levelCount = 0;
Jeremy Hayes2ffbaa72017-03-14 17:05:50 -060016838 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
Tony Barbourd6673642016-05-05 14:46:39 -060016839 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
16840 m_errorMonitor->VerifyFound();
16841 imgViewInfo.subresourceRange.levelCount = 1;
16842
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060016843 // View's levelCount can't be > image's mipLevels - Expect VIEW_CREATE_ERROR
16844 imgViewInfo.subresourceRange.levelCount = 2;
16845 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
16846 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
16847 m_errorMonitor->VerifyFound();
16848 imgViewInfo.subresourceRange.levelCount = 1;
16849
16850 // View can't have baseArrayLayer >= image's arraySize - Expect VIEW_CREATE_ERROR
16851 imgViewInfo.subresourceRange.baseArrayLayer = 1;
16852 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00769);
16853 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
16854 m_errorMonitor->VerifyFound();
16855 imgViewInfo.subresourceRange.baseArrayLayer = 0;
16856
Jeremy Hayes2ffbaa72017-03-14 17:05:50 -060016857 // View's layerCount can't be 0 - Expect VIEW_CREATE_ERROR
16858 imgViewInfo.subresourceRange.layerCount = 0;
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060016859 m_errorMonitor->SetDesiredFailureMsg(
16860 VK_DEBUG_REPORT_ERROR_BIT_EXT,
16861 "if pCreateInfo->viewType is VK_IMAGE_TYPE_2D, pCreateInfo->subresourceRange.layerCount must be 1");
Tony Barbourd6673642016-05-05 14:46:39 -060016862 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
16863 m_errorMonitor->VerifyFound();
16864 imgViewInfo.subresourceRange.layerCount = 1;
16865
Tony Barbourd6673642016-05-05 14:46:39 -060016866 // Can't use depth format for view into color image - Expect INVALID_FORMAT
Tony Barbourf887b162017-03-09 10:06:46 -070016867 imgViewInfo.format = depth_format;
Jeremy Hayes2ffbaa72017-03-14 17:05:50 -060016868 m_errorMonitor->SetDesiredFailureMsg(
16869 VK_DEBUG_REPORT_ERROR_BIT_EXT,
16870 "Formats MUST be IDENTICAL unless VK_IMAGE_CREATE_MUTABLE_FORMAT BIT was set on image creation.");
Tony Barbourd6673642016-05-05 14:46:39 -060016871 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
16872 m_errorMonitor->VerifyFound();
16873 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
16874
Tony Barbourd6673642016-05-05 14:46:39 -060016875 // Same compatibility class but no MUTABLE_FORMAT bit - Expect
16876 // VIEW_CREATE_ERROR
16877 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UINT;
Jeremy Hayes2ffbaa72017-03-14 17:05:50 -060016878 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02172);
Tony Barbourd6673642016-05-05 14:46:39 -060016879 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
16880 m_errorMonitor->VerifyFound();
16881 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
16882
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060016883 // TODO: Update framework to easily passing mutable flag into ImageObj init
16884 // For now just allowing image for this one test to not have memory bound
Jeremy Hayes5a7cf2e2017-01-06 15:23:27 -070016885 // TODO: The following line is preventing the intended validation from occurring because of the way the error monitor works.
16886 // m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16887 // " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Tony Barbourd6673642016-05-05 14:46:39 -060016888 // Have MUTABLE_FORMAT bit but not in same compatibility class - Expect
16889 // VIEW_CREATE_ERROR
16890 VkImageCreateInfo mutImgInfo = image.create_info();
16891 VkImage mutImage;
16892 mutImgInfo.format = VK_FORMAT_R8_UINT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016893 assert(m_device->format_properties(VK_FORMAT_R8_UINT).optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
Tony Barbourd6673642016-05-05 14:46:39 -060016894 mutImgInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
16895 mutImgInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Jeremy Hayes2ffbaa72017-03-14 17:05:50 -060016896 VkResult ret = vkCreateImage(m_device->handle(), &mutImgInfo, NULL, &mutImage);
Tony Barbourd6673642016-05-05 14:46:39 -060016897 ASSERT_VK_SUCCESS(ret);
Jeremy Hayes2ffbaa72017-03-14 17:05:50 -060016898
16899 VkMemoryRequirements requirements;
16900 vkGetImageMemoryRequirements(m_device->device(), mutImage, &requirements);
16901
16902 VkMemoryAllocateInfo alloc_info{};
16903 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16904 alloc_info.pNext = NULL;
16905 alloc_info.memoryTypeIndex = 0;
16906 alloc_info.allocationSize = requirements.size;
16907 bool pass = m_device->phy().set_memory_type(requirements.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
16908 ASSERT_TRUE(pass);
16909
16910 VkDeviceMemory memory;
16911 ret = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &memory);
16912 ASSERT_VK_SUCCESS(ret);
16913
16914 ret = vkBindImageMemory(m_device->device(), mutImage, memory, 0);
16915 ASSERT_VK_SUCCESS(ret);
16916
Tony Barbourd6673642016-05-05 14:46:39 -060016917 imgViewInfo.image = mutImage;
Jeremy Hayes2ffbaa72017-03-14 17:05:50 -060016918 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02171);
Tony Barbourd6673642016-05-05 14:46:39 -060016919 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
16920 m_errorMonitor->VerifyFound();
16921 imgViewInfo.image = image.handle();
Jeremy Hayes2ffbaa72017-03-14 17:05:50 -060016922
16923 vkFreeMemory(m_device->device(), memory, NULL);
Tony Barbourd6673642016-05-05 14:46:39 -060016924 vkDestroyImage(m_device->handle(), mutImage, NULL);
16925}
16926
Dave Houlton75967fc2017-03-06 17:21:16 -070016927TEST_F(VkLayerTest, CompressedImageMipCopyTests) {
16928 TEST_DESCRIPTION("Image/Buffer copies for higher mip levels");
16929
Tony Barbour1fa09702017-03-16 12:09:08 -060016930 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton75967fc2017-03-06 17:21:16 -070016931
Jamie Madill35127872017-03-15 16:17:46 -040016932 VkPhysicalDeviceFeatures device_features = {};
Dave Houlton75967fc2017-03-06 17:21:16 -070016933 ASSERT_NO_FATAL_FAILURE(GetPhysicalDeviceFeatures(&device_features));
16934 VkFormat compressed_format = VK_FORMAT_UNDEFINED;
16935 if (device_features.textureCompressionBC) {
16936 compressed_format = VK_FORMAT_BC3_SRGB_BLOCK;
16937 } else if (device_features.textureCompressionETC2) {
16938 compressed_format = VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK;
16939 } else if (device_features.textureCompressionASTC_LDR) {
16940 compressed_format = VK_FORMAT_ASTC_4x4_UNORM_BLOCK;
16941 } else {
16942 printf(" No compressed formats supported - CompressedImageMipCopyTests skipped.\n");
16943 return;
16944 }
16945
16946 VkImageCreateInfo ci;
16947 ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16948 ci.pNext = NULL;
16949 ci.flags = 0;
16950 ci.imageType = VK_IMAGE_TYPE_2D;
16951 ci.format = compressed_format;
16952 ci.extent = {32, 32, 1};
16953 ci.mipLevels = 6;
16954 ci.arrayLayers = 1;
16955 ci.samples = VK_SAMPLE_COUNT_1_BIT;
16956 ci.tiling = VK_IMAGE_TILING_OPTIMAL;
16957 ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
16958 ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
16959 ci.queueFamilyIndexCount = 0;
16960 ci.pQueueFamilyIndices = NULL;
16961 ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
16962
16963 VkImageObj image(m_device);
16964 image.init(&ci);
16965 ASSERT_TRUE(image.initialized());
16966
16967 VkImageObj odd_image(m_device);
16968 ci.extent = {31, 32, 1}; // Mips are [31,32] [15,16] [7,8] [3,4], [1,2] [1,1]
16969 odd_image.init(&ci);
16970 ASSERT_TRUE(odd_image.initialized());
16971
16972 // Allocate buffers
16973 VkMemoryPropertyFlags reqs = 0;
16974 vk_testing::Buffer buffer_1024, buffer_64, buffer_16, buffer_8;
16975 buffer_1024.init_as_src_and_dst(*m_device, 1024, reqs);
16976 buffer_64.init_as_src_and_dst(*m_device, 64, reqs);
16977 buffer_16.init_as_src_and_dst(*m_device, 16, reqs);
16978 buffer_8.init_as_src_and_dst(*m_device, 8, reqs);
16979
16980 VkBufferImageCopy region = {};
16981 region.bufferRowLength = 0;
16982 region.bufferImageHeight = 0;
16983 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16984 region.imageSubresource.layerCount = 1;
16985 region.imageOffset = {0, 0, 0};
16986 region.bufferOffset = 0;
16987
16988 // start recording
16989 m_commandBuffer->BeginCommandBuffer();
16990
16991 // Mip level copies that work - 5 levels
16992 m_errorMonitor->ExpectSuccess();
16993
16994 // Mip 0 should fit in 1k buffer - 1k texels @ 1b each
16995 region.imageExtent = {32, 32, 1};
16996 region.imageSubresource.mipLevel = 0;
16997 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_1024.handle(), 1,
16998 &region);
16999 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_1024.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17000 &region);
17001
17002 // Mip 2 should fit in 64b buffer - 64 texels @ 1b each
17003 region.imageExtent = {8, 8, 1};
17004 region.imageSubresource.mipLevel = 2;
17005 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_64.handle(), 1,
17006 &region);
17007 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17008 &region);
17009
17010 // Mip 3 should fit in 16b buffer - 16 texels @ 1b each
17011 region.imageExtent = {4, 4, 1};
17012 region.imageSubresource.mipLevel = 3;
17013 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
17014 &region);
17015 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17016 &region);
17017
17018 // Mip 4&5 should fit in 16b buffer with no complaint - 4 & 1 texels @ 1b each
17019 region.imageExtent = {2, 2, 1};
17020 region.imageSubresource.mipLevel = 4;
17021 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
17022 &region);
17023 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17024 &region);
17025
17026 region.imageExtent = {1, 1, 1};
17027 region.imageSubresource.mipLevel = 5;
17028 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
17029 &region);
17030 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17031 &region);
17032 m_errorMonitor->VerifyNotFound();
17033
17034 // Buffer must accomodate a full compressed block, regardless of texel count
17035 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01246);
17036 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_8.handle(), 1,
17037 &region);
17038 m_errorMonitor->VerifyFound();
17039 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01227);
17040 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_8.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17041 &region);
17042 m_errorMonitor->VerifyFound();
17043
17044 // Copy width < compressed block size, but not the full mip width
17045 region.imageExtent = {1, 2, 1};
17046 region.imageSubresource.mipLevel = 4;
17047 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01275);
17048 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
17049 &region);
17050 m_errorMonitor->VerifyFound();
17051 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01275);
17052 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17053 &region);
17054 m_errorMonitor->VerifyFound();
17055
17056 // Copy height < compressed block size but not the full mip height
17057 region.imageExtent = {2, 1, 1};
17058 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01276);
17059 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
17060 &region);
17061 m_errorMonitor->VerifyFound();
17062 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01276);
17063 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17064 &region);
17065 m_errorMonitor->VerifyFound();
17066
17067 // Offsets must be multiple of compressed block size
17068 region.imageOffset = {1, 1, 0};
17069 region.imageExtent = {1, 1, 1};
17070 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01273);
17071 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
17072 &region);
17073 m_errorMonitor->VerifyFound();
17074 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01273);
17075 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17076 &region);
17077 m_errorMonitor->VerifyFound();
17078
17079 // Offset + extent width = mip width - should succeed
17080 region.imageOffset = {4, 4, 0};
17081 region.imageExtent = {3, 4, 1};
17082 region.imageSubresource.mipLevel = 2;
17083 m_errorMonitor->ExpectSuccess();
17084 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), odd_image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
17085 &region);
17086 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), odd_image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17087 &region);
17088 m_errorMonitor->VerifyNotFound();
17089
17090 // Offset + extent width > mip width, but still within the final compressed block - should succeed
17091 region.imageExtent = {4, 4, 1};
17092 m_errorMonitor->ExpectSuccess();
17093 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), odd_image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
17094 &region);
17095 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), odd_image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17096 &region);
17097 m_errorMonitor->VerifyNotFound();
17098
17099 // Offset + extent width < mip width and not a multiple of block width - should fail
17100 region.imageExtent = {3, 3, 1};
17101 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01276);
17102 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), odd_image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
17103 &region);
17104 m_errorMonitor->VerifyFound();
17105 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01276);
17106 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), odd_image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17107 &region);
17108 m_errorMonitor->VerifyFound();
17109}
17110
Dave Houlton59a20702017-02-02 17:26:23 -070017111TEST_F(VkLayerTest, ImageBufferCopyTests) {
17112 TEST_DESCRIPTION("Image to buffer and buffer to image tests");
17113
Tony Barbour1fa09702017-03-16 12:09:08 -060017114 ASSERT_NO_FATAL_FAILURE(Init());
Tony Barbourf887b162017-03-09 10:06:46 -070017115 VkFormatProperties format_props = m_device->format_properties(VK_FORMAT_D24_UNORM_S8_UINT);
17116 if (!(format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT)) {
17117 printf(" VK_FORMAT_D24_UNORM_S8_UINT not supported. Skipped.\n");
17118 return;
17119 }
Dave Houlton584d51e2017-02-16 12:52:54 -070017120
17121 // Bail if any dimension of transfer granularity is 0.
17122 auto index = m_device->graphics_queue_node_index_;
17123 auto queue_family_properties = m_device->phy().queue_properties();
17124 if ((queue_family_properties[index].minImageTransferGranularity.depth == 0) ||
17125 (queue_family_properties[index].minImageTransferGranularity.width == 0) ||
17126 (queue_family_properties[index].minImageTransferGranularity.height == 0)) {
17127 printf(" Subresource copies are disallowed when xfer granularity (x|y|z) is 0. Skipped.\n");
17128 return;
17129 }
17130
Dave Houlton59a20702017-02-02 17:26:23 -070017131 VkImageObj image_64k(m_device); // 128^2 texels, 64k
17132 VkImageObj image_16k(m_device); // 64^2 texels, 16k
17133 VkImageObj image_16k_depth(m_device); // 64^2 texels, depth, 16k
Dave Houltonf3229d52017-02-21 15:59:08 -070017134 VkImageObj ds_image_4D_1S(m_device); // 256^2 texels, 512kb (256k depth, 64k stencil, 192k pack)
17135 VkImageObj ds_image_3D_1S(m_device); // 256^2 texels, 256kb (192k depth, 64k stencil)
17136 VkImageObj ds_image_2D(m_device); // 256^2 texels, 128k (128k depth)
17137 VkImageObj ds_image_1S(m_device); // 256^2 texels, 64k (64k stencil)
17138
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017139 image_64k.Init(128, 128, 1, VK_FORMAT_R8G8B8A8_UINT,
Dave Houlton59a20702017-02-02 17:26:23 -070017140 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
17141 VK_IMAGE_TILING_OPTIMAL, 0);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017142 image_16k.Init(64, 64, 1, VK_FORMAT_R8G8B8A8_UINT,
Dave Houlton59a20702017-02-02 17:26:23 -070017143 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
17144 VK_IMAGE_TILING_OPTIMAL, 0);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017145 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 -070017146 VK_IMAGE_TILING_OPTIMAL, 0);
Dave Houlton59a20702017-02-02 17:26:23 -070017147 ASSERT_TRUE(image_64k.initialized());
17148 ASSERT_TRUE(image_16k.initialized());
17149 ASSERT_TRUE(image_16k_depth.initialized());
Dave Houlton59a20702017-02-02 17:26:23 -070017150
Dave Houltonf3229d52017-02-21 15:59:08 -070017151 // Verify all needed Depth/Stencil formats are supported
17152 bool missing_ds_support = false;
17153 VkFormatProperties props = {0, 0, 0};
17154 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D32_SFLOAT_S8_UINT, &props);
17155 missing_ds_support |= (props.bufferFeatures == 0 && props.linearTilingFeatures == 0 && props.optimalTilingFeatures == 0);
17156 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D24_UNORM_S8_UINT, &props);
17157 missing_ds_support |= (props.bufferFeatures == 0 && props.linearTilingFeatures == 0 && props.optimalTilingFeatures == 0);
17158 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D16_UNORM, &props);
17159 missing_ds_support |= (props.bufferFeatures == 0 && props.linearTilingFeatures == 0 && props.optimalTilingFeatures == 0);
17160 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_S8_UINT, &props);
17161 missing_ds_support |= (props.bufferFeatures == 0 && props.linearTilingFeatures == 0 && props.optimalTilingFeatures == 0);
17162
17163 if (!missing_ds_support) {
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017164 ds_image_4D_1S.Init(
17165 256, 256, 1, VK_FORMAT_D32_SFLOAT_S8_UINT,
Dave Houltonf3229d52017-02-21 15:59:08 -070017166 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
17167 VK_IMAGE_TILING_OPTIMAL, 0);
17168 ASSERT_TRUE(ds_image_4D_1S.initialized());
17169
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017170 ds_image_3D_1S.Init(
17171 256, 256, 1, VK_FORMAT_D24_UNORM_S8_UINT,
Dave Houltonf3229d52017-02-21 15:59:08 -070017172 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
17173 VK_IMAGE_TILING_OPTIMAL, 0);
17174 ASSERT_TRUE(ds_image_3D_1S.initialized());
17175
Dave Houlton11dcd5e2017-04-25 16:00:10 -060017176 ds_image_2D.Init(
17177 256, 256, 1, VK_FORMAT_D16_UNORM,
17178 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
17179 VK_IMAGE_TILING_OPTIMAL, 0);
Dave Houltonf3229d52017-02-21 15:59:08 -070017180 ASSERT_TRUE(ds_image_2D.initialized());
17181
Dave Houlton11dcd5e2017-04-25 16:00:10 -060017182 ds_image_1S.Init(
17183 256, 256, 1, VK_FORMAT_S8_UINT,
17184 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
17185 VK_IMAGE_TILING_OPTIMAL, 0);
Dave Houltonf3229d52017-02-21 15:59:08 -070017186 ASSERT_TRUE(ds_image_1S.initialized());
17187 }
17188
17189 // Allocate buffers
17190 vk_testing::Buffer buffer_256k, buffer_128k, buffer_64k, buffer_16k;
Dave Houlton59a20702017-02-02 17:26:23 -070017191 VkMemoryPropertyFlags reqs = 0;
Dave Houltonf3229d52017-02-21 15:59:08 -070017192 buffer_256k.init_as_src_and_dst(*m_device, 262144, reqs); // 256k
17193 buffer_128k.init_as_src_and_dst(*m_device, 131072, reqs); // 128k
17194 buffer_64k.init_as_src_and_dst(*m_device, 65536, reqs); // 64k
17195 buffer_16k.init_as_src_and_dst(*m_device, 16384, reqs); // 16k
Dave Houlton59a20702017-02-02 17:26:23 -070017196
17197 VkBufferImageCopy region = {};
17198 region.bufferRowLength = 0;
17199 region.bufferImageHeight = 0;
17200 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17201 region.imageSubresource.layerCount = 1;
17202 region.imageOffset = {0, 0, 0};
17203 region.imageExtent = {64, 64, 1};
17204 region.bufferOffset = 0;
17205
17206 // attempt copies before putting command buffer in recording state
17207 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01240);
17208 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64k.handle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17209 &region);
17210 m_errorMonitor->VerifyFound();
17211
17212 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01258);
17213 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_64k.handle(), 1,
17214 &region);
17215 m_errorMonitor->VerifyFound();
17216
17217 // start recording
17218 m_commandBuffer->BeginCommandBuffer();
17219
17220 // successful copies
17221 m_errorMonitor->ExpectSuccess();
17222 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
17223 &region);
17224 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16k.handle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17225 &region);
17226 region.imageOffset.x = 16; // 16k copy, offset requires larger image
17227 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
17228 &region);
17229 region.imageExtent.height = 78; // > 16k copy requires larger buffer & image
17230 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64k.handle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17231 &region);
17232 region.imageOffset.x = 0;
17233 region.imageExtent.height = 64;
17234 region.bufferOffset = 256; // 16k copy with buffer offset, requires larger buffer
17235 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_64k.handle(), 1,
17236 &region);
17237 m_errorMonitor->VerifyNotFound();
17238
Dave Houlton9dae7ec2017-03-01 16:23:25 -070017239 // image/buffer too small (extent too large) on copy to image
Dave Houlton59a20702017-02-02 17:26:23 -070017240 region.imageExtent = {65, 64, 1};
17241 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01227); // buffer too small
17242 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16k.handle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17243 &region);
17244 m_errorMonitor->VerifyFound();
17245
17246 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01228); // image too small
17247 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64k.handle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17248 &region);
17249 m_errorMonitor->VerifyFound();
17250
17251 // image/buffer too small (offset) on copy to image
17252 region.imageExtent = {64, 64, 1};
17253 region.imageOffset = {0, 4, 0};
17254 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01227); // buffer too small
17255 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16k.handle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17256 &region);
17257 m_errorMonitor->VerifyFound();
17258
17259 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01228); // image too small
17260 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64k.handle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17261 &region);
17262 m_errorMonitor->VerifyFound();
17263
17264 // image/buffer too small on copy to buffer
17265 region.imageExtent = {64, 64, 1};
17266 region.imageOffset = {0, 0, 0};
Mark Lobodzinski80871462017-02-16 10:37:27 -070017267 region.bufferOffset = 4;
Dave Houlton59a20702017-02-02 17:26:23 -070017268 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01246); // buffer too small
17269 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
17270 &region);
17271 m_errorMonitor->VerifyFound();
17272
17273 region.imageExtent = {64, 65, 1};
17274 region.bufferOffset = 0;
17275 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01245); // image too small
17276 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_64k.handle(), 1,
17277 &region);
17278 m_errorMonitor->VerifyFound();
17279
17280 // buffer size ok but rowlength causes loose packing
17281 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01246);
17282 region.imageExtent = {64, 64, 1};
17283 region.bufferRowLength = 68;
17284 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
17285 &region);
17286 m_errorMonitor->VerifyFound();
17287
Dave Houlton9dae7ec2017-03-01 16:23:25 -070017288 // An extent with zero area should produce a warning, but no error
17289 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT | VK_DEBUG_REPORT_ERROR_BIT_EXT, "} has zero area");
17290 region.imageExtent.width = 0;
17291 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
17292 &region);
17293 m_errorMonitor->VerifyFound();
17294
Dave Houlton59a20702017-02-02 17:26:23 -070017295 // aspect bits
17296 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01280); // more than 1 aspect bit set
17297 region.imageExtent = {64, 64, 1};
17298 region.bufferRowLength = 0;
17299 region.bufferImageHeight = 0;
17300 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
17301 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_depth.handle(), VK_IMAGE_LAYOUT_GENERAL,
17302 buffer_16k.handle(), 1, &region);
17303 m_errorMonitor->VerifyFound();
17304
17305 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01279); // mis-matched aspect
17306 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
17307 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
17308 &region);
17309 m_errorMonitor->VerifyFound();
17310
17311 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01279); // different mis-matched aspect
17312 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17313 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_depth.handle(), VK_IMAGE_LAYOUT_GENERAL,
17314 buffer_16k.handle(), 1, &region);
17315 m_errorMonitor->VerifyFound();
17316
Dave Houltonf3229d52017-02-21 15:59:08 -070017317 // Test Depth/Stencil copies
17318 if (missing_ds_support) {
17319 printf(" Depth / Stencil formats unsupported - skipping D/S tests.\n");
17320 } else {
17321 VkBufferImageCopy ds_region = {};
17322 ds_region.bufferOffset = 0;
17323 ds_region.bufferRowLength = 0;
17324 ds_region.bufferImageHeight = 0;
17325 ds_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
17326 ds_region.imageSubresource.mipLevel = 0;
17327 ds_region.imageSubresource.baseArrayLayer = 0;
17328 ds_region.imageSubresource.layerCount = 1;
17329 ds_region.imageOffset = {0, 0, 0};
17330 ds_region.imageExtent = {256, 256, 1};
17331
17332 // Depth copies that should succeed
17333 m_errorMonitor->ExpectSuccess(); // Extract 4b depth per texel, pack into 256k buffer
17334 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_4D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
17335 buffer_256k.handle(), 1, &ds_region);
17336 m_errorMonitor->VerifyNotFound();
17337
17338 m_errorMonitor->ExpectSuccess(); // Extract 3b depth per texel, pack (loose) into 256k buffer
17339 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_3D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
17340 buffer_256k.handle(), 1, &ds_region);
17341 m_errorMonitor->VerifyNotFound();
17342
17343 m_errorMonitor->ExpectSuccess(); // Copy 2b depth per texel, into 128k buffer
17344 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_2D.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
17345 buffer_128k.handle(), 1, &ds_region);
17346 m_errorMonitor->VerifyNotFound();
17347
17348 // Depth copies that should fail
17349 ds_region.bufferOffset = 4;
17350 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17351 VALIDATION_ERROR_01246); // Extract 4b depth per texel, pack into 256k buffer
17352 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_4D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
17353 buffer_256k.handle(), 1, &ds_region);
17354 m_errorMonitor->VerifyFound();
17355
17356 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17357 VALIDATION_ERROR_01246); // Extract 3b depth per texel, pack (loose) into 256k buffer
17358 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_3D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
17359 buffer_256k.handle(), 1, &ds_region);
17360 m_errorMonitor->VerifyFound();
17361
17362 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17363 VALIDATION_ERROR_01246); // Copy 2b depth per texel, into 128k buffer
17364 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_2D.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
17365 buffer_128k.handle(), 1, &ds_region);
17366 m_errorMonitor->VerifyFound();
17367
17368 // Stencil copies that should succeed
17369 ds_region.bufferOffset = 0;
17370 ds_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT;
17371 m_errorMonitor->ExpectSuccess(); // Extract 1b stencil per texel, pack into 64k buffer
17372 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_4D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
17373 buffer_64k.handle(), 1, &ds_region);
17374 m_errorMonitor->VerifyNotFound();
17375
17376 m_errorMonitor->ExpectSuccess(); // Extract 1b stencil per texel, pack into 64k buffer
17377 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_3D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
17378 buffer_64k.handle(), 1, &ds_region);
17379 m_errorMonitor->VerifyNotFound();
17380
17381 m_errorMonitor->ExpectSuccess(); // Copy 1b depth per texel, into 64k buffer
17382 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
17383 buffer_64k.handle(), 1, &ds_region);
17384 m_errorMonitor->VerifyNotFound();
17385
17386 // Stencil copies that should fail
17387 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17388 VALIDATION_ERROR_01246); // Extract 1b stencil per texel, pack into 64k buffer
17389 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_4D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
17390 buffer_16k.handle(), 1, &ds_region);
17391 m_errorMonitor->VerifyFound();
17392
17393 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17394 VALIDATION_ERROR_01246); // Extract 1b stencil per texel, pack into 64k buffer
17395 ds_region.bufferRowLength = 260;
17396 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_3D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
17397 buffer_64k.handle(), 1, &ds_region);
17398 m_errorMonitor->VerifyFound();
17399
17400 ds_region.bufferRowLength = 0;
17401 ds_region.bufferOffset = 4;
17402 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17403 VALIDATION_ERROR_01246); // Copy 1b depth per texel, into 64k buffer
17404 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
17405 buffer_64k.handle(), 1, &ds_region);
17406 m_errorMonitor->VerifyFound();
17407 }
17408
Dave Houlton584d51e2017-02-16 12:52:54 -070017409 // Test compressed formats, if supported
Jamie Madill35127872017-03-15 16:17:46 -040017410 VkPhysicalDeviceFeatures device_features = {};
Dave Houlton584d51e2017-02-16 12:52:54 -070017411 ASSERT_NO_FATAL_FAILURE(GetPhysicalDeviceFeatures(&device_features));
Dave Houltonf3229d52017-02-21 15:59:08 -070017412 if (!(device_features.textureCompressionBC || device_features.textureCompressionETC2 ||
17413 device_features.textureCompressionASTC_LDR)) {
17414 printf(" No compressed formats supported - block compression tests skipped.\n");
17415 } else {
Dave Houlton67e9b532017-03-02 17:00:10 -070017416 VkImageObj image_16k_4x4comp(m_device); // 128^2 texels as 32^2 compressed (4x4) blocks, 16k
17417 VkImageObj image_NPOT_4x4comp(m_device); // 130^2 texels as 33^2 compressed (4x4) blocks
Dave Houlton584d51e2017-02-16 12:52:54 -070017418 if (device_features.textureCompressionBC) {
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017419 image_16k_4x4comp.Init(128, 128, 1, VK_FORMAT_BC3_SRGB_BLOCK, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_OPTIMAL,
17420 0);
17421 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 -070017422 0);
Dave Houlton584d51e2017-02-16 12:52:54 -070017423 } else if (device_features.textureCompressionETC2) {
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017424 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 -070017425 VK_IMAGE_TILING_OPTIMAL, 0);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017426 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 -070017427 VK_IMAGE_TILING_OPTIMAL, 0);
Dave Houlton584d51e2017-02-16 12:52:54 -070017428 } else {
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017429 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 -070017430 VK_IMAGE_TILING_OPTIMAL, 0);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017431 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 -070017432 VK_IMAGE_TILING_OPTIMAL, 0);
Dave Houlton584d51e2017-02-16 12:52:54 -070017433 }
17434 ASSERT_TRUE(image_16k_4x4comp.initialized());
Dave Houlton59a20702017-02-02 17:26:23 -070017435
Dave Houlton584d51e2017-02-16 12:52:54 -070017436 // Just fits
17437 m_errorMonitor->ExpectSuccess();
17438 region.imageExtent = {128, 128, 1};
17439 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
17440 buffer_16k.handle(), 1, &region);
17441 m_errorMonitor->VerifyNotFound();
Dave Houlton59a20702017-02-02 17:26:23 -070017442
Dave Houlton584d51e2017-02-16 12:52:54 -070017443 // with offset, too big for buffer
17444 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01246);
17445 region.bufferOffset = 16;
17446 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
17447 buffer_16k.handle(), 1, &region);
17448 m_errorMonitor->VerifyFound();
Dave Houlton67e9b532017-03-02 17:00:10 -070017449 region.bufferOffset = 0;
Dave Houlton59a20702017-02-02 17:26:23 -070017450
Dave Houlton67e9b532017-03-02 17:00:10 -070017451 // extents that are not a multiple of compressed block size
17452 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01275);
17453 region.imageExtent.width = 66;
17454 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_NPOT_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
17455 buffer_16k.handle(), 1, &region);
17456 m_errorMonitor->VerifyFound();
17457 region.imageExtent.width = 128;
17458
17459 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01276);
Dave Houlton9dae7ec2017-03-01 16:23:25 -070017460 region.imageExtent.height = 2;
Dave Houlton67e9b532017-03-02 17:00:10 -070017461 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_NPOT_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
17462 buffer_16k.handle(), 1, &region);
17463 m_errorMonitor->VerifyFound();
17464 region.imageExtent.height = 128;
17465
17466 // TODO: All available compressed formats are 2D, with block depth of 1. Unable to provoke VU_01277.
17467
17468 // non-multiple extents are allowed if at the far edge of a non-block-multiple image - these should pass
17469 m_errorMonitor->ExpectSuccess();
17470 region.imageExtent.width = 66;
17471 region.imageOffset.x = 64;
17472 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_NPOT_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
17473 buffer_16k.handle(), 1, &region);
17474 region.imageExtent.width = 16;
17475 region.imageOffset.x = 0;
17476 region.imageExtent.height = 2;
17477 region.imageOffset.y = 128;
17478 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_NPOT_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
Dave Houlton9dae7ec2017-03-01 16:23:25 -070017479 buffer_16k.handle(), 1, &region);
17480 m_errorMonitor->VerifyNotFound();
Dave Houlton67e9b532017-03-02 17:00:10 -070017481 region.imageOffset = {0, 0, 0};
Dave Houlton9dae7ec2017-03-01 16:23:25 -070017482
Dave Houlton584d51e2017-02-16 12:52:54 -070017483 // buffer offset must be a multiple of texel block size (16)
17484 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01274);
17485 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01263);
17486 region.imageExtent = {64, 64, 1};
17487 region.bufferOffset = 24;
17488 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
17489 buffer_16k.handle(), 1, &region);
17490 m_errorMonitor->VerifyFound();
Dave Houlton59a20702017-02-02 17:26:23 -070017491
Dave Houlton584d51e2017-02-16 12:52:54 -070017492 // rowlength not a multiple of block width (4)
17493 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01271);
17494 region.bufferOffset = 0;
17495 region.bufferRowLength = 130;
17496 region.bufferImageHeight = 0;
17497 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
17498 buffer_64k.handle(), 1, &region);
17499 m_errorMonitor->VerifyFound();
Dave Houlton59a20702017-02-02 17:26:23 -070017500
Dave Houlton584d51e2017-02-16 12:52:54 -070017501 // imageheight not a multiple of block height (4)
17502 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01272);
17503 region.bufferRowLength = 0;
17504 region.bufferImageHeight = 130;
17505 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
17506 buffer_64k.handle(), 1, &region);
17507 m_errorMonitor->VerifyFound();
Dave Houlton584d51e2017-02-16 12:52:54 -070017508 }
Dave Houlton59a20702017-02-02 17:26:23 -070017509}
17510
Tony Barbourd6673642016-05-05 14:46:39 -060017511TEST_F(VkLayerTest, MiscImageLayerTests) {
Mark Lobodzinskie6911292017-02-15 14:38:51 -070017512 TEST_DESCRIPTION("Image-related tests that don't belong elsewhare");
Tony Barbourd6673642016-05-05 14:46:39 -060017513
Tony Barbour1fa09702017-03-16 12:09:08 -060017514 ASSERT_NO_FATAL_FAILURE(Init());
Tony Barbourd6673642016-05-05 14:46:39 -060017515
Rene Lindsay135204f2016-12-22 17:11:09 -070017516 // TODO: Ideally we should check if a format is supported, before using it.
Tony Barbourd6673642016-05-05 14:46:39 -060017517 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017518 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 -070017519 VK_IMAGE_TILING_OPTIMAL, 0); // 64bpp
Tony Barbourd6673642016-05-05 14:46:39 -060017520 ASSERT_TRUE(image.initialized());
Tony Barbourd6673642016-05-05 14:46:39 -060017521 vk_testing::Buffer buffer;
17522 VkMemoryPropertyFlags reqs = 0;
Rene Lindsay135204f2016-12-22 17:11:09 -070017523 buffer.init_as_src(*m_device, 128 * 128 * 8, reqs);
Tony Barbourd6673642016-05-05 14:46:39 -060017524 VkBufferImageCopy region = {};
17525 region.bufferRowLength = 128;
17526 region.bufferImageHeight = 128;
17527 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17528 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
Mark Lobodzinski3702e932016-11-22 11:40:48 -070017529 region.imageSubresource.layerCount = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060017530 region.imageExtent.height = 4;
17531 region.imageExtent.width = 4;
17532 region.imageExtent.depth = 1;
Rene Lindsay135204f2016-12-22 17:11:09 -070017533
17534 VkImageObj image2(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017535 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 -070017536 VK_IMAGE_TILING_OPTIMAL, 0); // 16bpp
Rene Lindsay135204f2016-12-22 17:11:09 -070017537 ASSERT_TRUE(image2.initialized());
17538 vk_testing::Buffer buffer2;
17539 VkMemoryPropertyFlags reqs2 = 0;
17540 buffer2.init_as_src(*m_device, 128 * 128 * 2, reqs2);
17541 VkBufferImageCopy region2 = {};
17542 region2.bufferRowLength = 128;
17543 region2.bufferImageHeight = 128;
17544 region2.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17545 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
17546 region2.imageSubresource.layerCount = 1;
17547 region2.imageExtent.height = 4;
17548 region2.imageExtent.width = 4;
17549 region2.imageExtent.depth = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060017550 m_commandBuffer->BeginCommandBuffer();
Tony Barbourd6673642016-05-05 14:46:39 -060017551
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070017552 // Image must have offset.z of 0 and extent.depth of 1
17553 // Introduce failure by setting imageExtent.depth to 0
17554 region.imageExtent.depth = 0;
Dave Houlton59a20702017-02-02 17:26:23 -070017555 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01747);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070017556 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017557 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070017558 m_errorMonitor->VerifyFound();
17559
17560 region.imageExtent.depth = 1;
17561
17562 // Image must have offset.z of 0 and extent.depth of 1
17563 // Introduce failure by setting imageOffset.z to 4
Dave Houlton9dae7ec2017-03-01 16:23:25 -070017564 // Note: Also (unavoidably) triggers 'region exceeds image' #1228
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070017565 region.imageOffset.z = 4;
Dave Houlton59a20702017-02-02 17:26:23 -070017566 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01747);
Dave Houlton9dae7ec2017-03-01 16:23:25 -070017567 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01228);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070017568 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017569 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070017570 m_errorMonitor->VerifyFound();
17571
17572 region.imageOffset.z = 0;
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060017573 // BufferOffset must be a multiple of the calling command's VkImage parameter's texel size
17574 // Introduce failure by setting bufferOffset to 1 and 1/2 texels
Rene Lindsay135204f2016-12-22 17:11:09 -070017575 region.bufferOffset = 4;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070017576 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01263);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017577 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
17578 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060017579 m_errorMonitor->VerifyFound();
17580
17581 // BufferOffset must be a multiple of 4
17582 // Introduce failure by setting bufferOffset to a value not divisible by 4
Rene Lindsay135204f2016-12-22 17:11:09 -070017583 region2.bufferOffset = 6;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070017584 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01264);
Rene Lindsay135204f2016-12-22 17:11:09 -070017585 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer2.handle(), image2.handle(),
17586 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region2);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060017587 m_errorMonitor->VerifyFound();
17588
17589 // BufferRowLength must be 0, or greater than or equal to the width member of imageExtent
17590 region.bufferOffset = 0;
17591 region.imageExtent.height = 128;
17592 region.imageExtent.width = 128;
17593 // Introduce failure by setting bufferRowLength > 0 but less than width
17594 region.bufferRowLength = 64;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070017595 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01265);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017596 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
17597 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060017598 m_errorMonitor->VerifyFound();
17599
17600 // BufferImageHeight must be 0, or greater than or equal to the height member of imageExtent
17601 region.bufferRowLength = 128;
17602 // Introduce failure by setting bufferRowHeight > 0 but less than height
17603 region.bufferImageHeight = 64;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070017604 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01266);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017605 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
17606 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060017607 m_errorMonitor->VerifyFound();
17608
17609 region.bufferImageHeight = 128;
Tony Barbourd6673642016-05-05 14:46:39 -060017610 VkImageObj intImage1(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017611 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 -070017612 VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbourd6673642016-05-05 14:46:39 -060017613 VkImageObj intImage2(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017614 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 -070017615 VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbourd6673642016-05-05 14:46:39 -060017616 VkImageBlit blitRegion = {};
17617 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17618 blitRegion.srcSubresource.baseArrayLayer = 0;
17619 blitRegion.srcSubresource.layerCount = 1;
17620 blitRegion.srcSubresource.mipLevel = 0;
17621 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17622 blitRegion.dstSubresource.baseArrayLayer = 0;
17623 blitRegion.dstSubresource.layerCount = 1;
17624 blitRegion.dstSubresource.mipLevel = 0;
17625
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060017626 // Look for NULL-blit warning
Jeremy Hayesf8e749f2017-03-15 09:40:27 -060017627 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
17628 "vkCmdBlitImage: pRegions[0].srcOffsets specify a zero-volume area.");
17629 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
17630 "vkCmdBlitImage: pRegions[0].dstOffsets specify a zero-volume area.");
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017631 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.Layout(), intImage2.handle(),
17632 intImage2.Layout(), 1, &blitRegion, VK_FILTER_LINEAR);
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060017633 m_errorMonitor->VerifyFound();
17634
Mark Lobodzinskic386ecb2017-02-02 16:12:37 -070017635 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00769);
Tony Barbourd6673642016-05-05 14:46:39 -060017636 VkImageMemoryBarrier img_barrier;
17637 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
17638 img_barrier.pNext = NULL;
17639 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
17640 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
17641 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
17642 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
17643 img_barrier.image = image.handle();
17644 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
17645 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
17646 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17647 img_barrier.subresourceRange.baseArrayLayer = 0;
17648 img_barrier.subresourceRange.baseMipLevel = 0;
Tony Barbourd6673642016-05-05 14:46:39 -060017649 img_barrier.subresourceRange.layerCount = 0;
17650 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017651 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
17652 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbourd6673642016-05-05 14:46:39 -060017653 m_errorMonitor->VerifyFound();
17654 img_barrier.subresourceRange.layerCount = 1;
17655}
17656
17657TEST_F(VkLayerTest, ImageFormatLimits) {
Tony Barbourd6673642016-05-05 14:46:39 -060017658 TEST_DESCRIPTION("Exceed the limits of image format ");
17659
Tony Barbour1fa09702017-03-16 12:09:08 -060017660 ASSERT_NO_FATAL_FAILURE(Init());
Jeremy Hayesbb63cc12017-03-20 15:33:01 -060017661
17662 VkFormat const format = VK_FORMAT_B8G8R8A8_UNORM;
17663 {
17664 VkFormatProperties properties;
17665 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), format, &properties);
17666 if (properties.linearTilingFeatures == 0) {
17667 printf(" Image format not supported; skipped.\n");
17668 return;
17669 }
17670 }
17671
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017672 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Tony Barbourd6673642016-05-05 14:46:39 -060017673 VkImageCreateInfo image_create_info = {};
17674 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17675 image_create_info.pNext = NULL;
17676 image_create_info.imageType = VK_IMAGE_TYPE_2D;
Jeremy Hayesbb63cc12017-03-20 15:33:01 -060017677 image_create_info.format = format;
Tony Barbourd6673642016-05-05 14:46:39 -060017678 image_create_info.extent.width = 32;
17679 image_create_info.extent.height = 32;
17680 image_create_info.extent.depth = 1;
17681 image_create_info.mipLevels = 1;
17682 image_create_info.arrayLayers = 1;
17683 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
17684 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
17685 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
17686 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
17687 image_create_info.flags = 0;
17688
17689 VkImage nullImg;
17690 VkImageFormatProperties imgFmtProps;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017691 vkGetPhysicalDeviceImageFormatProperties(gpu(), image_create_info.format, image_create_info.imageType, image_create_info.tiling,
17692 image_create_info.usage, image_create_info.flags, &imgFmtProps);
Rene Lindsayef5bc012017-01-06 15:38:00 -070017693 image_create_info.extent.width = imgFmtProps.maxExtent.width + 1;
Tony Barbourd6673642016-05-05 14:46:39 -060017694 // Expect INVALID_FORMAT_LIMITS_VIOLATION
17695 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
17696 m_errorMonitor->VerifyFound();
Rene Lindsayef5bc012017-01-06 15:38:00 -070017697 image_create_info.extent.width = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060017698
Tony Barbour0907e362017-03-09 15:05:30 -070017699 uint32_t maxDim =
17700 std::max(std::max(image_create_info.extent.width, image_create_info.extent.height), image_create_info.extent.depth);
17701 // If max mip levels exceeds image extents, skip the max mip levels test
17702 if ((imgFmtProps.maxMipLevels + 1) <= (floor(log2(maxDim)) + 1)) {
17703 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
17704 image_create_info.mipLevels = imgFmtProps.maxMipLevels + 1;
17705 // Expect INVALID_FORMAT_LIMITS_VIOLATION
17706 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
17707 m_errorMonitor->VerifyFound();
17708 image_create_info.mipLevels = 1;
17709 }
Tony Barbourd6673642016-05-05 14:46:39 -060017710
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017711 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060017712 image_create_info.arrayLayers = imgFmtProps.maxArrayLayers + 1;
17713 // Expect INVALID_FORMAT_LIMITS_VIOLATION
17714 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
17715 m_errorMonitor->VerifyFound();
17716 image_create_info.arrayLayers = 1;
17717
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017718 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is not supported by format");
Tony Barbourd6673642016-05-05 14:46:39 -060017719 int samples = imgFmtProps.sampleCounts >> 1;
17720 image_create_info.samples = (VkSampleCountFlagBits)samples;
17721 // Expect INVALID_FORMAT_LIMITS_VIOLATION
17722 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
17723 m_errorMonitor->VerifyFound();
17724 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
17725
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017726 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17727 "pCreateInfo->initialLayout, must be "
17728 "VK_IMAGE_LAYOUT_UNDEFINED or "
17729 "VK_IMAGE_LAYOUT_PREINITIALIZED");
Tony Barbourd6673642016-05-05 14:46:39 -060017730 image_create_info.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
17731 // Expect INVALID_LAYOUT
17732 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
17733 m_errorMonitor->VerifyFound();
17734 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
17735}
17736
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017737TEST_F(VkLayerTest, CopyImageSrcSizeExceeded) {
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017738 // Image copy with source region specified greater than src image size
Tony Barbour1fa09702017-03-16 12:09:08 -060017739 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017740
Dave Houltonfc1a4052017-04-27 14:32:45 -060017741 // Create images with full mip chain
17742 VkImageCreateInfo ci;
17743 ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17744 ci.pNext = NULL;
17745 ci.flags = 0;
17746 ci.imageType = VK_IMAGE_TYPE_3D;
17747 ci.format = VK_FORMAT_R8G8B8A8_UNORM;
17748 ci.extent = {32, 32, 8};
17749 ci.mipLevels = 6;
17750 ci.arrayLayers = 1;
17751 ci.samples = VK_SAMPLE_COUNT_1_BIT;
17752 ci.tiling = VK_IMAGE_TILING_OPTIMAL;
17753 ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
17754 ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
17755 ci.queueFamilyIndexCount = 0;
17756 ci.pQueueFamilyIndices = NULL;
17757 ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
17758
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017759 VkImageObj src_image(m_device);
Dave Houltonfc1a4052017-04-27 14:32:45 -060017760 src_image.init(&ci);
17761 ASSERT_TRUE(src_image.initialized());
17762
17763 // Dest image with one more mip level
17764 ci.extent = {64, 64, 16};
17765 ci.mipLevels = 7;
17766 ci.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017767 VkImageObj dst_image(m_device);
Dave Houltonfc1a4052017-04-27 14:32:45 -060017768 dst_image.init(&ci);
17769 ASSERT_TRUE(dst_image.initialized());
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017770
Tony Barbour552f6c02016-12-21 14:34:07 -070017771 m_commandBuffer->BeginCommandBuffer();
Dave Houltonfc1a4052017-04-27 14:32:45 -060017772
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017773 VkImageCopy copy_region;
Dave Houltonfc1a4052017-04-27 14:32:45 -060017774 copy_region.extent = {32, 32, 8};
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017775 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017776 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Dave Houltoncee81d02017-05-02 11:00:10 -060017777 copy_region.srcSubresource.mipLevel = 0;
17778 copy_region.dstSubresource.mipLevel = 0;
Dave Houltonfc1a4052017-04-27 14:32:45 -060017779 copy_region.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017780 copy_region.dstSubresource.baseArrayLayer = 0;
Dave Houltonfc1a4052017-04-27 14:32:45 -060017781 copy_region.srcSubresource.layerCount = 1;
17782 copy_region.dstSubresource.layerCount = 1;
17783 copy_region.srcOffset = {0, 0, 0};
17784 copy_region.dstOffset = {0, 0, 0};
17785
17786 m_errorMonitor->ExpectSuccess();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017787 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
17788 &copy_region);
Dave Houltonfc1a4052017-04-27 14:32:45 -060017789 m_errorMonitor->VerifyNotFound();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017790
Dave Houltonfc1a4052017-04-27 14:32:45 -060017791 // Source exceeded in x-dim, VU 01202
17792 copy_region.srcOffset.x = 4;
17793 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01175); // General "contained within" VU
17794 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01202);
17795 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
17796 &copy_region);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017797 m_errorMonitor->VerifyFound();
Dave Houltonfc1a4052017-04-27 14:32:45 -060017798
17799 // Source exceeded in y-dim, VU 01203
17800 copy_region.srcOffset.x = 0;
17801 copy_region.extent.height = 48;
17802 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01175);
17803 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01203);
17804 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
17805 &copy_region);
17806 m_errorMonitor->VerifyFound();
17807
17808 // Source exceeded in z-dim, VU 01204
17809 copy_region.extent = {4, 4, 4};
17810 copy_region.srcSubresource.mipLevel = 2;
17811 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01175);
17812 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01204);
17813 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
17814 &copy_region);
17815 m_errorMonitor->VerifyFound();
17816
17817 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017818}
17819
17820TEST_F(VkLayerTest, CopyImageDstSizeExceeded) {
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017821 // Image copy with dest region specified greater than dest image size
Tony Barbour1fa09702017-03-16 12:09:08 -060017822 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017823
Dave Houltonfc1a4052017-04-27 14:32:45 -060017824 // Create images with full mip chain
17825 VkImageCreateInfo ci;
17826 ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17827 ci.pNext = NULL;
17828 ci.flags = 0;
17829 ci.imageType = VK_IMAGE_TYPE_3D;
17830 ci.format = VK_FORMAT_R8G8B8A8_UNORM;
17831 ci.extent = {32, 32, 8};
17832 ci.mipLevels = 6;
17833 ci.arrayLayers = 1;
17834 ci.samples = VK_SAMPLE_COUNT_1_BIT;
17835 ci.tiling = VK_IMAGE_TILING_OPTIMAL;
17836 ci.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
17837 ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
17838 ci.queueFamilyIndexCount = 0;
17839 ci.pQueueFamilyIndices = NULL;
17840 ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
17841
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017842 VkImageObj dst_image(m_device);
Dave Houltonfc1a4052017-04-27 14:32:45 -060017843 dst_image.init(&ci);
17844 ASSERT_TRUE(dst_image.initialized());
17845
17846 // Src image with one more mip level
17847 ci.extent = {64, 64, 16};
17848 ci.mipLevels = 7;
17849 ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
17850 VkImageObj src_image(m_device);
17851 src_image.init(&ci);
17852 ASSERT_TRUE(src_image.initialized());
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017853
Tony Barbour552f6c02016-12-21 14:34:07 -070017854 m_commandBuffer->BeginCommandBuffer();
Dave Houltonfc1a4052017-04-27 14:32:45 -060017855
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017856 VkImageCopy copy_region;
Dave Houltonfc1a4052017-04-27 14:32:45 -060017857 copy_region.extent = {32, 32, 8};
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017858 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017859 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Dave Houltoncee81d02017-05-02 11:00:10 -060017860 copy_region.srcSubresource.mipLevel = 0;
17861 copy_region.dstSubresource.mipLevel = 0;
Dave Houltonfc1a4052017-04-27 14:32:45 -060017862 copy_region.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017863 copy_region.dstSubresource.baseArrayLayer = 0;
Dave Houltonfc1a4052017-04-27 14:32:45 -060017864 copy_region.srcSubresource.layerCount = 1;
17865 copy_region.dstSubresource.layerCount = 1;
17866 copy_region.srcOffset = {0, 0, 0};
17867 copy_region.dstOffset = {0, 0, 0};
17868
17869 m_errorMonitor->ExpectSuccess();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017870 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
17871 &copy_region);
Dave Houltonfc1a4052017-04-27 14:32:45 -060017872 m_errorMonitor->VerifyNotFound();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017873
Dave Houltonfc1a4052017-04-27 14:32:45 -060017874 // Dest exceeded in x-dim, VU 01205
17875 copy_region.dstOffset.x = 4;
17876 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01176); // General "contained within" VU
17877 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01205);
17878 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
17879 &copy_region);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017880 m_errorMonitor->VerifyFound();
Dave Houltonfc1a4052017-04-27 14:32:45 -060017881
17882 // Dest exceeded in y-dim, VU 01206
17883 copy_region.dstOffset.x = 0;
17884 copy_region.extent.height = 48;
17885 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01176);
17886 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01206);
17887 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
17888 &copy_region);
17889 m_errorMonitor->VerifyFound();
17890
17891 // Dest exceeded in z-dim, VU 01207
17892 copy_region.extent = {4, 4, 4};
17893 copy_region.dstSubresource.mipLevel = 2;
17894 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01176);
17895 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01207);
17896 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
17897 &copy_region);
17898 m_errorMonitor->VerifyFound();
17899
17900 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017901}
17902
Karl Schultz6addd812016-02-02 17:17:23 -070017903TEST_F(VkLayerTest, CopyImageFormatSizeMismatch) {
Karl Schultzbdb75952016-04-19 11:36:49 -060017904 VkResult err;
17905 bool pass;
17906
17907 // Create color images with different format sizes and try to copy between them
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070017908 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01184);
Karl Schultzbdb75952016-04-19 11:36:49 -060017909
Tony Barbour1fa09702017-03-16 12:09:08 -060017910 ASSERT_NO_FATAL_FAILURE(Init());
Karl Schultzbdb75952016-04-19 11:36:49 -060017911
17912 // Create two images of different types and try to copy between them
17913 VkImage srcImage;
17914 VkImage dstImage;
17915 VkDeviceMemory srcMem;
17916 VkDeviceMemory destMem;
17917 VkMemoryRequirements memReqs;
17918
17919 VkImageCreateInfo image_create_info = {};
17920 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17921 image_create_info.pNext = NULL;
17922 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17923 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
17924 image_create_info.extent.width = 32;
17925 image_create_info.extent.height = 32;
17926 image_create_info.extent.depth = 1;
17927 image_create_info.mipLevels = 1;
17928 image_create_info.arrayLayers = 1;
17929 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
17930 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
17931 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
17932 image_create_info.flags = 0;
17933
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017934 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060017935 ASSERT_VK_SUCCESS(err);
17936
17937 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
17938 // Introduce failure by creating second image with a different-sized format.
17939 image_create_info.format = VK_FORMAT_R5G5B5A1_UNORM_PACK16;
Tobin Ehlis6d4d1d52017-04-05 12:06:10 -060017940 VkFormatProperties properties;
17941 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), image_create_info.format, &properties);
17942 if (properties.optimalTilingFeatures == 0) {
17943 printf(" Image format not supported; skipped.\n");
17944 return;
17945 }
Karl Schultzbdb75952016-04-19 11:36:49 -060017946
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017947 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060017948 ASSERT_VK_SUCCESS(err);
17949
17950 // Allocate memory
17951 VkMemoryAllocateInfo memAlloc = {};
17952 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17953 memAlloc.pNext = NULL;
17954 memAlloc.allocationSize = 0;
17955 memAlloc.memoryTypeIndex = 0;
17956
17957 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
17958 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017959 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060017960 ASSERT_TRUE(pass);
17961 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
17962 ASSERT_VK_SUCCESS(err);
17963
17964 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
17965 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017966 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060017967 ASSERT_TRUE(pass);
17968 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
17969 ASSERT_VK_SUCCESS(err);
17970
17971 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
17972 ASSERT_VK_SUCCESS(err);
17973 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
17974 ASSERT_VK_SUCCESS(err);
17975
Tony Barbour552f6c02016-12-21 14:34:07 -070017976 m_commandBuffer->BeginCommandBuffer();
Karl Schultzbdb75952016-04-19 11:36:49 -060017977 VkImageCopy copyRegion;
17978 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17979 copyRegion.srcSubresource.mipLevel = 0;
17980 copyRegion.srcSubresource.baseArrayLayer = 0;
17981 copyRegion.srcSubresource.layerCount = 0;
17982 copyRegion.srcOffset.x = 0;
17983 copyRegion.srcOffset.y = 0;
17984 copyRegion.srcOffset.z = 0;
17985 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17986 copyRegion.dstSubresource.mipLevel = 0;
17987 copyRegion.dstSubresource.baseArrayLayer = 0;
17988 copyRegion.dstSubresource.layerCount = 0;
17989 copyRegion.dstOffset.x = 0;
17990 copyRegion.dstOffset.y = 0;
17991 copyRegion.dstOffset.z = 0;
17992 copyRegion.extent.width = 1;
17993 copyRegion.extent.height = 1;
17994 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017995 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070017996 m_commandBuffer->EndCommandBuffer();
Karl Schultzbdb75952016-04-19 11:36:49 -060017997
17998 m_errorMonitor->VerifyFound();
17999
18000 vkDestroyImage(m_device->device(), srcImage, NULL);
18001 vkDestroyImage(m_device->device(), dstImage, NULL);
18002 vkFreeMemory(m_device->device(), srcMem, NULL);
18003 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060018004}
18005
Karl Schultz6addd812016-02-02 17:17:23 -070018006TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch) {
18007 VkResult err;
18008 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060018009
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018010 // Create a depth image and a depth/stencil image and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018011 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
18012 "vkCmdCopyImage called with unmatched source and dest image depth");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060018013
Tony Barbour1fa09702017-03-16 12:09:08 -060018014 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -060018015 auto depth_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbourf887b162017-03-09 10:06:46 -070018016 if (!depth_format) {
18017 return;
18018 }
Mike Stroyana3082432015-09-25 13:39:21 -060018019
18020 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070018021 VkImage srcImage;
18022 VkImage dstImage;
18023 VkDeviceMemory srcMem;
18024 VkDeviceMemory destMem;
18025 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060018026
18027 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070018028 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
18029 image_create_info.pNext = NULL;
18030 image_create_info.imageType = VK_IMAGE_TYPE_2D;
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018031 image_create_info.format = VK_FORMAT_D32_SFLOAT;
Karl Schultz6addd812016-02-02 17:17:23 -070018032 image_create_info.extent.width = 32;
18033 image_create_info.extent.height = 32;
18034 image_create_info.extent.depth = 1;
18035 image_create_info.mipLevels = 1;
18036 image_create_info.arrayLayers = 1;
18037 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Youngad61f4b2017-04-07 08:59:56 -060018038 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Karl Schultz6addd812016-02-02 17:17:23 -070018039 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
18040 image_create_info.flags = 0;
Tobin Ehlis6d4d1d52017-04-05 12:06:10 -060018041 VkFormatProperties properties;
18042 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), image_create_info.format, &properties);
18043 if (properties.optimalTilingFeatures == 0) {
18044 printf(" Image format not supported; skipped.\n");
18045 return;
18046 }
Mike Stroyana3082432015-09-25 13:39:21 -060018047
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018048 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060018049 ASSERT_VK_SUCCESS(err);
18050
Karl Schultzbdb75952016-04-19 11:36:49 -060018051 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
18052
Mark Lobodzinskidb117632016-03-31 10:45:56 -060018053 // Introduce failure by creating second image with a depth/stencil format
Karl Schultz6addd812016-02-02 17:17:23 -070018054 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Tony Barbourf887b162017-03-09 10:06:46 -070018055 image_create_info.format = depth_format;
Mark Lobodzinski867787a2016-10-14 11:49:55 -060018056 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060018057
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018058 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060018059 ASSERT_VK_SUCCESS(err);
18060
18061 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018062 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070018063 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18064 memAlloc.pNext = NULL;
18065 memAlloc.allocationSize = 0;
18066 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018067
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060018068 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060018069 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018070 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060018071 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018072 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060018073 ASSERT_VK_SUCCESS(err);
18074
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018075 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060018076 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018077 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060018078 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018079 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060018080 ASSERT_VK_SUCCESS(err);
18081
18082 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
18083 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018084 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060018085 ASSERT_VK_SUCCESS(err);
18086
Tony Barbour552f6c02016-12-21 14:34:07 -070018087 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060018088 VkImageCopy copyRegion;
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018089 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060018090 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060018091 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018092 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018093 copyRegion.srcOffset.x = 0;
18094 copyRegion.srcOffset.y = 0;
18095 copyRegion.srcOffset.z = 0;
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018096 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018097 copyRegion.dstSubresource.mipLevel = 0;
18098 copyRegion.dstSubresource.baseArrayLayer = 0;
18099 copyRegion.dstSubresource.layerCount = 0;
18100 copyRegion.dstOffset.x = 0;
18101 copyRegion.dstOffset.y = 0;
18102 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018103 copyRegion.extent.width = 1;
18104 copyRegion.extent.height = 1;
18105 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018106 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070018107 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060018108
Chris Forbes8f36a8a2016-04-07 13:21:07 +120018109 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060018110
Chia-I Wuf7458c52015-10-26 21:10:41 +080018111 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018112 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080018113 vkFreeMemory(m_device->device(), srcMem, NULL);
18114 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060018115}
18116
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018117TEST_F(VkLayerTest, CopyImageSampleCountMismatch) {
18118 TEST_DESCRIPTION("Image copies with sample count mis-matches");
Dave Houlton33c22b72017-02-28 13:16:02 -070018119
Mark Lobodzinski77e590c2017-03-17 12:05:16 -060018120 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton33c22b72017-02-28 13:16:02 -070018121
18122 VkImageFormatProperties image_format_properties;
18123 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
18124 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT, 0,
18125 &image_format_properties);
18126
18127 if ((0 == (VK_SAMPLE_COUNT_2_BIT & image_format_properties.sampleCounts)) ||
18128 (0 == (VK_SAMPLE_COUNT_4_BIT & image_format_properties.sampleCounts))) {
18129 printf(" Image multi-sample support not found; skipped.\n");
18130 return;
18131 }
18132
18133 VkImageCreateInfo ci;
18134 ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
18135 ci.pNext = NULL;
18136 ci.flags = 0;
18137 ci.imageType = VK_IMAGE_TYPE_2D;
18138 ci.format = VK_FORMAT_R8G8B8A8_UNORM;
18139 ci.extent = {128, 128, 1};
18140 ci.mipLevels = 1;
18141 ci.arrayLayers = 1;
18142 ci.samples = VK_SAMPLE_COUNT_1_BIT;
18143 ci.tiling = VK_IMAGE_TILING_OPTIMAL;
18144 ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
18145 ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
18146 ci.queueFamilyIndexCount = 0;
18147 ci.pQueueFamilyIndices = NULL;
18148 ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
18149
18150 VkImageObj image1(m_device);
18151 image1.init(&ci);
18152 ASSERT_TRUE(image1.initialized());
18153
18154 ci.samples = VK_SAMPLE_COUNT_2_BIT;
18155 VkImageObj image2(m_device);
18156 image2.init(&ci);
18157 ASSERT_TRUE(image2.initialized());
18158
18159 ci.samples = VK_SAMPLE_COUNT_4_BIT;
18160 VkImageObj image4(m_device);
18161 image4.init(&ci);
18162 ASSERT_TRUE(image4.initialized());
18163
18164 m_commandBuffer->BeginCommandBuffer();
18165
18166 VkImageCopy copyRegion;
18167 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
18168 copyRegion.srcSubresource.mipLevel = 0;
18169 copyRegion.srcSubresource.baseArrayLayer = 0;
18170 copyRegion.srcSubresource.layerCount = 1;
18171 copyRegion.srcOffset = {0, 0, 0};
18172 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
18173 copyRegion.dstSubresource.mipLevel = 0;
18174 copyRegion.dstSubresource.baseArrayLayer = 0;
18175 copyRegion.dstSubresource.layerCount = 1;
18176 copyRegion.dstOffset = {0, 0, 0};
18177 copyRegion.extent = {128, 128, 1};
18178
18179 // Copy a single sample image to/from a multi-sample image
18180 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01185);
18181 vkCmdCopyImage(m_commandBuffer->GetBufferHandle(), image1.handle(), VK_IMAGE_LAYOUT_GENERAL, image4.handle(),
18182 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
18183 m_errorMonitor->VerifyFound();
18184
18185 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01185);
18186 vkCmdCopyImage(m_commandBuffer->GetBufferHandle(), image2.handle(), VK_IMAGE_LAYOUT_GENERAL, image1.handle(),
18187 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
18188 m_errorMonitor->VerifyFound();
18189
18190 // Copy between multi-sample images with different sample counts
18191 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01185);
18192 vkCmdCopyImage(m_commandBuffer->GetBufferHandle(), image2.handle(), VK_IMAGE_LAYOUT_GENERAL, image4.handle(),
18193 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
18194 m_errorMonitor->VerifyFound();
18195
18196 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01185);
18197 vkCmdCopyImage(m_commandBuffer->GetBufferHandle(), image4.handle(), VK_IMAGE_LAYOUT_GENERAL, image2.handle(),
18198 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
18199 m_errorMonitor->VerifyFound();
18200
18201 m_commandBuffer->EndCommandBuffer();
18202}
18203
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018204TEST_F(VkLayerTest, CopyImageAspectMismatch) {
18205 TEST_DESCRIPTION("Image copies with aspect mask errors");
Mark Lobodzinski77e590c2017-03-17 12:05:16 -060018206 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -060018207 auto ds_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbour9357d542017-03-24 15:42:21 -060018208 if (!ds_format) {
18209 return;
18210 }
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018211
Tobin Ehlis6d4d1d52017-04-05 12:06:10 -060018212 VkFormatProperties properties;
18213 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D32_SFLOAT, &properties);
18214 if (properties.optimalTilingFeatures == 0) {
18215 printf(" Image format VK_FORMAT_D32_SFLOAT not supported; skipped.\n");
18216 return;
18217 }
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018218 VkImageObj color_image(m_device), ds_image(m_device), depth_image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060018219 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 -060018220 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 -060018221 VK_IMAGE_TILING_OPTIMAL, 0);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060018222 ds_image.Init(128, 128, 1, ds_format, VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
18223 VK_IMAGE_TILING_OPTIMAL, 0);
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018224 ASSERT_TRUE(color_image.initialized());
18225 ASSERT_TRUE(depth_image.initialized());
18226 ASSERT_TRUE(ds_image.initialized());
18227
18228 VkImageCopy copyRegion;
18229 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
18230 copyRegion.srcSubresource.mipLevel = 0;
18231 copyRegion.srcSubresource.baseArrayLayer = 0;
18232 copyRegion.srcSubresource.layerCount = 1;
18233 copyRegion.srcOffset = {0, 0, 0};
18234 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
18235 copyRegion.dstSubresource.mipLevel = 0;
18236 copyRegion.dstSubresource.baseArrayLayer = 0;
18237 copyRegion.dstSubresource.layerCount = 1;
18238 copyRegion.dstOffset = {64, 0, 0};
18239 copyRegion.extent = {64, 128, 1};
18240
18241 // Submitting command before command buffer is in recording state
Dave Houlton3c9fca72017-03-27 17:25:54 -060018242 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
18243 "You must call vkBeginCommandBuffer"); // VALIDATION_ERROR_01192);
18244 vkCmdCopyImage(m_commandBuffer->GetBufferHandle(), depth_image.handle(), VK_IMAGE_LAYOUT_GENERAL, depth_image.handle(),
18245 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018246 m_errorMonitor->VerifyFound();
18247
18248 m_commandBuffer->BeginCommandBuffer();
18249
18250 // Src and dest aspect masks don't match
18251 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT;
18252 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01197);
Dave Houlton3c9fca72017-03-27 17:25:54 -060018253 vkCmdCopyImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, ds_image.handle(),
18254 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018255 m_errorMonitor->VerifyFound();
18256 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
18257
18258 // Illegal combinations of aspect bits - VU 01221
Dave Houlton3c9fca72017-03-27 17:25:54 -060018259 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT; // color must be alone
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018260 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT;
18261 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01221);
18262 // These aspect/format mismatches are redundant but unavoidable here
18263 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01200);
18264 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01201);
Dave Houlton3c9fca72017-03-27 17:25:54 -060018265 vkCmdCopyImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_GENERAL, color_image.handle(),
18266 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018267 m_errorMonitor->VerifyFound();
18268 // Metadata aspect is illegal - VU 01222
18269 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
18270 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
18271 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01222);
18272 // These aspect/format mismatches are redundant but unavoidable here
Dave Houlton3c9fca72017-03-27 17:25:54 -060018273 vkCmdCopyImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_GENERAL, color_image.handle(),
18274 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018275 m_errorMonitor->VerifyFound();
18276
18277 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
18278 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
18279
18280 // Aspect mask doesn't match source image format - VU 01200
18281 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01200);
18282 // Again redundant but unavoidable when provoking vu01200 w/o vu01201
18283 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "unmatched source and dest image depth/stencil formats");
18284 vkCmdCopyImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_GENERAL, depth_image.handle(),
18285 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
18286 m_errorMonitor->VerifyFound();
18287
18288 // Aspect mask doesn't match dest image format - VU 01201
18289 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
18290 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
18291 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01201);
18292 // Again redundant but unavoidable when provoking vu01201 w/o vu01200
18293 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "unmatched source and dest image depth/stencil formats");
18294 vkCmdCopyImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_GENERAL, depth_image.handle(),
18295 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
18296 m_errorMonitor->VerifyFound();
18297
18298 m_commandBuffer->EndCommandBuffer();
18299}
18300
Karl Schultz6addd812016-02-02 17:17:23 -070018301TEST_F(VkLayerTest, ResolveImageLowSampleCount) {
18302 VkResult err;
18303 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060018304
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018305 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
18306 "vkCmdResolveImage called with source sample count less than 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060018307
Tony Barbour1fa09702017-03-16 12:09:08 -060018308 ASSERT_NO_FATAL_FAILURE(Init());
Mike Stroyana3082432015-09-25 13:39:21 -060018309
18310 // Create two images of sample count 1 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070018311 VkImage srcImage;
18312 VkImage dstImage;
18313 VkDeviceMemory srcMem;
18314 VkDeviceMemory destMem;
18315 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060018316
18317 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070018318 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
18319 image_create_info.pNext = NULL;
18320 image_create_info.imageType = VK_IMAGE_TYPE_2D;
18321 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
18322 image_create_info.extent.width = 32;
18323 image_create_info.extent.height = 1;
18324 image_create_info.extent.depth = 1;
18325 image_create_info.mipLevels = 1;
18326 image_create_info.arrayLayers = 1;
18327 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
18328 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
18329 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
18330 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018331
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018332 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060018333 ASSERT_VK_SUCCESS(err);
18334
Karl Schultz6addd812016-02-02 17:17:23 -070018335 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060018336
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018337 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060018338 ASSERT_VK_SUCCESS(err);
18339
18340 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018341 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070018342 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18343 memAlloc.pNext = NULL;
18344 memAlloc.allocationSize = 0;
18345 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018346
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060018347 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060018348 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018349 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060018350 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018351 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060018352 ASSERT_VK_SUCCESS(err);
18353
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018354 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060018355 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018356 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060018357 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018358 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060018359 ASSERT_VK_SUCCESS(err);
18360
18361 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
18362 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018363 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060018364 ASSERT_VK_SUCCESS(err);
18365
Tony Barbour552f6c02016-12-21 14:34:07 -070018366 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060018367 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070018368 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
18369 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060018370 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080018371 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060018372 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060018373 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130018374 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060018375 resolveRegion.srcOffset.x = 0;
18376 resolveRegion.srcOffset.y = 0;
18377 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080018378 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018379 resolveRegion.dstSubresource.mipLevel = 0;
18380 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130018381 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018382 resolveRegion.dstOffset.x = 0;
18383 resolveRegion.dstOffset.y = 0;
18384 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018385 resolveRegion.extent.width = 1;
18386 resolveRegion.extent.height = 1;
18387 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018388 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070018389 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060018390
Chris Forbes8f36a8a2016-04-07 13:21:07 +120018391 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060018392
Chia-I Wuf7458c52015-10-26 21:10:41 +080018393 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018394 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080018395 vkFreeMemory(m_device->device(), srcMem, NULL);
18396 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060018397}
18398
Karl Schultz6addd812016-02-02 17:17:23 -070018399TEST_F(VkLayerTest, ResolveImageHighSampleCount) {
18400 VkResult err;
18401 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060018402
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018403 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
18404 "vkCmdResolveImage called with dest sample count greater than 1.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060018405
Tony Barbour1fa09702017-03-16 12:09:08 -060018406 ASSERT_NO_FATAL_FAILURE(Init());
Mike Stroyana3082432015-09-25 13:39:21 -060018407
Chris Forbesa7530692016-05-08 12:35:39 +120018408 // Create two images of sample count 4 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070018409 VkImage srcImage;
18410 VkImage dstImage;
18411 VkDeviceMemory srcMem;
18412 VkDeviceMemory destMem;
18413 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060018414
18415 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070018416 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
18417 image_create_info.pNext = NULL;
18418 image_create_info.imageType = VK_IMAGE_TYPE_2D;
18419 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
18420 image_create_info.extent.width = 32;
18421 image_create_info.extent.height = 1;
18422 image_create_info.extent.depth = 1;
18423 image_create_info.mipLevels = 1;
18424 image_create_info.arrayLayers = 1;
Chris Forbesa7530692016-05-08 12:35:39 +120018425 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070018426 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
18427 // Note: Some implementations expect color attachment usage for any
18428 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018429 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070018430 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018431
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018432 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060018433 ASSERT_VK_SUCCESS(err);
18434
Karl Schultz6addd812016-02-02 17:17:23 -070018435 // Note: Some implementations expect color attachment usage for any
18436 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018437 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060018438
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018439 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060018440 ASSERT_VK_SUCCESS(err);
18441
18442 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018443 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070018444 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18445 memAlloc.pNext = NULL;
18446 memAlloc.allocationSize = 0;
18447 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018448
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060018449 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060018450 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018451 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060018452 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018453 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060018454 ASSERT_VK_SUCCESS(err);
18455
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018456 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060018457 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018458 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060018459 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018460 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060018461 ASSERT_VK_SUCCESS(err);
18462
18463 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
18464 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018465 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060018466 ASSERT_VK_SUCCESS(err);
18467
Tony Barbour552f6c02016-12-21 14:34:07 -070018468 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060018469 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070018470 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
18471 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060018472 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080018473 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060018474 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060018475 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130018476 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060018477 resolveRegion.srcOffset.x = 0;
18478 resolveRegion.srcOffset.y = 0;
18479 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080018480 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018481 resolveRegion.dstSubresource.mipLevel = 0;
18482 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130018483 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018484 resolveRegion.dstOffset.x = 0;
18485 resolveRegion.dstOffset.y = 0;
18486 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018487 resolveRegion.extent.width = 1;
18488 resolveRegion.extent.height = 1;
18489 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018490 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070018491 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060018492
Chris Forbes8f36a8a2016-04-07 13:21:07 +120018493 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060018494
Chia-I Wuf7458c52015-10-26 21:10:41 +080018495 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018496 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080018497 vkFreeMemory(m_device->device(), srcMem, NULL);
18498 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060018499}
18500
Karl Schultz6addd812016-02-02 17:17:23 -070018501TEST_F(VkLayerTest, ResolveImageFormatMismatch) {
18502 VkResult err;
18503 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060018504
Mark Lobodzinski50fbef12017-02-06 15:31:33 -070018505 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018506 "vkCmdResolveImage called with unmatched source and dest formats.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060018507
Tony Barbour1fa09702017-03-16 12:09:08 -060018508 ASSERT_NO_FATAL_FAILURE(Init());
Mike Stroyana3082432015-09-25 13:39:21 -060018509
18510 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070018511 VkImage srcImage;
18512 VkImage dstImage;
18513 VkDeviceMemory srcMem;
18514 VkDeviceMemory destMem;
18515 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060018516
18517 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070018518 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
18519 image_create_info.pNext = NULL;
18520 image_create_info.imageType = VK_IMAGE_TYPE_2D;
18521 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
18522 image_create_info.extent.width = 32;
18523 image_create_info.extent.height = 1;
18524 image_create_info.extent.depth = 1;
18525 image_create_info.mipLevels = 1;
18526 image_create_info.arrayLayers = 1;
18527 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
18528 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
18529 // Note: Some implementations expect color attachment usage for any
18530 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018531 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070018532 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018533
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018534 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060018535 ASSERT_VK_SUCCESS(err);
18536
Karl Schultz6addd812016-02-02 17:17:23 -070018537 // Set format to something other than source image
18538 image_create_info.format = VK_FORMAT_R32_SFLOAT;
18539 // Note: Some implementations expect color attachment usage for any
18540 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018541 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070018542 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060018543
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018544 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060018545 ASSERT_VK_SUCCESS(err);
18546
18547 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018548 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070018549 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18550 memAlloc.pNext = NULL;
18551 memAlloc.allocationSize = 0;
18552 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018553
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060018554 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060018555 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018556 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060018557 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018558 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060018559 ASSERT_VK_SUCCESS(err);
18560
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018561 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060018562 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018563 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060018564 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018565 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060018566 ASSERT_VK_SUCCESS(err);
18567
18568 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
18569 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018570 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060018571 ASSERT_VK_SUCCESS(err);
18572
Tony Barbour552f6c02016-12-21 14:34:07 -070018573 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060018574 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070018575 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
18576 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060018577 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080018578 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060018579 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060018580 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130018581 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060018582 resolveRegion.srcOffset.x = 0;
18583 resolveRegion.srcOffset.y = 0;
18584 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080018585 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018586 resolveRegion.dstSubresource.mipLevel = 0;
18587 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130018588 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018589 resolveRegion.dstOffset.x = 0;
18590 resolveRegion.dstOffset.y = 0;
18591 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018592 resolveRegion.extent.width = 1;
18593 resolveRegion.extent.height = 1;
18594 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018595 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070018596 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060018597
Chris Forbes8f36a8a2016-04-07 13:21:07 +120018598 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060018599
Chia-I Wuf7458c52015-10-26 21:10:41 +080018600 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018601 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080018602 vkFreeMemory(m_device->device(), srcMem, NULL);
18603 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060018604}
18605
Karl Schultz6addd812016-02-02 17:17:23 -070018606TEST_F(VkLayerTest, ResolveImageTypeMismatch) {
18607 VkResult err;
18608 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060018609
Mark Lobodzinski50fbef12017-02-06 15:31:33 -070018610 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018611 "vkCmdResolveImage called with unmatched source and dest image types.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060018612
Tony Barbour1fa09702017-03-16 12:09:08 -060018613 ASSERT_NO_FATAL_FAILURE(Init());
Mike Stroyana3082432015-09-25 13:39:21 -060018614
18615 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070018616 VkImage srcImage;
18617 VkImage dstImage;
18618 VkDeviceMemory srcMem;
18619 VkDeviceMemory destMem;
18620 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060018621
18622 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070018623 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
18624 image_create_info.pNext = NULL;
18625 image_create_info.imageType = VK_IMAGE_TYPE_2D;
18626 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
18627 image_create_info.extent.width = 32;
18628 image_create_info.extent.height = 1;
18629 image_create_info.extent.depth = 1;
18630 image_create_info.mipLevels = 1;
18631 image_create_info.arrayLayers = 1;
18632 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
18633 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
18634 // Note: Some implementations expect color attachment usage for any
18635 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018636 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070018637 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018638
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018639 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060018640 ASSERT_VK_SUCCESS(err);
18641
Karl Schultz6addd812016-02-02 17:17:23 -070018642 image_create_info.imageType = VK_IMAGE_TYPE_1D;
18643 // Note: Some implementations expect color attachment usage for any
18644 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018645 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070018646 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060018647
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018648 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060018649 ASSERT_VK_SUCCESS(err);
18650
18651 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018652 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070018653 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18654 memAlloc.pNext = NULL;
18655 memAlloc.allocationSize = 0;
18656 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018657
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060018658 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060018659 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018660 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060018661 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018662 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060018663 ASSERT_VK_SUCCESS(err);
18664
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018665 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060018666 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018667 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060018668 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018669 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060018670 ASSERT_VK_SUCCESS(err);
18671
18672 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
18673 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018674 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060018675 ASSERT_VK_SUCCESS(err);
18676
Tony Barbour552f6c02016-12-21 14:34:07 -070018677 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060018678 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070018679 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
18680 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060018681 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080018682 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060018683 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060018684 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130018685 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060018686 resolveRegion.srcOffset.x = 0;
18687 resolveRegion.srcOffset.y = 0;
18688 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080018689 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018690 resolveRegion.dstSubresource.mipLevel = 0;
18691 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130018692 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018693 resolveRegion.dstOffset.x = 0;
18694 resolveRegion.dstOffset.y = 0;
18695 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018696 resolveRegion.extent.width = 1;
18697 resolveRegion.extent.height = 1;
18698 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018699 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070018700 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060018701
Chris Forbes8f36a8a2016-04-07 13:21:07 +120018702 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060018703
Chia-I Wuf7458c52015-10-26 21:10:41 +080018704 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018705 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080018706 vkFreeMemory(m_device->device(), srcMem, NULL);
18707 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060018708}
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018709
Karl Schultz6addd812016-02-02 17:17:23 -070018710TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018711 // Create a single Image descriptor and cause it to first hit an error due
Karl Schultz6addd812016-02-02 17:17:23 -070018712 // to using a DS format, then cause it to hit error due to COLOR_BIT not
18713 // set in aspect
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018714 // The image format check comes 2nd in validation so we trigger it first,
18715 // then when we cause aspect fail next, bad format check will be preempted
Karl Schultz6addd812016-02-02 17:17:23 -070018716 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018717
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018718 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
18719 "Combination depth/stencil image formats can have only the ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060018720
Tony Barbour1fa09702017-03-16 12:09:08 -060018721 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -060018722 auto depth_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbourf887b162017-03-09 10:06:46 -070018723 if (!depth_format) {
18724 return;
18725 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060018726
Chia-I Wu1b99bb22015-10-27 19:25:11 +080018727 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070018728 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
18729 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018730
18731 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070018732 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
18733 ds_pool_ci.pNext = NULL;
18734 ds_pool_ci.maxSets = 1;
18735 ds_pool_ci.poolSizeCount = 1;
18736 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018737
18738 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018739 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018740 ASSERT_VK_SUCCESS(err);
18741
18742 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070018743 dsl_binding.binding = 0;
18744 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
18745 dsl_binding.descriptorCount = 1;
18746 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
18747 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018748
18749 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070018750 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
18751 ds_layout_ci.pNext = NULL;
18752 ds_layout_ci.bindingCount = 1;
18753 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018754 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018755 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018756 ASSERT_VK_SUCCESS(err);
18757
18758 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018759 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080018760 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070018761 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018762 alloc_info.descriptorPool = ds_pool;
18763 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018764 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018765 ASSERT_VK_SUCCESS(err);
18766
Karl Schultz6addd812016-02-02 17:17:23 -070018767 VkImage image_bad;
18768 VkImage image_good;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018769 // One bad format and one good format for Color attachment
Tony Barbourf887b162017-03-09 10:06:46 -070018770 const VkFormat tex_format_bad = depth_format;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018771 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
Karl Schultz6addd812016-02-02 17:17:23 -070018772 const int32_t tex_width = 32;
18773 const int32_t tex_height = 32;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018774
18775 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070018776 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
18777 image_create_info.pNext = NULL;
18778 image_create_info.imageType = VK_IMAGE_TYPE_2D;
18779 image_create_info.format = tex_format_bad;
18780 image_create_info.extent.width = tex_width;
18781 image_create_info.extent.height = tex_height;
18782 image_create_info.extent.depth = 1;
18783 image_create_info.mipLevels = 1;
18784 image_create_info.arrayLayers = 1;
18785 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
18786 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018787 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070018788 image_create_info.flags = 0;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018789
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018790 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018791 ASSERT_VK_SUCCESS(err);
18792 image_create_info.format = tex_format_good;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018793 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
18794 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_good);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018795 ASSERT_VK_SUCCESS(err);
18796
Rene Lindsayf1e89c82016-12-28 13:18:31 -070018797 // ---Bind image memory---
18798 VkMemoryRequirements img_mem_reqs;
18799 vkGetImageMemoryRequirements(m_device->device(), image_bad, &img_mem_reqs);
18800 VkMemoryAllocateInfo image_alloc_info = {};
18801 image_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18802 image_alloc_info.pNext = NULL;
18803 image_alloc_info.memoryTypeIndex = 0;
18804 image_alloc_info.allocationSize = img_mem_reqs.size;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018805 bool pass =
18806 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 -070018807 ASSERT_TRUE(pass);
18808 VkDeviceMemory mem;
18809 err = vkAllocateMemory(m_device->device(), &image_alloc_info, NULL, &mem);
18810 ASSERT_VK_SUCCESS(err);
18811 err = vkBindImageMemory(m_device->device(), image_bad, mem, 0);
18812 ASSERT_VK_SUCCESS(err);
18813 // -----------------------
18814
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018815 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130018816 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070018817 image_view_create_info.image = image_bad;
18818 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
18819 image_view_create_info.format = tex_format_bad;
18820 image_view_create_info.subresourceRange.baseArrayLayer = 0;
18821 image_view_create_info.subresourceRange.baseMipLevel = 0;
18822 image_view_create_info.subresourceRange.layerCount = 1;
18823 image_view_create_info.subresourceRange.levelCount = 1;
Rene Lindsayf1e89c82016-12-28 13:18:31 -070018824 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018825
18826 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018827 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060018828
Chris Forbes8f36a8a2016-04-07 13:21:07 +120018829 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018830
Chia-I Wuf7458c52015-10-26 21:10:41 +080018831 vkDestroyImage(m_device->device(), image_bad, NULL);
18832 vkDestroyImage(m_device->device(), image_good, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080018833 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
18834 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Rene Lindsayf1e89c82016-12-28 13:18:31 -070018835
18836 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018837}
Tobin Ehlis6e23d772016-05-19 11:08:34 -060018838
18839TEST_F(VkLayerTest, ClearImageErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018840 TEST_DESCRIPTION(
18841 "Call ClearColorImage w/ a depth|stencil image and "
18842 "ClearDepthStencilImage with a color image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060018843
Tony Barbour1fa09702017-03-16 12:09:08 -060018844 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -060018845 auto depth_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbourf887b162017-03-09 10:06:46 -070018846 if (!depth_format) {
18847 return;
18848 }
Tobin Ehlis6e23d772016-05-19 11:08:34 -060018849 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18850
Tony Barbour552f6c02016-12-21 14:34:07 -070018851 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis6e23d772016-05-19 11:08:34 -060018852
18853 // Color image
18854 VkClearColorValue clear_color;
18855 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
18856 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
18857 const VkFormat color_format = VK_FORMAT_B8G8R8A8_UNORM;
18858 const int32_t img_width = 32;
18859 const int32_t img_height = 32;
18860 VkImageCreateInfo image_create_info = {};
18861 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
18862 image_create_info.pNext = NULL;
18863 image_create_info.imageType = VK_IMAGE_TYPE_2D;
18864 image_create_info.format = color_format;
18865 image_create_info.extent.width = img_width;
18866 image_create_info.extent.height = img_height;
18867 image_create_info.extent.depth = 1;
18868 image_create_info.mipLevels = 1;
18869 image_create_info.arrayLayers = 1;
18870 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
18871 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
18872 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
18873
18874 vk_testing::Image color_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018875 color_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060018876
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018877 const VkImageSubresourceRange color_range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060018878
18879 // Depth/Stencil image
18880 VkClearDepthStencilValue clear_value = {0};
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018881 reqs = 0; // don't need HOST_VISIBLE DS image
Tobin Ehlis6e23d772016-05-19 11:08:34 -060018882 VkImageCreateInfo ds_image_create_info = vk_testing::Image::create_info();
18883 ds_image_create_info.imageType = VK_IMAGE_TYPE_2D;
Tony Barbourf887b162017-03-09 10:06:46 -070018884 ds_image_create_info.format = depth_format;
Tobin Ehlis6e23d772016-05-19 11:08:34 -060018885 ds_image_create_info.extent.width = 64;
18886 ds_image_create_info.extent.height = 64;
18887 ds_image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Rene Lindsaya1fc64a2016-12-27 15:18:54 -070018888 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 -060018889
18890 vk_testing::Image ds_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018891 ds_image.init(*m_device, (const VkImageCreateInfo &)ds_image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060018892
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018893 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 -060018894
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018895 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060018896
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018897 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tobin Ehlis6e23d772016-05-19 11:08:34 -060018898 &color_range);
18899
18900 m_errorMonitor->VerifyFound();
18901
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018902 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
18903 "vkCmdClearColorImage called with "
18904 "image created without "
18905 "VK_IMAGE_USAGE_TRANSFER_DST_BIT");
Tony Barbour26434b92016-06-02 09:43:50 -060018906
Rene Lindsaya1fc64a2016-12-27 15:18:54 -070018907 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tony Barbour26434b92016-06-02 09:43:50 -060018908 &color_range);
18909
18910 m_errorMonitor->VerifyFound();
18911
Tobin Ehlis6e23d772016-05-19 11:08:34 -060018912 // Call CmdClearDepthStencilImage with color image
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018913 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
18914 "vkCmdClearDepthStencilImage called without a depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060018915
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018916 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
18917 &clear_value, 1, &ds_range);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060018918
18919 m_errorMonitor->VerifyFound();
18920}
Tobin Ehliscde08892015-09-22 10:11:37 -060018921
Mike Schuchardt35fece12017-03-07 14:40:28 -070018922TEST_F(VkLayerTest, CommandQueueFlags) {
18923 TEST_DESCRIPTION(
18924 "Allocate a command buffer on a queue that does not support graphics and try to issue a "
18925 "graphics-only command");
18926
18927 ASSERT_NO_FATAL_FAILURE(Init());
18928
18929 uint32_t queueFamilyIndex = m_device->QueueFamilyWithoutCapabilities(VK_QUEUE_GRAPHICS_BIT);
Dave Houlton3c9fca72017-03-27 17:25:54 -060018930 if (queueFamilyIndex == UINT32_MAX) {
Mike Schuchardt35fece12017-03-07 14:40:28 -070018931 printf(" Non-graphics queue family not found; skipped.\n");
18932 return;
18933 } else {
18934 // Create command pool on a non-graphics queue
18935 VkCommandPoolObj command_pool(m_device, queueFamilyIndex);
18936
18937 // Setup command buffer on pool
18938 VkCommandBufferObj command_buffer(m_device, &command_pool);
18939 command_buffer.BeginCommandBuffer();
18940
18941 // Issue a graphics only command
18942 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01446);
18943 VkViewport viewport = {0, 0, 16, 16, 0, 1};
18944 command_buffer.SetViewport(0, 1, &viewport);
18945 m_errorMonitor->VerifyFound();
18946 }
18947}
18948
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018949// WSI Enabled Tests
18950//
Chris Forbes09368e42016-10-13 11:59:22 +130018951#if 0
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018952TEST_F(VkWsiEnabledLayerTest, TestEnabledWsi) {
18953
18954#if defined(VK_USE_PLATFORM_XCB_KHR)
18955 VkSurfaceKHR surface = VK_NULL_HANDLE;
18956
18957 VkResult err;
18958 bool pass;
18959 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
18960 VkSwapchainCreateInfoKHR swapchain_create_info = {};
18961 // uint32_t swapchain_image_count = 0;
18962 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
18963 // uint32_t image_index = 0;
18964 // VkPresentInfoKHR present_info = {};
18965
Tony Barbour1fa09702017-03-16 12:09:08 -060018966 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018967
18968 // Use the create function from one of the VK_KHR_*_surface extension in
18969 // order to create a surface, testing all known errors in the process,
18970 // before successfully creating a surface:
18971 // First, try to create a surface without a VkXcbSurfaceCreateInfoKHR:
18972 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo specified as NULL");
18973 err = vkCreateXcbSurfaceKHR(instance(), NULL, NULL, &surface);
18974 pass = (err != VK_SUCCESS);
18975 ASSERT_TRUE(pass);
18976 m_errorMonitor->VerifyFound();
18977
18978 // Next, try to create a surface with the wrong
18979 // VkXcbSurfaceCreateInfoKHR::sType:
18980 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
18981 xcb_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
18982 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
18983 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
18984 pass = (err != VK_SUCCESS);
18985 ASSERT_TRUE(pass);
18986 m_errorMonitor->VerifyFound();
18987
18988 // Create a native window, and then correctly create a surface:
18989 xcb_connection_t *connection;
18990 xcb_screen_t *screen;
18991 xcb_window_t xcb_window;
18992 xcb_intern_atom_reply_t *atom_wm_delete_window;
18993
18994 const xcb_setup_t *setup;
18995 xcb_screen_iterator_t iter;
18996 int scr;
18997 uint32_t value_mask, value_list[32];
18998 int width = 1;
18999 int height = 1;
19000
19001 connection = xcb_connect(NULL, &scr);
19002 ASSERT_TRUE(connection != NULL);
19003 setup = xcb_get_setup(connection);
19004 iter = xcb_setup_roots_iterator(setup);
19005 while (scr-- > 0)
19006 xcb_screen_next(&iter);
19007 screen = iter.data;
19008
19009 xcb_window = xcb_generate_id(connection);
19010
19011 value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
19012 value_list[0] = screen->black_pixel;
19013 value_list[1] = XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_STRUCTURE_NOTIFY;
19014
19015 xcb_create_window(connection, XCB_COPY_FROM_PARENT, xcb_window, screen->root, 0, 0, width, height, 0,
19016 XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual, value_mask, value_list);
19017
19018 /* Magic code that will send notification when window is destroyed */
19019 xcb_intern_atom_cookie_t cookie = xcb_intern_atom(connection, 1, 12, "WM_PROTOCOLS");
19020 xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply(connection, cookie, 0);
19021
19022 xcb_intern_atom_cookie_t cookie2 = xcb_intern_atom(connection, 0, 16, "WM_DELETE_WINDOW");
19023 atom_wm_delete_window = xcb_intern_atom_reply(connection, cookie2, 0);
19024 xcb_change_property(connection, XCB_PROP_MODE_REPLACE, xcb_window, (*reply).atom, 4, 32, 1, &(*atom_wm_delete_window).atom);
19025 free(reply);
19026
19027 xcb_map_window(connection, xcb_window);
19028
19029 // Force the x/y coordinates to 100,100 results are identical in consecutive
19030 // runs
19031 const uint32_t coords[] = { 100, 100 };
19032 xcb_configure_window(connection, xcb_window, XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, coords);
19033
19034 // Finally, try to correctly create a surface:
19035 xcb_create_info.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
19036 xcb_create_info.pNext = NULL;
19037 xcb_create_info.flags = 0;
19038 xcb_create_info.connection = connection;
19039 xcb_create_info.window = xcb_window;
19040 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
19041 pass = (err == VK_SUCCESS);
19042 ASSERT_TRUE(pass);
19043
19044 // Check if surface supports presentation:
19045
19046 // 1st, do so without having queried the queue families:
19047 VkBool32 supported = false;
19048 // TODO: Get the following error to come out:
19049 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
19050 "called before calling the vkGetPhysicalDeviceQueueFamilyProperties "
19051 "function");
19052 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
19053 pass = (err != VK_SUCCESS);
19054 // ASSERT_TRUE(pass);
19055 // m_errorMonitor->VerifyFound();
19056
19057 // Next, query a queue family index that's too large:
19058 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
19059 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 100000, surface, &supported);
19060 pass = (err != VK_SUCCESS);
19061 ASSERT_TRUE(pass);
19062 m_errorMonitor->VerifyFound();
19063
19064 // Finally, do so correctly:
19065 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
19066 // SUPPORTED
19067 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
19068 pass = (err == VK_SUCCESS);
19069 ASSERT_TRUE(pass);
19070
19071 // Before proceeding, try to create a swapchain without having called
19072 // vkGetPhysicalDeviceSurfaceCapabilitiesKHR():
19073 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
19074 swapchain_create_info.pNext = NULL;
19075 swapchain_create_info.flags = 0;
19076 swapchain_create_info.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
19077 swapchain_create_info.surface = surface;
19078 swapchain_create_info.imageArrayLayers = 1;
19079 swapchain_create_info.preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
19080 swapchain_create_info.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
19081 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
19082 "called before calling vkGetPhysicalDeviceSurfaceCapabilitiesKHR().");
19083 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
19084 pass = (err != VK_SUCCESS);
19085 ASSERT_TRUE(pass);
19086 m_errorMonitor->VerifyFound();
19087
19088 // Get the surface capabilities:
19089 VkSurfaceCapabilitiesKHR surface_capabilities;
19090
19091 // Do so correctly (only error logged by this entrypoint is if the
19092 // extension isn't enabled):
19093 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &surface_capabilities);
19094 pass = (err == VK_SUCCESS);
19095 ASSERT_TRUE(pass);
19096
19097 // Get the surface formats:
19098 uint32_t surface_format_count;
19099
19100 // First, try without a pointer to surface_format_count:
19101 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSurfaceFormatCount "
19102 "specified as NULL");
19103 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, NULL, NULL);
19104 pass = (err == VK_SUCCESS);
19105 ASSERT_TRUE(pass);
19106 m_errorMonitor->VerifyFound();
19107
19108 // Next, call with a non-NULL pSurfaceFormats, even though we haven't
19109 // correctly done a 1st try (to get the count):
19110 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
19111 surface_format_count = 0;
19112 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, (VkSurfaceFormatKHR *)&surface_format_count);
19113 pass = (err == VK_SUCCESS);
19114 ASSERT_TRUE(pass);
19115 m_errorMonitor->VerifyFound();
19116
19117 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
19118 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
19119 pass = (err == VK_SUCCESS);
19120 ASSERT_TRUE(pass);
19121
19122 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
19123 VkSurfaceFormatKHR *surface_formats = (VkSurfaceFormatKHR *)malloc(surface_format_count * sizeof(VkSurfaceFormatKHR));
19124
19125 // Next, do a 2nd try with surface_format_count being set too high:
19126 surface_format_count += 5;
19127 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
19128 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
19129 pass = (err == VK_SUCCESS);
19130 ASSERT_TRUE(pass);
19131 m_errorMonitor->VerifyFound();
19132
19133 // Finally, do a correct 1st and 2nd try:
19134 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
19135 pass = (err == VK_SUCCESS);
19136 ASSERT_TRUE(pass);
19137 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
19138 pass = (err == VK_SUCCESS);
19139 ASSERT_TRUE(pass);
19140
19141 // Get the surface present modes:
19142 uint32_t surface_present_mode_count;
19143
19144 // First, try without a pointer to surface_format_count:
19145 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pPresentModeCount "
19146 "specified as NULL");
19147
19148 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, NULL, NULL);
19149 pass = (err == VK_SUCCESS);
19150 ASSERT_TRUE(pass);
19151 m_errorMonitor->VerifyFound();
19152
19153 // Next, call with a non-NULL VkPresentModeKHR, even though we haven't
19154 // correctly done a 1st try (to get the count):
19155 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
19156 surface_present_mode_count = 0;
19157 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count,
19158 (VkPresentModeKHR *)&surface_present_mode_count);
19159 pass = (err == VK_SUCCESS);
19160 ASSERT_TRUE(pass);
19161 m_errorMonitor->VerifyFound();
19162
19163 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
19164 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
19165 pass = (err == VK_SUCCESS);
19166 ASSERT_TRUE(pass);
19167
19168 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
19169 VkPresentModeKHR *surface_present_modes = (VkPresentModeKHR *)malloc(surface_present_mode_count * sizeof(VkPresentModeKHR));
19170
19171 // Next, do a 2nd try with surface_format_count being set too high:
19172 surface_present_mode_count += 5;
19173 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
19174 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
19175 pass = (err == VK_SUCCESS);
19176 ASSERT_TRUE(pass);
19177 m_errorMonitor->VerifyFound();
19178
19179 // Finally, do a correct 1st and 2nd try:
19180 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
19181 pass = (err == VK_SUCCESS);
19182 ASSERT_TRUE(pass);
19183 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
19184 pass = (err == VK_SUCCESS);
19185 ASSERT_TRUE(pass);
19186
19187 // Create a swapchain:
19188
19189 // First, try without a pointer to swapchain_create_info:
19190 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo "
19191 "specified as NULL");
19192
19193 err = vkCreateSwapchainKHR(m_device->device(), NULL, NULL, &swapchain);
19194 pass = (err != VK_SUCCESS);
19195 ASSERT_TRUE(pass);
19196 m_errorMonitor->VerifyFound();
19197
19198 // Next, call with a non-NULL swapchain_create_info, that has the wrong
19199 // sType:
19200 swapchain_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
19201 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
19202
19203 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
19204 pass = (err != VK_SUCCESS);
19205 ASSERT_TRUE(pass);
19206 m_errorMonitor->VerifyFound();
19207
19208 // Next, call with a NULL swapchain pointer:
19209 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
19210 swapchain_create_info.pNext = NULL;
19211 swapchain_create_info.flags = 0;
19212 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSwapchain "
19213 "specified as NULL");
19214
19215 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, NULL);
19216 pass = (err != VK_SUCCESS);
19217 ASSERT_TRUE(pass);
19218 m_errorMonitor->VerifyFound();
19219
19220 // TODO: Enhance swapchain layer so that
19221 // swapchain_create_info.queueFamilyIndexCount is checked against something?
19222
19223 // Next, call with a queue family index that's too large:
19224 uint32_t queueFamilyIndex[2] = { 100000, 0 };
19225 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
19226 swapchain_create_info.queueFamilyIndexCount = 2;
19227 swapchain_create_info.pQueueFamilyIndices = queueFamilyIndex;
19228 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
19229 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
19230 pass = (err != VK_SUCCESS);
19231 ASSERT_TRUE(pass);
19232 m_errorMonitor->VerifyFound();
19233
19234 // Next, call a queueFamilyIndexCount that's too small for CONCURRENT:
19235 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
19236 swapchain_create_info.queueFamilyIndexCount = 1;
19237 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
19238 "but with a bad value(s) for pCreateInfo->queueFamilyIndexCount or "
19239 "pCreateInfo->pQueueFamilyIndices).");
19240 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
19241 pass = (err != VK_SUCCESS);
19242 ASSERT_TRUE(pass);
19243 m_errorMonitor->VerifyFound();
19244
19245 // Next, call with an invalid imageSharingMode:
19246 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_MAX_ENUM;
19247 swapchain_create_info.queueFamilyIndexCount = 1;
19248 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
19249 "called with a non-supported pCreateInfo->imageSharingMode (i.e.");
19250 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
19251 pass = (err != VK_SUCCESS);
19252 ASSERT_TRUE(pass);
19253 m_errorMonitor->VerifyFound();
19254 // Fix for the future:
19255 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
19256 // SUPPORTED
19257 swapchain_create_info.queueFamilyIndexCount = 0;
19258 queueFamilyIndex[0] = 0;
19259 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
19260
19261 // TODO: CONTINUE TESTING VALIDATION OF vkCreateSwapchainKHR() ...
19262 // Get the images from a swapchain:
19263 // Acquire an image from a swapchain:
19264 // Present an image to a swapchain:
19265 // Destroy the swapchain:
19266
19267 // TODOs:
19268 //
19269 // - Try destroying the device without first destroying the swapchain
19270 //
19271 // - Try destroying the device without first destroying the surface
19272 //
19273 // - Try destroying the surface without first destroying the swapchain
19274
19275 // Destroy the surface:
19276 vkDestroySurfaceKHR(instance(), surface, NULL);
19277
19278 // Tear down the window:
19279 xcb_destroy_window(connection, xcb_window);
19280 xcb_disconnect(connection);
19281
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019282#else // VK_USE_PLATFORM_XCB_KHR
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019283 return;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019284#endif // VK_USE_PLATFORM_XCB_KHR
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019285}
Chris Forbes09368e42016-10-13 11:59:22 +130019286#endif
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019287
19288//
19289// POSITIVE VALIDATION TESTS
19290//
19291// These tests do not expect to encounter ANY validation errors pass only if this is true
19292
Mark Lobodzinski781aeb52017-02-22 10:57:53 -070019293TEST_F(VkPositiveLayerTest, SecondaryCommandBufferClearColorAttachments) {
19294 TEST_DESCRIPTION("Create a secondary command buffer and record a CmdClearAttachments call into it");
Tony Barbour1fa09702017-03-16 12:09:08 -060019295 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski781aeb52017-02-22 10:57:53 -070019296 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19297
19298 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
19299 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mike Schuchardt06304c22017-03-01 17:09:09 -070019300 command_buffer_allocate_info.commandPool = m_commandPool->handle();
Mark Lobodzinski781aeb52017-02-22 10:57:53 -070019301 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
19302 command_buffer_allocate_info.commandBufferCount = 1;
19303
19304 VkCommandBuffer secondary_command_buffer;
19305 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
19306 VkCommandBufferBeginInfo command_buffer_begin_info = {};
19307 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
19308 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
19309 command_buffer_inheritance_info.renderPass = m_renderPass;
19310 command_buffer_inheritance_info.framebuffer = m_framebuffer;
19311
19312 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19313 command_buffer_begin_info.flags =
19314 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
19315 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
19316
19317 vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
19318 VkClearAttachment color_attachment;
19319 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
19320 color_attachment.clearValue.color.float32[0] = 0;
19321 color_attachment.clearValue.color.float32[1] = 0;
19322 color_attachment.clearValue.color.float32[2] = 0;
19323 color_attachment.clearValue.color.float32[3] = 0;
19324 color_attachment.colorAttachment = 0;
19325 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
19326 vkCmdClearAttachments(secondary_command_buffer, 1, &color_attachment, 1, &clear_rect);
19327}
19328
Tobin Ehlise0006882016-11-03 10:14:28 -060019329TEST_F(VkPositiveLayerTest, SecondaryCommandBufferImageLayoutTransitions) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019330 TEST_DESCRIPTION(
19331 "Perform an image layout transition in a secondary command buffer followed "
19332 "by a transition in the primary.");
Tobin Ehlise0006882016-11-03 10:14:28 -060019333 VkResult err;
19334 m_errorMonitor->ExpectSuccess();
Tony Barbour1fa09702017-03-16 12:09:08 -060019335 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -060019336 auto depth_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbourf887b162017-03-09 10:06:46 -070019337 if (!depth_format) {
19338 return;
19339 }
Tobin Ehlise0006882016-11-03 10:14:28 -060019340 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19341 // Allocate a secondary and primary cmd buffer
19342 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
19343 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mike Schuchardt06304c22017-03-01 17:09:09 -070019344 command_buffer_allocate_info.commandPool = m_commandPool->handle();
Tobin Ehlise0006882016-11-03 10:14:28 -060019345 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
19346 command_buffer_allocate_info.commandBufferCount = 1;
19347
19348 VkCommandBuffer secondary_command_buffer;
19349 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
19350 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19351 VkCommandBuffer primary_command_buffer;
19352 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &primary_command_buffer));
19353 VkCommandBufferBeginInfo command_buffer_begin_info = {};
19354 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
19355 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
19356 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19357 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
19358 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
19359
19360 err = vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
19361 ASSERT_VK_SUCCESS(err);
19362 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060019363 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 -060019364 ASSERT_TRUE(image.initialized());
19365 VkImageMemoryBarrier img_barrier = {};
19366 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
19367 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
19368 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
19369 img_barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
19370 img_barrier.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19371 img_barrier.image = image.handle();
19372 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
19373 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
19374 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
19375 img_barrier.subresourceRange.baseArrayLayer = 0;
19376 img_barrier.subresourceRange.baseMipLevel = 0;
19377 img_barrier.subresourceRange.layerCount = 1;
19378 img_barrier.subresourceRange.levelCount = 1;
19379 vkCmdPipelineBarrier(secondary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr,
19380 0, nullptr, 1, &img_barrier);
19381 err = vkEndCommandBuffer(secondary_command_buffer);
19382 ASSERT_VK_SUCCESS(err);
19383
19384 // Now update primary cmd buffer to execute secondary and transitions image
19385 command_buffer_begin_info.pInheritanceInfo = nullptr;
19386 err = vkBeginCommandBuffer(primary_command_buffer, &command_buffer_begin_info);
19387 ASSERT_VK_SUCCESS(err);
19388 vkCmdExecuteCommands(primary_command_buffer, 1, &secondary_command_buffer);
19389 VkImageMemoryBarrier img_barrier2 = {};
19390 img_barrier2.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
19391 img_barrier2.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
19392 img_barrier2.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
19393 img_barrier2.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19394 img_barrier2.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19395 img_barrier2.image = image.handle();
19396 img_barrier2.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
19397 img_barrier2.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
19398 img_barrier2.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
19399 img_barrier2.subresourceRange.baseArrayLayer = 0;
19400 img_barrier2.subresourceRange.baseMipLevel = 0;
19401 img_barrier2.subresourceRange.layerCount = 1;
19402 img_barrier2.subresourceRange.levelCount = 1;
19403 vkCmdPipelineBarrier(primary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
19404 nullptr, 1, &img_barrier2);
19405 err = vkEndCommandBuffer(primary_command_buffer);
19406 ASSERT_VK_SUCCESS(err);
19407 VkSubmitInfo submit_info = {};
19408 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19409 submit_info.commandBufferCount = 1;
19410 submit_info.pCommandBuffers = &primary_command_buffer;
19411 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
19412 ASSERT_VK_SUCCESS(err);
19413 m_errorMonitor->VerifyNotFound();
19414 err = vkDeviceWaitIdle(m_device->device());
19415 ASSERT_VK_SUCCESS(err);
Mike Schuchardt06304c22017-03-01 17:09:09 -070019416 vkFreeCommandBuffers(m_device->device(), m_commandPool->handle(), 1, &secondary_command_buffer);
19417 vkFreeCommandBuffers(m_device->device(), m_commandPool->handle(), 1, &primary_command_buffer);
Tobin Ehlise0006882016-11-03 10:14:28 -060019418}
19419
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019420// This is a positive test. No failures are expected.
19421TEST_F(VkPositiveLayerTest, IgnoreUnrelatedDescriptor) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019422 TEST_DESCRIPTION(
19423 "Ensure that the vkUpdateDescriptorSets validation code "
19424 "is ignoring VkWriteDescriptorSet members that are not "
19425 "related to the descriptor type specified by "
19426 "VkWriteDescriptorSet::descriptorType. Correct "
19427 "validation behavior will result in the test running to "
19428 "completion without validation errors.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019429
19430 const uintptr_t invalid_ptr = 0xcdcdcdcd;
19431
Tony Barbour1fa09702017-03-16 12:09:08 -060019432 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019433
19434 // Image Case
19435 {
19436 m_errorMonitor->ExpectSuccess();
19437
19438 VkImage image;
19439 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
19440 const int32_t tex_width = 32;
19441 const int32_t tex_height = 32;
19442 VkImageCreateInfo image_create_info = {};
19443 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
19444 image_create_info.pNext = NULL;
19445 image_create_info.imageType = VK_IMAGE_TYPE_2D;
19446 image_create_info.format = tex_format;
19447 image_create_info.extent.width = tex_width;
19448 image_create_info.extent.height = tex_height;
19449 image_create_info.extent.depth = 1;
19450 image_create_info.mipLevels = 1;
19451 image_create_info.arrayLayers = 1;
19452 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
19453 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
19454 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
19455 image_create_info.flags = 0;
19456 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
19457 ASSERT_VK_SUCCESS(err);
19458
19459 VkMemoryRequirements memory_reqs;
19460 VkDeviceMemory image_memory;
19461 bool pass;
19462 VkMemoryAllocateInfo memory_info = {};
19463 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
19464 memory_info.pNext = NULL;
19465 memory_info.allocationSize = 0;
19466 memory_info.memoryTypeIndex = 0;
19467 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
19468 memory_info.allocationSize = memory_reqs.size;
19469 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
19470 ASSERT_TRUE(pass);
19471 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
19472 ASSERT_VK_SUCCESS(err);
19473 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
19474 ASSERT_VK_SUCCESS(err);
19475
19476 VkImageViewCreateInfo image_view_create_info = {};
19477 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
19478 image_view_create_info.image = image;
19479 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
19480 image_view_create_info.format = tex_format;
19481 image_view_create_info.subresourceRange.layerCount = 1;
19482 image_view_create_info.subresourceRange.baseMipLevel = 0;
19483 image_view_create_info.subresourceRange.levelCount = 1;
19484 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
19485
19486 VkImageView view;
19487 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
19488 ASSERT_VK_SUCCESS(err);
19489
19490 VkDescriptorPoolSize ds_type_count = {};
19491 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
19492 ds_type_count.descriptorCount = 1;
19493
19494 VkDescriptorPoolCreateInfo ds_pool_ci = {};
19495 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
19496 ds_pool_ci.pNext = NULL;
19497 ds_pool_ci.maxSets = 1;
19498 ds_pool_ci.poolSizeCount = 1;
19499 ds_pool_ci.pPoolSizes = &ds_type_count;
19500
19501 VkDescriptorPool ds_pool;
19502 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
19503 ASSERT_VK_SUCCESS(err);
19504
19505 VkDescriptorSetLayoutBinding dsl_binding = {};
19506 dsl_binding.binding = 0;
19507 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
19508 dsl_binding.descriptorCount = 1;
19509 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
19510 dsl_binding.pImmutableSamplers = NULL;
19511
19512 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
19513 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
19514 ds_layout_ci.pNext = NULL;
19515 ds_layout_ci.bindingCount = 1;
19516 ds_layout_ci.pBindings = &dsl_binding;
19517 VkDescriptorSetLayout ds_layout;
19518 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
19519 ASSERT_VK_SUCCESS(err);
19520
19521 VkDescriptorSet descriptor_set;
19522 VkDescriptorSetAllocateInfo alloc_info = {};
19523 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
19524 alloc_info.descriptorSetCount = 1;
19525 alloc_info.descriptorPool = ds_pool;
19526 alloc_info.pSetLayouts = &ds_layout;
19527 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
19528 ASSERT_VK_SUCCESS(err);
19529
19530 VkDescriptorImageInfo image_info = {};
19531 image_info.imageView = view;
19532 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
19533
19534 VkWriteDescriptorSet descriptor_write;
19535 memset(&descriptor_write, 0, sizeof(descriptor_write));
19536 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
19537 descriptor_write.dstSet = descriptor_set;
19538 descriptor_write.dstBinding = 0;
19539 descriptor_write.descriptorCount = 1;
19540 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
19541 descriptor_write.pImageInfo = &image_info;
19542
19543 // Set pBufferInfo and pTexelBufferView to invalid values, which should
19544 // be
19545 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE.
19546 // This will most likely produce a crash if the parameter_validation
19547 // layer
19548 // does not correctly ignore pBufferInfo.
19549 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
19550 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
19551
19552 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
19553
19554 m_errorMonitor->VerifyNotFound();
19555
19556 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
19557 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
19558 vkDestroyImageView(m_device->device(), view, NULL);
19559 vkDestroyImage(m_device->device(), image, NULL);
19560 vkFreeMemory(m_device->device(), image_memory, NULL);
19561 }
19562
19563 // Buffer Case
19564 {
19565 m_errorMonitor->ExpectSuccess();
19566
19567 VkBuffer buffer;
19568 uint32_t queue_family_index = 0;
19569 VkBufferCreateInfo buffer_create_info = {};
19570 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
19571 buffer_create_info.size = 1024;
19572 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
19573 buffer_create_info.queueFamilyIndexCount = 1;
19574 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
19575
19576 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
19577 ASSERT_VK_SUCCESS(err);
19578
19579 VkMemoryRequirements memory_reqs;
19580 VkDeviceMemory buffer_memory;
19581 bool pass;
19582 VkMemoryAllocateInfo memory_info = {};
19583 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
19584 memory_info.pNext = NULL;
19585 memory_info.allocationSize = 0;
19586 memory_info.memoryTypeIndex = 0;
19587
19588 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
19589 memory_info.allocationSize = memory_reqs.size;
19590 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
19591 ASSERT_TRUE(pass);
19592
19593 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
19594 ASSERT_VK_SUCCESS(err);
19595 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
19596 ASSERT_VK_SUCCESS(err);
19597
19598 VkDescriptorPoolSize ds_type_count = {};
19599 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
19600 ds_type_count.descriptorCount = 1;
19601
19602 VkDescriptorPoolCreateInfo ds_pool_ci = {};
19603 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
19604 ds_pool_ci.pNext = NULL;
19605 ds_pool_ci.maxSets = 1;
19606 ds_pool_ci.poolSizeCount = 1;
19607 ds_pool_ci.pPoolSizes = &ds_type_count;
19608
19609 VkDescriptorPool ds_pool;
19610 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
19611 ASSERT_VK_SUCCESS(err);
19612
19613 VkDescriptorSetLayoutBinding dsl_binding = {};
19614 dsl_binding.binding = 0;
19615 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
19616 dsl_binding.descriptorCount = 1;
19617 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
19618 dsl_binding.pImmutableSamplers = NULL;
19619
19620 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
19621 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
19622 ds_layout_ci.pNext = NULL;
19623 ds_layout_ci.bindingCount = 1;
19624 ds_layout_ci.pBindings = &dsl_binding;
19625 VkDescriptorSetLayout ds_layout;
19626 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
19627 ASSERT_VK_SUCCESS(err);
19628
19629 VkDescriptorSet descriptor_set;
19630 VkDescriptorSetAllocateInfo alloc_info = {};
19631 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
19632 alloc_info.descriptorSetCount = 1;
19633 alloc_info.descriptorPool = ds_pool;
19634 alloc_info.pSetLayouts = &ds_layout;
19635 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
19636 ASSERT_VK_SUCCESS(err);
19637
19638 VkDescriptorBufferInfo buffer_info = {};
19639 buffer_info.buffer = buffer;
19640 buffer_info.offset = 0;
19641 buffer_info.range = 1024;
19642
19643 VkWriteDescriptorSet descriptor_write;
19644 memset(&descriptor_write, 0, sizeof(descriptor_write));
19645 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
19646 descriptor_write.dstSet = descriptor_set;
19647 descriptor_write.dstBinding = 0;
19648 descriptor_write.descriptorCount = 1;
19649 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
19650 descriptor_write.pBufferInfo = &buffer_info;
19651
19652 // Set pImageInfo and pTexelBufferView to invalid values, which should
19653 // be
19654 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER.
19655 // This will most likely produce a crash if the parameter_validation
19656 // layer
19657 // does not correctly ignore pImageInfo.
19658 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
19659 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
19660
19661 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
19662
19663 m_errorMonitor->VerifyNotFound();
19664
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019665 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
19666 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
19667 vkDestroyBuffer(m_device->device(), buffer, NULL);
19668 vkFreeMemory(m_device->device(), buffer_memory, NULL);
19669 }
19670
19671 // Texel Buffer Case
19672 {
19673 m_errorMonitor->ExpectSuccess();
19674
19675 VkBuffer buffer;
19676 uint32_t queue_family_index = 0;
19677 VkBufferCreateInfo buffer_create_info = {};
19678 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
19679 buffer_create_info.size = 1024;
19680 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
19681 buffer_create_info.queueFamilyIndexCount = 1;
19682 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
19683
19684 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
19685 ASSERT_VK_SUCCESS(err);
19686
19687 VkMemoryRequirements memory_reqs;
19688 VkDeviceMemory buffer_memory;
19689 bool pass;
19690 VkMemoryAllocateInfo memory_info = {};
19691 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
19692 memory_info.pNext = NULL;
19693 memory_info.allocationSize = 0;
19694 memory_info.memoryTypeIndex = 0;
19695
19696 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
19697 memory_info.allocationSize = memory_reqs.size;
19698 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
19699 ASSERT_TRUE(pass);
19700
19701 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
19702 ASSERT_VK_SUCCESS(err);
19703 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
19704 ASSERT_VK_SUCCESS(err);
19705
19706 VkBufferViewCreateInfo buff_view_ci = {};
19707 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
19708 buff_view_ci.buffer = buffer;
19709 buff_view_ci.format = VK_FORMAT_R8_UNORM;
19710 buff_view_ci.range = VK_WHOLE_SIZE;
19711 VkBufferView buffer_view;
19712 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buffer_view);
19713
19714 VkDescriptorPoolSize ds_type_count = {};
19715 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
19716 ds_type_count.descriptorCount = 1;
19717
19718 VkDescriptorPoolCreateInfo ds_pool_ci = {};
19719 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
19720 ds_pool_ci.pNext = NULL;
19721 ds_pool_ci.maxSets = 1;
19722 ds_pool_ci.poolSizeCount = 1;
19723 ds_pool_ci.pPoolSizes = &ds_type_count;
19724
19725 VkDescriptorPool ds_pool;
19726 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
19727 ASSERT_VK_SUCCESS(err);
19728
19729 VkDescriptorSetLayoutBinding dsl_binding = {};
19730 dsl_binding.binding = 0;
19731 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
19732 dsl_binding.descriptorCount = 1;
19733 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
19734 dsl_binding.pImmutableSamplers = NULL;
19735
19736 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
19737 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
19738 ds_layout_ci.pNext = NULL;
19739 ds_layout_ci.bindingCount = 1;
19740 ds_layout_ci.pBindings = &dsl_binding;
19741 VkDescriptorSetLayout ds_layout;
19742 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
19743 ASSERT_VK_SUCCESS(err);
19744
19745 VkDescriptorSet descriptor_set;
19746 VkDescriptorSetAllocateInfo alloc_info = {};
19747 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
19748 alloc_info.descriptorSetCount = 1;
19749 alloc_info.descriptorPool = ds_pool;
19750 alloc_info.pSetLayouts = &ds_layout;
19751 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
19752 ASSERT_VK_SUCCESS(err);
19753
19754 VkWriteDescriptorSet descriptor_write;
19755 memset(&descriptor_write, 0, sizeof(descriptor_write));
19756 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
19757 descriptor_write.dstSet = descriptor_set;
19758 descriptor_write.dstBinding = 0;
19759 descriptor_write.descriptorCount = 1;
19760 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
19761 descriptor_write.pTexelBufferView = &buffer_view;
19762
19763 // Set pImageInfo and pBufferInfo to invalid values, which should be
19764 // ignored for descriptorType ==
19765 // VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER.
19766 // This will most likely produce a crash if the parameter_validation
19767 // layer
19768 // does not correctly ignore pImageInfo and pBufferInfo.
19769 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
19770 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
19771
19772 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
19773
19774 m_errorMonitor->VerifyNotFound();
19775
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019776 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
19777 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
19778 vkDestroyBufferView(m_device->device(), buffer_view, NULL);
19779 vkDestroyBuffer(m_device->device(), buffer, NULL);
19780 vkFreeMemory(m_device->device(), buffer_memory, NULL);
19781 }
19782}
19783
Tobin Ehlis8893af82017-05-08 12:52:25 -060019784TEST_F(VkPositiveLayerTest, ImmutableSamplerOnlyDescriptor) {
19785 TEST_DESCRIPTION(
19786 "Bind a DescriptorSet with only an immutable sampler"
19787 "and make sure that we don't warn for no update.");
19788
19789 ASSERT_NO_FATAL_FAILURE(Init());
19790 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19791
19792 VkDescriptorPoolSize ds_type_count = {};
19793 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
19794 ds_type_count.descriptorCount = 1;
19795
19796 VkDescriptorPoolCreateInfo ds_pool_ci = {};
19797 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
19798 ds_pool_ci.maxSets = 1;
19799 ds_pool_ci.poolSizeCount = 1;
19800 ds_pool_ci.pPoolSizes = &ds_type_count;
19801
19802 VkDescriptorPool ds_pool;
19803 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
19804 ASSERT_VK_SUCCESS(err);
19805
19806 VkSamplerCreateInfo sampler_ci = {};
19807 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
19808 sampler_ci.pNext = NULL;
19809 sampler_ci.magFilter = VK_FILTER_NEAREST;
19810 sampler_ci.minFilter = VK_FILTER_NEAREST;
19811 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
19812 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
19813 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
19814 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
19815 sampler_ci.mipLodBias = 1.0;
19816 sampler_ci.anisotropyEnable = VK_FALSE;
19817 sampler_ci.maxAnisotropy = 1;
19818 sampler_ci.compareEnable = VK_FALSE;
19819 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
19820 sampler_ci.minLod = 1.0;
19821 sampler_ci.maxLod = 1.0;
19822 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
19823 sampler_ci.unnormalizedCoordinates = VK_FALSE;
19824 VkSampler sampler;
19825
19826 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
19827 ASSERT_VK_SUCCESS(err);
19828
19829 VkDescriptorSetLayoutBinding layout_binding = {};
19830 layout_binding.binding = 0;
19831 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
19832 layout_binding.descriptorCount = 1;
19833 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
19834 layout_binding.pImmutableSamplers = static_cast<VkSampler *>(&sampler);
19835
19836 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
19837 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
19838 ds_layout_ci.bindingCount = 1;
19839 ds_layout_ci.pBindings = &layout_binding;
19840 VkDescriptorSetLayout ds_layout;
19841 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
19842 ASSERT_VK_SUCCESS(err);
19843
19844 VkDescriptorSetAllocateInfo alloc_info = {};
19845 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
19846 alloc_info.descriptorSetCount = 1;
19847 alloc_info.descriptorPool = ds_pool;
19848 alloc_info.pSetLayouts = &ds_layout;
19849 VkDescriptorSet descriptor_set;
19850 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
19851 ASSERT_VK_SUCCESS(err);
19852
19853 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
19854 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
19855 pipeline_layout_ci.pNext = NULL;
19856 pipeline_layout_ci.setLayoutCount = 1;
19857 pipeline_layout_ci.pSetLayouts = &ds_layout;
19858
19859 VkPipelineLayout pipeline_layout;
19860 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
19861 ASSERT_VK_SUCCESS(err);
19862
19863 m_errorMonitor->ExpectSuccess();
19864 m_commandBuffer->BeginCommandBuffer();
19865 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
19866
19867 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
19868 &descriptor_set, 0, nullptr);
19869 m_errorMonitor->VerifyNotFound();
19870
19871 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
19872 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
19873 vkDestroySampler(m_device->device(), sampler, NULL);
19874 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
19875}
19876
Tobin Ehlisf7428442016-10-25 07:58:24 -060019877TEST_F(VkLayerTest, DuplicateDescriptorBinding) {
19878 TEST_DESCRIPTION("Create a descriptor set layout with a duplicate binding number.");
19879
Tony Barbour1fa09702017-03-16 12:09:08 -060019880 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisf7428442016-10-25 07:58:24 -060019881 // Create layout where two binding #s are "1"
19882 static const uint32_t NUM_BINDINGS = 3;
19883 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
19884 dsl_binding[0].binding = 1;
19885 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
19886 dsl_binding[0].descriptorCount = 1;
19887 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
19888 dsl_binding[0].pImmutableSamplers = NULL;
19889 dsl_binding[1].binding = 0;
19890 dsl_binding[1].descriptorCount = 1;
19891 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
19892 dsl_binding[1].descriptorCount = 1;
19893 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
19894 dsl_binding[1].pImmutableSamplers = NULL;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019895 dsl_binding[2].binding = 1; // Duplicate binding should cause error
Tobin Ehlisf7428442016-10-25 07:58:24 -060019896 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
19897 dsl_binding[2].descriptorCount = 1;
19898 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
19899 dsl_binding[2].pImmutableSamplers = NULL;
19900
19901 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
19902 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
19903 ds_layout_ci.pNext = NULL;
19904 ds_layout_ci.bindingCount = NUM_BINDINGS;
19905 ds_layout_ci.pBindings = dsl_binding;
19906 VkDescriptorSetLayout ds_layout;
19907 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02345);
19908 vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
19909 m_errorMonitor->VerifyFound();
19910}
19911
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060019912TEST_F(VkLayerTest, ViewportAndScissorBoundsChecking) {
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060019913 TEST_DESCRIPTION("Verify errors are detected on misuse of SetViewport and SetScissor.");
19914
Tony Barbour1fa09702017-03-16 12:09:08 -060019915 ASSERT_NO_FATAL_FAILURE(Init());
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060019916
Tony Barbour552f6c02016-12-21 14:34:07 -070019917 m_commandBuffer->BeginCommandBuffer();
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060019918
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060019919 const VkPhysicalDeviceLimits &limits = m_device->props.limits;
19920
19921 {
19922 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01448);
19923 VkViewport viewport = {0, 0, static_cast<float>(limits.maxViewportDimensions[0] + 1), 16, 0, 1};
19924 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
19925 m_errorMonitor->VerifyFound();
19926 }
19927
19928 {
19929 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01449);
19930 VkViewport viewport = {0, 0, 16, static_cast<float>(limits.maxViewportDimensions[1] + 1), 0, 1};
19931 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
19932 m_errorMonitor->VerifyFound();
19933 }
19934
19935 {
19936 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
19937 VkViewport viewport = {limits.viewportBoundsRange[0] - 1, 0, 16, 16, 0, 1};
19938 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
19939 m_errorMonitor->VerifyFound();
19940 }
19941
19942 {
19943 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
19944 VkViewport viewport = {0, limits.viewportBoundsRange[0] - 1, 16, 16, 0, 1};
19945 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
19946 m_errorMonitor->VerifyFound();
19947 }
19948
19949 {
19950 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01451);
19951 VkViewport viewport = {limits.viewportBoundsRange[1], 0, 16, 16, 0, 1};
19952 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
19953 m_errorMonitor->VerifyFound();
19954 }
19955
19956 {
19957 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01452);
19958 VkViewport viewport = {0, limits.viewportBoundsRange[1], 16, 16, 0, 1};
19959 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
19960 m_errorMonitor->VerifyFound();
19961 }
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060019962
19963 {
19964 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
19965 VkRect2D scissor = {{-1, 0}, {16, 16}};
19966 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
19967 m_errorMonitor->VerifyFound();
19968 }
19969
19970 {
19971 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
19972 VkRect2D scissor = {{0, -2}, {16, 16}};
19973 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
19974 m_errorMonitor->VerifyFound();
19975 }
19976
19977 {
19978 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01490);
19979 VkRect2D scissor = {{100, 100}, {INT_MAX, 16}};
19980 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
19981 m_errorMonitor->VerifyFound();
19982 }
19983
19984 {
19985 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01491);
19986 VkRect2D scissor = {{100, 100}, {16, INT_MAX}};
19987 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
19988 m_errorMonitor->VerifyFound();
19989 }
19990
Tony Barbour552f6c02016-12-21 14:34:07 -070019991 m_commandBuffer->EndCommandBuffer();
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060019992}
19993
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019994// This is a positive test. No failures are expected.
19995TEST_F(VkPositiveLayerTest, EmptyDescriptorUpdateTest) {
19996 TEST_DESCRIPTION("Update last descriptor in a set that includes an empty binding");
19997 VkResult err;
19998
Tony Barbour1fa09702017-03-16 12:09:08 -060019999 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020000 m_errorMonitor->ExpectSuccess();
20001 VkDescriptorPoolSize ds_type_count = {};
20002 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
20003 ds_type_count.descriptorCount = 2;
20004
20005 VkDescriptorPoolCreateInfo ds_pool_ci = {};
20006 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
20007 ds_pool_ci.pNext = NULL;
20008 ds_pool_ci.maxSets = 1;
20009 ds_pool_ci.poolSizeCount = 1;
20010 ds_pool_ci.pPoolSizes = &ds_type_count;
20011
20012 VkDescriptorPool ds_pool;
20013 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
20014 ASSERT_VK_SUCCESS(err);
20015
20016 // Create layout with two uniform buffer descriptors w/ empty binding between them
20017 static const uint32_t NUM_BINDINGS = 3;
20018 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
20019 dsl_binding[0].binding = 0;
20020 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
20021 dsl_binding[0].descriptorCount = 1;
20022 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
20023 dsl_binding[0].pImmutableSamplers = NULL;
20024 dsl_binding[1].binding = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020025 dsl_binding[1].descriptorCount = 0; // empty binding
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020026 dsl_binding[2].binding = 2;
20027 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
20028 dsl_binding[2].descriptorCount = 1;
20029 dsl_binding[2].stageFlags = VK_SHADER_STAGE_ALL;
20030 dsl_binding[2].pImmutableSamplers = NULL;
20031
20032 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
20033 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
20034 ds_layout_ci.pNext = NULL;
20035 ds_layout_ci.bindingCount = NUM_BINDINGS;
20036 ds_layout_ci.pBindings = dsl_binding;
20037 VkDescriptorSetLayout ds_layout;
20038 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
20039 ASSERT_VK_SUCCESS(err);
20040
20041 VkDescriptorSet descriptor_set = {};
20042 VkDescriptorSetAllocateInfo alloc_info = {};
20043 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
20044 alloc_info.descriptorSetCount = 1;
20045 alloc_info.descriptorPool = ds_pool;
20046 alloc_info.pSetLayouts = &ds_layout;
20047 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
20048 ASSERT_VK_SUCCESS(err);
20049
20050 // Create a buffer to be used for update
20051 VkBufferCreateInfo buff_ci = {};
20052 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
20053 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
20054 buff_ci.size = 256;
20055 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
20056 VkBuffer buffer;
20057 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
20058 ASSERT_VK_SUCCESS(err);
20059 // Have to bind memory to buffer before descriptor update
20060 VkMemoryAllocateInfo mem_alloc = {};
20061 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
20062 mem_alloc.pNext = NULL;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020063 mem_alloc.allocationSize = 512; // one allocation for both buffers
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020064 mem_alloc.memoryTypeIndex = 0;
20065
20066 VkMemoryRequirements mem_reqs;
20067 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
20068 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
20069 if (!pass) {
20070 vkDestroyBuffer(m_device->device(), buffer, NULL);
20071 return;
20072 }
20073
20074 VkDeviceMemory mem;
20075 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
20076 ASSERT_VK_SUCCESS(err);
20077 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
20078 ASSERT_VK_SUCCESS(err);
20079
20080 // Only update the descriptor at binding 2
20081 VkDescriptorBufferInfo buff_info = {};
20082 buff_info.buffer = buffer;
20083 buff_info.offset = 0;
20084 buff_info.range = VK_WHOLE_SIZE;
20085 VkWriteDescriptorSet descriptor_write = {};
20086 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
20087 descriptor_write.dstBinding = 2;
20088 descriptor_write.descriptorCount = 1;
20089 descriptor_write.pTexelBufferView = nullptr;
20090 descriptor_write.pBufferInfo = &buff_info;
20091 descriptor_write.pImageInfo = nullptr;
20092 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
20093 descriptor_write.dstSet = descriptor_set;
20094
20095 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
20096
20097 m_errorMonitor->VerifyNotFound();
20098 // Cleanup
20099 vkFreeMemory(m_device->device(), mem, NULL);
20100 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
20101 vkDestroyBuffer(m_device->device(), buffer, NULL);
20102 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
20103}
20104
20105// This is a positive test. No failures are expected.
20106TEST_F(VkPositiveLayerTest, TestAliasedMemoryTracking) {
20107 VkResult err;
20108 bool pass;
20109
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020110 TEST_DESCRIPTION(
20111 "Create a buffer, allocate memory, bind memory, destroy "
20112 "the buffer, create an image, and bind the same memory to "
20113 "it");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020114
20115 m_errorMonitor->ExpectSuccess();
20116
Tony Barbour1fa09702017-03-16 12:09:08 -060020117 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020118
20119 VkBuffer buffer;
20120 VkImage image;
20121 VkDeviceMemory mem;
20122 VkMemoryRequirements mem_reqs;
20123
20124 VkBufferCreateInfo buf_info = {};
20125 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
20126 buf_info.pNext = NULL;
20127 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
20128 buf_info.size = 256;
20129 buf_info.queueFamilyIndexCount = 0;
20130 buf_info.pQueueFamilyIndices = NULL;
20131 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
20132 buf_info.flags = 0;
20133 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
20134 ASSERT_VK_SUCCESS(err);
20135
20136 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
20137
20138 VkMemoryAllocateInfo alloc_info = {};
20139 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
20140 alloc_info.pNext = NULL;
20141 alloc_info.memoryTypeIndex = 0;
Dave Houlton9dae7ec2017-03-01 16:23:25 -070020142
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020143 // Ensure memory is big enough for both bindings
20144 alloc_info.allocationSize = 0x10000;
20145
20146 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
20147 if (!pass) {
20148 vkDestroyBuffer(m_device->device(), buffer, NULL);
20149 return;
20150 }
20151
20152 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
20153 ASSERT_VK_SUCCESS(err);
20154
20155 uint8_t *pData;
20156 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
20157 ASSERT_VK_SUCCESS(err);
20158
20159 memset(pData, 0xCADECADE, static_cast<size_t>(mem_reqs.size));
20160
20161 vkUnmapMemory(m_device->device(), mem);
20162
20163 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
20164 ASSERT_VK_SUCCESS(err);
20165
20166 // NOW, destroy the buffer. Obviously, the resource no longer occupies this
20167 // memory. In fact, it was never used by the GPU.
20168 // Just be be sure, wait for idle.
20169 vkDestroyBuffer(m_device->device(), buffer, NULL);
20170 vkDeviceWaitIdle(m_device->device());
20171
Tobin Ehlis6a005702016-12-28 15:25:56 -070020172 // Use optimal as some platforms report linear support but then fail image creation
20173 VkImageTiling image_tiling = VK_IMAGE_TILING_OPTIMAL;
20174 VkImageFormatProperties image_format_properties;
20175 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D, image_tiling,
20176 VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0, &image_format_properties);
20177 if (image_format_properties.maxExtent.width == 0) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070020178 printf(" Image format not supported; skipped.\n");
Tobin Ehlis6a005702016-12-28 15:25:56 -070020179 vkFreeMemory(m_device->device(), mem, NULL);
20180 return;
20181 }
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020182 VkImageCreateInfo image_create_info = {};
20183 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
20184 image_create_info.pNext = NULL;
20185 image_create_info.imageType = VK_IMAGE_TYPE_2D;
20186 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
20187 image_create_info.extent.width = 64;
20188 image_create_info.extent.height = 64;
20189 image_create_info.extent.depth = 1;
20190 image_create_info.mipLevels = 1;
20191 image_create_info.arrayLayers = 1;
20192 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis6a005702016-12-28 15:25:56 -070020193 image_create_info.tiling = image_tiling;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020194 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
20195 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
20196 image_create_info.queueFamilyIndexCount = 0;
20197 image_create_info.pQueueFamilyIndices = NULL;
20198 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
20199 image_create_info.flags = 0;
20200
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020201 /* Create a mappable image. It will be the texture if linear images are ok
Dave Houlton9dae7ec2017-03-01 16:23:25 -070020202 * to be textures or it will be the staging image if they are not.
20203 */
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020204 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
20205 ASSERT_VK_SUCCESS(err);
20206
20207 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
20208
Tobin Ehlis6a005702016-12-28 15:25:56 -070020209 VkMemoryAllocateInfo mem_alloc = {};
20210 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
20211 mem_alloc.pNext = NULL;
20212 mem_alloc.allocationSize = 0;
20213 mem_alloc.memoryTypeIndex = 0;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020214 mem_alloc.allocationSize = mem_reqs.size;
20215
20216 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
20217 if (!pass) {
Tobin Ehlis6a005702016-12-28 15:25:56 -070020218 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020219 vkDestroyImage(m_device->device(), image, NULL);
20220 return;
20221 }
20222
20223 // VALIDATION FAILURE:
20224 err = vkBindImageMemory(m_device->device(), image, mem, 0);
20225 ASSERT_VK_SUCCESS(err);
20226
20227 m_errorMonitor->VerifyNotFound();
20228
20229 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020230 vkDestroyImage(m_device->device(), image, NULL);
20231}
20232
Tony Barbourab713912017-02-02 14:17:35 -070020233// This is a positive test. No failures are expected.
20234TEST_F(VkPositiveLayerTest, TestDestroyFreeNullHandles) {
20235 VkResult err;
20236
20237 TEST_DESCRIPTION(
20238 "Call all applicable destroy and free routines with NULL"
20239 "handles, expecting no validation errors");
20240
20241 m_errorMonitor->ExpectSuccess();
20242
Tony Barbour1fa09702017-03-16 12:09:08 -060020243 ASSERT_NO_FATAL_FAILURE(Init());
Tony Barbourab713912017-02-02 14:17:35 -070020244 vkDestroyBuffer(m_device->device(), VK_NULL_HANDLE, NULL);
20245 vkDestroyBufferView(m_device->device(), VK_NULL_HANDLE, NULL);
20246 vkDestroyCommandPool(m_device->device(), VK_NULL_HANDLE, NULL);
20247 vkDestroyDescriptorPool(m_device->device(), VK_NULL_HANDLE, NULL);
20248 vkDestroyDescriptorSetLayout(m_device->device(), VK_NULL_HANDLE, NULL);
20249 vkDestroyDevice(VK_NULL_HANDLE, NULL);
20250 vkDestroyEvent(m_device->device(), VK_NULL_HANDLE, NULL);
20251 vkDestroyFence(m_device->device(), VK_NULL_HANDLE, NULL);
20252 vkDestroyFramebuffer(m_device->device(), VK_NULL_HANDLE, NULL);
20253 vkDestroyImage(m_device->device(), VK_NULL_HANDLE, NULL);
20254 vkDestroyImageView(m_device->device(), VK_NULL_HANDLE, NULL);
20255 vkDestroyInstance(VK_NULL_HANDLE, NULL);
20256 vkDestroyPipeline(m_device->device(), VK_NULL_HANDLE, NULL);
20257 vkDestroyPipelineCache(m_device->device(), VK_NULL_HANDLE, NULL);
20258 vkDestroyPipelineLayout(m_device->device(), VK_NULL_HANDLE, NULL);
20259 vkDestroyQueryPool(m_device->device(), VK_NULL_HANDLE, NULL);
20260 vkDestroyRenderPass(m_device->device(), VK_NULL_HANDLE, NULL);
20261 vkDestroySampler(m_device->device(), VK_NULL_HANDLE, NULL);
20262 vkDestroySemaphore(m_device->device(), VK_NULL_HANDLE, NULL);
20263 vkDestroyShaderModule(m_device->device(), VK_NULL_HANDLE, NULL);
20264
20265 VkCommandPool command_pool;
20266 VkCommandPoolCreateInfo pool_create_info{};
20267 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20268 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20269 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20270 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20271 VkCommandBuffer command_buffers[3] = {};
20272 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20273 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20274 command_buffer_allocate_info.commandPool = command_pool;
20275 command_buffer_allocate_info.commandBufferCount = 1;
20276 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20277 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffers[1]);
20278 vkFreeCommandBuffers(m_device->device(), command_pool, 3, command_buffers);
20279 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20280
20281 VkDescriptorPoolSize ds_type_count = {};
20282 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
20283 ds_type_count.descriptorCount = 1;
20284
20285 VkDescriptorPoolCreateInfo ds_pool_ci = {};
20286 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
20287 ds_pool_ci.pNext = NULL;
20288 ds_pool_ci.maxSets = 1;
20289 ds_pool_ci.poolSizeCount = 1;
20290 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
20291 ds_pool_ci.pPoolSizes = &ds_type_count;
20292
20293 VkDescriptorPool ds_pool;
20294 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
20295 ASSERT_VK_SUCCESS(err);
20296
20297 VkDescriptorSetLayoutBinding dsl_binding = {};
20298 dsl_binding.binding = 2;
20299 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
20300 dsl_binding.descriptorCount = 1;
20301 dsl_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
20302 dsl_binding.pImmutableSamplers = NULL;
20303 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
20304 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
20305 ds_layout_ci.pNext = NULL;
20306 ds_layout_ci.bindingCount = 1;
20307 ds_layout_ci.pBindings = &dsl_binding;
20308 VkDescriptorSetLayout ds_layout;
20309 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
20310 ASSERT_VK_SUCCESS(err);
20311
20312 VkDescriptorSet descriptor_sets[3] = {};
20313 VkDescriptorSetAllocateInfo alloc_info = {};
20314 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
20315 alloc_info.descriptorSetCount = 1;
20316 alloc_info.descriptorPool = ds_pool;
20317 alloc_info.pSetLayouts = &ds_layout;
20318 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_sets[1]);
20319 ASSERT_VK_SUCCESS(err);
20320 vkFreeDescriptorSets(m_device->device(), ds_pool, 3, descriptor_sets);
20321 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
20322 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
20323
20324 vkFreeMemory(m_device->device(), VK_NULL_HANDLE, NULL);
20325
20326 m_errorMonitor->VerifyNotFound();
20327}
20328
Tony Barbour626994c2017-02-08 15:29:37 -070020329TEST_F(VkPositiveLayerTest, QueueSubmitSemaphoresAndLayoutTracking) {
Tony Barboure0c5cc92017-02-08 13:53:39 -070020330 TEST_DESCRIPTION("Submit multiple command buffers with chained semaphore signals and layout transitions");
Tony Barbour626994c2017-02-08 15:29:37 -070020331
20332 m_errorMonitor->ExpectSuccess();
20333
Tony Barbour1fa09702017-03-16 12:09:08 -060020334 ASSERT_NO_FATAL_FAILURE(Init());
Tony Barbour626994c2017-02-08 15:29:37 -070020335 VkCommandBuffer cmd_bufs[4];
20336 VkCommandBufferAllocateInfo alloc_info;
20337 alloc_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20338 alloc_info.pNext = NULL;
20339 alloc_info.commandBufferCount = 4;
Mike Schuchardt06304c22017-03-01 17:09:09 -070020340 alloc_info.commandPool = m_commandPool->handle();
Tony Barbour626994c2017-02-08 15:29:37 -070020341 alloc_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20342 vkAllocateCommandBuffers(m_device->device(), &alloc_info, cmd_bufs);
20343 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060020344 image.Init(128, 128, 1, VK_FORMAT_B8G8R8A8_UNORM,
Mike Weiblen62d08a32017-03-07 22:18:27 -070020345 (VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT),
20346 VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbour626994c2017-02-08 15:29:37 -070020347 ASSERT_TRUE(image.initialized());
20348 VkCommandBufferBeginInfo cb_binfo;
20349 cb_binfo.pNext = NULL;
20350 cb_binfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20351 cb_binfo.pInheritanceInfo = VK_NULL_HANDLE;
20352 cb_binfo.flags = 0;
20353 // Use 4 command buffers, each with an image layout transition, ColorAO->General->ColorAO->TransferSrc->TransferDst
20354 vkBeginCommandBuffer(cmd_bufs[0], &cb_binfo);
20355 VkImageMemoryBarrier img_barrier = {};
20356 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
20357 img_barrier.pNext = NULL;
20358 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
20359 img_barrier.dstAccessMask = VK_ACCESS_HOST_WRITE_BIT;
20360 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
20361 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
20362 img_barrier.image = image.handle();
20363 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
20364 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
20365 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
20366 img_barrier.subresourceRange.baseArrayLayer = 0;
20367 img_barrier.subresourceRange.baseMipLevel = 0;
20368 img_barrier.subresourceRange.layerCount = 1;
20369 img_barrier.subresourceRange.levelCount = 1;
20370 vkCmdPipelineBarrier(cmd_bufs[0], VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 0, nullptr, 0, nullptr, 1,
20371 &img_barrier);
20372 vkEndCommandBuffer(cmd_bufs[0]);
20373 vkBeginCommandBuffer(cmd_bufs[1], &cb_binfo);
20374 img_barrier.oldLayout = VK_IMAGE_LAYOUT_GENERAL;
20375 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
20376 vkCmdPipelineBarrier(cmd_bufs[1], VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 0, nullptr, 0, nullptr, 1,
20377 &img_barrier);
20378 vkEndCommandBuffer(cmd_bufs[1]);
20379 vkBeginCommandBuffer(cmd_bufs[2], &cb_binfo);
20380 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
20381 img_barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
20382 vkCmdPipelineBarrier(cmd_bufs[2], VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 0, nullptr, 0, nullptr, 1,
20383 &img_barrier);
20384 vkEndCommandBuffer(cmd_bufs[2]);
20385 vkBeginCommandBuffer(cmd_bufs[3], &cb_binfo);
20386 img_barrier.oldLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
20387 img_barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
20388 vkCmdPipelineBarrier(cmd_bufs[3], VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 0, nullptr, 0, nullptr, 1,
20389 &img_barrier);
20390 vkEndCommandBuffer(cmd_bufs[3]);
20391
20392 // Submit 4 command buffers in 3 submits, with submits 2 and 3 waiting for semaphores from submits 1 and 2
20393 VkSemaphore semaphore1, semaphore2;
20394 VkSemaphoreCreateInfo semaphore_create_info{};
20395 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
20396 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore1);
20397 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore2);
20398 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
20399 VkSubmitInfo submit_info[3];
20400 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20401 submit_info[0].pNext = nullptr;
20402 submit_info[0].commandBufferCount = 1;
20403 submit_info[0].pCommandBuffers = &cmd_bufs[0];
20404 submit_info[0].signalSemaphoreCount = 1;
20405 submit_info[0].pSignalSemaphores = &semaphore1;
20406 submit_info[0].waitSemaphoreCount = 0;
20407 submit_info[0].pWaitDstStageMask = nullptr;
20408 submit_info[0].pWaitDstStageMask = flags;
20409 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20410 submit_info[1].pNext = nullptr;
20411 submit_info[1].commandBufferCount = 1;
20412 submit_info[1].pCommandBuffers = &cmd_bufs[1];
20413 submit_info[1].waitSemaphoreCount = 1;
20414 submit_info[1].pWaitSemaphores = &semaphore1;
20415 submit_info[1].signalSemaphoreCount = 1;
20416 submit_info[1].pSignalSemaphores = &semaphore2;
20417 submit_info[1].pWaitDstStageMask = flags;
20418 submit_info[2].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20419 submit_info[2].pNext = nullptr;
20420 submit_info[2].commandBufferCount = 2;
20421 submit_info[2].pCommandBuffers = &cmd_bufs[2];
20422 submit_info[2].waitSemaphoreCount = 1;
20423 submit_info[2].pWaitSemaphores = &semaphore2;
20424 submit_info[2].signalSemaphoreCount = 0;
20425 submit_info[2].pSignalSemaphores = nullptr;
20426 submit_info[2].pWaitDstStageMask = flags;
20427 vkQueueSubmit(m_device->m_queue, 3, submit_info, VK_NULL_HANDLE);
20428 vkQueueWaitIdle(m_device->m_queue);
20429
20430 vkDestroySemaphore(m_device->device(), semaphore1, NULL);
20431 vkDestroySemaphore(m_device->device(), semaphore2, NULL);
20432 m_errorMonitor->VerifyNotFound();
20433}
20434
Tobin Ehlis953e8392016-11-17 10:54:13 -070020435TEST_F(VkPositiveLayerTest, DynamicOffsetWithInactiveBinding) {
20436 // Create a descriptorSet w/ dynamic descriptors where 1 binding is inactive
20437 // We previously had a bug where dynamic offset of inactive bindings was still being used
20438 VkResult err;
20439 m_errorMonitor->ExpectSuccess();
20440
Tony Barbour1fa09702017-03-16 12:09:08 -060020441 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis953e8392016-11-17 10:54:13 -070020442 ASSERT_NO_FATAL_FAILURE(InitViewport());
20443 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20444
20445 VkDescriptorPoolSize ds_type_count = {};
20446 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
20447 ds_type_count.descriptorCount = 3;
20448
20449 VkDescriptorPoolCreateInfo ds_pool_ci = {};
20450 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
20451 ds_pool_ci.pNext = NULL;
20452 ds_pool_ci.maxSets = 1;
20453 ds_pool_ci.poolSizeCount = 1;
20454 ds_pool_ci.pPoolSizes = &ds_type_count;
20455
20456 VkDescriptorPool ds_pool;
20457 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
20458 ASSERT_VK_SUCCESS(err);
20459
20460 const uint32_t BINDING_COUNT = 3;
20461 VkDescriptorSetLayoutBinding dsl_binding[BINDING_COUNT] = {};
Tobin Ehlis0050fba2016-11-30 10:22:02 -070020462 dsl_binding[0].binding = 2;
Tobin Ehlis953e8392016-11-17 10:54:13 -070020463 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
20464 dsl_binding[0].descriptorCount = 1;
20465 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
20466 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis0050fba2016-11-30 10:22:02 -070020467 dsl_binding[1].binding = 0;
Tobin Ehlis953e8392016-11-17 10:54:13 -070020468 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
20469 dsl_binding[1].descriptorCount = 1;
20470 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
20471 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis0050fba2016-11-30 10:22:02 -070020472 dsl_binding[2].binding = 1;
Tobin Ehlis953e8392016-11-17 10:54:13 -070020473 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
20474 dsl_binding[2].descriptorCount = 1;
20475 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
20476 dsl_binding[2].pImmutableSamplers = NULL;
20477
20478 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
20479 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
20480 ds_layout_ci.pNext = NULL;
20481 ds_layout_ci.bindingCount = BINDING_COUNT;
20482 ds_layout_ci.pBindings = dsl_binding;
20483 VkDescriptorSetLayout ds_layout;
20484 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
20485 ASSERT_VK_SUCCESS(err);
20486
20487 VkDescriptorSet descriptor_set;
20488 VkDescriptorSetAllocateInfo alloc_info = {};
20489 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
20490 alloc_info.descriptorSetCount = 1;
20491 alloc_info.descriptorPool = ds_pool;
20492 alloc_info.pSetLayouts = &ds_layout;
20493 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
20494 ASSERT_VK_SUCCESS(err);
20495
20496 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
20497 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
20498 pipeline_layout_ci.pNext = NULL;
20499 pipeline_layout_ci.setLayoutCount = 1;
20500 pipeline_layout_ci.pSetLayouts = &ds_layout;
20501
20502 VkPipelineLayout pipeline_layout;
20503 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
20504 ASSERT_VK_SUCCESS(err);
20505
20506 // Create two buffers to update the descriptors with
20507 // The first will be 2k and used for bindings 0 & 1, the second is 1k for binding 2
20508 uint32_t qfi = 0;
20509 VkBufferCreateInfo buffCI = {};
20510 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
20511 buffCI.size = 2048;
20512 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
20513 buffCI.queueFamilyIndexCount = 1;
20514 buffCI.pQueueFamilyIndices = &qfi;
20515
20516 VkBuffer dyub1;
20517 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub1);
20518 ASSERT_VK_SUCCESS(err);
20519 // buffer2
20520 buffCI.size = 1024;
20521 VkBuffer dyub2;
20522 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub2);
20523 ASSERT_VK_SUCCESS(err);
20524 // Allocate memory and bind to buffers
20525 VkMemoryAllocateInfo mem_alloc[2] = {};
20526 mem_alloc[0].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
20527 mem_alloc[0].pNext = NULL;
20528 mem_alloc[0].memoryTypeIndex = 0;
20529 mem_alloc[1].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
20530 mem_alloc[1].pNext = NULL;
20531 mem_alloc[1].memoryTypeIndex = 0;
20532
20533 VkMemoryRequirements mem_reqs1;
20534 vkGetBufferMemoryRequirements(m_device->device(), dyub1, &mem_reqs1);
20535 VkMemoryRequirements mem_reqs2;
20536 vkGetBufferMemoryRequirements(m_device->device(), dyub2, &mem_reqs2);
20537 mem_alloc[0].allocationSize = mem_reqs1.size;
20538 bool pass = m_device->phy().set_memory_type(mem_reqs1.memoryTypeBits, &mem_alloc[0], 0);
20539 mem_alloc[1].allocationSize = mem_reqs2.size;
20540 pass &= m_device->phy().set_memory_type(mem_reqs2.memoryTypeBits, &mem_alloc[1], 0);
20541 if (!pass) {
20542 vkDestroyBuffer(m_device->device(), dyub1, NULL);
20543 vkDestroyBuffer(m_device->device(), dyub2, NULL);
20544 return;
20545 }
20546
20547 VkDeviceMemory mem1;
20548 err = vkAllocateMemory(m_device->device(), &mem_alloc[0], NULL, &mem1);
20549 ASSERT_VK_SUCCESS(err);
20550 err = vkBindBufferMemory(m_device->device(), dyub1, mem1, 0);
20551 ASSERT_VK_SUCCESS(err);
20552 VkDeviceMemory mem2;
20553 err = vkAllocateMemory(m_device->device(), &mem_alloc[1], NULL, &mem2);
20554 ASSERT_VK_SUCCESS(err);
20555 err = vkBindBufferMemory(m_device->device(), dyub2, mem2, 0);
20556 ASSERT_VK_SUCCESS(err);
20557 // Update descriptors
20558 VkDescriptorBufferInfo buff_info[BINDING_COUNT] = {};
20559 buff_info[0].buffer = dyub1;
20560 buff_info[0].offset = 0;
20561 buff_info[0].range = 256;
20562 buff_info[1].buffer = dyub1;
20563 buff_info[1].offset = 256;
20564 buff_info[1].range = 512;
20565 buff_info[2].buffer = dyub2;
20566 buff_info[2].offset = 0;
20567 buff_info[2].range = 512;
20568
20569 VkWriteDescriptorSet descriptor_write;
20570 memset(&descriptor_write, 0, sizeof(descriptor_write));
20571 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
20572 descriptor_write.dstSet = descriptor_set;
20573 descriptor_write.dstBinding = 0;
20574 descriptor_write.descriptorCount = BINDING_COUNT;
20575 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
20576 descriptor_write.pBufferInfo = buff_info;
20577
20578 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
20579
Tony Barbour552f6c02016-12-21 14:34:07 -070020580 m_commandBuffer->BeginCommandBuffer();
20581 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis953e8392016-11-17 10:54:13 -070020582
20583 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020584 char const *vsSource =
20585 "#version 450\n"
20586 "\n"
20587 "out gl_PerVertex { \n"
20588 " vec4 gl_Position;\n"
20589 "};\n"
20590 "void main(){\n"
20591 " gl_Position = vec4(1);\n"
20592 "}\n";
20593 char const *fsSource =
20594 "#version 450\n"
20595 "\n"
20596 "layout(location=0) out vec4 x;\n"
20597 "layout(set=0) layout(binding=0) uniform foo1 { int x; int y; } bar1;\n"
20598 "layout(set=0) layout(binding=2) uniform foo2 { int x; int y; } bar2;\n"
20599 "void main(){\n"
20600 " x = vec4(bar1.y) + vec4(bar2.y);\n"
20601 "}\n";
Tobin Ehlis953e8392016-11-17 10:54:13 -070020602 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
20603 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
20604 VkPipelineObj pipe(m_device);
20605 pipe.SetViewport(m_viewports);
20606 pipe.SetScissor(m_scissors);
20607 pipe.AddShader(&vs);
20608 pipe.AddShader(&fs);
20609 pipe.AddColorAttachment();
20610 pipe.CreateVKPipeline(pipeline_layout, renderPass());
20611
20612 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
20613 // This update should succeed, but offset of inactive binding 1 oversteps binding 2 buffer size
20614 // we used to have a bug in this case.
20615 uint32_t dyn_off[BINDING_COUNT] = {0, 1024, 256};
20616 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
20617 &descriptor_set, BINDING_COUNT, dyn_off);
20618 Draw(1, 0, 0, 0);
20619 m_errorMonitor->VerifyNotFound();
20620
20621 vkDestroyBuffer(m_device->device(), dyub1, NULL);
20622 vkDestroyBuffer(m_device->device(), dyub2, NULL);
20623 vkFreeMemory(m_device->device(), mem1, NULL);
20624 vkFreeMemory(m_device->device(), mem2, NULL);
20625
20626 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
20627 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
20628 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
20629}
20630
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020631TEST_F(VkPositiveLayerTest, NonCoherentMemoryMapping) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020632 TEST_DESCRIPTION(
20633 "Ensure that validations handling of non-coherent memory "
20634 "mapping while using VK_WHOLE_SIZE does not cause access "
20635 "violations");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020636 VkResult err;
20637 uint8_t *pData;
Tony Barbour1fa09702017-03-16 12:09:08 -060020638 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020639
20640 VkDeviceMemory mem;
20641 VkMemoryRequirements mem_reqs;
20642 mem_reqs.memoryTypeBits = 0xFFFFFFFF;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070020643 const VkDeviceSize atom_size = m_device->props.limits.nonCoherentAtomSize;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020644 VkMemoryAllocateInfo alloc_info = {};
20645 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
20646 alloc_info.pNext = NULL;
20647 alloc_info.memoryTypeIndex = 0;
20648
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070020649 static const VkDeviceSize allocation_size = 32 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020650 alloc_info.allocationSize = allocation_size;
20651
20652 // Find a memory configurations WITHOUT a COHERENT bit, otherwise exit
20653 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 -070020654 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020655 if (!pass) {
20656 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020657 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
20658 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020659 if (!pass) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020660 pass = m_device->phy().set_memory_type(
20661 mem_reqs.memoryTypeBits, &alloc_info,
20662 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT | VK_MEMORY_PROPERTY_HOST_CACHED_BIT,
20663 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020664 if (!pass) {
20665 return;
20666 }
20667 }
20668 }
20669
20670 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
20671 ASSERT_VK_SUCCESS(err);
20672
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070020673 // Map/Flush/Invalidate using WHOLE_SIZE and zero offsets and entire mapped range
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020674 m_errorMonitor->ExpectSuccess();
20675 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
20676 ASSERT_VK_SUCCESS(err);
20677 VkMappedMemoryRange mmr = {};
20678 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
20679 mmr.memory = mem;
20680 mmr.offset = 0;
20681 mmr.size = VK_WHOLE_SIZE;
20682 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
20683 ASSERT_VK_SUCCESS(err);
20684 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
20685 ASSERT_VK_SUCCESS(err);
20686 m_errorMonitor->VerifyNotFound();
20687 vkUnmapMemory(m_device->device(), mem);
20688
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070020689 // Map/Flush/Invalidate using WHOLE_SIZE and an offset and entire mapped range
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020690 m_errorMonitor->ExpectSuccess();
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070020691 err = vkMapMemory(m_device->device(), mem, 5 * atom_size, VK_WHOLE_SIZE, 0, (void **)&pData);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020692 ASSERT_VK_SUCCESS(err);
20693 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
20694 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070020695 mmr.offset = 6 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020696 mmr.size = VK_WHOLE_SIZE;
20697 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
20698 ASSERT_VK_SUCCESS(err);
20699 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
20700 ASSERT_VK_SUCCESS(err);
20701 m_errorMonitor->VerifyNotFound();
20702 vkUnmapMemory(m_device->device(), mem);
20703
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070020704 // Map with offset and size
20705 // Flush/Invalidate subrange of mapped area with offset and size
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020706 m_errorMonitor->ExpectSuccess();
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070020707 err = vkMapMemory(m_device->device(), mem, 3 * atom_size, 9 * atom_size, 0, (void **)&pData);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020708 ASSERT_VK_SUCCESS(err);
20709 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
20710 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070020711 mmr.offset = 4 * atom_size;
20712 mmr.size = 2 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020713 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
20714 ASSERT_VK_SUCCESS(err);
20715 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
20716 ASSERT_VK_SUCCESS(err);
20717 m_errorMonitor->VerifyNotFound();
20718 vkUnmapMemory(m_device->device(), mem);
20719
20720 // Map without offset and flush WHOLE_SIZE with two separate offsets
20721 m_errorMonitor->ExpectSuccess();
20722 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
20723 ASSERT_VK_SUCCESS(err);
20724 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
20725 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070020726 mmr.offset = allocation_size - (4 * atom_size);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020727 mmr.size = VK_WHOLE_SIZE;
20728 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
20729 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070020730 mmr.offset = allocation_size - (6 * atom_size);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020731 mmr.size = VK_WHOLE_SIZE;
20732 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
20733 ASSERT_VK_SUCCESS(err);
20734 m_errorMonitor->VerifyNotFound();
20735 vkUnmapMemory(m_device->device(), mem);
20736
20737 vkFreeMemory(m_device->device(), mem, NULL);
20738}
20739
20740// This is a positive test. We used to expect error in this case but spec now allows it
20741TEST_F(VkPositiveLayerTest, ResetUnsignaledFence) {
20742 m_errorMonitor->ExpectSuccess();
20743 vk_testing::Fence testFence;
20744 VkFenceCreateInfo fenceInfo = {};
20745 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
20746 fenceInfo.pNext = NULL;
20747
Tony Barbour1fa09702017-03-16 12:09:08 -060020748 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020749 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020750 VkFence fences[1] = {testFence.handle()};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020751 VkResult result = vkResetFences(m_device->device(), 1, fences);
20752 ASSERT_VK_SUCCESS(result);
20753
20754 m_errorMonitor->VerifyNotFound();
20755}
20756
20757TEST_F(VkPositiveLayerTest, CommandBufferSimultaneousUseSync) {
20758 m_errorMonitor->ExpectSuccess();
20759
Tony Barbour1fa09702017-03-16 12:09:08 -060020760 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020761 VkResult err;
20762
20763 // Record (empty!) command buffer that can be submitted multiple times
20764 // simultaneously.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020765 VkCommandBufferBeginInfo cbbi = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
20766 VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020767 m_commandBuffer->BeginCommandBuffer(&cbbi);
20768 m_commandBuffer->EndCommandBuffer();
20769
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020770 VkFenceCreateInfo fci = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020771 VkFence fence;
20772 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
20773 ASSERT_VK_SUCCESS(err);
20774
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020775 VkSemaphoreCreateInfo sci = {VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020776 VkSemaphore s1, s2;
20777 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s1);
20778 ASSERT_VK_SUCCESS(err);
20779 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s2);
20780 ASSERT_VK_SUCCESS(err);
20781
20782 // Submit CB once signaling s1, with fence so we can roll forward to its retirement.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020783 VkSubmitInfo si = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &m_commandBuffer->handle(), 1, &s1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020784 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
20785 ASSERT_VK_SUCCESS(err);
20786
20787 // Submit CB again, signaling s2.
20788 si.pSignalSemaphores = &s2;
20789 err = vkQueueSubmit(m_device->m_queue, 1, &si, VK_NULL_HANDLE);
20790 ASSERT_VK_SUCCESS(err);
20791
20792 // Wait for fence.
20793 err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
20794 ASSERT_VK_SUCCESS(err);
20795
20796 // CB is still in flight from second submission, but semaphore s1 is no
20797 // longer in flight. delete it.
20798 vkDestroySemaphore(m_device->device(), s1, nullptr);
20799
20800 m_errorMonitor->VerifyNotFound();
20801
20802 // Force device idle and clean up remaining objects
20803 vkDeviceWaitIdle(m_device->device());
20804 vkDestroySemaphore(m_device->device(), s2, nullptr);
20805 vkDestroyFence(m_device->device(), fence, nullptr);
20806}
20807
20808TEST_F(VkPositiveLayerTest, FenceCreateSignaledWaitHandling) {
20809 m_errorMonitor->ExpectSuccess();
20810
Tony Barbour1fa09702017-03-16 12:09:08 -060020811 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020812 VkResult err;
20813
20814 // A fence created signaled
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020815 VkFenceCreateInfo fci1 = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, VK_FENCE_CREATE_SIGNALED_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020816 VkFence f1;
20817 err = vkCreateFence(m_device->device(), &fci1, nullptr, &f1);
20818 ASSERT_VK_SUCCESS(err);
20819
20820 // A fence created not
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020821 VkFenceCreateInfo fci2 = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020822 VkFence f2;
20823 err = vkCreateFence(m_device->device(), &fci2, nullptr, &f2);
20824 ASSERT_VK_SUCCESS(err);
20825
20826 // Submit the unsignaled fence
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020827 VkSubmitInfo si = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 0, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020828 err = vkQueueSubmit(m_device->m_queue, 1, &si, f2);
20829
20830 // Wait on both fences, with signaled first.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020831 VkFence fences[] = {f1, f2};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020832 vkWaitForFences(m_device->device(), 2, fences, VK_TRUE, UINT64_MAX);
20833
20834 // Should have both retired!
20835 vkDestroyFence(m_device->device(), f1, nullptr);
20836 vkDestroyFence(m_device->device(), f2, nullptr);
20837
20838 m_errorMonitor->VerifyNotFound();
20839}
20840
20841TEST_F(VkPositiveLayerTest, ValidUsage) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020842 TEST_DESCRIPTION(
20843 "Verify that creating an image view from an image with valid usage "
20844 "doesn't generate validation errors");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020845
Tony Barbour1fa09702017-03-16 12:09:08 -060020846 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020847
20848 m_errorMonitor->ExpectSuccess();
20849 // Verify that we can create a view with usage INPUT_ATTACHMENT
20850 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060020851 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 -060020852 ASSERT_TRUE(image.initialized());
20853 VkImageView imageView;
20854 VkImageViewCreateInfo ivci = {};
20855 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
20856 ivci.image = image.handle();
20857 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
20858 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
20859 ivci.subresourceRange.layerCount = 1;
20860 ivci.subresourceRange.baseMipLevel = 0;
20861 ivci.subresourceRange.levelCount = 1;
20862 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
20863
20864 vkCreateImageView(m_device->device(), &ivci, NULL, &imageView);
20865 m_errorMonitor->VerifyNotFound();
20866 vkDestroyImageView(m_device->device(), imageView, NULL);
20867}
20868
20869// This is a positive test. No failures are expected.
20870TEST_F(VkPositiveLayerTest, BindSparse) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020871 TEST_DESCRIPTION(
20872 "Bind 2 memory ranges to one image using vkQueueBindSparse, destroy the image"
20873 "and then free the memory");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020874
Tony Barbour1fa09702017-03-16 12:09:08 -060020875 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020876
20877 auto index = m_device->graphics_queue_node_index_;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020878 if (!(m_device->queue_props[index].queueFlags & VK_QUEUE_SPARSE_BINDING_BIT)) return;
Tony Barbour623721f2017-03-24 15:00:21 -060020879 if (!m_device->phy().features().sparseBinding) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020880
20881 m_errorMonitor->ExpectSuccess();
20882
20883 VkImage image;
20884 VkImageCreateInfo image_create_info = {};
20885 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
20886 image_create_info.pNext = NULL;
20887 image_create_info.imageType = VK_IMAGE_TYPE_2D;
20888 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
20889 image_create_info.extent.width = 64;
20890 image_create_info.extent.height = 64;
20891 image_create_info.extent.depth = 1;
20892 image_create_info.mipLevels = 1;
20893 image_create_info.arrayLayers = 1;
20894 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
20895 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
20896 image_create_info.usage = VK_IMAGE_USAGE_STORAGE_BIT;
20897 image_create_info.flags = VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
20898 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
20899 ASSERT_VK_SUCCESS(err);
20900
20901 VkMemoryRequirements memory_reqs;
20902 VkDeviceMemory memory_one, memory_two;
20903 bool pass;
20904 VkMemoryAllocateInfo memory_info = {};
20905 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
20906 memory_info.pNext = NULL;
20907 memory_info.allocationSize = 0;
20908 memory_info.memoryTypeIndex = 0;
20909 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
20910 // Find an image big enough to allow sparse mapping of 2 memory regions
20911 // Increase the image size until it is at least twice the
20912 // size of the required alignment, to ensure we can bind both
20913 // allocated memory blocks to the image on aligned offsets.
20914 while (memory_reqs.size < (memory_reqs.alignment * 2)) {
20915 vkDestroyImage(m_device->device(), image, nullptr);
20916 image_create_info.extent.width *= 2;
20917 image_create_info.extent.height *= 2;
20918 err = vkCreateImage(m_device->device(), &image_create_info, nullptr, &image);
20919 ASSERT_VK_SUCCESS(err);
20920 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
20921 }
20922 // Allocate 2 memory regions of minimum alignment size, bind one at 0, the other
20923 // at the end of the first
20924 memory_info.allocationSize = memory_reqs.alignment;
20925 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
20926 ASSERT_TRUE(pass);
20927 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_one);
20928 ASSERT_VK_SUCCESS(err);
20929 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_two);
20930 ASSERT_VK_SUCCESS(err);
20931 VkSparseMemoryBind binds[2];
20932 binds[0].flags = 0;
20933 binds[0].memory = memory_one;
20934 binds[0].memoryOffset = 0;
20935 binds[0].resourceOffset = 0;
20936 binds[0].size = memory_info.allocationSize;
20937 binds[1].flags = 0;
20938 binds[1].memory = memory_two;
20939 binds[1].memoryOffset = 0;
20940 binds[1].resourceOffset = memory_info.allocationSize;
20941 binds[1].size = memory_info.allocationSize;
20942
20943 VkSparseImageOpaqueMemoryBindInfo opaqueBindInfo;
20944 opaqueBindInfo.image = image;
20945 opaqueBindInfo.bindCount = 2;
20946 opaqueBindInfo.pBinds = binds;
20947
20948 VkFence fence = VK_NULL_HANDLE;
20949 VkBindSparseInfo bindSparseInfo = {};
20950 bindSparseInfo.sType = VK_STRUCTURE_TYPE_BIND_SPARSE_INFO;
20951 bindSparseInfo.imageOpaqueBindCount = 1;
20952 bindSparseInfo.pImageOpaqueBinds = &opaqueBindInfo;
20953
20954 vkQueueBindSparse(m_device->m_queue, 1, &bindSparseInfo, fence);
20955 vkQueueWaitIdle(m_device->m_queue);
20956 vkDestroyImage(m_device->device(), image, NULL);
20957 vkFreeMemory(m_device->device(), memory_one, NULL);
20958 vkFreeMemory(m_device->device(), memory_two, NULL);
20959 m_errorMonitor->VerifyNotFound();
20960}
20961
20962TEST_F(VkPositiveLayerTest, RenderPassInitialLayoutUndefined) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020963 TEST_DESCRIPTION(
20964 "Ensure that CmdBeginRenderPass with an attachment's "
20965 "initialLayout of VK_IMAGE_LAYOUT_UNDEFINED works when "
20966 "the command buffer has prior knowledge of that "
20967 "attachment's layout.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020968
20969 m_errorMonitor->ExpectSuccess();
20970
Tony Barbour1fa09702017-03-16 12:09:08 -060020971 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020972
20973 // A renderpass with one color attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020974 VkAttachmentDescription attachment = {0,
20975 VK_FORMAT_R8G8B8A8_UNORM,
20976 VK_SAMPLE_COUNT_1_BIT,
20977 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
20978 VK_ATTACHMENT_STORE_OP_STORE,
20979 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
20980 VK_ATTACHMENT_STORE_OP_DONT_CARE,
20981 VK_IMAGE_LAYOUT_UNDEFINED,
20982 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020983
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020984 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020985
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020986 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020987
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020988 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020989
20990 VkRenderPass rp;
20991 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
20992 ASSERT_VK_SUCCESS(err);
20993
20994 // A compatible framebuffer.
20995 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060020996 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 -060020997 ASSERT_TRUE(image.initialized());
20998
20999 VkImageViewCreateInfo ivci = {
21000 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
21001 nullptr,
21002 0,
21003 image.handle(),
21004 VK_IMAGE_VIEW_TYPE_2D,
21005 VK_FORMAT_R8G8B8A8_UNORM,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021006 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
21007 VK_COMPONENT_SWIZZLE_IDENTITY},
21008 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021009 };
21010 VkImageView view;
21011 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
21012 ASSERT_VK_SUCCESS(err);
21013
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021014 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021015 VkFramebuffer fb;
21016 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
21017 ASSERT_VK_SUCCESS(err);
21018
21019 // Record a single command buffer which uses this renderpass twice. The
21020 // bug is triggered at the beginning of the second renderpass, when the
21021 // command buffer already has a layout recorded for the attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021022 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 -070021023 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021024 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
21025 vkCmdEndRenderPass(m_commandBuffer->handle());
21026 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
21027
21028 m_errorMonitor->VerifyNotFound();
21029
21030 vkCmdEndRenderPass(m_commandBuffer->handle());
Tony Barbour552f6c02016-12-21 14:34:07 -070021031 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021032
21033 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
21034 vkDestroyRenderPass(m_device->device(), rp, nullptr);
21035 vkDestroyImageView(m_device->device(), view, nullptr);
21036}
21037
21038TEST_F(VkPositiveLayerTest, FramebufferBindingDestroyCommandPool) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021039 TEST_DESCRIPTION(
21040 "This test should pass. Create a Framebuffer and "
21041 "command buffer, bind them together, then destroy "
21042 "command pool and framebuffer and verify there are no "
21043 "errors.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021044
21045 m_errorMonitor->ExpectSuccess();
21046
Tony Barbour1fa09702017-03-16 12:09:08 -060021047 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021048
21049 // A renderpass with one color attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021050 VkAttachmentDescription attachment = {0,
21051 VK_FORMAT_R8G8B8A8_UNORM,
21052 VK_SAMPLE_COUNT_1_BIT,
21053 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
21054 VK_ATTACHMENT_STORE_OP_STORE,
21055 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
21056 VK_ATTACHMENT_STORE_OP_DONT_CARE,
21057 VK_IMAGE_LAYOUT_UNDEFINED,
21058 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021059
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021060 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021061
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021062 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021063
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021064 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021065
21066 VkRenderPass rp;
21067 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
21068 ASSERT_VK_SUCCESS(err);
21069
21070 // A compatible framebuffer.
21071 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060021072 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 -060021073 ASSERT_TRUE(image.initialized());
21074
21075 VkImageViewCreateInfo ivci = {
21076 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
21077 nullptr,
21078 0,
21079 image.handle(),
21080 VK_IMAGE_VIEW_TYPE_2D,
21081 VK_FORMAT_R8G8B8A8_UNORM,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021082 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
21083 VK_COMPONENT_SWIZZLE_IDENTITY},
21084 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021085 };
21086 VkImageView view;
21087 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
21088 ASSERT_VK_SUCCESS(err);
21089
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021090 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021091 VkFramebuffer fb;
21092 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
21093 ASSERT_VK_SUCCESS(err);
21094
21095 // Explicitly create a command buffer to bind the FB to so that we can then
21096 // destroy the command pool in order to implicitly free command buffer
21097 VkCommandPool command_pool;
21098 VkCommandPoolCreateInfo pool_create_info{};
21099 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
21100 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
21101 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
21102 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
21103
21104 VkCommandBuffer command_buffer;
21105 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
21106 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
21107 command_buffer_allocate_info.commandPool = command_pool;
21108 command_buffer_allocate_info.commandBufferCount = 1;
21109 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
21110 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
21111
21112 // Begin our cmd buffer with renderpass using our framebuffer
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021113 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 -060021114 VkCommandBufferBeginInfo begin_info{};
21115 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21116 vkBeginCommandBuffer(command_buffer, &begin_info);
21117
21118 vkCmdBeginRenderPass(command_buffer, &rpbi, VK_SUBPASS_CONTENTS_INLINE);
21119 vkCmdEndRenderPass(command_buffer);
21120 vkEndCommandBuffer(command_buffer);
21121 vkDestroyImageView(m_device->device(), view, nullptr);
21122 // Destroy command pool to implicitly free command buffer
21123 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
21124 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
21125 vkDestroyRenderPass(m_device->device(), rp, nullptr);
21126 m_errorMonitor->VerifyNotFound();
21127}
21128
21129TEST_F(VkPositiveLayerTest, RenderPassSubpassZeroTransitionsApplied) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021130 TEST_DESCRIPTION(
21131 "Ensure that CmdBeginRenderPass applies the layout "
21132 "transitions for the first subpass");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021133
21134 m_errorMonitor->ExpectSuccess();
21135
Tony Barbour1fa09702017-03-16 12:09:08 -060021136 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021137
21138 // A renderpass with one color attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021139 VkAttachmentDescription attachment = {0,
21140 VK_FORMAT_R8G8B8A8_UNORM,
21141 VK_SAMPLE_COUNT_1_BIT,
21142 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
21143 VK_ATTACHMENT_STORE_OP_STORE,
21144 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
21145 VK_ATTACHMENT_STORE_OP_DONT_CARE,
21146 VK_IMAGE_LAYOUT_UNDEFINED,
21147 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021148
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021149 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021150
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021151 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021152
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021153 VkSubpassDependency dep = {0,
21154 0,
21155 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
21156 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
21157 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
21158 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
21159 VK_DEPENDENCY_BY_REGION_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021160
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021161 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021162
21163 VkResult err;
21164 VkRenderPass rp;
21165 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
21166 ASSERT_VK_SUCCESS(err);
21167
21168 // A compatible framebuffer.
21169 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060021170 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 -060021171 ASSERT_TRUE(image.initialized());
21172
21173 VkImageViewCreateInfo ivci = {
21174 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
21175 nullptr,
21176 0,
21177 image.handle(),
21178 VK_IMAGE_VIEW_TYPE_2D,
21179 VK_FORMAT_R8G8B8A8_UNORM,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021180 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
21181 VK_COMPONENT_SWIZZLE_IDENTITY},
21182 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021183 };
21184 VkImageView view;
21185 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
21186 ASSERT_VK_SUCCESS(err);
21187
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021188 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021189 VkFramebuffer fb;
21190 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
21191 ASSERT_VK_SUCCESS(err);
21192
21193 // Record a single command buffer which issues a pipeline barrier w/
21194 // image memory barrier for the attachment. This detects the previously
21195 // missing tracking of the subpass layout by throwing a validation error
21196 // if it doesn't occur.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021197 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 -070021198 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021199 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
21200
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021201 VkImageMemoryBarrier imb = {VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
21202 nullptr,
21203 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
21204 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
21205 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
21206 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
21207 VK_QUEUE_FAMILY_IGNORED,
21208 VK_QUEUE_FAMILY_IGNORED,
21209 image.handle(),
21210 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1}};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021211 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021212 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
21213 &imb);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021214
21215 vkCmdEndRenderPass(m_commandBuffer->handle());
21216 m_errorMonitor->VerifyNotFound();
Tony Barbour552f6c02016-12-21 14:34:07 -070021217 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021218
21219 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
21220 vkDestroyRenderPass(m_device->device(), rp, nullptr);
21221 vkDestroyImageView(m_device->device(), view, nullptr);
21222}
21223
21224TEST_F(VkPositiveLayerTest, DepthStencilLayoutTransitionForDepthOnlyImageview) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021225 TEST_DESCRIPTION(
21226 "Validate that when an imageView of a depth/stencil image "
21227 "is used as a depth/stencil framebuffer attachment, the "
21228 "aspectMask is ignored and both depth and stencil image "
21229 "subresources are used.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021230
Tony Barbour1fa09702017-03-16 12:09:08 -060021231 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021232 VkFormatProperties format_properties;
21233 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_D32_SFLOAT_S8_UINT, &format_properties);
21234 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
21235 return;
21236 }
21237
21238 m_errorMonitor->ExpectSuccess();
21239
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021240 VkAttachmentDescription attachment = {0,
21241 VK_FORMAT_D32_SFLOAT_S8_UINT,
21242 VK_SAMPLE_COUNT_1_BIT,
21243 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
21244 VK_ATTACHMENT_STORE_OP_STORE,
21245 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
21246 VK_ATTACHMENT_STORE_OP_DONT_CARE,
21247 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
21248 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021249
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021250 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021251
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021252 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, &att_ref, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021253
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021254 VkSubpassDependency dep = {0,
21255 0,
21256 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
21257 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
21258 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
21259 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
21260 VK_DEPENDENCY_BY_REGION_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021261
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021262 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021263
21264 VkResult err;
21265 VkRenderPass rp;
21266 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
21267 ASSERT_VK_SUCCESS(err);
21268
21269 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060021270 image.InitNoLayout(32, 32, 1, VK_FORMAT_D32_SFLOAT_S8_UINT,
21271 0x26, // usage
21272 VK_IMAGE_TILING_OPTIMAL, 0);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021273 ASSERT_TRUE(image.initialized());
21274 image.SetLayout(0x6, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
21275
21276 VkImageViewCreateInfo ivci = {
21277 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
21278 nullptr,
21279 0,
21280 image.handle(),
21281 VK_IMAGE_VIEW_TYPE_2D,
21282 VK_FORMAT_D32_SFLOAT_S8_UINT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021283 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
21284 {0x2, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021285 };
21286 VkImageView view;
21287 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
21288 ASSERT_VK_SUCCESS(err);
21289
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021290 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021291 VkFramebuffer fb;
21292 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
21293 ASSERT_VK_SUCCESS(err);
21294
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021295 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 -070021296 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021297 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
21298
21299 VkImageMemoryBarrier imb = {};
21300 imb.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
21301 imb.pNext = nullptr;
21302 imb.srcAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
21303 imb.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
21304 imb.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
21305 imb.newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
21306 imb.srcQueueFamilyIndex = 0;
21307 imb.dstQueueFamilyIndex = 0;
21308 imb.image = image.handle();
21309 imb.subresourceRange.aspectMask = 0x6;
21310 imb.subresourceRange.baseMipLevel = 0;
21311 imb.subresourceRange.levelCount = 0x1;
21312 imb.subresourceRange.baseArrayLayer = 0;
21313 imb.subresourceRange.layerCount = 0x1;
21314
21315 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021316 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
21317 &imb);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021318
21319 vkCmdEndRenderPass(m_commandBuffer->handle());
Tony Barbour552f6c02016-12-21 14:34:07 -070021320 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021321 QueueCommandBuffer(false);
21322 m_errorMonitor->VerifyNotFound();
21323
21324 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
21325 vkDestroyRenderPass(m_device->device(), rp, nullptr);
21326 vkDestroyImageView(m_device->device(), view, nullptr);
21327}
21328
21329TEST_F(VkPositiveLayerTest, RenderPassTransitionsAttachmentUnused) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021330 TEST_DESCRIPTION(
21331 "Ensure that layout transitions work correctly without "
21332 "errors, when an attachment reference is "
21333 "VK_ATTACHMENT_UNUSED");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021334
21335 m_errorMonitor->ExpectSuccess();
21336
Tony Barbour1fa09702017-03-16 12:09:08 -060021337 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021338
21339 // A renderpass with no attachments
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021340 VkAttachmentReference att_ref = {VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021341
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021342 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021343
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021344 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 1, &subpass, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021345
21346 VkRenderPass rp;
21347 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
21348 ASSERT_VK_SUCCESS(err);
21349
21350 // A compatible framebuffer.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021351 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021352 VkFramebuffer fb;
21353 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
21354 ASSERT_VK_SUCCESS(err);
21355
21356 // Record a command buffer which just begins and ends the renderpass. The
21357 // bug manifests in BeginRenderPass.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021358 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 -070021359 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021360 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
21361 vkCmdEndRenderPass(m_commandBuffer->handle());
21362 m_errorMonitor->VerifyNotFound();
Tony Barbour552f6c02016-12-21 14:34:07 -070021363 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021364
21365 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
21366 vkDestroyRenderPass(m_device->device(), rp, nullptr);
21367}
21368
21369// This is a positive test. No errors are expected.
21370TEST_F(VkPositiveLayerTest, StencilLoadOp) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021371 TEST_DESCRIPTION(
21372 "Create a stencil-only attachment with a LOAD_OP set to "
21373 "CLEAR. stencil[Load|Store]Op used to be ignored.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021374 VkResult result = VK_SUCCESS;
Tony Barbour1fa09702017-03-16 12:09:08 -060021375 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -060021376 auto depth_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbourf887b162017-03-09 10:06:46 -070021377 if (!depth_format) {
21378 printf(" No Depth + Stencil format found. Skipped.\n");
21379 return;
21380 }
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021381 VkImageFormatProperties formatProps;
Tony Barbourf887b162017-03-09 10:06:46 -070021382 vkGetPhysicalDeviceImageFormatProperties(gpu(), depth_format, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021383 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0,
21384 &formatProps);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021385 if (formatProps.maxExtent.width < 100 || formatProps.maxExtent.height < 100) {
21386 return;
21387 }
21388
Tony Barbourf887b162017-03-09 10:06:46 -070021389 VkFormat depth_stencil_fmt = depth_format;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021390 m_depthStencil->Init(m_device, 100, 100, depth_stencil_fmt,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021391 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021392 VkAttachmentDescription att = {};
21393 VkAttachmentReference ref = {};
21394 att.format = depth_stencil_fmt;
21395 att.samples = VK_SAMPLE_COUNT_1_BIT;
21396 att.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
21397 att.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
21398 att.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
21399 att.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE;
21400 att.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
21401 att.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
21402
21403 VkClearValue clear;
21404 clear.depthStencil.depth = 1.0;
21405 clear.depthStencil.stencil = 0;
21406 ref.attachment = 0;
21407 ref.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
21408
21409 VkSubpassDescription subpass = {};
21410 subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
21411 subpass.flags = 0;
21412 subpass.inputAttachmentCount = 0;
21413 subpass.pInputAttachments = NULL;
21414 subpass.colorAttachmentCount = 0;
21415 subpass.pColorAttachments = NULL;
21416 subpass.pResolveAttachments = NULL;
21417 subpass.pDepthStencilAttachment = &ref;
21418 subpass.preserveAttachmentCount = 0;
21419 subpass.pPreserveAttachments = NULL;
21420
21421 VkRenderPass rp;
21422 VkRenderPassCreateInfo rp_info = {};
21423 rp_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
21424 rp_info.attachmentCount = 1;
21425 rp_info.pAttachments = &att;
21426 rp_info.subpassCount = 1;
21427 rp_info.pSubpasses = &subpass;
21428 result = vkCreateRenderPass(device(), &rp_info, NULL, &rp);
21429 ASSERT_VK_SUCCESS(result);
21430
21431 VkImageView *depthView = m_depthStencil->BindInfo();
21432 VkFramebufferCreateInfo fb_info = {};
21433 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
21434 fb_info.pNext = NULL;
21435 fb_info.renderPass = rp;
21436 fb_info.attachmentCount = 1;
21437 fb_info.pAttachments = depthView;
21438 fb_info.width = 100;
21439 fb_info.height = 100;
21440 fb_info.layers = 1;
21441 VkFramebuffer fb;
21442 result = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
21443 ASSERT_VK_SUCCESS(result);
21444
21445 VkRenderPassBeginInfo rpbinfo = {};
21446 rpbinfo.clearValueCount = 1;
21447 rpbinfo.pClearValues = &clear;
21448 rpbinfo.pNext = NULL;
21449 rpbinfo.renderPass = rp;
21450 rpbinfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
21451 rpbinfo.renderArea.extent.width = 100;
21452 rpbinfo.renderArea.extent.height = 100;
21453 rpbinfo.renderArea.offset.x = 0;
21454 rpbinfo.renderArea.offset.y = 0;
21455 rpbinfo.framebuffer = fb;
21456
21457 VkFence fence = {};
21458 VkFenceCreateInfo fence_ci = {};
21459 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
21460 fence_ci.pNext = nullptr;
21461 fence_ci.flags = 0;
21462 result = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fence);
21463 ASSERT_VK_SUCCESS(result);
21464
21465 m_commandBuffer->BeginCommandBuffer();
21466 m_commandBuffer->BeginRenderPass(rpbinfo);
21467 m_commandBuffer->EndRenderPass();
21468 m_commandBuffer->EndCommandBuffer();
21469 m_commandBuffer->QueueCommandBuffer(fence);
21470
21471 VkImageObj destImage(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060021472 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 -070021473 VK_IMAGE_TILING_OPTIMAL, 0);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021474 VkImageMemoryBarrier barrier = {};
21475 VkImageSubresourceRange range;
21476 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
21477 barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
21478 barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT;
21479 barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
21480 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
21481 barrier.image = m_depthStencil->handle();
21482 range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
21483 range.baseMipLevel = 0;
21484 range.levelCount = 1;
21485 range.baseArrayLayer = 0;
21486 range.layerCount = 1;
21487 barrier.subresourceRange = range;
21488 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
21489 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
21490 cmdbuf.BeginCommandBuffer();
21491 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 -070021492 &barrier);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021493 barrier.srcAccessMask = 0;
21494 barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
21495 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
21496 barrier.image = destImage.handle();
21497 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
21498 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 -070021499 &barrier);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021500 VkImageCopy cregion;
21501 cregion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
21502 cregion.srcSubresource.mipLevel = 0;
21503 cregion.srcSubresource.baseArrayLayer = 0;
21504 cregion.srcSubresource.layerCount = 1;
21505 cregion.srcOffset.x = 0;
21506 cregion.srcOffset.y = 0;
21507 cregion.srcOffset.z = 0;
21508 cregion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
21509 cregion.dstSubresource.mipLevel = 0;
21510 cregion.dstSubresource.baseArrayLayer = 0;
21511 cregion.dstSubresource.layerCount = 1;
21512 cregion.dstOffset.x = 0;
21513 cregion.dstOffset.y = 0;
21514 cregion.dstOffset.z = 0;
21515 cregion.extent.width = 100;
21516 cregion.extent.height = 100;
21517 cregion.extent.depth = 1;
21518 cmdbuf.CopyImage(m_depthStencil->handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, destImage.handle(),
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021519 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &cregion);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021520 cmdbuf.EndCommandBuffer();
21521
21522 VkSubmitInfo submit_info;
21523 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21524 submit_info.pNext = NULL;
21525 submit_info.waitSemaphoreCount = 0;
21526 submit_info.pWaitSemaphores = NULL;
21527 submit_info.pWaitDstStageMask = NULL;
21528 submit_info.commandBufferCount = 1;
21529 submit_info.pCommandBuffers = &cmdbuf.handle();
21530 submit_info.signalSemaphoreCount = 0;
21531 submit_info.pSignalSemaphores = NULL;
21532
21533 m_errorMonitor->ExpectSuccess();
21534 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
21535 m_errorMonitor->VerifyNotFound();
21536
21537 vkQueueWaitIdle(m_device->m_queue);
21538 vkDestroyFence(m_device->device(), fence, nullptr);
21539 vkDestroyRenderPass(m_device->device(), rp, nullptr);
21540 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
21541}
21542
21543// This is a positive test. No errors should be generated.
Mike Weiblene4e225d2017-03-07 23:15:43 -070021544TEST_F(VkPositiveLayerTest, BarrierLayoutToImageUsage) {
21545 TEST_DESCRIPTION("Ensure barriers' new and old VkImageLayout are compatible with their images' VkImageUsageFlags");
21546
21547 m_errorMonitor->ExpectSuccess();
21548
Tony Barbour1fa09702017-03-16 12:09:08 -060021549 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -060021550 auto depth_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbour9357d542017-03-24 15:42:21 -060021551 if (!depth_format) {
21552 printf(" No Depth + Stencil format found. Skipped.\n");
21553 return;
21554 }
Mike Weiblene4e225d2017-03-07 23:15:43 -070021555 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21556
21557 VkImageMemoryBarrier img_barrier = {};
21558 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
21559 img_barrier.pNext = NULL;
21560 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
21561 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
21562 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
21563 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
21564 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
21565 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
21566 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
21567 img_barrier.subresourceRange.baseArrayLayer = 0;
21568 img_barrier.subresourceRange.baseMipLevel = 0;
21569 img_barrier.subresourceRange.layerCount = 1;
21570 img_barrier.subresourceRange.levelCount = 1;
21571
21572 {
21573 VkImageObj img_color(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060021574 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 -070021575 ASSERT_TRUE(img_color.initialized());
21576
21577 VkImageObj img_ds1(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060021578 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 -070021579 ASSERT_TRUE(img_ds1.initialized());
21580
21581 VkImageObj img_ds2(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060021582 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 -070021583 ASSERT_TRUE(img_ds2.initialized());
21584
21585 VkImageObj img_xfer_src(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060021586 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 -070021587 ASSERT_TRUE(img_xfer_src.initialized());
21588
21589 VkImageObj img_xfer_dst(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060021590 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 -070021591 ASSERT_TRUE(img_xfer_dst.initialized());
21592
21593 VkImageObj img_sampled(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060021594 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 -070021595 ASSERT_TRUE(img_sampled.initialized());
21596
21597 VkImageObj img_input(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060021598 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 -070021599 ASSERT_TRUE(img_input.initialized());
21600
21601 const struct {
21602 VkImageObj &image_obj;
21603 VkImageLayout old_layout;
21604 VkImageLayout new_layout;
21605 } buffer_layouts[] = {
21606 // clang-format off
21607 {img_color, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL},
21608 {img_ds1, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL},
21609 {img_ds2, VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL},
21610 {img_sampled, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL},
21611 {img_input, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL},
21612 {img_xfer_src, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL},
21613 {img_xfer_dst, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL},
21614 // clang-format on
21615 };
21616 const uint32_t layout_count = sizeof(buffer_layouts) / sizeof(buffer_layouts[0]);
21617
21618 m_commandBuffer->BeginCommandBuffer();
21619 for (uint32_t i = 0; i < layout_count; ++i) {
21620 img_barrier.image = buffer_layouts[i].image_obj.handle();
21621 const VkImageUsageFlags usage = buffer_layouts[i].image_obj.usage();
21622 img_barrier.subresourceRange.aspectMask = (usage == VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT)
21623 ? (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)
21624 : VK_IMAGE_ASPECT_COLOR_BIT;
21625
21626 img_barrier.oldLayout = buffer_layouts[i].old_layout;
21627 img_barrier.newLayout = buffer_layouts[i].new_layout;
21628 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT,
21629 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0, nullptr, 1, &img_barrier);
21630
21631 img_barrier.oldLayout = buffer_layouts[i].new_layout;
21632 img_barrier.newLayout = buffer_layouts[i].old_layout;
21633 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT,
21634 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0, nullptr, 1, &img_barrier);
21635 }
21636 m_commandBuffer->EndCommandBuffer();
21637
21638 img_barrier.oldLayout = VK_IMAGE_LAYOUT_GENERAL;
21639 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
21640 }
21641 m_errorMonitor->VerifyNotFound();
21642}
21643
21644// This is a positive test. No errors should be generated.
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021645TEST_F(VkPositiveLayerTest, WaitEventThenSet) {
21646 TEST_DESCRIPTION("Wait on a event then set it after the wait has been submitted.");
21647
21648 m_errorMonitor->ExpectSuccess();
Tony Barbour1fa09702017-03-16 12:09:08 -060021649 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021650
21651 VkEvent event;
21652 VkEventCreateInfo event_create_info{};
21653 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
21654 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
21655
21656 VkCommandPool command_pool;
21657 VkCommandPoolCreateInfo pool_create_info{};
21658 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
21659 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
21660 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
21661 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
21662
21663 VkCommandBuffer command_buffer;
21664 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
21665 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
21666 command_buffer_allocate_info.commandPool = command_pool;
21667 command_buffer_allocate_info.commandBufferCount = 1;
21668 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
21669 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
21670
21671 VkQueue queue = VK_NULL_HANDLE;
21672 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
21673
21674 {
21675 VkCommandBufferBeginInfo begin_info{};
21676 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21677 vkBeginCommandBuffer(command_buffer, &begin_info);
21678
21679 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 -070021680 nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021681 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
21682 vkEndCommandBuffer(command_buffer);
21683 }
21684 {
21685 VkSubmitInfo submit_info{};
21686 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21687 submit_info.commandBufferCount = 1;
21688 submit_info.pCommandBuffers = &command_buffer;
21689 submit_info.signalSemaphoreCount = 0;
21690 submit_info.pSignalSemaphores = nullptr;
21691 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
21692 }
21693 { vkSetEvent(m_device->device(), event); }
21694
21695 vkQueueWaitIdle(queue);
21696
21697 vkDestroyEvent(m_device->device(), event, nullptr);
21698 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
21699 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
21700
21701 m_errorMonitor->VerifyNotFound();
21702}
21703// This is a positive test. No errors should be generated.
21704TEST_F(VkPositiveLayerTest, QueryAndCopySecondaryCommandBuffers) {
21705 TEST_DESCRIPTION("Issue a query on a secondary command buffery and copy it on a primary.");
21706
Tony Barbour1fa09702017-03-16 12:09:08 -060021707 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021708 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021709
21710 m_errorMonitor->ExpectSuccess();
21711
21712 VkQueryPool query_pool;
21713 VkQueryPoolCreateInfo query_pool_create_info{};
21714 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
21715 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
21716 query_pool_create_info.queryCount = 1;
21717 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
21718
21719 VkCommandPool command_pool;
21720 VkCommandPoolCreateInfo pool_create_info{};
21721 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
21722 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
21723 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
21724 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
21725
21726 VkCommandBuffer command_buffer;
21727 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
21728 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
21729 command_buffer_allocate_info.commandPool = command_pool;
21730 command_buffer_allocate_info.commandBufferCount = 1;
21731 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
21732 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
21733
21734 VkCommandBuffer secondary_command_buffer;
21735 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
21736 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer);
21737
21738 VkQueue queue = VK_NULL_HANDLE;
21739 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
21740
21741 uint32_t qfi = 0;
21742 VkBufferCreateInfo buff_create_info = {};
21743 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
21744 buff_create_info.size = 1024;
21745 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
21746 buff_create_info.queueFamilyIndexCount = 1;
21747 buff_create_info.pQueueFamilyIndices = &qfi;
21748
21749 VkResult err;
21750 VkBuffer buffer;
21751 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
21752 ASSERT_VK_SUCCESS(err);
21753 VkMemoryAllocateInfo mem_alloc = {};
21754 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
21755 mem_alloc.pNext = NULL;
21756 mem_alloc.allocationSize = 1024;
21757 mem_alloc.memoryTypeIndex = 0;
21758
21759 VkMemoryRequirements memReqs;
21760 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
21761 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
21762 if (!pass) {
21763 vkDestroyBuffer(m_device->device(), buffer, NULL);
21764 return;
21765 }
21766
21767 VkDeviceMemory mem;
21768 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
21769 ASSERT_VK_SUCCESS(err);
21770 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
21771 ASSERT_VK_SUCCESS(err);
21772
21773 VkCommandBufferInheritanceInfo hinfo = {};
21774 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
21775 hinfo.renderPass = VK_NULL_HANDLE;
21776 hinfo.subpass = 0;
21777 hinfo.framebuffer = VK_NULL_HANDLE;
21778 hinfo.occlusionQueryEnable = VK_FALSE;
21779 hinfo.queryFlags = 0;
21780 hinfo.pipelineStatistics = 0;
21781
21782 {
21783 VkCommandBufferBeginInfo begin_info{};
21784 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21785 begin_info.pInheritanceInfo = &hinfo;
21786 vkBeginCommandBuffer(secondary_command_buffer, &begin_info);
21787
21788 vkCmdResetQueryPool(secondary_command_buffer, query_pool, 0, 1);
21789 vkCmdWriteTimestamp(secondary_command_buffer, VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
21790
21791 vkEndCommandBuffer(secondary_command_buffer);
21792
21793 begin_info.pInheritanceInfo = nullptr;
21794 vkBeginCommandBuffer(command_buffer, &begin_info);
21795
21796 vkCmdExecuteCommands(command_buffer, 1, &secondary_command_buffer);
21797 vkCmdCopyQueryPoolResults(command_buffer, query_pool, 0, 1, buffer, 0, 0, 0);
21798
21799 vkEndCommandBuffer(command_buffer);
21800 }
21801 {
21802 VkSubmitInfo submit_info{};
21803 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21804 submit_info.commandBufferCount = 1;
21805 submit_info.pCommandBuffers = &command_buffer;
21806 submit_info.signalSemaphoreCount = 0;
21807 submit_info.pSignalSemaphores = nullptr;
21808 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
21809 }
21810
21811 vkQueueWaitIdle(queue);
21812
21813 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
21814 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
21815 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &secondary_command_buffer);
21816 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
21817 vkDestroyBuffer(m_device->device(), buffer, NULL);
21818 vkFreeMemory(m_device->device(), mem, NULL);
21819
21820 m_errorMonitor->VerifyNotFound();
21821}
21822
21823// This is a positive test. No errors should be generated.
21824TEST_F(VkPositiveLayerTest, QueryAndCopyMultipleCommandBuffers) {
21825 TEST_DESCRIPTION("Issue a query and copy from it on a second command buffer.");
21826
Tony Barbour1fa09702017-03-16 12:09:08 -060021827 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021828 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021829
21830 m_errorMonitor->ExpectSuccess();
21831
21832 VkQueryPool query_pool;
21833 VkQueryPoolCreateInfo query_pool_create_info{};
21834 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
21835 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
21836 query_pool_create_info.queryCount = 1;
21837 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
21838
21839 VkCommandPool command_pool;
21840 VkCommandPoolCreateInfo pool_create_info{};
21841 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
21842 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
21843 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
21844 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
21845
21846 VkCommandBuffer command_buffer[2];
21847 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
21848 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
21849 command_buffer_allocate_info.commandPool = command_pool;
21850 command_buffer_allocate_info.commandBufferCount = 2;
21851 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
21852 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
21853
21854 VkQueue queue = VK_NULL_HANDLE;
21855 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
21856
21857 uint32_t qfi = 0;
21858 VkBufferCreateInfo buff_create_info = {};
21859 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
21860 buff_create_info.size = 1024;
21861 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
21862 buff_create_info.queueFamilyIndexCount = 1;
21863 buff_create_info.pQueueFamilyIndices = &qfi;
21864
21865 VkResult err;
21866 VkBuffer buffer;
21867 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
21868 ASSERT_VK_SUCCESS(err);
21869 VkMemoryAllocateInfo mem_alloc = {};
21870 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
21871 mem_alloc.pNext = NULL;
21872 mem_alloc.allocationSize = 1024;
21873 mem_alloc.memoryTypeIndex = 0;
21874
21875 VkMemoryRequirements memReqs;
21876 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
21877 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
21878 if (!pass) {
21879 vkDestroyBuffer(m_device->device(), buffer, NULL);
21880 return;
21881 }
21882
21883 VkDeviceMemory mem;
21884 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
21885 ASSERT_VK_SUCCESS(err);
21886 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
21887 ASSERT_VK_SUCCESS(err);
21888
21889 {
21890 VkCommandBufferBeginInfo begin_info{};
21891 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21892 vkBeginCommandBuffer(command_buffer[0], &begin_info);
21893
21894 vkCmdResetQueryPool(command_buffer[0], query_pool, 0, 1);
21895 vkCmdWriteTimestamp(command_buffer[0], VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
21896
21897 vkEndCommandBuffer(command_buffer[0]);
21898
21899 vkBeginCommandBuffer(command_buffer[1], &begin_info);
21900
21901 vkCmdCopyQueryPoolResults(command_buffer[1], query_pool, 0, 1, buffer, 0, 0, 0);
21902
21903 vkEndCommandBuffer(command_buffer[1]);
21904 }
21905 {
21906 VkSubmitInfo submit_info{};
21907 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21908 submit_info.commandBufferCount = 2;
21909 submit_info.pCommandBuffers = command_buffer;
21910 submit_info.signalSemaphoreCount = 0;
21911 submit_info.pSignalSemaphores = nullptr;
21912 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
21913 }
21914
21915 vkQueueWaitIdle(queue);
21916
21917 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
21918 vkFreeCommandBuffers(m_device->device(), command_pool, 2, command_buffer);
21919 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
21920 vkDestroyBuffer(m_device->device(), buffer, NULL);
21921 vkFreeMemory(m_device->device(), mem, NULL);
21922
21923 m_errorMonitor->VerifyNotFound();
21924}
21925
Tony Barbourc46924f2016-11-04 11:49:52 -060021926TEST_F(VkLayerTest, ResetEventThenSet) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021927 TEST_DESCRIPTION("Reset an event then set it after the reset has been submitted.");
21928
Tony Barbour1fa09702017-03-16 12:09:08 -060021929 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021930 VkEvent event;
21931 VkEventCreateInfo event_create_info{};
21932 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
21933 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
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;
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 = 1;
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_, 0, &queue);
21952
21953 {
21954 VkCommandBufferBeginInfo begin_info{};
21955 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21956 vkBeginCommandBuffer(command_buffer, &begin_info);
21957
21958 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021959 vkEndCommandBuffer(command_buffer);
21960 }
21961 {
21962 VkSubmitInfo submit_info{};
21963 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21964 submit_info.commandBufferCount = 1;
21965 submit_info.pCommandBuffers = &command_buffer;
21966 submit_info.signalSemaphoreCount = 0;
21967 submit_info.pSignalSemaphores = nullptr;
21968 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
21969 }
21970 {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021971 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
21972 "that is already in use by a "
21973 "command buffer.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021974 vkSetEvent(m_device->device(), event);
21975 m_errorMonitor->VerifyFound();
21976 }
21977
21978 vkQueueWaitIdle(queue);
21979
21980 vkDestroyEvent(m_device->device(), event, nullptr);
21981 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
21982 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
21983}
21984
21985// This is a positive test. No errors should be generated.
21986TEST_F(VkPositiveLayerTest, TwoFencesThreeFrames) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021987 TEST_DESCRIPTION(
21988 "Two command buffers with two separate fences are each "
21989 "run through a Submit & WaitForFences cycle 3 times. This "
21990 "previously revealed a bug so running this positive test "
21991 "to prevent a regression.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021992 m_errorMonitor->ExpectSuccess();
21993
Tony Barbour1fa09702017-03-16 12:09:08 -060021994 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021995 VkQueue queue = VK_NULL_HANDLE;
21996 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
21997
21998 static const uint32_t NUM_OBJECTS = 2;
21999 static const uint32_t NUM_FRAMES = 3;
22000 VkCommandBuffer cmd_buffers[NUM_OBJECTS] = {};
22001 VkFence fences[NUM_OBJECTS] = {};
22002
22003 VkCommandPool cmd_pool;
22004 VkCommandPoolCreateInfo cmd_pool_ci = {};
22005 cmd_pool_ci.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
22006 cmd_pool_ci.queueFamilyIndex = m_device->graphics_queue_node_index_;
22007 cmd_pool_ci.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
22008 VkResult err = vkCreateCommandPool(m_device->device(), &cmd_pool_ci, nullptr, &cmd_pool);
22009 ASSERT_VK_SUCCESS(err);
22010
22011 VkCommandBufferAllocateInfo cmd_buf_info = {};
22012 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
22013 cmd_buf_info.commandPool = cmd_pool;
22014 cmd_buf_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
22015 cmd_buf_info.commandBufferCount = 1;
22016
22017 VkFenceCreateInfo fence_ci = {};
22018 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
22019 fence_ci.pNext = nullptr;
22020 fence_ci.flags = 0;
22021
22022 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
22023 err = vkAllocateCommandBuffers(m_device->device(), &cmd_buf_info, &cmd_buffers[i]);
22024 ASSERT_VK_SUCCESS(err);
22025 err = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fences[i]);
22026 ASSERT_VK_SUCCESS(err);
22027 }
22028
22029 for (uint32_t frame = 0; frame < NUM_FRAMES; ++frame) {
22030 for (uint32_t obj = 0; obj < NUM_OBJECTS; ++obj) {
22031 // Create empty cmd buffer
22032 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
22033 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22034
22035 err = vkBeginCommandBuffer(cmd_buffers[obj], &cmdBufBeginDesc);
22036 ASSERT_VK_SUCCESS(err);
22037 err = vkEndCommandBuffer(cmd_buffers[obj]);
22038 ASSERT_VK_SUCCESS(err);
22039
22040 VkSubmitInfo submit_info = {};
22041 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22042 submit_info.commandBufferCount = 1;
22043 submit_info.pCommandBuffers = &cmd_buffers[obj];
22044 // Submit cmd buffer and wait for fence
22045 err = vkQueueSubmit(queue, 1, &submit_info, fences[obj]);
22046 ASSERT_VK_SUCCESS(err);
22047 err = vkWaitForFences(m_device->device(), 1, &fences[obj], VK_TRUE, UINT64_MAX);
22048 ASSERT_VK_SUCCESS(err);
22049 err = vkResetFences(m_device->device(), 1, &fences[obj]);
22050 ASSERT_VK_SUCCESS(err);
22051 }
22052 }
22053 m_errorMonitor->VerifyNotFound();
22054 vkDestroyCommandPool(m_device->device(), cmd_pool, NULL);
22055 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
22056 vkDestroyFence(m_device->device(), fences[i], nullptr);
22057 }
22058}
22059// This is a positive test. No errors should be generated.
22060TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWI) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022061 TEST_DESCRIPTION(
22062 "Two command buffers, each in a separate QueueSubmit call "
22063 "submitted on separate queues followed by a QueueWaitIdle.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022064
Tony Barbour1fa09702017-03-16 12:09:08 -060022065 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022066 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022067
22068 m_errorMonitor->ExpectSuccess();
22069
22070 VkSemaphore semaphore;
22071 VkSemaphoreCreateInfo semaphore_create_info{};
22072 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
22073 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
22074
22075 VkCommandPool command_pool;
22076 VkCommandPoolCreateInfo pool_create_info{};
22077 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
22078 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
22079 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
22080 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
22081
22082 VkCommandBuffer command_buffer[2];
22083 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
22084 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
22085 command_buffer_allocate_info.commandPool = command_pool;
22086 command_buffer_allocate_info.commandBufferCount = 2;
22087 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
22088 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
22089
22090 VkQueue queue = VK_NULL_HANDLE;
22091 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
22092
22093 {
22094 VkCommandBufferBeginInfo begin_info{};
22095 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22096 vkBeginCommandBuffer(command_buffer[0], &begin_info);
22097
22098 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 -070022099 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022100
22101 VkViewport viewport{};
22102 viewport.maxDepth = 1.0f;
22103 viewport.minDepth = 0.0f;
22104 viewport.width = 512;
22105 viewport.height = 512;
22106 viewport.x = 0;
22107 viewport.y = 0;
22108 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
22109 vkEndCommandBuffer(command_buffer[0]);
22110 }
22111 {
22112 VkCommandBufferBeginInfo begin_info{};
22113 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22114 vkBeginCommandBuffer(command_buffer[1], &begin_info);
22115
22116 VkViewport viewport{};
22117 viewport.maxDepth = 1.0f;
22118 viewport.minDepth = 0.0f;
22119 viewport.width = 512;
22120 viewport.height = 512;
22121 viewport.x = 0;
22122 viewport.y = 0;
22123 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
22124 vkEndCommandBuffer(command_buffer[1]);
22125 }
22126 {
22127 VkSubmitInfo submit_info{};
22128 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22129 submit_info.commandBufferCount = 1;
22130 submit_info.pCommandBuffers = &command_buffer[0];
22131 submit_info.signalSemaphoreCount = 1;
22132 submit_info.pSignalSemaphores = &semaphore;
22133 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
22134 }
22135 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022136 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022137 VkSubmitInfo submit_info{};
22138 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22139 submit_info.commandBufferCount = 1;
22140 submit_info.pCommandBuffers = &command_buffer[1];
22141 submit_info.waitSemaphoreCount = 1;
22142 submit_info.pWaitSemaphores = &semaphore;
22143 submit_info.pWaitDstStageMask = flags;
22144 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
22145 }
22146
22147 vkQueueWaitIdle(m_device->m_queue);
22148
22149 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
22150 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
22151 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
22152
22153 m_errorMonitor->VerifyNotFound();
22154}
22155
22156// This is a positive test. No errors should be generated.
22157TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWIFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022158 TEST_DESCRIPTION(
22159 "Two command buffers, each in a separate QueueSubmit call "
22160 "submitted on separate queues, the second having a fence"
22161 "followed by a QueueWaitIdle.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022162
Tony Barbour1fa09702017-03-16 12:09:08 -060022163 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022164 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022165
22166 m_errorMonitor->ExpectSuccess();
22167
22168 VkFence fence;
22169 VkFenceCreateInfo fence_create_info{};
22170 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
22171 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
22172
22173 VkSemaphore semaphore;
22174 VkSemaphoreCreateInfo semaphore_create_info{};
22175 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
22176 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
22177
22178 VkCommandPool command_pool;
22179 VkCommandPoolCreateInfo pool_create_info{};
22180 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
22181 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
22182 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
22183 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
22184
22185 VkCommandBuffer command_buffer[2];
22186 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
22187 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
22188 command_buffer_allocate_info.commandPool = command_pool;
22189 command_buffer_allocate_info.commandBufferCount = 2;
22190 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
22191 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
22192
22193 VkQueue queue = VK_NULL_HANDLE;
22194 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
22195
22196 {
22197 VkCommandBufferBeginInfo begin_info{};
22198 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22199 vkBeginCommandBuffer(command_buffer[0], &begin_info);
22200
22201 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 -070022202 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022203
22204 VkViewport viewport{};
22205 viewport.maxDepth = 1.0f;
22206 viewport.minDepth = 0.0f;
22207 viewport.width = 512;
22208 viewport.height = 512;
22209 viewport.x = 0;
22210 viewport.y = 0;
22211 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
22212 vkEndCommandBuffer(command_buffer[0]);
22213 }
22214 {
22215 VkCommandBufferBeginInfo begin_info{};
22216 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22217 vkBeginCommandBuffer(command_buffer[1], &begin_info);
22218
22219 VkViewport viewport{};
22220 viewport.maxDepth = 1.0f;
22221 viewport.minDepth = 0.0f;
22222 viewport.width = 512;
22223 viewport.height = 512;
22224 viewport.x = 0;
22225 viewport.y = 0;
22226 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
22227 vkEndCommandBuffer(command_buffer[1]);
22228 }
22229 {
22230 VkSubmitInfo submit_info{};
22231 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22232 submit_info.commandBufferCount = 1;
22233 submit_info.pCommandBuffers = &command_buffer[0];
22234 submit_info.signalSemaphoreCount = 1;
22235 submit_info.pSignalSemaphores = &semaphore;
22236 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
22237 }
22238 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022239 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022240 VkSubmitInfo submit_info{};
22241 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22242 submit_info.commandBufferCount = 1;
22243 submit_info.pCommandBuffers = &command_buffer[1];
22244 submit_info.waitSemaphoreCount = 1;
22245 submit_info.pWaitSemaphores = &semaphore;
22246 submit_info.pWaitDstStageMask = flags;
22247 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
22248 }
22249
22250 vkQueueWaitIdle(m_device->m_queue);
22251
22252 vkDestroyFence(m_device->device(), fence, nullptr);
22253 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
22254 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
22255 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
22256
22257 m_errorMonitor->VerifyNotFound();
22258}
22259
22260// This is a positive test. No errors should be generated.
22261TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceTwoWFF) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022262 TEST_DESCRIPTION(
22263 "Two command buffers, each in a separate QueueSubmit call "
22264 "submitted on separate queues, the second having a fence"
22265 "followed by two consecutive WaitForFences calls on the same fence.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022266
Tony Barbour1fa09702017-03-16 12:09:08 -060022267 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022268 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022269
22270 m_errorMonitor->ExpectSuccess();
22271
22272 VkFence fence;
22273 VkFenceCreateInfo fence_create_info{};
22274 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
22275 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
22276
22277 VkSemaphore semaphore;
22278 VkSemaphoreCreateInfo semaphore_create_info{};
22279 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
22280 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
22281
22282 VkCommandPool command_pool;
22283 VkCommandPoolCreateInfo pool_create_info{};
22284 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
22285 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
22286 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
22287 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
22288
22289 VkCommandBuffer command_buffer[2];
22290 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
22291 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
22292 command_buffer_allocate_info.commandPool = command_pool;
22293 command_buffer_allocate_info.commandBufferCount = 2;
22294 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
22295 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
22296
22297 VkQueue queue = VK_NULL_HANDLE;
22298 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
22299
22300 {
22301 VkCommandBufferBeginInfo begin_info{};
22302 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22303 vkBeginCommandBuffer(command_buffer[0], &begin_info);
22304
22305 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 -070022306 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022307
22308 VkViewport viewport{};
22309 viewport.maxDepth = 1.0f;
22310 viewport.minDepth = 0.0f;
22311 viewport.width = 512;
22312 viewport.height = 512;
22313 viewport.x = 0;
22314 viewport.y = 0;
22315 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
22316 vkEndCommandBuffer(command_buffer[0]);
22317 }
22318 {
22319 VkCommandBufferBeginInfo begin_info{};
22320 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22321 vkBeginCommandBuffer(command_buffer[1], &begin_info);
22322
22323 VkViewport viewport{};
22324 viewport.maxDepth = 1.0f;
22325 viewport.minDepth = 0.0f;
22326 viewport.width = 512;
22327 viewport.height = 512;
22328 viewport.x = 0;
22329 viewport.y = 0;
22330 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
22331 vkEndCommandBuffer(command_buffer[1]);
22332 }
22333 {
22334 VkSubmitInfo submit_info{};
22335 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22336 submit_info.commandBufferCount = 1;
22337 submit_info.pCommandBuffers = &command_buffer[0];
22338 submit_info.signalSemaphoreCount = 1;
22339 submit_info.pSignalSemaphores = &semaphore;
22340 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
22341 }
22342 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022343 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022344 VkSubmitInfo submit_info{};
22345 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22346 submit_info.commandBufferCount = 1;
22347 submit_info.pCommandBuffers = &command_buffer[1];
22348 submit_info.waitSemaphoreCount = 1;
22349 submit_info.pWaitSemaphores = &semaphore;
22350 submit_info.pWaitDstStageMask = flags;
22351 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
22352 }
22353
22354 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
22355 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
22356
22357 vkDestroyFence(m_device->device(), fence, nullptr);
22358 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
22359 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
22360 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
22361
22362 m_errorMonitor->VerifyNotFound();
22363}
22364
22365TEST_F(VkPositiveLayerTest, TwoQueuesEnsureCorrectRetirementWithWorkStolen) {
Tony Barbour1fa09702017-03-16 12:09:08 -060022366 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022367 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070022368 printf(" Test requires two queues, skipping\n");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022369 return;
22370 }
22371
22372 VkResult err;
22373
22374 m_errorMonitor->ExpectSuccess();
22375
22376 VkQueue q0 = m_device->m_queue;
22377 VkQueue q1 = nullptr;
22378 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &q1);
22379 ASSERT_NE(q1, nullptr);
22380
22381 // An (empty) command buffer. We must have work in the first submission --
22382 // the layer treats unfenced work differently from fenced work.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022383 VkCommandPoolCreateInfo cpci = {VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, nullptr, 0, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022384 VkCommandPool pool;
22385 err = vkCreateCommandPool(m_device->device(), &cpci, nullptr, &pool);
22386 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022387 VkCommandBufferAllocateInfo cbai = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, nullptr, pool,
22388 VK_COMMAND_BUFFER_LEVEL_PRIMARY, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022389 VkCommandBuffer cb;
22390 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &cb);
22391 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022392 VkCommandBufferBeginInfo cbbi = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022393 err = vkBeginCommandBuffer(cb, &cbbi);
22394 ASSERT_VK_SUCCESS(err);
22395 err = vkEndCommandBuffer(cb);
22396 ASSERT_VK_SUCCESS(err);
22397
22398 // A semaphore
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022399 VkSemaphoreCreateInfo sci = {VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022400 VkSemaphore s;
22401 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s);
22402 ASSERT_VK_SUCCESS(err);
22403
22404 // First submission, to q0
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022405 VkSubmitInfo s0 = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &cb, 1, &s};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022406
22407 err = vkQueueSubmit(q0, 1, &s0, VK_NULL_HANDLE);
22408 ASSERT_VK_SUCCESS(err);
22409
22410 // Second submission, to q1, waiting on s
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022411 VkFlags waitmask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; // doesn't really matter what this value is.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022412 VkSubmitInfo s1 = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 1, &s, &waitmask, 0, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022413
22414 err = vkQueueSubmit(q1, 1, &s1, VK_NULL_HANDLE);
22415 ASSERT_VK_SUCCESS(err);
22416
22417 // Wait for q0 idle
22418 err = vkQueueWaitIdle(q0);
22419 ASSERT_VK_SUCCESS(err);
22420
22421 // Command buffer should have been completed (it was on q0); reset the pool.
22422 vkFreeCommandBuffers(m_device->device(), pool, 1, &cb);
22423
22424 m_errorMonitor->VerifyNotFound();
22425
22426 // Force device completely idle and clean up resources
22427 vkDeviceWaitIdle(m_device->device());
22428 vkDestroyCommandPool(m_device->device(), pool, nullptr);
22429 vkDestroySemaphore(m_device->device(), s, nullptr);
22430}
22431
22432// This is a positive test. No errors should be generated.
22433TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022434 TEST_DESCRIPTION(
22435 "Two command buffers, each in a separate QueueSubmit call "
22436 "submitted on separate queues, the second having a fence, "
22437 "followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022438
Tony Barbour1fa09702017-03-16 12:09:08 -060022439 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022440 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022441
22442 m_errorMonitor->ExpectSuccess();
22443
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022444 VkFence fence;
22445 VkFenceCreateInfo fence_create_info{};
22446 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
22447 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
22448
22449 VkSemaphore semaphore;
22450 VkSemaphoreCreateInfo semaphore_create_info{};
22451 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
22452 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
22453
22454 VkCommandPool command_pool;
22455 VkCommandPoolCreateInfo pool_create_info{};
22456 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
22457 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
22458 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
22459 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
22460
22461 VkCommandBuffer command_buffer[2];
22462 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
22463 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
22464 command_buffer_allocate_info.commandPool = command_pool;
22465 command_buffer_allocate_info.commandBufferCount = 2;
22466 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
22467 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
22468
22469 VkQueue queue = VK_NULL_HANDLE;
22470 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
22471
22472 {
22473 VkCommandBufferBeginInfo begin_info{};
22474 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22475 vkBeginCommandBuffer(command_buffer[0], &begin_info);
22476
22477 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 -070022478 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022479
22480 VkViewport viewport{};
22481 viewport.maxDepth = 1.0f;
22482 viewport.minDepth = 0.0f;
22483 viewport.width = 512;
22484 viewport.height = 512;
22485 viewport.x = 0;
22486 viewport.y = 0;
22487 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
22488 vkEndCommandBuffer(command_buffer[0]);
22489 }
22490 {
22491 VkCommandBufferBeginInfo begin_info{};
22492 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22493 vkBeginCommandBuffer(command_buffer[1], &begin_info);
22494
22495 VkViewport viewport{};
22496 viewport.maxDepth = 1.0f;
22497 viewport.minDepth = 0.0f;
22498 viewport.width = 512;
22499 viewport.height = 512;
22500 viewport.x = 0;
22501 viewport.y = 0;
22502 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
22503 vkEndCommandBuffer(command_buffer[1]);
22504 }
22505 {
22506 VkSubmitInfo submit_info{};
22507 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22508 submit_info.commandBufferCount = 1;
22509 submit_info.pCommandBuffers = &command_buffer[0];
22510 submit_info.signalSemaphoreCount = 1;
22511 submit_info.pSignalSemaphores = &semaphore;
22512 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
22513 }
22514 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022515 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022516 VkSubmitInfo submit_info{};
22517 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22518 submit_info.commandBufferCount = 1;
22519 submit_info.pCommandBuffers = &command_buffer[1];
22520 submit_info.waitSemaphoreCount = 1;
22521 submit_info.pWaitSemaphores = &semaphore;
22522 submit_info.pWaitDstStageMask = flags;
22523 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
22524 }
22525
22526 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
22527
22528 vkDestroyFence(m_device->device(), fence, nullptr);
22529 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
22530 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
22531 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
22532
22533 m_errorMonitor->VerifyNotFound();
22534}
22535
22536// This is a positive test. No errors should be generated.
22537TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueWithSemaphoreAndOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022538 TEST_DESCRIPTION(
22539 "Two command buffers, each in a separate QueueSubmit call "
22540 "on the same queue, sharing a signal/wait semaphore, the "
22541 "second having a fence, "
22542 "followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022543
22544 m_errorMonitor->ExpectSuccess();
22545
Tony Barbour1fa09702017-03-16 12:09:08 -060022546 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022547 VkFence fence;
22548 VkFenceCreateInfo fence_create_info{};
22549 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
22550 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
22551
22552 VkSemaphore semaphore;
22553 VkSemaphoreCreateInfo semaphore_create_info{};
22554 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
22555 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
22556
22557 VkCommandPool command_pool;
22558 VkCommandPoolCreateInfo pool_create_info{};
22559 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
22560 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
22561 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
22562 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
22563
22564 VkCommandBuffer command_buffer[2];
22565 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
22566 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
22567 command_buffer_allocate_info.commandPool = command_pool;
22568 command_buffer_allocate_info.commandBufferCount = 2;
22569 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
22570 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
22571
22572 {
22573 VkCommandBufferBeginInfo begin_info{};
22574 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22575 vkBeginCommandBuffer(command_buffer[0], &begin_info);
22576
22577 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 -070022578 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022579
22580 VkViewport viewport{};
22581 viewport.maxDepth = 1.0f;
22582 viewport.minDepth = 0.0f;
22583 viewport.width = 512;
22584 viewport.height = 512;
22585 viewport.x = 0;
22586 viewport.y = 0;
22587 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
22588 vkEndCommandBuffer(command_buffer[0]);
22589 }
22590 {
22591 VkCommandBufferBeginInfo begin_info{};
22592 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22593 vkBeginCommandBuffer(command_buffer[1], &begin_info);
22594
22595 VkViewport viewport{};
22596 viewport.maxDepth = 1.0f;
22597 viewport.minDepth = 0.0f;
22598 viewport.width = 512;
22599 viewport.height = 512;
22600 viewport.x = 0;
22601 viewport.y = 0;
22602 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
22603 vkEndCommandBuffer(command_buffer[1]);
22604 }
22605 {
22606 VkSubmitInfo submit_info{};
22607 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22608 submit_info.commandBufferCount = 1;
22609 submit_info.pCommandBuffers = &command_buffer[0];
22610 submit_info.signalSemaphoreCount = 1;
22611 submit_info.pSignalSemaphores = &semaphore;
22612 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
22613 }
22614 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022615 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022616 VkSubmitInfo submit_info{};
22617 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22618 submit_info.commandBufferCount = 1;
22619 submit_info.pCommandBuffers = &command_buffer[1];
22620 submit_info.waitSemaphoreCount = 1;
22621 submit_info.pWaitSemaphores = &semaphore;
22622 submit_info.pWaitDstStageMask = flags;
22623 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
22624 }
22625
22626 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
22627
22628 vkDestroyFence(m_device->device(), fence, nullptr);
22629 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
22630 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
22631 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
22632
22633 m_errorMonitor->VerifyNotFound();
22634}
22635
22636// This is a positive test. No errors should be generated.
22637TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueNullQueueSubmitWithFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022638 TEST_DESCRIPTION(
22639 "Two command buffers, each in a separate QueueSubmit call "
22640 "on the same queue, no fences, followed by a third QueueSubmit with NO "
22641 "SubmitInfos but with a fence, followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022642
22643 m_errorMonitor->ExpectSuccess();
22644
Tony Barbour1fa09702017-03-16 12:09:08 -060022645 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022646 VkFence fence;
22647 VkFenceCreateInfo fence_create_info{};
22648 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
22649 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
22650
22651 VkCommandPool command_pool;
22652 VkCommandPoolCreateInfo pool_create_info{};
22653 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
22654 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
22655 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
22656 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
22657
22658 VkCommandBuffer command_buffer[2];
22659 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
22660 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
22661 command_buffer_allocate_info.commandPool = command_pool;
22662 command_buffer_allocate_info.commandBufferCount = 2;
22663 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
22664 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
22665
22666 {
22667 VkCommandBufferBeginInfo begin_info{};
22668 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22669 vkBeginCommandBuffer(command_buffer[0], &begin_info);
22670
22671 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 -070022672 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022673
22674 VkViewport viewport{};
22675 viewport.maxDepth = 1.0f;
22676 viewport.minDepth = 0.0f;
22677 viewport.width = 512;
22678 viewport.height = 512;
22679 viewport.x = 0;
22680 viewport.y = 0;
22681 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
22682 vkEndCommandBuffer(command_buffer[0]);
22683 }
22684 {
22685 VkCommandBufferBeginInfo begin_info{};
22686 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22687 vkBeginCommandBuffer(command_buffer[1], &begin_info);
22688
22689 VkViewport viewport{};
22690 viewport.maxDepth = 1.0f;
22691 viewport.minDepth = 0.0f;
22692 viewport.width = 512;
22693 viewport.height = 512;
22694 viewport.x = 0;
22695 viewport.y = 0;
22696 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
22697 vkEndCommandBuffer(command_buffer[1]);
22698 }
22699 {
22700 VkSubmitInfo submit_info{};
22701 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22702 submit_info.commandBufferCount = 1;
22703 submit_info.pCommandBuffers = &command_buffer[0];
22704 submit_info.signalSemaphoreCount = 0;
22705 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
22706 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
22707 }
22708 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022709 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022710 VkSubmitInfo submit_info{};
22711 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22712 submit_info.commandBufferCount = 1;
22713 submit_info.pCommandBuffers = &command_buffer[1];
22714 submit_info.waitSemaphoreCount = 0;
22715 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
22716 submit_info.pWaitDstStageMask = flags;
22717 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
22718 }
22719
22720 vkQueueSubmit(m_device->m_queue, 0, NULL, fence);
22721
22722 VkResult err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
22723 ASSERT_VK_SUCCESS(err);
22724
22725 vkDestroyFence(m_device->device(), fence, 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, TwoQueueSubmitsOneQueueOneFence) {
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, the second having a fence, followed "
22737 "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, fence);
22814 }
22815
22816 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
22817
22818 vkDestroyFence(m_device->device(), fence, nullptr);
22819 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
22820 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
22821
22822 m_errorMonitor->VerifyNotFound();
22823}
22824
22825// This is a positive test. No errors should be generated.
22826TEST_F(VkPositiveLayerTest, TwoSubmitInfosWithSemaphoreOneQueueSubmitsOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022827 TEST_DESCRIPTION(
22828 "Two command buffers each in a separate SubmitInfo sent in a single "
22829 "QueueSubmit call followed by a WaitForFences call.");
Tony Barbour1fa09702017-03-16 12:09:08 -060022830 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022831
22832 m_errorMonitor->ExpectSuccess();
22833
22834 VkFence fence;
22835 VkFenceCreateInfo fence_create_info{};
22836 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
22837 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
22838
22839 VkSemaphore semaphore;
22840 VkSemaphoreCreateInfo semaphore_create_info{};
22841 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
22842 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
22843
22844 VkCommandPool command_pool;
22845 VkCommandPoolCreateInfo pool_create_info{};
22846 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
22847 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
22848 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
22849 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
22850
22851 VkCommandBuffer command_buffer[2];
22852 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
22853 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
22854 command_buffer_allocate_info.commandPool = command_pool;
22855 command_buffer_allocate_info.commandBufferCount = 2;
22856 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
22857 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
22858
22859 {
22860 VkCommandBufferBeginInfo begin_info{};
22861 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22862 vkBeginCommandBuffer(command_buffer[0], &begin_info);
22863
22864 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 -070022865 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022866
22867 VkViewport viewport{};
22868 viewport.maxDepth = 1.0f;
22869 viewport.minDepth = 0.0f;
22870 viewport.width = 512;
22871 viewport.height = 512;
22872 viewport.x = 0;
22873 viewport.y = 0;
22874 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
22875 vkEndCommandBuffer(command_buffer[0]);
22876 }
22877 {
22878 VkCommandBufferBeginInfo begin_info{};
22879 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22880 vkBeginCommandBuffer(command_buffer[1], &begin_info);
22881
22882 VkViewport viewport{};
22883 viewport.maxDepth = 1.0f;
22884 viewport.minDepth = 0.0f;
22885 viewport.width = 512;
22886 viewport.height = 512;
22887 viewport.x = 0;
22888 viewport.y = 0;
22889 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
22890 vkEndCommandBuffer(command_buffer[1]);
22891 }
22892 {
22893 VkSubmitInfo submit_info[2];
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022894 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022895
22896 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22897 submit_info[0].pNext = NULL;
22898 submit_info[0].commandBufferCount = 1;
22899 submit_info[0].pCommandBuffers = &command_buffer[0];
22900 submit_info[0].signalSemaphoreCount = 1;
22901 submit_info[0].pSignalSemaphores = &semaphore;
22902 submit_info[0].waitSemaphoreCount = 0;
22903 submit_info[0].pWaitSemaphores = NULL;
22904 submit_info[0].pWaitDstStageMask = 0;
22905
22906 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22907 submit_info[1].pNext = NULL;
22908 submit_info[1].commandBufferCount = 1;
22909 submit_info[1].pCommandBuffers = &command_buffer[1];
22910 submit_info[1].waitSemaphoreCount = 1;
22911 submit_info[1].pWaitSemaphores = &semaphore;
22912 submit_info[1].pWaitDstStageMask = flags;
22913 submit_info[1].signalSemaphoreCount = 0;
22914 submit_info[1].pSignalSemaphores = NULL;
22915 vkQueueSubmit(m_device->m_queue, 2, &submit_info[0], fence);
22916 }
22917
22918 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
22919
22920 vkDestroyFence(m_device->device(), fence, nullptr);
22921 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
22922 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
22923 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
22924
22925 m_errorMonitor->VerifyNotFound();
22926}
22927
22928TEST_F(VkPositiveLayerTest, RenderPassSecondaryCommandBuffersMultipleTimes) {
22929 m_errorMonitor->ExpectSuccess();
22930
Tony Barbour1fa09702017-03-16 12:09:08 -060022931 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022932 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
22933
Tony Barbour552f6c02016-12-21 14:34:07 -070022934 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022935
22936 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
22937 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
22938 m_errorMonitor->VerifyNotFound();
22939 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
22940 m_errorMonitor->VerifyNotFound();
22941 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
22942 m_errorMonitor->VerifyNotFound();
22943
22944 m_commandBuffer->EndCommandBuffer();
22945 m_errorMonitor->VerifyNotFound();
22946}
22947
22948TEST_F(VkPositiveLayerTest, ValidRenderPassAttachmentLayoutWithLoadOp) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022949 TEST_DESCRIPTION(
22950 "Positive test where we create a renderpass with an "
22951 "attachment that uses LOAD_OP_CLEAR, the first subpass "
22952 "has a valid layout, and a second subpass then uses a "
22953 "valid *READ_ONLY* layout.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022954 m_errorMonitor->ExpectSuccess();
Tony Barbour1fa09702017-03-16 12:09:08 -060022955 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -060022956 auto depth_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbourf887b162017-03-09 10:06:46 -070022957 if (!depth_format) {
22958 printf(" No Depth + Stencil format found. Skipped.\n");
22959 return;
22960 }
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022961
22962 VkAttachmentReference attach[2] = {};
22963 attach[0].attachment = 0;
22964 attach[0].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
22965 attach[1].attachment = 0;
22966 attach[1].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
22967 VkSubpassDescription subpasses[2] = {};
22968 // First subpass clears DS attach on load
22969 subpasses[0].pDepthStencilAttachment = &attach[0];
22970 // 2nd subpass reads in DS as input attachment
22971 subpasses[1].inputAttachmentCount = 1;
22972 subpasses[1].pInputAttachments = &attach[1];
22973 VkAttachmentDescription attach_desc = {};
Tony Barbourf887b162017-03-09 10:06:46 -070022974 attach_desc.format = depth_format;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022975 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
22976 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
22977 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
22978 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
22979 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
22980 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
22981 attach_desc.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
22982 VkRenderPassCreateInfo rpci = {};
22983 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
22984 rpci.attachmentCount = 1;
22985 rpci.pAttachments = &attach_desc;
22986 rpci.subpassCount = 2;
22987 rpci.pSubpasses = subpasses;
22988
22989 // Now create RenderPass and verify no errors
22990 VkRenderPass rp;
22991 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
22992 m_errorMonitor->VerifyNotFound();
22993
22994 vkDestroyRenderPass(m_device->device(), rp, NULL);
22995}
22996
Tobin Ehlis01103de2017-02-16 13:22:47 -070022997TEST_F(VkPositiveLayerTest, RenderPassDepthStencilLayoutTransition) {
22998 TEST_DESCRIPTION(
22999 "Create a render pass with depth-stencil attachment where layout transition "
23000 "from UNDEFINED TO DS_READ_ONLY_OPTIMAL is set by render pass and verify that "
23001 "transition has correctly occurred at queue submit time with no validation errors.");
23002
Tony Barbour1fa09702017-03-16 12:09:08 -060023003 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -060023004 auto depth_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbourf887b162017-03-09 10:06:46 -070023005 if (!depth_format) {
23006 printf(" No Depth + Stencil format found. Skipped.\n");
23007 return;
23008 }
Tobin Ehlis01103de2017-02-16 13:22:47 -070023009 VkImageFormatProperties format_props;
Tony Barbourf887b162017-03-09 10:06:46 -070023010 vkGetPhysicalDeviceImageFormatProperties(gpu(), depth_format, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
Tobin Ehlis01103de2017-02-16 13:22:47 -070023011 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, 0, &format_props);
23012 if (format_props.maxExtent.width < 32 || format_props.maxExtent.height < 32) {
Tony Barbourf887b162017-03-09 10:06:46 -070023013 printf("Depth extent too small, RenderPassDepthStencilLayoutTransition skipped.\n");
Tobin Ehlis01103de2017-02-16 13:22:47 -070023014 return;
23015 }
23016
23017 m_errorMonitor->ExpectSuccess();
Tobin Ehlis01103de2017-02-16 13:22:47 -070023018 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
23019
23020 // A renderpass with one depth/stencil attachment.
23021 VkAttachmentDescription attachment = {0,
Tony Barbourf887b162017-03-09 10:06:46 -070023022 depth_format,
Tobin Ehlis01103de2017-02-16 13:22:47 -070023023 VK_SAMPLE_COUNT_1_BIT,
23024 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
23025 VK_ATTACHMENT_STORE_OP_DONT_CARE,
23026 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
23027 VK_ATTACHMENT_STORE_OP_DONT_CARE,
23028 VK_IMAGE_LAYOUT_UNDEFINED,
23029 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
23030
23031 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
23032
23033 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, &att_ref, 0, nullptr};
23034
23035 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
23036
23037 VkRenderPass rp;
23038 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
23039 ASSERT_VK_SUCCESS(err);
23040 // A compatible ds image.
23041 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060023042 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 -070023043 ASSERT_TRUE(image.initialized());
23044
23045 VkImageViewCreateInfo ivci = {
23046 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
23047 nullptr,
23048 0,
23049 image.handle(),
23050 VK_IMAGE_VIEW_TYPE_2D,
Tony Barbourf887b162017-03-09 10:06:46 -070023051 depth_format,
Tobin Ehlis01103de2017-02-16 13:22:47 -070023052 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
23053 VK_COMPONENT_SWIZZLE_IDENTITY},
23054 {VK_IMAGE_ASPECT_DEPTH_BIT, 0, 1, 0, 1},
23055 };
23056 VkImageView view;
23057 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
23058 ASSERT_VK_SUCCESS(err);
23059
23060 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
23061 VkFramebuffer fb;
23062 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
23063 ASSERT_VK_SUCCESS(err);
23064
23065 VkRenderPassBeginInfo rpbi = {VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb, {{0, 0}, {32, 32}}, 0, nullptr};
23066 m_commandBuffer->BeginCommandBuffer();
23067 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
23068 vkCmdEndRenderPass(m_commandBuffer->handle());
23069 m_commandBuffer->EndCommandBuffer();
23070 QueueCommandBuffer(false);
23071 m_errorMonitor->VerifyNotFound();
23072
23073 // Cleanup
23074 vkDestroyImageView(m_device->device(), view, NULL);
23075 vkDestroyRenderPass(m_device->device(), rp, NULL);
23076 vkDestroyFramebuffer(m_device->device(), fb, NULL);
23077}
23078
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023079TEST_F(VkPositiveLayerTest, CreatePipelineAttribMatrixType) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023080 TEST_DESCRIPTION(
23081 "Test that pipeline validation accepts matrices passed "
23082 "as vertex attributes");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023083 m_errorMonitor->ExpectSuccess();
23084
Tony Barbour1fa09702017-03-16 12:09:08 -060023085 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023086 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
23087
23088 VkVertexInputBindingDescription input_binding;
23089 memset(&input_binding, 0, sizeof(input_binding));
23090
23091 VkVertexInputAttributeDescription input_attribs[2];
23092 memset(input_attribs, 0, sizeof(input_attribs));
23093
23094 for (int i = 0; i < 2; i++) {
23095 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
23096 input_attribs[i].location = i;
23097 }
23098
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023099 char const *vsSource =
23100 "#version 450\n"
23101 "\n"
23102 "layout(location=0) in mat2x4 x;\n"
23103 "out gl_PerVertex {\n"
23104 " vec4 gl_Position;\n"
23105 "};\n"
23106 "void main(){\n"
23107 " gl_Position = x[0] + x[1];\n"
23108 "}\n";
23109 char const *fsSource =
23110 "#version 450\n"
23111 "\n"
23112 "layout(location=0) out vec4 color;\n"
23113 "void main(){\n"
23114 " color = vec4(1);\n"
23115 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023116
23117 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
23118 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
23119
23120 VkPipelineObj pipe(m_device);
23121 pipe.AddColorAttachment();
23122 pipe.AddShader(&vs);
23123 pipe.AddShader(&fs);
23124
23125 pipe.AddVertexInputBindings(&input_binding, 1);
23126 pipe.AddVertexInputAttribs(input_attribs, 2);
23127
23128 VkDescriptorSetObj descriptorSet(m_device);
23129 descriptorSet.AppendDummy();
23130 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
23131
23132 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
23133
23134 /* expect success */
23135 m_errorMonitor->VerifyNotFound();
23136}
23137
23138TEST_F(VkPositiveLayerTest, CreatePipelineAttribArrayType) {
23139 m_errorMonitor->ExpectSuccess();
23140
Tony Barbour1fa09702017-03-16 12:09:08 -060023141 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023142 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
23143
23144 VkVertexInputBindingDescription input_binding;
23145 memset(&input_binding, 0, sizeof(input_binding));
23146
23147 VkVertexInputAttributeDescription input_attribs[2];
23148 memset(input_attribs, 0, sizeof(input_attribs));
23149
23150 for (int i = 0; i < 2; i++) {
23151 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
23152 input_attribs[i].location = i;
23153 }
23154
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023155 char const *vsSource =
23156 "#version 450\n"
23157 "\n"
23158 "layout(location=0) in vec4 x[2];\n"
23159 "out gl_PerVertex {\n"
23160 " vec4 gl_Position;\n"
23161 "};\n"
23162 "void main(){\n"
23163 " gl_Position = x[0] + x[1];\n"
23164 "}\n";
23165 char const *fsSource =
23166 "#version 450\n"
23167 "\n"
23168 "layout(location=0) out vec4 color;\n"
23169 "void main(){\n"
23170 " color = vec4(1);\n"
23171 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023172
23173 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
23174 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
23175
23176 VkPipelineObj pipe(m_device);
23177 pipe.AddColorAttachment();
23178 pipe.AddShader(&vs);
23179 pipe.AddShader(&fs);
23180
23181 pipe.AddVertexInputBindings(&input_binding, 1);
23182 pipe.AddVertexInputAttribs(input_attribs, 2);
23183
23184 VkDescriptorSetObj descriptorSet(m_device);
23185 descriptorSet.AppendDummy();
23186 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
23187
23188 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
23189
23190 m_errorMonitor->VerifyNotFound();
23191}
23192
23193TEST_F(VkPositiveLayerTest, CreatePipelineAttribComponents) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023194 TEST_DESCRIPTION(
23195 "Test that pipeline validation accepts consuming a vertex attribute "
23196 "through multiple vertex shader inputs, each consuming a different "
23197 "subset of the components.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023198 m_errorMonitor->ExpectSuccess();
23199
Tony Barbour1fa09702017-03-16 12:09:08 -060023200 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023201 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
23202
23203 VkVertexInputBindingDescription input_binding;
23204 memset(&input_binding, 0, sizeof(input_binding));
23205
23206 VkVertexInputAttributeDescription input_attribs[3];
23207 memset(input_attribs, 0, sizeof(input_attribs));
23208
23209 for (int i = 0; i < 3; i++) {
23210 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
23211 input_attribs[i].location = i;
23212 }
23213
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023214 char const *vsSource =
23215 "#version 450\n"
23216 "\n"
23217 "layout(location=0) in vec4 x;\n"
23218 "layout(location=1) in vec3 y1;\n"
23219 "layout(location=1, component=3) in float y2;\n"
23220 "layout(location=2) in vec4 z;\n"
23221 "out gl_PerVertex {\n"
23222 " vec4 gl_Position;\n"
23223 "};\n"
23224 "void main(){\n"
23225 " gl_Position = x + vec4(y1, y2) + z;\n"
23226 "}\n";
23227 char const *fsSource =
23228 "#version 450\n"
23229 "\n"
23230 "layout(location=0) out vec4 color;\n"
23231 "void main(){\n"
23232 " color = vec4(1);\n"
23233 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023234
23235 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
23236 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
23237
23238 VkPipelineObj pipe(m_device);
23239 pipe.AddColorAttachment();
23240 pipe.AddShader(&vs);
23241 pipe.AddShader(&fs);
23242
23243 pipe.AddVertexInputBindings(&input_binding, 1);
23244 pipe.AddVertexInputAttribs(input_attribs, 3);
23245
23246 VkDescriptorSetObj descriptorSet(m_device);
23247 descriptorSet.AppendDummy();
23248 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
23249
23250 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
23251
23252 m_errorMonitor->VerifyNotFound();
23253}
23254
23255TEST_F(VkPositiveLayerTest, CreatePipelineSimplePositive) {
23256 m_errorMonitor->ExpectSuccess();
23257
Tony Barbour1fa09702017-03-16 12:09:08 -060023258 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023259 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
23260
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023261 char const *vsSource =
23262 "#version 450\n"
23263 "out gl_PerVertex {\n"
23264 " vec4 gl_Position;\n"
23265 "};\n"
23266 "void main(){\n"
23267 " gl_Position = vec4(0);\n"
23268 "}\n";
23269 char const *fsSource =
23270 "#version 450\n"
23271 "\n"
23272 "layout(location=0) out vec4 color;\n"
23273 "void main(){\n"
23274 " color = vec4(1);\n"
23275 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023276
23277 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
23278 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
23279
23280 VkPipelineObj pipe(m_device);
23281 pipe.AddColorAttachment();
23282 pipe.AddShader(&vs);
23283 pipe.AddShader(&fs);
23284
23285 VkDescriptorSetObj descriptorSet(m_device);
23286 descriptorSet.AppendDummy();
23287 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
23288
23289 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
23290
23291 m_errorMonitor->VerifyNotFound();
23292}
23293
23294TEST_F(VkPositiveLayerTest, CreatePipelineRelaxedTypeMatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023295 TEST_DESCRIPTION(
23296 "Test that pipeline validation accepts the relaxed type matching rules "
23297 "set out in 14.1.3: fundamental type must match, and producer side must "
23298 "have at least as many components");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023299 m_errorMonitor->ExpectSuccess();
23300
23301 // VK 1.0.8 Specification, 14.1.3 "Additionally,..." block
23302
Tony Barbour1fa09702017-03-16 12:09:08 -060023303 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023304 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
23305
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023306 char const *vsSource =
23307 "#version 450\n"
23308 "out gl_PerVertex {\n"
23309 " vec4 gl_Position;\n"
23310 "};\n"
23311 "layout(location=0) out vec3 x;\n"
23312 "layout(location=1) out ivec3 y;\n"
23313 "layout(location=2) out vec3 z;\n"
23314 "void main(){\n"
23315 " gl_Position = vec4(0);\n"
23316 " x = vec3(0); y = ivec3(0); z = vec3(0);\n"
23317 "}\n";
23318 char const *fsSource =
23319 "#version 450\n"
23320 "\n"
23321 "layout(location=0) out vec4 color;\n"
23322 "layout(location=0) in float x;\n"
23323 "layout(location=1) flat in int y;\n"
23324 "layout(location=2) in vec2 z;\n"
23325 "void main(){\n"
23326 " color = vec4(1 + x + y + z.x);\n"
23327 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023328
23329 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
23330 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
23331
23332 VkPipelineObj pipe(m_device);
23333 pipe.AddColorAttachment();
23334 pipe.AddShader(&vs);
23335 pipe.AddShader(&fs);
23336
23337 VkDescriptorSetObj descriptorSet(m_device);
23338 descriptorSet.AppendDummy();
23339 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
23340
23341 VkResult err = VK_SUCCESS;
23342 err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
23343 ASSERT_VK_SUCCESS(err);
23344
23345 m_errorMonitor->VerifyNotFound();
23346}
23347
23348TEST_F(VkPositiveLayerTest, CreatePipelineTessPerVertex) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023349 TEST_DESCRIPTION(
23350 "Test that pipeline validation accepts per-vertex variables "
23351 "passed between the TCS and TES stages");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023352 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
23357 if (!m_device->phy().features().tessellationShader) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070023358 printf(" Device does not support tessellation shaders; skipped.\n");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023359 return;
23360 }
23361
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023362 char const *vsSource =
23363 "#version 450\n"
23364 "void main(){}\n";
23365 char const *tcsSource =
23366 "#version 450\n"
23367 "layout(location=0) out int x[];\n"
23368 "layout(vertices=3) out;\n"
23369 "void main(){\n"
23370 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
23371 " gl_TessLevelInner[0] = 1;\n"
23372 " x[gl_InvocationID] = gl_InvocationID;\n"
23373 "}\n";
23374 char const *tesSource =
23375 "#version 450\n"
23376 "layout(triangles, equal_spacing, cw) in;\n"
23377 "layout(location=0) in int x[];\n"
23378 "out gl_PerVertex { vec4 gl_Position; };\n"
23379 "void main(){\n"
23380 " gl_Position.xyz = gl_TessCoord;\n"
23381 " gl_Position.w = x[0] + x[1] + x[2];\n"
23382 "}\n";
23383 char const *fsSource =
23384 "#version 450\n"
23385 "layout(location=0) out vec4 color;\n"
23386 "void main(){\n"
23387 " color = vec4(1);\n"
23388 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023389
23390 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
23391 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
23392 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
23393 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
23394
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023395 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
23396 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023397
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023398 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023399
23400 VkPipelineObj pipe(m_device);
23401 pipe.SetInputAssembly(&iasci);
23402 pipe.SetTessellation(&tsci);
23403 pipe.AddColorAttachment();
23404 pipe.AddShader(&vs);
23405 pipe.AddShader(&tcs);
23406 pipe.AddShader(&tes);
23407 pipe.AddShader(&fs);
23408
23409 VkDescriptorSetObj descriptorSet(m_device);
23410 descriptorSet.AppendDummy();
23411 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
23412
23413 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
23414
23415 m_errorMonitor->VerifyNotFound();
23416}
23417
23418TEST_F(VkPositiveLayerTest, CreatePipelineGeometryInputBlockPositive) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023419 TEST_DESCRIPTION(
23420 "Test that pipeline validation accepts a user-defined "
23421 "interface block passed into the geometry shader. This "
23422 "is interesting because the 'extra' array level is not "
23423 "present on the member type, but on the block instance.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023424 m_errorMonitor->ExpectSuccess();
23425
Tony Barbour1fa09702017-03-16 12:09:08 -060023426 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023427 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
23428
23429 if (!m_device->phy().features().geometryShader) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070023430 printf(" Device does not support geometry shaders; skipped.\n");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023431 return;
23432 }
23433
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023434 char const *vsSource =
23435 "#version 450\n"
23436 "layout(location=0) out VertexData { vec4 x; } vs_out;\n"
23437 "void main(){\n"
23438 " vs_out.x = vec4(1);\n"
23439 "}\n";
23440 char const *gsSource =
23441 "#version 450\n"
23442 "layout(triangles) in;\n"
23443 "layout(triangle_strip, max_vertices=3) out;\n"
23444 "layout(location=0) in VertexData { vec4 x; } gs_in[];\n"
23445 "out gl_PerVertex { vec4 gl_Position; };\n"
23446 "void main() {\n"
23447 " gl_Position = gs_in[0].x;\n"
23448 " EmitVertex();\n"
23449 "}\n";
23450 char const *fsSource =
23451 "#version 450\n"
23452 "layout(location=0) out vec4 color;\n"
23453 "void main(){\n"
23454 " color = vec4(1);\n"
23455 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023456
23457 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
23458 VkShaderObj gs(m_device, gsSource, VK_SHADER_STAGE_GEOMETRY_BIT, this);
23459 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
23460
23461 VkPipelineObj pipe(m_device);
23462 pipe.AddColorAttachment();
23463 pipe.AddShader(&vs);
23464 pipe.AddShader(&gs);
23465 pipe.AddShader(&fs);
23466
23467 VkDescriptorSetObj descriptorSet(m_device);
23468 descriptorSet.AppendDummy();
23469 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
23470
23471 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
23472
23473 m_errorMonitor->VerifyNotFound();
23474}
23475
23476TEST_F(VkPositiveLayerTest, CreatePipeline64BitAttributesPositive) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023477 TEST_DESCRIPTION(
23478 "Test that pipeline validation accepts basic use of 64bit vertex "
23479 "attributes. This is interesting because they consume multiple "
23480 "locations.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023481 m_errorMonitor->ExpectSuccess();
23482
Tony Barbour1fa09702017-03-16 12:09:08 -060023483 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023484 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
23485
23486 if (!m_device->phy().features().shaderFloat64) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070023487 printf(" Device does not support 64bit vertex attributes; skipped.\n");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023488 return;
23489 }
23490
23491 VkVertexInputBindingDescription input_bindings[1];
23492 memset(input_bindings, 0, sizeof(input_bindings));
23493
23494 VkVertexInputAttributeDescription input_attribs[4];
23495 memset(input_attribs, 0, sizeof(input_attribs));
23496 input_attribs[0].location = 0;
23497 input_attribs[0].offset = 0;
23498 input_attribs[0].format = VK_FORMAT_R64G64B64A64_SFLOAT;
23499 input_attribs[1].location = 2;
23500 input_attribs[1].offset = 32;
23501 input_attribs[1].format = VK_FORMAT_R64G64B64A64_SFLOAT;
23502 input_attribs[2].location = 4;
23503 input_attribs[2].offset = 64;
23504 input_attribs[2].format = VK_FORMAT_R64G64B64A64_SFLOAT;
23505 input_attribs[3].location = 6;
23506 input_attribs[3].offset = 96;
23507 input_attribs[3].format = VK_FORMAT_R64G64B64A64_SFLOAT;
23508
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023509 char const *vsSource =
23510 "#version 450\n"
23511 "\n"
23512 "layout(location=0) in dmat4 x;\n"
23513 "out gl_PerVertex {\n"
23514 " vec4 gl_Position;\n"
23515 "};\n"
23516 "void main(){\n"
23517 " gl_Position = vec4(x[0][0]);\n"
23518 "}\n";
23519 char const *fsSource =
23520 "#version 450\n"
23521 "\n"
23522 "layout(location=0) out vec4 color;\n"
23523 "void main(){\n"
23524 " color = vec4(1);\n"
23525 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023526
23527 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
23528 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
23529
23530 VkPipelineObj pipe(m_device);
23531 pipe.AddColorAttachment();
23532 pipe.AddShader(&vs);
23533 pipe.AddShader(&fs);
23534
23535 pipe.AddVertexInputBindings(input_bindings, 1);
23536 pipe.AddVertexInputAttribs(input_attribs, 4);
23537
23538 VkDescriptorSetObj descriptorSet(m_device);
23539 descriptorSet.AppendDummy();
23540 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
23541
23542 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
23543
23544 m_errorMonitor->VerifyNotFound();
23545}
23546
23547TEST_F(VkPositiveLayerTest, CreatePipelineInputAttachmentPositive) {
23548 TEST_DESCRIPTION("Positive test for a correctly matched input attachment");
23549 m_errorMonitor->ExpectSuccess();
23550
Tony Barbour1fa09702017-03-16 12:09:08 -060023551 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023552
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023553 char const *vsSource =
23554 "#version 450\n"
23555 "\n"
23556 "out gl_PerVertex {\n"
23557 " vec4 gl_Position;\n"
23558 "};\n"
23559 "void main(){\n"
23560 " gl_Position = vec4(1);\n"
23561 "}\n";
23562 char const *fsSource =
23563 "#version 450\n"
23564 "\n"
23565 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
23566 "layout(location=0) out vec4 color;\n"
23567 "void main() {\n"
23568 " color = subpassLoad(x);\n"
23569 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023570
23571 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
23572 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
23573
23574 VkPipelineObj pipe(m_device);
23575 pipe.AddShader(&vs);
23576 pipe.AddShader(&fs);
23577 pipe.AddColorAttachment();
23578 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
23579
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023580 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
23581 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023582 VkDescriptorSetLayout dsl;
23583 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
23584 ASSERT_VK_SUCCESS(err);
23585
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023586 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023587 VkPipelineLayout pl;
23588 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
23589 ASSERT_VK_SUCCESS(err);
23590
23591 VkAttachmentDescription descs[2] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023592 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
23593 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
23594 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
23595 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
23596 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 -060023597 };
23598 VkAttachmentReference color = {
23599 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
23600 };
23601 VkAttachmentReference input = {
23602 1, VK_IMAGE_LAYOUT_GENERAL,
23603 };
23604
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023605 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023606
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023607 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023608 VkRenderPass rp;
23609 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
23610 ASSERT_VK_SUCCESS(err);
23611
23612 // should be OK. would go wrong here if it's going to...
23613 pipe.CreateVKPipeline(pl, rp);
23614
23615 m_errorMonitor->VerifyNotFound();
23616
23617 vkDestroyRenderPass(m_device->device(), rp, nullptr);
23618 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
23619 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
23620}
23621
23622TEST_F(VkPositiveLayerTest, CreateComputePipelineMissingDescriptorUnusedPositive) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023623 TEST_DESCRIPTION(
23624 "Test that pipeline validation accepts a compute pipeline which declares a "
23625 "descriptor-backed resource which is not provided, but the shader does not "
23626 "statically use it. This is interesting because it requires compute pipelines "
23627 "to have a proper descriptor use walk, which they didn't for some time.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023628 m_errorMonitor->ExpectSuccess();
23629
Tony Barbour1fa09702017-03-16 12:09:08 -060023630 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023631
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023632 char const *csSource =
23633 "#version 450\n"
23634 "\n"
23635 "layout(local_size_x=1) in;\n"
23636 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
23637 "void main(){\n"
23638 " // x is not used.\n"
23639 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023640
23641 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
23642
23643 VkDescriptorSetObj descriptorSet(m_device);
23644 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
23645
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023646 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
23647 nullptr,
23648 0,
23649 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
23650 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
23651 descriptorSet.GetPipelineLayout(),
23652 VK_NULL_HANDLE,
23653 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023654
23655 VkPipeline pipe;
23656 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
23657
23658 m_errorMonitor->VerifyNotFound();
23659
23660 if (err == VK_SUCCESS) {
23661 vkDestroyPipeline(m_device->device(), pipe, nullptr);
23662 }
23663}
23664
23665TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsSampler) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023666 TEST_DESCRIPTION(
23667 "Test that pipeline validation accepts a shader consuming only the "
23668 "sampler portion of a combined image + sampler");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023669 m_errorMonitor->ExpectSuccess();
23670
Tony Barbour1fa09702017-03-16 12:09:08 -060023671 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023672
23673 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023674 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
23675 {1, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
23676 {2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023677 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023678 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023679 VkDescriptorSetLayout dsl;
23680 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
23681 ASSERT_VK_SUCCESS(err);
23682
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023683 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023684 VkPipelineLayout pl;
23685 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
23686 ASSERT_VK_SUCCESS(err);
23687
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023688 char const *csSource =
23689 "#version 450\n"
23690 "\n"
23691 "layout(local_size_x=1) in;\n"
23692 "layout(set=0, binding=0) uniform sampler s;\n"
23693 "layout(set=0, binding=1) uniform texture2D t;\n"
23694 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
23695 "void main() {\n"
23696 " x = texture(sampler2D(t, s), vec2(0));\n"
23697 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023698 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
23699
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023700 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
23701 nullptr,
23702 0,
23703 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
23704 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
23705 pl,
23706 VK_NULL_HANDLE,
23707 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023708
23709 VkPipeline pipe;
23710 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
23711
23712 m_errorMonitor->VerifyNotFound();
23713
23714 if (err == VK_SUCCESS) {
23715 vkDestroyPipeline(m_device->device(), pipe, nullptr);
23716 }
23717
23718 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
23719 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
23720}
23721
23722TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsImage) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023723 TEST_DESCRIPTION(
23724 "Test that pipeline validation accepts a shader consuming only the "
23725 "image portion of a combined image + sampler");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023726 m_errorMonitor->ExpectSuccess();
23727
Tony Barbour1fa09702017-03-16 12:09:08 -060023728 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023729
23730 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023731 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
23732 {1, VK_DESCRIPTOR_TYPE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
23733 {2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023734 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023735 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023736 VkDescriptorSetLayout dsl;
23737 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
23738 ASSERT_VK_SUCCESS(err);
23739
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023740 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023741 VkPipelineLayout pl;
23742 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
23743 ASSERT_VK_SUCCESS(err);
23744
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023745 char const *csSource =
23746 "#version 450\n"
23747 "\n"
23748 "layout(local_size_x=1) in;\n"
23749 "layout(set=0, binding=0) uniform texture2D t;\n"
23750 "layout(set=0, binding=1) uniform sampler s;\n"
23751 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
23752 "void main() {\n"
23753 " x = texture(sampler2D(t, s), vec2(0));\n"
23754 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023755 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
23756
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023757 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
23758 nullptr,
23759 0,
23760 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
23761 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
23762 pl,
23763 VK_NULL_HANDLE,
23764 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023765
23766 VkPipeline pipe;
23767 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
23768
23769 m_errorMonitor->VerifyNotFound();
23770
23771 if (err == VK_SUCCESS) {
23772 vkDestroyPipeline(m_device->device(), pipe, nullptr);
23773 }
23774
23775 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
23776 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
23777}
23778
23779TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsBoth) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023780 TEST_DESCRIPTION(
23781 "Test that pipeline validation accepts a shader consuming "
23782 "both the sampler and the image of a combined image+sampler "
23783 "but via separate variables");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023784 m_errorMonitor->ExpectSuccess();
23785
Tony Barbour1fa09702017-03-16 12:09:08 -060023786 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023787
23788 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023789 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
23790 {1, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023791 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023792 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 2, bindings};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023793 VkDescriptorSetLayout dsl;
23794 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
23795 ASSERT_VK_SUCCESS(err);
23796
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023797 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023798 VkPipelineLayout pl;
23799 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
23800 ASSERT_VK_SUCCESS(err);
23801
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023802 char const *csSource =
23803 "#version 450\n"
23804 "\n"
23805 "layout(local_size_x=1) in;\n"
23806 "layout(set=0, binding=0) uniform texture2D t;\n"
23807 "layout(set=0, binding=0) uniform sampler s; // both binding 0!\n"
23808 "layout(set=0, binding=1) buffer block { vec4 x; };\n"
23809 "void main() {\n"
23810 " x = texture(sampler2D(t, s), vec2(0));\n"
23811 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023812 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
23813
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023814 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
23815 nullptr,
23816 0,
23817 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
23818 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
23819 pl,
23820 VK_NULL_HANDLE,
23821 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023822
23823 VkPipeline pipe;
23824 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
23825
23826 m_errorMonitor->VerifyNotFound();
23827
23828 if (err == VK_SUCCESS) {
23829 vkDestroyPipeline(m_device->device(), pipe, nullptr);
23830 }
23831
23832 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
23833 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
23834}
23835
Tony Barbour3ed87a02017-03-15 16:19:02 -060023836TEST_F(VkPositiveLayerTest, Maintenance1Tests) {
Mark Lobodzinskidf784fc2017-03-14 09:18:40 -060023837 TEST_DESCRIPTION("Validate various special cases for the Maintenance1_KHR extension");
23838
Tony Barbour3ed87a02017-03-15 16:19:02 -060023839 device_extension_names.push_back(VK_KHR_MAINTENANCE1_EXTENSION_NAME);
Tony Barbour73c0f352017-03-16 15:55:38 -060023840 InitFramework(instance_layer_names, instance_extension_names, device_extension_names, myDbgFunc, m_errorMonitor);
Tony Barbour3ed87a02017-03-15 16:19:02 -060023841
Mark Lobodzinskidf784fc2017-03-14 09:18:40 -060023842 // Ensure that extension is available and enabled.
23843 uint32_t extension_count = 0;
23844 bool supports_maintenance1_extension = false;
23845 VkResult err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, nullptr);
23846 ASSERT_VK_SUCCESS(err);
23847 if (extension_count > 0) {
23848 std::vector<VkExtensionProperties> available_extensions(extension_count);
23849
23850 err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, &available_extensions[0]);
23851 ASSERT_VK_SUCCESS(err);
23852 for (const auto &extension_props : available_extensions) {
23853 if (strcmp(extension_props.extensionName, VK_KHR_MAINTENANCE1_EXTENSION_NAME) == 0) {
23854 supports_maintenance1_extension = true;
23855 }
23856 }
23857 }
23858
23859 // Proceed if extension is supported by hardware
23860 if (!supports_maintenance1_extension) {
23861 printf(" Maintenance1 Extension not supported, skipping tests\n");
23862 return;
23863 }
Mark Lobodzinskidf784fc2017-03-14 09:18:40 -060023864
23865 m_errorMonitor->ExpectSuccess();
Dave Houlton8e0fe7a2017-03-30 10:32:10 -060023866 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskidf784fc2017-03-14 09:18:40 -060023867 VkCommandBuffer cmd_buf;
23868 VkCommandBufferAllocateInfo alloc_info;
23869 alloc_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
23870 alloc_info.pNext = NULL;
23871 alloc_info.commandBufferCount = 1;
Mike Schuchardt06304c22017-03-01 17:09:09 -070023872 alloc_info.commandPool = m_commandPool->handle();
Mark Lobodzinskidf784fc2017-03-14 09:18:40 -060023873 alloc_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
23874 vkAllocateCommandBuffers(m_device->device(), &alloc_info, &cmd_buf);
23875
23876 VkCommandBufferBeginInfo cb_binfo;
23877 cb_binfo.pNext = NULL;
23878 cb_binfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
23879 cb_binfo.pInheritanceInfo = VK_NULL_HANDLE;
23880 cb_binfo.flags = 0;
23881 vkBeginCommandBuffer(cmd_buf, &cb_binfo);
23882 // Set Negative height, should give error if Maintenance 1 is not enabled
23883 VkViewport viewport = {0, 0, 16, -16, 0, 1};
23884 vkCmdSetViewport(cmd_buf, 0, 1, &viewport);
23885 vkEndCommandBuffer(cmd_buf);
23886
23887 m_errorMonitor->VerifyNotFound();
23888}
23889
Mark Lobodzinski35ecad32017-03-27 13:09:07 -060023890TEST_F(VkLayerTest, DuplicateValidPNextStructures) {
23891 TEST_DESCRIPTION("Create a pNext chain containing valid strutures, but with a duplicate structure type");
23892
23893 ASSERT_NO_FATAL_FAILURE(Init());
23894
23895 uint32_t extension_count = 0;
23896 VkResult err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, nullptr);
23897 ASSERT_VK_SUCCESS(err);
23898
23899 if (extension_count > 0) {
23900 std::vector<VkExtensionProperties> available_extensions(extension_count);
23901 err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, &available_extensions[0]);
23902 ASSERT_VK_SUCCESS(err);
23903
23904 for (const auto &extension_props : available_extensions) {
23905 if (strcmp(extension_props.extensionName, VK_NV_DEDICATED_ALLOCATION_EXTENSION_NAME) == 0) {
23906 // Create two pNext structures which by themselves would be valid
23907 VkDedicatedAllocationBufferCreateInfoNV dedicated_buffer_create_info = {};
23908 VkDedicatedAllocationBufferCreateInfoNV dedicated_buffer_create_info_2 = {};
23909 dedicated_buffer_create_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_BUFFER_CREATE_INFO_NV;
23910 dedicated_buffer_create_info.pNext = &dedicated_buffer_create_info_2;
23911 dedicated_buffer_create_info.dedicatedAllocation = VK_TRUE;
23912
23913 dedicated_buffer_create_info_2.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_BUFFER_CREATE_INFO_NV;
23914 dedicated_buffer_create_info_2.pNext = nullptr;
23915 dedicated_buffer_create_info_2.dedicatedAllocation = VK_TRUE;
23916
23917 uint32_t queue_family_index = 0;
23918 VkBufferCreateInfo buffer_create_info = {};
23919 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
23920 buffer_create_info.pNext = &dedicated_buffer_create_info;
23921 buffer_create_info.size = 1024;
23922 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
23923 buffer_create_info.queueFamilyIndexCount = 1;
23924 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
23925
23926 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "chain contains duplicate structure types");
23927 VkBuffer buffer;
23928 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
23929 m_errorMonitor->VerifyFound();
23930 }
23931 }
23932 }
23933}
23934
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023935TEST_F(VkPositiveLayerTest, ValidStructPNext) {
23936 TEST_DESCRIPTION("Verify that a valid pNext value is handled correctly");
23937
Tony Barbour1fa09702017-03-16 12:09:08 -060023938 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023939
23940 // Positive test to check parameter_validation and unique_objects support
23941 // for NV_dedicated_allocation
23942 uint32_t extension_count = 0;
23943 bool supports_nv_dedicated_allocation = false;
23944 VkResult err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, nullptr);
23945 ASSERT_VK_SUCCESS(err);
23946
23947 if (extension_count > 0) {
23948 std::vector<VkExtensionProperties> available_extensions(extension_count);
23949
23950 err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, &available_extensions[0]);
23951 ASSERT_VK_SUCCESS(err);
23952
23953 for (const auto &extension_props : available_extensions) {
23954 if (strcmp(extension_props.extensionName, VK_NV_DEDICATED_ALLOCATION_EXTENSION_NAME) == 0) {
23955 supports_nv_dedicated_allocation = true;
23956 }
23957 }
23958 }
23959
23960 if (supports_nv_dedicated_allocation) {
23961 m_errorMonitor->ExpectSuccess();
23962
23963 VkDedicatedAllocationBufferCreateInfoNV dedicated_buffer_create_info = {};
23964 dedicated_buffer_create_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_BUFFER_CREATE_INFO_NV;
23965 dedicated_buffer_create_info.pNext = nullptr;
23966 dedicated_buffer_create_info.dedicatedAllocation = VK_TRUE;
23967
23968 uint32_t queue_family_index = 0;
23969 VkBufferCreateInfo buffer_create_info = {};
23970 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
23971 buffer_create_info.pNext = &dedicated_buffer_create_info;
23972 buffer_create_info.size = 1024;
23973 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
23974 buffer_create_info.queueFamilyIndexCount = 1;
23975 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
23976
23977 VkBuffer buffer;
Karl Schultz47dd59d2017-01-20 13:19:20 -070023978 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023979 ASSERT_VK_SUCCESS(err);
23980
23981 VkMemoryRequirements memory_reqs;
23982 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
23983
23984 VkDedicatedAllocationMemoryAllocateInfoNV dedicated_memory_info = {};
23985 dedicated_memory_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_MEMORY_ALLOCATE_INFO_NV;
23986 dedicated_memory_info.pNext = nullptr;
23987 dedicated_memory_info.buffer = buffer;
23988 dedicated_memory_info.image = VK_NULL_HANDLE;
23989
23990 VkMemoryAllocateInfo memory_info = {};
23991 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
23992 memory_info.pNext = &dedicated_memory_info;
23993 memory_info.allocationSize = memory_reqs.size;
23994
23995 bool pass;
23996 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
23997 ASSERT_TRUE(pass);
23998
23999 VkDeviceMemory buffer_memory;
24000 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
24001 ASSERT_VK_SUCCESS(err);
24002
24003 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
24004 ASSERT_VK_SUCCESS(err);
24005
24006 vkDestroyBuffer(m_device->device(), buffer, NULL);
24007 vkFreeMemory(m_device->device(), buffer_memory, NULL);
24008
24009 m_errorMonitor->VerifyNotFound();
24010 }
24011}
24012
24013TEST_F(VkPositiveLayerTest, PSOPolygonModeValid) {
24014 VkResult err;
24015
24016 TEST_DESCRIPTION("Verify that using a solid polygon fill mode works correctly.");
24017
Tony Barbour1fa09702017-03-16 12:09:08 -060024018 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024019 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
24020
24021 std::vector<const char *> device_extension_names;
24022 auto features = m_device->phy().features();
24023 // Artificially disable support for non-solid fill modes
24024 features.fillModeNonSolid = false;
24025 // The sacrificial device object
24026 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
24027
24028 VkRenderpassObj render_pass(&test_device);
24029
24030 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
24031 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
24032 pipeline_layout_ci.setLayoutCount = 0;
24033 pipeline_layout_ci.pSetLayouts = NULL;
24034
24035 VkPipelineLayout pipeline_layout;
24036 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
24037 ASSERT_VK_SUCCESS(err);
24038
24039 VkPipelineRasterizationStateCreateInfo rs_ci = {};
24040 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
24041 rs_ci.pNext = nullptr;
24042 rs_ci.lineWidth = 1.0f;
24043 rs_ci.rasterizerDiscardEnable = true;
24044
24045 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
24046 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
24047
24048 // Set polygonMode=FILL. No error is expected
24049 m_errorMonitor->ExpectSuccess();
24050 {
24051 VkPipelineObj pipe(&test_device);
24052 pipe.AddShader(&vs);
24053 pipe.AddShader(&fs);
24054 pipe.AddColorAttachment();
24055 // Set polygonMode to a good value
24056 rs_ci.polygonMode = VK_POLYGON_MODE_FILL;
24057 pipe.SetRasterization(&rs_ci);
24058 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
24059 }
24060 m_errorMonitor->VerifyNotFound();
24061
24062 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
24063}
24064
Dave Houlton1150cf52017-04-27 14:38:11 -060024065TEST_F(VkPositiveLayerTest, LongSemaphoreChain) {
Chris Forbes94196952017-04-06 16:30:59 -070024066 m_errorMonitor->ExpectSuccess();
24067
24068 ASSERT_NO_FATAL_FAILURE(Init());
24069 VkResult err;
24070
24071 std::vector<VkSemaphore> semaphores;
24072
24073 const int chainLength = 32768;
24074 VkPipelineStageFlags flags = VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT;
24075
24076 for (int i = 0; i < chainLength; i++) {
Dave Houlton1150cf52017-04-27 14:38:11 -060024077 VkSemaphoreCreateInfo sci = {VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0};
Chris Forbes94196952017-04-06 16:30:59 -070024078 VkSemaphore semaphore;
24079 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &semaphore);
24080 ASSERT_VK_SUCCESS(err);
24081
24082 semaphores.push_back(semaphore);
24083
Chris Forbesfc50aaa2017-05-01 10:20:17 -070024084 VkSubmitInfo si = {VK_STRUCTURE_TYPE_SUBMIT_INFO,
24085 nullptr,
24086 semaphores.size() > 1 ? 1u : 0u,
24087 semaphores.size() > 1 ? &semaphores[semaphores.size() - 2] : nullptr,
24088 &flags,
24089 0,
24090 nullptr,
24091 1,
24092 &semaphores[semaphores.size() - 1]};
Chris Forbes94196952017-04-06 16:30:59 -070024093 err = vkQueueSubmit(m_device->m_queue, 1, &si, VK_NULL_HANDLE);
24094 ASSERT_VK_SUCCESS(err);
24095 }
24096
Dave Houlton1150cf52017-04-27 14:38:11 -060024097 VkFenceCreateInfo fci = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0};
Chris Forbes94196952017-04-06 16:30:59 -070024098 VkFence fence;
24099 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
24100 ASSERT_VK_SUCCESS(err);
Dave Houlton1150cf52017-04-27 14:38:11 -060024101 VkSubmitInfo si = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 1, &semaphores.back(), &flags, 0, nullptr, 0, nullptr};
Chris Forbes94196952017-04-06 16:30:59 -070024102 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
24103 ASSERT_VK_SUCCESS(err);
24104
24105 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
24106
Dave Houlton1150cf52017-04-27 14:38:11 -060024107 for (auto semaphore : semaphores) vkDestroySemaphore(m_device->device(), semaphore, nullptr);
Chris Forbes94196952017-04-06 16:30:59 -070024108
24109 vkDestroyFence(m_device->device(), fence, nullptr);
24110
24111 m_errorMonitor->VerifyNotFound();
24112}
24113
Mike Stroyanca855662017-05-02 11:06:27 -060024114extern "C" void *ReleaseNullFence(void *arg) {
24115 struct thread_data_struct *data = (struct thread_data_struct *)arg;
24116
24117 for (int i = 0; i < 40000; i++) {
24118 vkDestroyFence(data->device, VK_NULL_HANDLE, NULL);
24119 if (data->bailout) {
24120 break;
24121 }
24122 }
24123 return NULL;
24124}
24125
24126TEST_F(VkPositiveLayerTest, ThreadNullFenceCollision) {
24127 test_platform_thread thread;
24128
24129 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "THREADING ERROR");
24130
24131 ASSERT_NO_FATAL_FAILURE(Init());
24132
24133 struct thread_data_struct data;
24134 data.device = m_device->device();
24135 data.bailout = false;
24136 m_errorMonitor->SetBailout(&data.bailout);
24137
24138 // Call vkDestroyFence of VK_NULL_HANDLE repeatedly using multiple threads.
24139 // There should be no validation error from collision of that non-object.
24140 test_platform_thread_create(&thread, ReleaseNullFence, (void *)&data);
24141 for (int i = 0; i < 40000; i++) {
24142 vkDestroyFence(m_device->device(), VK_NULL_HANDLE, NULL);
24143 }
24144 test_platform_thread_join(thread, NULL);
24145
24146 m_errorMonitor->SetBailout(NULL);
24147
24148 m_errorMonitor->VerifyNotFound();
24149}
24150
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070024151#if 0 // A few devices have issues with this test so disabling for now
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024152TEST_F(VkPositiveLayerTest, LongFenceChain)
24153{
24154 m_errorMonitor->ExpectSuccess();
24155
Tony Barbour1fa09702017-03-16 12:09:08 -060024156 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024157 VkResult err;
24158
24159 std::vector<VkFence> fences;
24160
24161 const int chainLength = 32768;
24162
24163 for (int i = 0; i < chainLength; i++) {
24164 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
24165 VkFence fence;
24166 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
24167 ASSERT_VK_SUCCESS(err);
24168
24169 fences.push_back(fence);
24170
24171 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr,
24172 0, nullptr, 0, nullptr };
24173 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
24174 ASSERT_VK_SUCCESS(err);
24175
24176 }
24177
24178 // BOOM, stack overflow.
24179 vkWaitForFences(m_device->device(), 1, &fences.back(), VK_TRUE, UINT64_MAX);
24180
24181 for (auto fence : fences)
24182 vkDestroyFence(m_device->device(), fence, nullptr);
24183
24184 m_errorMonitor->VerifyNotFound();
24185}
24186#endif
24187
Cody Northrop1242dfd2016-07-13 17:24:59 -060024188#if defined(ANDROID) && defined(VALIDATION_APK)
Cody Northropb94529f2017-04-05 13:05:51 -060024189const char *appTag = "VulkanLayerValidationTests";
Cody Northrop1242dfd2016-07-13 17:24:59 -060024190static bool initialized = false;
24191static bool active = false;
24192
24193// Convert Intents to argv
24194// Ported from Hologram sample, only difference is flexible key
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024195std::vector<std::string> get_args(android_app &app, const char *intent_extra_data_key) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060024196 std::vector<std::string> args;
24197 JavaVM &vm = *app.activity->vm;
24198 JNIEnv *p_env;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070024199 if (vm.AttachCurrentThread(&p_env, nullptr) != JNI_OK) return args;
Cody Northrop1242dfd2016-07-13 17:24:59 -060024200
24201 JNIEnv &env = *p_env;
24202 jobject activity = app.activity->clazz;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024203 jmethodID get_intent_method = env.GetMethodID(env.GetObjectClass(activity), "getIntent", "()Landroid/content/Intent;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060024204 jobject intent = env.CallObjectMethod(activity, get_intent_method);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024205 jmethodID get_string_extra_method =
24206 env.GetMethodID(env.GetObjectClass(intent), "getStringExtra", "(Ljava/lang/String;)Ljava/lang/String;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060024207 jvalue get_string_extra_args;
24208 get_string_extra_args.l = env.NewStringUTF(intent_extra_data_key);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024209 jstring extra_str = static_cast<jstring>(env.CallObjectMethodA(intent, get_string_extra_method, &get_string_extra_args));
Cody Northrop1242dfd2016-07-13 17:24:59 -060024210
24211 std::string args_str;
24212 if (extra_str) {
24213 const char *extra_utf = env.GetStringUTFChars(extra_str, nullptr);
24214 args_str = extra_utf;
24215 env.ReleaseStringUTFChars(extra_str, extra_utf);
24216 env.DeleteLocalRef(extra_str);
24217 }
24218
24219 env.DeleteLocalRef(get_string_extra_args.l);
24220 env.DeleteLocalRef(intent);
24221 vm.DetachCurrentThread();
24222
24223 // split args_str
24224 std::stringstream ss(args_str);
24225 std::string arg;
24226 while (std::getline(ss, arg, ' ')) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070024227 if (!arg.empty()) args.push_back(arg);
Cody Northrop1242dfd2016-07-13 17:24:59 -060024228 }
24229
24230 return args;
24231}
24232
Dave Houlton11dcd5e2017-04-25 16:00:10 -060024233void addFullTestCommentIfPresent(const ::testing::TestInfo &test_info, std::string &error_message) {
24234 const char *const type_param = test_info.type_param();
24235 const char *const value_param = test_info.value_param();
Cody Northropb94529f2017-04-05 13:05:51 -060024236
24237 if (type_param != NULL || value_param != NULL) {
24238 error_message.append(", where ");
24239 if (type_param != NULL) {
Dave Houlton11dcd5e2017-04-25 16:00:10 -060024240 error_message.append("TypeParam = ").append(type_param);
24241 if (value_param != NULL) error_message.append(" and ");
Cody Northropb94529f2017-04-05 13:05:51 -060024242 }
24243 if (value_param != NULL) {
24244 error_message.append("GetParam() = ").append(value_param);
24245 }
24246 }
24247}
24248
24249// Inspired by https://github.com/google/googletest/blob/master/googletest/docs/AdvancedGuide.md
24250class LogcatPrinter : public ::testing::EmptyTestEventListener {
24251 // Called before a test starts.
Dave Houlton11dcd5e2017-04-25 16:00:10 -060024252 virtual void OnTestStart(const ::testing::TestInfo &test_info) {
Cody Northropb94529f2017-04-05 13:05:51 -060024253 __android_log_print(ANDROID_LOG_INFO, appTag, "[ RUN ] %s.%s", test_info.test_case_name(), test_info.name());
24254 }
24255
24256 // Called after a failed assertion or a SUCCEED() invocation.
Dave Houlton11dcd5e2017-04-25 16:00:10 -060024257 virtual void OnTestPartResult(const ::testing::TestPartResult &result) {
Cody Northropb94529f2017-04-05 13:05:51 -060024258 // If the test part succeeded, we don't need to do anything.
Dave Houlton11dcd5e2017-04-25 16:00:10 -060024259 if (result.type() == ::testing::TestPartResult::kSuccess) return;
Cody Northropb94529f2017-04-05 13:05:51 -060024260
Dave Houlton11dcd5e2017-04-25 16:00:10 -060024261 __android_log_print(ANDROID_LOG_INFO, appTag, "%s in %s:%d %s", result.failed() ? "*** Failure" : "Success",
24262 result.file_name(), result.line_number(), result.summary());
Cody Northropb94529f2017-04-05 13:05:51 -060024263 }
24264
24265 // Called after a test ends.
Dave Houlton11dcd5e2017-04-25 16:00:10 -060024266 virtual void OnTestEnd(const ::testing::TestInfo &info) {
Cody Northropb94529f2017-04-05 13:05:51 -060024267 std::string result;
24268 if (info.result()->Passed()) {
24269 result.append("[ OK ]");
24270 } else {
24271 result.append("[ FAILED ]");
24272 }
24273 result.append(info.test_case_name()).append(".").append(info.name());
Dave Houlton11dcd5e2017-04-25 16:00:10 -060024274 if (info.result()->Failed()) addFullTestCommentIfPresent(info, result);
Cody Northropb94529f2017-04-05 13:05:51 -060024275
24276 if (::testing::GTEST_FLAG(print_time)) {
24277 std::ostringstream os;
24278 os << info.result()->elapsed_time();
24279 result.append(" (").append(os.str()).append(" ms)");
24280 }
24281
24282 __android_log_print(ANDROID_LOG_INFO, appTag, "%s", result.c_str());
24283 };
24284};
24285
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024286static int32_t processInput(struct android_app *app, AInputEvent *event) { return 0; }
Cody Northrop1242dfd2016-07-13 17:24:59 -060024287
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024288static void processCommand(struct android_app *app, int32_t cmd) {
24289 switch (cmd) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070024290 case APP_CMD_INIT_WINDOW: {
24291 if (app->window) {
24292 initialized = true;
24293 }
24294 break;
Cody Northrop1242dfd2016-07-13 17:24:59 -060024295 }
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070024296 case APP_CMD_GAINED_FOCUS: {
24297 active = true;
24298 break;
24299 }
24300 case APP_CMD_LOST_FOCUS: {
24301 active = false;
24302 break;
24303 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060024304 }
24305}
24306
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024307void android_main(struct android_app *app) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060024308 app_dummy();
24309
Cody Northrop1242dfd2016-07-13 17:24:59 -060024310 int vulkanSupport = InitVulkan();
24311 if (vulkanSupport == 0) {
24312 __android_log_print(ANDROID_LOG_INFO, appTag, "==== FAILED ==== No Vulkan support found");
24313 return;
24314 }
24315
24316 app->onAppCmd = processCommand;
24317 app->onInputEvent = processInput;
24318
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024319 while (1) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060024320 int events;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024321 struct android_poll_source *source;
24322 while (ALooper_pollAll(active ? 0 : -1, NULL, &events, (void **)&source) >= 0) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060024323 if (source) {
24324 source->process(app, source);
24325 }
24326
24327 if (app->destroyRequested != 0) {
24328 VkTestFramework::Finish();
24329 return;
24330 }
24331 }
24332
24333 if (initialized && active) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024334 // Use the following key to send arguments to gtest, i.e.
24335 // --es args "--gtest_filter=-VkLayerTest.foo"
24336 const char key[] = "args";
24337 std::vector<std::string> args = get_args(*app, key);
Cody Northrop1242dfd2016-07-13 17:24:59 -060024338
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024339 std::string filter = "";
24340 if (args.size() > 0) {
24341 __android_log_print(ANDROID_LOG_INFO, appTag, "Intent args = %s", args[0].c_str());
24342 filter += args[0];
24343 } else {
24344 __android_log_print(ANDROID_LOG_INFO, appTag, "No Intent args detected");
24345 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060024346
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024347 int argc = 2;
24348 char *argv[] = {(char *)"foo", (char *)filter.c_str()};
24349 __android_log_print(ANDROID_LOG_DEBUG, appTag, "filter = %s", argv[1]);
Cody Northrop1242dfd2016-07-13 17:24:59 -060024350
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024351 // Route output to files until we can override the gtest output
24352 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/out.txt", "w", stdout);
24353 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/err.txt", "w", stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060024354
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024355 ::testing::InitGoogleTest(&argc, argv);
Cody Northropb94529f2017-04-05 13:05:51 -060024356
Dave Houlton11dcd5e2017-04-25 16:00:10 -060024357 ::testing::TestEventListeners &listeners = ::testing::UnitTest::GetInstance()->listeners();
Cody Northropb94529f2017-04-05 13:05:51 -060024358 listeners.Append(new LogcatPrinter);
24359
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024360 VkTestFramework::InitArgs(&argc, argv);
24361 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Cody Northrop1242dfd2016-07-13 17:24:59 -060024362
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024363 int result = RUN_ALL_TESTS();
Cody Northrop1242dfd2016-07-13 17:24:59 -060024364
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024365 if (result != 0) {
24366 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests FAILED ====");
24367 } else {
24368 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests PASSED ====");
24369 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060024370
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024371 VkTestFramework::Finish();
Cody Northrop1242dfd2016-07-13 17:24:59 -060024372
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024373 fclose(stdout);
24374 fclose(stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060024375
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024376 ANativeActivity_finish(app->activity);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024377 return;
Cody Northrop1242dfd2016-07-13 17:24:59 -060024378 }
24379 }
24380}
24381#endif
24382
Tony Barbour300a6082015-04-07 13:44:53 -060024383int main(int argc, char **argv) {
24384 int result;
24385
Cody Northrop8e54a402016-03-08 22:25:52 -070024386#ifdef ANDROID
24387 int vulkanSupport = InitVulkan();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070024388 if (vulkanSupport == 0) return 1;
Cody Northrop8e54a402016-03-08 22:25:52 -070024389#endif
24390
Tony Barbour300a6082015-04-07 13:44:53 -060024391 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -060024392 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour300a6082015-04-07 13:44:53 -060024393
24394 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
24395
24396 result = RUN_ALL_TESTS();
24397
Tony Barbour6918cd52015-04-09 12:58:51 -060024398 VkTestFramework::Finish();
Tony Barbour300a6082015-04-07 13:44:53 -060024399 return result;
24400}