blob: e2a04131123fcdff850d80891b467c528ff71e94 [file] [log] [blame]
Karl Schultz6addd812016-02-02 17:17:23 -07001/*
Mike Weiblen40b160e2017-02-06 19:21:52 -07002 * Copyright (c) 2015-2017 The Khronos Group Inc.
3 * Copyright (c) 2015-2017 Valve Corporation
4 * Copyright (c) 2015-2017 LunarG, Inc.
5 * Copyright (c) 2015-2017 Google, Inc.
Karl Schultz6addd812016-02-02 17:17:23 -07006 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -06007 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
Karl Schultz6addd812016-02-02 17:17:23 -070010 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -060011 * http://www.apache.org/licenses/LICENSE-2.0
Karl Schultz6addd812016-02-02 17:17:23 -070012 *
13 * Author: Chia-I Wu <olvaffe@gmail.com>
14 * Author: Chris Forbes <chrisf@ijw.co.nz>
15 * Author: Courtney Goeltzenleuchter <courtney@LunarG.com>
16 * Author: Mark Lobodzinski <mark@lunarg.com>
17 * Author: Mike Stroyan <mike@LunarG.com>
18 * Author: Tobin Ehlis <tobine@google.com>
19 * Author: Tony Barbour <tony@LunarG.com>
Cody Northrop1242dfd2016-07-13 17:24:59 -060020 * Author: Cody Northrop <cnorthrop@google.com>
Dave Houlton59a20702017-02-02 17:26:23 -070021 * Author: Dave Houlton <daveh@lunarg.com>
Karl Schultz6addd812016-02-02 17:17:23 -070022 */
Tony Barbour65c48b32015-11-17 10:02:56 -070023
Cody Northrop8e54a402016-03-08 22:25:52 -070024#ifdef ANDROID
25#include "vulkan_wrapper.h"
26#else
David Pinedo9316d3b2015-11-06 12:54:48 -070027#include <vulkan/vulkan.h>
Cody Northrop8e54a402016-03-08 22:25:52 -070028#endif
Cody Northrop1242dfd2016-07-13 17:24:59 -060029
30#if defined(ANDROID) && defined(VALIDATION_APK)
31#include <android/log.h>
32#include <android_native_app_glue.h>
33#endif
34
Jon Ashburn7fa7e222016-02-02 12:08:10 -070035#include "icd-spv.h"
Mark Lobodzinskice751c62016-09-08 10:45:35 -060036#include "test_common.h"
37#include "vk_layer_config.h"
Dave Houlton3c9fca72017-03-27 17:25:54 -060038#include "vk_format_utils.h"
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060039#include "vk_validation_error_messages.h"
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060040#include "vkrenderframework.h"
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070041
42#include <algorithm>
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060043#include <limits.h>
44#include <unordered_set>
Tony Barbour300a6082015-04-07 13:44:53 -060045
Mark Lobodzinski3780e142015-05-14 15:08:13 -050046#define GLM_FORCE_RADIANS
47#include "glm/glm.hpp"
48#include <glm/gtc/matrix_transform.hpp>
49
50//--------------------------------------------------------------------------------------
51// Mesh and VertexFormat Data
52//--------------------------------------------------------------------------------------
Karl Schultz6addd812016-02-02 17:17:23 -070053struct Vertex {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070054 float posX, posY, posZ, posW; // Position data
55 float r, g, b, a; // Color
Mark Lobodzinski3780e142015-05-14 15:08:13 -050056};
57
Karl Schultz6addd812016-02-02 17:17:23 -070058#define XYZ1(_x_, _y_, _z_) (_x_), (_y_), (_z_), 1.f
Mark Lobodzinski3780e142015-05-14 15:08:13 -050059
60typedef enum _BsoFailSelect {
Karl Schultz6addd812016-02-02 17:17:23 -070061 BsoFailNone = 0x00000000,
62 BsoFailLineWidth = 0x00000001,
63 BsoFailDepthBias = 0x00000002,
64 BsoFailViewport = 0x00000004,
65 BsoFailScissor = 0x00000008,
66 BsoFailBlend = 0x00000010,
67 BsoFailDepthBounds = 0x00000020,
68 BsoFailStencilReadMask = 0x00000040,
69 BsoFailStencilWriteMask = 0x00000080,
70 BsoFailStencilReference = 0x00000100,
Mark Muellerd4914412016-06-13 17:52:06 -060071 BsoFailCmdClearAttachments = 0x00000200,
Tobin Ehlis379ba3b2016-07-19 11:22:29 -060072 BsoFailIndexBuffer = 0x00000400,
Mark Lobodzinski3780e142015-05-14 15:08:13 -050073} BsoFailSelect;
74
75struct vktriangle_vs_uniform {
76 // Must start with MVP
Karl Schultz6addd812016-02-02 17:17:23 -070077 float mvp[4][4];
78 float position[3][4];
79 float color[3][4];
Mark Lobodzinski3780e142015-05-14 15:08:13 -050080};
81
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070082static const char bindStateVertShaderText[] =
83 "#version 450\n"
84 "vec2 vertices[3];\n"
85 "out gl_PerVertex {\n"
86 " vec4 gl_Position;\n"
87 "};\n"
88 "void main() {\n"
89 " vertices[0] = vec2(-1.0, -1.0);\n"
90 " vertices[1] = vec2( 1.0, -1.0);\n"
91 " vertices[2] = vec2( 0.0, 1.0);\n"
92 " gl_Position = vec4(vertices[gl_VertexIndex % 3], 0.0, 1.0);\n"
93 "}\n";
Mark Lobodzinski3780e142015-05-14 15:08:13 -050094
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070095static const char bindStateFragShaderText[] =
96 "#version 450\n"
97 "\n"
98 "layout(location = 0) out vec4 uFragColor;\n"
99 "void main(){\n"
100 " uFragColor = vec4(0,1,0,1);\n"
101 "}\n";
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500102
Dave Houlton1d2022c2017-03-29 11:43:58 -0600103// Format search helper
104VkFormat FindSupportedDepthStencilFormat(VkPhysicalDevice phy) {
Dave Houltond7472002017-03-30 09:48:28 -0600105 VkFormat ds_formats[] = {VK_FORMAT_D16_UNORM_S8_UINT, VK_FORMAT_D24_UNORM_S8_UINT, VK_FORMAT_D32_SFLOAT_S8_UINT};
Dave Houlton1d2022c2017-03-29 11:43:58 -0600106 for (uint32_t i = 0; i < sizeof(ds_formats); i++) {
107 VkFormatProperties format_props;
108 vkGetPhysicalDeviceFormatProperties(phy, ds_formats[i], &format_props);
109
110 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
111 return ds_formats[i];
112 }
113 }
114 return (VkFormat)0;
115}
116
117// Validation report callback prototype
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600118static VKAPI_ATTR VkBool32 VKAPI_CALL myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType, uint64_t srcObject,
119 size_t location, int32_t msgCode, const char *pLayerPrefix, const char *pMsg,
120 void *pUserData);
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600121
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600122// ErrorMonitor Usage:
123//
Dave Houltonfbf52152017-01-06 12:55:29 -0700124// Call SetDesiredFailureMsg with a string to be compared against all
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600125// encountered log messages, or a validation error enum identifying
126// desired error message. Passing NULL or VALIDATION_ERROR_MAX_ENUM
127// will match all log messages. logMsg will return true for skipCall
128// only if msg is matched or NULL.
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600129//
Dave Houltonfbf52152017-01-06 12:55:29 -0700130// Call VerifyFound to determine if all desired failure messages
131// were encountered. Call VerifyNotFound to determine if any unexpected
132// failure was encountered.
Tony Barbour300a6082015-04-07 13:44:53 -0600133class ErrorMonitor {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700134 public:
Karl Schultz6addd812016-02-02 17:17:23 -0700135 ErrorMonitor() {
Dave Houltonfbf52152017-01-06 12:55:29 -0700136 test_platform_thread_create_mutex(&mutex_);
137 test_platform_thread_lock_mutex(&mutex_);
138 Reset();
139 test_platform_thread_unlock_mutex(&mutex_);
Tony Barbour300a6082015-04-07 13:44:53 -0600140 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600141
Dave Houltonfbf52152017-01-06 12:55:29 -0700142 ~ErrorMonitor() { test_platform_thread_delete_mutex(&mutex_); }
Dustin Graves48458142016-04-29 16:11:55 -0600143
Dave Houltonfbf52152017-01-06 12:55:29 -0700144 // Set monitor to pristine state
145 void Reset() {
146 message_flags_ = VK_DEBUG_REPORT_ERROR_BIT_EXT;
147 bailout_ = NULL;
148 message_found_ = VK_FALSE;
149 failure_message_strings_.clear();
150 desired_message_strings_.clear();
151 desired_message_ids_.clear();
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700152 ignore_message_strings_.clear();
Dave Houltonfbf52152017-01-06 12:55:29 -0700153 other_messages_.clear();
154 message_outstanding_count_ = 0;
155 }
156
157 // ErrorMonitor will look for an error message containing the specified string(s)
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700158 void SetDesiredFailureMsg(const VkFlags msgFlags, const char *const msgString) {
Dave Houltonfbf52152017-01-06 12:55:29 -0700159 test_platform_thread_lock_mutex(&mutex_);
160 desired_message_strings_.insert(msgString);
161 message_flags_ |= msgFlags;
162 message_outstanding_count_++;
163 test_platform_thread_unlock_mutex(&mutex_);
Tony Barbour300a6082015-04-07 13:44:53 -0600164 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600165
Jeremy Hayesde6d96c2017-02-01 15:22:32 -0700166 // ErrorMonitor will look for an error message containing the specified string(s)
167 template <typename Iter>
168 void SetDesiredFailureMsg(const VkFlags msgFlags, Iter iter, const Iter end) {
169 for (; iter != end; ++iter) {
170 SetDesiredFailureMsg(msgFlags, *iter);
171 }
172 }
173
Dave Houltonfbf52152017-01-06 12:55:29 -0700174 // ErrorMonitor will look for a message ID matching the specified one(s)
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700175 void SetDesiredFailureMsg(const VkFlags msgFlags, const UNIQUE_VALIDATION_ERROR_CODE msg_id) {
Dave Houltonfbf52152017-01-06 12:55:29 -0700176 test_platform_thread_lock_mutex(&mutex_);
177 desired_message_ids_.insert(msg_id);
178 message_flags_ |= msgFlags;
179 message_outstanding_count_++;
180 test_platform_thread_unlock_mutex(&mutex_);
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600181 }
182
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700183 // Set an error that the error monitor will ignore. Do not use this function if you are creating a new test.
184 // TODO: This is stopgap to block new unexpected errors from being introduced. The long-term goal is to remove the use of this
185 // function and its definition.
186 void SetUnexpectedError(const char *const msg) {
187 test_platform_thread_lock_mutex(&mutex_);
188
189 ignore_message_strings_.emplace_back(msg);
190
191 test_platform_thread_unlock_mutex(&mutex_);
192 }
193
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700194 VkBool32 CheckForDesiredMsg(const uint32_t message_code, const char *const msgString) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600195 VkBool32 result = VK_FALSE;
Dave Houltonfbf52152017-01-06 12:55:29 -0700196 test_platform_thread_lock_mutex(&mutex_);
197 if (bailout_ != NULL) {
198 *bailout_ = true;
Mike Stroyanaccf7692015-05-12 16:00:45 -0600199 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600200 string errorString(msgString);
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600201 bool found_expected = false;
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600202
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700203 if (!IgnoreMessage(errorString)) {
204 for (auto desired_msg : desired_message_strings_) {
205 if (desired_msg.length() == 0) {
206 // An empty desired_msg string "" indicates a positive test - not expecting an error.
207 // Return true to avoid calling layers/driver with this error.
208 // And don't erase the "" string, so it remains if another error is found.
209 result = VK_TRUE;
210 found_expected = true;
211 message_found_ = VK_TRUE;
212 failure_message_strings_.insert(errorString);
213 } else if (errorString.find(desired_msg) != string::npos) {
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600214 found_expected = true;
Dave Houltonfbf52152017-01-06 12:55:29 -0700215 message_outstanding_count_--;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700216 failure_message_strings_.insert(errorString);
Dave Houltonfbf52152017-01-06 12:55:29 -0700217 message_found_ = VK_TRUE;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700218 result = VK_TRUE;
219 // We only want one match for each expected error so remove from set here
220 // Since we're about the break the loop it's ok to remove from set we're iterating over
221 desired_message_strings_.erase(desired_msg);
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600222 break;
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600223 }
224 }
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700225 for (auto desired_id : desired_message_ids_) {
226 if (desired_id == VALIDATION_ERROR_MAX_ENUM) {
227 // A message ID set to MAX_ENUM indicates a positive test - not expecting an error.
228 // Return true to avoid calling layers/driver with this error.
229 result = VK_TRUE;
230 } else if (desired_id == message_code) {
231 // Double-check that the string matches the error enum
232 if (errorString.find(validation_error_map[desired_id]) != string::npos) {
233 found_expected = true;
234 message_outstanding_count_--;
235 result = VK_TRUE;
236 message_found_ = VK_TRUE;
237 desired_message_ids_.erase(desired_id);
238 break;
239 } else {
240 // Treat this message as a regular unexpected error, but print a warning jic
241 printf("Message (%s) from MessageID %d does not correspond to expected message from error Database (%s)\n",
242 errorString.c_str(), desired_id, validation_error_map[desired_id]);
243 }
244 }
245 }
246
247 if (!found_expected) {
Jeremy Hayes2a54c012017-03-16 13:32:05 -0600248 printf("Unexpected: %s\n", msgString);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700249 other_messages_.push_back(errorString);
250 }
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600251 }
252
Dave Houltonfbf52152017-01-06 12:55:29 -0700253 test_platform_thread_unlock_mutex(&mutex_);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600254 return result;
Mike Stroyanaccf7692015-05-12 16:00:45 -0600255 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600256
Jeremy Hayes2a54c012017-03-16 13:32:05 -0600257 vector<string> GetOtherFailureMsgs(void) const { return other_messages_; }
258
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700259 VkDebugReportFlagsEXT GetMessageFlags(void) const { return message_flags_; }
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600260
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700261 VkBool32 AnyDesiredMsgFound(void) const { return message_found_; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600262
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700263 VkBool32 AllDesiredMsgsFound(void) const { return (0 == message_outstanding_count_); }
Dave Houltonfbf52152017-01-06 12:55:29 -0700264
265 void SetBailout(bool *bailout) { bailout_ = bailout; }
Tony Barbour300a6082015-04-07 13:44:53 -0600266
Jeremy Hayes2a54c012017-03-16 13:32:05 -0600267 void DumpFailureMsgs(void) const {
268 vector<string> otherMsgs = GetOtherFailureMsgs();
269 if (otherMsgs.size()) {
270 cout << "Other error messages logged for this test were:" << endl;
271 for (auto iter = otherMsgs.begin(); iter != otherMsgs.end(); iter++) {
272 cout << " " << *iter << endl;
Tony Barbour59b42282016-11-03 13:31:28 -0600273 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600274 }
275 }
276
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600277 // Helpers
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200278
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600279 // ExpectSuccess now takes an optional argument allowing a custom combination of debug flags
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700280 void ExpectSuccess(VkDebugReportFlagsEXT const message_flag_mask = VK_DEBUG_REPORT_ERROR_BIT_EXT) {
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600281 // Match ANY message matching specified type
282 SetDesiredFailureMsg(message_flag_mask, "");
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700283 message_flags_ = message_flag_mask; // override mask handling in SetDesired...
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200284 }
285
286 void VerifyFound() {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600287 // Not seeing the desired message is a failure. /Before/ throwing, dump any other messages.
Dave Houltonfbf52152017-01-06 12:55:29 -0700288 if (!AllDesiredMsgsFound()) {
Jeremy Hayes2a54c012017-03-16 13:32:05 -0600289 DumpFailureMsgs();
Dave Houltonfbf52152017-01-06 12:55:29 -0700290 for (auto desired_msg : desired_message_strings_) {
Dave Houltond5507dd2017-01-24 15:29:02 -0700291 ADD_FAILURE() << "Did not receive expected error '" << desired_msg << "'";
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600292 }
Dave Houltonfbf52152017-01-06 12:55:29 -0700293 for (auto desired_id : desired_message_ids_) {
Dave Houltond5507dd2017-01-24 15:29:02 -0700294 ADD_FAILURE() << "Did not receive expected error ENUM '" << desired_id << "'";
Tony Barbour59b42282016-11-03 13:31:28 -0600295 }
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200296 }
Dave Houltonfbf52152017-01-06 12:55:29 -0700297 Reset();
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200298 }
299
300 void VerifyNotFound() {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600301 // ExpectSuccess() configured us to match anything. Any error is a failure.
Dave Houltonfbf52152017-01-06 12:55:29 -0700302 if (AnyDesiredMsgFound()) {
Jeremy Hayes2a54c012017-03-16 13:32:05 -0600303 DumpFailureMsgs();
Dave Houltonfbf52152017-01-06 12:55:29 -0700304 for (auto msg : failure_message_strings_) {
Dave Houltond5507dd2017-01-24 15:29:02 -0700305 ADD_FAILURE() << "Expected to succeed but got error: " << msg;
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600306 }
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200307 }
Dave Houltonfbf52152017-01-06 12:55:29 -0700308 Reset();
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200309 }
310
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700311 private:
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700312 // TODO: This is stopgap to block new unexpected errors from being introduced. The long-term goal is to remove the use of this
313 // function and its definition.
314 bool IgnoreMessage(std::string const &msg) const {
315 if (ignore_message_strings_.empty()) {
316 return false;
317 }
318
319 return std::find_if(ignore_message_strings_.begin(), ignore_message_strings_.end(), [&msg](std::string const &str) {
320 return msg.find(str) != std::string::npos;
321 }) != ignore_message_strings_.end();
322 }
323
Mark Lobodzinski729a8d32017-01-26 12:16:30 -0700324 VkFlags message_flags_;
325 std::unordered_set<uint32_t> desired_message_ids_;
326 std::unordered_set<string> desired_message_strings_;
327 std::unordered_set<string> failure_message_strings_;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700328 std::vector<std::string> ignore_message_strings_;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -0700329 vector<string> other_messages_;
330 test_platform_thread_mutex mutex_;
331 bool *bailout_;
332 VkBool32 message_found_;
333 int message_outstanding_count_;
Tony Barbour300a6082015-04-07 13:44:53 -0600334};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500335
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600336static VKAPI_ATTR VkBool32 VKAPI_CALL myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType, uint64_t srcObject,
337 size_t location, int32_t msgCode, const char *pLayerPrefix, const char *pMsg,
338 void *pUserData) {
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600339 ErrorMonitor *errMonitor = (ErrorMonitor *)pUserData;
340 if (msgFlags & errMonitor->GetMessageFlags()) {
Dave Houltonc85c4a82017-04-25 15:56:45 -0600341#ifdef _DEBUG
342 char embedded_code_string[2048];
343 snprintf(embedded_code_string, 2048, "%s [%05d]", pMsg, msgCode);
344 return errMonitor->CheckForDesiredMsg(msgCode, embedded_code_string);
345#else
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600346 return errMonitor->CheckForDesiredMsg(msgCode, pMsg);
Dave Houltonc85c4a82017-04-25 15:56:45 -0600347#endif
Tony Barbour0b4d9562015-04-09 10:48:04 -0600348 }
Courtney Goeltzenleuchter06640832015-09-04 13:52:24 -0600349 return false;
Tony Barbour300a6082015-04-07 13:44:53 -0600350}
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500351
Karl Schultz6addd812016-02-02 17:17:23 -0700352class VkLayerTest : public VkRenderFramework {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700353 public:
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600354 void VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask);
355 void GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet,
Karl Schultz6addd812016-02-02 17:17:23 -0700356 BsoFailSelect failMask);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600357 void GenericDrawPreparation(VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask) {
358 GenericDrawPreparation(m_commandBuffer, pipelineobj, descriptorSet, failMask);
Karl Schultz6addd812016-02-02 17:17:23 -0700359 }
Tony Barbour300a6082015-04-07 13:44:53 -0600360
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600361 void Draw(uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance) {
362 m_commandBuffer->Draw(vertexCount, instanceCount, firstVertex, firstInstance);
Karl Schultz6addd812016-02-02 17:17:23 -0700363 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600364 void DrawIndexed(uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex, int32_t vertexOffset,
Karl Schultz6addd812016-02-02 17:17:23 -0700365 uint32_t firstInstance) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600366 m_commandBuffer->DrawIndexed(indexCount, instanceCount, firstIndex, vertexOffset, firstInstance);
Karl Schultz6addd812016-02-02 17:17:23 -0700367 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600368 void QueueCommandBuffer(bool checkSuccess = true) { m_commandBuffer->QueueCommandBuffer(checkSuccess); }
369 void QueueCommandBuffer(const VkFence &fence) { m_commandBuffer->QueueCommandBuffer(fence); }
370 void BindVertexBuffer(VkConstantBufferObj *vertexBuffer, VkDeviceSize offset, uint32_t binding) {
Karl Schultz6addd812016-02-02 17:17:23 -0700371 m_commandBuffer->BindVertexBuffer(vertexBuffer, offset, binding);
372 }
373 void BindIndexBuffer(VkIndexBufferObj *indexBuffer, VkDeviceSize offset) {
374 m_commandBuffer->BindIndexBuffer(indexBuffer, offset);
375 }
Tony Barbour1fa09702017-03-16 12:09:08 -0600376 void Init(VkPhysicalDeviceFeatures *features = nullptr, const VkCommandPoolCreateFlags flags = 0) {
377 InitFramework(instance_layer_names, instance_extension_names, device_extension_names, myDbgFunc, m_errorMonitor);
378 InitState(features, flags);
379 }
380
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700381 protected:
Karl Schultz6addd812016-02-02 17:17:23 -0700382 ErrorMonitor *m_errorMonitor;
Ian Elliott2c1daf52016-05-12 09:41:46 -0600383 bool m_enableWSI;
Tony Barbour1fa09702017-03-16 12:09:08 -0600384 std::vector<const char *> instance_layer_names;
385 std::vector<const char *> instance_extension_names;
386 std::vector<const char *> device_extension_names;
Tony Barbour300a6082015-04-07 13:44:53 -0600387
388 virtual void SetUp() {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700389 instance_extension_names.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME);
Courtney Goeltzenleuchterc2b06fe2015-06-16 15:59:11 -0600390 /*
391 * Since CreateDbgMsgCallback is an instance level extension call
392 * any extension / layer that utilizes that feature also needs
393 * to be enabled at create instance time.
394 */
Karl Schultz6addd812016-02-02 17:17:23 -0700395 // Use Threading layer first to protect others from
396 // ThreadCommandBufferCollision test
Courtney Goeltzenleuchter76885322016-02-06 17:11:22 -0700397 instance_layer_names.push_back("VK_LAYER_GOOGLE_threading");
Tobin Ehlis24aab042016-03-24 10:54:18 -0600398 instance_layer_names.push_back("VK_LAYER_LUNARG_parameter_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800399 instance_layer_names.push_back("VK_LAYER_LUNARG_object_tracker");
Tobin Ehlisc96f8062016-03-09 16:12:48 -0700400 instance_layer_names.push_back("VK_LAYER_LUNARG_core_validation");
Ian Elliotte48a1382016-04-28 14:22:58 -0600401 instance_layer_names.push_back("VK_LAYER_LUNARG_swapchain");
Dustin Graveseaa78cd2016-01-26 16:30:22 -0700402 instance_layer_names.push_back("VK_LAYER_GOOGLE_unique_objects");
Courtney Goeltzenleuchterd971b612015-06-17 20:51:59 -0600403
Ian Elliott2c1daf52016-05-12 09:41:46 -0600404 if (m_enableWSI) {
405 instance_extension_names.push_back(VK_KHR_SURFACE_EXTENSION_NAME);
406 device_extension_names.push_back(VK_KHR_SWAPCHAIN_EXTENSION_NAME);
407#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
408#if defined(VK_USE_PLATFORM_ANDROID_KHR)
409 instance_extension_names.push_back(VK_KHR_ANDROID_SURFACE_EXTENSION_NAME);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700410#endif // VK_USE_PLATFORM_ANDROID_KHR
Ian Elliott2c1daf52016-05-12 09:41:46 -0600411#if defined(VK_USE_PLATFORM_MIR_KHR)
412 instance_extension_names.push_back(VK_KHR_MIR_SURFACE_EXTENSION_NAME);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700413#endif // VK_USE_PLATFORM_MIR_KHR
Ian Elliott2c1daf52016-05-12 09:41:46 -0600414#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
415 instance_extension_names.push_back(VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700416#endif // VK_USE_PLATFORM_WAYLAND_KHR
Ian Elliott2c1daf52016-05-12 09:41:46 -0600417#if defined(VK_USE_PLATFORM_WIN32_KHR)
418 instance_extension_names.push_back(VK_KHR_WIN32_SURFACE_EXTENSION_NAME);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700419#endif // VK_USE_PLATFORM_WIN32_KHR
420#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott2c1daf52016-05-12 09:41:46 -0600421#if defined(VK_USE_PLATFORM_XCB_KHR)
422 instance_extension_names.push_back(VK_KHR_XCB_SURFACE_EXTENSION_NAME);
423#elif defined(VK_USE_PLATFORM_XLIB_KHR)
424 instance_extension_names.push_back(VK_KHR_XLIB_SURFACE_EXTENSION_NAME);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700425#endif // VK_USE_PLATFORM_XLIB_KHR
Ian Elliott2c1daf52016-05-12 09:41:46 -0600426 }
427
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600428 this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Tony Barbour300a6082015-04-07 13:44:53 -0600429 this->app_info.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800430 this->app_info.pApplicationName = "layer_tests";
431 this->app_info.applicationVersion = 1;
Tony Barbour300a6082015-04-07 13:44:53 -0600432 this->app_info.pEngineName = "unittest";
433 this->app_info.engineVersion = 1;
Jon Ashburnc5012ff2016-03-22 13:57:46 -0600434 this->app_info.apiVersion = VK_API_VERSION_1_0;
Tony Barbour300a6082015-04-07 13:44:53 -0600435
Tony Barbour15524c32015-04-29 17:34:29 -0600436 m_errorMonitor = new ErrorMonitor;
Tony Barbour300a6082015-04-07 13:44:53 -0600437 }
438
439 virtual void TearDown() {
440 // Clean up resources before we reset
Tony Barbour300a6082015-04-07 13:44:53 -0600441 ShutdownFramework();
Tony Barbour0b4d9562015-04-09 10:48:04 -0600442 delete m_errorMonitor;
Tony Barbour300a6082015-04-07 13:44:53 -0600443 }
Ian Elliott2c1daf52016-05-12 09:41:46 -0600444
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600445 VkLayerTest() { m_enableWSI = false; }
Tony Barbour300a6082015-04-07 13:44:53 -0600446};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500447
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600448void VkLayerTest::VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500449 // Create identity matrix
450 int i;
451 struct vktriangle_vs_uniform data;
452
453 glm::mat4 Projection = glm::mat4(1.0f);
Karl Schultz6addd812016-02-02 17:17:23 -0700454 glm::mat4 View = glm::mat4(1.0f);
455 glm::mat4 Model = glm::mat4(1.0f);
456 glm::mat4 MVP = Projection * View * Model;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500457 const int matrixSize = sizeof(MVP);
Karl Schultz6addd812016-02-02 17:17:23 -0700458 const int bufSize = sizeof(vktriangle_vs_uniform) / sizeof(float);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500459
460 memcpy(&data.mvp, &MVP[0][0], matrixSize);
461
Karl Schultz6addd812016-02-02 17:17:23 -0700462 static const Vertex tri_data[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600463 {XYZ1(-1, -1, 0), XYZ1(1.f, 0.f, 0.f)}, {XYZ1(1, -1, 0), XYZ1(0.f, 1.f, 0.f)}, {XYZ1(0, 1, 0), XYZ1(0.f, 0.f, 1.f)},
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500464 };
465
Karl Schultz6addd812016-02-02 17:17:23 -0700466 for (i = 0; i < 3; i++) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500467 data.position[i][0] = tri_data[i].posX;
468 data.position[i][1] = tri_data[i].posY;
469 data.position[i][2] = tri_data[i].posZ;
470 data.position[i][3] = tri_data[i].posW;
Karl Schultz6addd812016-02-02 17:17:23 -0700471 data.color[i][0] = tri_data[i].r;
472 data.color[i][1] = tri_data[i].g;
473 data.color[i][2] = tri_data[i].b;
474 data.color[i][3] = tri_data[i].a;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500475 }
476
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500477 ASSERT_NO_FATAL_FAILURE(InitViewport());
478
Chris Forbesbcfaadd2016-09-16 14:13:53 +1200479 VkConstantBufferObj constantBuffer(m_device, bufSize * 2, sizeof(float), (const void *)&data,
480 VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500481
Karl Schultz6addd812016-02-02 17:17:23 -0700482 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600483 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500484
485 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +0800486 pipelineobj.AddColorAttachment();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500487 pipelineobj.AddShader(&vs);
488 pipelineobj.AddShader(&ps);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600489 if (failMask & BsoFailLineWidth) {
490 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_LINE_WIDTH);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600491 VkPipelineInputAssemblyStateCreateInfo ia_state = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600492 ia_state.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600493 ia_state.topology = VK_PRIMITIVE_TOPOLOGY_LINE_LIST;
494 pipelineobj.SetInputAssembly(&ia_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600495 }
496 if (failMask & BsoFailDepthBias) {
497 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BIAS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600498 VkPipelineRasterizationStateCreateInfo rs_state = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600499 rs_state.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600500 rs_state.depthBiasEnable = VK_TRUE;
Mark Young7394fdd2016-03-31 14:56:43 -0600501 rs_state.lineWidth = 1.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600502 pipelineobj.SetRasterization(&rs_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600503 }
Rene Lindsayacbf5e62016-12-15 18:47:11 -0700504 // Viewport and scissors must stay in sync or other errors will occur than
Karl Schultz6addd812016-02-02 17:17:23 -0700505 // the ones we want
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600506 if (failMask & BsoFailViewport) {
507 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_VIEWPORT);
508 }
509 if (failMask & BsoFailScissor) {
510 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_SCISSOR);
511 }
512 if (failMask & BsoFailBlend) {
513 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_BLEND_CONSTANTS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600514 VkPipelineColorBlendAttachmentState att_state = {};
515 att_state.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
516 att_state.blendEnable = VK_TRUE;
517 pipelineobj.AddColorAttachment(0, &att_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600518 }
519 if (failMask & BsoFailDepthBounds) {
520 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BOUNDS);
521 }
522 if (failMask & BsoFailStencilReadMask) {
523 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK);
524 }
525 if (failMask & BsoFailStencilWriteMask) {
526 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_WRITE_MASK);
527 }
528 if (failMask & BsoFailStencilReference) {
529 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_REFERENCE);
530 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500531
532 VkDescriptorSetObj descriptorSet(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600533 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, constantBuffer);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500534
535 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour552f6c02016-12-21 14:34:07 -0700536 m_commandBuffer->BeginCommandBuffer();
537 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500538
Tony Barbourfe3351b2015-07-28 10:17:20 -0600539 GenericDrawPreparation(pipelineobj, descriptorSet, failMask);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500540
541 // render triangle
Tobin Ehlis379ba3b2016-07-19 11:22:29 -0600542 if (failMask & BsoFailIndexBuffer) {
543 // Use DrawIndexed w/o an index buffer bound
544 DrawIndexed(3, 1, 0, 0, 0);
545 } else {
546 Draw(3, 1, 0, 0);
547 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500548
Mark Muellerd4914412016-06-13 17:52:06 -0600549 if (failMask & BsoFailCmdClearAttachments) {
550 VkClearAttachment color_attachment = {};
551 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700552 color_attachment.colorAttachment = 1; // Someone who knew what they were doing would use 0 for the index;
Mark Muellerd4914412016-06-13 17:52:06 -0600553 VkClearRect clear_rect = {{{0, 0}, {static_cast<uint32_t>(m_width), static_cast<uint32_t>(m_height)}}, 0, 0};
554
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600555 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Muellerd4914412016-06-13 17:52:06 -0600556 }
557
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500558 // finalize recording of the command buffer
Tony Barbour552f6c02016-12-21 14:34:07 -0700559 m_commandBuffer->EndRenderPass();
560 m_commandBuffer->EndCommandBuffer();
Tony Barbourfe3351b2015-07-28 10:17:20 -0600561 QueueCommandBuffer();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500562}
563
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600564void VkLayerTest::GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj,
565 VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500566 if (m_depthStencil->Initialized()) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600567 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, m_depthStencil);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500568 } else {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600569 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500570 }
571
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800572 commandBuffer->PrepareAttachments();
Karl Schultz6addd812016-02-02 17:17:23 -0700573 // Make sure depthWriteEnable is set so that Depth fail test will work
574 // correctly
575 // Make sure stencilTestEnable is set so that Stencil fail test will work
576 // correctly
Tony Barboureb254902015-07-15 12:50:33 -0600577 VkStencilOpState stencil = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800578 stencil.failOp = VK_STENCIL_OP_KEEP;
579 stencil.passOp = VK_STENCIL_OP_KEEP;
580 stencil.depthFailOp = VK_STENCIL_OP_KEEP;
581 stencil.compareOp = VK_COMPARE_OP_NEVER;
Tony Barboureb254902015-07-15 12:50:33 -0600582
583 VkPipelineDepthStencilStateCreateInfo ds_ci = {};
584 ds_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600585 ds_ci.pNext = NULL;
586 ds_ci.depthTestEnable = VK_FALSE;
587 ds_ci.depthWriteEnable = VK_TRUE;
588 ds_ci.depthCompareOp = VK_COMPARE_OP_NEVER;
589 ds_ci.depthBoundsTestEnable = VK_FALSE;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600590 if (failMask & BsoFailDepthBounds) {
591 ds_ci.depthBoundsTestEnable = VK_TRUE;
Tobin Ehlis21c88352016-05-26 06:15:45 -0600592 ds_ci.maxDepthBounds = 0.0f;
593 ds_ci.minDepthBounds = 0.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600594 }
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600595 ds_ci.stencilTestEnable = VK_TRUE;
596 ds_ci.front = stencil;
597 ds_ci.back = stencil;
Tony Barboureb254902015-07-15 12:50:33 -0600598
Tobin Ehlis4bf96d12015-06-25 11:58:41 -0600599 pipelineobj.SetDepthStencil(&ds_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -0600600 pipelineobj.SetViewport(m_viewports);
601 pipelineobj.SetScissor(m_scissors);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800602 descriptorSet.CreateVKDescriptorSet(commandBuffer);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600603 VkResult err = pipelineobj.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Cody Northrop29a08f22015-08-27 10:20:35 -0600604 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800605 commandBuffer->BindPipeline(pipelineobj);
606 commandBuffer->BindDescriptorSet(descriptorSet);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500607}
608
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600609class VkPositiveLayerTest : public VkLayerTest {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700610 public:
611 protected:
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600612};
613
Ian Elliott2c1daf52016-05-12 09:41:46 -0600614class VkWsiEnabledLayerTest : public VkLayerTest {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700615 public:
616 protected:
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600617 VkWsiEnabledLayerTest() { m_enableWSI = true; }
Ian Elliott2c1daf52016-05-12 09:41:46 -0600618};
619
Mark Muellerdfe37552016-07-07 14:47:42 -0600620class VkBufferTest {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700621 public:
Mark Muellerdfe37552016-07-07 14:47:42 -0600622 enum eTestEnFlags {
623 eDoubleDelete,
624 eInvalidDeviceOffset,
625 eInvalidMemoryOffset,
626 eBindNullBuffer,
627 eFreeInvalidHandle,
Mark Mueller4042b652016-09-05 22:52:21 -0600628 eNone,
Mark Muellerdfe37552016-07-07 14:47:42 -0600629 };
630
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600631 enum eTestConditions { eOffsetAlignment = 1 };
Mark Muellerdfe37552016-07-07 14:47:42 -0600632
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600633 static bool GetTestConditionValid(VkDeviceObj *aVulkanDevice, eTestEnFlags aTestFlag, VkBufferUsageFlags aBufferUsage = 0) {
634 if (eInvalidDeviceOffset != aTestFlag && eInvalidMemoryOffset != aTestFlag) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600635 return true;
636 }
637 VkDeviceSize offset_limit = 0;
638 if (eInvalidMemoryOffset == aTestFlag) {
639 VkBuffer vulkanBuffer;
640 VkBufferCreateInfo buffer_create_info = {};
641 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
642 buffer_create_info.size = 32;
643 buffer_create_info.usage = aBufferUsage;
644
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600645 vkCreateBuffer(aVulkanDevice->device(), &buffer_create_info, nullptr, &vulkanBuffer);
Mark Mueller4042b652016-09-05 22:52:21 -0600646 VkMemoryRequirements memory_reqs = {};
Mark Muellerdfe37552016-07-07 14:47:42 -0600647
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600648 vkGetBufferMemoryRequirements(aVulkanDevice->device(), vulkanBuffer, &memory_reqs);
Mark Muellerdfe37552016-07-07 14:47:42 -0600649 vkDestroyBuffer(aVulkanDevice->device(), vulkanBuffer, nullptr);
650 offset_limit = memory_reqs.alignment;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600651 } else if ((VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT | VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT) & aBufferUsage) {
652 offset_limit = aVulkanDevice->props.limits.minTexelBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600653 } else if (VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT & aBufferUsage) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600654 offset_limit = aVulkanDevice->props.limits.minUniformBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600655 } else if (VK_BUFFER_USAGE_STORAGE_BUFFER_BIT & aBufferUsage) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600656 offset_limit = aVulkanDevice->props.limits.minStorageBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600657 }
658 if (eOffsetAlignment < offset_limit) {
659 return true;
660 }
661 return false;
662 }
663
664 // A constructor which performs validation tests within construction.
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600665 VkBufferTest(VkDeviceObj *aVulkanDevice, VkBufferUsageFlags aBufferUsage, eTestEnFlags aTestFlag = eNone)
666 : AllocateCurrent(false), BoundCurrent(false), CreateCurrent(false), VulkanDevice(aVulkanDevice->device()) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600667 if (eBindNullBuffer == aTestFlag) {
668 VulkanMemory = 0;
669 vkBindBufferMemory(VulkanDevice, VulkanBuffer, VulkanMemory, 0);
670 } else {
671 VkBufferCreateInfo buffer_create_info = {};
672 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
673 buffer_create_info.size = 32;
674 buffer_create_info.usage = aBufferUsage;
675
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600676 vkCreateBuffer(VulkanDevice, &buffer_create_info, nullptr, &VulkanBuffer);
Mark Muellerdfe37552016-07-07 14:47:42 -0600677
678 CreateCurrent = true;
679
680 VkMemoryRequirements memory_requirements;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600681 vkGetBufferMemoryRequirements(VulkanDevice, VulkanBuffer, &memory_requirements);
Mark Muellerdfe37552016-07-07 14:47:42 -0600682
683 VkMemoryAllocateInfo memory_allocate_info = {};
684 memory_allocate_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Cort Stratton77a0d592017-02-17 13:14:13 -0800685 memory_allocate_info.allocationSize = memory_requirements.size + eOffsetAlignment;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600686 bool pass = aVulkanDevice->phy().set_memory_type(memory_requirements.memoryTypeBits, &memory_allocate_info,
687 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Mark Muellerdfe37552016-07-07 14:47:42 -0600688 if (!pass) {
689 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
690 return;
691 }
692
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600693 vkAllocateMemory(VulkanDevice, &memory_allocate_info, NULL, &VulkanMemory);
Mark Muellerdfe37552016-07-07 14:47:42 -0600694 AllocateCurrent = true;
695 // NB: 1 is intentionally an invalid offset value
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600696 const bool offset_en = eInvalidDeviceOffset == aTestFlag || eInvalidMemoryOffset == aTestFlag;
697 vkBindBufferMemory(VulkanDevice, VulkanBuffer, VulkanMemory, offset_en ? eOffsetAlignment : 0);
Mark Muellerdfe37552016-07-07 14:47:42 -0600698 BoundCurrent = true;
699
700 InvalidDeleteEn = (eFreeInvalidHandle == aTestFlag);
701 }
702 }
703
704 ~VkBufferTest() {
705 if (CreateCurrent) {
706 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
707 }
708 if (AllocateCurrent) {
709 if (InvalidDeleteEn) {
710 union {
711 VkDeviceMemory device_memory;
712 unsigned long long index_access;
713 } bad_index;
714
715 bad_index.device_memory = VulkanMemory;
716 bad_index.index_access++;
717
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600718 vkFreeMemory(VulkanDevice, bad_index.device_memory, nullptr);
Mark Muellerdfe37552016-07-07 14:47:42 -0600719 }
720 vkFreeMemory(VulkanDevice, VulkanMemory, nullptr);
721 }
722 }
723
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600724 bool GetBufferCurrent() { return AllocateCurrent && BoundCurrent && CreateCurrent; }
Mark Muellerdfe37552016-07-07 14:47:42 -0600725
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600726 const VkBuffer &GetBuffer() { return VulkanBuffer; }
Mark Muellerdfe37552016-07-07 14:47:42 -0600727
728 void TestDoubleDestroy() {
729 // Destroy the buffer but leave the flag set, which will cause
730 // the buffer to be destroyed again in the destructor.
731 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
732 }
733
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700734 protected:
Mark Muellerdfe37552016-07-07 14:47:42 -0600735 bool AllocateCurrent;
736 bool BoundCurrent;
737 bool CreateCurrent;
738 bool InvalidDeleteEn;
739
740 VkBuffer VulkanBuffer;
741 VkDevice VulkanDevice;
742 VkDeviceMemory VulkanMemory;
Mark Muellerdfe37552016-07-07 14:47:42 -0600743};
744
745class VkVerticesObj {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700746 public:
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600747 VkVerticesObj(VkDeviceObj *aVulkanDevice, unsigned aAttributeCount, unsigned aBindingCount, unsigned aByteStride,
Mark Muellerdfe37552016-07-07 14:47:42 -0600748 VkDeviceSize aVertexCount, const float *aVerticies)
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700749 : BoundCurrent(false),
750 AttributeCount(aAttributeCount),
751 BindingCount(aBindingCount),
752 BindId(BindIdGenerator),
Mark Muellerdfe37552016-07-07 14:47:42 -0600753 PipelineVertexInputStateCreateInfo(),
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600754 VulkanMemoryBuffer(aVulkanDevice, 1, static_cast<int>(aByteStride * aVertexCount),
755 reinterpret_cast<const void *>(aVerticies), VK_BUFFER_USAGE_VERTEX_BUFFER_BIT) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700756 BindIdGenerator++; // NB: This can wrap w/misuse
Mark Muellerdfe37552016-07-07 14:47:42 -0600757
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600758 VertexInputAttributeDescription = new VkVertexInputAttributeDescription[AttributeCount];
759 VertexInputBindingDescription = new VkVertexInputBindingDescription[BindingCount];
Mark Muellerdfe37552016-07-07 14:47:42 -0600760
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600761 PipelineVertexInputStateCreateInfo.pVertexAttributeDescriptions = VertexInputAttributeDescription;
762 PipelineVertexInputStateCreateInfo.vertexAttributeDescriptionCount = AttributeCount;
763 PipelineVertexInputStateCreateInfo.pVertexBindingDescriptions = VertexInputBindingDescription;
764 PipelineVertexInputStateCreateInfo.vertexBindingDescriptionCount = BindingCount;
765 PipelineVertexInputStateCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -0600766
767 unsigned i = 0;
768 do {
769 VertexInputAttributeDescription[i].binding = BindId;
770 VertexInputAttributeDescription[i].location = i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600771 VertexInputAttributeDescription[i].format = VK_FORMAT_R32G32B32_SFLOAT;
772 VertexInputAttributeDescription[i].offset = sizeof(float) * aByteStride;
Mark Muellerdfe37552016-07-07 14:47:42 -0600773 i++;
774 } while (AttributeCount < i);
775
776 i = 0;
777 do {
778 VertexInputBindingDescription[i].binding = BindId;
779 VertexInputBindingDescription[i].stride = aByteStride;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600780 VertexInputBindingDescription[i].inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
Mark Muellerdfe37552016-07-07 14:47:42 -0600781 i++;
782 } while (BindingCount < i);
783 }
784
785 ~VkVerticesObj() {
786 if (VertexInputAttributeDescription) {
787 delete[] VertexInputAttributeDescription;
788 }
789 if (VertexInputBindingDescription) {
790 delete[] VertexInputBindingDescription;
791 }
792 }
793
794 bool AddVertexInputToPipe(VkPipelineObj &aPipelineObj) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600795 aPipelineObj.AddVertexInputAttribs(VertexInputAttributeDescription, AttributeCount);
796 aPipelineObj.AddVertexInputBindings(VertexInputBindingDescription, BindingCount);
Mark Muellerdfe37552016-07-07 14:47:42 -0600797 return true;
798 }
799
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600800 void BindVertexBuffers(VkCommandBuffer aCommandBuffer, unsigned aOffsetCount = 0, VkDeviceSize *aOffsetList = nullptr) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600801 VkDeviceSize *offsetList;
802 unsigned offsetCount;
803
804 if (aOffsetCount) {
805 offsetList = aOffsetList;
806 offsetCount = aOffsetCount;
807 } else {
808 offsetList = new VkDeviceSize[1]();
809 offsetCount = 1;
810 }
811
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600812 vkCmdBindVertexBuffers(aCommandBuffer, BindId, offsetCount, &VulkanMemoryBuffer.handle(), offsetList);
Mark Muellerdfe37552016-07-07 14:47:42 -0600813 BoundCurrent = true;
814
815 if (!aOffsetCount) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600816 delete[] offsetList;
Mark Muellerdfe37552016-07-07 14:47:42 -0600817 }
818 }
819
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700820 protected:
Mark Muellerdfe37552016-07-07 14:47:42 -0600821 static uint32_t BindIdGenerator;
822
823 bool BoundCurrent;
824 unsigned AttributeCount;
825 unsigned BindingCount;
826 uint32_t BindId;
827
828 VkPipelineVertexInputStateCreateInfo PipelineVertexInputStateCreateInfo;
829 VkVertexInputAttributeDescription *VertexInputAttributeDescription;
830 VkVertexInputBindingDescription *VertexInputBindingDescription;
831 VkConstantBufferObj VulkanMemoryBuffer;
832};
833
834uint32_t VkVerticesObj::BindIdGenerator;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500835// ********************************************************************************************************************
836// ********************************************************************************************************************
837// ********************************************************************************************************************
838// ********************************************************************************************************************
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600839TEST_F(VkLayerTest, RequiredParameter) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700840 TEST_DESCRIPTION(
841 "Specify VK_NULL_HANDLE, NULL, and 0 for required handle, "
842 "pointer, array, and array count parameters");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600843
Tony Barbour1fa09702017-03-16 12:09:08 -0600844 ASSERT_NO_FATAL_FAILURE(Init());
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600845
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600846 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pFeatures specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600847 // Specify NULL for a pointer to a handle
848 // Expected to trigger an error with
849 // parameter_validation::validate_required_pointer
850 vkGetPhysicalDeviceFeatures(gpu(), NULL);
851 m_errorMonitor->VerifyFound();
852
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600853 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
854 "required parameter pQueueFamilyPropertyCount specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600855 // Specify NULL for pointer to array count
856 // Expected to trigger an error with parameter_validation::validate_array
Dustin Gravesa4bb8c12016-05-16 17:22:51 -0600857 vkGetPhysicalDeviceQueueFamilyProperties(gpu(), NULL, NULL);
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600858 m_errorMonitor->VerifyFound();
859
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600860 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter viewportCount must be greater than 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600861 // Specify 0 for a required array count
862 // Expected to trigger an error with parameter_validation::validate_array
863 VkViewport view_port = {};
864 m_commandBuffer->SetViewport(0, 0, &view_port);
865 m_errorMonitor->VerifyFound();
866
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600867 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pViewports specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600868 // Specify NULL for a required array
869 // Expected to trigger an error with parameter_validation::validate_array
870 m_commandBuffer->SetViewport(0, 1, NULL);
871 m_errorMonitor->VerifyFound();
872
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600873 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter memory specified as VK_NULL_HANDLE");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600874 // Specify VK_NULL_HANDLE for a required handle
875 // Expected to trigger an error with
876 // parameter_validation::validate_required_handle
877 vkUnmapMemory(device(), VK_NULL_HANDLE);
878 m_errorMonitor->VerifyFound();
879
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600880 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
881 "required parameter pFences[0] specified as VK_NULL_HANDLE");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600882 // Specify VK_NULL_HANDLE for a required handle array entry
883 // Expected to trigger an error with
884 // parameter_validation::validate_required_handle_array
885 VkFence fence = VK_NULL_HANDLE;
886 vkResetFences(device(), 1, &fence);
887 m_errorMonitor->VerifyFound();
888
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600889 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pAllocateInfo specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600890 // Specify NULL for a required struct pointer
891 // Expected to trigger an error with
892 // parameter_validation::validate_struct_type
893 VkDeviceMemory memory = VK_NULL_HANDLE;
894 vkAllocateMemory(device(), NULL, NULL, &memory);
895 m_errorMonitor->VerifyFound();
896
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600897 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "value of faceMask must not be 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600898 // Specify 0 for a required VkFlags parameter
899 // Expected to trigger an error with parameter_validation::validate_flags
900 m_commandBuffer->SetStencilReference(0, 0);
901 m_errorMonitor->VerifyFound();
902
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600903 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "value of pSubmits[0].pWaitDstStageMask[0] must not be 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600904 // Specify 0 for a required VkFlags array entry
905 // Expected to trigger an error with
906 // parameter_validation::validate_flags_array
907 VkSemaphore semaphore = VK_NULL_HANDLE;
908 VkPipelineStageFlags stageFlags = 0;
909 VkSubmitInfo submitInfo = {};
910 submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
911 submitInfo.waitSemaphoreCount = 1;
912 submitInfo.pWaitSemaphores = &semaphore;
913 submitInfo.pWaitDstStageMask = &stageFlags;
914 vkQueueSubmit(m_device->m_queue, 1, &submitInfo, VK_NULL_HANDLE);
915 m_errorMonitor->VerifyFound();
916}
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600917
Dustin Gravesfce74c02016-05-10 11:42:58 -0600918TEST_F(VkLayerTest, ReservedParameter) {
919 TEST_DESCRIPTION("Specify a non-zero value for a reserved parameter");
920
Tony Barbour1fa09702017-03-16 12:09:08 -0600921 ASSERT_NO_FATAL_FAILURE(Init());
Dustin Gravesfce74c02016-05-10 11:42:58 -0600922
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600923 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " must be 0");
Dustin Gravesfce74c02016-05-10 11:42:58 -0600924 // Specify 0 for a reserved VkFlags parameter
925 // Expected to trigger an error with
926 // parameter_validation::validate_reserved_flags
927 VkEvent event_handle = VK_NULL_HANDLE;
928 VkEventCreateInfo event_info = {};
929 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
930 event_info.flags = 1;
931 vkCreateEvent(device(), &event_info, NULL, &event_handle);
932 m_errorMonitor->VerifyFound();
933}
934
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600935TEST_F(VkLayerTest, InvalidStructSType) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700936 TEST_DESCRIPTION(
937 "Specify an invalid VkStructureType for a Vulkan "
938 "structure's sType field");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600939
Tony Barbour1fa09702017-03-16 12:09:08 -0600940 ASSERT_NO_FATAL_FAILURE(Init());
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600941
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600942 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pAllocateInfo->sType must be");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600943 // Zero struct memory, effectively setting sType to
944 // VK_STRUCTURE_TYPE_APPLICATION_INFO
945 // Expected to trigger an error with
946 // parameter_validation::validate_struct_type
947 VkMemoryAllocateInfo alloc_info = {};
948 VkDeviceMemory memory = VK_NULL_HANDLE;
949 vkAllocateMemory(device(), &alloc_info, NULL, &memory);
950 m_errorMonitor->VerifyFound();
951
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600952 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pSubmits[0].sType must be");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600953 // Zero struct memory, effectively setting sType to
954 // VK_STRUCTURE_TYPE_APPLICATION_INFO
955 // Expected to trigger an error with
956 // parameter_validation::validate_struct_type_array
957 VkSubmitInfo submit_info = {};
958 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
959 m_errorMonitor->VerifyFound();
960}
961
962TEST_F(VkLayerTest, InvalidStructPNext) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600963 TEST_DESCRIPTION("Specify an invalid value for a Vulkan structure's pNext field");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600964
Tony Barbour1fa09702017-03-16 12:09:08 -0600965 ASSERT_NO_FATAL_FAILURE(Init());
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600966
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600967 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "value of pCreateInfo->pNext must be NULL");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600968 // Set VkMemoryAllocateInfo::pNext to a non-NULL value, when pNext must be NULL.
Karl Schultz38b50992016-07-11 16:09:09 -0600969 // Need to pick a function that has no allowed pNext structure types.
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600970 // Expected to trigger an error with parameter_validation::validate_struct_pnext
Karl Schultz38b50992016-07-11 16:09:09 -0600971 VkEvent event = VK_NULL_HANDLE;
Karl Schultz70db3902016-07-11 16:22:10 -0600972 VkEventCreateInfo event_alloc_info = {};
Karl Schultz38b50992016-07-11 16:09:09 -0600973 // Zero-initialization will provide the correct sType
974 VkApplicationInfo app_info = {};
975 event_alloc_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
976 event_alloc_info.pNext = &app_info;
977 vkCreateEvent(device(), &event_alloc_info, NULL, &event);
978 m_errorMonitor->VerifyFound();
979
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600980 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
981 " chain includes a structure with unexpected VkStructureType ");
Karl Schultz38b50992016-07-11 16:09:09 -0600982 // Set VkMemoryAllocateInfo::pNext to a non-NULL value, but use
983 // a function that has allowed pNext structure types and specify
984 // a structure type that is not allowed.
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600985 // Expected to trigger an error with parameter_validation::validate_struct_pnext
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600986 VkDeviceMemory memory = VK_NULL_HANDLE;
Dustin Graves47b6cba2016-05-10 17:34:38 -0600987 VkMemoryAllocateInfo memory_alloc_info = {};
988 memory_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
989 memory_alloc_info.pNext = &app_info;
990 vkAllocateMemory(device(), &memory_alloc_info, NULL, &memory);
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600991 m_errorMonitor->VerifyFound();
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600992}
Dustin Graves5d33d532016-05-09 16:21:12 -0600993
Chris Forbes93c08962017-05-19 11:25:59 -0700994TEST_F(VkLayerTest, UnrecognizedValueOutOfRange) {
Tony Barbour1fa09702017-03-16 12:09:08 -0600995 ASSERT_NO_FATAL_FAILURE(Init());
Dustin Graves5d33d532016-05-09 16:21:12 -0600996
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700997 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
998 "does not fall within the begin..end "
999 "range of the core VkFormat "
1000 "enumeration tokens");
Dustin Graves5d33d532016-05-09 16:21:12 -06001001 // Specify an invalid VkFormat value
1002 // Expected to trigger an error with
1003 // parameter_validation::validate_ranged_enum
1004 VkFormatProperties format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001005 vkGetPhysicalDeviceFormatProperties(gpu(), static_cast<VkFormat>(8000), &format_properties);
Dustin Graves5d33d532016-05-09 16:21:12 -06001006 m_errorMonitor->VerifyFound();
Chris Forbes93c08962017-05-19 11:25:59 -07001007}
1008
1009TEST_F(VkLayerTest, UnrecognizedValueBadMask) {
1010 ASSERT_NO_FATAL_FAILURE(Init());
Dustin Graves5d33d532016-05-09 16:21:12 -06001011
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001012 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "contains flag bits that are not recognized members of");
Dustin Graves5d33d532016-05-09 16:21:12 -06001013 // Specify an invalid VkFlags bitmask value
1014 // Expected to trigger an error with parameter_validation::validate_flags
1015 VkImageFormatProperties image_format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001016 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
1017 static_cast<VkImageUsageFlags>(1 << 25), 0, &image_format_properties);
Dustin Graves5d33d532016-05-09 16:21:12 -06001018 m_errorMonitor->VerifyFound();
Chris Forbes93c08962017-05-19 11:25:59 -07001019}
1020
1021TEST_F(VkLayerTest, UnrecognizedValueBadFlag) {
1022 ASSERT_NO_FATAL_FAILURE(Init());
Dustin Graves5d33d532016-05-09 16:21:12 -06001023
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001024 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "contains flag bits that are not recognized members of");
Dustin Graves5d33d532016-05-09 16:21:12 -06001025 // Specify an invalid VkFlags array entry
1026 // Expected to trigger an error with
1027 // parameter_validation::validate_flags_array
1028 VkSemaphore semaphore = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001029 VkPipelineStageFlags stage_flags = static_cast<VkPipelineStageFlags>(1 << 25);
Dustin Graves5d33d532016-05-09 16:21:12 -06001030 VkSubmitInfo submit_info = {};
1031 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1032 submit_info.waitSemaphoreCount = 1;
1033 submit_info.pWaitSemaphores = &semaphore;
1034 submit_info.pWaitDstStageMask = &stage_flags;
1035 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
1036 m_errorMonitor->VerifyFound();
Chris Forbes93c08962017-05-19 11:25:59 -07001037}
1038
1039TEST_F(VkLayerTest, UnrecognizedValueBadBool) {
1040 ASSERT_NO_FATAL_FAILURE(Init());
Dustin Graves5d33d532016-05-09 16:21:12 -06001041
Cort Strattonedbe9b82017-05-16 07:38:35 -07001042 // Sneak in a test to make sure using VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE
1043 // doesn't trigger a false positive.
1044 uint32_t extension_count = 0;
1045 bool supports_mirror_clamp = false;
1046 VkResult err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, nullptr);
1047 ASSERT_VK_SUCCESS(err);
1048 if (extension_count > 0) {
1049 std::vector<VkExtensionProperties> available_extensions(extension_count);
1050
1051 err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, &available_extensions[0]);
1052 ASSERT_VK_SUCCESS(err);
1053 for (const auto &extension_props : available_extensions) {
1054 if (strcmp(extension_props.extensionName, VK_KHR_SAMPLER_MIRROR_CLAMP_TO_EDGE_EXTENSION_NAME) == 0) {
1055 supports_mirror_clamp = true;
1056 }
1057 }
1058 }
1059 VkSamplerAddressMode address_mode = VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE;
1060 if (!supports_mirror_clamp) {
1061 printf(" mirror_clamp_to_edge Extension not supported, skipping tests\n");
1062 address_mode = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
Cort Strattonedbe9b82017-05-16 07:38:35 -07001063 }
1064
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001065 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "is neither VK_TRUE nor VK_FALSE");
Dustin Graves5d33d532016-05-09 16:21:12 -06001066 // Specify an invalid VkBool32 value
1067 // Expected to trigger a warning with
1068 // parameter_validation::validate_bool32
1069 VkSampler sampler = VK_NULL_HANDLE;
1070 VkSamplerCreateInfo sampler_info = {};
1071 sampler_info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
1072 sampler_info.pNext = NULL;
1073 sampler_info.magFilter = VK_FILTER_NEAREST;
1074 sampler_info.minFilter = VK_FILTER_NEAREST;
1075 sampler_info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
Cort Strattonedbe9b82017-05-16 07:38:35 -07001076 sampler_info.addressModeU = address_mode;
1077 sampler_info.addressModeV = address_mode;
1078 sampler_info.addressModeW = address_mode;
Dustin Graves5d33d532016-05-09 16:21:12 -06001079 sampler_info.mipLodBias = 1.0;
1080 sampler_info.maxAnisotropy = 1;
1081 sampler_info.compareEnable = VK_FALSE;
1082 sampler_info.compareOp = VK_COMPARE_OP_NEVER;
1083 sampler_info.minLod = 1.0;
1084 sampler_info.maxLod = 1.0;
1085 sampler_info.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
1086 sampler_info.unnormalizedCoordinates = VK_FALSE;
1087 // Not VK_TRUE or VK_FALSE
1088 sampler_info.anisotropyEnable = 3;
1089 vkCreateSampler(m_device->device(), &sampler_info, NULL, &sampler);
1090 m_errorMonitor->VerifyFound();
Chris Forbes93c08962017-05-19 11:25:59 -07001091}
1092
1093#if 0
1094TEST_F(VkLayerTest, UnrecognizedValueMaxEnum) {
1095 ASSERT_NO_FATAL_FAILURE(Init());
Cort Strattonedbe9b82017-05-16 07:38:35 -07001096
1097 // Specify MAX_ENUM
1098 VkDescriptorSetLayoutBinding binding = {};
1099 binding.binding = 0;
1100 binding.descriptorType = VK_DESCRIPTOR_TYPE_MAX_ENUM;
1101 binding.descriptorCount = 1;
1102 binding.stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
1103 VkDescriptorSetLayoutCreateInfo layout_ci = {};
1104 layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1105 layout_ci.bindingCount = 1;
1106 layout_ci.pBindings = &binding;
1107 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "does not fall within the begin..end range");
1108 VkDescriptorSetLayout layout = VK_NULL_HANDLE;
1109 vkCreateDescriptorSetLayout(device(), &layout_ci, NULL, &layout);
1110 m_errorMonitor->VerifyFound();
1111 if (layout != VK_NULL_HANDLE) {
1112 vkDestroyDescriptorSetLayout(device(), layout, NULL);
1113 }
Dustin Graves5d33d532016-05-09 16:21:12 -06001114}
Chris Forbes93c08962017-05-19 11:25:59 -07001115#endif
Dustin Gravesfce74c02016-05-10 11:42:58 -06001116
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001117TEST_F(VkLayerTest, UpdateBufferAlignment) {
1118 TEST_DESCRIPTION("Check alignment parameters for vkCmdUpdateBuffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001119 uint32_t updateData[] = {1, 2, 3, 4, 5, 6, 7, 8};
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001120
Tony Barbour1fa09702017-03-16 12:09:08 -06001121 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001122
1123 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1124 vk_testing::Buffer buffer;
1125 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
1126
Tony Barbour552f6c02016-12-21 14:34:07 -07001127 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001128 // Introduce failure by using dstOffset that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001129 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001130 m_commandBuffer->UpdateBuffer(buffer.handle(), 1, 4, updateData);
1131 m_errorMonitor->VerifyFound();
1132
1133 // Introduce failure by using dataSize that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001134 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001135 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 6, updateData);
1136 m_errorMonitor->VerifyFound();
1137
1138 // Introduce failure by using dataSize that is < 0
1139 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001140 "must be greater than zero and less than or equal to 65536");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001141 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, -44, updateData);
1142 m_errorMonitor->VerifyFound();
1143
1144 // Introduce failure by using dataSize that is > 65536
1145 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001146 "must be greater than zero and less than or equal to 65536");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001147 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 80000, updateData);
1148 m_errorMonitor->VerifyFound();
1149
Tony Barbour552f6c02016-12-21 14:34:07 -07001150 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001151}
1152
1153TEST_F(VkLayerTest, FillBufferAlignment) {
1154 TEST_DESCRIPTION("Check alignment parameters for vkCmdFillBuffer");
1155
Tony Barbour1fa09702017-03-16 12:09:08 -06001156 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001157
1158 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1159 vk_testing::Buffer buffer;
1160 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
1161
Tony Barbour552f6c02016-12-21 14:34:07 -07001162 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001163
1164 // Introduce failure by using dstOffset that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001165 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001166 m_commandBuffer->FillBuffer(buffer.handle(), 1, 4, 0x11111111);
1167 m_errorMonitor->VerifyFound();
1168
1169 // Introduce failure by using size that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001170 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001171 m_commandBuffer->FillBuffer(buffer.handle(), 0, 6, 0x11111111);
1172 m_errorMonitor->VerifyFound();
1173
1174 // Introduce failure by using size that is zero
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001175 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must be greater than zero");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001176 m_commandBuffer->FillBuffer(buffer.handle(), 0, 0, 0x11111111);
1177 m_errorMonitor->VerifyFound();
1178
Tony Barbour552f6c02016-12-21 14:34:07 -07001179 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001180}
Dustin Graves40f35822016-06-23 11:12:53 -06001181
Cortd889ff92016-07-27 09:51:27 -07001182TEST_F(VkLayerTest, PSOPolygonModeInvalid) {
1183 VkResult err;
1184
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001185 TEST_DESCRIPTION(
1186 "Attempt to use a non-solid polygon fill mode in a "
1187 "pipeline when this feature is not enabled.");
Cortd889ff92016-07-27 09:51:27 -07001188
Tony Barbour1fa09702017-03-16 12:09:08 -06001189 ASSERT_NO_FATAL_FAILURE(Init());
Cortd889ff92016-07-27 09:51:27 -07001190 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1191
1192 std::vector<const char *> device_extension_names;
1193 auto features = m_device->phy().features();
1194 // Artificially disable support for non-solid fill modes
Chris Forbes05054022017-05-17 16:29:06 -07001195 features.fillModeNonSolid = VK_FALSE;
Cortd889ff92016-07-27 09:51:27 -07001196 // The sacrificial device object
1197 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
1198
1199 VkRenderpassObj render_pass(&test_device);
1200
1201 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1202 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1203 pipeline_layout_ci.setLayoutCount = 0;
1204 pipeline_layout_ci.pSetLayouts = NULL;
1205
1206 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001207 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Cortd889ff92016-07-27 09:51:27 -07001208 ASSERT_VK_SUCCESS(err);
1209
1210 VkPipelineRasterizationStateCreateInfo rs_ci = {};
1211 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
1212 rs_ci.pNext = nullptr;
1213 rs_ci.lineWidth = 1.0f;
Chris Forbes05054022017-05-17 16:29:06 -07001214 rs_ci.rasterizerDiscardEnable = VK_TRUE;
Cortd889ff92016-07-27 09:51:27 -07001215
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001216 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
1217 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Cortd889ff92016-07-27 09:51:27 -07001218
Mark Lobodzinski5e644732016-08-15 16:51:19 -06001219 // Set polygonMode to unsupported value POINT, should fail
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001220 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1221 "polygonMode cannot be VK_POLYGON_MODE_POINT or VK_POLYGON_MODE_LINE");
Cortd889ff92016-07-27 09:51:27 -07001222 {
1223 VkPipelineObj pipe(&test_device);
1224 pipe.AddShader(&vs);
1225 pipe.AddShader(&fs);
1226 pipe.AddColorAttachment();
1227 // Introduce failure by setting unsupported polygon mode
1228 rs_ci.polygonMode = VK_POLYGON_MODE_POINT;
1229 pipe.SetRasterization(&rs_ci);
1230 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
1231 }
1232 m_errorMonitor->VerifyFound();
1233
1234 // Try again with polygonMode=LINE, should fail
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001235 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1236 "polygonMode cannot be VK_POLYGON_MODE_POINT or VK_POLYGON_MODE_LINE");
Cortd889ff92016-07-27 09:51:27 -07001237 {
1238 VkPipelineObj pipe(&test_device);
1239 pipe.AddShader(&vs);
1240 pipe.AddShader(&fs);
1241 pipe.AddColorAttachment();
1242 // Introduce failure by setting unsupported polygon mode
1243 rs_ci.polygonMode = VK_POLYGON_MODE_LINE;
1244 pipe.SetRasterization(&rs_ci);
1245 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
1246 }
1247 m_errorMonitor->VerifyFound();
1248
Cortd889ff92016-07-27 09:51:27 -07001249 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
1250}
1251
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001252#if 0
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001253TEST_F(VkLayerTest, CallResetCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001254{
1255 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001256 VkFenceCreateInfo fenceInfo = {};
1257 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1258 fenceInfo.pNext = NULL;
1259 fenceInfo.flags = 0;
1260
Mike Weiblencce7ec72016-10-17 19:33:05 -06001261 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Resetting command buffer");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001262
Tony Barbour1fa09702017-03-16 12:09:08 -06001263 ASSERT_NO_FATAL_FAILURE(Init());
Tony Barbourc1eb1a52015-07-20 13:00:10 -06001264
1265 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1266 vk_testing::Buffer buffer;
1267 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001268
Tony Barbourfe3351b2015-07-28 10:17:20 -06001269 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001270 m_commandBuffer->FillBuffer(buffer.handle(), 0, 4, 0x11111111);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001271 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001272
1273 testFence.init(*m_device, fenceInfo);
1274
1275 // Bypass framework since it does the waits automatically
1276 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001277 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001278 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1279 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001280 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001281 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001282 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001283 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001284 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001285 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001286 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001287
1288 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001289 ASSERT_VK_SUCCESS( err );
1290
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001291 // Introduce failure by calling begin again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001292 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001293
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001294 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001295}
1296
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001297TEST_F(VkLayerTest, CallBeginCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001298{
1299 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001300 VkFenceCreateInfo fenceInfo = {};
1301 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1302 fenceInfo.pNext = NULL;
1303 fenceInfo.flags = 0;
1304
Mike Weiblencce7ec72016-10-17 19:33:05 -06001305 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Calling vkBeginCommandBuffer() on active command buffer");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001306
Tony Barbour1fa09702017-03-16 12:09:08 -06001307 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001308 ASSERT_NO_FATAL_FAILURE(InitViewport());
1309 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1310
Tony Barbourfe3351b2015-07-28 10:17:20 -06001311 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001312 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001313 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001314
1315 testFence.init(*m_device, fenceInfo);
1316
1317 // Bypass framework since it does the waits automatically
1318 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001319 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001320 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1321 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001322 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001323 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001324 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001325 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001326 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001327 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001328 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001329
1330 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001331 ASSERT_VK_SUCCESS( err );
1332
Jon Ashburnf19916e2016-01-11 13:12:43 -07001333 VkCommandBufferInheritanceInfo hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001334 VkCommandBufferBeginInfo info = {};
1335 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
1336 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001337 info.renderPass = VK_NULL_HANDLE;
1338 info.subpass = 0;
1339 info.framebuffer = VK_NULL_HANDLE;
Chia-I Wub8d47ae2015-11-11 10:18:12 +08001340 info.occlusionQueryEnable = VK_FALSE;
1341 info.queryFlags = 0;
1342 info.pipelineStatistics = 0;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001343
1344 // Introduce failure by calling BCB again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001345 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001346
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001347 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001348}
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001349#endif
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001350
Mark Lobodzinski833bb552016-12-15 07:41:13 -07001351TEST_F(VkLayerTest, SparseBindingImageBufferCreate) {
1352 TEST_DESCRIPTION("Create buffer/image with sparse attributes but without the sparse_binding bit set");
1353
Tony Barbour1fa09702017-03-16 12:09:08 -06001354 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski833bb552016-12-15 07:41:13 -07001355
1356 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00669);
1357 VkBuffer buffer;
1358 VkBufferCreateInfo buf_info = {};
1359 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1360 buf_info.pNext = NULL;
1361 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
1362 buf_info.size = 2048;
1363 buf_info.queueFamilyIndexCount = 0;
1364 buf_info.pQueueFamilyIndices = NULL;
1365 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1366 buf_info.flags = VK_BUFFER_CREATE_SPARSE_RESIDENCY_BIT;
1367 vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1368 m_errorMonitor->VerifyFound();
1369
1370 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02160);
1371 VkImage image;
1372 VkImageCreateInfo image_create_info = {};
1373 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1374 image_create_info.pNext = NULL;
1375 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1376 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1377 image_create_info.extent.width = 512;
1378 image_create_info.extent.height = 64;
1379 image_create_info.extent.depth = 1;
1380 image_create_info.mipLevels = 1;
1381 image_create_info.arrayLayers = 1;
1382 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1383 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
1384 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1385 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1386 image_create_info.queueFamilyIndexCount = 0;
1387 image_create_info.pQueueFamilyIndices = NULL;
1388 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1389 image_create_info.flags = VK_BUFFER_CREATE_SPARSE_ALIASED_BIT;
1390 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1391 m_errorMonitor->VerifyFound();
1392}
1393
Dave Houlton829c0d82017-01-24 15:09:17 -07001394TEST_F(VkLayerTest, SparseResidencyImageCreateUnsupportedTypes) {
1395 TEST_DESCRIPTION("Create images with sparse residency with unsupported types");
1396
1397 // Determine which device feature are available
Dave Houlton0ba0fdf2017-03-29 12:05:26 -06001398 VkPhysicalDeviceFeatures device_features = {};
Dave Houlton8e0fe7a2017-03-30 10:32:10 -06001399 ASSERT_NO_FATAL_FAILURE(
1400 InitFramework(instance_layer_names, instance_extension_names, device_extension_names, myDbgFunc, m_errorMonitor));
Dave Houlton0ba0fdf2017-03-29 12:05:26 -06001401 ASSERT_NO_FATAL_FAILURE(GetPhysicalDeviceFeatures(&device_features));
Dave Houlton829c0d82017-01-24 15:09:17 -07001402
Dave Houlton8e0fe7a2017-03-30 10:32:10 -06001403 // Mask out device features we don't want and initialize device state
Dave Houlton0ba0fdf2017-03-29 12:05:26 -06001404 device_features.sparseResidencyImage2D = VK_FALSE;
1405 device_features.sparseResidencyImage3D = VK_FALSE;
Dave Houlton8e0fe7a2017-03-30 10:32:10 -06001406 ASSERT_NO_FATAL_FAILURE(InitState(&device_features));
Dave Houlton829c0d82017-01-24 15:09:17 -07001407
1408 VkImage image = VK_NULL_HANDLE;
1409 VkResult result = VK_RESULT_MAX_ENUM;
1410 VkImageCreateInfo image_create_info = {};
1411 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1412 image_create_info.pNext = NULL;
1413 image_create_info.imageType = VK_IMAGE_TYPE_1D;
1414 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1415 image_create_info.extent.width = 512;
1416 image_create_info.extent.height = 1;
1417 image_create_info.extent.depth = 1;
1418 image_create_info.mipLevels = 1;
1419 image_create_info.arrayLayers = 1;
1420 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1421 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
1422 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1423 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1424 image_create_info.queueFamilyIndexCount = 0;
1425 image_create_info.pQueueFamilyIndices = NULL;
1426 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1427 image_create_info.flags = VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT | VK_BUFFER_CREATE_SPARSE_BINDING_BIT;
1428
1429 // 1D image w/ sparse residency is an error
1430 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02352);
1431 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1432 m_errorMonitor->VerifyFound();
1433 if (VK_SUCCESS == result) {
1434 vkDestroyImage(m_device->device(), image, NULL);
1435 image = VK_NULL_HANDLE;
1436 }
1437
1438 // 2D image w/ sparse residency when feature isn't available
1439 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1440 image_create_info.extent.height = 64;
1441 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02144);
1442 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1443 m_errorMonitor->VerifyFound();
1444 if (VK_SUCCESS == result) {
1445 vkDestroyImage(m_device->device(), image, NULL);
1446 image = VK_NULL_HANDLE;
1447 }
1448
1449 // 3D image w/ sparse residency when feature isn't available
1450 image_create_info.imageType = VK_IMAGE_TYPE_3D;
1451 image_create_info.extent.depth = 8;
1452 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02145);
1453 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1454 m_errorMonitor->VerifyFound();
1455 if (VK_SUCCESS == result) {
1456 vkDestroyImage(m_device->device(), image, NULL);
1457 image = VK_NULL_HANDLE;
1458 }
1459}
1460
1461TEST_F(VkLayerTest, SparseResidencyImageCreateUnsupportedSamples) {
1462 TEST_DESCRIPTION("Create images with sparse residency with unsupported tiling or sample counts");
1463
1464 // Determine which device feature are available
Dave Houlton0ba0fdf2017-03-29 12:05:26 -06001465 VkPhysicalDeviceFeatures device_features = {};
Dave Houlton8e0fe7a2017-03-30 10:32:10 -06001466 ASSERT_NO_FATAL_FAILURE(
1467 InitFramework(instance_layer_names, instance_extension_names, device_extension_names, myDbgFunc, m_errorMonitor));
Dave Houlton0ba0fdf2017-03-29 12:05:26 -06001468 ASSERT_NO_FATAL_FAILURE(GetPhysicalDeviceFeatures(&device_features));
Dave Houlton829c0d82017-01-24 15:09:17 -07001469
Dave Houlton0ba0fdf2017-03-29 12:05:26 -06001470 // These tests require that the device support sparse residency for 2D images
1471 if (VK_TRUE != device_features.sparseResidencyImage2D) {
1472 printf(" Test requires unsupported SparseResidencyImage2D feature. Skipped.\n");
Dave Houlton829c0d82017-01-24 15:09:17 -07001473 return;
1474 }
1475
Dave Houlton8e0fe7a2017-03-30 10:32:10 -06001476 // Mask out device features we don't want and initialize device state
Dave Houlton0ba0fdf2017-03-29 12:05:26 -06001477 device_features.sparseResidency2Samples = VK_FALSE;
1478 device_features.sparseResidency4Samples = VK_FALSE;
1479 device_features.sparseResidency8Samples = VK_FALSE;
1480 device_features.sparseResidency16Samples = VK_FALSE;
Dave Houlton8e0fe7a2017-03-30 10:32:10 -06001481 ASSERT_NO_FATAL_FAILURE(InitState(&device_features));
Dave Houlton829c0d82017-01-24 15:09:17 -07001482
1483 VkImage image = VK_NULL_HANDLE;
1484 VkResult result = VK_RESULT_MAX_ENUM;
1485 VkImageCreateInfo image_create_info = {};
1486 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1487 image_create_info.pNext = NULL;
1488 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1489 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1490 image_create_info.extent.width = 64;
1491 image_create_info.extent.height = 64;
1492 image_create_info.extent.depth = 1;
1493 image_create_info.mipLevels = 1;
1494 image_create_info.arrayLayers = 1;
1495 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1496 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1497 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1498 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1499 image_create_info.queueFamilyIndexCount = 0;
1500 image_create_info.pQueueFamilyIndices = NULL;
1501 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1502 image_create_info.flags = VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT | VK_BUFFER_CREATE_SPARSE_BINDING_BIT;
1503
1504 // 2D image w/ sparse residency and linear tiling is an error
1505 m_errorMonitor->SetDesiredFailureMsg(
1506 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1507 "VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT then image tiling of VK_IMAGE_TILING_LINEAR is not supported");
1508 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1509 m_errorMonitor->VerifyFound();
1510 if (VK_SUCCESS == result) {
1511 vkDestroyImage(m_device->device(), image, NULL);
1512 image = VK_NULL_HANDLE;
1513 }
1514 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
1515
1516 // Multi-sample image w/ sparse residency when feature isn't available (4 flavors)
1517 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
1518 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02146);
1519 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1520 m_errorMonitor->VerifyFound();
1521 if (VK_SUCCESS == result) {
1522 vkDestroyImage(m_device->device(), image, NULL);
1523 image = VK_NULL_HANDLE;
1524 }
1525
1526 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
1527 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02147);
1528 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1529 m_errorMonitor->VerifyFound();
1530 if (VK_SUCCESS == result) {
1531 vkDestroyImage(m_device->device(), image, NULL);
1532 image = VK_NULL_HANDLE;
1533 }
1534
1535 image_create_info.samples = VK_SAMPLE_COUNT_8_BIT;
1536 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02148);
1537 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1538 m_errorMonitor->VerifyFound();
1539 if (VK_SUCCESS == result) {
1540 vkDestroyImage(m_device->device(), image, NULL);
1541 image = VK_NULL_HANDLE;
1542 }
1543
1544 image_create_info.samples = VK_SAMPLE_COUNT_16_BIT;
1545 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02149);
1546 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1547 m_errorMonitor->VerifyFound();
1548 if (VK_SUCCESS == result) {
1549 vkDestroyImage(m_device->device(), image, NULL);
1550 image = VK_NULL_HANDLE;
1551 }
1552}
1553
Tobin Ehlisf11be982016-05-11 13:52:53 -06001554TEST_F(VkLayerTest, InvalidMemoryAliasing) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001555 TEST_DESCRIPTION(
1556 "Create a buffer and image, allocate memory, and bind the "
1557 "buffer and image to memory such that they will alias.");
Tobin Ehlisf11be982016-05-11 13:52:53 -06001558 VkResult err;
1559 bool pass;
Tony Barbour1fa09702017-03-16 12:09:08 -06001560 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisf11be982016-05-11 13:52:53 -06001561
Tobin Ehlis077ded32016-05-12 17:39:13 -06001562 VkBuffer buffer, buffer2;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001563 VkImage image;
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001564 VkImage image2;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001565 VkDeviceMemory mem; // buffer will be bound first
1566 VkDeviceMemory mem_img; // image bound first
Tobin Ehlis077ded32016-05-12 17:39:13 -06001567 VkMemoryRequirements buff_mem_reqs, img_mem_reqs;
Rene Lindsayd14f5572016-12-16 14:57:18 -07001568 VkMemoryRequirements buff_mem_reqs2, img_mem_reqs2;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001569
1570 VkBufferCreateInfo buf_info = {};
1571 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1572 buf_info.pNext = NULL;
1573 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1574 buf_info.size = 256;
1575 buf_info.queueFamilyIndexCount = 0;
1576 buf_info.pQueueFamilyIndices = NULL;
1577 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1578 buf_info.flags = 0;
1579 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1580 ASSERT_VK_SUCCESS(err);
1581
Tobin Ehlis077ded32016-05-12 17:39:13 -06001582 vkGetBufferMemoryRequirements(m_device->device(), buffer, &buff_mem_reqs);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001583
1584 VkImageCreateInfo image_create_info = {};
1585 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1586 image_create_info.pNext = NULL;
1587 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1588 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1589 image_create_info.extent.width = 64;
1590 image_create_info.extent.height = 64;
1591 image_create_info.extent.depth = 1;
1592 image_create_info.mipLevels = 1;
1593 image_create_info.arrayLayers = 1;
1594 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis12a4b5e2016-08-08 12:33:11 -06001595 // Image tiling must be optimal to trigger error when aliasing linear buffer
1596 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001597 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1598 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1599 image_create_info.queueFamilyIndexCount = 0;
1600 image_create_info.pQueueFamilyIndices = NULL;
1601 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1602 image_create_info.flags = 0;
1603
Tobin Ehlisf11be982016-05-11 13:52:53 -06001604 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1605 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001606 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
1607 ASSERT_VK_SUCCESS(err);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001608
Tobin Ehlis077ded32016-05-12 17:39:13 -06001609 vkGetImageMemoryRequirements(m_device->device(), image, &img_mem_reqs);
1610
1611 VkMemoryAllocateInfo alloc_info = {};
1612 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1613 alloc_info.pNext = NULL;
1614 alloc_info.memoryTypeIndex = 0;
1615 // Ensure memory is big enough for both bindings
1616 alloc_info.allocationSize = buff_mem_reqs.size + img_mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001617 pass = m_device->phy().set_memory_type(buff_mem_reqs.memoryTypeBits & img_mem_reqs.memoryTypeBits, &alloc_info,
1618 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001619 if (!pass) {
Tobin Ehlis077ded32016-05-12 17:39:13 -06001620 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001621 vkDestroyImage(m_device->device(), image, NULL);
Mark Lobodzinskid2d2d4c2017-02-16 11:51:58 -07001622 vkDestroyImage(m_device->device(), image2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001623 return;
1624 }
Tobin Ehlis077ded32016-05-12 17:39:13 -06001625 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1626 ASSERT_VK_SUCCESS(err);
1627 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
1628 ASSERT_VK_SUCCESS(err);
1629
Rene Lindsayd14f5572016-12-16 14:57:18 -07001630 vkGetImageMemoryRequirements(m_device->device(), image2, &img_mem_reqs2);
1631
Tobin Ehlis32b2bbc2016-12-13 17:33:41 -07001632 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " is aliased with linear buffer 0x");
Tobin Ehlis077ded32016-05-12 17:39:13 -06001633 // VALIDATION FAILURE due to image mapping overlapping buffer mapping
Tobin Ehlisf11be982016-05-11 13:52:53 -06001634 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1635 m_errorMonitor->VerifyFound();
1636
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001637 // Now correctly bind image2 to second mem allocation before incorrectly
Tobin Ehlis077ded32016-05-12 17:39:13 -06001638 // aliasing buffer2
1639 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer2);
1640 ASSERT_VK_SUCCESS(err);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001641 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem_img);
1642 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001643 err = vkBindImageMemory(m_device->device(), image2, mem_img, 0);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001644 ASSERT_VK_SUCCESS(err);
Tobin Ehlis32b2bbc2016-12-13 17:33:41 -07001645 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "is aliased with non-linear image 0x");
Rene Lindsayd14f5572016-12-16 14:57:18 -07001646 vkGetBufferMemoryRequirements(m_device->device(), buffer2, &buff_mem_reqs2);
Tobin Ehlis077ded32016-05-12 17:39:13 -06001647 err = vkBindBufferMemory(m_device->device(), buffer2, mem_img, 0);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001648 m_errorMonitor->VerifyFound();
1649
1650 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlis077ded32016-05-12 17:39:13 -06001651 vkDestroyBuffer(m_device->device(), buffer2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001652 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001653 vkDestroyImage(m_device->device(), image2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001654 vkFreeMemory(m_device->device(), mem, NULL);
1655 vkFreeMemory(m_device->device(), mem_img, NULL);
1656}
1657
Tobin Ehlis35372522016-05-12 08:32:31 -06001658TEST_F(VkLayerTest, InvalidMemoryMapping) {
1659 TEST_DESCRIPTION("Attempt to map memory in a number of incorrect ways");
1660 VkResult err;
1661 bool pass;
Tony Barbour1fa09702017-03-16 12:09:08 -06001662 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis35372522016-05-12 08:32:31 -06001663
1664 VkBuffer buffer;
1665 VkDeviceMemory mem;
1666 VkMemoryRequirements mem_reqs;
1667
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001668 const VkDeviceSize atom_size = m_device->props.limits.nonCoherentAtomSize;
1669
Tobin Ehlis35372522016-05-12 08:32:31 -06001670 VkBufferCreateInfo buf_info = {};
1671 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1672 buf_info.pNext = NULL;
1673 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1674 buf_info.size = 256;
1675 buf_info.queueFamilyIndexCount = 0;
1676 buf_info.pQueueFamilyIndices = NULL;
1677 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1678 buf_info.flags = 0;
1679 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1680 ASSERT_VK_SUCCESS(err);
1681
1682 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
1683 VkMemoryAllocateInfo alloc_info = {};
1684 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1685 alloc_info.pNext = NULL;
1686 alloc_info.memoryTypeIndex = 0;
1687
1688 // Ensure memory is big enough for both bindings
1689 static const VkDeviceSize allocation_size = 0x10000;
1690 alloc_info.allocationSize = allocation_size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001691 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Tobin Ehlis35372522016-05-12 08:32:31 -06001692 if (!pass) {
1693 vkDestroyBuffer(m_device->device(), buffer, NULL);
1694 return;
1695 }
1696 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1697 ASSERT_VK_SUCCESS(err);
1698
1699 uint8_t *pData;
1700 // Attempt to map memory size 0 is invalid
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001701 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VkMapMemory: Attempting to map memory range of size zero");
Tobin Ehlis35372522016-05-12 08:32:31 -06001702 err = vkMapMemory(m_device->device(), mem, 0, 0, 0, (void **)&pData);
1703 m_errorMonitor->VerifyFound();
1704 // Map memory twice
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001705 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001706 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001707 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1708 "VkMapMemory: Attempting to map memory on an already-mapped object ");
1709 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001710 m_errorMonitor->VerifyFound();
1711
1712 // Unmap the memory to avoid re-map error
1713 vkUnmapMemory(m_device->device(), mem);
1714 // overstep allocation with VK_WHOLE_SIZE
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001715 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1716 " with size of VK_WHOLE_SIZE oversteps total array size 0x");
1717 err = vkMapMemory(m_device->device(), mem, allocation_size + 1, VK_WHOLE_SIZE, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001718 m_errorMonitor->VerifyFound();
1719 // overstep allocation w/o VK_WHOLE_SIZE
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001720 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " oversteps total array size 0x");
1721 err = vkMapMemory(m_device->device(), mem, 1, allocation_size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001722 m_errorMonitor->VerifyFound();
1723 // Now error due to unmapping memory that's not mapped
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001724 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Unmapping Memory without memory being mapped: ");
Tobin Ehlis35372522016-05-12 08:32:31 -06001725 vkUnmapMemory(m_device->device(), mem);
1726 m_errorMonitor->VerifyFound();
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001727
Tobin Ehlis35372522016-05-12 08:32:31 -06001728 // Now map memory and cause errors due to flushing invalid ranges
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001729 err = vkMapMemory(m_device->device(), mem, 4 * atom_size, VK_WHOLE_SIZE, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001730 ASSERT_VK_SUCCESS(err);
1731 VkMappedMemoryRange mmr = {};
Chris Forbes3aec0892016-06-13 10:29:26 +12001732 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
Tobin Ehlis35372522016-05-12 08:32:31 -06001733 mmr.memory = mem;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001734 mmr.offset = atom_size; // Error b/c offset less than offset of mapped mem
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001735 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00642);
Tobin Ehlis35372522016-05-12 08:32:31 -06001736 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1737 m_errorMonitor->VerifyFound();
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001738
Tobin Ehlis35372522016-05-12 08:32:31 -06001739 // Now flush range that oversteps mapped range
1740 vkUnmapMemory(m_device->device(), mem);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001741 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001742 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001743 mmr.offset = atom_size;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001744 mmr.size = 4 * atom_size; // Flushing bounds exceed mapped bounds
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001745 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00642);
1746 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1747 m_errorMonitor->VerifyFound();
1748
1749 // Now flush range with VK_WHOLE_SIZE that oversteps offset
1750 vkUnmapMemory(m_device->device(), mem);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001751 err = vkMapMemory(m_device->device(), mem, 2 * atom_size, 4 * atom_size, 0, (void **)&pData);
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001752 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001753 mmr.offset = atom_size;
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001754 mmr.size = VK_WHOLE_SIZE;
1755 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00643);
Tobin Ehlis35372522016-05-12 08:32:31 -06001756 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1757 m_errorMonitor->VerifyFound();
1758
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001759#if 0 // Planning discussion with working group on this validation check.
Mark Lobodzinski3826a4f2016-11-15 09:38:51 -07001760 // Some platforms have an atomsize of 1 which makes the test meaningless
1761 if (atom_size > 3) {
1762 // Now with an offset NOT a multiple of the device limit
1763 vkUnmapMemory(m_device->device(), mem);
1764 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
1765 ASSERT_VK_SUCCESS(err);
1766 mmr.offset = 3; // Not a multiple of atom_size
1767 mmr.size = VK_WHOLE_SIZE;
1768 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00644);
1769 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1770 m_errorMonitor->VerifyFound();
1771
1772 // Now with a size NOT a multiple of the device limit
1773 vkUnmapMemory(m_device->device(), mem);
1774 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
1775 ASSERT_VK_SUCCESS(err);
1776 mmr.offset = atom_size;
1777 mmr.size = 2 * atom_size + 1; // Not a multiple of atom_size
1778 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00645);
1779 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1780 m_errorMonitor->VerifyFound();
1781 }
Tony Barboure3975eb2016-12-15 14:52:44 -07001782#endif
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001783 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
1784 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Tobin Ehlis35372522016-05-12 08:32:31 -06001785 if (!pass) {
1786 vkFreeMemory(m_device->device(), mem, NULL);
1787 vkDestroyBuffer(m_device->device(), buffer, NULL);
1788 return;
1789 }
1790 // TODO : If we can get HOST_VISIBLE w/o HOST_COHERENT we can test cases of
1791 // MEMTRACK_INVALID_MAP in validateAndCopyNoncoherentMemoryToDriver()
1792
1793 vkDestroyBuffer(m_device->device(), buffer, NULL);
1794 vkFreeMemory(m_device->device(), mem, NULL);
1795}
1796
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001797#if 0 // disabled until PV gets real extension enable checks
Ian Elliott1c32c772016-04-28 14:47:13 -06001798TEST_F(VkLayerTest, EnableWsiBeforeUse) {
1799 VkResult err;
1800 bool pass;
1801
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001802 // FIXME: After we turn on this code for non-Linux platforms, uncomment the
1803 // following declaration (which is temporarily being moved below):
1804 // VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott1c32c772016-04-28 14:47:13 -06001805 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001806 VkSwapchainCreateInfoKHR swapchain_create_info = {VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR};
Ian Elliott1c32c772016-04-28 14:47:13 -06001807 uint32_t swapchain_image_count = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001808 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
Ian Elliott1c32c772016-04-28 14:47:13 -06001809 uint32_t image_index = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001810 // VkPresentInfoKHR present_info = {};
Ian Elliott1c32c772016-04-28 14:47:13 -06001811
Tony Barbour1fa09702017-03-16 12:09:08 -06001812 ASSERT_NO_FATAL_FAILURE(Init());
Ian Elliott1c32c772016-04-28 14:47:13 -06001813
Ian Elliott3f06ce52016-04-29 14:46:21 -06001814#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
1815#if defined(VK_USE_PLATFORM_ANDROID_KHR)
1816 // Use the functions from the VK_KHR_android_surface extension without
1817 // enabling that extension:
1818
1819 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001820 VkAndroidSurfaceCreateInfoKHR android_create_info = {VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001821 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1822 err = vkCreateAndroidSurfaceKHR(instance(), &android_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001823 pass = (err != VK_SUCCESS);
1824 ASSERT_TRUE(pass);
1825 m_errorMonitor->VerifyFound();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001826#endif // VK_USE_PLATFORM_ANDROID_KHR
Ian Elliott3f06ce52016-04-29 14:46:21 -06001827
Ian Elliott3f06ce52016-04-29 14:46:21 -06001828#if defined(VK_USE_PLATFORM_MIR_KHR)
1829 // Use the functions from the VK_KHR_mir_surface extension without enabling
1830 // that extension:
1831
1832 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001833 VkMirSurfaceCreateInfoKHR mir_create_info = {VK_STRUCTURE_TYPE_MIR_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001834 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott3f06ce52016-04-29 14:46:21 -06001835 err = vkCreateMirSurfaceKHR(instance(), &mir_create_info, NULL, &surface);
1836 pass = (err != VK_SUCCESS);
1837 ASSERT_TRUE(pass);
1838 m_errorMonitor->VerifyFound();
1839
1840 // Tell whether an mir_connection supports presentation:
1841 MirConnection *mir_connection = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001842 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1843 vkGetPhysicalDeviceMirPresentationSupportKHR(gpu(), 0, mir_connection, visual_id);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001844 m_errorMonitor->VerifyFound();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001845#endif // VK_USE_PLATFORM_MIR_KHR
Ian Elliott3f06ce52016-04-29 14:46:21 -06001846
Ian Elliott3f06ce52016-04-29 14:46:21 -06001847#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
1848 // Use the functions from the VK_KHR_wayland_surface extension without
1849 // enabling that extension:
1850
1851 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001852 VkWaylandSurfaceCreateInfoKHR wayland_create_info = {VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001853 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1854 err = vkCreateWaylandSurfaceKHR(instance(), &wayland_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001855 pass = (err != VK_SUCCESS);
1856 ASSERT_TRUE(pass);
1857 m_errorMonitor->VerifyFound();
1858
1859 // Tell whether an wayland_display supports presentation:
1860 struct wl_display wayland_display = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001861 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1862 vkGetPhysicalDeviceWaylandPresentationSupportKHR(gpu(), 0, &wayland_display);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001863 m_errorMonitor->VerifyFound();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001864#endif // VK_USE_PLATFORM_WAYLAND_KHR
1865#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott3f06ce52016-04-29 14:46:21 -06001866
Ian Elliott3f06ce52016-04-29 14:46:21 -06001867#if defined(VK_USE_PLATFORM_WIN32_KHR)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001868 // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1869 // TO NON-LINUX PLATFORMS:
1870 VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott3f06ce52016-04-29 14:46:21 -06001871 // Use the functions from the VK_KHR_win32_surface extension without
1872 // enabling that extension:
1873
1874 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001875 VkWin32SurfaceCreateInfoKHR win32_create_info = {VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001876 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1877 err = vkCreateWin32SurfaceKHR(instance(), &win32_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001878 pass = (err != VK_SUCCESS);
1879 ASSERT_TRUE(pass);
1880 m_errorMonitor->VerifyFound();
1881
1882 // Tell whether win32 supports presentation:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001883 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott489eec02016-05-05 14:12:44 -06001884 vkGetPhysicalDeviceWin32PresentationSupportKHR(gpu(), 0);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001885 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001886// Set this (for now, until all platforms are supported and tested):
1887#define NEED_TO_TEST_THIS_ON_PLATFORM
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001888#endif // VK_USE_PLATFORM_WIN32_KHR
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07001889#if defined(VK_USE_PLATFORM_XCB_KHR) || defined(VK_USE_PLATFORM_XLIB_KHR)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001890 // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1891 // TO NON-LINUX PLATFORMS:
1892 VkSurfaceKHR surface = VK_NULL_HANDLE;
Tony Barbour2e7bd402016-11-14 14:46:33 -07001893#endif
1894#if defined(VK_USE_PLATFORM_XCB_KHR)
Ian Elliott1c32c772016-04-28 14:47:13 -06001895 // Use the functions from the VK_KHR_xcb_surface extension without enabling
1896 // that extension:
1897
1898 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001899 VkXcbSurfaceCreateInfoKHR xcb_create_info = {VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001900 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001901 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
1902 pass = (err != VK_SUCCESS);
1903 ASSERT_TRUE(pass);
1904 m_errorMonitor->VerifyFound();
1905
1906 // Tell whether an xcb_visualid_t supports presentation:
Ian Elliott3f06ce52016-04-29 14:46:21 -06001907 xcb_connection_t *xcb_connection = NULL;
Ian Elliott1c32c772016-04-28 14:47:13 -06001908 xcb_visualid_t visual_id = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001909 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1910 vkGetPhysicalDeviceXcbPresentationSupportKHR(gpu(), 0, xcb_connection, visual_id);
Ian Elliott1c32c772016-04-28 14:47:13 -06001911 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001912// Set this (for now, until all platforms are supported and tested):
1913#define NEED_TO_TEST_THIS_ON_PLATFORM
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001914#endif // VK_USE_PLATFORM_XCB_KHR
Ian Elliott1c32c772016-04-28 14:47:13 -06001915
Ian Elliott12630812016-04-29 14:35:43 -06001916#if defined(VK_USE_PLATFORM_XLIB_KHR)
1917 // Use the functions from the VK_KHR_xlib_surface extension without enabling
1918 // that extension:
1919
1920 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001921 VkXlibSurfaceCreateInfoKHR xlib_create_info = {VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001922 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06001923 err = vkCreateXlibSurfaceKHR(instance(), &xlib_create_info, NULL, &surface);
1924 pass = (err != VK_SUCCESS);
1925 ASSERT_TRUE(pass);
1926 m_errorMonitor->VerifyFound();
1927
1928 // Tell whether an Xlib VisualID supports presentation:
1929 Display *dpy = NULL;
1930 VisualID visual = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001931 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06001932 vkGetPhysicalDeviceXlibPresentationSupportKHR(gpu(), 0, dpy, visual);
1933 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001934// Set this (for now, until all platforms are supported and tested):
1935#define NEED_TO_TEST_THIS_ON_PLATFORM
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001936#endif // VK_USE_PLATFORM_XLIB_KHR
Ian Elliott12630812016-04-29 14:35:43 -06001937
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001938// Use the functions from the VK_KHR_surface extension without enabling
1939// that extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06001940
Ian Elliott489eec02016-05-05 14:12:44 -06001941#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001942 // Destroy a surface:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001943 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001944 vkDestroySurfaceKHR(instance(), surface, NULL);
1945 m_errorMonitor->VerifyFound();
1946
1947 // Check if surface supports presentation:
1948 VkBool32 supported = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001949 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001950 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
1951 pass = (err != VK_SUCCESS);
1952 ASSERT_TRUE(pass);
1953 m_errorMonitor->VerifyFound();
1954
1955 // Check surface capabilities:
1956 VkSurfaceCapabilitiesKHR capabilities = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001957 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1958 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &capabilities);
Ian Elliott1c32c772016-04-28 14:47:13 -06001959 pass = (err != VK_SUCCESS);
1960 ASSERT_TRUE(pass);
1961 m_errorMonitor->VerifyFound();
1962
1963 // Check surface formats:
1964 uint32_t format_count = 0;
1965 VkSurfaceFormatKHR *formats = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001966 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1967 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &format_count, formats);
Ian Elliott1c32c772016-04-28 14:47:13 -06001968 pass = (err != VK_SUCCESS);
1969 ASSERT_TRUE(pass);
1970 m_errorMonitor->VerifyFound();
1971
1972 // Check surface present modes:
1973 uint32_t present_mode_count = 0;
1974 VkSurfaceFormatKHR *present_modes = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001975 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1976 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &present_mode_count, present_modes);
Ian Elliott1c32c772016-04-28 14:47:13 -06001977 pass = (err != VK_SUCCESS);
1978 ASSERT_TRUE(pass);
1979 m_errorMonitor->VerifyFound();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001980#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001981
Ian Elliott1c32c772016-04-28 14:47:13 -06001982 // Use the functions from the VK_KHR_swapchain extension without enabling
1983 // that extension:
1984
1985 // Create a swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001986 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001987 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
1988 swapchain_create_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001989 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
Ian Elliott1c32c772016-04-28 14:47:13 -06001990 pass = (err != VK_SUCCESS);
1991 ASSERT_TRUE(pass);
1992 m_errorMonitor->VerifyFound();
1993
1994 // Get the images from the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001995 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1996 err = vkGetSwapchainImagesKHR(m_device->device(), swapchain, &swapchain_image_count, NULL);
Ian Elliott1c32c772016-04-28 14:47:13 -06001997 pass = (err != VK_SUCCESS);
1998 ASSERT_TRUE(pass);
1999 m_errorMonitor->VerifyFound();
2000
Chris Forbeseb7d5502016-09-13 18:19:21 +12002001 // Add a fence to avoid (justifiable) error about not providing fence OR semaphore
2002 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
2003 VkFence fence;
2004 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
2005
Ian Elliott1c32c772016-04-28 14:47:13 -06002006 // Try to acquire an image:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002007 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Chris Forbeseb7d5502016-09-13 18:19:21 +12002008 err = vkAcquireNextImageKHR(m_device->device(), swapchain, 0, VK_NULL_HANDLE, fence, &image_index);
Ian Elliott1c32c772016-04-28 14:47:13 -06002009 pass = (err != VK_SUCCESS);
2010 ASSERT_TRUE(pass);
2011 m_errorMonitor->VerifyFound();
2012
Chris Forbeseb7d5502016-09-13 18:19:21 +12002013 vkDestroyFence(m_device->device(), fence, nullptr);
2014
Ian Elliott1c32c772016-04-28 14:47:13 -06002015 // Try to present an image:
Ian Elliott2c1daf52016-05-12 09:41:46 -06002016 //
2017 // NOTE: Currently can't test this because a real swapchain is needed (as
2018 // opposed to the fake one we created) in order for the layer to lookup the
2019 // VkDevice used to enable the extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06002020
2021 // Destroy the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002022 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06002023 vkDestroySwapchainKHR(m_device->device(), swapchain, NULL);
2024 m_errorMonitor->VerifyFound();
2025}
Chris Forbes09368e42016-10-13 11:59:22 +13002026#endif
Ian Elliott1c32c772016-04-28 14:47:13 -06002027
Karl Schultz6addd812016-02-02 17:17:23 -07002028TEST_F(VkLayerTest, MapMemWithoutHostVisibleBit) {
2029 VkResult err;
2030 bool pass;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002031
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002032 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2033 "Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002034
Tony Barbour1fa09702017-03-16 12:09:08 -06002035 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002036
2037 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07002038 VkImage image;
2039 VkDeviceMemory mem;
2040 VkMemoryRequirements mem_reqs;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002041
Karl Schultz6addd812016-02-02 17:17:23 -07002042 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2043 const int32_t tex_width = 32;
2044 const int32_t tex_height = 32;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002045
Tony Barboureb254902015-07-15 12:50:33 -06002046 VkImageCreateInfo image_create_info = {};
2047 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07002048 image_create_info.pNext = NULL;
2049 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2050 image_create_info.format = tex_format;
2051 image_create_info.extent.width = tex_width;
2052 image_create_info.extent.height = tex_height;
2053 image_create_info.extent.depth = 1;
2054 image_create_info.mipLevels = 1;
2055 image_create_info.arrayLayers = 1;
2056 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2057 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2058 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2059 image_create_info.flags = 0;
Chris Forbese65e4d02016-09-13 17:39:18 +12002060 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002061
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002062 VkMemoryAllocateInfo mem_alloc = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002063 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07002064 mem_alloc.pNext = NULL;
2065 mem_alloc.allocationSize = 0;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002066
Chia-I Wuf7458c52015-10-26 21:10:41 +08002067 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002068 ASSERT_VK_SUCCESS(err);
2069
Karl Schultz6addd812016-02-02 17:17:23 -07002070 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002071
Mark Lobodzinski23065352015-05-29 09:32:35 -05002072 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002073
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002074 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002075 if (!pass) { // If we can't find any unmappable memory this test doesn't
2076 // make sense
Chia-I Wuf7458c52015-10-26 21:10:41 +08002077 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbour02fdc7d2015-08-04 16:13:01 -06002078 return;
Mike Stroyand1c84a52015-08-18 14:40:24 -06002079 }
Mike Stroyan713b2d72015-08-04 10:49:29 -06002080
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002081 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002082 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002083 ASSERT_VK_SUCCESS(err);
2084
2085 // Try to bind free memory that has been freed
Tony Barbour67e99152015-07-10 14:10:27 -06002086 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002087 ASSERT_VK_SUCCESS(err);
2088
2089 // Map memory as if to initialize the image
2090 void *mappedAddress = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002091 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, &mappedAddress);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002092
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002093 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002094
Chia-I Wuf7458c52015-10-26 21:10:41 +08002095 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06002096 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002097}
2098
Karl Schultz6addd812016-02-02 17:17:23 -07002099TEST_F(VkLayerTest, RebindMemory) {
2100 VkResult err;
2101 bool pass;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002102
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002103 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which has already been bound to mem object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002104
Tony Barbour1fa09702017-03-16 12:09:08 -06002105 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002106
2107 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07002108 VkImage image;
2109 VkDeviceMemory mem1;
2110 VkDeviceMemory mem2;
2111 VkMemoryRequirements mem_reqs;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002112
Karl Schultz6addd812016-02-02 17:17:23 -07002113 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2114 const int32_t tex_width = 32;
2115 const int32_t tex_height = 32;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002116
Tony Barboureb254902015-07-15 12:50:33 -06002117 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002118 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2119 image_create_info.pNext = NULL;
2120 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2121 image_create_info.format = tex_format;
2122 image_create_info.extent.width = tex_width;
2123 image_create_info.extent.height = tex_height;
2124 image_create_info.extent.depth = 1;
2125 image_create_info.mipLevels = 1;
2126 image_create_info.arrayLayers = 1;
2127 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2128 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2129 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2130 image_create_info.flags = 0;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002131
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002132 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002133 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2134 mem_alloc.pNext = NULL;
2135 mem_alloc.allocationSize = 0;
2136 mem_alloc.memoryTypeIndex = 0;
Tony Barboureb254902015-07-15 12:50:33 -06002137
Karl Schultz6addd812016-02-02 17:17:23 -07002138 // Introduce failure, do NOT set memProps to
2139 // VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
Tony Barboureb254902015-07-15 12:50:33 -06002140 mem_alloc.memoryTypeIndex = 1;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002141 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002142 ASSERT_VK_SUCCESS(err);
2143
Karl Schultz6addd812016-02-02 17:17:23 -07002144 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002145
2146 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002147 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002148 ASSERT_TRUE(pass);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002149
2150 // allocate 2 memory objects
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002151 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem1);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002152 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002153 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem2);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002154 ASSERT_VK_SUCCESS(err);
2155
2156 // Bind first memory object to Image object
Tony Barbour67e99152015-07-10 14:10:27 -06002157 err = vkBindImageMemory(m_device->device(), image, mem1, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002158 ASSERT_VK_SUCCESS(err);
2159
Karl Schultz6addd812016-02-02 17:17:23 -07002160 // Introduce validation failure, try to bind a different memory object to
2161 // the same image object
Tony Barbour67e99152015-07-10 14:10:27 -06002162 err = vkBindImageMemory(m_device->device(), image, mem2, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002163
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002164 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002165
Chia-I Wuf7458c52015-10-26 21:10:41 +08002166 vkDestroyImage(m_device->device(), image, NULL);
2167 vkFreeMemory(m_device->device(), mem1, NULL);
2168 vkFreeMemory(m_device->device(), mem2, NULL);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002169}
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002170
Karl Schultz6addd812016-02-02 17:17:23 -07002171TEST_F(VkLayerTest, SubmitSignaledFence) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002172 vk_testing::Fence testFence;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002173
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002174 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2175 "submitted in SIGNALED state. Fences "
2176 "must be reset before being submitted");
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002177
2178 VkFenceCreateInfo fenceInfo = {};
Tony Barbour0b4d9562015-04-09 10:48:04 -06002179 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2180 fenceInfo.pNext = NULL;
2181 fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
Tony Barbour300a6082015-04-07 13:44:53 -06002182
Tony Barbour1fa09702017-03-16 12:09:08 -06002183 ASSERT_NO_FATAL_FAILURE(Init());
Tony Barbour300a6082015-04-07 13:44:53 -06002184 ASSERT_NO_FATAL_FAILURE(InitViewport());
2185 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2186
Tony Barbour552f6c02016-12-21 14:34:07 -07002187 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002188 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbour552f6c02016-12-21 14:34:07 -07002189 m_commandBuffer->EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -06002190
2191 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002192
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002193 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08002194 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2195 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002196 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002197 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07002198 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002199 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002200 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08002201 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002202 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06002203
2204 vkQueueSubmit(m_device->m_queue, 1, &submit_info, testFence.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07002205 vkQueueWaitIdle(m_device->m_queue);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002206
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002207 m_errorMonitor->VerifyFound();
Tony Barbour0b4d9562015-04-09 10:48:04 -06002208}
Chris Forbes4e44c912016-06-16 10:20:00 +12002209
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002210TEST_F(VkLayerTest, InvalidUsageBits) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002211 TEST_DESCRIPTION(
2212 "Specify wrong usage for image then create conflicting view of image "
2213 "Initialize buffer with wrong usage then perform copy expecting errors "
2214 "from both the image and the buffer (2 calls)");
Mark Lobodzinski33826372017-04-13 11:10:11 -06002215 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid usage flag for Image ");
Tobin Ehlis41376e12015-07-03 08:45:14 -06002216
Tony Barbour1fa09702017-03-16 12:09:08 -06002217 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -06002218 auto format = FindSupportedDepthStencilFormat(gpu());
Tony Barbourf887b162017-03-09 10:06:46 -07002219 if (!format) {
2220 printf(" No Depth + Stencil format found. Skipped.\n");
2221 return;
2222 }
Chris Forbesd2b5fe42016-11-28 18:00:00 +13002223
Tony Barbourf92621a2016-05-02 14:28:12 -06002224 VkImageObj image(m_device);
Tony Barbour75d79f02016-08-30 09:39:07 -06002225 // Initialize image with USAGE_TRANSIENT_ATTACHMENT
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06002226 image.Init(128, 128, 1, format, VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Karl Schultzb5bc11e2016-05-04 08:36:08 -06002227 ASSERT_TRUE(image.initialized());
Tobin Ehlis41376e12015-07-03 08:45:14 -06002228
Tony Barbourf92621a2016-05-02 14:28:12 -06002229 VkImageView dsv;
2230 VkImageViewCreateInfo dsvci = {};
2231 dsvci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
2232 dsvci.image = image.handle();
2233 dsvci.viewType = VK_IMAGE_VIEW_TYPE_2D;
Chris Forbesd2b5fe42016-11-28 18:00:00 +13002234 dsvci.format = format;
Tony Barbourf92621a2016-05-02 14:28:12 -06002235 dsvci.subresourceRange.layerCount = 1;
2236 dsvci.subresourceRange.baseMipLevel = 0;
2237 dsvci.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002238 dsvci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis41376e12015-07-03 08:45:14 -06002239
Tony Barbourf92621a2016-05-02 14:28:12 -06002240 // Create a view with depth / stencil aspect for image with different usage
2241 vkCreateImageView(m_device->device(), &dsvci, NULL, &dsv);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002242
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002243 m_errorMonitor->VerifyFound();
Tony Barbourf92621a2016-05-02 14:28:12 -06002244
2245 // Initialize buffer with TRANSFER_DST usage
2246 vk_testing::Buffer buffer;
2247 VkMemoryPropertyFlags reqs = 0;
2248 buffer.init_as_dst(*m_device, 128 * 128, reqs);
2249 VkBufferImageCopy region = {};
2250 region.bufferRowLength = 128;
2251 region.bufferImageHeight = 128;
Mark Lobodzinski80871462017-02-16 10:37:27 -07002252 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Tony Barbourf92621a2016-05-02 14:28:12 -06002253 region.imageSubresource.layerCount = 1;
2254 region.imageExtent.height = 16;
2255 region.imageExtent.width = 16;
2256 region.imageExtent.depth = 1;
2257
Mark Lobodzinski80871462017-02-16 10:37:27 -07002258 // Buffer usage not set to TRANSFER_SRC and image usage not set to TRANSFER_DST
Tony Barbour552f6c02016-12-21 14:34:07 -07002259 m_commandBuffer->BeginCommandBuffer();
Tony Barbourf92621a2016-05-02 14:28:12 -06002260
Chris Forbesda581202016-10-06 18:25:26 +13002261 // two separate errors from this call:
Mark Lobodzinski33826372017-04-13 11:10:11 -06002262 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image should have VK_IMAGE_USAGE_TRANSFER_DST_BIT");
2263 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Buffer should have VK_BUFFER_USAGE_TRANSFER_SRC_BIT");
Chris Forbesda581202016-10-06 18:25:26 +13002264
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002265 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
2266 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourf92621a2016-05-02 14:28:12 -06002267 m_errorMonitor->VerifyFound();
Tobin Ehlis41376e12015-07-03 08:45:14 -06002268}
Tony Barbour75d79f02016-08-30 09:39:07 -06002269
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002270TEST_F(VkLayerTest, LeakAnObject) {
2271 VkResult err;
2272
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002273 TEST_DESCRIPTION("Create a fence and destroy its device without first destroying the fence.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002274
2275 // Note that we have to create a new device since destroying the
2276 // framework's device causes Teardown() to fail and just calling Teardown
2277 // will destroy the errorMonitor.
2278
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002279 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "has not been destroyed.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002280
Tony Barbour1fa09702017-03-16 12:09:08 -06002281 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002282
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002283 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002284 std::vector<VkDeviceQueueCreateInfo> queue_info;
2285 queue_info.reserve(queue_props.size());
2286 std::vector<std::vector<float>> queue_priorities;
2287 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
2288 VkDeviceQueueCreateInfo qi = {};
2289 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
2290 qi.pNext = NULL;
2291 qi.queueFamilyIndex = i;
2292 qi.queueCount = queue_props[i].queueCount;
2293 queue_priorities.emplace_back(qi.queueCount, 0.0f);
2294 qi.pQueuePriorities = queue_priorities[i].data();
2295 queue_info.push_back(qi);
2296 }
2297
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002298 std::vector<const char *> device_extension_names;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002299
2300 // The sacrificial device object
2301 VkDevice testDevice;
2302 VkDeviceCreateInfo device_create_info = {};
2303 auto features = m_device->phy().features();
2304 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
2305 device_create_info.pNext = NULL;
2306 device_create_info.queueCreateInfoCount = queue_info.size();
2307 device_create_info.pQueueCreateInfos = queue_info.data();
Tony Barbour4c70d102016-08-08 16:06:56 -06002308 device_create_info.enabledLayerCount = 0;
2309 device_create_info.ppEnabledLayerNames = NULL;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002310 device_create_info.pEnabledFeatures = &features;
2311 err = vkCreateDevice(gpu(), &device_create_info, NULL, &testDevice);
2312 ASSERT_VK_SUCCESS(err);
2313
2314 VkFence fence;
2315 VkFenceCreateInfo fence_create_info = {};
2316 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2317 fence_create_info.pNext = NULL;
2318 fence_create_info.flags = 0;
2319 err = vkCreateFence(testDevice, &fence_create_info, NULL, &fence);
2320 ASSERT_VK_SUCCESS(err);
2321
2322 // Induce failure by not calling vkDestroyFence
2323 vkDestroyDevice(testDevice, NULL);
2324 m_errorMonitor->VerifyFound();
2325}
2326
2327TEST_F(VkLayerTest, InvalidCommandPoolConsistency) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002328 TEST_DESCRIPTION(
2329 "Allocate command buffers from one command pool and "
2330 "attempt to delete them from another.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002331
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002332 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeCommandBuffers is attempting to free Command Buffer");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002333
Tony Barbour1fa09702017-03-16 12:09:08 -06002334 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002335 VkCommandPool command_pool_one;
2336 VkCommandPool command_pool_two;
2337
2338 VkCommandPoolCreateInfo pool_create_info{};
2339 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
2340 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
2341 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
2342
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002343 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002344
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002345 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002346
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002347 VkCommandBuffer cb;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002348 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002349 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002350 command_buffer_allocate_info.commandPool = command_pool_one;
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002351 command_buffer_allocate_info.commandBufferCount = 1;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002352 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002353 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &cb);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002354
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002355 vkFreeCommandBuffers(m_device->device(), command_pool_two, 1, &cb);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002356
2357 m_errorMonitor->VerifyFound();
2358
2359 vkDestroyCommandPool(m_device->device(), command_pool_one, NULL);
2360 vkDestroyCommandPool(m_device->device(), command_pool_two, NULL);
2361}
2362
2363TEST_F(VkLayerTest, InvalidDescriptorPoolConsistency) {
2364 VkResult err;
2365
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002366 TEST_DESCRIPTION(
2367 "Allocate descriptor sets from one DS pool and "
2368 "attempt to delete them from another.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002369
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002370 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeDescriptorSets is attempting to free descriptorSet");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002371
Tony Barbour1fa09702017-03-16 12:09:08 -06002372 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002373 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2374
2375 VkDescriptorPoolSize ds_type_count = {};
2376 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
2377 ds_type_count.descriptorCount = 1;
2378
2379 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2380 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2381 ds_pool_ci.pNext = NULL;
2382 ds_pool_ci.flags = 0;
2383 ds_pool_ci.maxSets = 1;
2384 ds_pool_ci.poolSizeCount = 1;
2385 ds_pool_ci.pPoolSizes = &ds_type_count;
2386
2387 VkDescriptorPool ds_pool_one;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002388 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002389 ASSERT_VK_SUCCESS(err);
2390
2391 // Create a second descriptor pool
2392 VkDescriptorPool ds_pool_two;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002393 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002394 ASSERT_VK_SUCCESS(err);
2395
2396 VkDescriptorSetLayoutBinding dsl_binding = {};
2397 dsl_binding.binding = 0;
2398 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
2399 dsl_binding.descriptorCount = 1;
2400 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2401 dsl_binding.pImmutableSamplers = NULL;
2402
2403 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2404 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2405 ds_layout_ci.pNext = NULL;
2406 ds_layout_ci.bindingCount = 1;
2407 ds_layout_ci.pBindings = &dsl_binding;
2408
2409 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002410 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002411 ASSERT_VK_SUCCESS(err);
2412
2413 VkDescriptorSet descriptorSet;
2414 VkDescriptorSetAllocateInfo alloc_info = {};
2415 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
2416 alloc_info.descriptorSetCount = 1;
2417 alloc_info.descriptorPool = ds_pool_one;
2418 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002419 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002420 ASSERT_VK_SUCCESS(err);
2421
2422 err = vkFreeDescriptorSets(m_device->device(), ds_pool_two, 1, &descriptorSet);
2423
2424 m_errorMonitor->VerifyFound();
2425
2426 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2427 vkDestroyDescriptorPool(m_device->device(), ds_pool_one, NULL);
2428 vkDestroyDescriptorPool(m_device->device(), ds_pool_two, NULL);
2429}
2430
2431TEST_F(VkLayerTest, CreateUnknownObject) {
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002432 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00788);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002433
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002434 TEST_DESCRIPTION("Pass an invalid image object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002435
Tony Barbour1fa09702017-03-16 12:09:08 -06002436 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002437
2438 // Pass bogus handle into GetImageMemoryRequirements
2439 VkMemoryRequirements mem_reqs;
2440 uint64_t fakeImageHandle = 0xCADECADE;
2441 VkImage fauxImage = reinterpret_cast<VkImage &>(fakeImageHandle);
2442
2443 vkGetImageMemoryRequirements(m_device->device(), fauxImage, &mem_reqs);
2444
2445 m_errorMonitor->VerifyFound();
2446}
2447
Mike Schuchardt17838902017-02-21 09:48:06 -07002448TEST_F(VkLayerTest, UseObjectWithWrongDevice) {
2449 TEST_DESCRIPTION(
2450 "Try to destroy a render pass object using a device other than the one it was created on. "
2451 "This should generate a distinct error from the invalid handle error.");
2452 // Create first device and renderpass
Tony Barbour1fa09702017-03-16 12:09:08 -06002453 ASSERT_NO_FATAL_FAILURE(Init());
Mike Schuchardt17838902017-02-21 09:48:06 -07002454 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2455
2456 // Create second device
2457 float priorities[] = {1.0f};
2458 VkDeviceQueueCreateInfo queue_info{};
2459 queue_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
2460 queue_info.pNext = NULL;
2461 queue_info.flags = 0;
2462 queue_info.queueFamilyIndex = 0;
2463 queue_info.queueCount = 1;
2464 queue_info.pQueuePriorities = &priorities[0];
2465
2466 VkDeviceCreateInfo device_create_info = {};
2467 auto features = m_device->phy().features();
2468 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
2469 device_create_info.pNext = NULL;
2470 device_create_info.queueCreateInfoCount = 1;
2471 device_create_info.pQueueCreateInfos = &queue_info;
2472 device_create_info.enabledLayerCount = 0;
2473 device_create_info.ppEnabledLayerNames = NULL;
2474 device_create_info.pEnabledFeatures = &features;
2475
2476 VkDevice second_device;
2477 ASSERT_VK_SUCCESS(vkCreateDevice(gpu(), &device_create_info, NULL, &second_device));
2478
2479 // Try to destroy the renderpass from the first device using the second device
2480 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00399);
2481 vkDestroyRenderPass(second_device, m_renderPass, NULL);
2482 m_errorMonitor->VerifyFound();
2483
2484 vkDestroyDevice(second_device, NULL);
2485}
2486
Karl Schultz6addd812016-02-02 17:17:23 -07002487TEST_F(VkLayerTest, PipelineNotBound) {
2488 VkResult err;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002489
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002490 TEST_DESCRIPTION("Pass in an invalid pipeline object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002491
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002492 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00601);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002493
Tony Barbour1fa09702017-03-16 12:09:08 -06002494 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002495 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002496
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002497 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002498 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2499 ds_type_count.descriptorCount = 1;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002500
2501 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002502 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2503 ds_pool_ci.pNext = NULL;
2504 ds_pool_ci.maxSets = 1;
2505 ds_pool_ci.poolSizeCount = 1;
2506 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002507
2508 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002509 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002510 ASSERT_VK_SUCCESS(err);
2511
2512 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002513 dsl_binding.binding = 0;
2514 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2515 dsl_binding.descriptorCount = 1;
2516 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2517 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002518
2519 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002520 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2521 ds_layout_ci.pNext = NULL;
2522 ds_layout_ci.bindingCount = 1;
2523 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002524
2525 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002526 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002527 ASSERT_VK_SUCCESS(err);
2528
2529 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002530 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002531 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07002532 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002533 alloc_info.descriptorPool = ds_pool;
2534 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002535 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002536 ASSERT_VK_SUCCESS(err);
2537
2538 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002539 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2540 pipeline_layout_ci.pNext = NULL;
2541 pipeline_layout_ci.setLayoutCount = 1;
2542 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002543
2544 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002545 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002546 ASSERT_VK_SUCCESS(err);
2547
Mark Youngad779052016-01-06 14:26:04 -07002548 VkPipeline badPipeline = (VkPipeline)((size_t)0xbaadb1be);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002549
Tony Barbour552f6c02016-12-21 14:34:07 -07002550 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002551 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002552
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002553 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002554
Chia-I Wuf7458c52015-10-26 21:10:41 +08002555 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2556 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2557 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002558}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002559
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002560TEST_F(VkLayerTest, BindImageInvalidMemoryType) {
2561 VkResult err;
2562
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002563 TEST_DESCRIPTION(
2564 "Test validation check for an invalid memory type index "
2565 "during bind[Buffer|Image]Memory time");
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002566
Tony Barbour1fa09702017-03-16 12:09:08 -06002567 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002568
2569 // Create an image, allocate memory, set a bad typeIndex and then try to
2570 // bind it
2571 VkImage image;
2572 VkDeviceMemory mem;
2573 VkMemoryRequirements mem_reqs;
2574 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2575 const int32_t tex_width = 32;
2576 const int32_t tex_height = 32;
2577
2578 VkImageCreateInfo image_create_info = {};
2579 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2580 image_create_info.pNext = NULL;
2581 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2582 image_create_info.format = tex_format;
2583 image_create_info.extent.width = tex_width;
2584 image_create_info.extent.height = tex_height;
2585 image_create_info.extent.depth = 1;
2586 image_create_info.mipLevels = 1;
2587 image_create_info.arrayLayers = 1;
2588 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2589 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2590 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2591 image_create_info.flags = 0;
2592
2593 VkMemoryAllocateInfo mem_alloc = {};
2594 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2595 mem_alloc.pNext = NULL;
2596 mem_alloc.allocationSize = 0;
2597 mem_alloc.memoryTypeIndex = 0;
2598
2599 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
2600 ASSERT_VK_SUCCESS(err);
2601
2602 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
2603 mem_alloc.allocationSize = mem_reqs.size;
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002604
2605 // Introduce Failure, select invalid TypeIndex
2606 VkPhysicalDeviceMemoryProperties memory_info;
2607
2608 vkGetPhysicalDeviceMemoryProperties(gpu(), &memory_info);
2609 unsigned int i;
2610 for (i = 0; i < memory_info.memoryTypeCount; i++) {
2611 if ((mem_reqs.memoryTypeBits & (1 << i)) == 0) {
2612 mem_alloc.memoryTypeIndex = i;
2613 break;
2614 }
2615 }
2616 if (i >= memory_info.memoryTypeCount) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07002617 printf(" No invalid memory type index could be found; skipped.\n");
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002618 vkDestroyImage(m_device->device(), image, NULL);
2619 return;
2620 }
2621
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002622 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "for this object type are not compatible with the memory");
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002623
2624 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
2625 ASSERT_VK_SUCCESS(err);
2626
2627 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2628 (void)err;
2629
2630 m_errorMonitor->VerifyFound();
2631
2632 vkDestroyImage(m_device->device(), image, NULL);
2633 vkFreeMemory(m_device->device(), mem, NULL);
2634}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002635
Karl Schultz6addd812016-02-02 17:17:23 -07002636TEST_F(VkLayerTest, BindInvalidMemory) {
2637 VkResult err;
2638 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002639
Tony Barbour1fa09702017-03-16 12:09:08 -06002640 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisec598302015-09-15 15:02:17 -06002641
Cortf801b982017-01-17 18:10:21 -08002642 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
Cort Strattonde748202017-02-17 12:50:01 -08002643 const int32_t tex_width = 256;
2644 const int32_t tex_height = 256;
Tobin Ehlisec598302015-09-15 15:02:17 -06002645
2646 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002647 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2648 image_create_info.pNext = NULL;
2649 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2650 image_create_info.format = tex_format;
2651 image_create_info.extent.width = tex_width;
2652 image_create_info.extent.height = tex_height;
2653 image_create_info.extent.depth = 1;
2654 image_create_info.mipLevels = 1;
2655 image_create_info.arrayLayers = 1;
2656 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Cort Strattonf1d8a4a2017-01-28 14:17:04 -08002657 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Karl Schultz6addd812016-02-02 17:17:23 -07002658 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2659 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002660
Cortf801b982017-01-17 18:10:21 -08002661 VkBufferCreateInfo buffer_create_info = {};
2662 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
2663 buffer_create_info.pNext = NULL;
2664 buffer_create_info.flags = 0;
Cort Strattonde748202017-02-17 12:50:01 -08002665 buffer_create_info.size = 4 * 1024 * 1024;
2666 buffer_create_info.usage = VK_BUFFER_USAGE_VERTEX_BUFFER_BIT;
Cortf801b982017-01-17 18:10:21 -08002667 buffer_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
Tobin Ehlisec598302015-09-15 15:02:17 -06002668
Cortf801b982017-01-17 18:10:21 -08002669 // Create an image/buffer, allocate memory, free it, and then try to bind it
2670 {
2671 VkImage image = VK_NULL_HANDLE;
2672 VkBuffer buffer = VK_NULL_HANDLE;
2673 err = vkCreateImage(device(), &image_create_info, NULL, &image);
2674 ASSERT_VK_SUCCESS(err);
2675 err = vkCreateBuffer(device(), &buffer_create_info, NULL, &buffer);
2676 ASSERT_VK_SUCCESS(err);
2677 VkMemoryRequirements image_mem_reqs = {}, buffer_mem_reqs = {};
2678 vkGetImageMemoryRequirements(device(), image, &image_mem_reqs);
2679 vkGetBufferMemoryRequirements(device(), buffer, &buffer_mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002680
Cortf801b982017-01-17 18:10:21 -08002681 VkMemoryAllocateInfo image_mem_alloc = {}, buffer_mem_alloc = {};
2682 image_mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2683 image_mem_alloc.allocationSize = image_mem_reqs.size;
2684 pass = m_device->phy().set_memory_type(image_mem_reqs.memoryTypeBits, &image_mem_alloc, 0);
2685 ASSERT_TRUE(pass);
2686 buffer_mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2687 buffer_mem_alloc.allocationSize = buffer_mem_reqs.size;
2688 pass = m_device->phy().set_memory_type(buffer_mem_reqs.memoryTypeBits, &buffer_mem_alloc, 0);
2689 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002690
Cortf801b982017-01-17 18:10:21 -08002691 VkDeviceMemory image_mem = VK_NULL_HANDLE, buffer_mem = VK_NULL_HANDLE;
2692 err = vkAllocateMemory(device(), &image_mem_alloc, NULL, &image_mem);
2693 ASSERT_VK_SUCCESS(err);
2694 err = vkAllocateMemory(device(), &buffer_mem_alloc, NULL, &buffer_mem);
2695 ASSERT_VK_SUCCESS(err);
Tobin Ehlisec598302015-09-15 15:02:17 -06002696
Cortf801b982017-01-17 18:10:21 -08002697 vkFreeMemory(device(), image_mem, NULL);
2698 vkFreeMemory(device(), buffer_mem, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002699
Cortf801b982017-01-17 18:10:21 -08002700 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00809);
2701 err = vkBindImageMemory(device(), image, image_mem, 0);
2702 (void)err; // This may very well return an error.
2703 m_errorMonitor->VerifyFound();
Tobin Ehlisec598302015-09-15 15:02:17 -06002704
Cortf801b982017-01-17 18:10:21 -08002705 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00800);
2706 err = vkBindBufferMemory(device(), buffer, buffer_mem, 0);
2707 (void)err; // This may very well return an error.
2708 m_errorMonitor->VerifyFound();
Tobin Ehlisec598302015-09-15 15:02:17 -06002709
Cortf801b982017-01-17 18:10:21 -08002710 vkDestroyImage(m_device->device(), image, NULL);
2711 vkDestroyBuffer(m_device->device(), buffer, NULL);
2712 }
Cort Strattonc21601b2017-01-28 14:16:16 -08002713
2714 // Try to bind memory to an object that already has a memory binding
2715 {
2716 VkImage image = VK_NULL_HANDLE;
2717 err = vkCreateImage(device(), &image_create_info, NULL, &image);
2718 ASSERT_VK_SUCCESS(err);
2719 VkBuffer buffer = VK_NULL_HANDLE;
2720 err = vkCreateBuffer(device(), &buffer_create_info, NULL, &buffer);
2721 ASSERT_VK_SUCCESS(err);
2722 VkMemoryRequirements image_mem_reqs = {}, buffer_mem_reqs = {};
2723 vkGetImageMemoryRequirements(device(), image, &image_mem_reqs);
2724 vkGetBufferMemoryRequirements(device(), buffer, &buffer_mem_reqs);
2725 VkMemoryAllocateInfo image_alloc_info = {}, buffer_alloc_info = {};
2726 image_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2727 image_alloc_info.allocationSize = image_mem_reqs.size;
2728 buffer_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2729 buffer_alloc_info.allocationSize = buffer_mem_reqs.size;
2730 pass = m_device->phy().set_memory_type(image_mem_reqs.memoryTypeBits, &image_alloc_info, 0);
2731 ASSERT_TRUE(pass);
2732 pass = m_device->phy().set_memory_type(buffer_mem_reqs.memoryTypeBits, &buffer_alloc_info, 0);
2733 ASSERT_TRUE(pass);
2734 VkDeviceMemory image_mem, buffer_mem;
2735 err = vkAllocateMemory(device(), &image_alloc_info, NULL, &image_mem);
2736 ASSERT_VK_SUCCESS(err);
2737 err = vkAllocateMemory(device(), &buffer_alloc_info, NULL, &buffer_mem);
2738 ASSERT_VK_SUCCESS(err);
2739
2740 err = vkBindImageMemory(device(), image, image_mem, 0);
2741 ASSERT_VK_SUCCESS(err);
2742 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00803);
2743 err = vkBindImageMemory(device(), image, image_mem, 0);
2744 (void)err; // This may very well return an error.
2745 m_errorMonitor->VerifyFound();
2746
2747 err = vkBindBufferMemory(device(), buffer, buffer_mem, 0);
2748 ASSERT_VK_SUCCESS(err);
2749 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00791);
2750 err = vkBindBufferMemory(device(), buffer, buffer_mem, 0);
2751 (void)err; // This may very well return an error.
2752 m_errorMonitor->VerifyFound();
2753
2754 vkFreeMemory(device(), image_mem, NULL);
2755 vkFreeMemory(device(), buffer_mem, NULL);
2756 vkDestroyImage(device(), image, NULL);
2757 vkDestroyBuffer(device(), buffer, NULL);
2758 }
Cort Strattonf1d8a4a2017-01-28 14:17:04 -08002759
Cort Strattonde748202017-02-17 12:50:01 -08002760 // Try to bind memory to an object with an invalid memoryOffset
Cort6c7dff72017-01-27 18:34:50 -08002761 {
2762 VkImage image = VK_NULL_HANDLE;
2763 err = vkCreateImage(device(), &image_create_info, NULL, &image);
2764 ASSERT_VK_SUCCESS(err);
2765 VkBuffer buffer = VK_NULL_HANDLE;
2766 err = vkCreateBuffer(device(), &buffer_create_info, NULL, &buffer);
2767 ASSERT_VK_SUCCESS(err);
2768 VkMemoryRequirements image_mem_reqs = {}, buffer_mem_reqs = {};
2769 vkGetImageMemoryRequirements(device(), image, &image_mem_reqs);
2770 vkGetBufferMemoryRequirements(device(), buffer, &buffer_mem_reqs);
2771 VkMemoryAllocateInfo image_alloc_info = {}, buffer_alloc_info = {};
2772 image_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Cort Strattonde748202017-02-17 12:50:01 -08002773 // Leave some extra space for alignment wiggle room
2774 image_alloc_info.allocationSize = image_mem_reqs.size + image_mem_reqs.alignment;
Cort6c7dff72017-01-27 18:34:50 -08002775 buffer_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Cort Strattonde748202017-02-17 12:50:01 -08002776 buffer_alloc_info.allocationSize = buffer_mem_reqs.size + buffer_mem_reqs.alignment;
Cort6c7dff72017-01-27 18:34:50 -08002777 pass = m_device->phy().set_memory_type(image_mem_reqs.memoryTypeBits, &image_alloc_info, 0);
2778 ASSERT_TRUE(pass);
2779 pass = m_device->phy().set_memory_type(buffer_mem_reqs.memoryTypeBits, &buffer_alloc_info, 0);
2780 ASSERT_TRUE(pass);
2781 VkDeviceMemory image_mem, buffer_mem;
2782 err = vkAllocateMemory(device(), &image_alloc_info, NULL, &image_mem);
2783 ASSERT_VK_SUCCESS(err);
2784 err = vkAllocateMemory(device(), &buffer_alloc_info, NULL, &buffer_mem);
2785 ASSERT_VK_SUCCESS(err);
2786
Cort Strattonde748202017-02-17 12:50:01 -08002787 // Test unaligned memory offset
2788 {
2789 if (image_mem_reqs.alignment > 1) {
2790 VkDeviceSize image_offset = 1;
2791 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02178);
2792 err = vkBindImageMemory(device(), image, image_mem, image_offset);
2793 (void)err; // This may very well return an error.
2794 m_errorMonitor->VerifyFound();
2795 }
Cort6c7dff72017-01-27 18:34:50 -08002796
Cort Strattonde748202017-02-17 12:50:01 -08002797 if (buffer_mem_reqs.alignment > 1) {
2798 VkDeviceSize buffer_offset = 1;
2799 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02174);
2800 err = vkBindBufferMemory(device(), buffer, buffer_mem, buffer_offset);
2801 (void)err; // This may very well return an error.
2802 m_errorMonitor->VerifyFound();
2803 }
2804 }
2805
2806 // Test memory offsets outside the memory allocation
2807 {
2808 VkDeviceSize image_offset =
2809 (image_alloc_info.allocationSize + image_mem_reqs.alignment) & ~(image_mem_reqs.alignment - 1);
2810 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00805);
2811 err = vkBindImageMemory(device(), image, image_mem, image_offset);
2812 (void)err; // This may very well return an error.
2813 m_errorMonitor->VerifyFound();
2814
2815 VkDeviceSize buffer_offset =
2816 (buffer_alloc_info.allocationSize + buffer_mem_reqs.alignment) & ~(buffer_mem_reqs.alignment - 1);
2817 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00793);
2818 err = vkBindBufferMemory(device(), buffer, buffer_mem, buffer_offset);
2819 (void)err; // This may very well return an error.
2820 m_errorMonitor->VerifyFound();
2821 }
2822
2823 // Test memory offsets within the memory allocation, but which leave too little memory for
2824 // the resource.
2825 {
2826 VkDeviceSize image_offset = (image_mem_reqs.size - 1) & ~(image_mem_reqs.alignment - 1);
Tony Barbour02d08552017-03-24 16:36:01 -06002827 if ((image_offset > 0) && (image_mem_reqs.size < (image_alloc_info.allocationSize - image_mem_reqs.alignment))) {
Cort Strattonde748202017-02-17 12:50:01 -08002828 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02179);
2829 err = vkBindImageMemory(device(), image, image_mem, image_offset);
2830 (void)err; // This may very well return an error.
2831 m_errorMonitor->VerifyFound();
2832 }
2833
2834 VkDeviceSize buffer_offset = (buffer_mem_reqs.size - 1) & ~(buffer_mem_reqs.alignment - 1);
2835 if (buffer_offset > 0) {
2836 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02175);
2837 err = vkBindBufferMemory(device(), buffer, buffer_mem, buffer_offset);
2838 (void)err; // This may very well return an error.
2839 m_errorMonitor->VerifyFound();
2840 }
2841 }
Cort6c7dff72017-01-27 18:34:50 -08002842
2843 vkFreeMemory(device(), image_mem, NULL);
2844 vkFreeMemory(device(), buffer_mem, NULL);
2845 vkDestroyImage(device(), image, NULL);
2846 vkDestroyBuffer(device(), buffer, NULL);
2847 }
2848
Cort Stratton4c38bb52017-01-28 13:33:10 -08002849 // Try to bind memory to an object with an invalid memory type
2850 {
2851 VkImage image = VK_NULL_HANDLE;
2852 err = vkCreateImage(device(), &image_create_info, NULL, &image);
2853 ASSERT_VK_SUCCESS(err);
2854 VkBuffer buffer = VK_NULL_HANDLE;
2855 err = vkCreateBuffer(device(), &buffer_create_info, NULL, &buffer);
2856 ASSERT_VK_SUCCESS(err);
2857 VkMemoryRequirements image_mem_reqs = {}, buffer_mem_reqs = {};
2858 vkGetImageMemoryRequirements(device(), image, &image_mem_reqs);
2859 vkGetBufferMemoryRequirements(device(), buffer, &buffer_mem_reqs);
2860 VkMemoryAllocateInfo image_alloc_info = {}, buffer_alloc_info = {};
2861 image_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2862 image_alloc_info.allocationSize = image_mem_reqs.size;
2863 buffer_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2864 buffer_alloc_info.allocationSize = buffer_mem_reqs.size;
Cort Strattonccc90e32017-02-04 13:47:42 -08002865 // Create a mask of available memory types *not* supported by these resources,
2866 // and try to use one of them.
Cort Stratton4c38bb52017-01-28 13:33:10 -08002867 VkPhysicalDeviceMemoryProperties memory_properties = {};
2868 vkGetPhysicalDeviceMemoryProperties(m_device->phy().handle(), &memory_properties);
Cort Strattonccc90e32017-02-04 13:47:42 -08002869 VkDeviceMemory image_mem, buffer_mem;
2870
Cort Stratton4c38bb52017-01-28 13:33:10 -08002871 uint32_t image_unsupported_mem_type_bits = ((1 << memory_properties.memoryTypeCount) - 1) & ~image_mem_reqs.memoryTypeBits;
Cort Strattonccc90e32017-02-04 13:47:42 -08002872 if (image_unsupported_mem_type_bits != 0) {
Dave Houlton584d51e2017-02-16 12:52:54 -07002873 pass = m_device->phy().set_memory_type(image_unsupported_mem_type_bits, &image_alloc_info, 0);
2874 ASSERT_TRUE(pass);
2875 err = vkAllocateMemory(device(), &image_alloc_info, NULL, &image_mem);
2876 ASSERT_VK_SUCCESS(err);
2877 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00806);
2878 err = vkBindImageMemory(device(), image, image_mem, 0);
2879 (void)err; // This may very well return an error.
2880 m_errorMonitor->VerifyFound();
2881 vkFreeMemory(device(), image_mem, NULL);
Cort Strattonccc90e32017-02-04 13:47:42 -08002882 }
2883
Cort Stratton4c38bb52017-01-28 13:33:10 -08002884 uint32_t buffer_unsupported_mem_type_bits =
2885 ((1 << memory_properties.memoryTypeCount) - 1) & ~buffer_mem_reqs.memoryTypeBits;
Cort Strattonccc90e32017-02-04 13:47:42 -08002886 if (buffer_unsupported_mem_type_bits != 0) {
Dave Houlton584d51e2017-02-16 12:52:54 -07002887 pass = m_device->phy().set_memory_type(buffer_unsupported_mem_type_bits, &buffer_alloc_info, 0);
2888 ASSERT_TRUE(pass);
2889 err = vkAllocateMemory(device(), &buffer_alloc_info, NULL, &buffer_mem);
2890 ASSERT_VK_SUCCESS(err);
2891 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00797);
2892 err = vkBindBufferMemory(device(), buffer, buffer_mem, 0);
2893 (void)err; // This may very well return an error.
2894 m_errorMonitor->VerifyFound();
2895 vkFreeMemory(device(), buffer_mem, NULL);
Cort Strattonccc90e32017-02-04 13:47:42 -08002896 }
Cort Stratton4c38bb52017-01-28 13:33:10 -08002897
Cort Stratton4c38bb52017-01-28 13:33:10 -08002898 vkDestroyImage(device(), image, NULL);
2899 vkDestroyBuffer(device(), buffer, NULL);
2900 }
2901
Cort Strattonf1d8a4a2017-01-28 14:17:04 -08002902 // Try to bind memory to an image created with sparse memory flags
2903 {
2904 VkImageCreateInfo sparse_image_create_info = image_create_info;
2905 sparse_image_create_info.flags |= VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
2906 VkImageFormatProperties image_format_properties = {};
2907 err = vkGetPhysicalDeviceImageFormatProperties(m_device->phy().handle(), sparse_image_create_info.format,
2908 sparse_image_create_info.imageType, sparse_image_create_info.tiling,
2909 sparse_image_create_info.usage, sparse_image_create_info.flags,
2910 &image_format_properties);
2911 if (!m_device->phy().features().sparseResidencyImage2D || err == VK_ERROR_FORMAT_NOT_SUPPORTED) {
2912 // most likely means sparse formats aren't supported here; skip this test.
2913 } else {
2914 ASSERT_VK_SUCCESS(err);
2915 if (image_format_properties.maxExtent.width == 0) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07002916 printf(" Sparse image format not supported; skipped.\n");
Cort Strattonf1d8a4a2017-01-28 14:17:04 -08002917 return;
2918 } else {
2919 VkImage sparse_image = VK_NULL_HANDLE;
2920 err = vkCreateImage(m_device->device(), &sparse_image_create_info, NULL, &sparse_image);
2921 ASSERT_VK_SUCCESS(err);
2922 VkMemoryRequirements sparse_mem_reqs = {};
2923 vkGetImageMemoryRequirements(m_device->device(), sparse_image, &sparse_mem_reqs);
2924 if (sparse_mem_reqs.memoryTypeBits != 0) {
2925 VkMemoryAllocateInfo sparse_mem_alloc = {};
2926 sparse_mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2927 sparse_mem_alloc.pNext = NULL;
2928 sparse_mem_alloc.allocationSize = sparse_mem_reqs.size;
2929 sparse_mem_alloc.memoryTypeIndex = 0;
2930 pass = m_device->phy().set_memory_type(sparse_mem_reqs.memoryTypeBits, &sparse_mem_alloc, 0);
2931 ASSERT_TRUE(pass);
2932 VkDeviceMemory sparse_mem = VK_NULL_HANDLE;
2933 err = vkAllocateMemory(m_device->device(), &sparse_mem_alloc, NULL, &sparse_mem);
2934 ASSERT_VK_SUCCESS(err);
2935 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00804);
2936 err = vkBindImageMemory(m_device->device(), sparse_image, sparse_mem, 0);
2937 // This may very well return an error.
2938 (void)err;
2939 m_errorMonitor->VerifyFound();
2940 vkFreeMemory(m_device->device(), sparse_mem, NULL);
2941 }
2942 vkDestroyImage(m_device->device(), sparse_image, NULL);
2943 }
2944 }
2945 }
2946
2947 // Try to bind memory to a buffer created with sparse memory flags
2948 {
2949 VkBufferCreateInfo sparse_buffer_create_info = buffer_create_info;
2950 sparse_buffer_create_info.flags |= VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
2951 if (!m_device->phy().features().sparseResidencyBuffer) {
2952 // most likely means sparse formats aren't supported here; skip this test.
2953 } else {
2954 VkBuffer sparse_buffer = VK_NULL_HANDLE;
2955 err = vkCreateBuffer(m_device->device(), &sparse_buffer_create_info, NULL, &sparse_buffer);
2956 ASSERT_VK_SUCCESS(err);
2957 VkMemoryRequirements sparse_mem_reqs = {};
2958 vkGetBufferMemoryRequirements(m_device->device(), sparse_buffer, &sparse_mem_reqs);
2959 if (sparse_mem_reqs.memoryTypeBits != 0) {
2960 VkMemoryAllocateInfo sparse_mem_alloc = {};
2961 sparse_mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2962 sparse_mem_alloc.pNext = NULL;
2963 sparse_mem_alloc.allocationSize = sparse_mem_reqs.size;
2964 sparse_mem_alloc.memoryTypeIndex = 0;
2965 pass = m_device->phy().set_memory_type(sparse_mem_reqs.memoryTypeBits, &sparse_mem_alloc, 0);
2966 ASSERT_TRUE(pass);
2967 VkDeviceMemory sparse_mem = VK_NULL_HANDLE;
2968 err = vkAllocateMemory(m_device->device(), &sparse_mem_alloc, NULL, &sparse_mem);
2969 ASSERT_VK_SUCCESS(err);
2970 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00792);
2971 err = vkBindBufferMemory(m_device->device(), sparse_buffer, sparse_mem, 0);
2972 // This may very well return an error.
2973 (void)err;
2974 m_errorMonitor->VerifyFound();
2975 vkFreeMemory(m_device->device(), sparse_mem, NULL);
2976 }
2977 vkDestroyBuffer(m_device->device(), sparse_buffer, NULL);
2978 }
2979 }
Tobin Ehlisec598302015-09-15 15:02:17 -06002980}
2981
Karl Schultz6addd812016-02-02 17:17:23 -07002982TEST_F(VkLayerTest, BindMemoryToDestroyedObject) {
2983 VkResult err;
2984 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002985
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002986 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00808);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002987
Tony Barbour1fa09702017-03-16 12:09:08 -06002988 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisec598302015-09-15 15:02:17 -06002989
Karl Schultz6addd812016-02-02 17:17:23 -07002990 // Create an image object, allocate memory, destroy the object and then try
2991 // to bind it
2992 VkImage image;
2993 VkDeviceMemory mem;
2994 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06002995
Karl Schultz6addd812016-02-02 17:17:23 -07002996 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2997 const int32_t tex_width = 32;
2998 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06002999
3000 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003001 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3002 image_create_info.pNext = NULL;
3003 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3004 image_create_info.format = tex_format;
3005 image_create_info.extent.width = tex_width;
3006 image_create_info.extent.height = tex_height;
3007 image_create_info.extent.depth = 1;
3008 image_create_info.mipLevels = 1;
3009 image_create_info.arrayLayers = 1;
3010 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
3011 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
3012 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
3013 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06003014
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003015 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003016 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
3017 mem_alloc.pNext = NULL;
3018 mem_alloc.allocationSize = 0;
3019 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06003020
Chia-I Wuf7458c52015-10-26 21:10:41 +08003021 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06003022 ASSERT_VK_SUCCESS(err);
3023
Karl Schultz6addd812016-02-02 17:17:23 -07003024 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06003025
3026 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003027 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06003028 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06003029
3030 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003031 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06003032 ASSERT_VK_SUCCESS(err);
3033
3034 // Introduce validation failure, destroy Image object before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08003035 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06003036 ASSERT_VK_SUCCESS(err);
3037
3038 // Now Try to bind memory to this destroyed object
3039 err = vkBindImageMemory(m_device->device(), image, mem, 0);
3040 // This may very well return an error.
Karl Schultz6addd812016-02-02 17:17:23 -07003041 (void)err;
Tobin Ehlisec598302015-09-15 15:02:17 -06003042
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003043 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06003044
Chia-I Wuf7458c52015-10-26 21:10:41 +08003045 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003046}
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003047
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -07003048TEST_F(VkLayerTest, CreatePipelineBadVertexAttributeFormat) {
3049 TEST_DESCRIPTION("Test that pipeline validation catches invalid vertex attribute formats");
3050
Tony Barbour1fa09702017-03-16 12:09:08 -06003051 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -07003052 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3053
3054 VkVertexInputBindingDescription input_binding;
3055 memset(&input_binding, 0, sizeof(input_binding));
3056
3057 VkVertexInputAttributeDescription input_attribs;
3058 memset(&input_attribs, 0, sizeof(input_attribs));
3059
3060 // Pick a really bad format for this purpose and make sure it should fail
3061 input_attribs.format = VK_FORMAT_BC2_UNORM_BLOCK;
3062 VkFormatProperties format_props = m_device->format_properties(input_attribs.format);
3063 if ((format_props.bufferFeatures & VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT) != 0) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07003064 printf(" Format unsuitable for test; skipped.\n");
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -07003065 return;
3066 }
3067
3068 input_attribs.location = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003069 char const *vsSource =
3070 "#version 450\n"
3071 "\n"
3072 "out gl_PerVertex {\n"
3073 " vec4 gl_Position;\n"
3074 "};\n"
3075 "void main(){\n"
3076 " gl_Position = vec4(1);\n"
3077 "}\n";
3078 char const *fsSource =
3079 "#version 450\n"
3080 "\n"
3081 "layout(location=0) out vec4 color;\n"
3082 "void main(){\n"
3083 " color = vec4(1);\n"
3084 "}\n";
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -07003085
3086 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01413);
3087 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
3088 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
3089
3090 VkPipelineObj pipe(m_device);
3091 pipe.AddColorAttachment();
3092 pipe.AddShader(&vs);
3093 pipe.AddShader(&fs);
3094
3095 pipe.AddVertexInputBindings(&input_binding, 1);
3096 pipe.AddVertexInputAttribs(&input_attribs, 1);
3097
3098 VkDescriptorSetObj descriptorSet(m_device);
3099 descriptorSet.AppendDummy();
3100 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
3101
3102 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
3103
3104 m_errorMonitor->VerifyFound();
3105}
3106
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003107TEST_F(VkLayerTest, ImageSampleCounts) {
Jeremy Hayes0d104082017-02-21 10:24:16 -07003108 TEST_DESCRIPTION("Use bad sample counts in image transfer calls to trigger validation errors.");
Tony Barbour1fa09702017-03-16 12:09:08 -06003109 ASSERT_NO_FATAL_FAILURE(Init(nullptr, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT));
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003110
3111 VkMemoryPropertyFlags reqs = 0;
3112 VkImageCreateInfo image_create_info = {};
3113 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3114 image_create_info.pNext = NULL;
3115 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3116 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
3117 image_create_info.extent.width = 256;
3118 image_create_info.extent.height = 256;
3119 image_create_info.extent.depth = 1;
3120 image_create_info.mipLevels = 1;
3121 image_create_info.arrayLayers = 1;
3122 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
3123 image_create_info.flags = 0;
3124
3125 VkImageBlit blit_region = {};
3126 blit_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3127 blit_region.srcSubresource.baseArrayLayer = 0;
3128 blit_region.srcSubresource.layerCount = 1;
3129 blit_region.srcSubresource.mipLevel = 0;
3130 blit_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3131 blit_region.dstSubresource.baseArrayLayer = 0;
3132 blit_region.dstSubresource.layerCount = 1;
3133 blit_region.dstSubresource.mipLevel = 0;
3134
3135 // Create two images, the source with sampleCount = 2, and attempt to blit
3136 // between them
3137 {
3138 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003139 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003140 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003141 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003142 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003143 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003144 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003145 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003146 m_commandBuffer->BeginCommandBuffer();
Jeremy Hayes0d104082017-02-21 10:24:16 -07003147 m_errorMonitor->SetDesiredFailureMsg(
3148 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3149 "was created with a sample count of VK_SAMPLE_COUNT_2_BIT but must be VK_SAMPLE_COUNT_1_BIT");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003150 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3151 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003152 m_errorMonitor->VerifyFound();
3153 m_commandBuffer->EndCommandBuffer();
3154 }
3155
3156 // Create two images, the dest with sampleCount = 4, and attempt to blit
3157 // between them
3158 {
3159 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003160 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003161 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003162 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003163 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003164 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003165 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003166 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003167 m_commandBuffer->BeginCommandBuffer();
Jeremy Hayes0d104082017-02-21 10:24:16 -07003168 m_errorMonitor->SetDesiredFailureMsg(
3169 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3170 "was created with a sample count of VK_SAMPLE_COUNT_4_BIT but must be VK_SAMPLE_COUNT_1_BIT");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003171 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3172 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003173 m_errorMonitor->VerifyFound();
3174 m_commandBuffer->EndCommandBuffer();
3175 }
3176
3177 VkBufferImageCopy copy_region = {};
3178 copy_region.bufferRowLength = 128;
3179 copy_region.bufferImageHeight = 128;
3180 copy_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3181 copy_region.imageSubresource.layerCount = 1;
3182 copy_region.imageExtent.height = 64;
3183 copy_region.imageExtent.width = 64;
3184 copy_region.imageExtent.depth = 1;
3185
3186 // Create src buffer and dst image with sampleCount = 4 and attempt to copy
3187 // buffer to image
3188 {
3189 vk_testing::Buffer src_buffer;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003190 src_buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
3191 image_create_info.samples = VK_SAMPLE_COUNT_8_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003192 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003193 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003194 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003195 m_commandBuffer->BeginCommandBuffer();
Jeremy Hayes0d104082017-02-21 10:24:16 -07003196 m_errorMonitor->SetDesiredFailureMsg(
3197 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3198 "was created with a sample count of VK_SAMPLE_COUNT_8_BIT but must be VK_SAMPLE_COUNT_1_BIT");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003199 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), src_buffer.handle(), dst_image.handle(),
3200 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &copy_region);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003201 m_errorMonitor->VerifyFound();
3202 m_commandBuffer->EndCommandBuffer();
3203 }
3204
3205 // Create dst buffer and src image with sampleCount = 2 and attempt to copy
3206 // image to buffer
3207 {
3208 vk_testing::Buffer dst_buffer;
3209 dst_buffer.init_as_dst(*m_device, 128 * 128 * 4, reqs);
3210 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003211 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003212 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003213 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003214 m_commandBuffer->BeginCommandBuffer();
Jeremy Hayes0d104082017-02-21 10:24:16 -07003215 m_errorMonitor->SetDesiredFailureMsg(
3216 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3217 "was created with a sample count of VK_SAMPLE_COUNT_2_BIT but must be VK_SAMPLE_COUNT_1_BIT");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003218 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003219 dst_buffer.handle(), 1, &copy_region);
3220 m_errorMonitor->VerifyFound();
3221 m_commandBuffer->EndCommandBuffer();
3222 }
3223}
3224
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003225TEST_F(VkLayerTest, BlitImageFormats) {
Tony Barbour1fa09702017-03-16 12:09:08 -06003226 ASSERT_NO_FATAL_FAILURE(Init());
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003227
3228 VkImageObj src_image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06003229 src_image.Init(64, 64, 1, VK_FORMAT_A2B10G10R10_UINT_PACK32, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003230 VkImageObj dst_image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06003231 dst_image.Init(64, 64, 1, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003232 VkImageObj dst_image2(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06003233 dst_image2.Init(64, 64, 1, VK_FORMAT_R8G8B8A8_SINT, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003234
3235 VkImageBlit blitRegion = {};
3236 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3237 blitRegion.srcSubresource.baseArrayLayer = 0;
3238 blitRegion.srcSubresource.layerCount = 1;
3239 blitRegion.srcSubresource.mipLevel = 0;
3240 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3241 blitRegion.dstSubresource.baseArrayLayer = 0;
3242 blitRegion.dstSubresource.layerCount = 1;
3243 blitRegion.dstSubresource.mipLevel = 0;
3244
Dave Houlton34df4cb2016-12-01 16:43:06 -07003245 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02191);
3246
3247 // TODO: there are 9 permutations of signed, unsigned, & other for source and dest
3248 // this test is only checking 2 of them at the moment
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003249
3250 // Unsigned int vs not an int
Tony Barbour552f6c02016-12-21 14:34:07 -07003251 m_commandBuffer->BeginCommandBuffer();
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06003252 vkCmdBlitImage(m_commandBuffer->handle(), src_image.image(), src_image.Layout(), dst_image.image(), dst_image.Layout(), 1,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003253 &blitRegion, VK_FILTER_NEAREST);
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003254
3255 m_errorMonitor->VerifyFound();
3256
Dave Houlton34df4cb2016-12-01 16:43:06 -07003257 // Test should generate 2 VU failures
3258 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02190);
3259 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02191);
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003260
3261 // Unsigned int vs signed int
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06003262 vkCmdBlitImage(m_commandBuffer->handle(), src_image.image(), src_image.Layout(), dst_image2.image(), dst_image2.Layout(), 1,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003263 &blitRegion, VK_FILTER_NEAREST);
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003264
Dave Houlton34df4cb2016-12-01 16:43:06 -07003265 // TODO: Note that this only verifies that at least one of the VU enums was found
3266 // Also, if any were not seen, they'll remain in the target list (Soln TBD, JIRA task: VL-72)
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003267 m_errorMonitor->VerifyFound();
3268
Tony Barbour552f6c02016-12-21 14:34:07 -07003269 m_commandBuffer->EndCommandBuffer();
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003270}
3271
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003272TEST_F(VkLayerTest, DSImageTransferGranularityTests) {
3273 VkResult err;
3274 bool pass;
3275
3276 TEST_DESCRIPTION("Tests for validaiton of Queue Family property minImageTransferGranularity.");
Tony Barbour1fa09702017-03-16 12:09:08 -06003277 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003278
3279 // If w/d/h granularity is 1, test is not meaningful
3280 // TODO: When virtual device limits are available, create a set of limits for this test that
3281 // will always have a granularity of > 1 for w, h, and d
3282 auto index = m_device->graphics_queue_node_index_;
3283 auto queue_family_properties = m_device->phy().queue_properties();
3284
3285 if ((queue_family_properties[index].minImageTransferGranularity.depth < 4) ||
3286 (queue_family_properties[index].minImageTransferGranularity.width < 4) ||
3287 (queue_family_properties[index].minImageTransferGranularity.height < 4)) {
3288 return;
3289 }
3290
3291 // Create two images of different types and try to copy between them
3292 VkImage srcImage;
3293 VkImage dstImage;
3294 VkDeviceMemory srcMem;
3295 VkDeviceMemory destMem;
3296 VkMemoryRequirements memReqs;
3297
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003298 VkImageCreateInfo image_create_info = {};
3299 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3300 image_create_info.pNext = NULL;
3301 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3302 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
3303 image_create_info.extent.width = 32;
3304 image_create_info.extent.height = 32;
3305 image_create_info.extent.depth = 1;
3306 image_create_info.mipLevels = 1;
3307 image_create_info.arrayLayers = 4;
3308 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
3309 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
3310 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
3311 image_create_info.flags = 0;
3312
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003313 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003314 ASSERT_VK_SUCCESS(err);
3315
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003316 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003317 ASSERT_VK_SUCCESS(err);
3318
3319 // Allocate memory
3320 VkMemoryAllocateInfo memAlloc = {};
3321 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
3322 memAlloc.pNext = NULL;
3323 memAlloc.allocationSize = 0;
3324 memAlloc.memoryTypeIndex = 0;
3325
3326 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
3327 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003328 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003329 ASSERT_TRUE(pass);
3330 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
3331 ASSERT_VK_SUCCESS(err);
3332
3333 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
3334 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003335 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003336 ASSERT_VK_SUCCESS(err);
3337 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
3338 ASSERT_VK_SUCCESS(err);
3339
3340 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
3341 ASSERT_VK_SUCCESS(err);
3342 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
3343 ASSERT_VK_SUCCESS(err);
3344
Tony Barbour552f6c02016-12-21 14:34:07 -07003345 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003346 VkImageCopy copyRegion;
3347 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3348 copyRegion.srcSubresource.mipLevel = 0;
3349 copyRegion.srcSubresource.baseArrayLayer = 0;
3350 copyRegion.srcSubresource.layerCount = 1;
3351 copyRegion.srcOffset.x = 0;
3352 copyRegion.srcOffset.y = 0;
3353 copyRegion.srcOffset.z = 0;
3354 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3355 copyRegion.dstSubresource.mipLevel = 0;
3356 copyRegion.dstSubresource.baseArrayLayer = 0;
3357 copyRegion.dstSubresource.layerCount = 1;
3358 copyRegion.dstOffset.x = 0;
3359 copyRegion.dstOffset.y = 0;
3360 copyRegion.dstOffset.z = 0;
3361 copyRegion.extent.width = 1;
3362 copyRegion.extent.height = 1;
3363 copyRegion.extent.depth = 1;
3364
3365 // Introduce failure by setting srcOffset to a bad granularity value
3366 copyRegion.srcOffset.y = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003367 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3368 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003369 m_errorMonitor->VerifyFound();
3370
3371 // Introduce failure by setting extent to a bad granularity value
3372 copyRegion.srcOffset.y = 0;
3373 copyRegion.extent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003374 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3375 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003376 m_errorMonitor->VerifyFound();
3377
3378 // Now do some buffer/image copies
3379 vk_testing::Buffer buffer;
3380 VkMemoryPropertyFlags reqs = 0;
3381 buffer.init_as_dst(*m_device, 128 * 128, reqs);
3382 VkBufferImageCopy region = {};
3383 region.bufferOffset = 0;
3384 region.bufferRowLength = 3;
3385 region.bufferImageHeight = 128;
3386 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3387 region.imageSubresource.layerCount = 1;
3388 region.imageExtent.height = 16;
3389 region.imageExtent.width = 16;
3390 region.imageExtent.depth = 1;
3391 region.imageOffset.x = 0;
3392 region.imageOffset.y = 0;
3393 region.imageOffset.z = 0;
3394
3395 // Introduce failure by setting bufferRowLength to a bad granularity value
3396 region.bufferRowLength = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003397 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3398 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
3399 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003400 m_errorMonitor->VerifyFound();
3401 region.bufferRowLength = 128;
3402
3403 // Introduce failure by setting bufferOffset to a bad granularity value
3404 region.bufferOffset = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003405 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3406 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
3407 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003408 m_errorMonitor->VerifyFound();
3409 region.bufferOffset = 0;
3410
3411 // Introduce failure by setting bufferImageHeight to a bad granularity value
3412 region.bufferImageHeight = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003413 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3414 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
3415 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003416 m_errorMonitor->VerifyFound();
3417 region.bufferImageHeight = 128;
3418
3419 // Introduce failure by setting imageExtent to a bad granularity value
3420 region.imageExtent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003421 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3422 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
3423 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003424 m_errorMonitor->VerifyFound();
3425 region.imageExtent.width = 16;
3426
3427 // Introduce failure by setting imageOffset to a bad granularity value
3428 region.imageOffset.z = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003429 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3430 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
3431 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003432 m_errorMonitor->VerifyFound();
3433
Tony Barbour552f6c02016-12-21 14:34:07 -07003434 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003435
3436 vkDestroyImage(m_device->device(), srcImage, NULL);
3437 vkDestroyImage(m_device->device(), dstImage, NULL);
3438 vkFreeMemory(m_device->device(), srcMem, NULL);
3439 vkFreeMemory(m_device->device(), destMem, NULL);
3440}
3441
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003442TEST_F(VkLayerTest, MismatchedQueueFamiliesOnSubmit) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003443 TEST_DESCRIPTION(
3444 "Submit command buffer created using one queue family and "
3445 "attempt to submit them on a queue created in a different "
3446 "queue family.");
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003447
Tony Barbour1fa09702017-03-16 12:09:08 -06003448 ASSERT_NO_FATAL_FAILURE(Init());
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07003449
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003450 // This test is meaningless unless we have multiple queue families
3451 auto queue_family_properties = m_device->phy().queue_properties();
3452 if (queue_family_properties.size() < 2) {
3453 return;
3454 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003455 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is being submitted on queue ");
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003456 // Get safe index of another queue family
3457 uint32_t other_queue_family = (m_device->graphics_queue_node_index_ == 0) ? 1 : 0;
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003458 VkQueue other_queue;
3459 vkGetDeviceQueue(m_device->device(), other_queue_family, 0, &other_queue);
3460
3461 // Record an empty cmd buffer
3462 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
3463 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3464 vkBeginCommandBuffer(m_commandBuffer->handle(), &cmdBufBeginDesc);
3465 vkEndCommandBuffer(m_commandBuffer->handle());
3466
3467 // And submit on the wrong queue
3468 VkSubmitInfo submit_info = {};
3469 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3470 submit_info.commandBufferCount = 1;
3471 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Tobin Ehlisfd213ea2016-08-10 17:10:46 -06003472 vkQueueSubmit(other_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003473
3474 m_errorMonitor->VerifyFound();
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003475}
3476
Chris Forbes4c24a922016-11-16 08:59:10 +13003477TEST_F(VkLayerTest, RenderPassAttachmentIndexOutOfRange) {
Tony Barbour1fa09702017-03-16 12:09:08 -06003478 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes4c24a922016-11-16 08:59:10 +13003479
Chris Forbes2d9b2a82016-11-21 10:45:39 +13003480 // There are no attachments, but refer to attachment 0.
3481 VkAttachmentReference ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbes4c24a922016-11-16 08:59:10 +13003482 VkSubpassDescription subpasses[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003483 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &ref, nullptr, nullptr, 0, nullptr},
Chris Forbes4c24a922016-11-16 08:59:10 +13003484 };
3485
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003486 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 1, subpasses, 0, nullptr};
Chris Forbes4c24a922016-11-16 08:59:10 +13003487 VkRenderPass rp;
3488
Chris Forbes2d9b2a82016-11-21 10:45:39 +13003489 // "... must be less than the total number of attachments ..."
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003490 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00325);
Chris Forbes4c24a922016-11-16 08:59:10 +13003491 vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3492 m_errorMonitor->VerifyFound();
3493}
3494
Chris Forbesa58c4522016-09-28 15:19:39 +13003495TEST_F(VkLayerTest, RenderPassPipelineSubpassMismatch) {
3496 TEST_DESCRIPTION("Use a pipeline for the wrong subpass in a render pass instance");
Tony Barbour1fa09702017-03-16 12:09:08 -06003497 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbesa58c4522016-09-28 15:19:39 +13003498
3499 // A renderpass with two subpasses, both writing the same attachment.
3500 VkAttachmentDescription attach[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003501 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3502 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_UNDEFINED,
3503 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesa58c4522016-09-28 15:19:39 +13003504 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003505 VkAttachmentReference ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbesa58c4522016-09-28 15:19:39 +13003506 VkSubpassDescription subpasses[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003507 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &ref, nullptr, nullptr, 0, nullptr},
3508 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &ref, nullptr, nullptr, 0, nullptr},
Chris Forbesa58c4522016-09-28 15:19:39 +13003509 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003510 VkSubpassDependency dep = {0,
3511 1,
3512 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
3513 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
3514 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
3515 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
3516 VK_DEPENDENCY_BY_REGION_BIT};
3517 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, attach, 2, subpasses, 1, &dep};
Chris Forbesa58c4522016-09-28 15:19:39 +13003518 VkRenderPass rp;
3519 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3520 ASSERT_VK_SUCCESS(err);
3521
3522 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06003523 image.InitNoLayout(32, 32, 1, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Chris Forbesa58c4522016-09-28 15:19:39 +13003524 VkImageView imageView = image.targetView(VK_FORMAT_R8G8B8A8_UNORM);
3525
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003526 VkFramebufferCreateInfo fbci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &imageView, 32, 32, 1};
Chris Forbesa58c4522016-09-28 15:19:39 +13003527 VkFramebuffer fb;
3528 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
3529 ASSERT_VK_SUCCESS(err);
3530
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003531 char const *vsSource =
3532 "#version 450\n"
3533 "void main() { gl_Position = vec4(1); }\n";
3534 char const *fsSource =
3535 "#version 450\n"
3536 "layout(location=0) out vec4 color;\n"
3537 "void main() { color = vec4(1); }\n";
Chris Forbesa58c4522016-09-28 15:19:39 +13003538
3539 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
3540 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
3541 VkPipelineObj pipe(m_device);
3542 pipe.AddColorAttachment();
3543 pipe.AddShader(&vs);
3544 pipe.AddShader(&fs);
3545 VkViewport view_port = {};
3546 m_viewports.push_back(view_port);
3547 pipe.SetViewport(m_viewports);
3548 VkRect2D rect = {};
3549 m_scissors.push_back(rect);
3550 pipe.SetScissor(m_scissors);
3551
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003552 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 0, nullptr, 0, nullptr};
Chris Forbesa58c4522016-09-28 15:19:39 +13003553 VkPipelineLayout pl;
3554 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
3555 ASSERT_VK_SUCCESS(err);
3556 pipe.CreateVKPipeline(pl, rp);
3557
Tony Barbour552f6c02016-12-21 14:34:07 -07003558 m_commandBuffer->BeginCommandBuffer();
Chris Forbesa58c4522016-09-28 15:19:39 +13003559
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003560 VkRenderPassBeginInfo rpbi = {VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO,
3561 nullptr,
3562 rp,
3563 fb,
3564 {{
3565 0, 0,
3566 },
3567 {32, 32}},
3568 0,
3569 nullptr};
Chris Forbesa58c4522016-09-28 15:19:39 +13003570
3571 // subtest 1: bind in the wrong subpass
3572 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
3573 vkCmdNextSubpass(m_commandBuffer->handle(), VK_SUBPASS_CONTENTS_INLINE);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003574 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "built for subpass 0 but used in subpass 1");
Chris Forbesa58c4522016-09-28 15:19:39 +13003575 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
3576 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
3577 m_errorMonitor->VerifyFound();
3578
3579 vkCmdEndRenderPass(m_commandBuffer->handle());
3580
3581 // subtest 2: bind in correct subpass, then transition to next subpass
3582 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
3583 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
3584 vkCmdNextSubpass(m_commandBuffer->handle(), VK_SUBPASS_CONTENTS_INLINE);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003585 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "built for subpass 0 but used in subpass 1");
Chris Forbesa58c4522016-09-28 15:19:39 +13003586 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
3587 m_errorMonitor->VerifyFound();
3588
3589 vkCmdEndRenderPass(m_commandBuffer->handle());
3590
Tony Barbour552f6c02016-12-21 14:34:07 -07003591 m_commandBuffer->EndCommandBuffer();
Chris Forbesa58c4522016-09-28 15:19:39 +13003592
3593 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
3594 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
3595 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3596}
3597
Tony Barbour4e919972016-08-09 13:27:40 -06003598TEST_F(VkLayerTest, RenderPassInvalidRenderArea) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003599 TEST_DESCRIPTION(
3600 "Generate INVALID_RENDER_AREA error by beginning renderpass"
3601 "with extent outside of framebuffer");
Tony Barbour1fa09702017-03-16 12:09:08 -06003602 ASSERT_NO_FATAL_FAILURE(Init());
Tony Barbour4e919972016-08-09 13:27:40 -06003603 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3604
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003605 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3606 "Cannot execute a render pass with renderArea "
3607 "not within the bound of the framebuffer.");
Tony Barbour4e919972016-08-09 13:27:40 -06003608
3609 // Framebuffer for render target is 256x256, exceed that for INVALID_RENDER_AREA
3610 m_renderPassBeginInfo.renderArea.extent.width = 257;
3611 m_renderPassBeginInfo.renderArea.extent.height = 257;
Tony Barbour552f6c02016-12-21 14:34:07 -07003612 m_commandBuffer->BeginCommandBuffer();
3613 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tony Barbour4e919972016-08-09 13:27:40 -06003614 m_errorMonitor->VerifyFound();
3615}
3616
3617TEST_F(VkLayerTest, DisabledIndependentBlend) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003618 TEST_DESCRIPTION(
3619 "Generate INDEPENDENT_BLEND by disabling independent "
3620 "blend and then specifying different blend states for two "
3621 "attachements");
Cody Northrop5703cc72016-08-19 09:57:10 -06003622 VkPhysicalDeviceFeatures features = {};
3623 features.independentBlend = VK_FALSE;
Tony Barbour1fa09702017-03-16 12:09:08 -06003624 ASSERT_NO_FATAL_FAILURE(Init(&features));
Tony Barbour4e919972016-08-09 13:27:40 -06003625
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003626 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3627 "Invalid Pipeline CreateInfo: If independent blend feature not "
3628 "enabled, all elements of pAttachments must be identical");
Tony Barbour4e919972016-08-09 13:27:40 -06003629
Cody Northropc31a84f2016-08-22 10:41:47 -06003630 VkDescriptorSetObj descriptorSet(m_device);
3631 descriptorSet.AppendDummy();
3632 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Tony Barbour4e919972016-08-09 13:27:40 -06003633
Cody Northropc31a84f2016-08-22 10:41:47 -06003634 VkPipelineObj pipeline(m_device);
Tony Barbour0ace59a2017-02-06 13:38:36 -07003635 // Create a renderPass with two color attachments
3636 VkAttachmentReference attachments[2] = {};
3637 attachments[0].layout = VK_IMAGE_LAYOUT_GENERAL;
Tony Barbourffd60bd2017-03-09 12:04:55 -07003638 attachments[1].attachment = 1;
Tony Barbour0ace59a2017-02-06 13:38:36 -07003639 attachments[1].layout = VK_IMAGE_LAYOUT_GENERAL;
3640
3641 VkSubpassDescription subpass = {};
3642 subpass.pColorAttachments = attachments;
3643 subpass.colorAttachmentCount = 2;
3644
3645 VkRenderPassCreateInfo rpci = {};
3646 rpci.subpassCount = 1;
3647 rpci.pSubpasses = &subpass;
Tony Barbourffd60bd2017-03-09 12:04:55 -07003648 rpci.attachmentCount = 2;
Tony Barbour0ace59a2017-02-06 13:38:36 -07003649
Tony Barbourffd60bd2017-03-09 12:04:55 -07003650 VkAttachmentDescription attach_desc[2] = {};
3651 attach_desc[0].format = VK_FORMAT_B8G8R8A8_UNORM;
3652 attach_desc[0].samples = VK_SAMPLE_COUNT_1_BIT;
3653 attach_desc[0].initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
3654 attach_desc[0].finalLayout = VK_IMAGE_LAYOUT_GENERAL;
3655 attach_desc[1].format = VK_FORMAT_B8G8R8A8_UNORM;
3656 attach_desc[1].samples = VK_SAMPLE_COUNT_1_BIT;
3657 attach_desc[1].initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
3658 attach_desc[1].finalLayout = VK_IMAGE_LAYOUT_GENERAL;
Tony Barbour0ace59a2017-02-06 13:38:36 -07003659
Tony Barbourffd60bd2017-03-09 12:04:55 -07003660 rpci.pAttachments = attach_desc;
Tony Barbour0ace59a2017-02-06 13:38:36 -07003661 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3662
3663 VkRenderPass renderpass;
3664 vkCreateRenderPass(m_device->device(), &rpci, NULL, &renderpass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003665 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Cody Northropc31a84f2016-08-22 10:41:47 -06003666 pipeline.AddShader(&vs);
Cody Northrop5703cc72016-08-19 09:57:10 -06003667
Cody Northropc31a84f2016-08-22 10:41:47 -06003668 VkPipelineColorBlendAttachmentState att_state1 = {}, att_state2 = {};
3669 att_state1.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3670 att_state1.blendEnable = VK_TRUE;
3671 att_state2.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3672 att_state2.blendEnable = VK_FALSE;
3673 pipeline.AddColorAttachment(0, &att_state1);
3674 pipeline.AddColorAttachment(1, &att_state2);
Tony Barbour0ace59a2017-02-06 13:38:36 -07003675 pipeline.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderpass);
Cody Northropc31a84f2016-08-22 10:41:47 -06003676 m_errorMonitor->VerifyFound();
Tony Barbour0ace59a2017-02-06 13:38:36 -07003677 vkDestroyRenderPass(m_device->device(), renderpass, NULL);
Tony Barbour4e919972016-08-09 13:27:40 -06003678}
3679
Mike Weiblen40b160e2017-02-06 19:21:52 -07003680// Is the Pipeline compatible with the expectations of the Renderpass/subpasses?
3681TEST_F(VkLayerTest, PipelineRenderpassCompatibility) {
3682 TEST_DESCRIPTION(
3683 "Create a graphics pipeline that is incompatible with the requirements "
3684 "of its contained Renderpass/subpasses.");
Tony Barbour1fa09702017-03-16 12:09:08 -06003685 ASSERT_NO_FATAL_FAILURE(Init());
Mike Weiblen40b160e2017-02-06 19:21:52 -07003686
3687 VkDescriptorSetObj ds_obj(m_device);
3688 ds_obj.AppendDummy();
3689 ds_obj.CreateVKDescriptorSet(m_commandBuffer);
3690
3691 VkShaderObj vs_obj(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
3692
3693 VkPipelineColorBlendAttachmentState att_state1 = {};
3694 att_state1.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3695 att_state1.blendEnable = VK_TRUE;
3696
3697 VkRenderpassObj rp_obj(m_device);
3698
3699 {
3700 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02116);
3701 VkPipelineObj pipeline(m_device);
3702 pipeline.AddShader(&vs_obj);
3703 pipeline.AddColorAttachment(0, &att_state1);
3704
3705 VkGraphicsPipelineCreateInfo info = {};
3706 pipeline.InitGraphicsPipelineCreateInfo(&info);
3707 info.pColorBlendState = nullptr;
3708
3709 pipeline.CreateVKPipeline(ds_obj.GetPipelineLayout(), rp_obj.handle(), &info);
3710 m_errorMonitor->VerifyFound();
3711 }
3712}
3713
Cort Stratton7547f772017-05-04 15:18:52 -07003714TEST_F(VkLayerTest, CreateRenderPassAttachments) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003715 TEST_DESCRIPTION(
Cort Stratton7547f772017-05-04 15:18:52 -07003716 "Ensure that CreateRenderPass produces the expected validation errors "
3717 "when a subpass's attachments violate the valid usage conditions.");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003718
Tony Barbour1fa09702017-03-16 12:09:08 -06003719 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003720
Cort Stratton7547f772017-05-04 15:18:52 -07003721 std::vector<VkAttachmentDescription> attachments = {
3722 // input attachments
3723 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3724 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_GENERAL,
3725 VK_IMAGE_LAYOUT_GENERAL},
3726 // color attachments
3727 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3728 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3729 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3730 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3731 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3732 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3733 // depth attachment
3734 {0, VK_FORMAT_D24_UNORM_S8_UINT, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3735 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
3736 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL},
3737 // resolve attachment
3738 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3739 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3740 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3741 // preserve attachments
3742 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3743 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3744 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3745 };
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003746
Cort Stratton7547f772017-05-04 15:18:52 -07003747 std::vector<VkAttachmentReference> input = {
3748 {0, VK_IMAGE_LAYOUT_GENERAL},
3749 };
3750 std::vector<VkAttachmentReference> color = {
3751 {1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL}, {2, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3752 };
3753 VkAttachmentReference depth = {3, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
3754 std::vector<VkAttachmentReference> resolve = {
3755 {4, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL}, {VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3756 };
3757 std::vector<uint32_t> preserve = {5};
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003758
Cort Stratton7547f772017-05-04 15:18:52 -07003759 VkSubpassDescription subpass = {0,
3760 VK_PIPELINE_BIND_POINT_GRAPHICS,
3761 (uint32_t)input.size(),
3762 input.data(),
3763 (uint32_t)color.size(),
3764 color.data(),
3765 resolve.data(),
3766 &depth,
3767 (uint32_t)preserve.size(),
3768 preserve.data()};
3769
3770 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO,
3771 nullptr,
3772 0,
3773 (uint32_t)attachments.size(),
3774 attachments.data(),
3775 1,
3776 &subpass,
3777 0,
3778 nullptr};
3779
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003780 VkRenderPass rp;
Cort Stratton7547f772017-05-04 15:18:52 -07003781 VkResult err;
3782 // Test too many color attachments
3783 {
3784 std::vector<VkAttachmentReference> too_many_colors(m_device->props.limits.maxColorAttachments + 1, color[0]);
3785 subpass.colorAttachmentCount = (uint32_t)too_many_colors.size();
3786 subpass.pColorAttachments = too_many_colors.data();
3787 subpass.pResolveAttachments = NULL;
3788 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00348);
3789 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3790 m_errorMonitor->VerifyFound();
3791 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
3792 subpass.colorAttachmentCount = (uint32_t)color.size();
3793 subpass.pColorAttachments = color.data();
3794 subpass.pResolveAttachments = resolve.data();
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003795 }
Cort Stratton7547f772017-05-04 15:18:52 -07003796 // Test sample count mismatch between color buffers
3797 attachments[subpass.pColorAttachments[1].attachment].samples = VK_SAMPLE_COUNT_8_BIT;
3798 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00337);
3799 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
Chris Forbesc5389742016-06-29 11:49:23 +12003800 m_errorMonitor->VerifyFound();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003801 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
Cort Stratton7547f772017-05-04 15:18:52 -07003802 attachments[subpass.pColorAttachments[1].attachment].samples = attachments[subpass.pColorAttachments[0].attachment].samples;
3803 // Test sample count mismatch between color buffers and depth buffer
3804 attachments[subpass.pDepthStencilAttachment->attachment].samples = VK_SAMPLE_COUNT_8_BIT;
3805 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00337);
3806 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
Chris Forbesc5389742016-06-29 11:49:23 +12003807 m_errorMonitor->VerifyFound();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003808 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
Cort Stratton7547f772017-05-04 15:18:52 -07003809 attachments[subpass.pDepthStencilAttachment->attachment].samples = attachments[subpass.pColorAttachments[0].attachment].samples;
3810 // Test resolve attachment with UNUSED color attachment
3811 color[0].attachment = VK_ATTACHMENT_UNUSED;
3812 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00350);
3813 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
Chris Forbes3f128ef2016-06-29 14:58:53 +12003814 m_errorMonitor->VerifyFound();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003815 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
Cort Stratton7547f772017-05-04 15:18:52 -07003816 color[0].attachment = 1;
3817 // Test resolve from a single-sampled color attachment
3818 attachments[subpass.pColorAttachments[0].attachment].samples = VK_SAMPLE_COUNT_1_BIT;
3819 attachments[subpass.pColorAttachments[1].attachment].samples = VK_SAMPLE_COUNT_1_BIT; // avoid mismatch (00337)
3820 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00351);
3821 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3822 m_errorMonitor->VerifyFound();
3823 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
3824 attachments[subpass.pColorAttachments[0].attachment].samples = VK_SAMPLE_COUNT_4_BIT;
3825 attachments[subpass.pColorAttachments[1].attachment].samples = VK_SAMPLE_COUNT_4_BIT;
3826 // Test resolve to a multi-sampled resolve attachment
3827 attachments[subpass.pResolveAttachments[0].attachment].samples = VK_SAMPLE_COUNT_4_BIT;
3828 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00352);
3829 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3830 m_errorMonitor->VerifyFound();
3831 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
3832 attachments[subpass.pResolveAttachments[0].attachment].samples = VK_SAMPLE_COUNT_1_BIT;
3833 // Test with color/resolve format mismatch
3834 attachments[subpass.pColorAttachments[0].attachment].format = VK_FORMAT_R8G8B8A8_SRGB;
3835 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00353);
3836 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3837 m_errorMonitor->VerifyFound();
3838 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
3839 attachments[subpass.pColorAttachments[0].attachment].format = attachments[subpass.pResolveAttachments[0].attachment].format;
3840 // Test for UNUSED preserve attachments
3841 preserve[0] = VK_ATTACHMENT_UNUSED;
3842 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00356);
3843 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3844 m_errorMonitor->VerifyFound();
3845 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
3846 preserve[0] = 5;
3847 // Test for preserve attachments used elsewhere in the subpass
3848 color[0].attachment = preserve[0];
3849 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00357);
3850 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3851 m_errorMonitor->VerifyFound();
3852 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
3853 color[0].attachment = 1;
3854 // test for layout mismatch between input attachment and color attachment
3855 input[0].attachment = color[0].attachment;
3856 input[0].layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
3857 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00358);
3858 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3859 m_errorMonitor->VerifyFound();
3860 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
3861 input[0].attachment = 0;
3862 input[0].layout = VK_IMAGE_LAYOUT_GENERAL;
3863 // test for layout mismatch between input attachment and depth attachment
3864 input[0].attachment = depth.attachment;
3865 input[0].layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
3866 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00358);
3867 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3868 m_errorMonitor->VerifyFound();
3869 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
3870 input[0].attachment = 0;
3871 input[0].layout = VK_IMAGE_LAYOUT_GENERAL;
3872 // Test for attachment used first as input with loadOp=CLEAR
3873 {
3874 std::vector<VkSubpassDescription> subpasses = {subpass, subpass, subpass};
3875 subpasses[0].inputAttachmentCount = 0;
3876 subpasses[1].inputAttachmentCount = 0;
3877 attachments[input[0].attachment].loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
3878 VkRenderPassCreateInfo rpci_multipass = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO,
3879 nullptr,
3880 0,
3881 (uint32_t)attachments.size(),
3882 attachments.data(),
3883 (uint32_t)subpasses.size(),
3884 subpasses.data(),
3885 0,
3886 nullptr};
3887 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00349);
3888 err = vkCreateRenderPass(m_device->device(), &rpci_multipass, nullptr, &rp);
3889 m_errorMonitor->VerifyFound();
3890 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
3891 attachments[input[0].attachment].loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
3892 }
Chris Forbes3f128ef2016-06-29 14:58:53 +12003893}
3894
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003895TEST_F(VkLayerTest, FramebufferCreateErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003896 TEST_DESCRIPTION(
3897 "Hit errors when attempting to create a framebuffer :\n"
3898 " 1. Mismatch between framebuffer & renderPass attachmentCount\n"
3899 " 2. Use a color image as depthStencil attachment\n"
3900 " 3. Mismatch framebuffer & renderPass attachment formats\n"
3901 " 4. Mismatch framebuffer & renderPass attachment #samples\n"
3902 " 5. Framebuffer attachment w/ non-1 mip-levels\n"
3903 " 6. Framebuffer attachment where dimensions don't match\n"
Cort Stratton8133ec22017-04-27 16:25:03 +02003904 " 7. Framebuffer attachment where dimensions don't match\n"
3905 " 8. Framebuffer attachment w/o identity swizzle\n"
3906 " 9. framebuffer dimensions exceed physical device limits\n");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003907
Tony Barbour1fa09702017-03-16 12:09:08 -06003908 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003909 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3910
Cort Stratton8133ec22017-04-27 16:25:03 +02003911 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00404);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003912
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003913 // Create a renderPass with a single color attachment
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003914 VkAttachmentReference attach = {};
3915 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
3916 VkSubpassDescription subpass = {};
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003917 subpass.pColorAttachments = &attach;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003918 VkRenderPassCreateInfo rpci = {};
3919 rpci.subpassCount = 1;
3920 rpci.pSubpasses = &subpass;
3921 rpci.attachmentCount = 1;
3922 VkAttachmentDescription attach_desc = {};
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003923 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003924 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003925 rpci.pAttachments = &attach_desc;
3926 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3927 VkRenderPass rp;
3928 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3929 ASSERT_VK_SUCCESS(err);
3930
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003931 VkImageView ivs[2];
3932 ivs[0] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
3933 ivs[1] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003934 VkFramebufferCreateInfo fb_info = {};
3935 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
3936 fb_info.pNext = NULL;
3937 fb_info.renderPass = rp;
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003938 // Set mis-matching attachmentCount
3939 fb_info.attachmentCount = 2;
3940 fb_info.pAttachments = ivs;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003941 fb_info.width = 100;
3942 fb_info.height = 100;
3943 fb_info.layers = 1;
3944
3945 VkFramebuffer fb;
3946 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3947
3948 m_errorMonitor->VerifyFound();
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003949 if (err == VK_SUCCESS) {
3950 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3951 }
3952 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003953
3954 // Create a renderPass with a depth-stencil attachment created with
3955 // IMAGE_USAGE_COLOR_ATTACHMENT
3956 // Add our color attachment to pDepthStencilAttachment
3957 subpass.pDepthStencilAttachment = &attach;
3958 subpass.pColorAttachments = NULL;
3959 VkRenderPass rp_ds;
3960 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp_ds);
3961 ASSERT_VK_SUCCESS(err);
3962 // Set correct attachment count, but attachment has COLOR usage bit set
3963 fb_info.attachmentCount = 1;
3964 fb_info.renderPass = rp_ds;
3965
Cort Stratton8133ec22017-04-27 16:25:03 +02003966 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00406);
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003967 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3968
3969 m_errorMonitor->VerifyFound();
3970 if (err == VK_SUCCESS) {
3971 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3972 }
3973 vkDestroyRenderPass(m_device->device(), rp_ds, NULL);
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003974
3975 // Create new renderpass with alternate attachment format from fb
3976 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
3977 subpass.pDepthStencilAttachment = NULL;
3978 subpass.pColorAttachments = &attach;
3979 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3980 ASSERT_VK_SUCCESS(err);
3981
3982 // Cause error due to mis-matched formats between rp & fb
3983 // rp attachment 0 now has RGBA8 but corresponding fb attach is BGRA8
3984 fb_info.renderPass = rp;
Cort Stratton8133ec22017-04-27 16:25:03 +02003985 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00408);
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003986 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3987
3988 m_errorMonitor->VerifyFound();
3989 if (err == VK_SUCCESS) {
3990 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3991 }
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003992 vkDestroyRenderPass(m_device->device(), rp, NULL);
3993
3994 // Create new renderpass with alternate sample count from fb
3995 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
3996 attach_desc.samples = VK_SAMPLE_COUNT_4_BIT;
3997 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3998 ASSERT_VK_SUCCESS(err);
3999
4000 // Cause error due to mis-matched sample count between rp & fb
4001 fb_info.renderPass = rp;
Cort Stratton8133ec22017-04-27 16:25:03 +02004002 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00409);
Tobin Ehlis77d717c2016-06-22 14:19:19 -06004003 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4004
4005 m_errorMonitor->VerifyFound();
4006 if (err == VK_SUCCESS) {
4007 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4008 }
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06004009
4010 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis6cfda642016-06-22 16:12:58 -06004011
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06004012 {
4013 // Create an image with 2 mip levels.
4014 VkImageObj image(m_device);
4015 image.Init(128, 128, 2, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
4016 ASSERT_TRUE(image.initialized());
Tobin Ehlis6cfda642016-06-22 16:12:58 -06004017
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06004018 // Create a image view with two mip levels.
4019 VkImageView view;
4020 VkImageViewCreateInfo ivci = {};
4021 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
4022 ivci.image = image.handle();
4023 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
4024 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
4025 ivci.subresourceRange.layerCount = 1;
4026 ivci.subresourceRange.baseMipLevel = 0;
4027 // Set level count to 2 (only 1 is allowed for FB attachment)
4028 ivci.subresourceRange.levelCount = 2;
4029 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4030 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
4031 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6cfda642016-06-22 16:12:58 -06004032
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06004033 // Re-create renderpass to have matching sample count
4034 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
4035 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
4036 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6cfda642016-06-22 16:12:58 -06004037
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06004038 fb_info.renderPass = rp;
4039 fb_info.pAttachments = &view;
Cort Stratton8133ec22017-04-27 16:25:03 +02004040 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00411);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06004041 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4042
4043 m_errorMonitor->VerifyFound();
4044 if (err == VK_SUCCESS) {
4045 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4046 }
4047 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis6cfda642016-06-22 16:12:58 -06004048 }
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06004049
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06004050 // Update view to original color buffer and grow FB dimensions too big
4051 fb_info.pAttachments = ivs;
4052 fb_info.height = 1024;
4053 fb_info.width = 1024;
4054 fb_info.layers = 2;
Cort Stratton8133ec22017-04-27 16:25:03 +02004055 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00410);
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06004056 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4057
4058 m_errorMonitor->VerifyFound();
4059 if (err == VK_SUCCESS) {
4060 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4061 }
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06004062
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06004063 {
4064 // Create an image with one mip level.
4065 VkImageObj image(m_device);
4066 image.Init(128, 128, 1, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
4067 ASSERT_TRUE(image.initialized());
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06004068
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06004069 // Create view attachment with non-identity swizzle
4070 VkImageView view;
4071 VkImageViewCreateInfo ivci = {};
4072 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
4073 ivci.image = image.handle();
4074 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
4075 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
4076 ivci.subresourceRange.layerCount = 1;
4077 ivci.subresourceRange.baseMipLevel = 0;
4078 ivci.subresourceRange.levelCount = 1;
4079 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4080 ivci.components.r = VK_COMPONENT_SWIZZLE_G;
4081 ivci.components.g = VK_COMPONENT_SWIZZLE_R;
4082 ivci.components.b = VK_COMPONENT_SWIZZLE_A;
4083 ivci.components.a = VK_COMPONENT_SWIZZLE_B;
4084 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
4085 ASSERT_VK_SUCCESS(err);
4086
4087 fb_info.pAttachments = &view;
4088 fb_info.height = 100;
4089 fb_info.width = 100;
4090 fb_info.layers = 1;
4091
Cort Stratton8133ec22017-04-27 16:25:03 +02004092 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00412);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06004093 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4094
4095 m_errorMonitor->VerifyFound();
4096 if (err == VK_SUCCESS) {
4097 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4098 }
4099 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06004100 }
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06004101
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004102 // reset attachment to color attachment
4103 fb_info.pAttachments = ivs;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004104
4105 // Request fb that exceeds max width
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004106 fb_info.width = m_device->props.limits.maxFramebufferWidth + 1;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004107 fb_info.height = 100;
4108 fb_info.layers = 1;
4109 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00413);
Cort Stratton8133ec22017-04-27 16:25:03 +02004110 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00410);
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004111 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
Cort Stratton8133ec22017-04-27 16:25:03 +02004112 m_errorMonitor->VerifyFound();
4113 if (err == VK_SUCCESS) {
4114 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4115 }
4116 // and width=0
4117 fb_info.width = 0;
4118 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02806);
4119 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004120 m_errorMonitor->VerifyFound();
4121 if (err == VK_SUCCESS) {
4122 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4123 }
4124
4125 // Request fb that exceeds max height
4126 fb_info.width = 100;
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004127 fb_info.height = m_device->props.limits.maxFramebufferHeight + 1;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004128 fb_info.layers = 1;
4129 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00414);
Cort Stratton8133ec22017-04-27 16:25:03 +02004130 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00410);
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004131 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
Cort Stratton8133ec22017-04-27 16:25:03 +02004132 m_errorMonitor->VerifyFound();
4133 if (err == VK_SUCCESS) {
4134 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4135 }
4136 // and height=0
4137 fb_info.height = 0;
4138 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02807);
4139 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004140 m_errorMonitor->VerifyFound();
4141 if (err == VK_SUCCESS) {
4142 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4143 }
4144
4145 // Request fb that exceeds max layers
4146 fb_info.width = 100;
4147 fb_info.height = 100;
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004148 fb_info.layers = m_device->props.limits.maxFramebufferLayers + 1;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004149 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00415);
Cort Stratton8133ec22017-04-27 16:25:03 +02004150 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00410);
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004151 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
Cort Stratton8133ec22017-04-27 16:25:03 +02004152 m_errorMonitor->VerifyFound();
4153 if (err == VK_SUCCESS) {
4154 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4155 }
4156 // and layers=0
4157 fb_info.layers = 0;
4158 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02808);
4159 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004160 m_errorMonitor->VerifyFound();
4161 if (err == VK_SUCCESS) {
4162 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4163 }
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06004164
Tobin Ehlis6cfda642016-06-22 16:12:58 -06004165 vkDestroyRenderPass(m_device->device(), rp, NULL);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004166}
4167
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004168TEST_F(VkLayerTest, DynamicDepthBiasNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004169 TEST_DESCRIPTION(
4170 "Run a simple draw calls to validate failure when Depth Bias dynamic "
4171 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004172
Tony Barbour1fa09702017-03-16 12:09:08 -06004173 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004174 // Dynamic depth bias
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004175 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic depth bias state not set for this command buffer");
4176 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBias);
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004177 m_errorMonitor->VerifyFound();
4178}
4179
4180TEST_F(VkLayerTest, DynamicLineWidthNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004181 TEST_DESCRIPTION(
4182 "Run a simple draw calls to validate failure when Line Width dynamic "
4183 "state is required but not correctly bound.");
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004184
Tony Barbour1fa09702017-03-16 12:09:08 -06004185 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004186 // Dynamic line width
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004187 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic line width state not set for this command buffer");
4188 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailLineWidth);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004189 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004190}
4191
4192TEST_F(VkLayerTest, DynamicViewportNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004193 TEST_DESCRIPTION(
4194 "Run a simple draw calls to validate failure when Viewport dynamic "
4195 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004196
Tony Barbour1fa09702017-03-16 12:09:08 -06004197 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004198 // Dynamic viewport state
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07004199 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4200 "Dynamic viewport(s) 0 are used by pipeline state object, but were not provided");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004201 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailViewport);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004202 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004203}
4204
4205TEST_F(VkLayerTest, DynamicScissorNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004206 TEST_DESCRIPTION(
4207 "Run a simple draw calls to validate failure when Scissor dynamic "
4208 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004209
Tony Barbour1fa09702017-03-16 12:09:08 -06004210 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004211 // Dynamic scissor state
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07004212 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4213 "Dynamic scissor(s) 0 are used by pipeline state object, but were not provided");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004214 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailScissor);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004215 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004216}
4217
Cortd713fe82016-07-27 09:51:27 -07004218TEST_F(VkLayerTest, DynamicBlendConstantsNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004219 TEST_DESCRIPTION(
4220 "Run a simple draw calls to validate failure when Blend Constants "
4221 "dynamic state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004222
Tony Barbour1fa09702017-03-16 12:09:08 -06004223 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis21c88352016-05-26 06:15:45 -06004224 // Dynamic blend constant state
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004225 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4226 "Dynamic blend constants state not set for this command buffer");
4227 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailBlend);
Tobin Ehlis21c88352016-05-26 06:15:45 -06004228 m_errorMonitor->VerifyFound();
4229}
4230
4231TEST_F(VkLayerTest, DynamicDepthBoundsNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004232 TEST_DESCRIPTION(
4233 "Run a simple draw calls to validate failure when Depth Bounds dynamic "
4234 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004235
Tony Barbour1fa09702017-03-16 12:09:08 -06004236 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis21c88352016-05-26 06:15:45 -06004237 if (!m_device->phy().features().depthBounds) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07004238 printf(" Device does not support depthBounds test; skipped.\n");
Tobin Ehlis21c88352016-05-26 06:15:45 -06004239 return;
4240 }
4241 // Dynamic depth bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004242 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4243 "Dynamic depth bounds state not set for this command buffer");
4244 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBounds);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004245 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004246}
4247
4248TEST_F(VkLayerTest, DynamicStencilReadNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004249 TEST_DESCRIPTION(
4250 "Run a simple draw calls to validate failure when Stencil Read dynamic "
4251 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004252
Tony Barbour1fa09702017-03-16 12:09:08 -06004253 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004254 // Dynamic stencil read mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004255 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4256 "Dynamic stencil read mask state not set for this command buffer");
4257 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReadMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004258 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004259}
4260
4261TEST_F(VkLayerTest, DynamicStencilWriteNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004262 TEST_DESCRIPTION(
4263 "Run a simple draw calls to validate failure when Stencil Write dynamic"
4264 " state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004265
Tony Barbour1fa09702017-03-16 12:09:08 -06004266 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004267 // Dynamic stencil write mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004268 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4269 "Dynamic stencil write mask state not set for this command buffer");
4270 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilWriteMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004271 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004272}
4273
4274TEST_F(VkLayerTest, DynamicStencilRefNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004275 TEST_DESCRIPTION(
4276 "Run a simple draw calls to validate failure when Stencil Ref dynamic "
4277 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004278
Tony Barbour1fa09702017-03-16 12:09:08 -06004279 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004280 // Dynamic stencil reference
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004281 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4282 "Dynamic stencil reference state not set for this command buffer");
4283 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReference);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004284 m_errorMonitor->VerifyFound();
Tobin Ehlis963a4042015-09-29 08:18:34 -06004285}
4286
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06004287TEST_F(VkLayerTest, IndexBufferNotBound) {
4288 TEST_DESCRIPTION("Run an indexed draw call without an index buffer bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004289
Tony Barbour1fa09702017-03-16 12:09:08 -06004290 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004291 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4292 "Index buffer object not bound to this command buffer when Indexed ");
4293 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailIndexBuffer);
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06004294 m_errorMonitor->VerifyFound();
4295}
4296
Karl Schultz6addd812016-02-02 17:17:23 -07004297TEST_F(VkLayerTest, CommandBufferTwoSubmits) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004298 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4299 "was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has "
4300 "been submitted");
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004301
Tony Barbour1fa09702017-03-16 12:09:08 -06004302 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004303 ASSERT_NO_FATAL_FAILURE(InitViewport());
4304 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4305
Karl Schultz6addd812016-02-02 17:17:23 -07004306 // We luck out b/c by default the framework creates CB w/ the
4307 // VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set
Tony Barbour552f6c02016-12-21 14:34:07 -07004308 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004309 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbour552f6c02016-12-21 14:34:07 -07004310 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004311
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004312 // Bypass framework since it does the waits automatically
4313 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06004314 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08004315 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4316 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004317 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06004318 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07004319 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004320 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004321 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08004322 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06004323 submit_info.pSignalSemaphores = NULL;
4324
Chris Forbes40028e22016-06-13 09:59:34 +12004325 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Karl Schultz6addd812016-02-02 17:17:23 -07004326 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski89cad1a2016-11-11 15:51:31 -07004327 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004328
Karl Schultz6addd812016-02-02 17:17:23 -07004329 // Cause validation error by re-submitting cmd buffer that should only be
4330 // submitted once
Chris Forbes40028e22016-06-13 09:59:34 +12004331 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski89cad1a2016-11-11 15:51:31 -07004332 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004333
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004334 m_errorMonitor->VerifyFound();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004335}
4336
Karl Schultz6addd812016-02-02 17:17:23 -07004337TEST_F(VkLayerTest, AllocDescriptorFromEmptyPool) {
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004338 TEST_DESCRIPTION("Attempt to allocate more sets and descriptors than descriptor pool has available.");
Karl Schultz6addd812016-02-02 17:17:23 -07004339 VkResult err;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004340
Tony Barbour1fa09702017-03-16 12:09:08 -06004341 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004342 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004343
Karl Schultz6addd812016-02-02 17:17:23 -07004344 // Create Pool w/ 1 Sampler descriptor, but try to alloc Uniform Buffer
4345 // descriptor from it
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004346 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004347 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004348 ds_type_count.descriptorCount = 2;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004349
4350 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004351 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4352 ds_pool_ci.pNext = NULL;
4353 ds_pool_ci.flags = 0;
4354 ds_pool_ci.maxSets = 1;
4355 ds_pool_ci.poolSizeCount = 1;
4356 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004357
4358 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004359 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004360 ASSERT_VK_SUCCESS(err);
4361
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004362 VkDescriptorSetLayoutBinding dsl_binding_samp = {};
4363 dsl_binding_samp.binding = 0;
4364 dsl_binding_samp.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
4365 dsl_binding_samp.descriptorCount = 1;
4366 dsl_binding_samp.stageFlags = VK_SHADER_STAGE_ALL;
4367 dsl_binding_samp.pImmutableSamplers = NULL;
4368
4369 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4370 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4371 ds_layout_ci.pNext = NULL;
4372 ds_layout_ci.bindingCount = 1;
4373 ds_layout_ci.pBindings = &dsl_binding_samp;
4374
4375 VkDescriptorSetLayout ds_layout_samp;
4376 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_samp);
4377 ASSERT_VK_SUCCESS(err);
4378
4379 // Try to allocate 2 sets when pool only has 1 set
4380 VkDescriptorSet descriptor_sets[2];
4381 VkDescriptorSetLayout set_layouts[2] = {ds_layout_samp, ds_layout_samp};
4382 VkDescriptorSetAllocateInfo alloc_info = {};
4383 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4384 alloc_info.descriptorSetCount = 2;
4385 alloc_info.descriptorPool = ds_pool;
4386 alloc_info.pSetLayouts = set_layouts;
4387 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00911);
4388 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
4389 m_errorMonitor->VerifyFound();
4390
4391 alloc_info.descriptorSetCount = 1;
4392 // Create layout w/ descriptor type not available in pool
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004393 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004394 dsl_binding.binding = 0;
4395 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4396 dsl_binding.descriptorCount = 1;
4397 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4398 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004399
Karl Schultz6addd812016-02-02 17:17:23 -07004400 ds_layout_ci.bindingCount = 1;
4401 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004402
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004403 VkDescriptorSetLayout ds_layout_ub;
4404 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_ub);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004405 ASSERT_VK_SUCCESS(err);
4406
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004407 VkDescriptorSet descriptor_set;
Jon Ashburnf19916e2016-01-11 13:12:43 -07004408 alloc_info.descriptorSetCount = 1;
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004409 alloc_info.pSetLayouts = &ds_layout_ub;
4410 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00912);
4411 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004412
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004413 m_errorMonitor->VerifyFound();
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004414
Karl Schultz2825ab92016-12-02 08:23:14 -07004415 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_samp, NULL);
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004416 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_ub, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +08004417 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004418}
4419
Karl Schultz6addd812016-02-02 17:17:23 -07004420TEST_F(VkLayerTest, FreeDescriptorFromOneShotPool) {
4421 VkResult err;
Tobin Ehlise735c692015-10-08 13:13:50 -06004422
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07004423 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00922);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004424
Tony Barbour1fa09702017-03-16 12:09:08 -06004425 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlise735c692015-10-08 13:13:50 -06004426 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise735c692015-10-08 13:13:50 -06004427
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004428 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004429 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4430 ds_type_count.descriptorCount = 1;
Tobin Ehlise735c692015-10-08 13:13:50 -06004431
4432 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004433 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4434 ds_pool_ci.pNext = NULL;
4435 ds_pool_ci.maxSets = 1;
4436 ds_pool_ci.poolSizeCount = 1;
4437 ds_pool_ci.flags = 0;
4438 // Not specifying VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT means
4439 // app can only call vkResetDescriptorPool on this pool.;
4440 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise735c692015-10-08 13:13:50 -06004441
4442 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004443 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise735c692015-10-08 13:13:50 -06004444 ASSERT_VK_SUCCESS(err);
4445
4446 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004447 dsl_binding.binding = 0;
4448 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4449 dsl_binding.descriptorCount = 1;
4450 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4451 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise735c692015-10-08 13:13:50 -06004452
4453 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004454 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4455 ds_layout_ci.pNext = NULL;
4456 ds_layout_ci.bindingCount = 1;
4457 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise735c692015-10-08 13:13:50 -06004458
4459 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004460 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise735c692015-10-08 13:13:50 -06004461 ASSERT_VK_SUCCESS(err);
4462
4463 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004464 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08004465 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07004466 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06004467 alloc_info.descriptorPool = ds_pool;
4468 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004469 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise735c692015-10-08 13:13:50 -06004470 ASSERT_VK_SUCCESS(err);
4471
4472 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004473 m_errorMonitor->VerifyFound();
Tobin Ehlise735c692015-10-08 13:13:50 -06004474
Chia-I Wuf7458c52015-10-26 21:10:41 +08004475 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4476 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise735c692015-10-08 13:13:50 -06004477}
4478
Karl Schultz6addd812016-02-02 17:17:23 -07004479TEST_F(VkLayerTest, InvalidDescriptorPool) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004480 // Attempt to clear Descriptor Pool with bad object.
4481 // ObjectTracker should catch this.
Cody Northropc31a84f2016-08-22 10:41:47 -06004482
Tony Barbour1fa09702017-03-16 12:09:08 -06004483 ASSERT_NO_FATAL_FAILURE(Init());
Karl Schultzf78bcdd2016-11-30 12:36:01 -07004484 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00930);
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004485 uint64_t fake_pool_handle = 0xbaad6001;
4486 VkDescriptorPool bad_pool = reinterpret_cast<VkDescriptorPool &>(fake_pool_handle);
4487 vkResetDescriptorPool(device(), bad_pool, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -06004488 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004489}
4490
Karl Schultzf78bcdd2016-11-30 12:36:01 -07004491TEST_F(VkLayerTest, InvalidDescriptorSet) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004492 // Attempt to bind an invalid Descriptor Set to a valid Command Buffer
4493 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004494 // Create a valid cmd buffer
Karl Schultzbdb75952016-04-19 11:36:49 -06004495 // call vkCmdBindDescriptorSets w/ false Descriptor Set
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004496
4497 uint64_t fake_set_handle = 0xbaad6001;
4498 VkDescriptorSet bad_set = reinterpret_cast<VkDescriptorSet &>(fake_set_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06004499 VkResult err;
Karl Schultzf78bcdd2016-11-30 12:36:01 -07004500 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00982);
Karl Schultzbdb75952016-04-19 11:36:49 -06004501
Tony Barbour1fa09702017-03-16 12:09:08 -06004502 ASSERT_NO_FATAL_FAILURE(Init());
Karl Schultzbdb75952016-04-19 11:36:49 -06004503
4504 VkDescriptorSetLayoutBinding layout_bindings[1] = {};
4505 layout_bindings[0].binding = 0;
4506 layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4507 layout_bindings[0].descriptorCount = 1;
4508 layout_bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
4509 layout_bindings[0].pImmutableSamplers = NULL;
4510
4511 VkDescriptorSetLayout descriptor_set_layout;
4512 VkDescriptorSetLayoutCreateInfo dslci = {};
4513 dslci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4514 dslci.pNext = NULL;
4515 dslci.bindingCount = 1;
4516 dslci.pBindings = layout_bindings;
4517 err = vkCreateDescriptorSetLayout(device(), &dslci, NULL, &descriptor_set_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06004518 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06004519
4520 VkPipelineLayout pipeline_layout;
4521 VkPipelineLayoutCreateInfo plci = {};
4522 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4523 plci.pNext = NULL;
4524 plci.setLayoutCount = 1;
4525 plci.pSetLayouts = &descriptor_set_layout;
4526 err = vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06004527 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06004528
Tony Barbour552f6c02016-12-21 14:34:07 -07004529 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004530 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &bad_set, 0,
4531 NULL);
Karl Schultzbdb75952016-04-19 11:36:49 -06004532 m_errorMonitor->VerifyFound();
Tony Barbour552f6c02016-12-21 14:34:07 -07004533 m_commandBuffer->EndCommandBuffer();
Karl Schultzbdb75952016-04-19 11:36:49 -06004534 vkDestroyPipelineLayout(device(), pipeline_layout, NULL);
4535 vkDestroyDescriptorSetLayout(device(), descriptor_set_layout, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004536}
4537
Karl Schultz6addd812016-02-02 17:17:23 -07004538TEST_F(VkLayerTest, InvalidDescriptorSetLayout) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004539 // Attempt to create a Pipeline Layout with an invalid Descriptor Set Layout.
4540 // ObjectTracker should catch this.
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004541 uint64_t fake_layout_handle = 0xbaad6001;
4542 VkDescriptorSetLayout bad_layout = reinterpret_cast<VkDescriptorSetLayout &>(fake_layout_handle);
Karl Schultzf78bcdd2016-11-30 12:36:01 -07004543 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00875);
Tony Barbour1fa09702017-03-16 12:09:08 -06004544 ASSERT_NO_FATAL_FAILURE(Init());
Karl Schultzbdb75952016-04-19 11:36:49 -06004545 VkPipelineLayout pipeline_layout;
4546 VkPipelineLayoutCreateInfo plci = {};
4547 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4548 plci.pNext = NULL;
4549 plci.setLayoutCount = 1;
4550 plci.pSetLayouts = &bad_layout;
4551 vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
4552
4553 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004554}
4555
Mark Muellerd4914412016-06-13 17:52:06 -06004556TEST_F(VkLayerTest, WriteDescriptorSetIntegrityCheck) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004557 TEST_DESCRIPTION(
4558 "This test verifies some requirements of chapter 13.2.3 of the Vulkan Spec "
4559 "1) A uniform buffer update must have a valid buffer index."
4560 "2) When using an array of descriptors in a single WriteDescriptor,"
4561 " the descriptor types and stageflags must all be the same."
4562 "3) Immutable Sampler state must match across descriptors");
Mark Muellerd4914412016-06-13 17:52:06 -06004563
Mike Weiblena6666382017-01-05 15:16:11 -07004564 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00941);
Mark Muellerd4914412016-06-13 17:52:06 -06004565
Tony Barbour1fa09702017-03-16 12:09:08 -06004566 ASSERT_NO_FATAL_FAILURE(Init());
Mark Muellerd4914412016-06-13 17:52:06 -06004567 VkDescriptorPoolSize ds_type_count[4] = {};
4568 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4569 ds_type_count[0].descriptorCount = 1;
Tony Barboure132c5f2016-12-12 11:50:20 -07004570 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Muellerd4914412016-06-13 17:52:06 -06004571 ds_type_count[1].descriptorCount = 1;
Tony Barboure132c5f2016-12-12 11:50:20 -07004572 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Muellerd4914412016-06-13 17:52:06 -06004573 ds_type_count[2].descriptorCount = 1;
4574 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
4575 ds_type_count[3].descriptorCount = 1;
4576
4577 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4578 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4579 ds_pool_ci.maxSets = 1;
4580 ds_pool_ci.poolSizeCount = sizeof(ds_type_count) / sizeof(VkDescriptorPoolSize);
4581 ds_pool_ci.pPoolSizes = ds_type_count;
4582
4583 VkDescriptorPool ds_pool;
4584 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
4585 ASSERT_VK_SUCCESS(err);
4586
Mark Muellerb9896722016-06-16 09:54:29 -06004587 VkDescriptorSetLayoutBinding layout_binding[3] = {};
Mark Muellerd4914412016-06-13 17:52:06 -06004588 layout_binding[0].binding = 0;
4589 layout_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4590 layout_binding[0].descriptorCount = 1;
4591 layout_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
4592 layout_binding[0].pImmutableSamplers = NULL;
4593
4594 layout_binding[1].binding = 1;
4595 layout_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
4596 layout_binding[1].descriptorCount = 1;
4597 layout_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4598 layout_binding[1].pImmutableSamplers = NULL;
4599
4600 VkSamplerCreateInfo sampler_ci = {};
4601 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
4602 sampler_ci.pNext = NULL;
4603 sampler_ci.magFilter = VK_FILTER_NEAREST;
4604 sampler_ci.minFilter = VK_FILTER_NEAREST;
4605 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
4606 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4607 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4608 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4609 sampler_ci.mipLodBias = 1.0;
4610 sampler_ci.anisotropyEnable = VK_FALSE;
4611 sampler_ci.maxAnisotropy = 1;
4612 sampler_ci.compareEnable = VK_FALSE;
4613 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
4614 sampler_ci.minLod = 1.0;
4615 sampler_ci.maxLod = 1.0;
4616 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
4617 sampler_ci.unnormalizedCoordinates = VK_FALSE;
4618 VkSampler sampler;
4619
4620 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
4621 ASSERT_VK_SUCCESS(err);
4622
4623 layout_binding[2].binding = 2;
4624 layout_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
4625 layout_binding[2].descriptorCount = 1;
4626 layout_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4627 layout_binding[2].pImmutableSamplers = static_cast<VkSampler *>(&sampler);
4628
Mark Muellerd4914412016-06-13 17:52:06 -06004629 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4630 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4631 ds_layout_ci.bindingCount = sizeof(layout_binding) / sizeof(VkDescriptorSetLayoutBinding);
4632 ds_layout_ci.pBindings = layout_binding;
4633 VkDescriptorSetLayout ds_layout;
4634 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
4635 ASSERT_VK_SUCCESS(err);
4636
4637 VkDescriptorSetAllocateInfo alloc_info = {};
4638 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4639 alloc_info.descriptorSetCount = 1;
4640 alloc_info.descriptorPool = ds_pool;
4641 alloc_info.pSetLayouts = &ds_layout;
4642 VkDescriptorSet descriptorSet;
4643 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
4644 ASSERT_VK_SUCCESS(err);
4645
4646 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4647 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4648 pipeline_layout_ci.pNext = NULL;
4649 pipeline_layout_ci.setLayoutCount = 1;
4650 pipeline_layout_ci.pSetLayouts = &ds_layout;
4651
4652 VkPipelineLayout pipeline_layout;
4653 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4654 ASSERT_VK_SUCCESS(err);
4655
Mark Mueller5c838ce2016-06-16 09:54:29 -06004656 VkWriteDescriptorSet descriptor_write = {};
Mark Muellerd4914412016-06-13 17:52:06 -06004657 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4658 descriptor_write.dstSet = descriptorSet;
4659 descriptor_write.dstBinding = 0;
4660 descriptor_write.descriptorCount = 1;
4661 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4662
Mark Mueller5c838ce2016-06-16 09:54:29 -06004663 // 1) The uniform buffer is intentionally invalid here
Mark Muellerd4914412016-06-13 17:52:06 -06004664 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4665 m_errorMonitor->VerifyFound();
4666
4667 // Create a buffer to update the descriptor with
4668 uint32_t qfi = 0;
4669 VkBufferCreateInfo buffCI = {};
4670 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4671 buffCI.size = 1024;
4672 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
4673 buffCI.queueFamilyIndexCount = 1;
4674 buffCI.pQueueFamilyIndices = &qfi;
4675
4676 VkBuffer dyub;
4677 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
4678 ASSERT_VK_SUCCESS(err);
Mark Muellerd4914412016-06-13 17:52:06 -06004679
Tony Barboure132c5f2016-12-12 11:50:20 -07004680 VkDeviceMemory mem;
4681 VkMemoryRequirements mem_reqs;
4682 vkGetBufferMemoryRequirements(m_device->device(), dyub, &mem_reqs);
4683
4684 VkMemoryAllocateInfo mem_alloc_info = {};
4685 mem_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4686 mem_alloc_info.allocationSize = mem_reqs.size;
4687 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
4688 err = vkAllocateMemory(m_device->device(), &mem_alloc_info, NULL, &mem);
4689 ASSERT_VK_SUCCESS(err);
4690
4691 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
4692 ASSERT_VK_SUCCESS(err);
4693
4694 VkDescriptorBufferInfo buffInfo[2] = {};
4695 buffInfo[0].buffer = dyub;
4696 buffInfo[0].offset = 0;
4697 buffInfo[0].range = 1024;
4698 buffInfo[1].buffer = dyub;
4699 buffInfo[1].offset = 0;
4700 buffInfo[1].range = 1024;
4701 descriptor_write.pBufferInfo = buffInfo;
Mark Muellerd4914412016-06-13 17:52:06 -06004702 descriptor_write.descriptorCount = 2;
4703
Mark Mueller5c838ce2016-06-16 09:54:29 -06004704 // 2) The stateFlags don't match between the first and second descriptor
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07004705 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00938);
Mark Muellerd4914412016-06-13 17:52:06 -06004706 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4707 m_errorMonitor->VerifyFound();
4708
Mark Mueller5c838ce2016-06-16 09:54:29 -06004709 // 3) The second descriptor has a null_ptr pImmutableSamplers and
4710 // the third descriptor contains an immutable sampler
Mark Muellerd4914412016-06-13 17:52:06 -06004711 descriptor_write.dstBinding = 1;
4712 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Mueller5c838ce2016-06-16 09:54:29 -06004713
Mark Mueller5c838ce2016-06-16 09:54:29 -06004714 // Make pImageInfo index non-null to avoid complaints of it missing
4715 VkDescriptorImageInfo imageInfo = {};
4716 imageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
4717 descriptor_write.pImageInfo = &imageInfo;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07004718 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00938);
Mark Muellerd4914412016-06-13 17:52:06 -06004719 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4720 m_errorMonitor->VerifyFound();
4721
Mark Muellerd4914412016-06-13 17:52:06 -06004722 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tony Barboure132c5f2016-12-12 11:50:20 -07004723 vkFreeMemory(m_device->device(), mem, NULL);
Mark Muellerd4914412016-06-13 17:52:06 -06004724 vkDestroySampler(m_device->device(), sampler, NULL);
4725 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4726 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4727 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4728}
4729
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004730TEST_F(VkLayerTest, InvalidCmdBufferBufferDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004731 TEST_DESCRIPTION(
4732 "Attempt to draw with a command buffer that is invalid "
4733 "due to a buffer dependency being destroyed.");
Tony Barbour1fa09702017-03-16 12:09:08 -06004734 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004735
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004736 VkBuffer buffer;
4737 VkDeviceMemory mem;
4738 VkMemoryRequirements mem_reqs;
4739
4740 VkBufferCreateInfo buf_info = {};
4741 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes3d5882f2016-09-16 17:37:17 +12004742 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004743 buf_info.size = 256;
4744 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
4745 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
4746 ASSERT_VK_SUCCESS(err);
4747
4748 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
4749
4750 VkMemoryAllocateInfo alloc_info = {};
4751 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4752 alloc_info.allocationSize = 256;
4753 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004754 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004755 if (!pass) {
4756 vkDestroyBuffer(m_device->device(), buffer, NULL);
4757 return;
4758 }
4759 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
4760 ASSERT_VK_SUCCESS(err);
4761
4762 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
4763 ASSERT_VK_SUCCESS(err);
4764
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004765 m_commandBuffer->BeginCommandBuffer();
Chris Forbes3d5882f2016-09-16 17:37:17 +12004766 vkCmdFillBuffer(m_commandBuffer->GetBufferHandle(), buffer, 0, VK_WHOLE_SIZE, 0);
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004767 m_commandBuffer->EndCommandBuffer();
4768
Mark Lobodzinski33826372017-04-13 11:10:11 -06004769 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound Buffer ");
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004770 // Destroy buffer dependency prior to submit to cause ERROR
4771 vkDestroyBuffer(m_device->device(), buffer, NULL);
4772
4773 VkSubmitInfo submit_info = {};
4774 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4775 submit_info.commandBufferCount = 1;
4776 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4777 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4778
4779 m_errorMonitor->VerifyFound();
Rene Lindsayab6c5cd2016-12-20 14:05:37 -07004780 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004781 vkFreeMemory(m_device->handle(), mem, NULL);
4782}
4783
Tobin Ehlisea413442016-09-28 10:23:59 -06004784TEST_F(VkLayerTest, InvalidCmdBufferBufferViewDestroyed) {
4785 TEST_DESCRIPTION("Delete bufferView bound to cmd buffer, then attempt to submit cmd buffer.");
4786
Tony Barbour1fa09702017-03-16 12:09:08 -06004787 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisea413442016-09-28 10:23:59 -06004788 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4789
4790 VkDescriptorPoolSize ds_type_count;
4791 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4792 ds_type_count.descriptorCount = 1;
4793
4794 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4795 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4796 ds_pool_ci.maxSets = 1;
4797 ds_pool_ci.poolSizeCount = 1;
4798 ds_pool_ci.pPoolSizes = &ds_type_count;
4799
4800 VkDescriptorPool ds_pool;
4801 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
4802 ASSERT_VK_SUCCESS(err);
4803
4804 VkDescriptorSetLayoutBinding layout_binding;
4805 layout_binding.binding = 0;
4806 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4807 layout_binding.descriptorCount = 1;
4808 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4809 layout_binding.pImmutableSamplers = NULL;
4810
4811 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4812 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4813 ds_layout_ci.bindingCount = 1;
4814 ds_layout_ci.pBindings = &layout_binding;
4815 VkDescriptorSetLayout ds_layout;
4816 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
4817 ASSERT_VK_SUCCESS(err);
4818
4819 VkDescriptorSetAllocateInfo alloc_info = {};
4820 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4821 alloc_info.descriptorSetCount = 1;
4822 alloc_info.descriptorPool = ds_pool;
4823 alloc_info.pSetLayouts = &ds_layout;
4824 VkDescriptorSet descriptor_set;
4825 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
4826 ASSERT_VK_SUCCESS(err);
4827
4828 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4829 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4830 pipeline_layout_ci.pNext = NULL;
4831 pipeline_layout_ci.setLayoutCount = 1;
4832 pipeline_layout_ci.pSetLayouts = &ds_layout;
4833
4834 VkPipelineLayout pipeline_layout;
4835 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4836 ASSERT_VK_SUCCESS(err);
4837
4838 VkBuffer buffer;
4839 uint32_t queue_family_index = 0;
4840 VkBufferCreateInfo buffer_create_info = {};
4841 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4842 buffer_create_info.size = 1024;
4843 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
4844 buffer_create_info.queueFamilyIndexCount = 1;
4845 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
4846
4847 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
4848 ASSERT_VK_SUCCESS(err);
4849
4850 VkMemoryRequirements memory_reqs;
4851 VkDeviceMemory buffer_memory;
4852
4853 VkMemoryAllocateInfo memory_info = {};
4854 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4855 memory_info.allocationSize = 0;
4856 memory_info.memoryTypeIndex = 0;
4857
4858 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
4859 memory_info.allocationSize = memory_reqs.size;
4860 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
4861 ASSERT_TRUE(pass);
4862
4863 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
4864 ASSERT_VK_SUCCESS(err);
4865 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
4866 ASSERT_VK_SUCCESS(err);
4867
4868 VkBufferView view;
4869 VkBufferViewCreateInfo bvci = {};
4870 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
4871 bvci.buffer = buffer;
Tobin Ehliscc980e12017-05-19 12:05:49 -06004872 bvci.format = VK_FORMAT_R32_SFLOAT;
Tobin Ehlisea413442016-09-28 10:23:59 -06004873 bvci.range = VK_WHOLE_SIZE;
4874
4875 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
4876 ASSERT_VK_SUCCESS(err);
4877
4878 VkWriteDescriptorSet descriptor_write = {};
4879 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4880 descriptor_write.dstSet = descriptor_set;
4881 descriptor_write.dstBinding = 0;
4882 descriptor_write.descriptorCount = 1;
4883 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4884 descriptor_write.pTexelBufferView = &view;
4885
4886 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4887
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004888 char const *vsSource =
4889 "#version 450\n"
4890 "\n"
4891 "out gl_PerVertex { \n"
4892 " vec4 gl_Position;\n"
4893 "};\n"
4894 "void main(){\n"
4895 " gl_Position = vec4(1);\n"
4896 "}\n";
4897 char const *fsSource =
4898 "#version 450\n"
4899 "\n"
Tobin Ehliscc980e12017-05-19 12:05:49 -06004900 "layout(set=0, binding=0, r32f) uniform imageBuffer s;\n"
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004901 "layout(location=0) out vec4 x;\n"
4902 "void main(){\n"
4903 " x = imageLoad(s, 0);\n"
4904 "}\n";
Tobin Ehlisea413442016-09-28 10:23:59 -06004905 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4906 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
4907 VkPipelineObj pipe(m_device);
4908 pipe.AddShader(&vs);
4909 pipe.AddShader(&fs);
4910 pipe.AddColorAttachment();
4911 pipe.CreateVKPipeline(pipeline_layout, renderPass());
4912
Mark Lobodzinski33826372017-04-13 11:10:11 -06004913 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound BufferView ");
Tobin Ehlisea413442016-09-28 10:23:59 -06004914
Tony Barbour552f6c02016-12-21 14:34:07 -07004915 m_commandBuffer->BeginCommandBuffer();
4916 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
4917
Tobin Ehlisea413442016-09-28 10:23:59 -06004918 VkViewport viewport = {0, 0, 16, 16, 0, 1};
4919 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
4920 VkRect2D scissor = {{0, 0}, {16, 16}};
4921 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
4922 // Bind pipeline to cmd buffer
4923 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
4924 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
4925 &descriptor_set, 0, nullptr);
4926 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07004927 m_commandBuffer->EndRenderPass();
4928 m_commandBuffer->EndCommandBuffer();
Tobin Ehlisea413442016-09-28 10:23:59 -06004929
4930 // Delete BufferView in order to invalidate cmd buffer
4931 vkDestroyBufferView(m_device->device(), view, NULL);
4932 // Now attempt submit of cmd buffer
4933 VkSubmitInfo submit_info = {};
4934 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4935 submit_info.commandBufferCount = 1;
4936 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4937 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4938 m_errorMonitor->VerifyFound();
4939
4940 // Clean-up
4941 vkDestroyBuffer(m_device->device(), buffer, NULL);
4942 vkFreeMemory(m_device->device(), buffer_memory, NULL);
4943 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4944 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4945 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4946}
4947
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004948TEST_F(VkLayerTest, InvalidCmdBufferImageDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004949 TEST_DESCRIPTION(
4950 "Attempt to draw with a command buffer that is invalid "
4951 "due to an image dependency being destroyed.");
Tony Barbour1fa09702017-03-16 12:09:08 -06004952 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004953
4954 VkImage image;
4955 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4956 VkImageCreateInfo image_create_info = {};
4957 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4958 image_create_info.pNext = NULL;
4959 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4960 image_create_info.format = tex_format;
4961 image_create_info.extent.width = 32;
4962 image_create_info.extent.height = 32;
4963 image_create_info.extent.depth = 1;
4964 image_create_info.mipLevels = 1;
4965 image_create_info.arrayLayers = 1;
4966 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
4967 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004968 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004969 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004970 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004971 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004972 // Have to bind memory to image before recording cmd in cmd buffer using it
4973 VkMemoryRequirements mem_reqs;
4974 VkDeviceMemory image_mem;
4975 bool pass;
4976 VkMemoryAllocateInfo mem_alloc = {};
4977 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4978 mem_alloc.pNext = NULL;
4979 mem_alloc.memoryTypeIndex = 0;
4980 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
4981 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004982 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004983 ASSERT_TRUE(pass);
4984 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
4985 ASSERT_VK_SUCCESS(err);
4986 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
4987 ASSERT_VK_SUCCESS(err);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004988
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004989 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis764d7072016-07-01 12:54:29 -06004990 VkClearColorValue ccv;
4991 ccv.float32[0] = 1.0f;
4992 ccv.float32[1] = 1.0f;
4993 ccv.float32[2] = 1.0f;
4994 ccv.float32[3] = 1.0f;
4995 VkImageSubresourceRange isr = {};
4996 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004997 isr.baseArrayLayer = 0;
4998 isr.baseMipLevel = 0;
Tobin Ehlis764d7072016-07-01 12:54:29 -06004999 isr.layerCount = 1;
5000 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005001 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06005002 m_commandBuffer->EndCommandBuffer();
5003
Mark Lobodzinski33826372017-04-13 11:10:11 -06005004 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound Image ");
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06005005 // Destroy image dependency prior to submit to cause ERROR
5006 vkDestroyImage(m_device->device(), image, NULL);
5007
5008 VkSubmitInfo submit_info = {};
5009 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5010 submit_info.commandBufferCount = 1;
5011 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5012 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5013
5014 m_errorMonitor->VerifyFound();
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06005015 vkFreeMemory(m_device->device(), image_mem, nullptr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06005016}
5017
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005018TEST_F(VkLayerTest, InvalidCmdBufferFramebufferImageDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005019 TEST_DESCRIPTION(
5020 "Attempt to draw with a command buffer that is invalid "
5021 "due to a framebuffer image dependency being destroyed.");
Tony Barbour1fa09702017-03-16 12:09:08 -06005022 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005023 VkFormatProperties format_properties;
5024 VkResult err = VK_SUCCESS;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005025 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
5026 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005027 return;
5028 }
5029
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005030 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5031
5032 VkImageCreateInfo image_ci = {};
5033 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5034 image_ci.pNext = NULL;
5035 image_ci.imageType = VK_IMAGE_TYPE_2D;
5036 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
5037 image_ci.extent.width = 32;
5038 image_ci.extent.height = 32;
5039 image_ci.extent.depth = 1;
5040 image_ci.mipLevels = 1;
5041 image_ci.arrayLayers = 1;
5042 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
5043 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005044 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT;
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005045 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
5046 image_ci.flags = 0;
5047 VkImage image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005048 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005049
5050 VkMemoryRequirements memory_reqs;
5051 VkDeviceMemory image_memory;
5052 bool pass;
5053 VkMemoryAllocateInfo memory_info = {};
5054 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5055 memory_info.pNext = NULL;
5056 memory_info.allocationSize = 0;
5057 memory_info.memoryTypeIndex = 0;
5058 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5059 memory_info.allocationSize = memory_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005060 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005061 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005062 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005063 ASSERT_VK_SUCCESS(err);
5064 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5065 ASSERT_VK_SUCCESS(err);
5066
5067 VkImageViewCreateInfo ivci = {
5068 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
5069 nullptr,
5070 0,
5071 image,
5072 VK_IMAGE_VIEW_TYPE_2D,
5073 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005074 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005075 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
5076 };
5077 VkImageView view;
5078 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
5079 ASSERT_VK_SUCCESS(err);
5080
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005081 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 32, 32, 1};
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005082 VkFramebuffer fb;
5083 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
5084 ASSERT_VK_SUCCESS(err);
5085
5086 // Just use default renderpass with our framebuffer
5087 m_renderPassBeginInfo.framebuffer = fb;
Jeremy Hayesba817e12017-03-03 15:51:11 -07005088 m_renderPassBeginInfo.renderArea.extent.width = 32;
5089 m_renderPassBeginInfo.renderArea.extent.height = 32;
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005090 // Create Null cmd buffer for submit
Tony Barbour552f6c02016-12-21 14:34:07 -07005091 m_commandBuffer->BeginCommandBuffer();
5092 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
5093 m_commandBuffer->EndRenderPass();
5094 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005095 // Destroy image attached to framebuffer to invalidate cmd buffer
5096 vkDestroyImage(m_device->device(), image, NULL);
5097 // Now attempt to submit cmd buffer and verify error
Mark Lobodzinski33826372017-04-13 11:10:11 -06005098 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound Image ");
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005099 QueueCommandBuffer(false);
5100 m_errorMonitor->VerifyFound();
5101
5102 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
5103 vkDestroyImageView(m_device->device(), view, nullptr);
5104 vkFreeMemory(m_device->device(), image_memory, nullptr);
5105}
5106
Tobin Ehlisb329f992016-10-12 13:20:29 -06005107TEST_F(VkLayerTest, FramebufferInUseDestroyedSignaled) {
5108 TEST_DESCRIPTION("Delete in-use framebuffer.");
Tony Barbour1fa09702017-03-16 12:09:08 -06005109 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisb329f992016-10-12 13:20:29 -06005110 VkFormatProperties format_properties;
5111 VkResult err = VK_SUCCESS;
5112 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
5113
Tobin Ehlisb329f992016-10-12 13:20:29 -06005114 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5115
5116 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06005117 image.Init(256, 256, 1, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Tobin Ehlisb329f992016-10-12 13:20:29 -06005118 ASSERT_TRUE(image.initialized());
5119 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
5120
5121 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
5122 VkFramebuffer fb;
5123 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
5124 ASSERT_VK_SUCCESS(err);
5125
5126 // Just use default renderpass with our framebuffer
5127 m_renderPassBeginInfo.framebuffer = fb;
5128 // Create Null cmd buffer for submit
Tony Barbour552f6c02016-12-21 14:34:07 -07005129 m_commandBuffer->BeginCommandBuffer();
5130 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
5131 m_commandBuffer->EndRenderPass();
5132 m_commandBuffer->EndCommandBuffer();
Tobin Ehlisb329f992016-10-12 13:20:29 -06005133 // Submit cmd buffer to put it in-flight
5134 VkSubmitInfo submit_info = {};
5135 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5136 submit_info.commandBufferCount = 1;
5137 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5138 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5139 // Destroy framebuffer while in-flight
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07005140 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00422);
Tobin Ehlisb329f992016-10-12 13:20:29 -06005141 vkDestroyFramebuffer(m_device->device(), fb, NULL);
5142 m_errorMonitor->VerifyFound();
5143 // Wait for queue to complete so we can safely destroy everything
5144 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005145 m_errorMonitor->SetUnexpectedError("If framebuffer is not VK_NULL_HANDLE, framebuffer must be a valid VkFramebuffer handle");
5146 m_errorMonitor->SetUnexpectedError("Unable to remove Framebuffer obj");
Tobin Ehlisb329f992016-10-12 13:20:29 -06005147 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
5148}
5149
Tobin Ehlis88becd72016-09-21 14:33:41 -06005150TEST_F(VkLayerTest, FramebufferImageInUseDestroyedSignaled) {
5151 TEST_DESCRIPTION("Delete in-use image that's child of framebuffer.");
Tony Barbour1fa09702017-03-16 12:09:08 -06005152 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis88becd72016-09-21 14:33:41 -06005153 VkFormatProperties format_properties;
5154 VkResult err = VK_SUCCESS;
5155 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
Tobin Ehlis88becd72016-09-21 14:33:41 -06005156
Tobin Ehlis88becd72016-09-21 14:33:41 -06005157 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5158
5159 VkImageCreateInfo image_ci = {};
5160 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5161 image_ci.pNext = NULL;
5162 image_ci.imageType = VK_IMAGE_TYPE_2D;
5163 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
5164 image_ci.extent.width = 256;
5165 image_ci.extent.height = 256;
5166 image_ci.extent.depth = 1;
5167 image_ci.mipLevels = 1;
5168 image_ci.arrayLayers = 1;
5169 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
5170 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisc8ca0312016-09-22 07:30:05 -06005171 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Tobin Ehlis88becd72016-09-21 14:33:41 -06005172 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
5173 image_ci.flags = 0;
5174 VkImage image;
5175 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
5176
5177 VkMemoryRequirements memory_reqs;
5178 VkDeviceMemory image_memory;
5179 bool pass;
5180 VkMemoryAllocateInfo memory_info = {};
5181 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5182 memory_info.pNext = NULL;
5183 memory_info.allocationSize = 0;
5184 memory_info.memoryTypeIndex = 0;
5185 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5186 memory_info.allocationSize = memory_reqs.size;
5187 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
5188 ASSERT_TRUE(pass);
5189 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
5190 ASSERT_VK_SUCCESS(err);
5191 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5192 ASSERT_VK_SUCCESS(err);
5193
5194 VkImageViewCreateInfo ivci = {
5195 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
5196 nullptr,
5197 0,
5198 image,
5199 VK_IMAGE_VIEW_TYPE_2D,
5200 VK_FORMAT_B8G8R8A8_UNORM,
5201 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
5202 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
5203 };
5204 VkImageView view;
5205 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
5206 ASSERT_VK_SUCCESS(err);
5207
5208 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
5209 VkFramebuffer fb;
5210 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
5211 ASSERT_VK_SUCCESS(err);
5212
5213 // Just use default renderpass with our framebuffer
5214 m_renderPassBeginInfo.framebuffer = fb;
5215 // Create Null cmd buffer for submit
Tony Barbour552f6c02016-12-21 14:34:07 -07005216 m_commandBuffer->BeginCommandBuffer();
5217 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
5218 m_commandBuffer->EndRenderPass();
5219 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis88becd72016-09-21 14:33:41 -06005220 // Submit cmd buffer to put it (and attached imageView) in-flight
5221 VkSubmitInfo submit_info = {};
5222 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5223 submit_info.commandBufferCount = 1;
5224 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5225 // Submit cmd buffer to put framebuffer and children in-flight
5226 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5227 // Destroy image attached to framebuffer while in-flight
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07005228 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00743);
Tobin Ehlis88becd72016-09-21 14:33:41 -06005229 vkDestroyImage(m_device->device(), image, NULL);
5230 m_errorMonitor->VerifyFound();
5231 // Wait for queue to complete so we can safely destroy image and other objects
5232 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005233 m_errorMonitor->SetUnexpectedError("If image is not VK_NULL_HANDLE, image must be a valid VkImage handle");
5234 m_errorMonitor->SetUnexpectedError("Unable to remove Image obj");
Tobin Ehlis88becd72016-09-21 14:33:41 -06005235 vkDestroyImage(m_device->device(), image, NULL);
5236 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
5237 vkDestroyImageView(m_device->device(), view, nullptr);
5238 vkFreeMemory(m_device->device(), image_memory, nullptr);
5239}
5240
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005241TEST_F(VkLayerTest, RenderPassInUseDestroyedSignaled) {
5242 TEST_DESCRIPTION("Delete in-use renderPass.");
5243
Tony Barbour1fa09702017-03-16 12:09:08 -06005244 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005245 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5246
5247 // Create simple renderpass
5248 VkAttachmentReference attach = {};
5249 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
5250 VkSubpassDescription subpass = {};
Dave Houlton756e6742017-03-23 14:33:22 -06005251 subpass.colorAttachmentCount = 1;
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005252 subpass.pColorAttachments = &attach;
5253 VkRenderPassCreateInfo rpci = {};
5254 rpci.subpassCount = 1;
5255 rpci.pSubpasses = &subpass;
5256 rpci.attachmentCount = 1;
5257 VkAttachmentDescription attach_desc = {};
5258 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
5259 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
5260 rpci.pAttachments = &attach_desc;
5261 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
5262 VkRenderPass rp;
5263 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
5264 ASSERT_VK_SUCCESS(err);
5265
5266 // Create a pipeline that uses the given renderpass
5267 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5268 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5269
5270 VkPipelineLayout pipeline_layout;
5271 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
5272 ASSERT_VK_SUCCESS(err);
5273
5274 VkPipelineViewportStateCreateInfo vp_state_ci = {};
5275 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
5276 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005277 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005278 vp_state_ci.pViewports = &vp;
5279 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005280 VkRect2D scissors = {}; // Dummy scissors to point to
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005281 vp_state_ci.pScissors = &scissors;
5282
5283 VkPipelineShaderStageCreateInfo shaderStages[2];
5284 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
5285
5286 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005287 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005288 // but add it to be able to run on more devices
5289 shaderStages[0] = vs.GetStageCreateInfo();
5290 shaderStages[1] = fs.GetStageCreateInfo();
5291
5292 VkPipelineVertexInputStateCreateInfo vi_ci = {};
5293 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
5294
5295 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
5296 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
5297 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
5298
5299 VkPipelineRasterizationStateCreateInfo rs_ci = {};
5300 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
5301 rs_ci.rasterizerDiscardEnable = true;
5302 rs_ci.lineWidth = 1.0f;
5303
5304 VkPipelineColorBlendAttachmentState att = {};
5305 att.blendEnable = VK_FALSE;
5306 att.colorWriteMask = 0xf;
5307
5308 VkPipelineColorBlendStateCreateInfo cb_ci = {};
5309 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
5310 cb_ci.attachmentCount = 1;
5311 cb_ci.pAttachments = &att;
5312
5313 VkGraphicsPipelineCreateInfo gp_ci = {};
5314 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
5315 gp_ci.stageCount = 2;
5316 gp_ci.pStages = shaderStages;
5317 gp_ci.pVertexInputState = &vi_ci;
5318 gp_ci.pInputAssemblyState = &ia_ci;
5319 gp_ci.pViewportState = &vp_state_ci;
5320 gp_ci.pRasterizationState = &rs_ci;
5321 gp_ci.pColorBlendState = &cb_ci;
5322 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
5323 gp_ci.layout = pipeline_layout;
5324 gp_ci.renderPass = rp;
5325
5326 VkPipelineCacheCreateInfo pc_ci = {};
5327 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
5328
Dave Houlton756e6742017-03-23 14:33:22 -06005329 m_errorMonitor->ExpectSuccess();
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005330 VkPipeline pipeline;
5331 VkPipelineCache pipe_cache;
5332 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipe_cache);
5333 ASSERT_VK_SUCCESS(err);
5334
5335 err = vkCreateGraphicsPipelines(m_device->device(), pipe_cache, 1, &gp_ci, NULL, &pipeline);
5336 ASSERT_VK_SUCCESS(err);
Dave Houlton756e6742017-03-23 14:33:22 -06005337
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005338 // Bind pipeline to cmd buffer, will also bind renderpass
5339 m_commandBuffer->BeginCommandBuffer();
5340 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
5341 m_commandBuffer->EndCommandBuffer();
5342
5343 VkSubmitInfo submit_info = {};
5344 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5345 submit_info.commandBufferCount = 1;
5346 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5347 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Dave Houlton756e6742017-03-23 14:33:22 -06005348 m_errorMonitor->VerifyNotFound();
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005349
5350 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00393);
5351 vkDestroyRenderPass(m_device->device(), rp, nullptr);
5352 m_errorMonitor->VerifyFound();
5353
5354 // Wait for queue to complete so we can safely destroy everything
5355 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005356 m_errorMonitor->SetUnexpectedError("If renderPass is not VK_NULL_HANDLE, renderPass must be a valid VkRenderPass handle");
Mark Lobodzinski74597792017-04-11 15:43:49 -06005357 m_errorMonitor->SetUnexpectedError("Unable to remove RenderPass obj");
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005358 vkDestroyRenderPass(m_device->device(), rp, nullptr);
5359 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
5360 vkDestroyPipelineCache(m_device->device(), pipe_cache, nullptr);
5361 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
5362}
5363
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005364TEST_F(VkLayerTest, ImageMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005365 TEST_DESCRIPTION("Attempt to draw with an image which has not had memory bound to it.");
Tony Barbour1fa09702017-03-16 12:09:08 -06005366 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005367
5368 VkImage image;
5369 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5370 VkImageCreateInfo image_create_info = {};
5371 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5372 image_create_info.pNext = NULL;
5373 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5374 image_create_info.format = tex_format;
5375 image_create_info.extent.width = 32;
5376 image_create_info.extent.height = 32;
5377 image_create_info.extent.depth = 1;
5378 image_create_info.mipLevels = 1;
5379 image_create_info.arrayLayers = 1;
5380 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5381 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005382 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005383 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005384 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005385 ASSERT_VK_SUCCESS(err);
5386 // Have to bind memory to image before recording cmd in cmd buffer using it
5387 VkMemoryRequirements mem_reqs;
5388 VkDeviceMemory image_mem;
5389 bool pass;
5390 VkMemoryAllocateInfo mem_alloc = {};
5391 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5392 mem_alloc.pNext = NULL;
5393 mem_alloc.memoryTypeIndex = 0;
5394 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
5395 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005396 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005397 ASSERT_TRUE(pass);
5398 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
5399 ASSERT_VK_SUCCESS(err);
5400
Tobin Ehlisfed999f2016-09-21 15:09:45 -06005401 // Introduce error, do not call vkBindImageMemory(m_device->device(), image, image_mem, 0);
5402 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005403 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005404
5405 m_commandBuffer->BeginCommandBuffer();
5406 VkClearColorValue ccv;
5407 ccv.float32[0] = 1.0f;
5408 ccv.float32[1] = 1.0f;
5409 ccv.float32[2] = 1.0f;
5410 ccv.float32[3] = 1.0f;
5411 VkImageSubresourceRange isr = {};
5412 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
5413 isr.baseArrayLayer = 0;
5414 isr.baseMipLevel = 0;
5415 isr.layerCount = 1;
5416 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005417 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005418 m_commandBuffer->EndCommandBuffer();
5419
5420 m_errorMonitor->VerifyFound();
5421 vkDestroyImage(m_device->device(), image, NULL);
5422 vkFreeMemory(m_device->device(), image_mem, nullptr);
5423}
5424
5425TEST_F(VkLayerTest, BufferMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005426 TEST_DESCRIPTION("Attempt to copy from a buffer which has not had memory bound to it.");
Tony Barbour1fa09702017-03-16 12:09:08 -06005427 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005428
5429 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06005430 image.Init(128, 128, 1, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005431 VK_IMAGE_TILING_OPTIMAL, 0);
5432 ASSERT_TRUE(image.initialized());
5433
5434 VkBuffer buffer;
5435 VkDeviceMemory mem;
5436 VkMemoryRequirements mem_reqs;
5437
5438 VkBufferCreateInfo buf_info = {};
5439 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes8d260dd2016-09-16 17:42:42 +12005440 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski80871462017-02-16 10:37:27 -07005441 buf_info.size = 1024;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005442 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
5443 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
5444 ASSERT_VK_SUCCESS(err);
5445
5446 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
5447
5448 VkMemoryAllocateInfo alloc_info = {};
5449 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Mark Lobodzinski80871462017-02-16 10:37:27 -07005450 alloc_info.allocationSize = 1024;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005451 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005452 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005453 if (!pass) {
5454 vkDestroyBuffer(m_device->device(), buffer, NULL);
5455 return;
5456 }
5457 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
5458 ASSERT_VK_SUCCESS(err);
5459
Tobin Ehlisfed999f2016-09-21 15:09:45 -06005460 // Introduce failure by not calling vkBindBufferMemory(m_device->device(), buffer, mem, 0);
5461 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005462 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005463 VkBufferImageCopy region = {};
Mark Lobodzinski80871462017-02-16 10:37:27 -07005464 region.bufferRowLength = 16;
5465 region.bufferImageHeight = 16;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005466 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
5467
5468 region.imageSubresource.layerCount = 1;
5469 region.imageExtent.height = 4;
5470 region.imageExtent.width = 4;
5471 region.imageExtent.depth = 1;
5472 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005473 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer, image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
5474 &region);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005475 m_commandBuffer->EndCommandBuffer();
5476
5477 m_errorMonitor->VerifyFound();
5478
5479 vkDestroyBuffer(m_device->device(), buffer, NULL);
5480 vkFreeMemory(m_device->handle(), mem, NULL);
5481}
5482
Tobin Ehlis85940f52016-07-07 16:57:21 -06005483TEST_F(VkLayerTest, InvalidCmdBufferEventDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005484 TEST_DESCRIPTION(
5485 "Attempt to draw with a command buffer that is invalid "
5486 "due to an event dependency being destroyed.");
Tony Barbour1fa09702017-03-16 12:09:08 -06005487 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis85940f52016-07-07 16:57:21 -06005488
5489 VkEvent event;
5490 VkEventCreateInfo evci = {};
5491 evci.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
5492 VkResult result = vkCreateEvent(m_device->device(), &evci, NULL, &event);
5493 ASSERT_VK_SUCCESS(result);
5494
5495 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005496 vkCmdSetEvent(m_commandBuffer->GetBufferHandle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Tobin Ehlis85940f52016-07-07 16:57:21 -06005497 m_commandBuffer->EndCommandBuffer();
5498
Mark Lobodzinski33826372017-04-13 11:10:11 -06005499 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound Event ");
Tobin Ehlis85940f52016-07-07 16:57:21 -06005500 // Destroy event dependency prior to submit to cause ERROR
5501 vkDestroyEvent(m_device->device(), event, NULL);
5502
5503 VkSubmitInfo submit_info = {};
5504 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5505 submit_info.commandBufferCount = 1;
5506 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5507 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5508
5509 m_errorMonitor->VerifyFound();
5510}
5511
Tobin Ehlisdbea7552016-07-08 14:33:31 -06005512TEST_F(VkLayerTest, InvalidCmdBufferQueryPoolDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005513 TEST_DESCRIPTION(
5514 "Attempt to draw with a command buffer that is invalid "
5515 "due to a query pool dependency being destroyed.");
Tony Barbour1fa09702017-03-16 12:09:08 -06005516 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisdbea7552016-07-08 14:33:31 -06005517
5518 VkQueryPool query_pool;
5519 VkQueryPoolCreateInfo qpci{};
5520 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
5521 qpci.queryType = VK_QUERY_TYPE_TIMESTAMP;
5522 qpci.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005523 VkResult result = vkCreateQueryPool(m_device->device(), &qpci, nullptr, &query_pool);
Tobin Ehlisdbea7552016-07-08 14:33:31 -06005524 ASSERT_VK_SUCCESS(result);
5525
5526 m_commandBuffer->BeginCommandBuffer();
5527 vkCmdResetQueryPool(m_commandBuffer->GetBufferHandle(), query_pool, 0, 1);
5528 m_commandBuffer->EndCommandBuffer();
5529
Mark Lobodzinski33826372017-04-13 11:10:11 -06005530 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound QueryPool ");
Tobin Ehlisdbea7552016-07-08 14:33:31 -06005531 // Destroy query pool dependency prior to submit to cause ERROR
5532 vkDestroyQueryPool(m_device->device(), query_pool, NULL);
5533
5534 VkSubmitInfo submit_info = {};
5535 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5536 submit_info.commandBufferCount = 1;
5537 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5538 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5539
5540 m_errorMonitor->VerifyFound();
5541}
5542
Tobin Ehlis24130d92016-07-08 15:50:53 -06005543TEST_F(VkLayerTest, InvalidCmdBufferPipelineDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005544 TEST_DESCRIPTION(
5545 "Attempt to draw with a command buffer that is invalid "
5546 "due to a pipeline dependency being destroyed.");
Tony Barbour1fa09702017-03-16 12:09:08 -06005547 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis24130d92016-07-08 15:50:53 -06005548 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5549
5550 VkResult err;
5551
5552 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5553 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5554
5555 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005556 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis24130d92016-07-08 15:50:53 -06005557 ASSERT_VK_SUCCESS(err);
5558
5559 VkPipelineViewportStateCreateInfo vp_state_ci = {};
5560 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
5561 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005562 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -06005563 vp_state_ci.pViewports = &vp;
Tobin Ehlis24130d92016-07-08 15:50:53 -06005564 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005565 VkRect2D scissors = {}; // Dummy scissors to point to
Tobin Ehlis24130d92016-07-08 15:50:53 -06005566 vp_state_ci.pScissors = &scissors;
Tobin Ehlis24130d92016-07-08 15:50:53 -06005567
5568 VkPipelineShaderStageCreateInfo shaderStages[2];
5569 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
5570
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005571 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005572 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005573 // but add it to be able to run on more devices
Tobin Ehlis24130d92016-07-08 15:50:53 -06005574 shaderStages[0] = vs.GetStageCreateInfo();
5575 shaderStages[1] = fs.GetStageCreateInfo();
5576
5577 VkPipelineVertexInputStateCreateInfo vi_ci = {};
5578 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
5579
5580 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
5581 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
5582 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
5583
5584 VkPipelineRasterizationStateCreateInfo rs_ci = {};
5585 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbese06ba252016-09-16 17:48:53 +12005586 rs_ci.rasterizerDiscardEnable = true;
5587 rs_ci.lineWidth = 1.0f;
Tobin Ehlis24130d92016-07-08 15:50:53 -06005588
5589 VkPipelineColorBlendAttachmentState att = {};
5590 att.blendEnable = VK_FALSE;
5591 att.colorWriteMask = 0xf;
5592
5593 VkPipelineColorBlendStateCreateInfo cb_ci = {};
5594 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
5595 cb_ci.attachmentCount = 1;
5596 cb_ci.pAttachments = &att;
5597
5598 VkGraphicsPipelineCreateInfo gp_ci = {};
5599 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
5600 gp_ci.stageCount = 2;
5601 gp_ci.pStages = shaderStages;
5602 gp_ci.pVertexInputState = &vi_ci;
5603 gp_ci.pInputAssemblyState = &ia_ci;
5604 gp_ci.pViewportState = &vp_state_ci;
5605 gp_ci.pRasterizationState = &rs_ci;
5606 gp_ci.pColorBlendState = &cb_ci;
Tobin Ehlis24130d92016-07-08 15:50:53 -06005607 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
5608 gp_ci.layout = pipeline_layout;
5609 gp_ci.renderPass = renderPass();
5610
5611 VkPipelineCacheCreateInfo pc_ci = {};
5612 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
5613
5614 VkPipeline pipeline;
5615 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005616 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis24130d92016-07-08 15:50:53 -06005617 ASSERT_VK_SUCCESS(err);
5618
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005619 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06005620 ASSERT_VK_SUCCESS(err);
5621
5622 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005623 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06005624 m_commandBuffer->EndCommandBuffer();
5625 // Now destroy pipeline in order to cause error when submitting
5626 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
5627
Mark Lobodzinski33826372017-04-13 11:10:11 -06005628 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound Pipeline ");
Tobin Ehlis24130d92016-07-08 15:50:53 -06005629
5630 VkSubmitInfo submit_info = {};
5631 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5632 submit_info.commandBufferCount = 1;
5633 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5634 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5635
5636 m_errorMonitor->VerifyFound();
5637 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
5638 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5639}
5640
Tobin Ehlis31289162016-08-17 14:57:58 -06005641TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetBufferDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005642 TEST_DESCRIPTION(
5643 "Attempt to draw with a command buffer that is invalid "
5644 "due to a bound descriptor set with a buffer dependency "
5645 "being destroyed.");
Tony Barbour1fa09702017-03-16 12:09:08 -06005646 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis31289162016-08-17 14:57:58 -06005647 ASSERT_NO_FATAL_FAILURE(InitViewport());
5648 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5649
5650 VkDescriptorPoolSize ds_type_count = {};
5651 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5652 ds_type_count.descriptorCount = 1;
5653
5654 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5655 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5656 ds_pool_ci.pNext = NULL;
5657 ds_pool_ci.maxSets = 1;
5658 ds_pool_ci.poolSizeCount = 1;
5659 ds_pool_ci.pPoolSizes = &ds_type_count;
5660
5661 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005662 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis31289162016-08-17 14:57:58 -06005663 ASSERT_VK_SUCCESS(err);
5664
5665 VkDescriptorSetLayoutBinding dsl_binding = {};
5666 dsl_binding.binding = 0;
5667 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5668 dsl_binding.descriptorCount = 1;
5669 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5670 dsl_binding.pImmutableSamplers = NULL;
5671
5672 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5673 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5674 ds_layout_ci.pNext = NULL;
5675 ds_layout_ci.bindingCount = 1;
5676 ds_layout_ci.pBindings = &dsl_binding;
5677 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005678 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06005679 ASSERT_VK_SUCCESS(err);
5680
5681 VkDescriptorSet descriptorSet;
5682 VkDescriptorSetAllocateInfo alloc_info = {};
5683 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5684 alloc_info.descriptorSetCount = 1;
5685 alloc_info.descriptorPool = ds_pool;
5686 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005687 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis31289162016-08-17 14:57:58 -06005688 ASSERT_VK_SUCCESS(err);
5689
5690 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5691 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5692 pipeline_layout_ci.pNext = NULL;
5693 pipeline_layout_ci.setLayoutCount = 1;
5694 pipeline_layout_ci.pSetLayouts = &ds_layout;
5695
5696 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005697 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06005698 ASSERT_VK_SUCCESS(err);
5699
5700 // Create a buffer to update the descriptor with
5701 uint32_t qfi = 0;
5702 VkBufferCreateInfo buffCI = {};
5703 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
5704 buffCI.size = 1024;
5705 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
5706 buffCI.queueFamilyIndexCount = 1;
5707 buffCI.pQueueFamilyIndices = &qfi;
5708
5709 VkBuffer buffer;
5710 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &buffer);
5711 ASSERT_VK_SUCCESS(err);
5712 // Allocate memory and bind to buffer so we can make it to the appropriate
5713 // error
5714 VkMemoryAllocateInfo mem_alloc = {};
5715 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5716 mem_alloc.pNext = NULL;
5717 mem_alloc.allocationSize = 1024;
5718 mem_alloc.memoryTypeIndex = 0;
5719
5720 VkMemoryRequirements memReqs;
5721 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005722 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis31289162016-08-17 14:57:58 -06005723 if (!pass) {
5724 vkDestroyBuffer(m_device->device(), buffer, NULL);
5725 return;
5726 }
5727
5728 VkDeviceMemory mem;
5729 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
5730 ASSERT_VK_SUCCESS(err);
5731 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
5732 ASSERT_VK_SUCCESS(err);
5733 // Correctly update descriptor to avoid "NOT_UPDATED" error
5734 VkDescriptorBufferInfo buffInfo = {};
5735 buffInfo.buffer = buffer;
5736 buffInfo.offset = 0;
5737 buffInfo.range = 1024;
5738
5739 VkWriteDescriptorSet descriptor_write;
5740 memset(&descriptor_write, 0, sizeof(descriptor_write));
5741 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5742 descriptor_write.dstSet = descriptorSet;
5743 descriptor_write.dstBinding = 0;
5744 descriptor_write.descriptorCount = 1;
5745 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5746 descriptor_write.pBufferInfo = &buffInfo;
5747
5748 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5749
5750 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005751 char const *vsSource =
5752 "#version 450\n"
5753 "\n"
5754 "out gl_PerVertex { \n"
5755 " vec4 gl_Position;\n"
5756 "};\n"
5757 "void main(){\n"
5758 " gl_Position = vec4(1);\n"
5759 "}\n";
5760 char const *fsSource =
5761 "#version 450\n"
5762 "\n"
5763 "layout(location=0) out vec4 x;\n"
5764 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
5765 "void main(){\n"
5766 " x = vec4(bar.y);\n"
5767 "}\n";
Tobin Ehlis31289162016-08-17 14:57:58 -06005768 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5769 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5770 VkPipelineObj pipe(m_device);
5771 pipe.AddShader(&vs);
5772 pipe.AddShader(&fs);
5773 pipe.AddColorAttachment();
5774 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5775
Tony Barbour552f6c02016-12-21 14:34:07 -07005776 m_commandBuffer->BeginCommandBuffer();
5777 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005778 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5779 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5780 &descriptorSet, 0, NULL);
Rene Lindsay0583ac92017-01-16 14:29:10 -07005781
5782 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &m_viewports[0]);
5783 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &m_scissors[0]);
5784
Tobin Ehlis31289162016-08-17 14:57:58 -06005785 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005786 m_commandBuffer->EndRenderPass();
5787 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski33826372017-04-13 11:10:11 -06005788 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound Buffer ");
Tobin Ehlis31289162016-08-17 14:57:58 -06005789 // Destroy buffer should invalidate the cmd buffer, causing error on submit
5790 vkDestroyBuffer(m_device->device(), buffer, NULL);
5791 // Attempt to submit cmd buffer
5792 VkSubmitInfo submit_info = {};
5793 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5794 submit_info.commandBufferCount = 1;
5795 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5796 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5797 m_errorMonitor->VerifyFound();
5798 // Cleanup
5799 vkFreeMemory(m_device->device(), mem, NULL);
5800
5801 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5802 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5803 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5804}
5805
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005806TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetImageSamplerDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005807 TEST_DESCRIPTION(
5808 "Attempt to draw with a command buffer that is invalid "
5809 "due to a bound descriptor sets with a combined image "
5810 "sampler having their image, sampler, and descriptor set "
5811 "each respectively destroyed and then attempting to "
5812 "submit associated cmd buffers. Attempt to destroy a "
5813 "DescriptorSet that is in use.");
Tony Barbour1fa09702017-03-16 12:09:08 -06005814 ASSERT_NO_FATAL_FAILURE(Init(nullptr, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT));
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005815 ASSERT_NO_FATAL_FAILURE(InitViewport());
5816 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5817
5818 VkDescriptorPoolSize ds_type_count = {};
5819 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5820 ds_type_count.descriptorCount = 1;
5821
5822 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5823 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5824 ds_pool_ci.pNext = NULL;
Rene Lindsayed88b732017-01-27 15:55:29 -07005825 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005826 ds_pool_ci.maxSets = 1;
5827 ds_pool_ci.poolSizeCount = 1;
5828 ds_pool_ci.pPoolSizes = &ds_type_count;
5829
5830 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005831 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005832 ASSERT_VK_SUCCESS(err);
5833
5834 VkDescriptorSetLayoutBinding dsl_binding = {};
5835 dsl_binding.binding = 0;
5836 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5837 dsl_binding.descriptorCount = 1;
5838 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5839 dsl_binding.pImmutableSamplers = NULL;
5840
5841 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5842 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5843 ds_layout_ci.pNext = NULL;
5844 ds_layout_ci.bindingCount = 1;
5845 ds_layout_ci.pBindings = &dsl_binding;
5846 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005847 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005848 ASSERT_VK_SUCCESS(err);
5849
5850 VkDescriptorSet descriptorSet;
5851 VkDescriptorSetAllocateInfo alloc_info = {};
5852 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5853 alloc_info.descriptorSetCount = 1;
5854 alloc_info.descriptorPool = ds_pool;
5855 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005856 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005857 ASSERT_VK_SUCCESS(err);
5858
5859 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5860 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5861 pipeline_layout_ci.pNext = NULL;
5862 pipeline_layout_ci.setLayoutCount = 1;
5863 pipeline_layout_ci.pSetLayouts = &ds_layout;
5864
5865 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005866 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005867 ASSERT_VK_SUCCESS(err);
5868
5869 // Create images to update the descriptor with
5870 VkImage image;
5871 VkImage image2;
5872 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5873 const int32_t tex_width = 32;
5874 const int32_t tex_height = 32;
5875 VkImageCreateInfo image_create_info = {};
5876 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5877 image_create_info.pNext = NULL;
5878 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5879 image_create_info.format = tex_format;
5880 image_create_info.extent.width = tex_width;
5881 image_create_info.extent.height = tex_height;
5882 image_create_info.extent.depth = 1;
5883 image_create_info.mipLevels = 1;
5884 image_create_info.arrayLayers = 1;
5885 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5886 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
5887 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5888 image_create_info.flags = 0;
5889 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
5890 ASSERT_VK_SUCCESS(err);
5891 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
5892 ASSERT_VK_SUCCESS(err);
5893
5894 VkMemoryRequirements memory_reqs;
5895 VkDeviceMemory image_memory;
5896 bool pass;
5897 VkMemoryAllocateInfo memory_info = {};
5898 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5899 memory_info.pNext = NULL;
5900 memory_info.allocationSize = 0;
5901 memory_info.memoryTypeIndex = 0;
5902 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5903 // Allocate enough memory for both images
5904 memory_info.allocationSize = memory_reqs.size * 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005905 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005906 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005907 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005908 ASSERT_VK_SUCCESS(err);
5909 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5910 ASSERT_VK_SUCCESS(err);
5911 // Bind second image to memory right after first image
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005912 err = vkBindImageMemory(m_device->device(), image2, image_memory, memory_reqs.size);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005913 ASSERT_VK_SUCCESS(err);
5914
5915 VkImageViewCreateInfo image_view_create_info = {};
5916 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5917 image_view_create_info.image = image;
5918 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5919 image_view_create_info.format = tex_format;
5920 image_view_create_info.subresourceRange.layerCount = 1;
5921 image_view_create_info.subresourceRange.baseMipLevel = 0;
5922 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005923 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005924
5925 VkImageView view;
5926 VkImageView view2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005927 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005928 ASSERT_VK_SUCCESS(err);
5929 image_view_create_info.image = image2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005930 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view2);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005931 ASSERT_VK_SUCCESS(err);
5932 // Create Samplers
5933 VkSamplerCreateInfo sampler_ci = {};
5934 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5935 sampler_ci.pNext = NULL;
5936 sampler_ci.magFilter = VK_FILTER_NEAREST;
5937 sampler_ci.minFilter = VK_FILTER_NEAREST;
5938 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5939 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5940 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5941 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5942 sampler_ci.mipLodBias = 1.0;
5943 sampler_ci.anisotropyEnable = VK_FALSE;
5944 sampler_ci.maxAnisotropy = 1;
5945 sampler_ci.compareEnable = VK_FALSE;
5946 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5947 sampler_ci.minLod = 1.0;
5948 sampler_ci.maxLod = 1.0;
5949 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5950 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5951 VkSampler sampler;
5952 VkSampler sampler2;
5953 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5954 ASSERT_VK_SUCCESS(err);
5955 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler2);
5956 ASSERT_VK_SUCCESS(err);
5957 // Update descriptor with image and sampler
5958 VkDescriptorImageInfo img_info = {};
5959 img_info.sampler = sampler;
5960 img_info.imageView = view;
5961 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5962
5963 VkWriteDescriptorSet descriptor_write;
5964 memset(&descriptor_write, 0, sizeof(descriptor_write));
5965 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5966 descriptor_write.dstSet = descriptorSet;
5967 descriptor_write.dstBinding = 0;
5968 descriptor_write.descriptorCount = 1;
5969 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5970 descriptor_write.pImageInfo = &img_info;
5971
5972 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5973
5974 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005975 char const *vsSource =
5976 "#version 450\n"
5977 "\n"
5978 "out gl_PerVertex { \n"
5979 " vec4 gl_Position;\n"
5980 "};\n"
5981 "void main(){\n"
5982 " gl_Position = vec4(1);\n"
5983 "}\n";
5984 char const *fsSource =
5985 "#version 450\n"
5986 "\n"
5987 "layout(set=0, binding=0) uniform sampler2D s;\n"
5988 "layout(location=0) out vec4 x;\n"
5989 "void main(){\n"
5990 " x = texture(s, vec2(1));\n"
5991 "}\n";
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005992 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5993 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5994 VkPipelineObj pipe(m_device);
5995 pipe.AddShader(&vs);
5996 pipe.AddShader(&fs);
5997 pipe.AddColorAttachment();
5998 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5999
6000 // First error case is destroying sampler prior to cmd buffer submission
Mark Lobodzinski33826372017-04-13 11:10:11 -06006001 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is invalid because bound Sampler");
Tony Barbour552f6c02016-12-21 14:34:07 -07006002 m_commandBuffer->BeginCommandBuffer();
6003 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006004 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
6005 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6006 &descriptorSet, 0, NULL);
Rene Lindsaya31285f2017-01-11 16:35:53 -07006007 VkViewport viewport = {0, 0, 16, 16, 0, 1};
6008 VkRect2D scissor = {{0, 0}, {16, 16}};
6009 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
6010 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06006011 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07006012 m_commandBuffer->EndRenderPass();
6013 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06006014 // Destroy sampler invalidates the cmd buffer, causing error on submit
6015 vkDestroySampler(m_device->device(), sampler, NULL);
6016 // Attempt to submit cmd buffer
6017 VkSubmitInfo submit_info = {};
6018 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6019 submit_info.commandBufferCount = 1;
6020 submit_info.pCommandBuffers = &m_commandBuffer->handle();
6021 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
6022 m_errorMonitor->VerifyFound();
Rene Lindsaya31285f2017-01-11 16:35:53 -07006023
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06006024 // Now re-update descriptor with valid sampler and delete image
6025 img_info.sampler = sampler2;
6026 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Rene Lindsayed88b732017-01-27 15:55:29 -07006027
6028 VkCommandBufferBeginInfo info = {};
6029 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
6030 info.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
6031
Mark Lobodzinski33826372017-04-13 11:10:11 -06006032 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound Image ");
Rene Lindsayed88b732017-01-27 15:55:29 -07006033 m_commandBuffer->BeginCommandBuffer(&info);
Tony Barbour552f6c02016-12-21 14:34:07 -07006034 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006035 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
6036 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6037 &descriptorSet, 0, NULL);
Rene Lindsaya31285f2017-01-11 16:35:53 -07006038 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
6039 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06006040 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07006041 m_commandBuffer->EndRenderPass();
6042 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06006043 // Destroy image invalidates the cmd buffer, causing error on submit
6044 vkDestroyImage(m_device->device(), image, NULL);
6045 // Attempt to submit cmd buffer
6046 submit_info = {};
6047 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6048 submit_info.commandBufferCount = 1;
6049 submit_info.pCommandBuffers = &m_commandBuffer->handle();
6050 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
6051 m_errorMonitor->VerifyFound();
6052 // Now update descriptor to be valid, but then free descriptor
6053 img_info.imageView = view2;
6054 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Rene Lindsayed88b732017-01-27 15:55:29 -07006055 m_commandBuffer->BeginCommandBuffer(&info);
Tony Barbour552f6c02016-12-21 14:34:07 -07006056 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006057 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
6058 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6059 &descriptorSet, 0, NULL);
Rene Lindsaya31285f2017-01-11 16:35:53 -07006060 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
6061 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06006062 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07006063 m_commandBuffer->EndRenderPass();
6064 m_commandBuffer->EndCommandBuffer();
Tony Barbourc373c012017-01-26 10:53:28 -07006065 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Dave Houltonfbf52152017-01-06 12:55:29 -07006066
6067 // Immediately try to destroy the descriptor set in the active command buffer - failure expected
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006068 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call vkFreeDescriptorSets() on descriptor set 0x");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06006069 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Mark Mueller917f6bc2016-08-30 10:57:19 -06006070 m_errorMonitor->VerifyFound();
Dave Houltonfbf52152017-01-06 12:55:29 -07006071
6072 // Try again once the queue is idle - should succeed w/o error
Dave Houltond5507dd2017-01-24 15:29:02 -07006073 // TODO - though the particular error above doesn't re-occur, there are other 'unexpecteds' still to clean up
Dave Houltonfbf52152017-01-06 12:55:29 -07006074 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07006075 m_errorMonitor->SetUnexpectedError(
6076 "pDescriptorSets must be a pointer to an array of descriptorSetCount VkDescriptorSet handles, each element of which must "
6077 "either be a valid handle or VK_NULL_HANDLE");
Mark Lobodzinski74597792017-04-11 15:43:49 -06006078 m_errorMonitor->SetUnexpectedError("Unable to remove DescriptorSet obj");
Dave Houltonfbf52152017-01-06 12:55:29 -07006079 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
6080
6081 // Attempt to submit cmd buffer containing the freed descriptor set
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06006082 submit_info = {};
6083 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6084 submit_info.commandBufferCount = 1;
6085 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Lobodzinski33826372017-04-13 11:10:11 -06006086 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound DescriptorSet ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06006087 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
6088 m_errorMonitor->VerifyFound();
Dave Houltonfbf52152017-01-06 12:55:29 -07006089
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06006090 // Cleanup
6091 vkFreeMemory(m_device->device(), image_memory, NULL);
6092 vkDestroySampler(m_device->device(), sampler2, NULL);
6093 vkDestroyImage(m_device->device(), image2, NULL);
6094 vkDestroyImageView(m_device->device(), view, NULL);
6095 vkDestroyImageView(m_device->device(), view2, NULL);
6096 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6097 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6098 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6099}
6100
Tobin Ehlisaabbcd02017-04-13 14:15:21 -06006101TEST_F(VkLayerTest, ImageDescriptorLayoutMismatch) {
6102 TEST_DESCRIPTION("Update an image sampler with a layout that doesn't match the actual image layout at the image is used.");
6103 ASSERT_NO_FATAL_FAILURE(Init(nullptr, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT));
6104 ASSERT_NO_FATAL_FAILURE(InitViewport());
6105 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6106
6107 VkDescriptorPoolSize ds_type_count = {};
6108 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6109 ds_type_count.descriptorCount = 1;
6110
6111 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6112 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6113 ds_pool_ci.pNext = NULL;
6114 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
6115 ds_pool_ci.maxSets = 1;
6116 ds_pool_ci.poolSizeCount = 1;
6117 ds_pool_ci.pPoolSizes = &ds_type_count;
6118
6119 VkDescriptorPool ds_pool;
6120 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
6121 ASSERT_VK_SUCCESS(err);
6122
6123 VkDescriptorSetLayoutBinding dsl_binding = {};
6124 dsl_binding.binding = 0;
6125 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6126 dsl_binding.descriptorCount = 1;
6127 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6128 dsl_binding.pImmutableSamplers = NULL;
6129
6130 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6131 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6132 ds_layout_ci.pNext = NULL;
6133 ds_layout_ci.bindingCount = 1;
6134 ds_layout_ci.pBindings = &dsl_binding;
6135 VkDescriptorSetLayout ds_layout;
6136 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
6137 ASSERT_VK_SUCCESS(err);
6138
6139 VkDescriptorSet descriptorSet;
6140 VkDescriptorSetAllocateInfo alloc_info = {};
6141 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6142 alloc_info.descriptorSetCount = 1;
6143 alloc_info.descriptorPool = ds_pool;
6144 alloc_info.pSetLayouts = &ds_layout;
6145 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
6146 ASSERT_VK_SUCCESS(err);
6147
6148 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6149 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6150 pipeline_layout_ci.pNext = NULL;
6151 pipeline_layout_ci.setLayoutCount = 1;
6152 pipeline_layout_ci.pSetLayouts = &ds_layout;
6153
6154 VkPipelineLayout pipeline_layout;
6155 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
6156 ASSERT_VK_SUCCESS(err);
6157
6158 // Create images to update the descriptor with
6159 const VkFormat format = VK_FORMAT_B8G8R8A8_UNORM;
6160 VkImageObj image(m_device);
6161 image.Init(32, 32, 1, format, VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VK_IMAGE_TILING_OPTIMAL,
6162 0);
6163 ASSERT_TRUE(image.initialized());
6164
6165 VkImageViewCreateInfo image_view_create_info = {};
6166 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
6167 image_view_create_info.image = image.handle();
6168 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
6169 image_view_create_info.format = format;
6170 image_view_create_info.subresourceRange.layerCount = 1;
6171 image_view_create_info.subresourceRange.baseMipLevel = 0;
6172 image_view_create_info.subresourceRange.levelCount = 1;
6173 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
6174
6175 VkImageView view;
6176 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
6177 ASSERT_VK_SUCCESS(err);
6178 // Create Sampler
6179 VkSamplerCreateInfo sampler_ci = {};
6180 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
6181 sampler_ci.pNext = NULL;
6182 sampler_ci.magFilter = VK_FILTER_NEAREST;
6183 sampler_ci.minFilter = VK_FILTER_NEAREST;
6184 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
6185 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6186 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6187 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6188 sampler_ci.mipLodBias = 1.0;
6189 sampler_ci.anisotropyEnable = VK_FALSE;
6190 sampler_ci.maxAnisotropy = 1;
6191 sampler_ci.compareEnable = VK_FALSE;
6192 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
6193 sampler_ci.minLod = 1.0;
6194 sampler_ci.maxLod = 1.0;
6195 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
6196 sampler_ci.unnormalizedCoordinates = VK_FALSE;
6197 VkSampler sampler;
6198 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
6199 ASSERT_VK_SUCCESS(err);
6200 // Update descriptor with image and sampler
6201 VkDescriptorImageInfo img_info = {};
6202 img_info.sampler = sampler;
6203 img_info.imageView = view;
6204 // This should cause a mis-match. Actual layout at use time is SHADER_RO
6205 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
6206
6207 VkWriteDescriptorSet descriptor_write;
6208 memset(&descriptor_write, 0, sizeof(descriptor_write));
6209 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6210 descriptor_write.dstSet = descriptorSet;
6211 descriptor_write.dstBinding = 0;
6212 descriptor_write.descriptorCount = 1;
6213 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6214 descriptor_write.pImageInfo = &img_info;
6215
6216 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6217
6218 // Create PSO to be used for draw-time errors below
6219 char const *vsSource =
6220 "#version 450\n"
6221 "\n"
6222 "out gl_PerVertex { \n"
6223 " vec4 gl_Position;\n"
6224 "};\n"
6225 "void main(){\n"
6226 " gl_Position = vec4(1);\n"
6227 "}\n";
6228 char const *fsSource =
6229 "#version 450\n"
6230 "\n"
6231 "layout(set=0, binding=0) uniform sampler2D s;\n"
6232 "layout(location=0) out vec4 x;\n"
6233 "void main(){\n"
6234 " x = texture(s, vec2(1));\n"
6235 "}\n";
6236 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6237 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
6238 VkPipelineObj pipe(m_device);
6239 pipe.AddShader(&vs);
6240 pipe.AddShader(&fs);
6241 pipe.AddColorAttachment();
6242 pipe.CreateVKPipeline(pipeline_layout, renderPass());
6243
6244 VkCommandBufferObj cmd_buf(m_device, m_commandPool);
6245 cmd_buf.BeginCommandBuffer();
Tobin Ehlisaabbcd02017-04-13 14:15:21 -06006246 // record layout different than actual descriptor layout of SHADER_RO
6247 image.SetLayout(&cmd_buf, VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL);
Mark Lobodzinski95512b72017-05-10 12:21:30 -06006248 cmd_buf.BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlisaabbcd02017-04-13 14:15:21 -06006249 vkCmdBindPipeline(cmd_buf.handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
6250 vkCmdBindDescriptorSets(cmd_buf.handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &descriptorSet, 0, NULL);
6251 VkViewport viewport = {0, 0, 16, 16, 0, 1};
6252 VkRect2D scissor = {{0, 0}, {16, 16}};
6253 vkCmdSetViewport(cmd_buf.handle(), 0, 1, &viewport);
6254 vkCmdSetScissor(cmd_buf.handle(), 0, 1, &scissor);
6255 // At draw time the update layout will mis-match the actual layout
6256 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6257 " with specific layout VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL that doesn't match the "
6258 "actual current layout VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL.");
6259 m_errorMonitor->SetDesiredFailureMsg(
6260 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6261 " Image layout specified at vkUpdateDescriptorSets() time doesn't match actual image layout at time descriptor is used.");
6262 cmd_buf.Draw(1, 0, 0, 0);
6263 m_errorMonitor->VerifyFound();
6264 cmd_buf.EndRenderPass();
6265 cmd_buf.EndCommandBuffer();
6266 // Submit cmd buffer
6267 VkSubmitInfo submit_info = {};
6268 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6269 submit_info.commandBufferCount = 1;
6270 submit_info.pCommandBuffers = &cmd_buf.handle();
6271 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
6272 vkQueueWaitIdle(m_device->m_queue);
6273 // Cleanup
6274 vkDestroySampler(m_device->device(), sampler, NULL);
6275 vkDestroyImageView(m_device->device(), view, NULL);
6276 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6277 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6278 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6279}
6280
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006281TEST_F(VkLayerTest, DescriptorPoolInUseDestroyedSignaled) {
6282 TEST_DESCRIPTION("Delete a DescriptorPool with a DescriptorSet that is in use.");
Tony Barbour1fa09702017-03-16 12:09:08 -06006283 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006284 ASSERT_NO_FATAL_FAILURE(InitViewport());
6285 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6286
6287 VkDescriptorPoolSize ds_type_count = {};
6288 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6289 ds_type_count.descriptorCount = 1;
6290
6291 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6292 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6293 ds_pool_ci.pNext = NULL;
6294 ds_pool_ci.maxSets = 1;
6295 ds_pool_ci.poolSizeCount = 1;
6296 ds_pool_ci.pPoolSizes = &ds_type_count;
6297
6298 VkDescriptorPool ds_pool;
6299 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
6300 ASSERT_VK_SUCCESS(err);
6301
6302 VkDescriptorSetLayoutBinding dsl_binding = {};
6303 dsl_binding.binding = 0;
6304 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6305 dsl_binding.descriptorCount = 1;
6306 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6307 dsl_binding.pImmutableSamplers = NULL;
6308
6309 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6310 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6311 ds_layout_ci.pNext = NULL;
6312 ds_layout_ci.bindingCount = 1;
6313 ds_layout_ci.pBindings = &dsl_binding;
6314 VkDescriptorSetLayout ds_layout;
6315 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
6316 ASSERT_VK_SUCCESS(err);
6317
6318 VkDescriptorSet descriptor_set;
6319 VkDescriptorSetAllocateInfo alloc_info = {};
6320 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6321 alloc_info.descriptorSetCount = 1;
6322 alloc_info.descriptorPool = ds_pool;
6323 alloc_info.pSetLayouts = &ds_layout;
6324 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
6325 ASSERT_VK_SUCCESS(err);
6326
6327 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6328 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6329 pipeline_layout_ci.pNext = NULL;
6330 pipeline_layout_ci.setLayoutCount = 1;
6331 pipeline_layout_ci.pSetLayouts = &ds_layout;
6332
6333 VkPipelineLayout pipeline_layout;
6334 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
6335 ASSERT_VK_SUCCESS(err);
6336
6337 // Create image to update the descriptor with
6338 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06006339 image.Init(32, 32, 1, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006340 ASSERT_TRUE(image.initialized());
6341
6342 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
6343 // Create Sampler
6344 VkSamplerCreateInfo sampler_ci = {};
6345 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
6346 sampler_ci.pNext = NULL;
6347 sampler_ci.magFilter = VK_FILTER_NEAREST;
6348 sampler_ci.minFilter = VK_FILTER_NEAREST;
6349 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
6350 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6351 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6352 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6353 sampler_ci.mipLodBias = 1.0;
6354 sampler_ci.anisotropyEnable = VK_FALSE;
6355 sampler_ci.maxAnisotropy = 1;
6356 sampler_ci.compareEnable = VK_FALSE;
6357 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
6358 sampler_ci.minLod = 1.0;
6359 sampler_ci.maxLod = 1.0;
6360 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
6361 sampler_ci.unnormalizedCoordinates = VK_FALSE;
6362 VkSampler sampler;
6363 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
6364 ASSERT_VK_SUCCESS(err);
6365 // Update descriptor with image and sampler
6366 VkDescriptorImageInfo img_info = {};
6367 img_info.sampler = sampler;
6368 img_info.imageView = view;
6369 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
6370
6371 VkWriteDescriptorSet descriptor_write;
6372 memset(&descriptor_write, 0, sizeof(descriptor_write));
6373 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6374 descriptor_write.dstSet = descriptor_set;
6375 descriptor_write.dstBinding = 0;
6376 descriptor_write.descriptorCount = 1;
6377 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6378 descriptor_write.pImageInfo = &img_info;
6379
6380 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6381
6382 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006383 char const *vsSource =
6384 "#version 450\n"
6385 "\n"
6386 "out gl_PerVertex { \n"
6387 " vec4 gl_Position;\n"
6388 "};\n"
6389 "void main(){\n"
6390 " gl_Position = vec4(1);\n"
6391 "}\n";
6392 char const *fsSource =
6393 "#version 450\n"
6394 "\n"
6395 "layout(set=0, binding=0) uniform sampler2D s;\n"
6396 "layout(location=0) out vec4 x;\n"
6397 "void main(){\n"
6398 " x = texture(s, vec2(1));\n"
6399 "}\n";
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006400 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6401 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
6402 VkPipelineObj pipe(m_device);
6403 pipe.AddShader(&vs);
6404 pipe.AddShader(&fs);
6405 pipe.AddColorAttachment();
6406 pipe.CreateVKPipeline(pipeline_layout, renderPass());
6407
Tony Barbour552f6c02016-12-21 14:34:07 -07006408 m_commandBuffer->BeginCommandBuffer();
6409 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006410 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
6411 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6412 &descriptor_set, 0, NULL);
Rene Lindsaye353a072017-01-16 11:07:28 -07006413
6414 VkViewport viewport = {0, 0, 16, 16, 0, 1};
6415 VkRect2D scissor = {{0, 0}, {16, 16}};
6416 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
6417 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
6418
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006419 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07006420 m_commandBuffer->EndRenderPass();
6421 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006422 // Submit cmd buffer to put pool in-flight
6423 VkSubmitInfo submit_info = {};
6424 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6425 submit_info.commandBufferCount = 1;
6426 submit_info.pCommandBuffers = &m_commandBuffer->handle();
6427 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
6428 // Destroy pool while in-flight, causing error
Mark Lobodzinski33826372017-04-13 11:10:11 -06006429 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete DescriptorPool ");
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006430 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6431 m_errorMonitor->VerifyFound();
6432 vkQueueWaitIdle(m_device->m_queue);
6433 // Cleanup
6434 vkDestroySampler(m_device->device(), sampler, NULL);
6435 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6436 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07006437 m_errorMonitor->SetUnexpectedError(
6438 "If descriptorPool is not VK_NULL_HANDLE, descriptorPool must be a valid VkDescriptorPool handle");
Mark Lobodzinski74597792017-04-11 15:43:49 -06006439 m_errorMonitor->SetUnexpectedError("Unable to remove DescriptorPool obj");
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006440 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Rene Lindsaye353a072017-01-16 11:07:28 -07006441 // TODO : It seems Validation layers think ds_pool was already destroyed, even though it wasn't?
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006442}
6443
Tobin Ehlis50a095d2016-09-21 17:32:49 -06006444TEST_F(VkLayerTest, DescriptorImageUpdateNoMemoryBound) {
6445 TEST_DESCRIPTION("Attempt an image descriptor set update where image's bound memory has been freed.");
Tony Barbour1fa09702017-03-16 12:09:08 -06006446 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis50a095d2016-09-21 17:32:49 -06006447 ASSERT_NO_FATAL_FAILURE(InitViewport());
6448 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6449
6450 VkDescriptorPoolSize ds_type_count = {};
6451 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6452 ds_type_count.descriptorCount = 1;
6453
6454 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6455 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6456 ds_pool_ci.pNext = NULL;
6457 ds_pool_ci.maxSets = 1;
6458 ds_pool_ci.poolSizeCount = 1;
6459 ds_pool_ci.pPoolSizes = &ds_type_count;
6460
6461 VkDescriptorPool ds_pool;
6462 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
6463 ASSERT_VK_SUCCESS(err);
6464
6465 VkDescriptorSetLayoutBinding dsl_binding = {};
6466 dsl_binding.binding = 0;
6467 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6468 dsl_binding.descriptorCount = 1;
6469 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6470 dsl_binding.pImmutableSamplers = NULL;
6471
6472 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6473 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6474 ds_layout_ci.pNext = NULL;
6475 ds_layout_ci.bindingCount = 1;
6476 ds_layout_ci.pBindings = &dsl_binding;
6477 VkDescriptorSetLayout ds_layout;
6478 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
6479 ASSERT_VK_SUCCESS(err);
6480
6481 VkDescriptorSet descriptorSet;
6482 VkDescriptorSetAllocateInfo alloc_info = {};
6483 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6484 alloc_info.descriptorSetCount = 1;
6485 alloc_info.descriptorPool = ds_pool;
6486 alloc_info.pSetLayouts = &ds_layout;
6487 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
6488 ASSERT_VK_SUCCESS(err);
6489
6490 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6491 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6492 pipeline_layout_ci.pNext = NULL;
6493 pipeline_layout_ci.setLayoutCount = 1;
6494 pipeline_layout_ci.pSetLayouts = &ds_layout;
6495
6496 VkPipelineLayout pipeline_layout;
6497 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
6498 ASSERT_VK_SUCCESS(err);
6499
6500 // Create images to update the descriptor with
6501 VkImage image;
6502 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
6503 const int32_t tex_width = 32;
6504 const int32_t tex_height = 32;
6505 VkImageCreateInfo image_create_info = {};
6506 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6507 image_create_info.pNext = NULL;
6508 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6509 image_create_info.format = tex_format;
6510 image_create_info.extent.width = tex_width;
6511 image_create_info.extent.height = tex_height;
6512 image_create_info.extent.depth = 1;
6513 image_create_info.mipLevels = 1;
6514 image_create_info.arrayLayers = 1;
6515 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
6516 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
6517 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
6518 image_create_info.flags = 0;
6519 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
6520 ASSERT_VK_SUCCESS(err);
6521 // Initially bind memory to avoid error at bind view time. We'll break binding before update.
6522 VkMemoryRequirements memory_reqs;
6523 VkDeviceMemory image_memory;
6524 bool pass;
6525 VkMemoryAllocateInfo memory_info = {};
6526 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6527 memory_info.pNext = NULL;
6528 memory_info.allocationSize = 0;
6529 memory_info.memoryTypeIndex = 0;
6530 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
6531 // Allocate enough memory for image
6532 memory_info.allocationSize = memory_reqs.size;
6533 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
6534 ASSERT_TRUE(pass);
6535 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
6536 ASSERT_VK_SUCCESS(err);
6537 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
6538 ASSERT_VK_SUCCESS(err);
6539
6540 VkImageViewCreateInfo image_view_create_info = {};
6541 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
6542 image_view_create_info.image = image;
6543 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
6544 image_view_create_info.format = tex_format;
6545 image_view_create_info.subresourceRange.layerCount = 1;
6546 image_view_create_info.subresourceRange.baseMipLevel = 0;
6547 image_view_create_info.subresourceRange.levelCount = 1;
6548 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
6549
6550 VkImageView view;
6551 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
6552 ASSERT_VK_SUCCESS(err);
6553 // Create Samplers
6554 VkSamplerCreateInfo sampler_ci = {};
6555 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
6556 sampler_ci.pNext = NULL;
6557 sampler_ci.magFilter = VK_FILTER_NEAREST;
6558 sampler_ci.minFilter = VK_FILTER_NEAREST;
6559 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
6560 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6561 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6562 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6563 sampler_ci.mipLodBias = 1.0;
6564 sampler_ci.anisotropyEnable = VK_FALSE;
6565 sampler_ci.maxAnisotropy = 1;
6566 sampler_ci.compareEnable = VK_FALSE;
6567 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
6568 sampler_ci.minLod = 1.0;
6569 sampler_ci.maxLod = 1.0;
6570 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
6571 sampler_ci.unnormalizedCoordinates = VK_FALSE;
6572 VkSampler sampler;
6573 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
6574 ASSERT_VK_SUCCESS(err);
6575 // Update descriptor with image and sampler
6576 VkDescriptorImageInfo img_info = {};
6577 img_info.sampler = sampler;
6578 img_info.imageView = view;
6579 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
6580
6581 VkWriteDescriptorSet descriptor_write;
6582 memset(&descriptor_write, 0, sizeof(descriptor_write));
6583 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6584 descriptor_write.dstSet = descriptorSet;
6585 descriptor_write.dstBinding = 0;
6586 descriptor_write.descriptorCount = 1;
6587 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6588 descriptor_write.pImageInfo = &img_info;
6589 // Break memory binding and attempt update
6590 vkFreeMemory(m_device->device(), image_memory, nullptr);
6591 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006592 " previously bound memory was freed. Memory must not be freed prior to this operation.");
Tobin Ehlis50a095d2016-09-21 17:32:49 -06006593 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6594 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
6595 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6596 m_errorMonitor->VerifyFound();
6597 // Cleanup
6598 vkDestroyImage(m_device->device(), image, NULL);
6599 vkDestroySampler(m_device->device(), sampler, NULL);
6600 vkDestroyImageView(m_device->device(), view, NULL);
6601 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6602 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6603 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6604}
6605
Karl Schultz6addd812016-02-02 17:17:23 -07006606TEST_F(VkLayerTest, InvalidPipeline) {
Karl Schultzbdb75952016-04-19 11:36:49 -06006607 // Attempt to bind an invalid Pipeline to a valid Command Buffer
6608 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06006609 // Create a valid cmd buffer
6610 // call vkCmdBindPipeline w/ false Pipeline
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06006611 uint64_t fake_pipeline_handle = 0xbaad6001;
6612 VkPipeline bad_pipeline = reinterpret_cast<VkPipeline &>(fake_pipeline_handle);
Tony Barbour1fa09702017-03-16 12:09:08 -06006613 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes4dbf70f2016-09-16 17:58:00 +12006614 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6615
Karl Schultzf78bcdd2016-11-30 12:36:01 -07006616 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00601);
Tony Barbour552f6c02016-12-21 14:34:07 -07006617 m_commandBuffer->BeginCommandBuffer();
6618 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006619 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, bad_pipeline);
Karl Schultzbdb75952016-04-19 11:36:49 -06006620 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12006621
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06006622 // Now issue a draw call with no pipeline bound
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006623 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "At Draw/Dispatch time no valid VkPipeline is bound!");
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06006624 Draw(1, 0, 0, 0);
6625 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12006626
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06006627 // Finally same check once more but with Dispatch/Compute
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006628 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "At Draw/Dispatch time no valid VkPipeline is bound!");
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006629 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); // must be outside renderpass
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06006630 vkCmdDispatch(m_commandBuffer->GetBufferHandle(), 0, 0, 0);
6631 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06006632}
6633
Karl Schultz6addd812016-02-02 17:17:23 -07006634TEST_F(VkLayerTest, DescriptorSetNotUpdated) {
Tobin Ehlis5a5f5ef2016-08-17 13:56:55 -06006635 TEST_DESCRIPTION("Bind a descriptor set that hasn't been updated.");
Karl Schultz6addd812016-02-02 17:17:23 -07006636 VkResult err;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006637
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006638 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " bound but it was never updated. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006639
Tony Barbour1fa09702017-03-16 12:09:08 -06006640 ASSERT_NO_FATAL_FAILURE(Init());
Mike Stroyan713b2d72015-08-04 10:49:29 -06006641 ASSERT_NO_FATAL_FAILURE(InitViewport());
6642 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006643 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006644 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6645 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06006646
6647 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006648 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6649 ds_pool_ci.pNext = NULL;
6650 ds_pool_ci.maxSets = 1;
6651 ds_pool_ci.poolSizeCount = 1;
6652 ds_pool_ci.pPoolSizes = &ds_type_count;
Mike Stroyan713b2d72015-08-04 10:49:29 -06006653
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006654 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006655 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006656 ASSERT_VK_SUCCESS(err);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006657
Tony Barboureb254902015-07-15 12:50:33 -06006658 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006659 dsl_binding.binding = 0;
6660 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6661 dsl_binding.descriptorCount = 1;
6662 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6663 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006664
Tony Barboureb254902015-07-15 12:50:33 -06006665 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006666 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6667 ds_layout_ci.pNext = NULL;
6668 ds_layout_ci.bindingCount = 1;
6669 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006670 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006671 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006672 ASSERT_VK_SUCCESS(err);
6673
6674 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006675 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006676 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006677 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006678 alloc_info.descriptorPool = ds_pool;
6679 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006680 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006681 ASSERT_VK_SUCCESS(err);
6682
Tony Barboureb254902015-07-15 12:50:33 -06006683 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006684 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6685 pipeline_layout_ci.pNext = NULL;
6686 pipeline_layout_ci.setLayoutCount = 1;
6687 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006688
6689 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006690 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006691 ASSERT_VK_SUCCESS(err);
6692
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006693 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06006694 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07006695 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006696 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006697
Tony Barbourc95e4ac2015-08-04 17:05:26 -06006698 VkPipelineObj pipe(m_device);
6699 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06006700 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06006701 pipe.AddColorAttachment();
Tony Barbourc95e4ac2015-08-04 17:05:26 -06006702 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06006703
Tony Barbour552f6c02016-12-21 14:34:07 -07006704 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006705 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
6706 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6707 &descriptorSet, 0, NULL);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006708
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006709 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06006710
Chia-I Wuf7458c52015-10-26 21:10:41 +08006711 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6712 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6713 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006714}
6715
Karl Schultz6addd812016-02-02 17:17:23 -07006716TEST_F(VkLayerTest, InvalidBufferViewObject) {
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006717 // Create a single TEXEL_BUFFER descriptor and send it an invalid bufferView
Karl Schultz6addd812016-02-02 17:17:23 -07006718 VkResult err;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006719
Karl Schultzf78bcdd2016-11-30 12:36:01 -07006720 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00940);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006721
Tony Barbour1fa09702017-03-16 12:09:08 -06006722 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006723 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006724 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
6725 ds_type_count.descriptorCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006726
6727 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006728 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6729 ds_pool_ci.pNext = NULL;
6730 ds_pool_ci.maxSets = 1;
6731 ds_pool_ci.poolSizeCount = 1;
6732 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006733
6734 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006735 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006736 ASSERT_VK_SUCCESS(err);
6737
6738 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006739 dsl_binding.binding = 0;
6740 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
6741 dsl_binding.descriptorCount = 1;
6742 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6743 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006744
6745 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006746 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6747 ds_layout_ci.pNext = NULL;
6748 ds_layout_ci.bindingCount = 1;
6749 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006750 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006751 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006752 ASSERT_VK_SUCCESS(err);
6753
6754 VkDescriptorSet descriptorSet;
6755 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006756 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006757 alloc_info.descriptorSetCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006758 alloc_info.descriptorPool = ds_pool;
6759 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006760 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006761 ASSERT_VK_SUCCESS(err);
6762
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006763 VkBufferView view = (VkBufferView)((size_t)0xbaadbeef); // invalid bufferView object
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006764 VkWriteDescriptorSet descriptor_write;
6765 memset(&descriptor_write, 0, sizeof(descriptor_write));
6766 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6767 descriptor_write.dstSet = descriptorSet;
6768 descriptor_write.dstBinding = 0;
6769 descriptor_write.descriptorCount = 1;
6770 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
6771 descriptor_write.pTexelBufferView = &view;
6772
6773 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6774
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006775 m_errorMonitor->VerifyFound();
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006776
6777 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6778 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6779}
6780
Mark Youngd339ba32016-05-30 13:28:35 -06006781TEST_F(VkLayerTest, CreateBufferViewNoMemoryBoundToBuffer) {
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006782 TEST_DESCRIPTION("Attempt to create a buffer view with a buffer that has no memory bound to it.");
Mark Youngd339ba32016-05-30 13:28:35 -06006783
6784 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06006785 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006786 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -06006787
Tony Barbour1fa09702017-03-16 12:09:08 -06006788 ASSERT_NO_FATAL_FAILURE(Init());
Mark Youngd339ba32016-05-30 13:28:35 -06006789
6790 // Create a buffer with no bound memory and then attempt to create
6791 // a buffer view.
6792 VkBufferCreateInfo buff_ci = {};
6793 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes4538d242016-09-13 18:13:58 +12006794 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -06006795 buff_ci.size = 256;
6796 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
6797 VkBuffer buffer;
6798 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
6799 ASSERT_VK_SUCCESS(err);
6800
6801 VkBufferViewCreateInfo buff_view_ci = {};
6802 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
6803 buff_view_ci.buffer = buffer;
6804 buff_view_ci.format = VK_FORMAT_R8_UNORM;
6805 buff_view_ci.range = VK_WHOLE_SIZE;
6806 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006807 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Mark Youngd339ba32016-05-30 13:28:35 -06006808
6809 m_errorMonitor->VerifyFound();
6810 vkDestroyBuffer(m_device->device(), buffer, NULL);
6811 // If last error is success, it still created the view, so delete it.
6812 if (err == VK_SUCCESS) {
6813 vkDestroyBufferView(m_device->device(), buff_view, NULL);
6814 }
6815}
6816
Karl Schultz6addd812016-02-02 17:17:23 -07006817TEST_F(VkLayerTest, InvalidDynamicOffsetCases) {
6818 // Create a descriptorSet w/ dynamic descriptor and then hit 3 offset error
6819 // cases:
Tobin Ehlisf6585052015-12-17 11:48:42 -07006820 // 1. No dynamicOffset supplied
6821 // 2. Too many dynamicOffsets supplied
6822 // 3. Dynamic offset oversteps buffer being updated
Karl Schultz6addd812016-02-02 17:17:23 -07006823 VkResult err;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006824 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6825 " requires 1 dynamicOffsets, but only "
6826 "0 dynamicOffsets are left in "
6827 "pDynamicOffsets ");
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006828
Tony Barbour1fa09702017-03-16 12:09:08 -06006829 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006830 ASSERT_NO_FATAL_FAILURE(InitViewport());
6831 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6832
6833 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006834 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6835 ds_type_count.descriptorCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006836
6837 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006838 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6839 ds_pool_ci.pNext = NULL;
6840 ds_pool_ci.maxSets = 1;
6841 ds_pool_ci.poolSizeCount = 1;
6842 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006843
6844 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006845 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006846 ASSERT_VK_SUCCESS(err);
6847
6848 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006849 dsl_binding.binding = 0;
6850 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6851 dsl_binding.descriptorCount = 1;
6852 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6853 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006854
6855 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006856 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6857 ds_layout_ci.pNext = NULL;
6858 ds_layout_ci.bindingCount = 1;
6859 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006860 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006861 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006862 ASSERT_VK_SUCCESS(err);
6863
6864 VkDescriptorSet descriptorSet;
6865 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006866 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006867 alloc_info.descriptorSetCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006868 alloc_info.descriptorPool = ds_pool;
6869 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006870 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006871 ASSERT_VK_SUCCESS(err);
6872
6873 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006874 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6875 pipeline_layout_ci.pNext = NULL;
6876 pipeline_layout_ci.setLayoutCount = 1;
6877 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006878
6879 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006880 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006881 ASSERT_VK_SUCCESS(err);
6882
6883 // Create a buffer to update the descriptor with
6884 uint32_t qfi = 0;
6885 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006886 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6887 buffCI.size = 1024;
6888 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6889 buffCI.queueFamilyIndexCount = 1;
6890 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006891
6892 VkBuffer dyub;
6893 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6894 ASSERT_VK_SUCCESS(err);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006895 // Allocate memory and bind to buffer so we can make it to the appropriate
6896 // error
6897 VkMemoryAllocateInfo mem_alloc = {};
6898 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6899 mem_alloc.pNext = NULL;
6900 mem_alloc.allocationSize = 1024;
Chris Forbesb6116cc2016-05-08 11:39:59 +12006901 mem_alloc.memoryTypeIndex = 0;
6902
6903 VkMemoryRequirements memReqs;
6904 vkGetBufferMemoryRequirements(m_device->device(), dyub, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006905 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Chris Forbesb6116cc2016-05-08 11:39:59 +12006906 if (!pass) {
6907 vkDestroyBuffer(m_device->device(), dyub, NULL);
6908 return;
6909 }
6910
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006911 VkDeviceMemory mem;
6912 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
6913 ASSERT_VK_SUCCESS(err);
6914 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
6915 ASSERT_VK_SUCCESS(err);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006916 // Correctly update descriptor to avoid "NOT_UPDATED" error
6917 VkDescriptorBufferInfo buffInfo = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006918 buffInfo.buffer = dyub;
6919 buffInfo.offset = 0;
6920 buffInfo.range = 1024;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006921
6922 VkWriteDescriptorSet descriptor_write;
6923 memset(&descriptor_write, 0, sizeof(descriptor_write));
6924 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6925 descriptor_write.dstSet = descriptorSet;
6926 descriptor_write.dstBinding = 0;
6927 descriptor_write.descriptorCount = 1;
6928 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6929 descriptor_write.pBufferInfo = &buffInfo;
6930
6931 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6932
Tony Barbour552f6c02016-12-21 14:34:07 -07006933 m_commandBuffer->BeginCommandBuffer();
6934 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006935 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6936 &descriptorSet, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006937 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07006938 uint32_t pDynOff[2] = {512, 756};
6939 // Now cause error b/c too many dynOffsets in array for # of dyn descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006940 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6941 "Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but ");
6942 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6943 &descriptorSet, 2, pDynOff);
Chris Forbes7b342802016-04-07 13:20:10 +12006944 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07006945 // Finally cause error due to dynamicOffset being too big
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006946 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6947 " dynamic offset 512 combined with "
6948 "offset 0 and range 1024 that "
6949 "oversteps the buffer size of 1024");
Tobin Ehlisf6585052015-12-17 11:48:42 -07006950 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006951 char const *vsSource =
6952 "#version 450\n"
6953 "\n"
6954 "out gl_PerVertex { \n"
6955 " vec4 gl_Position;\n"
6956 "};\n"
6957 "void main(){\n"
6958 " gl_Position = vec4(1);\n"
6959 "}\n";
6960 char const *fsSource =
6961 "#version 450\n"
6962 "\n"
6963 "layout(location=0) out vec4 x;\n"
6964 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
6965 "void main(){\n"
6966 " x = vec4(bar.y);\n"
6967 "}\n";
Tobin Ehlisf6585052015-12-17 11:48:42 -07006968 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6969 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
6970 VkPipelineObj pipe(m_device);
6971 pipe.AddShader(&vs);
6972 pipe.AddShader(&fs);
6973 pipe.AddColorAttachment();
6974 pipe.CreateVKPipeline(pipeline_layout, renderPass());
6975
Rene Lindsayacbf5e62016-12-15 18:47:11 -07006976 VkViewport viewport = {0, 0, 16, 16, 0, 1};
6977 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
6978 VkRect2D scissor = {{0, 0}, {16, 16}};
6979 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
6980
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006981 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07006982 // This update should succeed, but offset size of 512 will overstep buffer
6983 // /w range 1024 & size 1024
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006984 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6985 &descriptorSet, 1, pDynOff);
Tobin Ehlisf6585052015-12-17 11:48:42 -07006986 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006987 m_errorMonitor->VerifyFound();
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006988
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006989 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis512098e2016-05-05 09:06:12 -06006990 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006991
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006992 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06006993 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006994 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6995}
6996
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006997TEST_F(VkLayerTest, DescriptorBufferUpdateNoMemoryBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006998 TEST_DESCRIPTION(
6999 "Attempt to update a descriptor with a non-sparse buffer "
7000 "that doesn't have memory bound");
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06007001 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06007002 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06007003 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Tobin Ehlisfed999f2016-09-21 15:09:45 -06007004 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7005 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06007006
Tony Barbour1fa09702017-03-16 12:09:08 -06007007 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06007008 ASSERT_NO_FATAL_FAILURE(InitViewport());
7009 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7010
7011 VkDescriptorPoolSize ds_type_count = {};
7012 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
7013 ds_type_count.descriptorCount = 1;
7014
7015 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7016 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7017 ds_pool_ci.pNext = NULL;
7018 ds_pool_ci.maxSets = 1;
7019 ds_pool_ci.poolSizeCount = 1;
7020 ds_pool_ci.pPoolSizes = &ds_type_count;
7021
7022 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007023 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06007024 ASSERT_VK_SUCCESS(err);
7025
7026 VkDescriptorSetLayoutBinding dsl_binding = {};
7027 dsl_binding.binding = 0;
7028 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
7029 dsl_binding.descriptorCount = 1;
7030 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7031 dsl_binding.pImmutableSamplers = NULL;
7032
7033 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7034 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7035 ds_layout_ci.pNext = NULL;
7036 ds_layout_ci.bindingCount = 1;
7037 ds_layout_ci.pBindings = &dsl_binding;
7038 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007039 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06007040 ASSERT_VK_SUCCESS(err);
7041
7042 VkDescriptorSet descriptorSet;
7043 VkDescriptorSetAllocateInfo alloc_info = {};
7044 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7045 alloc_info.descriptorSetCount = 1;
7046 alloc_info.descriptorPool = ds_pool;
7047 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007048 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06007049 ASSERT_VK_SUCCESS(err);
7050
7051 // Create a buffer to update the descriptor with
7052 uint32_t qfi = 0;
7053 VkBufferCreateInfo buffCI = {};
7054 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
7055 buffCI.size = 1024;
7056 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
7057 buffCI.queueFamilyIndexCount = 1;
7058 buffCI.pQueueFamilyIndices = &qfi;
7059
7060 VkBuffer dyub;
7061 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
7062 ASSERT_VK_SUCCESS(err);
7063
7064 // Attempt to update descriptor without binding memory to it
7065 VkDescriptorBufferInfo buffInfo = {};
7066 buffInfo.buffer = dyub;
7067 buffInfo.offset = 0;
7068 buffInfo.range = 1024;
7069
7070 VkWriteDescriptorSet descriptor_write;
7071 memset(&descriptor_write, 0, sizeof(descriptor_write));
7072 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
7073 descriptor_write.dstSet = descriptorSet;
7074 descriptor_write.dstBinding = 0;
7075 descriptor_write.descriptorCount = 1;
7076 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
7077 descriptor_write.pBufferInfo = &buffInfo;
7078
7079 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
7080 m_errorMonitor->VerifyFound();
7081
7082 vkDestroyBuffer(m_device->device(), dyub, NULL);
7083 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7084 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
7085}
7086
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07007087TEST_F(VkLayerTest, InvalidPushConstants) {
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07007088 VkResult err;
Tony Barbour1fa09702017-03-16 12:09:08 -06007089 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07007090 ASSERT_NO_FATAL_FAILURE(InitViewport());
7091 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7092
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007093 VkPipelineLayout pipeline_layout;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07007094 VkPushConstantRange pc_range = {};
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07007095 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7096 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7097 pipeline_layout_ci.pushConstantRangeCount = 1;
7098 pipeline_layout_ci.pPushConstantRanges = &pc_range;
7099
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007100 //
7101 // Check for invalid push constant ranges in pipeline layouts.
7102 //
7103 struct PipelineLayoutTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06007104 VkPushConstantRange const range;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007105 char const *msg;
7106 };
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07007107
Karl Schultzc81037d2016-05-12 08:11:23 -06007108 const uint32_t too_big = m_device->props.limits.maxPushConstantsSize + 0x4;
7109 const std::array<PipelineLayoutTestCase, 10> range_tests = {{
7110 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0},
7111 "vkCreatePipelineLayout() call has push constants index 0 with "
7112 "size 0."},
7113 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
7114 "vkCreatePipelineLayout() call has push constants index 0 with "
7115 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06007116 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Karl Schultzc81037d2016-05-12 08:11:23 -06007117 "vkCreatePipelineLayout() call has push constants index 0 with "
7118 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06007119 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 0},
Karl Schultzc81037d2016-05-12 08:11:23 -06007120 "vkCreatePipelineLayout() call has push constants index 0 with "
7121 "size 0."},
7122 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
7123 "vkCreatePipelineLayout() call has push constants index 0 with "
7124 "offset 1. Offset must"},
7125 {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big},
7126 "vkCreatePipelineLayout() call has push constants index 0 "
7127 "with offset "},
7128 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big},
7129 "vkCreatePipelineLayout() call has push constants "
7130 "index 0 with offset "},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06007131 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06007132 "vkCreatePipelineLayout() call has push constants index 0 "
7133 "with offset "},
7134 {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020},
7135 "vkCreatePipelineLayout() call has push "
7136 "constants index 0 with offset "},
7137 {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0},
7138 "vkCreatePipelineLayout() call has push "
7139 "constants index 0 with offset "},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007140 }};
7141
7142 // Check for invalid offset and size
Karl Schultzc81037d2016-05-12 08:11:23 -06007143 for (const auto &iter : range_tests) {
7144 pc_range = iter.range;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007145 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
7146 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007147 m_errorMonitor->VerifyFound();
7148 if (VK_SUCCESS == err) {
7149 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7150 }
7151 }
7152
7153 // Check for invalid stage flag
7154 pc_range.offset = 0;
7155 pc_range.size = 16;
7156 pc_range.stageFlags = 0;
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06007157 m_errorMonitor->SetDesiredFailureMsg(
7158 VK_DEBUG_REPORT_ERROR_BIT_EXT,
7159 "vkCreatePipelineLayout: value of pCreateInfo->pPushConstantRanges[0].stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007160 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007161 m_errorMonitor->VerifyFound();
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007162 if (VK_SUCCESS == err) {
7163 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7164 }
7165
Karl Schultzc59b72d2017-02-24 15:45:05 -07007166 // Check for duplicate stage flags in a list of push constant ranges.
7167 // A shader can only have one push constant block and that block is mapped
7168 // to the push constant range that has that shader's stage flag set.
7169 // The shader's stage flag can only appear once in all the ranges, so the
7170 // implementation can find the one and only range to map it to.
Karl Schultzc81037d2016-05-12 08:11:23 -06007171 const uint32_t ranges_per_test = 5;
Karl Schultzc59b72d2017-02-24 15:45:05 -07007172 struct DuplicateStageFlagsTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06007173 VkPushConstantRange const ranges[ranges_per_test];
Jeremy Hayesde6d96c2017-02-01 15:22:32 -07007174 std::vector<char const *> const msg;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007175 };
Karl Schultzc59b72d2017-02-24 15:45:05 -07007176 // Overlapping ranges are OK, but a stage flag can appear only once.
7177 const std::array<DuplicateStageFlagsTestCase, 3> duplicate_stageFlags_tests = {
7178 {
7179 {{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
7180 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
7181 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
7182 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007183 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzc59b72d2017-02-24 15:45:05 -07007184 {
7185 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 0 and 1.",
7186 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 0 and 2.",
7187 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 0 and 3.",
7188 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 0 and 4.",
7189 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 1 and 2.",
7190 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 1 and 3.",
7191 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 1 and 4.",
7192 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 2 and 3.",
7193 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 2 and 4.",
7194 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 3 and 4.",
7195 }},
7196 {{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
7197 {VK_SHADER_STAGE_GEOMETRY_BIT, 0, 4},
7198 {VK_SHADER_STAGE_FRAGMENT_BIT, 0, 4},
7199 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
7200 {VK_SHADER_STAGE_GEOMETRY_BIT, 0, 4}},
7201 {
7202 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 0 and 3.",
7203 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 1 and 4.",
7204 }},
7205 {{{VK_SHADER_STAGE_FRAGMENT_BIT, 0, 4},
7206 {VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 4},
7207 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
7208 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
7209 {VK_SHADER_STAGE_GEOMETRY_BIT, 0, 4}},
7210 {
7211 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 2 and 3.",
7212 }},
7213 },
7214 };
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007215
Karl Schultzc59b72d2017-02-24 15:45:05 -07007216 for (const auto &iter : duplicate_stageFlags_tests) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007217 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
Karl Schultzc81037d2016-05-12 08:11:23 -06007218 pipeline_layout_ci.pushConstantRangeCount = ranges_per_test;
Karl Schultzc59b72d2017-02-24 15:45:05 -07007219 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg.begin(), iter.msg.end());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007220 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007221 m_errorMonitor->VerifyFound();
7222 if (VK_SUCCESS == err) {
7223 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7224 }
7225 }
7226
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007227 //
7228 // CmdPushConstants tests
7229 //
7230
Karl Schultzc59b72d2017-02-24 15:45:05 -07007231 // Setup a pipeline layout with ranges: [0,16) [64,80)
Karl Schultzc81037d2016-05-12 08:11:23 -06007232 const VkPushConstantRange pc_range2[] = {
Karl Schultzc59b72d2017-02-24 15:45:05 -07007233 {VK_SHADER_STAGE_VERTEX_BIT, 64, 16}, {VK_SHADER_STAGE_FRAGMENT_BIT, 0, 16},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007234 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007235 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range2) / sizeof(VkPushConstantRange);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007236 pipeline_layout_ci.pPushConstantRanges = pc_range2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007237 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07007238 ASSERT_VK_SUCCESS(err);
Karl Schultzc59b72d2017-02-24 15:45:05 -07007239
7240 const uint8_t dummy_values[100] = {};
7241
7242 m_commandBuffer->BeginCommandBuffer();
7243 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007244
7245 // Check for invalid stage flag
Karl Schultzc59b72d2017-02-24 15:45:05 -07007246 // Note that VU 00996 isn't reached due to parameter validation
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06007247 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdPushConstants: value of stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007248 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, 0, 0, 16, dummy_values);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007249 m_errorMonitor->VerifyFound();
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007250
Karl Schultzc59b72d2017-02-24 15:45:05 -07007251 m_errorMonitor->ExpectSuccess();
7252 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, VK_SHADER_STAGE_FRAGMENT_BIT, 0, 16, dummy_values);
7253 m_errorMonitor->VerifyNotFound();
7254 m_errorMonitor->ExpectSuccess();
7255 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, VK_SHADER_STAGE_VERTEX_BIT, 64, 16, dummy_values);
7256 m_errorMonitor->VerifyNotFound();
7257 const std::array<VkPushConstantRange, 6> cmd_range_tests = {{
7258 {VK_SHADER_STAGE_FRAGMENT_BIT, 64, 16},
7259 {VK_SHADER_STAGE_VERTEX_BIT, 0, 16},
7260 {VK_SHADER_STAGE_GEOMETRY_BIT, 0, 16},
7261 {VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT, 0, 16},
7262 {VK_SHADER_STAGE_VERTEX_BIT, 24, 16},
7263 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06007264 }};
Karl Schultzc59b72d2017-02-24 15:45:05 -07007265 for (const auto &iter : cmd_range_tests) {
7266 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00988);
7267 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.stageFlags, iter.offset, iter.size,
7268 dummy_values);
Karl Schultzc81037d2016-05-12 08:11:23 -06007269 m_errorMonitor->VerifyFound();
7270 }
Karl Schultzc81037d2016-05-12 08:11:23 -06007271
Tony Barbour552f6c02016-12-21 14:34:07 -07007272 m_commandBuffer->EndRenderPass();
7273 m_commandBuffer->EndCommandBuffer();
Karl Schultzc59b72d2017-02-24 15:45:05 -07007274 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07007275}
7276
Karl Schultz6addd812016-02-02 17:17:23 -07007277TEST_F(VkLayerTest, DescriptorSetCompatibility) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07007278 // Test various desriptorSet errors with bad binding combinations
Karl Schultz6addd812016-02-02 17:17:23 -07007279 VkResult err;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007280
Tony Barbour1fa09702017-03-16 12:09:08 -06007281 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis559c6382015-11-05 09:52:49 -07007282 ASSERT_NO_FATAL_FAILURE(InitViewport());
7283 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7284
7285 static const uint32_t NUM_DESCRIPTOR_TYPES = 5;
7286 VkDescriptorPoolSize ds_type_count[NUM_DESCRIPTOR_TYPES] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007287 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7288 ds_type_count[0].descriptorCount = 10;
7289 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
7290 ds_type_count[1].descriptorCount = 2;
7291 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
7292 ds_type_count[2].descriptorCount = 2;
7293 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_SAMPLER;
7294 ds_type_count[3].descriptorCount = 5;
7295 // TODO : LunarG ILO driver currently asserts in desc.c w/ INPUT_ATTACHMENT
7296 // type
7297 // ds_type_count[4].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
7298 ds_type_count[4].type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
7299 ds_type_count[4].descriptorCount = 2;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007300
7301 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007302 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7303 ds_pool_ci.pNext = NULL;
7304 ds_pool_ci.maxSets = 5;
7305 ds_pool_ci.poolSizeCount = NUM_DESCRIPTOR_TYPES;
7306 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007307
7308 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007309 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007310 ASSERT_VK_SUCCESS(err);
7311
7312 static const uint32_t MAX_DS_TYPES_IN_LAYOUT = 2;
7313 VkDescriptorSetLayoutBinding dsl_binding[MAX_DS_TYPES_IN_LAYOUT] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007314 dsl_binding[0].binding = 0;
7315 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7316 dsl_binding[0].descriptorCount = 5;
7317 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
7318 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007319
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007320 // Create layout identical to set0 layout but w/ different stageFlags
7321 VkDescriptorSetLayoutBinding dsl_fs_stage_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007322 dsl_fs_stage_only.binding = 0;
7323 dsl_fs_stage_only.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7324 dsl_fs_stage_only.descriptorCount = 5;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007325 dsl_fs_stage_only.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; // Different stageFlags to cause error at
7326 // bind time
Karl Schultz6addd812016-02-02 17:17:23 -07007327 dsl_fs_stage_only.pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007328 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007329 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7330 ds_layout_ci.pNext = NULL;
7331 ds_layout_ci.bindingCount = 1;
7332 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007333 static const uint32_t NUM_LAYOUTS = 4;
7334 VkDescriptorSetLayout ds_layout[NUM_LAYOUTS] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007335 VkDescriptorSetLayout ds_layout_fs_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007336 // Create 4 unique layouts for full pipelineLayout, and 1 special fs-only
7337 // layout for error case
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007338 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[0]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007339 ASSERT_VK_SUCCESS(err);
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07007340 ds_layout_ci.pBindings = &dsl_fs_stage_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007341 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007342 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007343 dsl_binding[0].binding = 0;
7344 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007345 dsl_binding[0].descriptorCount = 2;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07007346 dsl_binding[1].binding = 1;
7347 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
7348 dsl_binding[1].descriptorCount = 2;
7349 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
7350 dsl_binding[1].pImmutableSamplers = NULL;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07007351 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007352 ds_layout_ci.bindingCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007353 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[1]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007354 ASSERT_VK_SUCCESS(err);
7355 dsl_binding[0].binding = 0;
7356 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007357 dsl_binding[0].descriptorCount = 5;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007358 ds_layout_ci.bindingCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007359 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[2]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007360 ASSERT_VK_SUCCESS(err);
7361 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007362 dsl_binding[0].descriptorCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007363 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[3]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007364 ASSERT_VK_SUCCESS(err);
7365
7366 static const uint32_t NUM_SETS = 4;
7367 VkDescriptorSet descriptorSet[NUM_SETS] = {};
7368 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007369 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007370 alloc_info.descriptorSetCount = NUM_LAYOUTS;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007371 alloc_info.descriptorPool = ds_pool;
7372 alloc_info.pSetLayouts = ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007373 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptorSet);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007374 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007375 VkDescriptorSet ds0_fs_only = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07007376 alloc_info.descriptorSetCount = 1;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007377 alloc_info.pSetLayouts = &ds_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007378 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &ds0_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007379 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007380
7381 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007382 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7383 pipeline_layout_ci.pNext = NULL;
7384 pipeline_layout_ci.setLayoutCount = NUM_LAYOUTS;
7385 pipeline_layout_ci.pSetLayouts = ds_layout;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007386
7387 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007388 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007389 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007390 // Create pipelineLayout with only one setLayout
7391 pipeline_layout_ci.setLayoutCount = 1;
7392 VkPipelineLayout single_pipe_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007393 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &single_pipe_layout);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007394 ASSERT_VK_SUCCESS(err);
7395 // Create pipelineLayout with 2 descriptor setLayout at index 0
7396 pipeline_layout_ci.pSetLayouts = &ds_layout[3];
7397 VkPipelineLayout pipe_layout_one_desc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007398 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_one_desc);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007399 ASSERT_VK_SUCCESS(err);
7400 // Create pipelineLayout with 5 SAMPLER descriptor setLayout at index 0
7401 pipeline_layout_ci.pSetLayouts = &ds_layout[2];
7402 VkPipelineLayout pipe_layout_five_samp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007403 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_five_samp);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007404 ASSERT_VK_SUCCESS(err);
7405 // Create pipelineLayout with UB type, but stageFlags for FS only
7406 pipeline_layout_ci.pSetLayouts = &ds_layout_fs_only;
7407 VkPipelineLayout pipe_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007408 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007409 ASSERT_VK_SUCCESS(err);
7410 // Create pipelineLayout w/ incompatible set0 layout, but set1 is fine
7411 VkDescriptorSetLayout pl_bad_s0[2] = {};
7412 pl_bad_s0[0] = ds_layout_fs_only;
7413 pl_bad_s0[1] = ds_layout[1];
7414 pipeline_layout_ci.setLayoutCount = 2;
7415 pipeline_layout_ci.pSetLayouts = pl_bad_s0;
7416 VkPipelineLayout pipe_layout_bad_set0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007417 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_bad_set0);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007418 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007419
Tobin Ehlis88452832015-12-03 09:40:56 -07007420 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007421 char const *vsSource =
7422 "#version 450\n"
7423 "\n"
7424 "out gl_PerVertex {\n"
7425 " vec4 gl_Position;\n"
7426 "};\n"
7427 "void main(){\n"
7428 " gl_Position = vec4(1);\n"
7429 "}\n";
7430 char const *fsSource =
7431 "#version 450\n"
7432 "\n"
7433 "layout(location=0) out vec4 x;\n"
7434 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
7435 "void main(){\n"
7436 " x = vec4(bar.y);\n"
7437 "}\n";
Tobin Ehlis88452832015-12-03 09:40:56 -07007438 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
7439 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007440 VkPipelineObj pipe(m_device);
7441 pipe.AddShader(&vs);
7442 pipe.AddShader(&fs);
Tobin Ehlis88452832015-12-03 09:40:56 -07007443 pipe.AddColorAttachment();
7444 pipe.CreateVKPipeline(pipe_layout_fs_only, renderPass());
Tobin Ehlis559c6382015-11-05 09:52:49 -07007445
Tony Barbour552f6c02016-12-21 14:34:07 -07007446 m_commandBuffer->BeginCommandBuffer();
7447 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis88452832015-12-03 09:40:56 -07007448
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007449 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07007450 // NOTE : I believe LunarG ilo driver has bug (LX#189) that requires binding
7451 // of PSO
7452 // here before binding DSs. Otherwise we assert in cmd_copy_dset_data() of
7453 // cmd_pipeline.c
7454 // due to the fact that cmd_alloc_dset_data() has not been called in
7455 // cmd_bind_graphics_pipeline()
7456 // TODO : Want to cause various binding incompatibility issues here to test
7457 // DrawState
Tobin Ehlis559c6382015-11-05 09:52:49 -07007458 // First cause various verify_layout_compatibility() fails
7459 // Second disturb early and late sets and verify INFO msgs
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007460 // verify_set_layout_compatibility fail cases:
7461 // 1. invalid VkPipelineLayout (layout) passed into vkCmdBindDescriptorSets
Karl Schultzf78bcdd2016-11-30 12:36:01 -07007462 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00981);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007463 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
7464 (VkPipelineLayout)((size_t)0xbaadb1be), 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007465 m_errorMonitor->VerifyFound();
7466
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007467 // 2. layoutIndex exceeds # of layouts in layout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007468 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempting to bind set to index 1");
7469 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, single_pipe_layout, 0, 2,
7470 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007471 m_errorMonitor->VerifyFound();
7472
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007473 vkDestroyPipelineLayout(m_device->device(), single_pipe_layout, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07007474 // 3. Pipeline setLayout[0] has 2 descriptors, but set being bound has 5
7475 // descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007476 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has 2 descriptors, but DescriptorSetLayout ");
7477 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_one_desc, 0, 1,
7478 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007479 m_errorMonitor->VerifyFound();
7480
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007481 vkDestroyPipelineLayout(m_device->device(), pipe_layout_one_desc, NULL);
7482 // 4. same # of descriptors but mismatch in type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007483 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is type 'VK_DESCRIPTOR_TYPE_SAMPLER' but binding ");
7484 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_five_samp, 0, 1,
7485 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007486 m_errorMonitor->VerifyFound();
7487
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007488 vkDestroyPipelineLayout(m_device->device(), pipe_layout_five_samp, NULL);
7489 // 5. same # of descriptors but mismatch in stageFlags
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007490 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7491 " has stageFlags 16 but binding 0 for DescriptorSetLayout ");
7492 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
7493 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007494 m_errorMonitor->VerifyFound();
7495
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007496 // Cause INFO messages due to disturbing previously bound Sets
7497 // First bind sets 0 & 1
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007498 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
7499 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007500 // 1. Disturb bound set0 by re-binding set1 w/ updated pipelineLayout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007501 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " previously bound as set #0 was disturbed ");
7502 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
7503 &descriptorSet[1], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007504 m_errorMonitor->VerifyFound();
7505
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007506 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
7507 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007508 // 2. Disturb set after last bound set
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007509 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
7510 " newly bound as set #0 so set #1 and "
7511 "any subsequent sets were disturbed ");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007512 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
7513 &ds0_fs_only, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007514 m_errorMonitor->VerifyFound();
7515
Tobin Ehlis10fad692016-07-07 12:00:36 -06007516 // Now that we're done actively using the pipelineLayout that gfx pipeline
7517 // was created with, we should be able to delete it. Do that now to verify
7518 // that validation obeys pipelineLayout lifetime
7519 vkDestroyPipelineLayout(m_device->device(), pipe_layout_fs_only, NULL);
7520
Tobin Ehlis88452832015-12-03 09:40:56 -07007521 // Cause draw-time errors due to PSO incompatibilities
Karl Schultz6addd812016-02-02 17:17:23 -07007522 // 1. Error due to not binding required set (we actually use same code as
7523 // above to disturb set0)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007524 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
7525 &descriptorSet[0], 0, NULL);
7526 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
7527 &descriptorSet[1], 0, NULL);
7528 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " uses set #0 but that set is not bound.");
Rene Lindsay9f228e42017-01-16 13:57:45 -07007529
7530 VkViewport viewport = {0, 0, 16, 16, 0, 1};
7531 VkRect2D scissor = {{0, 0}, {16, 16}};
7532 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
7533 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
7534
Tobin Ehlis88452832015-12-03 09:40:56 -07007535 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007536 m_errorMonitor->VerifyFound();
7537
Tobin Ehlis991d45a2016-01-06 08:48:41 -07007538 vkDestroyPipelineLayout(m_device->device(), pipe_layout_bad_set0, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07007539 // 2. Error due to bound set not being compatible with PSO's
7540 // VkPipelineLayout (diff stageFlags in this case)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007541 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
7542 &descriptorSet[0], 0, NULL);
7543 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " bound as set #0 is not compatible with ");
Tobin Ehlis88452832015-12-03 09:40:56 -07007544 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007545 m_errorMonitor->VerifyFound();
7546
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007547 // Remaining clean-up
Karl Schultz6addd812016-02-02 17:17:23 -07007548 for (uint32_t i = 0; i < NUM_LAYOUTS; ++i) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007549 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout[i], NULL);
7550 }
7551 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_fs_only, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007552 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7553 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
7554}
Tobin Ehlis559c6382015-11-05 09:52:49 -07007555
Karl Schultz6addd812016-02-02 17:17:23 -07007556TEST_F(VkLayerTest, NoBeginCommandBuffer) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007557 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7558 "You must call vkBeginCommandBuffer() before this call to ");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007559
Tony Barbour1fa09702017-03-16 12:09:08 -06007560 ASSERT_NO_FATAL_FAILURE(Init());
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007561 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007562 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007563 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007564
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007565 m_errorMonitor->VerifyFound();
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007566}
7567
Karl Schultz6addd812016-02-02 17:17:23 -07007568TEST_F(VkLayerTest, SecondaryCommandBufferNullRenderpass) {
7569 VkResult err;
7570 VkCommandBuffer draw_cmd;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007571
Karl Schultzf78bcdd2016-11-30 12:36:01 -07007572 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00110);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007573
Tony Barbour1fa09702017-03-16 12:09:08 -06007574 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06007575
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007576 VkCommandBufferAllocateInfo cmd = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007577 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06007578 cmd.pNext = NULL;
Mike Schuchardt06304c22017-03-01 17:09:09 -07007579 cmd.commandPool = m_commandPool->handle();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007580 cmd.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007581 cmd.commandBufferCount = 1;
Cody Northropb4569702015-08-04 17:35:57 -06007582
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007583 err = vkAllocateCommandBuffers(m_device->device(), &cmd, &draw_cmd);
Mike Stroyand1c84a52015-08-18 14:40:24 -06007584 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06007585
7586 // Force the failure by not setting the Renderpass and Framebuffer fields
Jon Ashburnf19916e2016-01-11 13:12:43 -07007587 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Rene Lindsay65072a92017-01-23 11:38:10 -07007588 cmd_buf_hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
7589
7590 VkCommandBufferBeginInfo cmd_buf_info = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007591 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06007592 cmd_buf_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007593 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007594 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06007595
7596 // The error should be caught by validation of the BeginCommandBuffer call
7597 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
7598
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007599 m_errorMonitor->VerifyFound();
Mike Schuchardt06304c22017-03-01 17:09:09 -07007600 vkFreeCommandBuffers(m_device->device(), m_commandPool->handle(), 1, &draw_cmd);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06007601}
7602
Chris Forbes5b3725e2017-05-18 16:01:20 -07007603TEST_F(VkLayerTest, SecondaryCommandBufferRerecordedExplicitReset) {
Chris Forbes9480ae92017-05-17 17:14:34 -07007604 ASSERT_NO_FATAL_FAILURE(Init());
7605
Chris Forbes5b3725e2017-05-18 16:01:20 -07007606 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was destroyed or rerecorded");
Chris Forbes9480ae92017-05-17 17:14:34 -07007607
7608 // A pool we can reset in.
7609 VkCommandPoolObj pool(m_device, m_device->graphics_queue_node_index_,
7610 VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT);
7611 VkCommandBufferObj secondary(m_device, &pool,
7612 VK_COMMAND_BUFFER_LEVEL_SECONDARY);
7613
7614 secondary.begin();
7615 secondary.end();
7616
7617 m_commandBuffer->begin();
7618 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary.handle());
7619
7620 // rerecording of secondary
Chris Forbes5b3725e2017-05-18 16:01:20 -07007621 secondary.reset(); // explicit reset here.
Chris Forbes9480ae92017-05-17 17:14:34 -07007622 secondary.begin();
7623 secondary.end();
7624
7625 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary.handle());
Chris Forbes5b3725e2017-05-18 16:01:20 -07007626 m_errorMonitor->VerifyFound();
7627}
Chris Forbes9480ae92017-05-17 17:14:34 -07007628
Chris Forbes5b3725e2017-05-18 16:01:20 -07007629TEST_F(VkLayerTest, SecondaryCommandBufferRerecordedNoReset) {
7630 ASSERT_NO_FATAL_FAILURE(Init());
7631
7632 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was destroyed or rerecorded");
7633
7634 // A pool we can reset in.
7635 VkCommandPoolObj pool(m_device, m_device->graphics_queue_node_index_,
7636 VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT);
7637 VkCommandBufferObj secondary(m_device, &pool,
7638 VK_COMMAND_BUFFER_LEVEL_SECONDARY);
7639
7640 secondary.begin();
7641 secondary.end();
7642
7643 m_commandBuffer->begin();
7644 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary.handle());
7645
7646 // rerecording of secondary
7647 secondary.begin(); // implicit reset in begin
7648 secondary.end();
7649
7650 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary.handle());
Chris Forbes9480ae92017-05-17 17:14:34 -07007651 m_errorMonitor->VerifyFound();
7652}
7653
Chris Forbes42bbfe22017-05-18 16:20:53 -07007654TEST_F(VkLayerTest, CascadedInvalidation) {
7655 ASSERT_NO_FATAL_FAILURE(Init());
7656
7657 VkEventCreateInfo eci = { VK_STRUCTURE_TYPE_EVENT_CREATE_INFO, nullptr, 0 };
7658 VkEvent event;
7659 vkCreateEvent(m_device->device(), &eci, nullptr, &event);
7660
7661 VkCommandBufferObj secondary(m_device, m_commandPool, VK_COMMAND_BUFFER_LEVEL_SECONDARY);
7662 secondary.begin();
7663 vkCmdSetEvent(secondary.handle(), event, VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT);
7664 secondary.end();
7665
7666 m_commandBuffer->begin();
7667 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary.handle());
7668 m_commandBuffer->end();
7669
7670 // destroying the event should invalidate both primary and secondary CB
7671 vkDestroyEvent(m_device->device(), event, nullptr);
7672
7673 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "invalid because bound Event");
7674 m_commandBuffer->QueueCommandBuffer(false);
7675 m_errorMonitor->VerifyFound();
7676}
7677
Karl Schultz6addd812016-02-02 17:17:23 -07007678TEST_F(VkLayerTest, CommandBufferResetErrors) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007679 // Cause error due to Begin while recording CB
7680 // Then cause 2 errors for attempting to reset CB w/o having
7681 // VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT set for the pool from
7682 // which CBs were allocated. Note that this bit is off by default.
Mike Weiblencce7ec72016-10-17 19:33:05 -06007683 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call Begin on command buffer");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007684
Tony Barbour1fa09702017-03-16 12:09:08 -06007685 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007686
7687 // Calls AllocateCommandBuffers
7688 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
7689
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07007690 // Force the failure by setting the Renderpass and Framebuffer fields with (fake) data
Jon Ashburnf19916e2016-01-11 13:12:43 -07007691 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07007692 cmd_buf_hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
7693 VkCommandBufferBeginInfo cmd_buf_info = {};
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007694 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
7695 cmd_buf_info.pNext = NULL;
7696 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007697 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007698
7699 // Begin CB to transition to recording state
7700 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
7701 // Can't re-begin. This should trigger error
7702 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007703 m_errorMonitor->VerifyFound();
7704
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07007705 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00093);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007706 VkCommandBufferResetFlags flags = 0; // Don't care about flags for this test
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007707 // Reset attempt will trigger error due to incorrect CommandPool state
7708 vkResetCommandBuffer(commandBuffer.GetBufferHandle(), flags);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007709 m_errorMonitor->VerifyFound();
7710
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07007711 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00105);
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007712 // Transition CB to RECORDED state
7713 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
7714 // Now attempting to Begin will implicitly reset, which triggers error
7715 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007716 m_errorMonitor->VerifyFound();
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007717}
7718
Karl Schultz6addd812016-02-02 17:17:23 -07007719TEST_F(VkLayerTest, InvalidPipelineCreateState) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007720 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07007721 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007722
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07007723 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7724 "Invalid Pipeline CreateInfo State: Vertex Shader required");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007725
Tony Barbour1fa09702017-03-16 12:09:08 -06007726 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06007727 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06007728
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007729 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007730 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7731 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06007732
7733 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007734 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7735 ds_pool_ci.pNext = NULL;
7736 ds_pool_ci.maxSets = 1;
7737 ds_pool_ci.poolSizeCount = 1;
7738 ds_pool_ci.pPoolSizes = &ds_type_count;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06007739
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007740 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007741 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007742 ASSERT_VK_SUCCESS(err);
7743
Tony Barboureb254902015-07-15 12:50:33 -06007744 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007745 dsl_binding.binding = 0;
7746 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7747 dsl_binding.descriptorCount = 1;
7748 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7749 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007750
Tony Barboureb254902015-07-15 12:50:33 -06007751 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007752 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7753 ds_layout_ci.pNext = NULL;
7754 ds_layout_ci.bindingCount = 1;
7755 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06007756
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007757 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007758 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007759 ASSERT_VK_SUCCESS(err);
7760
7761 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007762 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007763 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007764 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007765 alloc_info.descriptorPool = ds_pool;
7766 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007767 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007768 ASSERT_VK_SUCCESS(err);
7769
Tony Barboureb254902015-07-15 12:50:33 -06007770 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007771 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7772 pipeline_layout_ci.setLayoutCount = 1;
7773 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007774
7775 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007776 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007777 ASSERT_VK_SUCCESS(err);
7778
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007779 VkViewport vp = {}; // Just need dummy vp to point to
7780 VkRect2D sc = {}; // dummy scissor to point to
Tobin Ehlise68360f2015-10-01 11:15:13 -06007781
7782 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007783 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7784 vp_state_ci.scissorCount = 1;
7785 vp_state_ci.pScissors = &sc;
7786 vp_state_ci.viewportCount = 1;
7787 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007788
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007789 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7790 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7791 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7792 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7793 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7794 rs_state_ci.depthClampEnable = VK_FALSE;
Rene Lindsayae4977b2017-01-23 14:55:54 -07007795 rs_state_ci.rasterizerDiscardEnable = VK_TRUE;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007796 rs_state_ci.depthBiasEnable = VK_FALSE;
Rene Lindsayae4977b2017-01-23 14:55:54 -07007797 rs_state_ci.lineWidth = 1.0f;
7798
7799 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7800 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7801 vi_ci.pNext = nullptr;
7802 vi_ci.vertexBindingDescriptionCount = 0;
7803 vi_ci.pVertexBindingDescriptions = nullptr;
7804 vi_ci.vertexAttributeDescriptionCount = 0;
7805 vi_ci.pVertexAttributeDescriptions = nullptr;
7806
7807 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7808 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7809 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7810
7811 VkPipelineShaderStageCreateInfo shaderStages[2];
7812 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7813
7814 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7815 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Dave Houlton59a20702017-02-02 17:26:23 -07007816 shaderStages[0] = fs.GetStageCreateInfo(); // should be: vs.GetStageCreateInfo();
Rene Lindsayae4977b2017-01-23 14:55:54 -07007817 shaderStages[1] = fs.GetStageCreateInfo();
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007818
Tony Barboureb254902015-07-15 12:50:33 -06007819 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007820 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7821 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007822 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007823 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7824 gp_ci.layout = pipeline_layout;
7825 gp_ci.renderPass = renderPass();
Rene Lindsayae4977b2017-01-23 14:55:54 -07007826 gp_ci.pVertexInputState = &vi_ci;
7827 gp_ci.pInputAssemblyState = &ia_ci;
7828
7829 gp_ci.stageCount = 1;
7830 gp_ci.pStages = shaderStages;
Tony Barboureb254902015-07-15 12:50:33 -06007831
7832 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007833 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7834 pc_ci.initialDataSize = 0;
7835 pc_ci.pInitialData = 0;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007836
7837 VkPipeline pipeline;
Jon Ashburnc669cc62015-07-09 15:02:25 -06007838 VkPipelineCache pipelineCache;
7839
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007840 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Jon Ashburnc669cc62015-07-09 15:02:25 -06007841 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007842 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007843 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007844
Chia-I Wuf7458c52015-10-26 21:10:41 +08007845 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7846 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7847 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7848 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007849}
Rene Lindsayae4977b2017-01-23 14:55:54 -07007850
Tobin Ehlis912df022015-09-17 08:46:18 -06007851/*// TODO : This test should be good, but needs Tess support in compiler to run
7852TEST_F(VkLayerTest, InvalidPatchControlPoints)
7853{
7854 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis912df022015-09-17 08:46:18 -06007855 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007856
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07007857 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07007858 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH
7859primitive ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007860
Tony Barbour1fa09702017-03-16 12:09:08 -06007861 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis912df022015-09-17 08:46:18 -06007862 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis912df022015-09-17 08:46:18 -06007863
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007864 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis912df022015-09-17 08:46:18 -06007865 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007866 ds_type_count.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007867
7868 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7869 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7870 ds_pool_ci.pNext = NULL;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007871 ds_pool_ci.poolSizeCount = 1;
7872 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis912df022015-09-17 08:46:18 -06007873
7874 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07007875 err = vkCreateDescriptorPool(m_device->device(),
7876VK_DESCRIPTOR_POOL_USAGE_NON_FREE, 1, &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis912df022015-09-17 08:46:18 -06007877 ASSERT_VK_SUCCESS(err);
7878
7879 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08007880 dsl_binding.binding = 0;
Tobin Ehlis912df022015-09-17 08:46:18 -06007881 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08007882 dsl_binding.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007883 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7884 dsl_binding.pImmutableSamplers = NULL;
7885
7886 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007887 ds_layout_ci.sType =
7888VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06007889 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007890 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07007891 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis912df022015-09-17 08:46:18 -06007892
7893 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007894 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
7895&ds_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06007896 ASSERT_VK_SUCCESS(err);
7897
7898 VkDescriptorSet descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07007899 err = vkAllocateDescriptorSets(m_device->device(), ds_pool,
7900VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet);
Tobin Ehlis912df022015-09-17 08:46:18 -06007901 ASSERT_VK_SUCCESS(err);
7902
7903 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007904 pipeline_layout_ci.sType =
7905VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06007906 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007907 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007908 pipeline_layout_ci.pSetLayouts = &ds_layout;
7909
7910 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007911 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
7912&pipeline_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06007913 ASSERT_VK_SUCCESS(err);
7914
7915 VkPipelineShaderStageCreateInfo shaderStages[3];
7916 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
7917
Karl Schultz6addd812016-02-02 17:17:23 -07007918 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT,
7919this);
Tobin Ehlis912df022015-09-17 08:46:18 -06007920 // Just using VS txt for Tess shaders as we don't care about functionality
Karl Schultz6addd812016-02-02 17:17:23 -07007921 VkShaderObj
7922tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
7923this);
7924 VkShaderObj
7925te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT,
7926this);
Tobin Ehlis912df022015-09-17 08:46:18 -06007927
Karl Schultz6addd812016-02-02 17:17:23 -07007928 shaderStages[0].sType =
7929VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007930 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007931 shaderStages[0].shader = vs.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07007932 shaderStages[1].sType =
7933VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007934 shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007935 shaderStages[1].shader = tc.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07007936 shaderStages[2].sType =
7937VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007938 shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007939 shaderStages[2].shader = te.handle();
7940
7941 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007942 iaCI.sType =
7943VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Chia-I Wu515eb8f2015-10-31 00:31:16 +08007944 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST;
Tobin Ehlis912df022015-09-17 08:46:18 -06007945
7946 VkPipelineTessellationStateCreateInfo tsCI = {};
7947 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
7948 tsCI.patchControlPoints = 0; // This will cause an error
7949
7950 VkGraphicsPipelineCreateInfo gp_ci = {};
7951 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7952 gp_ci.pNext = NULL;
7953 gp_ci.stageCount = 3;
7954 gp_ci.pStages = shaderStages;
7955 gp_ci.pVertexInputState = NULL;
7956 gp_ci.pInputAssemblyState = &iaCI;
7957 gp_ci.pTessellationState = &tsCI;
7958 gp_ci.pViewportState = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007959 gp_ci.pRasterizationState = NULL;
Tobin Ehlis912df022015-09-17 08:46:18 -06007960 gp_ci.pMultisampleState = NULL;
7961 gp_ci.pDepthStencilState = NULL;
7962 gp_ci.pColorBlendState = NULL;
7963 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7964 gp_ci.layout = pipeline_layout;
7965 gp_ci.renderPass = renderPass();
7966
7967 VkPipelineCacheCreateInfo pc_ci = {};
7968 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7969 pc_ci.pNext = NULL;
7970 pc_ci.initialSize = 0;
7971 pc_ci.initialData = 0;
7972 pc_ci.maxSize = 0;
7973
7974 VkPipeline pipeline;
7975 VkPipelineCache pipelineCache;
7976
Karl Schultz6addd812016-02-02 17:17:23 -07007977 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL,
7978&pipelineCache);
Tobin Ehlis912df022015-09-17 08:46:18 -06007979 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07007980 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
7981&gp_ci, NULL, &pipeline);
Tobin Ehlis912df022015-09-17 08:46:18 -06007982
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007983 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007984
Chia-I Wuf7458c52015-10-26 21:10:41 +08007985 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7986 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7987 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7988 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis912df022015-09-17 08:46:18 -06007989}
7990*/
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007991
Mark Lobodzinski510aa5c2016-12-19 07:59:10 -07007992TEST_F(VkLayerTest, PSOViewportScissorCountTests) {
Karl Schultz6addd812016-02-02 17:17:23 -07007993 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007994
Mark Lobodzinski510aa5c2016-12-19 07:59:10 -07007995 TEST_DESCRIPTION("Test various cases of viewport and scissor count validation");
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007996
Tony Barbour1fa09702017-03-16 12:09:08 -06007997 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007998 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007999
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008000 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008001 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8002 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008003
8004 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008005 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8006 ds_pool_ci.maxSets = 1;
8007 ds_pool_ci.poolSizeCount = 1;
8008 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008009
8010 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008011 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008012 ASSERT_VK_SUCCESS(err);
8013
8014 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008015 dsl_binding.binding = 0;
8016 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8017 dsl_binding.descriptorCount = 1;
8018 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008019
8020 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008021 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8022 ds_layout_ci.bindingCount = 1;
8023 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008024
8025 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008026 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008027 ASSERT_VK_SUCCESS(err);
8028
8029 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008030 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008031 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008032 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008033 alloc_info.descriptorPool = ds_pool;
8034 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008035 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008036 ASSERT_VK_SUCCESS(err);
8037
8038 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008039 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8040 pipeline_layout_ci.setLayoutCount = 1;
8041 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008042
8043 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008044 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008045 ASSERT_VK_SUCCESS(err);
8046
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07008047 VkViewport vp = {};
Tobin Ehlise68360f2015-10-01 11:15:13 -06008048 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008049 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
Mark Lobodzinski510aa5c2016-12-19 07:59:10 -07008050 vp_state_ci.scissorCount = 1;
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07008051 vp_state_ci.viewportCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -07008052 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008053
Karl Schultzdfdb8d42016-03-08 10:30:21 -07008054 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
8055 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
8056 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
8057 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
8058 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
8059 rs_state_ci.depthClampEnable = VK_FALSE;
8060 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
8061 rs_state_ci.depthBiasEnable = VK_FALSE;
8062
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07008063 VkPipelineVertexInputStateCreateInfo vi_ci = {};
8064 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
8065 vi_ci.pNext = nullptr;
8066 vi_ci.vertexBindingDescriptionCount = 0;
8067 vi_ci.pVertexBindingDescriptions = nullptr;
8068 vi_ci.vertexAttributeDescriptionCount = 0;
8069 vi_ci.pVertexAttributeDescriptions = nullptr;
8070
8071 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
8072 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
8073 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
8074
8075 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
8076 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
8077 pipe_ms_state_ci.pNext = NULL;
8078 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
8079 pipe_ms_state_ci.sampleShadingEnable = 0;
8080 pipe_ms_state_ci.minSampleShading = 1.0;
8081 pipe_ms_state_ci.pSampleMask = NULL;
8082
Cody Northropeb3a6c12015-10-05 14:44:45 -06008083 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07008084 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06008085
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008086 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07008087 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chia-I Wu28e06912015-10-31 00:31:16 +08008088 shaderStages[0] = vs.GetStageCreateInfo();
8089 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06008090
8091 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008092 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8093 gp_ci.stageCount = 2;
8094 gp_ci.pStages = shaderStages;
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07008095 gp_ci.pVertexInputState = &vi_ci;
8096 gp_ci.pInputAssemblyState = &ia_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07008097 gp_ci.pViewportState = &vp_state_ci;
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07008098 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07008099 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07008100 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
8101 gp_ci.layout = pipeline_layout;
8102 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06008103
8104 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008105 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008106
8107 VkPipeline pipeline;
8108 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008109 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008110 ASSERT_VK_SUCCESS(err);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008111
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07008112 if (!m_device->phy().features().multiViewport) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07008113 printf(" MultiViewport feature is disabled -- skipping enabled-state checks.\n");
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07008114
8115 // Check case where multiViewport is disabled and viewport count is not 1
8116 // We check scissor/viewport simultaneously since separating them would trigger the mismatch error, 1434.
8117 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01430);
8118 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01431);
8119 vp_state_ci.scissorCount = 0;
8120 vp_state_ci.viewportCount = 0;
8121 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
8122 m_errorMonitor->VerifyFound();
8123 } else {
8124 if (m_device->props.limits.maxViewports == 1) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07008125 printf(" Device limit maxViewports is 1, skipping tests that require higher limits.\n");
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07008126 } else {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07008127 printf(" MultiViewport feature is enabled -- skipping disabled-state checks.\n");
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07008128
8129 // Check is that viewportcount and scissorcount match
8130 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01434);
8131 vp_state_ci.scissorCount = 1;
8132 vp_state_ci.viewportCount = m_device->props.limits.maxViewports;
8133 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
8134 m_errorMonitor->VerifyFound();
8135
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07008136 // Check case where multiViewport is enabled and viewport count is greater than max
8137 // We check scissor/viewport simultaneously since separating them would trigger the mismatch error, 1434.
8138 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01432);
8139 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01433);
8140 vp_state_ci.scissorCount = m_device->props.limits.maxViewports + 1;
8141 vp_state_ci.viewportCount = m_device->props.limits.maxViewports + 1;
8142 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
8143 m_errorMonitor->VerifyFound();
8144 }
8145 }
Tobin Ehlise68360f2015-10-01 11:15:13 -06008146
Chia-I Wuf7458c52015-10-26 21:10:41 +08008147 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
8148 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8149 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8150 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008151}
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07008152
8153// Don't set viewport state in PSO. This is an error b/c we always need this state for the counts even if the data is going to be
8154// set dynamically.
Karl Schultz6addd812016-02-02 17:17:23 -07008155TEST_F(VkLayerTest, PSOViewportStateNotSet) {
Karl Schultz6addd812016-02-02 17:17:23 -07008156 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008157
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07008158 TEST_DESCRIPTION("Create a graphics pipeline with rasterization enabled but no viewport state.");
8159
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07008160 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02113);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008161
Tony Barbour1fa09702017-03-16 12:09:08 -06008162 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlise68360f2015-10-01 11:15:13 -06008163 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06008164
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008165 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008166 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8167 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008168
8169 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008170 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8171 ds_pool_ci.maxSets = 1;
8172 ds_pool_ci.poolSizeCount = 1;
8173 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008174
8175 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008176 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008177 ASSERT_VK_SUCCESS(err);
8178
8179 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008180 dsl_binding.binding = 0;
8181 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8182 dsl_binding.descriptorCount = 1;
8183 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008184
8185 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008186 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8187 ds_layout_ci.bindingCount = 1;
8188 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008189
8190 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008191 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008192 ASSERT_VK_SUCCESS(err);
8193
8194 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008195 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008196 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008197 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008198 alloc_info.descriptorPool = ds_pool;
8199 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008200 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008201 ASSERT_VK_SUCCESS(err);
8202
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07008203 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
8204 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
8205 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
8206
8207 VkPipelineVertexInputStateCreateInfo vi_ci = {};
8208 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
8209 vi_ci.pNext = nullptr;
8210 vi_ci.vertexBindingDescriptionCount = 0;
8211 vi_ci.pVertexBindingDescriptions = nullptr;
8212 vi_ci.vertexAttributeDescriptionCount = 0;
8213 vi_ci.pVertexAttributeDescriptions = nullptr;
8214
8215 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
8216 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
8217 pipe_ms_state_ci.pNext = NULL;
8218 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
8219 pipe_ms_state_ci.sampleShadingEnable = 0;
8220 pipe_ms_state_ci.minSampleShading = 1.0;
8221 pipe_ms_state_ci.pSampleMask = NULL;
8222
Tobin Ehlise68360f2015-10-01 11:15:13 -06008223 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008224 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8225 pipeline_layout_ci.setLayoutCount = 1;
8226 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008227
8228 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008229 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008230 ASSERT_VK_SUCCESS(err);
8231
8232 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
8233 // Set scissor as dynamic to avoid second error
8234 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008235 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
8236 dyn_state_ci.dynamicStateCount = 1;
8237 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008238
Cody Northropeb3a6c12015-10-05 14:44:45 -06008239 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07008240 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06008241
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008242 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07008243 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
8244 // We shouldn't need a fragment shader but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08008245 shaderStages[0] = vs.GetStageCreateInfo();
8246 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06008247
Karl Schultzdfdb8d42016-03-08 10:30:21 -07008248 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
8249 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
8250 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
8251 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
8252 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
8253 rs_state_ci.depthClampEnable = VK_FALSE;
8254 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
8255 rs_state_ci.depthBiasEnable = VK_FALSE;
8256
Tobin Ehlise68360f2015-10-01 11:15:13 -06008257 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008258 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8259 gp_ci.stageCount = 2;
8260 gp_ci.pStages = shaderStages;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07008261 gp_ci.pRasterizationState = &rs_state_ci;
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07008262 // Not setting VP state w/o dynamic vp state should cause validation error
8263 gp_ci.pViewportState = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -07008264 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07008265 gp_ci.pVertexInputState = &vi_ci;
8266 gp_ci.pInputAssemblyState = &ia_ci;
8267 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07008268 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
8269 gp_ci.layout = pipeline_layout;
8270 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06008271
8272 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008273 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008274
8275 VkPipeline pipeline;
8276 VkPipelineCache pipelineCache;
8277
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008278 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008279 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008280 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008281
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008282 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06008283
Chia-I Wuf7458c52015-10-26 21:10:41 +08008284 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
8285 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8286 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8287 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008288}
Mark Lobodzinski73169e22016-12-16 14:01:17 -07008289
8290// Create PSO w/o non-zero viewportCount but no viewport data, then run second test where dynamic scissor count doesn't match PSO
8291// scissor count
Karl Schultz6addd812016-02-02 17:17:23 -07008292TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch) {
8293 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008294
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07008295 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02110);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008296
Tony Barbour1fa09702017-03-16 12:09:08 -06008297 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12008298
8299 if (!m_device->phy().features().multiViewport) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07008300 printf(" Device does not support multiple viewports/scissors; skipped.\n");
Chris Forbesc08a6ca2016-07-28 14:14:07 +12008301 return;
8302 }
8303
Tobin Ehlise68360f2015-10-01 11:15:13 -06008304 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06008305
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008306 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008307 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8308 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008309
8310 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008311 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8312 ds_pool_ci.maxSets = 1;
8313 ds_pool_ci.poolSizeCount = 1;
8314 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008315
8316 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008317 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008318 ASSERT_VK_SUCCESS(err);
8319
8320 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008321 dsl_binding.binding = 0;
8322 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8323 dsl_binding.descriptorCount = 1;
8324 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008325
8326 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008327 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8328 ds_layout_ci.bindingCount = 1;
8329 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008330
8331 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008332 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008333 ASSERT_VK_SUCCESS(err);
8334
8335 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008336 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008337 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008338 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008339 alloc_info.descriptorPool = ds_pool;
8340 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008341 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008342 ASSERT_VK_SUCCESS(err);
8343
8344 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008345 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8346 pipeline_layout_ci.setLayoutCount = 1;
8347 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008348
8349 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008350 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008351 ASSERT_VK_SUCCESS(err);
8352
8353 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008354 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
8355 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008356 vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error
Karl Schultz6addd812016-02-02 17:17:23 -07008357 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008358 vp_state_ci.pScissors = NULL; // Scissor is dynamic (below) so this won't cause error
Tobin Ehlise68360f2015-10-01 11:15:13 -06008359
8360 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
8361 // Set scissor as dynamic to avoid that error
8362 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008363 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
8364 dyn_state_ci.dynamicStateCount = 1;
8365 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008366
Mark Lobodzinski73169e22016-12-16 14:01:17 -07008367 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
8368 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
8369 pipe_ms_state_ci.pNext = NULL;
8370 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
8371 pipe_ms_state_ci.sampleShadingEnable = 0;
8372 pipe_ms_state_ci.minSampleShading = 1.0;
8373 pipe_ms_state_ci.pSampleMask = NULL;
8374
Cody Northropeb3a6c12015-10-05 14:44:45 -06008375 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07008376 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06008377
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008378 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski73169e22016-12-16 14:01:17 -07008379 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
8380 // We shouldn't need a fragment shader but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08008381 shaderStages[0] = vs.GetStageCreateInfo();
8382 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06008383
Cody Northropf6622dc2015-10-06 10:33:21 -06008384 VkPipelineVertexInputStateCreateInfo vi_ci = {};
8385 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
8386 vi_ci.pNext = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008387 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06008388 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008389 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06008390 vi_ci.pVertexAttributeDescriptions = nullptr;
8391
8392 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
8393 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
8394 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
8395
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008396 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008397 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Mark Lobodzinski73169e22016-12-16 14:01:17 -07008398 rs_ci.lineWidth = m_device->props.limits.lineWidthRange[0];
Cody Northropf6622dc2015-10-06 10:33:21 -06008399 rs_ci.pNext = nullptr;
8400
Mark Youngc89c6312016-03-31 16:03:20 -06008401 VkPipelineColorBlendAttachmentState att = {};
8402 att.blendEnable = VK_FALSE;
8403 att.colorWriteMask = 0xf;
8404
Cody Northropf6622dc2015-10-06 10:33:21 -06008405 VkPipelineColorBlendStateCreateInfo cb_ci = {};
8406 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
8407 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06008408 cb_ci.attachmentCount = 1;
8409 cb_ci.pAttachments = &att;
Cody Northropf6622dc2015-10-06 10:33:21 -06008410
Tobin Ehlise68360f2015-10-01 11:15:13 -06008411 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008412 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8413 gp_ci.stageCount = 2;
8414 gp_ci.pStages = shaderStages;
8415 gp_ci.pVertexInputState = &vi_ci;
8416 gp_ci.pInputAssemblyState = &ia_ci;
8417 gp_ci.pViewportState = &vp_state_ci;
8418 gp_ci.pRasterizationState = &rs_ci;
8419 gp_ci.pColorBlendState = &cb_ci;
8420 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski73169e22016-12-16 14:01:17 -07008421 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07008422 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
8423 gp_ci.layout = pipeline_layout;
8424 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06008425
8426 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008427 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008428
8429 VkPipeline pipeline;
8430 VkPipelineCache pipelineCache;
8431
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008432 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008433 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008434 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008435
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008436 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008437
Tobin Ehlisd332f282015-10-02 11:00:56 -06008438 // Now hit second fail case where we set scissor w/ different count than PSO
Karl Schultz6addd812016-02-02 17:17:23 -07008439 // First need to successfully create the PSO from above by setting
8440 // pViewports
Mike Weiblen95dd0f92016-10-19 12:28:27 -06008441 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic scissor(s) 0 are used by pipeline state object, ");
Karl Schultz6addd812016-02-02 17:17:23 -07008442
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008443 VkViewport vp = {}; // Just need dummy vp to point to
Karl Schultz6addd812016-02-02 17:17:23 -07008444 vp_state_ci.pViewports = &vp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008445 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07008446 ASSERT_VK_SUCCESS(err);
Tony Barbour552f6c02016-12-21 14:34:07 -07008447 m_commandBuffer->BeginCommandBuffer();
8448 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008449 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008450 VkRect2D scissors[1] = {}; // don't care about data
Karl Schultz6addd812016-02-02 17:17:23 -07008451 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12008452 vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 1, 1, scissors);
Karl Schultz6addd812016-02-02 17:17:23 -07008453 Draw(1, 0, 0, 0);
8454
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008455 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07008456
8457 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
8458 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8459 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8460 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008461 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07008462}
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008463
8464// Create PSO w/o non-zero scissorCount but no scissor data, then run second test where dynamic viewportCount doesn't match PSO
Karl Schultz6addd812016-02-02 17:17:23 -07008465// viewportCount
8466TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch) {
8467 VkResult err;
8468
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07008469 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02111);
Karl Schultz6addd812016-02-02 17:17:23 -07008470
Tony Barbour1fa09702017-03-16 12:09:08 -06008471 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12008472
8473 if (!m_device->phy().features().multiViewport) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07008474 printf(" Device does not support multiple viewports/scissors; skipped.\n");
Chris Forbesc08a6ca2016-07-28 14:14:07 +12008475 return;
8476 }
8477
Karl Schultz6addd812016-02-02 17:17:23 -07008478 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8479
8480 VkDescriptorPoolSize ds_type_count = {};
8481 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8482 ds_type_count.descriptorCount = 1;
8483
8484 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8485 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8486 ds_pool_ci.maxSets = 1;
8487 ds_pool_ci.poolSizeCount = 1;
8488 ds_pool_ci.pPoolSizes = &ds_type_count;
8489
8490 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008491 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Karl Schultz6addd812016-02-02 17:17:23 -07008492 ASSERT_VK_SUCCESS(err);
8493
8494 VkDescriptorSetLayoutBinding dsl_binding = {};
8495 dsl_binding.binding = 0;
8496 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8497 dsl_binding.descriptorCount = 1;
8498 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8499
8500 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8501 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8502 ds_layout_ci.bindingCount = 1;
8503 ds_layout_ci.pBindings = &dsl_binding;
8504
8505 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008506 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07008507 ASSERT_VK_SUCCESS(err);
8508
8509 VkDescriptorSet descriptorSet;
8510 VkDescriptorSetAllocateInfo alloc_info = {};
8511 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8512 alloc_info.descriptorSetCount = 1;
8513 alloc_info.descriptorPool = ds_pool;
8514 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008515 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Karl Schultz6addd812016-02-02 17:17:23 -07008516 ASSERT_VK_SUCCESS(err);
8517
8518 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
8519 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8520 pipeline_layout_ci.setLayoutCount = 1;
8521 pipeline_layout_ci.pSetLayouts = &ds_layout;
8522
8523 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008524 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07008525 ASSERT_VK_SUCCESS(err);
8526
8527 VkPipelineViewportStateCreateInfo vp_state_ci = {};
8528 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
8529 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008530 vp_state_ci.pScissors = NULL; // Null scissor w/ count of 1 should cause error
Karl Schultz6addd812016-02-02 17:17:23 -07008531 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008532 vp_state_ci.pViewports = NULL; // vp is dynamic (below) so this won't cause error
Karl Schultz6addd812016-02-02 17:17:23 -07008533
8534 VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT;
8535 // Set scissor as dynamic to avoid that error
8536 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
8537 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
8538 dyn_state_ci.dynamicStateCount = 1;
8539 dyn_state_ci.pDynamicStates = &vp_state;
8540
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008541 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
8542 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
8543 pipe_ms_state_ci.pNext = NULL;
8544 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
8545 pipe_ms_state_ci.sampleShadingEnable = 0;
8546 pipe_ms_state_ci.minSampleShading = 1.0;
8547 pipe_ms_state_ci.pSampleMask = NULL;
8548
Karl Schultz6addd812016-02-02 17:17:23 -07008549 VkPipelineShaderStageCreateInfo shaderStages[2];
8550 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
8551
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008552 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008553 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
8554 // We shouldn't need a fragment shader but add it to be able to run on more devices
Karl Schultz6addd812016-02-02 17:17:23 -07008555 shaderStages[0] = vs.GetStageCreateInfo();
8556 shaderStages[1] = fs.GetStageCreateInfo();
8557
8558 VkPipelineVertexInputStateCreateInfo vi_ci = {};
8559 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
8560 vi_ci.pNext = nullptr;
8561 vi_ci.vertexBindingDescriptionCount = 0;
8562 vi_ci.pVertexBindingDescriptions = nullptr;
8563 vi_ci.vertexAttributeDescriptionCount = 0;
8564 vi_ci.pVertexAttributeDescriptions = nullptr;
8565
8566 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
8567 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
8568 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
8569
8570 VkPipelineRasterizationStateCreateInfo rs_ci = {};
8571 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008572 rs_ci.lineWidth = m_device->props.limits.lineWidthRange[0];
Karl Schultz6addd812016-02-02 17:17:23 -07008573 rs_ci.pNext = nullptr;
8574
Mark Youngc89c6312016-03-31 16:03:20 -06008575 VkPipelineColorBlendAttachmentState att = {};
8576 att.blendEnable = VK_FALSE;
8577 att.colorWriteMask = 0xf;
8578
Karl Schultz6addd812016-02-02 17:17:23 -07008579 VkPipelineColorBlendStateCreateInfo cb_ci = {};
8580 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
8581 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06008582 cb_ci.attachmentCount = 1;
8583 cb_ci.pAttachments = &att;
Karl Schultz6addd812016-02-02 17:17:23 -07008584
8585 VkGraphicsPipelineCreateInfo gp_ci = {};
8586 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8587 gp_ci.stageCount = 2;
8588 gp_ci.pStages = shaderStages;
8589 gp_ci.pVertexInputState = &vi_ci;
8590 gp_ci.pInputAssemblyState = &ia_ci;
8591 gp_ci.pViewportState = &vp_state_ci;
8592 gp_ci.pRasterizationState = &rs_ci;
8593 gp_ci.pColorBlendState = &cb_ci;
8594 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008595 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07008596 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
8597 gp_ci.layout = pipeline_layout;
8598 gp_ci.renderPass = renderPass();
8599
8600 VkPipelineCacheCreateInfo pc_ci = {};
8601 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
8602
8603 VkPipeline pipeline;
8604 VkPipelineCache pipelineCache;
8605
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008606 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Karl Schultz6addd812016-02-02 17:17:23 -07008607 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008608 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07008609
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008610 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07008611
8612 // Now hit second fail case where we set scissor w/ different count than PSO
8613 // First need to successfully create the PSO from above by setting
8614 // pViewports
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07008615 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8616 "Dynamic viewport(s) 0 are used by pipeline state object, ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008617
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008618 VkRect2D sc = {}; // Just need dummy vp to point to
Tobin Ehlisd332f282015-10-02 11:00:56 -06008619 vp_state_ci.pScissors = &sc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008620 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06008621 ASSERT_VK_SUCCESS(err);
Tony Barbour552f6c02016-12-21 14:34:07 -07008622 m_commandBuffer->BeginCommandBuffer();
8623 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008624 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008625 VkViewport viewports[1] = {};
8626 viewports[0].width = 8;
8627 viewports[0].height = 8;
Tobin Ehlisd332f282015-10-02 11:00:56 -06008628 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12008629 vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 1, 1, viewports);
Tobin Ehlisd332f282015-10-02 11:00:56 -06008630 Draw(1, 0, 0, 0);
8631
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008632 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06008633
Chia-I Wuf7458c52015-10-26 21:10:41 +08008634 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
8635 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8636 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8637 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008638 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008639}
8640
Mark Young7394fdd2016-03-31 14:56:43 -06008641TEST_F(VkLayerTest, PSOLineWidthInvalid) {
8642 VkResult err;
8643
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008644 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06008645
Tony Barbour1fa09702017-03-16 12:09:08 -06008646 ASSERT_NO_FATAL_FAILURE(Init());
Mark Young7394fdd2016-03-31 14:56:43 -06008647 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8648
8649 VkDescriptorPoolSize ds_type_count = {};
8650 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8651 ds_type_count.descriptorCount = 1;
8652
8653 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8654 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8655 ds_pool_ci.maxSets = 1;
8656 ds_pool_ci.poolSizeCount = 1;
8657 ds_pool_ci.pPoolSizes = &ds_type_count;
8658
8659 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008660 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Young7394fdd2016-03-31 14:56:43 -06008661 ASSERT_VK_SUCCESS(err);
8662
8663 VkDescriptorSetLayoutBinding dsl_binding = {};
8664 dsl_binding.binding = 0;
8665 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8666 dsl_binding.descriptorCount = 1;
8667 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8668
8669 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8670 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8671 ds_layout_ci.bindingCount = 1;
8672 ds_layout_ci.pBindings = &dsl_binding;
8673
8674 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008675 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06008676 ASSERT_VK_SUCCESS(err);
8677
8678 VkDescriptorSet descriptorSet;
8679 VkDescriptorSetAllocateInfo alloc_info = {};
8680 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8681 alloc_info.descriptorSetCount = 1;
8682 alloc_info.descriptorPool = ds_pool;
8683 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008684 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Young7394fdd2016-03-31 14:56:43 -06008685 ASSERT_VK_SUCCESS(err);
8686
8687 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
8688 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8689 pipeline_layout_ci.setLayoutCount = 1;
8690 pipeline_layout_ci.pSetLayouts = &ds_layout;
8691
8692 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008693 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06008694 ASSERT_VK_SUCCESS(err);
8695
8696 VkPipelineViewportStateCreateInfo vp_state_ci = {};
8697 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
8698 vp_state_ci.scissorCount = 1;
8699 vp_state_ci.pScissors = NULL;
8700 vp_state_ci.viewportCount = 1;
8701 vp_state_ci.pViewports = NULL;
8702
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008703 VkDynamicState dynamic_states[3] = {VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR, VK_DYNAMIC_STATE_LINE_WIDTH};
Mark Young7394fdd2016-03-31 14:56:43 -06008704 // Set scissor as dynamic to avoid that error
8705 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
8706 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
8707 dyn_state_ci.dynamicStateCount = 2;
8708 dyn_state_ci.pDynamicStates = dynamic_states;
8709
8710 VkPipelineShaderStageCreateInfo shaderStages[2];
8711 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
8712
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008713 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
8714 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT,
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008715 this); // TODO - We shouldn't need a fragment shader
8716 // but add it to be able to run on more devices
Mark Young7394fdd2016-03-31 14:56:43 -06008717 shaderStages[0] = vs.GetStageCreateInfo();
8718 shaderStages[1] = fs.GetStageCreateInfo();
8719
8720 VkPipelineVertexInputStateCreateInfo vi_ci = {};
8721 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
8722 vi_ci.pNext = nullptr;
8723 vi_ci.vertexBindingDescriptionCount = 0;
8724 vi_ci.pVertexBindingDescriptions = nullptr;
8725 vi_ci.vertexAttributeDescriptionCount = 0;
8726 vi_ci.pVertexAttributeDescriptions = nullptr;
8727
8728 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
8729 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
8730 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
8731
8732 VkPipelineRasterizationStateCreateInfo rs_ci = {};
8733 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
8734 rs_ci.pNext = nullptr;
Rene Lindsay144e4842017-01-20 14:27:15 -07008735 rs_ci.rasterizerDiscardEnable = VK_TRUE;
Mark Young7394fdd2016-03-31 14:56:43 -06008736
Mark Young47107952016-05-02 15:59:55 -06008737 // Check too low (line width of -1.0f).
8738 rs_ci.lineWidth = -1.0f;
Mark Young7394fdd2016-03-31 14:56:43 -06008739
8740 VkPipelineColorBlendAttachmentState att = {};
8741 att.blendEnable = VK_FALSE;
8742 att.colorWriteMask = 0xf;
8743
8744 VkPipelineColorBlendStateCreateInfo cb_ci = {};
8745 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
8746 cb_ci.pNext = nullptr;
8747 cb_ci.attachmentCount = 1;
8748 cb_ci.pAttachments = &att;
8749
8750 VkGraphicsPipelineCreateInfo gp_ci = {};
8751 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8752 gp_ci.stageCount = 2;
8753 gp_ci.pStages = shaderStages;
8754 gp_ci.pVertexInputState = &vi_ci;
8755 gp_ci.pInputAssemblyState = &ia_ci;
8756 gp_ci.pViewportState = &vp_state_ci;
8757 gp_ci.pRasterizationState = &rs_ci;
8758 gp_ci.pColorBlendState = &cb_ci;
8759 gp_ci.pDynamicState = &dyn_state_ci;
8760 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
8761 gp_ci.layout = pipeline_layout;
8762 gp_ci.renderPass = renderPass();
8763
8764 VkPipelineCacheCreateInfo pc_ci = {};
8765 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
8766
8767 VkPipeline pipeline;
8768 VkPipelineCache pipelineCache;
8769
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008770 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06008771 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008772 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06008773
8774 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06008775 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06008776
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008777 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06008778
8779 // Check too high (line width of 65536.0f).
8780 rs_ci.lineWidth = 65536.0f;
8781
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008782 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06008783 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008784 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06008785
8786 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06008787 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06008788
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008789 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06008790
8791 dyn_state_ci.dynamicStateCount = 3;
8792
8793 rs_ci.lineWidth = 1.0f;
8794
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008795 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06008796 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008797 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tony Barbour552f6c02016-12-21 14:34:07 -07008798 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008799 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06008800
8801 // Check too low with dynamic setting.
Mark Young47107952016-05-02 15:59:55 -06008802 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), -1.0f);
Mark Young7394fdd2016-03-31 14:56:43 -06008803 m_errorMonitor->VerifyFound();
8804
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008805 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06008806
8807 // Check too high with dynamic setting.
8808 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), 65536.0f);
8809 m_errorMonitor->VerifyFound();
Tony Barbour552f6c02016-12-21 14:34:07 -07008810 m_commandBuffer->EndCommandBuffer();
Mark Young7394fdd2016-03-31 14:56:43 -06008811
8812 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
8813 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8814 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8815 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008816 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06008817}
8818
Jeremy Hayes37f0cdd2017-05-04 18:08:49 -06008819TEST_F(VkLayerTest, VALIDATION_ERROR_01407) {
8820 TEST_DESCRIPTION("Test VALIDATION_ERROR_01407: binding must be less than VkPhysicalDeviceLimits::maxVertexInputBindings");
8821
8822 ASSERT_NO_FATAL_FAILURE(Init());
8823 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8824
8825 VkPipelineCache pipeline_cache;
8826 {
8827 VkPipelineCacheCreateInfo create_info{};
8828 create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
8829
8830 VkResult err = vkCreatePipelineCache(m_device->device(), &create_info, nullptr, &pipeline_cache);
8831 ASSERT_VK_SUCCESS(err);
8832 }
8833
8834 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
8835 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
8836
8837 VkPipelineShaderStageCreateInfo stages[2]{{}};
8838 stages[0] = vs.GetStageCreateInfo();
8839 stages[1] = fs.GetStageCreateInfo();
8840
8841 // Test when binding is greater than or equal to VkPhysicalDeviceLimits::maxVertexInputBindings.
8842 VkVertexInputBindingDescription vertex_input_binding_description{};
8843 vertex_input_binding_description.binding = m_device->props.limits.maxVertexInputBindings;
8844
8845 VkPipelineVertexInputStateCreateInfo vertex_input_state{};
8846 vertex_input_state.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
8847 vertex_input_state.pNext = nullptr;
8848 vertex_input_state.vertexBindingDescriptionCount = 1;
8849 vertex_input_state.pVertexBindingDescriptions = &vertex_input_binding_description;
8850 vertex_input_state.vertexAttributeDescriptionCount = 0;
8851 vertex_input_state.pVertexAttributeDescriptions = nullptr;
8852
8853 VkPipelineInputAssemblyStateCreateInfo input_assembly_state{};
8854 input_assembly_state.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
8855 input_assembly_state.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
8856
8857 VkViewport viewport{};
8858 VkPipelineViewportStateCreateInfo viewport_state{};
8859 viewport_state.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
8860 viewport_state.scissorCount = 1;
8861 viewport_state.viewportCount = 1;
8862 viewport_state.pViewports = &viewport;
8863
8864 VkPipelineMultisampleStateCreateInfo multisample_state{};
8865 multisample_state.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
8866 multisample_state.pNext = nullptr;
8867 multisample_state.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
8868 multisample_state.sampleShadingEnable = 0;
8869 multisample_state.minSampleShading = 1.0;
8870 multisample_state.pSampleMask = nullptr;
8871
8872 VkPipelineRasterizationStateCreateInfo rasterization_state{};
8873 rasterization_state.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
8874 rasterization_state.polygonMode = VK_POLYGON_MODE_FILL;
8875 rasterization_state.cullMode = VK_CULL_MODE_BACK_BIT;
8876 rasterization_state.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
8877 rasterization_state.depthClampEnable = VK_FALSE;
8878 rasterization_state.rasterizerDiscardEnable = VK_FALSE;
8879 rasterization_state.depthBiasEnable = VK_FALSE;
8880
8881 VkPipelineLayout pipeline_layout;
8882 {
8883 VkPipelineLayoutCreateInfo create_info{};
8884 create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8885 create_info.setLayoutCount = 0;
8886 create_info.pSetLayouts = nullptr;
8887
8888 VkResult err = vkCreatePipelineLayout(m_device->device(), &create_info, nullptr, &pipeline_layout);
8889 ASSERT_VK_SUCCESS(err);
8890 }
8891
8892 {
8893 VkGraphicsPipelineCreateInfo create_info{};
8894 create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8895 create_info.stageCount = 2;
8896 create_info.pStages = stages;
8897 create_info.pVertexInputState = &vertex_input_state;
8898 create_info.pInputAssemblyState = &input_assembly_state;
8899 create_info.pViewportState = &viewport_state;
8900 create_info.pMultisampleState = &multisample_state;
8901 create_info.pRasterizationState = &rasterization_state;
8902 create_info.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
8903 create_info.layout = pipeline_layout;
8904 create_info.renderPass = renderPass();
8905
8906 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01407);
8907 VkPipeline pipeline;
8908 vkCreateGraphicsPipelines(m_device->device(), pipeline_cache, 1, &create_info, nullptr, &pipeline);
8909 m_errorMonitor->VerifyFound();
8910 }
8911
8912 vkDestroyPipelineCache(m_device->device(), pipeline_cache, nullptr);
8913 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
8914}
8915
8916TEST_F(VkLayerTest, VALIDATION_ERROR_01408) {
8917 TEST_DESCRIPTION(
8918 "Test VALIDATION_ERROR_01408: stride must be less than or equal to VkPhysicalDeviceLimits::maxVertexInputBindingStride");
8919
8920 ASSERT_NO_FATAL_FAILURE(Init());
8921 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8922
8923 VkPipelineCache pipeline_cache;
8924 {
8925 VkPipelineCacheCreateInfo create_info{};
8926 create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
8927
8928 VkResult err = vkCreatePipelineCache(m_device->device(), &create_info, nullptr, &pipeline_cache);
8929 ASSERT_VK_SUCCESS(err);
8930 }
8931
8932 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
8933 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
8934
8935 VkPipelineShaderStageCreateInfo stages[2]{{}};
8936 stages[0] = vs.GetStageCreateInfo();
8937 stages[1] = fs.GetStageCreateInfo();
8938
8939 // Test when stride is greater than VkPhysicalDeviceLimits::maxVertexInputBindingStride.
8940 VkVertexInputBindingDescription vertex_input_binding_description{};
8941 vertex_input_binding_description.stride = m_device->props.limits.maxVertexInputBindingStride + 1;
8942
8943 VkPipelineVertexInputStateCreateInfo vertex_input_state{};
8944 vertex_input_state.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
8945 vertex_input_state.pNext = nullptr;
8946 vertex_input_state.vertexBindingDescriptionCount = 1;
8947 vertex_input_state.pVertexBindingDescriptions = &vertex_input_binding_description;
8948 vertex_input_state.vertexAttributeDescriptionCount = 0;
8949 vertex_input_state.pVertexAttributeDescriptions = nullptr;
8950
8951 VkPipelineInputAssemblyStateCreateInfo input_assembly_state{};
8952 input_assembly_state.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
8953 input_assembly_state.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
8954
8955 VkViewport viewport{};
8956 VkPipelineViewportStateCreateInfo viewport_state{};
8957 viewport_state.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
8958 viewport_state.scissorCount = 1;
8959 viewport_state.viewportCount = 1;
8960 viewport_state.pViewports = &viewport;
8961
8962 VkPipelineMultisampleStateCreateInfo multisample_state{};
8963 multisample_state.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
8964 multisample_state.pNext = nullptr;
8965 multisample_state.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
8966 multisample_state.sampleShadingEnable = 0;
8967 multisample_state.minSampleShading = 1.0;
8968 multisample_state.pSampleMask = nullptr;
8969
8970 VkPipelineRasterizationStateCreateInfo rasterization_state{};
8971 rasterization_state.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
8972 rasterization_state.polygonMode = VK_POLYGON_MODE_FILL;
8973 rasterization_state.cullMode = VK_CULL_MODE_BACK_BIT;
8974 rasterization_state.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
8975 rasterization_state.depthClampEnable = VK_FALSE;
8976 rasterization_state.rasterizerDiscardEnable = VK_FALSE;
8977 rasterization_state.depthBiasEnable = VK_FALSE;
8978
8979 VkPipelineLayout pipeline_layout;
8980 {
8981 VkPipelineLayoutCreateInfo create_info{};
8982 create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8983 create_info.setLayoutCount = 0;
8984 create_info.pSetLayouts = nullptr;
8985
8986 VkResult err = vkCreatePipelineLayout(m_device->device(), &create_info, nullptr, &pipeline_layout);
8987 ASSERT_VK_SUCCESS(err);
8988 }
8989
8990 {
8991 VkGraphicsPipelineCreateInfo create_info{};
8992 create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8993 create_info.stageCount = 2;
8994 create_info.pStages = stages;
8995 create_info.pVertexInputState = &vertex_input_state;
8996 create_info.pInputAssemblyState = &input_assembly_state;
8997 create_info.pViewportState = &viewport_state;
8998 create_info.pMultisampleState = &multisample_state;
8999 create_info.pRasterizationState = &rasterization_state;
9000 create_info.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
9001 create_info.layout = pipeline_layout;
9002 create_info.renderPass = renderPass();
9003
9004 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01408);
9005 VkPipeline pipeline;
9006 vkCreateGraphicsPipelines(m_device->device(), pipeline_cache, 1, &create_info, nullptr, &pipeline);
9007 m_errorMonitor->VerifyFound();
9008 }
9009
9010 vkDestroyPipelineCache(m_device->device(), pipeline_cache, nullptr);
9011 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
9012}
9013
Jeremy Hayes091e1ab2017-05-04 18:10:28 -06009014TEST_F(VkLayerTest, VALIDATION_ERROR_01410) {
9015 TEST_DESCRIPTION("Test VALIDATION_ERROR_01410: location must be less than VkPhysicalDeviceLimits::maxVertexInputAttributes");
9016
9017 ASSERT_NO_FATAL_FAILURE(Init());
9018 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9019
9020 VkPipelineCache pipeline_cache;
9021 {
9022 VkPipelineCacheCreateInfo create_info{};
9023 create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
9024
9025 VkResult err = vkCreatePipelineCache(m_device->device(), &create_info, nullptr, &pipeline_cache);
9026 ASSERT_VK_SUCCESS(err);
9027 }
9028
9029 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9030 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
9031
9032 VkPipelineShaderStageCreateInfo stages[2]{{}};
9033 stages[0] = vs.GetStageCreateInfo();
9034 stages[1] = fs.GetStageCreateInfo();
9035
9036 // Test when location is greater than or equal to VkPhysicalDeviceLimits::maxVertexInputAttributes.
9037 VkVertexInputAttributeDescription vertex_input_attribute_description{};
9038 vertex_input_attribute_description.location = m_device->props.limits.maxVertexInputAttributes;
9039
9040 VkPipelineVertexInputStateCreateInfo vertex_input_state{};
9041 vertex_input_state.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
9042 vertex_input_state.pNext = nullptr;
9043 vertex_input_state.vertexBindingDescriptionCount = 0;
9044 vertex_input_state.pVertexBindingDescriptions = nullptr;
9045 vertex_input_state.vertexAttributeDescriptionCount = 1;
9046 vertex_input_state.pVertexAttributeDescriptions = &vertex_input_attribute_description;
9047
9048 VkPipelineInputAssemblyStateCreateInfo input_assembly_state{};
9049 input_assembly_state.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
9050 input_assembly_state.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
9051
9052 VkViewport viewport{};
9053 VkPipelineViewportStateCreateInfo viewport_state{};
9054 viewport_state.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
9055 viewport_state.scissorCount = 1;
9056 viewport_state.viewportCount = 1;
9057 viewport_state.pViewports = &viewport;
9058
9059 VkPipelineMultisampleStateCreateInfo multisample_state{};
9060 multisample_state.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
9061 multisample_state.pNext = nullptr;
9062 multisample_state.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
9063 multisample_state.sampleShadingEnable = 0;
9064 multisample_state.minSampleShading = 1.0;
9065 multisample_state.pSampleMask = nullptr;
9066
9067 VkPipelineRasterizationStateCreateInfo rasterization_state{};
9068 rasterization_state.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
9069 rasterization_state.polygonMode = VK_POLYGON_MODE_FILL;
9070 rasterization_state.cullMode = VK_CULL_MODE_BACK_BIT;
9071 rasterization_state.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
9072 rasterization_state.depthClampEnable = VK_FALSE;
9073 rasterization_state.rasterizerDiscardEnable = VK_FALSE;
9074 rasterization_state.depthBiasEnable = VK_FALSE;
9075
9076 VkPipelineLayout pipeline_layout;
9077 {
9078 VkPipelineLayoutCreateInfo create_info{};
9079 create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9080 create_info.setLayoutCount = 0;
9081 create_info.pSetLayouts = nullptr;
9082
9083 VkResult err = vkCreatePipelineLayout(m_device->device(), &create_info, nullptr, &pipeline_layout);
9084 ASSERT_VK_SUCCESS(err);
9085 }
9086
9087 {
9088 VkGraphicsPipelineCreateInfo create_info{};
9089 create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
9090 create_info.stageCount = 2;
9091 create_info.pStages = stages;
9092 create_info.pVertexInputState = &vertex_input_state;
9093 create_info.pInputAssemblyState = &input_assembly_state;
9094 create_info.pViewportState = &viewport_state;
9095 create_info.pMultisampleState = &multisample_state;
9096 create_info.pRasterizationState = &rasterization_state;
9097 create_info.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
9098 create_info.layout = pipeline_layout;
9099 create_info.renderPass = renderPass();
9100
9101 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01410);
9102 VkPipeline pipeline;
9103 vkCreateGraphicsPipelines(m_device->device(), pipeline_cache, 1, &create_info, nullptr, &pipeline);
9104 m_errorMonitor->VerifyFound();
9105 }
9106
9107 vkDestroyPipelineCache(m_device->device(), pipeline_cache, nullptr);
9108 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
9109}
9110
9111TEST_F(VkLayerTest, VALIDATION_ERROR_01411) {
9112 TEST_DESCRIPTION("Test VALIDATION_ERROR_01411: binding must be less than VkPhysicalDeviceLimits::maxVertexInputBindings");
9113
9114 ASSERT_NO_FATAL_FAILURE(Init());
9115 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9116
9117 VkPipelineCache pipeline_cache;
9118 {
9119 VkPipelineCacheCreateInfo create_info{};
9120 create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
9121
9122 VkResult err = vkCreatePipelineCache(m_device->device(), &create_info, nullptr, &pipeline_cache);
9123 ASSERT_VK_SUCCESS(err);
9124 }
9125
9126 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9127 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
9128
9129 VkPipelineShaderStageCreateInfo stages[2]{{}};
9130 stages[0] = vs.GetStageCreateInfo();
9131 stages[1] = fs.GetStageCreateInfo();
9132
9133 // Test when binding is greater than or equal to VkPhysicalDeviceLimits::maxVertexInputBindings.
9134 VkVertexInputAttributeDescription vertex_input_attribute_description{};
9135 vertex_input_attribute_description.binding = m_device->props.limits.maxVertexInputBindings;
9136
9137 VkPipelineVertexInputStateCreateInfo vertex_input_state{};
9138 vertex_input_state.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
9139 vertex_input_state.pNext = nullptr;
9140 vertex_input_state.vertexBindingDescriptionCount = 0;
9141 vertex_input_state.pVertexBindingDescriptions = nullptr;
9142 vertex_input_state.vertexAttributeDescriptionCount = 1;
9143 vertex_input_state.pVertexAttributeDescriptions = &vertex_input_attribute_description;
9144
9145 VkPipelineInputAssemblyStateCreateInfo input_assembly_state{};
9146 input_assembly_state.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
9147 input_assembly_state.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
9148
9149 VkViewport viewport{};
9150 VkPipelineViewportStateCreateInfo viewport_state{};
9151 viewport_state.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
9152 viewport_state.scissorCount = 1;
9153 viewport_state.viewportCount = 1;
9154 viewport_state.pViewports = &viewport;
9155
9156 VkPipelineMultisampleStateCreateInfo multisample_state{};
9157 multisample_state.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
9158 multisample_state.pNext = nullptr;
9159 multisample_state.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
9160 multisample_state.sampleShadingEnable = 0;
9161 multisample_state.minSampleShading = 1.0;
9162 multisample_state.pSampleMask = nullptr;
9163
9164 VkPipelineRasterizationStateCreateInfo rasterization_state{};
9165 rasterization_state.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
9166 rasterization_state.polygonMode = VK_POLYGON_MODE_FILL;
9167 rasterization_state.cullMode = VK_CULL_MODE_BACK_BIT;
9168 rasterization_state.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
9169 rasterization_state.depthClampEnable = VK_FALSE;
9170 rasterization_state.rasterizerDiscardEnable = VK_FALSE;
9171 rasterization_state.depthBiasEnable = VK_FALSE;
9172
9173 VkPipelineLayout pipeline_layout;
9174 {
9175 VkPipelineLayoutCreateInfo create_info{};
9176 create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9177 create_info.setLayoutCount = 0;
9178 create_info.pSetLayouts = nullptr;
9179
9180 VkResult err = vkCreatePipelineLayout(m_device->device(), &create_info, nullptr, &pipeline_layout);
9181 ASSERT_VK_SUCCESS(err);
9182 }
9183
9184 {
9185 VkGraphicsPipelineCreateInfo create_info{};
9186 create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
9187 create_info.stageCount = 2;
9188 create_info.pStages = stages;
9189 create_info.pVertexInputState = &vertex_input_state;
9190 create_info.pInputAssemblyState = &input_assembly_state;
9191 create_info.pViewportState = &viewport_state;
9192 create_info.pMultisampleState = &multisample_state;
9193 create_info.pRasterizationState = &rasterization_state;
9194 create_info.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
9195 create_info.layout = pipeline_layout;
9196 create_info.renderPass = renderPass();
9197
9198 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01411);
9199 VkPipeline pipeline;
9200 vkCreateGraphicsPipelines(m_device->device(), pipeline_cache, 1, &create_info, nullptr, &pipeline);
9201 m_errorMonitor->VerifyFound();
9202 }
9203
9204 vkDestroyPipelineCache(m_device->device(), pipeline_cache, nullptr);
9205 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
9206}
9207
9208TEST_F(VkLayerTest, VALIDATION_ERROR_01412) {
9209 TEST_DESCRIPTION(
9210 "Test VALIDATION_ERROR_01412: offset must be less than or equal to VkPhysicalDeviceLimits::maxVertexInputAttributeOffset");
9211
9212 ASSERT_NO_FATAL_FAILURE(Init());
9213 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9214
9215 VkPipelineCache pipeline_cache;
9216 {
9217 VkPipelineCacheCreateInfo create_info{};
9218 create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
9219
9220 VkResult err = vkCreatePipelineCache(m_device->device(), &create_info, nullptr, &pipeline_cache);
9221 ASSERT_VK_SUCCESS(err);
9222 }
9223
9224 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9225 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
9226
9227 VkPipelineShaderStageCreateInfo stages[2]{{}};
9228 stages[0] = vs.GetStageCreateInfo();
9229 stages[1] = fs.GetStageCreateInfo();
9230
9231 // Test when offset is greater than maximum.
9232 VkVertexInputAttributeDescription vertex_input_attribute_description{};
9233 vertex_input_attribute_description.offset = m_device->props.limits.maxVertexInputAttributeOffset + 1;
9234
9235 VkPipelineVertexInputStateCreateInfo vertex_input_state{};
9236 vertex_input_state.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
9237 vertex_input_state.pNext = nullptr;
9238 vertex_input_state.vertexBindingDescriptionCount = 0;
9239 vertex_input_state.pVertexBindingDescriptions = nullptr;
9240 vertex_input_state.vertexAttributeDescriptionCount = 1;
9241 vertex_input_state.pVertexAttributeDescriptions = &vertex_input_attribute_description;
9242
9243 VkPipelineInputAssemblyStateCreateInfo input_assembly_state{};
9244 input_assembly_state.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
9245 input_assembly_state.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
9246
9247 VkViewport viewport{};
9248 VkPipelineViewportStateCreateInfo viewport_state{};
9249 viewport_state.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
9250 viewport_state.scissorCount = 1;
9251 viewport_state.viewportCount = 1;
9252 viewport_state.pViewports = &viewport;
9253
9254 VkPipelineMultisampleStateCreateInfo multisample_state{};
9255 multisample_state.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
9256 multisample_state.pNext = nullptr;
9257 multisample_state.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
9258 multisample_state.sampleShadingEnable = 0;
9259 multisample_state.minSampleShading = 1.0;
9260 multisample_state.pSampleMask = nullptr;
9261
9262 VkPipelineRasterizationStateCreateInfo rasterization_state{};
9263 rasterization_state.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
9264 rasterization_state.polygonMode = VK_POLYGON_MODE_FILL;
9265 rasterization_state.cullMode = VK_CULL_MODE_BACK_BIT;
9266 rasterization_state.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
9267 rasterization_state.depthClampEnable = VK_FALSE;
9268 rasterization_state.rasterizerDiscardEnable = VK_FALSE;
9269 rasterization_state.depthBiasEnable = VK_FALSE;
9270
9271 VkPipelineLayout pipeline_layout;
9272 {
9273 VkPipelineLayoutCreateInfo create_info{};
9274 create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9275 create_info.setLayoutCount = 0;
9276 create_info.pSetLayouts = nullptr;
9277
9278 VkResult err = vkCreatePipelineLayout(m_device->device(), &create_info, nullptr, &pipeline_layout);
9279 ASSERT_VK_SUCCESS(err);
9280 }
9281
9282 {
9283 VkGraphicsPipelineCreateInfo create_info{};
9284 create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
9285 create_info.stageCount = 2;
9286 create_info.pStages = stages;
9287 create_info.pVertexInputState = &vertex_input_state;
9288 create_info.pInputAssemblyState = &input_assembly_state;
9289 create_info.pViewportState = &viewport_state;
9290 create_info.pMultisampleState = &multisample_state;
9291 create_info.pRasterizationState = &rasterization_state;
9292 create_info.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
9293 create_info.layout = pipeline_layout;
9294 create_info.renderPass = renderPass();
9295
9296 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01412);
9297 VkPipeline pipeline;
9298 vkCreateGraphicsPipelines(m_device->device(), pipeline_cache, 1, &create_info, nullptr, &pipeline);
9299 m_errorMonitor->VerifyFound();
9300 }
9301
9302 vkDestroyPipelineCache(m_device->device(), pipeline_cache, nullptr);
9303 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
9304}
9305
Karl Schultz6addd812016-02-02 17:17:23 -07009306TEST_F(VkLayerTest, NullRenderPass) {
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06009307 // Bind a NULL RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009308 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mike Schuchardt0b1f2f82016-12-28 15:11:20 -07009309 "vkCmdBeginRenderPass: required parameter pRenderPassBegin specified as NULL");
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06009310
Tony Barbour1fa09702017-03-16 12:09:08 -06009311 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06009312 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06009313
Tony Barbour552f6c02016-12-21 14:34:07 -07009314 m_commandBuffer->BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07009315 // Don't care about RenderPass handle b/c error should be flagged before
9316 // that
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009317 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06009318
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009319 m_errorMonitor->VerifyFound();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06009320}
9321
Karl Schultz6addd812016-02-02 17:17:23 -07009322TEST_F(VkLayerTest, RenderPassWithinRenderPass) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009323 // Bind a BeginRenderPass within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009324 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9325 "It is invalid to issue this call inside an active render pass");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009326
Tony Barbour1fa09702017-03-16 12:09:08 -06009327 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009328 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009329
Tony Barbour552f6c02016-12-21 14:34:07 -07009330 m_commandBuffer->BeginCommandBuffer();
9331 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Karl Schultz6addd812016-02-02 17:17:23 -07009332 // Just create a dummy Renderpass that's non-NULL so we can get to the
9333 // proper error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009334 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009335
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009336 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009337}
9338
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06009339TEST_F(VkLayerTest, RenderPassClearOpMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009340 TEST_DESCRIPTION(
9341 "Begin a renderPass where clearValueCount is less than"
9342 "the number of renderPass attachments that use loadOp"
9343 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06009344
Tony Barbour1fa09702017-03-16 12:09:08 -06009345 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06009346 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9347
9348 // Create a renderPass with a single attachment that uses loadOp CLEAR
9349 VkAttachmentReference attach = {};
9350 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
9351 VkSubpassDescription subpass = {};
Cort Stratton7547f772017-05-04 15:18:52 -07009352 subpass.colorAttachmentCount = 1;
9353 subpass.pColorAttachments = &attach;
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06009354 VkRenderPassCreateInfo rpci = {};
9355 rpci.subpassCount = 1;
9356 rpci.pSubpasses = &subpass;
9357 rpci.attachmentCount = 1;
9358 VkAttachmentDescription attach_desc = {};
Rene Lindsay4bf0e4c2017-01-31 14:20:34 -07009359 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06009360 // Set loadOp to CLEAR
9361 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
9362 rpci.pAttachments = &attach_desc;
9363 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
9364 VkRenderPass rp;
9365 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
9366
9367 VkCommandBufferInheritanceInfo hinfo = {};
9368 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
9369 hinfo.renderPass = VK_NULL_HANDLE;
9370 hinfo.subpass = 0;
9371 hinfo.framebuffer = VK_NULL_HANDLE;
9372 hinfo.occlusionQueryEnable = VK_FALSE;
9373 hinfo.queryFlags = 0;
9374 hinfo.pipelineStatistics = 0;
9375 VkCommandBufferBeginInfo info = {};
9376 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
9377 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
9378 info.pInheritanceInfo = &hinfo;
9379
9380 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
9381 VkRenderPassBeginInfo rp_begin = {};
9382 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
9383 rp_begin.pNext = NULL;
9384 rp_begin.renderPass = renderPass();
9385 rp_begin.framebuffer = framebuffer();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009386 rp_begin.clearValueCount = 0; // Should be 1
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06009387
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07009388 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00442);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06009389
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009390 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06009391
9392 m_errorMonitor->VerifyFound();
Mark Lobodzinski5c70ebd2016-06-09 13:45:00 -06009393
9394 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06009395}
9396
Cody Northrop3bb4d962016-05-09 16:15:57 -06009397TEST_F(VkLayerTest, EndCommandBufferWithinRenderPass) {
Cody Northrop3bb4d962016-05-09 16:15:57 -06009398 TEST_DESCRIPTION("End a command buffer with an active render pass");
9399
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009400 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9401 "It is invalid to issue this call inside an active render pass");
Cody Northrop3bb4d962016-05-09 16:15:57 -06009402
Tony Barbour1fa09702017-03-16 12:09:08 -06009403 ASSERT_NO_FATAL_FAILURE(Init());
Cody Northrop3bb4d962016-05-09 16:15:57 -06009404 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9405
Tony Barbour552f6c02016-12-21 14:34:07 -07009406 m_commandBuffer->BeginCommandBuffer();
9407 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
9408 vkEndCommandBuffer(m_commandBuffer->handle());
Cody Northrop3bb4d962016-05-09 16:15:57 -06009409
9410 m_errorMonitor->VerifyFound();
9411
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009412 // TODO: Add test for VK_COMMAND_BUFFER_LEVEL_SECONDARY
9413 // TODO: Add test for VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT
Cody Northrop3bb4d962016-05-09 16:15:57 -06009414}
9415
Karl Schultz6addd812016-02-02 17:17:23 -07009416TEST_F(VkLayerTest, FillBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009417 // Call CmdFillBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009418 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9419 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009420
Tony Barbour1fa09702017-03-16 12:09:08 -06009421 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009422 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009423
Tony Barbour552f6c02016-12-21 14:34:07 -07009424 m_commandBuffer->BeginCommandBuffer();
9425 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009426
9427 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009428 vk_testing::Buffer dstBuffer;
9429 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009430
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009431 m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009432
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009433 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009434}
9435
Karl Schultz6addd812016-02-02 17:17:23 -07009436TEST_F(VkLayerTest, UpdateBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009437 // Call CmdUpdateBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009438 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9439 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009440
Tony Barbour1fa09702017-03-16 12:09:08 -06009441 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009442 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009443
Tony Barbour552f6c02016-12-21 14:34:07 -07009444 m_commandBuffer->BeginCommandBuffer();
9445 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009446
9447 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009448 vk_testing::Buffer dstBuffer;
9449 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009450
Karl Schultz6addd812016-02-02 17:17:23 -07009451 VkDeviceSize dstOffset = 0;
Rene Lindsay32d26902017-02-02 16:49:24 -07009452 uint32_t Data[] = {1, 2, 3, 4, 5, 6, 7, 8};
9453 VkDeviceSize dataSize = sizeof(Data) / sizeof(uint32_t);
9454 vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(), dstOffset, dataSize, &Data);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009455
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009456 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009457}
9458
Petr Kraus4d718682017-05-18 03:38:41 +02009459TEST_F(VkLayerTest, ClearColorImageWithBadRange) {
9460 TEST_DESCRIPTION("Record clear color with an invalid VkImageSubresourceRange");
9461
9462 ASSERT_NO_FATAL_FAILURE(Init());
9463 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9464
9465 VkImageObj image(m_device);
9466 image.Init(32, 32, 1, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_OPTIMAL);
9467 ASSERT_TRUE(image.create_info().arrayLayers == 1);
9468 ASSERT_TRUE(image.initialized());
9469 image.SetLayout(VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
9470
9471 const VkClearColorValue clear_color = {{0.0f, 0.0f, 0.0f, 1.0f}};
9472
9473 m_commandBuffer->BeginCommandBuffer();
9474 const auto cb_handle = m_commandBuffer->GetBufferHandle();
9475
9476 // Try levelCount = 0
9477 {
9478 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
9479 const VkImageSubresourceRange range = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 0, 1};
9480 vkCmdClearColorImage(cb_handle, image.handle(), image.Layout(), &clear_color, 1, &range);
9481 m_errorMonitor->VerifyFound();
9482 }
9483
9484 // Try baseLevel + levelCount > image.mipLevels
9485 {
9486 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
9487 const VkImageSubresourceRange range = {VK_IMAGE_ASPECT_COLOR_BIT, 1, 1, 0, 1};
9488 vkCmdClearColorImage(cb_handle, image.handle(), image.Layout(), &clear_color, 1, &range);
9489 m_errorMonitor->VerifyFound();
9490 }
9491
9492 // Try baseLevel >= image.mipLevels with VK_REMAINING_MIP_LEVELS
9493 {
9494 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9495 "vkCmdClearColorImage: pRanges[0].baseMipLevel (= 1) is greater or equal to the mip "
9496 "level count of the image (i.e. greater or equal to 1).");
9497 const VkImageSubresourceRange range = {VK_IMAGE_ASPECT_COLOR_BIT, 1, VK_REMAINING_MIP_LEVELS, 0, 1};
9498 vkCmdClearColorImage(cb_handle, image.handle(), image.Layout(), &clear_color, 1, &range);
9499 m_errorMonitor->VerifyFound();
9500 }
9501
9502 // Try layerCount = 0
9503 {
9504 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02931);
9505 const VkImageSubresourceRange range = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 0};
9506 vkCmdClearColorImage(cb_handle, image.handle(), image.Layout(), &clear_color, 1, &range);
9507 m_errorMonitor->VerifyFound();
9508 }
9509
9510 // Try baseLayer + layerCount > image.arrayLayers
9511 {
9512 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02931);
9513 const VkImageSubresourceRange range = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 1, 1};
9514 vkCmdClearColorImage(cb_handle, image.handle(), image.Layout(), &clear_color, 1, &range);
9515 m_errorMonitor->VerifyFound();
9516 }
9517
9518 // Try baseLevel >= image.mipLevels with VK_REMAINING_ARRAY_LAYERS
9519 {
9520 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9521 "vkCmdClearColorImage: pRanges[0].baseArrayLayer (= 1) is greater or equal to the "
9522 "arrayLayers of the image when it was created (i.e. greater or equal to 1).");
9523 const VkImageSubresourceRange range = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 1, VK_REMAINING_ARRAY_LAYERS};
9524 vkCmdClearColorImage(cb_handle, image.handle(), image.Layout(), &clear_color, 1, &range);
9525 m_errorMonitor->VerifyFound();
9526 }
9527}
9528
9529TEST_F(VkLayerTest, ClearDepthStencilWithBadRange) {
9530 TEST_DESCRIPTION("Record clear depth with an invalid VkImageSubresourceRange");
9531
9532 ASSERT_NO_FATAL_FAILURE(Init());
9533 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9534
9535 const auto depth_format = FindSupportedDepthStencilFormat(gpu());
9536 if (!depth_format) {
9537 printf(" No Depth + Stencil format found. Skipped.\n");
9538 return;
9539 }
9540
9541 VkImageObj image(m_device);
9542 image.Init(32, 32, 1, depth_format, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_OPTIMAL);
9543 ASSERT_TRUE(image.create_info().arrayLayers == 1);
9544 ASSERT_TRUE(image.initialized());
9545 const VkImageAspectFlags ds_aspect = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
9546 image.SetLayout(ds_aspect, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
9547
9548 const VkClearDepthStencilValue clear_value = {};
9549
9550 m_commandBuffer->BeginCommandBuffer();
9551 const auto cb_handle = m_commandBuffer->GetBufferHandle();
9552
9553 // Try levelCount = 0
9554 {
9555 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
9556 const VkImageSubresourceRange range = {ds_aspect, 0, 0, 0, 1};
9557 vkCmdClearDepthStencilImage(cb_handle, image.handle(), image.Layout(), &clear_value, 1, &range);
9558 m_errorMonitor->VerifyFound();
9559 }
9560
9561 // Try baseLevel + levelCount > image.mipLevels
9562 {
9563 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
9564 const VkImageSubresourceRange range = {ds_aspect, 1, 1, 0, 1};
9565 vkCmdClearDepthStencilImage(cb_handle, image.handle(), image.Layout(), &clear_value, 1, &range);
9566 m_errorMonitor->VerifyFound();
9567 }
9568
9569 // Try baseLevel >= image.mipLevels with VK_REMAINING_MIP_LEVELS
9570 {
9571 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9572 "vkCmdClearDepthStencilImage: pRanges[0].baseMipLevel (= 1) is greater or equal to "
9573 "the mip level count of the image (i.e. greater or equal to 1).");
9574 const VkImageSubresourceRange range = {ds_aspect, 1, VK_REMAINING_MIP_LEVELS, 0, 1};
9575 vkCmdClearDepthStencilImage(cb_handle, image.handle(), image.Layout(), &clear_value, 1, &range);
9576 m_errorMonitor->VerifyFound();
9577 }
9578
9579 // Try layerCount = 0
9580 {
9581 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02931);
9582 const VkImageSubresourceRange range = {ds_aspect, 0, 1, 0, 0};
9583 vkCmdClearDepthStencilImage(cb_handle, image.handle(), image.Layout(), &clear_value, 1, &range);
9584 m_errorMonitor->VerifyFound();
9585 }
9586
9587 // Try baseLayer + layerCount > image.arrayLayers
9588 {
9589 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02931);
9590 const VkImageSubresourceRange range = {ds_aspect, 0, 1, 1, 1};
9591 vkCmdClearDepthStencilImage(cb_handle, image.handle(), image.Layout(), &clear_value, 1, &range);
9592 m_errorMonitor->VerifyFound();
9593 }
9594
9595 // Try baseLevel >= image.mipLevels with VK_REMAINING_ARRAY_LAYERS
9596 {
9597 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9598 "vkCmdClearDepthStencilImage: pRanges[0].baseArrayLayer (= 1) is greater or equal to "
9599 "the arrayLayers of the image when it was created (i.e. greater or equal to 1).");
9600 const VkImageSubresourceRange range = {ds_aspect, 0, 1, 1, VK_REMAINING_ARRAY_LAYERS};
9601 vkCmdClearDepthStencilImage(cb_handle, image.handle(), image.Layout(), &clear_value, 1, &range);
9602 m_errorMonitor->VerifyFound();
9603 }
9604}
9605
Karl Schultz6addd812016-02-02 17:17:23 -07009606TEST_F(VkLayerTest, ClearColorImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009607 // Call CmdClearColorImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009608 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9609 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009610
Tony Barbour1fa09702017-03-16 12:09:08 -06009611 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009612 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009613
Tony Barbour552f6c02016-12-21 14:34:07 -07009614 m_commandBuffer->BeginCommandBuffer();
9615 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009616
Michael Lentine0a369f62016-02-03 16:51:46 -06009617 VkClearColorValue clear_color;
9618 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
Karl Schultz6addd812016-02-02 17:17:23 -07009619 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
9620 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
9621 const int32_t tex_width = 32;
9622 const int32_t tex_height = 32;
9623 VkImageCreateInfo image_create_info = {};
9624 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
9625 image_create_info.pNext = NULL;
9626 image_create_info.imageType = VK_IMAGE_TYPE_2D;
9627 image_create_info.format = tex_format;
9628 image_create_info.extent.width = tex_width;
9629 image_create_info.extent.height = tex_height;
9630 image_create_info.extent.depth = 1;
9631 image_create_info.mipLevels = 1;
9632 image_create_info.arrayLayers = 1;
9633 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
9634 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
Jeremy Hayesa3d5c7b2017-03-07 16:01:52 -07009635 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009636
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009637 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009638 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009639
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009640 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009641
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009642 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009643
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009644 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009645}
9646
Karl Schultz6addd812016-02-02 17:17:23 -07009647TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009648 // Call CmdClearDepthStencilImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009649 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9650 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009651
Tony Barbour1fa09702017-03-16 12:09:08 -06009652 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009653 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009654
Dave Houlton1d2022c2017-03-29 11:43:58 -06009655 auto depth_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbourf887b162017-03-09 10:06:46 -07009656 if (!depth_format) {
9657 printf(" No Depth + Stencil format found. Skipped.\n");
9658 return;
9659 }
9660
Tony Barbour552f6c02016-12-21 14:34:07 -07009661 m_commandBuffer->BeginCommandBuffer();
9662 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009663
9664 VkClearDepthStencilValue clear_value = {0};
Dustin Gravesa2e5c942016-02-11 18:28:06 -07009665 VkMemoryPropertyFlags reqs = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07009666 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
9667 image_create_info.imageType = VK_IMAGE_TYPE_2D;
Tony Barbourf887b162017-03-09 10:06:46 -07009668 image_create_info.format = depth_format;
Karl Schultz6addd812016-02-02 17:17:23 -07009669 image_create_info.extent.width = 64;
9670 image_create_info.extent.height = 64;
9671 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
9672 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009673
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009674 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009675 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009676
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009677 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009678
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07009679 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_value, 1,
9680 &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009681
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009682 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009683}
9684
Karl Schultz6addd812016-02-02 17:17:23 -07009685TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass) {
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06009686 // Call CmdClearAttachmentss outside of an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07009687 VkResult err;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009688
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009689 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9690 "vkCmdClearAttachments(): This call "
9691 "must be issued inside an active "
9692 "render pass");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009693
Tony Barbour1fa09702017-03-16 12:09:08 -06009694 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009695 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009696
9697 // Start no RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009698 err = m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009699 ASSERT_VK_SUCCESS(err);
9700
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06009701 VkClearAttachment color_attachment;
9702 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9703 color_attachment.clearValue.color.float32[0] = 0;
9704 color_attachment.clearValue.color.float32[1] = 0;
9705 color_attachment.clearValue.color.float32[2] = 0;
9706 color_attachment.clearValue.color.float32[3] = 0;
9707 color_attachment.colorAttachment = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07009708 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009709 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009710
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009711 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009712}
9713
Chris Forbes3b97e932016-09-07 11:29:24 +12009714TEST_F(VkLayerTest, RenderPassExcessiveNextSubpass) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009715 TEST_DESCRIPTION(
9716 "Test that an error is produced when CmdNextSubpass is "
9717 "called too many times in a renderpass instance");
Chris Forbes3b97e932016-09-07 11:29:24 +12009718
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009719 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9720 "vkCmdNextSubpass(): Attempted to advance "
9721 "beyond final subpass");
Chris Forbes3b97e932016-09-07 11:29:24 +12009722
Tony Barbour1fa09702017-03-16 12:09:08 -06009723 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes3b97e932016-09-07 11:29:24 +12009724 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9725
Tony Barbour552f6c02016-12-21 14:34:07 -07009726 m_commandBuffer->BeginCommandBuffer();
9727 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes3b97e932016-09-07 11:29:24 +12009728
9729 // error here.
9730 vkCmdNextSubpass(m_commandBuffer->GetBufferHandle(), VK_SUBPASS_CONTENTS_INLINE);
9731 m_errorMonitor->VerifyFound();
9732
Tony Barbour552f6c02016-12-21 14:34:07 -07009733 m_commandBuffer->EndRenderPass();
9734 m_commandBuffer->EndCommandBuffer();
Chris Forbes3b97e932016-09-07 11:29:24 +12009735}
9736
Chris Forbes6d624702016-09-07 13:57:05 +12009737TEST_F(VkLayerTest, RenderPassEndedBeforeFinalSubpass) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009738 TEST_DESCRIPTION(
9739 "Test that an error is produced when CmdEndRenderPass is "
9740 "called before the final subpass has been reached");
Chris Forbes6d624702016-09-07 13:57:05 +12009741
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009742 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9743 "vkCmdEndRenderPass(): Called before reaching "
9744 "final subpass");
Chris Forbes6d624702016-09-07 13:57:05 +12009745
Tony Barbour1fa09702017-03-16 12:09:08 -06009746 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009747 VkSubpassDescription sd[2] = {{0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr},
9748 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr}};
Chris Forbes6d624702016-09-07 13:57:05 +12009749
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009750 VkRenderPassCreateInfo rcpi = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 2, sd, 0, nullptr};
Chris Forbes6d624702016-09-07 13:57:05 +12009751
9752 VkRenderPass rp;
9753 VkResult err = vkCreateRenderPass(m_device->device(), &rcpi, nullptr, &rp);
9754 ASSERT_VK_SUCCESS(err);
9755
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009756 VkFramebufferCreateInfo fbci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 16, 16, 1};
Chris Forbes6d624702016-09-07 13:57:05 +12009757
9758 VkFramebuffer fb;
9759 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
9760 ASSERT_VK_SUCCESS(err);
9761
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009762 m_commandBuffer->BeginCommandBuffer(); // no implicit RP begin
Chris Forbes6d624702016-09-07 13:57:05 +12009763
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009764 VkRenderPassBeginInfo rpbi = {VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb, {{0, 0}, {16, 16}}, 0, nullptr};
Chris Forbes6d624702016-09-07 13:57:05 +12009765
9766 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
9767
9768 // Error here.
9769 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
9770 m_errorMonitor->VerifyFound();
9771
9772 // Clean up.
9773 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
9774 vkDestroyRenderPass(m_device->device(), rp, nullptr);
9775}
9776
Karl Schultz9e66a292016-04-21 15:57:51 -06009777TEST_F(VkLayerTest, BufferMemoryBarrierNoBuffer) {
9778 // Try to add a buffer memory barrier with no buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009779 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9780 "required parameter pBufferMemoryBarriers[0].buffer specified as VK_NULL_HANDLE");
Karl Schultz9e66a292016-04-21 15:57:51 -06009781
Tony Barbour1fa09702017-03-16 12:09:08 -06009782 ASSERT_NO_FATAL_FAILURE(Init());
Tony Barbour552f6c02016-12-21 14:34:07 -07009783 m_commandBuffer->BeginCommandBuffer();
Karl Schultz9e66a292016-04-21 15:57:51 -06009784
9785 VkBufferMemoryBarrier buf_barrier = {};
9786 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
9787 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
9788 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
9789 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
9790 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
9791 buf_barrier.buffer = VK_NULL_HANDLE;
9792 buf_barrier.offset = 0;
9793 buf_barrier.size = VK_WHOLE_SIZE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009794 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9795 nullptr, 1, &buf_barrier, 0, nullptr);
Karl Schultz9e66a292016-04-21 15:57:51 -06009796
9797 m_errorMonitor->VerifyFound();
9798}
9799
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009800TEST_F(VkLayerTest, InvalidBarriers) {
9801 TEST_DESCRIPTION("A variety of ways to get VK_INVALID_BARRIER ");
9802
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009803 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Barriers cannot be set during subpass");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009804
Tony Barbour1fa09702017-03-16 12:09:08 -06009805 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -06009806 auto depth_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbourf887b162017-03-09 10:06:46 -07009807 if (!depth_format) {
9808 printf(" No Depth + Stencil format found. Skipped.\n");
9809 return;
9810 }
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009811 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9812
9813 VkMemoryBarrier mem_barrier = {};
9814 mem_barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER;
9815 mem_barrier.pNext = NULL;
9816 mem_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
9817 mem_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
Tony Barbour552f6c02016-12-21 14:34:07 -07009818 m_commandBuffer->BeginCommandBuffer();
9819 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009820 // BeginCommandBuffer() starts a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009821 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 1,
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009822 &mem_barrier, 0, nullptr, 0, nullptr);
9823 m_errorMonitor->VerifyFound();
9824
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009825 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image Layout cannot be transitioned to UNDEFINED");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009826 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06009827 image.Init(128, 128, 1, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009828 ASSERT_TRUE(image.initialized());
9829 VkImageMemoryBarrier img_barrier = {};
9830 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
9831 img_barrier.pNext = NULL;
9832 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
9833 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
Mark Lobodzinski95512b72017-05-10 12:21:30 -06009834 img_barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009835 // New layout can't be UNDEFINED
9836 img_barrier.newLayout = VK_IMAGE_LAYOUT_UNDEFINED;
9837 img_barrier.image = image.handle();
9838 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
9839 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
9840 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9841 img_barrier.subresourceRange.baseArrayLayer = 0;
9842 img_barrier.subresourceRange.baseMipLevel = 0;
9843 img_barrier.subresourceRange.layerCount = 1;
9844 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009845 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9846 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009847 m_errorMonitor->VerifyFound();
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009848
Mark Lobodzinski95512b72017-05-10 12:21:30 -06009849 // Transition image to color attachment optimal
9850 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
9851 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
9852 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9853 nullptr, 0, nullptr, 1, &img_barrier);
9854 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinski95512b72017-05-10 12:21:30 -06009855
Mark Lobodzinski45daf6e2017-05-10 13:19:02 -06009856 // Try to change layout in a renderpass
9857 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02080);
9858 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9859 nullptr, 0, nullptr, 1, &img_barrier);
9860 m_errorMonitor->VerifyFound();
9861
9862 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
Petr Kraus4d718682017-05-18 03:38:41 +02009863 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02931);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009864 // baseArrayLayer + layerCount must be <= image's arrayLayers
9865 img_barrier.subresourceRange.baseArrayLayer = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009866 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9867 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009868 m_errorMonitor->VerifyFound();
9869 img_barrier.subresourceRange.baseArrayLayer = 0;
9870
Petr Kraus4d718682017-05-18 03:38:41 +02009871 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009872 // baseMipLevel + levelCount must be <= image's mipLevels
9873 img_barrier.subresourceRange.baseMipLevel = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009874 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9875 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009876 m_errorMonitor->VerifyFound();
9877 img_barrier.subresourceRange.baseMipLevel = 0;
9878
Mike Weiblen7053aa32017-01-25 15:21:10 -07009879 // levelCount must be non-zero.
9880 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
9881 img_barrier.subresourceRange.levelCount = 0;
9882 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9883 nullptr, 0, nullptr, 1, &img_barrier);
9884 m_errorMonitor->VerifyFound();
9885 img_barrier.subresourceRange.levelCount = 1;
9886
9887 // layerCount must be non-zero.
Petr Kraus4d718682017-05-18 03:38:41 +02009888 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02931);
Mike Weiblen7053aa32017-01-25 15:21:10 -07009889 img_barrier.subresourceRange.layerCount = 0;
9890 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9891 nullptr, 0, nullptr, 1, &img_barrier);
9892 m_errorMonitor->VerifyFound();
9893 img_barrier.subresourceRange.layerCount = 1;
9894
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009895 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Buffer Barriers cannot be used during a render pass");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009896 vk_testing::Buffer buffer;
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07009897 VkMemoryPropertyFlags mem_reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
9898 buffer.init_as_src_and_dst(*m_device, 256, mem_reqs);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009899 VkBufferMemoryBarrier buf_barrier = {};
9900 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
9901 buf_barrier.pNext = NULL;
9902 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
9903 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
9904 buf_barrier.buffer = buffer.handle();
9905 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
9906 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
9907 buf_barrier.offset = 0;
9908 buf_barrier.size = VK_WHOLE_SIZE;
9909 // Can't send buffer barrier during a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009910 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9911 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009912 m_errorMonitor->VerifyFound();
9913 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
9914
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009915 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which is not less than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009916 buf_barrier.offset = 257;
9917 // Offset greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009918 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9919 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009920 m_errorMonitor->VerifyFound();
9921 buf_barrier.offset = 0;
9922
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009923 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "whose sum is greater than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009924 buf_barrier.size = 257;
9925 // Size greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009926 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9927 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009928 m_errorMonitor->VerifyFound();
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009929
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009930 // Now exercise barrier aspect bit errors, first DS
Tobin Ehlis99ab0d22017-04-26 16:53:52 -06009931 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00741);
9932 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00302);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009933 VkDepthStencilObj ds_image(m_device);
Tony Barbourf887b162017-03-09 10:06:46 -07009934 ds_image.Init(m_device, 128, 128, depth_format);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009935 ASSERT_TRUE(ds_image.initialized());
Tobin Ehlis15684a02016-07-21 14:55:26 -06009936 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
9937 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009938 img_barrier.image = ds_image.handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07009939
9940 // Not having DEPTH or STENCIL set is an error
Rene Lindsay4834cba2017-02-02 17:18:56 -07009941 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009942 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9943 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009944 m_errorMonitor->VerifyFound();
Dave Houltonfbf52152017-01-06 12:55:29 -07009945
Tobin Ehlis99ab0d22017-04-26 16:53:52 -06009946 // Having only one of depth or stencil set for DS image is an error
9947 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00302);
9948 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT;
9949 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9950 nullptr, 0, nullptr, 1, &img_barrier);
9951 m_errorMonitor->VerifyFound();
9952
9953 // Having anything other than DEPTH and STENCIL is an error
9954 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00741);
Dave Houltonfbf52152017-01-06 12:55:29 -07009955 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT | VK_IMAGE_ASPECT_COLOR_BIT;
9956 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9957 nullptr, 0, nullptr, 1, &img_barrier);
9958 m_errorMonitor->VerifyFound();
9959
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009960 // Now test depth-only
9961 VkFormatProperties format_props;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009962 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D16_UNORM, &format_props);
9963 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009964 VkDepthStencilObj d_image(m_device);
9965 d_image.Init(m_device, 128, 128, VK_FORMAT_D16_UNORM);
9966 ASSERT_TRUE(d_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009967 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06009968 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009969 img_barrier.image = d_image.handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07009970
9971 // DEPTH bit must be set
9972 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9973 "Depth-only image formats must have the VK_IMAGE_ASPECT_DEPTH_BIT set.");
Rene Lindsay4834cba2017-02-02 17:18:56 -07009974 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Dave Houltonfbf52152017-01-06 12:55:29 -07009975 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
9976 0, nullptr, 0, nullptr, 1, &img_barrier);
9977 m_errorMonitor->VerifyFound();
9978
9979 // No bits other than DEPTH may be set
9980 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9981 "Depth-only image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT set.");
9982 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009983 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
9984 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009985 m_errorMonitor->VerifyFound();
9986 }
Dave Houltonfbf52152017-01-06 12:55:29 -07009987
9988 // Now test stencil-only
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009989 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_S8_UINT, &format_props);
9990 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009991 VkDepthStencilObj s_image(m_device);
9992 s_image.Init(m_device, 128, 128, VK_FORMAT_S8_UINT);
9993 ASSERT_TRUE(s_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009994 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06009995 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009996 img_barrier.image = s_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06009997 // Use of COLOR aspect on depth image is error
Dave Houltonf3229d52017-02-21 15:59:08 -07009998 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9999 "Stencil-only image formats must have the VK_IMAGE_ASPECT_STENCIL_BIT set.");
Tobin Ehlis15684a02016-07-21 14:55:26 -060010000 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010001 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
10002 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010003 m_errorMonitor->VerifyFound();
10004 }
Dave Houltonfbf52152017-01-06 12:55:29 -070010005
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010006 // Finally test color
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010007 VkImageObj c_image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060010008 c_image.Init(128, 128, 1, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010009 ASSERT_TRUE(c_image.initialized());
10010 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10011 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
10012 img_barrier.image = c_image.handle();
Dave Houltonfbf52152017-01-06 12:55:29 -070010013
10014 // COLOR bit must be set
10015 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10016 "Color image formats must have the VK_IMAGE_ASPECT_COLOR_BIT set.");
Rene Lindsay4834cba2017-02-02 17:18:56 -070010017 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Dave Houltonfbf52152017-01-06 12:55:29 -070010018 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10019 nullptr, 0, nullptr, 1, &img_barrier);
10020 m_errorMonitor->VerifyFound();
10021
10022 // No bits other than COLOR may be set
10023 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10024 "Color image formats must have ONLY the VK_IMAGE_ASPECT_COLOR_BIT set.");
10025 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010026 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10027 nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010028 m_errorMonitor->VerifyFound();
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -070010029
Mike Weiblene6e01172017-03-07 22:18:40 -070010030 // A barrier's new and old VkImageLayout must be compatible with an image's VkImageUsageFlags.
10031 {
10032 VkImageObj img_color(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060010033 img_color.Init(128, 128, 1, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL);
Mike Weiblene6e01172017-03-07 22:18:40 -070010034 ASSERT_TRUE(img_color.initialized());
10035
10036 VkImageObj img_ds(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060010037 img_ds.Init(128, 128, 1, depth_format, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL);
Mike Weiblene6e01172017-03-07 22:18:40 -070010038 ASSERT_TRUE(img_ds.initialized());
10039
10040 VkImageObj img_xfer_src(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060010041 img_xfer_src.Init(128, 128, 1, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_OPTIMAL);
Mike Weiblene6e01172017-03-07 22:18:40 -070010042 ASSERT_TRUE(img_xfer_src.initialized());
10043
10044 VkImageObj img_xfer_dst(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060010045 img_xfer_dst.Init(128, 128, 1, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_OPTIMAL);
Mike Weiblene6e01172017-03-07 22:18:40 -070010046 ASSERT_TRUE(img_xfer_dst.initialized());
10047
10048 VkImageObj img_sampled(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060010049 img_sampled.Init(32, 32, 1, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL);
Mike Weiblene6e01172017-03-07 22:18:40 -070010050 ASSERT_TRUE(img_sampled.initialized());
10051
10052 VkImageObj img_input(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060010053 img_input.Init(128, 128, 1, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL);
Mike Weiblene6e01172017-03-07 22:18:40 -070010054 ASSERT_TRUE(img_input.initialized());
10055
10056 const struct {
10057 VkImageObj &image_obj;
10058 VkImageLayout bad_layout;
10059 UNIQUE_VALIDATION_ERROR_CODE msg_code;
10060 } bad_buffer_layouts[] = {
10061 // clang-format off
10062 // images _without_ VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT
10063 {img_ds, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VALIDATION_ERROR_00303},
10064 {img_xfer_src, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VALIDATION_ERROR_00303},
10065 {img_xfer_dst, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VALIDATION_ERROR_00303},
10066 {img_sampled, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VALIDATION_ERROR_00303},
10067 {img_input, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VALIDATION_ERROR_00303},
10068 // images _without_ VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT
10069 {img_color, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, VALIDATION_ERROR_00304},
10070 {img_xfer_src, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, VALIDATION_ERROR_00304},
10071 {img_xfer_dst, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, VALIDATION_ERROR_00304},
10072 {img_sampled, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, VALIDATION_ERROR_00304},
10073 {img_input, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, VALIDATION_ERROR_00304},
10074 {img_color, VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL, VALIDATION_ERROR_00305},
10075 {img_xfer_src, VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL, VALIDATION_ERROR_00305},
10076 {img_xfer_dst, VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL, VALIDATION_ERROR_00305},
10077 {img_sampled, VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL, VALIDATION_ERROR_00305},
10078 {img_input, VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL, VALIDATION_ERROR_00305},
10079 // images _without_ VK_IMAGE_USAGE_SAMPLED_BIT or VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT
10080 {img_color, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VALIDATION_ERROR_00306},
10081 {img_ds, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VALIDATION_ERROR_00306},
10082 {img_xfer_src, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VALIDATION_ERROR_00306},
10083 {img_xfer_dst, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VALIDATION_ERROR_00306},
10084 // images _without_ VK_IMAGE_USAGE_TRANSFER_SRC_BIT
10085 {img_color, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VALIDATION_ERROR_00307},
10086 {img_ds, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VALIDATION_ERROR_00307},
10087 {img_xfer_dst, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VALIDATION_ERROR_00307},
10088 {img_sampled, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VALIDATION_ERROR_00307},
10089 {img_input, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VALIDATION_ERROR_00307},
10090 // images _without_ VK_IMAGE_USAGE_TRANSFER_DST_BIT
10091 {img_color, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VALIDATION_ERROR_00308},
10092 {img_ds, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VALIDATION_ERROR_00308},
10093 {img_xfer_src, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VALIDATION_ERROR_00308},
10094 {img_sampled, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VALIDATION_ERROR_00308},
10095 {img_input, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VALIDATION_ERROR_00308},
10096 // clang-format on
10097 };
10098 const uint32_t layout_count = sizeof(bad_buffer_layouts) / sizeof(bad_buffer_layouts[0]);
10099
10100 for (uint32_t i = 0; i < layout_count; ++i) {
10101 img_barrier.image = bad_buffer_layouts[i].image_obj.handle();
10102 const VkImageUsageFlags usage = bad_buffer_layouts[i].image_obj.usage();
10103 img_barrier.subresourceRange.aspectMask = (usage == VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT)
10104 ? (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)
10105 : VK_IMAGE_ASPECT_COLOR_BIT;
10106
10107 img_barrier.oldLayout = bad_buffer_layouts[i].bad_layout;
10108 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
10109 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_buffer_layouts[i].msg_code);
10110 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT,
10111 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0, nullptr, 1, &img_barrier);
10112 m_errorMonitor->VerifyFound();
10113
10114 img_barrier.oldLayout = VK_IMAGE_LAYOUT_GENERAL;
10115 img_barrier.newLayout = bad_buffer_layouts[i].bad_layout;
10116 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_buffer_layouts[i].msg_code);
10117 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT,
10118 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0, nullptr, 1, &img_barrier);
10119 m_errorMonitor->VerifyFound();
10120 }
10121
10122 img_barrier.oldLayout = VK_IMAGE_LAYOUT_GENERAL;
10123 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
10124 }
10125
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -070010126 // Attempt to mismatch barriers/waitEvents calls with incompatible queues
10127
10128 // Create command pool with incompatible queueflags
10129 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
Mike Schuchardt06304c22017-03-01 17:09:09 -070010130 uint32_t queue_family_index = m_device->QueueFamilyWithoutCapabilities(VK_QUEUE_COMPUTE_BIT);
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -070010131 if (queue_family_index == UINT32_MAX) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070010132 printf(" No non-compute queue found; skipped.\n");
Mike Weiblene6e01172017-03-07 22:18:40 -070010133 return; // NOTE: this exits the test function!
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -070010134 }
10135 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02513);
10136
10137 VkCommandPool command_pool;
10138 VkCommandPoolCreateInfo pool_create_info{};
10139 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
10140 pool_create_info.queueFamilyIndex = queue_family_index;
10141 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
10142 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
10143
10144 // Allocate a command buffer
10145 VkCommandBuffer bad_command_buffer;
10146 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
10147 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
10148 command_buffer_allocate_info.commandPool = command_pool;
10149 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
10150 command_buffer_allocate_info.commandBufferCount = 1;
10151 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &bad_command_buffer));
10152
10153 VkCommandBufferBeginInfo cbbi = {};
10154 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
10155 vkBeginCommandBuffer(bad_command_buffer, &cbbi);
10156 buf_barrier.offset = 0;
10157 buf_barrier.size = VK_WHOLE_SIZE;
10158 vkCmdPipelineBarrier(bad_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1,
10159 &buf_barrier, 0, nullptr);
10160 m_errorMonitor->VerifyFound();
10161
10162 if ((queue_props[queue_family_index].queueFlags & VK_QUEUE_GRAPHICS_BIT) == 0) {
10163 vkEndCommandBuffer(bad_command_buffer);
10164 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070010165 printf(" The non-compute queue does not support graphics; skipped.\n");
Mike Weiblene6e01172017-03-07 22:18:40 -070010166 return; // NOTE: this exits the test function!
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -070010167 }
10168 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02510);
10169 VkEvent event;
10170 VkEventCreateInfo event_create_info{};
10171 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
10172 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
10173 vkCmdWaitEvents(bad_command_buffer, 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, nullptr, 0,
10174 nullptr, 0, nullptr);
10175 m_errorMonitor->VerifyFound();
10176
10177 vkEndCommandBuffer(bad_command_buffer);
10178 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010179}
10180
Chris Forbes50223732017-05-01 09:43:35 -070010181TEST_F(VkPositiveLayerTest, LayoutFromPresentWithoutAccessMemoryRead) {
10182 // Transition an image away from PRESENT_SRC_KHR without ACCESS_MEMORY_READ
10183 // in srcAccessMask.
Tony Barbour18ba25c2016-09-29 13:42:40 -060010184
Chris Forbes50223732017-05-01 09:43:35 -070010185 // The required behavior here was a bit unclear in earlier versions of the
10186 // spec, but there is no memory dependency required here, so this should
10187 // work without warnings.
10188
10189 m_errorMonitor->ExpectSuccess();
Tony Barbour1fa09702017-03-16 12:09:08 -060010190 ASSERT_NO_FATAL_FAILURE(Init());
Tony Barbour18ba25c2016-09-29 13:42:40 -060010191 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060010192 image.Init(128, 128, 1, VK_FORMAT_B8G8R8A8_UNORM, (VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT),
Mike Weiblen62d08a32017-03-07 22:18:27 -070010193 VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbour18ba25c2016-09-29 13:42:40 -060010194 ASSERT_TRUE(image.initialized());
10195
10196 VkImageMemoryBarrier barrier = {};
10197 VkImageSubresourceRange range;
10198 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
Tony Barbour18ba25c2016-09-29 13:42:40 -060010199 barrier.srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
Chris Forbes50223732017-05-01 09:43:35 -070010200 barrier.dstAccessMask = 0;
Tony Barbour18ba25c2016-09-29 13:42:40 -060010201 barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10202 barrier.newLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
10203 barrier.image = image.handle();
10204 range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10205 range.baseMipLevel = 0;
10206 range.levelCount = 1;
10207 range.baseArrayLayer = 0;
10208 range.layerCount = 1;
10209 barrier.subresourceRange = range;
10210 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
10211 cmdbuf.BeginCommandBuffer();
10212 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
10213 &barrier);
10214 barrier.oldLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
10215 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
10216 barrier.srcAccessMask = 0;
10217 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
10218 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
10219 &barrier);
10220
Chris Forbes50223732017-05-01 09:43:35 -070010221 m_errorMonitor->VerifyNotFound();
Tony Barbour18ba25c2016-09-29 13:42:40 -060010222}
10223
Karl Schultz6addd812016-02-02 17:17:23 -070010224TEST_F(VkLayerTest, IdxBufferAlignmentError) {
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010225 // Bind a BeginRenderPass within an active RenderPass
Tony Barbour1fa09702017-03-16 12:09:08 -060010226 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010227 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010228
Jeremy Hayes483d95d2017-03-08 11:03:01 -070010229 uint32_t const indices[] = {0};
10230 VkBufferCreateInfo buf_info = {};
10231 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
10232 buf_info.size = 1024;
10233 buf_info.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
10234 buf_info.queueFamilyIndexCount = 1;
10235 buf_info.pQueueFamilyIndices = indices;
10236
10237 VkBuffer buffer;
10238 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
10239 ASSERT_VK_SUCCESS(err);
10240
10241 VkMemoryRequirements requirements;
10242 vkGetBufferMemoryRequirements(m_device->device(), buffer, &requirements);
10243
10244 VkMemoryAllocateInfo alloc_info{};
10245 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10246 alloc_info.pNext = NULL;
10247 alloc_info.memoryTypeIndex = 0;
10248 alloc_info.allocationSize = requirements.size;
10249 bool pass = m_device->phy().set_memory_type(requirements.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
10250 ASSERT_TRUE(pass);
10251
10252 VkDeviceMemory memory;
10253 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &memory);
10254 ASSERT_VK_SUCCESS(err);
10255
10256 err = vkBindBufferMemory(m_device->device(), buffer, memory, 0);
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010257 ASSERT_VK_SUCCESS(err);
10258
Tony Barbour552f6c02016-12-21 14:34:07 -070010259 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010260 ASSERT_VK_SUCCESS(err);
Jeremy Hayes483d95d2017-03-08 11:03:01 -070010261
Karl Schultz6addd812016-02-02 17:17:23 -070010262 // vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
10263 // VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010264 // Should error before calling to driver so don't care about actual data
Jeremy Hayes483d95d2017-03-08 11:03:01 -070010265 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdBindIndexBuffer() offset (0x7) does not fall on ");
10266 vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), buffer, 7, VK_INDEX_TYPE_UINT16);
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010267 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010268
Jeremy Hayes483d95d2017-03-08 11:03:01 -070010269 vkFreeMemory(m_device->device(), memory, NULL);
10270 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010271}
10272
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -070010273TEST_F(VkLayerTest, InvalidQueueFamilyIndex) {
10274 // Create an out-of-range queueFamilyIndex
Tony Barbour1fa09702017-03-16 12:09:08 -060010275 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -070010276 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10277 VkBufferCreateInfo buffCI = {};
10278 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
10279 buffCI.size = 1024;
Mark Lobodzinski4761d212017-02-28 13:12:44 -070010280 buffCI.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
Jeremy Hayes8a43a0d2017-03-09 11:27:52 -070010281 buffCI.queueFamilyIndexCount = 2;
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -070010282 // Introduce failure by specifying invalid queue_family_index
Mark Lobodzinski4761d212017-02-28 13:12:44 -070010283 uint32_t qfi[2];
10284 qfi[0] = 777;
Jeremy Hayes8a43a0d2017-03-09 11:27:52 -070010285 qfi[1] = 0;
Mark Lobodzinski4761d212017-02-28 13:12:44 -070010286
10287 buffCI.pQueueFamilyIndices = qfi;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010288 buffCI.sharingMode = VK_SHARING_MODE_CONCURRENT; // qfi only matters in CONCURRENT mode
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -070010289
10290 VkBuffer ib;
Jeremy Hayes8a43a0d2017-03-09 11:27:52 -070010291 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Petr Kraus97291752017-05-11 01:05:16 +020010292 "vkCreateBuffer: pCreateInfo->pQueueFamilyIndices[0] (= 777) is not one of the queue "
10293 "families given via VkDeviceQueueCreateInfo structures when the device was created.");
Mark Lobodzinski1f9ebb72017-05-11 15:25:51 -060010294 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010295 m_errorMonitor->VerifyFound();
Mark Lobodzinski4761d212017-02-28 13:12:44 -070010296
10297 if (m_device->queue_props.size() > 2) {
Tony Barbour75db7402017-03-09 14:51:36 -070010298 VkBuffer ib2;
Mark Lobodzinski4761d212017-02-28 13:12:44 -070010299 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which was not created allowing concurrent");
10300
10301 // Create buffer shared to queue families 1 and 2, but submitted on queue family 0
10302 buffCI.queueFamilyIndexCount = 2;
10303 qfi[0] = 1;
10304 qfi[1] = 2;
Tony Barbour75db7402017-03-09 14:51:36 -070010305 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib2);
Mark Lobodzinski4761d212017-02-28 13:12:44 -070010306 VkDeviceMemory mem;
10307 VkMemoryRequirements mem_reqs;
Tony Barbour75db7402017-03-09 14:51:36 -070010308 vkGetBufferMemoryRequirements(m_device->device(), ib2, &mem_reqs);
Mark Lobodzinski4761d212017-02-28 13:12:44 -070010309
10310 VkMemoryAllocateInfo alloc_info = {};
10311 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10312 alloc_info.allocationSize = 1024;
10313 bool pass = false;
10314 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
10315 if (!pass) {
Tony Barbour75db7402017-03-09 14:51:36 -070010316 vkDestroyBuffer(m_device->device(), ib2, NULL);
Mark Lobodzinski4761d212017-02-28 13:12:44 -070010317 return;
10318 }
10319 vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
Tony Barbour75db7402017-03-09 14:51:36 -070010320 vkBindBufferMemory(m_device->device(), ib2, mem, 0);
Mark Lobodzinski4761d212017-02-28 13:12:44 -070010321
10322 m_commandBuffer->begin();
Tony Barbour75db7402017-03-09 14:51:36 -070010323 vkCmdFillBuffer(m_commandBuffer->handle(), ib2, 0, 16, 5);
Mark Lobodzinski4761d212017-02-28 13:12:44 -070010324 m_commandBuffer->end();
10325 QueueCommandBuffer(false);
10326 m_errorMonitor->VerifyFound();
Tony Barbour75db7402017-03-09 14:51:36 -070010327 vkDestroyBuffer(m_device->device(), ib2, NULL);
10328 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski4761d212017-02-28 13:12:44 -070010329 }
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -070010330}
10331
Karl Schultz6addd812016-02-02 17:17:23 -070010332TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010333 TEST_DESCRIPTION(
10334 "Attempt vkCmdExecuteCommands with a primary command buffer"
10335 " (should only be secondary)");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010336
Tony Barbour1fa09702017-03-16 12:09:08 -060010337 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -060010338 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -060010339
Chris Forbesf29a84f2016-10-06 18:39:28 +130010340 // An empty primary command buffer
10341 VkCommandBufferObj cb(m_device, m_commandPool);
10342 cb.BeginCommandBuffer();
10343 cb.EndCommandBuffer();
Tobin Ehlis0c94db02016-07-19 10:49:32 -060010344
Chris Forbesf29a84f2016-10-06 18:39:28 +130010345 m_commandBuffer->BeginCommandBuffer();
10346 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
10347 VkCommandBuffer handle = cb.handle();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -060010348
Chris Forbesf29a84f2016-10-06 18:39:28 +130010349 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdExecuteCommands() called w/ Primary Cmd Buffer ");
10350 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &handle);
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010351 m_errorMonitor->VerifyFound();
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070010352
Tobin Ehlis6d4d1d52017-04-05 12:06:10 -060010353 m_errorMonitor->SetUnexpectedError("All elements of pCommandBuffers must not be in the pending state");
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -060010354}
10355
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010356TEST_F(VkLayerTest, DSUsageBitsErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010357 TEST_DESCRIPTION(
10358 "Attempt to update descriptor sets for images and buffers "
10359 "that do not have correct usage bits sets.");
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010360 VkResult err;
10361
Tony Barbour1fa09702017-03-16 12:09:08 -060010362 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010363 VkDescriptorPoolSize ds_type_count[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
10364 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
10365 ds_type_count[i].type = VkDescriptorType(i);
10366 ds_type_count[i].descriptorCount = 1;
10367 }
10368 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10369 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10370 ds_pool_ci.pNext = NULL;
10371 ds_pool_ci.maxSets = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
10372 ds_pool_ci.poolSizeCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
10373 ds_pool_ci.pPoolSizes = ds_type_count;
10374
10375 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010376 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010377 ASSERT_VK_SUCCESS(err);
10378
10379 // Create 10 layouts where each has a single descriptor of different type
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010380 VkDescriptorSetLayoutBinding dsl_binding[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010381 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
10382 dsl_binding[i].binding = 0;
10383 dsl_binding[i].descriptorType = VkDescriptorType(i);
10384 dsl_binding[i].descriptorCount = 1;
10385 dsl_binding[i].stageFlags = VK_SHADER_STAGE_ALL;
10386 dsl_binding[i].pImmutableSamplers = NULL;
10387 }
10388
10389 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10390 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10391 ds_layout_ci.pNext = NULL;
10392 ds_layout_ci.bindingCount = 1;
10393 VkDescriptorSetLayout ds_layouts[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
10394 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
10395 ds_layout_ci.pBindings = dsl_binding + i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010396 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, ds_layouts + i);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010397 ASSERT_VK_SUCCESS(err);
10398 }
10399 VkDescriptorSet descriptor_sets[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
10400 VkDescriptorSetAllocateInfo alloc_info = {};
10401 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10402 alloc_info.descriptorSetCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
10403 alloc_info.descriptorPool = ds_pool;
10404 alloc_info.pSetLayouts = ds_layouts;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010405 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010406 ASSERT_VK_SUCCESS(err);
10407
10408 // Create a buffer & bufferView to be used for invalid updates
10409 VkBufferCreateInfo buff_ci = {};
10410 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Tony Barbour415497c2017-01-24 10:06:09 -070010411 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010412 buff_ci.size = 256;
10413 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
Tony Barbour415497c2017-01-24 10:06:09 -070010414 VkBuffer buffer, storage_texel_buffer;
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010415 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
10416 ASSERT_VK_SUCCESS(err);
Tony Barbour415497c2017-01-24 10:06:09 -070010417
10418 // Create another buffer to use in testing the UNIFORM_TEXEL_BUFFER case
10419 buff_ci.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
10420 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &storage_texel_buffer);
10421 ASSERT_VK_SUCCESS(err);
10422
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -070010423 VkMemoryRequirements mem_reqs;
10424 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
10425 VkMemoryAllocateInfo mem_alloc_info = {};
10426 mem_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10427 mem_alloc_info.pNext = NULL;
10428 mem_alloc_info.memoryTypeIndex = 0;
10429 mem_alloc_info.allocationSize = mem_reqs.size;
10430 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc_info, 0);
10431 if (!pass) {
10432 vkDestroyBuffer(m_device->device(), buffer, NULL);
10433 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10434 return;
10435 }
10436 VkDeviceMemory mem;
10437 err = vkAllocateMemory(m_device->device(), &mem_alloc_info, NULL, &mem);
10438 ASSERT_VK_SUCCESS(err);
10439 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
10440 ASSERT_VK_SUCCESS(err);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010441
10442 VkBufferViewCreateInfo buff_view_ci = {};
10443 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
10444 buff_view_ci.buffer = buffer;
10445 buff_view_ci.format = VK_FORMAT_R8_UNORM;
10446 buff_view_ci.range = VK_WHOLE_SIZE;
10447 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010448 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010449 ASSERT_VK_SUCCESS(err);
10450
Tony Barbour415497c2017-01-24 10:06:09 -070010451 // Now get resources / view for storage_texel_buffer
10452 vkGetBufferMemoryRequirements(m_device->device(), storage_texel_buffer, &mem_reqs);
10453 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc_info, 0);
10454 if (!pass) {
10455 vkDestroyBuffer(m_device->device(), buffer, NULL);
10456 vkDestroyBufferView(m_device->device(), buff_view, NULL);
10457 vkFreeMemory(m_device->device(), mem, NULL);
10458 vkDestroyBuffer(m_device->device(), storage_texel_buffer, NULL);
10459 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10460 return;
10461 }
10462 VkDeviceMemory storage_texel_buffer_mem;
10463 VkBufferView storage_texel_buffer_view;
10464 err = vkAllocateMemory(m_device->device(), &mem_alloc_info, NULL, &storage_texel_buffer_mem);
10465 ASSERT_VK_SUCCESS(err);
10466 err = vkBindBufferMemory(m_device->device(), storage_texel_buffer, storage_texel_buffer_mem, 0);
10467 ASSERT_VK_SUCCESS(err);
10468 buff_view_ci.buffer = storage_texel_buffer;
10469 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &storage_texel_buffer_view);
10470 ASSERT_VK_SUCCESS(err);
10471
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010472 // Create an image to be used for invalid updates
Tony Barbour4b4a4222017-01-24 11:46:34 -070010473 // Find a format / tiling for COLOR_ATTACHMENT
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010474 VkImageCreateInfo image_ci = {};
Tony Barbour4b4a4222017-01-24 11:46:34 -070010475 image_ci.format = VK_FORMAT_UNDEFINED;
10476 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
10477 VkFormat format = static_cast<VkFormat>(f);
10478 VkFormatProperties fProps = m_device->format_properties(format);
10479 if (fProps.linearTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) {
10480 image_ci.format = format;
10481 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
10482 break;
10483 } else if (fProps.optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) {
10484 image_ci.format = format;
10485 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
10486 break;
10487 }
10488 }
10489 if (image_ci.format == VK_FORMAT_UNDEFINED) {
10490 return;
10491 }
10492
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010493 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10494 image_ci.imageType = VK_IMAGE_TYPE_2D;
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010495 image_ci.extent.width = 64;
10496 image_ci.extent.height = 64;
10497 image_ci.extent.depth = 1;
10498 image_ci.mipLevels = 1;
10499 image_ci.arrayLayers = 1;
10500 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010501 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
Tony Barbour4b4a4222017-01-24 11:46:34 -070010502 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010503 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
10504 VkImage image;
10505 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
10506 ASSERT_VK_SUCCESS(err);
10507 // Bind memory to image
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010508 VkDeviceMemory image_mem;
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -070010509
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010510 VkMemoryAllocateInfo mem_alloc = {};
10511 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10512 mem_alloc.pNext = NULL;
10513 mem_alloc.allocationSize = 0;
10514 mem_alloc.memoryTypeIndex = 0;
10515 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
10516 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010517 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010518 ASSERT_TRUE(pass);
10519 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
10520 ASSERT_VK_SUCCESS(err);
10521 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
10522 ASSERT_VK_SUCCESS(err);
10523 // Now create view for image
10524 VkImageViewCreateInfo image_view_ci = {};
10525 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
10526 image_view_ci.image = image;
Tony Barbour4b4a4222017-01-24 11:46:34 -070010527 image_view_ci.format = image_ci.format;
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010528 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
10529 image_view_ci.subresourceRange.layerCount = 1;
10530 image_view_ci.subresourceRange.baseArrayLayer = 0;
10531 image_view_ci.subresourceRange.levelCount = 1;
10532 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10533 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010534 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010535 ASSERT_VK_SUCCESS(err);
10536
10537 VkDescriptorBufferInfo buff_info = {};
10538 buff_info.buffer = buffer;
10539 VkDescriptorImageInfo img_info = {};
10540 img_info.imageView = image_view;
10541 VkWriteDescriptorSet descriptor_write = {};
10542 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10543 descriptor_write.dstBinding = 0;
10544 descriptor_write.descriptorCount = 1;
10545 descriptor_write.pTexelBufferView = &buff_view;
10546 descriptor_write.pBufferInfo = &buff_info;
10547 descriptor_write.pImageInfo = &img_info;
10548
10549 // These error messages align with VkDescriptorType struct
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -070010550 UNIQUE_VALIDATION_ERROR_CODE error_codes[] = {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010551 VALIDATION_ERROR_00943, // placeholder, no error for SAMPLER descriptor
10552 VALIDATION_ERROR_00943, // COMBINED_IMAGE_SAMPLER
10553 VALIDATION_ERROR_00943, // SAMPLED_IMAGE
10554 VALIDATION_ERROR_00943, // STORAGE_IMAGE
10555 VALIDATION_ERROR_00950, // UNIFORM_TEXEL_BUFFER
10556 VALIDATION_ERROR_00951, // STORAGE_TEXEL_BUFFER
10557 VALIDATION_ERROR_00946, // UNIFORM_BUFFER
10558 VALIDATION_ERROR_00947, // STORAGE_BUFFER
10559 VALIDATION_ERROR_00946, // UNIFORM_BUFFER_DYNAMIC
10560 VALIDATION_ERROR_00947, // STORAGE_BUFFER_DYNAMIC
10561 VALIDATION_ERROR_00943 // INPUT_ATTACHMENT
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -070010562 };
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010563 // Start loop at 1 as SAMPLER desc type has no usage bit error
10564 for (uint32_t i = 1; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
Tony Barbour415497c2017-01-24 10:06:09 -070010565 if (VkDescriptorType(i) == VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER) {
10566 // Now check for UNIFORM_TEXEL_BUFFER using storage_texel_buffer_view
10567 descriptor_write.pTexelBufferView = &storage_texel_buffer_view;
10568 }
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010569 descriptor_write.descriptorType = VkDescriptorType(i);
10570 descriptor_write.dstSet = descriptor_sets[i];
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -070010571 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_codes[i]);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010572
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010573 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010574
10575 m_errorMonitor->VerifyFound();
10576 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[i], NULL);
Tony Barbour415497c2017-01-24 10:06:09 -070010577 if (VkDescriptorType(i) == VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER) {
10578 descriptor_write.pTexelBufferView = &buff_view;
10579 }
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010580 }
Tony Barbour415497c2017-01-24 10:06:09 -070010581
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010582 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[0], NULL);
10583 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -060010584 vkFreeMemory(m_device->device(), image_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010585 vkDestroyImageView(m_device->device(), image_view, NULL);
10586 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tony Barbour415497c2017-01-24 10:06:09 -070010587 vkDestroyBuffer(m_device->device(), storage_texel_buffer, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010588 vkDestroyBufferView(m_device->device(), buff_view, NULL);
Tony Barbour415497c2017-01-24 10:06:09 -070010589 vkDestroyBufferView(m_device->device(), storage_texel_buffer_view, NULL);
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -070010590 vkFreeMemory(m_device->device(), mem, NULL);
Tony Barbour415497c2017-01-24 10:06:09 -070010591 vkFreeMemory(m_device->device(), storage_texel_buffer_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010592 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10593}
10594
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010595TEST_F(VkLayerTest, DSBufferInfoErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010596 TEST_DESCRIPTION(
10597 "Attempt to update buffer descriptor set that has incorrect "
10598 "parameters in VkDescriptorBufferInfo struct. This includes:\n"
Jeremy Hayesd1a6a822017-03-09 14:39:45 -070010599 "1. offset value greater than or equal to buffer size\n"
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010600 "2. range value of 0\n"
10601 "3. range value greater than buffer (size - offset)");
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010602 VkResult err;
10603
Tony Barbour1fa09702017-03-16 12:09:08 -060010604 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010605 VkDescriptorPoolSize ds_type_count = {};
10606 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10607 ds_type_count.descriptorCount = 1;
10608
10609 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10610 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10611 ds_pool_ci.pNext = NULL;
Jeremy Hayesd1a6a822017-03-09 14:39:45 -070010612 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010613 ds_pool_ci.maxSets = 1;
10614 ds_pool_ci.poolSizeCount = 1;
10615 ds_pool_ci.pPoolSizes = &ds_type_count;
10616
10617 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010618 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010619 ASSERT_VK_SUCCESS(err);
10620
10621 // Create layout with single uniform buffer descriptor
10622 VkDescriptorSetLayoutBinding dsl_binding = {};
10623 dsl_binding.binding = 0;
10624 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10625 dsl_binding.descriptorCount = 1;
10626 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10627 dsl_binding.pImmutableSamplers = NULL;
10628
10629 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10630 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10631 ds_layout_ci.pNext = NULL;
10632 ds_layout_ci.bindingCount = 1;
10633 ds_layout_ci.pBindings = &dsl_binding;
10634 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010635 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010636 ASSERT_VK_SUCCESS(err);
10637
10638 VkDescriptorSet descriptor_set = {};
10639 VkDescriptorSetAllocateInfo alloc_info = {};
10640 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10641 alloc_info.descriptorSetCount = 1;
10642 alloc_info.descriptorPool = ds_pool;
10643 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010644 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010645 ASSERT_VK_SUCCESS(err);
10646
10647 // Create a buffer to be used for invalid updates
10648 VkBufferCreateInfo buff_ci = {};
10649 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
10650 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
Jeremy Hayesd1a6a822017-03-09 14:39:45 -070010651 buff_ci.size = m_device->props.limits.minUniformBufferOffsetAlignment;
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010652 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
10653 VkBuffer buffer;
10654 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
10655 ASSERT_VK_SUCCESS(err);
Jeremy Hayesd1a6a822017-03-09 14:39:45 -070010656
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010657 // Have to bind memory to buffer before descriptor update
10658 VkMemoryAllocateInfo mem_alloc = {};
10659 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10660 mem_alloc.pNext = NULL;
Jeremy Hayesd1a6a822017-03-09 14:39:45 -070010661 mem_alloc.allocationSize = buff_ci.size;
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010662 mem_alloc.memoryTypeIndex = 0;
10663
10664 VkMemoryRequirements mem_reqs;
10665 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010666 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010667 if (!pass) {
10668 vkDestroyBuffer(m_device->device(), buffer, NULL);
10669 return;
10670 }
10671
10672 VkDeviceMemory mem;
10673 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
10674 ASSERT_VK_SUCCESS(err);
10675 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
10676 ASSERT_VK_SUCCESS(err);
10677
10678 VkDescriptorBufferInfo buff_info = {};
10679 buff_info.buffer = buffer;
Jeremy Hayesd1a6a822017-03-09 14:39:45 -070010680 // Cause error due to offset out of range
10681 buff_info.offset = buff_ci.size;
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010682 buff_info.range = VK_WHOLE_SIZE;
10683 VkWriteDescriptorSet descriptor_write = {};
10684 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10685 descriptor_write.dstBinding = 0;
10686 descriptor_write.descriptorCount = 1;
10687 descriptor_write.pTexelBufferView = nullptr;
10688 descriptor_write.pBufferInfo = &buff_info;
10689 descriptor_write.pImageInfo = nullptr;
10690
10691 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10692 descriptor_write.dstSet = descriptor_set;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070010693 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00959);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010694
10695 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10696
10697 m_errorMonitor->VerifyFound();
10698 // Now cause error due to range of 0
10699 buff_info.offset = 0;
10700 buff_info.range = 0;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070010701 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00960);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010702
10703 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10704
10705 m_errorMonitor->VerifyFound();
10706 // Now cause error due to range exceeding buffer size - offset
Jeremy Hayesd1a6a822017-03-09 14:39:45 -070010707 buff_info.offset = 0;
10708 buff_info.range = buff_ci.size + 1;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070010709 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00961);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010710
10711 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10712
10713 m_errorMonitor->VerifyFound();
Mark Lobodzinski4bb54092016-07-06 14:27:19 -060010714 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010715 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10716 vkDestroyBuffer(m_device->device(), buffer, NULL);
10717 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
10718 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10719}
10720
Tobin Ehlis845887e2017-02-02 19:01:44 -070010721TEST_F(VkLayerTest, DSBufferLimitErrors) {
10722 TEST_DESCRIPTION(
10723 "Attempt to update buffer descriptor set that has VkDescriptorBufferInfo values that violate device limits.\n"
10724 "Test cases include:\n"
10725 "1. range of uniform buffer update exceeds maxUniformBufferRange\n"
10726 "2. offset of uniform buffer update is not multiple of minUniformBufferOffsetAlignment\n"
10727 "3. range of storage buffer update exceeds maxStorageBufferRange\n"
10728 "4. offset of storage buffer update is not multiple of minStorageBufferOffsetAlignment");
10729 VkResult err;
10730
Tony Barbour1fa09702017-03-16 12:09:08 -060010731 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis845887e2017-02-02 19:01:44 -070010732 VkDescriptorPoolSize ds_type_count[2] = {};
10733 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10734 ds_type_count[0].descriptorCount = 1;
10735 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
10736 ds_type_count[1].descriptorCount = 1;
10737
10738 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10739 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10740 ds_pool_ci.pNext = NULL;
10741 ds_pool_ci.maxSets = 1;
10742 ds_pool_ci.poolSizeCount = 2;
10743 ds_pool_ci.pPoolSizes = ds_type_count;
10744
10745 VkDescriptorPool ds_pool;
10746 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
10747 ASSERT_VK_SUCCESS(err);
10748
10749 // Create layout with single uniform buffer & single storage buffer descriptor
10750 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
10751 dsl_binding[0].binding = 0;
10752 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10753 dsl_binding[0].descriptorCount = 1;
10754 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
10755 dsl_binding[0].pImmutableSamplers = NULL;
10756 dsl_binding[1].binding = 1;
10757 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
10758 dsl_binding[1].descriptorCount = 1;
10759 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
10760 dsl_binding[1].pImmutableSamplers = NULL;
10761
10762 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10763 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10764 ds_layout_ci.pNext = NULL;
10765 ds_layout_ci.bindingCount = 2;
10766 ds_layout_ci.pBindings = dsl_binding;
10767 VkDescriptorSetLayout ds_layout;
10768 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
10769 ASSERT_VK_SUCCESS(err);
10770
10771 VkDescriptorSet descriptor_set = {};
10772 VkDescriptorSetAllocateInfo alloc_info = {};
10773 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10774 alloc_info.descriptorSetCount = 1;
10775 alloc_info.descriptorPool = ds_pool;
10776 alloc_info.pSetLayouts = &ds_layout;
10777 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
10778 ASSERT_VK_SUCCESS(err);
10779
10780 // Create a buffer to be used for invalid updates
10781 auto max_ub_range = m_device->props.limits.maxUniformBufferRange;
10782 auto min_ub_align = m_device->props.limits.minUniformBufferOffsetAlignment;
10783 auto max_sb_range = m_device->props.limits.maxStorageBufferRange;
10784 auto min_sb_align = m_device->props.limits.minStorageBufferOffsetAlignment;
10785 VkBufferCreateInfo ub_ci = {};
10786 ub_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
10787 ub_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
10788 ub_ci.size = max_ub_range + 128; // Make buffer bigger than range limit
10789 ub_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
10790 VkBuffer uniform_buffer;
10791 err = vkCreateBuffer(m_device->device(), &ub_ci, NULL, &uniform_buffer);
10792 ASSERT_VK_SUCCESS(err);
10793 VkBufferCreateInfo sb_ci = {};
10794 sb_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
10795 sb_ci.usage = VK_BUFFER_USAGE_STORAGE_BUFFER_BIT;
10796 sb_ci.size = max_sb_range + 128; // Make buffer bigger than range limit
10797 sb_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
10798 VkBuffer storage_buffer;
10799 err = vkCreateBuffer(m_device->device(), &sb_ci, NULL, &storage_buffer);
10800 ASSERT_VK_SUCCESS(err);
10801 // Have to bind memory to buffer before descriptor update
10802 VkMemoryAllocateInfo mem_alloc = {};
10803 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10804 mem_alloc.pNext = NULL;
10805 mem_alloc.allocationSize = ub_ci.size + sb_ci.size + 1024; // additional buffer for offset
10806 mem_alloc.memoryTypeIndex = 0;
10807
Cort Stratton77a0d592017-02-17 13:14:13 -080010808 VkMemoryRequirements ub_mem_reqs, sb_mem_reqs;
10809 vkGetBufferMemoryRequirements(m_device->device(), uniform_buffer, &ub_mem_reqs);
10810 bool pass = m_device->phy().set_memory_type(ub_mem_reqs.memoryTypeBits, &mem_alloc, 0);
10811 vkGetBufferMemoryRequirements(m_device->device(), storage_buffer, &sb_mem_reqs);
10812 pass &= m_device->phy().set_memory_type(sb_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis845887e2017-02-02 19:01:44 -070010813 if (!pass) {
Tobin Ehlis15c83792017-02-07 10:09:33 -070010814 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Tobin Ehlis845887e2017-02-02 19:01:44 -070010815 vkDestroyBuffer(m_device->device(), uniform_buffer, NULL);
Tobin Ehlis15c83792017-02-07 10:09:33 -070010816 vkDestroyBuffer(m_device->device(), storage_buffer, NULL);
10817 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis845887e2017-02-02 19:01:44 -070010818 return;
10819 }
10820
10821 VkDeviceMemory mem;
10822 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlis15c83792017-02-07 10:09:33 -070010823 if (VK_SUCCESS != err) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070010824 printf(" Failed to allocate memory in DSBufferLimitErrors; skipped.\n");
Tobin Ehlis15c83792017-02-07 10:09:33 -070010825 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10826 vkDestroyBuffer(m_device->device(), uniform_buffer, NULL);
10827 vkDestroyBuffer(m_device->device(), storage_buffer, NULL);
10828 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10829 return;
10830 }
Tobin Ehlis845887e2017-02-02 19:01:44 -070010831 ASSERT_VK_SUCCESS(err);
10832 err = vkBindBufferMemory(m_device->device(), uniform_buffer, mem, 0);
10833 ASSERT_VK_SUCCESS(err);
Cort Stratton77a0d592017-02-17 13:14:13 -080010834 auto sb_offset = (ub_ci.size + sb_mem_reqs.alignment - 1) & ~(sb_mem_reqs.alignment - 1);
Tobin Ehlis845887e2017-02-02 19:01:44 -070010835 err = vkBindBufferMemory(m_device->device(), storage_buffer, mem, sb_offset);
10836 ASSERT_VK_SUCCESS(err);
10837
10838 VkDescriptorBufferInfo buff_info = {};
10839 buff_info.buffer = uniform_buffer;
10840 buff_info.range = ub_ci.size; // This will exceed limit
10841 VkWriteDescriptorSet descriptor_write = {};
10842 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10843 descriptor_write.dstBinding = 0;
10844 descriptor_write.descriptorCount = 1;
10845 descriptor_write.pTexelBufferView = nullptr;
10846 descriptor_write.pBufferInfo = &buff_info;
10847 descriptor_write.pImageInfo = nullptr;
10848
10849 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10850 descriptor_write.dstSet = descriptor_set;
Tony Barbour02d08552017-03-24 16:36:01 -060010851 if (max_ub_range != UINT32_MAX) {
10852 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00948);
10853 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10854 m_errorMonitor->VerifyFound();
10855 }
Tobin Ehlis845887e2017-02-02 19:01:44 -070010856 // Reduce size of range to acceptable limit & cause offset error
10857 buff_info.range = max_ub_range;
10858 buff_info.offset = min_ub_align - 1;
10859 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00944);
10860 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10861 m_errorMonitor->VerifyFound();
10862
10863 // Now break storage updates
10864 buff_info.buffer = storage_buffer;
10865 buff_info.range = sb_ci.size; // This will exceed limit
10866 buff_info.offset = 0; // Reset offset for this update
10867
10868 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
10869 descriptor_write.dstBinding = 1;
Tony Barbour02d08552017-03-24 16:36:01 -060010870 if (max_ub_range != UINT32_MAX) {
10871 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00949);
10872 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10873 m_errorMonitor->VerifyFound();
10874 }
Tobin Ehlis845887e2017-02-02 19:01:44 -070010875
10876 // Reduce size of range to acceptable limit & cause offset error
10877 buff_info.range = max_sb_range;
10878 buff_info.offset = min_sb_align - 1;
10879 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00945);
10880 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10881 m_errorMonitor->VerifyFound();
10882
10883 vkFreeMemory(m_device->device(), mem, NULL);
10884 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10885 vkDestroyBuffer(m_device->device(), uniform_buffer, NULL);
10886 vkDestroyBuffer(m_device->device(), storage_buffer, NULL);
10887 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10888}
10889
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010890TEST_F(VkLayerTest, DSAspectBitsErrors) {
10891 // TODO : Initially only catching case where DEPTH & STENCIL aspect bits
10892 // are set, but could expand this test to hit more cases.
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010893 TEST_DESCRIPTION(
10894 "Attempt to update descriptor sets for images "
10895 "that do not have correct aspect bits sets.");
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010896 VkResult err;
10897
Tony Barbour1fa09702017-03-16 12:09:08 -060010898 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -060010899 auto depth_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbourf887b162017-03-09 10:06:46 -070010900 if (!depth_format) {
10901 printf(" No Depth + Stencil format found. Skipped.\n");
10902 return;
10903 }
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010904 VkDescriptorPoolSize ds_type_count = {};
10905 ds_type_count.type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
10906 ds_type_count.descriptorCount = 1;
10907
10908 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10909 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10910 ds_pool_ci.pNext = NULL;
Jeremy Hayes293c7ed2017-03-09 14:47:07 -070010911 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010912 ds_pool_ci.maxSets = 5;
10913 ds_pool_ci.poolSizeCount = 1;
10914 ds_pool_ci.pPoolSizes = &ds_type_count;
10915
10916 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010917 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010918 ASSERT_VK_SUCCESS(err);
10919
10920 VkDescriptorSetLayoutBinding dsl_binding = {};
10921 dsl_binding.binding = 0;
10922 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
10923 dsl_binding.descriptorCount = 1;
10924 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10925 dsl_binding.pImmutableSamplers = NULL;
10926
10927 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10928 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10929 ds_layout_ci.pNext = NULL;
10930 ds_layout_ci.bindingCount = 1;
10931 ds_layout_ci.pBindings = &dsl_binding;
10932 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010933 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010934 ASSERT_VK_SUCCESS(err);
10935
10936 VkDescriptorSet descriptor_set = {};
10937 VkDescriptorSetAllocateInfo alloc_info = {};
10938 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10939 alloc_info.descriptorSetCount = 1;
10940 alloc_info.descriptorPool = ds_pool;
10941 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010942 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010943 ASSERT_VK_SUCCESS(err);
10944
10945 // Create an image to be used for invalid updates
10946 VkImageCreateInfo image_ci = {};
10947 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10948 image_ci.imageType = VK_IMAGE_TYPE_2D;
Tony Barbourf887b162017-03-09 10:06:46 -070010949 image_ci.format = depth_format;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010950 image_ci.extent.width = 64;
10951 image_ci.extent.height = 64;
10952 image_ci.extent.depth = 1;
10953 image_ci.mipLevels = 1;
10954 image_ci.arrayLayers = 1;
10955 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Young2d1fa302017-03-02 10:13:09 -070010956 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010957 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
10958 image_ci.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
10959 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
10960 VkImage image;
10961 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
10962 ASSERT_VK_SUCCESS(err);
10963 // Bind memory to image
10964 VkMemoryRequirements mem_reqs;
10965 VkDeviceMemory image_mem;
10966 bool pass;
10967 VkMemoryAllocateInfo mem_alloc = {};
10968 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10969 mem_alloc.pNext = NULL;
10970 mem_alloc.allocationSize = 0;
10971 mem_alloc.memoryTypeIndex = 0;
10972 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
10973 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010974 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010975 ASSERT_TRUE(pass);
10976 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
10977 ASSERT_VK_SUCCESS(err);
10978 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
10979 ASSERT_VK_SUCCESS(err);
10980 // Now create view for image
10981 VkImageViewCreateInfo image_view_ci = {};
10982 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
10983 image_view_ci.image = image;
Tony Barbourf887b162017-03-09 10:06:46 -070010984 image_view_ci.format = depth_format;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010985 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
10986 image_view_ci.subresourceRange.layerCount = 1;
10987 image_view_ci.subresourceRange.baseArrayLayer = 0;
10988 image_view_ci.subresourceRange.levelCount = 1;
10989 // Setting both depth & stencil aspect bits is illegal for descriptor
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010990 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010991
10992 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010993 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010994 ASSERT_VK_SUCCESS(err);
10995
10996 VkDescriptorImageInfo img_info = {};
10997 img_info.imageView = image_view;
10998 VkWriteDescriptorSet descriptor_write = {};
10999 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11000 descriptor_write.dstBinding = 0;
11001 descriptor_write.descriptorCount = 1;
11002 descriptor_write.pTexelBufferView = NULL;
11003 descriptor_write.pBufferInfo = NULL;
11004 descriptor_write.pImageInfo = &img_info;
11005 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
11006 descriptor_write.dstSet = descriptor_set;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011007 const char *error_msg =
11008 " please only set either VK_IMAGE_ASPECT_DEPTH_BIT "
11009 "or VK_IMAGE_ASPECT_STENCIL_BIT ";
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011010 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msg);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060011011
11012 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11013
11014 m_errorMonitor->VerifyFound();
11015 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11016 vkDestroyImage(m_device->device(), image, NULL);
11017 vkFreeMemory(m_device->device(), image_mem, NULL);
11018 vkDestroyImageView(m_device->device(), image_view, NULL);
11019 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
11020 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11021}
11022
Karl Schultz6addd812016-02-02 17:17:23 -070011023TEST_F(VkLayerTest, DSTypeMismatch) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060011024 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Karl Schultz6addd812016-02-02 17:17:23 -070011025 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011026
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011027 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11028 " binding #0 with type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER but update "
11029 "type is VK_DESCRIPTOR_TYPE_SAMPLER");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011030
Tony Barbour1fa09702017-03-16 12:09:08 -060011031 ASSERT_NO_FATAL_FAILURE(Init());
Karl Schultz6addd812016-02-02 17:17:23 -070011032 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011033 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011034 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11035 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011036
11037 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011038 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11039 ds_pool_ci.pNext = NULL;
11040 ds_pool_ci.maxSets = 1;
11041 ds_pool_ci.poolSizeCount = 1;
11042 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060011043
Tobin Ehlis3b780662015-05-28 12:11:26 -060011044 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011045 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011046 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -060011047 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011048 dsl_binding.binding = 0;
11049 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11050 dsl_binding.descriptorCount = 1;
11051 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11052 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011053
Tony Barboureb254902015-07-15 12:50:33 -060011054 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011055 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11056 ds_layout_ci.pNext = NULL;
11057 ds_layout_ci.bindingCount = 1;
11058 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060011059
Tobin Ehlis3b780662015-05-28 12:11:26 -060011060 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011061 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011062 ASSERT_VK_SUCCESS(err);
11063
11064 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011065 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011066 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011067 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011068 alloc_info.descriptorPool = ds_pool;
11069 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011070 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011071 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011072
Tobin Ehlis30db8f82016-05-05 08:19:48 -060011073 VkSamplerCreateInfo sampler_ci = {};
11074 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11075 sampler_ci.pNext = NULL;
11076 sampler_ci.magFilter = VK_FILTER_NEAREST;
11077 sampler_ci.minFilter = VK_FILTER_NEAREST;
11078 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11079 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11080 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11081 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11082 sampler_ci.mipLodBias = 1.0;
11083 sampler_ci.anisotropyEnable = VK_FALSE;
11084 sampler_ci.maxAnisotropy = 1;
11085 sampler_ci.compareEnable = VK_FALSE;
11086 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11087 sampler_ci.minLod = 1.0;
11088 sampler_ci.maxLod = 1.0;
11089 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11090 sampler_ci.unnormalizedCoordinates = VK_FALSE;
11091 VkSampler sampler;
11092 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
11093 ASSERT_VK_SUCCESS(err);
11094
11095 VkDescriptorImageInfo info = {};
11096 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011097
11098 VkWriteDescriptorSet descriptor_write;
11099 memset(&descriptor_write, 0, sizeof(descriptor_write));
11100 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011101 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011102 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011103 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011104 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060011105 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011106
11107 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11108
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011109 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011110
Chia-I Wuf7458c52015-10-26 21:10:41 +080011111 vkDestroySampler(m_device->device(), sampler, NULL);
11112 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11113 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060011114}
11115
Karl Schultz6addd812016-02-02 17:17:23 -070011116TEST_F(VkLayerTest, DSUpdateOutOfBounds) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060011117 // For overlapping Update, have arrayIndex exceed that of layout
Karl Schultz6addd812016-02-02 17:17:23 -070011118 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011119
Tobin Ehlisf922ef82016-11-30 10:19:14 -070011120 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00938);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011121
Tony Barbour1fa09702017-03-16 12:09:08 -060011122 ASSERT_NO_FATAL_FAILURE(Init());
Karl Schultz6addd812016-02-02 17:17:23 -070011123 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011124 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011125 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11126 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011127
11128 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011129 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11130 ds_pool_ci.pNext = NULL;
11131 ds_pool_ci.maxSets = 1;
11132 ds_pool_ci.poolSizeCount = 1;
11133 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060011134
Tobin Ehlis3b780662015-05-28 12:11:26 -060011135 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011136 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011137 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011138
Tony Barboureb254902015-07-15 12:50:33 -060011139 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011140 dsl_binding.binding = 0;
11141 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11142 dsl_binding.descriptorCount = 1;
11143 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11144 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -060011145
11146 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011147 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11148 ds_layout_ci.pNext = NULL;
11149 ds_layout_ci.bindingCount = 1;
11150 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060011151
Tobin Ehlis3b780662015-05-28 12:11:26 -060011152 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011153 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011154 ASSERT_VK_SUCCESS(err);
11155
11156 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011157 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011158 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011159 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011160 alloc_info.descriptorPool = ds_pool;
11161 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011162 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011163 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011164
Jeremy Hayesd5b95db2017-03-09 15:24:24 -070011165 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
11166
Tobin Ehlis30db8f82016-05-05 08:19:48 -060011167 // Correctly update descriptor to avoid "NOT_UPDATED" error
11168 VkDescriptorBufferInfo buff_info = {};
Jeremy Hayesd5b95db2017-03-09 15:24:24 -070011169 buff_info.buffer = buffer_test.GetBuffer();
Tobin Ehlis30db8f82016-05-05 08:19:48 -060011170 buff_info.offset = 0;
11171 buff_info.range = 1024;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011172
11173 VkWriteDescriptorSet descriptor_write;
11174 memset(&descriptor_write, 0, sizeof(descriptor_write));
11175 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011176 descriptor_write.dstSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011177 descriptor_write.dstArrayElement = 1; /* This index out of bounds for the update */
Chia-I Wud50a7d72015-10-26 20:48:51 +080011178 descriptor_write.descriptorCount = 1;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -060011179 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11180 descriptor_write.pBufferInfo = &buff_info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011181
11182 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11183
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011184 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011185
Chia-I Wuf7458c52015-10-26 21:10:41 +080011186 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11187 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060011188}
11189
Karl Schultz6addd812016-02-02 17:17:23 -070011190TEST_F(VkLayerTest, InvalidDSUpdateIndex) {
Tobin Ehlisc8d352d2016-11-21 10:33:40 -070011191 // Create layout w/ count of 1 and attempt update to that layout w/ binding index 2
Karl Schultz6addd812016-02-02 17:17:23 -070011192 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011193
Tobin Ehlisc8d352d2016-11-21 10:33:40 -070011194 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00936);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011195
Tony Barbour1fa09702017-03-16 12:09:08 -060011196 ASSERT_NO_FATAL_FAILURE(Init());
Karl Schultz6addd812016-02-02 17:17:23 -070011197 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011198 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011199 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11200 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011201
11202 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011203 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11204 ds_pool_ci.pNext = NULL;
11205 ds_pool_ci.maxSets = 1;
11206 ds_pool_ci.poolSizeCount = 1;
11207 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060011208
Tobin Ehlis3b780662015-05-28 12:11:26 -060011209 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011210 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011211 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011212
Tony Barboureb254902015-07-15 12:50:33 -060011213 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011214 dsl_binding.binding = 0;
11215 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11216 dsl_binding.descriptorCount = 1;
11217 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11218 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -060011219
11220 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011221 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11222 ds_layout_ci.pNext = NULL;
11223 ds_layout_ci.bindingCount = 1;
11224 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011225 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011226 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011227 ASSERT_VK_SUCCESS(err);
11228
11229 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011230 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011231 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011232 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011233 alloc_info.descriptorPool = ds_pool;
11234 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011235 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011236 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011237
Tony Barboureb254902015-07-15 12:50:33 -060011238 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011239 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11240 sampler_ci.pNext = NULL;
11241 sampler_ci.magFilter = VK_FILTER_NEAREST;
11242 sampler_ci.minFilter = VK_FILTER_NEAREST;
11243 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11244 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11245 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11246 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11247 sampler_ci.mipLodBias = 1.0;
11248 sampler_ci.anisotropyEnable = VK_FALSE;
11249 sampler_ci.maxAnisotropy = 1;
11250 sampler_ci.compareEnable = VK_FALSE;
11251 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11252 sampler_ci.minLod = 1.0;
11253 sampler_ci.maxLod = 1.0;
11254 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11255 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -060011256
Tobin Ehlis3b780662015-05-28 12:11:26 -060011257 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011258 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011259 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011260
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060011261 VkDescriptorImageInfo info = {};
11262 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011263
11264 VkWriteDescriptorSet descriptor_write;
11265 memset(&descriptor_write, 0, sizeof(descriptor_write));
11266 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011267 descriptor_write.dstSet = descriptorSet;
11268 descriptor_write.dstBinding = 2;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011269 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011270 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011271 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060011272 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011273
11274 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11275
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011276 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011277
Chia-I Wuf7458c52015-10-26 21:10:41 +080011278 vkDestroySampler(m_device->device(), sampler, NULL);
11279 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11280 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060011281}
11282
Tobin Ehlise202b2d2016-11-21 10:36:16 -070011283TEST_F(VkLayerTest, DSUpdateEmptyBinding) {
11284 // Create layout w/ empty binding and attempt to update it
11285 VkResult err;
11286
Tony Barbour1fa09702017-03-16 12:09:08 -060011287 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlise202b2d2016-11-21 10:36:16 -070011288
11289 VkDescriptorPoolSize ds_type_count = {};
11290 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
11291 ds_type_count.descriptorCount = 1;
11292
11293 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11294 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11295 ds_pool_ci.pNext = NULL;
11296 ds_pool_ci.maxSets = 1;
11297 ds_pool_ci.poolSizeCount = 1;
11298 ds_pool_ci.pPoolSizes = &ds_type_count;
11299
11300 VkDescriptorPool ds_pool;
11301 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
11302 ASSERT_VK_SUCCESS(err);
11303
11304 VkDescriptorSetLayoutBinding dsl_binding = {};
11305 dsl_binding.binding = 0;
11306 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
11307 dsl_binding.descriptorCount = 0;
11308 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11309 dsl_binding.pImmutableSamplers = NULL;
11310
11311 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11312 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11313 ds_layout_ci.pNext = NULL;
11314 ds_layout_ci.bindingCount = 1;
11315 ds_layout_ci.pBindings = &dsl_binding;
11316 VkDescriptorSetLayout ds_layout;
11317 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
11318 ASSERT_VK_SUCCESS(err);
11319
11320 VkDescriptorSet descriptor_set;
11321 VkDescriptorSetAllocateInfo alloc_info = {};
11322 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11323 alloc_info.descriptorSetCount = 1;
11324 alloc_info.descriptorPool = ds_pool;
11325 alloc_info.pSetLayouts = &ds_layout;
11326 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
11327 ASSERT_VK_SUCCESS(err);
11328
11329 VkSamplerCreateInfo sampler_ci = {};
11330 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11331 sampler_ci.magFilter = VK_FILTER_NEAREST;
11332 sampler_ci.minFilter = VK_FILTER_NEAREST;
11333 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11334 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11335 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11336 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11337 sampler_ci.mipLodBias = 1.0;
11338 sampler_ci.maxAnisotropy = 1;
11339 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11340 sampler_ci.minLod = 1.0;
11341 sampler_ci.maxLod = 1.0;
11342 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11343
11344 VkSampler sampler;
11345 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
11346 ASSERT_VK_SUCCESS(err);
11347
11348 VkDescriptorImageInfo info = {};
11349 info.sampler = sampler;
11350
11351 VkWriteDescriptorSet descriptor_write;
11352 memset(&descriptor_write, 0, sizeof(descriptor_write));
11353 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11354 descriptor_write.dstSet = descriptor_set;
11355 descriptor_write.dstBinding = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011356 descriptor_write.descriptorCount = 1; // Lie here to avoid parameter_validation error
Tobin Ehlise202b2d2016-11-21 10:36:16 -070011357 // This is the wrong type, but empty binding error will be flagged first
11358 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
11359 descriptor_write.pImageInfo = &info;
11360
11361 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02348);
11362 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11363 m_errorMonitor->VerifyFound();
11364
11365 vkDestroySampler(m_device->device(), sampler, NULL);
11366 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11367 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11368}
11369
Karl Schultz6addd812016-02-02 17:17:23 -070011370TEST_F(VkLayerTest, InvalidDSUpdateStruct) {
11371 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_*
11372 // types
11373 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011374
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011375 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, ".sType must be VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011376
Tony Barbour1fa09702017-03-16 12:09:08 -060011377 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011378
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011379 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011380 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11381 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011382
11383 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011384 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11385 ds_pool_ci.pNext = NULL;
11386 ds_pool_ci.maxSets = 1;
11387 ds_pool_ci.poolSizeCount = 1;
11388 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060011389
Tobin Ehlis3b780662015-05-28 12:11:26 -060011390 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011391 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011392 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -060011393 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011394 dsl_binding.binding = 0;
11395 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11396 dsl_binding.descriptorCount = 1;
11397 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11398 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011399
Tony Barboureb254902015-07-15 12:50:33 -060011400 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011401 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11402 ds_layout_ci.pNext = NULL;
11403 ds_layout_ci.bindingCount = 1;
11404 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060011405
Tobin Ehlis3b780662015-05-28 12:11:26 -060011406 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011407 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011408 ASSERT_VK_SUCCESS(err);
11409
11410 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011411 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011412 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011413 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011414 alloc_info.descriptorPool = ds_pool;
11415 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011416 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011417 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011418
Tony Barboureb254902015-07-15 12:50:33 -060011419 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011420 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11421 sampler_ci.pNext = NULL;
11422 sampler_ci.magFilter = VK_FILTER_NEAREST;
11423 sampler_ci.minFilter = VK_FILTER_NEAREST;
11424 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11425 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11426 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11427 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11428 sampler_ci.mipLodBias = 1.0;
11429 sampler_ci.anisotropyEnable = VK_FALSE;
11430 sampler_ci.maxAnisotropy = 1;
11431 sampler_ci.compareEnable = VK_FALSE;
11432 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11433 sampler_ci.minLod = 1.0;
11434 sampler_ci.maxLod = 1.0;
11435 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11436 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011437 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011438 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011439 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011440
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060011441 VkDescriptorImageInfo info = {};
11442 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011443
11444 VkWriteDescriptorSet descriptor_write;
11445 memset(&descriptor_write, 0, sizeof(descriptor_write));
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011446 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011447 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011448 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011449 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011450 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060011451 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011452
11453 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11454
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011455 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011456
Chia-I Wuf7458c52015-10-26 21:10:41 +080011457 vkDestroySampler(m_device->device(), sampler, NULL);
11458 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11459 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060011460}
11461
Karl Schultz6addd812016-02-02 17:17:23 -070011462TEST_F(VkLayerTest, SampleDescriptorUpdateError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011463 // Create a single Sampler descriptor and send it an invalid Sampler
Karl Schultz6addd812016-02-02 17:17:23 -070011464 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011465
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070011466 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00942);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011467
Tony Barbour1fa09702017-03-16 12:09:08 -060011468 ASSERT_NO_FATAL_FAILURE(Init());
Karl Schultz6addd812016-02-02 17:17:23 -070011469 // TODO : Farm Descriptor setup code to helper function(s) to reduce copied
11470 // code
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011471 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011472 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
11473 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011474
11475 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011476 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11477 ds_pool_ci.pNext = NULL;
11478 ds_pool_ci.maxSets = 1;
11479 ds_pool_ci.poolSizeCount = 1;
11480 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011481
11482 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011483 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011484 ASSERT_VK_SUCCESS(err);
11485
11486 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011487 dsl_binding.binding = 0;
11488 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
11489 dsl_binding.descriptorCount = 1;
11490 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11491 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011492
11493 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011494 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11495 ds_layout_ci.pNext = NULL;
11496 ds_layout_ci.bindingCount = 1;
11497 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011498 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011499 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011500 ASSERT_VK_SUCCESS(err);
11501
11502 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011503 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011504 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011505 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011506 alloc_info.descriptorPool = ds_pool;
11507 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011508 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011509 ASSERT_VK_SUCCESS(err);
11510
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011511 VkSampler sampler = (VkSampler)((size_t)0xbaadbeef); // Sampler with invalid handle
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011512
11513 VkDescriptorImageInfo descriptor_info;
11514 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
11515 descriptor_info.sampler = sampler;
11516
11517 VkWriteDescriptorSet descriptor_write;
11518 memset(&descriptor_write, 0, sizeof(descriptor_write));
11519 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011520 descriptor_write.dstSet = descriptorSet;
11521 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011522 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011523 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
11524 descriptor_write.pImageInfo = &descriptor_info;
11525
11526 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11527
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011528 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011529
Chia-I Wuf7458c52015-10-26 21:10:41 +080011530 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11531 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011532}
11533
Karl Schultz6addd812016-02-02 17:17:23 -070011534TEST_F(VkLayerTest, ImageViewDescriptorUpdateError) {
11535 // Create a single combined Image/Sampler descriptor and send it an invalid
11536 // imageView
11537 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011538
Karl Schultzf78bcdd2016-11-30 12:36:01 -070011539 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00943);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011540
Tony Barbour1fa09702017-03-16 12:09:08 -060011541 ASSERT_NO_FATAL_FAILURE(Init());
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011542 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011543 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11544 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011545
11546 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011547 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11548 ds_pool_ci.pNext = NULL;
11549 ds_pool_ci.maxSets = 1;
11550 ds_pool_ci.poolSizeCount = 1;
11551 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011552
11553 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011554 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011555 ASSERT_VK_SUCCESS(err);
11556
11557 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011558 dsl_binding.binding = 0;
11559 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11560 dsl_binding.descriptorCount = 1;
11561 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11562 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011563
11564 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011565 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11566 ds_layout_ci.pNext = NULL;
11567 ds_layout_ci.bindingCount = 1;
11568 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011569 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011570 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011571 ASSERT_VK_SUCCESS(err);
11572
11573 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011574 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011575 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011576 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011577 alloc_info.descriptorPool = ds_pool;
11578 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011579 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011580 ASSERT_VK_SUCCESS(err);
11581
11582 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011583 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11584 sampler_ci.pNext = NULL;
11585 sampler_ci.magFilter = VK_FILTER_NEAREST;
11586 sampler_ci.minFilter = VK_FILTER_NEAREST;
11587 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11588 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11589 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11590 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11591 sampler_ci.mipLodBias = 1.0;
11592 sampler_ci.anisotropyEnable = VK_FALSE;
11593 sampler_ci.maxAnisotropy = 1;
11594 sampler_ci.compareEnable = VK_FALSE;
11595 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11596 sampler_ci.minLod = 1.0;
11597 sampler_ci.maxLod = 1.0;
11598 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11599 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011600
11601 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011602 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011603 ASSERT_VK_SUCCESS(err);
11604
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011605 VkImageView view = (VkImageView)((size_t)0xbaadbeef); // invalid imageView object
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011606
11607 VkDescriptorImageInfo descriptor_info;
11608 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
11609 descriptor_info.sampler = sampler;
11610 descriptor_info.imageView = view;
11611
11612 VkWriteDescriptorSet descriptor_write;
11613 memset(&descriptor_write, 0, sizeof(descriptor_write));
11614 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011615 descriptor_write.dstSet = descriptorSet;
11616 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011617 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011618 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11619 descriptor_write.pImageInfo = &descriptor_info;
11620
11621 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11622
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011623 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011624
Chia-I Wuf7458c52015-10-26 21:10:41 +080011625 vkDestroySampler(m_device->device(), sampler, NULL);
11626 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11627 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011628}
11629
Karl Schultz6addd812016-02-02 17:17:23 -070011630TEST_F(VkLayerTest, CopyDescriptorUpdateErrors) {
11631 // Create DS w/ layout of 2 types, write update 1 and attempt to copy-update
11632 // into the other
11633 VkResult err;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011634
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011635 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11636 " binding #1 with type "
11637 "VK_DESCRIPTOR_TYPE_SAMPLER. Types do "
11638 "not match.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011639
Tony Barbour1fa09702017-03-16 12:09:08 -060011640 ASSERT_NO_FATAL_FAILURE(Init());
Karl Schultz6addd812016-02-02 17:17:23 -070011641 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011642 VkDescriptorPoolSize ds_type_count[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011643 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11644 ds_type_count[0].descriptorCount = 1;
11645 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
11646 ds_type_count[1].descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011647
11648 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011649 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11650 ds_pool_ci.pNext = NULL;
11651 ds_pool_ci.maxSets = 1;
11652 ds_pool_ci.poolSizeCount = 2;
11653 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011654
11655 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011656 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis04356f92015-10-27 16:35:27 -060011657 ASSERT_VK_SUCCESS(err);
11658 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011659 dsl_binding[0].binding = 0;
11660 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11661 dsl_binding[0].descriptorCount = 1;
11662 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
11663 dsl_binding[0].pImmutableSamplers = NULL;
11664 dsl_binding[1].binding = 1;
11665 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
11666 dsl_binding[1].descriptorCount = 1;
11667 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
11668 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011669
11670 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011671 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11672 ds_layout_ci.pNext = NULL;
11673 ds_layout_ci.bindingCount = 2;
11674 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011675
11676 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011677 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis04356f92015-10-27 16:35:27 -060011678 ASSERT_VK_SUCCESS(err);
11679
11680 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011681 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011682 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011683 alloc_info.descriptorSetCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011684 alloc_info.descriptorPool = ds_pool;
11685 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011686 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis04356f92015-10-27 16:35:27 -060011687 ASSERT_VK_SUCCESS(err);
11688
11689 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011690 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11691 sampler_ci.pNext = NULL;
11692 sampler_ci.magFilter = VK_FILTER_NEAREST;
11693 sampler_ci.minFilter = VK_FILTER_NEAREST;
11694 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11695 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11696 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11697 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11698 sampler_ci.mipLodBias = 1.0;
11699 sampler_ci.anisotropyEnable = VK_FALSE;
11700 sampler_ci.maxAnisotropy = 1;
11701 sampler_ci.compareEnable = VK_FALSE;
11702 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11703 sampler_ci.minLod = 1.0;
11704 sampler_ci.maxLod = 1.0;
11705 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11706 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011707
11708 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011709 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis04356f92015-10-27 16:35:27 -060011710 ASSERT_VK_SUCCESS(err);
11711
11712 VkDescriptorImageInfo info = {};
11713 info.sampler = sampler;
11714
11715 VkWriteDescriptorSet descriptor_write;
11716 memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet));
11717 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011718 descriptor_write.dstSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011719 descriptor_write.dstBinding = 1; // SAMPLER binding from layout above
Chia-I Wud50a7d72015-10-26 20:48:51 +080011720 descriptor_write.descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011721 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
11722 descriptor_write.pImageInfo = &info;
11723 // This write update should succeed
11724 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11725 // Now perform a copy update that fails due to type mismatch
11726 VkCopyDescriptorSet copy_ds_update;
11727 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
11728 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
11729 copy_ds_update.srcSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011730 copy_ds_update.srcBinding = 1; // Copy from SAMPLER binding
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011731 copy_ds_update.dstSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011732 copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding
11733 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -060011734 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
11735
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011736 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -060011737 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011738 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " does not have copy update src binding of 3.");
Tobin Ehlis04356f92015-10-27 16:35:27 -060011739 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
11740 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
11741 copy_ds_update.srcSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011742 copy_ds_update.srcBinding = 3; // ERROR : Invalid binding for matching layout
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011743 copy_ds_update.dstSet = descriptorSet;
11744 copy_ds_update.dstBinding = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011745 copy_ds_update.descriptorCount = 1; // Copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -060011746 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
11747
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011748 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011749
Tobin Ehlis04356f92015-10-27 16:35:27 -060011750 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011751 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11752 " binding#1 with offset index of 1 plus "
11753 "update array offset of 0 and update of "
11754 "5 descriptors oversteps total number "
11755 "of descriptors in set: 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011756
Tobin Ehlis04356f92015-10-27 16:35:27 -060011757 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
11758 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
11759 copy_ds_update.srcSet = descriptorSet;
11760 copy_ds_update.srcBinding = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011761 copy_ds_update.dstSet = descriptorSet;
11762 copy_ds_update.dstBinding = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011763 copy_ds_update.descriptorCount = 5; // ERROR copy 5 descriptors (out of bounds for layout)
Tobin Ehlis04356f92015-10-27 16:35:27 -060011764 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
11765
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011766 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -060011767
Chia-I Wuf7458c52015-10-26 21:10:41 +080011768 vkDestroySampler(m_device->device(), sampler, NULL);
11769 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11770 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis04356f92015-10-27 16:35:27 -060011771}
11772
Karl Schultz6addd812016-02-02 17:17:23 -070011773TEST_F(VkLayerTest, NumSamplesMismatch) {
11774 // Create CommandBuffer where MSAA samples doesn't match RenderPass
11775 // sampleCount
11776 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011777
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011778 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Num samples mismatch! ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011779
Tony Barbour1fa09702017-03-16 12:09:08 -060011780 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis3b780662015-05-28 12:11:26 -060011781 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011782 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -060011783 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011784 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011785
11786 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011787 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11788 ds_pool_ci.pNext = NULL;
11789 ds_pool_ci.maxSets = 1;
11790 ds_pool_ci.poolSizeCount = 1;
11791 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060011792
Tobin Ehlis3b780662015-05-28 12:11:26 -060011793 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011794 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011795 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011796
Tony Barboureb254902015-07-15 12:50:33 -060011797 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +080011798 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -060011799 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +080011800 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011801 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11802 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011803
Tony Barboureb254902015-07-15 12:50:33 -060011804 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11805 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11806 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011807 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -070011808 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060011809
Tobin Ehlis3b780662015-05-28 12:11:26 -060011810 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011811 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011812 ASSERT_VK_SUCCESS(err);
11813
11814 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011815 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011816 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011817 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011818 alloc_info.descriptorPool = ds_pool;
11819 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011820 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011821 ASSERT_VK_SUCCESS(err);
11822
Tony Barboureb254902015-07-15 12:50:33 -060011823 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011824 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070011825 pipe_ms_state_ci.pNext = NULL;
11826 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
11827 pipe_ms_state_ci.sampleShadingEnable = 0;
11828 pipe_ms_state_ci.minSampleShading = 1.0;
11829 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011830
Tony Barboureb254902015-07-15 12:50:33 -060011831 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011832 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11833 pipeline_layout_ci.pNext = NULL;
11834 pipeline_layout_ci.setLayoutCount = 1;
11835 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011836
11837 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011838 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011839 ASSERT_VK_SUCCESS(err);
11840
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011841 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011842 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011843 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011844 VkPipelineObj pipe(m_device);
11845 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060011846 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -060011847 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011848 pipe.SetMSAA(&pipe_ms_state_ci);
11849 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis3b780662015-05-28 12:11:26 -060011850
Tony Barbour552f6c02016-12-21 14:34:07 -070011851 m_commandBuffer->BeginCommandBuffer();
11852 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011853 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis3b780662015-05-28 12:11:26 -060011854
Rene Lindsay3bdc7a42017-01-06 13:20:15 -070011855 VkViewport viewport = {0, 0, 16, 16, 0, 1};
11856 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
11857 VkRect2D scissor = {{0, 0}, {16, 16}};
11858 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
11859
Mark Young29927482016-05-04 14:38:51 -060011860 // Render triangle (the error should trigger on the attempt to draw).
11861 Draw(3, 1, 0, 0);
11862
11863 // Finalize recording of the command buffer
Tony Barbour552f6c02016-12-21 14:34:07 -070011864 m_commandBuffer->EndRenderPass();
11865 m_commandBuffer->EndCommandBuffer();
Mark Young29927482016-05-04 14:38:51 -060011866
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011867 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011868
Chia-I Wuf7458c52015-10-26 21:10:41 +080011869 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11870 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11871 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060011872}
Mark Young29927482016-05-04 14:38:51 -060011873
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011874TEST_F(VkLayerTest, RenderPassIncompatible) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011875 TEST_DESCRIPTION(
11876 "Hit RenderPass incompatible cases. "
11877 "Initial case is drawing with an active renderpass that's "
11878 "not compatible with the bound pipeline state object's creation renderpass");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011879 VkResult err;
11880
Tony Barbour1fa09702017-03-16 12:09:08 -060011881 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011882 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11883
11884 VkDescriptorSetLayoutBinding dsl_binding = {};
11885 dsl_binding.binding = 0;
11886 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11887 dsl_binding.descriptorCount = 1;
11888 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11889 dsl_binding.pImmutableSamplers = NULL;
11890
11891 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11892 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11893 ds_layout_ci.pNext = NULL;
11894 ds_layout_ci.bindingCount = 1;
11895 ds_layout_ci.pBindings = &dsl_binding;
11896
11897 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011898 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011899 ASSERT_VK_SUCCESS(err);
11900
11901 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11902 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11903 pipeline_layout_ci.pNext = NULL;
11904 pipeline_layout_ci.setLayoutCount = 1;
11905 pipeline_layout_ci.pSetLayouts = &ds_layout;
11906
11907 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011908 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011909 ASSERT_VK_SUCCESS(err);
11910
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011911 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011912 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011913 // but add it to be able to run on more devices
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011914 // Create a renderpass that will be incompatible with default renderpass
11915 VkAttachmentReference attach = {};
Cort Stratton7547f772017-05-04 15:18:52 -070011916 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011917 VkAttachmentReference color_att = {};
Cort Stratton7547f772017-05-04 15:18:52 -070011918 color_att.layout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011919 VkSubpassDescription subpass = {};
11920 subpass.inputAttachmentCount = 1;
11921 subpass.pInputAttachments = &attach;
11922 subpass.colorAttachmentCount = 1;
11923 subpass.pColorAttachments = &color_att;
11924 VkRenderPassCreateInfo rpci = {};
11925 rpci.subpassCount = 1;
11926 rpci.pSubpasses = &subpass;
11927 rpci.attachmentCount = 1;
11928 VkAttachmentDescription attach_desc = {};
11929 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Cody Northropbd16af12016-06-21 09:25:48 -060011930 // Format incompatible with PSO RP color attach format B8G8R8A8_UNORM
11931 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011932 rpci.pAttachments = &attach_desc;
11933 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
11934 VkRenderPass rp;
11935 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11936 VkPipelineObj pipe(m_device);
11937 pipe.AddShader(&vs);
11938 pipe.AddShader(&fs);
11939 pipe.AddColorAttachment();
11940 VkViewport view_port = {};
11941 m_viewports.push_back(view_port);
11942 pipe.SetViewport(m_viewports);
11943 VkRect2D rect = {};
11944 m_scissors.push_back(rect);
11945 pipe.SetScissor(m_scissors);
11946 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11947
11948 VkCommandBufferInheritanceInfo cbii = {};
11949 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
11950 cbii.renderPass = rp;
11951 cbii.subpass = 0;
11952 VkCommandBufferBeginInfo cbbi = {};
11953 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
11954 cbbi.pInheritanceInfo = &cbii;
11955 vkBeginCommandBuffer(m_commandBuffer->handle(), &cbbi);
11956 VkRenderPassBeginInfo rpbi = {};
11957 rpbi.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
11958 rpbi.framebuffer = m_framebuffer;
11959 rpbi.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011960 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
11961 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011962
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011963 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is incompatible w/ gfx pipeline ");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011964 // Render triangle (the error should trigger on the attempt to draw).
11965 Draw(3, 1, 0, 0);
11966
11967 // Finalize recording of the command buffer
Tony Barbour552f6c02016-12-21 14:34:07 -070011968 m_commandBuffer->EndRenderPass();
11969 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011970
11971 m_errorMonitor->VerifyFound();
11972
11973 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11974 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11975 vkDestroyRenderPass(m_device->device(), rp, NULL);
11976}
11977
Mark Youngc89c6312016-03-31 16:03:20 -060011978TEST_F(VkLayerTest, NumBlendAttachMismatch) {
11979 // Create Pipeline where the number of blend attachments doesn't match the
11980 // number of color attachments. In this case, we don't add any color
11981 // blend attachments even though we have a color attachment.
11982 VkResult err;
11983
Tobin Ehlis974c0d92017-02-01 13:31:22 -070011984 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02109);
Mark Youngc89c6312016-03-31 16:03:20 -060011985
Tony Barbour1fa09702017-03-16 12:09:08 -060011986 ASSERT_NO_FATAL_FAILURE(Init());
Mark Youngc89c6312016-03-31 16:03:20 -060011987 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11988 VkDescriptorPoolSize ds_type_count = {};
11989 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11990 ds_type_count.descriptorCount = 1;
11991
11992 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11993 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11994 ds_pool_ci.pNext = NULL;
11995 ds_pool_ci.maxSets = 1;
11996 ds_pool_ci.poolSizeCount = 1;
11997 ds_pool_ci.pPoolSizes = &ds_type_count;
11998
11999 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012000 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Youngc89c6312016-03-31 16:03:20 -060012001 ASSERT_VK_SUCCESS(err);
12002
12003 VkDescriptorSetLayoutBinding dsl_binding = {};
12004 dsl_binding.binding = 0;
12005 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12006 dsl_binding.descriptorCount = 1;
12007 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
12008 dsl_binding.pImmutableSamplers = NULL;
12009
12010 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
12011 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12012 ds_layout_ci.pNext = NULL;
12013 ds_layout_ci.bindingCount = 1;
12014 ds_layout_ci.pBindings = &dsl_binding;
12015
12016 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012017 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Youngc89c6312016-03-31 16:03:20 -060012018 ASSERT_VK_SUCCESS(err);
12019
12020 VkDescriptorSet descriptorSet;
12021 VkDescriptorSetAllocateInfo alloc_info = {};
12022 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12023 alloc_info.descriptorSetCount = 1;
12024 alloc_info.descriptorPool = ds_pool;
12025 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012026 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Youngc89c6312016-03-31 16:03:20 -060012027 ASSERT_VK_SUCCESS(err);
12028
12029 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012030 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Youngc89c6312016-03-31 16:03:20 -060012031 pipe_ms_state_ci.pNext = NULL;
12032 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
12033 pipe_ms_state_ci.sampleShadingEnable = 0;
12034 pipe_ms_state_ci.minSampleShading = 1.0;
12035 pipe_ms_state_ci.pSampleMask = NULL;
12036
12037 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12038 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12039 pipeline_layout_ci.pNext = NULL;
12040 pipeline_layout_ci.setLayoutCount = 1;
12041 pipeline_layout_ci.pSetLayouts = &ds_layout;
12042
12043 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012044 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Youngc89c6312016-03-31 16:03:20 -060012045 ASSERT_VK_SUCCESS(err);
12046
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012047 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012048 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012049 // but add it to be able to run on more devices
Mark Youngc89c6312016-03-31 16:03:20 -060012050 VkPipelineObj pipe(m_device);
12051 pipe.AddShader(&vs);
12052 pipe.AddShader(&fs);
12053 pipe.SetMSAA(&pipe_ms_state_ci);
12054 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012055 m_errorMonitor->VerifyFound();
Mark Youngc89c6312016-03-31 16:03:20 -060012056
12057 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12058 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12059 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
12060}
Mark Young29927482016-05-04 14:38:51 -060012061
Mark Muellerd4914412016-06-13 17:52:06 -060012062TEST_F(VkLayerTest, MissingClearAttachment) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012063 TEST_DESCRIPTION(
12064 "Points to a wrong colorAttachment index in a VkClearAttachment "
12065 "structure passed to vkCmdClearAttachments");
Tony Barbour1fa09702017-03-16 12:09:08 -060012066 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012067 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01114);
Mark Muellerd4914412016-06-13 17:52:06 -060012068
12069 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailCmdClearAttachments);
12070 m_errorMonitor->VerifyFound();
12071}
12072
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070012073TEST_F(VkLayerTest, CmdClearAttachmentTests) {
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070012074 TEST_DESCRIPTION("Various tests for validating usage of vkCmdClearAttachments");
12075 VkResult err;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012076
Tony Barbour1fa09702017-03-16 12:09:08 -060012077 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis53eddda2015-07-01 16:46:13 -060012078 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060012079
Chia-I Wu1b99bb22015-10-27 19:25:11 +080012080 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012081 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12082 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060012083
12084 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012085 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12086 ds_pool_ci.pNext = NULL;
12087 ds_pool_ci.maxSets = 1;
12088 ds_pool_ci.poolSizeCount = 1;
12089 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060012090
Tobin Ehlis53eddda2015-07-01 16:46:13 -060012091 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012092 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060012093 ASSERT_VK_SUCCESS(err);
12094
Tony Barboureb254902015-07-15 12:50:33 -060012095 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012096 dsl_binding.binding = 0;
12097 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12098 dsl_binding.descriptorCount = 1;
12099 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
12100 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060012101
Tony Barboureb254902015-07-15 12:50:33 -060012102 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012103 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12104 ds_layout_ci.pNext = NULL;
12105 ds_layout_ci.bindingCount = 1;
12106 ds_layout_ci.pBindings = &dsl_binding;
Mark Lobodzinski209b5292015-09-17 09:44:05 -060012107
Tobin Ehlis53eddda2015-07-01 16:46:13 -060012108 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012109 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060012110 ASSERT_VK_SUCCESS(err);
12111
12112 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012113 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080012114 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070012115 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060012116 alloc_info.descriptorPool = ds_pool;
12117 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012118 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060012119 ASSERT_VK_SUCCESS(err);
12120
Tony Barboureb254902015-07-15 12:50:33 -060012121 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012122 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070012123 pipe_ms_state_ci.pNext = NULL;
12124 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
12125 pipe_ms_state_ci.sampleShadingEnable = 0;
12126 pipe_ms_state_ci.minSampleShading = 1.0;
12127 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060012128
Tony Barboureb254902015-07-15 12:50:33 -060012129 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012130 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12131 pipeline_layout_ci.pNext = NULL;
12132 pipeline_layout_ci.setLayoutCount = 1;
12133 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060012134
12135 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012136 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060012137 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski209b5292015-09-17 09:44:05 -060012138
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012139 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -060012140 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -070012141 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012142 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012143
Tony Barbour62e1a5b2015-08-06 10:16:07 -060012144 VkPipelineObj pipe(m_device);
12145 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060012146 pipe.AddShader(&fs);
Jeremy Hayes7332f342017-03-09 15:54:12 -070012147 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060012148 pipe.SetMSAA(&pipe_ms_state_ci);
12149 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060012150
Tony Barbour552f6c02016-12-21 14:34:07 -070012151 m_commandBuffer->BeginCommandBuffer();
12152 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060012153
Karl Schultz6addd812016-02-02 17:17:23 -070012154 // Main thing we care about for this test is that the VkImage obj we're
12155 // clearing matches Color Attachment of FB
Tobin Ehlis53eddda2015-07-01 16:46:13 -060012156 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -060012157 VkClearAttachment color_attachment;
12158 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12159 color_attachment.clearValue.color.float32[0] = 1.0;
12160 color_attachment.clearValue.color.float32[1] = 1.0;
12161 color_attachment.clearValue.color.float32[2] = 1.0;
12162 color_attachment.clearValue.color.float32[3] = 1.0;
12163 color_attachment.colorAttachment = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012164 VkClearRect clear_rect = {{{0, 0}, {(uint32_t)m_width, (uint32_t)m_height}}};
Tobin Ehlis53eddda2015-07-01 16:46:13 -060012165
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070012166 // Call for full-sized FB Color attachment prior to issuing a Draw
12167 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070012168 "vkCmdClearAttachments() issued on command buffer object ");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012169 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070012170 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012171
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070012172 clear_rect.rect.extent.width = renderPassBeginInfo().renderArea.extent.width + 4;
12173 clear_rect.rect.extent.height = clear_rect.rect.extent.height / 2;
12174 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01115);
12175 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
12176 m_errorMonitor->VerifyFound();
12177
12178 clear_rect.rect.extent.width = (uint32_t)m_width / 2;
12179 clear_rect.layerCount = 2;
12180 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01116);
12181 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012182 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060012183
Chia-I Wuf7458c52015-10-26 21:10:41 +080012184 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12185 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12186 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060012187}
12188
Karl Schultz6addd812016-02-02 17:17:23 -070012189TEST_F(VkLayerTest, VtxBufferBadIndex) {
12190 VkResult err;
Tobin Ehlis502480b2015-06-24 15:53:07 -060012191
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012192 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
12193 "but no vertex buffers are attached to this Pipeline State Object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012194
Tony Barbour1fa09702017-03-16 12:09:08 -060012195 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisd332f282015-10-02 11:00:56 -060012196 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlis502480b2015-06-24 15:53:07 -060012197 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060012198
Chia-I Wu1b99bb22015-10-27 19:25:11 +080012199 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012200 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12201 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060012202
12203 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012204 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12205 ds_pool_ci.pNext = NULL;
12206 ds_pool_ci.maxSets = 1;
12207 ds_pool_ci.poolSizeCount = 1;
12208 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060012209
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060012210 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012211 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis502480b2015-06-24 15:53:07 -060012212 ASSERT_VK_SUCCESS(err);
12213
Tony Barboureb254902015-07-15 12:50:33 -060012214 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012215 dsl_binding.binding = 0;
12216 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12217 dsl_binding.descriptorCount = 1;
12218 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
12219 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060012220
Tony Barboureb254902015-07-15 12:50:33 -060012221 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012222 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12223 ds_layout_ci.pNext = NULL;
12224 ds_layout_ci.bindingCount = 1;
12225 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060012226
Tobin Ehlis502480b2015-06-24 15:53:07 -060012227 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012228 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060012229 ASSERT_VK_SUCCESS(err);
12230
12231 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012232 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080012233 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070012234 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060012235 alloc_info.descriptorPool = ds_pool;
12236 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012237 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis502480b2015-06-24 15:53:07 -060012238 ASSERT_VK_SUCCESS(err);
12239
Tony Barboureb254902015-07-15 12:50:33 -060012240 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012241 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070012242 pipe_ms_state_ci.pNext = NULL;
12243 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
12244 pipe_ms_state_ci.sampleShadingEnable = 0;
12245 pipe_ms_state_ci.minSampleShading = 1.0;
12246 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060012247
Tony Barboureb254902015-07-15 12:50:33 -060012248 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012249 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12250 pipeline_layout_ci.pNext = NULL;
12251 pipeline_layout_ci.setLayoutCount = 1;
12252 pipeline_layout_ci.pSetLayouts = &ds_layout;
12253 VkPipelineLayout pipeline_layout;
Tobin Ehlis502480b2015-06-24 15:53:07 -060012254
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012255 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060012256 ASSERT_VK_SUCCESS(err);
12257
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012258 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012259 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012260 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -060012261 VkPipelineObj pipe(m_device);
12262 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060012263 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -060012264 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060012265 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -060012266 pipe.SetViewport(m_viewports);
12267 pipe.SetScissor(m_scissors);
Tony Barbour62e1a5b2015-08-06 10:16:07 -060012268 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060012269
Tony Barbour552f6c02016-12-21 14:34:07 -070012270 m_commandBuffer->BeginCommandBuffer();
12271 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012272 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisf7bf4502015-09-09 15:12:35 -060012273 // Don't care about actual data, just need to get to draw to flag error
12274 static const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012275 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), (const void *)&vbo_data);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012276 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -060012277 Draw(1, 0, 0, 0);
Tobin Ehlis502480b2015-06-24 15:53:07 -060012278
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012279 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060012280
Chia-I Wuf7458c52015-10-26 21:10:41 +080012281 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12282 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12283 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis502480b2015-06-24 15:53:07 -060012284}
Mark Muellerdfe37552016-07-07 14:47:42 -060012285
Mark Mueller2ee294f2016-08-04 12:59:48 -060012286TEST_F(VkLayerTest, MismatchCountQueueCreateRequestedFeature) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012287 TEST_DESCRIPTION(
12288 "Use an invalid count in a vkEnumeratePhysicalDevices call."
12289 "Use invalid Queue Family Index in vkCreateDevice");
Tony Barbour1fa09702017-03-16 12:09:08 -060012290 ASSERT_NO_FATAL_FAILURE(Init());
Mark Mueller2ee294f2016-08-04 12:59:48 -060012291
Mark Mueller880fce52016-08-17 15:23:23 -060012292 // The following test fails with recent NVidia drivers.
12293 // By the time core_validation is reached, the NVidia
12294 // driver has sanitized the invalid condition and core_validation
12295 // is not introduced to the failure condition. This is not the case
12296 // with AMD and Mesa drivers. Futher investigation is required
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012297 // uint32_t count = static_cast<uint32_t>(~0);
12298 // VkPhysicalDevice physical_device;
12299 // vkEnumeratePhysicalDevices(instance(), &count, &physical_device);
12300 // m_errorMonitor->VerifyFound();
Mark Mueller2ee294f2016-08-04 12:59:48 -060012301
Mark Mueller2ee294f2016-08-04 12:59:48 -060012302 float queue_priority = 0.0;
Mark Mueller2ee294f2016-08-04 12:59:48 -060012303 VkDeviceQueueCreateInfo queue_create_info = {};
12304 queue_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
12305 queue_create_info.queueCount = 1;
12306 queue_create_info.pQueuePriorities = &queue_priority;
12307 queue_create_info.queueFamilyIndex = static_cast<uint32_t>(~0);
12308
12309 VkPhysicalDeviceFeatures features = m_device->phy().features();
12310 VkDevice testDevice;
12311 VkDeviceCreateInfo device_create_info = {};
12312 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
12313 device_create_info.queueCreateInfoCount = 1;
12314 device_create_info.pQueueCreateInfos = &queue_create_info;
12315 device_create_info.pEnabledFeatures = &features;
Jeremy Hayesb26fd042017-03-10 09:13:22 -070012316
Petr Kraus56ed9192017-05-08 23:45:36 +020012317 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00054);
Jeremy Hayes17fd3662017-03-17 11:51:11 -060012318 // The following unexpected error is coming from the LunarG loader. Do not make it a desired message because platforms that do
12319 // not use the LunarG loader (e.g. Android) will not see the message and the test will fail.
12320 m_errorMonitor->SetUnexpectedError("Failed to create device chain.");
Mark Mueller2ee294f2016-08-04 12:59:48 -060012321 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
12322 m_errorMonitor->VerifyFound();
12323
12324 queue_create_info.queueFamilyIndex = 1;
Tobin Ehliscc980e12017-05-19 12:05:49 -060012325 if (m_device->phy().queue_properties().size() < 2) {
12326 queue_create_info.queueFamilyIndex = 0;
12327 }
Mark Mueller2ee294f2016-08-04 12:59:48 -060012328
12329 unsigned feature_count = sizeof(VkPhysicalDeviceFeatures) / sizeof(VkBool32);
12330 VkBool32 *feature_array = reinterpret_cast<VkBool32 *>(&features);
12331 for (unsigned i = 0; i < feature_count; i++) {
12332 if (VK_FALSE == feature_array[i]) {
12333 feature_array[i] = VK_TRUE;
Mark Mueller2ee294f2016-08-04 12:59:48 -060012334 device_create_info.pEnabledFeatures = &features;
Jeremy Hayesb26fd042017-03-10 09:13:22 -070012335 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12336 "While calling vkCreateDevice(), requesting feature #");
Jeremy Hayes17fd3662017-03-17 11:51:11 -060012337 // The following unexpected error is coming from the LunarG loader. Do not make it a desired message because platforms
12338 // that do not use the LunarG loader (e.g. Android) will not see the message and the test will fail.
12339 m_errorMonitor->SetUnexpectedError("Failed to create device chain.");
Jeremy Hayesb26fd042017-03-10 09:13:22 -070012340 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12341 "You requested features that are unavailable on this device. You should first "
12342 "query feature availability by calling vkGetPhysicalDeviceFeatures().");
Mark Mueller2ee294f2016-08-04 12:59:48 -060012343 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
12344 m_errorMonitor->VerifyFound();
12345 break;
12346 }
12347 }
12348}
12349
Tobin Ehlis16edf082016-11-21 12:33:49 -070012350TEST_F(VkLayerTest, InvalidQueryPoolCreate) {
12351 TEST_DESCRIPTION("Attempt to create a query pool for PIPELINE_STATISTICS without enabling pipeline stats for the device.");
12352
Tony Barbour1fa09702017-03-16 12:09:08 -060012353 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis16edf082016-11-21 12:33:49 -070012354
12355 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
12356 std::vector<VkDeviceQueueCreateInfo> queue_info;
12357 queue_info.reserve(queue_props.size());
12358 std::vector<std::vector<float>> queue_priorities;
12359 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
12360 VkDeviceQueueCreateInfo qi{};
12361 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
12362 qi.queueFamilyIndex = i;
12363 qi.queueCount = queue_props[i].queueCount;
12364 queue_priorities.emplace_back(qi.queueCount, 0.0f);
12365 qi.pQueuePriorities = queue_priorities[i].data();
12366 queue_info.push_back(qi);
12367 }
12368
12369 std::vector<const char *> device_extension_names;
12370
12371 VkDevice local_device;
12372 VkDeviceCreateInfo device_create_info = {};
12373 auto features = m_device->phy().features();
12374 // Intentionally disable pipeline stats
12375 features.pipelineStatisticsQuery = VK_FALSE;
12376 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
12377 device_create_info.pNext = NULL;
12378 device_create_info.queueCreateInfoCount = queue_info.size();
12379 device_create_info.pQueueCreateInfos = queue_info.data();
12380 device_create_info.enabledLayerCount = 0;
12381 device_create_info.ppEnabledLayerNames = NULL;
12382 device_create_info.pEnabledFeatures = &features;
12383 VkResult err = vkCreateDevice(gpu(), &device_create_info, nullptr, &local_device);
12384 ASSERT_VK_SUCCESS(err);
12385
12386 VkQueryPoolCreateInfo qpci{};
12387 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
12388 qpci.queryType = VK_QUERY_TYPE_PIPELINE_STATISTICS;
12389 qpci.queryCount = 1;
12390 VkQueryPool query_pool;
12391
12392 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01006);
12393 vkCreateQueryPool(local_device, &qpci, nullptr, &query_pool);
12394 m_errorMonitor->VerifyFound();
12395
12396 vkDestroyDevice(local_device, nullptr);
12397}
12398
Mark Mueller2ee294f2016-08-04 12:59:48 -060012399TEST_F(VkLayerTest, InvalidQueueIndexInvalidQuery) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012400 TEST_DESCRIPTION(
12401 "Use an invalid queue index in a vkCmdWaitEvents call."
12402 "End a command buffer with a query still in progress.");
Mark Mueller2ee294f2016-08-04 12:59:48 -060012403
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012404 const char *invalid_queue_index =
12405 "was created with sharingMode of VK_SHARING_MODE_EXCLUSIVE. If one "
12406 "of src- or dstQueueFamilyIndex is VK_QUEUE_FAMILY_IGNORED, both "
12407 "must be.";
Mark Mueller2ee294f2016-08-04 12:59:48 -060012408
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012409 const char *invalid_query = "Ending command buffer with in progress query: queryPool 0x";
Mark Mueller2ee294f2016-08-04 12:59:48 -060012410
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012411 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queue_index);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012412
Tony Barbour1fa09702017-03-16 12:09:08 -060012413 ASSERT_NO_FATAL_FAILURE(Init());
Mark Mueller2ee294f2016-08-04 12:59:48 -060012414
12415 VkEvent event;
12416 VkEventCreateInfo event_create_info{};
12417 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
12418 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
12419
Mark Mueller2ee294f2016-08-04 12:59:48 -060012420 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012421 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012422
Tony Barbour552f6c02016-12-21 14:34:07 -070012423 m_commandBuffer->BeginCommandBuffer();
Mark Mueller2ee294f2016-08-04 12:59:48 -060012424
12425 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060012426 image.Init(128, 128, 1, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012427 ASSERT_TRUE(image.initialized());
12428 VkImageMemoryBarrier img_barrier = {};
12429 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
12430 img_barrier.pNext = NULL;
12431 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
12432 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
12433 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
12434 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
12435 img_barrier.image = image.handle();
12436 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
Mark Lobodzinski2a74c5c2016-08-17 13:26:28 -060012437
12438 // QueueFamilyIndex must be VK_QUEUE_FAMILY_IGNORED, this verifies
12439 // that layer validation catches the case when it is not.
12440 img_barrier.dstQueueFamilyIndex = 0;
Mark Mueller2ee294f2016-08-04 12:59:48 -060012441 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12442 img_barrier.subresourceRange.baseArrayLayer = 0;
12443 img_barrier.subresourceRange.baseMipLevel = 0;
12444 img_barrier.subresourceRange.layerCount = 1;
12445 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012446 vkCmdWaitEvents(m_commandBuffer->handle(), 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0,
12447 nullptr, 0, nullptr, 1, &img_barrier);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012448 m_errorMonitor->VerifyFound();
12449
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012450 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_query);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012451
12452 VkQueryPool query_pool;
12453 VkQueryPoolCreateInfo query_pool_create_info = {};
12454 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
12455 query_pool_create_info.queryType = VK_QUERY_TYPE_OCCLUSION;
12456 query_pool_create_info.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012457 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012458
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012459 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0 /*startQuery*/, 1 /*queryCount*/);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012460 vkCmdBeginQuery(m_commandBuffer->handle(), query_pool, 0, 0);
12461
12462 vkEndCommandBuffer(m_commandBuffer->handle());
12463 m_errorMonitor->VerifyFound();
12464
12465 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
12466 vkDestroyEvent(m_device->device(), event, nullptr);
12467}
12468
Mark Muellerdfe37552016-07-07 14:47:42 -060012469TEST_F(VkLayerTest, VertexBufferInvalid) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012470 TEST_DESCRIPTION(
12471 "Submit a command buffer using deleted vertex buffer, "
12472 "delete a buffer twice, use an invalid offset for each "
12473 "buffer type, and attempt to bind a null buffer");
Mark Muellerdfe37552016-07-07 14:47:42 -060012474
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012475 const char *deleted_buffer_in_command_buffer =
12476 "Cannot submit cmd buffer "
12477 "using deleted buffer ";
12478 const char *invalid_offset_message =
12479 "vkBindBufferMemory(): "
12480 "memoryOffset is 0x";
12481 const char *invalid_storage_buffer_offset_message =
12482 "vkBindBufferMemory(): "
12483 "storage memoryOffset "
12484 "is 0x";
12485 const char *invalid_texel_buffer_offset_message =
12486 "vkBindBufferMemory(): "
12487 "texel memoryOffset "
12488 "is 0x";
12489 const char *invalid_uniform_buffer_offset_message =
12490 "vkBindBufferMemory(): "
12491 "uniform memoryOffset "
12492 "is 0x";
Mark Muellerdfe37552016-07-07 14:47:42 -060012493
Tony Barbour1fa09702017-03-16 12:09:08 -060012494 ASSERT_NO_FATAL_FAILURE(Init());
Mark Muellerdfe37552016-07-07 14:47:42 -060012495 ASSERT_NO_FATAL_FAILURE(InitViewport());
12496 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12497
12498 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012499 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -060012500 pipe_ms_state_ci.pNext = NULL;
12501 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
12502 pipe_ms_state_ci.sampleShadingEnable = 0;
12503 pipe_ms_state_ci.minSampleShading = 1.0;
12504 pipe_ms_state_ci.pSampleMask = nullptr;
12505
12506 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12507 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12508 VkPipelineLayout pipeline_layout;
12509
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012510 VkResult err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, nullptr, &pipeline_layout);
Mark Muellerdfe37552016-07-07 14:47:42 -060012511 ASSERT_VK_SUCCESS(err);
12512
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012513 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
12514 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Muellerdfe37552016-07-07 14:47:42 -060012515 VkPipelineObj pipe(m_device);
12516 pipe.AddShader(&vs);
12517 pipe.AddShader(&fs);
12518 pipe.AddColorAttachment();
12519 pipe.SetMSAA(&pipe_ms_state_ci);
12520 pipe.SetViewport(m_viewports);
12521 pipe.SetScissor(m_scissors);
12522 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12523
Tony Barbour552f6c02016-12-21 14:34:07 -070012524 m_commandBuffer->BeginCommandBuffer();
12525 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012526 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Muellerdfe37552016-07-07 14:47:42 -060012527
12528 {
12529 // Create and bind a vertex buffer in a reduced scope, which will cause
12530 // it to be deleted upon leaving this scope
12531 const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012532 VkVerticesObj draw_verticies(m_device, 1, 1, sizeof(vbo_data), 3, vbo_data);
Mark Muellerdfe37552016-07-07 14:47:42 -060012533 draw_verticies.BindVertexBuffers(m_commandBuffer->handle());
12534 draw_verticies.AddVertexInputToPipe(pipe);
12535 }
12536
12537 Draw(1, 0, 0, 0);
12538
Tony Barbour552f6c02016-12-21 14:34:07 -070012539 m_commandBuffer->EndRenderPass();
12540 m_commandBuffer->EndCommandBuffer();
Mark Muellerdfe37552016-07-07 14:47:42 -060012541
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012542 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, deleted_buffer_in_command_buffer);
Mark Muellerdfe37552016-07-07 14:47:42 -060012543 QueueCommandBuffer(false);
12544 m_errorMonitor->VerifyFound();
12545
12546 {
12547 // Create and bind a vertex buffer in a reduced scope, and delete it
12548 // twice, the second through the destructor
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012549 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eDoubleDelete);
Karl Schultzf78bcdd2016-11-30 12:36:01 -070012550 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00680);
Mark Muellerdfe37552016-07-07 14:47:42 -060012551 buffer_test.TestDoubleDestroy();
12552 }
12553 m_errorMonitor->VerifyFound();
12554
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012555 m_errorMonitor->SetUnexpectedError("value of pCreateInfo->usage must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012556 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidMemoryOffset)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060012557 // Create and bind a memory buffer with an invalid offset.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012558 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_offset_message);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012559 m_errorMonitor->SetUnexpectedError(
12560 "If buffer was created with the VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT or VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT, "
12561 "memoryOffset must be a multiple of VkPhysicalDeviceLimits::minTexelBufferOffsetAlignment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012562 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidMemoryOffset);
12563 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012564 m_errorMonitor->VerifyFound();
12565 }
12566
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012567 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset,
12568 VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060012569 // Create and bind a memory buffer with an invalid offset again,
12570 // but look for a texel buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012571 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_texel_buffer_offset_message);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012572 m_errorMonitor->SetUnexpectedError(
12573 "memoryOffset must be an integer multiple of the alignment member of the VkMemoryRequirements structure returned from "
12574 "a call to vkGetBufferMemoryRequirements with buffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012575 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
12576 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012577 m_errorMonitor->VerifyFound();
12578 }
12579
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012580 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060012581 // Create and bind a memory buffer with an invalid offset again, but
12582 // look for a uniform buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012583 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_uniform_buffer_offset_message);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012584 m_errorMonitor->SetUnexpectedError(
12585 "memoryOffset must be an integer multiple of the alignment member of the VkMemoryRequirements structure returned from "
12586 "a call to vkGetBufferMemoryRequirements with buffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012587 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
12588 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012589 m_errorMonitor->VerifyFound();
12590 }
12591
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012592 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060012593 // Create and bind a memory buffer with an invalid offset again, but
12594 // look for a storage buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012595 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_storage_buffer_offset_message);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012596 m_errorMonitor->SetUnexpectedError(
12597 "memoryOffset must be an integer multiple of the alignment member of the VkMemoryRequirements structure returned from "
12598 "a call to vkGetBufferMemoryRequirements with buffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012599 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
12600 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012601 m_errorMonitor->VerifyFound();
12602 }
12603
12604 {
12605 // Attempt to bind a null buffer.
Karl Schultzf78bcdd2016-11-30 12:36:01 -070012606 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00799);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012607 m_errorMonitor->SetUnexpectedError("required parameter memory specified as VK_NULL_HANDLE");
12608 m_errorMonitor->SetUnexpectedError("memory must be a valid VkDeviceMemory handle");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012609 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eBindNullBuffer);
12610 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012611 m_errorMonitor->VerifyFound();
12612 }
12613
12614 {
12615 // Attempt to use an invalid handle to delete a buffer.
Karl Schultzf78bcdd2016-11-30 12:36:01 -070012616 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00622);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012617 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eFreeInvalidHandle);
12618 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012619 }
12620 m_errorMonitor->VerifyFound();
12621
12622 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12623}
12624
Tony Barbourff1351e2017-05-10 11:14:03 -060012625TEST_F(VkLayerTest, BadVertexBufferOffset) {
12626 TEST_DESCRIPTION("Submit an offset past the end of a vertex buffer");
12627
12628 ASSERT_NO_FATAL_FAILURE(Init());
12629 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12630 static const float vbo_data[3] = {1.f, 0.f, 1.f};
Tony Barboure94224e2017-05-11 15:22:43 -060012631 VkConstantBufferObj vbo(m_device, 3, sizeof(float), (const void *)&vbo_data);
Tony Barbourff1351e2017-05-10 11:14:03 -060012632 m_commandBuffer->BeginCommandBuffer();
12633 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
12634 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01417);
Tony Barboure94224e2017-05-11 15:22:43 -060012635 BindVertexBuffer(&vbo, (VkDeviceSize)(3 * sizeof(float)), 1); // Offset at the end of the buffer
Tony Barbourff1351e2017-05-10 11:14:03 -060012636 m_errorMonitor->VerifyFound();
12637}
12638
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012639// INVALID_IMAGE_LAYOUT tests (one other case is hit by MapMemWithoutHostVisibleBit and not here)
12640TEST_F(VkLayerTest, InvalidImageLayout) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012641 TEST_DESCRIPTION(
12642 "Hit all possible validation checks associated with the "
12643 "DRAWSTATE_INVALID_IMAGE_LAYOUT enum. Generally these involve having"
12644 "images in the wrong layout when they're copied or transitioned.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012645 // 3 in ValidateCmdBufImageLayouts
12646 // * -1 Attempt to submit cmd buf w/ deleted image
12647 // * -2 Cmd buf submit of image w/ layout not matching first use w/ subresource
12648 // * -3 Cmd buf submit of image w/ layout not matching first use w/o subresource
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012649
Tony Barbour1fa09702017-03-16 12:09:08 -060012650 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -060012651 auto depth_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbourf887b162017-03-09 10:06:46 -070012652 if (!depth_format) {
12653 printf(" No Depth + Stencil format found. Skipped.\n");
12654 return;
12655 }
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012656 // Create src & dst images to use for copy operations
12657 VkImage src_image;
12658 VkImage dst_image;
Cort3b021012016-12-07 12:00:57 -080012659 VkImage depth_image;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012660
12661 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
12662 const int32_t tex_width = 32;
12663 const int32_t tex_height = 32;
12664
12665 VkImageCreateInfo image_create_info = {};
12666 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
12667 image_create_info.pNext = NULL;
12668 image_create_info.imageType = VK_IMAGE_TYPE_2D;
12669 image_create_info.format = tex_format;
12670 image_create_info.extent.width = tex_width;
12671 image_create_info.extent.height = tex_height;
12672 image_create_info.extent.depth = 1;
12673 image_create_info.mipLevels = 1;
12674 image_create_info.arrayLayers = 4;
12675 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
12676 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
12677 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Cort3b021012016-12-07 12:00:57 -080012678 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012679 image_create_info.flags = 0;
12680
12681 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &src_image);
12682 ASSERT_VK_SUCCESS(err);
Cort3b021012016-12-07 12:00:57 -080012683 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012684 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dst_image);
12685 ASSERT_VK_SUCCESS(err);
Cort3b021012016-12-07 12:00:57 -080012686 image_create_info.format = VK_FORMAT_D32_SFLOAT;
12687 image_create_info.usage |= VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
12688 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &depth_image);
12689 ASSERT_VK_SUCCESS(err);
12690
12691 // Allocate memory
12692 VkMemoryRequirements img_mem_reqs = {};
Cort530cf382016-12-08 09:59:47 -080012693 VkMemoryAllocateInfo mem_alloc = {};
Cort3b021012016-12-07 12:00:57 -080012694 VkDeviceMemory src_image_mem, dst_image_mem, depth_image_mem;
Cort530cf382016-12-08 09:59:47 -080012695 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
12696 mem_alloc.pNext = NULL;
12697 mem_alloc.allocationSize = 0;
12698 mem_alloc.memoryTypeIndex = 0;
Cort3b021012016-12-07 12:00:57 -080012699
12700 vkGetImageMemoryRequirements(m_device->device(), src_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080012701 mem_alloc.allocationSize = img_mem_reqs.size;
12702 bool pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080012703 ASSERT_TRUE(pass);
Cort530cf382016-12-08 09:59:47 -080012704 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &src_image_mem);
Cort3b021012016-12-07 12:00:57 -080012705 ASSERT_VK_SUCCESS(err);
12706
12707 vkGetImageMemoryRequirements(m_device->device(), dst_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080012708 mem_alloc.allocationSize = img_mem_reqs.size;
12709 pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080012710 ASSERT_VK_SUCCESS(err);
Cort530cf382016-12-08 09:59:47 -080012711 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &dst_image_mem);
Cort3b021012016-12-07 12:00:57 -080012712 ASSERT_VK_SUCCESS(err);
12713
12714 vkGetImageMemoryRequirements(m_device->device(), depth_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080012715 mem_alloc.allocationSize = img_mem_reqs.size;
12716 pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080012717 ASSERT_VK_SUCCESS(err);
Cort530cf382016-12-08 09:59:47 -080012718 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &depth_image_mem);
Cort3b021012016-12-07 12:00:57 -080012719 ASSERT_VK_SUCCESS(err);
12720
12721 err = vkBindImageMemory(m_device->device(), src_image, src_image_mem, 0);
12722 ASSERT_VK_SUCCESS(err);
12723 err = vkBindImageMemory(m_device->device(), dst_image, dst_image_mem, 0);
12724 ASSERT_VK_SUCCESS(err);
12725 err = vkBindImageMemory(m_device->device(), depth_image, depth_image_mem, 0);
12726 ASSERT_VK_SUCCESS(err);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012727
Tony Barbour552f6c02016-12-21 14:34:07 -070012728 m_commandBuffer->BeginCommandBuffer();
Cort530cf382016-12-08 09:59:47 -080012729 VkImageCopy copy_region;
12730 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12731 copy_region.srcSubresource.mipLevel = 0;
12732 copy_region.srcSubresource.baseArrayLayer = 0;
12733 copy_region.srcSubresource.layerCount = 1;
12734 copy_region.srcOffset.x = 0;
12735 copy_region.srcOffset.y = 0;
12736 copy_region.srcOffset.z = 0;
12737 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12738 copy_region.dstSubresource.mipLevel = 0;
12739 copy_region.dstSubresource.baseArrayLayer = 0;
12740 copy_region.dstSubresource.layerCount = 1;
12741 copy_region.dstOffset.x = 0;
12742 copy_region.dstOffset.y = 0;
12743 copy_region.dstOffset.z = 0;
12744 copy_region.extent.width = 1;
12745 copy_region.extent.height = 1;
12746 copy_region.extent.depth = 1;
12747
Mark Lobodzinski91c28262017-03-22 13:06:12 -060012748 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
12749 "layout should be VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL instead of GENERAL.");
12750 m_errorMonitor->SetUnexpectedError("layout should be VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL instead of GENERAL.");
Tobin Ehlis74cc6822017-03-14 16:16:51 -060012751
Cort530cf382016-12-08 09:59:47 -080012752 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copy_region);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012753 m_errorMonitor->VerifyFound();
Tobin Ehlise35b66a2017-03-15 12:18:31 -060012754 // The first call hits the expected WARNING and skips the call down the chain, so call a second time to call down chain and
12755 // update layer state
Mark Lobodzinski91c28262017-03-22 13:06:12 -060012756 m_errorMonitor->SetUnexpectedError("layout should be VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL instead of GENERAL.");
12757 m_errorMonitor->SetUnexpectedError("layout should be VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL instead of GENERAL.");
Tobin Ehlise35b66a2017-03-15 12:18:31 -060012758 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copy_region);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012759 // Now cause error due to src image layout changing
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012760 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski91c28262017-03-22 13:06:12 -060012761 "with specific layout VK_IMAGE_LAYOUT_UNDEFINED that "
12762 "doesn't match the actual current layout VK_IMAGE_LAYOUT_GENERAL.");
Mark Lobodzinskic61e1da2017-05-15 16:18:13 -060012763 m_errorMonitor->SetUnexpectedError("is VK_IMAGE_LAYOUT_UNDEFINED but can only be VK_IMAGE_LAYOUT");
Cort530cf382016-12-08 09:59:47 -080012764 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copy_region);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012765 m_errorMonitor->VerifyFound();
12766 // Final src error is due to bad layout type
Tobin Ehlis74cc6822017-03-14 16:16:51 -060012767 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski91c28262017-03-22 13:06:12 -060012768 "is VK_IMAGE_LAYOUT_UNDEFINED but can only be "
Tobin Ehlis74cc6822017-03-14 16:16:51 -060012769 "VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL or VK_IMAGE_LAYOUT_GENERAL.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012770 m_errorMonitor->SetUnexpectedError(
Mark Lobodzinski91c28262017-03-22 13:06:12 -060012771 "with specific layout VK_IMAGE_LAYOUT_UNDEFINED that doesn't match the actual current layout VK_IMAGE_LAYOUT_GENERAL.");
Cort530cf382016-12-08 09:59:47 -080012772 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copy_region);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012773 m_errorMonitor->VerifyFound();
12774 // Now verify same checks for dst
Mark Lobodzinski91c28262017-03-22 13:06:12 -060012775 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
12776 "layout should be VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL instead of GENERAL.");
12777 m_errorMonitor->SetUnexpectedError("layout should be VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL instead of GENERAL.");
Cort530cf382016-12-08 09:59:47 -080012778 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copy_region);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012779 m_errorMonitor->VerifyFound();
12780 // Now cause error due to src image layout changing
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012781 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski91c28262017-03-22 13:06:12 -060012782 "with specific layout VK_IMAGE_LAYOUT_UNDEFINED that doesn't match "
Tobin Ehlis74cc6822017-03-14 16:16:51 -060012783 "the actual current layout VK_IMAGE_LAYOUT_GENERAL.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012784 m_errorMonitor->SetUnexpectedError(
Mark Lobodzinski91c28262017-03-22 13:06:12 -060012785 "is VK_IMAGE_LAYOUT_UNDEFINED but can only be VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL or VK_IMAGE_LAYOUT_GENERAL.");
Cort530cf382016-12-08 09:59:47 -080012786 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, &copy_region);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012787 m_errorMonitor->VerifyFound();
Tobin Ehlis74cc6822017-03-14 16:16:51 -060012788 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski91c28262017-03-22 13:06:12 -060012789 "is VK_IMAGE_LAYOUT_UNDEFINED but can only be VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL "
12790 "or VK_IMAGE_LAYOUT_GENERAL.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012791 m_errorMonitor->SetUnexpectedError(
Mark Lobodzinski91c28262017-03-22 13:06:12 -060012792 "with specific layout VK_IMAGE_LAYOUT_UNDEFINED that doesn't match the actual current layout VK_IMAGE_LAYOUT_GENERAL.");
Cort530cf382016-12-08 09:59:47 -080012793 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, &copy_region);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012794 m_errorMonitor->VerifyFound();
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010012795
Cort3b021012016-12-07 12:00:57 -080012796 // Convert dst and depth images to TRANSFER_DST for subsequent tests
12797 VkImageMemoryBarrier transfer_dst_image_barrier[1] = {};
12798 transfer_dst_image_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
12799 transfer_dst_image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
12800 transfer_dst_image_barrier[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
12801 transfer_dst_image_barrier[0].srcAccessMask = 0;
12802 transfer_dst_image_barrier[0].dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
12803 transfer_dst_image_barrier[0].image = dst_image;
12804 transfer_dst_image_barrier[0].subresourceRange.layerCount = image_create_info.arrayLayers;
12805 transfer_dst_image_barrier[0].subresourceRange.levelCount = image_create_info.mipLevels;
12806 transfer_dst_image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12807 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
12808 NULL, 0, NULL, 1, transfer_dst_image_barrier);
12809 transfer_dst_image_barrier[0].image = depth_image;
12810 transfer_dst_image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
12811 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
12812 NULL, 0, NULL, 1, transfer_dst_image_barrier);
12813
12814 // Cause errors due to clearing with invalid image layouts
Cort530cf382016-12-08 09:59:47 -080012815 VkClearColorValue color_clear_value = {};
12816 VkImageSubresourceRange clear_range;
12817 clear_range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12818 clear_range.baseMipLevel = 0;
12819 clear_range.baseArrayLayer = 0;
12820 clear_range.layerCount = 1;
12821 clear_range.levelCount = 1;
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010012822
Cort3b021012016-12-07 12:00:57 -080012823 // Fail due to explicitly prohibited layout for color clear (only GENERAL and TRANSFER_DST are permitted).
12824 // Since the image is currently not in UNDEFINED layout, this will emit two errors.
12825 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01086);
12826 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01085);
Cort530cf382016-12-08 09:59:47 -080012827 m_commandBuffer->ClearColorImage(dst_image, VK_IMAGE_LAYOUT_UNDEFINED, &color_clear_value, 1, &clear_range);
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010012828 m_errorMonitor->VerifyFound();
Cort3b021012016-12-07 12:00:57 -080012829 // Fail due to provided layout not matching actual current layout for color clear.
12830 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01085);
Cort530cf382016-12-08 09:59:47 -080012831 m_commandBuffer->ClearColorImage(dst_image, VK_IMAGE_LAYOUT_GENERAL, &color_clear_value, 1, &clear_range);
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010012832 m_errorMonitor->VerifyFound();
Cort3b021012016-12-07 12:00:57 -080012833
Cort530cf382016-12-08 09:59:47 -080012834 VkClearDepthStencilValue depth_clear_value = {};
12835 clear_range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Cort3b021012016-12-07 12:00:57 -080012836
12837 // Fail due to explicitly prohibited layout for depth clear (only GENERAL and TRANSFER_DST are permitted).
12838 // Since the image is currently not in UNDEFINED layout, this will emit two errors.
12839 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01101);
12840 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01100);
Cort530cf382016-12-08 09:59:47 -080012841 m_commandBuffer->ClearDepthStencilImage(depth_image, VK_IMAGE_LAYOUT_UNDEFINED, &depth_clear_value, 1, &clear_range);
Cort3b021012016-12-07 12:00:57 -080012842 m_errorMonitor->VerifyFound();
12843 // Fail due to provided layout not matching actual current layout for depth clear.
12844 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01100);
Cort530cf382016-12-08 09:59:47 -080012845 m_commandBuffer->ClearDepthStencilImage(depth_image, VK_IMAGE_LAYOUT_GENERAL, &depth_clear_value, 1, &clear_range);
Cort3b021012016-12-07 12:00:57 -080012846 m_errorMonitor->VerifyFound();
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010012847
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012848 // Now cause error due to bad image layout transition in PipelineBarrier
12849 VkImageMemoryBarrier image_barrier[1] = {};
Cort3b021012016-12-07 12:00:57 -080012850 image_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012851 image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
Cort3b021012016-12-07 12:00:57 -080012852 image_barrier[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012853 image_barrier[0].image = src_image;
Cort3b021012016-12-07 12:00:57 -080012854 image_barrier[0].subresourceRange.layerCount = image_create_info.arrayLayers;
12855 image_barrier[0].subresourceRange.levelCount = image_create_info.mipLevels;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012856 image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012857 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski91c28262017-03-22 13:06:12 -060012858 "you cannot transition the layout of aspect 1 from "
12859 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL when current layout is "
12860 "VK_IMAGE_LAYOUT_GENERAL.");
Mike Weiblen62d08a32017-03-07 22:18:27 -070012861 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00305);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012862 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
12863 NULL, 0, NULL, 1, image_barrier);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012864 m_errorMonitor->VerifyFound();
12865
12866 // Finally some layout errors at RenderPass create time
12867 // Just hacking in specific state to get to the errors we want so don't copy this unless you know what you're doing.
12868 VkAttachmentReference attach = {};
12869 // perf warning for GENERAL layout w/ non-DS input attachment
12870 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
12871 VkSubpassDescription subpass = {};
12872 subpass.inputAttachmentCount = 1;
12873 subpass.pInputAttachments = &attach;
12874 VkRenderPassCreateInfo rpci = {};
12875 rpci.subpassCount = 1;
12876 rpci.pSubpasses = &subpass;
12877 rpci.attachmentCount = 1;
12878 VkAttachmentDescription attach_desc = {};
12879 attach_desc.format = VK_FORMAT_UNDEFINED;
12880 rpci.pAttachments = &attach_desc;
Tobin Ehlis1efce022016-05-11 10:40:34 -060012881 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012882 VkRenderPass rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012883 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
12884 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012885 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12886 m_errorMonitor->VerifyFound();
12887 // error w/ non-general layout
12888 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
12889
12890 m_errorMonitor->SetDesiredFailureMsg(
12891 VK_DEBUG_REPORT_ERROR_BIT_EXT,
12892 "Layout for input attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be READ_ONLY_OPTIMAL or GENERAL.");
12893 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12894 m_errorMonitor->VerifyFound();
12895 subpass.inputAttachmentCount = 0;
12896 subpass.colorAttachmentCount = 1;
12897 subpass.pColorAttachments = &attach;
12898 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
12899 // perf warning for GENERAL layout on color attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012900 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
12901 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012902 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12903 m_errorMonitor->VerifyFound();
12904 // error w/ non-color opt or GENERAL layout for color attachment
12905 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
12906 m_errorMonitor->SetDesiredFailureMsg(
12907 VK_DEBUG_REPORT_ERROR_BIT_EXT,
12908 "Layout for color attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.");
12909 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12910 m_errorMonitor->VerifyFound();
12911 subpass.colorAttachmentCount = 0;
12912 subpass.pDepthStencilAttachment = &attach;
12913 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
12914 // perf warning for GENERAL layout on DS attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012915 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
12916 "GENERAL layout for depth attachment may not give optimal performance.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012917 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12918 m_errorMonitor->VerifyFound();
12919 // error w/ non-ds opt or GENERAL layout for color attachment
12920 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012921 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12922 "Layout for depth attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be "
12923 "DEPTH_STENCIL_ATTACHMENT_OPTIMAL, DEPTH_STENCIL_READ_ONLY_OPTIMAL or GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012924 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12925 m_errorMonitor->VerifyFound();
Tobin Ehlis1efce022016-05-11 10:40:34 -060012926 // For this error we need a valid renderpass so create default one
12927 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
12928 attach.attachment = 0;
Tony Barbourf887b162017-03-09 10:06:46 -070012929 attach_desc.format = depth_format;
Tobin Ehlis1efce022016-05-11 10:40:34 -060012930 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
12931 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
12932 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
12933 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
12934 // Can't do a CLEAR load on READ_ONLY initialLayout
12935 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
12936 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
12937 attach_desc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012938 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski91c28262017-03-22 13:06:12 -060012939 "with invalid first layout VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL");
Tobin Ehlis1efce022016-05-11 10:40:34 -060012940 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12941 m_errorMonitor->VerifyFound();
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012942
Cort3b021012016-12-07 12:00:57 -080012943 vkFreeMemory(m_device->device(), src_image_mem, NULL);
12944 vkFreeMemory(m_device->device(), dst_image_mem, NULL);
12945 vkFreeMemory(m_device->device(), depth_image_mem, NULL);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012946 vkDestroyImage(m_device->device(), src_image, NULL);
12947 vkDestroyImage(m_device->device(), dst_image, NULL);
Cort3b021012016-12-07 12:00:57 -080012948 vkDestroyImage(m_device->device(), depth_image, NULL);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012949}
Tobin Ehlisd8d89182016-07-18 20:13:11 -060012950
Tobin Ehlise0936662016-10-11 08:10:51 -060012951TEST_F(VkLayerTest, InvalidStorageImageLayout) {
12952 TEST_DESCRIPTION("Attempt to update a STORAGE_IMAGE descriptor w/o GENERAL layout.");
12953 VkResult err;
12954
Tony Barbour1fa09702017-03-16 12:09:08 -060012955 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlise0936662016-10-11 08:10:51 -060012956
12957 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
12958 VkImageTiling tiling;
12959 VkFormatProperties format_properties;
12960 vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties);
12961 if (format_properties.linearTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
12962 tiling = VK_IMAGE_TILING_LINEAR;
12963 } else if (format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
12964 tiling = VK_IMAGE_TILING_OPTIMAL;
12965 } else {
Dave Houlton584d51e2017-02-16 12:52:54 -070012966 printf(" Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; skipped.\n");
Tobin Ehlise0936662016-10-11 08:10:51 -060012967 return;
12968 }
12969
12970 VkDescriptorPoolSize ds_type = {};
12971 ds_type.type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
12972 ds_type.descriptorCount = 1;
12973
12974 VkDescriptorPoolCreateInfo ds_pool_ci = {};
12975 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12976 ds_pool_ci.maxSets = 1;
12977 ds_pool_ci.poolSizeCount = 1;
12978 ds_pool_ci.pPoolSizes = &ds_type;
12979 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
12980
12981 VkDescriptorPool ds_pool;
12982 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
12983 ASSERT_VK_SUCCESS(err);
12984
12985 VkDescriptorSetLayoutBinding dsl_binding = {};
12986 dsl_binding.binding = 0;
12987 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
12988 dsl_binding.descriptorCount = 1;
12989 dsl_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12990 dsl_binding.pImmutableSamplers = NULL;
12991
12992 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
12993 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12994 ds_layout_ci.pNext = NULL;
12995 ds_layout_ci.bindingCount = 1;
12996 ds_layout_ci.pBindings = &dsl_binding;
12997
12998 VkDescriptorSetLayout ds_layout;
12999 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
13000 ASSERT_VK_SUCCESS(err);
13001
13002 VkDescriptorSetAllocateInfo alloc_info = {};
13003 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
13004 alloc_info.descriptorSetCount = 1;
13005 alloc_info.descriptorPool = ds_pool;
13006 alloc_info.pSetLayouts = &ds_layout;
13007 VkDescriptorSet descriptor_set;
13008 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
13009 ASSERT_VK_SUCCESS(err);
13010
13011 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
13012 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13013 pipeline_layout_ci.pNext = NULL;
13014 pipeline_layout_ci.setLayoutCount = 1;
13015 pipeline_layout_ci.pSetLayouts = &ds_layout;
13016 VkPipelineLayout pipeline_layout;
13017 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
13018 ASSERT_VK_SUCCESS(err);
13019
13020 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060013021 image.Init(32, 32, 1, tex_format, VK_IMAGE_USAGE_STORAGE_BIT, tiling, 0);
Tobin Ehlise0936662016-10-11 08:10:51 -060013022 ASSERT_TRUE(image.initialized());
13023 VkImageView view = image.targetView(tex_format);
13024
13025 VkDescriptorImageInfo image_info = {};
13026 image_info.imageView = view;
13027 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
13028
13029 VkWriteDescriptorSet descriptor_write = {};
13030 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
13031 descriptor_write.dstSet = descriptor_set;
13032 descriptor_write.dstBinding = 0;
13033 descriptor_write.descriptorCount = 1;
13034 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
13035 descriptor_write.pImageInfo = &image_info;
13036
13037 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13038 " of VK_DESCRIPTOR_TYPE_STORAGE_IMAGE type is being updated with layout "
13039 "VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL but according to spec ");
13040 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
13041 m_errorMonitor->VerifyFound();
13042
13043 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
13044 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
13045 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
13046 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
13047}
13048
Chris Forbes3fa68552017-05-18 14:34:05 -070013049TEST_F(VkLayerTest, NonSimultaneousSecondaryMarksPrimary) {
Tony Barbour1fa09702017-03-16 12:09:08 -060013050 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes3fa68552017-05-18 14:34:05 -070013051 const char *simultaneous_use_message =
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013052 "does not have VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set and "
13053 "will cause primary command buffer";
Mark Mueller93b938f2016-08-18 10:27:40 -060013054
Chris Forbes3fa68552017-05-18 14:34:05 -070013055 VkCommandBufferObj secondary(m_device, m_commandPool, VK_COMMAND_BUFFER_LEVEL_SECONDARY);
Mark Mueller93b938f2016-08-18 10:27:40 -060013056
Chris Forbes3fa68552017-05-18 14:34:05 -070013057 secondary.begin();
13058 secondary.end();
Rene Lindsay24cf6c52017-01-04 12:06:59 -070013059
Chris Forbes3fa68552017-05-18 14:34:05 -070013060 VkCommandBufferBeginInfo cbbi = {
13061 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
13062 VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT, nullptr,
13063 };
Mark Mueller93b938f2016-08-18 10:27:40 -060013064
Chris Forbes3fa68552017-05-18 14:34:05 -070013065 m_commandBuffer->begin(&cbbi);
13066 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, simultaneous_use_message);
13067 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary.handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060013068 m_errorMonitor->VerifyFound();
Chris Forbes3fa68552017-05-18 14:34:05 -070013069 m_commandBuffer->end();
13070}
Mark Mueller93b938f2016-08-18 10:27:40 -060013071
Chris Forbes3fa68552017-05-18 14:34:05 -070013072TEST_F(VkLayerTest, SimultaneousUseSecondaryTwoExecutes) {
13073 ASSERT_NO_FATAL_FAILURE(Init());
Mark Mueller93b938f2016-08-18 10:27:40 -060013074
Chris Forbes3fa68552017-05-18 14:34:05 -070013075 const char *simultaneous_use_message = "without VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set!";
Mark Mueller4042b652016-09-05 22:52:21 -060013076
Chris Forbes3fa68552017-05-18 14:34:05 -070013077 VkCommandBufferObj secondary(m_device, m_commandPool, VK_COMMAND_BUFFER_LEVEL_SECONDARY);
13078
13079 VkCommandBufferInheritanceInfo inh = {
13080 VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO, nullptr,
13081 };
13082 VkCommandBufferBeginInfo cbbi = {
13083 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
13084 0, &inh
13085 };
13086
13087 secondary.begin(&cbbi);
13088 secondary.end();
13089
13090 m_commandBuffer->begin();
13091 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary.handle());
13092 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, simultaneous_use_message);
13093 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary.handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060013094 m_errorMonitor->VerifyFound();
Chris Forbes3fa68552017-05-18 14:34:05 -070013095 m_commandBuffer->end();
13096}
Rene Lindsay24cf6c52017-01-04 12:06:59 -070013097
Chris Forbes3fa68552017-05-18 14:34:05 -070013098TEST_F(VkLayerTest, SimultaneousUseSecondarySingleExecute) {
13099 ASSERT_NO_FATAL_FAILURE(Init());
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070013100
Chris Forbes3fa68552017-05-18 14:34:05 -070013101 // variation on previous test executing the same CB twice in the same
13102 // CmdExecuteCommands call
13103
13104 const char *simultaneous_use_message = "without VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set!";
13105
13106 VkCommandBufferObj secondary(m_device, m_commandPool, VK_COMMAND_BUFFER_LEVEL_SECONDARY);
13107
13108 VkCommandBufferInheritanceInfo inh = {
13109 VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO, nullptr,
13110 };
13111 VkCommandBufferBeginInfo cbbi = {
13112 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
13113 0, &inh
13114 };
13115
13116 secondary.begin(&cbbi);
13117 secondary.end();
13118
13119 m_commandBuffer->begin();
13120 VkCommandBuffer cbs[] = { secondary.handle(), secondary.handle() };
13121 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, simultaneous_use_message);
13122 vkCmdExecuteCommands(m_commandBuffer->handle(), 2, cbs);
13123 m_errorMonitor->VerifyFound();
13124 m_commandBuffer->end();
Mark Mueller93b938f2016-08-18 10:27:40 -060013125}
13126
Tony Barbour626994c2017-02-08 15:29:37 -070013127TEST_F(VkLayerTest, SimultaneousUseOneShot) {
13128 TEST_DESCRIPTION(
13129 "Submit the same command buffer twice in one submit looking for simultaneous use and one time submit"
13130 "errors");
13131 const char *simultaneous_use_message = "is already in use and is not marked for simultaneous use";
13132 const char *one_shot_message = "VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has been submitted";
Tony Barbour1fa09702017-03-16 12:09:08 -060013133 ASSERT_NO_FATAL_FAILURE(Init());
Tony Barbour626994c2017-02-08 15:29:37 -070013134
13135 VkCommandBuffer cmd_bufs[2];
13136 VkCommandBufferAllocateInfo alloc_info;
13137 alloc_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
13138 alloc_info.pNext = NULL;
13139 alloc_info.commandBufferCount = 2;
Mike Schuchardt06304c22017-03-01 17:09:09 -070013140 alloc_info.commandPool = m_commandPool->handle();
Tony Barbour626994c2017-02-08 15:29:37 -070013141 alloc_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
13142 vkAllocateCommandBuffers(m_device->device(), &alloc_info, cmd_bufs);
13143
13144 VkCommandBufferBeginInfo cb_binfo;
13145 cb_binfo.pNext = NULL;
13146 cb_binfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
13147 cb_binfo.pInheritanceInfo = VK_NULL_HANDLE;
13148 cb_binfo.flags = 0;
13149 vkBeginCommandBuffer(cmd_bufs[0], &cb_binfo);
13150 VkViewport viewport = {0, 0, 16, 16, 0, 1};
13151 vkCmdSetViewport(cmd_bufs[0], 0, 1, &viewport);
13152 vkEndCommandBuffer(cmd_bufs[0]);
13153 VkCommandBuffer duplicates[2] = {cmd_bufs[0], cmd_bufs[0]};
13154
13155 VkSubmitInfo submit_info = {};
13156 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
13157 submit_info.commandBufferCount = 2;
13158 submit_info.pCommandBuffers = duplicates;
13159 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, simultaneous_use_message);
13160 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
13161 m_errorMonitor->VerifyFound();
13162 vkQueueWaitIdle(m_device->m_queue);
13163
13164 // Set one time use and now look for one time submit
13165 duplicates[0] = duplicates[1] = cmd_bufs[1];
13166 cb_binfo.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT | VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
13167 vkBeginCommandBuffer(cmd_bufs[1], &cb_binfo);
13168 vkCmdSetViewport(cmd_bufs[1], 0, 1, &viewport);
13169 vkEndCommandBuffer(cmd_bufs[1]);
13170 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, one_shot_message);
13171 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
13172 m_errorMonitor->VerifyFound();
13173 vkQueueWaitIdle(m_device->m_queue);
13174}
13175
Tobin Ehlisb093da82017-01-19 12:05:27 -070013176TEST_F(VkLayerTest, StageMaskGsTsEnabled) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013177 TEST_DESCRIPTION(
13178 "Attempt to use a stageMask w/ geometry shader and tesselation shader bits enabled when those features are "
13179 "disabled on the device.");
Tobin Ehlisb093da82017-01-19 12:05:27 -070013180
Tony Barbour1fa09702017-03-16 12:09:08 -060013181 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisb093da82017-01-19 12:05:27 -070013182 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13183
13184 std::vector<const char *> device_extension_names;
13185 auto features = m_device->phy().features();
13186 // Make sure gs & ts are disabled
13187 features.geometryShader = false;
13188 features.tessellationShader = false;
13189 // The sacrificial device object
13190 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
13191
13192 VkCommandPoolCreateInfo pool_create_info{};
13193 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
13194 pool_create_info.queueFamilyIndex = test_device.graphics_queue_node_index_;
13195
13196 VkCommandPool command_pool;
13197 vkCreateCommandPool(test_device.handle(), &pool_create_info, nullptr, &command_pool);
13198
13199 VkCommandBufferAllocateInfo cmd = {};
13200 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
13201 cmd.pNext = NULL;
13202 cmd.commandPool = command_pool;
13203 cmd.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
13204 cmd.commandBufferCount = 1;
13205
13206 VkCommandBuffer cmd_buffer;
13207 VkResult err = vkAllocateCommandBuffers(test_device.handle(), &cmd, &cmd_buffer);
13208 ASSERT_VK_SUCCESS(err);
13209
13210 VkEvent event;
13211 VkEventCreateInfo evci = {};
13212 evci.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
13213 VkResult result = vkCreateEvent(test_device.handle(), &evci, NULL, &event);
13214 ASSERT_VK_SUCCESS(result);
13215
13216 VkCommandBufferBeginInfo cbbi = {};
13217 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
13218 vkBeginCommandBuffer(cmd_buffer, &cbbi);
13219 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00230);
13220 vkCmdSetEvent(cmd_buffer, event, VK_PIPELINE_STAGE_GEOMETRY_SHADER_BIT);
13221 m_errorMonitor->VerifyFound();
13222
13223 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00231);
13224 vkCmdSetEvent(cmd_buffer, event, VK_PIPELINE_STAGE_TESSELLATION_CONTROL_SHADER_BIT);
13225 m_errorMonitor->VerifyFound();
13226
13227 vkDestroyEvent(test_device.handle(), event, NULL);
13228 vkDestroyCommandPool(test_device.handle(), command_pool, NULL);
13229}
13230
Chris Forbesd70103a2017-04-13 11:34:09 -070013231TEST_F(VkLayerTest, EventInUseDestroyedSignaled) {
Tony Barbour1fa09702017-03-16 12:09:08 -060013232 ASSERT_NO_FATAL_FAILURE(Init());
Mark Mueller917f6bc2016-08-30 10:57:19 -060013233 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13234
Tony Barbour552f6c02016-12-21 14:34:07 -070013235 m_commandBuffer->BeginCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060013236
13237 VkEvent event;
13238 VkEventCreateInfo event_create_info = {};
13239 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
13240 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013241 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Mueller917f6bc2016-08-30 10:57:19 -060013242
Tony Barbour552f6c02016-12-21 14:34:07 -070013243 m_commandBuffer->EndCommandBuffer();
Mark Muellerc8d441e2016-08-23 17:36:00 -060013244 vkDestroyEvent(m_device->device(), event, nullptr);
13245
13246 VkSubmitInfo submit_info = {};
13247 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
13248 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013249 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Lobodzinskife4be302017-02-14 13:08:15 -070013250 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is invalid because bound");
Mark Muellerc8d441e2016-08-23 17:36:00 -060013251 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
13252 m_errorMonitor->VerifyFound();
Chris Forbesd70103a2017-04-13 11:34:09 -070013253}
Mark Muellerc8d441e2016-08-23 17:36:00 -060013254
Chris Forbesd70103a2017-04-13 11:34:09 -070013255TEST_F(VkLayerTest, InUseDestroyedSignaled) {
13256 TEST_DESCRIPTION(
13257 "Use vkCmdExecuteCommands with invalid state "
13258 "in primary and secondary command buffers. "
13259 "Delete objects that are inuse. Call VkQueueSubmit "
13260 "with an event that has been deleted.");
Mark Muellerc8d441e2016-08-23 17:36:00 -060013261
Chris Forbesd70103a2017-04-13 11:34:09 -070013262 ASSERT_NO_FATAL_FAILURE(Init());
13263 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13264
13265 m_errorMonitor->ExpectSuccess();
Mark Muellerc8d441e2016-08-23 17:36:00 -060013266
Mark Mueller917f6bc2016-08-30 10:57:19 -060013267 VkSemaphoreCreateInfo semaphore_create_info = {};
13268 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
13269 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013270 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller917f6bc2016-08-30 10:57:19 -060013271 VkFenceCreateInfo fence_create_info = {};
13272 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
13273 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013274 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller917f6bc2016-08-30 10:57:19 -060013275
13276 VkDescriptorPoolSize descriptor_pool_type_count = {};
Mark Mueller4042b652016-09-05 22:52:21 -060013277 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060013278 descriptor_pool_type_count.descriptorCount = 1;
13279
13280 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
13281 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
13282 descriptor_pool_create_info.maxSets = 1;
13283 descriptor_pool_create_info.poolSizeCount = 1;
13284 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013285 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Mark Mueller917f6bc2016-08-30 10:57:19 -060013286
13287 VkDescriptorPool descriptorset_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013288 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
Mark Mueller917f6bc2016-08-30 10:57:19 -060013289
13290 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
Mark Mueller4042b652016-09-05 22:52:21 -060013291 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060013292 descriptorset_layout_binding.descriptorCount = 1;
13293 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
13294
13295 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013296 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060013297 descriptorset_layout_create_info.bindingCount = 1;
13298 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
13299
13300 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013301 ASSERT_VK_SUCCESS(
13302 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060013303
13304 VkDescriptorSet descriptorset;
13305 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013306 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060013307 descriptorset_allocate_info.descriptorSetCount = 1;
13308 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
13309 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013310 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
Mark Mueller917f6bc2016-08-30 10:57:19 -060013311
Mark Mueller4042b652016-09-05 22:52:21 -060013312 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
13313
13314 VkDescriptorBufferInfo buffer_info = {};
13315 buffer_info.buffer = buffer_test.GetBuffer();
13316 buffer_info.offset = 0;
13317 buffer_info.range = 1024;
13318
13319 VkWriteDescriptorSet write_descriptor_set = {};
13320 write_descriptor_set.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
13321 write_descriptor_set.dstSet = descriptorset;
13322 write_descriptor_set.descriptorCount = 1;
13323 write_descriptor_set.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
13324 write_descriptor_set.pBufferInfo = &buffer_info;
13325
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013326 vkUpdateDescriptorSets(m_device->device(), 1, &write_descriptor_set, 0, nullptr);
Mark Mueller4042b652016-09-05 22:52:21 -060013327
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013328 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
13329 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Mueller917f6bc2016-08-30 10:57:19 -060013330
13331 VkPipelineObj pipe(m_device);
13332 pipe.AddColorAttachment();
13333 pipe.AddShader(&vs);
13334 pipe.AddShader(&fs);
13335
13336 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013337 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060013338 pipeline_layout_create_info.setLayoutCount = 1;
13339 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
13340
13341 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013342 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060013343
13344 pipe.CreateVKPipeline(pipeline_layout, m_renderPass);
13345
Chris Forbesd70103a2017-04-13 11:34:09 -070013346 VkEvent event;
13347 VkEventCreateInfo event_create_info = {};
13348 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
13349 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
13350
Tony Barbour552f6c02016-12-21 14:34:07 -070013351 m_commandBuffer->BeginCommandBuffer();
Chris Forbesd70103a2017-04-13 11:34:09 -070013352
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013353 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Muellerc8d441e2016-08-23 17:36:00 -060013354
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013355 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
13356 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
13357 &descriptorset, 0, NULL);
Mark Mueller917f6bc2016-08-30 10:57:19 -060013358
Tony Barbour552f6c02016-12-21 14:34:07 -070013359 m_commandBuffer->EndCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060013360
Chris Forbesd70103a2017-04-13 11:34:09 -070013361 VkSubmitInfo submit_info = {};
13362 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
13363 submit_info.commandBufferCount = 1;
13364 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller917f6bc2016-08-30 10:57:19 -060013365 submit_info.signalSemaphoreCount = 1;
13366 submit_info.pSignalSemaphores = &semaphore;
13367 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013368 m_errorMonitor->Reset(); // resume logmsg processing
Mark Muellerc8d441e2016-08-23 17:36:00 -060013369
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070013370 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00213);
Mark Mueller917f6bc2016-08-30 10:57:19 -060013371 vkDestroyEvent(m_device->device(), event, nullptr);
13372 m_errorMonitor->VerifyFound();
13373
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070013374 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00199);
Mark Mueller917f6bc2016-08-30 10:57:19 -060013375 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
13376 m_errorMonitor->VerifyFound();
13377
Jeremy Hayes08369882017-02-02 10:31:06 -070013378 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Fence 0x");
Mark Mueller917f6bc2016-08-30 10:57:19 -060013379 vkDestroyFence(m_device->device(), fence, nullptr);
13380 m_errorMonitor->VerifyFound();
13381
Tobin Ehlis122207b2016-09-01 08:50:06 -070013382 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070013383 m_errorMonitor->SetUnexpectedError("If semaphore is not VK_NULL_HANDLE, semaphore must be a valid VkSemaphore handle");
13384 m_errorMonitor->SetUnexpectedError("Unable to remove Semaphore obj");
Mark Mueller917f6bc2016-08-30 10:57:19 -060013385 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070013386 m_errorMonitor->SetUnexpectedError("If fence is not VK_NULL_HANDLE, fence must be a valid VkFence handle");
13387 m_errorMonitor->SetUnexpectedError("Unable to remove Fence obj");
Mark Mueller917f6bc2016-08-30 10:57:19 -060013388 vkDestroyFence(m_device->device(), fence, nullptr);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070013389 m_errorMonitor->SetUnexpectedError("If event is not VK_NULL_HANDLE, event must be a valid VkEvent handle");
13390 m_errorMonitor->SetUnexpectedError("Unable to remove Event obj");
Mark Mueller917f6bc2016-08-30 10:57:19 -060013391 vkDestroyEvent(m_device->device(), event, nullptr);
13392 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013393 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
Mark Mueller917f6bc2016-08-30 10:57:19 -060013394 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13395}
13396
Tobin Ehlis2adda372016-09-01 08:51:06 -070013397TEST_F(VkLayerTest, QueryPoolInUseDestroyedSignaled) {
13398 TEST_DESCRIPTION("Delete in-use query pool.");
13399
Tony Barbour1fa09702017-03-16 12:09:08 -060013400 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis2adda372016-09-01 08:51:06 -070013401 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13402
13403 VkQueryPool query_pool;
13404 VkQueryPoolCreateInfo query_pool_ci{};
13405 query_pool_ci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
13406 query_pool_ci.queryType = VK_QUERY_TYPE_TIMESTAMP;
13407 query_pool_ci.queryCount = 1;
13408 vkCreateQueryPool(m_device->device(), &query_pool_ci, nullptr, &query_pool);
Tony Barbour552f6c02016-12-21 14:34:07 -070013409 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis2adda372016-09-01 08:51:06 -070013410 // Reset query pool to create binding with cmd buffer
13411 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0, 1);
13412
Tony Barbour552f6c02016-12-21 14:34:07 -070013413 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis2adda372016-09-01 08:51:06 -070013414
13415 VkSubmitInfo submit_info = {};
13416 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
13417 submit_info.commandBufferCount = 1;
13418 submit_info.pCommandBuffers = &m_commandBuffer->handle();
13419 // Submit cmd buffer and then destroy query pool while in-flight
13420 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
13421
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070013422 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01012);
Tobin Ehlis2adda372016-09-01 08:51:06 -070013423 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
13424 m_errorMonitor->VerifyFound();
13425
13426 vkQueueWaitIdle(m_device->m_queue);
13427 // Now that cmd buffer done we can safely destroy query_pool
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070013428 m_errorMonitor->SetUnexpectedError("If queryPool is not VK_NULL_HANDLE, queryPool must be a valid VkQueryPool handle");
Mark Lobodzinski74597792017-04-11 15:43:49 -060013429 m_errorMonitor->SetUnexpectedError("Unable to remove QueryPool obj");
Tobin Ehlis2adda372016-09-01 08:51:06 -070013430 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
13431}
13432
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060013433TEST_F(VkLayerTest, PipelineInUseDestroyedSignaled) {
13434 TEST_DESCRIPTION("Delete in-use pipeline.");
13435
Tony Barbour1fa09702017-03-16 12:09:08 -060013436 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060013437 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13438
13439 // Empty pipeline layout used for binding PSO
13440 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
13441 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13442 pipeline_layout_ci.setLayoutCount = 0;
13443 pipeline_layout_ci.pSetLayouts = NULL;
13444
13445 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013446 VkResult err = vkCreatePipelineLayout(m_device->handle(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060013447 ASSERT_VK_SUCCESS(err);
13448
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070013449 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00555);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060013450 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013451 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
13452 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060013453 // Store pipeline handle so we can actually delete it before test finishes
13454 VkPipeline delete_this_pipeline;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013455 { // Scope pipeline so it will be auto-deleted
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060013456 VkPipelineObj pipe(m_device);
13457 pipe.AddShader(&vs);
13458 pipe.AddShader(&fs);
13459 pipe.AddColorAttachment();
13460 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13461 delete_this_pipeline = pipe.handle();
13462
Tony Barbour552f6c02016-12-21 14:34:07 -070013463 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060013464 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013465 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060013466
Tony Barbour552f6c02016-12-21 14:34:07 -070013467 m_commandBuffer->EndCommandBuffer();
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060013468
13469 VkSubmitInfo submit_info = {};
13470 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
13471 submit_info.commandBufferCount = 1;
13472 submit_info.pCommandBuffers = &m_commandBuffer->handle();
13473 // Submit cmd buffer and then pipeline destroyed while in-flight
13474 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013475 } // Pipeline deletion triggered here
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060013476 m_errorMonitor->VerifyFound();
13477 // Make sure queue finished and then actually delete pipeline
13478 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070013479 m_errorMonitor->SetUnexpectedError("If pipeline is not VK_NULL_HANDLE, pipeline must be a valid VkPipeline handle");
13480 m_errorMonitor->SetUnexpectedError("Unable to remove Pipeline obj");
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060013481 vkDestroyPipeline(m_device->handle(), delete_this_pipeline, nullptr);
13482 vkDestroyPipelineLayout(m_device->handle(), pipeline_layout, nullptr);
13483}
13484
Tobin Ehlis7d965da2016-09-19 16:15:45 -060013485TEST_F(VkLayerTest, ImageViewInUseDestroyedSignaled) {
13486 TEST_DESCRIPTION("Delete in-use imageView.");
13487
Tony Barbour1fa09702017-03-16 12:09:08 -060013488 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis7d965da2016-09-19 16:15:45 -060013489 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13490
13491 VkDescriptorPoolSize ds_type_count;
13492 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
13493 ds_type_count.descriptorCount = 1;
13494
13495 VkDescriptorPoolCreateInfo ds_pool_ci = {};
13496 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
13497 ds_pool_ci.maxSets = 1;
13498 ds_pool_ci.poolSizeCount = 1;
13499 ds_pool_ci.pPoolSizes = &ds_type_count;
13500
13501 VkDescriptorPool ds_pool;
13502 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
13503 ASSERT_VK_SUCCESS(err);
13504
13505 VkSamplerCreateInfo sampler_ci = {};
13506 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
13507 sampler_ci.pNext = NULL;
13508 sampler_ci.magFilter = VK_FILTER_NEAREST;
13509 sampler_ci.minFilter = VK_FILTER_NEAREST;
13510 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
13511 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
13512 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
13513 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
13514 sampler_ci.mipLodBias = 1.0;
13515 sampler_ci.anisotropyEnable = VK_FALSE;
13516 sampler_ci.maxAnisotropy = 1;
13517 sampler_ci.compareEnable = VK_FALSE;
13518 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
13519 sampler_ci.minLod = 1.0;
13520 sampler_ci.maxLod = 1.0;
13521 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
13522 sampler_ci.unnormalizedCoordinates = VK_FALSE;
13523 VkSampler sampler;
13524
13525 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
13526 ASSERT_VK_SUCCESS(err);
13527
13528 VkDescriptorSetLayoutBinding layout_binding;
13529 layout_binding.binding = 0;
13530 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
13531 layout_binding.descriptorCount = 1;
13532 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
13533 layout_binding.pImmutableSamplers = NULL;
13534
13535 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
13536 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
13537 ds_layout_ci.bindingCount = 1;
13538 ds_layout_ci.pBindings = &layout_binding;
13539 VkDescriptorSetLayout ds_layout;
13540 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
13541 ASSERT_VK_SUCCESS(err);
13542
13543 VkDescriptorSetAllocateInfo alloc_info = {};
13544 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
13545 alloc_info.descriptorSetCount = 1;
13546 alloc_info.descriptorPool = ds_pool;
13547 alloc_info.pSetLayouts = &ds_layout;
13548 VkDescriptorSet descriptor_set;
13549 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
13550 ASSERT_VK_SUCCESS(err);
13551
13552 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
13553 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13554 pipeline_layout_ci.pNext = NULL;
13555 pipeline_layout_ci.setLayoutCount = 1;
13556 pipeline_layout_ci.pSetLayouts = &ds_layout;
13557
13558 VkPipelineLayout pipeline_layout;
13559 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
13560 ASSERT_VK_SUCCESS(err);
13561
13562 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060013563 image.Init(128, 128, 1, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Tobin Ehlis7d965da2016-09-19 16:15:45 -060013564 ASSERT_TRUE(image.initialized());
13565
13566 VkImageView view;
13567 VkImageViewCreateInfo ivci = {};
13568 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
13569 ivci.image = image.handle();
13570 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
13571 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
13572 ivci.subresourceRange.layerCount = 1;
13573 ivci.subresourceRange.baseMipLevel = 0;
13574 ivci.subresourceRange.levelCount = 1;
13575 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
13576
13577 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
13578 ASSERT_VK_SUCCESS(err);
13579
13580 VkDescriptorImageInfo image_info{};
13581 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
13582 image_info.imageView = view;
13583 image_info.sampler = sampler;
13584
13585 VkWriteDescriptorSet descriptor_write = {};
13586 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
13587 descriptor_write.dstSet = descriptor_set;
13588 descriptor_write.dstBinding = 0;
13589 descriptor_write.descriptorCount = 1;
13590 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
13591 descriptor_write.pImageInfo = &image_info;
13592
13593 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
13594
13595 // Create PSO to use the sampler
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013596 char const *vsSource =
13597 "#version 450\n"
13598 "\n"
13599 "out gl_PerVertex { \n"
13600 " vec4 gl_Position;\n"
13601 "};\n"
13602 "void main(){\n"
13603 " gl_Position = vec4(1);\n"
13604 "}\n";
13605 char const *fsSource =
13606 "#version 450\n"
13607 "\n"
13608 "layout(set=0, binding=0) uniform sampler2D s;\n"
13609 "layout(location=0) out vec4 x;\n"
13610 "void main(){\n"
13611 " x = texture(s, vec2(1));\n"
13612 "}\n";
Tobin Ehlis7d965da2016-09-19 16:15:45 -060013613 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13614 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13615 VkPipelineObj pipe(m_device);
13616 pipe.AddShader(&vs);
13617 pipe.AddShader(&fs);
13618 pipe.AddColorAttachment();
13619 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13620
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070013621 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00776);
Tobin Ehlis7d965da2016-09-19 16:15:45 -060013622
Tony Barbour552f6c02016-12-21 14:34:07 -070013623 m_commandBuffer->BeginCommandBuffer();
13624 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis7d965da2016-09-19 16:15:45 -060013625 // Bind pipeline to cmd buffer
13626 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
13627 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
13628 &descriptor_set, 0, nullptr);
Rene Lindsaya8880622017-01-18 13:12:59 -070013629
13630 VkViewport viewport = {0, 0, 16, 16, 0, 1};
13631 VkRect2D scissor = {{0, 0}, {16, 16}};
13632 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
13633 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
13634
Tobin Ehlis7d965da2016-09-19 16:15:45 -060013635 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070013636 m_commandBuffer->EndRenderPass();
13637 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis7d965da2016-09-19 16:15:45 -060013638 // Submit cmd buffer then destroy sampler
13639 VkSubmitInfo submit_info = {};
13640 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
13641 submit_info.commandBufferCount = 1;
13642 submit_info.pCommandBuffers = &m_commandBuffer->handle();
13643 // Submit cmd buffer and then destroy imageView while in-flight
13644 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
13645
13646 vkDestroyImageView(m_device->device(), view, nullptr);
13647 m_errorMonitor->VerifyFound();
13648 vkQueueWaitIdle(m_device->m_queue);
13649 // Now we can actually destroy imageView
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070013650 m_errorMonitor->SetUnexpectedError("If imageView is not VK_NULL_HANDLE, imageView must be a valid VkImageView handle");
Mark Lobodzinski74597792017-04-11 15:43:49 -060013651 m_errorMonitor->SetUnexpectedError("Unable to remove ImageView obj");
Tobin Ehlis7d965da2016-09-19 16:15:45 -060013652 vkDestroyImageView(m_device->device(), view, NULL);
13653 vkDestroySampler(m_device->device(), sampler, nullptr);
13654 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
13655 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
13656 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
13657}
13658
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060013659TEST_F(VkLayerTest, BufferViewInUseDestroyedSignaled) {
13660 TEST_DESCRIPTION("Delete in-use bufferView.");
13661
Tony Barbour1fa09702017-03-16 12:09:08 -060013662 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060013663 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13664
13665 VkDescriptorPoolSize ds_type_count;
13666 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
13667 ds_type_count.descriptorCount = 1;
13668
13669 VkDescriptorPoolCreateInfo ds_pool_ci = {};
13670 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
13671 ds_pool_ci.maxSets = 1;
13672 ds_pool_ci.poolSizeCount = 1;
13673 ds_pool_ci.pPoolSizes = &ds_type_count;
13674
13675 VkDescriptorPool ds_pool;
13676 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
13677 ASSERT_VK_SUCCESS(err);
13678
13679 VkDescriptorSetLayoutBinding layout_binding;
13680 layout_binding.binding = 0;
13681 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
13682 layout_binding.descriptorCount = 1;
13683 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
13684 layout_binding.pImmutableSamplers = NULL;
13685
13686 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
13687 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
13688 ds_layout_ci.bindingCount = 1;
13689 ds_layout_ci.pBindings = &layout_binding;
13690 VkDescriptorSetLayout ds_layout;
13691 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
13692 ASSERT_VK_SUCCESS(err);
13693
13694 VkDescriptorSetAllocateInfo alloc_info = {};
13695 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
13696 alloc_info.descriptorSetCount = 1;
13697 alloc_info.descriptorPool = ds_pool;
13698 alloc_info.pSetLayouts = &ds_layout;
13699 VkDescriptorSet descriptor_set;
13700 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
13701 ASSERT_VK_SUCCESS(err);
13702
13703 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
13704 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13705 pipeline_layout_ci.pNext = NULL;
13706 pipeline_layout_ci.setLayoutCount = 1;
13707 pipeline_layout_ci.pSetLayouts = &ds_layout;
13708
13709 VkPipelineLayout pipeline_layout;
13710 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
13711 ASSERT_VK_SUCCESS(err);
13712
13713 VkBuffer buffer;
13714 uint32_t queue_family_index = 0;
13715 VkBufferCreateInfo buffer_create_info = {};
13716 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
13717 buffer_create_info.size = 1024;
13718 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
13719 buffer_create_info.queueFamilyIndexCount = 1;
13720 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
13721
13722 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
13723 ASSERT_VK_SUCCESS(err);
13724
13725 VkMemoryRequirements memory_reqs;
13726 VkDeviceMemory buffer_memory;
13727
13728 VkMemoryAllocateInfo memory_info = {};
13729 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
13730 memory_info.allocationSize = 0;
13731 memory_info.memoryTypeIndex = 0;
13732
13733 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
13734 memory_info.allocationSize = memory_reqs.size;
13735 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
13736 ASSERT_TRUE(pass);
13737
13738 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
13739 ASSERT_VK_SUCCESS(err);
13740 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
13741 ASSERT_VK_SUCCESS(err);
13742
13743 VkBufferView view;
13744 VkBufferViewCreateInfo bvci = {};
13745 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
13746 bvci.buffer = buffer;
Tobin Ehliscc980e12017-05-19 12:05:49 -060013747 bvci.format = VK_FORMAT_R32_SFLOAT;
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060013748 bvci.range = VK_WHOLE_SIZE;
13749
13750 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
13751 ASSERT_VK_SUCCESS(err);
13752
13753 VkWriteDescriptorSet descriptor_write = {};
13754 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
13755 descriptor_write.dstSet = descriptor_set;
13756 descriptor_write.dstBinding = 0;
13757 descriptor_write.descriptorCount = 1;
13758 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
13759 descriptor_write.pTexelBufferView = &view;
13760
13761 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
13762
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013763 char const *vsSource =
13764 "#version 450\n"
13765 "\n"
13766 "out gl_PerVertex { \n"
13767 " vec4 gl_Position;\n"
13768 "};\n"
13769 "void main(){\n"
13770 " gl_Position = vec4(1);\n"
13771 "}\n";
13772 char const *fsSource =
13773 "#version 450\n"
13774 "\n"
Tobin Ehliscc980e12017-05-19 12:05:49 -060013775 "layout(set=0, binding=0, r32f) uniform imageBuffer s;\n"
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013776 "layout(location=0) out vec4 x;\n"
13777 "void main(){\n"
13778 " x = imageLoad(s, 0);\n"
13779 "}\n";
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060013780 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13781 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13782 VkPipelineObj pipe(m_device);
13783 pipe.AddShader(&vs);
13784 pipe.AddShader(&fs);
13785 pipe.AddColorAttachment();
13786 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13787
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070013788 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00701);
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060013789
Tony Barbour552f6c02016-12-21 14:34:07 -070013790 m_commandBuffer->BeginCommandBuffer();
13791 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060013792 VkViewport viewport = {0, 0, 16, 16, 0, 1};
13793 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
13794 VkRect2D scissor = {{0, 0}, {16, 16}};
13795 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
13796 // Bind pipeline to cmd buffer
13797 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
13798 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
13799 &descriptor_set, 0, nullptr);
13800 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070013801 m_commandBuffer->EndRenderPass();
13802 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060013803
13804 VkSubmitInfo submit_info = {};
13805 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
13806 submit_info.commandBufferCount = 1;
13807 submit_info.pCommandBuffers = &m_commandBuffer->handle();
13808 // Submit cmd buffer and then destroy bufferView while in-flight
13809 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
13810
13811 vkDestroyBufferView(m_device->device(), view, nullptr);
13812 m_errorMonitor->VerifyFound();
13813 vkQueueWaitIdle(m_device->m_queue);
13814 // Now we can actually destroy bufferView
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070013815 m_errorMonitor->SetUnexpectedError("If bufferView is not VK_NULL_HANDLE, bufferView must be a valid VkBufferView handle");
Mark Lobodzinski74597792017-04-11 15:43:49 -060013816 m_errorMonitor->SetUnexpectedError("Unable to remove BufferView obj");
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060013817 vkDestroyBufferView(m_device->device(), view, NULL);
13818 vkDestroyBuffer(m_device->device(), buffer, NULL);
13819 vkFreeMemory(m_device->device(), buffer_memory, NULL);
13820 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
13821 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
13822 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
13823}
13824
Tobin Ehlis209532e2016-09-07 13:52:18 -060013825TEST_F(VkLayerTest, SamplerInUseDestroyedSignaled) {
13826 TEST_DESCRIPTION("Delete in-use sampler.");
13827
Tony Barbour1fa09702017-03-16 12:09:08 -060013828 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis209532e2016-09-07 13:52:18 -060013829 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13830
13831 VkDescriptorPoolSize ds_type_count;
13832 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
13833 ds_type_count.descriptorCount = 1;
13834
13835 VkDescriptorPoolCreateInfo ds_pool_ci = {};
13836 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
13837 ds_pool_ci.maxSets = 1;
13838 ds_pool_ci.poolSizeCount = 1;
13839 ds_pool_ci.pPoolSizes = &ds_type_count;
13840
13841 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013842 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis209532e2016-09-07 13:52:18 -060013843 ASSERT_VK_SUCCESS(err);
13844
13845 VkSamplerCreateInfo sampler_ci = {};
13846 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
13847 sampler_ci.pNext = NULL;
13848 sampler_ci.magFilter = VK_FILTER_NEAREST;
13849 sampler_ci.minFilter = VK_FILTER_NEAREST;
13850 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
13851 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
13852 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
13853 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
13854 sampler_ci.mipLodBias = 1.0;
13855 sampler_ci.anisotropyEnable = VK_FALSE;
13856 sampler_ci.maxAnisotropy = 1;
13857 sampler_ci.compareEnable = VK_FALSE;
13858 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
13859 sampler_ci.minLod = 1.0;
13860 sampler_ci.maxLod = 1.0;
13861 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
13862 sampler_ci.unnormalizedCoordinates = VK_FALSE;
13863 VkSampler sampler;
13864
13865 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
13866 ASSERT_VK_SUCCESS(err);
13867
13868 VkDescriptorSetLayoutBinding layout_binding;
13869 layout_binding.binding = 0;
Tobin Ehlis94fc0ad2016-09-19 16:23:01 -060013870 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
Tobin Ehlis209532e2016-09-07 13:52:18 -060013871 layout_binding.descriptorCount = 1;
13872 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
13873 layout_binding.pImmutableSamplers = NULL;
13874
13875 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
13876 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
13877 ds_layout_ci.bindingCount = 1;
13878 ds_layout_ci.pBindings = &layout_binding;
13879 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013880 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060013881 ASSERT_VK_SUCCESS(err);
13882
13883 VkDescriptorSetAllocateInfo alloc_info = {};
13884 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
13885 alloc_info.descriptorSetCount = 1;
13886 alloc_info.descriptorPool = ds_pool;
13887 alloc_info.pSetLayouts = &ds_layout;
13888 VkDescriptorSet descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013889 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis209532e2016-09-07 13:52:18 -060013890 ASSERT_VK_SUCCESS(err);
13891
13892 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
13893 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13894 pipeline_layout_ci.pNext = NULL;
13895 pipeline_layout_ci.setLayoutCount = 1;
13896 pipeline_layout_ci.pSetLayouts = &ds_layout;
13897
13898 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013899 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060013900 ASSERT_VK_SUCCESS(err);
13901
13902 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060013903 image.Init(128, 128, 1, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Tobin Ehlis209532e2016-09-07 13:52:18 -060013904 ASSERT_TRUE(image.initialized());
13905
13906 VkImageView view;
13907 VkImageViewCreateInfo ivci = {};
13908 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
13909 ivci.image = image.handle();
13910 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
13911 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
13912 ivci.subresourceRange.layerCount = 1;
13913 ivci.subresourceRange.baseMipLevel = 0;
13914 ivci.subresourceRange.levelCount = 1;
13915 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
13916
13917 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
13918 ASSERT_VK_SUCCESS(err);
13919
13920 VkDescriptorImageInfo image_info{};
13921 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
13922 image_info.imageView = view;
13923 image_info.sampler = sampler;
13924
13925 VkWriteDescriptorSet descriptor_write = {};
13926 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
13927 descriptor_write.dstSet = descriptor_set;
13928 descriptor_write.dstBinding = 0;
13929 descriptor_write.descriptorCount = 1;
13930 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
13931 descriptor_write.pImageInfo = &image_info;
13932
13933 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
13934
13935 // Create PSO to use the sampler
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013936 char const *vsSource =
13937 "#version 450\n"
13938 "\n"
13939 "out gl_PerVertex { \n"
13940 " vec4 gl_Position;\n"
13941 "};\n"
13942 "void main(){\n"
13943 " gl_Position = vec4(1);\n"
13944 "}\n";
13945 char const *fsSource =
13946 "#version 450\n"
13947 "\n"
13948 "layout(set=0, binding=0) uniform sampler2D s;\n"
13949 "layout(location=0) out vec4 x;\n"
13950 "void main(){\n"
13951 " x = texture(s, vec2(1));\n"
13952 "}\n";
Tobin Ehlis209532e2016-09-07 13:52:18 -060013953 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13954 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13955 VkPipelineObj pipe(m_device);
13956 pipe.AddShader(&vs);
13957 pipe.AddShader(&fs);
13958 pipe.AddColorAttachment();
13959 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13960
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070013961 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00837);
Tobin Ehlis209532e2016-09-07 13:52:18 -060013962
Tony Barbour552f6c02016-12-21 14:34:07 -070013963 m_commandBuffer->BeginCommandBuffer();
13964 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis209532e2016-09-07 13:52:18 -060013965 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013966 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
13967 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
13968 &descriptor_set, 0, nullptr);
Rene Lindsay4da11732017-01-13 14:42:10 -070013969
13970 VkViewport viewport = {0, 0, 16, 16, 0, 1};
13971 VkRect2D scissor = {{0, 0}, {16, 16}};
13972 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
13973 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
13974
Tobin Ehlis209532e2016-09-07 13:52:18 -060013975 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070013976 m_commandBuffer->EndRenderPass();
13977 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis209532e2016-09-07 13:52:18 -060013978 // Submit cmd buffer then destroy sampler
13979 VkSubmitInfo submit_info = {};
13980 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
13981 submit_info.commandBufferCount = 1;
13982 submit_info.pCommandBuffers = &m_commandBuffer->handle();
13983 // Submit cmd buffer and then destroy sampler while in-flight
13984 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
13985
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013986 vkDestroySampler(m_device->device(), sampler, nullptr); // Destroyed too soon
Tobin Ehlis209532e2016-09-07 13:52:18 -060013987 m_errorMonitor->VerifyFound();
13988 vkQueueWaitIdle(m_device->m_queue);
Rene Lindsay4da11732017-01-13 14:42:10 -070013989
Tobin Ehlis209532e2016-09-07 13:52:18 -060013990 // Now we can actually destroy sampler
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070013991 m_errorMonitor->SetUnexpectedError("If sampler is not VK_NULL_HANDLE, sampler must be a valid VkSampler handle");
13992 m_errorMonitor->SetUnexpectedError("Unable to remove Sampler obj");
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013993 vkDestroySampler(m_device->device(), sampler, NULL); // Destroyed for real
Tobin Ehlis209532e2016-09-07 13:52:18 -060013994 vkDestroyImageView(m_device->device(), view, NULL);
13995 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
13996 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
13997 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
13998}
13999
Mark Mueller1cd9f412016-08-25 13:23:52 -060014000TEST_F(VkLayerTest, QueueForwardProgressFenceWait) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014001 TEST_DESCRIPTION(
14002 "Call VkQueueSubmit with a semaphore that is already "
14003 "signaled but not waited on by the queue. Wait on a "
14004 "fence that has not yet been submitted to a queue.");
Mark Mueller96a56d52016-08-24 10:28:05 -060014005
Tony Barbour1fa09702017-03-16 12:09:08 -060014006 ASSERT_NO_FATAL_FAILURE(Init());
Mark Mueller96a56d52016-08-24 10:28:05 -060014007 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14008
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014009 const char *queue_forward_progress_message = " that has already been signaled but not waited on by queue 0x";
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014010 const char *invalid_fence_wait_message =
14011 " which has not been submitted on a Queue or during "
14012 "acquire next image.";
Mark Mueller96a56d52016-08-24 10:28:05 -060014013
Chris Forbese98aec12017-05-18 12:50:14 -070014014 VkCommandBufferObj cb1(m_device, m_commandPool);
14015 cb1.begin();
14016 cb1.end();
Mark Mueller96a56d52016-08-24 10:28:05 -060014017
14018 VkSemaphoreCreateInfo semaphore_create_info = {};
14019 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
14020 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014021 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller96a56d52016-08-24 10:28:05 -060014022 VkSubmitInfo submit_info = {};
14023 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
14024 submit_info.commandBufferCount = 1;
Chris Forbese98aec12017-05-18 12:50:14 -070014025 submit_info.pCommandBuffers = &cb1.handle();
Mark Mueller96a56d52016-08-24 10:28:05 -060014026 submit_info.signalSemaphoreCount = 1;
14027 submit_info.pSignalSemaphores = &semaphore;
14028 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Chris Forbese98aec12017-05-18 12:50:14 -070014029
Tony Barbour552f6c02016-12-21 14:34:07 -070014030 m_commandBuffer->BeginCommandBuffer();
14031 m_commandBuffer->EndCommandBuffer();
Chris Forbese98aec12017-05-18 12:50:14 -070014032 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014033 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, queue_forward_progress_message);
Mark Mueller96a56d52016-08-24 10:28:05 -060014034 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
14035 m_errorMonitor->VerifyFound();
14036
Mark Mueller1cd9f412016-08-25 13:23:52 -060014037 VkFenceCreateInfo fence_create_info = {};
14038 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
14039 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014040 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller1cd9f412016-08-25 13:23:52 -060014041
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014042 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, invalid_fence_wait_message);
Mark Mueller1cd9f412016-08-25 13:23:52 -060014043 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
14044 m_errorMonitor->VerifyFound();
14045
Mark Mueller4042b652016-09-05 22:52:21 -060014046 vkDeviceWaitIdle(m_device->device());
Mark Mueller1cd9f412016-08-25 13:23:52 -060014047 vkDestroyFence(m_device->device(), fence, nullptr);
Mark Mueller96a56d52016-08-24 10:28:05 -060014048 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
14049}
14050
Tobin Ehlis4af23302016-07-19 10:50:30 -060014051TEST_F(VkLayerTest, FramebufferIncompatible) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014052 TEST_DESCRIPTION(
14053 "Bind a secondary command buffer with with a framebuffer "
14054 "that does not match the framebuffer for the active "
14055 "renderpass.");
Tony Barbour1fa09702017-03-16 12:09:08 -060014056 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis4af23302016-07-19 10:50:30 -060014057 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14058
14059 // A renderpass with one color attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014060 VkAttachmentDescription attachment = {0,
14061 VK_FORMAT_B8G8R8A8_UNORM,
14062 VK_SAMPLE_COUNT_1_BIT,
14063 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
14064 VK_ATTACHMENT_STORE_OP_STORE,
14065 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
14066 VK_ATTACHMENT_STORE_OP_DONT_CARE,
14067 VK_IMAGE_LAYOUT_UNDEFINED,
14068 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060014069
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014070 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060014071
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014072 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060014073
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014074 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060014075
14076 VkRenderPass rp;
14077 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
14078 ASSERT_VK_SUCCESS(err);
14079
14080 // A compatible framebuffer.
14081 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060014082 image.Init(32, 32, 1, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Tobin Ehlis4af23302016-07-19 10:50:30 -060014083 ASSERT_TRUE(image.initialized());
14084
14085 VkImageViewCreateInfo ivci = {
14086 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
14087 nullptr,
14088 0,
14089 image.handle(),
14090 VK_IMAGE_VIEW_TYPE_2D,
14091 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014092 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
14093 VK_COMPONENT_SWIZZLE_IDENTITY},
Tobin Ehlis4af23302016-07-19 10:50:30 -060014094 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
14095 };
14096 VkImageView view;
14097 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
14098 ASSERT_VK_SUCCESS(err);
14099
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014100 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Tobin Ehlis4af23302016-07-19 10:50:30 -060014101 VkFramebuffer fb;
14102 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
14103 ASSERT_VK_SUCCESS(err);
14104
14105 VkCommandBufferAllocateInfo cbai = {};
14106 cbai.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mike Schuchardt06304c22017-03-01 17:09:09 -070014107 cbai.commandPool = m_commandPool->handle();
Tobin Ehlis4af23302016-07-19 10:50:30 -060014108 cbai.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
14109 cbai.commandBufferCount = 1;
14110
14111 VkCommandBuffer sec_cb;
14112 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &sec_cb);
14113 ASSERT_VK_SUCCESS(err);
14114 VkCommandBufferBeginInfo cbbi = {};
14115 VkCommandBufferInheritanceInfo cbii = {};
Chris Forbes98420382016-11-28 17:56:51 +130014116 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Tobin Ehlis4af23302016-07-19 10:50:30 -060014117 cbii.renderPass = renderPass();
14118 cbii.framebuffer = fb;
14119 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
14120 cbbi.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014121 cbbi.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
Tobin Ehlis4af23302016-07-19 10:50:30 -060014122 cbbi.pInheritanceInfo = &cbii;
14123 vkBeginCommandBuffer(sec_cb, &cbbi);
14124 vkEndCommandBuffer(sec_cb);
14125
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014126 VkCommandBufferBeginInfo cbbi2 = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, 0, nullptr};
Chris Forbes3400bc52016-09-13 18:10:34 +120014127 vkBeginCommandBuffer(m_commandBuffer->GetBufferHandle(), &cbbi2);
14128 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Tobin Ehlis4af23302016-07-19 10:50:30 -060014129
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014130 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060014131 " that is not the same as the primary command buffer's current active framebuffer ");
Tobin Ehlis4af23302016-07-19 10:50:30 -060014132 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &sec_cb);
14133 m_errorMonitor->VerifyFound();
14134 // Cleanup
14135 vkDestroyImageView(m_device->device(), view, NULL);
14136 vkDestroyRenderPass(m_device->device(), rp, NULL);
14137 vkDestroyFramebuffer(m_device->device(), fb, NULL);
14138}
Tobin Ehlis52b504f2016-07-19 13:25:12 -060014139
14140TEST_F(VkLayerTest, ColorBlendLogicOpTests) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014141 TEST_DESCRIPTION(
14142 "If logicOp is available on the device, set it to an "
14143 "invalid value. If logicOp is not available, attempt to "
14144 "use it and verify that we see the correct error.");
Tony Barbour1fa09702017-03-16 12:09:08 -060014145 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis52b504f2016-07-19 13:25:12 -060014146 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14147
14148 auto features = m_device->phy().features();
14149 // Set the expected error depending on whether or not logicOp available
14150 if (VK_FALSE == features.logicOp) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014151 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14152 "If logic operations feature not "
14153 "enabled, logicOpEnable must be "
14154 "VK_FALSE");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060014155 } else {
Chris Forbes34797bc2016-10-03 15:28:49 +130014156 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "pColorBlendState->logicOp (16)");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060014157 }
14158 // Create a pipeline using logicOp
14159 VkResult err;
14160
14161 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
14162 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
14163
14164 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014165 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060014166 ASSERT_VK_SUCCESS(err);
14167
14168 VkPipelineViewportStateCreateInfo vp_state_ci = {};
14169 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
14170 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014171 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060014172 vp_state_ci.pViewports = &vp;
14173 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014174 VkRect2D scissors = {}; // Dummy scissors to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060014175 vp_state_ci.pScissors = &scissors;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060014176
14177 VkPipelineShaderStageCreateInfo shaderStages[2];
14178 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
14179
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014180 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
14181 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060014182 shaderStages[0] = vs.GetStageCreateInfo();
14183 shaderStages[1] = fs.GetStageCreateInfo();
14184
14185 VkPipelineVertexInputStateCreateInfo vi_ci = {};
14186 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
14187
14188 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
14189 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
14190 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
14191
14192 VkPipelineRasterizationStateCreateInfo rs_ci = {};
14193 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbes14088512016-10-03 14:28:00 +130014194 rs_ci.lineWidth = 1.0f;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060014195
14196 VkPipelineColorBlendAttachmentState att = {};
14197 att.blendEnable = VK_FALSE;
14198 att.colorWriteMask = 0xf;
14199
14200 VkPipelineColorBlendStateCreateInfo cb_ci = {};
14201 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
14202 // Enable logicOp & set logicOp to value 1 beyond allowed entries
14203 cb_ci.logicOpEnable = VK_TRUE;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014204 cb_ci.logicOp = VK_LOGIC_OP_RANGE_SIZE; // This should cause an error
Tobin Ehlis52b504f2016-07-19 13:25:12 -060014205 cb_ci.attachmentCount = 1;
14206 cb_ci.pAttachments = &att;
14207
Chris Forbes8aeacbf2016-10-03 14:25:08 +130014208 VkPipelineMultisampleStateCreateInfo ms_ci = {};
14209 ms_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
14210 ms_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
14211
Tobin Ehlis52b504f2016-07-19 13:25:12 -060014212 VkGraphicsPipelineCreateInfo gp_ci = {};
14213 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
14214 gp_ci.stageCount = 2;
14215 gp_ci.pStages = shaderStages;
14216 gp_ci.pVertexInputState = &vi_ci;
14217 gp_ci.pInputAssemblyState = &ia_ci;
14218 gp_ci.pViewportState = &vp_state_ci;
14219 gp_ci.pRasterizationState = &rs_ci;
14220 gp_ci.pColorBlendState = &cb_ci;
Chris Forbes8aeacbf2016-10-03 14:25:08 +130014221 gp_ci.pMultisampleState = &ms_ci;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060014222 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
14223 gp_ci.layout = pipeline_layout;
14224 gp_ci.renderPass = renderPass();
14225
14226 VkPipelineCacheCreateInfo pc_ci = {};
14227 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
14228
14229 VkPipeline pipeline;
14230 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014231 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060014232 ASSERT_VK_SUCCESS(err);
14233
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014234 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060014235 m_errorMonitor->VerifyFound();
14236 if (VK_SUCCESS == err) {
14237 vkDestroyPipeline(m_device->device(), pipeline, NULL);
14238 }
Tobin Ehlis52b504f2016-07-19 13:25:12 -060014239 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
14240 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
14241}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060014242
Mike Stroyanaccf7692015-05-12 16:00:45 -060014243#if GTEST_IS_THREADSAFE
14244struct thread_data_struct {
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014245 VkCommandBuffer commandBuffer;
Mike Stroyanca855662017-05-02 11:06:27 -060014246 VkDevice device;
Mike Stroyanaccf7692015-05-12 16:00:45 -060014247 VkEvent event;
14248 bool bailout;
14249};
14250
Karl Schultz6addd812016-02-02 17:17:23 -070014251extern "C" void *AddToCommandBuffer(void *arg) {
14252 struct thread_data_struct *data = (struct thread_data_struct *)arg;
Mike Stroyanaccf7692015-05-12 16:00:45 -060014253
Mike Stroyana6d14942016-07-13 15:10:05 -060014254 for (int i = 0; i < 80000; i++) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014255 vkCmdSetEvent(data->commandBuffer, data->event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mike Stroyanaccf7692015-05-12 16:00:45 -060014256 if (data->bailout) {
14257 break;
14258 }
14259 }
14260 return NULL;
14261}
14262
Karl Schultz6addd812016-02-02 17:17:23 -070014263TEST_F(VkLayerTest, ThreadCommandBufferCollision) {
Mike Stroyan4268d1f2015-07-13 14:45:35 -060014264 test_platform_thread thread;
Mike Stroyanaccf7692015-05-12 16:00:45 -060014265
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014266 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "THREADING ERROR");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014267
Tony Barbour1fa09702017-03-16 12:09:08 -060014268 ASSERT_NO_FATAL_FAILURE(Init());
Mike Stroyanaccf7692015-05-12 16:00:45 -060014269 ASSERT_NO_FATAL_FAILURE(InitViewport());
14270 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14271
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014272 // Calls AllocateCommandBuffers
14273 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060014274
14275 // Avoid creating RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014276 commandBuffer.BeginCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060014277
14278 VkEventCreateInfo event_info;
14279 VkEvent event;
Mike Stroyanaccf7692015-05-12 16:00:45 -060014280 VkResult err;
14281
14282 memset(&event_info, 0, sizeof(event_info));
14283 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
14284
Chia-I Wuf7458c52015-10-26 21:10:41 +080014285 err = vkCreateEvent(device(), &event_info, NULL, &event);
Mike Stroyanaccf7692015-05-12 16:00:45 -060014286 ASSERT_VK_SUCCESS(err);
14287
Mike Stroyanaccf7692015-05-12 16:00:45 -060014288 err = vkResetEvent(device(), event);
14289 ASSERT_VK_SUCCESS(err);
14290
14291 struct thread_data_struct data;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014292 data.commandBuffer = commandBuffer.GetBufferHandle();
Mike Stroyanaccf7692015-05-12 16:00:45 -060014293 data.event = event;
14294 data.bailout = false;
14295 m_errorMonitor->SetBailout(&data.bailout);
Mike Stroyana6d14942016-07-13 15:10:05 -060014296
14297 // First do some correct operations using multiple threads.
14298 // Add many entries to command buffer from another thread.
14299 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
14300 // Make non-conflicting calls from this thread at the same time.
14301 for (int i = 0; i < 80000; i++) {
Mike Stroyand6343902016-07-14 08:56:16 -060014302 uint32_t count;
14303 vkEnumeratePhysicalDevices(instance(), &count, NULL);
Mike Stroyana6d14942016-07-13 15:10:05 -060014304 }
14305 test_platform_thread_join(thread, NULL);
14306
14307 // Then do some incorrect operations using multiple threads.
Mike Stroyanaccf7692015-05-12 16:00:45 -060014308 // Add many entries to command buffer from another thread.
Mike Stroyan4268d1f2015-07-13 14:45:35 -060014309 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyanaccf7692015-05-12 16:00:45 -060014310 // Add many entries to command buffer from this thread at the same time.
14311 AddToCommandBuffer(&data);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060014312
Mike Stroyan4268d1f2015-07-13 14:45:35 -060014313 test_platform_thread_join(thread, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014314 commandBuffer.EndCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060014315
Mike Stroyan10b8cb72016-01-22 15:22:03 -070014316 m_errorMonitor->SetBailout(NULL);
14317
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014318 m_errorMonitor->VerifyFound();
Mike Stroyanaccf7692015-05-12 16:00:45 -060014319
Chia-I Wuf7458c52015-10-26 21:10:41 +080014320 vkDestroyEvent(device(), event, NULL);
Mike Stroyanaccf7692015-05-12 16:00:45 -060014321}
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014322#endif // GTEST_IS_THREADSAFE
Mark Lobodzinski209b5292015-09-17 09:44:05 -060014323
Karl Schultz6addd812016-02-02 17:17:23 -070014324TEST_F(VkLayerTest, InvalidSPIRVCodeSize) {
Mark Lobodzinskid742b312017-05-09 16:26:27 -060014325 TEST_DESCRIPTION("Test that errors are produced for a spirv modules with invalid code sizes");
Chris Forbes1cc79542016-07-20 11:13:44 +120014326
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014327 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014328
Tony Barbour1fa09702017-03-16 12:09:08 -060014329 ASSERT_NO_FATAL_FAILURE(Init());
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014330 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14331
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014332 VkShaderModule module;
14333 VkShaderModuleCreateInfo moduleCreateInfo;
14334 struct icd_spv_header spv;
14335
14336 spv.magic = ICD_SPV_MAGIC;
14337 spv.version = ICD_SPV_VERSION;
14338 spv.gen_magic = 0;
14339
14340 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
14341 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070014342 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014343 moduleCreateInfo.codeSize = 4;
14344 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080014345 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014346
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014347 m_errorMonitor->VerifyFound();
Mark Lobodzinskid742b312017-05-09 16:26:27 -060014348
14349 char const *vsSource =
14350 "#version 450\n"
14351 "\n"
14352 "layout(location=0) out float x;\n"
14353 "out gl_PerVertex {\n"
14354 " vec4 gl_Position;\n"
14355 "};\n"
14356 "void main(){\n"
14357 " gl_Position = vec4(1);\n"
14358 " x = 0;\n"
14359 "}\n";
14360
14361 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02816);
14362 std::vector<unsigned int> shader;
14363 VkShaderModuleCreateInfo module_create_info;
14364 VkShaderModule shader_module;
14365 module_create_info.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
14366 module_create_info.pNext = NULL;
14367 this->GLSLtoSPV(VK_SHADER_STAGE_VERTEX_BIT, vsSource, shader);
14368 module_create_info.pCode = shader.data();
14369 // Introduce failure by making codeSize a non-multiple of 4
14370 module_create_info.codeSize = shader.size() * sizeof(unsigned int) - 1;
14371 module_create_info.flags = 0;
14372 vkCreateShaderModule(m_device->handle(), &module_create_info, NULL, &shader_module);
14373
14374 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014375}
14376
Karl Schultz6addd812016-02-02 17:17:23 -070014377TEST_F(VkLayerTest, InvalidSPIRVMagic) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014378 TEST_DESCRIPTION(
14379 "Test that an error is produced for a spirv module "
14380 "with a bad magic number");
Chris Forbes1cc79542016-07-20 11:13:44 +120014381
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014382 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V magic number");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014383
Tony Barbour1fa09702017-03-16 12:09:08 -060014384 ASSERT_NO_FATAL_FAILURE(Init());
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014385 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14386
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014387 VkShaderModule module;
14388 VkShaderModuleCreateInfo moduleCreateInfo;
14389 struct icd_spv_header spv;
14390
14391 spv.magic = ~ICD_SPV_MAGIC;
14392 spv.version = ICD_SPV_VERSION;
14393 spv.gen_magic = 0;
14394
14395 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
14396 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070014397 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Mark Lobodzinskid742b312017-05-09 16:26:27 -060014398 moduleCreateInfo.codeSize = sizeof(spv) + 16;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014399 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080014400 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014401
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014402 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014403}
14404
Chris Forbesb4afd0f2016-04-04 10:48:35 +120014405#if 0
14406// Not currently covered by SPIRV-Tools validator
Karl Schultz6addd812016-02-02 17:17:23 -070014407TEST_F(VkLayerTest, InvalidSPIRVVersion) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070014408 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +120014409 "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014410
Tony Barbour1fa09702017-03-16 12:09:08 -060014411 ASSERT_NO_FATAL_FAILURE(Init());
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014412 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14413
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014414 VkShaderModule module;
14415 VkShaderModuleCreateInfo moduleCreateInfo;
14416 struct icd_spv_header spv;
14417
14418 spv.magic = ICD_SPV_MAGIC;
14419 spv.version = ~ICD_SPV_VERSION;
14420 spv.gen_magic = 0;
14421
14422 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
14423 moduleCreateInfo.pNext = NULL;
14424
Karl Schultz6addd812016-02-02 17:17:23 -070014425 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014426 moduleCreateInfo.codeSize = sizeof(spv) + 10;
14427 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080014428 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014429
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014430 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014431}
Chris Forbesb4afd0f2016-04-04 10:48:35 +120014432#endif
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014433
Karl Schultz6addd812016-02-02 17:17:23 -070014434TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014435 TEST_DESCRIPTION(
14436 "Test that a warning is produced for a vertex output that "
14437 "is not consumed by the fragment stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014438 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "not consumed by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014439
Tony Barbour1fa09702017-03-16 12:09:08 -060014440 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014441 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes9f7ff632015-05-25 11:13:08 +120014442
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014443 char const *vsSource =
14444 "#version 450\n"
14445 "\n"
14446 "layout(location=0) out float x;\n"
14447 "out gl_PerVertex {\n"
14448 " vec4 gl_Position;\n"
14449 "};\n"
14450 "void main(){\n"
14451 " gl_Position = vec4(1);\n"
14452 " x = 0;\n"
14453 "}\n";
14454 char const *fsSource =
14455 "#version 450\n"
14456 "\n"
14457 "layout(location=0) out vec4 color;\n"
14458 "void main(){\n"
14459 " color = vec4(1);\n"
14460 "}\n";
Chris Forbes9f7ff632015-05-25 11:13:08 +120014461
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014462 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14463 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes9f7ff632015-05-25 11:13:08 +120014464
14465 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014466 pipe.AddColorAttachment();
Chris Forbes9f7ff632015-05-25 11:13:08 +120014467 pipe.AddShader(&vs);
14468 pipe.AddShader(&fs);
14469
Chris Forbes9f7ff632015-05-25 11:13:08 +120014470 VkDescriptorSetObj descriptorSet(m_device);
14471 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014472 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes9f7ff632015-05-25 11:13:08 +120014473
Tony Barbour5781e8f2015-08-04 16:23:11 -060014474 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes9f7ff632015-05-25 11:13:08 +120014475
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014476 m_errorMonitor->VerifyFound();
Chris Forbes9f7ff632015-05-25 11:13:08 +120014477}
Chris Forbes9f7ff632015-05-25 11:13:08 +120014478
Mark Mueller098c9cb2016-09-08 09:01:57 -060014479TEST_F(VkLayerTest, CreatePipelineCheckShaderBadSpecialization) {
14480 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
14481
Tony Barbour1fa09702017-03-16 12:09:08 -060014482 ASSERT_NO_FATAL_FAILURE(Init());
Mark Mueller098c9cb2016-09-08 09:01:57 -060014483 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14484
14485 const char *bad_specialization_message =
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014486 "Specialization entry 0 (for constant id 0) references memory outside provided specialization data ";
Mark Mueller098c9cb2016-09-08 09:01:57 -060014487
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014488 char const *vsSource =
14489 "#version 450\n"
14490 "\n"
14491 "out gl_PerVertex {\n"
14492 " vec4 gl_Position;\n"
14493 "};\n"
14494 "void main(){\n"
14495 " gl_Position = vec4(1);\n"
14496 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060014497
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014498 char const *fsSource =
14499 "#version 450\n"
14500 "\n"
14501 "layout (constant_id = 0) const float r = 0.0f;\n"
14502 "layout(location = 0) out vec4 uFragColor;\n"
14503 "void main(){\n"
14504 " uFragColor = vec4(r,1,0,1);\n"
14505 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060014506
14507 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14508 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14509
14510 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
14511 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
14512
14513 VkPipelineLayout pipeline_layout;
14514 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
14515
14516 VkPipelineViewportStateCreateInfo vp_state_create_info = {};
14517 vp_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
14518 vp_state_create_info.viewportCount = 1;
14519 VkViewport viewport = {};
14520 vp_state_create_info.pViewports = &viewport;
14521 vp_state_create_info.scissorCount = 1;
14522 VkRect2D scissors = {};
14523 vp_state_create_info.pScissors = &scissors;
14524
14525 VkDynamicState scissor_state = VK_DYNAMIC_STATE_SCISSOR;
14526
14527 VkPipelineDynamicStateCreateInfo pipeline_dynamic_state_create_info = {};
14528 pipeline_dynamic_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
14529 pipeline_dynamic_state_create_info.dynamicStateCount = 1;
14530 pipeline_dynamic_state_create_info.pDynamicStates = &scissor_state;
14531
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014532 VkPipelineShaderStageCreateInfo shader_stage_create_info[2] = {vs.GetStageCreateInfo(), fs.GetStageCreateInfo()};
Mark Mueller098c9cb2016-09-08 09:01:57 -060014533
14534 VkPipelineVertexInputStateCreateInfo vertex_input_create_info = {};
14535 vertex_input_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
14536
14537 VkPipelineInputAssemblyStateCreateInfo input_assembly_create_info = {};
14538 input_assembly_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
14539 input_assembly_create_info.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
14540
14541 VkPipelineRasterizationStateCreateInfo rasterization_state_create_info = {};
14542 rasterization_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
14543 rasterization_state_create_info.pNext = nullptr;
14544 rasterization_state_create_info.lineWidth = 1.0f;
14545 rasterization_state_create_info.rasterizerDiscardEnable = true;
14546
14547 VkPipelineColorBlendAttachmentState color_blend_attachment_state = {};
14548 color_blend_attachment_state.blendEnable = VK_FALSE;
14549 color_blend_attachment_state.colorWriteMask = 0xf;
14550
14551 VkPipelineColorBlendStateCreateInfo color_blend_state_create_info = {};
14552 color_blend_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
14553 color_blend_state_create_info.attachmentCount = 1;
14554 color_blend_state_create_info.pAttachments = &color_blend_attachment_state;
14555
14556 VkGraphicsPipelineCreateInfo graphicspipe_create_info = {};
14557 graphicspipe_create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
14558 graphicspipe_create_info.stageCount = 2;
14559 graphicspipe_create_info.pStages = shader_stage_create_info;
14560 graphicspipe_create_info.pVertexInputState = &vertex_input_create_info;
14561 graphicspipe_create_info.pInputAssemblyState = &input_assembly_create_info;
14562 graphicspipe_create_info.pViewportState = &vp_state_create_info;
14563 graphicspipe_create_info.pRasterizationState = &rasterization_state_create_info;
14564 graphicspipe_create_info.pColorBlendState = &color_blend_state_create_info;
14565 graphicspipe_create_info.pDynamicState = &pipeline_dynamic_state_create_info;
14566 graphicspipe_create_info.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
14567 graphicspipe_create_info.layout = pipeline_layout;
14568 graphicspipe_create_info.renderPass = renderPass();
14569
14570 VkPipelineCacheCreateInfo pipeline_cache_create_info = {};
14571 pipeline_cache_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
14572
14573 VkPipelineCache pipelineCache;
14574 ASSERT_VK_SUCCESS(vkCreatePipelineCache(m_device->device(), &pipeline_cache_create_info, nullptr, &pipelineCache));
14575
14576 // This structure maps constant ids to data locations.
14577 const VkSpecializationMapEntry entry =
14578 // id, offset, size
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014579 {0, 4, sizeof(uint32_t)}; // Challenge core validation by using a bogus offset.
Mark Mueller098c9cb2016-09-08 09:01:57 -060014580
14581 uint32_t data = 1;
14582
14583 // Set up the info describing spec map and data
14584 const VkSpecializationInfo specialization_info = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014585 1, &entry, 1 * sizeof(float), &data,
Mark Mueller098c9cb2016-09-08 09:01:57 -060014586 };
14587 shader_stage_create_info[0].pSpecializationInfo = &specialization_info;
14588
14589 VkPipeline pipeline;
14590 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_specialization_message);
14591 vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &graphicspipe_create_info, nullptr, &pipeline);
14592 m_errorMonitor->VerifyFound();
14593
14594 vkDestroyPipelineCache(m_device->device(), pipelineCache, nullptr);
14595 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
14596}
14597
14598TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorTypeMismatch) {
14599 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
14600
Tony Barbour1fa09702017-03-16 12:09:08 -060014601 ASSERT_NO_FATAL_FAILURE(Init());
Mark Mueller098c9cb2016-09-08 09:01:57 -060014602 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14603
14604 const char *descriptor_type_mismatch_message = "Type mismatch on descriptor slot 0.0 (used as type ";
14605
14606 VkDescriptorPoolSize descriptor_pool_type_count[2] = {};
14607 descriptor_pool_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
14608 descriptor_pool_type_count[0].descriptorCount = 1;
14609 descriptor_pool_type_count[1].type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
14610 descriptor_pool_type_count[1].descriptorCount = 1;
14611
14612 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
14613 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
14614 descriptor_pool_create_info.maxSets = 1;
14615 descriptor_pool_create_info.poolSizeCount = 2;
14616 descriptor_pool_create_info.pPoolSizes = descriptor_pool_type_count;
14617 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
14618
14619 VkDescriptorPool descriptorset_pool;
14620 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
14621
14622 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
14623 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
14624 descriptorset_layout_binding.descriptorCount = 1;
14625 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
Cody Northropa6484fd2017-03-10 14:13:49 -070014626 descriptorset_layout_binding.pImmutableSamplers = nullptr;
Mark Mueller098c9cb2016-09-08 09:01:57 -060014627
14628 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
14629 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
14630 descriptorset_layout_create_info.bindingCount = 1;
14631 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
14632
14633 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014634 ASSERT_VK_SUCCESS(
14635 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller098c9cb2016-09-08 09:01:57 -060014636
14637 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
14638 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
14639 descriptorset_allocate_info.descriptorSetCount = 1;
14640 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
14641 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
14642 VkDescriptorSet descriptorset;
14643 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
14644
14645 // Challenge core_validation with a non uniform buffer type.
14646 VkBufferTest storage_buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT);
14647
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014648 char const *vsSource =
14649 "#version 450\n"
14650 "\n"
14651 "layout (std140, set = 0, binding = 0) uniform buf {\n"
14652 " mat4 mvp;\n"
14653 "} ubuf;\n"
14654 "out gl_PerVertex {\n"
14655 " vec4 gl_Position;\n"
14656 "};\n"
14657 "void main(){\n"
14658 " gl_Position = ubuf.mvp * vec4(1);\n"
14659 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060014660
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014661 char const *fsSource =
14662 "#version 450\n"
14663 "\n"
14664 "layout(location = 0) out vec4 uFragColor;\n"
14665 "void main(){\n"
14666 " uFragColor = vec4(0,1,0,1);\n"
14667 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060014668
14669 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14670 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14671
14672 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
14673 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
14674 pipeline_layout_create_info.setLayoutCount = 1;
14675 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
14676
14677 VkPipelineLayout pipeline_layout;
14678 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
14679
14680 VkPipelineObj pipe(m_device);
14681 pipe.AddColorAttachment();
14682 pipe.AddShader(&vs);
14683 pipe.AddShader(&fs);
14684
14685 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_type_mismatch_message);
14686 pipe.CreateVKPipeline(pipeline_layout, renderPass());
14687 m_errorMonitor->VerifyFound();
14688
14689 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
14690 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
14691 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
14692}
14693
14694TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorNotAccessible) {
14695 TEST_DESCRIPTION(
14696 "Create a pipeline in which a descriptor used by a shader stage does not include that stage in its stageFlags.");
14697
Tony Barbour1fa09702017-03-16 12:09:08 -060014698 ASSERT_NO_FATAL_FAILURE(Init());
Mark Mueller098c9cb2016-09-08 09:01:57 -060014699 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14700
14701 const char *descriptor_not_accessible_message = "Shader uses descriptor slot 0.0 (used as type ";
14702
14703 VkDescriptorPoolSize descriptor_pool_type_count = {};
14704 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
14705 descriptor_pool_type_count.descriptorCount = 1;
14706
14707 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
14708 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
14709 descriptor_pool_create_info.maxSets = 1;
14710 descriptor_pool_create_info.poolSizeCount = 1;
14711 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
14712 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
14713
14714 VkDescriptorPool descriptorset_pool;
14715 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
14716
14717 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
14718 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
14719 descriptorset_layout_binding.descriptorCount = 1;
14720 // Intentionally make the uniform buffer inaccessible to the vertex shader to challenge core_validation
14721 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
Cody Northropa6484fd2017-03-10 14:13:49 -070014722 descriptorset_layout_binding.pImmutableSamplers = nullptr;
Mark Mueller098c9cb2016-09-08 09:01:57 -060014723
14724 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
14725 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
14726 descriptorset_layout_create_info.bindingCount = 1;
14727 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
14728
14729 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014730 ASSERT_VK_SUCCESS(
14731 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller098c9cb2016-09-08 09:01:57 -060014732
14733 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
14734 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
14735 descriptorset_allocate_info.descriptorSetCount = 1;
14736 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
14737 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
14738 VkDescriptorSet descriptorset;
14739 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
14740
14741 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
14742
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014743 char const *vsSource =
14744 "#version 450\n"
14745 "\n"
14746 "layout (std140, set = 0, binding = 0) uniform buf {\n"
14747 " mat4 mvp;\n"
14748 "} ubuf;\n"
14749 "out gl_PerVertex {\n"
14750 " vec4 gl_Position;\n"
14751 "};\n"
14752 "void main(){\n"
14753 " gl_Position = ubuf.mvp * vec4(1);\n"
14754 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060014755
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014756 char const *fsSource =
14757 "#version 450\n"
14758 "\n"
14759 "layout(location = 0) out vec4 uFragColor;\n"
14760 "void main(){\n"
14761 " uFragColor = vec4(0,1,0,1);\n"
14762 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060014763
14764 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14765 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14766
14767 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
14768 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
14769 pipeline_layout_create_info.setLayoutCount = 1;
14770 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
14771
14772 VkPipelineLayout pipeline_layout;
14773 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
14774
14775 VkPipelineObj pipe(m_device);
14776 pipe.AddColorAttachment();
14777 pipe.AddShader(&vs);
14778 pipe.AddShader(&fs);
14779
14780 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_not_accessible_message);
14781 pipe.CreateVKPipeline(pipeline_layout, renderPass());
14782 m_errorMonitor->VerifyFound();
14783
14784 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
14785 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
14786 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
14787}
14788
14789TEST_F(VkLayerTest, CreatePipelineCheckShaderPushConstantNotAccessible) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014790 TEST_DESCRIPTION(
14791 "Create a graphics pipleine in which a push constant range containing a push constant block member is not "
14792 "accessible from the current shader stage.");
Mark Mueller098c9cb2016-09-08 09:01:57 -060014793
Tony Barbour1fa09702017-03-16 12:09:08 -060014794 ASSERT_NO_FATAL_FAILURE(Init());
Mark Mueller098c9cb2016-09-08 09:01:57 -060014795 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14796
14797 const char *push_constant_not_accessible_message =
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014798 "Push constant range covering variable starting at offset 0 not accessible from stage VK_SHADER_STAGE_VERTEX_BIT";
Mark Mueller098c9cb2016-09-08 09:01:57 -060014799
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014800 char const *vsSource =
14801 "#version 450\n"
14802 "\n"
14803 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
14804 "out gl_PerVertex {\n"
14805 " vec4 gl_Position;\n"
14806 "};\n"
14807 "void main(){\n"
14808 " gl_Position = vec4(consts.x);\n"
14809 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060014810
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014811 char const *fsSource =
14812 "#version 450\n"
14813 "\n"
14814 "layout(location = 0) out vec4 uFragColor;\n"
14815 "void main(){\n"
14816 " uFragColor = vec4(0,1,0,1);\n"
14817 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060014818
14819 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14820 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14821
14822 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
14823 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
14824
14825 // Set up a push constant range
14826 VkPushConstantRange push_constant_ranges = {};
14827 // Set to the wrong stage to challenge core_validation
14828 push_constant_ranges.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
14829 push_constant_ranges.size = 4;
14830
14831 pipeline_layout_create_info.pPushConstantRanges = &push_constant_ranges;
14832 pipeline_layout_create_info.pushConstantRangeCount = 1;
14833
14834 VkPipelineLayout pipeline_layout;
14835 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
14836
14837 VkPipelineObj pipe(m_device);
14838 pipe.AddColorAttachment();
14839 pipe.AddShader(&vs);
14840 pipe.AddShader(&fs);
14841
14842 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, push_constant_not_accessible_message);
14843 pipe.CreateVKPipeline(pipeline_layout, renderPass());
14844 m_errorMonitor->VerifyFound();
14845
14846 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
14847}
14848
14849TEST_F(VkLayerTest, CreatePipelineCheckShaderNotEnabled) {
14850 TEST_DESCRIPTION(
14851 "Create a graphics pipeline in which a capability declared by the shader requires a feature not enabled on the device.");
14852
Tony Barbour1fa09702017-03-16 12:09:08 -060014853 ASSERT_NO_FATAL_FAILURE(Init());
Mark Mueller098c9cb2016-09-08 09:01:57 -060014854 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14855
14856 const char *feature_not_enabled_message =
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014857 "Shader requires VkPhysicalDeviceFeatures::shaderFloat64 but is not enabled on the device";
Mark Mueller098c9cb2016-09-08 09:01:57 -060014858
14859 // Some awkward steps are required to test with custom device features.
14860 std::vector<const char *> device_extension_names;
14861 auto features = m_device->phy().features();
14862 // Disable support for 64 bit floats
14863 features.shaderFloat64 = false;
14864 // The sacrificial device object
14865 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
14866
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014867 char const *vsSource =
14868 "#version 450\n"
14869 "\n"
14870 "out gl_PerVertex {\n"
14871 " vec4 gl_Position;\n"
14872 "};\n"
14873 "void main(){\n"
14874 " gl_Position = vec4(1);\n"
14875 "}\n";
14876 char const *fsSource =
14877 "#version 450\n"
14878 "\n"
14879 "layout(location=0) out vec4 color;\n"
14880 "void main(){\n"
14881 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
14882 " color = vec4(green);\n"
14883 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060014884
14885 VkShaderObj vs(&test_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14886 VkShaderObj fs(&test_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14887
14888 VkRenderpassObj render_pass(&test_device);
Mark Mueller098c9cb2016-09-08 09:01:57 -060014889
14890 VkPipelineObj pipe(&test_device);
14891 pipe.AddColorAttachment();
14892 pipe.AddShader(&vs);
14893 pipe.AddShader(&fs);
14894
14895 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
14896 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
14897 VkPipelineLayout pipeline_layout;
14898 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(test_device.device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
14899
14900 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, feature_not_enabled_message);
14901 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
14902 m_errorMonitor->VerifyFound();
14903
14904 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, nullptr);
14905}
14906
Mark Lobodzinski20832822017-03-24 14:49:45 -060014907TEST_F(VkLayerTest, CreateShaderModuleCheckBadCapability) {
14908 TEST_DESCRIPTION("Create a shader in which a capability declared by the shader is not supported.");
14909 // Note that this failure message comes from spirv-tools, specifically the validator.
Mark Mueller098c9cb2016-09-08 09:01:57 -060014910
Tony Barbour1fa09702017-03-16 12:09:08 -060014911 ASSERT_NO_FATAL_FAILURE(Init());
Mark Mueller098c9cb2016-09-08 09:01:57 -060014912 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14913
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014914 char const *vsSource =
14915 "#version 450\n"
14916 "\n"
14917 "out gl_PerVertex {\n"
14918 " vec4 gl_Position;\n"
14919 "};\n"
14920 "layout(xfb_buffer = 1) out;"
14921 "void main(){\n"
14922 " gl_Position = vec4(1);\n"
14923 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060014924
Mark Lobodzinski20832822017-03-24 14:49:45 -060014925 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Capability value 53 is not allowed by Vulkan");
Mark Mueller098c9cb2016-09-08 09:01:57 -060014926
Mark Lobodzinski20832822017-03-24 14:49:45 -060014927 std::vector<unsigned int> spv;
14928 VkShaderModuleCreateInfo module_create_info;
14929 VkShaderModule shader_module;
14930 module_create_info.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
14931 module_create_info.pNext = NULL;
14932 this->GLSLtoSPV(VK_SHADER_STAGE_VERTEX_BIT, vsSource, spv);
14933 module_create_info.pCode = spv.data();
14934 module_create_info.codeSize = spv.size() * sizeof(unsigned int);
14935 module_create_info.flags = 0;
Mark Mueller098c9cb2016-09-08 09:01:57 -060014936
Mark Lobodzinski20832822017-03-24 14:49:45 -060014937 vkCreateShaderModule(m_device->handle(), &module_create_info, NULL, &shader_module);
Mark Mueller098c9cb2016-09-08 09:01:57 -060014938
Mark Lobodzinski20832822017-03-24 14:49:45 -060014939 m_errorMonitor->VerifyFound();
Mark Mueller098c9cb2016-09-08 09:01:57 -060014940}
14941
Karl Schultz6addd812016-02-02 17:17:23 -070014942TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014943 TEST_DESCRIPTION(
14944 "Test that an error is produced for a fragment shader input "
14945 "which is not present in the outputs of the previous stage");
Chris Forbes1cc79542016-07-20 11:13:44 +120014946
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014947 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014948
Tony Barbour1fa09702017-03-16 12:09:08 -060014949 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014950 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes59cb88d2015-05-25 11:13:13 +120014951
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014952 char const *vsSource =
14953 "#version 450\n"
14954 "\n"
14955 "out gl_PerVertex {\n"
14956 " vec4 gl_Position;\n"
14957 "};\n"
14958 "void main(){\n"
14959 " gl_Position = vec4(1);\n"
14960 "}\n";
14961 char const *fsSource =
14962 "#version 450\n"
14963 "\n"
14964 "layout(location=0) in float x;\n"
14965 "layout(location=0) out vec4 color;\n"
14966 "void main(){\n"
14967 " color = vec4(x);\n"
14968 "}\n";
Chris Forbes59cb88d2015-05-25 11:13:13 +120014969
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014970 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14971 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes59cb88d2015-05-25 11:13:13 +120014972
14973 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014974 pipe.AddColorAttachment();
Chris Forbes59cb88d2015-05-25 11:13:13 +120014975 pipe.AddShader(&vs);
14976 pipe.AddShader(&fs);
14977
Chris Forbes59cb88d2015-05-25 11:13:13 +120014978 VkDescriptorSetObj descriptorSet(m_device);
14979 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014980 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes59cb88d2015-05-25 11:13:13 +120014981
Tony Barbour5781e8f2015-08-04 16:23:11 -060014982 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes59cb88d2015-05-25 11:13:13 +120014983
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014984 m_errorMonitor->VerifyFound();
Chris Forbes59cb88d2015-05-25 11:13:13 +120014985}
14986
Karl Schultz6addd812016-02-02 17:17:23 -070014987TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvidedInBlock) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014988 TEST_DESCRIPTION(
14989 "Test that an error is produced for a fragment shader input "
14990 "within an interace block, which is not present in the outputs "
14991 "of the previous stage.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014992 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Chris Forbesa3e85f62016-01-15 14:53:11 +130014993
Tony Barbour1fa09702017-03-16 12:09:08 -060014994 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbesa3e85f62016-01-15 14:53:11 +130014995 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14996
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014997 char const *vsSource =
14998 "#version 450\n"
14999 "\n"
15000 "out gl_PerVertex {\n"
15001 " vec4 gl_Position;\n"
15002 "};\n"
15003 "void main(){\n"
15004 " gl_Position = vec4(1);\n"
15005 "}\n";
15006 char const *fsSource =
15007 "#version 450\n"
15008 "\n"
15009 "in block { layout(location=0) float x; } ins;\n"
15010 "layout(location=0) out vec4 color;\n"
15011 "void main(){\n"
15012 " color = vec4(ins.x);\n"
15013 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130015014
15015 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15016 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15017
15018 VkPipelineObj pipe(m_device);
15019 pipe.AddColorAttachment();
15020 pipe.AddShader(&vs);
15021 pipe.AddShader(&fs);
15022
15023 VkDescriptorSetObj descriptorSet(m_device);
15024 descriptorSet.AppendDummy();
15025 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15026
15027 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15028
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015029 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130015030}
15031
Karl Schultz6addd812016-02-02 17:17:23 -070015032TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchArraySize) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015033 TEST_DESCRIPTION(
15034 "Test that an error is produced for mismatched array sizes "
15035 "across the vertex->fragment shader interface");
15036 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15037 "Type mismatch on location 0.0: 'ptr to "
15038 "output arr[2] of float32' vs 'ptr to "
15039 "input arr[1] of float32'");
Chris Forbes0036fd12016-01-26 14:19:49 +130015040
Tony Barbour1fa09702017-03-16 12:09:08 -060015041 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes0036fd12016-01-26 14:19:49 +130015042 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15043
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015044 char const *vsSource =
15045 "#version 450\n"
15046 "\n"
15047 "layout(location=0) out float x[2];\n"
15048 "out gl_PerVertex {\n"
15049 " vec4 gl_Position;\n"
15050 "};\n"
15051 "void main(){\n"
15052 " x[0] = 0; x[1] = 0;\n"
15053 " gl_Position = vec4(1);\n"
15054 "}\n";
15055 char const *fsSource =
15056 "#version 450\n"
15057 "\n"
15058 "layout(location=0) in float x[1];\n"
15059 "layout(location=0) out vec4 color;\n"
15060 "void main(){\n"
15061 " color = vec4(x[0]);\n"
15062 "}\n";
Chris Forbes0036fd12016-01-26 14:19:49 +130015063
15064 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15065 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15066
15067 VkPipelineObj pipe(m_device);
15068 pipe.AddColorAttachment();
15069 pipe.AddShader(&vs);
15070 pipe.AddShader(&fs);
15071
15072 VkDescriptorSetObj descriptorSet(m_device);
15073 descriptorSet.AppendDummy();
15074 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15075
15076 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15077
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015078 m_errorMonitor->VerifyFound();
Chris Forbes0036fd12016-01-26 14:19:49 +130015079}
15080
Karl Schultz6addd812016-02-02 17:17:23 -070015081TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015082 TEST_DESCRIPTION(
15083 "Test that an error is produced for mismatched types across "
15084 "the vertex->fragment shader interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015085 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015086
Tony Barbour1fa09702017-03-16 12:09:08 -060015087 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060015088 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesb56af562015-05-25 11:13:17 +120015089
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015090 char const *vsSource =
15091 "#version 450\n"
15092 "\n"
15093 "layout(location=0) out int x;\n"
15094 "out gl_PerVertex {\n"
15095 " vec4 gl_Position;\n"
15096 "};\n"
15097 "void main(){\n"
15098 " x = 0;\n"
15099 " gl_Position = vec4(1);\n"
15100 "}\n";
15101 char const *fsSource =
15102 "#version 450\n"
15103 "\n"
15104 "layout(location=0) in float x;\n" /* VS writes int */
15105 "layout(location=0) out vec4 color;\n"
15106 "void main(){\n"
15107 " color = vec4(x);\n"
15108 "}\n";
Chris Forbesb56af562015-05-25 11:13:17 +120015109
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060015110 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15111 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesb56af562015-05-25 11:13:17 +120015112
15113 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080015114 pipe.AddColorAttachment();
Chris Forbesb56af562015-05-25 11:13:17 +120015115 pipe.AddShader(&vs);
15116 pipe.AddShader(&fs);
15117
Chris Forbesb56af562015-05-25 11:13:17 +120015118 VkDescriptorSetObj descriptorSet(m_device);
15119 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015120 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesb56af562015-05-25 11:13:17 +120015121
Tony Barbour5781e8f2015-08-04 16:23:11 -060015122 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesb56af562015-05-25 11:13:17 +120015123
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015124 m_errorMonitor->VerifyFound();
Chris Forbesb56af562015-05-25 11:13:17 +120015125}
15126
Karl Schultz6addd812016-02-02 17:17:23 -070015127TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchInBlock) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015128 TEST_DESCRIPTION(
15129 "Test that an error is produced for mismatched types across "
15130 "the vertex->fragment shader interface, when the variable is contained within "
15131 "an interface block");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015132 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Chris Forbesa3e85f62016-01-15 14:53:11 +130015133
Tony Barbour1fa09702017-03-16 12:09:08 -060015134 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbesa3e85f62016-01-15 14:53:11 +130015135 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15136
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015137 char const *vsSource =
15138 "#version 450\n"
15139 "\n"
15140 "out block { layout(location=0) int x; } outs;\n"
15141 "out gl_PerVertex {\n"
15142 " vec4 gl_Position;\n"
15143 "};\n"
15144 "void main(){\n"
15145 " outs.x = 0;\n"
15146 " gl_Position = vec4(1);\n"
15147 "}\n";
15148 char const *fsSource =
15149 "#version 450\n"
15150 "\n"
15151 "in block { layout(location=0) float x; } ins;\n" /* VS writes int */
15152 "layout(location=0) out vec4 color;\n"
15153 "void main(){\n"
15154 " color = vec4(ins.x);\n"
15155 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130015156
15157 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15158 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15159
15160 VkPipelineObj pipe(m_device);
15161 pipe.AddColorAttachment();
15162 pipe.AddShader(&vs);
15163 pipe.AddShader(&fs);
15164
15165 VkDescriptorSetObj descriptorSet(m_device);
15166 descriptorSet.AppendDummy();
15167 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15168
15169 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15170
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015171 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130015172}
15173
15174TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByLocation) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015175 TEST_DESCRIPTION(
15176 "Test that an error is produced for location mismatches across "
15177 "the vertex->fragment shader interface; This should manifest as a not-written/not-consumed "
15178 "pair, but flushes out broken walking of the interfaces");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015179 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "location 0.0 which is not written by vertex shader");
Chris Forbese9928822016-02-17 14:44:52 +130015180
Tony Barbour1fa09702017-03-16 12:09:08 -060015181 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbese9928822016-02-17 14:44:52 +130015182 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15183
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015184 char const *vsSource =
15185 "#version 450\n"
15186 "\n"
15187 "out block { layout(location=1) float x; } outs;\n"
15188 "out gl_PerVertex {\n"
15189 " vec4 gl_Position;\n"
15190 "};\n"
15191 "void main(){\n"
15192 " outs.x = 0;\n"
15193 " gl_Position = vec4(1);\n"
15194 "}\n";
15195 char const *fsSource =
15196 "#version 450\n"
15197 "\n"
15198 "in block { layout(location=0) float x; } ins;\n"
15199 "layout(location=0) out vec4 color;\n"
15200 "void main(){\n"
15201 " color = vec4(ins.x);\n"
15202 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130015203
15204 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15205 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15206
15207 VkPipelineObj pipe(m_device);
15208 pipe.AddColorAttachment();
15209 pipe.AddShader(&vs);
15210 pipe.AddShader(&fs);
15211
15212 VkDescriptorSetObj descriptorSet(m_device);
15213 descriptorSet.AppendDummy();
15214 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15215
15216 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15217
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015218 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130015219}
15220
15221TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByComponent) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015222 TEST_DESCRIPTION(
15223 "Test that an error is produced for component mismatches across the "
15224 "vertex->fragment shader interface. It's not enough to have the same set of locations in "
15225 "use; matching is defined in terms of spirv variables.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015226 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "location 0.1 which is not written by vertex shader");
Chris Forbese9928822016-02-17 14:44:52 +130015227
Tony Barbour1fa09702017-03-16 12:09:08 -060015228 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbese9928822016-02-17 14:44:52 +130015229 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15230
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015231 char const *vsSource =
15232 "#version 450\n"
15233 "\n"
15234 "out block { layout(location=0, component=0) float x; } outs;\n"
15235 "out gl_PerVertex {\n"
15236 " vec4 gl_Position;\n"
15237 "};\n"
15238 "void main(){\n"
15239 " outs.x = 0;\n"
15240 " gl_Position = vec4(1);\n"
15241 "}\n";
15242 char const *fsSource =
15243 "#version 450\n"
15244 "\n"
15245 "in block { layout(location=0, component=1) float x; } ins;\n"
15246 "layout(location=0) out vec4 color;\n"
15247 "void main(){\n"
15248 " color = vec4(ins.x);\n"
15249 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130015250
15251 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15252 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15253
15254 VkPipelineObj pipe(m_device);
15255 pipe.AddColorAttachment();
15256 pipe.AddShader(&vs);
15257 pipe.AddShader(&fs);
15258
15259 VkDescriptorSetObj descriptorSet(m_device);
15260 descriptorSet.AppendDummy();
15261 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15262
15263 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15264
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015265 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130015266}
15267
Chris Forbes1f3b0152016-11-30 12:48:40 +130015268TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByPrecision) {
15269 TEST_DESCRIPTION("Test that the RelaxedPrecision decoration is validated to match");
15270
Tony Barbour1fa09702017-03-16 12:09:08 -060015271 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes1f3b0152016-11-30 12:48:40 +130015272 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15273
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015274 char const *vsSource =
15275 "#version 450\n"
15276 "layout(location=0) out mediump float x;\n"
15277 "void main() { gl_Position = vec4(0); x = 1.0; }\n";
15278 char const *fsSource =
15279 "#version 450\n"
15280 "layout(location=0) in highp float x;\n"
15281 "layout(location=0) out vec4 color;\n"
15282 "void main() { color = vec4(x); }\n";
Chris Forbes1f3b0152016-11-30 12:48:40 +130015283
15284 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15285 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15286
15287 VkPipelineObj pipe(m_device);
15288 pipe.AddColorAttachment();
15289 pipe.AddShader(&vs);
15290 pipe.AddShader(&fs);
15291
15292 VkDescriptorSetObj descriptorSet(m_device);
15293 descriptorSet.AppendDummy();
15294 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15295
15296 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "differ in precision");
15297
15298 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15299
15300 m_errorMonitor->VerifyFound();
15301}
15302
Chris Forbes870a39e2016-11-30 12:55:56 +130015303TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByPrecisionBlock) {
15304 TEST_DESCRIPTION("Test that the RelaxedPrecision decoration is validated to match");
15305
Tony Barbour1fa09702017-03-16 12:09:08 -060015306 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes870a39e2016-11-30 12:55:56 +130015307 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15308
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015309 char const *vsSource =
15310 "#version 450\n"
15311 "out block { layout(location=0) mediump float x; };\n"
15312 "void main() { gl_Position = vec4(0); x = 1.0; }\n";
15313 char const *fsSource =
15314 "#version 450\n"
15315 "in block { layout(location=0) highp float x; };\n"
15316 "layout(location=0) out vec4 color;\n"
15317 "void main() { color = vec4(x); }\n";
Chris Forbes870a39e2016-11-30 12:55:56 +130015318
15319 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15320 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15321
15322 VkPipelineObj pipe(m_device);
15323 pipe.AddColorAttachment();
15324 pipe.AddShader(&vs);
15325 pipe.AddShader(&fs);
15326
15327 VkDescriptorSetObj descriptorSet(m_device);
15328 descriptorSet.AppendDummy();
15329 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15330
15331 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "differ in precision");
15332
15333 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15334
15335 m_errorMonitor->VerifyFound();
15336}
15337
Karl Schultz6addd812016-02-02 17:17:23 -070015338TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015339 TEST_DESCRIPTION(
15340 "Test that a warning is produced for a vertex attribute which is "
15341 "not consumed by the vertex shader");
Mike Weiblencce7ec72016-10-17 19:33:05 -060015342 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015343
Tony Barbour1fa09702017-03-16 12:09:08 -060015344 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060015345 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesde136e02015-05-25 11:13:28 +120015346
15347 VkVertexInputBindingDescription input_binding;
15348 memset(&input_binding, 0, sizeof(input_binding));
15349
15350 VkVertexInputAttributeDescription input_attrib;
15351 memset(&input_attrib, 0, sizeof(input_attrib));
15352 input_attrib.format = VK_FORMAT_R32_SFLOAT;
15353
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015354 char const *vsSource =
15355 "#version 450\n"
15356 "\n"
15357 "out gl_PerVertex {\n"
15358 " vec4 gl_Position;\n"
15359 "};\n"
15360 "void main(){\n"
15361 " gl_Position = vec4(1);\n"
15362 "}\n";
15363 char const *fsSource =
15364 "#version 450\n"
15365 "\n"
15366 "layout(location=0) out vec4 color;\n"
15367 "void main(){\n"
15368 " color = vec4(1);\n"
15369 "}\n";
Chris Forbesde136e02015-05-25 11:13:28 +120015370
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060015371 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15372 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesde136e02015-05-25 11:13:28 +120015373
15374 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080015375 pipe.AddColorAttachment();
Chris Forbesde136e02015-05-25 11:13:28 +120015376 pipe.AddShader(&vs);
15377 pipe.AddShader(&fs);
15378
15379 pipe.AddVertexInputBindings(&input_binding, 1);
15380 pipe.AddVertexInputAttribs(&input_attrib, 1);
15381
Chris Forbesde136e02015-05-25 11:13:28 +120015382 VkDescriptorSetObj descriptorSet(m_device);
15383 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015384 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesde136e02015-05-25 11:13:28 +120015385
Tony Barbour5781e8f2015-08-04 16:23:11 -060015386 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesde136e02015-05-25 11:13:28 +120015387
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015388 m_errorMonitor->VerifyFound();
Chris Forbesde136e02015-05-25 11:13:28 +120015389}
15390
Karl Schultz6addd812016-02-02 17:17:23 -070015391TEST_F(VkLayerTest, CreatePipelineAttribLocationMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015392 TEST_DESCRIPTION(
15393 "Test that a warning is produced for a location mismatch on "
15394 "vertex attributes. This flushes out bad behavior in the interface walker");
Mike Weiblencce7ec72016-10-17 19:33:05 -060015395 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Chris Forbes7d83cd52016-01-15 11:32:03 +130015396
Tony Barbour1fa09702017-03-16 12:09:08 -060015397 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes7d83cd52016-01-15 11:32:03 +130015398 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15399
15400 VkVertexInputBindingDescription input_binding;
15401 memset(&input_binding, 0, sizeof(input_binding));
15402
15403 VkVertexInputAttributeDescription input_attrib;
15404 memset(&input_attrib, 0, sizeof(input_attrib));
15405 input_attrib.format = VK_FORMAT_R32_SFLOAT;
15406
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015407 char const *vsSource =
15408 "#version 450\n"
15409 "\n"
15410 "layout(location=1) in float x;\n"
15411 "out gl_PerVertex {\n"
15412 " vec4 gl_Position;\n"
15413 "};\n"
15414 "void main(){\n"
15415 " gl_Position = vec4(x);\n"
15416 "}\n";
15417 char const *fsSource =
15418 "#version 450\n"
15419 "\n"
15420 "layout(location=0) out vec4 color;\n"
15421 "void main(){\n"
15422 " color = vec4(1);\n"
15423 "}\n";
Chris Forbes7d83cd52016-01-15 11:32:03 +130015424
15425 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15426 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15427
15428 VkPipelineObj pipe(m_device);
15429 pipe.AddColorAttachment();
15430 pipe.AddShader(&vs);
15431 pipe.AddShader(&fs);
15432
15433 pipe.AddVertexInputBindings(&input_binding, 1);
15434 pipe.AddVertexInputAttribs(&input_attrib, 1);
15435
15436 VkDescriptorSetObj descriptorSet(m_device);
15437 descriptorSet.AppendDummy();
15438 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15439
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070015440 m_errorMonitor->SetUnexpectedError("Vertex shader consumes input at location 1 but not provided");
Chris Forbes7d83cd52016-01-15 11:32:03 +130015441 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15442
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015443 m_errorMonitor->VerifyFound();
Chris Forbes7d83cd52016-01-15 11:32:03 +130015444}
15445
Karl Schultz6addd812016-02-02 17:17:23 -070015446TEST_F(VkLayerTest, CreatePipelineAttribNotProvided) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015447 TEST_DESCRIPTION(
15448 "Test that an error is produced for a vertex shader input which is not "
15449 "provided by a vertex attribute");
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070015450 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15451 "Vertex shader consumes input at location 0 but not provided");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015452
Tony Barbour1fa09702017-03-16 12:09:08 -060015453 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060015454 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes62e8e502015-05-25 11:13:29 +120015455
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015456 char const *vsSource =
15457 "#version 450\n"
15458 "\n"
15459 "layout(location=0) in vec4 x;\n" /* not provided */
15460 "out gl_PerVertex {\n"
15461 " vec4 gl_Position;\n"
15462 "};\n"
15463 "void main(){\n"
15464 " gl_Position = x;\n"
15465 "}\n";
15466 char const *fsSource =
15467 "#version 450\n"
15468 "\n"
15469 "layout(location=0) out vec4 color;\n"
15470 "void main(){\n"
15471 " color = vec4(1);\n"
15472 "}\n";
Chris Forbes62e8e502015-05-25 11:13:29 +120015473
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060015474 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15475 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes62e8e502015-05-25 11:13:29 +120015476
15477 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080015478 pipe.AddColorAttachment();
Chris Forbes62e8e502015-05-25 11:13:29 +120015479 pipe.AddShader(&vs);
15480 pipe.AddShader(&fs);
15481
Chris Forbes62e8e502015-05-25 11:13:29 +120015482 VkDescriptorSetObj descriptorSet(m_device);
15483 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015484 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes62e8e502015-05-25 11:13:29 +120015485
Tony Barbour5781e8f2015-08-04 16:23:11 -060015486 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes62e8e502015-05-25 11:13:29 +120015487
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015488 m_errorMonitor->VerifyFound();
Chris Forbes62e8e502015-05-25 11:13:29 +120015489}
15490
Karl Schultz6addd812016-02-02 17:17:23 -070015491TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015492 TEST_DESCRIPTION(
15493 "Test that an error is produced for a mismatch between the "
15494 "fundamental type (float/int/uint) of an attribute and the "
15495 "vertex shader input that consumes it");
Mike Weiblen15bd38e2016-10-03 19:19:41 -060015496 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "location 0 does not match vertex shader input type");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015497
Tony Barbour1fa09702017-03-16 12:09:08 -060015498 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060015499 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc97d98e2015-05-25 11:13:31 +120015500
15501 VkVertexInputBindingDescription input_binding;
15502 memset(&input_binding, 0, sizeof(input_binding));
15503
15504 VkVertexInputAttributeDescription input_attrib;
15505 memset(&input_attrib, 0, sizeof(input_attrib));
15506 input_attrib.format = VK_FORMAT_R32_SFLOAT;
15507
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015508 char const *vsSource =
15509 "#version 450\n"
15510 "\n"
15511 "layout(location=0) in int x;\n" /* attrib provided float */
15512 "out gl_PerVertex {\n"
15513 " vec4 gl_Position;\n"
15514 "};\n"
15515 "void main(){\n"
15516 " gl_Position = vec4(x);\n"
15517 "}\n";
15518 char const *fsSource =
15519 "#version 450\n"
15520 "\n"
15521 "layout(location=0) out vec4 color;\n"
15522 "void main(){\n"
15523 " color = vec4(1);\n"
15524 "}\n";
Chris Forbesc97d98e2015-05-25 11:13:31 +120015525
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060015526 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15527 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc97d98e2015-05-25 11:13:31 +120015528
15529 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080015530 pipe.AddColorAttachment();
Chris Forbesc97d98e2015-05-25 11:13:31 +120015531 pipe.AddShader(&vs);
15532 pipe.AddShader(&fs);
15533
15534 pipe.AddVertexInputBindings(&input_binding, 1);
15535 pipe.AddVertexInputAttribs(&input_attrib, 1);
15536
Chris Forbesc97d98e2015-05-25 11:13:31 +120015537 VkDescriptorSetObj descriptorSet(m_device);
15538 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015539 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesc97d98e2015-05-25 11:13:31 +120015540
Tony Barbour5781e8f2015-08-04 16:23:11 -060015541 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc97d98e2015-05-25 11:13:31 +120015542
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015543 m_errorMonitor->VerifyFound();
Chris Forbesc97d98e2015-05-25 11:13:31 +120015544}
15545
Chris Forbesc68b43c2016-04-06 11:18:47 +120015546TEST_F(VkLayerTest, CreatePipelineDuplicateStage) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015547 TEST_DESCRIPTION(
15548 "Test that an error is produced for a pipeline containing multiple "
15549 "shaders for the same stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015550 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15551 "Multiple shaders provided for stage VK_SHADER_STAGE_VERTEX_BIT");
Chris Forbesc68b43c2016-04-06 11:18:47 +120015552
Tony Barbour1fa09702017-03-16 12:09:08 -060015553 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbesc68b43c2016-04-06 11:18:47 +120015554 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15555
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015556 char const *vsSource =
15557 "#version 450\n"
15558 "\n"
15559 "out gl_PerVertex {\n"
15560 " vec4 gl_Position;\n"
15561 "};\n"
15562 "void main(){\n"
15563 " gl_Position = vec4(1);\n"
15564 "}\n";
15565 char const *fsSource =
15566 "#version 450\n"
15567 "\n"
15568 "layout(location=0) out vec4 color;\n"
15569 "void main(){\n"
15570 " color = vec4(1);\n"
15571 "}\n";
Chris Forbesc68b43c2016-04-06 11:18:47 +120015572
15573 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15574 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15575
15576 VkPipelineObj pipe(m_device);
15577 pipe.AddColorAttachment();
15578 pipe.AddShader(&vs);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015579 pipe.AddShader(&vs); // intentionally duplicate vertex shader attachment
Chris Forbesc68b43c2016-04-06 11:18:47 +120015580 pipe.AddShader(&fs);
15581
15582 VkDescriptorSetObj descriptorSet(m_device);
15583 descriptorSet.AppendDummy();
15584 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15585
15586 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15587
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015588 m_errorMonitor->VerifyFound();
Chris Forbesc68b43c2016-04-06 11:18:47 +120015589}
15590
Chris Forbes82ff92a2016-09-09 10:50:24 +120015591TEST_F(VkLayerTest, CreatePipelineMissingEntrypoint) {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070015592 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "No entrypoint found named `foo`");
Chris Forbes82ff92a2016-09-09 10:50:24 +120015593
Tony Barbour1fa09702017-03-16 12:09:08 -060015594 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes82ff92a2016-09-09 10:50:24 +120015595 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15596
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015597 char const *vsSource =
15598 "#version 450\n"
15599 "out gl_PerVertex {\n"
15600 " vec4 gl_Position;\n"
15601 "};\n"
15602 "void main(){\n"
15603 " gl_Position = vec4(0);\n"
15604 "}\n";
15605 char const *fsSource =
15606 "#version 450\n"
15607 "\n"
15608 "layout(location=0) out vec4 color;\n"
15609 "void main(){\n"
15610 " color = vec4(1);\n"
15611 "}\n";
Chris Forbes82ff92a2016-09-09 10:50:24 +120015612
15613 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15614 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this, "foo");
15615
15616 VkPipelineObj pipe(m_device);
15617 pipe.AddColorAttachment();
15618 pipe.AddShader(&vs);
15619 pipe.AddShader(&fs);
15620
15621 VkDescriptorSetObj descriptorSet(m_device);
15622 descriptorSet.AppendDummy();
15623 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15624
15625 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15626
15627 m_errorMonitor->VerifyFound();
15628}
15629
Chris Forbesae9d8cd2016-09-13 16:32:57 +120015630TEST_F(VkLayerTest, CreatePipelineDepthStencilRequired) {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070015631 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15632 "pDepthStencilState is NULL when rasterization is enabled and subpass "
15633 "uses a depth/stencil attachment");
Chris Forbesae9d8cd2016-09-13 16:32:57 +120015634
Tony Barbour1fa09702017-03-16 12:09:08 -060015635 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbesae9d8cd2016-09-13 16:32:57 +120015636 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15637
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015638 char const *vsSource =
15639 "#version 450\n"
15640 "void main(){ gl_Position = vec4(0); }\n";
15641 char const *fsSource =
15642 "#version 450\n"
15643 "\n"
15644 "layout(location=0) out vec4 color;\n"
15645 "void main(){\n"
15646 " color = vec4(1);\n"
15647 "}\n";
Chris Forbesae9d8cd2016-09-13 16:32:57 +120015648
15649 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15650 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15651
15652 VkPipelineObj pipe(m_device);
15653 pipe.AddColorAttachment();
15654 pipe.AddShader(&vs);
15655 pipe.AddShader(&fs);
15656
15657 VkDescriptorSetObj descriptorSet(m_device);
15658 descriptorSet.AppendDummy();
15659 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15660
15661 VkAttachmentDescription attachments[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070015662 {
15663 0, VK_FORMAT_B8G8R8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
15664 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_UNDEFINED,
15665 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
Chris Forbesae9d8cd2016-09-13 16:32:57 +120015666 },
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070015667 {
15668 0, VK_FORMAT_D16_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
15669 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_UNDEFINED,
15670 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
Chris Forbesae9d8cd2016-09-13 16:32:57 +120015671 },
15672 };
15673 VkAttachmentReference refs[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070015674 {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL}, {1, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL},
Chris Forbesae9d8cd2016-09-13 16:32:57 +120015675 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070015676 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &refs[0], nullptr, &refs[1], 0, nullptr};
15677 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesae9d8cd2016-09-13 16:32:57 +120015678 VkRenderPass rp;
15679 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
15680 ASSERT_VK_SUCCESS(err);
15681
15682 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), rp);
15683
15684 m_errorMonitor->VerifyFound();
15685
15686 vkDestroyRenderPass(m_device->device(), rp, nullptr);
15687}
15688
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015689TEST_F(VkLayerTest, CreatePipelineTessPatchDecorationMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015690 TEST_DESCRIPTION(
15691 "Test that an error is produced for a variable output from "
15692 "the TCS without the patch decoration, but consumed in the TES "
15693 "with the decoration.");
15694 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15695 "is per-vertex in tessellation control shader stage "
15696 "but per-patch in tessellation evaluation shader stage");
Chris Forbesa0193bc2016-04-04 19:19:47 +120015697
Tony Barbour1fa09702017-03-16 12:09:08 -060015698 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbesa0193bc2016-04-04 19:19:47 +120015699 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15700
Chris Forbesc1e852d2016-04-04 19:26:42 +120015701 if (!m_device->phy().features().tessellationShader) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070015702 printf(" Device does not support tessellation shaders; skipped.\n");
Chris Forbesc1e852d2016-04-04 19:26:42 +120015703 return;
15704 }
15705
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015706 char const *vsSource =
15707 "#version 450\n"
15708 "void main(){}\n";
15709 char const *tcsSource =
15710 "#version 450\n"
15711 "layout(location=0) out int x[];\n"
15712 "layout(vertices=3) out;\n"
15713 "void main(){\n"
15714 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
15715 " gl_TessLevelInner[0] = 1;\n"
15716 " x[gl_InvocationID] = gl_InvocationID;\n"
15717 "}\n";
15718 char const *tesSource =
15719 "#version 450\n"
15720 "layout(triangles, equal_spacing, cw) in;\n"
15721 "layout(location=0) patch in int x;\n"
15722 "out gl_PerVertex { vec4 gl_Position; };\n"
15723 "void main(){\n"
15724 " gl_Position.xyz = gl_TessCoord;\n"
15725 " gl_Position.w = x;\n"
15726 "}\n";
15727 char const *fsSource =
15728 "#version 450\n"
15729 "layout(location=0) out vec4 color;\n"
15730 "void main(){\n"
15731 " color = vec4(1);\n"
15732 "}\n";
Chris Forbesa0193bc2016-04-04 19:19:47 +120015733
15734 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15735 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
15736 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
15737 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15738
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015739 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
15740 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Chris Forbesa0193bc2016-04-04 19:19:47 +120015741
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015742 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Chris Forbesa0193bc2016-04-04 19:19:47 +120015743
15744 VkPipelineObj pipe(m_device);
15745 pipe.SetInputAssembly(&iasci);
15746 pipe.SetTessellation(&tsci);
15747 pipe.AddColorAttachment();
15748 pipe.AddShader(&vs);
15749 pipe.AddShader(&tcs);
15750 pipe.AddShader(&tes);
15751 pipe.AddShader(&fs);
15752
15753 VkDescriptorSetObj descriptorSet(m_device);
15754 descriptorSet.AppendDummy();
15755 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15756
15757 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15758
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015759 m_errorMonitor->VerifyFound();
Chris Forbesa0193bc2016-04-04 19:19:47 +120015760}
15761
Cort Stratton2bcca1b2017-05-05 16:02:35 -070015762TEST_F(VkLayerTest, CreatePipelineTessErrors) {
15763 TEST_DESCRIPTION("Test various errors when creating a graphics pipeline with tessellation stages active.");
15764
15765 ASSERT_NO_FATAL_FAILURE(Init());
15766 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15767
15768 if (!m_device->phy().features().tessellationShader) {
15769 printf(" Device does not support tessellation shaders; skipped.\n");
15770 return;
15771 }
15772
15773 char const *vsSource =
15774 "#version 450\n"
15775 "void main(){}\n";
15776 char const *tcsSource =
15777 "#version 450\n"
15778 "layout(vertices=3) out;\n"
15779 "void main(){\n"
15780 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
15781 " gl_TessLevelInner[0] = 1;\n"
15782 "}\n";
15783 char const *tesSource =
15784 "#version 450\n"
15785 "layout(triangles, equal_spacing, cw) in;\n"
15786 "out gl_PerVertex { vec4 gl_Position; };\n"
15787 "void main(){\n"
15788 " gl_Position.xyz = gl_TessCoord;\n"
15789 " gl_Position.w = 0;\n"
15790 "}\n";
15791 char const *fsSource =
15792 "#version 450\n"
15793 "layout(location=0) out vec4 color;\n"
15794 "void main(){\n"
15795 " color = vec4(1);\n"
15796 "}\n";
15797
15798 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15799 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
15800 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
15801 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15802
15803 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
15804 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
15805
15806 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
15807
15808 VkDescriptorSetObj descriptorSet(m_device);
15809 descriptorSet.AppendDummy();
15810 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15811
15812 {
15813 VkPipelineObj pipe(m_device);
15814 VkPipelineInputAssemblyStateCreateInfo iasci_bad = iasci;
15815 iasci_bad.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST; // otherwise we get a failure about invalid topology
15816 pipe.SetInputAssembly(&iasci_bad);
15817 pipe.AddColorAttachment();
15818 pipe.AddShader(&vs);
15819 pipe.AddShader(&fs);
15820
15821 // Pass a tess control shader without a tess eval shader
15822 pipe.AddShader(&tcs);
15823 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00534);
15824 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15825 m_errorMonitor->VerifyFound();
15826 }
15827
15828 {
15829 VkPipelineObj pipe(m_device);
15830 VkPipelineInputAssemblyStateCreateInfo iasci_bad = iasci;
15831 iasci_bad.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST; // otherwise we get a failure about invalid topology
15832 pipe.SetInputAssembly(&iasci_bad);
15833 pipe.AddColorAttachment();
15834 pipe.AddShader(&vs);
15835 pipe.AddShader(&fs);
15836
15837 // Pass a tess eval shader without a tess control shader
15838 pipe.AddShader(&tes);
15839 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00535);
15840 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15841 m_errorMonitor->VerifyFound();
15842 }
15843
15844 {
15845 VkPipelineObj pipe(m_device);
15846 pipe.SetInputAssembly(&iasci);
15847 pipe.AddColorAttachment();
15848 pipe.AddShader(&vs);
15849 pipe.AddShader(&fs);
15850
15851 // Pass patch topology without tessellation shaders
15852 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02100);
15853 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15854 m_errorMonitor->VerifyFound();
15855
15856 pipe.AddShader(&tcs);
15857 pipe.AddShader(&tes);
15858 // Pass a NULL pTessellationState (with active tessellation shader stages)
15859 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00536);
15860 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15861 m_errorMonitor->VerifyFound();
15862
15863 // Pass an invalid pTessellationState (bad sType)
15864 VkPipelineTessellationStateCreateInfo tsci_bad = tsci;
15865 tsci_bad.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
15866 pipe.SetTessellation(&tsci_bad);
15867 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01427);
15868 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15869 m_errorMonitor->VerifyFound();
15870 // Pass out-of-range patchControlPoints
15871 tsci_bad = tsci;
15872 tsci_bad.patchControlPoints = 0;
15873 pipe.SetTessellation(&tsci);
15874 pipe.SetTessellation(&tsci_bad);
15875 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01426);
15876 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15877 m_errorMonitor->VerifyFound();
15878 tsci_bad.patchControlPoints = m_device->props.limits.maxTessellationPatchSize + 1;
15879 pipe.SetTessellation(&tsci_bad);
15880 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01426);
15881 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15882 m_errorMonitor->VerifyFound();
15883 pipe.SetTessellation(&tsci);
15884
15885 // Pass an invalid primitive topology
15886 VkPipelineInputAssemblyStateCreateInfo iasci_bad = iasci;
15887 iasci_bad.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
15888 pipe.SetInputAssembly(&iasci_bad);
15889 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02099);
15890 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15891 m_errorMonitor->VerifyFound();
15892 pipe.SetInputAssembly(&iasci);
15893 }
15894}
15895
Karl Schultz6addd812016-02-02 17:17:23 -070015896TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015897 TEST_DESCRIPTION(
15898 "Test that an error is produced for a vertex attribute setup where multiple "
15899 "bindings provide the same location");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015900 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15901 "Duplicate vertex input binding descriptions for binding 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015902
Tony Barbour1fa09702017-03-16 12:09:08 -060015903 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060015904 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes280ba2c2015-06-12 11:16:41 +120015905
15906 /* Two binding descriptions for binding 0 */
15907 VkVertexInputBindingDescription input_bindings[2];
15908 memset(input_bindings, 0, sizeof(input_bindings));
15909
15910 VkVertexInputAttributeDescription input_attrib;
15911 memset(&input_attrib, 0, sizeof(input_attrib));
15912 input_attrib.format = VK_FORMAT_R32_SFLOAT;
15913
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015914 char const *vsSource =
15915 "#version 450\n"
15916 "\n"
15917 "layout(location=0) in float x;\n" /* attrib provided float */
15918 "out gl_PerVertex {\n"
15919 " vec4 gl_Position;\n"
15920 "};\n"
15921 "void main(){\n"
15922 " gl_Position = vec4(x);\n"
15923 "}\n";
15924 char const *fsSource =
15925 "#version 450\n"
15926 "\n"
15927 "layout(location=0) out vec4 color;\n"
15928 "void main(){\n"
15929 " color = vec4(1);\n"
15930 "}\n";
Chris Forbes280ba2c2015-06-12 11:16:41 +120015931
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060015932 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15933 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes280ba2c2015-06-12 11:16:41 +120015934
15935 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080015936 pipe.AddColorAttachment();
Chris Forbes280ba2c2015-06-12 11:16:41 +120015937 pipe.AddShader(&vs);
15938 pipe.AddShader(&fs);
15939
15940 pipe.AddVertexInputBindings(input_bindings, 2);
15941 pipe.AddVertexInputAttribs(&input_attrib, 1);
15942
Chris Forbes280ba2c2015-06-12 11:16:41 +120015943 VkDescriptorSetObj descriptorSet(m_device);
15944 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015945 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes280ba2c2015-06-12 11:16:41 +120015946
Tony Barbour5781e8f2015-08-04 16:23:11 -060015947 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes280ba2c2015-06-12 11:16:41 +120015948
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015949 m_errorMonitor->VerifyFound();
Chris Forbes280ba2c2015-06-12 11:16:41 +120015950}
Chris Forbes8f68b562015-05-25 11:13:32 +120015951
Karl Schultz6addd812016-02-02 17:17:23 -070015952TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015953 TEST_DESCRIPTION(
15954 "Test that an error is produced for a fragment shader which does not "
15955 "provide an output for one of the pipeline's color attachments");
Mike Weiblencce7ec72016-10-17 19:33:05 -060015956 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attachment 0 not written by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015957
Tony Barbour1fa09702017-03-16 12:09:08 -060015958 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120015959
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015960 char const *vsSource =
15961 "#version 450\n"
15962 "\n"
15963 "out gl_PerVertex {\n"
15964 " vec4 gl_Position;\n"
15965 "};\n"
15966 "void main(){\n"
15967 " gl_Position = vec4(1);\n"
15968 "}\n";
15969 char const *fsSource =
15970 "#version 450\n"
15971 "\n"
15972 "void main(){\n"
15973 "}\n";
Chris Forbes4d6d1e52015-05-25 11:13:40 +120015974
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060015975 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15976 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120015977
15978 VkPipelineObj pipe(m_device);
15979 pipe.AddShader(&vs);
15980 pipe.AddShader(&fs);
15981
Chia-I Wu08accc62015-07-07 11:50:03 +080015982 /* set up CB 0, not written */
15983 pipe.AddColorAttachment();
15984 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120015985
Chris Forbes4d6d1e52015-05-25 11:13:40 +120015986 VkDescriptorSetObj descriptorSet(m_device);
15987 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015988 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120015989
Tony Barbour5781e8f2015-08-04 16:23:11 -060015990 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120015991
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015992 m_errorMonitor->VerifyFound();
Chris Forbes4d6d1e52015-05-25 11:13:40 +120015993}
15994
Karl Schultz6addd812016-02-02 17:17:23 -070015995TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015996 TEST_DESCRIPTION(
15997 "Test that a warning is produced for a fragment shader which provides a spurious "
15998 "output with no matching attachment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015999 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060016000 "fragment shader writes to output location 1 with no matching attachment");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016001
Tony Barbour1fa09702017-03-16 12:09:08 -060016002 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120016003
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016004 char const *vsSource =
16005 "#version 450\n"
16006 "\n"
16007 "out gl_PerVertex {\n"
16008 " vec4 gl_Position;\n"
16009 "};\n"
16010 "void main(){\n"
16011 " gl_Position = vec4(1);\n"
16012 "}\n";
16013 char const *fsSource =
16014 "#version 450\n"
16015 "\n"
16016 "layout(location=0) out vec4 x;\n"
16017 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
16018 "void main(){\n"
16019 " x = vec4(1);\n"
16020 " y = vec4(1);\n"
16021 "}\n";
Chris Forbesf3fffaa2015-05-25 11:13:43 +120016022
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060016023 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
16024 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120016025
16026 VkPipelineObj pipe(m_device);
16027 pipe.AddShader(&vs);
16028 pipe.AddShader(&fs);
16029
Chia-I Wu08accc62015-07-07 11:50:03 +080016030 /* set up CB 0, not written */
16031 pipe.AddColorAttachment();
16032 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120016033 /* FS writes CB 1, but we don't configure it */
16034
Chris Forbesf3fffaa2015-05-25 11:13:43 +120016035 VkDescriptorSetObj descriptorSet(m_device);
16036 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016037 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120016038
Tony Barbour5781e8f2015-08-04 16:23:11 -060016039 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120016040
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016041 m_errorMonitor->VerifyFound();
Chris Forbesf3fffaa2015-05-25 11:13:43 +120016042}
16043
Karl Schultz6addd812016-02-02 17:17:23 -070016044TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016045 TEST_DESCRIPTION(
16046 "Test that an error is produced for a mismatch between the fundamental "
16047 "type of an fragment shader output variable, and the format of the corresponding attachment");
Mike Weiblencce7ec72016-10-17 19:33:05 -060016048 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "does not match fragment shader output type");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016049
Tony Barbour1fa09702017-03-16 12:09:08 -060016050 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbesa36d69e2015-05-25 11:13:44 +120016051
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016052 char const *vsSource =
16053 "#version 450\n"
16054 "\n"
16055 "out gl_PerVertex {\n"
16056 " vec4 gl_Position;\n"
16057 "};\n"
16058 "void main(){\n"
16059 " gl_Position = vec4(1);\n"
16060 "}\n";
16061 char const *fsSource =
16062 "#version 450\n"
16063 "\n"
16064 "layout(location=0) out ivec4 x;\n" /* not UNORM */
16065 "void main(){\n"
16066 " x = ivec4(1);\n"
16067 "}\n";
Chris Forbesa36d69e2015-05-25 11:13:44 +120016068
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060016069 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
16070 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa36d69e2015-05-25 11:13:44 +120016071
16072 VkPipelineObj pipe(m_device);
16073 pipe.AddShader(&vs);
16074 pipe.AddShader(&fs);
16075
Chia-I Wu08accc62015-07-07 11:50:03 +080016076 /* set up CB 0; type is UNORM by default */
16077 pipe.AddColorAttachment();
16078 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa36d69e2015-05-25 11:13:44 +120016079
Chris Forbesa36d69e2015-05-25 11:13:44 +120016080 VkDescriptorSetObj descriptorSet(m_device);
16081 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016082 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesa36d69e2015-05-25 11:13:44 +120016083
Tony Barbour5781e8f2015-08-04 16:23:11 -060016084 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa36d69e2015-05-25 11:13:44 +120016085
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016086 m_errorMonitor->VerifyFound();
Chris Forbesa36d69e2015-05-25 11:13:44 +120016087}
Chris Forbes7b1b8932015-06-05 14:43:36 +120016088
Karl Schultz6addd812016-02-02 17:17:23 -070016089TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016090 TEST_DESCRIPTION(
16091 "Test that an error is produced for a shader consuming a uniform "
16092 "block which has no corresponding binding in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016093 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in pipeline layout");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016094
Tony Barbour1fa09702017-03-16 12:09:08 -060016095 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes556c76c2015-08-14 12:04:59 +120016096
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016097 char const *vsSource =
16098 "#version 450\n"
16099 "\n"
16100 "out gl_PerVertex {\n"
16101 " vec4 gl_Position;\n"
16102 "};\n"
16103 "void main(){\n"
16104 " gl_Position = vec4(1);\n"
16105 "}\n";
16106 char const *fsSource =
16107 "#version 450\n"
16108 "\n"
16109 "layout(location=0) out vec4 x;\n"
16110 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
16111 "void main(){\n"
16112 " x = vec4(bar.y);\n"
16113 "}\n";
Chris Forbes556c76c2015-08-14 12:04:59 +120016114
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060016115 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
16116 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes556c76c2015-08-14 12:04:59 +120016117
Chris Forbes556c76c2015-08-14 12:04:59 +120016118 VkPipelineObj pipe(m_device);
16119 pipe.AddShader(&vs);
16120 pipe.AddShader(&fs);
16121
16122 /* set up CB 0; type is UNORM by default */
16123 pipe.AddColorAttachment();
16124 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16125
16126 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016127 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes556c76c2015-08-14 12:04:59 +120016128
16129 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
16130
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016131 m_errorMonitor->VerifyFound();
Chris Forbes556c76c2015-08-14 12:04:59 +120016132}
16133
Chris Forbes5c59e902016-02-26 16:56:09 +130016134TEST_F(VkLayerTest, CreatePipelinePushConstantsNotInLayout) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016135 TEST_DESCRIPTION(
16136 "Test that an error is produced for a shader consuming push constants "
16137 "which are not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016138 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in layout");
Chris Forbes5c59e902016-02-26 16:56:09 +130016139
Tony Barbour1fa09702017-03-16 12:09:08 -060016140 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes5c59e902016-02-26 16:56:09 +130016141
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016142 char const *vsSource =
16143 "#version 450\n"
16144 "\n"
16145 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
16146 "out gl_PerVertex {\n"
16147 " vec4 gl_Position;\n"
16148 "};\n"
16149 "void main(){\n"
16150 " gl_Position = vec4(consts.x);\n"
16151 "}\n";
16152 char const *fsSource =
16153 "#version 450\n"
16154 "\n"
16155 "layout(location=0) out vec4 x;\n"
16156 "void main(){\n"
16157 " x = vec4(1);\n"
16158 "}\n";
Chris Forbes5c59e902016-02-26 16:56:09 +130016159
16160 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
16161 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
16162
16163 VkPipelineObj pipe(m_device);
16164 pipe.AddShader(&vs);
16165 pipe.AddShader(&fs);
16166
16167 /* set up CB 0; type is UNORM by default */
16168 pipe.AddColorAttachment();
16169 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16170
16171 VkDescriptorSetObj descriptorSet(m_device);
16172 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
16173
16174 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
16175
16176 /* should have generated an error -- no push constant ranges provided! */
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016177 m_errorMonitor->VerifyFound();
Chris Forbes5c59e902016-02-26 16:56:09 +130016178}
16179
Chris Forbes3fb17902016-08-22 14:57:55 +120016180TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissing) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016181 TEST_DESCRIPTION(
16182 "Test that an error is produced for a shader consuming an input attachment "
16183 "which is not included in the subpass description");
Chris Forbes3fb17902016-08-22 14:57:55 +120016184 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16185 "consumes input attachment index 0 but not provided in subpass");
16186
Tony Barbour1fa09702017-03-16 12:09:08 -060016187 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes3fb17902016-08-22 14:57:55 +120016188
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016189 char const *vsSource =
16190 "#version 450\n"
16191 "\n"
16192 "out gl_PerVertex {\n"
16193 " vec4 gl_Position;\n"
16194 "};\n"
16195 "void main(){\n"
16196 " gl_Position = vec4(1);\n"
16197 "}\n";
16198 char const *fsSource =
16199 "#version 450\n"
16200 "\n"
16201 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
16202 "layout(location=0) out vec4 color;\n"
16203 "void main() {\n"
16204 " color = subpassLoad(x);\n"
16205 "}\n";
Chris Forbes3fb17902016-08-22 14:57:55 +120016206
16207 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
16208 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
16209
16210 VkPipelineObj pipe(m_device);
16211 pipe.AddShader(&vs);
16212 pipe.AddShader(&fs);
16213 pipe.AddColorAttachment();
16214 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16215
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016216 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
16217 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes3fb17902016-08-22 14:57:55 +120016218 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016219 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes3fb17902016-08-22 14:57:55 +120016220 ASSERT_VK_SUCCESS(err);
16221
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016222 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes3fb17902016-08-22 14:57:55 +120016223 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016224 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes3fb17902016-08-22 14:57:55 +120016225 ASSERT_VK_SUCCESS(err);
16226
16227 // error here.
16228 pipe.CreateVKPipeline(pl, renderPass());
16229
16230 m_errorMonitor->VerifyFound();
16231
16232 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
16233 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
16234}
16235
Chris Forbes5a9a0472016-08-22 16:02:09 +120016236TEST_F(VkLayerTest, CreatePipelineInputAttachmentTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016237 TEST_DESCRIPTION(
16238 "Test that an error is produced for a shader consuming an input attachment "
16239 "with a format having a different fundamental type");
Chris Forbes5a9a0472016-08-22 16:02:09 +120016240 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16241 "input attachment 0 format of VK_FORMAT_R8G8B8A8_UINT does not match");
16242
Tony Barbour1fa09702017-03-16 12:09:08 -060016243 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes5a9a0472016-08-22 16:02:09 +120016244
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016245 char const *vsSource =
16246 "#version 450\n"
16247 "\n"
16248 "out gl_PerVertex {\n"
16249 " vec4 gl_Position;\n"
16250 "};\n"
16251 "void main(){\n"
16252 " gl_Position = vec4(1);\n"
16253 "}\n";
16254 char const *fsSource =
16255 "#version 450\n"
16256 "\n"
16257 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
16258 "layout(location=0) out vec4 color;\n"
16259 "void main() {\n"
16260 " color = subpassLoad(x);\n"
16261 "}\n";
Chris Forbes5a9a0472016-08-22 16:02:09 +120016262
16263 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
16264 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
16265
16266 VkPipelineObj pipe(m_device);
16267 pipe.AddShader(&vs);
16268 pipe.AddShader(&fs);
16269 pipe.AddColorAttachment();
16270 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16271
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016272 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
16273 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes5a9a0472016-08-22 16:02:09 +120016274 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016275 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120016276 ASSERT_VK_SUCCESS(err);
16277
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016278 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120016279 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016280 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120016281 ASSERT_VK_SUCCESS(err);
16282
16283 VkAttachmentDescription descs[2] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016284 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
16285 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
16286 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
16287 {0, VK_FORMAT_R8G8B8A8_UINT, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
16288 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_LAYOUT_GENERAL},
Chris Forbes5a9a0472016-08-22 16:02:09 +120016289 };
16290 VkAttachmentReference color = {
16291 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
16292 };
16293 VkAttachmentReference input = {
16294 1, VK_IMAGE_LAYOUT_GENERAL,
16295 };
16296
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016297 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120016298
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016299 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120016300 VkRenderPass rp;
16301 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
16302 ASSERT_VK_SUCCESS(err);
16303
16304 // error here.
16305 pipe.CreateVKPipeline(pl, rp);
16306
16307 m_errorMonitor->VerifyFound();
16308
16309 vkDestroyRenderPass(m_device->device(), rp, nullptr);
16310 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
16311 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
16312}
16313
Chris Forbes541f7b02016-08-22 15:30:27 +120016314TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissingArray) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016315 TEST_DESCRIPTION(
16316 "Test that an error is produced for a shader consuming an input attachment "
16317 "which is not included in the subpass description -- array case");
Chris Forbes541f7b02016-08-22 15:30:27 +120016318 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Rene Lindsay07b60af2017-01-10 15:57:55 -070016319 "consumes input attachment index 0 but not provided in subpass");
Chris Forbes541f7b02016-08-22 15:30:27 +120016320
Tony Barbour1fa09702017-03-16 12:09:08 -060016321 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes541f7b02016-08-22 15:30:27 +120016322
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016323 char const *vsSource =
16324 "#version 450\n"
16325 "\n"
16326 "out gl_PerVertex {\n"
16327 " vec4 gl_Position;\n"
16328 "};\n"
16329 "void main(){\n"
16330 " gl_Position = vec4(1);\n"
16331 "}\n";
16332 char const *fsSource =
16333 "#version 450\n"
16334 "\n"
16335 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput xs[1];\n"
16336 "layout(location=0) out vec4 color;\n"
16337 "void main() {\n"
16338 " color = subpassLoad(xs[0]);\n"
16339 "}\n";
Chris Forbes541f7b02016-08-22 15:30:27 +120016340
16341 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
16342 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
16343
16344 VkPipelineObj pipe(m_device);
16345 pipe.AddShader(&vs);
16346 pipe.AddShader(&fs);
16347 pipe.AddColorAttachment();
16348 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16349
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016350 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 2, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
16351 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes541f7b02016-08-22 15:30:27 +120016352 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016353 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes541f7b02016-08-22 15:30:27 +120016354 ASSERT_VK_SUCCESS(err);
16355
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016356 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes541f7b02016-08-22 15:30:27 +120016357 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016358 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes541f7b02016-08-22 15:30:27 +120016359 ASSERT_VK_SUCCESS(err);
16360
16361 // error here.
16362 pipe.CreateVKPipeline(pl, renderPass());
16363
16364 m_errorMonitor->VerifyFound();
16365
16366 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
16367 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
16368}
16369
Chris Forbes10eb9ae2016-05-31 16:09:42 +120016370TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptor) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016371 TEST_DESCRIPTION(
16372 "Test that an error is produced for a compute pipeline consuming a "
16373 "descriptor which is not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016374 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Shader uses descriptor slot 0.0");
Chris Forbes10eb9ae2016-05-31 16:09:42 +120016375
Tony Barbour1fa09702017-03-16 12:09:08 -060016376 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes10eb9ae2016-05-31 16:09:42 +120016377
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016378 char const *csSource =
16379 "#version 450\n"
16380 "\n"
16381 "layout(local_size_x=1) in;\n"
16382 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
16383 "void main(){\n"
16384 " x = vec4(1);\n"
16385 "}\n";
Chris Forbes10eb9ae2016-05-31 16:09:42 +120016386
16387 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
16388
16389 VkDescriptorSetObj descriptorSet(m_device);
16390 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
16391
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016392 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
16393 nullptr,
16394 0,
16395 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
16396 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
16397 descriptorSet.GetPipelineLayout(),
16398 VK_NULL_HANDLE,
16399 -1};
Chris Forbes10eb9ae2016-05-31 16:09:42 +120016400
16401 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016402 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes10eb9ae2016-05-31 16:09:42 +120016403
16404 m_errorMonitor->VerifyFound();
16405
16406 if (err == VK_SUCCESS) {
16407 vkDestroyPipeline(m_device->device(), pipe, nullptr);
16408 }
16409}
16410
Chris Forbes22a9b092016-07-19 14:34:05 +120016411TEST_F(VkLayerTest, CreateComputePipelineDescriptorTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016412 TEST_DESCRIPTION(
16413 "Test that an error is produced for a pipeline consuming a "
16414 "descriptor-backed resource of a mismatched type");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016415 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16416 "but descriptor of type VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER");
Chris Forbes22a9b092016-07-19 14:34:05 +120016417
Tony Barbour1fa09702017-03-16 12:09:08 -060016418 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes22a9b092016-07-19 14:34:05 +120016419
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016420 VkDescriptorSetLayoutBinding binding = {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr};
16421 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &binding};
Chris Forbes22a9b092016-07-19 14:34:05 +120016422 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016423 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes22a9b092016-07-19 14:34:05 +120016424 ASSERT_VK_SUCCESS(err);
16425
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016426 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes22a9b092016-07-19 14:34:05 +120016427 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016428 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes22a9b092016-07-19 14:34:05 +120016429 ASSERT_VK_SUCCESS(err);
16430
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016431 char const *csSource =
16432 "#version 450\n"
16433 "\n"
16434 "layout(local_size_x=1) in;\n"
16435 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
16436 "void main() {\n"
16437 " x.x = 1.0f;\n"
16438 "}\n";
Chris Forbes22a9b092016-07-19 14:34:05 +120016439 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
16440
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016441 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
16442 nullptr,
16443 0,
16444 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
16445 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
16446 pl,
16447 VK_NULL_HANDLE,
16448 -1};
Chris Forbes22a9b092016-07-19 14:34:05 +120016449
16450 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016451 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes22a9b092016-07-19 14:34:05 +120016452
16453 m_errorMonitor->VerifyFound();
16454
16455 if (err == VK_SUCCESS) {
16456 vkDestroyPipeline(m_device->device(), pipe, nullptr);
16457 }
16458
16459 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
16460 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
16461}
16462
Chris Forbes50020592016-07-27 13:52:41 +120016463TEST_F(VkLayerTest, DrawTimeImageViewTypeMismatchWithPipeline) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016464 TEST_DESCRIPTION(
16465 "Test that an error is produced when an image view type "
16466 "does not match the dimensionality declared in the shader");
Chris Forbes50020592016-07-27 13:52:41 +120016467
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016468 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "requires an image view of type VK_IMAGE_VIEW_TYPE_3D");
Chris Forbes50020592016-07-27 13:52:41 +120016469
Tony Barbour1fa09702017-03-16 12:09:08 -060016470 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes50020592016-07-27 13:52:41 +120016471 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16472
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016473 char const *vsSource =
16474 "#version 450\n"
16475 "\n"
16476 "out gl_PerVertex { vec4 gl_Position; };\n"
16477 "void main() { gl_Position = vec4(0); }\n";
16478 char const *fsSource =
16479 "#version 450\n"
16480 "\n"
16481 "layout(set=0, binding=0) uniform sampler3D s;\n"
16482 "layout(location=0) out vec4 color;\n"
16483 "void main() {\n"
16484 " color = texture(s, vec3(0));\n"
16485 "}\n";
Chris Forbes50020592016-07-27 13:52:41 +120016486 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
16487 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
16488
16489 VkPipelineObj pipe(m_device);
16490 pipe.AddShader(&vs);
16491 pipe.AddShader(&fs);
16492 pipe.AddColorAttachment();
16493
16494 VkTextureObj texture(m_device, nullptr);
16495 VkSamplerObj sampler(m_device);
16496
16497 VkDescriptorSetObj descriptorSet(m_device);
16498 descriptorSet.AppendSamplerTexture(&sampler, &texture);
16499 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
16500
16501 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
16502 ASSERT_VK_SUCCESS(err);
16503
Tony Barbour552f6c02016-12-21 14:34:07 -070016504 m_commandBuffer->BeginCommandBuffer();
16505 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes50020592016-07-27 13:52:41 +120016506
16507 m_commandBuffer->BindPipeline(pipe);
16508 m_commandBuffer->BindDescriptorSet(descriptorSet);
16509
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016510 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes50020592016-07-27 13:52:41 +120016511 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016512 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes50020592016-07-27 13:52:41 +120016513 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16514
16515 // error produced here.
16516 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
16517
16518 m_errorMonitor->VerifyFound();
16519
Tony Barbour552f6c02016-12-21 14:34:07 -070016520 m_commandBuffer->EndRenderPass();
16521 m_commandBuffer->EndCommandBuffer();
Chris Forbes50020592016-07-27 13:52:41 +120016522}
16523
Chris Forbes5533bfc2016-07-27 14:12:34 +120016524TEST_F(VkLayerTest, DrawTimeImageMultisampleMismatchWithPipeline) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016525 TEST_DESCRIPTION(
16526 "Test that an error is produced when a multisampled images "
16527 "are consumed via singlesample images types in the shader, or vice versa.");
Chris Forbes5533bfc2016-07-27 14:12:34 +120016528
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016529 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "requires bound image to have multiple samples");
Chris Forbes5533bfc2016-07-27 14:12:34 +120016530
Tony Barbour1fa09702017-03-16 12:09:08 -060016531 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes5533bfc2016-07-27 14:12:34 +120016532 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16533
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016534 char const *vsSource =
16535 "#version 450\n"
16536 "\n"
16537 "out gl_PerVertex { vec4 gl_Position; };\n"
16538 "void main() { gl_Position = vec4(0); }\n";
16539 char const *fsSource =
16540 "#version 450\n"
16541 "\n"
16542 "layout(set=0, binding=0) uniform sampler2DMS s;\n"
16543 "layout(location=0) out vec4 color;\n"
16544 "void main() {\n"
16545 " color = texelFetch(s, ivec2(0), 0);\n"
16546 "}\n";
Chris Forbes5533bfc2016-07-27 14:12:34 +120016547 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
16548 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
16549
16550 VkPipelineObj pipe(m_device);
16551 pipe.AddShader(&vs);
16552 pipe.AddShader(&fs);
16553 pipe.AddColorAttachment();
16554
16555 VkTextureObj texture(m_device, nullptr);
16556 VkSamplerObj sampler(m_device);
16557
16558 VkDescriptorSetObj descriptorSet(m_device);
16559 descriptorSet.AppendSamplerTexture(&sampler, &texture);
16560 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
16561
16562 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
16563 ASSERT_VK_SUCCESS(err);
16564
Tony Barbour552f6c02016-12-21 14:34:07 -070016565 m_commandBuffer->BeginCommandBuffer();
16566 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes5533bfc2016-07-27 14:12:34 +120016567
16568 m_commandBuffer->BindPipeline(pipe);
16569 m_commandBuffer->BindDescriptorSet(descriptorSet);
16570
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016571 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes5533bfc2016-07-27 14:12:34 +120016572 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016573 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes5533bfc2016-07-27 14:12:34 +120016574 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16575
16576 // error produced here.
16577 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
16578
16579 m_errorMonitor->VerifyFound();
16580
Tony Barbour552f6c02016-12-21 14:34:07 -070016581 m_commandBuffer->EndRenderPass();
16582 m_commandBuffer->EndCommandBuffer();
Chris Forbes5533bfc2016-07-27 14:12:34 +120016583}
16584
Mark Youngc48c4c12016-04-11 14:26:49 -060016585TEST_F(VkLayerTest, CreateImageLimitsViolationMaxWidth) {
Tony Barbour1fa09702017-03-16 12:09:08 -060016586 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060016587
Jeremy Hayesbb63cc12017-03-20 15:33:01 -060016588 VkFormat const format = VK_FORMAT_B8G8R8A8_UNORM;
16589 {
16590 VkFormatProperties properties;
16591 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), format, &properties);
16592 if (properties.optimalTilingFeatures == 0) {
16593 printf(" Image format not supported; skipped.\n");
16594 return;
16595 }
16596 }
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060016597
Jeremy Hayesbb63cc12017-03-20 15:33:01 -060016598 VkImageCreateInfo info = {};
16599 info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16600 info.pNext = NULL;
16601 info.imageType = VK_IMAGE_TYPE_2D;
16602 info.format = format;
16603 info.extent.height = 32;
16604 info.extent.depth = 1;
16605 info.mipLevels = 1;
16606 info.arrayLayers = 1;
16607 info.samples = VK_SAMPLE_COUNT_1_BIT;
16608 info.tiling = VK_IMAGE_TILING_OPTIMAL;
16609 info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
16610 info.flags = 0;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060016611
16612 // Introduce error by sending down a bogus width extent
Jeremy Hayesbb63cc12017-03-20 15:33:01 -060016613 {
16614 VkImageFormatProperties properties;
16615 auto const result = vkGetPhysicalDeviceImageFormatProperties(m_device->phy().handle(), info.format, info.imageType,
16616 info.tiling, info.usage, info.flags, &properties);
16617 ASSERT_VK_SUCCESS(result);
16618 info.extent.width = properties.maxExtent.width + 1;
16619 }
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060016620
Jeremy Hayesbb63cc12017-03-20 15:33:01 -060016621 VkImage image;
16622 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
16623 vkCreateImage(m_device->device(), &info, NULL, &image);
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016624 m_errorMonitor->VerifyFound();
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060016625}
16626
Mark Youngc48c4c12016-04-11 14:26:49 -060016627TEST_F(VkLayerTest, CreateImageLimitsViolationMinWidth) {
Tony Barbour1fa09702017-03-16 12:09:08 -060016628 ASSERT_NO_FATAL_FAILURE(Init());
Mark Youngc48c4c12016-04-11 14:26:49 -060016629
Jeremy Hayesbb63cc12017-03-20 15:33:01 -060016630 VkFormat const format = VK_FORMAT_B8G8R8A8_UNORM;
16631 {
16632 VkFormatProperties properties;
16633 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), format, &properties);
16634 if (properties.optimalTilingFeatures == 0) {
16635 printf(" Image format not supported; skipped.\n");
16636 return;
16637 }
16638 }
Mark Youngc48c4c12016-04-11 14:26:49 -060016639
Jeremy Hayesbb63cc12017-03-20 15:33:01 -060016640 VkImageCreateInfo info = {};
16641 info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16642 info.pNext = NULL;
16643 info.imageType = VK_IMAGE_TYPE_2D;
16644 info.format = format;
16645 info.extent.height = 32;
16646 info.extent.depth = 1;
16647 info.mipLevels = 1;
16648 info.arrayLayers = 1;
16649 info.samples = VK_SAMPLE_COUNT_1_BIT;
16650 info.tiling = VK_IMAGE_TILING_OPTIMAL;
16651 info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
16652 info.flags = 0;
Mark Youngc48c4c12016-04-11 14:26:49 -060016653
16654 // Introduce error by sending down a bogus width extent
Jeremy Hayesbb63cc12017-03-20 15:33:01 -060016655 info.extent.width = 0;
Mark Youngc48c4c12016-04-11 14:26:49 -060016656
Jeremy Hayesbb63cc12017-03-20 15:33:01 -060016657 VkImage image;
Tobin Ehlisa55b1d42017-04-04 12:23:48 -060016658 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02917);
Jeremy Hayesbb63cc12017-03-20 15:33:01 -060016659 m_errorMonitor->SetUnexpectedError("parameter pCreateInfo->extent.width must be greater than 0");
16660 vkCreateImage(m_device->device(), &info, NULL, &image);
Mark Youngc48c4c12016-04-11 14:26:49 -060016661 m_errorMonitor->VerifyFound();
16662}
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -070016663
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060016664TEST_F(VkLayerTest, AttachmentDescriptionUndefinedFormat) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016665 TEST_DESCRIPTION(
16666 "Create a render pass with an attachment description "
16667 "format set to VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060016668
Tony Barbour1fa09702017-03-16 12:09:08 -060016669 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060016670 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16671
Jeremy Hayes632e0ab2017-02-09 13:32:28 -070016672 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "format is VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060016673
16674 VkAttachmentReference color_attach = {};
16675 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
16676 color_attach.attachment = 0;
16677 VkSubpassDescription subpass = {};
16678 subpass.colorAttachmentCount = 1;
16679 subpass.pColorAttachments = &color_attach;
16680
16681 VkRenderPassCreateInfo rpci = {};
16682 rpci.subpassCount = 1;
16683 rpci.pSubpasses = &subpass;
16684 rpci.attachmentCount = 1;
16685 VkAttachmentDescription attach_desc = {};
16686 attach_desc.format = VK_FORMAT_UNDEFINED;
16687 rpci.pAttachments = &attach_desc;
16688 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
16689 VkRenderPass rp;
16690 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
16691
16692 m_errorMonitor->VerifyFound();
16693
16694 if (result == VK_SUCCESS) {
16695 vkDestroyRenderPass(m_device->device(), rp, NULL);
16696 }
16697}
16698
Mark Youngd339ba32016-05-30 13:28:35 -060016699TEST_F(VkLayerTest, CreateImageViewNoMemoryBoundToImage) {
16700 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -060016701 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -060016702 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -060016703
Tony Barbour1fa09702017-03-16 12:09:08 -060016704 ASSERT_NO_FATAL_FAILURE(Init());
Mark Youngd339ba32016-05-30 13:28:35 -060016705
16706 // Create an image and try to create a view with no memory backing the image
16707 VkImage image;
16708
16709 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
16710 const int32_t tex_width = 32;
16711 const int32_t tex_height = 32;
16712
16713 VkImageCreateInfo image_create_info = {};
16714 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16715 image_create_info.pNext = NULL;
16716 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16717 image_create_info.format = tex_format;
16718 image_create_info.extent.width = tex_width;
16719 image_create_info.extent.height = tex_height;
16720 image_create_info.extent.depth = 1;
16721 image_create_info.mipLevels = 1;
16722 image_create_info.arrayLayers = 1;
16723 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16724 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16725 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
16726 image_create_info.flags = 0;
16727
16728 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
16729 ASSERT_VK_SUCCESS(err);
16730
16731 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130016732 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Mark Youngd339ba32016-05-30 13:28:35 -060016733 image_view_create_info.image = image;
16734 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
16735 image_view_create_info.format = tex_format;
16736 image_view_create_info.subresourceRange.layerCount = 1;
16737 image_view_create_info.subresourceRange.baseMipLevel = 0;
16738 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016739 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -060016740
16741 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016742 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Youngd339ba32016-05-30 13:28:35 -060016743
16744 m_errorMonitor->VerifyFound();
16745 vkDestroyImage(m_device->device(), image, NULL);
16746 // If last error is success, it still created the view, so delete it.
16747 if (err == VK_SUCCESS) {
16748 vkDestroyImageView(m_device->device(), view, NULL);
16749 }
Mark Youngd339ba32016-05-30 13:28:35 -060016750}
16751
Karl Schultz6addd812016-02-02 17:17:23 -070016752TEST_F(VkLayerTest, InvalidImageViewAspect) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016753 TEST_DESCRIPTION("Create an image and try to create a view with an invalid aspectMask");
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070016754 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00741);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016755
Tony Barbour1fa09702017-03-16 12:09:08 -060016756 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060016757
Karl Schultz6addd812016-02-02 17:17:23 -070016758 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060016759 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060016760 image.Init(32, 32, 1, tex_format, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_LINEAR, 0);
Tobin Ehlis1f567a22016-05-25 16:15:18 -060016761 ASSERT_TRUE(image.initialized());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060016762
16763 VkImageViewCreateInfo image_view_create_info = {};
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060016764 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060016765 image_view_create_info.image = image.handle();
Karl Schultz6addd812016-02-02 17:17:23 -070016766 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
16767 image_view_create_info.format = tex_format;
16768 image_view_create_info.subresourceRange.baseMipLevel = 0;
16769 image_view_create_info.subresourceRange.levelCount = 1;
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060016770 image_view_create_info.subresourceRange.layerCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070016771 // Cause an error by setting an invalid image aspect
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016772 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060016773
16774 VkImageView view;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060016775 vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060016776
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016777 m_errorMonitor->VerifyFound();
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060016778}
16779
Mike Weiblena1e13f42017-02-09 21:25:59 -070016780TEST_F(VkLayerTest, ExerciseGetImageSubresourceLayout) {
16781 TEST_DESCRIPTION("Test vkGetImageSubresourceLayout() valid usages");
16782
Tony Barbour1fa09702017-03-16 12:09:08 -060016783 ASSERT_NO_FATAL_FAILURE(Init());
Mike Weiblena1e13f42017-02-09 21:25:59 -070016784 VkSubresourceLayout subres_layout = {};
16785
16786 // VU 00732: image must have been created with tiling equal to VK_IMAGE_TILING_LINEAR
16787 {
16788 const VkImageTiling tiling = VK_IMAGE_TILING_OPTIMAL; // ERROR: violates VU 00732
16789 VkImageObj img(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060016790 img.InitNoLayout(32, 32, 1, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, tiling);
Mike Weiblena1e13f42017-02-09 21:25:59 -070016791 ASSERT_TRUE(img.initialized());
16792
16793 VkImageSubresource subres = {};
16794 subres.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16795 subres.mipLevel = 0;
16796 subres.arrayLayer = 0;
16797
16798 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00732);
16799 vkGetImageSubresourceLayout(m_device->device(), img.image(), &subres, &subres_layout);
16800 m_errorMonitor->VerifyFound();
16801 }
16802
16803 // VU 00733: The aspectMask member of pSubresource must only have a single bit set
16804 {
16805 VkImageObj img(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060016806 img.InitNoLayout(32, 32, 1, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
Mike Weiblena1e13f42017-02-09 21:25:59 -070016807 ASSERT_TRUE(img.initialized());
16808
16809 VkImageSubresource subres = {};
16810 subres.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_METADATA_BIT; // ERROR: triggers VU 00733
16811 subres.mipLevel = 0;
16812 subres.arrayLayer = 0;
16813
16814 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00733);
16815 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00741);
16816 vkGetImageSubresourceLayout(m_device->device(), img.image(), &subres, &subres_layout);
16817 m_errorMonitor->VerifyFound();
16818 }
16819
16820 // 00739 mipLevel must be less than the mipLevels specified in VkImageCreateInfo when the image was created
16821 {
16822 VkImageObj img(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060016823 img.InitNoLayout(32, 32, 1, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
Mike Weiblena1e13f42017-02-09 21:25:59 -070016824 ASSERT_TRUE(img.initialized());
16825
16826 VkImageSubresource subres = {};
16827 subres.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16828 subres.mipLevel = 1; // ERROR: triggers VU 00739
16829 subres.arrayLayer = 0;
16830
16831 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00739);
16832 vkGetImageSubresourceLayout(m_device->device(), img.image(), &subres, &subres_layout);
16833 m_errorMonitor->VerifyFound();
16834 }
16835
16836 // 00740 arrayLayer must be less than the arrayLayers specified in VkImageCreateInfo when the image was created
16837 {
16838 VkImageObj img(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060016839 img.InitNoLayout(32, 32, 1, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
Mike Weiblena1e13f42017-02-09 21:25:59 -070016840 ASSERT_TRUE(img.initialized());
16841
16842 VkImageSubresource subres = {};
16843 subres.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16844 subres.mipLevel = 0;
16845 subres.arrayLayer = 1; // ERROR: triggers VU 00740
16846
16847 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00740);
16848 vkGetImageSubresourceLayout(m_device->device(), img.image(), &subres, &subres_layout);
16849 m_errorMonitor->VerifyFound();
16850 }
16851}
16852
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016853TEST_F(VkLayerTest, CopyImageLayerCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -070016854 VkResult err;
16855 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016856
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070016857 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01198);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016858
Tony Barbour1fa09702017-03-16 12:09:08 -060016859 ASSERT_NO_FATAL_FAILURE(Init());
Mike Stroyana3082432015-09-25 13:39:21 -060016860
16861 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070016862 VkImage srcImage;
16863 VkImage dstImage;
16864 VkDeviceMemory srcMem;
16865 VkDeviceMemory destMem;
16866 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016867
16868 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016869 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16870 image_create_info.pNext = NULL;
16871 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16872 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16873 image_create_info.extent.width = 32;
16874 image_create_info.extent.height = 32;
16875 image_create_info.extent.depth = 1;
16876 image_create_info.mipLevels = 1;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016877 image_create_info.arrayLayers = 4;
Karl Schultz6addd812016-02-02 17:17:23 -070016878 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16879 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16880 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16881 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016882
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016883 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016884 ASSERT_VK_SUCCESS(err);
16885
Mark Lobodzinski867787a2016-10-14 11:49:55 -060016886 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016887 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016888 ASSERT_VK_SUCCESS(err);
16889
16890 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016891 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016892 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16893 memAlloc.pNext = NULL;
16894 memAlloc.allocationSize = 0;
16895 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016896
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060016897 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016898 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016899 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016900 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016901 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016902 ASSERT_VK_SUCCESS(err);
16903
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016904 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016905 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016906 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016907 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016908 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016909 ASSERT_VK_SUCCESS(err);
16910
16911 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16912 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016913 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016914 ASSERT_VK_SUCCESS(err);
16915
Tony Barbour552f6c02016-12-21 14:34:07 -070016916 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060016917 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016918 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016919 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060016920 copyRegion.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016921 copyRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060016922 copyRegion.srcOffset.x = 0;
16923 copyRegion.srcOffset.y = 0;
16924 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016925 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016926 copyRegion.dstSubresource.mipLevel = 0;
16927 copyRegion.dstSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016928 // Introduce failure by forcing the dst layerCount to differ from src
16929 copyRegion.dstSubresource.layerCount = 3;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016930 copyRegion.dstOffset.x = 0;
16931 copyRegion.dstOffset.y = 0;
16932 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016933 copyRegion.extent.width = 1;
16934 copyRegion.extent.height = 1;
16935 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016936 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070016937 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060016938
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016939 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060016940
Chia-I Wuf7458c52015-10-26 21:10:41 +080016941 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016942 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016943 vkFreeMemory(m_device->device(), srcMem, NULL);
16944 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016945}
16946
Tony Barbourd6673642016-05-05 14:46:39 -060016947TEST_F(VkLayerTest, ImageLayerUnsupportedFormat) {
Tony Barbourd6673642016-05-05 14:46:39 -060016948 TEST_DESCRIPTION("Creating images with unsuported formats ");
16949
Tony Barbour1fa09702017-03-16 12:09:08 -060016950 ASSERT_NO_FATAL_FAILURE(Init());
Tony Barbourd6673642016-05-05 14:46:39 -060016951 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourd6673642016-05-05 14:46:39 -060016952
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060016953 // Create image with unsupported format - Expect FORMAT_UNSUPPORTED
Chris Forbesf4d8e332016-11-28 17:51:10 +130016954 VkImageCreateInfo image_create_info = {};
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060016955 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060016956 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16957 image_create_info.format = VK_FORMAT_UNDEFINED;
16958 image_create_info.extent.width = 32;
16959 image_create_info.extent.height = 32;
16960 image_create_info.extent.depth = 1;
16961 image_create_info.mipLevels = 1;
16962 image_create_info.arrayLayers = 1;
16963 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16964 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16965 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060016966
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016967 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16968 "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED");
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060016969
Jeremy Hayes96dcd812017-03-14 14:04:19 -060016970 VkImage image;
16971 vkCreateImage(m_device->handle(), &image_create_info, NULL, &image);
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060016972 m_errorMonitor->VerifyFound();
16973
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060016974 // Look for a format that is COMPLETELY unsupported with this hardware
Jeremy Hayes96dcd812017-03-14 14:04:19 -060016975 VkFormat unsupported = VK_FORMAT_UNDEFINED;
Tony Barbourd6673642016-05-05 14:46:39 -060016976 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
16977 VkFormat format = static_cast<VkFormat>(f);
16978 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016979 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Tony Barbourd6673642016-05-05 14:46:39 -060016980 unsupported = format;
16981 break;
16982 }
16983 }
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060016984
Tony Barbourd6673642016-05-05 14:46:39 -060016985 if (unsupported != VK_FORMAT_UNDEFINED) {
Tony Barbourd6673642016-05-05 14:46:39 -060016986 image_create_info.format = unsupported;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016987 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is an unsupported format");
Tony Barbourd6673642016-05-05 14:46:39 -060016988
Jeremy Hayes96dcd812017-03-14 14:04:19 -060016989 vkCreateImage(m_device->handle(), &image_create_info, NULL, &image);
Tony Barbourd6673642016-05-05 14:46:39 -060016990 m_errorMonitor->VerifyFound();
16991 }
16992}
16993
16994TEST_F(VkLayerTest, ImageLayerViewTests) {
Tony Barbourd6673642016-05-05 14:46:39 -060016995 TEST_DESCRIPTION("Passing bad parameters to CreateImageView");
16996
Tony Barbour1fa09702017-03-16 12:09:08 -060016997 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -060016998 auto depth_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbourf887b162017-03-09 10:06:46 -070016999 if (!depth_format) {
17000 return;
17001 }
Tony Barbourd6673642016-05-05 14:46:39 -060017002
17003 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017004 image.Init(128, 128, 1, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
Tony Barbourd6673642016-05-05 14:46:39 -060017005 VK_IMAGE_TILING_OPTIMAL, 0);
17006 ASSERT_TRUE(image.initialized());
17007
17008 VkImageView imgView;
17009 VkImageViewCreateInfo imgViewInfo = {};
17010 imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
17011 imgViewInfo.image = image.handle();
17012 imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
17013 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
17014 imgViewInfo.subresourceRange.layerCount = 1;
17015 imgViewInfo.subresourceRange.baseMipLevel = 0;
17016 imgViewInfo.subresourceRange.levelCount = 1;
17017 imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17018
Tony Barbourd6673642016-05-05 14:46:39 -060017019
Tony Barbourd6673642016-05-05 14:46:39 -060017020 // Can't use depth format for view into color image - Expect INVALID_FORMAT
Tony Barbourf887b162017-03-09 10:06:46 -070017021 imgViewInfo.format = depth_format;
Jeremy Hayes2ffbaa72017-03-14 17:05:50 -060017022 m_errorMonitor->SetDesiredFailureMsg(
17023 VK_DEBUG_REPORT_ERROR_BIT_EXT,
17024 "Formats MUST be IDENTICAL unless VK_IMAGE_CREATE_MUTABLE_FORMAT BIT was set on image creation.");
Tony Barbourd6673642016-05-05 14:46:39 -060017025 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
17026 m_errorMonitor->VerifyFound();
17027 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
17028
Tony Barbourd6673642016-05-05 14:46:39 -060017029 // Same compatibility class but no MUTABLE_FORMAT bit - Expect
17030 // VIEW_CREATE_ERROR
17031 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UINT;
Jeremy Hayes2ffbaa72017-03-14 17:05:50 -060017032 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02172);
Tony Barbourd6673642016-05-05 14:46:39 -060017033 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
17034 m_errorMonitor->VerifyFound();
17035 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
17036
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060017037 // TODO: Update framework to easily passing mutable flag into ImageObj init
17038 // For now just allowing image for this one test to not have memory bound
Jeremy Hayes5a7cf2e2017-01-06 15:23:27 -070017039 // TODO: The following line is preventing the intended validation from occurring because of the way the error monitor works.
17040 // m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17041 // " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Tony Barbourd6673642016-05-05 14:46:39 -060017042 // Have MUTABLE_FORMAT bit but not in same compatibility class - Expect
17043 // VIEW_CREATE_ERROR
17044 VkImageCreateInfo mutImgInfo = image.create_info();
17045 VkImage mutImage;
17046 mutImgInfo.format = VK_FORMAT_R8_UINT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017047 assert(m_device->format_properties(VK_FORMAT_R8_UINT).optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
Tony Barbourd6673642016-05-05 14:46:39 -060017048 mutImgInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
17049 mutImgInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Jeremy Hayes2ffbaa72017-03-14 17:05:50 -060017050 VkResult ret = vkCreateImage(m_device->handle(), &mutImgInfo, NULL, &mutImage);
Tony Barbourd6673642016-05-05 14:46:39 -060017051 ASSERT_VK_SUCCESS(ret);
Jeremy Hayes2ffbaa72017-03-14 17:05:50 -060017052
17053 VkMemoryRequirements requirements;
17054 vkGetImageMemoryRequirements(m_device->device(), mutImage, &requirements);
17055
17056 VkMemoryAllocateInfo alloc_info{};
17057 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17058 alloc_info.pNext = NULL;
17059 alloc_info.memoryTypeIndex = 0;
17060 alloc_info.allocationSize = requirements.size;
17061 bool pass = m_device->phy().set_memory_type(requirements.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
17062 ASSERT_TRUE(pass);
17063
17064 VkDeviceMemory memory;
17065 ret = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &memory);
17066 ASSERT_VK_SUCCESS(ret);
17067
17068 ret = vkBindImageMemory(m_device->device(), mutImage, memory, 0);
17069 ASSERT_VK_SUCCESS(ret);
17070
Tony Barbourd6673642016-05-05 14:46:39 -060017071 imgViewInfo.image = mutImage;
Jeremy Hayes2ffbaa72017-03-14 17:05:50 -060017072 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02171);
Tony Barbourd6673642016-05-05 14:46:39 -060017073 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
17074 m_errorMonitor->VerifyFound();
17075 imgViewInfo.image = image.handle();
Jeremy Hayes2ffbaa72017-03-14 17:05:50 -060017076
17077 vkFreeMemory(m_device->device(), memory, NULL);
Tony Barbourd6673642016-05-05 14:46:39 -060017078 vkDestroyImage(m_device->handle(), mutImage, NULL);
17079}
17080
Petr Kraus4d718682017-05-18 03:38:41 +020017081TEST_F(VkLayerTest, ImageViewSubresourceRangeTests) {
17082 TEST_DESCRIPTION("Passing bad image subrange to CreateImageView");
17083
17084 ASSERT_NO_FATAL_FAILURE(Init());
17085 auto depth_format = FindSupportedDepthStencilFormat(gpu());
17086 if (!depth_format) {
17087 return;
17088 }
17089
17090 VkImageObj image(m_device);
17091 image.Init(128, 128, 1, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
17092 VK_IMAGE_TILING_OPTIMAL, 0);
17093 ASSERT_TRUE(image.initialized());
17094
17095 VkImageView imgView;
17096 VkImageViewCreateInfo imgViewInfo = {};
17097 imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
17098 imgViewInfo.image = image.handle();
17099 imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
17100 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
17101 imgViewInfo.subresourceRange.layerCount = 1;
17102 imgViewInfo.subresourceRange.baseMipLevel = 0;
17103 imgViewInfo.subresourceRange.levelCount = 1;
17104 imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17105
17106 // View's levelCount can't be 0
17107 imgViewInfo.subresourceRange.levelCount = 0;
17108 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
17109 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
17110 m_errorMonitor->VerifyFound();
17111 imgViewInfo.subresourceRange.levelCount = 1;
17112
17113 // View can't have baseMipLevel >= image's mipLevels
17114 imgViewInfo.subresourceRange.baseMipLevel = 1;
17115 imgViewInfo.subresourceRange.levelCount = VK_REMAINING_MIP_LEVELS;
17116 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17117 "vkCreateImageView: pCreateInfo->subresourceRange.baseMipLevel (= 1) is greater or equal "
17118 "to the mip level count of the image (i.e. greater or equal to 1).");
17119 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
17120 m_errorMonitor->VerifyFound();
17121 imgViewInfo.subresourceRange.baseMipLevel = 0;
17122 imgViewInfo.subresourceRange.levelCount = 1;
17123
17124 // View can't have baseMipLevel >= image's mipLevels
17125 imgViewInfo.subresourceRange.baseMipLevel = 1;
17126 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
17127 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
17128 m_errorMonitor->VerifyFound();
17129 imgViewInfo.subresourceRange.baseMipLevel = 0;
17130
17131 // View's baseMipLevel + levelCount can't be > image's mipLevels
17132 imgViewInfo.subresourceRange.levelCount = 2;
17133 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
17134 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
17135 m_errorMonitor->VerifyFound();
17136 imgViewInfo.subresourceRange.levelCount = 1;
17137
17138 // View's layerCount can't be 0
17139 imgViewInfo.subresourceRange.layerCount = 0;
17140 m_errorMonitor->SetDesiredFailureMsg(
17141 VK_DEBUG_REPORT_ERROR_BIT_EXT,
17142 "if pCreateInfo->viewType is VK_IMAGE_TYPE_2D, pCreateInfo->subresourceRange.layerCount must be 1");
17143 // m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02931); // overlap with param_validation
17144 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
17145 m_errorMonitor->VerifyFound();
17146 imgViewInfo.subresourceRange.layerCount = 1;
17147
17148 // View can't have baseArrayLayer >= image's arraySize
17149 imgViewInfo.subresourceRange.baseArrayLayer = 1;
17150 imgViewInfo.subresourceRange.layerCount = VK_REMAINING_ARRAY_LAYERS;
17151 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17152 "vkCreateImageView: pCreateInfo->subresourceRange.baseArrayLayer (= 1) is greater or "
17153 "equal to the arrayLayers of the image when it was created (i.e. greater or equal to 1).");
17154 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
17155 m_errorMonitor->VerifyFound();
17156 imgViewInfo.subresourceRange.baseArrayLayer = 0;
17157 imgViewInfo.subresourceRange.layerCount = 1;
17158
17159 // View can't have baseArrayLayer >= image's arraySize
17160 imgViewInfo.subresourceRange.baseArrayLayer = 1;
17161 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02931);
17162 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
17163 m_errorMonitor->VerifyFound();
17164 imgViewInfo.subresourceRange.baseArrayLayer = 0;
17165
17166 // View's baseArrayLayer + layerCount can't be > image's arrayLayers
17167 imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D_ARRAY;
17168 imgViewInfo.subresourceRange.layerCount = 2;
17169 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02931);
17170 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
17171 m_errorMonitor->VerifyFound();
17172 imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
17173 imgViewInfo.subresourceRange.layerCount = 1;
17174
17175 // View's layerCount of 2D view has to be 1
17176 imgViewInfo.subresourceRange.layerCount = 2;
17177 m_errorMonitor->SetDesiredFailureMsg(
17178 VK_DEBUG_REPORT_ERROR_BIT_EXT,
17179 "if pCreateInfo->viewType is VK_IMAGE_TYPE_2D, pCreateInfo->subresourceRange.layerCount must be 1");
17180 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
17181 m_errorMonitor->VerifyFound();
17182 imgViewInfo.subresourceRange.layerCount = 1;
17183
17184 // TODO: should test maitenance1 3D -> 2D array view feature
17185}
17186
Dave Houlton75967fc2017-03-06 17:21:16 -070017187TEST_F(VkLayerTest, CompressedImageMipCopyTests) {
17188 TEST_DESCRIPTION("Image/Buffer copies for higher mip levels");
17189
Tony Barbour1fa09702017-03-16 12:09:08 -060017190 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton75967fc2017-03-06 17:21:16 -070017191
Jamie Madill35127872017-03-15 16:17:46 -040017192 VkPhysicalDeviceFeatures device_features = {};
Dave Houlton75967fc2017-03-06 17:21:16 -070017193 ASSERT_NO_FATAL_FAILURE(GetPhysicalDeviceFeatures(&device_features));
17194 VkFormat compressed_format = VK_FORMAT_UNDEFINED;
17195 if (device_features.textureCompressionBC) {
17196 compressed_format = VK_FORMAT_BC3_SRGB_BLOCK;
17197 } else if (device_features.textureCompressionETC2) {
17198 compressed_format = VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK;
17199 } else if (device_features.textureCompressionASTC_LDR) {
17200 compressed_format = VK_FORMAT_ASTC_4x4_UNORM_BLOCK;
17201 } else {
17202 printf(" No compressed formats supported - CompressedImageMipCopyTests skipped.\n");
17203 return;
17204 }
17205
17206 VkImageCreateInfo ci;
17207 ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17208 ci.pNext = NULL;
17209 ci.flags = 0;
17210 ci.imageType = VK_IMAGE_TYPE_2D;
17211 ci.format = compressed_format;
17212 ci.extent = {32, 32, 1};
17213 ci.mipLevels = 6;
17214 ci.arrayLayers = 1;
17215 ci.samples = VK_SAMPLE_COUNT_1_BIT;
17216 ci.tiling = VK_IMAGE_TILING_OPTIMAL;
17217 ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
17218 ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
17219 ci.queueFamilyIndexCount = 0;
17220 ci.pQueueFamilyIndices = NULL;
17221 ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
17222
17223 VkImageObj image(m_device);
17224 image.init(&ci);
17225 ASSERT_TRUE(image.initialized());
17226
17227 VkImageObj odd_image(m_device);
17228 ci.extent = {31, 32, 1}; // Mips are [31,32] [15,16] [7,8] [3,4], [1,2] [1,1]
17229 odd_image.init(&ci);
17230 ASSERT_TRUE(odd_image.initialized());
17231
17232 // Allocate buffers
17233 VkMemoryPropertyFlags reqs = 0;
17234 vk_testing::Buffer buffer_1024, buffer_64, buffer_16, buffer_8;
17235 buffer_1024.init_as_src_and_dst(*m_device, 1024, reqs);
17236 buffer_64.init_as_src_and_dst(*m_device, 64, reqs);
17237 buffer_16.init_as_src_and_dst(*m_device, 16, reqs);
17238 buffer_8.init_as_src_and_dst(*m_device, 8, reqs);
17239
17240 VkBufferImageCopy region = {};
17241 region.bufferRowLength = 0;
17242 region.bufferImageHeight = 0;
17243 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17244 region.imageSubresource.layerCount = 1;
17245 region.imageOffset = {0, 0, 0};
17246 region.bufferOffset = 0;
17247
17248 // start recording
17249 m_commandBuffer->BeginCommandBuffer();
17250
17251 // Mip level copies that work - 5 levels
17252 m_errorMonitor->ExpectSuccess();
17253
17254 // Mip 0 should fit in 1k buffer - 1k texels @ 1b each
17255 region.imageExtent = {32, 32, 1};
17256 region.imageSubresource.mipLevel = 0;
17257 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_1024.handle(), 1,
17258 &region);
17259 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_1024.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17260 &region);
17261
17262 // Mip 2 should fit in 64b buffer - 64 texels @ 1b each
17263 region.imageExtent = {8, 8, 1};
17264 region.imageSubresource.mipLevel = 2;
17265 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_64.handle(), 1,
17266 &region);
17267 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17268 &region);
17269
17270 // Mip 3 should fit in 16b buffer - 16 texels @ 1b each
17271 region.imageExtent = {4, 4, 1};
17272 region.imageSubresource.mipLevel = 3;
17273 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
17274 &region);
17275 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17276 &region);
17277
17278 // Mip 4&5 should fit in 16b buffer with no complaint - 4 & 1 texels @ 1b each
17279 region.imageExtent = {2, 2, 1};
17280 region.imageSubresource.mipLevel = 4;
17281 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
17282 &region);
17283 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17284 &region);
17285
17286 region.imageExtent = {1, 1, 1};
17287 region.imageSubresource.mipLevel = 5;
17288 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
17289 &region);
17290 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17291 &region);
17292 m_errorMonitor->VerifyNotFound();
17293
17294 // Buffer must accomodate a full compressed block, regardless of texel count
17295 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01246);
17296 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_8.handle(), 1,
17297 &region);
17298 m_errorMonitor->VerifyFound();
17299 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01227);
17300 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_8.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17301 &region);
17302 m_errorMonitor->VerifyFound();
17303
17304 // Copy width < compressed block size, but not the full mip width
17305 region.imageExtent = {1, 2, 1};
17306 region.imageSubresource.mipLevel = 4;
17307 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01275);
17308 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
17309 &region);
17310 m_errorMonitor->VerifyFound();
17311 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01275);
17312 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17313 &region);
17314 m_errorMonitor->VerifyFound();
17315
17316 // Copy height < compressed block size but not the full mip height
17317 region.imageExtent = {2, 1, 1};
17318 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01276);
17319 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
17320 &region);
17321 m_errorMonitor->VerifyFound();
17322 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01276);
17323 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17324 &region);
17325 m_errorMonitor->VerifyFound();
17326
17327 // Offsets must be multiple of compressed block size
17328 region.imageOffset = {1, 1, 0};
17329 region.imageExtent = {1, 1, 1};
17330 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01273);
17331 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
17332 &region);
17333 m_errorMonitor->VerifyFound();
17334 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01273);
17335 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17336 &region);
17337 m_errorMonitor->VerifyFound();
17338
17339 // Offset + extent width = mip width - should succeed
17340 region.imageOffset = {4, 4, 0};
17341 region.imageExtent = {3, 4, 1};
17342 region.imageSubresource.mipLevel = 2;
17343 m_errorMonitor->ExpectSuccess();
17344 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), odd_image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
17345 &region);
17346 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), odd_image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17347 &region);
17348 m_errorMonitor->VerifyNotFound();
17349
17350 // Offset + extent width > mip width, but still within the final compressed block - should succeed
17351 region.imageExtent = {4, 4, 1};
17352 m_errorMonitor->ExpectSuccess();
17353 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), odd_image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
17354 &region);
17355 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), odd_image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17356 &region);
17357 m_errorMonitor->VerifyNotFound();
17358
17359 // Offset + extent width < mip width and not a multiple of block width - should fail
17360 region.imageExtent = {3, 3, 1};
17361 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01276);
17362 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), odd_image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
17363 &region);
17364 m_errorMonitor->VerifyFound();
17365 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01276);
17366 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), odd_image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17367 &region);
17368 m_errorMonitor->VerifyFound();
17369}
17370
Dave Houlton59a20702017-02-02 17:26:23 -070017371TEST_F(VkLayerTest, ImageBufferCopyTests) {
17372 TEST_DESCRIPTION("Image to buffer and buffer to image tests");
17373
Tony Barbour1fa09702017-03-16 12:09:08 -060017374 ASSERT_NO_FATAL_FAILURE(Init());
Tony Barbourf887b162017-03-09 10:06:46 -070017375 VkFormatProperties format_props = m_device->format_properties(VK_FORMAT_D24_UNORM_S8_UINT);
17376 if (!(format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT)) {
17377 printf(" VK_FORMAT_D24_UNORM_S8_UINT not supported. Skipped.\n");
17378 return;
17379 }
Dave Houlton584d51e2017-02-16 12:52:54 -070017380
17381 // Bail if any dimension of transfer granularity is 0.
17382 auto index = m_device->graphics_queue_node_index_;
17383 auto queue_family_properties = m_device->phy().queue_properties();
17384 if ((queue_family_properties[index].minImageTransferGranularity.depth == 0) ||
17385 (queue_family_properties[index].minImageTransferGranularity.width == 0) ||
17386 (queue_family_properties[index].minImageTransferGranularity.height == 0)) {
17387 printf(" Subresource copies are disallowed when xfer granularity (x|y|z) is 0. Skipped.\n");
17388 return;
17389 }
17390
Dave Houlton59a20702017-02-02 17:26:23 -070017391 VkImageObj image_64k(m_device); // 128^2 texels, 64k
17392 VkImageObj image_16k(m_device); // 64^2 texels, 16k
17393 VkImageObj image_16k_depth(m_device); // 64^2 texels, depth, 16k
Dave Houltonf3229d52017-02-21 15:59:08 -070017394 VkImageObj ds_image_4D_1S(m_device); // 256^2 texels, 512kb (256k depth, 64k stencil, 192k pack)
17395 VkImageObj ds_image_3D_1S(m_device); // 256^2 texels, 256kb (192k depth, 64k stencil)
17396 VkImageObj ds_image_2D(m_device); // 256^2 texels, 128k (128k depth)
17397 VkImageObj ds_image_1S(m_device); // 256^2 texels, 64k (64k stencil)
17398
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017399 image_64k.Init(128, 128, 1, VK_FORMAT_R8G8B8A8_UINT,
Dave Houlton59a20702017-02-02 17:26:23 -070017400 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
17401 VK_IMAGE_TILING_OPTIMAL, 0);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017402 image_16k.Init(64, 64, 1, VK_FORMAT_R8G8B8A8_UINT,
Dave Houlton59a20702017-02-02 17:26:23 -070017403 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
17404 VK_IMAGE_TILING_OPTIMAL, 0);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017405 image_16k_depth.Init(64, 64, 1, VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
Dave Houlton59a20702017-02-02 17:26:23 -070017406 VK_IMAGE_TILING_OPTIMAL, 0);
Dave Houlton59a20702017-02-02 17:26:23 -070017407 ASSERT_TRUE(image_64k.initialized());
17408 ASSERT_TRUE(image_16k.initialized());
17409 ASSERT_TRUE(image_16k_depth.initialized());
Dave Houlton59a20702017-02-02 17:26:23 -070017410
Dave Houltonf3229d52017-02-21 15:59:08 -070017411 // Verify all needed Depth/Stencil formats are supported
17412 bool missing_ds_support = false;
17413 VkFormatProperties props = {0, 0, 0};
17414 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D32_SFLOAT_S8_UINT, &props);
17415 missing_ds_support |= (props.bufferFeatures == 0 && props.linearTilingFeatures == 0 && props.optimalTilingFeatures == 0);
17416 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D24_UNORM_S8_UINT, &props);
17417 missing_ds_support |= (props.bufferFeatures == 0 && props.linearTilingFeatures == 0 && props.optimalTilingFeatures == 0);
17418 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D16_UNORM, &props);
17419 missing_ds_support |= (props.bufferFeatures == 0 && props.linearTilingFeatures == 0 && props.optimalTilingFeatures == 0);
17420 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_S8_UINT, &props);
17421 missing_ds_support |= (props.bufferFeatures == 0 && props.linearTilingFeatures == 0 && props.optimalTilingFeatures == 0);
17422
17423 if (!missing_ds_support) {
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017424 ds_image_4D_1S.Init(
17425 256, 256, 1, VK_FORMAT_D32_SFLOAT_S8_UINT,
Dave Houltonf3229d52017-02-21 15:59:08 -070017426 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
17427 VK_IMAGE_TILING_OPTIMAL, 0);
17428 ASSERT_TRUE(ds_image_4D_1S.initialized());
17429
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017430 ds_image_3D_1S.Init(
17431 256, 256, 1, VK_FORMAT_D24_UNORM_S8_UINT,
Dave Houltonf3229d52017-02-21 15:59:08 -070017432 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
17433 VK_IMAGE_TILING_OPTIMAL, 0);
17434 ASSERT_TRUE(ds_image_3D_1S.initialized());
17435
Dave Houlton11dcd5e2017-04-25 16:00:10 -060017436 ds_image_2D.Init(
17437 256, 256, 1, VK_FORMAT_D16_UNORM,
17438 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
17439 VK_IMAGE_TILING_OPTIMAL, 0);
Dave Houltonf3229d52017-02-21 15:59:08 -070017440 ASSERT_TRUE(ds_image_2D.initialized());
17441
Dave Houlton11dcd5e2017-04-25 16:00:10 -060017442 ds_image_1S.Init(
17443 256, 256, 1, VK_FORMAT_S8_UINT,
17444 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
17445 VK_IMAGE_TILING_OPTIMAL, 0);
Dave Houltonf3229d52017-02-21 15:59:08 -070017446 ASSERT_TRUE(ds_image_1S.initialized());
17447 }
17448
17449 // Allocate buffers
17450 vk_testing::Buffer buffer_256k, buffer_128k, buffer_64k, buffer_16k;
Dave Houlton59a20702017-02-02 17:26:23 -070017451 VkMemoryPropertyFlags reqs = 0;
Dave Houltonf3229d52017-02-21 15:59:08 -070017452 buffer_256k.init_as_src_and_dst(*m_device, 262144, reqs); // 256k
17453 buffer_128k.init_as_src_and_dst(*m_device, 131072, reqs); // 128k
17454 buffer_64k.init_as_src_and_dst(*m_device, 65536, reqs); // 64k
17455 buffer_16k.init_as_src_and_dst(*m_device, 16384, reqs); // 16k
Dave Houlton59a20702017-02-02 17:26:23 -070017456
17457 VkBufferImageCopy region = {};
17458 region.bufferRowLength = 0;
17459 region.bufferImageHeight = 0;
17460 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17461 region.imageSubresource.layerCount = 1;
17462 region.imageOffset = {0, 0, 0};
17463 region.imageExtent = {64, 64, 1};
17464 region.bufferOffset = 0;
17465
17466 // attempt copies before putting command buffer in recording state
17467 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01240);
17468 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64k.handle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17469 &region);
17470 m_errorMonitor->VerifyFound();
17471
17472 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01258);
17473 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_64k.handle(), 1,
17474 &region);
17475 m_errorMonitor->VerifyFound();
17476
17477 // start recording
17478 m_commandBuffer->BeginCommandBuffer();
17479
17480 // successful copies
17481 m_errorMonitor->ExpectSuccess();
17482 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
17483 &region);
17484 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16k.handle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17485 &region);
17486 region.imageOffset.x = 16; // 16k copy, offset requires larger image
17487 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
17488 &region);
17489 region.imageExtent.height = 78; // > 16k copy requires larger buffer & image
17490 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64k.handle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17491 &region);
17492 region.imageOffset.x = 0;
17493 region.imageExtent.height = 64;
17494 region.bufferOffset = 256; // 16k copy with buffer offset, requires larger buffer
17495 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_64k.handle(), 1,
17496 &region);
17497 m_errorMonitor->VerifyNotFound();
17498
Dave Houlton9dae7ec2017-03-01 16:23:25 -070017499 // image/buffer too small (extent too large) on copy to image
Dave Houlton59a20702017-02-02 17:26:23 -070017500 region.imageExtent = {65, 64, 1};
17501 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01227); // buffer too small
17502 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16k.handle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17503 &region);
17504 m_errorMonitor->VerifyFound();
17505
17506 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01228); // image too small
17507 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64k.handle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17508 &region);
17509 m_errorMonitor->VerifyFound();
17510
17511 // image/buffer too small (offset) on copy to image
17512 region.imageExtent = {64, 64, 1};
17513 region.imageOffset = {0, 4, 0};
17514 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01227); // buffer too small
17515 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16k.handle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17516 &region);
17517 m_errorMonitor->VerifyFound();
17518
17519 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01228); // image too small
17520 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64k.handle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17521 &region);
17522 m_errorMonitor->VerifyFound();
17523
17524 // image/buffer too small on copy to buffer
17525 region.imageExtent = {64, 64, 1};
17526 region.imageOffset = {0, 0, 0};
Mark Lobodzinski80871462017-02-16 10:37:27 -070017527 region.bufferOffset = 4;
Dave Houlton59a20702017-02-02 17:26:23 -070017528 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01246); // buffer too small
17529 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
17530 &region);
17531 m_errorMonitor->VerifyFound();
17532
17533 region.imageExtent = {64, 65, 1};
17534 region.bufferOffset = 0;
17535 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01245); // image too small
17536 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_64k.handle(), 1,
17537 &region);
17538 m_errorMonitor->VerifyFound();
17539
17540 // buffer size ok but rowlength causes loose packing
17541 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01246);
17542 region.imageExtent = {64, 64, 1};
17543 region.bufferRowLength = 68;
17544 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
17545 &region);
17546 m_errorMonitor->VerifyFound();
17547
Dave Houlton9dae7ec2017-03-01 16:23:25 -070017548 // An extent with zero area should produce a warning, but no error
17549 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT | VK_DEBUG_REPORT_ERROR_BIT_EXT, "} has zero area");
17550 region.imageExtent.width = 0;
17551 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
17552 &region);
17553 m_errorMonitor->VerifyFound();
17554
Dave Houlton59a20702017-02-02 17:26:23 -070017555 // aspect bits
17556 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01280); // more than 1 aspect bit set
17557 region.imageExtent = {64, 64, 1};
17558 region.bufferRowLength = 0;
17559 region.bufferImageHeight = 0;
17560 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
17561 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_depth.handle(), VK_IMAGE_LAYOUT_GENERAL,
17562 buffer_16k.handle(), 1, &region);
17563 m_errorMonitor->VerifyFound();
17564
17565 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01279); // mis-matched aspect
17566 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
17567 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
17568 &region);
17569 m_errorMonitor->VerifyFound();
17570
17571 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01279); // different mis-matched aspect
17572 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17573 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_depth.handle(), VK_IMAGE_LAYOUT_GENERAL,
17574 buffer_16k.handle(), 1, &region);
17575 m_errorMonitor->VerifyFound();
17576
Dave Houltonf3229d52017-02-21 15:59:08 -070017577 // Test Depth/Stencil copies
17578 if (missing_ds_support) {
17579 printf(" Depth / Stencil formats unsupported - skipping D/S tests.\n");
17580 } else {
17581 VkBufferImageCopy ds_region = {};
17582 ds_region.bufferOffset = 0;
17583 ds_region.bufferRowLength = 0;
17584 ds_region.bufferImageHeight = 0;
17585 ds_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
17586 ds_region.imageSubresource.mipLevel = 0;
17587 ds_region.imageSubresource.baseArrayLayer = 0;
17588 ds_region.imageSubresource.layerCount = 1;
17589 ds_region.imageOffset = {0, 0, 0};
17590 ds_region.imageExtent = {256, 256, 1};
17591
17592 // Depth copies that should succeed
17593 m_errorMonitor->ExpectSuccess(); // Extract 4b depth per texel, pack into 256k buffer
17594 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_4D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
17595 buffer_256k.handle(), 1, &ds_region);
17596 m_errorMonitor->VerifyNotFound();
17597
17598 m_errorMonitor->ExpectSuccess(); // Extract 3b depth per texel, pack (loose) into 256k buffer
17599 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_3D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
17600 buffer_256k.handle(), 1, &ds_region);
17601 m_errorMonitor->VerifyNotFound();
17602
17603 m_errorMonitor->ExpectSuccess(); // Copy 2b depth per texel, into 128k buffer
17604 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_2D.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
17605 buffer_128k.handle(), 1, &ds_region);
17606 m_errorMonitor->VerifyNotFound();
17607
17608 // Depth copies that should fail
17609 ds_region.bufferOffset = 4;
17610 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17611 VALIDATION_ERROR_01246); // Extract 4b depth per texel, pack into 256k buffer
17612 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_4D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
17613 buffer_256k.handle(), 1, &ds_region);
17614 m_errorMonitor->VerifyFound();
17615
17616 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17617 VALIDATION_ERROR_01246); // Extract 3b depth per texel, pack (loose) into 256k buffer
17618 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_3D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
17619 buffer_256k.handle(), 1, &ds_region);
17620 m_errorMonitor->VerifyFound();
17621
17622 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17623 VALIDATION_ERROR_01246); // Copy 2b depth per texel, into 128k buffer
17624 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_2D.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
17625 buffer_128k.handle(), 1, &ds_region);
17626 m_errorMonitor->VerifyFound();
17627
17628 // Stencil copies that should succeed
17629 ds_region.bufferOffset = 0;
17630 ds_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT;
17631 m_errorMonitor->ExpectSuccess(); // Extract 1b stencil per texel, pack into 64k buffer
17632 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_4D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
17633 buffer_64k.handle(), 1, &ds_region);
17634 m_errorMonitor->VerifyNotFound();
17635
17636 m_errorMonitor->ExpectSuccess(); // Extract 1b stencil per texel, pack into 64k buffer
17637 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_3D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
17638 buffer_64k.handle(), 1, &ds_region);
17639 m_errorMonitor->VerifyNotFound();
17640
17641 m_errorMonitor->ExpectSuccess(); // Copy 1b depth per texel, into 64k buffer
17642 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
17643 buffer_64k.handle(), 1, &ds_region);
17644 m_errorMonitor->VerifyNotFound();
17645
17646 // Stencil copies that should fail
17647 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17648 VALIDATION_ERROR_01246); // Extract 1b stencil per texel, pack into 64k buffer
17649 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_4D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
17650 buffer_16k.handle(), 1, &ds_region);
17651 m_errorMonitor->VerifyFound();
17652
17653 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17654 VALIDATION_ERROR_01246); // Extract 1b stencil per texel, pack into 64k buffer
17655 ds_region.bufferRowLength = 260;
17656 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_3D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
17657 buffer_64k.handle(), 1, &ds_region);
17658 m_errorMonitor->VerifyFound();
17659
17660 ds_region.bufferRowLength = 0;
17661 ds_region.bufferOffset = 4;
17662 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17663 VALIDATION_ERROR_01246); // Copy 1b depth per texel, into 64k buffer
17664 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
17665 buffer_64k.handle(), 1, &ds_region);
17666 m_errorMonitor->VerifyFound();
17667 }
17668
Dave Houlton584d51e2017-02-16 12:52:54 -070017669 // Test compressed formats, if supported
Jamie Madill35127872017-03-15 16:17:46 -040017670 VkPhysicalDeviceFeatures device_features = {};
Dave Houlton584d51e2017-02-16 12:52:54 -070017671 ASSERT_NO_FATAL_FAILURE(GetPhysicalDeviceFeatures(&device_features));
Dave Houltonf3229d52017-02-21 15:59:08 -070017672 if (!(device_features.textureCompressionBC || device_features.textureCompressionETC2 ||
17673 device_features.textureCompressionASTC_LDR)) {
17674 printf(" No compressed formats supported - block compression tests skipped.\n");
17675 } else {
Dave Houlton67e9b532017-03-02 17:00:10 -070017676 VkImageObj image_16k_4x4comp(m_device); // 128^2 texels as 32^2 compressed (4x4) blocks, 16k
17677 VkImageObj image_NPOT_4x4comp(m_device); // 130^2 texels as 33^2 compressed (4x4) blocks
Dave Houlton584d51e2017-02-16 12:52:54 -070017678 if (device_features.textureCompressionBC) {
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017679 image_16k_4x4comp.Init(128, 128, 1, VK_FORMAT_BC3_SRGB_BLOCK, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_OPTIMAL,
17680 0);
17681 image_NPOT_4x4comp.Init(130, 130, 1, VK_FORMAT_BC3_SRGB_BLOCK, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_OPTIMAL,
Dave Houlton67e9b532017-03-02 17:00:10 -070017682 0);
Dave Houlton584d51e2017-02-16 12:52:54 -070017683 } else if (device_features.textureCompressionETC2) {
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017684 image_16k_4x4comp.Init(128, 128, 1, VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK, VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
Dave Houlton584d51e2017-02-16 12:52:54 -070017685 VK_IMAGE_TILING_OPTIMAL, 0);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017686 image_NPOT_4x4comp.Init(130, 130, 1, VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK, VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
Dave Houlton67e9b532017-03-02 17:00:10 -070017687 VK_IMAGE_TILING_OPTIMAL, 0);
Dave Houlton584d51e2017-02-16 12:52:54 -070017688 } else {
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017689 image_16k_4x4comp.Init(128, 128, 1, VK_FORMAT_ASTC_4x4_UNORM_BLOCK, VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
Dave Houlton9dae7ec2017-03-01 16:23:25 -070017690 VK_IMAGE_TILING_OPTIMAL, 0);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017691 image_NPOT_4x4comp.Init(130, 130, 1, VK_FORMAT_ASTC_4x4_UNORM_BLOCK, VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
Dave Houlton67e9b532017-03-02 17:00:10 -070017692 VK_IMAGE_TILING_OPTIMAL, 0);
Dave Houlton584d51e2017-02-16 12:52:54 -070017693 }
17694 ASSERT_TRUE(image_16k_4x4comp.initialized());
Dave Houlton59a20702017-02-02 17:26:23 -070017695
Dave Houlton584d51e2017-02-16 12:52:54 -070017696 // Just fits
17697 m_errorMonitor->ExpectSuccess();
17698 region.imageExtent = {128, 128, 1};
17699 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
17700 buffer_16k.handle(), 1, &region);
17701 m_errorMonitor->VerifyNotFound();
Dave Houlton59a20702017-02-02 17:26:23 -070017702
Dave Houlton584d51e2017-02-16 12:52:54 -070017703 // with offset, too big for buffer
17704 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01246);
17705 region.bufferOffset = 16;
17706 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
17707 buffer_16k.handle(), 1, &region);
17708 m_errorMonitor->VerifyFound();
Dave Houlton67e9b532017-03-02 17:00:10 -070017709 region.bufferOffset = 0;
Dave Houlton59a20702017-02-02 17:26:23 -070017710
Dave Houlton67e9b532017-03-02 17:00:10 -070017711 // extents that are not a multiple of compressed block size
17712 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01275);
17713 region.imageExtent.width = 66;
17714 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_NPOT_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
17715 buffer_16k.handle(), 1, &region);
17716 m_errorMonitor->VerifyFound();
17717 region.imageExtent.width = 128;
17718
17719 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01276);
Dave Houlton9dae7ec2017-03-01 16:23:25 -070017720 region.imageExtent.height = 2;
Dave Houlton67e9b532017-03-02 17:00:10 -070017721 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_NPOT_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
17722 buffer_16k.handle(), 1, &region);
17723 m_errorMonitor->VerifyFound();
17724 region.imageExtent.height = 128;
17725
17726 // TODO: All available compressed formats are 2D, with block depth of 1. Unable to provoke VU_01277.
17727
17728 // non-multiple extents are allowed if at the far edge of a non-block-multiple image - these should pass
17729 m_errorMonitor->ExpectSuccess();
17730 region.imageExtent.width = 66;
17731 region.imageOffset.x = 64;
17732 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_NPOT_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
17733 buffer_16k.handle(), 1, &region);
17734 region.imageExtent.width = 16;
17735 region.imageOffset.x = 0;
17736 region.imageExtent.height = 2;
17737 region.imageOffset.y = 128;
17738 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_NPOT_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
Dave Houlton9dae7ec2017-03-01 16:23:25 -070017739 buffer_16k.handle(), 1, &region);
17740 m_errorMonitor->VerifyNotFound();
Dave Houlton67e9b532017-03-02 17:00:10 -070017741 region.imageOffset = {0, 0, 0};
Dave Houlton9dae7ec2017-03-01 16:23:25 -070017742
Dave Houlton584d51e2017-02-16 12:52:54 -070017743 // buffer offset must be a multiple of texel block size (16)
17744 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01274);
17745 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01263);
17746 region.imageExtent = {64, 64, 1};
17747 region.bufferOffset = 24;
17748 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
17749 buffer_16k.handle(), 1, &region);
17750 m_errorMonitor->VerifyFound();
Dave Houlton59a20702017-02-02 17:26:23 -070017751
Dave Houlton584d51e2017-02-16 12:52:54 -070017752 // rowlength not a multiple of block width (4)
17753 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01271);
17754 region.bufferOffset = 0;
17755 region.bufferRowLength = 130;
17756 region.bufferImageHeight = 0;
17757 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
17758 buffer_64k.handle(), 1, &region);
17759 m_errorMonitor->VerifyFound();
Dave Houlton59a20702017-02-02 17:26:23 -070017760
Dave Houlton584d51e2017-02-16 12:52:54 -070017761 // imageheight not a multiple of block height (4)
17762 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01272);
17763 region.bufferRowLength = 0;
17764 region.bufferImageHeight = 130;
17765 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
17766 buffer_64k.handle(), 1, &region);
17767 m_errorMonitor->VerifyFound();
Dave Houlton584d51e2017-02-16 12:52:54 -070017768 }
Dave Houlton59a20702017-02-02 17:26:23 -070017769}
17770
Tony Barbourd6673642016-05-05 14:46:39 -060017771TEST_F(VkLayerTest, MiscImageLayerTests) {
Mark Lobodzinskie6911292017-02-15 14:38:51 -070017772 TEST_DESCRIPTION("Image-related tests that don't belong elsewhare");
Tony Barbourd6673642016-05-05 14:46:39 -060017773
Tony Barbour1fa09702017-03-16 12:09:08 -060017774 ASSERT_NO_FATAL_FAILURE(Init());
Tony Barbourd6673642016-05-05 14:46:39 -060017775
Rene Lindsay135204f2016-12-22 17:11:09 -070017776 // TODO: Ideally we should check if a format is supported, before using it.
Tony Barbourd6673642016-05-05 14:46:39 -060017777 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017778 image.Init(128, 128, 1, VK_FORMAT_R16G16B16A16_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017779 VK_IMAGE_TILING_OPTIMAL, 0); // 64bpp
Tony Barbourd6673642016-05-05 14:46:39 -060017780 ASSERT_TRUE(image.initialized());
Tony Barbourd6673642016-05-05 14:46:39 -060017781 vk_testing::Buffer buffer;
17782 VkMemoryPropertyFlags reqs = 0;
Rene Lindsay135204f2016-12-22 17:11:09 -070017783 buffer.init_as_src(*m_device, 128 * 128 * 8, reqs);
Tony Barbourd6673642016-05-05 14:46:39 -060017784 VkBufferImageCopy region = {};
17785 region.bufferRowLength = 128;
17786 region.bufferImageHeight = 128;
17787 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17788 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
Mark Lobodzinski3702e932016-11-22 11:40:48 -070017789 region.imageSubresource.layerCount = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060017790 region.imageExtent.height = 4;
17791 region.imageExtent.width = 4;
17792 region.imageExtent.depth = 1;
Rene Lindsay135204f2016-12-22 17:11:09 -070017793
17794 VkImageObj image2(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017795 image2.Init(128, 128, 1, VK_FORMAT_R8G8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017796 VK_IMAGE_TILING_OPTIMAL, 0); // 16bpp
Rene Lindsay135204f2016-12-22 17:11:09 -070017797 ASSERT_TRUE(image2.initialized());
17798 vk_testing::Buffer buffer2;
17799 VkMemoryPropertyFlags reqs2 = 0;
17800 buffer2.init_as_src(*m_device, 128 * 128 * 2, reqs2);
17801 VkBufferImageCopy region2 = {};
17802 region2.bufferRowLength = 128;
17803 region2.bufferImageHeight = 128;
17804 region2.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17805 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
17806 region2.imageSubresource.layerCount = 1;
17807 region2.imageExtent.height = 4;
17808 region2.imageExtent.width = 4;
17809 region2.imageExtent.depth = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060017810 m_commandBuffer->BeginCommandBuffer();
Tony Barbourd6673642016-05-05 14:46:39 -060017811
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070017812 // Image must have offset.z of 0 and extent.depth of 1
17813 // Introduce failure by setting imageExtent.depth to 0
17814 region.imageExtent.depth = 0;
Dave Houlton59a20702017-02-02 17:26:23 -070017815 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01747);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070017816 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017817 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070017818 m_errorMonitor->VerifyFound();
17819
17820 region.imageExtent.depth = 1;
17821
17822 // Image must have offset.z of 0 and extent.depth of 1
17823 // Introduce failure by setting imageOffset.z to 4
Dave Houlton9dae7ec2017-03-01 16:23:25 -070017824 // Note: Also (unavoidably) triggers 'region exceeds image' #1228
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070017825 region.imageOffset.z = 4;
Dave Houlton59a20702017-02-02 17:26:23 -070017826 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01747);
Dave Houlton9dae7ec2017-03-01 16:23:25 -070017827 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01228);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070017828 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017829 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070017830 m_errorMonitor->VerifyFound();
17831
17832 region.imageOffset.z = 0;
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060017833 // BufferOffset must be a multiple of the calling command's VkImage parameter's texel size
17834 // Introduce failure by setting bufferOffset to 1 and 1/2 texels
Rene Lindsay135204f2016-12-22 17:11:09 -070017835 region.bufferOffset = 4;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070017836 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01263);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017837 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
17838 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060017839 m_errorMonitor->VerifyFound();
17840
17841 // BufferOffset must be a multiple of 4
17842 // Introduce failure by setting bufferOffset to a value not divisible by 4
Rene Lindsay135204f2016-12-22 17:11:09 -070017843 region2.bufferOffset = 6;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070017844 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01264);
Rene Lindsay135204f2016-12-22 17:11:09 -070017845 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer2.handle(), image2.handle(),
17846 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region2);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060017847 m_errorMonitor->VerifyFound();
17848
17849 // BufferRowLength must be 0, or greater than or equal to the width member of imageExtent
17850 region.bufferOffset = 0;
17851 region.imageExtent.height = 128;
17852 region.imageExtent.width = 128;
17853 // Introduce failure by setting bufferRowLength > 0 but less than width
17854 region.bufferRowLength = 64;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070017855 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01265);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017856 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
17857 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060017858 m_errorMonitor->VerifyFound();
17859
17860 // BufferImageHeight must be 0, or greater than or equal to the height member of imageExtent
17861 region.bufferRowLength = 128;
17862 // Introduce failure by setting bufferRowHeight > 0 but less than height
17863 region.bufferImageHeight = 64;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070017864 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01266);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017865 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
17866 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060017867 m_errorMonitor->VerifyFound();
17868
17869 region.bufferImageHeight = 128;
Tony Barbourd6673642016-05-05 14:46:39 -060017870 VkImageObj intImage1(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017871 intImage1.Init(128, 128, 1, VK_FORMAT_R8_UINT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
Rene Lindsaya35e1cb2016-12-26 10:30:05 -070017872 VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbourd6673642016-05-05 14:46:39 -060017873 VkImageObj intImage2(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017874 intImage2.Init(128, 128, 1, VK_FORMAT_R8_UINT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
Rene Lindsaya35e1cb2016-12-26 10:30:05 -070017875 VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbourd6673642016-05-05 14:46:39 -060017876 VkImageBlit blitRegion = {};
17877 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17878 blitRegion.srcSubresource.baseArrayLayer = 0;
17879 blitRegion.srcSubresource.layerCount = 1;
17880 blitRegion.srcSubresource.mipLevel = 0;
17881 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17882 blitRegion.dstSubresource.baseArrayLayer = 0;
17883 blitRegion.dstSubresource.layerCount = 1;
17884 blitRegion.dstSubresource.mipLevel = 0;
17885
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060017886 // Look for NULL-blit warning
Jeremy Hayesf8e749f2017-03-15 09:40:27 -060017887 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
17888 "vkCmdBlitImage: pRegions[0].srcOffsets specify a zero-volume area.");
17889 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
17890 "vkCmdBlitImage: pRegions[0].dstOffsets specify a zero-volume area.");
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017891 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.Layout(), intImage2.handle(),
17892 intImage2.Layout(), 1, &blitRegion, VK_FILTER_LINEAR);
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060017893 m_errorMonitor->VerifyFound();
17894
Petr Kraus4d718682017-05-18 03:38:41 +020017895 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02931);
Tony Barbourd6673642016-05-05 14:46:39 -060017896 VkImageMemoryBarrier img_barrier;
17897 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
17898 img_barrier.pNext = NULL;
17899 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
17900 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
17901 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
17902 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
17903 img_barrier.image = image.handle();
17904 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
17905 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
17906 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17907 img_barrier.subresourceRange.baseArrayLayer = 0;
17908 img_barrier.subresourceRange.baseMipLevel = 0;
Tony Barbourd6673642016-05-05 14:46:39 -060017909 img_barrier.subresourceRange.layerCount = 0;
17910 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017911 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
17912 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbourd6673642016-05-05 14:46:39 -060017913 m_errorMonitor->VerifyFound();
17914 img_barrier.subresourceRange.layerCount = 1;
17915}
17916
17917TEST_F(VkLayerTest, ImageFormatLimits) {
Tony Barbourd6673642016-05-05 14:46:39 -060017918 TEST_DESCRIPTION("Exceed the limits of image format ");
17919
Tony Barbour1fa09702017-03-16 12:09:08 -060017920 ASSERT_NO_FATAL_FAILURE(Init());
Jeremy Hayesbb63cc12017-03-20 15:33:01 -060017921
17922 VkFormat const format = VK_FORMAT_B8G8R8A8_UNORM;
17923 {
17924 VkFormatProperties properties;
17925 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), format, &properties);
17926 if (properties.linearTilingFeatures == 0) {
17927 printf(" Image format not supported; skipped.\n");
17928 return;
17929 }
17930 }
17931
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017932 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Tony Barbourd6673642016-05-05 14:46:39 -060017933 VkImageCreateInfo image_create_info = {};
17934 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17935 image_create_info.pNext = NULL;
17936 image_create_info.imageType = VK_IMAGE_TYPE_2D;
Jeremy Hayesbb63cc12017-03-20 15:33:01 -060017937 image_create_info.format = format;
Tony Barbourd6673642016-05-05 14:46:39 -060017938 image_create_info.extent.width = 32;
17939 image_create_info.extent.height = 32;
17940 image_create_info.extent.depth = 1;
17941 image_create_info.mipLevels = 1;
17942 image_create_info.arrayLayers = 1;
17943 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
17944 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
17945 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
17946 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
17947 image_create_info.flags = 0;
17948
17949 VkImage nullImg;
17950 VkImageFormatProperties imgFmtProps;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017951 vkGetPhysicalDeviceImageFormatProperties(gpu(), image_create_info.format, image_create_info.imageType, image_create_info.tiling,
17952 image_create_info.usage, image_create_info.flags, &imgFmtProps);
Rene Lindsayef5bc012017-01-06 15:38:00 -070017953 image_create_info.extent.width = imgFmtProps.maxExtent.width + 1;
Tony Barbourd6673642016-05-05 14:46:39 -060017954 // Expect INVALID_FORMAT_LIMITS_VIOLATION
17955 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
17956 m_errorMonitor->VerifyFound();
Rene Lindsayef5bc012017-01-06 15:38:00 -070017957 image_create_info.extent.width = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060017958
Tony Barbour0907e362017-03-09 15:05:30 -070017959 uint32_t maxDim =
17960 std::max(std::max(image_create_info.extent.width, image_create_info.extent.height), image_create_info.extent.depth);
17961 // If max mip levels exceeds image extents, skip the max mip levels test
17962 if ((imgFmtProps.maxMipLevels + 1) <= (floor(log2(maxDim)) + 1)) {
17963 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
17964 image_create_info.mipLevels = imgFmtProps.maxMipLevels + 1;
17965 // Expect INVALID_FORMAT_LIMITS_VIOLATION
17966 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
17967 m_errorMonitor->VerifyFound();
17968 image_create_info.mipLevels = 1;
17969 }
Tony Barbourd6673642016-05-05 14:46:39 -060017970
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017971 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060017972 image_create_info.arrayLayers = imgFmtProps.maxArrayLayers + 1;
17973 // Expect INVALID_FORMAT_LIMITS_VIOLATION
17974 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
17975 m_errorMonitor->VerifyFound();
17976 image_create_info.arrayLayers = 1;
17977
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017978 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is not supported by format");
Tony Barbourd6673642016-05-05 14:46:39 -060017979 int samples = imgFmtProps.sampleCounts >> 1;
17980 image_create_info.samples = (VkSampleCountFlagBits)samples;
17981 // Expect INVALID_FORMAT_LIMITS_VIOLATION
17982 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
17983 m_errorMonitor->VerifyFound();
17984 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
17985
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017986 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17987 "pCreateInfo->initialLayout, must be "
17988 "VK_IMAGE_LAYOUT_UNDEFINED or "
17989 "VK_IMAGE_LAYOUT_PREINITIALIZED");
Tony Barbourd6673642016-05-05 14:46:39 -060017990 image_create_info.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
17991 // Expect INVALID_LAYOUT
17992 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
17993 m_errorMonitor->VerifyFound();
17994 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
17995}
17996
Dave Houltona7df3782017-05-09 18:00:46 -060017997TEST_F(VkLayerTest, CopyImageTypeExtentMismatch) {
17998 // Image copy tests where format type and extents don't match
17999
18000 // Include maintenance1 extension if available
18001 device_extension_names.push_back(VK_KHR_MAINTENANCE1_EXTENSION_NAME);
18002 InitFramework(instance_layer_names, instance_extension_names, device_extension_names, myDbgFunc, m_errorMonitor);
18003
18004 // See if maintenance1 extension is available and enabled.
18005 uint32_t extension_count = 0;
18006 bool supports_maintenance1_extension = false;
18007 VkResult err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, nullptr);
18008 ASSERT_VK_SUCCESS(err);
18009 if (extension_count > 0) {
18010 std::vector<VkExtensionProperties> available_extensions(extension_count);
18011
18012 err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, &available_extensions[0]);
18013 ASSERT_VK_SUCCESS(err);
18014 for (const auto &extension_props : available_extensions) {
18015 if (strcmp(extension_props.extensionName, VK_KHR_MAINTENANCE1_EXTENSION_NAME) == 0) {
18016 supports_maintenance1_extension = true;
18017 }
18018 }
18019 }
18020
18021 ASSERT_NO_FATAL_FAILURE(InitState());
18022
18023 VkImageCreateInfo ci;
18024 ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
18025 ci.pNext = NULL;
18026 ci.flags = 0;
18027 ci.imageType = VK_IMAGE_TYPE_1D;
18028 ci.format = VK_FORMAT_R8G8B8A8_UNORM;
18029 ci.extent = {32, 1, 1};
18030 ci.mipLevels = 1;
18031 ci.arrayLayers = 1;
18032 ci.samples = VK_SAMPLE_COUNT_1_BIT;
18033 ci.tiling = VK_IMAGE_TILING_OPTIMAL;
18034 ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
18035 ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
18036 ci.queueFamilyIndexCount = 0;
18037 ci.pQueueFamilyIndices = NULL;
18038 ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
18039
18040 // Create 1D image
18041 VkImageObj image_1D(m_device);
18042 image_1D.init(&ci);
18043 ASSERT_TRUE(image_1D.initialized());
18044
18045 // 2D image
18046 ci.imageType = VK_IMAGE_TYPE_2D;
18047 ci.extent = {32, 32, 1};
18048 VkImageObj image_2D(m_device);
18049 image_2D.init(&ci);
18050 ASSERT_TRUE(image_2D.initialized());
18051
18052 // 3D image
18053 ci.imageType = VK_IMAGE_TYPE_3D;
18054 ci.extent = {32, 32, 8};
18055 VkImageObj image_3D(m_device);
18056 image_3D.init(&ci);
18057 ASSERT_TRUE(image_3D.initialized());
18058
18059 // 2D image array
18060 ci.imageType = VK_IMAGE_TYPE_2D;
18061 ci.extent = {32, 32, 1};
18062 ci.arrayLayers = 8;
18063 VkImageObj image_2D_array(m_device);
18064 image_2D_array.init(&ci);
18065 ASSERT_TRUE(image_2D_array.initialized());
18066
18067 m_commandBuffer->BeginCommandBuffer();
18068
18069 VkImageCopy copy_region;
18070 copy_region.extent = {32, 1, 1};
18071 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
18072 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
18073 copy_region.srcSubresource.mipLevel = 0;
18074 copy_region.dstSubresource.mipLevel = 0;
18075 copy_region.srcSubresource.baseArrayLayer = 0;
18076 copy_region.dstSubresource.baseArrayLayer = 0;
18077 copy_region.srcSubresource.layerCount = 1;
18078 copy_region.dstSubresource.layerCount = 1;
18079 copy_region.srcOffset = {0, 0, 0};
18080 copy_region.dstOffset = {0, 0, 0};
18081
18082 // Sanity check
18083 m_errorMonitor->ExpectSuccess();
18084 m_commandBuffer->CopyImage(image_1D.image(), VK_IMAGE_LAYOUT_GENERAL, image_2D.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
18085 &copy_region);
18086 m_errorMonitor->VerifyNotFound();
18087
18088 // 1D texture w/ offset.y > 0. Source = VU 01742, dest = 01744
18089 copy_region.srcOffset.y = 1;
18090 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01742);
18091 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01203); // also y-dim overrun
18092 m_commandBuffer->CopyImage(image_1D.image(), VK_IMAGE_LAYOUT_GENERAL, image_2D.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
18093 &copy_region);
18094 m_errorMonitor->VerifyFound();
18095 copy_region.srcOffset.y = 0;
18096 copy_region.dstOffset.y = 1;
18097 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01744);
18098 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01206); // also y-dim overrun
18099 m_commandBuffer->CopyImage(image_2D.image(), VK_IMAGE_LAYOUT_GENERAL, image_1D.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
18100 &copy_region);
18101 m_errorMonitor->VerifyFound();
18102 copy_region.dstOffset.y = 0;
18103
18104 // 1D texture w/ extent.height > 1. Source = VU 01742, dest = 01744
18105 copy_region.extent.height = 2;
18106 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01742);
18107 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01203); // also y-dim overrun
18108 m_commandBuffer->CopyImage(image_1D.image(), VK_IMAGE_LAYOUT_GENERAL, image_2D.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
18109 &copy_region);
18110 m_errorMonitor->VerifyFound();
18111 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01744);
18112 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01206); // also y-dim overrun
18113 m_commandBuffer->CopyImage(image_2D.image(), VK_IMAGE_LAYOUT_GENERAL, image_1D.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
18114 &copy_region);
18115 m_errorMonitor->VerifyFound();
18116 copy_region.extent.height = 1;
18117
18118 // 2D texture w/ offset.z > 0. Source = VU 01743, dest = 01745
18119 copy_region.extent = {16, 16, 1};
18120 copy_region.srcOffset.z = 4;
18121 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01743);
18122 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01204); // also z-dim overrun
18123 m_commandBuffer->CopyImage(image_2D.image(), VK_IMAGE_LAYOUT_GENERAL, image_3D.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
18124 &copy_region);
18125 m_errorMonitor->VerifyFound();
18126 copy_region.srcOffset.z = 0;
18127 copy_region.dstOffset.z = 1;
18128 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01745);
18129 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01207); // also z-dim overrun
18130 m_commandBuffer->CopyImage(image_3D.image(), VK_IMAGE_LAYOUT_GENERAL, image_2D.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
18131 &copy_region);
18132 m_errorMonitor->VerifyFound();
18133 copy_region.dstOffset.z = 0;
18134
18135 // 2D texture w/ extent.depth > 1. Source = VU 01743, dest = 01745
18136 copy_region.extent.depth = 8;
18137 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01743);
18138 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01204); // also z-dim overrun
18139 if (supports_maintenance1_extension) { // With maintenance1, will also report a depth slice mismatch
18140 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01198);
18141 }
18142 m_commandBuffer->CopyImage(image_2D.image(), VK_IMAGE_LAYOUT_GENERAL, image_3D.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
18143 &copy_region);
18144 m_errorMonitor->VerifyFound();
18145 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01745);
18146 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01207); // also z-dim overrun
18147 if (supports_maintenance1_extension) { // With maintenance1, will also report a depth slice mismatch
18148 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01198);
18149 }
18150 m_commandBuffer->CopyImage(image_3D.image(), VK_IMAGE_LAYOUT_GENERAL, image_2D.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
18151 &copy_region);
18152 m_errorMonitor->VerifyFound();
18153 copy_region.extent.depth = 1;
18154
18155 // 3D texture accessing an array layer other than 0. VU 01199
18156 copy_region.extent = {4, 4, 1};
18157 copy_region.srcSubresource.baseArrayLayer = 1;
18158 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01199);
18159 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01224); // also triggers 'too many layers'
18160 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
18161 VALIDATION_ERROR_02603); // and 'copy from layer not present'
18162 m_commandBuffer->CopyImage(image_3D.image(), VK_IMAGE_LAYOUT_GENERAL, image_2D.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
18163 &copy_region);
18164 m_errorMonitor->VerifyFound();
18165
18166 if (supports_maintenance1_extension) {
18167 // Copy from layer not present - VU02603
18168 // TODO: this VU is redundant with VU01224. Gitlab issue 812 submitted to have it removed.
18169 copy_region.srcSubresource.baseArrayLayer = 4;
18170 copy_region.srcSubresource.layerCount = 6;
18171 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02603);
18172 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01224);
18173 m_commandBuffer->CopyImage(image_2D_array.image(), VK_IMAGE_LAYOUT_GENERAL, image_3D.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
18174 &copy_region);
18175 m_errorMonitor->VerifyFound();
18176 copy_region.srcSubresource.baseArrayLayer = 0;
18177 copy_region.srcSubresource.layerCount = 1;
18178
18179 // Copy to layer not present - VU02604
18180 // TODO: this VU is redundant with VU01224. Gitlab issue 812 submitted to have it removed.
18181 copy_region.dstSubresource.baseArrayLayer = 1;
18182 copy_region.dstSubresource.layerCount = 8;
18183 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02604);
18184 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01224);
18185 m_commandBuffer->CopyImage(image_3D.image(), VK_IMAGE_LAYOUT_GENERAL, image_2D_array.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
18186 &copy_region);
18187 m_errorMonitor->VerifyFound();
18188 copy_region.dstSubresource.layerCount = 1;
18189 }
18190 m_commandBuffer->EndCommandBuffer();
18191}
18192
18193TEST_F(VkLayerTest, CopyImageCompressedBlockAlignment) {
18194 // Image copy tests on compressed images with block alignment errors
18195
18196 ASSERT_NO_FATAL_FAILURE(Init());
18197
18198 // Select a compressed format and verify support
18199 VkPhysicalDeviceFeatures device_features = {};
18200 ASSERT_NO_FATAL_FAILURE(GetPhysicalDeviceFeatures(&device_features));
18201 VkFormat compressed_format = VK_FORMAT_UNDEFINED;
18202 if (device_features.textureCompressionBC) {
18203 compressed_format = VK_FORMAT_BC3_SRGB_BLOCK;
18204 } else if (device_features.textureCompressionETC2) {
18205 compressed_format = VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK;
18206 } else if (device_features.textureCompressionASTC_LDR) {
18207 compressed_format = VK_FORMAT_ASTC_4x4_UNORM_BLOCK;
18208 }
18209
18210 VkImageCreateInfo ci;
18211 ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
18212 ci.pNext = NULL;
18213 ci.flags = 0;
18214 ci.imageType = VK_IMAGE_TYPE_2D;
18215 ci.format = compressed_format;
18216 ci.extent = {64, 64, 1};
18217 ci.mipLevels = 1;
18218 ci.arrayLayers = 1;
18219 ci.samples = VK_SAMPLE_COUNT_1_BIT;
18220 ci.tiling = VK_IMAGE_TILING_OPTIMAL;
18221 ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
18222 ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
18223 ci.queueFamilyIndexCount = 0;
18224 ci.pQueueFamilyIndices = NULL;
18225 ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
18226
18227 VkImageFormatProperties img_prop = {};
18228 if (VK_SUCCESS != vkGetPhysicalDeviceImageFormatProperties(m_device->phy().handle(), ci.format, ci.imageType, ci.tiling,
18229 ci.usage, ci.flags, &img_prop)) {
18230 printf(" No compressed formats supported - CopyImageCompressedBlockAlignment skipped.\n");
18231 return;
18232 }
18233
18234 // Create images
18235 VkImageObj image_1(m_device);
18236 image_1.init(&ci);
18237 ASSERT_TRUE(image_1.initialized());
18238
18239 ci.extent = {62, 62, 1}; // slightly smaller and not divisible by block size
18240 VkImageObj image_2(m_device);
18241 image_2.init(&ci);
18242 ASSERT_TRUE(image_2.initialized());
18243
18244 m_commandBuffer->BeginCommandBuffer();
18245
18246 VkImageCopy copy_region;
18247 copy_region.extent = {48, 48, 1};
18248 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
18249 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
18250 copy_region.srcSubresource.mipLevel = 0;
18251 copy_region.dstSubresource.mipLevel = 0;
18252 copy_region.srcSubresource.baseArrayLayer = 0;
18253 copy_region.dstSubresource.baseArrayLayer = 0;
18254 copy_region.srcSubresource.layerCount = 1;
18255 copy_region.dstSubresource.layerCount = 1;
18256 copy_region.srcOffset = {0, 0, 0};
18257 copy_region.dstOffset = {0, 0, 0};
18258
18259 // Sanity check
18260 m_errorMonitor->ExpectSuccess();
18261 m_commandBuffer->CopyImage(image_1.image(), VK_IMAGE_LAYOUT_GENERAL, image_2.image(), VK_IMAGE_LAYOUT_GENERAL, 1, &copy_region);
18262 m_errorMonitor->VerifyNotFound();
18263
18264 // Src, Dest offsets must be multiples of compressed block sizes {4, 4, 1}
18265 // Image transfer granularity gets set to compressed block size, so an ITG error is also (unavoidably) triggered.
18266 copy_region.srcOffset = {2, 4, 0}; // source width
18267 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01209);
18268 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
18269 m_commandBuffer->CopyImage(image_1.image(), VK_IMAGE_LAYOUT_GENERAL, image_2.image(), VK_IMAGE_LAYOUT_GENERAL, 1, &copy_region);
18270 m_errorMonitor->VerifyFound();
18271 copy_region.srcOffset = {12, 1, 0}; // source height
18272 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01209);
18273 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
18274 m_commandBuffer->CopyImage(image_1.image(), VK_IMAGE_LAYOUT_GENERAL, image_2.image(), VK_IMAGE_LAYOUT_GENERAL, 1, &copy_region);
18275 m_errorMonitor->VerifyFound();
18276 copy_region.srcOffset = {0, 0, 0};
18277 copy_region.dstOffset = {1, 0, 0}; // dest width
18278 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01214);
18279 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
18280 m_commandBuffer->CopyImage(image_1.image(), VK_IMAGE_LAYOUT_GENERAL, image_2.image(), VK_IMAGE_LAYOUT_GENERAL, 1, &copy_region);
18281 m_errorMonitor->VerifyFound();
18282 copy_region.dstOffset = {4, 1, 0}; // dest height
18283 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01214);
18284 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
18285 m_commandBuffer->CopyImage(image_1.image(), VK_IMAGE_LAYOUT_GENERAL, image_2.image(), VK_IMAGE_LAYOUT_GENERAL, 1, &copy_region);
18286 m_errorMonitor->VerifyFound();
18287 copy_region.dstOffset = {0, 0, 0};
18288
18289 // Copy extent must be multiples of compressed block sizes {4, 4, 1} if not full width/height
18290 copy_region.extent = {62, 60, 1}; // source width
18291 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01210);
18292 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
18293 m_commandBuffer->CopyImage(image_1.image(), VK_IMAGE_LAYOUT_GENERAL, image_2.image(), VK_IMAGE_LAYOUT_GENERAL, 1, &copy_region);
18294 m_errorMonitor->VerifyFound();
18295 copy_region.extent = {60, 62, 1}; // source height
18296 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01211);
18297 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
18298 m_commandBuffer->CopyImage(image_1.image(), VK_IMAGE_LAYOUT_GENERAL, image_2.image(), VK_IMAGE_LAYOUT_GENERAL, 1, &copy_region);
18299 m_errorMonitor->VerifyFound();
18300 copy_region.extent = {62, 60, 1}; // dest width
18301 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01215);
18302 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
18303 m_commandBuffer->CopyImage(image_2.image(), VK_IMAGE_LAYOUT_GENERAL, image_1.image(), VK_IMAGE_LAYOUT_GENERAL, 1, &copy_region);
18304 m_errorMonitor->VerifyFound();
18305 copy_region.extent = {60, 62, 1}; // dest height
18306 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01216);
18307 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
18308 m_commandBuffer->CopyImage(image_2.image(), VK_IMAGE_LAYOUT_GENERAL, image_1.image(), VK_IMAGE_LAYOUT_GENERAL, 1, &copy_region);
18309 m_errorMonitor->VerifyFound();
18310
18311 // Note: VALIDATION_ERROR_01212 and VALIDATION_ERROR_01217
18312 // VUs 01212 and 01217 should be tested here, if possible. There are currently no supported compressed formats with
18313 // a block depth other than 1, so impossible to create a 'not a multiple' condiditon for depth.
18314
18315 m_commandBuffer->EndCommandBuffer();
18316}
18317
Mark Lobodzinskicea14992016-10-14 10:59:42 -060018318TEST_F(VkLayerTest, CopyImageSrcSizeExceeded) {
Mark Lobodzinskicea14992016-10-14 10:59:42 -060018319 // Image copy with source region specified greater than src image size
Tony Barbour1fa09702017-03-16 12:09:08 -060018320 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskicea14992016-10-14 10:59:42 -060018321
Dave Houltonfc1a4052017-04-27 14:32:45 -060018322 // Create images with full mip chain
18323 VkImageCreateInfo ci;
18324 ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
18325 ci.pNext = NULL;
18326 ci.flags = 0;
18327 ci.imageType = VK_IMAGE_TYPE_3D;
18328 ci.format = VK_FORMAT_R8G8B8A8_UNORM;
18329 ci.extent = {32, 32, 8};
18330 ci.mipLevels = 6;
18331 ci.arrayLayers = 1;
18332 ci.samples = VK_SAMPLE_COUNT_1_BIT;
18333 ci.tiling = VK_IMAGE_TILING_OPTIMAL;
18334 ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
18335 ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
18336 ci.queueFamilyIndexCount = 0;
18337 ci.pQueueFamilyIndices = NULL;
18338 ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
18339
Mark Lobodzinskicea14992016-10-14 10:59:42 -060018340 VkImageObj src_image(m_device);
Dave Houltonfc1a4052017-04-27 14:32:45 -060018341 src_image.init(&ci);
18342 ASSERT_TRUE(src_image.initialized());
18343
18344 // Dest image with one more mip level
18345 ci.extent = {64, 64, 16};
18346 ci.mipLevels = 7;
18347 ci.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskicea14992016-10-14 10:59:42 -060018348 VkImageObj dst_image(m_device);
Dave Houltonfc1a4052017-04-27 14:32:45 -060018349 dst_image.init(&ci);
18350 ASSERT_TRUE(dst_image.initialized());
Mark Lobodzinskicea14992016-10-14 10:59:42 -060018351
Tony Barbour552f6c02016-12-21 14:34:07 -070018352 m_commandBuffer->BeginCommandBuffer();
Dave Houltonfc1a4052017-04-27 14:32:45 -060018353
Mark Lobodzinskicea14992016-10-14 10:59:42 -060018354 VkImageCopy copy_region;
Dave Houltonfc1a4052017-04-27 14:32:45 -060018355 copy_region.extent = {32, 32, 8};
Mark Lobodzinskicea14992016-10-14 10:59:42 -060018356 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskicea14992016-10-14 10:59:42 -060018357 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Dave Houltoncee81d02017-05-02 11:00:10 -060018358 copy_region.srcSubresource.mipLevel = 0;
18359 copy_region.dstSubresource.mipLevel = 0;
Dave Houltonfc1a4052017-04-27 14:32:45 -060018360 copy_region.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinskicea14992016-10-14 10:59:42 -060018361 copy_region.dstSubresource.baseArrayLayer = 0;
Dave Houltonfc1a4052017-04-27 14:32:45 -060018362 copy_region.srcSubresource.layerCount = 1;
18363 copy_region.dstSubresource.layerCount = 1;
18364 copy_region.srcOffset = {0, 0, 0};
18365 copy_region.dstOffset = {0, 0, 0};
18366
18367 m_errorMonitor->ExpectSuccess();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060018368 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
18369 &copy_region);
Dave Houltonfc1a4052017-04-27 14:32:45 -060018370 m_errorMonitor->VerifyNotFound();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060018371
Dave Houltonfc1a4052017-04-27 14:32:45 -060018372 // Source exceeded in x-dim, VU 01202
18373 copy_region.srcOffset.x = 4;
18374 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01175); // General "contained within" VU
18375 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01202);
18376 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
18377 &copy_region);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060018378 m_errorMonitor->VerifyFound();
Dave Houltonfc1a4052017-04-27 14:32:45 -060018379
18380 // Source exceeded in y-dim, VU 01203
18381 copy_region.srcOffset.x = 0;
18382 copy_region.extent.height = 48;
18383 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01175);
18384 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01203);
18385 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
18386 &copy_region);
18387 m_errorMonitor->VerifyFound();
18388
18389 // Source exceeded in z-dim, VU 01204
18390 copy_region.extent = {4, 4, 4};
18391 copy_region.srcSubresource.mipLevel = 2;
18392 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01175);
18393 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01204);
18394 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
18395 &copy_region);
18396 m_errorMonitor->VerifyFound();
18397
18398 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060018399}
18400
18401TEST_F(VkLayerTest, CopyImageDstSizeExceeded) {
Mark Lobodzinskicea14992016-10-14 10:59:42 -060018402 // Image copy with dest region specified greater than dest image size
Tony Barbour1fa09702017-03-16 12:09:08 -060018403 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskicea14992016-10-14 10:59:42 -060018404
Dave Houltonfc1a4052017-04-27 14:32:45 -060018405 // Create images with full mip chain
18406 VkImageCreateInfo ci;
18407 ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
18408 ci.pNext = NULL;
18409 ci.flags = 0;
18410 ci.imageType = VK_IMAGE_TYPE_3D;
18411 ci.format = VK_FORMAT_R8G8B8A8_UNORM;
18412 ci.extent = {32, 32, 8};
18413 ci.mipLevels = 6;
18414 ci.arrayLayers = 1;
18415 ci.samples = VK_SAMPLE_COUNT_1_BIT;
18416 ci.tiling = VK_IMAGE_TILING_OPTIMAL;
18417 ci.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
18418 ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
18419 ci.queueFamilyIndexCount = 0;
18420 ci.pQueueFamilyIndices = NULL;
18421 ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
18422
Mark Lobodzinskicea14992016-10-14 10:59:42 -060018423 VkImageObj dst_image(m_device);
Dave Houltonfc1a4052017-04-27 14:32:45 -060018424 dst_image.init(&ci);
18425 ASSERT_TRUE(dst_image.initialized());
18426
18427 // Src image with one more mip level
18428 ci.extent = {64, 64, 16};
18429 ci.mipLevels = 7;
18430 ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
18431 VkImageObj src_image(m_device);
18432 src_image.init(&ci);
18433 ASSERT_TRUE(src_image.initialized());
Mark Lobodzinskicea14992016-10-14 10:59:42 -060018434
Tony Barbour552f6c02016-12-21 14:34:07 -070018435 m_commandBuffer->BeginCommandBuffer();
Dave Houltonfc1a4052017-04-27 14:32:45 -060018436
Mark Lobodzinskicea14992016-10-14 10:59:42 -060018437 VkImageCopy copy_region;
Dave Houltonfc1a4052017-04-27 14:32:45 -060018438 copy_region.extent = {32, 32, 8};
Mark Lobodzinskicea14992016-10-14 10:59:42 -060018439 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskicea14992016-10-14 10:59:42 -060018440 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Dave Houltoncee81d02017-05-02 11:00:10 -060018441 copy_region.srcSubresource.mipLevel = 0;
18442 copy_region.dstSubresource.mipLevel = 0;
Dave Houltonfc1a4052017-04-27 14:32:45 -060018443 copy_region.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinskicea14992016-10-14 10:59:42 -060018444 copy_region.dstSubresource.baseArrayLayer = 0;
Dave Houltonfc1a4052017-04-27 14:32:45 -060018445 copy_region.srcSubresource.layerCount = 1;
18446 copy_region.dstSubresource.layerCount = 1;
18447 copy_region.srcOffset = {0, 0, 0};
18448 copy_region.dstOffset = {0, 0, 0};
18449
18450 m_errorMonitor->ExpectSuccess();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060018451 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
18452 &copy_region);
Dave Houltonfc1a4052017-04-27 14:32:45 -060018453 m_errorMonitor->VerifyNotFound();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060018454
Dave Houltonfc1a4052017-04-27 14:32:45 -060018455 // Dest exceeded in x-dim, VU 01205
18456 copy_region.dstOffset.x = 4;
18457 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01176); // General "contained within" VU
18458 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01205);
18459 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
18460 &copy_region);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060018461 m_errorMonitor->VerifyFound();
Dave Houltonfc1a4052017-04-27 14:32:45 -060018462
18463 // Dest exceeded in y-dim, VU 01206
18464 copy_region.dstOffset.x = 0;
18465 copy_region.extent.height = 48;
18466 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01176);
18467 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01206);
18468 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
18469 &copy_region);
18470 m_errorMonitor->VerifyFound();
18471
18472 // Dest exceeded in z-dim, VU 01207
18473 copy_region.extent = {4, 4, 4};
18474 copy_region.dstSubresource.mipLevel = 2;
18475 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01176);
18476 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01207);
18477 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
18478 &copy_region);
18479 m_errorMonitor->VerifyFound();
18480
18481 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060018482}
18483
Karl Schultz6addd812016-02-02 17:17:23 -070018484TEST_F(VkLayerTest, CopyImageFormatSizeMismatch) {
Karl Schultzbdb75952016-04-19 11:36:49 -060018485 VkResult err;
18486 bool pass;
18487
18488 // Create color images with different format sizes and try to copy between them
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070018489 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01184);
Karl Schultzbdb75952016-04-19 11:36:49 -060018490
Tony Barbour1fa09702017-03-16 12:09:08 -060018491 ASSERT_NO_FATAL_FAILURE(Init());
Karl Schultzbdb75952016-04-19 11:36:49 -060018492
18493 // Create two images of different types and try to copy between them
18494 VkImage srcImage;
18495 VkImage dstImage;
18496 VkDeviceMemory srcMem;
18497 VkDeviceMemory destMem;
18498 VkMemoryRequirements memReqs;
18499
18500 VkImageCreateInfo image_create_info = {};
18501 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
18502 image_create_info.pNext = NULL;
18503 image_create_info.imageType = VK_IMAGE_TYPE_2D;
18504 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
18505 image_create_info.extent.width = 32;
18506 image_create_info.extent.height = 32;
18507 image_create_info.extent.depth = 1;
18508 image_create_info.mipLevels = 1;
18509 image_create_info.arrayLayers = 1;
18510 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
18511 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
18512 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
18513 image_create_info.flags = 0;
18514
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018515 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060018516 ASSERT_VK_SUCCESS(err);
18517
18518 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
18519 // Introduce failure by creating second image with a different-sized format.
18520 image_create_info.format = VK_FORMAT_R5G5B5A1_UNORM_PACK16;
Tobin Ehlis6d4d1d52017-04-05 12:06:10 -060018521 VkFormatProperties properties;
18522 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), image_create_info.format, &properties);
18523 if (properties.optimalTilingFeatures == 0) {
Tobin Ehliscc980e12017-05-19 12:05:49 -060018524 vkDestroyImage(m_device->device(), srcImage, NULL);
Tobin Ehlis6d4d1d52017-04-05 12:06:10 -060018525 printf(" Image format not supported; skipped.\n");
18526 return;
18527 }
Karl Schultzbdb75952016-04-19 11:36:49 -060018528
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018529 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060018530 ASSERT_VK_SUCCESS(err);
18531
18532 // Allocate memory
18533 VkMemoryAllocateInfo memAlloc = {};
18534 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18535 memAlloc.pNext = NULL;
18536 memAlloc.allocationSize = 0;
18537 memAlloc.memoryTypeIndex = 0;
18538
18539 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
18540 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018541 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060018542 ASSERT_TRUE(pass);
18543 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
18544 ASSERT_VK_SUCCESS(err);
18545
18546 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
18547 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018548 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060018549 ASSERT_TRUE(pass);
18550 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
18551 ASSERT_VK_SUCCESS(err);
18552
18553 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
18554 ASSERT_VK_SUCCESS(err);
18555 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
18556 ASSERT_VK_SUCCESS(err);
18557
Tony Barbour552f6c02016-12-21 14:34:07 -070018558 m_commandBuffer->BeginCommandBuffer();
Karl Schultzbdb75952016-04-19 11:36:49 -060018559 VkImageCopy copyRegion;
18560 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
18561 copyRegion.srcSubresource.mipLevel = 0;
18562 copyRegion.srcSubresource.baseArrayLayer = 0;
18563 copyRegion.srcSubresource.layerCount = 0;
18564 copyRegion.srcOffset.x = 0;
18565 copyRegion.srcOffset.y = 0;
18566 copyRegion.srcOffset.z = 0;
18567 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
18568 copyRegion.dstSubresource.mipLevel = 0;
18569 copyRegion.dstSubresource.baseArrayLayer = 0;
18570 copyRegion.dstSubresource.layerCount = 0;
18571 copyRegion.dstOffset.x = 0;
18572 copyRegion.dstOffset.y = 0;
18573 copyRegion.dstOffset.z = 0;
18574 copyRegion.extent.width = 1;
18575 copyRegion.extent.height = 1;
18576 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018577 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070018578 m_commandBuffer->EndCommandBuffer();
Karl Schultzbdb75952016-04-19 11:36:49 -060018579
18580 m_errorMonitor->VerifyFound();
18581
18582 vkDestroyImage(m_device->device(), srcImage, NULL);
18583 vkDestroyImage(m_device->device(), dstImage, NULL);
18584 vkFreeMemory(m_device->device(), srcMem, NULL);
18585 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060018586}
18587
Karl Schultz6addd812016-02-02 17:17:23 -070018588TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch) {
18589 VkResult err;
18590 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060018591
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018592 // Create a depth image and a depth/stencil image and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018593 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
18594 "vkCmdCopyImage called with unmatched source and dest image depth");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060018595
Tony Barbour1fa09702017-03-16 12:09:08 -060018596 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -060018597 auto depth_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbourf887b162017-03-09 10:06:46 -070018598 if (!depth_format) {
18599 return;
18600 }
Mike Stroyana3082432015-09-25 13:39:21 -060018601
18602 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070018603 VkImage srcImage;
18604 VkImage dstImage;
18605 VkDeviceMemory srcMem;
18606 VkDeviceMemory destMem;
18607 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060018608
18609 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070018610 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
18611 image_create_info.pNext = NULL;
18612 image_create_info.imageType = VK_IMAGE_TYPE_2D;
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018613 image_create_info.format = VK_FORMAT_D32_SFLOAT;
Karl Schultz6addd812016-02-02 17:17:23 -070018614 image_create_info.extent.width = 32;
18615 image_create_info.extent.height = 32;
18616 image_create_info.extent.depth = 1;
18617 image_create_info.mipLevels = 1;
18618 image_create_info.arrayLayers = 1;
18619 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Youngad61f4b2017-04-07 08:59:56 -060018620 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Karl Schultz6addd812016-02-02 17:17:23 -070018621 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
18622 image_create_info.flags = 0;
Tobin Ehlis6d4d1d52017-04-05 12:06:10 -060018623 VkFormatProperties properties;
18624 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), image_create_info.format, &properties);
18625 if (properties.optimalTilingFeatures == 0) {
18626 printf(" Image format not supported; skipped.\n");
18627 return;
18628 }
Mike Stroyana3082432015-09-25 13:39:21 -060018629
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018630 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060018631 ASSERT_VK_SUCCESS(err);
18632
Karl Schultzbdb75952016-04-19 11:36:49 -060018633 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
18634
Mark Lobodzinskidb117632016-03-31 10:45:56 -060018635 // Introduce failure by creating second image with a depth/stencil format
Karl Schultz6addd812016-02-02 17:17:23 -070018636 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Tony Barbourf887b162017-03-09 10:06:46 -070018637 image_create_info.format = depth_format;
Mark Lobodzinski867787a2016-10-14 11:49:55 -060018638 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060018639
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018640 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060018641 ASSERT_VK_SUCCESS(err);
18642
18643 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018644 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070018645 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18646 memAlloc.pNext = NULL;
18647 memAlloc.allocationSize = 0;
18648 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018649
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060018650 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060018651 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018652 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060018653 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018654 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060018655 ASSERT_VK_SUCCESS(err);
18656
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018657 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060018658 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018659 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060018660 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018661 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060018662 ASSERT_VK_SUCCESS(err);
18663
18664 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
18665 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018666 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060018667 ASSERT_VK_SUCCESS(err);
18668
Tony Barbour552f6c02016-12-21 14:34:07 -070018669 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060018670 VkImageCopy copyRegion;
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018671 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060018672 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060018673 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018674 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018675 copyRegion.srcOffset.x = 0;
18676 copyRegion.srcOffset.y = 0;
18677 copyRegion.srcOffset.z = 0;
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018678 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018679 copyRegion.dstSubresource.mipLevel = 0;
18680 copyRegion.dstSubresource.baseArrayLayer = 0;
18681 copyRegion.dstSubresource.layerCount = 0;
18682 copyRegion.dstOffset.x = 0;
18683 copyRegion.dstOffset.y = 0;
18684 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018685 copyRegion.extent.width = 1;
18686 copyRegion.extent.height = 1;
18687 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018688 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070018689 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060018690
Chris Forbes8f36a8a2016-04-07 13:21:07 +120018691 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060018692
Chia-I Wuf7458c52015-10-26 21:10:41 +080018693 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018694 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080018695 vkFreeMemory(m_device->device(), srcMem, NULL);
18696 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060018697}
18698
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018699TEST_F(VkLayerTest, CopyImageSampleCountMismatch) {
18700 TEST_DESCRIPTION("Image copies with sample count mis-matches");
Dave Houlton33c22b72017-02-28 13:16:02 -070018701
Mark Lobodzinski77e590c2017-03-17 12:05:16 -060018702 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton33c22b72017-02-28 13:16:02 -070018703
18704 VkImageFormatProperties image_format_properties;
18705 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
18706 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT, 0,
18707 &image_format_properties);
18708
18709 if ((0 == (VK_SAMPLE_COUNT_2_BIT & image_format_properties.sampleCounts)) ||
18710 (0 == (VK_SAMPLE_COUNT_4_BIT & image_format_properties.sampleCounts))) {
18711 printf(" Image multi-sample support not found; skipped.\n");
18712 return;
18713 }
18714
18715 VkImageCreateInfo ci;
18716 ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
18717 ci.pNext = NULL;
18718 ci.flags = 0;
18719 ci.imageType = VK_IMAGE_TYPE_2D;
18720 ci.format = VK_FORMAT_R8G8B8A8_UNORM;
18721 ci.extent = {128, 128, 1};
18722 ci.mipLevels = 1;
18723 ci.arrayLayers = 1;
18724 ci.samples = VK_SAMPLE_COUNT_1_BIT;
18725 ci.tiling = VK_IMAGE_TILING_OPTIMAL;
18726 ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
18727 ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
18728 ci.queueFamilyIndexCount = 0;
18729 ci.pQueueFamilyIndices = NULL;
18730 ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
18731
18732 VkImageObj image1(m_device);
18733 image1.init(&ci);
18734 ASSERT_TRUE(image1.initialized());
18735
18736 ci.samples = VK_SAMPLE_COUNT_2_BIT;
18737 VkImageObj image2(m_device);
18738 image2.init(&ci);
18739 ASSERT_TRUE(image2.initialized());
18740
18741 ci.samples = VK_SAMPLE_COUNT_4_BIT;
18742 VkImageObj image4(m_device);
18743 image4.init(&ci);
18744 ASSERT_TRUE(image4.initialized());
18745
18746 m_commandBuffer->BeginCommandBuffer();
18747
18748 VkImageCopy copyRegion;
18749 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
18750 copyRegion.srcSubresource.mipLevel = 0;
18751 copyRegion.srcSubresource.baseArrayLayer = 0;
18752 copyRegion.srcSubresource.layerCount = 1;
18753 copyRegion.srcOffset = {0, 0, 0};
18754 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
18755 copyRegion.dstSubresource.mipLevel = 0;
18756 copyRegion.dstSubresource.baseArrayLayer = 0;
18757 copyRegion.dstSubresource.layerCount = 1;
18758 copyRegion.dstOffset = {0, 0, 0};
18759 copyRegion.extent = {128, 128, 1};
18760
18761 // Copy a single sample image to/from a multi-sample image
18762 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01185);
18763 vkCmdCopyImage(m_commandBuffer->GetBufferHandle(), image1.handle(), VK_IMAGE_LAYOUT_GENERAL, image4.handle(),
18764 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
18765 m_errorMonitor->VerifyFound();
18766
18767 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01185);
18768 vkCmdCopyImage(m_commandBuffer->GetBufferHandle(), image2.handle(), VK_IMAGE_LAYOUT_GENERAL, image1.handle(),
18769 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
18770 m_errorMonitor->VerifyFound();
18771
18772 // Copy between multi-sample images with different sample counts
18773 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01185);
18774 vkCmdCopyImage(m_commandBuffer->GetBufferHandle(), image2.handle(), VK_IMAGE_LAYOUT_GENERAL, image4.handle(),
18775 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
18776 m_errorMonitor->VerifyFound();
18777
18778 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01185);
18779 vkCmdCopyImage(m_commandBuffer->GetBufferHandle(), image4.handle(), VK_IMAGE_LAYOUT_GENERAL, image2.handle(),
18780 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
18781 m_errorMonitor->VerifyFound();
18782
18783 m_commandBuffer->EndCommandBuffer();
18784}
18785
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018786TEST_F(VkLayerTest, CopyImageAspectMismatch) {
18787 TEST_DESCRIPTION("Image copies with aspect mask errors");
Mark Lobodzinski77e590c2017-03-17 12:05:16 -060018788 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -060018789 auto ds_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbour9357d542017-03-24 15:42:21 -060018790 if (!ds_format) {
18791 return;
18792 }
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018793
Tobin Ehlis6d4d1d52017-04-05 12:06:10 -060018794 VkFormatProperties properties;
18795 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D32_SFLOAT, &properties);
18796 if (properties.optimalTilingFeatures == 0) {
18797 printf(" Image format VK_FORMAT_D32_SFLOAT not supported; skipped.\n");
18798 return;
18799 }
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018800 VkImageObj color_image(m_device), ds_image(m_device), depth_image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060018801 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 -060018802 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 -060018803 VK_IMAGE_TILING_OPTIMAL, 0);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060018804 ds_image.Init(128, 128, 1, ds_format, VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
18805 VK_IMAGE_TILING_OPTIMAL, 0);
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018806 ASSERT_TRUE(color_image.initialized());
18807 ASSERT_TRUE(depth_image.initialized());
18808 ASSERT_TRUE(ds_image.initialized());
18809
18810 VkImageCopy copyRegion;
18811 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
18812 copyRegion.srcSubresource.mipLevel = 0;
18813 copyRegion.srcSubresource.baseArrayLayer = 0;
18814 copyRegion.srcSubresource.layerCount = 1;
18815 copyRegion.srcOffset = {0, 0, 0};
18816 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
18817 copyRegion.dstSubresource.mipLevel = 0;
18818 copyRegion.dstSubresource.baseArrayLayer = 0;
18819 copyRegion.dstSubresource.layerCount = 1;
18820 copyRegion.dstOffset = {64, 0, 0};
18821 copyRegion.extent = {64, 128, 1};
18822
18823 // Submitting command before command buffer is in recording state
Dave Houlton3c9fca72017-03-27 17:25:54 -060018824 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
18825 "You must call vkBeginCommandBuffer"); // VALIDATION_ERROR_01192);
18826 vkCmdCopyImage(m_commandBuffer->GetBufferHandle(), depth_image.handle(), VK_IMAGE_LAYOUT_GENERAL, depth_image.handle(),
18827 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018828 m_errorMonitor->VerifyFound();
18829
18830 m_commandBuffer->BeginCommandBuffer();
18831
18832 // Src and dest aspect masks don't match
18833 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT;
18834 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01197);
Dave Houlton3c9fca72017-03-27 17:25:54 -060018835 vkCmdCopyImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, ds_image.handle(),
18836 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018837 m_errorMonitor->VerifyFound();
18838 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
18839
18840 // Illegal combinations of aspect bits - VU 01221
Dave Houlton3c9fca72017-03-27 17:25:54 -060018841 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT; // color must be alone
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018842 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT;
18843 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01221);
18844 // These aspect/format mismatches are redundant but unavoidable here
18845 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01200);
18846 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01201);
Dave Houlton3c9fca72017-03-27 17:25:54 -060018847 vkCmdCopyImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_GENERAL, color_image.handle(),
18848 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018849 m_errorMonitor->VerifyFound();
18850 // Metadata aspect is illegal - VU 01222
18851 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
18852 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
18853 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01222);
18854 // These aspect/format mismatches are redundant but unavoidable here
Dave Houlton3c9fca72017-03-27 17:25:54 -060018855 vkCmdCopyImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_GENERAL, color_image.handle(),
18856 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018857 m_errorMonitor->VerifyFound();
18858
18859 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
18860 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
18861
18862 // Aspect mask doesn't match source image format - VU 01200
18863 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01200);
18864 // Again redundant but unavoidable when provoking vu01200 w/o vu01201
18865 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "unmatched source and dest image depth/stencil formats");
18866 vkCmdCopyImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_GENERAL, depth_image.handle(),
18867 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
18868 m_errorMonitor->VerifyFound();
18869
18870 // Aspect mask doesn't match dest image format - VU 01201
18871 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
18872 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
18873 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01201);
18874 // Again redundant but unavoidable when provoking vu01201 w/o vu01200
18875 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "unmatched source and dest image depth/stencil formats");
18876 vkCmdCopyImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_GENERAL, depth_image.handle(),
18877 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
18878 m_errorMonitor->VerifyFound();
18879
18880 m_commandBuffer->EndCommandBuffer();
18881}
18882
Karl Schultz6addd812016-02-02 17:17:23 -070018883TEST_F(VkLayerTest, ResolveImageLowSampleCount) {
18884 VkResult err;
18885 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060018886
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018887 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
18888 "vkCmdResolveImage called with source sample count less than 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060018889
Tony Barbour1fa09702017-03-16 12:09:08 -060018890 ASSERT_NO_FATAL_FAILURE(Init());
Mike Stroyana3082432015-09-25 13:39:21 -060018891
18892 // Create two images of sample count 1 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070018893 VkImage srcImage;
18894 VkImage dstImage;
18895 VkDeviceMemory srcMem;
18896 VkDeviceMemory destMem;
18897 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060018898
18899 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070018900 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
18901 image_create_info.pNext = NULL;
18902 image_create_info.imageType = VK_IMAGE_TYPE_2D;
18903 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
18904 image_create_info.extent.width = 32;
18905 image_create_info.extent.height = 1;
18906 image_create_info.extent.depth = 1;
18907 image_create_info.mipLevels = 1;
18908 image_create_info.arrayLayers = 1;
18909 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
18910 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
18911 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
18912 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018913
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018914 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060018915 ASSERT_VK_SUCCESS(err);
18916
Karl Schultz6addd812016-02-02 17:17:23 -070018917 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060018918
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018919 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060018920 ASSERT_VK_SUCCESS(err);
18921
18922 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018923 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070018924 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18925 memAlloc.pNext = NULL;
18926 memAlloc.allocationSize = 0;
18927 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018928
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060018929 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060018930 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018931 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060018932 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018933 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060018934 ASSERT_VK_SUCCESS(err);
18935
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018936 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060018937 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018938 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060018939 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018940 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060018941 ASSERT_VK_SUCCESS(err);
18942
18943 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
18944 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018945 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060018946 ASSERT_VK_SUCCESS(err);
18947
Tony Barbour552f6c02016-12-21 14:34:07 -070018948 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060018949 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070018950 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
18951 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060018952 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080018953 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060018954 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060018955 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130018956 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060018957 resolveRegion.srcOffset.x = 0;
18958 resolveRegion.srcOffset.y = 0;
18959 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080018960 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018961 resolveRegion.dstSubresource.mipLevel = 0;
18962 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130018963 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018964 resolveRegion.dstOffset.x = 0;
18965 resolveRegion.dstOffset.y = 0;
18966 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018967 resolveRegion.extent.width = 1;
18968 resolveRegion.extent.height = 1;
18969 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018970 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070018971 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060018972
Chris Forbes8f36a8a2016-04-07 13:21:07 +120018973 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060018974
Chia-I Wuf7458c52015-10-26 21:10:41 +080018975 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018976 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080018977 vkFreeMemory(m_device->device(), srcMem, NULL);
18978 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060018979}
18980
Karl Schultz6addd812016-02-02 17:17:23 -070018981TEST_F(VkLayerTest, ResolveImageHighSampleCount) {
18982 VkResult err;
18983 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060018984
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018985 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
18986 "vkCmdResolveImage called with dest sample count greater than 1.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060018987
Tony Barbour1fa09702017-03-16 12:09:08 -060018988 ASSERT_NO_FATAL_FAILURE(Init());
Mike Stroyana3082432015-09-25 13:39:21 -060018989
Chris Forbesa7530692016-05-08 12:35:39 +120018990 // Create two images of sample count 4 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070018991 VkImage srcImage;
18992 VkImage dstImage;
18993 VkDeviceMemory srcMem;
18994 VkDeviceMemory destMem;
18995 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060018996
18997 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070018998 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
18999 image_create_info.pNext = NULL;
19000 image_create_info.imageType = VK_IMAGE_TYPE_2D;
19001 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
19002 image_create_info.extent.width = 32;
19003 image_create_info.extent.height = 1;
19004 image_create_info.extent.depth = 1;
19005 image_create_info.mipLevels = 1;
19006 image_create_info.arrayLayers = 1;
Chris Forbesa7530692016-05-08 12:35:39 +120019007 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070019008 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
19009 // Note: Some implementations expect color attachment usage for any
19010 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019011 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070019012 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060019013
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019014 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060019015 ASSERT_VK_SUCCESS(err);
19016
Karl Schultz6addd812016-02-02 17:17:23 -070019017 // Note: Some implementations expect color attachment usage for any
19018 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019019 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060019020
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019021 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060019022 ASSERT_VK_SUCCESS(err);
19023
19024 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080019025 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070019026 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
19027 memAlloc.pNext = NULL;
19028 memAlloc.allocationSize = 0;
19029 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060019030
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060019031 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060019032 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019033 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060019034 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080019035 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060019036 ASSERT_VK_SUCCESS(err);
19037
Chia-I Wu3432a0c2015-10-27 18:04:07 +080019038 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060019039 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019040 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060019041 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080019042 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060019043 ASSERT_VK_SUCCESS(err);
19044
19045 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
19046 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080019047 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060019048 ASSERT_VK_SUCCESS(err);
19049
Tony Barbour552f6c02016-12-21 14:34:07 -070019050 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060019051 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070019052 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
19053 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060019054 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080019055 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060019056 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060019057 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130019058 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060019059 resolveRegion.srcOffset.x = 0;
19060 resolveRegion.srcOffset.y = 0;
19061 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080019062 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080019063 resolveRegion.dstSubresource.mipLevel = 0;
19064 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130019065 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080019066 resolveRegion.dstOffset.x = 0;
19067 resolveRegion.dstOffset.y = 0;
19068 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060019069 resolveRegion.extent.width = 1;
19070 resolveRegion.extent.height = 1;
19071 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019072 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070019073 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060019074
Chris Forbes8f36a8a2016-04-07 13:21:07 +120019075 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060019076
Chia-I Wuf7458c52015-10-26 21:10:41 +080019077 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080019078 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080019079 vkFreeMemory(m_device->device(), srcMem, NULL);
19080 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060019081}
19082
Karl Schultz6addd812016-02-02 17:17:23 -070019083TEST_F(VkLayerTest, ResolveImageFormatMismatch) {
19084 VkResult err;
19085 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060019086
Mark Lobodzinski50fbef12017-02-06 15:31:33 -070019087 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019088 "vkCmdResolveImage called with unmatched source and dest formats.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060019089
Tony Barbour1fa09702017-03-16 12:09:08 -060019090 ASSERT_NO_FATAL_FAILURE(Init());
Mike Stroyana3082432015-09-25 13:39:21 -060019091
19092 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070019093 VkImage srcImage;
19094 VkImage dstImage;
19095 VkDeviceMemory srcMem;
19096 VkDeviceMemory destMem;
19097 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060019098
19099 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070019100 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
19101 image_create_info.pNext = NULL;
19102 image_create_info.imageType = VK_IMAGE_TYPE_2D;
19103 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
19104 image_create_info.extent.width = 32;
19105 image_create_info.extent.height = 1;
19106 image_create_info.extent.depth = 1;
19107 image_create_info.mipLevels = 1;
19108 image_create_info.arrayLayers = 1;
19109 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
19110 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
19111 // Note: Some implementations expect color attachment usage for any
19112 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019113 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070019114 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060019115
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019116 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060019117 ASSERT_VK_SUCCESS(err);
19118
Karl Schultz6addd812016-02-02 17:17:23 -070019119 // Set format to something other than source image
19120 image_create_info.format = VK_FORMAT_R32_SFLOAT;
19121 // Note: Some implementations expect color attachment usage for any
19122 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019123 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070019124 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060019125
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019126 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060019127 ASSERT_VK_SUCCESS(err);
19128
19129 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080019130 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070019131 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
19132 memAlloc.pNext = NULL;
19133 memAlloc.allocationSize = 0;
19134 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060019135
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060019136 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060019137 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019138 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060019139 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080019140 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060019141 ASSERT_VK_SUCCESS(err);
19142
Chia-I Wu3432a0c2015-10-27 18:04:07 +080019143 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060019144 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019145 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060019146 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080019147 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060019148 ASSERT_VK_SUCCESS(err);
19149
19150 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
19151 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080019152 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060019153 ASSERT_VK_SUCCESS(err);
19154
Tony Barbour552f6c02016-12-21 14:34:07 -070019155 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060019156 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070019157 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
19158 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060019159 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080019160 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060019161 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060019162 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130019163 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060019164 resolveRegion.srcOffset.x = 0;
19165 resolveRegion.srcOffset.y = 0;
19166 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080019167 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080019168 resolveRegion.dstSubresource.mipLevel = 0;
19169 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130019170 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080019171 resolveRegion.dstOffset.x = 0;
19172 resolveRegion.dstOffset.y = 0;
19173 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060019174 resolveRegion.extent.width = 1;
19175 resolveRegion.extent.height = 1;
19176 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019177 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070019178 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060019179
Chris Forbes8f36a8a2016-04-07 13:21:07 +120019180 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060019181
Chia-I Wuf7458c52015-10-26 21:10:41 +080019182 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080019183 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080019184 vkFreeMemory(m_device->device(), srcMem, NULL);
19185 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060019186}
19187
Karl Schultz6addd812016-02-02 17:17:23 -070019188TEST_F(VkLayerTest, ResolveImageTypeMismatch) {
19189 VkResult err;
19190 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060019191
Mark Lobodzinski50fbef12017-02-06 15:31:33 -070019192 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019193 "vkCmdResolveImage called with unmatched source and dest image types.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060019194
Tony Barbour1fa09702017-03-16 12:09:08 -060019195 ASSERT_NO_FATAL_FAILURE(Init());
Mike Stroyana3082432015-09-25 13:39:21 -060019196
19197 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070019198 VkImage srcImage;
19199 VkImage dstImage;
19200 VkDeviceMemory srcMem;
19201 VkDeviceMemory destMem;
19202 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060019203
19204 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070019205 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
19206 image_create_info.pNext = NULL;
19207 image_create_info.imageType = VK_IMAGE_TYPE_2D;
19208 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
19209 image_create_info.extent.width = 32;
19210 image_create_info.extent.height = 1;
19211 image_create_info.extent.depth = 1;
19212 image_create_info.mipLevels = 1;
19213 image_create_info.arrayLayers = 1;
19214 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
19215 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
19216 // Note: Some implementations expect color attachment usage for any
19217 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019218 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070019219 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060019220
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019221 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060019222 ASSERT_VK_SUCCESS(err);
19223
Karl Schultz6addd812016-02-02 17:17:23 -070019224 image_create_info.imageType = VK_IMAGE_TYPE_1D;
19225 // Note: Some implementations expect color attachment usage for any
19226 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019227 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070019228 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060019229
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019230 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060019231 ASSERT_VK_SUCCESS(err);
19232
19233 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080019234 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070019235 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
19236 memAlloc.pNext = NULL;
19237 memAlloc.allocationSize = 0;
19238 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060019239
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060019240 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060019241 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019242 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060019243 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080019244 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060019245 ASSERT_VK_SUCCESS(err);
19246
Chia-I Wu3432a0c2015-10-27 18:04:07 +080019247 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060019248 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019249 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060019250 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080019251 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060019252 ASSERT_VK_SUCCESS(err);
19253
19254 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
19255 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080019256 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060019257 ASSERT_VK_SUCCESS(err);
19258
Tony Barbour552f6c02016-12-21 14:34:07 -070019259 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060019260 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070019261 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
19262 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060019263 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080019264 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060019265 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060019266 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130019267 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060019268 resolveRegion.srcOffset.x = 0;
19269 resolveRegion.srcOffset.y = 0;
19270 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080019271 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080019272 resolveRegion.dstSubresource.mipLevel = 0;
19273 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130019274 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080019275 resolveRegion.dstOffset.x = 0;
19276 resolveRegion.dstOffset.y = 0;
19277 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060019278 resolveRegion.extent.width = 1;
19279 resolveRegion.extent.height = 1;
19280 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019281 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070019282 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060019283
Chris Forbes8f36a8a2016-04-07 13:21:07 +120019284 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060019285
Chia-I Wuf7458c52015-10-26 21:10:41 +080019286 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080019287 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080019288 vkFreeMemory(m_device->device(), srcMem, NULL);
19289 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060019290}
Tobin Ehlisa1c28562015-10-23 16:00:08 -060019291
Karl Schultz6addd812016-02-02 17:17:23 -070019292TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060019293 // Create a single Image descriptor and cause it to first hit an error due
Karl Schultz6addd812016-02-02 17:17:23 -070019294 // to using a DS format, then cause it to hit error due to COLOR_BIT not
19295 // set in aspect
Tobin Ehlisa1c28562015-10-23 16:00:08 -060019296 // The image format check comes 2nd in validation so we trigger it first,
19297 // then when we cause aspect fail next, bad format check will be preempted
Karl Schultz6addd812016-02-02 17:17:23 -070019298 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060019299
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019300 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
19301 "Combination depth/stencil image formats can have only the ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060019302
Tony Barbour1fa09702017-03-16 12:09:08 -060019303 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -060019304 auto depth_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbourf887b162017-03-09 10:06:46 -070019305 if (!depth_format) {
19306 return;
19307 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060019308
Chia-I Wu1b99bb22015-10-27 19:25:11 +080019309 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070019310 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
19311 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060019312
19313 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070019314 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
19315 ds_pool_ci.pNext = NULL;
19316 ds_pool_ci.maxSets = 1;
19317 ds_pool_ci.poolSizeCount = 1;
19318 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060019319
19320 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019321 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060019322 ASSERT_VK_SUCCESS(err);
19323
19324 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070019325 dsl_binding.binding = 0;
19326 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
19327 dsl_binding.descriptorCount = 1;
19328 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
19329 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060019330
19331 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070019332 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
19333 ds_layout_ci.pNext = NULL;
19334 ds_layout_ci.bindingCount = 1;
19335 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060019336 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019337 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060019338 ASSERT_VK_SUCCESS(err);
19339
19340 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080019341 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080019342 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070019343 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060019344 alloc_info.descriptorPool = ds_pool;
19345 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019346 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060019347 ASSERT_VK_SUCCESS(err);
19348
Karl Schultz6addd812016-02-02 17:17:23 -070019349 VkImage image_bad;
19350 VkImage image_good;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060019351 // One bad format and one good format for Color attachment
Tony Barbourf887b162017-03-09 10:06:46 -070019352 const VkFormat tex_format_bad = depth_format;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060019353 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
Karl Schultz6addd812016-02-02 17:17:23 -070019354 const int32_t tex_width = 32;
19355 const int32_t tex_height = 32;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060019356
19357 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070019358 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
19359 image_create_info.pNext = NULL;
19360 image_create_info.imageType = VK_IMAGE_TYPE_2D;
19361 image_create_info.format = tex_format_bad;
19362 image_create_info.extent.width = tex_width;
19363 image_create_info.extent.height = tex_height;
19364 image_create_info.extent.depth = 1;
19365 image_create_info.mipLevels = 1;
19366 image_create_info.arrayLayers = 1;
19367 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
19368 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019369 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070019370 image_create_info.flags = 0;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060019371
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019372 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060019373 ASSERT_VK_SUCCESS(err);
19374 image_create_info.format = tex_format_good;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019375 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
19376 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_good);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060019377 ASSERT_VK_SUCCESS(err);
19378
Rene Lindsayf1e89c82016-12-28 13:18:31 -070019379 // ---Bind image memory---
19380 VkMemoryRequirements img_mem_reqs;
19381 vkGetImageMemoryRequirements(m_device->device(), image_bad, &img_mem_reqs);
19382 VkMemoryAllocateInfo image_alloc_info = {};
19383 image_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
19384 image_alloc_info.pNext = NULL;
19385 image_alloc_info.memoryTypeIndex = 0;
19386 image_alloc_info.allocationSize = img_mem_reqs.size;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019387 bool pass =
19388 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 -070019389 ASSERT_TRUE(pass);
19390 VkDeviceMemory mem;
19391 err = vkAllocateMemory(m_device->device(), &image_alloc_info, NULL, &mem);
19392 ASSERT_VK_SUCCESS(err);
19393 err = vkBindImageMemory(m_device->device(), image_bad, mem, 0);
19394 ASSERT_VK_SUCCESS(err);
19395 // -----------------------
19396
Tobin Ehlisa1c28562015-10-23 16:00:08 -060019397 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130019398 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070019399 image_view_create_info.image = image_bad;
19400 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
19401 image_view_create_info.format = tex_format_bad;
19402 image_view_create_info.subresourceRange.baseArrayLayer = 0;
19403 image_view_create_info.subresourceRange.baseMipLevel = 0;
19404 image_view_create_info.subresourceRange.layerCount = 1;
19405 image_view_create_info.subresourceRange.levelCount = 1;
Rene Lindsayf1e89c82016-12-28 13:18:31 -070019406 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060019407
19408 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019409 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060019410
Chris Forbes8f36a8a2016-04-07 13:21:07 +120019411 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060019412
Chia-I Wuf7458c52015-10-26 21:10:41 +080019413 vkDestroyImage(m_device->device(), image_bad, NULL);
19414 vkDestroyImage(m_device->device(), image_good, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080019415 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
19416 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Rene Lindsayf1e89c82016-12-28 13:18:31 -070019417
19418 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060019419}
Tobin Ehlis6e23d772016-05-19 11:08:34 -060019420
19421TEST_F(VkLayerTest, ClearImageErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019422 TEST_DESCRIPTION(
19423 "Call ClearColorImage w/ a depth|stencil image and "
19424 "ClearDepthStencilImage with a color image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060019425
Tony Barbour1fa09702017-03-16 12:09:08 -060019426 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -060019427 auto depth_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbourf887b162017-03-09 10:06:46 -070019428 if (!depth_format) {
19429 return;
19430 }
Tobin Ehlis6e23d772016-05-19 11:08:34 -060019431 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19432
Tony Barbour552f6c02016-12-21 14:34:07 -070019433 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis6e23d772016-05-19 11:08:34 -060019434
19435 // Color image
19436 VkClearColorValue clear_color;
19437 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
19438 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
19439 const VkFormat color_format = VK_FORMAT_B8G8R8A8_UNORM;
19440 const int32_t img_width = 32;
19441 const int32_t img_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 = color_format;
19447 image_create_info.extent.width = img_width;
19448 image_create_info.extent.height = img_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_LINEAR;
19454 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
19455
19456 vk_testing::Image color_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019457 color_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060019458
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019459 const VkImageSubresourceRange color_range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060019460
19461 // Depth/Stencil image
19462 VkClearDepthStencilValue clear_value = {0};
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019463 reqs = 0; // don't need HOST_VISIBLE DS image
Tobin Ehlis6e23d772016-05-19 11:08:34 -060019464 VkImageCreateInfo ds_image_create_info = vk_testing::Image::create_info();
19465 ds_image_create_info.imageType = VK_IMAGE_TYPE_2D;
Tony Barbourf887b162017-03-09 10:06:46 -070019466 ds_image_create_info.format = depth_format;
Tobin Ehlis6e23d772016-05-19 11:08:34 -060019467 ds_image_create_info.extent.width = 64;
19468 ds_image_create_info.extent.height = 64;
19469 ds_image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Rene Lindsaya1fc64a2016-12-27 15:18:54 -070019470 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 -060019471
19472 vk_testing::Image ds_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019473 ds_image.init(*m_device, (const VkImageCreateInfo &)ds_image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060019474
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019475 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 -060019476
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019477 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060019478
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019479 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tobin Ehlis6e23d772016-05-19 11:08:34 -060019480 &color_range);
19481
19482 m_errorMonitor->VerifyFound();
19483
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019484 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
19485 "vkCmdClearColorImage called with "
19486 "image created without "
19487 "VK_IMAGE_USAGE_TRANSFER_DST_BIT");
Tony Barbour26434b92016-06-02 09:43:50 -060019488
Rene Lindsaya1fc64a2016-12-27 15:18:54 -070019489 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tony Barbour26434b92016-06-02 09:43:50 -060019490 &color_range);
19491
19492 m_errorMonitor->VerifyFound();
19493
Tobin Ehlis6e23d772016-05-19 11:08:34 -060019494 // Call CmdClearDepthStencilImage with color image
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019495 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
19496 "vkCmdClearDepthStencilImage called without a depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060019497
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019498 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
19499 &clear_value, 1, &ds_range);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060019500
19501 m_errorMonitor->VerifyFound();
19502}
Tobin Ehliscde08892015-09-22 10:11:37 -060019503
Mike Schuchardt35fece12017-03-07 14:40:28 -070019504TEST_F(VkLayerTest, CommandQueueFlags) {
19505 TEST_DESCRIPTION(
19506 "Allocate a command buffer on a queue that does not support graphics and try to issue a "
19507 "graphics-only command");
19508
19509 ASSERT_NO_FATAL_FAILURE(Init());
19510
19511 uint32_t queueFamilyIndex = m_device->QueueFamilyWithoutCapabilities(VK_QUEUE_GRAPHICS_BIT);
Dave Houlton3c9fca72017-03-27 17:25:54 -060019512 if (queueFamilyIndex == UINT32_MAX) {
Mike Schuchardt35fece12017-03-07 14:40:28 -070019513 printf(" Non-graphics queue family not found; skipped.\n");
19514 return;
19515 } else {
19516 // Create command pool on a non-graphics queue
19517 VkCommandPoolObj command_pool(m_device, queueFamilyIndex);
19518
19519 // Setup command buffer on pool
19520 VkCommandBufferObj command_buffer(m_device, &command_pool);
19521 command_buffer.BeginCommandBuffer();
19522
19523 // Issue a graphics only command
19524 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01446);
19525 VkViewport viewport = {0, 0, 16, 16, 0, 1};
19526 command_buffer.SetViewport(0, 1, &viewport);
19527 m_errorMonitor->VerifyFound();
19528 }
19529}
19530
Mark Lobodzinskib8359282017-05-16 09:17:51 -060019531TEST_F(VkLayerTest, ExecuteUnrecordedCBs) {
19532 TEST_DESCRIPTION(
19533 "Attempt vkCmdExecuteCommands and then QueueSubmit with an unrecorded secondary and primary command buffer, respectively");
19534
19535 ASSERT_NO_FATAL_FAILURE(Init());
19536 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19537 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00155);
19538 // Allocate a secondary command buffer
19539 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
19540 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19541 command_buffer_allocate_info.commandPool = m_commandPool->handle();
19542 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
19543 command_buffer_allocate_info.commandBufferCount = 1;
19544 VkCommandBuffer secondary_command_buffer;
19545 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
19546 VkCommandBufferBeginInfo command_buffer_begin_info = {};
19547 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19548 command_buffer_begin_info.flags =
19549 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
19550 command_buffer_begin_info.pInheritanceInfo = nullptr;
19551
19552 // Now update primary cmd buffer to execute unrecorded secondary
19553 VkResult err = vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
19554 ASSERT_VK_SUCCESS(err);
19555 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
19556 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
19557 vkCmdEndRenderPass(m_commandBuffer->handle());
19558 err = vkEndCommandBuffer(m_commandBuffer->handle());
19559 ASSERT_VK_SUCCESS(err);
19560 m_errorMonitor->VerifyFound();
19561
19562 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00134);
19563 // Allocate a primary command buffer
19564 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19565 command_buffer_allocate_info.commandBufferCount = 1;
19566 VkCommandBuffer primary_command_buffer;
19567 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &primary_command_buffer));
19568
19569 // And submit the unrecorded command buffer
19570 VkSubmitInfo submit_info = {};
19571 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19572 submit_info.commandBufferCount = 1;
19573 submit_info.pCommandBuffers = &primary_command_buffer;
19574 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
19575 m_errorMonitor->VerifyFound();
19576}
19577
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019578// WSI Enabled Tests
19579//
Chris Forbes09368e42016-10-13 11:59:22 +130019580#if 0
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019581TEST_F(VkWsiEnabledLayerTest, TestEnabledWsi) {
19582
19583#if defined(VK_USE_PLATFORM_XCB_KHR)
19584 VkSurfaceKHR surface = VK_NULL_HANDLE;
19585
19586 VkResult err;
19587 bool pass;
19588 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
19589 VkSwapchainCreateInfoKHR swapchain_create_info = {};
19590 // uint32_t swapchain_image_count = 0;
19591 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
19592 // uint32_t image_index = 0;
19593 // VkPresentInfoKHR present_info = {};
19594
Tony Barbour1fa09702017-03-16 12:09:08 -060019595 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019596
19597 // Use the create function from one of the VK_KHR_*_surface extension in
19598 // order to create a surface, testing all known errors in the process,
19599 // before successfully creating a surface:
19600 // First, try to create a surface without a VkXcbSurfaceCreateInfoKHR:
19601 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo specified as NULL");
19602 err = vkCreateXcbSurfaceKHR(instance(), NULL, NULL, &surface);
19603 pass = (err != VK_SUCCESS);
19604 ASSERT_TRUE(pass);
19605 m_errorMonitor->VerifyFound();
19606
19607 // Next, try to create a surface with the wrong
19608 // VkXcbSurfaceCreateInfoKHR::sType:
19609 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
19610 xcb_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
19611 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
19612 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
19613 pass = (err != VK_SUCCESS);
19614 ASSERT_TRUE(pass);
19615 m_errorMonitor->VerifyFound();
19616
19617 // Create a native window, and then correctly create a surface:
19618 xcb_connection_t *connection;
19619 xcb_screen_t *screen;
19620 xcb_window_t xcb_window;
19621 xcb_intern_atom_reply_t *atom_wm_delete_window;
19622
19623 const xcb_setup_t *setup;
19624 xcb_screen_iterator_t iter;
19625 int scr;
19626 uint32_t value_mask, value_list[32];
19627 int width = 1;
19628 int height = 1;
19629
19630 connection = xcb_connect(NULL, &scr);
19631 ASSERT_TRUE(connection != NULL);
19632 setup = xcb_get_setup(connection);
19633 iter = xcb_setup_roots_iterator(setup);
19634 while (scr-- > 0)
19635 xcb_screen_next(&iter);
19636 screen = iter.data;
19637
19638 xcb_window = xcb_generate_id(connection);
19639
19640 value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
19641 value_list[0] = screen->black_pixel;
19642 value_list[1] = XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_STRUCTURE_NOTIFY;
19643
19644 xcb_create_window(connection, XCB_COPY_FROM_PARENT, xcb_window, screen->root, 0, 0, width, height, 0,
19645 XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual, value_mask, value_list);
19646
19647 /* Magic code that will send notification when window is destroyed */
19648 xcb_intern_atom_cookie_t cookie = xcb_intern_atom(connection, 1, 12, "WM_PROTOCOLS");
19649 xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply(connection, cookie, 0);
19650
19651 xcb_intern_atom_cookie_t cookie2 = xcb_intern_atom(connection, 0, 16, "WM_DELETE_WINDOW");
19652 atom_wm_delete_window = xcb_intern_atom_reply(connection, cookie2, 0);
19653 xcb_change_property(connection, XCB_PROP_MODE_REPLACE, xcb_window, (*reply).atom, 4, 32, 1, &(*atom_wm_delete_window).atom);
19654 free(reply);
19655
19656 xcb_map_window(connection, xcb_window);
19657
19658 // Force the x/y coordinates to 100,100 results are identical in consecutive
19659 // runs
19660 const uint32_t coords[] = { 100, 100 };
19661 xcb_configure_window(connection, xcb_window, XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, coords);
19662
19663 // Finally, try to correctly create a surface:
19664 xcb_create_info.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
19665 xcb_create_info.pNext = NULL;
19666 xcb_create_info.flags = 0;
19667 xcb_create_info.connection = connection;
19668 xcb_create_info.window = xcb_window;
19669 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
19670 pass = (err == VK_SUCCESS);
19671 ASSERT_TRUE(pass);
19672
19673 // Check if surface supports presentation:
19674
19675 // 1st, do so without having queried the queue families:
19676 VkBool32 supported = false;
19677 // TODO: Get the following error to come out:
19678 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
19679 "called before calling the vkGetPhysicalDeviceQueueFamilyProperties "
19680 "function");
19681 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
19682 pass = (err != VK_SUCCESS);
19683 // ASSERT_TRUE(pass);
19684 // m_errorMonitor->VerifyFound();
19685
19686 // Next, query a queue family index that's too large:
19687 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
19688 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 100000, surface, &supported);
19689 pass = (err != VK_SUCCESS);
19690 ASSERT_TRUE(pass);
19691 m_errorMonitor->VerifyFound();
19692
19693 // Finally, do so correctly:
19694 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
19695 // SUPPORTED
19696 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
19697 pass = (err == VK_SUCCESS);
19698 ASSERT_TRUE(pass);
19699
19700 // Before proceeding, try to create a swapchain without having called
19701 // vkGetPhysicalDeviceSurfaceCapabilitiesKHR():
19702 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
19703 swapchain_create_info.pNext = NULL;
19704 swapchain_create_info.flags = 0;
19705 swapchain_create_info.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
19706 swapchain_create_info.surface = surface;
19707 swapchain_create_info.imageArrayLayers = 1;
19708 swapchain_create_info.preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
19709 swapchain_create_info.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
19710 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
19711 "called before calling vkGetPhysicalDeviceSurfaceCapabilitiesKHR().");
19712 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
19713 pass = (err != VK_SUCCESS);
19714 ASSERT_TRUE(pass);
19715 m_errorMonitor->VerifyFound();
19716
19717 // Get the surface capabilities:
19718 VkSurfaceCapabilitiesKHR surface_capabilities;
19719
19720 // Do so correctly (only error logged by this entrypoint is if the
19721 // extension isn't enabled):
19722 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &surface_capabilities);
19723 pass = (err == VK_SUCCESS);
19724 ASSERT_TRUE(pass);
19725
19726 // Get the surface formats:
19727 uint32_t surface_format_count;
19728
19729 // First, try without a pointer to surface_format_count:
19730 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSurfaceFormatCount "
19731 "specified as NULL");
19732 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, NULL, NULL);
19733 pass = (err == VK_SUCCESS);
19734 ASSERT_TRUE(pass);
19735 m_errorMonitor->VerifyFound();
19736
19737 // Next, call with a non-NULL pSurfaceFormats, even though we haven't
19738 // correctly done a 1st try (to get the count):
19739 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
19740 surface_format_count = 0;
19741 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, (VkSurfaceFormatKHR *)&surface_format_count);
19742 pass = (err == VK_SUCCESS);
19743 ASSERT_TRUE(pass);
19744 m_errorMonitor->VerifyFound();
19745
19746 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
19747 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
19748 pass = (err == VK_SUCCESS);
19749 ASSERT_TRUE(pass);
19750
19751 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
19752 VkSurfaceFormatKHR *surface_formats = (VkSurfaceFormatKHR *)malloc(surface_format_count * sizeof(VkSurfaceFormatKHR));
19753
19754 // Next, do a 2nd try with surface_format_count being set too high:
19755 surface_format_count += 5;
19756 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
19757 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
19758 pass = (err == VK_SUCCESS);
19759 ASSERT_TRUE(pass);
19760 m_errorMonitor->VerifyFound();
19761
19762 // Finally, do a correct 1st and 2nd try:
19763 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
19764 pass = (err == VK_SUCCESS);
19765 ASSERT_TRUE(pass);
19766 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
19767 pass = (err == VK_SUCCESS);
19768 ASSERT_TRUE(pass);
19769
19770 // Get the surface present modes:
19771 uint32_t surface_present_mode_count;
19772
19773 // First, try without a pointer to surface_format_count:
19774 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pPresentModeCount "
19775 "specified as NULL");
19776
19777 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, NULL, NULL);
19778 pass = (err == VK_SUCCESS);
19779 ASSERT_TRUE(pass);
19780 m_errorMonitor->VerifyFound();
19781
19782 // Next, call with a non-NULL VkPresentModeKHR, even though we haven't
19783 // correctly done a 1st try (to get the count):
19784 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
19785 surface_present_mode_count = 0;
19786 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count,
19787 (VkPresentModeKHR *)&surface_present_mode_count);
19788 pass = (err == VK_SUCCESS);
19789 ASSERT_TRUE(pass);
19790 m_errorMonitor->VerifyFound();
19791
19792 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
19793 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
19794 pass = (err == VK_SUCCESS);
19795 ASSERT_TRUE(pass);
19796
19797 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
19798 VkPresentModeKHR *surface_present_modes = (VkPresentModeKHR *)malloc(surface_present_mode_count * sizeof(VkPresentModeKHR));
19799
19800 // Next, do a 2nd try with surface_format_count being set too high:
19801 surface_present_mode_count += 5;
19802 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
19803 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
19804 pass = (err == VK_SUCCESS);
19805 ASSERT_TRUE(pass);
19806 m_errorMonitor->VerifyFound();
19807
19808 // Finally, do a correct 1st and 2nd try:
19809 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
19810 pass = (err == VK_SUCCESS);
19811 ASSERT_TRUE(pass);
19812 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
19813 pass = (err == VK_SUCCESS);
19814 ASSERT_TRUE(pass);
19815
19816 // Create a swapchain:
19817
19818 // First, try without a pointer to swapchain_create_info:
19819 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo "
19820 "specified as NULL");
19821
19822 err = vkCreateSwapchainKHR(m_device->device(), NULL, NULL, &swapchain);
19823 pass = (err != VK_SUCCESS);
19824 ASSERT_TRUE(pass);
19825 m_errorMonitor->VerifyFound();
19826
19827 // Next, call with a non-NULL swapchain_create_info, that has the wrong
19828 // sType:
19829 swapchain_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
19830 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
19831
19832 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
19833 pass = (err != VK_SUCCESS);
19834 ASSERT_TRUE(pass);
19835 m_errorMonitor->VerifyFound();
19836
19837 // Next, call with a NULL swapchain pointer:
19838 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
19839 swapchain_create_info.pNext = NULL;
19840 swapchain_create_info.flags = 0;
19841 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSwapchain "
19842 "specified as NULL");
19843
19844 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, NULL);
19845 pass = (err != VK_SUCCESS);
19846 ASSERT_TRUE(pass);
19847 m_errorMonitor->VerifyFound();
19848
19849 // TODO: Enhance swapchain layer so that
19850 // swapchain_create_info.queueFamilyIndexCount is checked against something?
19851
19852 // Next, call with a queue family index that's too large:
19853 uint32_t queueFamilyIndex[2] = { 100000, 0 };
19854 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
19855 swapchain_create_info.queueFamilyIndexCount = 2;
19856 swapchain_create_info.pQueueFamilyIndices = queueFamilyIndex;
19857 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
19858 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
19859 pass = (err != VK_SUCCESS);
19860 ASSERT_TRUE(pass);
19861 m_errorMonitor->VerifyFound();
19862
19863 // Next, call a queueFamilyIndexCount that's too small for CONCURRENT:
19864 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
19865 swapchain_create_info.queueFamilyIndexCount = 1;
19866 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
19867 "but with a bad value(s) for pCreateInfo->queueFamilyIndexCount or "
19868 "pCreateInfo->pQueueFamilyIndices).");
19869 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
19870 pass = (err != VK_SUCCESS);
19871 ASSERT_TRUE(pass);
19872 m_errorMonitor->VerifyFound();
19873
19874 // Next, call with an invalid imageSharingMode:
19875 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_MAX_ENUM;
19876 swapchain_create_info.queueFamilyIndexCount = 1;
19877 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
19878 "called with a non-supported pCreateInfo->imageSharingMode (i.e.");
19879 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
19880 pass = (err != VK_SUCCESS);
19881 ASSERT_TRUE(pass);
19882 m_errorMonitor->VerifyFound();
19883 // Fix for the future:
19884 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
19885 // SUPPORTED
19886 swapchain_create_info.queueFamilyIndexCount = 0;
19887 queueFamilyIndex[0] = 0;
19888 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
19889
19890 // TODO: CONTINUE TESTING VALIDATION OF vkCreateSwapchainKHR() ...
19891 // Get the images from a swapchain:
19892 // Acquire an image from a swapchain:
19893 // Present an image to a swapchain:
19894 // Destroy the swapchain:
19895
19896 // TODOs:
19897 //
19898 // - Try destroying the device without first destroying the swapchain
19899 //
19900 // - Try destroying the device without first destroying the surface
19901 //
19902 // - Try destroying the surface without first destroying the swapchain
19903
19904 // Destroy the surface:
19905 vkDestroySurfaceKHR(instance(), surface, NULL);
19906
19907 // Tear down the window:
19908 xcb_destroy_window(connection, xcb_window);
19909 xcb_disconnect(connection);
19910
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019911#else // VK_USE_PLATFORM_XCB_KHR
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019912 return;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019913#endif // VK_USE_PLATFORM_XCB_KHR
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019914}
Chris Forbes09368e42016-10-13 11:59:22 +130019915#endif
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019916
19917//
19918// POSITIVE VALIDATION TESTS
19919//
19920// These tests do not expect to encounter ANY validation errors pass only if this is true
19921
Mark Lobodzinski781aeb52017-02-22 10:57:53 -070019922TEST_F(VkPositiveLayerTest, SecondaryCommandBufferClearColorAttachments) {
19923 TEST_DESCRIPTION("Create a secondary command buffer and record a CmdClearAttachments call into it");
Tony Barbour1fa09702017-03-16 12:09:08 -060019924 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski781aeb52017-02-22 10:57:53 -070019925 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19926
19927 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
19928 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mike Schuchardt06304c22017-03-01 17:09:09 -070019929 command_buffer_allocate_info.commandPool = m_commandPool->handle();
Mark Lobodzinski781aeb52017-02-22 10:57:53 -070019930 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
19931 command_buffer_allocate_info.commandBufferCount = 1;
19932
19933 VkCommandBuffer secondary_command_buffer;
19934 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
19935 VkCommandBufferBeginInfo command_buffer_begin_info = {};
19936 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
19937 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
19938 command_buffer_inheritance_info.renderPass = m_renderPass;
19939 command_buffer_inheritance_info.framebuffer = m_framebuffer;
19940
19941 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19942 command_buffer_begin_info.flags =
19943 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
19944 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
19945
19946 vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
19947 VkClearAttachment color_attachment;
19948 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
19949 color_attachment.clearValue.color.float32[0] = 0;
19950 color_attachment.clearValue.color.float32[1] = 0;
19951 color_attachment.clearValue.color.float32[2] = 0;
19952 color_attachment.clearValue.color.float32[3] = 0;
19953 color_attachment.colorAttachment = 0;
19954 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
19955 vkCmdClearAttachments(secondary_command_buffer, 1, &color_attachment, 1, &clear_rect);
19956}
19957
Tobin Ehlise0006882016-11-03 10:14:28 -060019958TEST_F(VkPositiveLayerTest, SecondaryCommandBufferImageLayoutTransitions) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019959 TEST_DESCRIPTION(
19960 "Perform an image layout transition in a secondary command buffer followed "
19961 "by a transition in the primary.");
Tobin Ehlise0006882016-11-03 10:14:28 -060019962 VkResult err;
19963 m_errorMonitor->ExpectSuccess();
Tony Barbour1fa09702017-03-16 12:09:08 -060019964 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -060019965 auto depth_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbourf887b162017-03-09 10:06:46 -070019966 if (!depth_format) {
19967 return;
19968 }
Tobin Ehlise0006882016-11-03 10:14:28 -060019969 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19970 // Allocate a secondary and primary cmd buffer
19971 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
19972 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mike Schuchardt06304c22017-03-01 17:09:09 -070019973 command_buffer_allocate_info.commandPool = m_commandPool->handle();
Tobin Ehlise0006882016-11-03 10:14:28 -060019974 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
19975 command_buffer_allocate_info.commandBufferCount = 1;
19976
19977 VkCommandBuffer secondary_command_buffer;
19978 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
19979 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19980 VkCommandBuffer primary_command_buffer;
19981 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &primary_command_buffer));
19982 VkCommandBufferBeginInfo command_buffer_begin_info = {};
19983 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
19984 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
19985 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19986 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
19987 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
19988
19989 err = vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
19990 ASSERT_VK_SUCCESS(err);
19991 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060019992 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 -060019993 ASSERT_TRUE(image.initialized());
19994 VkImageMemoryBarrier img_barrier = {};
19995 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
19996 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
19997 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
19998 img_barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
19999 img_barrier.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
20000 img_barrier.image = image.handle();
20001 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
20002 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
20003 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
20004 img_barrier.subresourceRange.baseArrayLayer = 0;
20005 img_barrier.subresourceRange.baseMipLevel = 0;
20006 img_barrier.subresourceRange.layerCount = 1;
20007 img_barrier.subresourceRange.levelCount = 1;
20008 vkCmdPipelineBarrier(secondary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr,
20009 0, nullptr, 1, &img_barrier);
20010 err = vkEndCommandBuffer(secondary_command_buffer);
20011 ASSERT_VK_SUCCESS(err);
20012
20013 // Now update primary cmd buffer to execute secondary and transitions image
20014 command_buffer_begin_info.pInheritanceInfo = nullptr;
20015 err = vkBeginCommandBuffer(primary_command_buffer, &command_buffer_begin_info);
20016 ASSERT_VK_SUCCESS(err);
20017 vkCmdExecuteCommands(primary_command_buffer, 1, &secondary_command_buffer);
20018 VkImageMemoryBarrier img_barrier2 = {};
20019 img_barrier2.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
20020 img_barrier2.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
20021 img_barrier2.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
20022 img_barrier2.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
20023 img_barrier2.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
20024 img_barrier2.image = image.handle();
20025 img_barrier2.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
20026 img_barrier2.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
20027 img_barrier2.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
20028 img_barrier2.subresourceRange.baseArrayLayer = 0;
20029 img_barrier2.subresourceRange.baseMipLevel = 0;
20030 img_barrier2.subresourceRange.layerCount = 1;
20031 img_barrier2.subresourceRange.levelCount = 1;
20032 vkCmdPipelineBarrier(primary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
20033 nullptr, 1, &img_barrier2);
20034 err = vkEndCommandBuffer(primary_command_buffer);
20035 ASSERT_VK_SUCCESS(err);
20036 VkSubmitInfo submit_info = {};
20037 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20038 submit_info.commandBufferCount = 1;
20039 submit_info.pCommandBuffers = &primary_command_buffer;
20040 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
20041 ASSERT_VK_SUCCESS(err);
20042 m_errorMonitor->VerifyNotFound();
20043 err = vkDeviceWaitIdle(m_device->device());
20044 ASSERT_VK_SUCCESS(err);
Mike Schuchardt06304c22017-03-01 17:09:09 -070020045 vkFreeCommandBuffers(m_device->device(), m_commandPool->handle(), 1, &secondary_command_buffer);
20046 vkFreeCommandBuffers(m_device->device(), m_commandPool->handle(), 1, &primary_command_buffer);
Tobin Ehlise0006882016-11-03 10:14:28 -060020047}
20048
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020049// This is a positive test. No failures are expected.
20050TEST_F(VkPositiveLayerTest, IgnoreUnrelatedDescriptor) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020051 TEST_DESCRIPTION(
20052 "Ensure that the vkUpdateDescriptorSets validation code "
20053 "is ignoring VkWriteDescriptorSet members that are not "
20054 "related to the descriptor type specified by "
20055 "VkWriteDescriptorSet::descriptorType. Correct "
20056 "validation behavior will result in the test running to "
20057 "completion without validation errors.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020058
20059 const uintptr_t invalid_ptr = 0xcdcdcdcd;
20060
Tony Barbour1fa09702017-03-16 12:09:08 -060020061 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020062
20063 // Image Case
20064 {
20065 m_errorMonitor->ExpectSuccess();
20066
20067 VkImage image;
20068 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
20069 const int32_t tex_width = 32;
20070 const int32_t tex_height = 32;
20071 VkImageCreateInfo image_create_info = {};
20072 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
20073 image_create_info.pNext = NULL;
20074 image_create_info.imageType = VK_IMAGE_TYPE_2D;
20075 image_create_info.format = tex_format;
20076 image_create_info.extent.width = tex_width;
20077 image_create_info.extent.height = tex_height;
20078 image_create_info.extent.depth = 1;
20079 image_create_info.mipLevels = 1;
20080 image_create_info.arrayLayers = 1;
20081 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
20082 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
20083 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
20084 image_create_info.flags = 0;
20085 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
20086 ASSERT_VK_SUCCESS(err);
20087
20088 VkMemoryRequirements memory_reqs;
20089 VkDeviceMemory image_memory;
20090 bool pass;
20091 VkMemoryAllocateInfo memory_info = {};
20092 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
20093 memory_info.pNext = NULL;
20094 memory_info.allocationSize = 0;
20095 memory_info.memoryTypeIndex = 0;
20096 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
20097 memory_info.allocationSize = memory_reqs.size;
20098 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
20099 ASSERT_TRUE(pass);
20100 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
20101 ASSERT_VK_SUCCESS(err);
20102 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
20103 ASSERT_VK_SUCCESS(err);
20104
20105 VkImageViewCreateInfo image_view_create_info = {};
20106 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
20107 image_view_create_info.image = image;
20108 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
20109 image_view_create_info.format = tex_format;
20110 image_view_create_info.subresourceRange.layerCount = 1;
20111 image_view_create_info.subresourceRange.baseMipLevel = 0;
20112 image_view_create_info.subresourceRange.levelCount = 1;
20113 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
20114
20115 VkImageView view;
20116 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
20117 ASSERT_VK_SUCCESS(err);
20118
20119 VkDescriptorPoolSize ds_type_count = {};
20120 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
20121 ds_type_count.descriptorCount = 1;
20122
20123 VkDescriptorPoolCreateInfo ds_pool_ci = {};
20124 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
20125 ds_pool_ci.pNext = NULL;
20126 ds_pool_ci.maxSets = 1;
20127 ds_pool_ci.poolSizeCount = 1;
20128 ds_pool_ci.pPoolSizes = &ds_type_count;
20129
20130 VkDescriptorPool ds_pool;
20131 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
20132 ASSERT_VK_SUCCESS(err);
20133
20134 VkDescriptorSetLayoutBinding dsl_binding = {};
20135 dsl_binding.binding = 0;
20136 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
20137 dsl_binding.descriptorCount = 1;
20138 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
20139 dsl_binding.pImmutableSamplers = NULL;
20140
20141 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
20142 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
20143 ds_layout_ci.pNext = NULL;
20144 ds_layout_ci.bindingCount = 1;
20145 ds_layout_ci.pBindings = &dsl_binding;
20146 VkDescriptorSetLayout ds_layout;
20147 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
20148 ASSERT_VK_SUCCESS(err);
20149
20150 VkDescriptorSet descriptor_set;
20151 VkDescriptorSetAllocateInfo alloc_info = {};
20152 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
20153 alloc_info.descriptorSetCount = 1;
20154 alloc_info.descriptorPool = ds_pool;
20155 alloc_info.pSetLayouts = &ds_layout;
20156 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
20157 ASSERT_VK_SUCCESS(err);
20158
20159 VkDescriptorImageInfo image_info = {};
20160 image_info.imageView = view;
20161 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
20162
20163 VkWriteDescriptorSet descriptor_write;
20164 memset(&descriptor_write, 0, sizeof(descriptor_write));
20165 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
20166 descriptor_write.dstSet = descriptor_set;
20167 descriptor_write.dstBinding = 0;
20168 descriptor_write.descriptorCount = 1;
20169 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
20170 descriptor_write.pImageInfo = &image_info;
20171
20172 // Set pBufferInfo and pTexelBufferView to invalid values, which should
20173 // be
20174 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE.
20175 // This will most likely produce a crash if the parameter_validation
20176 // layer
20177 // does not correctly ignore pBufferInfo.
20178 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
20179 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
20180
20181 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
20182
20183 m_errorMonitor->VerifyNotFound();
20184
20185 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
20186 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
20187 vkDestroyImageView(m_device->device(), view, NULL);
20188 vkDestroyImage(m_device->device(), image, NULL);
20189 vkFreeMemory(m_device->device(), image_memory, NULL);
20190 }
20191
20192 // Buffer Case
20193 {
20194 m_errorMonitor->ExpectSuccess();
20195
20196 VkBuffer buffer;
20197 uint32_t queue_family_index = 0;
20198 VkBufferCreateInfo buffer_create_info = {};
20199 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
20200 buffer_create_info.size = 1024;
20201 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
20202 buffer_create_info.queueFamilyIndexCount = 1;
20203 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
20204
20205 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
20206 ASSERT_VK_SUCCESS(err);
20207
20208 VkMemoryRequirements memory_reqs;
20209 VkDeviceMemory buffer_memory;
20210 bool pass;
20211 VkMemoryAllocateInfo memory_info = {};
20212 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
20213 memory_info.pNext = NULL;
20214 memory_info.allocationSize = 0;
20215 memory_info.memoryTypeIndex = 0;
20216
20217 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
20218 memory_info.allocationSize = memory_reqs.size;
20219 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
20220 ASSERT_TRUE(pass);
20221
20222 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
20223 ASSERT_VK_SUCCESS(err);
20224 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
20225 ASSERT_VK_SUCCESS(err);
20226
20227 VkDescriptorPoolSize ds_type_count = {};
20228 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
20229 ds_type_count.descriptorCount = 1;
20230
20231 VkDescriptorPoolCreateInfo ds_pool_ci = {};
20232 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
20233 ds_pool_ci.pNext = NULL;
20234 ds_pool_ci.maxSets = 1;
20235 ds_pool_ci.poolSizeCount = 1;
20236 ds_pool_ci.pPoolSizes = &ds_type_count;
20237
20238 VkDescriptorPool ds_pool;
20239 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
20240 ASSERT_VK_SUCCESS(err);
20241
20242 VkDescriptorSetLayoutBinding dsl_binding = {};
20243 dsl_binding.binding = 0;
20244 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
20245 dsl_binding.descriptorCount = 1;
20246 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
20247 dsl_binding.pImmutableSamplers = NULL;
20248
20249 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
20250 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
20251 ds_layout_ci.pNext = NULL;
20252 ds_layout_ci.bindingCount = 1;
20253 ds_layout_ci.pBindings = &dsl_binding;
20254 VkDescriptorSetLayout ds_layout;
20255 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
20256 ASSERT_VK_SUCCESS(err);
20257
20258 VkDescriptorSet descriptor_set;
20259 VkDescriptorSetAllocateInfo alloc_info = {};
20260 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
20261 alloc_info.descriptorSetCount = 1;
20262 alloc_info.descriptorPool = ds_pool;
20263 alloc_info.pSetLayouts = &ds_layout;
20264 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
20265 ASSERT_VK_SUCCESS(err);
20266
20267 VkDescriptorBufferInfo buffer_info = {};
20268 buffer_info.buffer = buffer;
20269 buffer_info.offset = 0;
20270 buffer_info.range = 1024;
20271
20272 VkWriteDescriptorSet descriptor_write;
20273 memset(&descriptor_write, 0, sizeof(descriptor_write));
20274 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
20275 descriptor_write.dstSet = descriptor_set;
20276 descriptor_write.dstBinding = 0;
20277 descriptor_write.descriptorCount = 1;
20278 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
20279 descriptor_write.pBufferInfo = &buffer_info;
20280
20281 // Set pImageInfo and pTexelBufferView to invalid values, which should
20282 // be
20283 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER.
20284 // This will most likely produce a crash if the parameter_validation
20285 // layer
20286 // does not correctly ignore pImageInfo.
20287 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
20288 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
20289
20290 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
20291
20292 m_errorMonitor->VerifyNotFound();
20293
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020294 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
20295 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
20296 vkDestroyBuffer(m_device->device(), buffer, NULL);
20297 vkFreeMemory(m_device->device(), buffer_memory, NULL);
20298 }
20299
20300 // Texel Buffer Case
20301 {
20302 m_errorMonitor->ExpectSuccess();
20303
20304 VkBuffer buffer;
20305 uint32_t queue_family_index = 0;
20306 VkBufferCreateInfo buffer_create_info = {};
20307 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
20308 buffer_create_info.size = 1024;
20309 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
20310 buffer_create_info.queueFamilyIndexCount = 1;
20311 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
20312
20313 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
20314 ASSERT_VK_SUCCESS(err);
20315
20316 VkMemoryRequirements memory_reqs;
20317 VkDeviceMemory buffer_memory;
20318 bool pass;
20319 VkMemoryAllocateInfo memory_info = {};
20320 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
20321 memory_info.pNext = NULL;
20322 memory_info.allocationSize = 0;
20323 memory_info.memoryTypeIndex = 0;
20324
20325 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
20326 memory_info.allocationSize = memory_reqs.size;
20327 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
20328 ASSERT_TRUE(pass);
20329
20330 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
20331 ASSERT_VK_SUCCESS(err);
20332 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
20333 ASSERT_VK_SUCCESS(err);
20334
20335 VkBufferViewCreateInfo buff_view_ci = {};
20336 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
20337 buff_view_ci.buffer = buffer;
20338 buff_view_ci.format = VK_FORMAT_R8_UNORM;
20339 buff_view_ci.range = VK_WHOLE_SIZE;
20340 VkBufferView buffer_view;
20341 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buffer_view);
20342
20343 VkDescriptorPoolSize ds_type_count = {};
20344 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
20345 ds_type_count.descriptorCount = 1;
20346
20347 VkDescriptorPoolCreateInfo ds_pool_ci = {};
20348 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
20349 ds_pool_ci.pNext = NULL;
20350 ds_pool_ci.maxSets = 1;
20351 ds_pool_ci.poolSizeCount = 1;
20352 ds_pool_ci.pPoolSizes = &ds_type_count;
20353
20354 VkDescriptorPool ds_pool;
20355 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
20356 ASSERT_VK_SUCCESS(err);
20357
20358 VkDescriptorSetLayoutBinding dsl_binding = {};
20359 dsl_binding.binding = 0;
20360 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
20361 dsl_binding.descriptorCount = 1;
20362 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
20363 dsl_binding.pImmutableSamplers = NULL;
20364
20365 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
20366 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
20367 ds_layout_ci.pNext = NULL;
20368 ds_layout_ci.bindingCount = 1;
20369 ds_layout_ci.pBindings = &dsl_binding;
20370 VkDescriptorSetLayout ds_layout;
20371 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
20372 ASSERT_VK_SUCCESS(err);
20373
20374 VkDescriptorSet descriptor_set;
20375 VkDescriptorSetAllocateInfo alloc_info = {};
20376 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
20377 alloc_info.descriptorSetCount = 1;
20378 alloc_info.descriptorPool = ds_pool;
20379 alloc_info.pSetLayouts = &ds_layout;
20380 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
20381 ASSERT_VK_SUCCESS(err);
20382
20383 VkWriteDescriptorSet descriptor_write;
20384 memset(&descriptor_write, 0, sizeof(descriptor_write));
20385 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
20386 descriptor_write.dstSet = descriptor_set;
20387 descriptor_write.dstBinding = 0;
20388 descriptor_write.descriptorCount = 1;
20389 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
20390 descriptor_write.pTexelBufferView = &buffer_view;
20391
20392 // Set pImageInfo and pBufferInfo to invalid values, which should be
20393 // ignored for descriptorType ==
20394 // VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER.
20395 // This will most likely produce a crash if the parameter_validation
20396 // layer
20397 // does not correctly ignore pImageInfo and pBufferInfo.
20398 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
20399 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
20400
20401 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
20402
20403 m_errorMonitor->VerifyNotFound();
20404
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020405 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
20406 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
20407 vkDestroyBufferView(m_device->device(), buffer_view, NULL);
20408 vkDestroyBuffer(m_device->device(), buffer, NULL);
20409 vkFreeMemory(m_device->device(), buffer_memory, NULL);
20410 }
20411}
20412
Tobin Ehlis8893af82017-05-08 12:52:25 -060020413TEST_F(VkPositiveLayerTest, ImmutableSamplerOnlyDescriptor) {
20414 TEST_DESCRIPTION(
20415 "Bind a DescriptorSet with only an immutable sampler"
20416 "and make sure that we don't warn for no update.");
20417
20418 ASSERT_NO_FATAL_FAILURE(Init());
20419 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20420
20421 VkDescriptorPoolSize ds_type_count = {};
20422 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
20423 ds_type_count.descriptorCount = 1;
20424
20425 VkDescriptorPoolCreateInfo ds_pool_ci = {};
20426 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
20427 ds_pool_ci.maxSets = 1;
20428 ds_pool_ci.poolSizeCount = 1;
20429 ds_pool_ci.pPoolSizes = &ds_type_count;
20430
20431 VkDescriptorPool ds_pool;
20432 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
20433 ASSERT_VK_SUCCESS(err);
20434
20435 VkSamplerCreateInfo sampler_ci = {};
20436 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
20437 sampler_ci.pNext = NULL;
20438 sampler_ci.magFilter = VK_FILTER_NEAREST;
20439 sampler_ci.minFilter = VK_FILTER_NEAREST;
20440 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
20441 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
20442 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
20443 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
20444 sampler_ci.mipLodBias = 1.0;
20445 sampler_ci.anisotropyEnable = VK_FALSE;
20446 sampler_ci.maxAnisotropy = 1;
20447 sampler_ci.compareEnable = VK_FALSE;
20448 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
20449 sampler_ci.minLod = 1.0;
20450 sampler_ci.maxLod = 1.0;
20451 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
20452 sampler_ci.unnormalizedCoordinates = VK_FALSE;
20453 VkSampler sampler;
20454
20455 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
20456 ASSERT_VK_SUCCESS(err);
20457
20458 VkDescriptorSetLayoutBinding layout_binding = {};
20459 layout_binding.binding = 0;
20460 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
20461 layout_binding.descriptorCount = 1;
20462 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
20463 layout_binding.pImmutableSamplers = static_cast<VkSampler *>(&sampler);
20464
20465 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
20466 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
20467 ds_layout_ci.bindingCount = 1;
20468 ds_layout_ci.pBindings = &layout_binding;
20469 VkDescriptorSetLayout ds_layout;
20470 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
20471 ASSERT_VK_SUCCESS(err);
20472
20473 VkDescriptorSetAllocateInfo alloc_info = {};
20474 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
20475 alloc_info.descriptorSetCount = 1;
20476 alloc_info.descriptorPool = ds_pool;
20477 alloc_info.pSetLayouts = &ds_layout;
20478 VkDescriptorSet descriptor_set;
20479 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
20480 ASSERT_VK_SUCCESS(err);
20481
20482 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
20483 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
20484 pipeline_layout_ci.pNext = NULL;
20485 pipeline_layout_ci.setLayoutCount = 1;
20486 pipeline_layout_ci.pSetLayouts = &ds_layout;
20487
20488 VkPipelineLayout pipeline_layout;
20489 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
20490 ASSERT_VK_SUCCESS(err);
20491
20492 m_errorMonitor->ExpectSuccess();
20493 m_commandBuffer->BeginCommandBuffer();
20494 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
20495
20496 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
20497 &descriptor_set, 0, nullptr);
20498 m_errorMonitor->VerifyNotFound();
20499
20500 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
20501 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
20502 vkDestroySampler(m_device->device(), sampler, NULL);
20503 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
20504}
20505
Tobin Ehlisf7428442016-10-25 07:58:24 -060020506TEST_F(VkLayerTest, DuplicateDescriptorBinding) {
20507 TEST_DESCRIPTION("Create a descriptor set layout with a duplicate binding number.");
20508
Tony Barbour1fa09702017-03-16 12:09:08 -060020509 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisf7428442016-10-25 07:58:24 -060020510 // Create layout where two binding #s are "1"
20511 static const uint32_t NUM_BINDINGS = 3;
20512 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
20513 dsl_binding[0].binding = 1;
20514 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
20515 dsl_binding[0].descriptorCount = 1;
20516 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
20517 dsl_binding[0].pImmutableSamplers = NULL;
20518 dsl_binding[1].binding = 0;
20519 dsl_binding[1].descriptorCount = 1;
20520 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
20521 dsl_binding[1].descriptorCount = 1;
20522 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
20523 dsl_binding[1].pImmutableSamplers = NULL;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020524 dsl_binding[2].binding = 1; // Duplicate binding should cause error
Tobin Ehlisf7428442016-10-25 07:58:24 -060020525 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
20526 dsl_binding[2].descriptorCount = 1;
20527 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
20528 dsl_binding[2].pImmutableSamplers = NULL;
20529
20530 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
20531 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
20532 ds_layout_ci.pNext = NULL;
20533 ds_layout_ci.bindingCount = NUM_BINDINGS;
20534 ds_layout_ci.pBindings = dsl_binding;
20535 VkDescriptorSetLayout ds_layout;
20536 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02345);
20537 vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
20538 m_errorMonitor->VerifyFound();
20539}
20540
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060020541TEST_F(VkLayerTest, ViewportAndScissorBoundsChecking) {
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060020542 TEST_DESCRIPTION("Verify errors are detected on misuse of SetViewport and SetScissor.");
20543
Tony Barbour1fa09702017-03-16 12:09:08 -060020544 ASSERT_NO_FATAL_FAILURE(Init());
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060020545
Tony Barbour552f6c02016-12-21 14:34:07 -070020546 m_commandBuffer->BeginCommandBuffer();
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060020547
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060020548 const VkPhysicalDeviceLimits &limits = m_device->props.limits;
20549
20550 {
20551 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01448);
20552 VkViewport viewport = {0, 0, static_cast<float>(limits.maxViewportDimensions[0] + 1), 16, 0, 1};
20553 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
20554 m_errorMonitor->VerifyFound();
20555 }
20556
20557 {
20558 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01449);
20559 VkViewport viewport = {0, 0, 16, static_cast<float>(limits.maxViewportDimensions[1] + 1), 0, 1};
20560 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
20561 m_errorMonitor->VerifyFound();
20562 }
20563
20564 {
20565 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
20566 VkViewport viewport = {limits.viewportBoundsRange[0] - 1, 0, 16, 16, 0, 1};
20567 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
20568 m_errorMonitor->VerifyFound();
20569 }
20570
20571 {
20572 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
20573 VkViewport viewport = {0, limits.viewportBoundsRange[0] - 1, 16, 16, 0, 1};
20574 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
20575 m_errorMonitor->VerifyFound();
20576 }
20577
20578 {
20579 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01451);
20580 VkViewport viewport = {limits.viewportBoundsRange[1], 0, 16, 16, 0, 1};
20581 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
20582 m_errorMonitor->VerifyFound();
20583 }
20584
20585 {
20586 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01452);
20587 VkViewport viewport = {0, limits.viewportBoundsRange[1], 16, 16, 0, 1};
20588 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
20589 m_errorMonitor->VerifyFound();
20590 }
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060020591
20592 {
20593 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
20594 VkRect2D scissor = {{-1, 0}, {16, 16}};
20595 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
20596 m_errorMonitor->VerifyFound();
20597 }
20598
20599 {
20600 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
20601 VkRect2D scissor = {{0, -2}, {16, 16}};
20602 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
20603 m_errorMonitor->VerifyFound();
20604 }
20605
20606 {
20607 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01490);
20608 VkRect2D scissor = {{100, 100}, {INT_MAX, 16}};
20609 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
20610 m_errorMonitor->VerifyFound();
20611 }
20612
20613 {
20614 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01491);
20615 VkRect2D scissor = {{100, 100}, {16, INT_MAX}};
20616 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
20617 m_errorMonitor->VerifyFound();
20618 }
20619
Tony Barbour552f6c02016-12-21 14:34:07 -070020620 m_commandBuffer->EndCommandBuffer();
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060020621}
20622
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020623// This is a positive test. No failures are expected.
20624TEST_F(VkPositiveLayerTest, EmptyDescriptorUpdateTest) {
20625 TEST_DESCRIPTION("Update last descriptor in a set that includes an empty binding");
20626 VkResult err;
20627
Tony Barbour1fa09702017-03-16 12:09:08 -060020628 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020629 m_errorMonitor->ExpectSuccess();
20630 VkDescriptorPoolSize ds_type_count = {};
20631 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
20632 ds_type_count.descriptorCount = 2;
20633
20634 VkDescriptorPoolCreateInfo ds_pool_ci = {};
20635 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
20636 ds_pool_ci.pNext = NULL;
20637 ds_pool_ci.maxSets = 1;
20638 ds_pool_ci.poolSizeCount = 1;
20639 ds_pool_ci.pPoolSizes = &ds_type_count;
20640
20641 VkDescriptorPool ds_pool;
20642 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
20643 ASSERT_VK_SUCCESS(err);
20644
20645 // Create layout with two uniform buffer descriptors w/ empty binding between them
20646 static const uint32_t NUM_BINDINGS = 3;
20647 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
20648 dsl_binding[0].binding = 0;
20649 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
20650 dsl_binding[0].descriptorCount = 1;
20651 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
20652 dsl_binding[0].pImmutableSamplers = NULL;
20653 dsl_binding[1].binding = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020654 dsl_binding[1].descriptorCount = 0; // empty binding
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020655 dsl_binding[2].binding = 2;
20656 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
20657 dsl_binding[2].descriptorCount = 1;
20658 dsl_binding[2].stageFlags = VK_SHADER_STAGE_ALL;
20659 dsl_binding[2].pImmutableSamplers = NULL;
20660
20661 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
20662 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
20663 ds_layout_ci.pNext = NULL;
20664 ds_layout_ci.bindingCount = NUM_BINDINGS;
20665 ds_layout_ci.pBindings = dsl_binding;
20666 VkDescriptorSetLayout ds_layout;
20667 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
20668 ASSERT_VK_SUCCESS(err);
20669
20670 VkDescriptorSet descriptor_set = {};
20671 VkDescriptorSetAllocateInfo alloc_info = {};
20672 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
20673 alloc_info.descriptorSetCount = 1;
20674 alloc_info.descriptorPool = ds_pool;
20675 alloc_info.pSetLayouts = &ds_layout;
20676 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
20677 ASSERT_VK_SUCCESS(err);
20678
20679 // Create a buffer to be used for update
20680 VkBufferCreateInfo buff_ci = {};
20681 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
20682 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
20683 buff_ci.size = 256;
20684 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
20685 VkBuffer buffer;
20686 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
20687 ASSERT_VK_SUCCESS(err);
20688 // Have to bind memory to buffer before descriptor update
20689 VkMemoryAllocateInfo mem_alloc = {};
20690 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
20691 mem_alloc.pNext = NULL;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020692 mem_alloc.allocationSize = 512; // one allocation for both buffers
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020693 mem_alloc.memoryTypeIndex = 0;
20694
20695 VkMemoryRequirements mem_reqs;
20696 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
20697 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
20698 if (!pass) {
20699 vkDestroyBuffer(m_device->device(), buffer, NULL);
20700 return;
20701 }
20702
20703 VkDeviceMemory mem;
20704 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
20705 ASSERT_VK_SUCCESS(err);
20706 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
20707 ASSERT_VK_SUCCESS(err);
20708
20709 // Only update the descriptor at binding 2
20710 VkDescriptorBufferInfo buff_info = {};
20711 buff_info.buffer = buffer;
20712 buff_info.offset = 0;
20713 buff_info.range = VK_WHOLE_SIZE;
20714 VkWriteDescriptorSet descriptor_write = {};
20715 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
20716 descriptor_write.dstBinding = 2;
20717 descriptor_write.descriptorCount = 1;
20718 descriptor_write.pTexelBufferView = nullptr;
20719 descriptor_write.pBufferInfo = &buff_info;
20720 descriptor_write.pImageInfo = nullptr;
20721 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
20722 descriptor_write.dstSet = descriptor_set;
20723
20724 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
20725
20726 m_errorMonitor->VerifyNotFound();
20727 // Cleanup
20728 vkFreeMemory(m_device->device(), mem, NULL);
20729 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
20730 vkDestroyBuffer(m_device->device(), buffer, NULL);
20731 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
20732}
20733
20734// This is a positive test. No failures are expected.
20735TEST_F(VkPositiveLayerTest, TestAliasedMemoryTracking) {
20736 VkResult err;
20737 bool pass;
20738
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020739 TEST_DESCRIPTION(
20740 "Create a buffer, allocate memory, bind memory, destroy "
20741 "the buffer, create an image, and bind the same memory to "
20742 "it");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020743
20744 m_errorMonitor->ExpectSuccess();
20745
Tony Barbour1fa09702017-03-16 12:09:08 -060020746 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020747
20748 VkBuffer buffer;
20749 VkImage image;
20750 VkDeviceMemory mem;
20751 VkMemoryRequirements mem_reqs;
20752
20753 VkBufferCreateInfo buf_info = {};
20754 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
20755 buf_info.pNext = NULL;
20756 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
20757 buf_info.size = 256;
20758 buf_info.queueFamilyIndexCount = 0;
20759 buf_info.pQueueFamilyIndices = NULL;
20760 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
20761 buf_info.flags = 0;
20762 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
20763 ASSERT_VK_SUCCESS(err);
20764
20765 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
20766
20767 VkMemoryAllocateInfo alloc_info = {};
20768 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
20769 alloc_info.pNext = NULL;
20770 alloc_info.memoryTypeIndex = 0;
Dave Houlton9dae7ec2017-03-01 16:23:25 -070020771
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020772 // Ensure memory is big enough for both bindings
20773 alloc_info.allocationSize = 0x10000;
20774
20775 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
20776 if (!pass) {
20777 vkDestroyBuffer(m_device->device(), buffer, NULL);
20778 return;
20779 }
20780
20781 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
20782 ASSERT_VK_SUCCESS(err);
20783
20784 uint8_t *pData;
20785 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
20786 ASSERT_VK_SUCCESS(err);
20787
20788 memset(pData, 0xCADECADE, static_cast<size_t>(mem_reqs.size));
20789
20790 vkUnmapMemory(m_device->device(), mem);
20791
20792 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
20793 ASSERT_VK_SUCCESS(err);
20794
20795 // NOW, destroy the buffer. Obviously, the resource no longer occupies this
20796 // memory. In fact, it was never used by the GPU.
20797 // Just be be sure, wait for idle.
20798 vkDestroyBuffer(m_device->device(), buffer, NULL);
20799 vkDeviceWaitIdle(m_device->device());
20800
Tobin Ehlis6a005702016-12-28 15:25:56 -070020801 // Use optimal as some platforms report linear support but then fail image creation
20802 VkImageTiling image_tiling = VK_IMAGE_TILING_OPTIMAL;
20803 VkImageFormatProperties image_format_properties;
20804 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D, image_tiling,
20805 VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0, &image_format_properties);
20806 if (image_format_properties.maxExtent.width == 0) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070020807 printf(" Image format not supported; skipped.\n");
Tobin Ehlis6a005702016-12-28 15:25:56 -070020808 vkFreeMemory(m_device->device(), mem, NULL);
20809 return;
20810 }
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020811 VkImageCreateInfo image_create_info = {};
20812 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
20813 image_create_info.pNext = NULL;
20814 image_create_info.imageType = VK_IMAGE_TYPE_2D;
20815 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
20816 image_create_info.extent.width = 64;
20817 image_create_info.extent.height = 64;
20818 image_create_info.extent.depth = 1;
20819 image_create_info.mipLevels = 1;
20820 image_create_info.arrayLayers = 1;
20821 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis6a005702016-12-28 15:25:56 -070020822 image_create_info.tiling = image_tiling;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020823 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
20824 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
20825 image_create_info.queueFamilyIndexCount = 0;
20826 image_create_info.pQueueFamilyIndices = NULL;
20827 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
20828 image_create_info.flags = 0;
20829
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020830 /* Create a mappable image. It will be the texture if linear images are ok
Dave Houlton9dae7ec2017-03-01 16:23:25 -070020831 * to be textures or it will be the staging image if they are not.
20832 */
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020833 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
20834 ASSERT_VK_SUCCESS(err);
20835
20836 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
20837
Tobin Ehlis6a005702016-12-28 15:25:56 -070020838 VkMemoryAllocateInfo mem_alloc = {};
20839 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
20840 mem_alloc.pNext = NULL;
20841 mem_alloc.allocationSize = 0;
20842 mem_alloc.memoryTypeIndex = 0;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020843 mem_alloc.allocationSize = mem_reqs.size;
20844
20845 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
20846 if (!pass) {
Tobin Ehlis6a005702016-12-28 15:25:56 -070020847 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020848 vkDestroyImage(m_device->device(), image, NULL);
20849 return;
20850 }
20851
20852 // VALIDATION FAILURE:
20853 err = vkBindImageMemory(m_device->device(), image, mem, 0);
20854 ASSERT_VK_SUCCESS(err);
20855
20856 m_errorMonitor->VerifyNotFound();
20857
20858 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020859 vkDestroyImage(m_device->device(), image, NULL);
20860}
20861
Tony Barbourab713912017-02-02 14:17:35 -070020862// This is a positive test. No failures are expected.
20863TEST_F(VkPositiveLayerTest, TestDestroyFreeNullHandles) {
20864 VkResult err;
20865
20866 TEST_DESCRIPTION(
20867 "Call all applicable destroy and free routines with NULL"
20868 "handles, expecting no validation errors");
20869
20870 m_errorMonitor->ExpectSuccess();
20871
Tony Barbour1fa09702017-03-16 12:09:08 -060020872 ASSERT_NO_FATAL_FAILURE(Init());
Tony Barbourab713912017-02-02 14:17:35 -070020873 vkDestroyBuffer(m_device->device(), VK_NULL_HANDLE, NULL);
20874 vkDestroyBufferView(m_device->device(), VK_NULL_HANDLE, NULL);
20875 vkDestroyCommandPool(m_device->device(), VK_NULL_HANDLE, NULL);
20876 vkDestroyDescriptorPool(m_device->device(), VK_NULL_HANDLE, NULL);
20877 vkDestroyDescriptorSetLayout(m_device->device(), VK_NULL_HANDLE, NULL);
20878 vkDestroyDevice(VK_NULL_HANDLE, NULL);
20879 vkDestroyEvent(m_device->device(), VK_NULL_HANDLE, NULL);
20880 vkDestroyFence(m_device->device(), VK_NULL_HANDLE, NULL);
20881 vkDestroyFramebuffer(m_device->device(), VK_NULL_HANDLE, NULL);
20882 vkDestroyImage(m_device->device(), VK_NULL_HANDLE, NULL);
20883 vkDestroyImageView(m_device->device(), VK_NULL_HANDLE, NULL);
20884 vkDestroyInstance(VK_NULL_HANDLE, NULL);
20885 vkDestroyPipeline(m_device->device(), VK_NULL_HANDLE, NULL);
20886 vkDestroyPipelineCache(m_device->device(), VK_NULL_HANDLE, NULL);
20887 vkDestroyPipelineLayout(m_device->device(), VK_NULL_HANDLE, NULL);
20888 vkDestroyQueryPool(m_device->device(), VK_NULL_HANDLE, NULL);
20889 vkDestroyRenderPass(m_device->device(), VK_NULL_HANDLE, NULL);
20890 vkDestroySampler(m_device->device(), VK_NULL_HANDLE, NULL);
20891 vkDestroySemaphore(m_device->device(), VK_NULL_HANDLE, NULL);
20892 vkDestroyShaderModule(m_device->device(), VK_NULL_HANDLE, NULL);
20893
20894 VkCommandPool command_pool;
20895 VkCommandPoolCreateInfo pool_create_info{};
20896 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20897 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20898 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20899 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20900 VkCommandBuffer command_buffers[3] = {};
20901 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20902 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20903 command_buffer_allocate_info.commandPool = command_pool;
20904 command_buffer_allocate_info.commandBufferCount = 1;
20905 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20906 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffers[1]);
20907 vkFreeCommandBuffers(m_device->device(), command_pool, 3, command_buffers);
20908 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20909
20910 VkDescriptorPoolSize ds_type_count = {};
20911 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
20912 ds_type_count.descriptorCount = 1;
20913
20914 VkDescriptorPoolCreateInfo ds_pool_ci = {};
20915 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
20916 ds_pool_ci.pNext = NULL;
20917 ds_pool_ci.maxSets = 1;
20918 ds_pool_ci.poolSizeCount = 1;
20919 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
20920 ds_pool_ci.pPoolSizes = &ds_type_count;
20921
20922 VkDescriptorPool ds_pool;
20923 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
20924 ASSERT_VK_SUCCESS(err);
20925
20926 VkDescriptorSetLayoutBinding dsl_binding = {};
20927 dsl_binding.binding = 2;
20928 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
20929 dsl_binding.descriptorCount = 1;
20930 dsl_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
20931 dsl_binding.pImmutableSamplers = NULL;
20932 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
20933 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
20934 ds_layout_ci.pNext = NULL;
20935 ds_layout_ci.bindingCount = 1;
20936 ds_layout_ci.pBindings = &dsl_binding;
20937 VkDescriptorSetLayout ds_layout;
20938 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
20939 ASSERT_VK_SUCCESS(err);
20940
20941 VkDescriptorSet descriptor_sets[3] = {};
20942 VkDescriptorSetAllocateInfo alloc_info = {};
20943 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
20944 alloc_info.descriptorSetCount = 1;
20945 alloc_info.descriptorPool = ds_pool;
20946 alloc_info.pSetLayouts = &ds_layout;
20947 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_sets[1]);
20948 ASSERT_VK_SUCCESS(err);
20949 vkFreeDescriptorSets(m_device->device(), ds_pool, 3, descriptor_sets);
20950 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
20951 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
20952
20953 vkFreeMemory(m_device->device(), VK_NULL_HANDLE, NULL);
20954
20955 m_errorMonitor->VerifyNotFound();
20956}
20957
Tony Barbour626994c2017-02-08 15:29:37 -070020958TEST_F(VkPositiveLayerTest, QueueSubmitSemaphoresAndLayoutTracking) {
Tony Barboure0c5cc92017-02-08 13:53:39 -070020959 TEST_DESCRIPTION("Submit multiple command buffers with chained semaphore signals and layout transitions");
Tony Barbour626994c2017-02-08 15:29:37 -070020960
20961 m_errorMonitor->ExpectSuccess();
20962
Tony Barbour1fa09702017-03-16 12:09:08 -060020963 ASSERT_NO_FATAL_FAILURE(Init());
Tony Barbour626994c2017-02-08 15:29:37 -070020964 VkCommandBuffer cmd_bufs[4];
20965 VkCommandBufferAllocateInfo alloc_info;
20966 alloc_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20967 alloc_info.pNext = NULL;
20968 alloc_info.commandBufferCount = 4;
Mike Schuchardt06304c22017-03-01 17:09:09 -070020969 alloc_info.commandPool = m_commandPool->handle();
Tony Barbour626994c2017-02-08 15:29:37 -070020970 alloc_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20971 vkAllocateCommandBuffers(m_device->device(), &alloc_info, cmd_bufs);
20972 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060020973 image.Init(128, 128, 1, VK_FORMAT_B8G8R8A8_UNORM,
Mike Weiblen62d08a32017-03-07 22:18:27 -070020974 (VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT),
20975 VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbour626994c2017-02-08 15:29:37 -070020976 ASSERT_TRUE(image.initialized());
20977 VkCommandBufferBeginInfo cb_binfo;
20978 cb_binfo.pNext = NULL;
20979 cb_binfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20980 cb_binfo.pInheritanceInfo = VK_NULL_HANDLE;
20981 cb_binfo.flags = 0;
20982 // Use 4 command buffers, each with an image layout transition, ColorAO->General->ColorAO->TransferSrc->TransferDst
20983 vkBeginCommandBuffer(cmd_bufs[0], &cb_binfo);
20984 VkImageMemoryBarrier img_barrier = {};
20985 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
20986 img_barrier.pNext = NULL;
20987 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
20988 img_barrier.dstAccessMask = VK_ACCESS_HOST_WRITE_BIT;
20989 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
20990 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
20991 img_barrier.image = image.handle();
20992 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
20993 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
20994 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
20995 img_barrier.subresourceRange.baseArrayLayer = 0;
20996 img_barrier.subresourceRange.baseMipLevel = 0;
20997 img_barrier.subresourceRange.layerCount = 1;
20998 img_barrier.subresourceRange.levelCount = 1;
20999 vkCmdPipelineBarrier(cmd_bufs[0], VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 0, nullptr, 0, nullptr, 1,
21000 &img_barrier);
21001 vkEndCommandBuffer(cmd_bufs[0]);
21002 vkBeginCommandBuffer(cmd_bufs[1], &cb_binfo);
21003 img_barrier.oldLayout = VK_IMAGE_LAYOUT_GENERAL;
21004 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
21005 vkCmdPipelineBarrier(cmd_bufs[1], VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 0, nullptr, 0, nullptr, 1,
21006 &img_barrier);
21007 vkEndCommandBuffer(cmd_bufs[1]);
21008 vkBeginCommandBuffer(cmd_bufs[2], &cb_binfo);
21009 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
21010 img_barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
21011 vkCmdPipelineBarrier(cmd_bufs[2], VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 0, nullptr, 0, nullptr, 1,
21012 &img_barrier);
21013 vkEndCommandBuffer(cmd_bufs[2]);
21014 vkBeginCommandBuffer(cmd_bufs[3], &cb_binfo);
21015 img_barrier.oldLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
21016 img_barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
21017 vkCmdPipelineBarrier(cmd_bufs[3], VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 0, nullptr, 0, nullptr, 1,
21018 &img_barrier);
21019 vkEndCommandBuffer(cmd_bufs[3]);
21020
21021 // Submit 4 command buffers in 3 submits, with submits 2 and 3 waiting for semaphores from submits 1 and 2
21022 VkSemaphore semaphore1, semaphore2;
21023 VkSemaphoreCreateInfo semaphore_create_info{};
21024 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
21025 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore1);
21026 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore2);
21027 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
21028 VkSubmitInfo submit_info[3];
21029 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21030 submit_info[0].pNext = nullptr;
21031 submit_info[0].commandBufferCount = 1;
21032 submit_info[0].pCommandBuffers = &cmd_bufs[0];
21033 submit_info[0].signalSemaphoreCount = 1;
21034 submit_info[0].pSignalSemaphores = &semaphore1;
21035 submit_info[0].waitSemaphoreCount = 0;
21036 submit_info[0].pWaitDstStageMask = nullptr;
21037 submit_info[0].pWaitDstStageMask = flags;
21038 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21039 submit_info[1].pNext = nullptr;
21040 submit_info[1].commandBufferCount = 1;
21041 submit_info[1].pCommandBuffers = &cmd_bufs[1];
21042 submit_info[1].waitSemaphoreCount = 1;
21043 submit_info[1].pWaitSemaphores = &semaphore1;
21044 submit_info[1].signalSemaphoreCount = 1;
21045 submit_info[1].pSignalSemaphores = &semaphore2;
21046 submit_info[1].pWaitDstStageMask = flags;
21047 submit_info[2].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21048 submit_info[2].pNext = nullptr;
21049 submit_info[2].commandBufferCount = 2;
21050 submit_info[2].pCommandBuffers = &cmd_bufs[2];
21051 submit_info[2].waitSemaphoreCount = 1;
21052 submit_info[2].pWaitSemaphores = &semaphore2;
21053 submit_info[2].signalSemaphoreCount = 0;
21054 submit_info[2].pSignalSemaphores = nullptr;
21055 submit_info[2].pWaitDstStageMask = flags;
21056 vkQueueSubmit(m_device->m_queue, 3, submit_info, VK_NULL_HANDLE);
21057 vkQueueWaitIdle(m_device->m_queue);
21058
21059 vkDestroySemaphore(m_device->device(), semaphore1, NULL);
21060 vkDestroySemaphore(m_device->device(), semaphore2, NULL);
21061 m_errorMonitor->VerifyNotFound();
21062}
21063
Tobin Ehlis953e8392016-11-17 10:54:13 -070021064TEST_F(VkPositiveLayerTest, DynamicOffsetWithInactiveBinding) {
21065 // Create a descriptorSet w/ dynamic descriptors where 1 binding is inactive
21066 // We previously had a bug where dynamic offset of inactive bindings was still being used
21067 VkResult err;
21068 m_errorMonitor->ExpectSuccess();
21069
Tony Barbour1fa09702017-03-16 12:09:08 -060021070 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis953e8392016-11-17 10:54:13 -070021071 ASSERT_NO_FATAL_FAILURE(InitViewport());
21072 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21073
21074 VkDescriptorPoolSize ds_type_count = {};
21075 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
21076 ds_type_count.descriptorCount = 3;
21077
21078 VkDescriptorPoolCreateInfo ds_pool_ci = {};
21079 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
21080 ds_pool_ci.pNext = NULL;
21081 ds_pool_ci.maxSets = 1;
21082 ds_pool_ci.poolSizeCount = 1;
21083 ds_pool_ci.pPoolSizes = &ds_type_count;
21084
21085 VkDescriptorPool ds_pool;
21086 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
21087 ASSERT_VK_SUCCESS(err);
21088
21089 const uint32_t BINDING_COUNT = 3;
21090 VkDescriptorSetLayoutBinding dsl_binding[BINDING_COUNT] = {};
Tobin Ehlis0050fba2016-11-30 10:22:02 -070021091 dsl_binding[0].binding = 2;
Tobin Ehlis953e8392016-11-17 10:54:13 -070021092 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
21093 dsl_binding[0].descriptorCount = 1;
21094 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
21095 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis0050fba2016-11-30 10:22:02 -070021096 dsl_binding[1].binding = 0;
Tobin Ehlis953e8392016-11-17 10:54:13 -070021097 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
21098 dsl_binding[1].descriptorCount = 1;
21099 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
21100 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis0050fba2016-11-30 10:22:02 -070021101 dsl_binding[2].binding = 1;
Tobin Ehlis953e8392016-11-17 10:54:13 -070021102 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
21103 dsl_binding[2].descriptorCount = 1;
21104 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
21105 dsl_binding[2].pImmutableSamplers = NULL;
21106
21107 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
21108 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
21109 ds_layout_ci.pNext = NULL;
21110 ds_layout_ci.bindingCount = BINDING_COUNT;
21111 ds_layout_ci.pBindings = dsl_binding;
21112 VkDescriptorSetLayout ds_layout;
21113 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
21114 ASSERT_VK_SUCCESS(err);
21115
21116 VkDescriptorSet descriptor_set;
21117 VkDescriptorSetAllocateInfo alloc_info = {};
21118 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
21119 alloc_info.descriptorSetCount = 1;
21120 alloc_info.descriptorPool = ds_pool;
21121 alloc_info.pSetLayouts = &ds_layout;
21122 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
21123 ASSERT_VK_SUCCESS(err);
21124
21125 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
21126 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
21127 pipeline_layout_ci.pNext = NULL;
21128 pipeline_layout_ci.setLayoutCount = 1;
21129 pipeline_layout_ci.pSetLayouts = &ds_layout;
21130
21131 VkPipelineLayout pipeline_layout;
21132 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
21133 ASSERT_VK_SUCCESS(err);
21134
21135 // Create two buffers to update the descriptors with
21136 // The first will be 2k and used for bindings 0 & 1, the second is 1k for binding 2
21137 uint32_t qfi = 0;
21138 VkBufferCreateInfo buffCI = {};
21139 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
21140 buffCI.size = 2048;
21141 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
21142 buffCI.queueFamilyIndexCount = 1;
21143 buffCI.pQueueFamilyIndices = &qfi;
21144
21145 VkBuffer dyub1;
21146 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub1);
21147 ASSERT_VK_SUCCESS(err);
21148 // buffer2
21149 buffCI.size = 1024;
21150 VkBuffer dyub2;
21151 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub2);
21152 ASSERT_VK_SUCCESS(err);
21153 // Allocate memory and bind to buffers
21154 VkMemoryAllocateInfo mem_alloc[2] = {};
21155 mem_alloc[0].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
21156 mem_alloc[0].pNext = NULL;
21157 mem_alloc[0].memoryTypeIndex = 0;
21158 mem_alloc[1].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
21159 mem_alloc[1].pNext = NULL;
21160 mem_alloc[1].memoryTypeIndex = 0;
21161
21162 VkMemoryRequirements mem_reqs1;
21163 vkGetBufferMemoryRequirements(m_device->device(), dyub1, &mem_reqs1);
21164 VkMemoryRequirements mem_reqs2;
21165 vkGetBufferMemoryRequirements(m_device->device(), dyub2, &mem_reqs2);
21166 mem_alloc[0].allocationSize = mem_reqs1.size;
21167 bool pass = m_device->phy().set_memory_type(mem_reqs1.memoryTypeBits, &mem_alloc[0], 0);
21168 mem_alloc[1].allocationSize = mem_reqs2.size;
21169 pass &= m_device->phy().set_memory_type(mem_reqs2.memoryTypeBits, &mem_alloc[1], 0);
21170 if (!pass) {
21171 vkDestroyBuffer(m_device->device(), dyub1, NULL);
21172 vkDestroyBuffer(m_device->device(), dyub2, NULL);
21173 return;
21174 }
21175
21176 VkDeviceMemory mem1;
21177 err = vkAllocateMemory(m_device->device(), &mem_alloc[0], NULL, &mem1);
21178 ASSERT_VK_SUCCESS(err);
21179 err = vkBindBufferMemory(m_device->device(), dyub1, mem1, 0);
21180 ASSERT_VK_SUCCESS(err);
21181 VkDeviceMemory mem2;
21182 err = vkAllocateMemory(m_device->device(), &mem_alloc[1], NULL, &mem2);
21183 ASSERT_VK_SUCCESS(err);
21184 err = vkBindBufferMemory(m_device->device(), dyub2, mem2, 0);
21185 ASSERT_VK_SUCCESS(err);
21186 // Update descriptors
21187 VkDescriptorBufferInfo buff_info[BINDING_COUNT] = {};
21188 buff_info[0].buffer = dyub1;
21189 buff_info[0].offset = 0;
21190 buff_info[0].range = 256;
21191 buff_info[1].buffer = dyub1;
21192 buff_info[1].offset = 256;
21193 buff_info[1].range = 512;
21194 buff_info[2].buffer = dyub2;
21195 buff_info[2].offset = 0;
21196 buff_info[2].range = 512;
21197
21198 VkWriteDescriptorSet descriptor_write;
21199 memset(&descriptor_write, 0, sizeof(descriptor_write));
21200 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
21201 descriptor_write.dstSet = descriptor_set;
21202 descriptor_write.dstBinding = 0;
21203 descriptor_write.descriptorCount = BINDING_COUNT;
21204 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
21205 descriptor_write.pBufferInfo = buff_info;
21206
21207 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
21208
Tony Barbour552f6c02016-12-21 14:34:07 -070021209 m_commandBuffer->BeginCommandBuffer();
21210 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis953e8392016-11-17 10:54:13 -070021211
21212 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021213 char const *vsSource =
21214 "#version 450\n"
21215 "\n"
21216 "out gl_PerVertex { \n"
21217 " vec4 gl_Position;\n"
21218 "};\n"
21219 "void main(){\n"
21220 " gl_Position = vec4(1);\n"
21221 "}\n";
21222 char const *fsSource =
21223 "#version 450\n"
21224 "\n"
21225 "layout(location=0) out vec4 x;\n"
21226 "layout(set=0) layout(binding=0) uniform foo1 { int x; int y; } bar1;\n"
21227 "layout(set=0) layout(binding=2) uniform foo2 { int x; int y; } bar2;\n"
21228 "void main(){\n"
21229 " x = vec4(bar1.y) + vec4(bar2.y);\n"
21230 "}\n";
Tobin Ehlis953e8392016-11-17 10:54:13 -070021231 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21232 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21233 VkPipelineObj pipe(m_device);
21234 pipe.SetViewport(m_viewports);
21235 pipe.SetScissor(m_scissors);
21236 pipe.AddShader(&vs);
21237 pipe.AddShader(&fs);
21238 pipe.AddColorAttachment();
21239 pipe.CreateVKPipeline(pipeline_layout, renderPass());
21240
21241 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
21242 // This update should succeed, but offset of inactive binding 1 oversteps binding 2 buffer size
21243 // we used to have a bug in this case.
21244 uint32_t dyn_off[BINDING_COUNT] = {0, 1024, 256};
21245 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
21246 &descriptor_set, BINDING_COUNT, dyn_off);
21247 Draw(1, 0, 0, 0);
21248 m_errorMonitor->VerifyNotFound();
21249
21250 vkDestroyBuffer(m_device->device(), dyub1, NULL);
21251 vkDestroyBuffer(m_device->device(), dyub2, NULL);
21252 vkFreeMemory(m_device->device(), mem1, NULL);
21253 vkFreeMemory(m_device->device(), mem2, NULL);
21254
21255 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
21256 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
21257 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
21258}
21259
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021260TEST_F(VkPositiveLayerTest, NonCoherentMemoryMapping) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021261 TEST_DESCRIPTION(
21262 "Ensure that validations handling of non-coherent memory "
21263 "mapping while using VK_WHOLE_SIZE does not cause access "
21264 "violations");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021265 VkResult err;
21266 uint8_t *pData;
Tony Barbour1fa09702017-03-16 12:09:08 -060021267 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021268
21269 VkDeviceMemory mem;
21270 VkMemoryRequirements mem_reqs;
21271 mem_reqs.memoryTypeBits = 0xFFFFFFFF;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070021272 const VkDeviceSize atom_size = m_device->props.limits.nonCoherentAtomSize;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021273 VkMemoryAllocateInfo alloc_info = {};
21274 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
21275 alloc_info.pNext = NULL;
21276 alloc_info.memoryTypeIndex = 0;
21277
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070021278 static const VkDeviceSize allocation_size = 32 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021279 alloc_info.allocationSize = allocation_size;
21280
21281 // Find a memory configurations WITHOUT a COHERENT bit, otherwise exit
21282 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 -070021283 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021284 if (!pass) {
21285 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021286 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
21287 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021288 if (!pass) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021289 pass = m_device->phy().set_memory_type(
21290 mem_reqs.memoryTypeBits, &alloc_info,
21291 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT | VK_MEMORY_PROPERTY_HOST_CACHED_BIT,
21292 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021293 if (!pass) {
21294 return;
21295 }
21296 }
21297 }
21298
21299 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
21300 ASSERT_VK_SUCCESS(err);
21301
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070021302 // Map/Flush/Invalidate using WHOLE_SIZE and zero offsets and entire mapped range
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021303 m_errorMonitor->ExpectSuccess();
21304 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
21305 ASSERT_VK_SUCCESS(err);
21306 VkMappedMemoryRange mmr = {};
21307 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
21308 mmr.memory = mem;
21309 mmr.offset = 0;
21310 mmr.size = VK_WHOLE_SIZE;
21311 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
21312 ASSERT_VK_SUCCESS(err);
21313 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
21314 ASSERT_VK_SUCCESS(err);
21315 m_errorMonitor->VerifyNotFound();
21316 vkUnmapMemory(m_device->device(), mem);
21317
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070021318 // Map/Flush/Invalidate using WHOLE_SIZE and an offset and entire mapped range
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021319 m_errorMonitor->ExpectSuccess();
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070021320 err = vkMapMemory(m_device->device(), mem, 5 * atom_size, VK_WHOLE_SIZE, 0, (void **)&pData);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021321 ASSERT_VK_SUCCESS(err);
21322 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
21323 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070021324 mmr.offset = 6 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021325 mmr.size = VK_WHOLE_SIZE;
21326 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
21327 ASSERT_VK_SUCCESS(err);
21328 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
21329 ASSERT_VK_SUCCESS(err);
21330 m_errorMonitor->VerifyNotFound();
21331 vkUnmapMemory(m_device->device(), mem);
21332
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070021333 // Map with offset and size
21334 // Flush/Invalidate subrange of mapped area with offset and size
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021335 m_errorMonitor->ExpectSuccess();
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070021336 err = vkMapMemory(m_device->device(), mem, 3 * atom_size, 9 * atom_size, 0, (void **)&pData);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021337 ASSERT_VK_SUCCESS(err);
21338 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
21339 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070021340 mmr.offset = 4 * atom_size;
21341 mmr.size = 2 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021342 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
21343 ASSERT_VK_SUCCESS(err);
21344 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
21345 ASSERT_VK_SUCCESS(err);
21346 m_errorMonitor->VerifyNotFound();
21347 vkUnmapMemory(m_device->device(), mem);
21348
21349 // Map without offset and flush WHOLE_SIZE with two separate offsets
21350 m_errorMonitor->ExpectSuccess();
21351 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
21352 ASSERT_VK_SUCCESS(err);
21353 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
21354 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070021355 mmr.offset = allocation_size - (4 * atom_size);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021356 mmr.size = VK_WHOLE_SIZE;
21357 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
21358 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070021359 mmr.offset = allocation_size - (6 * atom_size);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021360 mmr.size = VK_WHOLE_SIZE;
21361 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
21362 ASSERT_VK_SUCCESS(err);
21363 m_errorMonitor->VerifyNotFound();
21364 vkUnmapMemory(m_device->device(), mem);
21365
21366 vkFreeMemory(m_device->device(), mem, NULL);
21367}
21368
21369// This is a positive test. We used to expect error in this case but spec now allows it
21370TEST_F(VkPositiveLayerTest, ResetUnsignaledFence) {
21371 m_errorMonitor->ExpectSuccess();
21372 vk_testing::Fence testFence;
21373 VkFenceCreateInfo fenceInfo = {};
21374 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
21375 fenceInfo.pNext = NULL;
21376
Tony Barbour1fa09702017-03-16 12:09:08 -060021377 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021378 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021379 VkFence fences[1] = {testFence.handle()};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021380 VkResult result = vkResetFences(m_device->device(), 1, fences);
21381 ASSERT_VK_SUCCESS(result);
21382
21383 m_errorMonitor->VerifyNotFound();
21384}
21385
21386TEST_F(VkPositiveLayerTest, CommandBufferSimultaneousUseSync) {
21387 m_errorMonitor->ExpectSuccess();
21388
Tony Barbour1fa09702017-03-16 12:09:08 -060021389 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021390 VkResult err;
21391
21392 // Record (empty!) command buffer that can be submitted multiple times
21393 // simultaneously.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021394 VkCommandBufferBeginInfo cbbi = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
21395 VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021396 m_commandBuffer->BeginCommandBuffer(&cbbi);
21397 m_commandBuffer->EndCommandBuffer();
21398
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021399 VkFenceCreateInfo fci = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021400 VkFence fence;
21401 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
21402 ASSERT_VK_SUCCESS(err);
21403
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021404 VkSemaphoreCreateInfo sci = {VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021405 VkSemaphore s1, s2;
21406 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s1);
21407 ASSERT_VK_SUCCESS(err);
21408 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s2);
21409 ASSERT_VK_SUCCESS(err);
21410
21411 // Submit CB once signaling s1, with fence so we can roll forward to its retirement.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021412 VkSubmitInfo si = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &m_commandBuffer->handle(), 1, &s1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021413 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
21414 ASSERT_VK_SUCCESS(err);
21415
21416 // Submit CB again, signaling s2.
21417 si.pSignalSemaphores = &s2;
21418 err = vkQueueSubmit(m_device->m_queue, 1, &si, VK_NULL_HANDLE);
21419 ASSERT_VK_SUCCESS(err);
21420
21421 // Wait for fence.
21422 err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
21423 ASSERT_VK_SUCCESS(err);
21424
21425 // CB is still in flight from second submission, but semaphore s1 is no
21426 // longer in flight. delete it.
21427 vkDestroySemaphore(m_device->device(), s1, nullptr);
21428
21429 m_errorMonitor->VerifyNotFound();
21430
21431 // Force device idle and clean up remaining objects
21432 vkDeviceWaitIdle(m_device->device());
21433 vkDestroySemaphore(m_device->device(), s2, nullptr);
21434 vkDestroyFence(m_device->device(), fence, nullptr);
21435}
21436
21437TEST_F(VkPositiveLayerTest, FenceCreateSignaledWaitHandling) {
21438 m_errorMonitor->ExpectSuccess();
21439
Tony Barbour1fa09702017-03-16 12:09:08 -060021440 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021441 VkResult err;
21442
21443 // A fence created signaled
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021444 VkFenceCreateInfo fci1 = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, VK_FENCE_CREATE_SIGNALED_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021445 VkFence f1;
21446 err = vkCreateFence(m_device->device(), &fci1, nullptr, &f1);
21447 ASSERT_VK_SUCCESS(err);
21448
21449 // A fence created not
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021450 VkFenceCreateInfo fci2 = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021451 VkFence f2;
21452 err = vkCreateFence(m_device->device(), &fci2, nullptr, &f2);
21453 ASSERT_VK_SUCCESS(err);
21454
21455 // Submit the unsignaled fence
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021456 VkSubmitInfo si = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 0, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021457 err = vkQueueSubmit(m_device->m_queue, 1, &si, f2);
21458
21459 // Wait on both fences, with signaled first.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021460 VkFence fences[] = {f1, f2};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021461 vkWaitForFences(m_device->device(), 2, fences, VK_TRUE, UINT64_MAX);
21462
21463 // Should have both retired!
21464 vkDestroyFence(m_device->device(), f1, nullptr);
21465 vkDestroyFence(m_device->device(), f2, nullptr);
21466
21467 m_errorMonitor->VerifyNotFound();
21468}
21469
21470TEST_F(VkPositiveLayerTest, ValidUsage) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021471 TEST_DESCRIPTION(
21472 "Verify that creating an image view from an image with valid usage "
21473 "doesn't generate validation errors");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021474
Tony Barbour1fa09702017-03-16 12:09:08 -060021475 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021476
21477 m_errorMonitor->ExpectSuccess();
21478 // Verify that we can create a view with usage INPUT_ATTACHMENT
21479 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060021480 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 -060021481 ASSERT_TRUE(image.initialized());
21482 VkImageView imageView;
21483 VkImageViewCreateInfo ivci = {};
21484 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
21485 ivci.image = image.handle();
21486 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
21487 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
21488 ivci.subresourceRange.layerCount = 1;
21489 ivci.subresourceRange.baseMipLevel = 0;
21490 ivci.subresourceRange.levelCount = 1;
21491 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
21492
21493 vkCreateImageView(m_device->device(), &ivci, NULL, &imageView);
21494 m_errorMonitor->VerifyNotFound();
21495 vkDestroyImageView(m_device->device(), imageView, NULL);
21496}
21497
21498// This is a positive test. No failures are expected.
21499TEST_F(VkPositiveLayerTest, BindSparse) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021500 TEST_DESCRIPTION(
21501 "Bind 2 memory ranges to one image using vkQueueBindSparse, destroy the image"
21502 "and then free the memory");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021503
Tony Barbour1fa09702017-03-16 12:09:08 -060021504 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021505
21506 auto index = m_device->graphics_queue_node_index_;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021507 if (!(m_device->queue_props[index].queueFlags & VK_QUEUE_SPARSE_BINDING_BIT)) return;
Tony Barbour623721f2017-03-24 15:00:21 -060021508 if (!m_device->phy().features().sparseBinding) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021509
21510 m_errorMonitor->ExpectSuccess();
21511
21512 VkImage image;
21513 VkImageCreateInfo image_create_info = {};
21514 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
21515 image_create_info.pNext = NULL;
21516 image_create_info.imageType = VK_IMAGE_TYPE_2D;
21517 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
21518 image_create_info.extent.width = 64;
21519 image_create_info.extent.height = 64;
21520 image_create_info.extent.depth = 1;
21521 image_create_info.mipLevels = 1;
21522 image_create_info.arrayLayers = 1;
21523 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
21524 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
21525 image_create_info.usage = VK_IMAGE_USAGE_STORAGE_BIT;
21526 image_create_info.flags = VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
21527 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
21528 ASSERT_VK_SUCCESS(err);
21529
21530 VkMemoryRequirements memory_reqs;
21531 VkDeviceMemory memory_one, memory_two;
21532 bool pass;
21533 VkMemoryAllocateInfo memory_info = {};
21534 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
21535 memory_info.pNext = NULL;
21536 memory_info.allocationSize = 0;
21537 memory_info.memoryTypeIndex = 0;
21538 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
21539 // Find an image big enough to allow sparse mapping of 2 memory regions
21540 // Increase the image size until it is at least twice the
21541 // size of the required alignment, to ensure we can bind both
21542 // allocated memory blocks to the image on aligned offsets.
21543 while (memory_reqs.size < (memory_reqs.alignment * 2)) {
21544 vkDestroyImage(m_device->device(), image, nullptr);
21545 image_create_info.extent.width *= 2;
21546 image_create_info.extent.height *= 2;
21547 err = vkCreateImage(m_device->device(), &image_create_info, nullptr, &image);
21548 ASSERT_VK_SUCCESS(err);
21549 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
21550 }
21551 // Allocate 2 memory regions of minimum alignment size, bind one at 0, the other
21552 // at the end of the first
21553 memory_info.allocationSize = memory_reqs.alignment;
21554 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
21555 ASSERT_TRUE(pass);
21556 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_one);
21557 ASSERT_VK_SUCCESS(err);
21558 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_two);
21559 ASSERT_VK_SUCCESS(err);
21560 VkSparseMemoryBind binds[2];
21561 binds[0].flags = 0;
21562 binds[0].memory = memory_one;
21563 binds[0].memoryOffset = 0;
21564 binds[0].resourceOffset = 0;
21565 binds[0].size = memory_info.allocationSize;
21566 binds[1].flags = 0;
21567 binds[1].memory = memory_two;
21568 binds[1].memoryOffset = 0;
21569 binds[1].resourceOffset = memory_info.allocationSize;
21570 binds[1].size = memory_info.allocationSize;
21571
21572 VkSparseImageOpaqueMemoryBindInfo opaqueBindInfo;
21573 opaqueBindInfo.image = image;
21574 opaqueBindInfo.bindCount = 2;
21575 opaqueBindInfo.pBinds = binds;
21576
21577 VkFence fence = VK_NULL_HANDLE;
21578 VkBindSparseInfo bindSparseInfo = {};
21579 bindSparseInfo.sType = VK_STRUCTURE_TYPE_BIND_SPARSE_INFO;
21580 bindSparseInfo.imageOpaqueBindCount = 1;
21581 bindSparseInfo.pImageOpaqueBinds = &opaqueBindInfo;
21582
21583 vkQueueBindSparse(m_device->m_queue, 1, &bindSparseInfo, fence);
21584 vkQueueWaitIdle(m_device->m_queue);
21585 vkDestroyImage(m_device->device(), image, NULL);
21586 vkFreeMemory(m_device->device(), memory_one, NULL);
21587 vkFreeMemory(m_device->device(), memory_two, NULL);
21588 m_errorMonitor->VerifyNotFound();
21589}
21590
21591TEST_F(VkPositiveLayerTest, RenderPassInitialLayoutUndefined) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021592 TEST_DESCRIPTION(
21593 "Ensure that CmdBeginRenderPass with an attachment's "
21594 "initialLayout of VK_IMAGE_LAYOUT_UNDEFINED works when "
21595 "the command buffer has prior knowledge of that "
21596 "attachment's layout.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021597
21598 m_errorMonitor->ExpectSuccess();
21599
Tony Barbour1fa09702017-03-16 12:09:08 -060021600 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021601
21602 // A renderpass with one color attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021603 VkAttachmentDescription attachment = {0,
21604 VK_FORMAT_R8G8B8A8_UNORM,
21605 VK_SAMPLE_COUNT_1_BIT,
21606 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
21607 VK_ATTACHMENT_STORE_OP_STORE,
21608 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
21609 VK_ATTACHMENT_STORE_OP_DONT_CARE,
21610 VK_IMAGE_LAYOUT_UNDEFINED,
21611 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021612
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021613 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021614
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021615 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021616
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021617 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021618
21619 VkRenderPass rp;
21620 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
21621 ASSERT_VK_SUCCESS(err);
21622
21623 // A compatible framebuffer.
21624 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060021625 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 -060021626 ASSERT_TRUE(image.initialized());
21627
21628 VkImageViewCreateInfo ivci = {
21629 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
21630 nullptr,
21631 0,
21632 image.handle(),
21633 VK_IMAGE_VIEW_TYPE_2D,
21634 VK_FORMAT_R8G8B8A8_UNORM,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021635 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
21636 VK_COMPONENT_SWIZZLE_IDENTITY},
21637 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021638 };
21639 VkImageView view;
21640 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
21641 ASSERT_VK_SUCCESS(err);
21642
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021643 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021644 VkFramebuffer fb;
21645 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
21646 ASSERT_VK_SUCCESS(err);
21647
21648 // Record a single command buffer which uses this renderpass twice. The
21649 // bug is triggered at the beginning of the second renderpass, when the
21650 // command buffer already has a layout recorded for the attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021651 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 -070021652 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021653 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
21654 vkCmdEndRenderPass(m_commandBuffer->handle());
21655 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
21656
21657 m_errorMonitor->VerifyNotFound();
21658
21659 vkCmdEndRenderPass(m_commandBuffer->handle());
Tony Barbour552f6c02016-12-21 14:34:07 -070021660 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021661
21662 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
21663 vkDestroyRenderPass(m_device->device(), rp, nullptr);
21664 vkDestroyImageView(m_device->device(), view, nullptr);
21665}
21666
21667TEST_F(VkPositiveLayerTest, FramebufferBindingDestroyCommandPool) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021668 TEST_DESCRIPTION(
21669 "This test should pass. Create a Framebuffer and "
21670 "command buffer, bind them together, then destroy "
21671 "command pool and framebuffer and verify there are no "
21672 "errors.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021673
21674 m_errorMonitor->ExpectSuccess();
21675
Tony Barbour1fa09702017-03-16 12:09:08 -060021676 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021677
21678 // A renderpass with one color attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021679 VkAttachmentDescription attachment = {0,
21680 VK_FORMAT_R8G8B8A8_UNORM,
21681 VK_SAMPLE_COUNT_1_BIT,
21682 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
21683 VK_ATTACHMENT_STORE_OP_STORE,
21684 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
21685 VK_ATTACHMENT_STORE_OP_DONT_CARE,
21686 VK_IMAGE_LAYOUT_UNDEFINED,
21687 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021688
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021689 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021690
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021691 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021692
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021693 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021694
21695 VkRenderPass rp;
21696 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
21697 ASSERT_VK_SUCCESS(err);
21698
21699 // A compatible framebuffer.
21700 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060021701 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 -060021702 ASSERT_TRUE(image.initialized());
21703
21704 VkImageViewCreateInfo ivci = {
21705 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
21706 nullptr,
21707 0,
21708 image.handle(),
21709 VK_IMAGE_VIEW_TYPE_2D,
21710 VK_FORMAT_R8G8B8A8_UNORM,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021711 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
21712 VK_COMPONENT_SWIZZLE_IDENTITY},
21713 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021714 };
21715 VkImageView view;
21716 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
21717 ASSERT_VK_SUCCESS(err);
21718
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021719 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021720 VkFramebuffer fb;
21721 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
21722 ASSERT_VK_SUCCESS(err);
21723
21724 // Explicitly create a command buffer to bind the FB to so that we can then
21725 // destroy the command pool in order to implicitly free command buffer
21726 VkCommandPool command_pool;
21727 VkCommandPoolCreateInfo pool_create_info{};
21728 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
21729 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
21730 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
21731 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
21732
21733 VkCommandBuffer command_buffer;
21734 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
21735 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
21736 command_buffer_allocate_info.commandPool = command_pool;
21737 command_buffer_allocate_info.commandBufferCount = 1;
21738 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
21739 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
21740
21741 // Begin our cmd buffer with renderpass using our framebuffer
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021742 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 -060021743 VkCommandBufferBeginInfo begin_info{};
21744 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21745 vkBeginCommandBuffer(command_buffer, &begin_info);
21746
21747 vkCmdBeginRenderPass(command_buffer, &rpbi, VK_SUBPASS_CONTENTS_INLINE);
21748 vkCmdEndRenderPass(command_buffer);
21749 vkEndCommandBuffer(command_buffer);
21750 vkDestroyImageView(m_device->device(), view, nullptr);
21751 // Destroy command pool to implicitly free command buffer
21752 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
21753 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
21754 vkDestroyRenderPass(m_device->device(), rp, nullptr);
21755 m_errorMonitor->VerifyNotFound();
21756}
21757
21758TEST_F(VkPositiveLayerTest, RenderPassSubpassZeroTransitionsApplied) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021759 TEST_DESCRIPTION(
21760 "Ensure that CmdBeginRenderPass applies the layout "
21761 "transitions for the first subpass");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021762
21763 m_errorMonitor->ExpectSuccess();
21764
Tony Barbour1fa09702017-03-16 12:09:08 -060021765 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021766
21767 // A renderpass with one color attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021768 VkAttachmentDescription attachment = {0,
21769 VK_FORMAT_R8G8B8A8_UNORM,
21770 VK_SAMPLE_COUNT_1_BIT,
21771 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
21772 VK_ATTACHMENT_STORE_OP_STORE,
21773 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
21774 VK_ATTACHMENT_STORE_OP_DONT_CARE,
21775 VK_IMAGE_LAYOUT_UNDEFINED,
21776 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021777
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021778 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021779
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021780 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021781
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021782 VkSubpassDependency dep = {0,
21783 0,
21784 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
21785 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
21786 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
21787 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
21788 VK_DEPENDENCY_BY_REGION_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021789
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021790 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021791
21792 VkResult err;
21793 VkRenderPass rp;
21794 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
21795 ASSERT_VK_SUCCESS(err);
21796
21797 // A compatible framebuffer.
21798 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060021799 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 -060021800 ASSERT_TRUE(image.initialized());
21801
21802 VkImageViewCreateInfo ivci = {
21803 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
21804 nullptr,
21805 0,
21806 image.handle(),
21807 VK_IMAGE_VIEW_TYPE_2D,
21808 VK_FORMAT_R8G8B8A8_UNORM,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021809 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
21810 VK_COMPONENT_SWIZZLE_IDENTITY},
21811 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021812 };
21813 VkImageView view;
21814 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
21815 ASSERT_VK_SUCCESS(err);
21816
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021817 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021818 VkFramebuffer fb;
21819 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
21820 ASSERT_VK_SUCCESS(err);
21821
21822 // Record a single command buffer which issues a pipeline barrier w/
21823 // image memory barrier for the attachment. This detects the previously
21824 // missing tracking of the subpass layout by throwing a validation error
21825 // if it doesn't occur.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021826 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 -070021827 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021828 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
21829
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021830 VkImageMemoryBarrier imb = {VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
21831 nullptr,
21832 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
21833 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
21834 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
21835 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
21836 VK_QUEUE_FAMILY_IGNORED,
21837 VK_QUEUE_FAMILY_IGNORED,
21838 image.handle(),
21839 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1}};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021840 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021841 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
21842 &imb);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021843
21844 vkCmdEndRenderPass(m_commandBuffer->handle());
21845 m_errorMonitor->VerifyNotFound();
Tony Barbour552f6c02016-12-21 14:34:07 -070021846 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021847
21848 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
21849 vkDestroyRenderPass(m_device->device(), rp, nullptr);
21850 vkDestroyImageView(m_device->device(), view, nullptr);
21851}
21852
21853TEST_F(VkPositiveLayerTest, DepthStencilLayoutTransitionForDepthOnlyImageview) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021854 TEST_DESCRIPTION(
21855 "Validate that when an imageView of a depth/stencil image "
21856 "is used as a depth/stencil framebuffer attachment, the "
21857 "aspectMask is ignored and both depth and stencil image "
21858 "subresources are used.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021859
Tony Barbour1fa09702017-03-16 12:09:08 -060021860 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021861 VkFormatProperties format_properties;
21862 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_D32_SFLOAT_S8_UINT, &format_properties);
21863 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
21864 return;
21865 }
21866
21867 m_errorMonitor->ExpectSuccess();
21868
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021869 VkAttachmentDescription attachment = {0,
21870 VK_FORMAT_D32_SFLOAT_S8_UINT,
21871 VK_SAMPLE_COUNT_1_BIT,
21872 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
21873 VK_ATTACHMENT_STORE_OP_STORE,
21874 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
21875 VK_ATTACHMENT_STORE_OP_DONT_CARE,
21876 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
21877 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021878
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021879 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021880
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021881 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, &att_ref, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021882
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021883 VkSubpassDependency dep = {0,
21884 0,
21885 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
21886 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
21887 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
21888 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
21889 VK_DEPENDENCY_BY_REGION_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021890
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021891 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021892
21893 VkResult err;
21894 VkRenderPass rp;
21895 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
21896 ASSERT_VK_SUCCESS(err);
21897
21898 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060021899 image.InitNoLayout(32, 32, 1, VK_FORMAT_D32_SFLOAT_S8_UINT,
21900 0x26, // usage
21901 VK_IMAGE_TILING_OPTIMAL, 0);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021902 ASSERT_TRUE(image.initialized());
21903 image.SetLayout(0x6, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
21904
21905 VkImageViewCreateInfo ivci = {
21906 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
21907 nullptr,
21908 0,
21909 image.handle(),
21910 VK_IMAGE_VIEW_TYPE_2D,
21911 VK_FORMAT_D32_SFLOAT_S8_UINT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021912 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
21913 {0x2, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021914 };
21915 VkImageView view;
21916 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
21917 ASSERT_VK_SUCCESS(err);
21918
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021919 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021920 VkFramebuffer fb;
21921 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
21922 ASSERT_VK_SUCCESS(err);
21923
Tony Barbour552f6c02016-12-21 14:34:07 -070021924 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021925
21926 VkImageMemoryBarrier imb = {};
21927 imb.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
21928 imb.pNext = nullptr;
21929 imb.srcAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
21930 imb.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
21931 imb.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
21932 imb.newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
21933 imb.srcQueueFamilyIndex = 0;
21934 imb.dstQueueFamilyIndex = 0;
21935 imb.image = image.handle();
21936 imb.subresourceRange.aspectMask = 0x6;
21937 imb.subresourceRange.baseMipLevel = 0;
21938 imb.subresourceRange.levelCount = 0x1;
21939 imb.subresourceRange.baseArrayLayer = 0;
21940 imb.subresourceRange.layerCount = 0x1;
21941
21942 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021943 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
21944 &imb);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021945
Tony Barbour552f6c02016-12-21 14:34:07 -070021946 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021947 QueueCommandBuffer(false);
21948 m_errorMonitor->VerifyNotFound();
21949
21950 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
21951 vkDestroyRenderPass(m_device->device(), rp, nullptr);
21952 vkDestroyImageView(m_device->device(), view, nullptr);
21953}
21954
21955TEST_F(VkPositiveLayerTest, RenderPassTransitionsAttachmentUnused) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021956 TEST_DESCRIPTION(
21957 "Ensure that layout transitions work correctly without "
21958 "errors, when an attachment reference is "
21959 "VK_ATTACHMENT_UNUSED");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021960
21961 m_errorMonitor->ExpectSuccess();
21962
Tony Barbour1fa09702017-03-16 12:09:08 -060021963 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021964
21965 // A renderpass with no attachments
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021966 VkAttachmentReference att_ref = {VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021967
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021968 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021969
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021970 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 1, &subpass, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021971
21972 VkRenderPass rp;
21973 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
21974 ASSERT_VK_SUCCESS(err);
21975
21976 // A compatible framebuffer.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021977 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021978 VkFramebuffer fb;
21979 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
21980 ASSERT_VK_SUCCESS(err);
21981
21982 // Record a command buffer which just begins and ends the renderpass. The
21983 // bug manifests in BeginRenderPass.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021984 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 -070021985 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021986 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
21987 vkCmdEndRenderPass(m_commandBuffer->handle());
21988 m_errorMonitor->VerifyNotFound();
Tony Barbour552f6c02016-12-21 14:34:07 -070021989 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021990
21991 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
21992 vkDestroyRenderPass(m_device->device(), rp, nullptr);
21993}
21994
21995// This is a positive test. No errors are expected.
21996TEST_F(VkPositiveLayerTest, StencilLoadOp) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021997 TEST_DESCRIPTION(
21998 "Create a stencil-only attachment with a LOAD_OP set to "
21999 "CLEAR. stencil[Load|Store]Op used to be ignored.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022000 VkResult result = VK_SUCCESS;
Tony Barbour1fa09702017-03-16 12:09:08 -060022001 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -060022002 auto depth_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbourf887b162017-03-09 10:06:46 -070022003 if (!depth_format) {
22004 printf(" No Depth + Stencil format found. Skipped.\n");
22005 return;
22006 }
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022007 VkImageFormatProperties formatProps;
Tony Barbourf887b162017-03-09 10:06:46 -070022008 vkGetPhysicalDeviceImageFormatProperties(gpu(), depth_format, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022009 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0,
22010 &formatProps);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022011 if (formatProps.maxExtent.width < 100 || formatProps.maxExtent.height < 100) {
22012 return;
22013 }
22014
Tony Barbourf887b162017-03-09 10:06:46 -070022015 VkFormat depth_stencil_fmt = depth_format;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022016 m_depthStencil->Init(m_device, 100, 100, depth_stencil_fmt,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022017 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022018 VkAttachmentDescription att = {};
22019 VkAttachmentReference ref = {};
22020 att.format = depth_stencil_fmt;
22021 att.samples = VK_SAMPLE_COUNT_1_BIT;
22022 att.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
22023 att.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
22024 att.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
22025 att.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE;
22026 att.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
22027 att.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
22028
22029 VkClearValue clear;
22030 clear.depthStencil.depth = 1.0;
22031 clear.depthStencil.stencil = 0;
22032 ref.attachment = 0;
22033 ref.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
22034
22035 VkSubpassDescription subpass = {};
22036 subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
22037 subpass.flags = 0;
22038 subpass.inputAttachmentCount = 0;
22039 subpass.pInputAttachments = NULL;
22040 subpass.colorAttachmentCount = 0;
22041 subpass.pColorAttachments = NULL;
22042 subpass.pResolveAttachments = NULL;
22043 subpass.pDepthStencilAttachment = &ref;
22044 subpass.preserveAttachmentCount = 0;
22045 subpass.pPreserveAttachments = NULL;
22046
22047 VkRenderPass rp;
22048 VkRenderPassCreateInfo rp_info = {};
22049 rp_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
22050 rp_info.attachmentCount = 1;
22051 rp_info.pAttachments = &att;
22052 rp_info.subpassCount = 1;
22053 rp_info.pSubpasses = &subpass;
22054 result = vkCreateRenderPass(device(), &rp_info, NULL, &rp);
22055 ASSERT_VK_SUCCESS(result);
22056
22057 VkImageView *depthView = m_depthStencil->BindInfo();
22058 VkFramebufferCreateInfo fb_info = {};
22059 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
22060 fb_info.pNext = NULL;
22061 fb_info.renderPass = rp;
22062 fb_info.attachmentCount = 1;
22063 fb_info.pAttachments = depthView;
22064 fb_info.width = 100;
22065 fb_info.height = 100;
22066 fb_info.layers = 1;
22067 VkFramebuffer fb;
22068 result = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
22069 ASSERT_VK_SUCCESS(result);
22070
22071 VkRenderPassBeginInfo rpbinfo = {};
22072 rpbinfo.clearValueCount = 1;
22073 rpbinfo.pClearValues = &clear;
22074 rpbinfo.pNext = NULL;
22075 rpbinfo.renderPass = rp;
22076 rpbinfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
22077 rpbinfo.renderArea.extent.width = 100;
22078 rpbinfo.renderArea.extent.height = 100;
22079 rpbinfo.renderArea.offset.x = 0;
22080 rpbinfo.renderArea.offset.y = 0;
22081 rpbinfo.framebuffer = fb;
22082
22083 VkFence fence = {};
22084 VkFenceCreateInfo fence_ci = {};
22085 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
22086 fence_ci.pNext = nullptr;
22087 fence_ci.flags = 0;
22088 result = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fence);
22089 ASSERT_VK_SUCCESS(result);
22090
22091 m_commandBuffer->BeginCommandBuffer();
22092 m_commandBuffer->BeginRenderPass(rpbinfo);
22093 m_commandBuffer->EndRenderPass();
22094 m_commandBuffer->EndCommandBuffer();
22095 m_commandBuffer->QueueCommandBuffer(fence);
22096
22097 VkImageObj destImage(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060022098 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 -070022099 VK_IMAGE_TILING_OPTIMAL, 0);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022100 VkImageMemoryBarrier barrier = {};
22101 VkImageSubresourceRange range;
22102 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
22103 barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
22104 barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT;
22105 barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
22106 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
22107 barrier.image = m_depthStencil->handle();
22108 range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
22109 range.baseMipLevel = 0;
22110 range.levelCount = 1;
22111 range.baseArrayLayer = 0;
22112 range.layerCount = 1;
22113 barrier.subresourceRange = range;
22114 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
22115 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
22116 cmdbuf.BeginCommandBuffer();
22117 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 -070022118 &barrier);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022119 barrier.srcAccessMask = 0;
22120 barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
22121 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
22122 barrier.image = destImage.handle();
22123 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
22124 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 -070022125 &barrier);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022126 VkImageCopy cregion;
22127 cregion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
22128 cregion.srcSubresource.mipLevel = 0;
22129 cregion.srcSubresource.baseArrayLayer = 0;
22130 cregion.srcSubresource.layerCount = 1;
22131 cregion.srcOffset.x = 0;
22132 cregion.srcOffset.y = 0;
22133 cregion.srcOffset.z = 0;
22134 cregion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
22135 cregion.dstSubresource.mipLevel = 0;
22136 cregion.dstSubresource.baseArrayLayer = 0;
22137 cregion.dstSubresource.layerCount = 1;
22138 cregion.dstOffset.x = 0;
22139 cregion.dstOffset.y = 0;
22140 cregion.dstOffset.z = 0;
22141 cregion.extent.width = 100;
22142 cregion.extent.height = 100;
22143 cregion.extent.depth = 1;
22144 cmdbuf.CopyImage(m_depthStencil->handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, destImage.handle(),
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022145 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &cregion);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022146 cmdbuf.EndCommandBuffer();
22147
22148 VkSubmitInfo submit_info;
22149 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22150 submit_info.pNext = NULL;
22151 submit_info.waitSemaphoreCount = 0;
22152 submit_info.pWaitSemaphores = NULL;
22153 submit_info.pWaitDstStageMask = NULL;
22154 submit_info.commandBufferCount = 1;
22155 submit_info.pCommandBuffers = &cmdbuf.handle();
22156 submit_info.signalSemaphoreCount = 0;
22157 submit_info.pSignalSemaphores = NULL;
22158
22159 m_errorMonitor->ExpectSuccess();
22160 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
22161 m_errorMonitor->VerifyNotFound();
22162
22163 vkQueueWaitIdle(m_device->m_queue);
22164 vkDestroyFence(m_device->device(), fence, nullptr);
22165 vkDestroyRenderPass(m_device->device(), rp, nullptr);
22166 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
22167}
22168
22169// This is a positive test. No errors should be generated.
Mike Weiblene4e225d2017-03-07 23:15:43 -070022170TEST_F(VkPositiveLayerTest, BarrierLayoutToImageUsage) {
22171 TEST_DESCRIPTION("Ensure barriers' new and old VkImageLayout are compatible with their images' VkImageUsageFlags");
22172
22173 m_errorMonitor->ExpectSuccess();
22174
Tony Barbour1fa09702017-03-16 12:09:08 -060022175 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -060022176 auto depth_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbour9357d542017-03-24 15:42:21 -060022177 if (!depth_format) {
22178 printf(" No Depth + Stencil format found. Skipped.\n");
22179 return;
22180 }
Mike Weiblene4e225d2017-03-07 23:15:43 -070022181 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
22182
22183 VkImageMemoryBarrier img_barrier = {};
22184 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
22185 img_barrier.pNext = NULL;
22186 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
22187 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
22188 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
22189 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
22190 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
22191 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
22192 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
22193 img_barrier.subresourceRange.baseArrayLayer = 0;
22194 img_barrier.subresourceRange.baseMipLevel = 0;
22195 img_barrier.subresourceRange.layerCount = 1;
22196 img_barrier.subresourceRange.levelCount = 1;
22197
22198 {
22199 VkImageObj img_color(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060022200 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 -070022201 ASSERT_TRUE(img_color.initialized());
22202
22203 VkImageObj img_ds1(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060022204 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 -070022205 ASSERT_TRUE(img_ds1.initialized());
22206
22207 VkImageObj img_ds2(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060022208 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 -070022209 ASSERT_TRUE(img_ds2.initialized());
22210
22211 VkImageObj img_xfer_src(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060022212 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 -070022213 ASSERT_TRUE(img_xfer_src.initialized());
22214
22215 VkImageObj img_xfer_dst(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060022216 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 -070022217 ASSERT_TRUE(img_xfer_dst.initialized());
22218
22219 VkImageObj img_sampled(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060022220 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 -070022221 ASSERT_TRUE(img_sampled.initialized());
22222
22223 VkImageObj img_input(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060022224 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 -070022225 ASSERT_TRUE(img_input.initialized());
22226
22227 const struct {
22228 VkImageObj &image_obj;
22229 VkImageLayout old_layout;
22230 VkImageLayout new_layout;
22231 } buffer_layouts[] = {
22232 // clang-format off
22233 {img_color, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL},
22234 {img_ds1, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL},
22235 {img_ds2, VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL},
22236 {img_sampled, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL},
22237 {img_input, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL},
22238 {img_xfer_src, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL},
22239 {img_xfer_dst, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL},
22240 // clang-format on
22241 };
22242 const uint32_t layout_count = sizeof(buffer_layouts) / sizeof(buffer_layouts[0]);
22243
22244 m_commandBuffer->BeginCommandBuffer();
22245 for (uint32_t i = 0; i < layout_count; ++i) {
22246 img_barrier.image = buffer_layouts[i].image_obj.handle();
22247 const VkImageUsageFlags usage = buffer_layouts[i].image_obj.usage();
22248 img_barrier.subresourceRange.aspectMask = (usage == VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT)
22249 ? (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)
22250 : VK_IMAGE_ASPECT_COLOR_BIT;
22251
22252 img_barrier.oldLayout = buffer_layouts[i].old_layout;
22253 img_barrier.newLayout = buffer_layouts[i].new_layout;
22254 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT,
22255 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0, nullptr, 1, &img_barrier);
22256
22257 img_barrier.oldLayout = buffer_layouts[i].new_layout;
22258 img_barrier.newLayout = buffer_layouts[i].old_layout;
22259 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT,
22260 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0, nullptr, 1, &img_barrier);
22261 }
22262 m_commandBuffer->EndCommandBuffer();
22263
22264 img_barrier.oldLayout = VK_IMAGE_LAYOUT_GENERAL;
22265 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
22266 }
22267 m_errorMonitor->VerifyNotFound();
22268}
22269
22270// This is a positive test. No errors should be generated.
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022271TEST_F(VkPositiveLayerTest, WaitEventThenSet) {
22272 TEST_DESCRIPTION("Wait on a event then set it after the wait has been submitted.");
22273
22274 m_errorMonitor->ExpectSuccess();
Tony Barbour1fa09702017-03-16 12:09:08 -060022275 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022276
22277 VkEvent event;
22278 VkEventCreateInfo event_create_info{};
22279 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
22280 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
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;
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 = 1;
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_, 0, &queue);
22299
22300 {
22301 VkCommandBufferBeginInfo begin_info{};
22302 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22303 vkBeginCommandBuffer(command_buffer, &begin_info);
22304
22305 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 -070022306 nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022307 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
22308 vkEndCommandBuffer(command_buffer);
22309 }
22310 {
22311 VkSubmitInfo submit_info{};
22312 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22313 submit_info.commandBufferCount = 1;
22314 submit_info.pCommandBuffers = &command_buffer;
22315 submit_info.signalSemaphoreCount = 0;
22316 submit_info.pSignalSemaphores = nullptr;
22317 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
22318 }
22319 { vkSetEvent(m_device->device(), event); }
22320
22321 vkQueueWaitIdle(queue);
22322
22323 vkDestroyEvent(m_device->device(), event, nullptr);
22324 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
22325 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
22326
22327 m_errorMonitor->VerifyNotFound();
22328}
22329// This is a positive test. No errors should be generated.
22330TEST_F(VkPositiveLayerTest, QueryAndCopySecondaryCommandBuffers) {
22331 TEST_DESCRIPTION("Issue a query on a secondary command buffery and copy it on a primary.");
22332
Tony Barbour1fa09702017-03-16 12:09:08 -060022333 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022334 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022335
22336 m_errorMonitor->ExpectSuccess();
22337
22338 VkQueryPool query_pool;
22339 VkQueryPoolCreateInfo query_pool_create_info{};
22340 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
22341 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
22342 query_pool_create_info.queryCount = 1;
22343 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
22344
22345 VkCommandPool command_pool;
22346 VkCommandPoolCreateInfo pool_create_info{};
22347 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
22348 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
22349 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
22350 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
22351
22352 VkCommandBuffer command_buffer;
22353 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
22354 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
22355 command_buffer_allocate_info.commandPool = command_pool;
22356 command_buffer_allocate_info.commandBufferCount = 1;
22357 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
22358 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
22359
22360 VkCommandBuffer secondary_command_buffer;
22361 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
22362 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer);
22363
22364 VkQueue queue = VK_NULL_HANDLE;
22365 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
22366
22367 uint32_t qfi = 0;
22368 VkBufferCreateInfo buff_create_info = {};
22369 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
22370 buff_create_info.size = 1024;
22371 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
22372 buff_create_info.queueFamilyIndexCount = 1;
22373 buff_create_info.pQueueFamilyIndices = &qfi;
22374
22375 VkResult err;
22376 VkBuffer buffer;
22377 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
22378 ASSERT_VK_SUCCESS(err);
22379 VkMemoryAllocateInfo mem_alloc = {};
22380 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
22381 mem_alloc.pNext = NULL;
22382 mem_alloc.allocationSize = 1024;
22383 mem_alloc.memoryTypeIndex = 0;
22384
22385 VkMemoryRequirements memReqs;
22386 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
22387 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
22388 if (!pass) {
22389 vkDestroyBuffer(m_device->device(), buffer, NULL);
22390 return;
22391 }
22392
22393 VkDeviceMemory mem;
22394 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
22395 ASSERT_VK_SUCCESS(err);
22396 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
22397 ASSERT_VK_SUCCESS(err);
22398
22399 VkCommandBufferInheritanceInfo hinfo = {};
22400 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
22401 hinfo.renderPass = VK_NULL_HANDLE;
22402 hinfo.subpass = 0;
22403 hinfo.framebuffer = VK_NULL_HANDLE;
22404 hinfo.occlusionQueryEnable = VK_FALSE;
22405 hinfo.queryFlags = 0;
22406 hinfo.pipelineStatistics = 0;
22407
22408 {
22409 VkCommandBufferBeginInfo begin_info{};
22410 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22411 begin_info.pInheritanceInfo = &hinfo;
22412 vkBeginCommandBuffer(secondary_command_buffer, &begin_info);
22413
22414 vkCmdResetQueryPool(secondary_command_buffer, query_pool, 0, 1);
22415 vkCmdWriteTimestamp(secondary_command_buffer, VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
22416
22417 vkEndCommandBuffer(secondary_command_buffer);
22418
22419 begin_info.pInheritanceInfo = nullptr;
22420 vkBeginCommandBuffer(command_buffer, &begin_info);
22421
22422 vkCmdExecuteCommands(command_buffer, 1, &secondary_command_buffer);
22423 vkCmdCopyQueryPoolResults(command_buffer, query_pool, 0, 1, buffer, 0, 0, 0);
22424
22425 vkEndCommandBuffer(command_buffer);
22426 }
22427 {
22428 VkSubmitInfo submit_info{};
22429 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22430 submit_info.commandBufferCount = 1;
22431 submit_info.pCommandBuffers = &command_buffer;
22432 submit_info.signalSemaphoreCount = 0;
22433 submit_info.pSignalSemaphores = nullptr;
22434 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
22435 }
22436
22437 vkQueueWaitIdle(queue);
22438
22439 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
22440 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
22441 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &secondary_command_buffer);
22442 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
22443 vkDestroyBuffer(m_device->device(), buffer, NULL);
22444 vkFreeMemory(m_device->device(), mem, NULL);
22445
22446 m_errorMonitor->VerifyNotFound();
22447}
22448
22449// This is a positive test. No errors should be generated.
22450TEST_F(VkPositiveLayerTest, QueryAndCopyMultipleCommandBuffers) {
22451 TEST_DESCRIPTION("Issue a query and copy from it on a second command buffer.");
22452
Tony Barbour1fa09702017-03-16 12:09:08 -060022453 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022454 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022455
22456 m_errorMonitor->ExpectSuccess();
22457
22458 VkQueryPool query_pool;
22459 VkQueryPoolCreateInfo query_pool_create_info{};
22460 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
22461 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
22462 query_pool_create_info.queryCount = 1;
22463 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
22464
22465 VkCommandPool command_pool;
22466 VkCommandPoolCreateInfo pool_create_info{};
22467 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
22468 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
22469 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
22470 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
22471
22472 VkCommandBuffer command_buffer[2];
22473 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
22474 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
22475 command_buffer_allocate_info.commandPool = command_pool;
22476 command_buffer_allocate_info.commandBufferCount = 2;
22477 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
22478 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
22479
22480 VkQueue queue = VK_NULL_HANDLE;
22481 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
22482
22483 uint32_t qfi = 0;
22484 VkBufferCreateInfo buff_create_info = {};
22485 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
22486 buff_create_info.size = 1024;
22487 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
22488 buff_create_info.queueFamilyIndexCount = 1;
22489 buff_create_info.pQueueFamilyIndices = &qfi;
22490
22491 VkResult err;
22492 VkBuffer buffer;
22493 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
22494 ASSERT_VK_SUCCESS(err);
22495 VkMemoryAllocateInfo mem_alloc = {};
22496 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
22497 mem_alloc.pNext = NULL;
22498 mem_alloc.allocationSize = 1024;
22499 mem_alloc.memoryTypeIndex = 0;
22500
22501 VkMemoryRequirements memReqs;
22502 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
22503 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
22504 if (!pass) {
22505 vkDestroyBuffer(m_device->device(), buffer, NULL);
22506 return;
22507 }
22508
22509 VkDeviceMemory mem;
22510 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
22511 ASSERT_VK_SUCCESS(err);
22512 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
22513 ASSERT_VK_SUCCESS(err);
22514
22515 {
22516 VkCommandBufferBeginInfo begin_info{};
22517 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22518 vkBeginCommandBuffer(command_buffer[0], &begin_info);
22519
22520 vkCmdResetQueryPool(command_buffer[0], query_pool, 0, 1);
22521 vkCmdWriteTimestamp(command_buffer[0], VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
22522
22523 vkEndCommandBuffer(command_buffer[0]);
22524
22525 vkBeginCommandBuffer(command_buffer[1], &begin_info);
22526
22527 vkCmdCopyQueryPoolResults(command_buffer[1], query_pool, 0, 1, buffer, 0, 0, 0);
22528
22529 vkEndCommandBuffer(command_buffer[1]);
22530 }
22531 {
22532 VkSubmitInfo submit_info{};
22533 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22534 submit_info.commandBufferCount = 2;
22535 submit_info.pCommandBuffers = command_buffer;
22536 submit_info.signalSemaphoreCount = 0;
22537 submit_info.pSignalSemaphores = nullptr;
22538 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
22539 }
22540
22541 vkQueueWaitIdle(queue);
22542
22543 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
22544 vkFreeCommandBuffers(m_device->device(), command_pool, 2, command_buffer);
22545 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
22546 vkDestroyBuffer(m_device->device(), buffer, NULL);
22547 vkFreeMemory(m_device->device(), mem, NULL);
22548
22549 m_errorMonitor->VerifyNotFound();
22550}
22551
Tony Barbourc46924f2016-11-04 11:49:52 -060022552TEST_F(VkLayerTest, ResetEventThenSet) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022553 TEST_DESCRIPTION("Reset an event then set it after the reset has been submitted.");
22554
Tony Barbour1fa09702017-03-16 12:09:08 -060022555 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022556 VkEvent event;
22557 VkEventCreateInfo event_create_info{};
22558 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
22559 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
22560
22561 VkCommandPool command_pool;
22562 VkCommandPoolCreateInfo pool_create_info{};
22563 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
22564 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
22565 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
22566 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
22567
22568 VkCommandBuffer command_buffer;
22569 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
22570 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
22571 command_buffer_allocate_info.commandPool = command_pool;
22572 command_buffer_allocate_info.commandBufferCount = 1;
22573 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
22574 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
22575
22576 VkQueue queue = VK_NULL_HANDLE;
22577 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
22578
22579 {
22580 VkCommandBufferBeginInfo begin_info{};
22581 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22582 vkBeginCommandBuffer(command_buffer, &begin_info);
22583
22584 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022585 vkEndCommandBuffer(command_buffer);
22586 }
22587 {
22588 VkSubmitInfo submit_info{};
22589 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22590 submit_info.commandBufferCount = 1;
22591 submit_info.pCommandBuffers = &command_buffer;
22592 submit_info.signalSemaphoreCount = 0;
22593 submit_info.pSignalSemaphores = nullptr;
22594 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
22595 }
22596 {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022597 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
22598 "that is already in use by a "
22599 "command buffer.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022600 vkSetEvent(m_device->device(), event);
22601 m_errorMonitor->VerifyFound();
22602 }
22603
22604 vkQueueWaitIdle(queue);
22605
22606 vkDestroyEvent(m_device->device(), event, nullptr);
22607 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
22608 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
22609}
22610
22611// This is a positive test. No errors should be generated.
22612TEST_F(VkPositiveLayerTest, TwoFencesThreeFrames) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022613 TEST_DESCRIPTION(
22614 "Two command buffers with two separate fences are each "
22615 "run through a Submit & WaitForFences cycle 3 times. This "
22616 "previously revealed a bug so running this positive test "
22617 "to prevent a regression.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022618 m_errorMonitor->ExpectSuccess();
22619
Tony Barbour1fa09702017-03-16 12:09:08 -060022620 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022621 VkQueue queue = VK_NULL_HANDLE;
22622 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
22623
22624 static const uint32_t NUM_OBJECTS = 2;
22625 static const uint32_t NUM_FRAMES = 3;
22626 VkCommandBuffer cmd_buffers[NUM_OBJECTS] = {};
22627 VkFence fences[NUM_OBJECTS] = {};
22628
22629 VkCommandPool cmd_pool;
22630 VkCommandPoolCreateInfo cmd_pool_ci = {};
22631 cmd_pool_ci.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
22632 cmd_pool_ci.queueFamilyIndex = m_device->graphics_queue_node_index_;
22633 cmd_pool_ci.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
22634 VkResult err = vkCreateCommandPool(m_device->device(), &cmd_pool_ci, nullptr, &cmd_pool);
22635 ASSERT_VK_SUCCESS(err);
22636
22637 VkCommandBufferAllocateInfo cmd_buf_info = {};
22638 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
22639 cmd_buf_info.commandPool = cmd_pool;
22640 cmd_buf_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
22641 cmd_buf_info.commandBufferCount = 1;
22642
22643 VkFenceCreateInfo fence_ci = {};
22644 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
22645 fence_ci.pNext = nullptr;
22646 fence_ci.flags = 0;
22647
22648 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
22649 err = vkAllocateCommandBuffers(m_device->device(), &cmd_buf_info, &cmd_buffers[i]);
22650 ASSERT_VK_SUCCESS(err);
22651 err = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fences[i]);
22652 ASSERT_VK_SUCCESS(err);
22653 }
22654
22655 for (uint32_t frame = 0; frame < NUM_FRAMES; ++frame) {
22656 for (uint32_t obj = 0; obj < NUM_OBJECTS; ++obj) {
22657 // Create empty cmd buffer
22658 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
22659 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22660
22661 err = vkBeginCommandBuffer(cmd_buffers[obj], &cmdBufBeginDesc);
22662 ASSERT_VK_SUCCESS(err);
22663 err = vkEndCommandBuffer(cmd_buffers[obj]);
22664 ASSERT_VK_SUCCESS(err);
22665
22666 VkSubmitInfo submit_info = {};
22667 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22668 submit_info.commandBufferCount = 1;
22669 submit_info.pCommandBuffers = &cmd_buffers[obj];
22670 // Submit cmd buffer and wait for fence
22671 err = vkQueueSubmit(queue, 1, &submit_info, fences[obj]);
22672 ASSERT_VK_SUCCESS(err);
22673 err = vkWaitForFences(m_device->device(), 1, &fences[obj], VK_TRUE, UINT64_MAX);
22674 ASSERT_VK_SUCCESS(err);
22675 err = vkResetFences(m_device->device(), 1, &fences[obj]);
22676 ASSERT_VK_SUCCESS(err);
22677 }
22678 }
22679 m_errorMonitor->VerifyNotFound();
22680 vkDestroyCommandPool(m_device->device(), cmd_pool, NULL);
22681 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
22682 vkDestroyFence(m_device->device(), fences[i], nullptr);
22683 }
22684}
22685// This is a positive test. No errors should be generated.
22686TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWI) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022687 TEST_DESCRIPTION(
22688 "Two command buffers, each in a separate QueueSubmit call "
22689 "submitted on separate queues followed by a QueueWaitIdle.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022690
Tony Barbour1fa09702017-03-16 12:09:08 -060022691 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022692 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022693
22694 m_errorMonitor->ExpectSuccess();
22695
22696 VkSemaphore semaphore;
22697 VkSemaphoreCreateInfo semaphore_create_info{};
22698 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
22699 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
22700
22701 VkCommandPool command_pool;
22702 VkCommandPoolCreateInfo pool_create_info{};
22703 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
22704 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
22705 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
22706 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
22707
22708 VkCommandBuffer command_buffer[2];
22709 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
22710 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
22711 command_buffer_allocate_info.commandPool = command_pool;
22712 command_buffer_allocate_info.commandBufferCount = 2;
22713 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
22714 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
22715
22716 VkQueue queue = VK_NULL_HANDLE;
22717 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
22718
22719 {
22720 VkCommandBufferBeginInfo begin_info{};
22721 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22722 vkBeginCommandBuffer(command_buffer[0], &begin_info);
22723
22724 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 -070022725 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022726
22727 VkViewport viewport{};
22728 viewport.maxDepth = 1.0f;
22729 viewport.minDepth = 0.0f;
22730 viewport.width = 512;
22731 viewport.height = 512;
22732 viewport.x = 0;
22733 viewport.y = 0;
22734 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
22735 vkEndCommandBuffer(command_buffer[0]);
22736 }
22737 {
22738 VkCommandBufferBeginInfo begin_info{};
22739 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22740 vkBeginCommandBuffer(command_buffer[1], &begin_info);
22741
22742 VkViewport viewport{};
22743 viewport.maxDepth = 1.0f;
22744 viewport.minDepth = 0.0f;
22745 viewport.width = 512;
22746 viewport.height = 512;
22747 viewport.x = 0;
22748 viewport.y = 0;
22749 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
22750 vkEndCommandBuffer(command_buffer[1]);
22751 }
22752 {
22753 VkSubmitInfo submit_info{};
22754 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22755 submit_info.commandBufferCount = 1;
22756 submit_info.pCommandBuffers = &command_buffer[0];
22757 submit_info.signalSemaphoreCount = 1;
22758 submit_info.pSignalSemaphores = &semaphore;
22759 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
22760 }
22761 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022762 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022763 VkSubmitInfo submit_info{};
22764 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22765 submit_info.commandBufferCount = 1;
22766 submit_info.pCommandBuffers = &command_buffer[1];
22767 submit_info.waitSemaphoreCount = 1;
22768 submit_info.pWaitSemaphores = &semaphore;
22769 submit_info.pWaitDstStageMask = flags;
22770 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
22771 }
22772
22773 vkQueueWaitIdle(m_device->m_queue);
22774
22775 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
22776 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
22777 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
22778
22779 m_errorMonitor->VerifyNotFound();
22780}
22781
22782// This is a positive test. No errors should be generated.
22783TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWIFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022784 TEST_DESCRIPTION(
22785 "Two command buffers, each in a separate QueueSubmit call "
22786 "submitted on separate queues, the second having a fence"
22787 "followed by a QueueWaitIdle.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022788
Tony Barbour1fa09702017-03-16 12:09:08 -060022789 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022790 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022791
22792 m_errorMonitor->ExpectSuccess();
22793
22794 VkFence fence;
22795 VkFenceCreateInfo fence_create_info{};
22796 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
22797 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
22798
22799 VkSemaphore semaphore;
22800 VkSemaphoreCreateInfo semaphore_create_info{};
22801 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
22802 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
22803
22804 VkCommandPool command_pool;
22805 VkCommandPoolCreateInfo pool_create_info{};
22806 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
22807 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
22808 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
22809 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
22810
22811 VkCommandBuffer command_buffer[2];
22812 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
22813 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
22814 command_buffer_allocate_info.commandPool = command_pool;
22815 command_buffer_allocate_info.commandBufferCount = 2;
22816 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
22817 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
22818
22819 VkQueue queue = VK_NULL_HANDLE;
22820 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
22821
22822 {
22823 VkCommandBufferBeginInfo begin_info{};
22824 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22825 vkBeginCommandBuffer(command_buffer[0], &begin_info);
22826
22827 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 -070022828 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022829
22830 VkViewport viewport{};
22831 viewport.maxDepth = 1.0f;
22832 viewport.minDepth = 0.0f;
22833 viewport.width = 512;
22834 viewport.height = 512;
22835 viewport.x = 0;
22836 viewport.y = 0;
22837 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
22838 vkEndCommandBuffer(command_buffer[0]);
22839 }
22840 {
22841 VkCommandBufferBeginInfo begin_info{};
22842 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22843 vkBeginCommandBuffer(command_buffer[1], &begin_info);
22844
22845 VkViewport viewport{};
22846 viewport.maxDepth = 1.0f;
22847 viewport.minDepth = 0.0f;
22848 viewport.width = 512;
22849 viewport.height = 512;
22850 viewport.x = 0;
22851 viewport.y = 0;
22852 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
22853 vkEndCommandBuffer(command_buffer[1]);
22854 }
22855 {
22856 VkSubmitInfo submit_info{};
22857 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22858 submit_info.commandBufferCount = 1;
22859 submit_info.pCommandBuffers = &command_buffer[0];
22860 submit_info.signalSemaphoreCount = 1;
22861 submit_info.pSignalSemaphores = &semaphore;
22862 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
22863 }
22864 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022865 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022866 VkSubmitInfo submit_info{};
22867 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22868 submit_info.commandBufferCount = 1;
22869 submit_info.pCommandBuffers = &command_buffer[1];
22870 submit_info.waitSemaphoreCount = 1;
22871 submit_info.pWaitSemaphores = &semaphore;
22872 submit_info.pWaitDstStageMask = flags;
22873 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
22874 }
22875
22876 vkQueueWaitIdle(m_device->m_queue);
22877
22878 vkDestroyFence(m_device->device(), fence, nullptr);
22879 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
22880 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
22881 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
22882
22883 m_errorMonitor->VerifyNotFound();
22884}
22885
22886// This is a positive test. No errors should be generated.
22887TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceTwoWFF) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022888 TEST_DESCRIPTION(
22889 "Two command buffers, each in a separate QueueSubmit call "
22890 "submitted on separate queues, the second having a fence"
22891 "followed by two consecutive WaitForFences calls on the same fence.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022892
Tony Barbour1fa09702017-03-16 12:09:08 -060022893 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022894 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022895
22896 m_errorMonitor->ExpectSuccess();
22897
22898 VkFence fence;
22899 VkFenceCreateInfo fence_create_info{};
22900 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
22901 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
22902
22903 VkSemaphore semaphore;
22904 VkSemaphoreCreateInfo semaphore_create_info{};
22905 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
22906 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
22907
22908 VkCommandPool command_pool;
22909 VkCommandPoolCreateInfo pool_create_info{};
22910 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
22911 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
22912 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
22913 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
22914
22915 VkCommandBuffer command_buffer[2];
22916 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
22917 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
22918 command_buffer_allocate_info.commandPool = command_pool;
22919 command_buffer_allocate_info.commandBufferCount = 2;
22920 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
22921 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
22922
22923 VkQueue queue = VK_NULL_HANDLE;
22924 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
22925
22926 {
22927 VkCommandBufferBeginInfo begin_info{};
22928 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22929 vkBeginCommandBuffer(command_buffer[0], &begin_info);
22930
22931 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 -070022932 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022933
22934 VkViewport viewport{};
22935 viewport.maxDepth = 1.0f;
22936 viewport.minDepth = 0.0f;
22937 viewport.width = 512;
22938 viewport.height = 512;
22939 viewport.x = 0;
22940 viewport.y = 0;
22941 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
22942 vkEndCommandBuffer(command_buffer[0]);
22943 }
22944 {
22945 VkCommandBufferBeginInfo begin_info{};
22946 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22947 vkBeginCommandBuffer(command_buffer[1], &begin_info);
22948
22949 VkViewport viewport{};
22950 viewport.maxDepth = 1.0f;
22951 viewport.minDepth = 0.0f;
22952 viewport.width = 512;
22953 viewport.height = 512;
22954 viewport.x = 0;
22955 viewport.y = 0;
22956 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
22957 vkEndCommandBuffer(command_buffer[1]);
22958 }
22959 {
22960 VkSubmitInfo submit_info{};
22961 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22962 submit_info.commandBufferCount = 1;
22963 submit_info.pCommandBuffers = &command_buffer[0];
22964 submit_info.signalSemaphoreCount = 1;
22965 submit_info.pSignalSemaphores = &semaphore;
22966 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
22967 }
22968 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022969 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022970 VkSubmitInfo submit_info{};
22971 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22972 submit_info.commandBufferCount = 1;
22973 submit_info.pCommandBuffers = &command_buffer[1];
22974 submit_info.waitSemaphoreCount = 1;
22975 submit_info.pWaitSemaphores = &semaphore;
22976 submit_info.pWaitDstStageMask = flags;
22977 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
22978 }
22979
22980 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
22981 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
22982
22983 vkDestroyFence(m_device->device(), fence, nullptr);
22984 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
22985 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
22986 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
22987
22988 m_errorMonitor->VerifyNotFound();
22989}
22990
22991TEST_F(VkPositiveLayerTest, TwoQueuesEnsureCorrectRetirementWithWorkStolen) {
Tony Barbour1fa09702017-03-16 12:09:08 -060022992 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022993 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070022994 printf(" Test requires two queues, skipping\n");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022995 return;
22996 }
22997
22998 VkResult err;
22999
23000 m_errorMonitor->ExpectSuccess();
23001
23002 VkQueue q0 = m_device->m_queue;
23003 VkQueue q1 = nullptr;
23004 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &q1);
23005 ASSERT_NE(q1, nullptr);
23006
23007 // An (empty) command buffer. We must have work in the first submission --
23008 // the layer treats unfenced work differently from fenced work.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023009 VkCommandPoolCreateInfo cpci = {VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, nullptr, 0, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023010 VkCommandPool pool;
23011 err = vkCreateCommandPool(m_device->device(), &cpci, nullptr, &pool);
23012 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023013 VkCommandBufferAllocateInfo cbai = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, nullptr, pool,
23014 VK_COMMAND_BUFFER_LEVEL_PRIMARY, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023015 VkCommandBuffer cb;
23016 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &cb);
23017 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023018 VkCommandBufferBeginInfo cbbi = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023019 err = vkBeginCommandBuffer(cb, &cbbi);
23020 ASSERT_VK_SUCCESS(err);
23021 err = vkEndCommandBuffer(cb);
23022 ASSERT_VK_SUCCESS(err);
23023
23024 // A semaphore
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023025 VkSemaphoreCreateInfo sci = {VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023026 VkSemaphore s;
23027 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s);
23028 ASSERT_VK_SUCCESS(err);
23029
23030 // First submission, to q0
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023031 VkSubmitInfo s0 = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &cb, 1, &s};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023032
23033 err = vkQueueSubmit(q0, 1, &s0, VK_NULL_HANDLE);
23034 ASSERT_VK_SUCCESS(err);
23035
23036 // Second submission, to q1, waiting on s
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023037 VkFlags waitmask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; // doesn't really matter what this value is.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023038 VkSubmitInfo s1 = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 1, &s, &waitmask, 0, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023039
23040 err = vkQueueSubmit(q1, 1, &s1, VK_NULL_HANDLE);
23041 ASSERT_VK_SUCCESS(err);
23042
23043 // Wait for q0 idle
23044 err = vkQueueWaitIdle(q0);
23045 ASSERT_VK_SUCCESS(err);
23046
23047 // Command buffer should have been completed (it was on q0); reset the pool.
23048 vkFreeCommandBuffers(m_device->device(), pool, 1, &cb);
23049
23050 m_errorMonitor->VerifyNotFound();
23051
23052 // Force device completely idle and clean up resources
23053 vkDeviceWaitIdle(m_device->device());
23054 vkDestroyCommandPool(m_device->device(), pool, nullptr);
23055 vkDestroySemaphore(m_device->device(), s, nullptr);
23056}
23057
23058// This is a positive test. No errors should be generated.
23059TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023060 TEST_DESCRIPTION(
23061 "Two command buffers, each in a separate QueueSubmit call "
23062 "submitted on separate queues, the second having a fence, "
23063 "followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023064
Tony Barbour1fa09702017-03-16 12:09:08 -060023065 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023066 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023067
23068 m_errorMonitor->ExpectSuccess();
23069
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023070 VkFence fence;
23071 VkFenceCreateInfo fence_create_info{};
23072 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
23073 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
23074
23075 VkSemaphore semaphore;
23076 VkSemaphoreCreateInfo semaphore_create_info{};
23077 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
23078 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
23079
23080 VkCommandPool command_pool;
23081 VkCommandPoolCreateInfo pool_create_info{};
23082 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
23083 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
23084 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
23085 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
23086
23087 VkCommandBuffer command_buffer[2];
23088 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
23089 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
23090 command_buffer_allocate_info.commandPool = command_pool;
23091 command_buffer_allocate_info.commandBufferCount = 2;
23092 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
23093 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
23094
23095 VkQueue queue = VK_NULL_HANDLE;
23096 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
23097
23098 {
23099 VkCommandBufferBeginInfo begin_info{};
23100 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
23101 vkBeginCommandBuffer(command_buffer[0], &begin_info);
23102
23103 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 -070023104 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023105
23106 VkViewport viewport{};
23107 viewport.maxDepth = 1.0f;
23108 viewport.minDepth = 0.0f;
23109 viewport.width = 512;
23110 viewport.height = 512;
23111 viewport.x = 0;
23112 viewport.y = 0;
23113 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
23114 vkEndCommandBuffer(command_buffer[0]);
23115 }
23116 {
23117 VkCommandBufferBeginInfo begin_info{};
23118 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
23119 vkBeginCommandBuffer(command_buffer[1], &begin_info);
23120
23121 VkViewport viewport{};
23122 viewport.maxDepth = 1.0f;
23123 viewport.minDepth = 0.0f;
23124 viewport.width = 512;
23125 viewport.height = 512;
23126 viewport.x = 0;
23127 viewport.y = 0;
23128 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
23129 vkEndCommandBuffer(command_buffer[1]);
23130 }
23131 {
23132 VkSubmitInfo submit_info{};
23133 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
23134 submit_info.commandBufferCount = 1;
23135 submit_info.pCommandBuffers = &command_buffer[0];
23136 submit_info.signalSemaphoreCount = 1;
23137 submit_info.pSignalSemaphores = &semaphore;
23138 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
23139 }
23140 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023141 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023142 VkSubmitInfo submit_info{};
23143 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
23144 submit_info.commandBufferCount = 1;
23145 submit_info.pCommandBuffers = &command_buffer[1];
23146 submit_info.waitSemaphoreCount = 1;
23147 submit_info.pWaitSemaphores = &semaphore;
23148 submit_info.pWaitDstStageMask = flags;
23149 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
23150 }
23151
23152 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
23153
23154 vkDestroyFence(m_device->device(), fence, nullptr);
23155 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
23156 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
23157 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
23158
23159 m_errorMonitor->VerifyNotFound();
23160}
23161
23162// This is a positive test. No errors should be generated.
23163TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueWithSemaphoreAndOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023164 TEST_DESCRIPTION(
23165 "Two command buffers, each in a separate QueueSubmit call "
23166 "on the same queue, sharing a signal/wait semaphore, the "
23167 "second having a fence, "
23168 "followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023169
23170 m_errorMonitor->ExpectSuccess();
23171
Tony Barbour1fa09702017-03-16 12:09:08 -060023172 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023173 VkFence fence;
23174 VkFenceCreateInfo fence_create_info{};
23175 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
23176 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
23177
23178 VkSemaphore semaphore;
23179 VkSemaphoreCreateInfo semaphore_create_info{};
23180 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
23181 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
23182
23183 VkCommandPool command_pool;
23184 VkCommandPoolCreateInfo pool_create_info{};
23185 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
23186 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
23187 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
23188 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
23189
23190 VkCommandBuffer command_buffer[2];
23191 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
23192 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
23193 command_buffer_allocate_info.commandPool = command_pool;
23194 command_buffer_allocate_info.commandBufferCount = 2;
23195 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
23196 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
23197
23198 {
23199 VkCommandBufferBeginInfo begin_info{};
23200 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
23201 vkBeginCommandBuffer(command_buffer[0], &begin_info);
23202
23203 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 -070023204 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023205
23206 VkViewport viewport{};
23207 viewport.maxDepth = 1.0f;
23208 viewport.minDepth = 0.0f;
23209 viewport.width = 512;
23210 viewport.height = 512;
23211 viewport.x = 0;
23212 viewport.y = 0;
23213 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
23214 vkEndCommandBuffer(command_buffer[0]);
23215 }
23216 {
23217 VkCommandBufferBeginInfo begin_info{};
23218 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
23219 vkBeginCommandBuffer(command_buffer[1], &begin_info);
23220
23221 VkViewport viewport{};
23222 viewport.maxDepth = 1.0f;
23223 viewport.minDepth = 0.0f;
23224 viewport.width = 512;
23225 viewport.height = 512;
23226 viewport.x = 0;
23227 viewport.y = 0;
23228 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
23229 vkEndCommandBuffer(command_buffer[1]);
23230 }
23231 {
23232 VkSubmitInfo submit_info{};
23233 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
23234 submit_info.commandBufferCount = 1;
23235 submit_info.pCommandBuffers = &command_buffer[0];
23236 submit_info.signalSemaphoreCount = 1;
23237 submit_info.pSignalSemaphores = &semaphore;
23238 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
23239 }
23240 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023241 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023242 VkSubmitInfo submit_info{};
23243 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
23244 submit_info.commandBufferCount = 1;
23245 submit_info.pCommandBuffers = &command_buffer[1];
23246 submit_info.waitSemaphoreCount = 1;
23247 submit_info.pWaitSemaphores = &semaphore;
23248 submit_info.pWaitDstStageMask = flags;
23249 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
23250 }
23251
23252 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
23253
23254 vkDestroyFence(m_device->device(), fence, nullptr);
23255 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
23256 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
23257 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
23258
23259 m_errorMonitor->VerifyNotFound();
23260}
23261
23262// This is a positive test. No errors should be generated.
23263TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueNullQueueSubmitWithFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023264 TEST_DESCRIPTION(
23265 "Two command buffers, each in a separate QueueSubmit call "
23266 "on the same queue, no fences, followed by a third QueueSubmit with NO "
23267 "SubmitInfos but with a fence, followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023268
23269 m_errorMonitor->ExpectSuccess();
23270
Tony Barbour1fa09702017-03-16 12:09:08 -060023271 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023272 VkFence fence;
23273 VkFenceCreateInfo fence_create_info{};
23274 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
23275 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
23276
23277 VkCommandPool command_pool;
23278 VkCommandPoolCreateInfo pool_create_info{};
23279 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
23280 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
23281 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
23282 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
23283
23284 VkCommandBuffer command_buffer[2];
23285 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
23286 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
23287 command_buffer_allocate_info.commandPool = command_pool;
23288 command_buffer_allocate_info.commandBufferCount = 2;
23289 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
23290 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
23291
23292 {
23293 VkCommandBufferBeginInfo begin_info{};
23294 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
23295 vkBeginCommandBuffer(command_buffer[0], &begin_info);
23296
23297 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 -070023298 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023299
23300 VkViewport viewport{};
23301 viewport.maxDepth = 1.0f;
23302 viewport.minDepth = 0.0f;
23303 viewport.width = 512;
23304 viewport.height = 512;
23305 viewport.x = 0;
23306 viewport.y = 0;
23307 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
23308 vkEndCommandBuffer(command_buffer[0]);
23309 }
23310 {
23311 VkCommandBufferBeginInfo begin_info{};
23312 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
23313 vkBeginCommandBuffer(command_buffer[1], &begin_info);
23314
23315 VkViewport viewport{};
23316 viewport.maxDepth = 1.0f;
23317 viewport.minDepth = 0.0f;
23318 viewport.width = 512;
23319 viewport.height = 512;
23320 viewport.x = 0;
23321 viewport.y = 0;
23322 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
23323 vkEndCommandBuffer(command_buffer[1]);
23324 }
23325 {
23326 VkSubmitInfo submit_info{};
23327 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
23328 submit_info.commandBufferCount = 1;
23329 submit_info.pCommandBuffers = &command_buffer[0];
23330 submit_info.signalSemaphoreCount = 0;
23331 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
23332 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
23333 }
23334 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023335 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023336 VkSubmitInfo submit_info{};
23337 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
23338 submit_info.commandBufferCount = 1;
23339 submit_info.pCommandBuffers = &command_buffer[1];
23340 submit_info.waitSemaphoreCount = 0;
23341 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
23342 submit_info.pWaitDstStageMask = flags;
23343 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
23344 }
23345
23346 vkQueueSubmit(m_device->m_queue, 0, NULL, fence);
23347
23348 VkResult err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
23349 ASSERT_VK_SUCCESS(err);
23350
23351 vkDestroyFence(m_device->device(), fence, nullptr);
23352 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
23353 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
23354
23355 m_errorMonitor->VerifyNotFound();
23356}
23357
23358// This is a positive test. No errors should be generated.
23359TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023360 TEST_DESCRIPTION(
23361 "Two command buffers, each in a separate QueueSubmit call "
23362 "on the same queue, the second having a fence, followed "
23363 "by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023364
23365 m_errorMonitor->ExpectSuccess();
23366
Tony Barbour1fa09702017-03-16 12:09:08 -060023367 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023368 VkFence fence;
23369 VkFenceCreateInfo fence_create_info{};
23370 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
23371 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
23372
23373 VkCommandPool command_pool;
23374 VkCommandPoolCreateInfo pool_create_info{};
23375 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
23376 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
23377 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
23378 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
23379
23380 VkCommandBuffer command_buffer[2];
23381 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
23382 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
23383 command_buffer_allocate_info.commandPool = command_pool;
23384 command_buffer_allocate_info.commandBufferCount = 2;
23385 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
23386 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
23387
23388 {
23389 VkCommandBufferBeginInfo begin_info{};
23390 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
23391 vkBeginCommandBuffer(command_buffer[0], &begin_info);
23392
23393 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 -070023394 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023395
23396 VkViewport viewport{};
23397 viewport.maxDepth = 1.0f;
23398 viewport.minDepth = 0.0f;
23399 viewport.width = 512;
23400 viewport.height = 512;
23401 viewport.x = 0;
23402 viewport.y = 0;
23403 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
23404 vkEndCommandBuffer(command_buffer[0]);
23405 }
23406 {
23407 VkCommandBufferBeginInfo begin_info{};
23408 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
23409 vkBeginCommandBuffer(command_buffer[1], &begin_info);
23410
23411 VkViewport viewport{};
23412 viewport.maxDepth = 1.0f;
23413 viewport.minDepth = 0.0f;
23414 viewport.width = 512;
23415 viewport.height = 512;
23416 viewport.x = 0;
23417 viewport.y = 0;
23418 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
23419 vkEndCommandBuffer(command_buffer[1]);
23420 }
23421 {
23422 VkSubmitInfo submit_info{};
23423 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
23424 submit_info.commandBufferCount = 1;
23425 submit_info.pCommandBuffers = &command_buffer[0];
23426 submit_info.signalSemaphoreCount = 0;
23427 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
23428 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
23429 }
23430 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023431 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023432 VkSubmitInfo submit_info{};
23433 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
23434 submit_info.commandBufferCount = 1;
23435 submit_info.pCommandBuffers = &command_buffer[1];
23436 submit_info.waitSemaphoreCount = 0;
23437 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
23438 submit_info.pWaitDstStageMask = flags;
23439 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
23440 }
23441
23442 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
23443
23444 vkDestroyFence(m_device->device(), fence, nullptr);
23445 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
23446 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
23447
23448 m_errorMonitor->VerifyNotFound();
23449}
23450
23451// This is a positive test. No errors should be generated.
23452TEST_F(VkPositiveLayerTest, TwoSubmitInfosWithSemaphoreOneQueueSubmitsOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023453 TEST_DESCRIPTION(
23454 "Two command buffers each in a separate SubmitInfo sent in a single "
23455 "QueueSubmit call followed by a WaitForFences call.");
Tony Barbour1fa09702017-03-16 12:09:08 -060023456 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023457
23458 m_errorMonitor->ExpectSuccess();
23459
23460 VkFence fence;
23461 VkFenceCreateInfo fence_create_info{};
23462 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
23463 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
23464
23465 VkSemaphore semaphore;
23466 VkSemaphoreCreateInfo semaphore_create_info{};
23467 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
23468 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
23469
23470 VkCommandPool command_pool;
23471 VkCommandPoolCreateInfo pool_create_info{};
23472 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
23473 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
23474 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
23475 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
23476
23477 VkCommandBuffer command_buffer[2];
23478 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
23479 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
23480 command_buffer_allocate_info.commandPool = command_pool;
23481 command_buffer_allocate_info.commandBufferCount = 2;
23482 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
23483 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
23484
23485 {
23486 VkCommandBufferBeginInfo begin_info{};
23487 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
23488 vkBeginCommandBuffer(command_buffer[0], &begin_info);
23489
23490 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 -070023491 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023492
23493 VkViewport viewport{};
23494 viewport.maxDepth = 1.0f;
23495 viewport.minDepth = 0.0f;
23496 viewport.width = 512;
23497 viewport.height = 512;
23498 viewport.x = 0;
23499 viewport.y = 0;
23500 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
23501 vkEndCommandBuffer(command_buffer[0]);
23502 }
23503 {
23504 VkCommandBufferBeginInfo begin_info{};
23505 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
23506 vkBeginCommandBuffer(command_buffer[1], &begin_info);
23507
23508 VkViewport viewport{};
23509 viewport.maxDepth = 1.0f;
23510 viewport.minDepth = 0.0f;
23511 viewport.width = 512;
23512 viewport.height = 512;
23513 viewport.x = 0;
23514 viewport.y = 0;
23515 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
23516 vkEndCommandBuffer(command_buffer[1]);
23517 }
23518 {
23519 VkSubmitInfo submit_info[2];
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023520 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023521
23522 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
23523 submit_info[0].pNext = NULL;
23524 submit_info[0].commandBufferCount = 1;
23525 submit_info[0].pCommandBuffers = &command_buffer[0];
23526 submit_info[0].signalSemaphoreCount = 1;
23527 submit_info[0].pSignalSemaphores = &semaphore;
23528 submit_info[0].waitSemaphoreCount = 0;
23529 submit_info[0].pWaitSemaphores = NULL;
23530 submit_info[0].pWaitDstStageMask = 0;
23531
23532 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
23533 submit_info[1].pNext = NULL;
23534 submit_info[1].commandBufferCount = 1;
23535 submit_info[1].pCommandBuffers = &command_buffer[1];
23536 submit_info[1].waitSemaphoreCount = 1;
23537 submit_info[1].pWaitSemaphores = &semaphore;
23538 submit_info[1].pWaitDstStageMask = flags;
23539 submit_info[1].signalSemaphoreCount = 0;
23540 submit_info[1].pSignalSemaphores = NULL;
23541 vkQueueSubmit(m_device->m_queue, 2, &submit_info[0], fence);
23542 }
23543
23544 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
23545
23546 vkDestroyFence(m_device->device(), fence, nullptr);
23547 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
23548 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
23549 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
23550
23551 m_errorMonitor->VerifyNotFound();
23552}
23553
23554TEST_F(VkPositiveLayerTest, RenderPassSecondaryCommandBuffersMultipleTimes) {
23555 m_errorMonitor->ExpectSuccess();
23556
Tony Barbour1fa09702017-03-16 12:09:08 -060023557 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023558 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
23559
Tony Barbour552f6c02016-12-21 14:34:07 -070023560 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023561
23562 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
23563 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
23564 m_errorMonitor->VerifyNotFound();
23565 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
23566 m_errorMonitor->VerifyNotFound();
23567 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
23568 m_errorMonitor->VerifyNotFound();
23569
23570 m_commandBuffer->EndCommandBuffer();
23571 m_errorMonitor->VerifyNotFound();
23572}
23573
23574TEST_F(VkPositiveLayerTest, ValidRenderPassAttachmentLayoutWithLoadOp) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023575 TEST_DESCRIPTION(
23576 "Positive test where we create a renderpass with an "
23577 "attachment that uses LOAD_OP_CLEAR, the first subpass "
23578 "has a valid layout, and a second subpass then uses a "
23579 "valid *READ_ONLY* layout.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023580 m_errorMonitor->ExpectSuccess();
Tony Barbour1fa09702017-03-16 12:09:08 -060023581 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -060023582 auto depth_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbourf887b162017-03-09 10:06:46 -070023583 if (!depth_format) {
23584 printf(" No Depth + Stencil format found. Skipped.\n");
23585 return;
23586 }
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023587
23588 VkAttachmentReference attach[2] = {};
23589 attach[0].attachment = 0;
23590 attach[0].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
23591 attach[1].attachment = 0;
23592 attach[1].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
23593 VkSubpassDescription subpasses[2] = {};
23594 // First subpass clears DS attach on load
23595 subpasses[0].pDepthStencilAttachment = &attach[0];
23596 // 2nd subpass reads in DS as input attachment
23597 subpasses[1].inputAttachmentCount = 1;
23598 subpasses[1].pInputAttachments = &attach[1];
23599 VkAttachmentDescription attach_desc = {};
Tony Barbourf887b162017-03-09 10:06:46 -070023600 attach_desc.format = depth_format;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023601 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
23602 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
23603 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
23604 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
23605 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
23606 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
23607 attach_desc.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
23608 VkRenderPassCreateInfo rpci = {};
23609 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
23610 rpci.attachmentCount = 1;
23611 rpci.pAttachments = &attach_desc;
23612 rpci.subpassCount = 2;
23613 rpci.pSubpasses = subpasses;
23614
23615 // Now create RenderPass and verify no errors
23616 VkRenderPass rp;
23617 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
23618 m_errorMonitor->VerifyNotFound();
23619
23620 vkDestroyRenderPass(m_device->device(), rp, NULL);
23621}
23622
Tobin Ehlis01103de2017-02-16 13:22:47 -070023623TEST_F(VkPositiveLayerTest, RenderPassDepthStencilLayoutTransition) {
23624 TEST_DESCRIPTION(
23625 "Create a render pass with depth-stencil attachment where layout transition "
23626 "from UNDEFINED TO DS_READ_ONLY_OPTIMAL is set by render pass and verify that "
23627 "transition has correctly occurred at queue submit time with no validation errors.");
23628
Tony Barbour1fa09702017-03-16 12:09:08 -060023629 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -060023630 auto depth_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbourf887b162017-03-09 10:06:46 -070023631 if (!depth_format) {
23632 printf(" No Depth + Stencil format found. Skipped.\n");
23633 return;
23634 }
Tobin Ehlis01103de2017-02-16 13:22:47 -070023635 VkImageFormatProperties format_props;
Tony Barbourf887b162017-03-09 10:06:46 -070023636 vkGetPhysicalDeviceImageFormatProperties(gpu(), depth_format, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
Tobin Ehlis01103de2017-02-16 13:22:47 -070023637 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, 0, &format_props);
23638 if (format_props.maxExtent.width < 32 || format_props.maxExtent.height < 32) {
Tony Barbourf887b162017-03-09 10:06:46 -070023639 printf("Depth extent too small, RenderPassDepthStencilLayoutTransition skipped.\n");
Tobin Ehlis01103de2017-02-16 13:22:47 -070023640 return;
23641 }
23642
23643 m_errorMonitor->ExpectSuccess();
Tobin Ehlis01103de2017-02-16 13:22:47 -070023644 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
23645
23646 // A renderpass with one depth/stencil attachment.
23647 VkAttachmentDescription attachment = {0,
Tony Barbourf887b162017-03-09 10:06:46 -070023648 depth_format,
Tobin Ehlis01103de2017-02-16 13:22:47 -070023649 VK_SAMPLE_COUNT_1_BIT,
23650 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
23651 VK_ATTACHMENT_STORE_OP_DONT_CARE,
23652 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
23653 VK_ATTACHMENT_STORE_OP_DONT_CARE,
23654 VK_IMAGE_LAYOUT_UNDEFINED,
23655 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
23656
23657 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
23658
23659 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, &att_ref, 0, nullptr};
23660
23661 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
23662
23663 VkRenderPass rp;
23664 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
23665 ASSERT_VK_SUCCESS(err);
23666 // A compatible ds image.
23667 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060023668 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 -070023669 ASSERT_TRUE(image.initialized());
23670
23671 VkImageViewCreateInfo ivci = {
23672 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
23673 nullptr,
23674 0,
23675 image.handle(),
23676 VK_IMAGE_VIEW_TYPE_2D,
Tony Barbourf887b162017-03-09 10:06:46 -070023677 depth_format,
Tobin Ehlis01103de2017-02-16 13:22:47 -070023678 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
23679 VK_COMPONENT_SWIZZLE_IDENTITY},
23680 {VK_IMAGE_ASPECT_DEPTH_BIT, 0, 1, 0, 1},
23681 };
23682 VkImageView view;
23683 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
23684 ASSERT_VK_SUCCESS(err);
23685
23686 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
23687 VkFramebuffer fb;
23688 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
23689 ASSERT_VK_SUCCESS(err);
23690
23691 VkRenderPassBeginInfo rpbi = {VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb, {{0, 0}, {32, 32}}, 0, nullptr};
23692 m_commandBuffer->BeginCommandBuffer();
23693 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
23694 vkCmdEndRenderPass(m_commandBuffer->handle());
23695 m_commandBuffer->EndCommandBuffer();
23696 QueueCommandBuffer(false);
23697 m_errorMonitor->VerifyNotFound();
23698
23699 // Cleanup
23700 vkDestroyImageView(m_device->device(), view, NULL);
23701 vkDestroyRenderPass(m_device->device(), rp, NULL);
23702 vkDestroyFramebuffer(m_device->device(), fb, NULL);
23703}
23704
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023705TEST_F(VkPositiveLayerTest, CreatePipelineAttribMatrixType) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023706 TEST_DESCRIPTION(
23707 "Test that pipeline validation accepts matrices passed "
23708 "as vertex attributes");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023709 m_errorMonitor->ExpectSuccess();
23710
Tony Barbour1fa09702017-03-16 12:09:08 -060023711 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023712 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
23713
23714 VkVertexInputBindingDescription input_binding;
23715 memset(&input_binding, 0, sizeof(input_binding));
23716
23717 VkVertexInputAttributeDescription input_attribs[2];
23718 memset(input_attribs, 0, sizeof(input_attribs));
23719
23720 for (int i = 0; i < 2; i++) {
23721 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
23722 input_attribs[i].location = i;
23723 }
23724
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023725 char const *vsSource =
23726 "#version 450\n"
23727 "\n"
23728 "layout(location=0) in mat2x4 x;\n"
23729 "out gl_PerVertex {\n"
23730 " vec4 gl_Position;\n"
23731 "};\n"
23732 "void main(){\n"
23733 " gl_Position = x[0] + x[1];\n"
23734 "}\n";
23735 char const *fsSource =
23736 "#version 450\n"
23737 "\n"
23738 "layout(location=0) out vec4 color;\n"
23739 "void main(){\n"
23740 " color = vec4(1);\n"
23741 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023742
23743 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
23744 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
23745
23746 VkPipelineObj pipe(m_device);
23747 pipe.AddColorAttachment();
23748 pipe.AddShader(&vs);
23749 pipe.AddShader(&fs);
23750
23751 pipe.AddVertexInputBindings(&input_binding, 1);
23752 pipe.AddVertexInputAttribs(input_attribs, 2);
23753
23754 VkDescriptorSetObj descriptorSet(m_device);
23755 descriptorSet.AppendDummy();
23756 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
23757
23758 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
23759
23760 /* expect success */
23761 m_errorMonitor->VerifyNotFound();
23762}
23763
23764TEST_F(VkPositiveLayerTest, CreatePipelineAttribArrayType) {
23765 m_errorMonitor->ExpectSuccess();
23766
Tony Barbour1fa09702017-03-16 12:09:08 -060023767 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023768 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
23769
23770 VkVertexInputBindingDescription input_binding;
23771 memset(&input_binding, 0, sizeof(input_binding));
23772
23773 VkVertexInputAttributeDescription input_attribs[2];
23774 memset(input_attribs, 0, sizeof(input_attribs));
23775
23776 for (int i = 0; i < 2; i++) {
23777 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
23778 input_attribs[i].location = i;
23779 }
23780
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023781 char const *vsSource =
23782 "#version 450\n"
23783 "\n"
23784 "layout(location=0) in vec4 x[2];\n"
23785 "out gl_PerVertex {\n"
23786 " vec4 gl_Position;\n"
23787 "};\n"
23788 "void main(){\n"
23789 " gl_Position = x[0] + x[1];\n"
23790 "}\n";
23791 char const *fsSource =
23792 "#version 450\n"
23793 "\n"
23794 "layout(location=0) out vec4 color;\n"
23795 "void main(){\n"
23796 " color = vec4(1);\n"
23797 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023798
23799 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
23800 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
23801
23802 VkPipelineObj pipe(m_device);
23803 pipe.AddColorAttachment();
23804 pipe.AddShader(&vs);
23805 pipe.AddShader(&fs);
23806
23807 pipe.AddVertexInputBindings(&input_binding, 1);
23808 pipe.AddVertexInputAttribs(input_attribs, 2);
23809
23810 VkDescriptorSetObj descriptorSet(m_device);
23811 descriptorSet.AppendDummy();
23812 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
23813
23814 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
23815
23816 m_errorMonitor->VerifyNotFound();
23817}
23818
23819TEST_F(VkPositiveLayerTest, CreatePipelineAttribComponents) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023820 TEST_DESCRIPTION(
23821 "Test that pipeline validation accepts consuming a vertex attribute "
23822 "through multiple vertex shader inputs, each consuming a different "
23823 "subset of the components.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023824 m_errorMonitor->ExpectSuccess();
23825
Tony Barbour1fa09702017-03-16 12:09:08 -060023826 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023827 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
23828
23829 VkVertexInputBindingDescription input_binding;
23830 memset(&input_binding, 0, sizeof(input_binding));
23831
23832 VkVertexInputAttributeDescription input_attribs[3];
23833 memset(input_attribs, 0, sizeof(input_attribs));
23834
23835 for (int i = 0; i < 3; i++) {
23836 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
23837 input_attribs[i].location = i;
23838 }
23839
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023840 char const *vsSource =
23841 "#version 450\n"
23842 "\n"
23843 "layout(location=0) in vec4 x;\n"
23844 "layout(location=1) in vec3 y1;\n"
23845 "layout(location=1, component=3) in float y2;\n"
23846 "layout(location=2) in vec4 z;\n"
23847 "out gl_PerVertex {\n"
23848 " vec4 gl_Position;\n"
23849 "};\n"
23850 "void main(){\n"
23851 " gl_Position = x + vec4(y1, y2) + z;\n"
23852 "}\n";
23853 char const *fsSource =
23854 "#version 450\n"
23855 "\n"
23856 "layout(location=0) out vec4 color;\n"
23857 "void main(){\n"
23858 " color = vec4(1);\n"
23859 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023860
23861 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
23862 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
23863
23864 VkPipelineObj pipe(m_device);
23865 pipe.AddColorAttachment();
23866 pipe.AddShader(&vs);
23867 pipe.AddShader(&fs);
23868
23869 pipe.AddVertexInputBindings(&input_binding, 1);
23870 pipe.AddVertexInputAttribs(input_attribs, 3);
23871
23872 VkDescriptorSetObj descriptorSet(m_device);
23873 descriptorSet.AppendDummy();
23874 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
23875
23876 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
23877
23878 m_errorMonitor->VerifyNotFound();
23879}
23880
23881TEST_F(VkPositiveLayerTest, CreatePipelineSimplePositive) {
23882 m_errorMonitor->ExpectSuccess();
23883
Tony Barbour1fa09702017-03-16 12:09:08 -060023884 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023885 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
23886
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023887 char const *vsSource =
23888 "#version 450\n"
23889 "out gl_PerVertex {\n"
23890 " vec4 gl_Position;\n"
23891 "};\n"
23892 "void main(){\n"
23893 " gl_Position = vec4(0);\n"
23894 "}\n";
23895 char const *fsSource =
23896 "#version 450\n"
23897 "\n"
23898 "layout(location=0) out vec4 color;\n"
23899 "void main(){\n"
23900 " color = vec4(1);\n"
23901 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023902
23903 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
23904 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
23905
23906 VkPipelineObj pipe(m_device);
23907 pipe.AddColorAttachment();
23908 pipe.AddShader(&vs);
23909 pipe.AddShader(&fs);
23910
23911 VkDescriptorSetObj descriptorSet(m_device);
23912 descriptorSet.AppendDummy();
23913 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
23914
23915 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
23916
23917 m_errorMonitor->VerifyNotFound();
23918}
23919
23920TEST_F(VkPositiveLayerTest, CreatePipelineRelaxedTypeMatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023921 TEST_DESCRIPTION(
23922 "Test that pipeline validation accepts the relaxed type matching rules "
23923 "set out in 14.1.3: fundamental type must match, and producer side must "
23924 "have at least as many components");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023925 m_errorMonitor->ExpectSuccess();
23926
23927 // VK 1.0.8 Specification, 14.1.3 "Additionally,..." block
23928
Tony Barbour1fa09702017-03-16 12:09:08 -060023929 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023930 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
23931
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023932 char const *vsSource =
23933 "#version 450\n"
23934 "out gl_PerVertex {\n"
23935 " vec4 gl_Position;\n"
23936 "};\n"
23937 "layout(location=0) out vec3 x;\n"
23938 "layout(location=1) out ivec3 y;\n"
23939 "layout(location=2) out vec3 z;\n"
23940 "void main(){\n"
23941 " gl_Position = vec4(0);\n"
23942 " x = vec3(0); y = ivec3(0); z = vec3(0);\n"
23943 "}\n";
23944 char const *fsSource =
23945 "#version 450\n"
23946 "\n"
23947 "layout(location=0) out vec4 color;\n"
23948 "layout(location=0) in float x;\n"
23949 "layout(location=1) flat in int y;\n"
23950 "layout(location=2) in vec2 z;\n"
23951 "void main(){\n"
23952 " color = vec4(1 + x + y + z.x);\n"
23953 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023954
23955 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
23956 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
23957
23958 VkPipelineObj pipe(m_device);
23959 pipe.AddColorAttachment();
23960 pipe.AddShader(&vs);
23961 pipe.AddShader(&fs);
23962
23963 VkDescriptorSetObj descriptorSet(m_device);
23964 descriptorSet.AppendDummy();
23965 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
23966
23967 VkResult err = VK_SUCCESS;
23968 err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
23969 ASSERT_VK_SUCCESS(err);
23970
23971 m_errorMonitor->VerifyNotFound();
23972}
23973
23974TEST_F(VkPositiveLayerTest, CreatePipelineTessPerVertex) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023975 TEST_DESCRIPTION(
23976 "Test that pipeline validation accepts per-vertex variables "
23977 "passed between the TCS and TES stages");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023978 m_errorMonitor->ExpectSuccess();
23979
Tony Barbour1fa09702017-03-16 12:09:08 -060023980 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023981 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
23982
23983 if (!m_device->phy().features().tessellationShader) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070023984 printf(" Device does not support tessellation shaders; skipped.\n");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023985 return;
23986 }
23987
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023988 char const *vsSource =
23989 "#version 450\n"
23990 "void main(){}\n";
23991 char const *tcsSource =
23992 "#version 450\n"
23993 "layout(location=0) out int x[];\n"
23994 "layout(vertices=3) out;\n"
23995 "void main(){\n"
23996 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
23997 " gl_TessLevelInner[0] = 1;\n"
23998 " x[gl_InvocationID] = gl_InvocationID;\n"
23999 "}\n";
24000 char const *tesSource =
24001 "#version 450\n"
24002 "layout(triangles, equal_spacing, cw) in;\n"
24003 "layout(location=0) in int x[];\n"
24004 "out gl_PerVertex { vec4 gl_Position; };\n"
24005 "void main(){\n"
24006 " gl_Position.xyz = gl_TessCoord;\n"
24007 " gl_Position.w = x[0] + x[1] + x[2];\n"
24008 "}\n";
24009 char const *fsSource =
24010 "#version 450\n"
24011 "layout(location=0) out vec4 color;\n"
24012 "void main(){\n"
24013 " color = vec4(1);\n"
24014 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024015
24016 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
24017 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
24018 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
24019 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
24020
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070024021 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
24022 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024023
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070024024 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024025
24026 VkPipelineObj pipe(m_device);
24027 pipe.SetInputAssembly(&iasci);
24028 pipe.SetTessellation(&tsci);
24029 pipe.AddColorAttachment();
24030 pipe.AddShader(&vs);
24031 pipe.AddShader(&tcs);
24032 pipe.AddShader(&tes);
24033 pipe.AddShader(&fs);
24034
24035 VkDescriptorSetObj descriptorSet(m_device);
24036 descriptorSet.AppendDummy();
24037 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
24038
24039 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
24040
24041 m_errorMonitor->VerifyNotFound();
24042}
24043
24044TEST_F(VkPositiveLayerTest, CreatePipelineGeometryInputBlockPositive) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070024045 TEST_DESCRIPTION(
24046 "Test that pipeline validation accepts a user-defined "
24047 "interface block passed into the geometry shader. This "
24048 "is interesting because the 'extra' array level is not "
24049 "present on the member type, but on the block instance.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024050 m_errorMonitor->ExpectSuccess();
24051
Tony Barbour1fa09702017-03-16 12:09:08 -060024052 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024053 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
24054
24055 if (!m_device->phy().features().geometryShader) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070024056 printf(" Device does not support geometry shaders; skipped.\n");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024057 return;
24058 }
24059
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070024060 char const *vsSource =
24061 "#version 450\n"
24062 "layout(location=0) out VertexData { vec4 x; } vs_out;\n"
24063 "void main(){\n"
24064 " vs_out.x = vec4(1);\n"
24065 "}\n";
24066 char const *gsSource =
24067 "#version 450\n"
24068 "layout(triangles) in;\n"
24069 "layout(triangle_strip, max_vertices=3) out;\n"
24070 "layout(location=0) in VertexData { vec4 x; } gs_in[];\n"
24071 "out gl_PerVertex { vec4 gl_Position; };\n"
24072 "void main() {\n"
24073 " gl_Position = gs_in[0].x;\n"
24074 " EmitVertex();\n"
24075 "}\n";
24076 char const *fsSource =
24077 "#version 450\n"
24078 "layout(location=0) out vec4 color;\n"
24079 "void main(){\n"
24080 " color = vec4(1);\n"
24081 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024082
24083 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
24084 VkShaderObj gs(m_device, gsSource, VK_SHADER_STAGE_GEOMETRY_BIT, this);
24085 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
24086
24087 VkPipelineObj pipe(m_device);
24088 pipe.AddColorAttachment();
24089 pipe.AddShader(&vs);
24090 pipe.AddShader(&gs);
24091 pipe.AddShader(&fs);
24092
24093 VkDescriptorSetObj descriptorSet(m_device);
24094 descriptorSet.AppendDummy();
24095 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
24096
24097 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
24098
24099 m_errorMonitor->VerifyNotFound();
24100}
24101
24102TEST_F(VkPositiveLayerTest, CreatePipeline64BitAttributesPositive) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070024103 TEST_DESCRIPTION(
24104 "Test that pipeline validation accepts basic use of 64bit vertex "
24105 "attributes. This is interesting because they consume multiple "
24106 "locations.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024107 m_errorMonitor->ExpectSuccess();
24108
Tony Barbour1fa09702017-03-16 12:09:08 -060024109 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024110 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
24111
24112 if (!m_device->phy().features().shaderFloat64) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070024113 printf(" Device does not support 64bit vertex attributes; skipped.\n");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024114 return;
24115 }
24116
24117 VkVertexInputBindingDescription input_bindings[1];
24118 memset(input_bindings, 0, sizeof(input_bindings));
24119
24120 VkVertexInputAttributeDescription input_attribs[4];
24121 memset(input_attribs, 0, sizeof(input_attribs));
24122 input_attribs[0].location = 0;
24123 input_attribs[0].offset = 0;
24124 input_attribs[0].format = VK_FORMAT_R64G64B64A64_SFLOAT;
24125 input_attribs[1].location = 2;
24126 input_attribs[1].offset = 32;
24127 input_attribs[1].format = VK_FORMAT_R64G64B64A64_SFLOAT;
24128 input_attribs[2].location = 4;
24129 input_attribs[2].offset = 64;
24130 input_attribs[2].format = VK_FORMAT_R64G64B64A64_SFLOAT;
24131 input_attribs[3].location = 6;
24132 input_attribs[3].offset = 96;
24133 input_attribs[3].format = VK_FORMAT_R64G64B64A64_SFLOAT;
24134
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070024135 char const *vsSource =
24136 "#version 450\n"
24137 "\n"
24138 "layout(location=0) in dmat4 x;\n"
24139 "out gl_PerVertex {\n"
24140 " vec4 gl_Position;\n"
24141 "};\n"
24142 "void main(){\n"
24143 " gl_Position = vec4(x[0][0]);\n"
24144 "}\n";
24145 char const *fsSource =
24146 "#version 450\n"
24147 "\n"
24148 "layout(location=0) out vec4 color;\n"
24149 "void main(){\n"
24150 " color = vec4(1);\n"
24151 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024152
24153 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
24154 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
24155
24156 VkPipelineObj pipe(m_device);
24157 pipe.AddColorAttachment();
24158 pipe.AddShader(&vs);
24159 pipe.AddShader(&fs);
24160
24161 pipe.AddVertexInputBindings(input_bindings, 1);
24162 pipe.AddVertexInputAttribs(input_attribs, 4);
24163
24164 VkDescriptorSetObj descriptorSet(m_device);
24165 descriptorSet.AppendDummy();
24166 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
24167
24168 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
24169
24170 m_errorMonitor->VerifyNotFound();
24171}
24172
24173TEST_F(VkPositiveLayerTest, CreatePipelineInputAttachmentPositive) {
24174 TEST_DESCRIPTION("Positive test for a correctly matched input attachment");
24175 m_errorMonitor->ExpectSuccess();
24176
Tony Barbour1fa09702017-03-16 12:09:08 -060024177 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024178
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070024179 char const *vsSource =
24180 "#version 450\n"
24181 "\n"
24182 "out gl_PerVertex {\n"
24183 " vec4 gl_Position;\n"
24184 "};\n"
24185 "void main(){\n"
24186 " gl_Position = vec4(1);\n"
24187 "}\n";
24188 char const *fsSource =
24189 "#version 450\n"
24190 "\n"
24191 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
24192 "layout(location=0) out vec4 color;\n"
24193 "void main() {\n"
24194 " color = subpassLoad(x);\n"
24195 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024196
24197 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
24198 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
24199
24200 VkPipelineObj pipe(m_device);
24201 pipe.AddShader(&vs);
24202 pipe.AddShader(&fs);
24203 pipe.AddColorAttachment();
24204 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
24205
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070024206 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
24207 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024208 VkDescriptorSetLayout dsl;
24209 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
24210 ASSERT_VK_SUCCESS(err);
24211
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070024212 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024213 VkPipelineLayout pl;
24214 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
24215 ASSERT_VK_SUCCESS(err);
24216
24217 VkAttachmentDescription descs[2] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070024218 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
24219 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
24220 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
24221 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
24222 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 -060024223 };
24224 VkAttachmentReference color = {
24225 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
24226 };
24227 VkAttachmentReference input = {
24228 1, VK_IMAGE_LAYOUT_GENERAL,
24229 };
24230
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070024231 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024232
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070024233 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024234 VkRenderPass rp;
24235 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
24236 ASSERT_VK_SUCCESS(err);
24237
24238 // should be OK. would go wrong here if it's going to...
24239 pipe.CreateVKPipeline(pl, rp);
24240
24241 m_errorMonitor->VerifyNotFound();
24242
24243 vkDestroyRenderPass(m_device->device(), rp, nullptr);
24244 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
24245 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
24246}
24247
24248TEST_F(VkPositiveLayerTest, CreateComputePipelineMissingDescriptorUnusedPositive) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070024249 TEST_DESCRIPTION(
24250 "Test that pipeline validation accepts a compute pipeline which declares a "
24251 "descriptor-backed resource which is not provided, but the shader does not "
24252 "statically use it. This is interesting because it requires compute pipelines "
24253 "to have a proper descriptor use walk, which they didn't for some time.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024254 m_errorMonitor->ExpectSuccess();
24255
Tony Barbour1fa09702017-03-16 12:09:08 -060024256 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024257
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070024258 char const *csSource =
24259 "#version 450\n"
24260 "\n"
24261 "layout(local_size_x=1) in;\n"
24262 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
24263 "void main(){\n"
24264 " // x is not used.\n"
24265 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024266
24267 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
24268
24269 VkDescriptorSetObj descriptorSet(m_device);
24270 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
24271
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070024272 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
24273 nullptr,
24274 0,
24275 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
24276 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
24277 descriptorSet.GetPipelineLayout(),
24278 VK_NULL_HANDLE,
24279 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024280
24281 VkPipeline pipe;
24282 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
24283
24284 m_errorMonitor->VerifyNotFound();
24285
24286 if (err == VK_SUCCESS) {
24287 vkDestroyPipeline(m_device->device(), pipe, nullptr);
24288 }
24289}
24290
24291TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsSampler) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070024292 TEST_DESCRIPTION(
24293 "Test that pipeline validation accepts a shader consuming only the "
24294 "sampler portion of a combined image + sampler");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024295 m_errorMonitor->ExpectSuccess();
24296
Tony Barbour1fa09702017-03-16 12:09:08 -060024297 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024298
24299 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070024300 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
24301 {1, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
24302 {2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024303 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070024304 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024305 VkDescriptorSetLayout dsl;
24306 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
24307 ASSERT_VK_SUCCESS(err);
24308
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070024309 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024310 VkPipelineLayout pl;
24311 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
24312 ASSERT_VK_SUCCESS(err);
24313
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070024314 char const *csSource =
24315 "#version 450\n"
24316 "\n"
24317 "layout(local_size_x=1) in;\n"
24318 "layout(set=0, binding=0) uniform sampler s;\n"
24319 "layout(set=0, binding=1) uniform texture2D t;\n"
24320 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
24321 "void main() {\n"
24322 " x = texture(sampler2D(t, s), vec2(0));\n"
24323 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024324 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
24325
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070024326 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
24327 nullptr,
24328 0,
24329 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
24330 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
24331 pl,
24332 VK_NULL_HANDLE,
24333 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024334
24335 VkPipeline pipe;
24336 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
24337
24338 m_errorMonitor->VerifyNotFound();
24339
24340 if (err == VK_SUCCESS) {
24341 vkDestroyPipeline(m_device->device(), pipe, nullptr);
24342 }
24343
24344 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
24345 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
24346}
24347
24348TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsImage) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070024349 TEST_DESCRIPTION(
24350 "Test that pipeline validation accepts a shader consuming only the "
24351 "image portion of a combined image + sampler");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024352 m_errorMonitor->ExpectSuccess();
24353
Tony Barbour1fa09702017-03-16 12:09:08 -060024354 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024355
24356 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070024357 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
24358 {1, VK_DESCRIPTOR_TYPE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
24359 {2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024360 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070024361 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024362 VkDescriptorSetLayout dsl;
24363 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
24364 ASSERT_VK_SUCCESS(err);
24365
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070024366 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024367 VkPipelineLayout pl;
24368 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
24369 ASSERT_VK_SUCCESS(err);
24370
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070024371 char const *csSource =
24372 "#version 450\n"
24373 "\n"
24374 "layout(local_size_x=1) in;\n"
24375 "layout(set=0, binding=0) uniform texture2D t;\n"
24376 "layout(set=0, binding=1) uniform sampler s;\n"
24377 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
24378 "void main() {\n"
24379 " x = texture(sampler2D(t, s), vec2(0));\n"
24380 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024381 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
24382
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070024383 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
24384 nullptr,
24385 0,
24386 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
24387 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
24388 pl,
24389 VK_NULL_HANDLE,
24390 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024391
24392 VkPipeline pipe;
24393 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
24394
24395 m_errorMonitor->VerifyNotFound();
24396
24397 if (err == VK_SUCCESS) {
24398 vkDestroyPipeline(m_device->device(), pipe, nullptr);
24399 }
24400
24401 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
24402 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
24403}
24404
24405TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsBoth) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070024406 TEST_DESCRIPTION(
24407 "Test that pipeline validation accepts a shader consuming "
24408 "both the sampler and the image of a combined image+sampler "
24409 "but via separate variables");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024410 m_errorMonitor->ExpectSuccess();
24411
Tony Barbour1fa09702017-03-16 12:09:08 -060024412 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024413
24414 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070024415 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
24416 {1, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024417 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070024418 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 2, bindings};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024419 VkDescriptorSetLayout dsl;
24420 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
24421 ASSERT_VK_SUCCESS(err);
24422
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070024423 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024424 VkPipelineLayout pl;
24425 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
24426 ASSERT_VK_SUCCESS(err);
24427
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070024428 char const *csSource =
24429 "#version 450\n"
24430 "\n"
24431 "layout(local_size_x=1) in;\n"
24432 "layout(set=0, binding=0) uniform texture2D t;\n"
24433 "layout(set=0, binding=0) uniform sampler s; // both binding 0!\n"
24434 "layout(set=0, binding=1) buffer block { vec4 x; };\n"
24435 "void main() {\n"
24436 " x = texture(sampler2D(t, s), vec2(0));\n"
24437 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024438 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
24439
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070024440 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
24441 nullptr,
24442 0,
24443 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
24444 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
24445 pl,
24446 VK_NULL_HANDLE,
24447 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024448
24449 VkPipeline pipe;
24450 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
24451
24452 m_errorMonitor->VerifyNotFound();
24453
24454 if (err == VK_SUCCESS) {
24455 vkDestroyPipeline(m_device->device(), pipe, nullptr);
24456 }
24457
24458 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
24459 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
24460}
24461
Tony Barbour3ed87a02017-03-15 16:19:02 -060024462TEST_F(VkPositiveLayerTest, Maintenance1Tests) {
Mark Lobodzinskidf784fc2017-03-14 09:18:40 -060024463 TEST_DESCRIPTION("Validate various special cases for the Maintenance1_KHR extension");
24464
Tony Barbour3ed87a02017-03-15 16:19:02 -060024465 device_extension_names.push_back(VK_KHR_MAINTENANCE1_EXTENSION_NAME);
Tony Barbour73c0f352017-03-16 15:55:38 -060024466 InitFramework(instance_layer_names, instance_extension_names, device_extension_names, myDbgFunc, m_errorMonitor);
Tony Barbour3ed87a02017-03-15 16:19:02 -060024467
Mark Lobodzinskidf784fc2017-03-14 09:18:40 -060024468 // Ensure that extension is available and enabled.
24469 uint32_t extension_count = 0;
24470 bool supports_maintenance1_extension = false;
24471 VkResult err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, nullptr);
24472 ASSERT_VK_SUCCESS(err);
24473 if (extension_count > 0) {
24474 std::vector<VkExtensionProperties> available_extensions(extension_count);
24475
24476 err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, &available_extensions[0]);
24477 ASSERT_VK_SUCCESS(err);
24478 for (const auto &extension_props : available_extensions) {
24479 if (strcmp(extension_props.extensionName, VK_KHR_MAINTENANCE1_EXTENSION_NAME) == 0) {
24480 supports_maintenance1_extension = true;
24481 }
24482 }
24483 }
24484
24485 // Proceed if extension is supported by hardware
24486 if (!supports_maintenance1_extension) {
24487 printf(" Maintenance1 Extension not supported, skipping tests\n");
24488 return;
24489 }
Mark Lobodzinskidf784fc2017-03-14 09:18:40 -060024490
24491 m_errorMonitor->ExpectSuccess();
Dave Houlton8e0fe7a2017-03-30 10:32:10 -060024492 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskidf784fc2017-03-14 09:18:40 -060024493 VkCommandBuffer cmd_buf;
24494 VkCommandBufferAllocateInfo alloc_info;
24495 alloc_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
24496 alloc_info.pNext = NULL;
24497 alloc_info.commandBufferCount = 1;
Mike Schuchardt06304c22017-03-01 17:09:09 -070024498 alloc_info.commandPool = m_commandPool->handle();
Mark Lobodzinskidf784fc2017-03-14 09:18:40 -060024499 alloc_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
24500 vkAllocateCommandBuffers(m_device->device(), &alloc_info, &cmd_buf);
24501
24502 VkCommandBufferBeginInfo cb_binfo;
24503 cb_binfo.pNext = NULL;
24504 cb_binfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
24505 cb_binfo.pInheritanceInfo = VK_NULL_HANDLE;
24506 cb_binfo.flags = 0;
24507 vkBeginCommandBuffer(cmd_buf, &cb_binfo);
24508 // Set Negative height, should give error if Maintenance 1 is not enabled
24509 VkViewport viewport = {0, 0, 16, -16, 0, 1};
24510 vkCmdSetViewport(cmd_buf, 0, 1, &viewport);
24511 vkEndCommandBuffer(cmd_buf);
24512
24513 m_errorMonitor->VerifyNotFound();
24514}
24515
Mark Lobodzinski35ecad32017-03-27 13:09:07 -060024516TEST_F(VkLayerTest, DuplicateValidPNextStructures) {
24517 TEST_DESCRIPTION("Create a pNext chain containing valid strutures, but with a duplicate structure type");
24518
24519 ASSERT_NO_FATAL_FAILURE(Init());
24520
24521 uint32_t extension_count = 0;
24522 VkResult err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, nullptr);
24523 ASSERT_VK_SUCCESS(err);
24524
24525 if (extension_count > 0) {
24526 std::vector<VkExtensionProperties> available_extensions(extension_count);
24527 err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, &available_extensions[0]);
24528 ASSERT_VK_SUCCESS(err);
24529
24530 for (const auto &extension_props : available_extensions) {
24531 if (strcmp(extension_props.extensionName, VK_NV_DEDICATED_ALLOCATION_EXTENSION_NAME) == 0) {
24532 // Create two pNext structures which by themselves would be valid
24533 VkDedicatedAllocationBufferCreateInfoNV dedicated_buffer_create_info = {};
24534 VkDedicatedAllocationBufferCreateInfoNV dedicated_buffer_create_info_2 = {};
24535 dedicated_buffer_create_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_BUFFER_CREATE_INFO_NV;
24536 dedicated_buffer_create_info.pNext = &dedicated_buffer_create_info_2;
24537 dedicated_buffer_create_info.dedicatedAllocation = VK_TRUE;
24538
24539 dedicated_buffer_create_info_2.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_BUFFER_CREATE_INFO_NV;
24540 dedicated_buffer_create_info_2.pNext = nullptr;
24541 dedicated_buffer_create_info_2.dedicatedAllocation = VK_TRUE;
24542
24543 uint32_t queue_family_index = 0;
24544 VkBufferCreateInfo buffer_create_info = {};
24545 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
24546 buffer_create_info.pNext = &dedicated_buffer_create_info;
24547 buffer_create_info.size = 1024;
24548 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
24549 buffer_create_info.queueFamilyIndexCount = 1;
24550 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
24551
24552 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "chain contains duplicate structure types");
24553 VkBuffer buffer;
24554 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
24555 m_errorMonitor->VerifyFound();
24556 }
24557 }
24558 }
24559}
24560
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024561TEST_F(VkPositiveLayerTest, ValidStructPNext) {
24562 TEST_DESCRIPTION("Verify that a valid pNext value is handled correctly");
24563
Tony Barbour1fa09702017-03-16 12:09:08 -060024564 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024565
24566 // Positive test to check parameter_validation and unique_objects support
24567 // for NV_dedicated_allocation
24568 uint32_t extension_count = 0;
24569 bool supports_nv_dedicated_allocation = false;
24570 VkResult err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, nullptr);
24571 ASSERT_VK_SUCCESS(err);
24572
24573 if (extension_count > 0) {
24574 std::vector<VkExtensionProperties> available_extensions(extension_count);
24575
24576 err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, &available_extensions[0]);
24577 ASSERT_VK_SUCCESS(err);
24578
24579 for (const auto &extension_props : available_extensions) {
24580 if (strcmp(extension_props.extensionName, VK_NV_DEDICATED_ALLOCATION_EXTENSION_NAME) == 0) {
24581 supports_nv_dedicated_allocation = true;
24582 }
24583 }
24584 }
24585
24586 if (supports_nv_dedicated_allocation) {
24587 m_errorMonitor->ExpectSuccess();
24588
24589 VkDedicatedAllocationBufferCreateInfoNV dedicated_buffer_create_info = {};
24590 dedicated_buffer_create_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_BUFFER_CREATE_INFO_NV;
24591 dedicated_buffer_create_info.pNext = nullptr;
24592 dedicated_buffer_create_info.dedicatedAllocation = VK_TRUE;
24593
24594 uint32_t queue_family_index = 0;
24595 VkBufferCreateInfo buffer_create_info = {};
24596 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
24597 buffer_create_info.pNext = &dedicated_buffer_create_info;
24598 buffer_create_info.size = 1024;
24599 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
24600 buffer_create_info.queueFamilyIndexCount = 1;
24601 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
24602
24603 VkBuffer buffer;
Karl Schultz47dd59d2017-01-20 13:19:20 -070024604 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024605 ASSERT_VK_SUCCESS(err);
24606
24607 VkMemoryRequirements memory_reqs;
24608 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
24609
24610 VkDedicatedAllocationMemoryAllocateInfoNV dedicated_memory_info = {};
24611 dedicated_memory_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_MEMORY_ALLOCATE_INFO_NV;
24612 dedicated_memory_info.pNext = nullptr;
24613 dedicated_memory_info.buffer = buffer;
24614 dedicated_memory_info.image = VK_NULL_HANDLE;
24615
24616 VkMemoryAllocateInfo memory_info = {};
24617 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
24618 memory_info.pNext = &dedicated_memory_info;
24619 memory_info.allocationSize = memory_reqs.size;
24620
24621 bool pass;
24622 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
24623 ASSERT_TRUE(pass);
24624
24625 VkDeviceMemory buffer_memory;
24626 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
24627 ASSERT_VK_SUCCESS(err);
24628
24629 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
24630 ASSERT_VK_SUCCESS(err);
24631
24632 vkDestroyBuffer(m_device->device(), buffer, NULL);
24633 vkFreeMemory(m_device->device(), buffer_memory, NULL);
24634
24635 m_errorMonitor->VerifyNotFound();
24636 }
24637}
24638
24639TEST_F(VkPositiveLayerTest, PSOPolygonModeValid) {
24640 VkResult err;
24641
24642 TEST_DESCRIPTION("Verify that using a solid polygon fill mode works correctly.");
24643
Tony Barbour1fa09702017-03-16 12:09:08 -060024644 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024645 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
24646
24647 std::vector<const char *> device_extension_names;
24648 auto features = m_device->phy().features();
24649 // Artificially disable support for non-solid fill modes
24650 features.fillModeNonSolid = false;
24651 // The sacrificial device object
24652 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
24653
24654 VkRenderpassObj render_pass(&test_device);
24655
24656 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
24657 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
24658 pipeline_layout_ci.setLayoutCount = 0;
24659 pipeline_layout_ci.pSetLayouts = NULL;
24660
24661 VkPipelineLayout pipeline_layout;
24662 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
24663 ASSERT_VK_SUCCESS(err);
24664
24665 VkPipelineRasterizationStateCreateInfo rs_ci = {};
24666 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
24667 rs_ci.pNext = nullptr;
24668 rs_ci.lineWidth = 1.0f;
24669 rs_ci.rasterizerDiscardEnable = true;
24670
24671 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
24672 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
24673
24674 // Set polygonMode=FILL. No error is expected
24675 m_errorMonitor->ExpectSuccess();
24676 {
24677 VkPipelineObj pipe(&test_device);
24678 pipe.AddShader(&vs);
24679 pipe.AddShader(&fs);
24680 pipe.AddColorAttachment();
24681 // Set polygonMode to a good value
24682 rs_ci.polygonMode = VK_POLYGON_MODE_FILL;
24683 pipe.SetRasterization(&rs_ci);
24684 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
24685 }
24686 m_errorMonitor->VerifyNotFound();
24687
24688 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
24689}
24690
Dave Houlton1150cf52017-04-27 14:38:11 -060024691TEST_F(VkPositiveLayerTest, LongSemaphoreChain) {
Chris Forbes94196952017-04-06 16:30:59 -070024692 m_errorMonitor->ExpectSuccess();
24693
24694 ASSERT_NO_FATAL_FAILURE(Init());
24695 VkResult err;
24696
24697 std::vector<VkSemaphore> semaphores;
24698
24699 const int chainLength = 32768;
24700 VkPipelineStageFlags flags = VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT;
24701
24702 for (int i = 0; i < chainLength; i++) {
Dave Houlton1150cf52017-04-27 14:38:11 -060024703 VkSemaphoreCreateInfo sci = {VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0};
Chris Forbes94196952017-04-06 16:30:59 -070024704 VkSemaphore semaphore;
24705 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &semaphore);
24706 ASSERT_VK_SUCCESS(err);
24707
24708 semaphores.push_back(semaphore);
24709
Chris Forbesfc50aaa2017-05-01 10:20:17 -070024710 VkSubmitInfo si = {VK_STRUCTURE_TYPE_SUBMIT_INFO,
24711 nullptr,
24712 semaphores.size() > 1 ? 1u : 0u,
24713 semaphores.size() > 1 ? &semaphores[semaphores.size() - 2] : nullptr,
24714 &flags,
24715 0,
24716 nullptr,
24717 1,
24718 &semaphores[semaphores.size() - 1]};
Chris Forbes94196952017-04-06 16:30:59 -070024719 err = vkQueueSubmit(m_device->m_queue, 1, &si, VK_NULL_HANDLE);
24720 ASSERT_VK_SUCCESS(err);
24721 }
24722
Dave Houlton1150cf52017-04-27 14:38:11 -060024723 VkFenceCreateInfo fci = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0};
Chris Forbes94196952017-04-06 16:30:59 -070024724 VkFence fence;
24725 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
24726 ASSERT_VK_SUCCESS(err);
Dave Houlton1150cf52017-04-27 14:38:11 -060024727 VkSubmitInfo si = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 1, &semaphores.back(), &flags, 0, nullptr, 0, nullptr};
Chris Forbes94196952017-04-06 16:30:59 -070024728 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
24729 ASSERT_VK_SUCCESS(err);
24730
24731 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
24732
Dave Houlton1150cf52017-04-27 14:38:11 -060024733 for (auto semaphore : semaphores) vkDestroySemaphore(m_device->device(), semaphore, nullptr);
Chris Forbes94196952017-04-06 16:30:59 -070024734
24735 vkDestroyFence(m_device->device(), fence, nullptr);
24736
24737 m_errorMonitor->VerifyNotFound();
24738}
24739
Mike Stroyanca855662017-05-02 11:06:27 -060024740extern "C" void *ReleaseNullFence(void *arg) {
24741 struct thread_data_struct *data = (struct thread_data_struct *)arg;
24742
24743 for (int i = 0; i < 40000; i++) {
24744 vkDestroyFence(data->device, VK_NULL_HANDLE, NULL);
24745 if (data->bailout) {
24746 break;
24747 }
24748 }
24749 return NULL;
24750}
24751
24752TEST_F(VkPositiveLayerTest, ThreadNullFenceCollision) {
24753 test_platform_thread thread;
24754
24755 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "THREADING ERROR");
24756
24757 ASSERT_NO_FATAL_FAILURE(Init());
24758
24759 struct thread_data_struct data;
24760 data.device = m_device->device();
24761 data.bailout = false;
24762 m_errorMonitor->SetBailout(&data.bailout);
24763
24764 // Call vkDestroyFence of VK_NULL_HANDLE repeatedly using multiple threads.
24765 // There should be no validation error from collision of that non-object.
24766 test_platform_thread_create(&thread, ReleaseNullFence, (void *)&data);
24767 for (int i = 0; i < 40000; i++) {
24768 vkDestroyFence(m_device->device(), VK_NULL_HANDLE, NULL);
24769 }
24770 test_platform_thread_join(thread, NULL);
24771
24772 m_errorMonitor->SetBailout(NULL);
24773
24774 m_errorMonitor->VerifyNotFound();
24775}
24776
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070024777#if 0 // A few devices have issues with this test so disabling for now
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024778TEST_F(VkPositiveLayerTest, LongFenceChain)
24779{
24780 m_errorMonitor->ExpectSuccess();
24781
Tony Barbour1fa09702017-03-16 12:09:08 -060024782 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024783 VkResult err;
24784
24785 std::vector<VkFence> fences;
24786
24787 const int chainLength = 32768;
24788
24789 for (int i = 0; i < chainLength; i++) {
24790 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
24791 VkFence fence;
24792 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
24793 ASSERT_VK_SUCCESS(err);
24794
24795 fences.push_back(fence);
24796
24797 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr,
24798 0, nullptr, 0, nullptr };
24799 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
24800 ASSERT_VK_SUCCESS(err);
24801
24802 }
24803
24804 // BOOM, stack overflow.
24805 vkWaitForFences(m_device->device(), 1, &fences.back(), VK_TRUE, UINT64_MAX);
24806
24807 for (auto fence : fences)
24808 vkDestroyFence(m_device->device(), fence, nullptr);
24809
24810 m_errorMonitor->VerifyNotFound();
24811}
24812#endif
24813
Petr Kraus4d718682017-05-18 03:38:41 +020024814TEST_F(VkPositiveLayerTest, ClearColorImageWithValidRange) {
24815 TEST_DESCRIPTION("Record clear color with a valid VkImageSubresourceRange");
24816
24817 ASSERT_NO_FATAL_FAILURE(Init());
24818 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
24819
24820 VkImageObj image(m_device);
24821 image.Init(32, 32, 1, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_OPTIMAL);
24822 ASSERT_TRUE(image.create_info().arrayLayers == 1);
24823 ASSERT_TRUE(image.initialized());
24824 image.SetLayout(VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
24825
24826 const VkClearColorValue clear_color = {{0.0f, 0.0f, 0.0f, 1.0f}};
24827
24828 m_commandBuffer->BeginCommandBuffer();
24829 const auto cb_handle = m_commandBuffer->GetBufferHandle();
24830
24831 // Try good case
24832 {
24833 m_errorMonitor->ExpectSuccess();
24834 VkImageSubresourceRange range = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1};
24835 vkCmdClearColorImage(cb_handle, image.handle(), image.Layout(), &clear_color, 1, &range);
24836 m_errorMonitor->VerifyNotFound();
24837 }
24838
24839 // Try good case with VK_REMAINING
24840 {
24841 m_errorMonitor->ExpectSuccess();
24842 VkImageSubresourceRange range = {VK_IMAGE_ASPECT_COLOR_BIT, 0, VK_REMAINING_MIP_LEVELS, 0, VK_REMAINING_ARRAY_LAYERS};
24843 vkCmdClearColorImage(cb_handle, image.handle(), image.Layout(), &clear_color, 1, &range);
24844 m_errorMonitor->VerifyNotFound();
24845 }
24846}
24847
24848TEST_F(VkPositiveLayerTest, ClearDepthStencilWithValidRange) {
24849 TEST_DESCRIPTION("Record clear depth with a valid VkImageSubresourceRange");
24850
24851 ASSERT_NO_FATAL_FAILURE(Init());
24852 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
24853
24854 auto depth_format = FindSupportedDepthStencilFormat(gpu());
24855 if (!depth_format) {
24856 printf(" No Depth + Stencil format found. Skipped.\n");
24857 return;
24858 }
24859
24860 VkImageObj image(m_device);
24861 image.Init(32, 32, 1, depth_format, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_OPTIMAL);
24862 ASSERT_TRUE(image.create_info().arrayLayers == 1);
24863 ASSERT_TRUE(image.initialized());
24864 const VkImageAspectFlags ds_aspect = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
24865 image.SetLayout(ds_aspect, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
24866
24867 const VkClearDepthStencilValue clear_value = {};
24868
24869 m_commandBuffer->BeginCommandBuffer();
24870 const auto cb_handle = m_commandBuffer->GetBufferHandle();
24871
24872 // Try good case
24873 {
24874 m_errorMonitor->ExpectSuccess();
24875 VkImageSubresourceRange range = {ds_aspect, 0, 1, 0, 1};
24876 vkCmdClearDepthStencilImage(cb_handle, image.handle(), image.Layout(), &clear_value, 1, &range);
24877 m_errorMonitor->VerifyNotFound();
24878 }
24879
24880 // Try good case with VK_REMAINING
24881 {
24882 m_errorMonitor->ExpectSuccess();
24883 VkImageSubresourceRange range = {ds_aspect, 0, VK_REMAINING_MIP_LEVELS, 0, VK_REMAINING_ARRAY_LAYERS};
24884 vkCmdClearDepthStencilImage(cb_handle, image.handle(), image.Layout(), &clear_value, 1, &range);
24885 m_errorMonitor->VerifyNotFound();
24886 }
24887}
24888
Cody Northrop1242dfd2016-07-13 17:24:59 -060024889#if defined(ANDROID) && defined(VALIDATION_APK)
Cody Northropb94529f2017-04-05 13:05:51 -060024890const char *appTag = "VulkanLayerValidationTests";
Cody Northrop1242dfd2016-07-13 17:24:59 -060024891static bool initialized = false;
24892static bool active = false;
24893
24894// Convert Intents to argv
24895// Ported from Hologram sample, only difference is flexible key
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024896std::vector<std::string> get_args(android_app &app, const char *intent_extra_data_key) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060024897 std::vector<std::string> args;
24898 JavaVM &vm = *app.activity->vm;
24899 JNIEnv *p_env;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070024900 if (vm.AttachCurrentThread(&p_env, nullptr) != JNI_OK) return args;
Cody Northrop1242dfd2016-07-13 17:24:59 -060024901
24902 JNIEnv &env = *p_env;
24903 jobject activity = app.activity->clazz;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024904 jmethodID get_intent_method = env.GetMethodID(env.GetObjectClass(activity), "getIntent", "()Landroid/content/Intent;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060024905 jobject intent = env.CallObjectMethod(activity, get_intent_method);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024906 jmethodID get_string_extra_method =
24907 env.GetMethodID(env.GetObjectClass(intent), "getStringExtra", "(Ljava/lang/String;)Ljava/lang/String;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060024908 jvalue get_string_extra_args;
24909 get_string_extra_args.l = env.NewStringUTF(intent_extra_data_key);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024910 jstring extra_str = static_cast<jstring>(env.CallObjectMethodA(intent, get_string_extra_method, &get_string_extra_args));
Cody Northrop1242dfd2016-07-13 17:24:59 -060024911
24912 std::string args_str;
24913 if (extra_str) {
24914 const char *extra_utf = env.GetStringUTFChars(extra_str, nullptr);
24915 args_str = extra_utf;
24916 env.ReleaseStringUTFChars(extra_str, extra_utf);
24917 env.DeleteLocalRef(extra_str);
24918 }
24919
24920 env.DeleteLocalRef(get_string_extra_args.l);
24921 env.DeleteLocalRef(intent);
24922 vm.DetachCurrentThread();
24923
24924 // split args_str
24925 std::stringstream ss(args_str);
24926 std::string arg;
24927 while (std::getline(ss, arg, ' ')) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070024928 if (!arg.empty()) args.push_back(arg);
Cody Northrop1242dfd2016-07-13 17:24:59 -060024929 }
24930
24931 return args;
24932}
24933
Dave Houlton11dcd5e2017-04-25 16:00:10 -060024934void addFullTestCommentIfPresent(const ::testing::TestInfo &test_info, std::string &error_message) {
24935 const char *const type_param = test_info.type_param();
24936 const char *const value_param = test_info.value_param();
Cody Northropb94529f2017-04-05 13:05:51 -060024937
24938 if (type_param != NULL || value_param != NULL) {
24939 error_message.append(", where ");
24940 if (type_param != NULL) {
Dave Houlton11dcd5e2017-04-25 16:00:10 -060024941 error_message.append("TypeParam = ").append(type_param);
24942 if (value_param != NULL) error_message.append(" and ");
Cody Northropb94529f2017-04-05 13:05:51 -060024943 }
24944 if (value_param != NULL) {
24945 error_message.append("GetParam() = ").append(value_param);
24946 }
24947 }
24948}
24949
24950// Inspired by https://github.com/google/googletest/blob/master/googletest/docs/AdvancedGuide.md
24951class LogcatPrinter : public ::testing::EmptyTestEventListener {
24952 // Called before a test starts.
Dave Houlton11dcd5e2017-04-25 16:00:10 -060024953 virtual void OnTestStart(const ::testing::TestInfo &test_info) {
Cody Northropb94529f2017-04-05 13:05:51 -060024954 __android_log_print(ANDROID_LOG_INFO, appTag, "[ RUN ] %s.%s", test_info.test_case_name(), test_info.name());
24955 }
24956
24957 // Called after a failed assertion or a SUCCEED() invocation.
Dave Houlton11dcd5e2017-04-25 16:00:10 -060024958 virtual void OnTestPartResult(const ::testing::TestPartResult &result) {
Cody Northropb94529f2017-04-05 13:05:51 -060024959 // If the test part succeeded, we don't need to do anything.
Dave Houlton11dcd5e2017-04-25 16:00:10 -060024960 if (result.type() == ::testing::TestPartResult::kSuccess) return;
Cody Northropb94529f2017-04-05 13:05:51 -060024961
Dave Houlton11dcd5e2017-04-25 16:00:10 -060024962 __android_log_print(ANDROID_LOG_INFO, appTag, "%s in %s:%d %s", result.failed() ? "*** Failure" : "Success",
24963 result.file_name(), result.line_number(), result.summary());
Cody Northropb94529f2017-04-05 13:05:51 -060024964 }
24965
24966 // Called after a test ends.
Dave Houlton11dcd5e2017-04-25 16:00:10 -060024967 virtual void OnTestEnd(const ::testing::TestInfo &info) {
Cody Northropb94529f2017-04-05 13:05:51 -060024968 std::string result;
24969 if (info.result()->Passed()) {
24970 result.append("[ OK ]");
24971 } else {
24972 result.append("[ FAILED ]");
24973 }
24974 result.append(info.test_case_name()).append(".").append(info.name());
Dave Houlton11dcd5e2017-04-25 16:00:10 -060024975 if (info.result()->Failed()) addFullTestCommentIfPresent(info, result);
Cody Northropb94529f2017-04-05 13:05:51 -060024976
24977 if (::testing::GTEST_FLAG(print_time)) {
24978 std::ostringstream os;
24979 os << info.result()->elapsed_time();
24980 result.append(" (").append(os.str()).append(" ms)");
24981 }
24982
24983 __android_log_print(ANDROID_LOG_INFO, appTag, "%s", result.c_str());
24984 };
24985};
24986
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024987static int32_t processInput(struct android_app *app, AInputEvent *event) { return 0; }
Cody Northrop1242dfd2016-07-13 17:24:59 -060024988
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024989static void processCommand(struct android_app *app, int32_t cmd) {
24990 switch (cmd) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070024991 case APP_CMD_INIT_WINDOW: {
24992 if (app->window) {
24993 initialized = true;
24994 }
24995 break;
Cody Northrop1242dfd2016-07-13 17:24:59 -060024996 }
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070024997 case APP_CMD_GAINED_FOCUS: {
24998 active = true;
24999 break;
25000 }
25001 case APP_CMD_LOST_FOCUS: {
25002 active = false;
25003 break;
25004 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060025005 }
25006}
25007
Mark Lobodzinskice751c62016-09-08 10:45:35 -060025008void android_main(struct android_app *app) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060025009 app_dummy();
25010
Cody Northrop1242dfd2016-07-13 17:24:59 -060025011 int vulkanSupport = InitVulkan();
25012 if (vulkanSupport == 0) {
25013 __android_log_print(ANDROID_LOG_INFO, appTag, "==== FAILED ==== No Vulkan support found");
25014 return;
25015 }
25016
25017 app->onAppCmd = processCommand;
25018 app->onInputEvent = processInput;
25019
Mark Lobodzinskice751c62016-09-08 10:45:35 -060025020 while (1) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060025021 int events;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060025022 struct android_poll_source *source;
25023 while (ALooper_pollAll(active ? 0 : -1, NULL, &events, (void **)&source) >= 0) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060025024 if (source) {
25025 source->process(app, source);
25026 }
25027
25028 if (app->destroyRequested != 0) {
25029 VkTestFramework::Finish();
25030 return;
25031 }
25032 }
25033
25034 if (initialized && active) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060025035 // Use the following key to send arguments to gtest, i.e.
25036 // --es args "--gtest_filter=-VkLayerTest.foo"
25037 const char key[] = "args";
25038 std::vector<std::string> args = get_args(*app, key);
Cody Northrop1242dfd2016-07-13 17:24:59 -060025039
Mark Lobodzinskice751c62016-09-08 10:45:35 -060025040 std::string filter = "";
25041 if (args.size() > 0) {
25042 __android_log_print(ANDROID_LOG_INFO, appTag, "Intent args = %s", args[0].c_str());
25043 filter += args[0];
25044 } else {
25045 __android_log_print(ANDROID_LOG_INFO, appTag, "No Intent args detected");
25046 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060025047
Mark Lobodzinskice751c62016-09-08 10:45:35 -060025048 int argc = 2;
25049 char *argv[] = {(char *)"foo", (char *)filter.c_str()};
25050 __android_log_print(ANDROID_LOG_DEBUG, appTag, "filter = %s", argv[1]);
Cody Northrop1242dfd2016-07-13 17:24:59 -060025051
Mark Lobodzinskice751c62016-09-08 10:45:35 -060025052 // Route output to files until we can override the gtest output
25053 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/out.txt", "w", stdout);
25054 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/err.txt", "w", stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060025055
Mark Lobodzinskice751c62016-09-08 10:45:35 -060025056 ::testing::InitGoogleTest(&argc, argv);
Cody Northropb94529f2017-04-05 13:05:51 -060025057
Dave Houlton11dcd5e2017-04-25 16:00:10 -060025058 ::testing::TestEventListeners &listeners = ::testing::UnitTest::GetInstance()->listeners();
Cody Northropb94529f2017-04-05 13:05:51 -060025059 listeners.Append(new LogcatPrinter);
25060
Mark Lobodzinskice751c62016-09-08 10:45:35 -060025061 VkTestFramework::InitArgs(&argc, argv);
25062 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Cody Northrop1242dfd2016-07-13 17:24:59 -060025063
Mark Lobodzinskice751c62016-09-08 10:45:35 -060025064 int result = RUN_ALL_TESTS();
Cody Northrop1242dfd2016-07-13 17:24:59 -060025065
Mark Lobodzinskice751c62016-09-08 10:45:35 -060025066 if (result != 0) {
25067 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests FAILED ====");
25068 } else {
25069 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests PASSED ====");
25070 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060025071
Mark Lobodzinskice751c62016-09-08 10:45:35 -060025072 VkTestFramework::Finish();
Cody Northrop1242dfd2016-07-13 17:24:59 -060025073
Mark Lobodzinskice751c62016-09-08 10:45:35 -060025074 fclose(stdout);
25075 fclose(stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060025076
Mark Lobodzinskice751c62016-09-08 10:45:35 -060025077 ANativeActivity_finish(app->activity);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060025078 return;
Cody Northrop1242dfd2016-07-13 17:24:59 -060025079 }
25080 }
25081}
25082#endif
25083
Tony Barbour300a6082015-04-07 13:44:53 -060025084int main(int argc, char **argv) {
25085 int result;
25086
Cody Northrop8e54a402016-03-08 22:25:52 -070025087#ifdef ANDROID
25088 int vulkanSupport = InitVulkan();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070025089 if (vulkanSupport == 0) return 1;
Cody Northrop8e54a402016-03-08 22:25:52 -070025090#endif
25091
Tony Barbour300a6082015-04-07 13:44:53 -060025092 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -060025093 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour300a6082015-04-07 13:44:53 -060025094
25095 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
25096
25097 result = RUN_ALL_TESTS();
25098
Tony Barbour6918cd52015-04-09 12:58:51 -060025099 VkTestFramework::Finish();
Tony Barbour300a6082015-04-07 13:44:53 -060025100 return result;
25101}