blob: 24d7ac9816047a2511344cea5ada4a5e261e4b11 [file] [log] [blame]
Karl Schultz6addd812016-02-02 17:17:23 -07001/*
Mike Weiblen40b160e2017-02-06 19:21:52 -07002 * Copyright (c) 2015-2017 The Khronos Group Inc.
3 * Copyright (c) 2015-2017 Valve Corporation
4 * Copyright (c) 2015-2017 LunarG, Inc.
5 * Copyright (c) 2015-2017 Google, Inc.
Karl Schultz6addd812016-02-02 17:17:23 -07006 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -06007 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
Karl Schultz6addd812016-02-02 17:17:23 -070010 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -060011 * http://www.apache.org/licenses/LICENSE-2.0
Karl Schultz6addd812016-02-02 17:17:23 -070012 *
13 * Author: Chia-I Wu <olvaffe@gmail.com>
14 * Author: Chris Forbes <chrisf@ijw.co.nz>
15 * Author: Courtney Goeltzenleuchter <courtney@LunarG.com>
16 * Author: Mark Lobodzinski <mark@lunarg.com>
17 * Author: Mike Stroyan <mike@LunarG.com>
18 * Author: Tobin Ehlis <tobine@google.com>
19 * Author: Tony Barbour <tony@LunarG.com>
Cody Northrop1242dfd2016-07-13 17:24:59 -060020 * Author: Cody Northrop <cnorthrop@google.com>
Dave Houlton59a20702017-02-02 17:26:23 -070021 * Author: Dave Houlton <daveh@lunarg.com>
Karl Schultz6addd812016-02-02 17:17:23 -070022 */
Tony Barbour65c48b32015-11-17 10:02:56 -070023
Cody Northrop8e54a402016-03-08 22:25:52 -070024#ifdef ANDROID
25#include "vulkan_wrapper.h"
26#else
David Pinedo9316d3b2015-11-06 12:54:48 -070027#include <vulkan/vulkan.h>
Cody Northrop8e54a402016-03-08 22:25:52 -070028#endif
Cody Northrop1242dfd2016-07-13 17:24:59 -060029
30#if defined(ANDROID) && defined(VALIDATION_APK)
31#include <android/log.h>
32#include <android_native_app_glue.h>
33#endif
34
Jon Ashburn7fa7e222016-02-02 12:08:10 -070035#include "icd-spv.h"
Mark Lobodzinskice751c62016-09-08 10:45:35 -060036#include "test_common.h"
37#include "vk_layer_config.h"
Dave Houlton3c9fca72017-03-27 17:25:54 -060038#include "vk_format_utils.h"
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060039#include "vk_validation_error_messages.h"
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060040#include "vkrenderframework.h"
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070041
42#include <algorithm>
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060043#include <limits.h>
44#include <unordered_set>
Tony Barbour300a6082015-04-07 13:44:53 -060045
Mark Lobodzinski3780e142015-05-14 15:08:13 -050046#define GLM_FORCE_RADIANS
47#include "glm/glm.hpp"
48#include <glm/gtc/matrix_transform.hpp>
49
50//--------------------------------------------------------------------------------------
51// Mesh and VertexFormat Data
52//--------------------------------------------------------------------------------------
Karl Schultz6addd812016-02-02 17:17:23 -070053struct Vertex {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070054 float posX, posY, posZ, posW; // Position data
55 float r, g, b, a; // Color
Mark Lobodzinski3780e142015-05-14 15:08:13 -050056};
57
Karl Schultz6addd812016-02-02 17:17:23 -070058#define XYZ1(_x_, _y_, _z_) (_x_), (_y_), (_z_), 1.f
Mark Lobodzinski3780e142015-05-14 15:08:13 -050059
60typedef enum _BsoFailSelect {
Karl Schultz6addd812016-02-02 17:17:23 -070061 BsoFailNone = 0x00000000,
62 BsoFailLineWidth = 0x00000001,
63 BsoFailDepthBias = 0x00000002,
64 BsoFailViewport = 0x00000004,
65 BsoFailScissor = 0x00000008,
66 BsoFailBlend = 0x00000010,
67 BsoFailDepthBounds = 0x00000020,
68 BsoFailStencilReadMask = 0x00000040,
69 BsoFailStencilWriteMask = 0x00000080,
70 BsoFailStencilReference = 0x00000100,
Mark Muellerd4914412016-06-13 17:52:06 -060071 BsoFailCmdClearAttachments = 0x00000200,
Tobin Ehlis379ba3b2016-07-19 11:22:29 -060072 BsoFailIndexBuffer = 0x00000400,
Mark Lobodzinski3780e142015-05-14 15:08:13 -050073} BsoFailSelect;
74
75struct vktriangle_vs_uniform {
76 // Must start with MVP
Karl Schultz6addd812016-02-02 17:17:23 -070077 float mvp[4][4];
78 float position[3][4];
79 float color[3][4];
Mark Lobodzinski3780e142015-05-14 15:08:13 -050080};
81
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070082static const char bindStateVertShaderText[] =
83 "#version 450\n"
84 "vec2 vertices[3];\n"
85 "out gl_PerVertex {\n"
86 " vec4 gl_Position;\n"
87 "};\n"
88 "void main() {\n"
89 " vertices[0] = vec2(-1.0, -1.0);\n"
90 " vertices[1] = vec2( 1.0, -1.0);\n"
91 " vertices[2] = vec2( 0.0, 1.0);\n"
92 " gl_Position = vec4(vertices[gl_VertexIndex % 3], 0.0, 1.0);\n"
93 "}\n";
Mark Lobodzinski3780e142015-05-14 15:08:13 -050094
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070095static const char bindStateFragShaderText[] =
96 "#version 450\n"
97 "\n"
98 "layout(location = 0) out vec4 uFragColor;\n"
99 "void main(){\n"
100 " uFragColor = vec4(0,1,0,1);\n"
101 "}\n";
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500102
Dave Houlton1d2022c2017-03-29 11:43:58 -0600103// Format search helper
104VkFormat FindSupportedDepthStencilFormat(VkPhysicalDevice phy) {
Dave Houltond7472002017-03-30 09:48:28 -0600105 VkFormat ds_formats[] = {VK_FORMAT_D16_UNORM_S8_UINT, VK_FORMAT_D24_UNORM_S8_UINT, VK_FORMAT_D32_SFLOAT_S8_UINT};
Dave Houlton1d2022c2017-03-29 11:43:58 -0600106 for (uint32_t i = 0; i < sizeof(ds_formats); i++) {
107 VkFormatProperties format_props;
108 vkGetPhysicalDeviceFormatProperties(phy, ds_formats[i], &format_props);
109
110 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
111 return ds_formats[i];
112 }
113 }
114 return (VkFormat)0;
115}
116
117// Validation report callback prototype
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600118static VKAPI_ATTR VkBool32 VKAPI_CALL myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType, uint64_t srcObject,
119 size_t location, int32_t msgCode, const char *pLayerPrefix, const char *pMsg,
120 void *pUserData);
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600121
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600122// ErrorMonitor Usage:
123//
Dave Houltonfbf52152017-01-06 12:55:29 -0700124// Call SetDesiredFailureMsg with a string to be compared against all
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600125// encountered log messages, or a validation error enum identifying
126// desired error message. Passing NULL or VALIDATION_ERROR_MAX_ENUM
127// will match all log messages. logMsg will return true for skipCall
128// only if msg is matched or NULL.
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600129//
Dave Houltonfbf52152017-01-06 12:55:29 -0700130// Call VerifyFound to determine if all desired failure messages
131// were encountered. Call VerifyNotFound to determine if any unexpected
132// failure was encountered.
Tony Barbour300a6082015-04-07 13:44:53 -0600133class ErrorMonitor {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700134 public:
Karl Schultz6addd812016-02-02 17:17:23 -0700135 ErrorMonitor() {
Dave Houltonfbf52152017-01-06 12:55:29 -0700136 test_platform_thread_create_mutex(&mutex_);
137 test_platform_thread_lock_mutex(&mutex_);
138 Reset();
139 test_platform_thread_unlock_mutex(&mutex_);
Tony Barbour300a6082015-04-07 13:44:53 -0600140 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600141
Dave Houltonfbf52152017-01-06 12:55:29 -0700142 ~ErrorMonitor() { test_platform_thread_delete_mutex(&mutex_); }
Dustin Graves48458142016-04-29 16:11:55 -0600143
Dave Houltonfbf52152017-01-06 12:55:29 -0700144 // Set monitor to pristine state
145 void Reset() {
146 message_flags_ = VK_DEBUG_REPORT_ERROR_BIT_EXT;
147 bailout_ = NULL;
148 message_found_ = VK_FALSE;
149 failure_message_strings_.clear();
150 desired_message_strings_.clear();
151 desired_message_ids_.clear();
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700152 ignore_message_strings_.clear();
Dave Houltonfbf52152017-01-06 12:55:29 -0700153 other_messages_.clear();
154 message_outstanding_count_ = 0;
155 }
156
157 // ErrorMonitor will look for an error message containing the specified string(s)
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700158 void SetDesiredFailureMsg(const VkFlags msgFlags, const char *const msgString) {
Dave Houltonfbf52152017-01-06 12:55:29 -0700159 test_platform_thread_lock_mutex(&mutex_);
160 desired_message_strings_.insert(msgString);
161 message_flags_ |= msgFlags;
162 message_outstanding_count_++;
163 test_platform_thread_unlock_mutex(&mutex_);
Tony Barbour300a6082015-04-07 13:44:53 -0600164 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600165
Jeremy Hayesde6d96c2017-02-01 15:22:32 -0700166 // ErrorMonitor will look for an error message containing the specified string(s)
167 template <typename Iter>
168 void SetDesiredFailureMsg(const VkFlags msgFlags, Iter iter, const Iter end) {
169 for (; iter != end; ++iter) {
170 SetDesiredFailureMsg(msgFlags, *iter);
171 }
172 }
173
Dave Houltonfbf52152017-01-06 12:55:29 -0700174 // ErrorMonitor will look for a message ID matching the specified one(s)
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700175 void SetDesiredFailureMsg(const VkFlags msgFlags, const UNIQUE_VALIDATION_ERROR_CODE msg_id) {
Dave Houltonfbf52152017-01-06 12:55:29 -0700176 test_platform_thread_lock_mutex(&mutex_);
177 desired_message_ids_.insert(msg_id);
178 message_flags_ |= msgFlags;
179 message_outstanding_count_++;
180 test_platform_thread_unlock_mutex(&mutex_);
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600181 }
182
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700183 // Set an error that the error monitor will ignore. Do not use this function if you are creating a new test.
184 // TODO: This is stopgap to block new unexpected errors from being introduced. The long-term goal is to remove the use of this
185 // function and its definition.
186 void SetUnexpectedError(const char *const msg) {
187 test_platform_thread_lock_mutex(&mutex_);
188
189 ignore_message_strings_.emplace_back(msg);
190
191 test_platform_thread_unlock_mutex(&mutex_);
192 }
193
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700194 VkBool32 CheckForDesiredMsg(const uint32_t message_code, const char *const msgString) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600195 VkBool32 result = VK_FALSE;
Dave Houltonfbf52152017-01-06 12:55:29 -0700196 test_platform_thread_lock_mutex(&mutex_);
197 if (bailout_ != NULL) {
198 *bailout_ = true;
Mike Stroyanaccf7692015-05-12 16:00:45 -0600199 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600200 string errorString(msgString);
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600201 bool found_expected = false;
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600202
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700203 if (!IgnoreMessage(errorString)) {
204 for (auto desired_msg : desired_message_strings_) {
205 if (desired_msg.length() == 0) {
206 // An empty desired_msg string "" indicates a positive test - not expecting an error.
207 // Return true to avoid calling layers/driver with this error.
208 // And don't erase the "" string, so it remains if another error is found.
209 result = VK_TRUE;
210 found_expected = true;
211 message_found_ = VK_TRUE;
212 failure_message_strings_.insert(errorString);
213 } else if (errorString.find(desired_msg) != string::npos) {
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600214 found_expected = true;
Dave Houltonfbf52152017-01-06 12:55:29 -0700215 message_outstanding_count_--;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700216 failure_message_strings_.insert(errorString);
Dave Houltonfbf52152017-01-06 12:55:29 -0700217 message_found_ = VK_TRUE;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700218 result = VK_TRUE;
219 // We only want one match for each expected error so remove from set here
220 // Since we're about the break the loop it's ok to remove from set we're iterating over
221 desired_message_strings_.erase(desired_msg);
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600222 break;
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600223 }
224 }
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700225 for (auto desired_id : desired_message_ids_) {
226 if (desired_id == VALIDATION_ERROR_MAX_ENUM) {
227 // A message ID set to MAX_ENUM indicates a positive test - not expecting an error.
228 // Return true to avoid calling layers/driver with this error.
229 result = VK_TRUE;
230 } else if (desired_id == message_code) {
231 // Double-check that the string matches the error enum
232 if (errorString.find(validation_error_map[desired_id]) != string::npos) {
233 found_expected = true;
234 message_outstanding_count_--;
235 result = VK_TRUE;
236 message_found_ = VK_TRUE;
237 desired_message_ids_.erase(desired_id);
238 break;
239 } else {
240 // Treat this message as a regular unexpected error, but print a warning jic
241 printf("Message (%s) from MessageID %d does not correspond to expected message from error Database (%s)\n",
242 errorString.c_str(), desired_id, validation_error_map[desired_id]);
243 }
244 }
245 }
246
247 if (!found_expected) {
Jeremy Hayes2a54c012017-03-16 13:32:05 -0600248 printf("Unexpected: %s\n", msgString);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700249 other_messages_.push_back(errorString);
250 }
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600251 }
252
Dave Houltonfbf52152017-01-06 12:55:29 -0700253 test_platform_thread_unlock_mutex(&mutex_);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600254 return result;
Mike Stroyanaccf7692015-05-12 16:00:45 -0600255 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600256
Jeremy Hayes2a54c012017-03-16 13:32:05 -0600257 vector<string> GetOtherFailureMsgs(void) const { return other_messages_; }
258
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700259 VkDebugReportFlagsEXT GetMessageFlags(void) const { return message_flags_; }
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600260
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700261 VkBool32 AnyDesiredMsgFound(void) const { return message_found_; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600262
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700263 VkBool32 AllDesiredMsgsFound(void) const { return (0 == message_outstanding_count_); }
Dave Houltonfbf52152017-01-06 12:55:29 -0700264
265 void SetBailout(bool *bailout) { bailout_ = bailout; }
Tony Barbour300a6082015-04-07 13:44:53 -0600266
Jeremy Hayes2a54c012017-03-16 13:32:05 -0600267 void DumpFailureMsgs(void) const {
268 vector<string> otherMsgs = GetOtherFailureMsgs();
269 if (otherMsgs.size()) {
270 cout << "Other error messages logged for this test were:" << endl;
271 for (auto iter = otherMsgs.begin(); iter != otherMsgs.end(); iter++) {
272 cout << " " << *iter << endl;
Tony Barbour59b42282016-11-03 13:31:28 -0600273 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600274 }
275 }
276
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600277 // Helpers
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200278
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600279 // ExpectSuccess now takes an optional argument allowing a custom combination of debug flags
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700280 void ExpectSuccess(VkDebugReportFlagsEXT const message_flag_mask = VK_DEBUG_REPORT_ERROR_BIT_EXT) {
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600281 // Match ANY message matching specified type
282 SetDesiredFailureMsg(message_flag_mask, "");
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700283 message_flags_ = message_flag_mask; // override mask handling in SetDesired...
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200284 }
285
286 void VerifyFound() {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600287 // Not seeing the desired message is a failure. /Before/ throwing, dump any other messages.
Dave Houltonfbf52152017-01-06 12:55:29 -0700288 if (!AllDesiredMsgsFound()) {
Jeremy Hayes2a54c012017-03-16 13:32:05 -0600289 DumpFailureMsgs();
Dave Houltonfbf52152017-01-06 12:55:29 -0700290 for (auto desired_msg : desired_message_strings_) {
Dave Houltond5507dd2017-01-24 15:29:02 -0700291 ADD_FAILURE() << "Did not receive expected error '" << desired_msg << "'";
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600292 }
Dave Houltonfbf52152017-01-06 12:55:29 -0700293 for (auto desired_id : desired_message_ids_) {
Dave Houltond5507dd2017-01-24 15:29:02 -0700294 ADD_FAILURE() << "Did not receive expected error ENUM '" << desired_id << "'";
Tony Barbour59b42282016-11-03 13:31:28 -0600295 }
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200296 }
Dave Houltonfbf52152017-01-06 12:55:29 -0700297 Reset();
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200298 }
299
300 void VerifyNotFound() {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600301 // ExpectSuccess() configured us to match anything. Any error is a failure.
Dave Houltonfbf52152017-01-06 12:55:29 -0700302 if (AnyDesiredMsgFound()) {
Jeremy Hayes2a54c012017-03-16 13:32:05 -0600303 DumpFailureMsgs();
Dave Houltonfbf52152017-01-06 12:55:29 -0700304 for (auto msg : failure_message_strings_) {
Dave Houltond5507dd2017-01-24 15:29:02 -0700305 ADD_FAILURE() << "Expected to succeed but got error: " << msg;
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600306 }
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200307 }
Dave Houltonfbf52152017-01-06 12:55:29 -0700308 Reset();
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200309 }
310
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700311 private:
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700312 // TODO: This is stopgap to block new unexpected errors from being introduced. The long-term goal is to remove the use of this
313 // function and its definition.
314 bool IgnoreMessage(std::string const &msg) const {
315 if (ignore_message_strings_.empty()) {
316 return false;
317 }
318
319 return std::find_if(ignore_message_strings_.begin(), ignore_message_strings_.end(), [&msg](std::string const &str) {
320 return msg.find(str) != std::string::npos;
321 }) != ignore_message_strings_.end();
322 }
323
Mark Lobodzinski729a8d32017-01-26 12:16:30 -0700324 VkFlags message_flags_;
325 std::unordered_set<uint32_t> desired_message_ids_;
326 std::unordered_set<string> desired_message_strings_;
327 std::unordered_set<string> failure_message_strings_;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700328 std::vector<std::string> ignore_message_strings_;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -0700329 vector<string> other_messages_;
330 test_platform_thread_mutex mutex_;
331 bool *bailout_;
332 VkBool32 message_found_;
333 int message_outstanding_count_;
Tony Barbour300a6082015-04-07 13:44:53 -0600334};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500335
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600336static VKAPI_ATTR VkBool32 VKAPI_CALL myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType, uint64_t srcObject,
337 size_t location, int32_t msgCode, const char *pLayerPrefix, const char *pMsg,
338 void *pUserData) {
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600339 ErrorMonitor *errMonitor = (ErrorMonitor *)pUserData;
340 if (msgFlags & errMonitor->GetMessageFlags()) {
Dave Houltonc85c4a82017-04-25 15:56:45 -0600341#ifdef _DEBUG
342 char embedded_code_string[2048];
343 snprintf(embedded_code_string, 2048, "%s [%05d]", pMsg, msgCode);
344 return errMonitor->CheckForDesiredMsg(msgCode, embedded_code_string);
345#else
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600346 return errMonitor->CheckForDesiredMsg(msgCode, pMsg);
Dave Houltonc85c4a82017-04-25 15:56:45 -0600347#endif
Tony Barbour0b4d9562015-04-09 10:48:04 -0600348 }
Courtney Goeltzenleuchter06640832015-09-04 13:52:24 -0600349 return false;
Tony Barbour300a6082015-04-07 13:44:53 -0600350}
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500351
Karl Schultz6addd812016-02-02 17:17:23 -0700352class VkLayerTest : public VkRenderFramework {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700353 public:
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600354 void VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask);
355 void GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet,
Karl Schultz6addd812016-02-02 17:17:23 -0700356 BsoFailSelect failMask);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600357 void GenericDrawPreparation(VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask) {
358 GenericDrawPreparation(m_commandBuffer, pipelineobj, descriptorSet, failMask);
Karl Schultz6addd812016-02-02 17:17:23 -0700359 }
Tony Barbour300a6082015-04-07 13:44:53 -0600360
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600361 void Draw(uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance) {
362 m_commandBuffer->Draw(vertexCount, instanceCount, firstVertex, firstInstance);
Karl Schultz6addd812016-02-02 17:17:23 -0700363 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600364 void DrawIndexed(uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex, int32_t vertexOffset,
Karl Schultz6addd812016-02-02 17:17:23 -0700365 uint32_t firstInstance) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600366 m_commandBuffer->DrawIndexed(indexCount, instanceCount, firstIndex, vertexOffset, firstInstance);
Karl Schultz6addd812016-02-02 17:17:23 -0700367 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600368 void QueueCommandBuffer(bool checkSuccess = true) { m_commandBuffer->QueueCommandBuffer(checkSuccess); }
369 void QueueCommandBuffer(const VkFence &fence) { m_commandBuffer->QueueCommandBuffer(fence); }
370 void BindVertexBuffer(VkConstantBufferObj *vertexBuffer, VkDeviceSize offset, uint32_t binding) {
Karl Schultz6addd812016-02-02 17:17:23 -0700371 m_commandBuffer->BindVertexBuffer(vertexBuffer, offset, binding);
372 }
373 void BindIndexBuffer(VkIndexBufferObj *indexBuffer, VkDeviceSize offset) {
374 m_commandBuffer->BindIndexBuffer(indexBuffer, offset);
375 }
Tony Barbour1fa09702017-03-16 12:09:08 -0600376 void Init(VkPhysicalDeviceFeatures *features = nullptr, const VkCommandPoolCreateFlags flags = 0) {
377 InitFramework(instance_layer_names, instance_extension_names, device_extension_names, myDbgFunc, m_errorMonitor);
378 InitState(features, flags);
379 }
380
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700381 protected:
Karl Schultz6addd812016-02-02 17:17:23 -0700382 ErrorMonitor *m_errorMonitor;
Ian Elliott2c1daf52016-05-12 09:41:46 -0600383 bool m_enableWSI;
Tony Barbour1fa09702017-03-16 12:09:08 -0600384 std::vector<const char *> instance_layer_names;
385 std::vector<const char *> instance_extension_names;
386 std::vector<const char *> device_extension_names;
Tony Barbour300a6082015-04-07 13:44:53 -0600387
388 virtual void SetUp() {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700389 instance_extension_names.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME);
Courtney Goeltzenleuchterc2b06fe2015-06-16 15:59:11 -0600390 /*
391 * Since CreateDbgMsgCallback is an instance level extension call
392 * any extension / layer that utilizes that feature also needs
393 * to be enabled at create instance time.
394 */
Karl Schultz6addd812016-02-02 17:17:23 -0700395 // Use Threading layer first to protect others from
396 // ThreadCommandBufferCollision test
Courtney Goeltzenleuchter76885322016-02-06 17:11:22 -0700397 instance_layer_names.push_back("VK_LAYER_GOOGLE_threading");
Tobin Ehlis24aab042016-03-24 10:54:18 -0600398 instance_layer_names.push_back("VK_LAYER_LUNARG_parameter_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800399 instance_layer_names.push_back("VK_LAYER_LUNARG_object_tracker");
Tobin Ehlisc96f8062016-03-09 16:12:48 -0700400 instance_layer_names.push_back("VK_LAYER_LUNARG_core_validation");
Ian Elliotte48a1382016-04-28 14:22:58 -0600401 instance_layer_names.push_back("VK_LAYER_LUNARG_swapchain");
Dustin Graveseaa78cd2016-01-26 16:30:22 -0700402 instance_layer_names.push_back("VK_LAYER_GOOGLE_unique_objects");
Courtney Goeltzenleuchterd971b612015-06-17 20:51:59 -0600403
Ian Elliott2c1daf52016-05-12 09:41:46 -0600404 if (m_enableWSI) {
405 instance_extension_names.push_back(VK_KHR_SURFACE_EXTENSION_NAME);
406 device_extension_names.push_back(VK_KHR_SWAPCHAIN_EXTENSION_NAME);
407#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
408#if defined(VK_USE_PLATFORM_ANDROID_KHR)
409 instance_extension_names.push_back(VK_KHR_ANDROID_SURFACE_EXTENSION_NAME);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700410#endif // VK_USE_PLATFORM_ANDROID_KHR
Ian Elliott2c1daf52016-05-12 09:41:46 -0600411#if defined(VK_USE_PLATFORM_MIR_KHR)
412 instance_extension_names.push_back(VK_KHR_MIR_SURFACE_EXTENSION_NAME);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700413#endif // VK_USE_PLATFORM_MIR_KHR
Ian Elliott2c1daf52016-05-12 09:41:46 -0600414#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
415 instance_extension_names.push_back(VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700416#endif // VK_USE_PLATFORM_WAYLAND_KHR
Ian Elliott2c1daf52016-05-12 09:41:46 -0600417#if defined(VK_USE_PLATFORM_WIN32_KHR)
418 instance_extension_names.push_back(VK_KHR_WIN32_SURFACE_EXTENSION_NAME);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700419#endif // VK_USE_PLATFORM_WIN32_KHR
420#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott2c1daf52016-05-12 09:41:46 -0600421#if defined(VK_USE_PLATFORM_XCB_KHR)
422 instance_extension_names.push_back(VK_KHR_XCB_SURFACE_EXTENSION_NAME);
423#elif defined(VK_USE_PLATFORM_XLIB_KHR)
424 instance_extension_names.push_back(VK_KHR_XLIB_SURFACE_EXTENSION_NAME);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700425#endif // VK_USE_PLATFORM_XLIB_KHR
Ian Elliott2c1daf52016-05-12 09:41:46 -0600426 }
427
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600428 this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Tony Barbour300a6082015-04-07 13:44:53 -0600429 this->app_info.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800430 this->app_info.pApplicationName = "layer_tests";
431 this->app_info.applicationVersion = 1;
Tony Barbour300a6082015-04-07 13:44:53 -0600432 this->app_info.pEngineName = "unittest";
433 this->app_info.engineVersion = 1;
Jon Ashburnc5012ff2016-03-22 13:57:46 -0600434 this->app_info.apiVersion = VK_API_VERSION_1_0;
Tony Barbour300a6082015-04-07 13:44:53 -0600435
Tony Barbour15524c32015-04-29 17:34:29 -0600436 m_errorMonitor = new ErrorMonitor;
Tony Barbour300a6082015-04-07 13:44:53 -0600437 }
438
439 virtual void TearDown() {
440 // Clean up resources before we reset
Tony Barbour300a6082015-04-07 13:44:53 -0600441 ShutdownFramework();
Tony Barbour0b4d9562015-04-09 10:48:04 -0600442 delete m_errorMonitor;
Tony Barbour300a6082015-04-07 13:44:53 -0600443 }
Ian Elliott2c1daf52016-05-12 09:41:46 -0600444
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600445 VkLayerTest() { m_enableWSI = false; }
Tony Barbour300a6082015-04-07 13:44:53 -0600446};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500447
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600448void VkLayerTest::VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500449 // Create identity matrix
450 int i;
451 struct vktriangle_vs_uniform data;
452
453 glm::mat4 Projection = glm::mat4(1.0f);
Karl Schultz6addd812016-02-02 17:17:23 -0700454 glm::mat4 View = glm::mat4(1.0f);
455 glm::mat4 Model = glm::mat4(1.0f);
456 glm::mat4 MVP = Projection * View * Model;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500457 const int matrixSize = sizeof(MVP);
Karl Schultz6addd812016-02-02 17:17:23 -0700458 const int bufSize = sizeof(vktriangle_vs_uniform) / sizeof(float);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500459
460 memcpy(&data.mvp, &MVP[0][0], matrixSize);
461
Karl Schultz6addd812016-02-02 17:17:23 -0700462 static const Vertex tri_data[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600463 {XYZ1(-1, -1, 0), XYZ1(1.f, 0.f, 0.f)}, {XYZ1(1, -1, 0), XYZ1(0.f, 1.f, 0.f)}, {XYZ1(0, 1, 0), XYZ1(0.f, 0.f, 1.f)},
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500464 };
465
Karl Schultz6addd812016-02-02 17:17:23 -0700466 for (i = 0; i < 3; i++) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500467 data.position[i][0] = tri_data[i].posX;
468 data.position[i][1] = tri_data[i].posY;
469 data.position[i][2] = tri_data[i].posZ;
470 data.position[i][3] = tri_data[i].posW;
Karl Schultz6addd812016-02-02 17:17:23 -0700471 data.color[i][0] = tri_data[i].r;
472 data.color[i][1] = tri_data[i].g;
473 data.color[i][2] = tri_data[i].b;
474 data.color[i][3] = tri_data[i].a;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500475 }
476
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500477 ASSERT_NO_FATAL_FAILURE(InitViewport());
478
Chris Forbesbcfaadd2016-09-16 14:13:53 +1200479 VkConstantBufferObj constantBuffer(m_device, bufSize * 2, sizeof(float), (const void *)&data,
480 VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500481
Karl Schultz6addd812016-02-02 17:17:23 -0700482 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600483 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500484
485 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +0800486 pipelineobj.AddColorAttachment();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500487 pipelineobj.AddShader(&vs);
488 pipelineobj.AddShader(&ps);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600489 if (failMask & BsoFailLineWidth) {
490 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_LINE_WIDTH);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600491 VkPipelineInputAssemblyStateCreateInfo ia_state = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600492 ia_state.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600493 ia_state.topology = VK_PRIMITIVE_TOPOLOGY_LINE_LIST;
494 pipelineobj.SetInputAssembly(&ia_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600495 }
496 if (failMask & BsoFailDepthBias) {
497 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BIAS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600498 VkPipelineRasterizationStateCreateInfo rs_state = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600499 rs_state.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600500 rs_state.depthBiasEnable = VK_TRUE;
Mark Young7394fdd2016-03-31 14:56:43 -0600501 rs_state.lineWidth = 1.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600502 pipelineobj.SetRasterization(&rs_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600503 }
Rene Lindsayacbf5e62016-12-15 18:47:11 -0700504 // Viewport and scissors must stay in sync or other errors will occur than
Karl Schultz6addd812016-02-02 17:17:23 -0700505 // the ones we want
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600506 if (failMask & BsoFailViewport) {
507 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_VIEWPORT);
508 }
509 if (failMask & BsoFailScissor) {
510 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_SCISSOR);
511 }
512 if (failMask & BsoFailBlend) {
513 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_BLEND_CONSTANTS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600514 VkPipelineColorBlendAttachmentState att_state = {};
515 att_state.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
516 att_state.blendEnable = VK_TRUE;
517 pipelineobj.AddColorAttachment(0, &att_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600518 }
519 if (failMask & BsoFailDepthBounds) {
520 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BOUNDS);
521 }
522 if (failMask & BsoFailStencilReadMask) {
523 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK);
524 }
525 if (failMask & BsoFailStencilWriteMask) {
526 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_WRITE_MASK);
527 }
528 if (failMask & BsoFailStencilReference) {
529 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_REFERENCE);
530 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500531
532 VkDescriptorSetObj descriptorSet(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600533 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, constantBuffer);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500534
535 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour552f6c02016-12-21 14:34:07 -0700536 m_commandBuffer->BeginCommandBuffer();
537 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500538
Tony Barbourfe3351b2015-07-28 10:17:20 -0600539 GenericDrawPreparation(pipelineobj, descriptorSet, failMask);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500540
541 // render triangle
Tobin Ehlis379ba3b2016-07-19 11:22:29 -0600542 if (failMask & BsoFailIndexBuffer) {
543 // Use DrawIndexed w/o an index buffer bound
544 DrawIndexed(3, 1, 0, 0, 0);
545 } else {
546 Draw(3, 1, 0, 0);
547 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500548
Mark Muellerd4914412016-06-13 17:52:06 -0600549 if (failMask & BsoFailCmdClearAttachments) {
550 VkClearAttachment color_attachment = {};
551 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700552 color_attachment.colorAttachment = 1; // Someone who knew what they were doing would use 0 for the index;
Mark Muellerd4914412016-06-13 17:52:06 -0600553 VkClearRect clear_rect = {{{0, 0}, {static_cast<uint32_t>(m_width), static_cast<uint32_t>(m_height)}}, 0, 0};
554
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600555 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Muellerd4914412016-06-13 17:52:06 -0600556 }
557
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500558 // finalize recording of the command buffer
Tony Barbour552f6c02016-12-21 14:34:07 -0700559 m_commandBuffer->EndRenderPass();
560 m_commandBuffer->EndCommandBuffer();
Tony Barbourfe3351b2015-07-28 10:17:20 -0600561 QueueCommandBuffer();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500562}
563
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600564void VkLayerTest::GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj,
565 VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500566 if (m_depthStencil->Initialized()) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600567 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, m_depthStencil);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500568 } else {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600569 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500570 }
571
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800572 commandBuffer->PrepareAttachments();
Karl Schultz6addd812016-02-02 17:17:23 -0700573 // Make sure depthWriteEnable is set so that Depth fail test will work
574 // correctly
575 // Make sure stencilTestEnable is set so that Stencil fail test will work
576 // correctly
Tony Barboureb254902015-07-15 12:50:33 -0600577 VkStencilOpState stencil = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800578 stencil.failOp = VK_STENCIL_OP_KEEP;
579 stencil.passOp = VK_STENCIL_OP_KEEP;
580 stencil.depthFailOp = VK_STENCIL_OP_KEEP;
581 stencil.compareOp = VK_COMPARE_OP_NEVER;
Tony Barboureb254902015-07-15 12:50:33 -0600582
583 VkPipelineDepthStencilStateCreateInfo ds_ci = {};
584 ds_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600585 ds_ci.pNext = NULL;
586 ds_ci.depthTestEnable = VK_FALSE;
587 ds_ci.depthWriteEnable = VK_TRUE;
588 ds_ci.depthCompareOp = VK_COMPARE_OP_NEVER;
589 ds_ci.depthBoundsTestEnable = VK_FALSE;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600590 if (failMask & BsoFailDepthBounds) {
591 ds_ci.depthBoundsTestEnable = VK_TRUE;
Tobin Ehlis21c88352016-05-26 06:15:45 -0600592 ds_ci.maxDepthBounds = 0.0f;
593 ds_ci.minDepthBounds = 0.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600594 }
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600595 ds_ci.stencilTestEnable = VK_TRUE;
596 ds_ci.front = stencil;
597 ds_ci.back = stencil;
Tony Barboureb254902015-07-15 12:50:33 -0600598
Tobin Ehlis4bf96d12015-06-25 11:58:41 -0600599 pipelineobj.SetDepthStencil(&ds_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -0600600 pipelineobj.SetViewport(m_viewports);
601 pipelineobj.SetScissor(m_scissors);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800602 descriptorSet.CreateVKDescriptorSet(commandBuffer);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600603 VkResult err = pipelineobj.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Cody Northrop29a08f22015-08-27 10:20:35 -0600604 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800605 commandBuffer->BindPipeline(pipelineobj);
606 commandBuffer->BindDescriptorSet(descriptorSet);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500607}
608
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600609class VkPositiveLayerTest : public VkLayerTest {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700610 public:
611 protected:
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600612};
613
Ian Elliott2c1daf52016-05-12 09:41:46 -0600614class VkWsiEnabledLayerTest : public VkLayerTest {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700615 public:
616 protected:
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600617 VkWsiEnabledLayerTest() { m_enableWSI = true; }
Ian Elliott2c1daf52016-05-12 09:41:46 -0600618};
619
Mark Muellerdfe37552016-07-07 14:47:42 -0600620class VkBufferTest {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700621 public:
Mark Muellerdfe37552016-07-07 14:47:42 -0600622 enum eTestEnFlags {
623 eDoubleDelete,
624 eInvalidDeviceOffset,
625 eInvalidMemoryOffset,
626 eBindNullBuffer,
627 eFreeInvalidHandle,
Mark Mueller4042b652016-09-05 22:52:21 -0600628 eNone,
Mark Muellerdfe37552016-07-07 14:47:42 -0600629 };
630
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600631 enum eTestConditions { eOffsetAlignment = 1 };
Mark Muellerdfe37552016-07-07 14:47:42 -0600632
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600633 static bool GetTestConditionValid(VkDeviceObj *aVulkanDevice, eTestEnFlags aTestFlag, VkBufferUsageFlags aBufferUsage = 0) {
634 if (eInvalidDeviceOffset != aTestFlag && eInvalidMemoryOffset != aTestFlag) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600635 return true;
636 }
637 VkDeviceSize offset_limit = 0;
638 if (eInvalidMemoryOffset == aTestFlag) {
639 VkBuffer vulkanBuffer;
640 VkBufferCreateInfo buffer_create_info = {};
641 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
642 buffer_create_info.size = 32;
643 buffer_create_info.usage = aBufferUsage;
644
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600645 vkCreateBuffer(aVulkanDevice->device(), &buffer_create_info, nullptr, &vulkanBuffer);
Mark Mueller4042b652016-09-05 22:52:21 -0600646 VkMemoryRequirements memory_reqs = {};
Mark Muellerdfe37552016-07-07 14:47:42 -0600647
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600648 vkGetBufferMemoryRequirements(aVulkanDevice->device(), vulkanBuffer, &memory_reqs);
Mark Muellerdfe37552016-07-07 14:47:42 -0600649 vkDestroyBuffer(aVulkanDevice->device(), vulkanBuffer, nullptr);
650 offset_limit = memory_reqs.alignment;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600651 } else if ((VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT | VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT) & aBufferUsage) {
652 offset_limit = aVulkanDevice->props.limits.minTexelBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600653 } else if (VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT & aBufferUsage) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600654 offset_limit = aVulkanDevice->props.limits.minUniformBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600655 } else if (VK_BUFFER_USAGE_STORAGE_BUFFER_BIT & aBufferUsage) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600656 offset_limit = aVulkanDevice->props.limits.minStorageBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600657 }
658 if (eOffsetAlignment < offset_limit) {
659 return true;
660 }
661 return false;
662 }
663
664 // A constructor which performs validation tests within construction.
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600665 VkBufferTest(VkDeviceObj *aVulkanDevice, VkBufferUsageFlags aBufferUsage, eTestEnFlags aTestFlag = eNone)
666 : AllocateCurrent(false), BoundCurrent(false), CreateCurrent(false), VulkanDevice(aVulkanDevice->device()) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600667 if (eBindNullBuffer == aTestFlag) {
668 VulkanMemory = 0;
669 vkBindBufferMemory(VulkanDevice, VulkanBuffer, VulkanMemory, 0);
670 } else {
671 VkBufferCreateInfo buffer_create_info = {};
672 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
673 buffer_create_info.size = 32;
674 buffer_create_info.usage = aBufferUsage;
675
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600676 vkCreateBuffer(VulkanDevice, &buffer_create_info, nullptr, &VulkanBuffer);
Mark Muellerdfe37552016-07-07 14:47:42 -0600677
678 CreateCurrent = true;
679
680 VkMemoryRequirements memory_requirements;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600681 vkGetBufferMemoryRequirements(VulkanDevice, VulkanBuffer, &memory_requirements);
Mark Muellerdfe37552016-07-07 14:47:42 -0600682
683 VkMemoryAllocateInfo memory_allocate_info = {};
684 memory_allocate_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Cort Stratton77a0d592017-02-17 13:14:13 -0800685 memory_allocate_info.allocationSize = memory_requirements.size + eOffsetAlignment;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600686 bool pass = aVulkanDevice->phy().set_memory_type(memory_requirements.memoryTypeBits, &memory_allocate_info,
687 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Mark Muellerdfe37552016-07-07 14:47:42 -0600688 if (!pass) {
689 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
690 return;
691 }
692
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600693 vkAllocateMemory(VulkanDevice, &memory_allocate_info, NULL, &VulkanMemory);
Mark Muellerdfe37552016-07-07 14:47:42 -0600694 AllocateCurrent = true;
695 // NB: 1 is intentionally an invalid offset value
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600696 const bool offset_en = eInvalidDeviceOffset == aTestFlag || eInvalidMemoryOffset == aTestFlag;
697 vkBindBufferMemory(VulkanDevice, VulkanBuffer, VulkanMemory, offset_en ? eOffsetAlignment : 0);
Mark Muellerdfe37552016-07-07 14:47:42 -0600698 BoundCurrent = true;
699
700 InvalidDeleteEn = (eFreeInvalidHandle == aTestFlag);
701 }
702 }
703
704 ~VkBufferTest() {
705 if (CreateCurrent) {
706 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
707 }
708 if (AllocateCurrent) {
709 if (InvalidDeleteEn) {
710 union {
711 VkDeviceMemory device_memory;
712 unsigned long long index_access;
713 } bad_index;
714
715 bad_index.device_memory = VulkanMemory;
716 bad_index.index_access++;
717
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600718 vkFreeMemory(VulkanDevice, bad_index.device_memory, nullptr);
Mark Muellerdfe37552016-07-07 14:47:42 -0600719 }
720 vkFreeMemory(VulkanDevice, VulkanMemory, nullptr);
721 }
722 }
723
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600724 bool GetBufferCurrent() { return AllocateCurrent && BoundCurrent && CreateCurrent; }
Mark Muellerdfe37552016-07-07 14:47:42 -0600725
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600726 const VkBuffer &GetBuffer() { return VulkanBuffer; }
Mark Muellerdfe37552016-07-07 14:47:42 -0600727
728 void TestDoubleDestroy() {
729 // Destroy the buffer but leave the flag set, which will cause
730 // the buffer to be destroyed again in the destructor.
731 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
732 }
733
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700734 protected:
Mark Muellerdfe37552016-07-07 14:47:42 -0600735 bool AllocateCurrent;
736 bool BoundCurrent;
737 bool CreateCurrent;
738 bool InvalidDeleteEn;
739
740 VkBuffer VulkanBuffer;
741 VkDevice VulkanDevice;
742 VkDeviceMemory VulkanMemory;
Mark Muellerdfe37552016-07-07 14:47:42 -0600743};
744
745class VkVerticesObj {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700746 public:
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600747 VkVerticesObj(VkDeviceObj *aVulkanDevice, unsigned aAttributeCount, unsigned aBindingCount, unsigned aByteStride,
Mark Muellerdfe37552016-07-07 14:47:42 -0600748 VkDeviceSize aVertexCount, const float *aVerticies)
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700749 : BoundCurrent(false),
750 AttributeCount(aAttributeCount),
751 BindingCount(aBindingCount),
752 BindId(BindIdGenerator),
Mark Muellerdfe37552016-07-07 14:47:42 -0600753 PipelineVertexInputStateCreateInfo(),
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600754 VulkanMemoryBuffer(aVulkanDevice, 1, static_cast<int>(aByteStride * aVertexCount),
755 reinterpret_cast<const void *>(aVerticies), VK_BUFFER_USAGE_VERTEX_BUFFER_BIT) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700756 BindIdGenerator++; // NB: This can wrap w/misuse
Mark Muellerdfe37552016-07-07 14:47:42 -0600757
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600758 VertexInputAttributeDescription = new VkVertexInputAttributeDescription[AttributeCount];
759 VertexInputBindingDescription = new VkVertexInputBindingDescription[BindingCount];
Mark Muellerdfe37552016-07-07 14:47:42 -0600760
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600761 PipelineVertexInputStateCreateInfo.pVertexAttributeDescriptions = VertexInputAttributeDescription;
762 PipelineVertexInputStateCreateInfo.vertexAttributeDescriptionCount = AttributeCount;
763 PipelineVertexInputStateCreateInfo.pVertexBindingDescriptions = VertexInputBindingDescription;
764 PipelineVertexInputStateCreateInfo.vertexBindingDescriptionCount = BindingCount;
765 PipelineVertexInputStateCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -0600766
767 unsigned i = 0;
768 do {
769 VertexInputAttributeDescription[i].binding = BindId;
770 VertexInputAttributeDescription[i].location = i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600771 VertexInputAttributeDescription[i].format = VK_FORMAT_R32G32B32_SFLOAT;
772 VertexInputAttributeDescription[i].offset = sizeof(float) * aByteStride;
Mark Muellerdfe37552016-07-07 14:47:42 -0600773 i++;
774 } while (AttributeCount < i);
775
776 i = 0;
777 do {
778 VertexInputBindingDescription[i].binding = BindId;
779 VertexInputBindingDescription[i].stride = aByteStride;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600780 VertexInputBindingDescription[i].inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
Mark Muellerdfe37552016-07-07 14:47:42 -0600781 i++;
782 } while (BindingCount < i);
783 }
784
785 ~VkVerticesObj() {
786 if (VertexInputAttributeDescription) {
787 delete[] VertexInputAttributeDescription;
788 }
789 if (VertexInputBindingDescription) {
790 delete[] VertexInputBindingDescription;
791 }
792 }
793
794 bool AddVertexInputToPipe(VkPipelineObj &aPipelineObj) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600795 aPipelineObj.AddVertexInputAttribs(VertexInputAttributeDescription, AttributeCount);
796 aPipelineObj.AddVertexInputBindings(VertexInputBindingDescription, BindingCount);
Mark Muellerdfe37552016-07-07 14:47:42 -0600797 return true;
798 }
799
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600800 void BindVertexBuffers(VkCommandBuffer aCommandBuffer, unsigned aOffsetCount = 0, VkDeviceSize *aOffsetList = nullptr) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600801 VkDeviceSize *offsetList;
802 unsigned offsetCount;
803
804 if (aOffsetCount) {
805 offsetList = aOffsetList;
806 offsetCount = aOffsetCount;
807 } else {
808 offsetList = new VkDeviceSize[1]();
809 offsetCount = 1;
810 }
811
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600812 vkCmdBindVertexBuffers(aCommandBuffer, BindId, offsetCount, &VulkanMemoryBuffer.handle(), offsetList);
Mark Muellerdfe37552016-07-07 14:47:42 -0600813 BoundCurrent = true;
814
815 if (!aOffsetCount) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600816 delete[] offsetList;
Mark Muellerdfe37552016-07-07 14:47:42 -0600817 }
818 }
819
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700820 protected:
Mark Muellerdfe37552016-07-07 14:47:42 -0600821 static uint32_t BindIdGenerator;
822
823 bool BoundCurrent;
824 unsigned AttributeCount;
825 unsigned BindingCount;
826 uint32_t BindId;
827
828 VkPipelineVertexInputStateCreateInfo PipelineVertexInputStateCreateInfo;
829 VkVertexInputAttributeDescription *VertexInputAttributeDescription;
830 VkVertexInputBindingDescription *VertexInputBindingDescription;
831 VkConstantBufferObj VulkanMemoryBuffer;
832};
833
834uint32_t VkVerticesObj::BindIdGenerator;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500835// ********************************************************************************************************************
836// ********************************************************************************************************************
837// ********************************************************************************************************************
838// ********************************************************************************************************************
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600839TEST_F(VkLayerTest, RequiredParameter) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700840 TEST_DESCRIPTION(
841 "Specify VK_NULL_HANDLE, NULL, and 0 for required handle, "
842 "pointer, array, and array count parameters");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600843
Tony Barbour1fa09702017-03-16 12:09:08 -0600844 ASSERT_NO_FATAL_FAILURE(Init());
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600845
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600846 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pFeatures specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600847 // Specify NULL for a pointer to a handle
848 // Expected to trigger an error with
849 // parameter_validation::validate_required_pointer
850 vkGetPhysicalDeviceFeatures(gpu(), NULL);
851 m_errorMonitor->VerifyFound();
852
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600853 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
854 "required parameter pQueueFamilyPropertyCount specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600855 // Specify NULL for pointer to array count
856 // Expected to trigger an error with parameter_validation::validate_array
Dustin Gravesa4bb8c12016-05-16 17:22:51 -0600857 vkGetPhysicalDeviceQueueFamilyProperties(gpu(), NULL, NULL);
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600858 m_errorMonitor->VerifyFound();
859
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600860 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter viewportCount must be greater than 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600861 // Specify 0 for a required array count
862 // Expected to trigger an error with parameter_validation::validate_array
863 VkViewport view_port = {};
864 m_commandBuffer->SetViewport(0, 0, &view_port);
865 m_errorMonitor->VerifyFound();
866
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600867 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pViewports specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600868 // Specify NULL for a required array
869 // Expected to trigger an error with parameter_validation::validate_array
870 m_commandBuffer->SetViewport(0, 1, NULL);
871 m_errorMonitor->VerifyFound();
872
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600873 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter memory specified as VK_NULL_HANDLE");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600874 // Specify VK_NULL_HANDLE for a required handle
875 // Expected to trigger an error with
876 // parameter_validation::validate_required_handle
877 vkUnmapMemory(device(), VK_NULL_HANDLE);
878 m_errorMonitor->VerifyFound();
879
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600880 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
881 "required parameter pFences[0] specified as VK_NULL_HANDLE");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600882 // Specify VK_NULL_HANDLE for a required handle array entry
883 // Expected to trigger an error with
884 // parameter_validation::validate_required_handle_array
885 VkFence fence = VK_NULL_HANDLE;
886 vkResetFences(device(), 1, &fence);
887 m_errorMonitor->VerifyFound();
888
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600889 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pAllocateInfo specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600890 // Specify NULL for a required struct pointer
891 // Expected to trigger an error with
892 // parameter_validation::validate_struct_type
893 VkDeviceMemory memory = VK_NULL_HANDLE;
894 vkAllocateMemory(device(), NULL, NULL, &memory);
895 m_errorMonitor->VerifyFound();
896
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600897 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "value of faceMask must not be 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600898 // Specify 0 for a required VkFlags parameter
899 // Expected to trigger an error with parameter_validation::validate_flags
900 m_commandBuffer->SetStencilReference(0, 0);
901 m_errorMonitor->VerifyFound();
902
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600903 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "value of pSubmits[0].pWaitDstStageMask[0] must not be 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600904 // Specify 0 for a required VkFlags array entry
905 // Expected to trigger an error with
906 // parameter_validation::validate_flags_array
907 VkSemaphore semaphore = VK_NULL_HANDLE;
908 VkPipelineStageFlags stageFlags = 0;
909 VkSubmitInfo submitInfo = {};
910 submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
911 submitInfo.waitSemaphoreCount = 1;
912 submitInfo.pWaitSemaphores = &semaphore;
913 submitInfo.pWaitDstStageMask = &stageFlags;
914 vkQueueSubmit(m_device->m_queue, 1, &submitInfo, VK_NULL_HANDLE);
915 m_errorMonitor->VerifyFound();
916}
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600917
Dustin Gravesfce74c02016-05-10 11:42:58 -0600918TEST_F(VkLayerTest, ReservedParameter) {
919 TEST_DESCRIPTION("Specify a non-zero value for a reserved parameter");
920
Tony Barbour1fa09702017-03-16 12:09:08 -0600921 ASSERT_NO_FATAL_FAILURE(Init());
Dustin Gravesfce74c02016-05-10 11:42:58 -0600922
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600923 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " must be 0");
Dustin Gravesfce74c02016-05-10 11:42:58 -0600924 // Specify 0 for a reserved VkFlags parameter
925 // Expected to trigger an error with
926 // parameter_validation::validate_reserved_flags
927 VkEvent event_handle = VK_NULL_HANDLE;
928 VkEventCreateInfo event_info = {};
929 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
930 event_info.flags = 1;
931 vkCreateEvent(device(), &event_info, NULL, &event_handle);
932 m_errorMonitor->VerifyFound();
933}
934
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600935TEST_F(VkLayerTest, InvalidStructSType) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700936 TEST_DESCRIPTION(
937 "Specify an invalid VkStructureType for a Vulkan "
938 "structure's sType field");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600939
Tony Barbour1fa09702017-03-16 12:09:08 -0600940 ASSERT_NO_FATAL_FAILURE(Init());
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600941
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600942 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pAllocateInfo->sType must be");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600943 // Zero struct memory, effectively setting sType to
944 // VK_STRUCTURE_TYPE_APPLICATION_INFO
945 // Expected to trigger an error with
946 // parameter_validation::validate_struct_type
947 VkMemoryAllocateInfo alloc_info = {};
948 VkDeviceMemory memory = VK_NULL_HANDLE;
949 vkAllocateMemory(device(), &alloc_info, NULL, &memory);
950 m_errorMonitor->VerifyFound();
951
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600952 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pSubmits[0].sType must be");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600953 // Zero struct memory, effectively setting sType to
954 // VK_STRUCTURE_TYPE_APPLICATION_INFO
955 // Expected to trigger an error with
956 // parameter_validation::validate_struct_type_array
957 VkSubmitInfo submit_info = {};
958 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
959 m_errorMonitor->VerifyFound();
960}
961
962TEST_F(VkLayerTest, InvalidStructPNext) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600963 TEST_DESCRIPTION("Specify an invalid value for a Vulkan structure's pNext field");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600964
Tony Barbour1fa09702017-03-16 12:09:08 -0600965 ASSERT_NO_FATAL_FAILURE(Init());
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600966
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600967 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "value of pCreateInfo->pNext must be NULL");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600968 // Set VkMemoryAllocateInfo::pNext to a non-NULL value, when pNext must be NULL.
Karl Schultz38b50992016-07-11 16:09:09 -0600969 // Need to pick a function that has no allowed pNext structure types.
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600970 // Expected to trigger an error with parameter_validation::validate_struct_pnext
Karl Schultz38b50992016-07-11 16:09:09 -0600971 VkEvent event = VK_NULL_HANDLE;
Karl Schultz70db3902016-07-11 16:22:10 -0600972 VkEventCreateInfo event_alloc_info = {};
Karl Schultz38b50992016-07-11 16:09:09 -0600973 // Zero-initialization will provide the correct sType
974 VkApplicationInfo app_info = {};
975 event_alloc_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
976 event_alloc_info.pNext = &app_info;
977 vkCreateEvent(device(), &event_alloc_info, NULL, &event);
978 m_errorMonitor->VerifyFound();
979
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600980 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
981 " chain includes a structure with unexpected VkStructureType ");
Karl Schultz38b50992016-07-11 16:09:09 -0600982 // Set VkMemoryAllocateInfo::pNext to a non-NULL value, but use
983 // a function that has allowed pNext structure types and specify
984 // a structure type that is not allowed.
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600985 // Expected to trigger an error with parameter_validation::validate_struct_pnext
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600986 VkDeviceMemory memory = VK_NULL_HANDLE;
Dustin Graves47b6cba2016-05-10 17:34:38 -0600987 VkMemoryAllocateInfo memory_alloc_info = {};
988 memory_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
989 memory_alloc_info.pNext = &app_info;
990 vkAllocateMemory(device(), &memory_alloc_info, NULL, &memory);
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600991 m_errorMonitor->VerifyFound();
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600992}
Dustin Graves5d33d532016-05-09 16:21:12 -0600993
994TEST_F(VkLayerTest, UnrecognizedValue) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600995 TEST_DESCRIPTION("Specify unrecognized Vulkan enumeration, flags, and VkBool32 values");
Dustin Graves5d33d532016-05-09 16:21:12 -0600996
Tony Barbour1fa09702017-03-16 12:09:08 -0600997 ASSERT_NO_FATAL_FAILURE(Init());
Dustin Graves5d33d532016-05-09 16:21:12 -0600998
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700999 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1000 "does not fall within the begin..end "
1001 "range of the core VkFormat "
1002 "enumeration tokens");
Dustin Graves5d33d532016-05-09 16:21:12 -06001003 // Specify an invalid VkFormat value
1004 // Expected to trigger an error with
1005 // parameter_validation::validate_ranged_enum
1006 VkFormatProperties format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001007 vkGetPhysicalDeviceFormatProperties(gpu(), static_cast<VkFormat>(8000), &format_properties);
Dustin Graves5d33d532016-05-09 16:21:12 -06001008 m_errorMonitor->VerifyFound();
1009
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001010 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "contains flag bits that are not recognized members of");
Dustin Graves5d33d532016-05-09 16:21:12 -06001011 // Specify an invalid VkFlags bitmask value
1012 // Expected to trigger an error with parameter_validation::validate_flags
1013 VkImageFormatProperties image_format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001014 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
1015 static_cast<VkImageUsageFlags>(1 << 25), 0, &image_format_properties);
Dustin Graves5d33d532016-05-09 16:21:12 -06001016 m_errorMonitor->VerifyFound();
1017
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001018 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "contains flag bits that are not recognized members of");
Dustin Graves5d33d532016-05-09 16:21:12 -06001019 // Specify an invalid VkFlags array entry
1020 // Expected to trigger an error with
1021 // parameter_validation::validate_flags_array
1022 VkSemaphore semaphore = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001023 VkPipelineStageFlags stage_flags = static_cast<VkPipelineStageFlags>(1 << 25);
Dustin Graves5d33d532016-05-09 16:21:12 -06001024 VkSubmitInfo submit_info = {};
1025 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1026 submit_info.waitSemaphoreCount = 1;
1027 submit_info.pWaitSemaphores = &semaphore;
1028 submit_info.pWaitDstStageMask = &stage_flags;
1029 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
1030 m_errorMonitor->VerifyFound();
1031
Cort Strattonedbe9b82017-05-16 07:38:35 -07001032 // Sneak in a test to make sure using VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE
1033 // doesn't trigger a false positive.
1034 uint32_t extension_count = 0;
1035 bool supports_mirror_clamp = false;
1036 VkResult err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, nullptr);
1037 ASSERT_VK_SUCCESS(err);
1038 if (extension_count > 0) {
1039 std::vector<VkExtensionProperties> available_extensions(extension_count);
1040
1041 err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, &available_extensions[0]);
1042 ASSERT_VK_SUCCESS(err);
1043 for (const auto &extension_props : available_extensions) {
1044 if (strcmp(extension_props.extensionName, VK_KHR_SAMPLER_MIRROR_CLAMP_TO_EDGE_EXTENSION_NAME) == 0) {
1045 supports_mirror_clamp = true;
1046 }
1047 }
1048 }
1049 VkSamplerAddressMode address_mode = VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE;
1050 if (!supports_mirror_clamp) {
1051 printf(" mirror_clamp_to_edge Extension not supported, skipping tests\n");
1052 address_mode = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1053 return;
1054 }
1055
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001056 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "is neither VK_TRUE nor VK_FALSE");
Dustin Graves5d33d532016-05-09 16:21:12 -06001057 // Specify an invalid VkBool32 value
1058 // Expected to trigger a warning with
1059 // parameter_validation::validate_bool32
1060 VkSampler sampler = VK_NULL_HANDLE;
1061 VkSamplerCreateInfo sampler_info = {};
1062 sampler_info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
1063 sampler_info.pNext = NULL;
1064 sampler_info.magFilter = VK_FILTER_NEAREST;
1065 sampler_info.minFilter = VK_FILTER_NEAREST;
1066 sampler_info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
Cort Strattonedbe9b82017-05-16 07:38:35 -07001067 sampler_info.addressModeU = address_mode;
1068 sampler_info.addressModeV = address_mode;
1069 sampler_info.addressModeW = address_mode;
Dustin Graves5d33d532016-05-09 16:21:12 -06001070 sampler_info.mipLodBias = 1.0;
1071 sampler_info.maxAnisotropy = 1;
1072 sampler_info.compareEnable = VK_FALSE;
1073 sampler_info.compareOp = VK_COMPARE_OP_NEVER;
1074 sampler_info.minLod = 1.0;
1075 sampler_info.maxLod = 1.0;
1076 sampler_info.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
1077 sampler_info.unnormalizedCoordinates = VK_FALSE;
1078 // Not VK_TRUE or VK_FALSE
1079 sampler_info.anisotropyEnable = 3;
1080 vkCreateSampler(m_device->device(), &sampler_info, NULL, &sampler);
1081 m_errorMonitor->VerifyFound();
Cort Strattonedbe9b82017-05-16 07:38:35 -07001082
1083 // Specify MAX_ENUM
1084 VkDescriptorSetLayoutBinding binding = {};
1085 binding.binding = 0;
1086 binding.descriptorType = VK_DESCRIPTOR_TYPE_MAX_ENUM;
1087 binding.descriptorCount = 1;
1088 binding.stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
1089 VkDescriptorSetLayoutCreateInfo layout_ci = {};
1090 layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1091 layout_ci.bindingCount = 1;
1092 layout_ci.pBindings = &binding;
1093 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "does not fall within the begin..end range");
1094 VkDescriptorSetLayout layout = VK_NULL_HANDLE;
1095 vkCreateDescriptorSetLayout(device(), &layout_ci, NULL, &layout);
1096 m_errorMonitor->VerifyFound();
1097 if (layout != VK_NULL_HANDLE) {
1098 vkDestroyDescriptorSetLayout(device(), layout, NULL);
1099 }
Dustin Graves5d33d532016-05-09 16:21:12 -06001100}
Dustin Gravesfce74c02016-05-10 11:42:58 -06001101
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001102TEST_F(VkLayerTest, UpdateBufferAlignment) {
1103 TEST_DESCRIPTION("Check alignment parameters for vkCmdUpdateBuffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001104 uint32_t updateData[] = {1, 2, 3, 4, 5, 6, 7, 8};
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001105
Tony Barbour1fa09702017-03-16 12:09:08 -06001106 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001107
1108 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1109 vk_testing::Buffer buffer;
1110 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
1111
Tony Barbour552f6c02016-12-21 14:34:07 -07001112 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001113 // Introduce failure by using dstOffset that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001114 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001115 m_commandBuffer->UpdateBuffer(buffer.handle(), 1, 4, updateData);
1116 m_errorMonitor->VerifyFound();
1117
1118 // Introduce failure by using dataSize that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001119 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001120 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 6, updateData);
1121 m_errorMonitor->VerifyFound();
1122
1123 // Introduce failure by using dataSize that is < 0
1124 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001125 "must be greater than zero and less than or equal to 65536");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001126 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, -44, updateData);
1127 m_errorMonitor->VerifyFound();
1128
1129 // Introduce failure by using dataSize that is > 65536
1130 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001131 "must be greater than zero and less than or equal to 65536");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001132 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 80000, updateData);
1133 m_errorMonitor->VerifyFound();
1134
Tony Barbour552f6c02016-12-21 14:34:07 -07001135 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001136}
1137
1138TEST_F(VkLayerTest, FillBufferAlignment) {
1139 TEST_DESCRIPTION("Check alignment parameters for vkCmdFillBuffer");
1140
Tony Barbour1fa09702017-03-16 12:09:08 -06001141 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001142
1143 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1144 vk_testing::Buffer buffer;
1145 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
1146
Tony Barbour552f6c02016-12-21 14:34:07 -07001147 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001148
1149 // Introduce failure by using dstOffset that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001150 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001151 m_commandBuffer->FillBuffer(buffer.handle(), 1, 4, 0x11111111);
1152 m_errorMonitor->VerifyFound();
1153
1154 // Introduce failure by using size that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001155 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001156 m_commandBuffer->FillBuffer(buffer.handle(), 0, 6, 0x11111111);
1157 m_errorMonitor->VerifyFound();
1158
1159 // Introduce failure by using size that is zero
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001160 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must be greater than zero");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001161 m_commandBuffer->FillBuffer(buffer.handle(), 0, 0, 0x11111111);
1162 m_errorMonitor->VerifyFound();
1163
Tony Barbour552f6c02016-12-21 14:34:07 -07001164 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001165}
Dustin Graves40f35822016-06-23 11:12:53 -06001166
Cortd889ff92016-07-27 09:51:27 -07001167TEST_F(VkLayerTest, PSOPolygonModeInvalid) {
1168 VkResult err;
1169
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001170 TEST_DESCRIPTION(
1171 "Attempt to use a non-solid polygon fill mode in a "
1172 "pipeline when this feature is not enabled.");
Cortd889ff92016-07-27 09:51:27 -07001173
Tony Barbour1fa09702017-03-16 12:09:08 -06001174 ASSERT_NO_FATAL_FAILURE(Init());
Cortd889ff92016-07-27 09:51:27 -07001175 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1176
1177 std::vector<const char *> device_extension_names;
1178 auto features = m_device->phy().features();
1179 // Artificially disable support for non-solid fill modes
Chris Forbes05054022017-05-17 16:29:06 -07001180 features.fillModeNonSolid = VK_FALSE;
Cortd889ff92016-07-27 09:51:27 -07001181 // The sacrificial device object
1182 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
1183
1184 VkRenderpassObj render_pass(&test_device);
1185
1186 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1187 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1188 pipeline_layout_ci.setLayoutCount = 0;
1189 pipeline_layout_ci.pSetLayouts = NULL;
1190
1191 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001192 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Cortd889ff92016-07-27 09:51:27 -07001193 ASSERT_VK_SUCCESS(err);
1194
1195 VkPipelineRasterizationStateCreateInfo rs_ci = {};
1196 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
1197 rs_ci.pNext = nullptr;
1198 rs_ci.lineWidth = 1.0f;
Chris Forbes05054022017-05-17 16:29:06 -07001199 rs_ci.rasterizerDiscardEnable = VK_TRUE;
Cortd889ff92016-07-27 09:51:27 -07001200
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001201 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
1202 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Cortd889ff92016-07-27 09:51:27 -07001203
Mark Lobodzinski5e644732016-08-15 16:51:19 -06001204 // Set polygonMode to unsupported value POINT, should fail
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001205 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1206 "polygonMode cannot be VK_POLYGON_MODE_POINT or VK_POLYGON_MODE_LINE");
Cortd889ff92016-07-27 09:51:27 -07001207 {
1208 VkPipelineObj pipe(&test_device);
1209 pipe.AddShader(&vs);
1210 pipe.AddShader(&fs);
1211 pipe.AddColorAttachment();
1212 // Introduce failure by setting unsupported polygon mode
1213 rs_ci.polygonMode = VK_POLYGON_MODE_POINT;
1214 pipe.SetRasterization(&rs_ci);
1215 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
1216 }
1217 m_errorMonitor->VerifyFound();
1218
1219 // Try again with polygonMode=LINE, 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_LINE;
1229 pipe.SetRasterization(&rs_ci);
1230 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
1231 }
1232 m_errorMonitor->VerifyFound();
1233
Cortd889ff92016-07-27 09:51:27 -07001234 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
1235}
1236
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001237#if 0
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001238TEST_F(VkLayerTest, CallResetCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001239{
1240 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001241 VkFenceCreateInfo fenceInfo = {};
1242 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1243 fenceInfo.pNext = NULL;
1244 fenceInfo.flags = 0;
1245
Mike Weiblencce7ec72016-10-17 19:33:05 -06001246 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Resetting command buffer");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001247
Tony Barbour1fa09702017-03-16 12:09:08 -06001248 ASSERT_NO_FATAL_FAILURE(Init());
Tony Barbourc1eb1a52015-07-20 13:00:10 -06001249
1250 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1251 vk_testing::Buffer buffer;
1252 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001253
Tony Barbourfe3351b2015-07-28 10:17:20 -06001254 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001255 m_commandBuffer->FillBuffer(buffer.handle(), 0, 4, 0x11111111);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001256 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001257
1258 testFence.init(*m_device, fenceInfo);
1259
1260 // Bypass framework since it does the waits automatically
1261 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001262 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001263 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1264 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001265 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001266 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001267 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001268 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001269 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001270 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001271 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001272
1273 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001274 ASSERT_VK_SUCCESS( err );
1275
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001276 // Introduce failure by calling begin again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001277 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001278
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001279 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001280}
1281
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001282TEST_F(VkLayerTest, CallBeginCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001283{
1284 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001285 VkFenceCreateInfo fenceInfo = {};
1286 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1287 fenceInfo.pNext = NULL;
1288 fenceInfo.flags = 0;
1289
Mike Weiblencce7ec72016-10-17 19:33:05 -06001290 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Calling vkBeginCommandBuffer() on active command buffer");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001291
Tony Barbour1fa09702017-03-16 12:09:08 -06001292 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001293 ASSERT_NO_FATAL_FAILURE(InitViewport());
1294 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1295
Tony Barbourfe3351b2015-07-28 10:17:20 -06001296 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001297 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001298 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001299
1300 testFence.init(*m_device, fenceInfo);
1301
1302 // Bypass framework since it does the waits automatically
1303 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001304 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001305 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1306 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001307 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001308 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001309 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001310 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001311 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001312 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001313 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001314
1315 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001316 ASSERT_VK_SUCCESS( err );
1317
Jon Ashburnf19916e2016-01-11 13:12:43 -07001318 VkCommandBufferInheritanceInfo hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001319 VkCommandBufferBeginInfo info = {};
1320 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
1321 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001322 info.renderPass = VK_NULL_HANDLE;
1323 info.subpass = 0;
1324 info.framebuffer = VK_NULL_HANDLE;
Chia-I Wub8d47ae2015-11-11 10:18:12 +08001325 info.occlusionQueryEnable = VK_FALSE;
1326 info.queryFlags = 0;
1327 info.pipelineStatistics = 0;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001328
1329 // Introduce failure by calling BCB again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001330 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001331
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001332 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001333}
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001334#endif
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001335
Mark Lobodzinski833bb552016-12-15 07:41:13 -07001336TEST_F(VkLayerTest, SparseBindingImageBufferCreate) {
1337 TEST_DESCRIPTION("Create buffer/image with sparse attributes but without the sparse_binding bit set");
1338
Tony Barbour1fa09702017-03-16 12:09:08 -06001339 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski833bb552016-12-15 07:41:13 -07001340
1341 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00669);
1342 VkBuffer buffer;
1343 VkBufferCreateInfo buf_info = {};
1344 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1345 buf_info.pNext = NULL;
1346 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
1347 buf_info.size = 2048;
1348 buf_info.queueFamilyIndexCount = 0;
1349 buf_info.pQueueFamilyIndices = NULL;
1350 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1351 buf_info.flags = VK_BUFFER_CREATE_SPARSE_RESIDENCY_BIT;
1352 vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1353 m_errorMonitor->VerifyFound();
1354
1355 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02160);
1356 VkImage image;
1357 VkImageCreateInfo image_create_info = {};
1358 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1359 image_create_info.pNext = NULL;
1360 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1361 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1362 image_create_info.extent.width = 512;
1363 image_create_info.extent.height = 64;
1364 image_create_info.extent.depth = 1;
1365 image_create_info.mipLevels = 1;
1366 image_create_info.arrayLayers = 1;
1367 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1368 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
1369 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1370 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1371 image_create_info.queueFamilyIndexCount = 0;
1372 image_create_info.pQueueFamilyIndices = NULL;
1373 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1374 image_create_info.flags = VK_BUFFER_CREATE_SPARSE_ALIASED_BIT;
1375 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1376 m_errorMonitor->VerifyFound();
1377}
1378
Dave Houlton829c0d82017-01-24 15:09:17 -07001379TEST_F(VkLayerTest, SparseResidencyImageCreateUnsupportedTypes) {
1380 TEST_DESCRIPTION("Create images with sparse residency with unsupported types");
1381
1382 // Determine which device feature are available
Dave Houlton0ba0fdf2017-03-29 12:05:26 -06001383 VkPhysicalDeviceFeatures device_features = {};
Dave Houlton8e0fe7a2017-03-30 10:32:10 -06001384 ASSERT_NO_FATAL_FAILURE(
1385 InitFramework(instance_layer_names, instance_extension_names, device_extension_names, myDbgFunc, m_errorMonitor));
Dave Houlton0ba0fdf2017-03-29 12:05:26 -06001386 ASSERT_NO_FATAL_FAILURE(GetPhysicalDeviceFeatures(&device_features));
Dave Houlton829c0d82017-01-24 15:09:17 -07001387
Dave Houlton8e0fe7a2017-03-30 10:32:10 -06001388 // Mask out device features we don't want and initialize device state
Dave Houlton0ba0fdf2017-03-29 12:05:26 -06001389 device_features.sparseResidencyImage2D = VK_FALSE;
1390 device_features.sparseResidencyImage3D = VK_FALSE;
Dave Houlton8e0fe7a2017-03-30 10:32:10 -06001391 ASSERT_NO_FATAL_FAILURE(InitState(&device_features));
Dave Houlton829c0d82017-01-24 15:09:17 -07001392
1393 VkImage image = VK_NULL_HANDLE;
1394 VkResult result = VK_RESULT_MAX_ENUM;
1395 VkImageCreateInfo image_create_info = {};
1396 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1397 image_create_info.pNext = NULL;
1398 image_create_info.imageType = VK_IMAGE_TYPE_1D;
1399 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1400 image_create_info.extent.width = 512;
1401 image_create_info.extent.height = 1;
1402 image_create_info.extent.depth = 1;
1403 image_create_info.mipLevels = 1;
1404 image_create_info.arrayLayers = 1;
1405 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1406 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
1407 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1408 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1409 image_create_info.queueFamilyIndexCount = 0;
1410 image_create_info.pQueueFamilyIndices = NULL;
1411 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1412 image_create_info.flags = VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT | VK_BUFFER_CREATE_SPARSE_BINDING_BIT;
1413
1414 // 1D image w/ sparse residency is an error
1415 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02352);
1416 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1417 m_errorMonitor->VerifyFound();
1418 if (VK_SUCCESS == result) {
1419 vkDestroyImage(m_device->device(), image, NULL);
1420 image = VK_NULL_HANDLE;
1421 }
1422
1423 // 2D image w/ sparse residency when feature isn't available
1424 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1425 image_create_info.extent.height = 64;
1426 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02144);
1427 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1428 m_errorMonitor->VerifyFound();
1429 if (VK_SUCCESS == result) {
1430 vkDestroyImage(m_device->device(), image, NULL);
1431 image = VK_NULL_HANDLE;
1432 }
1433
1434 // 3D image w/ sparse residency when feature isn't available
1435 image_create_info.imageType = VK_IMAGE_TYPE_3D;
1436 image_create_info.extent.depth = 8;
1437 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02145);
1438 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1439 m_errorMonitor->VerifyFound();
1440 if (VK_SUCCESS == result) {
1441 vkDestroyImage(m_device->device(), image, NULL);
1442 image = VK_NULL_HANDLE;
1443 }
1444}
1445
1446TEST_F(VkLayerTest, SparseResidencyImageCreateUnsupportedSamples) {
1447 TEST_DESCRIPTION("Create images with sparse residency with unsupported tiling or sample counts");
1448
1449 // Determine which device feature are available
Dave Houlton0ba0fdf2017-03-29 12:05:26 -06001450 VkPhysicalDeviceFeatures device_features = {};
Dave Houlton8e0fe7a2017-03-30 10:32:10 -06001451 ASSERT_NO_FATAL_FAILURE(
1452 InitFramework(instance_layer_names, instance_extension_names, device_extension_names, myDbgFunc, m_errorMonitor));
Dave Houlton0ba0fdf2017-03-29 12:05:26 -06001453 ASSERT_NO_FATAL_FAILURE(GetPhysicalDeviceFeatures(&device_features));
Dave Houlton829c0d82017-01-24 15:09:17 -07001454
Dave Houlton0ba0fdf2017-03-29 12:05:26 -06001455 // These tests require that the device support sparse residency for 2D images
1456 if (VK_TRUE != device_features.sparseResidencyImage2D) {
1457 printf(" Test requires unsupported SparseResidencyImage2D feature. Skipped.\n");
Dave Houlton829c0d82017-01-24 15:09:17 -07001458 return;
1459 }
1460
Dave Houlton8e0fe7a2017-03-30 10:32:10 -06001461 // Mask out device features we don't want and initialize device state
Dave Houlton0ba0fdf2017-03-29 12:05:26 -06001462 device_features.sparseResidency2Samples = VK_FALSE;
1463 device_features.sparseResidency4Samples = VK_FALSE;
1464 device_features.sparseResidency8Samples = VK_FALSE;
1465 device_features.sparseResidency16Samples = VK_FALSE;
Dave Houlton8e0fe7a2017-03-30 10:32:10 -06001466 ASSERT_NO_FATAL_FAILURE(InitState(&device_features));
Dave Houlton829c0d82017-01-24 15:09:17 -07001467
1468 VkImage image = VK_NULL_HANDLE;
1469 VkResult result = VK_RESULT_MAX_ENUM;
1470 VkImageCreateInfo image_create_info = {};
1471 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1472 image_create_info.pNext = NULL;
1473 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1474 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1475 image_create_info.extent.width = 64;
1476 image_create_info.extent.height = 64;
1477 image_create_info.extent.depth = 1;
1478 image_create_info.mipLevels = 1;
1479 image_create_info.arrayLayers = 1;
1480 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1481 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1482 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1483 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1484 image_create_info.queueFamilyIndexCount = 0;
1485 image_create_info.pQueueFamilyIndices = NULL;
1486 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1487 image_create_info.flags = VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT | VK_BUFFER_CREATE_SPARSE_BINDING_BIT;
1488
1489 // 2D image w/ sparse residency and linear tiling is an error
1490 m_errorMonitor->SetDesiredFailureMsg(
1491 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1492 "VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT then image tiling of VK_IMAGE_TILING_LINEAR is not supported");
1493 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1494 m_errorMonitor->VerifyFound();
1495 if (VK_SUCCESS == result) {
1496 vkDestroyImage(m_device->device(), image, NULL);
1497 image = VK_NULL_HANDLE;
1498 }
1499 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
1500
1501 // Multi-sample image w/ sparse residency when feature isn't available (4 flavors)
1502 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
1503 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02146);
1504 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1505 m_errorMonitor->VerifyFound();
1506 if (VK_SUCCESS == result) {
1507 vkDestroyImage(m_device->device(), image, NULL);
1508 image = VK_NULL_HANDLE;
1509 }
1510
1511 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
1512 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02147);
1513 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1514 m_errorMonitor->VerifyFound();
1515 if (VK_SUCCESS == result) {
1516 vkDestroyImage(m_device->device(), image, NULL);
1517 image = VK_NULL_HANDLE;
1518 }
1519
1520 image_create_info.samples = VK_SAMPLE_COUNT_8_BIT;
1521 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02148);
1522 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1523 m_errorMonitor->VerifyFound();
1524 if (VK_SUCCESS == result) {
1525 vkDestroyImage(m_device->device(), image, NULL);
1526 image = VK_NULL_HANDLE;
1527 }
1528
1529 image_create_info.samples = VK_SAMPLE_COUNT_16_BIT;
1530 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02149);
1531 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1532 m_errorMonitor->VerifyFound();
1533 if (VK_SUCCESS == result) {
1534 vkDestroyImage(m_device->device(), image, NULL);
1535 image = VK_NULL_HANDLE;
1536 }
1537}
1538
Tobin Ehlisf11be982016-05-11 13:52:53 -06001539TEST_F(VkLayerTest, InvalidMemoryAliasing) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001540 TEST_DESCRIPTION(
1541 "Create a buffer and image, allocate memory, and bind the "
1542 "buffer and image to memory such that they will alias.");
Tobin Ehlisf11be982016-05-11 13:52:53 -06001543 VkResult err;
1544 bool pass;
Tony Barbour1fa09702017-03-16 12:09:08 -06001545 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisf11be982016-05-11 13:52:53 -06001546
Tobin Ehlis077ded32016-05-12 17:39:13 -06001547 VkBuffer buffer, buffer2;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001548 VkImage image;
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001549 VkImage image2;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001550 VkDeviceMemory mem; // buffer will be bound first
1551 VkDeviceMemory mem_img; // image bound first
Tobin Ehlis077ded32016-05-12 17:39:13 -06001552 VkMemoryRequirements buff_mem_reqs, img_mem_reqs;
Rene Lindsayd14f5572016-12-16 14:57:18 -07001553 VkMemoryRequirements buff_mem_reqs2, img_mem_reqs2;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001554
1555 VkBufferCreateInfo buf_info = {};
1556 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1557 buf_info.pNext = NULL;
1558 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1559 buf_info.size = 256;
1560 buf_info.queueFamilyIndexCount = 0;
1561 buf_info.pQueueFamilyIndices = NULL;
1562 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1563 buf_info.flags = 0;
1564 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1565 ASSERT_VK_SUCCESS(err);
1566
Tobin Ehlis077ded32016-05-12 17:39:13 -06001567 vkGetBufferMemoryRequirements(m_device->device(), buffer, &buff_mem_reqs);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001568
1569 VkImageCreateInfo image_create_info = {};
1570 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1571 image_create_info.pNext = NULL;
1572 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1573 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1574 image_create_info.extent.width = 64;
1575 image_create_info.extent.height = 64;
1576 image_create_info.extent.depth = 1;
1577 image_create_info.mipLevels = 1;
1578 image_create_info.arrayLayers = 1;
1579 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis12a4b5e2016-08-08 12:33:11 -06001580 // Image tiling must be optimal to trigger error when aliasing linear buffer
1581 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001582 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1583 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1584 image_create_info.queueFamilyIndexCount = 0;
1585 image_create_info.pQueueFamilyIndices = NULL;
1586 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1587 image_create_info.flags = 0;
1588
Tobin Ehlisf11be982016-05-11 13:52:53 -06001589 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1590 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001591 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
1592 ASSERT_VK_SUCCESS(err);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001593
Tobin Ehlis077ded32016-05-12 17:39:13 -06001594 vkGetImageMemoryRequirements(m_device->device(), image, &img_mem_reqs);
1595
1596 VkMemoryAllocateInfo alloc_info = {};
1597 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1598 alloc_info.pNext = NULL;
1599 alloc_info.memoryTypeIndex = 0;
1600 // Ensure memory is big enough for both bindings
1601 alloc_info.allocationSize = buff_mem_reqs.size + img_mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001602 pass = m_device->phy().set_memory_type(buff_mem_reqs.memoryTypeBits & img_mem_reqs.memoryTypeBits, &alloc_info,
1603 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001604 if (!pass) {
Tobin Ehlis077ded32016-05-12 17:39:13 -06001605 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001606 vkDestroyImage(m_device->device(), image, NULL);
Mark Lobodzinskid2d2d4c2017-02-16 11:51:58 -07001607 vkDestroyImage(m_device->device(), image2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001608 return;
1609 }
Tobin Ehlis077ded32016-05-12 17:39:13 -06001610 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1611 ASSERT_VK_SUCCESS(err);
1612 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
1613 ASSERT_VK_SUCCESS(err);
1614
Rene Lindsayd14f5572016-12-16 14:57:18 -07001615 vkGetImageMemoryRequirements(m_device->device(), image2, &img_mem_reqs2);
1616
Tobin Ehlis32b2bbc2016-12-13 17:33:41 -07001617 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " is aliased with linear buffer 0x");
Tobin Ehlis077ded32016-05-12 17:39:13 -06001618 // VALIDATION FAILURE due to image mapping overlapping buffer mapping
Tobin Ehlisf11be982016-05-11 13:52:53 -06001619 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1620 m_errorMonitor->VerifyFound();
1621
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001622 // Now correctly bind image2 to second mem allocation before incorrectly
Tobin Ehlis077ded32016-05-12 17:39:13 -06001623 // aliasing buffer2
1624 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer2);
1625 ASSERT_VK_SUCCESS(err);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001626 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem_img);
1627 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001628 err = vkBindImageMemory(m_device->device(), image2, mem_img, 0);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001629 ASSERT_VK_SUCCESS(err);
Tobin Ehlis32b2bbc2016-12-13 17:33:41 -07001630 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "is aliased with non-linear image 0x");
Rene Lindsayd14f5572016-12-16 14:57:18 -07001631 vkGetBufferMemoryRequirements(m_device->device(), buffer2, &buff_mem_reqs2);
Tobin Ehlis077ded32016-05-12 17:39:13 -06001632 err = vkBindBufferMemory(m_device->device(), buffer2, mem_img, 0);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001633 m_errorMonitor->VerifyFound();
1634
1635 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlis077ded32016-05-12 17:39:13 -06001636 vkDestroyBuffer(m_device->device(), buffer2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001637 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001638 vkDestroyImage(m_device->device(), image2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001639 vkFreeMemory(m_device->device(), mem, NULL);
1640 vkFreeMemory(m_device->device(), mem_img, NULL);
1641}
1642
Tobin Ehlis35372522016-05-12 08:32:31 -06001643TEST_F(VkLayerTest, InvalidMemoryMapping) {
1644 TEST_DESCRIPTION("Attempt to map memory in a number of incorrect ways");
1645 VkResult err;
1646 bool pass;
Tony Barbour1fa09702017-03-16 12:09:08 -06001647 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis35372522016-05-12 08:32:31 -06001648
1649 VkBuffer buffer;
1650 VkDeviceMemory mem;
1651 VkMemoryRequirements mem_reqs;
1652
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001653 const VkDeviceSize atom_size = m_device->props.limits.nonCoherentAtomSize;
1654
Tobin Ehlis35372522016-05-12 08:32:31 -06001655 VkBufferCreateInfo buf_info = {};
1656 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1657 buf_info.pNext = NULL;
1658 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1659 buf_info.size = 256;
1660 buf_info.queueFamilyIndexCount = 0;
1661 buf_info.pQueueFamilyIndices = NULL;
1662 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1663 buf_info.flags = 0;
1664 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1665 ASSERT_VK_SUCCESS(err);
1666
1667 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
1668 VkMemoryAllocateInfo alloc_info = {};
1669 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1670 alloc_info.pNext = NULL;
1671 alloc_info.memoryTypeIndex = 0;
1672
1673 // Ensure memory is big enough for both bindings
1674 static const VkDeviceSize allocation_size = 0x10000;
1675 alloc_info.allocationSize = allocation_size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001676 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 -06001677 if (!pass) {
1678 vkDestroyBuffer(m_device->device(), buffer, NULL);
1679 return;
1680 }
1681 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1682 ASSERT_VK_SUCCESS(err);
1683
1684 uint8_t *pData;
1685 // Attempt to map memory size 0 is invalid
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001686 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 -06001687 err = vkMapMemory(m_device->device(), mem, 0, 0, 0, (void **)&pData);
1688 m_errorMonitor->VerifyFound();
1689 // Map memory twice
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001690 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001691 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001692 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1693 "VkMapMemory: Attempting to map memory on an already-mapped object ");
1694 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001695 m_errorMonitor->VerifyFound();
1696
1697 // Unmap the memory to avoid re-map error
1698 vkUnmapMemory(m_device->device(), mem);
1699 // overstep allocation with VK_WHOLE_SIZE
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001700 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1701 " with size of VK_WHOLE_SIZE oversteps total array size 0x");
1702 err = vkMapMemory(m_device->device(), mem, allocation_size + 1, VK_WHOLE_SIZE, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001703 m_errorMonitor->VerifyFound();
1704 // overstep allocation w/o VK_WHOLE_SIZE
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001705 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " oversteps total array size 0x");
1706 err = vkMapMemory(m_device->device(), mem, 1, allocation_size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001707 m_errorMonitor->VerifyFound();
1708 // Now error due to unmapping memory that's not mapped
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001709 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Unmapping Memory without memory being mapped: ");
Tobin Ehlis35372522016-05-12 08:32:31 -06001710 vkUnmapMemory(m_device->device(), mem);
1711 m_errorMonitor->VerifyFound();
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001712
Tobin Ehlis35372522016-05-12 08:32:31 -06001713 // Now map memory and cause errors due to flushing invalid ranges
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001714 err = vkMapMemory(m_device->device(), mem, 4 * atom_size, VK_WHOLE_SIZE, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001715 ASSERT_VK_SUCCESS(err);
1716 VkMappedMemoryRange mmr = {};
Chris Forbes3aec0892016-06-13 10:29:26 +12001717 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
Tobin Ehlis35372522016-05-12 08:32:31 -06001718 mmr.memory = mem;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001719 mmr.offset = atom_size; // Error b/c offset less than offset of mapped mem
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001720 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00642);
Tobin Ehlis35372522016-05-12 08:32:31 -06001721 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1722 m_errorMonitor->VerifyFound();
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001723
Tobin Ehlis35372522016-05-12 08:32:31 -06001724 // Now flush range that oversteps mapped range
1725 vkUnmapMemory(m_device->device(), mem);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001726 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001727 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001728 mmr.offset = atom_size;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001729 mmr.size = 4 * atom_size; // Flushing bounds exceed mapped bounds
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001730 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00642);
1731 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1732 m_errorMonitor->VerifyFound();
1733
1734 // Now flush range with VK_WHOLE_SIZE that oversteps offset
1735 vkUnmapMemory(m_device->device(), mem);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001736 err = vkMapMemory(m_device->device(), mem, 2 * atom_size, 4 * atom_size, 0, (void **)&pData);
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001737 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001738 mmr.offset = atom_size;
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001739 mmr.size = VK_WHOLE_SIZE;
1740 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00643);
Tobin Ehlis35372522016-05-12 08:32:31 -06001741 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1742 m_errorMonitor->VerifyFound();
1743
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001744#if 0 // Planning discussion with working group on this validation check.
Mark Lobodzinski3826a4f2016-11-15 09:38:51 -07001745 // Some platforms have an atomsize of 1 which makes the test meaningless
1746 if (atom_size > 3) {
1747 // Now with an offset NOT a multiple of the device limit
1748 vkUnmapMemory(m_device->device(), mem);
1749 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
1750 ASSERT_VK_SUCCESS(err);
1751 mmr.offset = 3; // Not a multiple of atom_size
1752 mmr.size = VK_WHOLE_SIZE;
1753 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00644);
1754 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1755 m_errorMonitor->VerifyFound();
1756
1757 // Now with a size NOT a multiple of the device limit
1758 vkUnmapMemory(m_device->device(), mem);
1759 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
1760 ASSERT_VK_SUCCESS(err);
1761 mmr.offset = atom_size;
1762 mmr.size = 2 * atom_size + 1; // Not a multiple of atom_size
1763 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00645);
1764 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1765 m_errorMonitor->VerifyFound();
1766 }
Tony Barboure3975eb2016-12-15 14:52:44 -07001767#endif
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001768 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
1769 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Tobin Ehlis35372522016-05-12 08:32:31 -06001770 if (!pass) {
1771 vkFreeMemory(m_device->device(), mem, NULL);
1772 vkDestroyBuffer(m_device->device(), buffer, NULL);
1773 return;
1774 }
1775 // TODO : If we can get HOST_VISIBLE w/o HOST_COHERENT we can test cases of
1776 // MEMTRACK_INVALID_MAP in validateAndCopyNoncoherentMemoryToDriver()
1777
1778 vkDestroyBuffer(m_device->device(), buffer, NULL);
1779 vkFreeMemory(m_device->device(), mem, NULL);
1780}
1781
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001782#if 0 // disabled until PV gets real extension enable checks
Ian Elliott1c32c772016-04-28 14:47:13 -06001783TEST_F(VkLayerTest, EnableWsiBeforeUse) {
1784 VkResult err;
1785 bool pass;
1786
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001787 // FIXME: After we turn on this code for non-Linux platforms, uncomment the
1788 // following declaration (which is temporarily being moved below):
1789 // VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott1c32c772016-04-28 14:47:13 -06001790 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001791 VkSwapchainCreateInfoKHR swapchain_create_info = {VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR};
Ian Elliott1c32c772016-04-28 14:47:13 -06001792 uint32_t swapchain_image_count = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001793 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
Ian Elliott1c32c772016-04-28 14:47:13 -06001794 uint32_t image_index = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001795 // VkPresentInfoKHR present_info = {};
Ian Elliott1c32c772016-04-28 14:47:13 -06001796
Tony Barbour1fa09702017-03-16 12:09:08 -06001797 ASSERT_NO_FATAL_FAILURE(Init());
Ian Elliott1c32c772016-04-28 14:47:13 -06001798
Ian Elliott3f06ce52016-04-29 14:46:21 -06001799#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
1800#if defined(VK_USE_PLATFORM_ANDROID_KHR)
1801 // Use the functions from the VK_KHR_android_surface extension without
1802 // enabling that extension:
1803
1804 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001805 VkAndroidSurfaceCreateInfoKHR android_create_info = {VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001806 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1807 err = vkCreateAndroidSurfaceKHR(instance(), &android_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001808 pass = (err != VK_SUCCESS);
1809 ASSERT_TRUE(pass);
1810 m_errorMonitor->VerifyFound();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001811#endif // VK_USE_PLATFORM_ANDROID_KHR
Ian Elliott3f06ce52016-04-29 14:46:21 -06001812
Ian Elliott3f06ce52016-04-29 14:46:21 -06001813#if defined(VK_USE_PLATFORM_MIR_KHR)
1814 // Use the functions from the VK_KHR_mir_surface extension without enabling
1815 // that extension:
1816
1817 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001818 VkMirSurfaceCreateInfoKHR mir_create_info = {VK_STRUCTURE_TYPE_MIR_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001819 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott3f06ce52016-04-29 14:46:21 -06001820 err = vkCreateMirSurfaceKHR(instance(), &mir_create_info, NULL, &surface);
1821 pass = (err != VK_SUCCESS);
1822 ASSERT_TRUE(pass);
1823 m_errorMonitor->VerifyFound();
1824
1825 // Tell whether an mir_connection supports presentation:
1826 MirConnection *mir_connection = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001827 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1828 vkGetPhysicalDeviceMirPresentationSupportKHR(gpu(), 0, mir_connection, visual_id);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001829 m_errorMonitor->VerifyFound();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001830#endif // VK_USE_PLATFORM_MIR_KHR
Ian Elliott3f06ce52016-04-29 14:46:21 -06001831
Ian Elliott3f06ce52016-04-29 14:46:21 -06001832#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
1833 // Use the functions from the VK_KHR_wayland_surface extension without
1834 // enabling that extension:
1835
1836 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001837 VkWaylandSurfaceCreateInfoKHR wayland_create_info = {VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001838 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1839 err = vkCreateWaylandSurfaceKHR(instance(), &wayland_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001840 pass = (err != VK_SUCCESS);
1841 ASSERT_TRUE(pass);
1842 m_errorMonitor->VerifyFound();
1843
1844 // Tell whether an wayland_display supports presentation:
1845 struct wl_display wayland_display = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001846 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1847 vkGetPhysicalDeviceWaylandPresentationSupportKHR(gpu(), 0, &wayland_display);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001848 m_errorMonitor->VerifyFound();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001849#endif // VK_USE_PLATFORM_WAYLAND_KHR
1850#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott3f06ce52016-04-29 14:46:21 -06001851
Ian Elliott3f06ce52016-04-29 14:46:21 -06001852#if defined(VK_USE_PLATFORM_WIN32_KHR)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001853 // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1854 // TO NON-LINUX PLATFORMS:
1855 VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott3f06ce52016-04-29 14:46:21 -06001856 // Use the functions from the VK_KHR_win32_surface extension without
1857 // enabling that extension:
1858
1859 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001860 VkWin32SurfaceCreateInfoKHR win32_create_info = {VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001861 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1862 err = vkCreateWin32SurfaceKHR(instance(), &win32_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001863 pass = (err != VK_SUCCESS);
1864 ASSERT_TRUE(pass);
1865 m_errorMonitor->VerifyFound();
1866
1867 // Tell whether win32 supports presentation:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001868 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott489eec02016-05-05 14:12:44 -06001869 vkGetPhysicalDeviceWin32PresentationSupportKHR(gpu(), 0);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001870 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001871// Set this (for now, until all platforms are supported and tested):
1872#define NEED_TO_TEST_THIS_ON_PLATFORM
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001873#endif // VK_USE_PLATFORM_WIN32_KHR
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07001874#if defined(VK_USE_PLATFORM_XCB_KHR) || defined(VK_USE_PLATFORM_XLIB_KHR)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001875 // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1876 // TO NON-LINUX PLATFORMS:
1877 VkSurfaceKHR surface = VK_NULL_HANDLE;
Tony Barbour2e7bd402016-11-14 14:46:33 -07001878#endif
1879#if defined(VK_USE_PLATFORM_XCB_KHR)
Ian Elliott1c32c772016-04-28 14:47:13 -06001880 // Use the functions from the VK_KHR_xcb_surface extension without enabling
1881 // that extension:
1882
1883 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001884 VkXcbSurfaceCreateInfoKHR xcb_create_info = {VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001885 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001886 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
1887 pass = (err != VK_SUCCESS);
1888 ASSERT_TRUE(pass);
1889 m_errorMonitor->VerifyFound();
1890
1891 // Tell whether an xcb_visualid_t supports presentation:
Ian Elliott3f06ce52016-04-29 14:46:21 -06001892 xcb_connection_t *xcb_connection = NULL;
Ian Elliott1c32c772016-04-28 14:47:13 -06001893 xcb_visualid_t visual_id = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001894 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1895 vkGetPhysicalDeviceXcbPresentationSupportKHR(gpu(), 0, xcb_connection, visual_id);
Ian Elliott1c32c772016-04-28 14:47:13 -06001896 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001897// Set this (for now, until all platforms are supported and tested):
1898#define NEED_TO_TEST_THIS_ON_PLATFORM
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001899#endif // VK_USE_PLATFORM_XCB_KHR
Ian Elliott1c32c772016-04-28 14:47:13 -06001900
Ian Elliott12630812016-04-29 14:35:43 -06001901#if defined(VK_USE_PLATFORM_XLIB_KHR)
1902 // Use the functions from the VK_KHR_xlib_surface extension without enabling
1903 // that extension:
1904
1905 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001906 VkXlibSurfaceCreateInfoKHR xlib_create_info = {VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001907 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06001908 err = vkCreateXlibSurfaceKHR(instance(), &xlib_create_info, NULL, &surface);
1909 pass = (err != VK_SUCCESS);
1910 ASSERT_TRUE(pass);
1911 m_errorMonitor->VerifyFound();
1912
1913 // Tell whether an Xlib VisualID supports presentation:
1914 Display *dpy = NULL;
1915 VisualID visual = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001916 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06001917 vkGetPhysicalDeviceXlibPresentationSupportKHR(gpu(), 0, dpy, visual);
1918 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001919// Set this (for now, until all platforms are supported and tested):
1920#define NEED_TO_TEST_THIS_ON_PLATFORM
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001921#endif // VK_USE_PLATFORM_XLIB_KHR
Ian Elliott12630812016-04-29 14:35:43 -06001922
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001923// Use the functions from the VK_KHR_surface extension without enabling
1924// that extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06001925
Ian Elliott489eec02016-05-05 14:12:44 -06001926#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001927 // Destroy a surface:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001928 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001929 vkDestroySurfaceKHR(instance(), surface, NULL);
1930 m_errorMonitor->VerifyFound();
1931
1932 // Check if surface supports presentation:
1933 VkBool32 supported = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001934 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001935 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
1936 pass = (err != VK_SUCCESS);
1937 ASSERT_TRUE(pass);
1938 m_errorMonitor->VerifyFound();
1939
1940 // Check surface capabilities:
1941 VkSurfaceCapabilitiesKHR capabilities = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001942 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1943 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &capabilities);
Ian Elliott1c32c772016-04-28 14:47:13 -06001944 pass = (err != VK_SUCCESS);
1945 ASSERT_TRUE(pass);
1946 m_errorMonitor->VerifyFound();
1947
1948 // Check surface formats:
1949 uint32_t format_count = 0;
1950 VkSurfaceFormatKHR *formats = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001951 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1952 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &format_count, formats);
Ian Elliott1c32c772016-04-28 14:47:13 -06001953 pass = (err != VK_SUCCESS);
1954 ASSERT_TRUE(pass);
1955 m_errorMonitor->VerifyFound();
1956
1957 // Check surface present modes:
1958 uint32_t present_mode_count = 0;
1959 VkSurfaceFormatKHR *present_modes = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001960 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1961 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &present_mode_count, present_modes);
Ian Elliott1c32c772016-04-28 14:47:13 -06001962 pass = (err != VK_SUCCESS);
1963 ASSERT_TRUE(pass);
1964 m_errorMonitor->VerifyFound();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001965#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001966
Ian Elliott1c32c772016-04-28 14:47:13 -06001967 // Use the functions from the VK_KHR_swapchain extension without enabling
1968 // that extension:
1969
1970 // Create a swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001971 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001972 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
1973 swapchain_create_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001974 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
Ian Elliott1c32c772016-04-28 14:47:13 -06001975 pass = (err != VK_SUCCESS);
1976 ASSERT_TRUE(pass);
1977 m_errorMonitor->VerifyFound();
1978
1979 // Get the images from the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001980 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1981 err = vkGetSwapchainImagesKHR(m_device->device(), swapchain, &swapchain_image_count, NULL);
Ian Elliott1c32c772016-04-28 14:47:13 -06001982 pass = (err != VK_SUCCESS);
1983 ASSERT_TRUE(pass);
1984 m_errorMonitor->VerifyFound();
1985
Chris Forbeseb7d5502016-09-13 18:19:21 +12001986 // Add a fence to avoid (justifiable) error about not providing fence OR semaphore
1987 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
1988 VkFence fence;
1989 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
1990
Ian Elliott1c32c772016-04-28 14:47:13 -06001991 // Try to acquire an image:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001992 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Chris Forbeseb7d5502016-09-13 18:19:21 +12001993 err = vkAcquireNextImageKHR(m_device->device(), swapchain, 0, VK_NULL_HANDLE, fence, &image_index);
Ian Elliott1c32c772016-04-28 14:47:13 -06001994 pass = (err != VK_SUCCESS);
1995 ASSERT_TRUE(pass);
1996 m_errorMonitor->VerifyFound();
1997
Chris Forbeseb7d5502016-09-13 18:19:21 +12001998 vkDestroyFence(m_device->device(), fence, nullptr);
1999
Ian Elliott1c32c772016-04-28 14:47:13 -06002000 // Try to present an image:
Ian Elliott2c1daf52016-05-12 09:41:46 -06002001 //
2002 // NOTE: Currently can't test this because a real swapchain is needed (as
2003 // opposed to the fake one we created) in order for the layer to lookup the
2004 // VkDevice used to enable the extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06002005
2006 // Destroy the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002007 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06002008 vkDestroySwapchainKHR(m_device->device(), swapchain, NULL);
2009 m_errorMonitor->VerifyFound();
2010}
Chris Forbes09368e42016-10-13 11:59:22 +13002011#endif
Ian Elliott1c32c772016-04-28 14:47:13 -06002012
Karl Schultz6addd812016-02-02 17:17:23 -07002013TEST_F(VkLayerTest, MapMemWithoutHostVisibleBit) {
2014 VkResult err;
2015 bool pass;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002016
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002017 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2018 "Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002019
Tony Barbour1fa09702017-03-16 12:09:08 -06002020 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002021
2022 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07002023 VkImage image;
2024 VkDeviceMemory mem;
2025 VkMemoryRequirements mem_reqs;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002026
Karl Schultz6addd812016-02-02 17:17:23 -07002027 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2028 const int32_t tex_width = 32;
2029 const int32_t tex_height = 32;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002030
Tony Barboureb254902015-07-15 12:50:33 -06002031 VkImageCreateInfo image_create_info = {};
2032 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07002033 image_create_info.pNext = NULL;
2034 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2035 image_create_info.format = tex_format;
2036 image_create_info.extent.width = tex_width;
2037 image_create_info.extent.height = tex_height;
2038 image_create_info.extent.depth = 1;
2039 image_create_info.mipLevels = 1;
2040 image_create_info.arrayLayers = 1;
2041 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2042 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2043 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2044 image_create_info.flags = 0;
Chris Forbese65e4d02016-09-13 17:39:18 +12002045 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002046
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002047 VkMemoryAllocateInfo mem_alloc = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002048 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07002049 mem_alloc.pNext = NULL;
2050 mem_alloc.allocationSize = 0;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002051
Chia-I Wuf7458c52015-10-26 21:10:41 +08002052 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002053 ASSERT_VK_SUCCESS(err);
2054
Karl Schultz6addd812016-02-02 17:17:23 -07002055 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002056
Mark Lobodzinski23065352015-05-29 09:32:35 -05002057 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002058
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002059 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 -07002060 if (!pass) { // If we can't find any unmappable memory this test doesn't
2061 // make sense
Chia-I Wuf7458c52015-10-26 21:10:41 +08002062 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbour02fdc7d2015-08-04 16:13:01 -06002063 return;
Mike Stroyand1c84a52015-08-18 14:40:24 -06002064 }
Mike Stroyan713b2d72015-08-04 10:49:29 -06002065
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002066 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002067 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002068 ASSERT_VK_SUCCESS(err);
2069
2070 // Try to bind free memory that has been freed
Tony Barbour67e99152015-07-10 14:10:27 -06002071 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002072 ASSERT_VK_SUCCESS(err);
2073
2074 // Map memory as if to initialize the image
2075 void *mappedAddress = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002076 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, &mappedAddress);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002077
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002078 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002079
Chia-I Wuf7458c52015-10-26 21:10:41 +08002080 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06002081 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002082}
2083
Karl Schultz6addd812016-02-02 17:17:23 -07002084TEST_F(VkLayerTest, RebindMemory) {
2085 VkResult err;
2086 bool pass;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002087
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002088 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which has already been bound to mem object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002089
Tony Barbour1fa09702017-03-16 12:09:08 -06002090 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002091
2092 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07002093 VkImage image;
2094 VkDeviceMemory mem1;
2095 VkDeviceMemory mem2;
2096 VkMemoryRequirements mem_reqs;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002097
Karl Schultz6addd812016-02-02 17:17:23 -07002098 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2099 const int32_t tex_width = 32;
2100 const int32_t tex_height = 32;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002101
Tony Barboureb254902015-07-15 12:50:33 -06002102 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002103 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2104 image_create_info.pNext = NULL;
2105 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2106 image_create_info.format = tex_format;
2107 image_create_info.extent.width = tex_width;
2108 image_create_info.extent.height = tex_height;
2109 image_create_info.extent.depth = 1;
2110 image_create_info.mipLevels = 1;
2111 image_create_info.arrayLayers = 1;
2112 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2113 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2114 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2115 image_create_info.flags = 0;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002116
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002117 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002118 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2119 mem_alloc.pNext = NULL;
2120 mem_alloc.allocationSize = 0;
2121 mem_alloc.memoryTypeIndex = 0;
Tony Barboureb254902015-07-15 12:50:33 -06002122
Karl Schultz6addd812016-02-02 17:17:23 -07002123 // Introduce failure, do NOT set memProps to
2124 // VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
Tony Barboureb254902015-07-15 12:50:33 -06002125 mem_alloc.memoryTypeIndex = 1;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002126 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002127 ASSERT_VK_SUCCESS(err);
2128
Karl Schultz6addd812016-02-02 17:17:23 -07002129 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002130
2131 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002132 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002133 ASSERT_TRUE(pass);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002134
2135 // allocate 2 memory objects
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002136 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem1);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002137 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002138 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem2);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002139 ASSERT_VK_SUCCESS(err);
2140
2141 // Bind first memory object to Image object
Tony Barbour67e99152015-07-10 14:10:27 -06002142 err = vkBindImageMemory(m_device->device(), image, mem1, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002143 ASSERT_VK_SUCCESS(err);
2144
Karl Schultz6addd812016-02-02 17:17:23 -07002145 // Introduce validation failure, try to bind a different memory object to
2146 // the same image object
Tony Barbour67e99152015-07-10 14:10:27 -06002147 err = vkBindImageMemory(m_device->device(), image, mem2, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002148
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002149 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002150
Chia-I Wuf7458c52015-10-26 21:10:41 +08002151 vkDestroyImage(m_device->device(), image, NULL);
2152 vkFreeMemory(m_device->device(), mem1, NULL);
2153 vkFreeMemory(m_device->device(), mem2, NULL);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002154}
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002155
Karl Schultz6addd812016-02-02 17:17:23 -07002156TEST_F(VkLayerTest, SubmitSignaledFence) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002157 vk_testing::Fence testFence;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002158
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002159 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2160 "submitted in SIGNALED state. Fences "
2161 "must be reset before being submitted");
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002162
2163 VkFenceCreateInfo fenceInfo = {};
Tony Barbour0b4d9562015-04-09 10:48:04 -06002164 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2165 fenceInfo.pNext = NULL;
2166 fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
Tony Barbour300a6082015-04-07 13:44:53 -06002167
Tony Barbour1fa09702017-03-16 12:09:08 -06002168 ASSERT_NO_FATAL_FAILURE(Init());
Tony Barbour300a6082015-04-07 13:44:53 -06002169 ASSERT_NO_FATAL_FAILURE(InitViewport());
2170 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2171
Tony Barbour552f6c02016-12-21 14:34:07 -07002172 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002173 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbour552f6c02016-12-21 14:34:07 -07002174 m_commandBuffer->EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -06002175
2176 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002177
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002178 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08002179 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2180 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002181 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002182 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07002183 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002184 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002185 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08002186 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002187 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06002188
2189 vkQueueSubmit(m_device->m_queue, 1, &submit_info, testFence.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07002190 vkQueueWaitIdle(m_device->m_queue);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002191
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002192 m_errorMonitor->VerifyFound();
Tony Barbour0b4d9562015-04-09 10:48:04 -06002193}
Chris Forbes4e44c912016-06-16 10:20:00 +12002194
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002195TEST_F(VkLayerTest, InvalidUsageBits) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002196 TEST_DESCRIPTION(
2197 "Specify wrong usage for image then create conflicting view of image "
2198 "Initialize buffer with wrong usage then perform copy expecting errors "
2199 "from both the image and the buffer (2 calls)");
Mark Lobodzinski33826372017-04-13 11:10:11 -06002200 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid usage flag for Image ");
Tobin Ehlis41376e12015-07-03 08:45:14 -06002201
Tony Barbour1fa09702017-03-16 12:09:08 -06002202 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -06002203 auto format = FindSupportedDepthStencilFormat(gpu());
Tony Barbourf887b162017-03-09 10:06:46 -07002204 if (!format) {
2205 printf(" No Depth + Stencil format found. Skipped.\n");
2206 return;
2207 }
Chris Forbesd2b5fe42016-11-28 18:00:00 +13002208
Tony Barbourf92621a2016-05-02 14:28:12 -06002209 VkImageObj image(m_device);
Tony Barbour75d79f02016-08-30 09:39:07 -06002210 // Initialize image with USAGE_TRANSIENT_ATTACHMENT
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06002211 image.Init(128, 128, 1, format, VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Karl Schultzb5bc11e2016-05-04 08:36:08 -06002212 ASSERT_TRUE(image.initialized());
Tobin Ehlis41376e12015-07-03 08:45:14 -06002213
Tony Barbourf92621a2016-05-02 14:28:12 -06002214 VkImageView dsv;
2215 VkImageViewCreateInfo dsvci = {};
2216 dsvci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
2217 dsvci.image = image.handle();
2218 dsvci.viewType = VK_IMAGE_VIEW_TYPE_2D;
Chris Forbesd2b5fe42016-11-28 18:00:00 +13002219 dsvci.format = format;
Tony Barbourf92621a2016-05-02 14:28:12 -06002220 dsvci.subresourceRange.layerCount = 1;
2221 dsvci.subresourceRange.baseMipLevel = 0;
2222 dsvci.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002223 dsvci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis41376e12015-07-03 08:45:14 -06002224
Tony Barbourf92621a2016-05-02 14:28:12 -06002225 // Create a view with depth / stencil aspect for image with different usage
2226 vkCreateImageView(m_device->device(), &dsvci, NULL, &dsv);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002227
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002228 m_errorMonitor->VerifyFound();
Tony Barbourf92621a2016-05-02 14:28:12 -06002229
2230 // Initialize buffer with TRANSFER_DST usage
2231 vk_testing::Buffer buffer;
2232 VkMemoryPropertyFlags reqs = 0;
2233 buffer.init_as_dst(*m_device, 128 * 128, reqs);
2234 VkBufferImageCopy region = {};
2235 region.bufferRowLength = 128;
2236 region.bufferImageHeight = 128;
Mark Lobodzinski80871462017-02-16 10:37:27 -07002237 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Tony Barbourf92621a2016-05-02 14:28:12 -06002238 region.imageSubresource.layerCount = 1;
2239 region.imageExtent.height = 16;
2240 region.imageExtent.width = 16;
2241 region.imageExtent.depth = 1;
2242
Mark Lobodzinski80871462017-02-16 10:37:27 -07002243 // Buffer usage not set to TRANSFER_SRC and image usage not set to TRANSFER_DST
Tony Barbour552f6c02016-12-21 14:34:07 -07002244 m_commandBuffer->BeginCommandBuffer();
Tony Barbourf92621a2016-05-02 14:28:12 -06002245
Chris Forbesda581202016-10-06 18:25:26 +13002246 // two separate errors from this call:
Mark Lobodzinski33826372017-04-13 11:10:11 -06002247 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image should have VK_IMAGE_USAGE_TRANSFER_DST_BIT");
2248 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 +13002249
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002250 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
2251 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourf92621a2016-05-02 14:28:12 -06002252 m_errorMonitor->VerifyFound();
Tobin Ehlis41376e12015-07-03 08:45:14 -06002253}
Tony Barbour75d79f02016-08-30 09:39:07 -06002254
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002255TEST_F(VkLayerTest, LeakAnObject) {
2256 VkResult err;
2257
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002258 TEST_DESCRIPTION("Create a fence and destroy its device without first destroying the fence.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002259
2260 // Note that we have to create a new device since destroying the
2261 // framework's device causes Teardown() to fail and just calling Teardown
2262 // will destroy the errorMonitor.
2263
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002264 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "has not been destroyed.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002265
Tony Barbour1fa09702017-03-16 12:09:08 -06002266 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002267
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002268 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002269 std::vector<VkDeviceQueueCreateInfo> queue_info;
2270 queue_info.reserve(queue_props.size());
2271 std::vector<std::vector<float>> queue_priorities;
2272 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
2273 VkDeviceQueueCreateInfo qi = {};
2274 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
2275 qi.pNext = NULL;
2276 qi.queueFamilyIndex = i;
2277 qi.queueCount = queue_props[i].queueCount;
2278 queue_priorities.emplace_back(qi.queueCount, 0.0f);
2279 qi.pQueuePriorities = queue_priorities[i].data();
2280 queue_info.push_back(qi);
2281 }
2282
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002283 std::vector<const char *> device_extension_names;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002284
2285 // The sacrificial device object
2286 VkDevice testDevice;
2287 VkDeviceCreateInfo device_create_info = {};
2288 auto features = m_device->phy().features();
2289 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
2290 device_create_info.pNext = NULL;
2291 device_create_info.queueCreateInfoCount = queue_info.size();
2292 device_create_info.pQueueCreateInfos = queue_info.data();
Tony Barbour4c70d102016-08-08 16:06:56 -06002293 device_create_info.enabledLayerCount = 0;
2294 device_create_info.ppEnabledLayerNames = NULL;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002295 device_create_info.pEnabledFeatures = &features;
2296 err = vkCreateDevice(gpu(), &device_create_info, NULL, &testDevice);
2297 ASSERT_VK_SUCCESS(err);
2298
2299 VkFence fence;
2300 VkFenceCreateInfo fence_create_info = {};
2301 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2302 fence_create_info.pNext = NULL;
2303 fence_create_info.flags = 0;
2304 err = vkCreateFence(testDevice, &fence_create_info, NULL, &fence);
2305 ASSERT_VK_SUCCESS(err);
2306
2307 // Induce failure by not calling vkDestroyFence
2308 vkDestroyDevice(testDevice, NULL);
2309 m_errorMonitor->VerifyFound();
2310}
2311
2312TEST_F(VkLayerTest, InvalidCommandPoolConsistency) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002313 TEST_DESCRIPTION(
2314 "Allocate command buffers from one command pool and "
2315 "attempt to delete them from another.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002316
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002317 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeCommandBuffers is attempting to free Command Buffer");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002318
Tony Barbour1fa09702017-03-16 12:09:08 -06002319 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002320 VkCommandPool command_pool_one;
2321 VkCommandPool command_pool_two;
2322
2323 VkCommandPoolCreateInfo pool_create_info{};
2324 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
2325 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
2326 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
2327
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002328 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002329
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002330 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002331
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002332 VkCommandBuffer cb;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002333 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002334 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002335 command_buffer_allocate_info.commandPool = command_pool_one;
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002336 command_buffer_allocate_info.commandBufferCount = 1;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002337 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002338 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &cb);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002339
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002340 vkFreeCommandBuffers(m_device->device(), command_pool_two, 1, &cb);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002341
2342 m_errorMonitor->VerifyFound();
2343
2344 vkDestroyCommandPool(m_device->device(), command_pool_one, NULL);
2345 vkDestroyCommandPool(m_device->device(), command_pool_two, NULL);
2346}
2347
2348TEST_F(VkLayerTest, InvalidDescriptorPoolConsistency) {
2349 VkResult err;
2350
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002351 TEST_DESCRIPTION(
2352 "Allocate descriptor sets from one DS pool and "
2353 "attempt to delete them from another.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002354
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002355 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeDescriptorSets is attempting to free descriptorSet");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002356
Tony Barbour1fa09702017-03-16 12:09:08 -06002357 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002358 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2359
2360 VkDescriptorPoolSize ds_type_count = {};
2361 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
2362 ds_type_count.descriptorCount = 1;
2363
2364 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2365 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2366 ds_pool_ci.pNext = NULL;
2367 ds_pool_ci.flags = 0;
2368 ds_pool_ci.maxSets = 1;
2369 ds_pool_ci.poolSizeCount = 1;
2370 ds_pool_ci.pPoolSizes = &ds_type_count;
2371
2372 VkDescriptorPool ds_pool_one;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002373 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002374 ASSERT_VK_SUCCESS(err);
2375
2376 // Create a second descriptor pool
2377 VkDescriptorPool ds_pool_two;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002378 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002379 ASSERT_VK_SUCCESS(err);
2380
2381 VkDescriptorSetLayoutBinding dsl_binding = {};
2382 dsl_binding.binding = 0;
2383 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
2384 dsl_binding.descriptorCount = 1;
2385 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2386 dsl_binding.pImmutableSamplers = NULL;
2387
2388 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2389 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2390 ds_layout_ci.pNext = NULL;
2391 ds_layout_ci.bindingCount = 1;
2392 ds_layout_ci.pBindings = &dsl_binding;
2393
2394 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002395 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002396 ASSERT_VK_SUCCESS(err);
2397
2398 VkDescriptorSet descriptorSet;
2399 VkDescriptorSetAllocateInfo alloc_info = {};
2400 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
2401 alloc_info.descriptorSetCount = 1;
2402 alloc_info.descriptorPool = ds_pool_one;
2403 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002404 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002405 ASSERT_VK_SUCCESS(err);
2406
2407 err = vkFreeDescriptorSets(m_device->device(), ds_pool_two, 1, &descriptorSet);
2408
2409 m_errorMonitor->VerifyFound();
2410
2411 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2412 vkDestroyDescriptorPool(m_device->device(), ds_pool_one, NULL);
2413 vkDestroyDescriptorPool(m_device->device(), ds_pool_two, NULL);
2414}
2415
2416TEST_F(VkLayerTest, CreateUnknownObject) {
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002417 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00788);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002418
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002419 TEST_DESCRIPTION("Pass an invalid image object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002420
Tony Barbour1fa09702017-03-16 12:09:08 -06002421 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002422
2423 // Pass bogus handle into GetImageMemoryRequirements
2424 VkMemoryRequirements mem_reqs;
2425 uint64_t fakeImageHandle = 0xCADECADE;
2426 VkImage fauxImage = reinterpret_cast<VkImage &>(fakeImageHandle);
2427
2428 vkGetImageMemoryRequirements(m_device->device(), fauxImage, &mem_reqs);
2429
2430 m_errorMonitor->VerifyFound();
2431}
2432
Mike Schuchardt17838902017-02-21 09:48:06 -07002433TEST_F(VkLayerTest, UseObjectWithWrongDevice) {
2434 TEST_DESCRIPTION(
2435 "Try to destroy a render pass object using a device other than the one it was created on. "
2436 "This should generate a distinct error from the invalid handle error.");
2437 // Create first device and renderpass
Tony Barbour1fa09702017-03-16 12:09:08 -06002438 ASSERT_NO_FATAL_FAILURE(Init());
Mike Schuchardt17838902017-02-21 09:48:06 -07002439 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2440
2441 // Create second device
2442 float priorities[] = {1.0f};
2443 VkDeviceQueueCreateInfo queue_info{};
2444 queue_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
2445 queue_info.pNext = NULL;
2446 queue_info.flags = 0;
2447 queue_info.queueFamilyIndex = 0;
2448 queue_info.queueCount = 1;
2449 queue_info.pQueuePriorities = &priorities[0];
2450
2451 VkDeviceCreateInfo device_create_info = {};
2452 auto features = m_device->phy().features();
2453 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
2454 device_create_info.pNext = NULL;
2455 device_create_info.queueCreateInfoCount = 1;
2456 device_create_info.pQueueCreateInfos = &queue_info;
2457 device_create_info.enabledLayerCount = 0;
2458 device_create_info.ppEnabledLayerNames = NULL;
2459 device_create_info.pEnabledFeatures = &features;
2460
2461 VkDevice second_device;
2462 ASSERT_VK_SUCCESS(vkCreateDevice(gpu(), &device_create_info, NULL, &second_device));
2463
2464 // Try to destroy the renderpass from the first device using the second device
2465 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00399);
2466 vkDestroyRenderPass(second_device, m_renderPass, NULL);
2467 m_errorMonitor->VerifyFound();
2468
2469 vkDestroyDevice(second_device, NULL);
2470}
2471
Karl Schultz6addd812016-02-02 17:17:23 -07002472TEST_F(VkLayerTest, PipelineNotBound) {
2473 VkResult err;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002474
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002475 TEST_DESCRIPTION("Pass in an invalid pipeline object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002476
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002477 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00601);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002478
Tony Barbour1fa09702017-03-16 12:09:08 -06002479 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002480 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002481
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002482 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002483 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2484 ds_type_count.descriptorCount = 1;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002485
2486 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002487 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2488 ds_pool_ci.pNext = NULL;
2489 ds_pool_ci.maxSets = 1;
2490 ds_pool_ci.poolSizeCount = 1;
2491 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002492
2493 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002494 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002495 ASSERT_VK_SUCCESS(err);
2496
2497 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002498 dsl_binding.binding = 0;
2499 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2500 dsl_binding.descriptorCount = 1;
2501 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2502 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002503
2504 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002505 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2506 ds_layout_ci.pNext = NULL;
2507 ds_layout_ci.bindingCount = 1;
2508 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002509
2510 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002511 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002512 ASSERT_VK_SUCCESS(err);
2513
2514 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002515 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002516 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07002517 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002518 alloc_info.descriptorPool = ds_pool;
2519 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002520 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002521 ASSERT_VK_SUCCESS(err);
2522
2523 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002524 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2525 pipeline_layout_ci.pNext = NULL;
2526 pipeline_layout_ci.setLayoutCount = 1;
2527 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002528
2529 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002530 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002531 ASSERT_VK_SUCCESS(err);
2532
Mark Youngad779052016-01-06 14:26:04 -07002533 VkPipeline badPipeline = (VkPipeline)((size_t)0xbaadb1be);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002534
Tony Barbour552f6c02016-12-21 14:34:07 -07002535 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002536 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002537
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002538 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002539
Chia-I Wuf7458c52015-10-26 21:10:41 +08002540 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2541 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2542 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002543}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002544
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002545TEST_F(VkLayerTest, BindImageInvalidMemoryType) {
2546 VkResult err;
2547
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002548 TEST_DESCRIPTION(
2549 "Test validation check for an invalid memory type index "
2550 "during bind[Buffer|Image]Memory time");
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002551
Tony Barbour1fa09702017-03-16 12:09:08 -06002552 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002553
2554 // Create an image, allocate memory, set a bad typeIndex and then try to
2555 // bind it
2556 VkImage image;
2557 VkDeviceMemory mem;
2558 VkMemoryRequirements mem_reqs;
2559 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2560 const int32_t tex_width = 32;
2561 const int32_t tex_height = 32;
2562
2563 VkImageCreateInfo image_create_info = {};
2564 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2565 image_create_info.pNext = NULL;
2566 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2567 image_create_info.format = tex_format;
2568 image_create_info.extent.width = tex_width;
2569 image_create_info.extent.height = tex_height;
2570 image_create_info.extent.depth = 1;
2571 image_create_info.mipLevels = 1;
2572 image_create_info.arrayLayers = 1;
2573 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2574 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2575 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2576 image_create_info.flags = 0;
2577
2578 VkMemoryAllocateInfo mem_alloc = {};
2579 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2580 mem_alloc.pNext = NULL;
2581 mem_alloc.allocationSize = 0;
2582 mem_alloc.memoryTypeIndex = 0;
2583
2584 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
2585 ASSERT_VK_SUCCESS(err);
2586
2587 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
2588 mem_alloc.allocationSize = mem_reqs.size;
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002589
2590 // Introduce Failure, select invalid TypeIndex
2591 VkPhysicalDeviceMemoryProperties memory_info;
2592
2593 vkGetPhysicalDeviceMemoryProperties(gpu(), &memory_info);
2594 unsigned int i;
2595 for (i = 0; i < memory_info.memoryTypeCount; i++) {
2596 if ((mem_reqs.memoryTypeBits & (1 << i)) == 0) {
2597 mem_alloc.memoryTypeIndex = i;
2598 break;
2599 }
2600 }
2601 if (i >= memory_info.memoryTypeCount) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07002602 printf(" No invalid memory type index could be found; skipped.\n");
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002603 vkDestroyImage(m_device->device(), image, NULL);
2604 return;
2605 }
2606
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002607 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 -06002608
2609 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
2610 ASSERT_VK_SUCCESS(err);
2611
2612 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2613 (void)err;
2614
2615 m_errorMonitor->VerifyFound();
2616
2617 vkDestroyImage(m_device->device(), image, NULL);
2618 vkFreeMemory(m_device->device(), mem, NULL);
2619}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002620
Karl Schultz6addd812016-02-02 17:17:23 -07002621TEST_F(VkLayerTest, BindInvalidMemory) {
2622 VkResult err;
2623 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002624
Tony Barbour1fa09702017-03-16 12:09:08 -06002625 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisec598302015-09-15 15:02:17 -06002626
Cortf801b982017-01-17 18:10:21 -08002627 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
Cort Strattonde748202017-02-17 12:50:01 -08002628 const int32_t tex_width = 256;
2629 const int32_t tex_height = 256;
Tobin Ehlisec598302015-09-15 15:02:17 -06002630
2631 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002632 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2633 image_create_info.pNext = NULL;
2634 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2635 image_create_info.format = tex_format;
2636 image_create_info.extent.width = tex_width;
2637 image_create_info.extent.height = tex_height;
2638 image_create_info.extent.depth = 1;
2639 image_create_info.mipLevels = 1;
2640 image_create_info.arrayLayers = 1;
2641 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Cort Strattonf1d8a4a2017-01-28 14:17:04 -08002642 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Karl Schultz6addd812016-02-02 17:17:23 -07002643 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2644 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002645
Cortf801b982017-01-17 18:10:21 -08002646 VkBufferCreateInfo buffer_create_info = {};
2647 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
2648 buffer_create_info.pNext = NULL;
2649 buffer_create_info.flags = 0;
Cort Strattonde748202017-02-17 12:50:01 -08002650 buffer_create_info.size = 4 * 1024 * 1024;
2651 buffer_create_info.usage = VK_BUFFER_USAGE_VERTEX_BUFFER_BIT;
Cortf801b982017-01-17 18:10:21 -08002652 buffer_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
Tobin Ehlisec598302015-09-15 15:02:17 -06002653
Cortf801b982017-01-17 18:10:21 -08002654 // Create an image/buffer, allocate memory, free it, and then try to bind it
2655 {
2656 VkImage image = VK_NULL_HANDLE;
2657 VkBuffer buffer = VK_NULL_HANDLE;
2658 err = vkCreateImage(device(), &image_create_info, NULL, &image);
2659 ASSERT_VK_SUCCESS(err);
2660 err = vkCreateBuffer(device(), &buffer_create_info, NULL, &buffer);
2661 ASSERT_VK_SUCCESS(err);
2662 VkMemoryRequirements image_mem_reqs = {}, buffer_mem_reqs = {};
2663 vkGetImageMemoryRequirements(device(), image, &image_mem_reqs);
2664 vkGetBufferMemoryRequirements(device(), buffer, &buffer_mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002665
Cortf801b982017-01-17 18:10:21 -08002666 VkMemoryAllocateInfo image_mem_alloc = {}, buffer_mem_alloc = {};
2667 image_mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2668 image_mem_alloc.allocationSize = image_mem_reqs.size;
2669 pass = m_device->phy().set_memory_type(image_mem_reqs.memoryTypeBits, &image_mem_alloc, 0);
2670 ASSERT_TRUE(pass);
2671 buffer_mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2672 buffer_mem_alloc.allocationSize = buffer_mem_reqs.size;
2673 pass = m_device->phy().set_memory_type(buffer_mem_reqs.memoryTypeBits, &buffer_mem_alloc, 0);
2674 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002675
Cortf801b982017-01-17 18:10:21 -08002676 VkDeviceMemory image_mem = VK_NULL_HANDLE, buffer_mem = VK_NULL_HANDLE;
2677 err = vkAllocateMemory(device(), &image_mem_alloc, NULL, &image_mem);
2678 ASSERT_VK_SUCCESS(err);
2679 err = vkAllocateMemory(device(), &buffer_mem_alloc, NULL, &buffer_mem);
2680 ASSERT_VK_SUCCESS(err);
Tobin Ehlisec598302015-09-15 15:02:17 -06002681
Cortf801b982017-01-17 18:10:21 -08002682 vkFreeMemory(device(), image_mem, NULL);
2683 vkFreeMemory(device(), buffer_mem, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002684
Cortf801b982017-01-17 18:10:21 -08002685 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00809);
2686 err = vkBindImageMemory(device(), image, image_mem, 0);
2687 (void)err; // This may very well return an error.
2688 m_errorMonitor->VerifyFound();
Tobin Ehlisec598302015-09-15 15:02:17 -06002689
Cortf801b982017-01-17 18:10:21 -08002690 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00800);
2691 err = vkBindBufferMemory(device(), buffer, buffer_mem, 0);
2692 (void)err; // This may very well return an error.
2693 m_errorMonitor->VerifyFound();
Tobin Ehlisec598302015-09-15 15:02:17 -06002694
Cortf801b982017-01-17 18:10:21 -08002695 vkDestroyImage(m_device->device(), image, NULL);
2696 vkDestroyBuffer(m_device->device(), buffer, NULL);
2697 }
Cort Strattonc21601b2017-01-28 14:16:16 -08002698
2699 // Try to bind memory to an object that already has a memory binding
2700 {
2701 VkImage image = VK_NULL_HANDLE;
2702 err = vkCreateImage(device(), &image_create_info, NULL, &image);
2703 ASSERT_VK_SUCCESS(err);
2704 VkBuffer buffer = VK_NULL_HANDLE;
2705 err = vkCreateBuffer(device(), &buffer_create_info, NULL, &buffer);
2706 ASSERT_VK_SUCCESS(err);
2707 VkMemoryRequirements image_mem_reqs = {}, buffer_mem_reqs = {};
2708 vkGetImageMemoryRequirements(device(), image, &image_mem_reqs);
2709 vkGetBufferMemoryRequirements(device(), buffer, &buffer_mem_reqs);
2710 VkMemoryAllocateInfo image_alloc_info = {}, buffer_alloc_info = {};
2711 image_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2712 image_alloc_info.allocationSize = image_mem_reqs.size;
2713 buffer_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2714 buffer_alloc_info.allocationSize = buffer_mem_reqs.size;
2715 pass = m_device->phy().set_memory_type(image_mem_reqs.memoryTypeBits, &image_alloc_info, 0);
2716 ASSERT_TRUE(pass);
2717 pass = m_device->phy().set_memory_type(buffer_mem_reqs.memoryTypeBits, &buffer_alloc_info, 0);
2718 ASSERT_TRUE(pass);
2719 VkDeviceMemory image_mem, buffer_mem;
2720 err = vkAllocateMemory(device(), &image_alloc_info, NULL, &image_mem);
2721 ASSERT_VK_SUCCESS(err);
2722 err = vkAllocateMemory(device(), &buffer_alloc_info, NULL, &buffer_mem);
2723 ASSERT_VK_SUCCESS(err);
2724
2725 err = vkBindImageMemory(device(), image, image_mem, 0);
2726 ASSERT_VK_SUCCESS(err);
2727 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00803);
2728 err = vkBindImageMemory(device(), image, image_mem, 0);
2729 (void)err; // This may very well return an error.
2730 m_errorMonitor->VerifyFound();
2731
2732 err = vkBindBufferMemory(device(), buffer, buffer_mem, 0);
2733 ASSERT_VK_SUCCESS(err);
2734 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00791);
2735 err = vkBindBufferMemory(device(), buffer, buffer_mem, 0);
2736 (void)err; // This may very well return an error.
2737 m_errorMonitor->VerifyFound();
2738
2739 vkFreeMemory(device(), image_mem, NULL);
2740 vkFreeMemory(device(), buffer_mem, NULL);
2741 vkDestroyImage(device(), image, NULL);
2742 vkDestroyBuffer(device(), buffer, NULL);
2743 }
Cort Strattonf1d8a4a2017-01-28 14:17:04 -08002744
Cort Strattonde748202017-02-17 12:50:01 -08002745 // Try to bind memory to an object with an invalid memoryOffset
Cort6c7dff72017-01-27 18:34:50 -08002746 {
2747 VkImage image = VK_NULL_HANDLE;
2748 err = vkCreateImage(device(), &image_create_info, NULL, &image);
2749 ASSERT_VK_SUCCESS(err);
2750 VkBuffer buffer = VK_NULL_HANDLE;
2751 err = vkCreateBuffer(device(), &buffer_create_info, NULL, &buffer);
2752 ASSERT_VK_SUCCESS(err);
2753 VkMemoryRequirements image_mem_reqs = {}, buffer_mem_reqs = {};
2754 vkGetImageMemoryRequirements(device(), image, &image_mem_reqs);
2755 vkGetBufferMemoryRequirements(device(), buffer, &buffer_mem_reqs);
2756 VkMemoryAllocateInfo image_alloc_info = {}, buffer_alloc_info = {};
2757 image_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Cort Strattonde748202017-02-17 12:50:01 -08002758 // Leave some extra space for alignment wiggle room
2759 image_alloc_info.allocationSize = image_mem_reqs.size + image_mem_reqs.alignment;
Cort6c7dff72017-01-27 18:34:50 -08002760 buffer_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Cort Strattonde748202017-02-17 12:50:01 -08002761 buffer_alloc_info.allocationSize = buffer_mem_reqs.size + buffer_mem_reqs.alignment;
Cort6c7dff72017-01-27 18:34:50 -08002762 pass = m_device->phy().set_memory_type(image_mem_reqs.memoryTypeBits, &image_alloc_info, 0);
2763 ASSERT_TRUE(pass);
2764 pass = m_device->phy().set_memory_type(buffer_mem_reqs.memoryTypeBits, &buffer_alloc_info, 0);
2765 ASSERT_TRUE(pass);
2766 VkDeviceMemory image_mem, buffer_mem;
2767 err = vkAllocateMemory(device(), &image_alloc_info, NULL, &image_mem);
2768 ASSERT_VK_SUCCESS(err);
2769 err = vkAllocateMemory(device(), &buffer_alloc_info, NULL, &buffer_mem);
2770 ASSERT_VK_SUCCESS(err);
2771
Cort Strattonde748202017-02-17 12:50:01 -08002772 // Test unaligned memory offset
2773 {
2774 if (image_mem_reqs.alignment > 1) {
2775 VkDeviceSize image_offset = 1;
2776 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02178);
2777 err = vkBindImageMemory(device(), image, image_mem, image_offset);
2778 (void)err; // This may very well return an error.
2779 m_errorMonitor->VerifyFound();
2780 }
Cort6c7dff72017-01-27 18:34:50 -08002781
Cort Strattonde748202017-02-17 12:50:01 -08002782 if (buffer_mem_reqs.alignment > 1) {
2783 VkDeviceSize buffer_offset = 1;
2784 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02174);
2785 err = vkBindBufferMemory(device(), buffer, buffer_mem, buffer_offset);
2786 (void)err; // This may very well return an error.
2787 m_errorMonitor->VerifyFound();
2788 }
2789 }
2790
2791 // Test memory offsets outside the memory allocation
2792 {
2793 VkDeviceSize image_offset =
2794 (image_alloc_info.allocationSize + image_mem_reqs.alignment) & ~(image_mem_reqs.alignment - 1);
2795 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00805);
2796 err = vkBindImageMemory(device(), image, image_mem, image_offset);
2797 (void)err; // This may very well return an error.
2798 m_errorMonitor->VerifyFound();
2799
2800 VkDeviceSize buffer_offset =
2801 (buffer_alloc_info.allocationSize + buffer_mem_reqs.alignment) & ~(buffer_mem_reqs.alignment - 1);
2802 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00793);
2803 err = vkBindBufferMemory(device(), buffer, buffer_mem, buffer_offset);
2804 (void)err; // This may very well return an error.
2805 m_errorMonitor->VerifyFound();
2806 }
2807
2808 // Test memory offsets within the memory allocation, but which leave too little memory for
2809 // the resource.
2810 {
2811 VkDeviceSize image_offset = (image_mem_reqs.size - 1) & ~(image_mem_reqs.alignment - 1);
Tony Barbour02d08552017-03-24 16:36:01 -06002812 if ((image_offset > 0) && (image_mem_reqs.size < (image_alloc_info.allocationSize - image_mem_reqs.alignment))) {
Cort Strattonde748202017-02-17 12:50:01 -08002813 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02179);
2814 err = vkBindImageMemory(device(), image, image_mem, image_offset);
2815 (void)err; // This may very well return an error.
2816 m_errorMonitor->VerifyFound();
2817 }
2818
2819 VkDeviceSize buffer_offset = (buffer_mem_reqs.size - 1) & ~(buffer_mem_reqs.alignment - 1);
2820 if (buffer_offset > 0) {
2821 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02175);
2822 err = vkBindBufferMemory(device(), buffer, buffer_mem, buffer_offset);
2823 (void)err; // This may very well return an error.
2824 m_errorMonitor->VerifyFound();
2825 }
2826 }
Cort6c7dff72017-01-27 18:34:50 -08002827
2828 vkFreeMemory(device(), image_mem, NULL);
2829 vkFreeMemory(device(), buffer_mem, NULL);
2830 vkDestroyImage(device(), image, NULL);
2831 vkDestroyBuffer(device(), buffer, NULL);
2832 }
2833
Cort Stratton4c38bb52017-01-28 13:33:10 -08002834 // Try to bind memory to an object with an invalid memory type
2835 {
2836 VkImage image = VK_NULL_HANDLE;
2837 err = vkCreateImage(device(), &image_create_info, NULL, &image);
2838 ASSERT_VK_SUCCESS(err);
2839 VkBuffer buffer = VK_NULL_HANDLE;
2840 err = vkCreateBuffer(device(), &buffer_create_info, NULL, &buffer);
2841 ASSERT_VK_SUCCESS(err);
2842 VkMemoryRequirements image_mem_reqs = {}, buffer_mem_reqs = {};
2843 vkGetImageMemoryRequirements(device(), image, &image_mem_reqs);
2844 vkGetBufferMemoryRequirements(device(), buffer, &buffer_mem_reqs);
2845 VkMemoryAllocateInfo image_alloc_info = {}, buffer_alloc_info = {};
2846 image_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2847 image_alloc_info.allocationSize = image_mem_reqs.size;
2848 buffer_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2849 buffer_alloc_info.allocationSize = buffer_mem_reqs.size;
Cort Strattonccc90e32017-02-04 13:47:42 -08002850 // Create a mask of available memory types *not* supported by these resources,
2851 // and try to use one of them.
Cort Stratton4c38bb52017-01-28 13:33:10 -08002852 VkPhysicalDeviceMemoryProperties memory_properties = {};
2853 vkGetPhysicalDeviceMemoryProperties(m_device->phy().handle(), &memory_properties);
Cort Strattonccc90e32017-02-04 13:47:42 -08002854 VkDeviceMemory image_mem, buffer_mem;
2855
Cort Stratton4c38bb52017-01-28 13:33:10 -08002856 uint32_t image_unsupported_mem_type_bits = ((1 << memory_properties.memoryTypeCount) - 1) & ~image_mem_reqs.memoryTypeBits;
Cort Strattonccc90e32017-02-04 13:47:42 -08002857 if (image_unsupported_mem_type_bits != 0) {
Dave Houlton584d51e2017-02-16 12:52:54 -07002858 pass = m_device->phy().set_memory_type(image_unsupported_mem_type_bits, &image_alloc_info, 0);
2859 ASSERT_TRUE(pass);
2860 err = vkAllocateMemory(device(), &image_alloc_info, NULL, &image_mem);
2861 ASSERT_VK_SUCCESS(err);
2862 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00806);
2863 err = vkBindImageMemory(device(), image, image_mem, 0);
2864 (void)err; // This may very well return an error.
2865 m_errorMonitor->VerifyFound();
2866 vkFreeMemory(device(), image_mem, NULL);
Cort Strattonccc90e32017-02-04 13:47:42 -08002867 }
2868
Cort Stratton4c38bb52017-01-28 13:33:10 -08002869 uint32_t buffer_unsupported_mem_type_bits =
2870 ((1 << memory_properties.memoryTypeCount) - 1) & ~buffer_mem_reqs.memoryTypeBits;
Cort Strattonccc90e32017-02-04 13:47:42 -08002871 if (buffer_unsupported_mem_type_bits != 0) {
Dave Houlton584d51e2017-02-16 12:52:54 -07002872 pass = m_device->phy().set_memory_type(buffer_unsupported_mem_type_bits, &buffer_alloc_info, 0);
2873 ASSERT_TRUE(pass);
2874 err = vkAllocateMemory(device(), &buffer_alloc_info, NULL, &buffer_mem);
2875 ASSERT_VK_SUCCESS(err);
2876 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00797);
2877 err = vkBindBufferMemory(device(), buffer, buffer_mem, 0);
2878 (void)err; // This may very well return an error.
2879 m_errorMonitor->VerifyFound();
2880 vkFreeMemory(device(), buffer_mem, NULL);
Cort Strattonccc90e32017-02-04 13:47:42 -08002881 }
Cort Stratton4c38bb52017-01-28 13:33:10 -08002882
Cort Stratton4c38bb52017-01-28 13:33:10 -08002883 vkDestroyImage(device(), image, NULL);
2884 vkDestroyBuffer(device(), buffer, NULL);
2885 }
2886
Cort Strattonf1d8a4a2017-01-28 14:17:04 -08002887 // Try to bind memory to an image created with sparse memory flags
2888 {
2889 VkImageCreateInfo sparse_image_create_info = image_create_info;
2890 sparse_image_create_info.flags |= VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
2891 VkImageFormatProperties image_format_properties = {};
2892 err = vkGetPhysicalDeviceImageFormatProperties(m_device->phy().handle(), sparse_image_create_info.format,
2893 sparse_image_create_info.imageType, sparse_image_create_info.tiling,
2894 sparse_image_create_info.usage, sparse_image_create_info.flags,
2895 &image_format_properties);
2896 if (!m_device->phy().features().sparseResidencyImage2D || err == VK_ERROR_FORMAT_NOT_SUPPORTED) {
2897 // most likely means sparse formats aren't supported here; skip this test.
2898 } else {
2899 ASSERT_VK_SUCCESS(err);
2900 if (image_format_properties.maxExtent.width == 0) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07002901 printf(" Sparse image format not supported; skipped.\n");
Cort Strattonf1d8a4a2017-01-28 14:17:04 -08002902 return;
2903 } else {
2904 VkImage sparse_image = VK_NULL_HANDLE;
2905 err = vkCreateImage(m_device->device(), &sparse_image_create_info, NULL, &sparse_image);
2906 ASSERT_VK_SUCCESS(err);
2907 VkMemoryRequirements sparse_mem_reqs = {};
2908 vkGetImageMemoryRequirements(m_device->device(), sparse_image, &sparse_mem_reqs);
2909 if (sparse_mem_reqs.memoryTypeBits != 0) {
2910 VkMemoryAllocateInfo sparse_mem_alloc = {};
2911 sparse_mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2912 sparse_mem_alloc.pNext = NULL;
2913 sparse_mem_alloc.allocationSize = sparse_mem_reqs.size;
2914 sparse_mem_alloc.memoryTypeIndex = 0;
2915 pass = m_device->phy().set_memory_type(sparse_mem_reqs.memoryTypeBits, &sparse_mem_alloc, 0);
2916 ASSERT_TRUE(pass);
2917 VkDeviceMemory sparse_mem = VK_NULL_HANDLE;
2918 err = vkAllocateMemory(m_device->device(), &sparse_mem_alloc, NULL, &sparse_mem);
2919 ASSERT_VK_SUCCESS(err);
2920 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00804);
2921 err = vkBindImageMemory(m_device->device(), sparse_image, sparse_mem, 0);
2922 // This may very well return an error.
2923 (void)err;
2924 m_errorMonitor->VerifyFound();
2925 vkFreeMemory(m_device->device(), sparse_mem, NULL);
2926 }
2927 vkDestroyImage(m_device->device(), sparse_image, NULL);
2928 }
2929 }
2930 }
2931
2932 // Try to bind memory to a buffer created with sparse memory flags
2933 {
2934 VkBufferCreateInfo sparse_buffer_create_info = buffer_create_info;
2935 sparse_buffer_create_info.flags |= VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
2936 if (!m_device->phy().features().sparseResidencyBuffer) {
2937 // most likely means sparse formats aren't supported here; skip this test.
2938 } else {
2939 VkBuffer sparse_buffer = VK_NULL_HANDLE;
2940 err = vkCreateBuffer(m_device->device(), &sparse_buffer_create_info, NULL, &sparse_buffer);
2941 ASSERT_VK_SUCCESS(err);
2942 VkMemoryRequirements sparse_mem_reqs = {};
2943 vkGetBufferMemoryRequirements(m_device->device(), sparse_buffer, &sparse_mem_reqs);
2944 if (sparse_mem_reqs.memoryTypeBits != 0) {
2945 VkMemoryAllocateInfo sparse_mem_alloc = {};
2946 sparse_mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2947 sparse_mem_alloc.pNext = NULL;
2948 sparse_mem_alloc.allocationSize = sparse_mem_reqs.size;
2949 sparse_mem_alloc.memoryTypeIndex = 0;
2950 pass = m_device->phy().set_memory_type(sparse_mem_reqs.memoryTypeBits, &sparse_mem_alloc, 0);
2951 ASSERT_TRUE(pass);
2952 VkDeviceMemory sparse_mem = VK_NULL_HANDLE;
2953 err = vkAllocateMemory(m_device->device(), &sparse_mem_alloc, NULL, &sparse_mem);
2954 ASSERT_VK_SUCCESS(err);
2955 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00792);
2956 err = vkBindBufferMemory(m_device->device(), sparse_buffer, sparse_mem, 0);
2957 // This may very well return an error.
2958 (void)err;
2959 m_errorMonitor->VerifyFound();
2960 vkFreeMemory(m_device->device(), sparse_mem, NULL);
2961 }
2962 vkDestroyBuffer(m_device->device(), sparse_buffer, NULL);
2963 }
2964 }
Tobin Ehlisec598302015-09-15 15:02:17 -06002965}
2966
Karl Schultz6addd812016-02-02 17:17:23 -07002967TEST_F(VkLayerTest, BindMemoryToDestroyedObject) {
2968 VkResult err;
2969 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002970
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002971 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00808);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002972
Tony Barbour1fa09702017-03-16 12:09:08 -06002973 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisec598302015-09-15 15:02:17 -06002974
Karl Schultz6addd812016-02-02 17:17:23 -07002975 // Create an image object, allocate memory, destroy the object and then try
2976 // to bind it
2977 VkImage image;
2978 VkDeviceMemory mem;
2979 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06002980
Karl Schultz6addd812016-02-02 17:17:23 -07002981 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2982 const int32_t tex_width = 32;
2983 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06002984
2985 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002986 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2987 image_create_info.pNext = NULL;
2988 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2989 image_create_info.format = tex_format;
2990 image_create_info.extent.width = tex_width;
2991 image_create_info.extent.height = tex_height;
2992 image_create_info.extent.depth = 1;
2993 image_create_info.mipLevels = 1;
2994 image_create_info.arrayLayers = 1;
2995 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2996 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2997 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2998 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002999
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003000 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003001 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
3002 mem_alloc.pNext = NULL;
3003 mem_alloc.allocationSize = 0;
3004 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06003005
Chia-I Wuf7458c52015-10-26 21:10:41 +08003006 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06003007 ASSERT_VK_SUCCESS(err);
3008
Karl Schultz6addd812016-02-02 17:17:23 -07003009 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06003010
3011 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003012 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06003013 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06003014
3015 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003016 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06003017 ASSERT_VK_SUCCESS(err);
3018
3019 // Introduce validation failure, destroy Image object before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08003020 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06003021 ASSERT_VK_SUCCESS(err);
3022
3023 // Now Try to bind memory to this destroyed object
3024 err = vkBindImageMemory(m_device->device(), image, mem, 0);
3025 // This may very well return an error.
Karl Schultz6addd812016-02-02 17:17:23 -07003026 (void)err;
Tobin Ehlisec598302015-09-15 15:02:17 -06003027
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003028 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06003029
Chia-I Wuf7458c52015-10-26 21:10:41 +08003030 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003031}
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003032
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -07003033TEST_F(VkLayerTest, CreatePipelineBadVertexAttributeFormat) {
3034 TEST_DESCRIPTION("Test that pipeline validation catches invalid vertex attribute formats");
3035
Tony Barbour1fa09702017-03-16 12:09:08 -06003036 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -07003037 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3038
3039 VkVertexInputBindingDescription input_binding;
3040 memset(&input_binding, 0, sizeof(input_binding));
3041
3042 VkVertexInputAttributeDescription input_attribs;
3043 memset(&input_attribs, 0, sizeof(input_attribs));
3044
3045 // Pick a really bad format for this purpose and make sure it should fail
3046 input_attribs.format = VK_FORMAT_BC2_UNORM_BLOCK;
3047 VkFormatProperties format_props = m_device->format_properties(input_attribs.format);
3048 if ((format_props.bufferFeatures & VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT) != 0) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07003049 printf(" Format unsuitable for test; skipped.\n");
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -07003050 return;
3051 }
3052
3053 input_attribs.location = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003054 char const *vsSource =
3055 "#version 450\n"
3056 "\n"
3057 "out gl_PerVertex {\n"
3058 " vec4 gl_Position;\n"
3059 "};\n"
3060 "void main(){\n"
3061 " gl_Position = vec4(1);\n"
3062 "}\n";
3063 char const *fsSource =
3064 "#version 450\n"
3065 "\n"
3066 "layout(location=0) out vec4 color;\n"
3067 "void main(){\n"
3068 " color = vec4(1);\n"
3069 "}\n";
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -07003070
3071 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01413);
3072 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
3073 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
3074
3075 VkPipelineObj pipe(m_device);
3076 pipe.AddColorAttachment();
3077 pipe.AddShader(&vs);
3078 pipe.AddShader(&fs);
3079
3080 pipe.AddVertexInputBindings(&input_binding, 1);
3081 pipe.AddVertexInputAttribs(&input_attribs, 1);
3082
3083 VkDescriptorSetObj descriptorSet(m_device);
3084 descriptorSet.AppendDummy();
3085 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
3086
3087 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
3088
3089 m_errorMonitor->VerifyFound();
3090}
3091
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003092TEST_F(VkLayerTest, ImageSampleCounts) {
Jeremy Hayes0d104082017-02-21 10:24:16 -07003093 TEST_DESCRIPTION("Use bad sample counts in image transfer calls to trigger validation errors.");
Tony Barbour1fa09702017-03-16 12:09:08 -06003094 ASSERT_NO_FATAL_FAILURE(Init(nullptr, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT));
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003095
3096 VkMemoryPropertyFlags reqs = 0;
3097 VkImageCreateInfo image_create_info = {};
3098 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3099 image_create_info.pNext = NULL;
3100 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3101 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
3102 image_create_info.extent.width = 256;
3103 image_create_info.extent.height = 256;
3104 image_create_info.extent.depth = 1;
3105 image_create_info.mipLevels = 1;
3106 image_create_info.arrayLayers = 1;
3107 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
3108 image_create_info.flags = 0;
3109
3110 VkImageBlit blit_region = {};
3111 blit_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3112 blit_region.srcSubresource.baseArrayLayer = 0;
3113 blit_region.srcSubresource.layerCount = 1;
3114 blit_region.srcSubresource.mipLevel = 0;
3115 blit_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3116 blit_region.dstSubresource.baseArrayLayer = 0;
3117 blit_region.dstSubresource.layerCount = 1;
3118 blit_region.dstSubresource.mipLevel = 0;
3119
3120 // Create two images, the source with sampleCount = 2, and attempt to blit
3121 // between them
3122 {
3123 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003124 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003125 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003126 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003127 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003128 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003129 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003130 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003131 m_commandBuffer->BeginCommandBuffer();
Jeremy Hayes0d104082017-02-21 10:24:16 -07003132 m_errorMonitor->SetDesiredFailureMsg(
3133 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3134 "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 -06003135 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3136 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003137 m_errorMonitor->VerifyFound();
3138 m_commandBuffer->EndCommandBuffer();
3139 }
3140
3141 // Create two images, the dest with sampleCount = 4, and attempt to blit
3142 // between them
3143 {
3144 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003145 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003146 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003147 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003148 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003149 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003150 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003151 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003152 m_commandBuffer->BeginCommandBuffer();
Jeremy Hayes0d104082017-02-21 10:24:16 -07003153 m_errorMonitor->SetDesiredFailureMsg(
3154 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3155 "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 -06003156 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3157 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003158 m_errorMonitor->VerifyFound();
3159 m_commandBuffer->EndCommandBuffer();
3160 }
3161
3162 VkBufferImageCopy copy_region = {};
3163 copy_region.bufferRowLength = 128;
3164 copy_region.bufferImageHeight = 128;
3165 copy_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3166 copy_region.imageSubresource.layerCount = 1;
3167 copy_region.imageExtent.height = 64;
3168 copy_region.imageExtent.width = 64;
3169 copy_region.imageExtent.depth = 1;
3170
3171 // Create src buffer and dst image with sampleCount = 4 and attempt to copy
3172 // buffer to image
3173 {
3174 vk_testing::Buffer src_buffer;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003175 src_buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
3176 image_create_info.samples = VK_SAMPLE_COUNT_8_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003177 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003178 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003179 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003180 m_commandBuffer->BeginCommandBuffer();
Jeremy Hayes0d104082017-02-21 10:24:16 -07003181 m_errorMonitor->SetDesiredFailureMsg(
3182 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3183 "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 -06003184 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), src_buffer.handle(), dst_image.handle(),
3185 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &copy_region);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003186 m_errorMonitor->VerifyFound();
3187 m_commandBuffer->EndCommandBuffer();
3188 }
3189
3190 // Create dst buffer and src image with sampleCount = 2 and attempt to copy
3191 // image to buffer
3192 {
3193 vk_testing::Buffer dst_buffer;
3194 dst_buffer.init_as_dst(*m_device, 128 * 128 * 4, reqs);
3195 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003196 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003197 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003198 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003199 m_commandBuffer->BeginCommandBuffer();
Jeremy Hayes0d104082017-02-21 10:24:16 -07003200 m_errorMonitor->SetDesiredFailureMsg(
3201 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3202 "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 -06003203 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003204 dst_buffer.handle(), 1, &copy_region);
3205 m_errorMonitor->VerifyFound();
3206 m_commandBuffer->EndCommandBuffer();
3207 }
3208}
3209
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003210TEST_F(VkLayerTest, BlitImageFormats) {
Tony Barbour1fa09702017-03-16 12:09:08 -06003211 ASSERT_NO_FATAL_FAILURE(Init());
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003212
3213 VkImageObj src_image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06003214 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 -06003215 VkImageObj dst_image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06003216 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 -06003217 VkImageObj dst_image2(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06003218 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 -06003219
3220 VkImageBlit blitRegion = {};
3221 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3222 blitRegion.srcSubresource.baseArrayLayer = 0;
3223 blitRegion.srcSubresource.layerCount = 1;
3224 blitRegion.srcSubresource.mipLevel = 0;
3225 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3226 blitRegion.dstSubresource.baseArrayLayer = 0;
3227 blitRegion.dstSubresource.layerCount = 1;
3228 blitRegion.dstSubresource.mipLevel = 0;
3229
Dave Houlton34df4cb2016-12-01 16:43:06 -07003230 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02191);
3231
3232 // TODO: there are 9 permutations of signed, unsigned, & other for source and dest
3233 // this test is only checking 2 of them at the moment
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003234
3235 // Unsigned int vs not an int
Tony Barbour552f6c02016-12-21 14:34:07 -07003236 m_commandBuffer->BeginCommandBuffer();
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06003237 vkCmdBlitImage(m_commandBuffer->handle(), src_image.image(), src_image.Layout(), dst_image.image(), dst_image.Layout(), 1,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003238 &blitRegion, VK_FILTER_NEAREST);
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003239
3240 m_errorMonitor->VerifyFound();
3241
Dave Houlton34df4cb2016-12-01 16:43:06 -07003242 // Test should generate 2 VU failures
3243 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02190);
3244 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02191);
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003245
3246 // Unsigned int vs signed int
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06003247 vkCmdBlitImage(m_commandBuffer->handle(), src_image.image(), src_image.Layout(), dst_image2.image(), dst_image2.Layout(), 1,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003248 &blitRegion, VK_FILTER_NEAREST);
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003249
Dave Houlton34df4cb2016-12-01 16:43:06 -07003250 // TODO: Note that this only verifies that at least one of the VU enums was found
3251 // 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 -06003252 m_errorMonitor->VerifyFound();
3253
Tony Barbour552f6c02016-12-21 14:34:07 -07003254 m_commandBuffer->EndCommandBuffer();
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003255}
3256
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003257TEST_F(VkLayerTest, DSImageTransferGranularityTests) {
3258 VkResult err;
3259 bool pass;
3260
3261 TEST_DESCRIPTION("Tests for validaiton of Queue Family property minImageTransferGranularity.");
Tony Barbour1fa09702017-03-16 12:09:08 -06003262 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003263
3264 // If w/d/h granularity is 1, test is not meaningful
3265 // TODO: When virtual device limits are available, create a set of limits for this test that
3266 // will always have a granularity of > 1 for w, h, and d
3267 auto index = m_device->graphics_queue_node_index_;
3268 auto queue_family_properties = m_device->phy().queue_properties();
3269
3270 if ((queue_family_properties[index].minImageTransferGranularity.depth < 4) ||
3271 (queue_family_properties[index].minImageTransferGranularity.width < 4) ||
3272 (queue_family_properties[index].minImageTransferGranularity.height < 4)) {
3273 return;
3274 }
3275
3276 // Create two images of different types and try to copy between them
3277 VkImage srcImage;
3278 VkImage dstImage;
3279 VkDeviceMemory srcMem;
3280 VkDeviceMemory destMem;
3281 VkMemoryRequirements memReqs;
3282
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003283 VkImageCreateInfo image_create_info = {};
3284 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3285 image_create_info.pNext = NULL;
3286 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3287 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
3288 image_create_info.extent.width = 32;
3289 image_create_info.extent.height = 32;
3290 image_create_info.extent.depth = 1;
3291 image_create_info.mipLevels = 1;
3292 image_create_info.arrayLayers = 4;
3293 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
3294 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
3295 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
3296 image_create_info.flags = 0;
3297
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003298 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003299 ASSERT_VK_SUCCESS(err);
3300
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003301 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003302 ASSERT_VK_SUCCESS(err);
3303
3304 // Allocate memory
3305 VkMemoryAllocateInfo memAlloc = {};
3306 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
3307 memAlloc.pNext = NULL;
3308 memAlloc.allocationSize = 0;
3309 memAlloc.memoryTypeIndex = 0;
3310
3311 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
3312 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003313 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003314 ASSERT_TRUE(pass);
3315 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
3316 ASSERT_VK_SUCCESS(err);
3317
3318 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
3319 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003320 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003321 ASSERT_VK_SUCCESS(err);
3322 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
3323 ASSERT_VK_SUCCESS(err);
3324
3325 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
3326 ASSERT_VK_SUCCESS(err);
3327 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
3328 ASSERT_VK_SUCCESS(err);
3329
Tony Barbour552f6c02016-12-21 14:34:07 -07003330 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003331 VkImageCopy copyRegion;
3332 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3333 copyRegion.srcSubresource.mipLevel = 0;
3334 copyRegion.srcSubresource.baseArrayLayer = 0;
3335 copyRegion.srcSubresource.layerCount = 1;
3336 copyRegion.srcOffset.x = 0;
3337 copyRegion.srcOffset.y = 0;
3338 copyRegion.srcOffset.z = 0;
3339 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3340 copyRegion.dstSubresource.mipLevel = 0;
3341 copyRegion.dstSubresource.baseArrayLayer = 0;
3342 copyRegion.dstSubresource.layerCount = 1;
3343 copyRegion.dstOffset.x = 0;
3344 copyRegion.dstOffset.y = 0;
3345 copyRegion.dstOffset.z = 0;
3346 copyRegion.extent.width = 1;
3347 copyRegion.extent.height = 1;
3348 copyRegion.extent.depth = 1;
3349
3350 // Introduce failure by setting srcOffset to a bad granularity value
3351 copyRegion.srcOffset.y = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003352 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3353 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003354 m_errorMonitor->VerifyFound();
3355
3356 // Introduce failure by setting extent to a bad granularity value
3357 copyRegion.srcOffset.y = 0;
3358 copyRegion.extent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003359 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3360 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003361 m_errorMonitor->VerifyFound();
3362
3363 // Now do some buffer/image copies
3364 vk_testing::Buffer buffer;
3365 VkMemoryPropertyFlags reqs = 0;
3366 buffer.init_as_dst(*m_device, 128 * 128, reqs);
3367 VkBufferImageCopy region = {};
3368 region.bufferOffset = 0;
3369 region.bufferRowLength = 3;
3370 region.bufferImageHeight = 128;
3371 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3372 region.imageSubresource.layerCount = 1;
3373 region.imageExtent.height = 16;
3374 region.imageExtent.width = 16;
3375 region.imageExtent.depth = 1;
3376 region.imageOffset.x = 0;
3377 region.imageOffset.y = 0;
3378 region.imageOffset.z = 0;
3379
3380 // Introduce failure by setting bufferRowLength to a bad granularity value
3381 region.bufferRowLength = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003382 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3383 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
3384 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003385 m_errorMonitor->VerifyFound();
3386 region.bufferRowLength = 128;
3387
3388 // Introduce failure by setting bufferOffset to a bad granularity value
3389 region.bufferOffset = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003390 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3391 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
3392 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003393 m_errorMonitor->VerifyFound();
3394 region.bufferOffset = 0;
3395
3396 // Introduce failure by setting bufferImageHeight to a bad granularity value
3397 region.bufferImageHeight = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003398 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3399 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
3400 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003401 m_errorMonitor->VerifyFound();
3402 region.bufferImageHeight = 128;
3403
3404 // Introduce failure by setting imageExtent to a bad granularity value
3405 region.imageExtent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003406 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3407 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
3408 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003409 m_errorMonitor->VerifyFound();
3410 region.imageExtent.width = 16;
3411
3412 // Introduce failure by setting imageOffset to a bad granularity value
3413 region.imageOffset.z = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003414 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3415 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
3416 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003417 m_errorMonitor->VerifyFound();
3418
Tony Barbour552f6c02016-12-21 14:34:07 -07003419 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003420
3421 vkDestroyImage(m_device->device(), srcImage, NULL);
3422 vkDestroyImage(m_device->device(), dstImage, NULL);
3423 vkFreeMemory(m_device->device(), srcMem, NULL);
3424 vkFreeMemory(m_device->device(), destMem, NULL);
3425}
3426
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003427TEST_F(VkLayerTest, MismatchedQueueFamiliesOnSubmit) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003428 TEST_DESCRIPTION(
3429 "Submit command buffer created using one queue family and "
3430 "attempt to submit them on a queue created in a different "
3431 "queue family.");
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003432
Tony Barbour1fa09702017-03-16 12:09:08 -06003433 ASSERT_NO_FATAL_FAILURE(Init());
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07003434
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003435 // This test is meaningless unless we have multiple queue families
3436 auto queue_family_properties = m_device->phy().queue_properties();
3437 if (queue_family_properties.size() < 2) {
3438 return;
3439 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003440 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is being submitted on queue ");
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003441 // Get safe index of another queue family
3442 uint32_t other_queue_family = (m_device->graphics_queue_node_index_ == 0) ? 1 : 0;
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003443 VkQueue other_queue;
3444 vkGetDeviceQueue(m_device->device(), other_queue_family, 0, &other_queue);
3445
3446 // Record an empty cmd buffer
3447 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
3448 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3449 vkBeginCommandBuffer(m_commandBuffer->handle(), &cmdBufBeginDesc);
3450 vkEndCommandBuffer(m_commandBuffer->handle());
3451
3452 // And submit on the wrong queue
3453 VkSubmitInfo submit_info = {};
3454 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3455 submit_info.commandBufferCount = 1;
3456 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Tobin Ehlisfd213ea2016-08-10 17:10:46 -06003457 vkQueueSubmit(other_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003458
3459 m_errorMonitor->VerifyFound();
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003460}
3461
Chris Forbes4c24a922016-11-16 08:59:10 +13003462TEST_F(VkLayerTest, RenderPassAttachmentIndexOutOfRange) {
Tony Barbour1fa09702017-03-16 12:09:08 -06003463 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes4c24a922016-11-16 08:59:10 +13003464
Chris Forbes2d9b2a82016-11-21 10:45:39 +13003465 // There are no attachments, but refer to attachment 0.
3466 VkAttachmentReference ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbes4c24a922016-11-16 08:59:10 +13003467 VkSubpassDescription subpasses[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003468 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &ref, nullptr, nullptr, 0, nullptr},
Chris Forbes4c24a922016-11-16 08:59:10 +13003469 };
3470
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003471 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 1, subpasses, 0, nullptr};
Chris Forbes4c24a922016-11-16 08:59:10 +13003472 VkRenderPass rp;
3473
Chris Forbes2d9b2a82016-11-21 10:45:39 +13003474 // "... must be less than the total number of attachments ..."
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003475 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00325);
Chris Forbes4c24a922016-11-16 08:59:10 +13003476 vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3477 m_errorMonitor->VerifyFound();
3478}
3479
Chris Forbesa58c4522016-09-28 15:19:39 +13003480TEST_F(VkLayerTest, RenderPassPipelineSubpassMismatch) {
3481 TEST_DESCRIPTION("Use a pipeline for the wrong subpass in a render pass instance");
Tony Barbour1fa09702017-03-16 12:09:08 -06003482 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbesa58c4522016-09-28 15:19:39 +13003483
3484 // A renderpass with two subpasses, both writing the same attachment.
3485 VkAttachmentDescription attach[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003486 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3487 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_UNDEFINED,
3488 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesa58c4522016-09-28 15:19:39 +13003489 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003490 VkAttachmentReference ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbesa58c4522016-09-28 15:19:39 +13003491 VkSubpassDescription subpasses[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003492 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &ref, nullptr, nullptr, 0, nullptr},
3493 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &ref, nullptr, nullptr, 0, nullptr},
Chris Forbesa58c4522016-09-28 15:19:39 +13003494 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003495 VkSubpassDependency dep = {0,
3496 1,
3497 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
3498 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
3499 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
3500 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
3501 VK_DEPENDENCY_BY_REGION_BIT};
3502 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, attach, 2, subpasses, 1, &dep};
Chris Forbesa58c4522016-09-28 15:19:39 +13003503 VkRenderPass rp;
3504 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3505 ASSERT_VK_SUCCESS(err);
3506
3507 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06003508 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 +13003509 VkImageView imageView = image.targetView(VK_FORMAT_R8G8B8A8_UNORM);
3510
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003511 VkFramebufferCreateInfo fbci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &imageView, 32, 32, 1};
Chris Forbesa58c4522016-09-28 15:19:39 +13003512 VkFramebuffer fb;
3513 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
3514 ASSERT_VK_SUCCESS(err);
3515
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003516 char const *vsSource =
3517 "#version 450\n"
3518 "void main() { gl_Position = vec4(1); }\n";
3519 char const *fsSource =
3520 "#version 450\n"
3521 "layout(location=0) out vec4 color;\n"
3522 "void main() { color = vec4(1); }\n";
Chris Forbesa58c4522016-09-28 15:19:39 +13003523
3524 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
3525 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
3526 VkPipelineObj pipe(m_device);
3527 pipe.AddColorAttachment();
3528 pipe.AddShader(&vs);
3529 pipe.AddShader(&fs);
3530 VkViewport view_port = {};
3531 m_viewports.push_back(view_port);
3532 pipe.SetViewport(m_viewports);
3533 VkRect2D rect = {};
3534 m_scissors.push_back(rect);
3535 pipe.SetScissor(m_scissors);
3536
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003537 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 0, nullptr, 0, nullptr};
Chris Forbesa58c4522016-09-28 15:19:39 +13003538 VkPipelineLayout pl;
3539 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
3540 ASSERT_VK_SUCCESS(err);
3541 pipe.CreateVKPipeline(pl, rp);
3542
Tony Barbour552f6c02016-12-21 14:34:07 -07003543 m_commandBuffer->BeginCommandBuffer();
Chris Forbesa58c4522016-09-28 15:19:39 +13003544
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003545 VkRenderPassBeginInfo rpbi = {VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO,
3546 nullptr,
3547 rp,
3548 fb,
3549 {{
3550 0, 0,
3551 },
3552 {32, 32}},
3553 0,
3554 nullptr};
Chris Forbesa58c4522016-09-28 15:19:39 +13003555
3556 // subtest 1: bind in the wrong subpass
3557 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
3558 vkCmdNextSubpass(m_commandBuffer->handle(), VK_SUBPASS_CONTENTS_INLINE);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003559 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "built for subpass 0 but used in subpass 1");
Chris Forbesa58c4522016-09-28 15:19:39 +13003560 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
3561 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
3562 m_errorMonitor->VerifyFound();
3563
3564 vkCmdEndRenderPass(m_commandBuffer->handle());
3565
3566 // subtest 2: bind in correct subpass, then transition to next subpass
3567 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
3568 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
3569 vkCmdNextSubpass(m_commandBuffer->handle(), VK_SUBPASS_CONTENTS_INLINE);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003570 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 +13003571 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
3572 m_errorMonitor->VerifyFound();
3573
3574 vkCmdEndRenderPass(m_commandBuffer->handle());
3575
Tony Barbour552f6c02016-12-21 14:34:07 -07003576 m_commandBuffer->EndCommandBuffer();
Chris Forbesa58c4522016-09-28 15:19:39 +13003577
3578 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
3579 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
3580 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3581}
3582
Tony Barbour4e919972016-08-09 13:27:40 -06003583TEST_F(VkLayerTest, RenderPassInvalidRenderArea) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003584 TEST_DESCRIPTION(
3585 "Generate INVALID_RENDER_AREA error by beginning renderpass"
3586 "with extent outside of framebuffer");
Tony Barbour1fa09702017-03-16 12:09:08 -06003587 ASSERT_NO_FATAL_FAILURE(Init());
Tony Barbour4e919972016-08-09 13:27:40 -06003588 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3589
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003590 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3591 "Cannot execute a render pass with renderArea "
3592 "not within the bound of the framebuffer.");
Tony Barbour4e919972016-08-09 13:27:40 -06003593
3594 // Framebuffer for render target is 256x256, exceed that for INVALID_RENDER_AREA
3595 m_renderPassBeginInfo.renderArea.extent.width = 257;
3596 m_renderPassBeginInfo.renderArea.extent.height = 257;
Tony Barbour552f6c02016-12-21 14:34:07 -07003597 m_commandBuffer->BeginCommandBuffer();
3598 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tony Barbour4e919972016-08-09 13:27:40 -06003599 m_errorMonitor->VerifyFound();
3600}
3601
3602TEST_F(VkLayerTest, DisabledIndependentBlend) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003603 TEST_DESCRIPTION(
3604 "Generate INDEPENDENT_BLEND by disabling independent "
3605 "blend and then specifying different blend states for two "
3606 "attachements");
Cody Northrop5703cc72016-08-19 09:57:10 -06003607 VkPhysicalDeviceFeatures features = {};
3608 features.independentBlend = VK_FALSE;
Tony Barbour1fa09702017-03-16 12:09:08 -06003609 ASSERT_NO_FATAL_FAILURE(Init(&features));
Tony Barbour4e919972016-08-09 13:27:40 -06003610
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003611 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3612 "Invalid Pipeline CreateInfo: If independent blend feature not "
3613 "enabled, all elements of pAttachments must be identical");
Tony Barbour4e919972016-08-09 13:27:40 -06003614
Cody Northropc31a84f2016-08-22 10:41:47 -06003615 VkDescriptorSetObj descriptorSet(m_device);
3616 descriptorSet.AppendDummy();
3617 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Tony Barbour4e919972016-08-09 13:27:40 -06003618
Cody Northropc31a84f2016-08-22 10:41:47 -06003619 VkPipelineObj pipeline(m_device);
Tony Barbour0ace59a2017-02-06 13:38:36 -07003620 // Create a renderPass with two color attachments
3621 VkAttachmentReference attachments[2] = {};
3622 attachments[0].layout = VK_IMAGE_LAYOUT_GENERAL;
Tony Barbourffd60bd2017-03-09 12:04:55 -07003623 attachments[1].attachment = 1;
Tony Barbour0ace59a2017-02-06 13:38:36 -07003624 attachments[1].layout = VK_IMAGE_LAYOUT_GENERAL;
3625
3626 VkSubpassDescription subpass = {};
3627 subpass.pColorAttachments = attachments;
3628 subpass.colorAttachmentCount = 2;
3629
3630 VkRenderPassCreateInfo rpci = {};
3631 rpci.subpassCount = 1;
3632 rpci.pSubpasses = &subpass;
Tony Barbourffd60bd2017-03-09 12:04:55 -07003633 rpci.attachmentCount = 2;
Tony Barbour0ace59a2017-02-06 13:38:36 -07003634
Tony Barbourffd60bd2017-03-09 12:04:55 -07003635 VkAttachmentDescription attach_desc[2] = {};
3636 attach_desc[0].format = VK_FORMAT_B8G8R8A8_UNORM;
3637 attach_desc[0].samples = VK_SAMPLE_COUNT_1_BIT;
3638 attach_desc[0].initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
3639 attach_desc[0].finalLayout = VK_IMAGE_LAYOUT_GENERAL;
3640 attach_desc[1].format = VK_FORMAT_B8G8R8A8_UNORM;
3641 attach_desc[1].samples = VK_SAMPLE_COUNT_1_BIT;
3642 attach_desc[1].initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
3643 attach_desc[1].finalLayout = VK_IMAGE_LAYOUT_GENERAL;
Tony Barbour0ace59a2017-02-06 13:38:36 -07003644
Tony Barbourffd60bd2017-03-09 12:04:55 -07003645 rpci.pAttachments = attach_desc;
Tony Barbour0ace59a2017-02-06 13:38:36 -07003646 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3647
3648 VkRenderPass renderpass;
3649 vkCreateRenderPass(m_device->device(), &rpci, NULL, &renderpass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003650 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Cody Northropc31a84f2016-08-22 10:41:47 -06003651 pipeline.AddShader(&vs);
Cody Northrop5703cc72016-08-19 09:57:10 -06003652
Cody Northropc31a84f2016-08-22 10:41:47 -06003653 VkPipelineColorBlendAttachmentState att_state1 = {}, att_state2 = {};
3654 att_state1.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3655 att_state1.blendEnable = VK_TRUE;
3656 att_state2.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3657 att_state2.blendEnable = VK_FALSE;
3658 pipeline.AddColorAttachment(0, &att_state1);
3659 pipeline.AddColorAttachment(1, &att_state2);
Tony Barbour0ace59a2017-02-06 13:38:36 -07003660 pipeline.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderpass);
Cody Northropc31a84f2016-08-22 10:41:47 -06003661 m_errorMonitor->VerifyFound();
Tony Barbour0ace59a2017-02-06 13:38:36 -07003662 vkDestroyRenderPass(m_device->device(), renderpass, NULL);
Tony Barbour4e919972016-08-09 13:27:40 -06003663}
3664
Mike Weiblen40b160e2017-02-06 19:21:52 -07003665// Is the Pipeline compatible with the expectations of the Renderpass/subpasses?
3666TEST_F(VkLayerTest, PipelineRenderpassCompatibility) {
3667 TEST_DESCRIPTION(
3668 "Create a graphics pipeline that is incompatible with the requirements "
3669 "of its contained Renderpass/subpasses.");
Tony Barbour1fa09702017-03-16 12:09:08 -06003670 ASSERT_NO_FATAL_FAILURE(Init());
Mike Weiblen40b160e2017-02-06 19:21:52 -07003671
3672 VkDescriptorSetObj ds_obj(m_device);
3673 ds_obj.AppendDummy();
3674 ds_obj.CreateVKDescriptorSet(m_commandBuffer);
3675
3676 VkShaderObj vs_obj(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
3677
3678 VkPipelineColorBlendAttachmentState att_state1 = {};
3679 att_state1.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3680 att_state1.blendEnable = VK_TRUE;
3681
3682 VkRenderpassObj rp_obj(m_device);
3683
3684 {
3685 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02116);
3686 VkPipelineObj pipeline(m_device);
3687 pipeline.AddShader(&vs_obj);
3688 pipeline.AddColorAttachment(0, &att_state1);
3689
3690 VkGraphicsPipelineCreateInfo info = {};
3691 pipeline.InitGraphicsPipelineCreateInfo(&info);
3692 info.pColorBlendState = nullptr;
3693
3694 pipeline.CreateVKPipeline(ds_obj.GetPipelineLayout(), rp_obj.handle(), &info);
3695 m_errorMonitor->VerifyFound();
3696 }
3697}
3698
Cort Stratton7547f772017-05-04 15:18:52 -07003699TEST_F(VkLayerTest, CreateRenderPassAttachments) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003700 TEST_DESCRIPTION(
Cort Stratton7547f772017-05-04 15:18:52 -07003701 "Ensure that CreateRenderPass produces the expected validation errors "
3702 "when a subpass's attachments violate the valid usage conditions.");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003703
Tony Barbour1fa09702017-03-16 12:09:08 -06003704 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003705
Cort Stratton7547f772017-05-04 15:18:52 -07003706 std::vector<VkAttachmentDescription> attachments = {
3707 // input attachments
3708 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3709 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_GENERAL,
3710 VK_IMAGE_LAYOUT_GENERAL},
3711 // color attachments
3712 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3713 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3714 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3715 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3716 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3717 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3718 // depth attachment
3719 {0, VK_FORMAT_D24_UNORM_S8_UINT, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3720 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
3721 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL},
3722 // resolve attachment
3723 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_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_COLOR_ATTACHMENT_OPTIMAL,
3725 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3726 // preserve 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 };
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003731
Cort Stratton7547f772017-05-04 15:18:52 -07003732 std::vector<VkAttachmentReference> input = {
3733 {0, VK_IMAGE_LAYOUT_GENERAL},
3734 };
3735 std::vector<VkAttachmentReference> color = {
3736 {1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL}, {2, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3737 };
3738 VkAttachmentReference depth = {3, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
3739 std::vector<VkAttachmentReference> resolve = {
3740 {4, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL}, {VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3741 };
3742 std::vector<uint32_t> preserve = {5};
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003743
Cort Stratton7547f772017-05-04 15:18:52 -07003744 VkSubpassDescription subpass = {0,
3745 VK_PIPELINE_BIND_POINT_GRAPHICS,
3746 (uint32_t)input.size(),
3747 input.data(),
3748 (uint32_t)color.size(),
3749 color.data(),
3750 resolve.data(),
3751 &depth,
3752 (uint32_t)preserve.size(),
3753 preserve.data()};
3754
3755 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO,
3756 nullptr,
3757 0,
3758 (uint32_t)attachments.size(),
3759 attachments.data(),
3760 1,
3761 &subpass,
3762 0,
3763 nullptr};
3764
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003765 VkRenderPass rp;
Cort Stratton7547f772017-05-04 15:18:52 -07003766 VkResult err;
3767 // Test too many color attachments
3768 {
3769 std::vector<VkAttachmentReference> too_many_colors(m_device->props.limits.maxColorAttachments + 1, color[0]);
3770 subpass.colorAttachmentCount = (uint32_t)too_many_colors.size();
3771 subpass.pColorAttachments = too_many_colors.data();
3772 subpass.pResolveAttachments = NULL;
3773 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00348);
3774 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3775 m_errorMonitor->VerifyFound();
3776 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
3777 subpass.colorAttachmentCount = (uint32_t)color.size();
3778 subpass.pColorAttachments = color.data();
3779 subpass.pResolveAttachments = resolve.data();
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003780 }
Cort Stratton7547f772017-05-04 15:18:52 -07003781 // Test sample count mismatch between color buffers
3782 attachments[subpass.pColorAttachments[1].attachment].samples = VK_SAMPLE_COUNT_8_BIT;
3783 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00337);
3784 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
Chris Forbesc5389742016-06-29 11:49:23 +12003785 m_errorMonitor->VerifyFound();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003786 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
Cort Stratton7547f772017-05-04 15:18:52 -07003787 attachments[subpass.pColorAttachments[1].attachment].samples = attachments[subpass.pColorAttachments[0].attachment].samples;
3788 // Test sample count mismatch between color buffers and depth buffer
3789 attachments[subpass.pDepthStencilAttachment->attachment].samples = VK_SAMPLE_COUNT_8_BIT;
3790 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00337);
3791 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
Chris Forbesc5389742016-06-29 11:49:23 +12003792 m_errorMonitor->VerifyFound();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003793 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
Cort Stratton7547f772017-05-04 15:18:52 -07003794 attachments[subpass.pDepthStencilAttachment->attachment].samples = attachments[subpass.pColorAttachments[0].attachment].samples;
3795 // Test resolve attachment with UNUSED color attachment
3796 color[0].attachment = VK_ATTACHMENT_UNUSED;
3797 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00350);
3798 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
Chris Forbes3f128ef2016-06-29 14:58:53 +12003799 m_errorMonitor->VerifyFound();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003800 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
Cort Stratton7547f772017-05-04 15:18:52 -07003801 color[0].attachment = 1;
3802 // Test resolve from a single-sampled color attachment
3803 attachments[subpass.pColorAttachments[0].attachment].samples = VK_SAMPLE_COUNT_1_BIT;
3804 attachments[subpass.pColorAttachments[1].attachment].samples = VK_SAMPLE_COUNT_1_BIT; // avoid mismatch (00337)
3805 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00351);
3806 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3807 m_errorMonitor->VerifyFound();
3808 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
3809 attachments[subpass.pColorAttachments[0].attachment].samples = VK_SAMPLE_COUNT_4_BIT;
3810 attachments[subpass.pColorAttachments[1].attachment].samples = VK_SAMPLE_COUNT_4_BIT;
3811 // Test resolve to a multi-sampled resolve attachment
3812 attachments[subpass.pResolveAttachments[0].attachment].samples = VK_SAMPLE_COUNT_4_BIT;
3813 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00352);
3814 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3815 m_errorMonitor->VerifyFound();
3816 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
3817 attachments[subpass.pResolveAttachments[0].attachment].samples = VK_SAMPLE_COUNT_1_BIT;
3818 // Test with color/resolve format mismatch
3819 attachments[subpass.pColorAttachments[0].attachment].format = VK_FORMAT_R8G8B8A8_SRGB;
3820 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00353);
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].format = attachments[subpass.pResolveAttachments[0].attachment].format;
3825 // Test for UNUSED preserve attachments
3826 preserve[0] = VK_ATTACHMENT_UNUSED;
3827 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00356);
3828 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3829 m_errorMonitor->VerifyFound();
3830 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
3831 preserve[0] = 5;
3832 // Test for preserve attachments used elsewhere in the subpass
3833 color[0].attachment = preserve[0];
3834 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00357);
3835 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3836 m_errorMonitor->VerifyFound();
3837 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
3838 color[0].attachment = 1;
3839 // test for layout mismatch between input attachment and color attachment
3840 input[0].attachment = color[0].attachment;
3841 input[0].layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
3842 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00358);
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 input[0].attachment = 0;
3847 input[0].layout = VK_IMAGE_LAYOUT_GENERAL;
3848 // test for layout mismatch between input attachment and depth attachment
3849 input[0].attachment = depth.attachment;
3850 input[0].layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
3851 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00358);
3852 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3853 m_errorMonitor->VerifyFound();
3854 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
3855 input[0].attachment = 0;
3856 input[0].layout = VK_IMAGE_LAYOUT_GENERAL;
3857 // Test for attachment used first as input with loadOp=CLEAR
3858 {
3859 std::vector<VkSubpassDescription> subpasses = {subpass, subpass, subpass};
3860 subpasses[0].inputAttachmentCount = 0;
3861 subpasses[1].inputAttachmentCount = 0;
3862 attachments[input[0].attachment].loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
3863 VkRenderPassCreateInfo rpci_multipass = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO,
3864 nullptr,
3865 0,
3866 (uint32_t)attachments.size(),
3867 attachments.data(),
3868 (uint32_t)subpasses.size(),
3869 subpasses.data(),
3870 0,
3871 nullptr};
3872 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00349);
3873 err = vkCreateRenderPass(m_device->device(), &rpci_multipass, nullptr, &rp);
3874 m_errorMonitor->VerifyFound();
3875 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
3876 attachments[input[0].attachment].loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
3877 }
Chris Forbes3f128ef2016-06-29 14:58:53 +12003878}
3879
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003880TEST_F(VkLayerTest, FramebufferCreateErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003881 TEST_DESCRIPTION(
3882 "Hit errors when attempting to create a framebuffer :\n"
3883 " 1. Mismatch between framebuffer & renderPass attachmentCount\n"
3884 " 2. Use a color image as depthStencil attachment\n"
3885 " 3. Mismatch framebuffer & renderPass attachment formats\n"
3886 " 4. Mismatch framebuffer & renderPass attachment #samples\n"
3887 " 5. Framebuffer attachment w/ non-1 mip-levels\n"
3888 " 6. Framebuffer attachment where dimensions don't match\n"
Cort Stratton8133ec22017-04-27 16:25:03 +02003889 " 7. Framebuffer attachment where dimensions don't match\n"
3890 " 8. Framebuffer attachment w/o identity swizzle\n"
3891 " 9. framebuffer dimensions exceed physical device limits\n");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003892
Tony Barbour1fa09702017-03-16 12:09:08 -06003893 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003894 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3895
Cort Stratton8133ec22017-04-27 16:25:03 +02003896 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00404);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003897
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003898 // Create a renderPass with a single color attachment
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003899 VkAttachmentReference attach = {};
3900 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
3901 VkSubpassDescription subpass = {};
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003902 subpass.pColorAttachments = &attach;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003903 VkRenderPassCreateInfo rpci = {};
3904 rpci.subpassCount = 1;
3905 rpci.pSubpasses = &subpass;
3906 rpci.attachmentCount = 1;
3907 VkAttachmentDescription attach_desc = {};
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003908 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003909 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003910 rpci.pAttachments = &attach_desc;
3911 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3912 VkRenderPass rp;
3913 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3914 ASSERT_VK_SUCCESS(err);
3915
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003916 VkImageView ivs[2];
3917 ivs[0] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
3918 ivs[1] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003919 VkFramebufferCreateInfo fb_info = {};
3920 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
3921 fb_info.pNext = NULL;
3922 fb_info.renderPass = rp;
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003923 // Set mis-matching attachmentCount
3924 fb_info.attachmentCount = 2;
3925 fb_info.pAttachments = ivs;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003926 fb_info.width = 100;
3927 fb_info.height = 100;
3928 fb_info.layers = 1;
3929
3930 VkFramebuffer fb;
3931 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3932
3933 m_errorMonitor->VerifyFound();
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003934 if (err == VK_SUCCESS) {
3935 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3936 }
3937 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003938
3939 // Create a renderPass with a depth-stencil attachment created with
3940 // IMAGE_USAGE_COLOR_ATTACHMENT
3941 // Add our color attachment to pDepthStencilAttachment
3942 subpass.pDepthStencilAttachment = &attach;
3943 subpass.pColorAttachments = NULL;
3944 VkRenderPass rp_ds;
3945 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp_ds);
3946 ASSERT_VK_SUCCESS(err);
3947 // Set correct attachment count, but attachment has COLOR usage bit set
3948 fb_info.attachmentCount = 1;
3949 fb_info.renderPass = rp_ds;
3950
Cort Stratton8133ec22017-04-27 16:25:03 +02003951 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00406);
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003952 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3953
3954 m_errorMonitor->VerifyFound();
3955 if (err == VK_SUCCESS) {
3956 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3957 }
3958 vkDestroyRenderPass(m_device->device(), rp_ds, NULL);
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003959
3960 // Create new renderpass with alternate attachment format from fb
3961 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
3962 subpass.pDepthStencilAttachment = NULL;
3963 subpass.pColorAttachments = &attach;
3964 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3965 ASSERT_VK_SUCCESS(err);
3966
3967 // Cause error due to mis-matched formats between rp & fb
3968 // rp attachment 0 now has RGBA8 but corresponding fb attach is BGRA8
3969 fb_info.renderPass = rp;
Cort Stratton8133ec22017-04-27 16:25:03 +02003970 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00408);
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003971 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3972
3973 m_errorMonitor->VerifyFound();
3974 if (err == VK_SUCCESS) {
3975 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3976 }
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003977 vkDestroyRenderPass(m_device->device(), rp, NULL);
3978
3979 // Create new renderpass with alternate sample count from fb
3980 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
3981 attach_desc.samples = VK_SAMPLE_COUNT_4_BIT;
3982 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3983 ASSERT_VK_SUCCESS(err);
3984
3985 // Cause error due to mis-matched sample count between rp & fb
3986 fb_info.renderPass = rp;
Cort Stratton8133ec22017-04-27 16:25:03 +02003987 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00409);
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003988 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3989
3990 m_errorMonitor->VerifyFound();
3991 if (err == VK_SUCCESS) {
3992 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3993 }
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003994
3995 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003996
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06003997 {
3998 // Create an image with 2 mip levels.
3999 VkImageObj image(m_device);
4000 image.Init(128, 128, 2, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
4001 ASSERT_TRUE(image.initialized());
Tobin Ehlis6cfda642016-06-22 16:12:58 -06004002
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06004003 // Create a image view with two mip levels.
4004 VkImageView view;
4005 VkImageViewCreateInfo ivci = {};
4006 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
4007 ivci.image = image.handle();
4008 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
4009 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
4010 ivci.subresourceRange.layerCount = 1;
4011 ivci.subresourceRange.baseMipLevel = 0;
4012 // Set level count to 2 (only 1 is allowed for FB attachment)
4013 ivci.subresourceRange.levelCount = 2;
4014 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4015 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
4016 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6cfda642016-06-22 16:12:58 -06004017
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06004018 // Re-create renderpass to have matching sample count
4019 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
4020 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
4021 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6cfda642016-06-22 16:12:58 -06004022
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06004023 fb_info.renderPass = rp;
4024 fb_info.pAttachments = &view;
Cort Stratton8133ec22017-04-27 16:25:03 +02004025 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00411);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06004026 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4027
4028 m_errorMonitor->VerifyFound();
4029 if (err == VK_SUCCESS) {
4030 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4031 }
4032 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis6cfda642016-06-22 16:12:58 -06004033 }
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06004034
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06004035 // Update view to original color buffer and grow FB dimensions too big
4036 fb_info.pAttachments = ivs;
4037 fb_info.height = 1024;
4038 fb_info.width = 1024;
4039 fb_info.layers = 2;
Cort Stratton8133ec22017-04-27 16:25:03 +02004040 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00410);
Tobin Ehlis27f2ae82016-06-23 07:36:57 -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 }
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06004047
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06004048 {
4049 // Create an image with one mip level.
4050 VkImageObj image(m_device);
4051 image.Init(128, 128, 1, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
4052 ASSERT_TRUE(image.initialized());
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06004053
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06004054 // Create view attachment with non-identity swizzle
4055 VkImageView view;
4056 VkImageViewCreateInfo ivci = {};
4057 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
4058 ivci.image = image.handle();
4059 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
4060 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
4061 ivci.subresourceRange.layerCount = 1;
4062 ivci.subresourceRange.baseMipLevel = 0;
4063 ivci.subresourceRange.levelCount = 1;
4064 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4065 ivci.components.r = VK_COMPONENT_SWIZZLE_G;
4066 ivci.components.g = VK_COMPONENT_SWIZZLE_R;
4067 ivci.components.b = VK_COMPONENT_SWIZZLE_A;
4068 ivci.components.a = VK_COMPONENT_SWIZZLE_B;
4069 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
4070 ASSERT_VK_SUCCESS(err);
4071
4072 fb_info.pAttachments = &view;
4073 fb_info.height = 100;
4074 fb_info.width = 100;
4075 fb_info.layers = 1;
4076
Cort Stratton8133ec22017-04-27 16:25:03 +02004077 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00412);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06004078 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4079
4080 m_errorMonitor->VerifyFound();
4081 if (err == VK_SUCCESS) {
4082 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4083 }
4084 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06004085 }
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06004086
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004087 // reset attachment to color attachment
4088 fb_info.pAttachments = ivs;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004089
4090 // Request fb that exceeds max width
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004091 fb_info.width = m_device->props.limits.maxFramebufferWidth + 1;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004092 fb_info.height = 100;
4093 fb_info.layers = 1;
4094 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00413);
Cort Stratton8133ec22017-04-27 16:25:03 +02004095 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00410);
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004096 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
Cort Stratton8133ec22017-04-27 16:25:03 +02004097 m_errorMonitor->VerifyFound();
4098 if (err == VK_SUCCESS) {
4099 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4100 }
4101 // and width=0
4102 fb_info.width = 0;
4103 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02806);
4104 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004105 m_errorMonitor->VerifyFound();
4106 if (err == VK_SUCCESS) {
4107 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4108 }
4109
4110 // Request fb that exceeds max height
4111 fb_info.width = 100;
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004112 fb_info.height = m_device->props.limits.maxFramebufferHeight + 1;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004113 fb_info.layers = 1;
4114 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00414);
Cort Stratton8133ec22017-04-27 16:25:03 +02004115 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00410);
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004116 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
Cort Stratton8133ec22017-04-27 16:25:03 +02004117 m_errorMonitor->VerifyFound();
4118 if (err == VK_SUCCESS) {
4119 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4120 }
4121 // and height=0
4122 fb_info.height = 0;
4123 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02807);
4124 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004125 m_errorMonitor->VerifyFound();
4126 if (err == VK_SUCCESS) {
4127 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4128 }
4129
4130 // Request fb that exceeds max layers
4131 fb_info.width = 100;
4132 fb_info.height = 100;
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004133 fb_info.layers = m_device->props.limits.maxFramebufferLayers + 1;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004134 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00415);
Cort Stratton8133ec22017-04-27 16:25:03 +02004135 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00410);
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004136 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
Cort Stratton8133ec22017-04-27 16:25:03 +02004137 m_errorMonitor->VerifyFound();
4138 if (err == VK_SUCCESS) {
4139 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4140 }
4141 // and layers=0
4142 fb_info.layers = 0;
4143 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02808);
4144 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004145 m_errorMonitor->VerifyFound();
4146 if (err == VK_SUCCESS) {
4147 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4148 }
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06004149
Tobin Ehlis6cfda642016-06-22 16:12:58 -06004150 vkDestroyRenderPass(m_device->device(), rp, NULL);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004151}
4152
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004153TEST_F(VkLayerTest, DynamicDepthBiasNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004154 TEST_DESCRIPTION(
4155 "Run a simple draw calls to validate failure when Depth Bias dynamic "
4156 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004157
Tony Barbour1fa09702017-03-16 12:09:08 -06004158 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004159 // Dynamic depth bias
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004160 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic depth bias state not set for this command buffer");
4161 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBias);
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004162 m_errorMonitor->VerifyFound();
4163}
4164
4165TEST_F(VkLayerTest, DynamicLineWidthNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004166 TEST_DESCRIPTION(
4167 "Run a simple draw calls to validate failure when Line Width dynamic "
4168 "state is required but not correctly bound.");
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004169
Tony Barbour1fa09702017-03-16 12:09:08 -06004170 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004171 // Dynamic line width
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004172 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic line width state not set for this command buffer");
4173 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailLineWidth);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004174 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004175}
4176
4177TEST_F(VkLayerTest, DynamicViewportNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004178 TEST_DESCRIPTION(
4179 "Run a simple draw calls to validate failure when Viewport dynamic "
4180 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004181
Tony Barbour1fa09702017-03-16 12:09:08 -06004182 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004183 // Dynamic viewport state
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07004184 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4185 "Dynamic viewport(s) 0 are used by pipeline state object, but were not provided");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004186 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailViewport);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004187 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004188}
4189
4190TEST_F(VkLayerTest, DynamicScissorNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004191 TEST_DESCRIPTION(
4192 "Run a simple draw calls to validate failure when Scissor dynamic "
4193 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004194
Tony Barbour1fa09702017-03-16 12:09:08 -06004195 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004196 // Dynamic scissor state
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07004197 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4198 "Dynamic scissor(s) 0 are used by pipeline state object, but were not provided");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004199 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailScissor);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004200 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004201}
4202
Cortd713fe82016-07-27 09:51:27 -07004203TEST_F(VkLayerTest, DynamicBlendConstantsNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004204 TEST_DESCRIPTION(
4205 "Run a simple draw calls to validate failure when Blend Constants "
4206 "dynamic state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004207
Tony Barbour1fa09702017-03-16 12:09:08 -06004208 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis21c88352016-05-26 06:15:45 -06004209 // Dynamic blend constant state
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004210 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4211 "Dynamic blend constants state not set for this command buffer");
4212 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailBlend);
Tobin Ehlis21c88352016-05-26 06:15:45 -06004213 m_errorMonitor->VerifyFound();
4214}
4215
4216TEST_F(VkLayerTest, DynamicDepthBoundsNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004217 TEST_DESCRIPTION(
4218 "Run a simple draw calls to validate failure when Depth Bounds dynamic "
4219 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004220
Tony Barbour1fa09702017-03-16 12:09:08 -06004221 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis21c88352016-05-26 06:15:45 -06004222 if (!m_device->phy().features().depthBounds) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07004223 printf(" Device does not support depthBounds test; skipped.\n");
Tobin Ehlis21c88352016-05-26 06:15:45 -06004224 return;
4225 }
4226 // Dynamic depth bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004227 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4228 "Dynamic depth bounds state not set for this command buffer");
4229 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBounds);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004230 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004231}
4232
4233TEST_F(VkLayerTest, DynamicStencilReadNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004234 TEST_DESCRIPTION(
4235 "Run a simple draw calls to validate failure when Stencil Read dynamic "
4236 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004237
Tony Barbour1fa09702017-03-16 12:09:08 -06004238 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004239 // Dynamic stencil read mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004240 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4241 "Dynamic stencil read mask state not set for this command buffer");
4242 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReadMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004243 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004244}
4245
4246TEST_F(VkLayerTest, DynamicStencilWriteNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004247 TEST_DESCRIPTION(
4248 "Run a simple draw calls to validate failure when Stencil Write dynamic"
4249 " state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004250
Tony Barbour1fa09702017-03-16 12:09:08 -06004251 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004252 // Dynamic stencil write mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004253 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4254 "Dynamic stencil write mask state not set for this command buffer");
4255 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilWriteMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004256 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004257}
4258
4259TEST_F(VkLayerTest, DynamicStencilRefNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004260 TEST_DESCRIPTION(
4261 "Run a simple draw calls to validate failure when Stencil Ref dynamic "
4262 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004263
Tony Barbour1fa09702017-03-16 12:09:08 -06004264 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004265 // Dynamic stencil reference
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004266 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4267 "Dynamic stencil reference state not set for this command buffer");
4268 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReference);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004269 m_errorMonitor->VerifyFound();
Tobin Ehlis963a4042015-09-29 08:18:34 -06004270}
4271
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06004272TEST_F(VkLayerTest, IndexBufferNotBound) {
4273 TEST_DESCRIPTION("Run an indexed draw call without an index buffer bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004274
Tony Barbour1fa09702017-03-16 12:09:08 -06004275 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004276 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4277 "Index buffer object not bound to this command buffer when Indexed ");
4278 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailIndexBuffer);
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06004279 m_errorMonitor->VerifyFound();
4280}
4281
Karl Schultz6addd812016-02-02 17:17:23 -07004282TEST_F(VkLayerTest, CommandBufferTwoSubmits) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004283 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4284 "was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has "
4285 "been submitted");
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004286
Tony Barbour1fa09702017-03-16 12:09:08 -06004287 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004288 ASSERT_NO_FATAL_FAILURE(InitViewport());
4289 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4290
Karl Schultz6addd812016-02-02 17:17:23 -07004291 // We luck out b/c by default the framework creates CB w/ the
4292 // VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set
Tony Barbour552f6c02016-12-21 14:34:07 -07004293 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004294 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbour552f6c02016-12-21 14:34:07 -07004295 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004296
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004297 // Bypass framework since it does the waits automatically
4298 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06004299 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08004300 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4301 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004302 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06004303 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07004304 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004305 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004306 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08004307 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06004308 submit_info.pSignalSemaphores = NULL;
4309
Chris Forbes40028e22016-06-13 09:59:34 +12004310 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Karl Schultz6addd812016-02-02 17:17:23 -07004311 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski89cad1a2016-11-11 15:51:31 -07004312 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004313
Karl Schultz6addd812016-02-02 17:17:23 -07004314 // Cause validation error by re-submitting cmd buffer that should only be
4315 // submitted once
Chris Forbes40028e22016-06-13 09:59:34 +12004316 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski89cad1a2016-11-11 15:51:31 -07004317 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004318
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004319 m_errorMonitor->VerifyFound();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004320}
4321
Karl Schultz6addd812016-02-02 17:17:23 -07004322TEST_F(VkLayerTest, AllocDescriptorFromEmptyPool) {
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004323 TEST_DESCRIPTION("Attempt to allocate more sets and descriptors than descriptor pool has available.");
Karl Schultz6addd812016-02-02 17:17:23 -07004324 VkResult err;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004325
Tony Barbour1fa09702017-03-16 12:09:08 -06004326 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004327 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004328
Karl Schultz6addd812016-02-02 17:17:23 -07004329 // Create Pool w/ 1 Sampler descriptor, but try to alloc Uniform Buffer
4330 // descriptor from it
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004331 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004332 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004333 ds_type_count.descriptorCount = 2;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004334
4335 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004336 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4337 ds_pool_ci.pNext = NULL;
4338 ds_pool_ci.flags = 0;
4339 ds_pool_ci.maxSets = 1;
4340 ds_pool_ci.poolSizeCount = 1;
4341 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004342
4343 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004344 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004345 ASSERT_VK_SUCCESS(err);
4346
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004347 VkDescriptorSetLayoutBinding dsl_binding_samp = {};
4348 dsl_binding_samp.binding = 0;
4349 dsl_binding_samp.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
4350 dsl_binding_samp.descriptorCount = 1;
4351 dsl_binding_samp.stageFlags = VK_SHADER_STAGE_ALL;
4352 dsl_binding_samp.pImmutableSamplers = NULL;
4353
4354 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4355 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4356 ds_layout_ci.pNext = NULL;
4357 ds_layout_ci.bindingCount = 1;
4358 ds_layout_ci.pBindings = &dsl_binding_samp;
4359
4360 VkDescriptorSetLayout ds_layout_samp;
4361 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_samp);
4362 ASSERT_VK_SUCCESS(err);
4363
4364 // Try to allocate 2 sets when pool only has 1 set
4365 VkDescriptorSet descriptor_sets[2];
4366 VkDescriptorSetLayout set_layouts[2] = {ds_layout_samp, ds_layout_samp};
4367 VkDescriptorSetAllocateInfo alloc_info = {};
4368 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4369 alloc_info.descriptorSetCount = 2;
4370 alloc_info.descriptorPool = ds_pool;
4371 alloc_info.pSetLayouts = set_layouts;
4372 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00911);
4373 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
4374 m_errorMonitor->VerifyFound();
4375
4376 alloc_info.descriptorSetCount = 1;
4377 // Create layout w/ descriptor type not available in pool
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004378 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004379 dsl_binding.binding = 0;
4380 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4381 dsl_binding.descriptorCount = 1;
4382 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4383 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004384
Karl Schultz6addd812016-02-02 17:17:23 -07004385 ds_layout_ci.bindingCount = 1;
4386 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004387
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004388 VkDescriptorSetLayout ds_layout_ub;
4389 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_ub);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004390 ASSERT_VK_SUCCESS(err);
4391
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004392 VkDescriptorSet descriptor_set;
Jon Ashburnf19916e2016-01-11 13:12:43 -07004393 alloc_info.descriptorSetCount = 1;
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004394 alloc_info.pSetLayouts = &ds_layout_ub;
4395 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00912);
4396 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004397
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004398 m_errorMonitor->VerifyFound();
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004399
Karl Schultz2825ab92016-12-02 08:23:14 -07004400 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_samp, NULL);
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004401 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_ub, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +08004402 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004403}
4404
Karl Schultz6addd812016-02-02 17:17:23 -07004405TEST_F(VkLayerTest, FreeDescriptorFromOneShotPool) {
4406 VkResult err;
Tobin Ehlise735c692015-10-08 13:13:50 -06004407
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07004408 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00922);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004409
Tony Barbour1fa09702017-03-16 12:09:08 -06004410 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlise735c692015-10-08 13:13:50 -06004411 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise735c692015-10-08 13:13:50 -06004412
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004413 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004414 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4415 ds_type_count.descriptorCount = 1;
Tobin Ehlise735c692015-10-08 13:13:50 -06004416
4417 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004418 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4419 ds_pool_ci.pNext = NULL;
4420 ds_pool_ci.maxSets = 1;
4421 ds_pool_ci.poolSizeCount = 1;
4422 ds_pool_ci.flags = 0;
4423 // Not specifying VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT means
4424 // app can only call vkResetDescriptorPool on this pool.;
4425 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise735c692015-10-08 13:13:50 -06004426
4427 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004428 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise735c692015-10-08 13:13:50 -06004429 ASSERT_VK_SUCCESS(err);
4430
4431 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004432 dsl_binding.binding = 0;
4433 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4434 dsl_binding.descriptorCount = 1;
4435 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4436 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise735c692015-10-08 13:13:50 -06004437
4438 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004439 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4440 ds_layout_ci.pNext = NULL;
4441 ds_layout_ci.bindingCount = 1;
4442 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise735c692015-10-08 13:13:50 -06004443
4444 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004445 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise735c692015-10-08 13:13:50 -06004446 ASSERT_VK_SUCCESS(err);
4447
4448 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004449 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08004450 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07004451 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06004452 alloc_info.descriptorPool = ds_pool;
4453 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004454 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise735c692015-10-08 13:13:50 -06004455 ASSERT_VK_SUCCESS(err);
4456
4457 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004458 m_errorMonitor->VerifyFound();
Tobin Ehlise735c692015-10-08 13:13:50 -06004459
Chia-I Wuf7458c52015-10-26 21:10:41 +08004460 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4461 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise735c692015-10-08 13:13:50 -06004462}
4463
Karl Schultz6addd812016-02-02 17:17:23 -07004464TEST_F(VkLayerTest, InvalidDescriptorPool) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004465 // Attempt to clear Descriptor Pool with bad object.
4466 // ObjectTracker should catch this.
Cody Northropc31a84f2016-08-22 10:41:47 -06004467
Tony Barbour1fa09702017-03-16 12:09:08 -06004468 ASSERT_NO_FATAL_FAILURE(Init());
Karl Schultzf78bcdd2016-11-30 12:36:01 -07004469 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00930);
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004470 uint64_t fake_pool_handle = 0xbaad6001;
4471 VkDescriptorPool bad_pool = reinterpret_cast<VkDescriptorPool &>(fake_pool_handle);
4472 vkResetDescriptorPool(device(), bad_pool, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -06004473 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004474}
4475
Karl Schultzf78bcdd2016-11-30 12:36:01 -07004476TEST_F(VkLayerTest, InvalidDescriptorSet) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004477 // Attempt to bind an invalid Descriptor Set to a valid Command Buffer
4478 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004479 // Create a valid cmd buffer
Karl Schultzbdb75952016-04-19 11:36:49 -06004480 // call vkCmdBindDescriptorSets w/ false Descriptor Set
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004481
4482 uint64_t fake_set_handle = 0xbaad6001;
4483 VkDescriptorSet bad_set = reinterpret_cast<VkDescriptorSet &>(fake_set_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06004484 VkResult err;
Karl Schultzf78bcdd2016-11-30 12:36:01 -07004485 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00982);
Karl Schultzbdb75952016-04-19 11:36:49 -06004486
Tony Barbour1fa09702017-03-16 12:09:08 -06004487 ASSERT_NO_FATAL_FAILURE(Init());
Karl Schultzbdb75952016-04-19 11:36:49 -06004488
4489 VkDescriptorSetLayoutBinding layout_bindings[1] = {};
4490 layout_bindings[0].binding = 0;
4491 layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4492 layout_bindings[0].descriptorCount = 1;
4493 layout_bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
4494 layout_bindings[0].pImmutableSamplers = NULL;
4495
4496 VkDescriptorSetLayout descriptor_set_layout;
4497 VkDescriptorSetLayoutCreateInfo dslci = {};
4498 dslci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4499 dslci.pNext = NULL;
4500 dslci.bindingCount = 1;
4501 dslci.pBindings = layout_bindings;
4502 err = vkCreateDescriptorSetLayout(device(), &dslci, NULL, &descriptor_set_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06004503 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06004504
4505 VkPipelineLayout pipeline_layout;
4506 VkPipelineLayoutCreateInfo plci = {};
4507 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4508 plci.pNext = NULL;
4509 plci.setLayoutCount = 1;
4510 plci.pSetLayouts = &descriptor_set_layout;
4511 err = vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06004512 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06004513
Tony Barbour552f6c02016-12-21 14:34:07 -07004514 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004515 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &bad_set, 0,
4516 NULL);
Karl Schultzbdb75952016-04-19 11:36:49 -06004517 m_errorMonitor->VerifyFound();
Tony Barbour552f6c02016-12-21 14:34:07 -07004518 m_commandBuffer->EndCommandBuffer();
Karl Schultzbdb75952016-04-19 11:36:49 -06004519 vkDestroyPipelineLayout(device(), pipeline_layout, NULL);
4520 vkDestroyDescriptorSetLayout(device(), descriptor_set_layout, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004521}
4522
Karl Schultz6addd812016-02-02 17:17:23 -07004523TEST_F(VkLayerTest, InvalidDescriptorSetLayout) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004524 // Attempt to create a Pipeline Layout with an invalid Descriptor Set Layout.
4525 // ObjectTracker should catch this.
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004526 uint64_t fake_layout_handle = 0xbaad6001;
4527 VkDescriptorSetLayout bad_layout = reinterpret_cast<VkDescriptorSetLayout &>(fake_layout_handle);
Karl Schultzf78bcdd2016-11-30 12:36:01 -07004528 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00875);
Tony Barbour1fa09702017-03-16 12:09:08 -06004529 ASSERT_NO_FATAL_FAILURE(Init());
Karl Schultzbdb75952016-04-19 11:36:49 -06004530 VkPipelineLayout pipeline_layout;
4531 VkPipelineLayoutCreateInfo plci = {};
4532 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4533 plci.pNext = NULL;
4534 plci.setLayoutCount = 1;
4535 plci.pSetLayouts = &bad_layout;
4536 vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
4537
4538 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004539}
4540
Mark Muellerd4914412016-06-13 17:52:06 -06004541TEST_F(VkLayerTest, WriteDescriptorSetIntegrityCheck) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004542 TEST_DESCRIPTION(
4543 "This test verifies some requirements of chapter 13.2.3 of the Vulkan Spec "
4544 "1) A uniform buffer update must have a valid buffer index."
4545 "2) When using an array of descriptors in a single WriteDescriptor,"
4546 " the descriptor types and stageflags must all be the same."
4547 "3) Immutable Sampler state must match across descriptors");
Mark Muellerd4914412016-06-13 17:52:06 -06004548
Mike Weiblena6666382017-01-05 15:16:11 -07004549 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00941);
Mark Muellerd4914412016-06-13 17:52:06 -06004550
Tony Barbour1fa09702017-03-16 12:09:08 -06004551 ASSERT_NO_FATAL_FAILURE(Init());
Mark Muellerd4914412016-06-13 17:52:06 -06004552 VkDescriptorPoolSize ds_type_count[4] = {};
4553 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4554 ds_type_count[0].descriptorCount = 1;
Tony Barboure132c5f2016-12-12 11:50:20 -07004555 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Muellerd4914412016-06-13 17:52:06 -06004556 ds_type_count[1].descriptorCount = 1;
Tony Barboure132c5f2016-12-12 11:50:20 -07004557 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Muellerd4914412016-06-13 17:52:06 -06004558 ds_type_count[2].descriptorCount = 1;
4559 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
4560 ds_type_count[3].descriptorCount = 1;
4561
4562 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4563 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4564 ds_pool_ci.maxSets = 1;
4565 ds_pool_ci.poolSizeCount = sizeof(ds_type_count) / sizeof(VkDescriptorPoolSize);
4566 ds_pool_ci.pPoolSizes = ds_type_count;
4567
4568 VkDescriptorPool ds_pool;
4569 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
4570 ASSERT_VK_SUCCESS(err);
4571
Mark Muellerb9896722016-06-16 09:54:29 -06004572 VkDescriptorSetLayoutBinding layout_binding[3] = {};
Mark Muellerd4914412016-06-13 17:52:06 -06004573 layout_binding[0].binding = 0;
4574 layout_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4575 layout_binding[0].descriptorCount = 1;
4576 layout_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
4577 layout_binding[0].pImmutableSamplers = NULL;
4578
4579 layout_binding[1].binding = 1;
4580 layout_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
4581 layout_binding[1].descriptorCount = 1;
4582 layout_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4583 layout_binding[1].pImmutableSamplers = NULL;
4584
4585 VkSamplerCreateInfo sampler_ci = {};
4586 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
4587 sampler_ci.pNext = NULL;
4588 sampler_ci.magFilter = VK_FILTER_NEAREST;
4589 sampler_ci.minFilter = VK_FILTER_NEAREST;
4590 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
4591 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4592 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4593 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4594 sampler_ci.mipLodBias = 1.0;
4595 sampler_ci.anisotropyEnable = VK_FALSE;
4596 sampler_ci.maxAnisotropy = 1;
4597 sampler_ci.compareEnable = VK_FALSE;
4598 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
4599 sampler_ci.minLod = 1.0;
4600 sampler_ci.maxLod = 1.0;
4601 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
4602 sampler_ci.unnormalizedCoordinates = VK_FALSE;
4603 VkSampler sampler;
4604
4605 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
4606 ASSERT_VK_SUCCESS(err);
4607
4608 layout_binding[2].binding = 2;
4609 layout_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
4610 layout_binding[2].descriptorCount = 1;
4611 layout_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4612 layout_binding[2].pImmutableSamplers = static_cast<VkSampler *>(&sampler);
4613
Mark Muellerd4914412016-06-13 17:52:06 -06004614 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4615 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4616 ds_layout_ci.bindingCount = sizeof(layout_binding) / sizeof(VkDescriptorSetLayoutBinding);
4617 ds_layout_ci.pBindings = layout_binding;
4618 VkDescriptorSetLayout ds_layout;
4619 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
4620 ASSERT_VK_SUCCESS(err);
4621
4622 VkDescriptorSetAllocateInfo alloc_info = {};
4623 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4624 alloc_info.descriptorSetCount = 1;
4625 alloc_info.descriptorPool = ds_pool;
4626 alloc_info.pSetLayouts = &ds_layout;
4627 VkDescriptorSet descriptorSet;
4628 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
4629 ASSERT_VK_SUCCESS(err);
4630
4631 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4632 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4633 pipeline_layout_ci.pNext = NULL;
4634 pipeline_layout_ci.setLayoutCount = 1;
4635 pipeline_layout_ci.pSetLayouts = &ds_layout;
4636
4637 VkPipelineLayout pipeline_layout;
4638 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4639 ASSERT_VK_SUCCESS(err);
4640
Mark Mueller5c838ce2016-06-16 09:54:29 -06004641 VkWriteDescriptorSet descriptor_write = {};
Mark Muellerd4914412016-06-13 17:52:06 -06004642 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4643 descriptor_write.dstSet = descriptorSet;
4644 descriptor_write.dstBinding = 0;
4645 descriptor_write.descriptorCount = 1;
4646 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4647
Mark Mueller5c838ce2016-06-16 09:54:29 -06004648 // 1) The uniform buffer is intentionally invalid here
Mark Muellerd4914412016-06-13 17:52:06 -06004649 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4650 m_errorMonitor->VerifyFound();
4651
4652 // Create a buffer to update the descriptor with
4653 uint32_t qfi = 0;
4654 VkBufferCreateInfo buffCI = {};
4655 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4656 buffCI.size = 1024;
4657 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
4658 buffCI.queueFamilyIndexCount = 1;
4659 buffCI.pQueueFamilyIndices = &qfi;
4660
4661 VkBuffer dyub;
4662 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
4663 ASSERT_VK_SUCCESS(err);
Mark Muellerd4914412016-06-13 17:52:06 -06004664
Tony Barboure132c5f2016-12-12 11:50:20 -07004665 VkDeviceMemory mem;
4666 VkMemoryRequirements mem_reqs;
4667 vkGetBufferMemoryRequirements(m_device->device(), dyub, &mem_reqs);
4668
4669 VkMemoryAllocateInfo mem_alloc_info = {};
4670 mem_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4671 mem_alloc_info.allocationSize = mem_reqs.size;
4672 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
4673 err = vkAllocateMemory(m_device->device(), &mem_alloc_info, NULL, &mem);
4674 ASSERT_VK_SUCCESS(err);
4675
4676 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
4677 ASSERT_VK_SUCCESS(err);
4678
4679 VkDescriptorBufferInfo buffInfo[2] = {};
4680 buffInfo[0].buffer = dyub;
4681 buffInfo[0].offset = 0;
4682 buffInfo[0].range = 1024;
4683 buffInfo[1].buffer = dyub;
4684 buffInfo[1].offset = 0;
4685 buffInfo[1].range = 1024;
4686 descriptor_write.pBufferInfo = buffInfo;
Mark Muellerd4914412016-06-13 17:52:06 -06004687 descriptor_write.descriptorCount = 2;
4688
Mark Mueller5c838ce2016-06-16 09:54:29 -06004689 // 2) The stateFlags don't match between the first and second descriptor
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07004690 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00938);
Mark Muellerd4914412016-06-13 17:52:06 -06004691 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4692 m_errorMonitor->VerifyFound();
4693
Mark Mueller5c838ce2016-06-16 09:54:29 -06004694 // 3) The second descriptor has a null_ptr pImmutableSamplers and
4695 // the third descriptor contains an immutable sampler
Mark Muellerd4914412016-06-13 17:52:06 -06004696 descriptor_write.dstBinding = 1;
4697 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Mueller5c838ce2016-06-16 09:54:29 -06004698
Mark Mueller5c838ce2016-06-16 09:54:29 -06004699 // Make pImageInfo index non-null to avoid complaints of it missing
4700 VkDescriptorImageInfo imageInfo = {};
4701 imageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
4702 descriptor_write.pImageInfo = &imageInfo;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07004703 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00938);
Mark Muellerd4914412016-06-13 17:52:06 -06004704 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4705 m_errorMonitor->VerifyFound();
4706
Mark Muellerd4914412016-06-13 17:52:06 -06004707 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tony Barboure132c5f2016-12-12 11:50:20 -07004708 vkFreeMemory(m_device->device(), mem, NULL);
Mark Muellerd4914412016-06-13 17:52:06 -06004709 vkDestroySampler(m_device->device(), sampler, NULL);
4710 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4711 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4712 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4713}
4714
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004715TEST_F(VkLayerTest, InvalidCmdBufferBufferDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004716 TEST_DESCRIPTION(
4717 "Attempt to draw with a command buffer that is invalid "
4718 "due to a buffer dependency being destroyed.");
Tony Barbour1fa09702017-03-16 12:09:08 -06004719 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004720
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004721 VkBuffer buffer;
4722 VkDeviceMemory mem;
4723 VkMemoryRequirements mem_reqs;
4724
4725 VkBufferCreateInfo buf_info = {};
4726 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes3d5882f2016-09-16 17:37:17 +12004727 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004728 buf_info.size = 256;
4729 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
4730 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
4731 ASSERT_VK_SUCCESS(err);
4732
4733 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
4734
4735 VkMemoryAllocateInfo alloc_info = {};
4736 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4737 alloc_info.allocationSize = 256;
4738 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004739 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 -06004740 if (!pass) {
4741 vkDestroyBuffer(m_device->device(), buffer, NULL);
4742 return;
4743 }
4744 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
4745 ASSERT_VK_SUCCESS(err);
4746
4747 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
4748 ASSERT_VK_SUCCESS(err);
4749
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004750 m_commandBuffer->BeginCommandBuffer();
Chris Forbes3d5882f2016-09-16 17:37:17 +12004751 vkCmdFillBuffer(m_commandBuffer->GetBufferHandle(), buffer, 0, VK_WHOLE_SIZE, 0);
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004752 m_commandBuffer->EndCommandBuffer();
4753
Mark Lobodzinski33826372017-04-13 11:10:11 -06004754 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound Buffer ");
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004755 // Destroy buffer dependency prior to submit to cause ERROR
4756 vkDestroyBuffer(m_device->device(), buffer, NULL);
4757
4758 VkSubmitInfo submit_info = {};
4759 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4760 submit_info.commandBufferCount = 1;
4761 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4762 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4763
4764 m_errorMonitor->VerifyFound();
Rene Lindsayab6c5cd2016-12-20 14:05:37 -07004765 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004766 vkFreeMemory(m_device->handle(), mem, NULL);
4767}
4768
Tobin Ehlisea413442016-09-28 10:23:59 -06004769TEST_F(VkLayerTest, InvalidCmdBufferBufferViewDestroyed) {
4770 TEST_DESCRIPTION("Delete bufferView bound to cmd buffer, then attempt to submit cmd buffer.");
4771
Tony Barbour1fa09702017-03-16 12:09:08 -06004772 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisea413442016-09-28 10:23:59 -06004773 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4774
4775 VkDescriptorPoolSize ds_type_count;
4776 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4777 ds_type_count.descriptorCount = 1;
4778
4779 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4780 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4781 ds_pool_ci.maxSets = 1;
4782 ds_pool_ci.poolSizeCount = 1;
4783 ds_pool_ci.pPoolSizes = &ds_type_count;
4784
4785 VkDescriptorPool ds_pool;
4786 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
4787 ASSERT_VK_SUCCESS(err);
4788
4789 VkDescriptorSetLayoutBinding layout_binding;
4790 layout_binding.binding = 0;
4791 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4792 layout_binding.descriptorCount = 1;
4793 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4794 layout_binding.pImmutableSamplers = NULL;
4795
4796 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4797 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4798 ds_layout_ci.bindingCount = 1;
4799 ds_layout_ci.pBindings = &layout_binding;
4800 VkDescriptorSetLayout ds_layout;
4801 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
4802 ASSERT_VK_SUCCESS(err);
4803
4804 VkDescriptorSetAllocateInfo alloc_info = {};
4805 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4806 alloc_info.descriptorSetCount = 1;
4807 alloc_info.descriptorPool = ds_pool;
4808 alloc_info.pSetLayouts = &ds_layout;
4809 VkDescriptorSet descriptor_set;
4810 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
4811 ASSERT_VK_SUCCESS(err);
4812
4813 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4814 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4815 pipeline_layout_ci.pNext = NULL;
4816 pipeline_layout_ci.setLayoutCount = 1;
4817 pipeline_layout_ci.pSetLayouts = &ds_layout;
4818
4819 VkPipelineLayout pipeline_layout;
4820 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4821 ASSERT_VK_SUCCESS(err);
4822
4823 VkBuffer buffer;
4824 uint32_t queue_family_index = 0;
4825 VkBufferCreateInfo buffer_create_info = {};
4826 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4827 buffer_create_info.size = 1024;
4828 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
4829 buffer_create_info.queueFamilyIndexCount = 1;
4830 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
4831
4832 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
4833 ASSERT_VK_SUCCESS(err);
4834
4835 VkMemoryRequirements memory_reqs;
4836 VkDeviceMemory buffer_memory;
4837
4838 VkMemoryAllocateInfo memory_info = {};
4839 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4840 memory_info.allocationSize = 0;
4841 memory_info.memoryTypeIndex = 0;
4842
4843 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
4844 memory_info.allocationSize = memory_reqs.size;
4845 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
4846 ASSERT_TRUE(pass);
4847
4848 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
4849 ASSERT_VK_SUCCESS(err);
4850 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
4851 ASSERT_VK_SUCCESS(err);
4852
4853 VkBufferView view;
4854 VkBufferViewCreateInfo bvci = {};
4855 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
4856 bvci.buffer = buffer;
4857 bvci.format = VK_FORMAT_R8_UNORM;
4858 bvci.range = VK_WHOLE_SIZE;
4859
4860 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
4861 ASSERT_VK_SUCCESS(err);
4862
4863 VkWriteDescriptorSet descriptor_write = {};
4864 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4865 descriptor_write.dstSet = descriptor_set;
4866 descriptor_write.dstBinding = 0;
4867 descriptor_write.descriptorCount = 1;
4868 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4869 descriptor_write.pTexelBufferView = &view;
4870
4871 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4872
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004873 char const *vsSource =
4874 "#version 450\n"
4875 "\n"
4876 "out gl_PerVertex { \n"
4877 " vec4 gl_Position;\n"
4878 "};\n"
4879 "void main(){\n"
4880 " gl_Position = vec4(1);\n"
4881 "}\n";
4882 char const *fsSource =
4883 "#version 450\n"
4884 "\n"
4885 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
4886 "layout(location=0) out vec4 x;\n"
4887 "void main(){\n"
4888 " x = imageLoad(s, 0);\n"
4889 "}\n";
Tobin Ehlisea413442016-09-28 10:23:59 -06004890 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4891 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
4892 VkPipelineObj pipe(m_device);
4893 pipe.AddShader(&vs);
4894 pipe.AddShader(&fs);
4895 pipe.AddColorAttachment();
4896 pipe.CreateVKPipeline(pipeline_layout, renderPass());
4897
Mark Lobodzinski33826372017-04-13 11:10:11 -06004898 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound BufferView ");
Tobin Ehlisea413442016-09-28 10:23:59 -06004899
Tony Barbour552f6c02016-12-21 14:34:07 -07004900 m_commandBuffer->BeginCommandBuffer();
4901 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
4902
Tobin Ehlisea413442016-09-28 10:23:59 -06004903 VkViewport viewport = {0, 0, 16, 16, 0, 1};
4904 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
4905 VkRect2D scissor = {{0, 0}, {16, 16}};
4906 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
4907 // Bind pipeline to cmd buffer
4908 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
4909 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
4910 &descriptor_set, 0, nullptr);
4911 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07004912 m_commandBuffer->EndRenderPass();
4913 m_commandBuffer->EndCommandBuffer();
Tobin Ehlisea413442016-09-28 10:23:59 -06004914
4915 // Delete BufferView in order to invalidate cmd buffer
4916 vkDestroyBufferView(m_device->device(), view, NULL);
4917 // Now attempt submit of cmd buffer
4918 VkSubmitInfo submit_info = {};
4919 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4920 submit_info.commandBufferCount = 1;
4921 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4922 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4923 m_errorMonitor->VerifyFound();
4924
4925 // Clean-up
4926 vkDestroyBuffer(m_device->device(), buffer, NULL);
4927 vkFreeMemory(m_device->device(), buffer_memory, NULL);
4928 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4929 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4930 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4931}
4932
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004933TEST_F(VkLayerTest, InvalidCmdBufferImageDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004934 TEST_DESCRIPTION(
4935 "Attempt to draw with a command buffer that is invalid "
4936 "due to an image dependency being destroyed.");
Tony Barbour1fa09702017-03-16 12:09:08 -06004937 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004938
4939 VkImage image;
4940 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4941 VkImageCreateInfo image_create_info = {};
4942 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4943 image_create_info.pNext = NULL;
4944 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4945 image_create_info.format = tex_format;
4946 image_create_info.extent.width = 32;
4947 image_create_info.extent.height = 32;
4948 image_create_info.extent.depth = 1;
4949 image_create_info.mipLevels = 1;
4950 image_create_info.arrayLayers = 1;
4951 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
4952 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004953 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004954 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004955 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004956 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004957 // Have to bind memory to image before recording cmd in cmd buffer using it
4958 VkMemoryRequirements mem_reqs;
4959 VkDeviceMemory image_mem;
4960 bool pass;
4961 VkMemoryAllocateInfo mem_alloc = {};
4962 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4963 mem_alloc.pNext = NULL;
4964 mem_alloc.memoryTypeIndex = 0;
4965 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
4966 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004967 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004968 ASSERT_TRUE(pass);
4969 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
4970 ASSERT_VK_SUCCESS(err);
4971 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
4972 ASSERT_VK_SUCCESS(err);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004973
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004974 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis764d7072016-07-01 12:54:29 -06004975 VkClearColorValue ccv;
4976 ccv.float32[0] = 1.0f;
4977 ccv.float32[1] = 1.0f;
4978 ccv.float32[2] = 1.0f;
4979 ccv.float32[3] = 1.0f;
4980 VkImageSubresourceRange isr = {};
4981 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004982 isr.baseArrayLayer = 0;
4983 isr.baseMipLevel = 0;
Tobin Ehlis764d7072016-07-01 12:54:29 -06004984 isr.layerCount = 1;
4985 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004986 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004987 m_commandBuffer->EndCommandBuffer();
4988
Mark Lobodzinski33826372017-04-13 11:10:11 -06004989 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound Image ");
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004990 // Destroy image dependency prior to submit to cause ERROR
4991 vkDestroyImage(m_device->device(), image, NULL);
4992
4993 VkSubmitInfo submit_info = {};
4994 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4995 submit_info.commandBufferCount = 1;
4996 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4997 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4998
4999 m_errorMonitor->VerifyFound();
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06005000 vkFreeMemory(m_device->device(), image_mem, nullptr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06005001}
5002
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005003TEST_F(VkLayerTest, InvalidCmdBufferFramebufferImageDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005004 TEST_DESCRIPTION(
5005 "Attempt to draw with a command buffer that is invalid "
5006 "due to a framebuffer image dependency being destroyed.");
Tony Barbour1fa09702017-03-16 12:09:08 -06005007 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005008 VkFormatProperties format_properties;
5009 VkResult err = VK_SUCCESS;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005010 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
5011 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005012 return;
5013 }
5014
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005015 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5016
5017 VkImageCreateInfo image_ci = {};
5018 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5019 image_ci.pNext = NULL;
5020 image_ci.imageType = VK_IMAGE_TYPE_2D;
5021 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
5022 image_ci.extent.width = 32;
5023 image_ci.extent.height = 32;
5024 image_ci.extent.depth = 1;
5025 image_ci.mipLevels = 1;
5026 image_ci.arrayLayers = 1;
5027 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
5028 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005029 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT;
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005030 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
5031 image_ci.flags = 0;
5032 VkImage image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005033 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005034
5035 VkMemoryRequirements memory_reqs;
5036 VkDeviceMemory image_memory;
5037 bool pass;
5038 VkMemoryAllocateInfo memory_info = {};
5039 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5040 memory_info.pNext = NULL;
5041 memory_info.allocationSize = 0;
5042 memory_info.memoryTypeIndex = 0;
5043 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5044 memory_info.allocationSize = memory_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005045 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005046 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005047 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005048 ASSERT_VK_SUCCESS(err);
5049 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5050 ASSERT_VK_SUCCESS(err);
5051
5052 VkImageViewCreateInfo ivci = {
5053 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
5054 nullptr,
5055 0,
5056 image,
5057 VK_IMAGE_VIEW_TYPE_2D,
5058 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005059 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005060 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
5061 };
5062 VkImageView view;
5063 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
5064 ASSERT_VK_SUCCESS(err);
5065
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005066 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 32, 32, 1};
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005067 VkFramebuffer fb;
5068 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
5069 ASSERT_VK_SUCCESS(err);
5070
5071 // Just use default renderpass with our framebuffer
5072 m_renderPassBeginInfo.framebuffer = fb;
Jeremy Hayesba817e12017-03-03 15:51:11 -07005073 m_renderPassBeginInfo.renderArea.extent.width = 32;
5074 m_renderPassBeginInfo.renderArea.extent.height = 32;
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005075 // Create Null cmd buffer for submit
Tony Barbour552f6c02016-12-21 14:34:07 -07005076 m_commandBuffer->BeginCommandBuffer();
5077 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
5078 m_commandBuffer->EndRenderPass();
5079 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005080 // Destroy image attached to framebuffer to invalidate cmd buffer
5081 vkDestroyImage(m_device->device(), image, NULL);
5082 // Now attempt to submit cmd buffer and verify error
Mark Lobodzinski33826372017-04-13 11:10:11 -06005083 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound Image ");
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005084 QueueCommandBuffer(false);
5085 m_errorMonitor->VerifyFound();
5086
5087 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
5088 vkDestroyImageView(m_device->device(), view, nullptr);
5089 vkFreeMemory(m_device->device(), image_memory, nullptr);
5090}
5091
Tobin Ehlisb329f992016-10-12 13:20:29 -06005092TEST_F(VkLayerTest, FramebufferInUseDestroyedSignaled) {
5093 TEST_DESCRIPTION("Delete in-use framebuffer.");
Tony Barbour1fa09702017-03-16 12:09:08 -06005094 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisb329f992016-10-12 13:20:29 -06005095 VkFormatProperties format_properties;
5096 VkResult err = VK_SUCCESS;
5097 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
5098
Tobin Ehlisb329f992016-10-12 13:20:29 -06005099 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5100
5101 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06005102 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 -06005103 ASSERT_TRUE(image.initialized());
5104 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
5105
5106 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
5107 VkFramebuffer fb;
5108 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
5109 ASSERT_VK_SUCCESS(err);
5110
5111 // Just use default renderpass with our framebuffer
5112 m_renderPassBeginInfo.framebuffer = fb;
5113 // Create Null cmd buffer for submit
Tony Barbour552f6c02016-12-21 14:34:07 -07005114 m_commandBuffer->BeginCommandBuffer();
5115 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
5116 m_commandBuffer->EndRenderPass();
5117 m_commandBuffer->EndCommandBuffer();
Tobin Ehlisb329f992016-10-12 13:20:29 -06005118 // Submit cmd buffer to put it in-flight
5119 VkSubmitInfo submit_info = {};
5120 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5121 submit_info.commandBufferCount = 1;
5122 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5123 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5124 // Destroy framebuffer while in-flight
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07005125 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00422);
Tobin Ehlisb329f992016-10-12 13:20:29 -06005126 vkDestroyFramebuffer(m_device->device(), fb, NULL);
5127 m_errorMonitor->VerifyFound();
5128 // Wait for queue to complete so we can safely destroy everything
5129 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005130 m_errorMonitor->SetUnexpectedError("If framebuffer is not VK_NULL_HANDLE, framebuffer must be a valid VkFramebuffer handle");
5131 m_errorMonitor->SetUnexpectedError("Unable to remove Framebuffer obj");
Tobin Ehlisb329f992016-10-12 13:20:29 -06005132 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
5133}
5134
Tobin Ehlis88becd72016-09-21 14:33:41 -06005135TEST_F(VkLayerTest, FramebufferImageInUseDestroyedSignaled) {
5136 TEST_DESCRIPTION("Delete in-use image that's child of framebuffer.");
Tony Barbour1fa09702017-03-16 12:09:08 -06005137 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis88becd72016-09-21 14:33:41 -06005138 VkFormatProperties format_properties;
5139 VkResult err = VK_SUCCESS;
5140 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
Tobin Ehlis88becd72016-09-21 14:33:41 -06005141
Tobin Ehlis88becd72016-09-21 14:33:41 -06005142 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5143
5144 VkImageCreateInfo image_ci = {};
5145 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5146 image_ci.pNext = NULL;
5147 image_ci.imageType = VK_IMAGE_TYPE_2D;
5148 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
5149 image_ci.extent.width = 256;
5150 image_ci.extent.height = 256;
5151 image_ci.extent.depth = 1;
5152 image_ci.mipLevels = 1;
5153 image_ci.arrayLayers = 1;
5154 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
5155 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisc8ca0312016-09-22 07:30:05 -06005156 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Tobin Ehlis88becd72016-09-21 14:33:41 -06005157 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
5158 image_ci.flags = 0;
5159 VkImage image;
5160 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
5161
5162 VkMemoryRequirements memory_reqs;
5163 VkDeviceMemory image_memory;
5164 bool pass;
5165 VkMemoryAllocateInfo memory_info = {};
5166 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5167 memory_info.pNext = NULL;
5168 memory_info.allocationSize = 0;
5169 memory_info.memoryTypeIndex = 0;
5170 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5171 memory_info.allocationSize = memory_reqs.size;
5172 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
5173 ASSERT_TRUE(pass);
5174 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
5175 ASSERT_VK_SUCCESS(err);
5176 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5177 ASSERT_VK_SUCCESS(err);
5178
5179 VkImageViewCreateInfo ivci = {
5180 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
5181 nullptr,
5182 0,
5183 image,
5184 VK_IMAGE_VIEW_TYPE_2D,
5185 VK_FORMAT_B8G8R8A8_UNORM,
5186 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
5187 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
5188 };
5189 VkImageView view;
5190 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
5191 ASSERT_VK_SUCCESS(err);
5192
5193 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
5194 VkFramebuffer fb;
5195 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
5196 ASSERT_VK_SUCCESS(err);
5197
5198 // Just use default renderpass with our framebuffer
5199 m_renderPassBeginInfo.framebuffer = fb;
5200 // Create Null cmd buffer for submit
Tony Barbour552f6c02016-12-21 14:34:07 -07005201 m_commandBuffer->BeginCommandBuffer();
5202 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
5203 m_commandBuffer->EndRenderPass();
5204 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis88becd72016-09-21 14:33:41 -06005205 // Submit cmd buffer to put it (and attached imageView) in-flight
5206 VkSubmitInfo submit_info = {};
5207 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5208 submit_info.commandBufferCount = 1;
5209 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5210 // Submit cmd buffer to put framebuffer and children in-flight
5211 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5212 // Destroy image attached to framebuffer while in-flight
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07005213 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00743);
Tobin Ehlis88becd72016-09-21 14:33:41 -06005214 vkDestroyImage(m_device->device(), image, NULL);
5215 m_errorMonitor->VerifyFound();
5216 // Wait for queue to complete so we can safely destroy image and other objects
5217 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005218 m_errorMonitor->SetUnexpectedError("If image is not VK_NULL_HANDLE, image must be a valid VkImage handle");
5219 m_errorMonitor->SetUnexpectedError("Unable to remove Image obj");
Tobin Ehlis88becd72016-09-21 14:33:41 -06005220 vkDestroyImage(m_device->device(), image, NULL);
5221 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
5222 vkDestroyImageView(m_device->device(), view, nullptr);
5223 vkFreeMemory(m_device->device(), image_memory, nullptr);
5224}
5225
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005226TEST_F(VkLayerTest, RenderPassInUseDestroyedSignaled) {
5227 TEST_DESCRIPTION("Delete in-use renderPass.");
5228
Tony Barbour1fa09702017-03-16 12:09:08 -06005229 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005230 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5231
5232 // Create simple renderpass
5233 VkAttachmentReference attach = {};
5234 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
5235 VkSubpassDescription subpass = {};
Dave Houlton756e6742017-03-23 14:33:22 -06005236 subpass.colorAttachmentCount = 1;
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005237 subpass.pColorAttachments = &attach;
5238 VkRenderPassCreateInfo rpci = {};
5239 rpci.subpassCount = 1;
5240 rpci.pSubpasses = &subpass;
5241 rpci.attachmentCount = 1;
5242 VkAttachmentDescription attach_desc = {};
5243 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
5244 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
5245 rpci.pAttachments = &attach_desc;
5246 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
5247 VkRenderPass rp;
5248 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
5249 ASSERT_VK_SUCCESS(err);
5250
5251 // Create a pipeline that uses the given renderpass
5252 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5253 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5254
5255 VkPipelineLayout pipeline_layout;
5256 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
5257 ASSERT_VK_SUCCESS(err);
5258
5259 VkPipelineViewportStateCreateInfo vp_state_ci = {};
5260 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
5261 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005262 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005263 vp_state_ci.pViewports = &vp;
5264 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005265 VkRect2D scissors = {}; // Dummy scissors to point to
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005266 vp_state_ci.pScissors = &scissors;
5267
5268 VkPipelineShaderStageCreateInfo shaderStages[2];
5269 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
5270
5271 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005272 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 -06005273 // but add it to be able to run on more devices
5274 shaderStages[0] = vs.GetStageCreateInfo();
5275 shaderStages[1] = fs.GetStageCreateInfo();
5276
5277 VkPipelineVertexInputStateCreateInfo vi_ci = {};
5278 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
5279
5280 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
5281 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
5282 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
5283
5284 VkPipelineRasterizationStateCreateInfo rs_ci = {};
5285 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
5286 rs_ci.rasterizerDiscardEnable = true;
5287 rs_ci.lineWidth = 1.0f;
5288
5289 VkPipelineColorBlendAttachmentState att = {};
5290 att.blendEnable = VK_FALSE;
5291 att.colorWriteMask = 0xf;
5292
5293 VkPipelineColorBlendStateCreateInfo cb_ci = {};
5294 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
5295 cb_ci.attachmentCount = 1;
5296 cb_ci.pAttachments = &att;
5297
5298 VkGraphicsPipelineCreateInfo gp_ci = {};
5299 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
5300 gp_ci.stageCount = 2;
5301 gp_ci.pStages = shaderStages;
5302 gp_ci.pVertexInputState = &vi_ci;
5303 gp_ci.pInputAssemblyState = &ia_ci;
5304 gp_ci.pViewportState = &vp_state_ci;
5305 gp_ci.pRasterizationState = &rs_ci;
5306 gp_ci.pColorBlendState = &cb_ci;
5307 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
5308 gp_ci.layout = pipeline_layout;
5309 gp_ci.renderPass = rp;
5310
5311 VkPipelineCacheCreateInfo pc_ci = {};
5312 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
5313
Dave Houlton756e6742017-03-23 14:33:22 -06005314 m_errorMonitor->ExpectSuccess();
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005315 VkPipeline pipeline;
5316 VkPipelineCache pipe_cache;
5317 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipe_cache);
5318 ASSERT_VK_SUCCESS(err);
5319
5320 err = vkCreateGraphicsPipelines(m_device->device(), pipe_cache, 1, &gp_ci, NULL, &pipeline);
5321 ASSERT_VK_SUCCESS(err);
Dave Houlton756e6742017-03-23 14:33:22 -06005322
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005323 // Bind pipeline to cmd buffer, will also bind renderpass
5324 m_commandBuffer->BeginCommandBuffer();
5325 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
5326 m_commandBuffer->EndCommandBuffer();
5327
5328 VkSubmitInfo submit_info = {};
5329 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5330 submit_info.commandBufferCount = 1;
5331 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5332 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Dave Houlton756e6742017-03-23 14:33:22 -06005333 m_errorMonitor->VerifyNotFound();
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005334
5335 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00393);
5336 vkDestroyRenderPass(m_device->device(), rp, nullptr);
5337 m_errorMonitor->VerifyFound();
5338
5339 // Wait for queue to complete so we can safely destroy everything
5340 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005341 m_errorMonitor->SetUnexpectedError("If renderPass is not VK_NULL_HANDLE, renderPass must be a valid VkRenderPass handle");
Mark Lobodzinski74597792017-04-11 15:43:49 -06005342 m_errorMonitor->SetUnexpectedError("Unable to remove RenderPass obj");
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005343 vkDestroyRenderPass(m_device->device(), rp, nullptr);
5344 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
5345 vkDestroyPipelineCache(m_device->device(), pipe_cache, nullptr);
5346 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
5347}
5348
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005349TEST_F(VkLayerTest, ImageMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005350 TEST_DESCRIPTION("Attempt to draw with an image which has not had memory bound to it.");
Tony Barbour1fa09702017-03-16 12:09:08 -06005351 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005352
5353 VkImage image;
5354 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5355 VkImageCreateInfo image_create_info = {};
5356 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5357 image_create_info.pNext = NULL;
5358 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5359 image_create_info.format = tex_format;
5360 image_create_info.extent.width = 32;
5361 image_create_info.extent.height = 32;
5362 image_create_info.extent.depth = 1;
5363 image_create_info.mipLevels = 1;
5364 image_create_info.arrayLayers = 1;
5365 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5366 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005367 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005368 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005369 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005370 ASSERT_VK_SUCCESS(err);
5371 // Have to bind memory to image before recording cmd in cmd buffer using it
5372 VkMemoryRequirements mem_reqs;
5373 VkDeviceMemory image_mem;
5374 bool pass;
5375 VkMemoryAllocateInfo mem_alloc = {};
5376 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5377 mem_alloc.pNext = NULL;
5378 mem_alloc.memoryTypeIndex = 0;
5379 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
5380 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005381 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005382 ASSERT_TRUE(pass);
5383 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
5384 ASSERT_VK_SUCCESS(err);
5385
Tobin Ehlisfed999f2016-09-21 15:09:45 -06005386 // Introduce error, do not call vkBindImageMemory(m_device->device(), image, image_mem, 0);
5387 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005388 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005389
5390 m_commandBuffer->BeginCommandBuffer();
5391 VkClearColorValue ccv;
5392 ccv.float32[0] = 1.0f;
5393 ccv.float32[1] = 1.0f;
5394 ccv.float32[2] = 1.0f;
5395 ccv.float32[3] = 1.0f;
5396 VkImageSubresourceRange isr = {};
5397 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
5398 isr.baseArrayLayer = 0;
5399 isr.baseMipLevel = 0;
5400 isr.layerCount = 1;
5401 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005402 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005403 m_commandBuffer->EndCommandBuffer();
5404
5405 m_errorMonitor->VerifyFound();
5406 vkDestroyImage(m_device->device(), image, NULL);
5407 vkFreeMemory(m_device->device(), image_mem, nullptr);
5408}
5409
5410TEST_F(VkLayerTest, BufferMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005411 TEST_DESCRIPTION("Attempt to copy from a buffer which has not had memory bound to it.");
Tony Barbour1fa09702017-03-16 12:09:08 -06005412 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005413
5414 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06005415 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 -06005416 VK_IMAGE_TILING_OPTIMAL, 0);
5417 ASSERT_TRUE(image.initialized());
5418
5419 VkBuffer buffer;
5420 VkDeviceMemory mem;
5421 VkMemoryRequirements mem_reqs;
5422
5423 VkBufferCreateInfo buf_info = {};
5424 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes8d260dd2016-09-16 17:42:42 +12005425 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski80871462017-02-16 10:37:27 -07005426 buf_info.size = 1024;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005427 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
5428 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
5429 ASSERT_VK_SUCCESS(err);
5430
5431 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
5432
5433 VkMemoryAllocateInfo alloc_info = {};
5434 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Mark Lobodzinski80871462017-02-16 10:37:27 -07005435 alloc_info.allocationSize = 1024;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005436 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005437 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 -06005438 if (!pass) {
5439 vkDestroyBuffer(m_device->device(), buffer, NULL);
5440 return;
5441 }
5442 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
5443 ASSERT_VK_SUCCESS(err);
5444
Tobin Ehlisfed999f2016-09-21 15:09:45 -06005445 // Introduce failure by not calling vkBindBufferMemory(m_device->device(), buffer, mem, 0);
5446 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005447 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005448 VkBufferImageCopy region = {};
Mark Lobodzinski80871462017-02-16 10:37:27 -07005449 region.bufferRowLength = 16;
5450 region.bufferImageHeight = 16;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005451 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
5452
5453 region.imageSubresource.layerCount = 1;
5454 region.imageExtent.height = 4;
5455 region.imageExtent.width = 4;
5456 region.imageExtent.depth = 1;
5457 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005458 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer, image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
5459 &region);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005460 m_commandBuffer->EndCommandBuffer();
5461
5462 m_errorMonitor->VerifyFound();
5463
5464 vkDestroyBuffer(m_device->device(), buffer, NULL);
5465 vkFreeMemory(m_device->handle(), mem, NULL);
5466}
5467
Tobin Ehlis85940f52016-07-07 16:57:21 -06005468TEST_F(VkLayerTest, InvalidCmdBufferEventDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005469 TEST_DESCRIPTION(
5470 "Attempt to draw with a command buffer that is invalid "
5471 "due to an event dependency being destroyed.");
Tony Barbour1fa09702017-03-16 12:09:08 -06005472 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis85940f52016-07-07 16:57:21 -06005473
5474 VkEvent event;
5475 VkEventCreateInfo evci = {};
5476 evci.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
5477 VkResult result = vkCreateEvent(m_device->device(), &evci, NULL, &event);
5478 ASSERT_VK_SUCCESS(result);
5479
5480 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005481 vkCmdSetEvent(m_commandBuffer->GetBufferHandle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Tobin Ehlis85940f52016-07-07 16:57:21 -06005482 m_commandBuffer->EndCommandBuffer();
5483
Mark Lobodzinski33826372017-04-13 11:10:11 -06005484 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound Event ");
Tobin Ehlis85940f52016-07-07 16:57:21 -06005485 // Destroy event dependency prior to submit to cause ERROR
5486 vkDestroyEvent(m_device->device(), event, NULL);
5487
5488 VkSubmitInfo submit_info = {};
5489 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5490 submit_info.commandBufferCount = 1;
5491 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5492 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5493
5494 m_errorMonitor->VerifyFound();
5495}
5496
Tobin Ehlisdbea7552016-07-08 14:33:31 -06005497TEST_F(VkLayerTest, InvalidCmdBufferQueryPoolDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005498 TEST_DESCRIPTION(
5499 "Attempt to draw with a command buffer that is invalid "
5500 "due to a query pool dependency being destroyed.");
Tony Barbour1fa09702017-03-16 12:09:08 -06005501 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisdbea7552016-07-08 14:33:31 -06005502
5503 VkQueryPool query_pool;
5504 VkQueryPoolCreateInfo qpci{};
5505 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
5506 qpci.queryType = VK_QUERY_TYPE_TIMESTAMP;
5507 qpci.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005508 VkResult result = vkCreateQueryPool(m_device->device(), &qpci, nullptr, &query_pool);
Tobin Ehlisdbea7552016-07-08 14:33:31 -06005509 ASSERT_VK_SUCCESS(result);
5510
5511 m_commandBuffer->BeginCommandBuffer();
5512 vkCmdResetQueryPool(m_commandBuffer->GetBufferHandle(), query_pool, 0, 1);
5513 m_commandBuffer->EndCommandBuffer();
5514
Mark Lobodzinski33826372017-04-13 11:10:11 -06005515 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound QueryPool ");
Tobin Ehlisdbea7552016-07-08 14:33:31 -06005516 // Destroy query pool dependency prior to submit to cause ERROR
5517 vkDestroyQueryPool(m_device->device(), query_pool, NULL);
5518
5519 VkSubmitInfo submit_info = {};
5520 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5521 submit_info.commandBufferCount = 1;
5522 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5523 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5524
5525 m_errorMonitor->VerifyFound();
5526}
5527
Tobin Ehlis24130d92016-07-08 15:50:53 -06005528TEST_F(VkLayerTest, InvalidCmdBufferPipelineDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005529 TEST_DESCRIPTION(
5530 "Attempt to draw with a command buffer that is invalid "
5531 "due to a pipeline dependency being destroyed.");
Tony Barbour1fa09702017-03-16 12:09:08 -06005532 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis24130d92016-07-08 15:50:53 -06005533 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5534
5535 VkResult err;
5536
5537 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5538 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5539
5540 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005541 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis24130d92016-07-08 15:50:53 -06005542 ASSERT_VK_SUCCESS(err);
5543
5544 VkPipelineViewportStateCreateInfo vp_state_ci = {};
5545 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
5546 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005547 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -06005548 vp_state_ci.pViewports = &vp;
Tobin Ehlis24130d92016-07-08 15:50:53 -06005549 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005550 VkRect2D scissors = {}; // Dummy scissors to point to
Tobin Ehlis24130d92016-07-08 15:50:53 -06005551 vp_state_ci.pScissors = &scissors;
Tobin Ehlis24130d92016-07-08 15:50:53 -06005552
5553 VkPipelineShaderStageCreateInfo shaderStages[2];
5554 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
5555
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005556 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005557 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 -06005558 // but add it to be able to run on more devices
Tobin Ehlis24130d92016-07-08 15:50:53 -06005559 shaderStages[0] = vs.GetStageCreateInfo();
5560 shaderStages[1] = fs.GetStageCreateInfo();
5561
5562 VkPipelineVertexInputStateCreateInfo vi_ci = {};
5563 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
5564
5565 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
5566 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
5567 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
5568
5569 VkPipelineRasterizationStateCreateInfo rs_ci = {};
5570 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbese06ba252016-09-16 17:48:53 +12005571 rs_ci.rasterizerDiscardEnable = true;
5572 rs_ci.lineWidth = 1.0f;
Tobin Ehlis24130d92016-07-08 15:50:53 -06005573
5574 VkPipelineColorBlendAttachmentState att = {};
5575 att.blendEnable = VK_FALSE;
5576 att.colorWriteMask = 0xf;
5577
5578 VkPipelineColorBlendStateCreateInfo cb_ci = {};
5579 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
5580 cb_ci.attachmentCount = 1;
5581 cb_ci.pAttachments = &att;
5582
5583 VkGraphicsPipelineCreateInfo gp_ci = {};
5584 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
5585 gp_ci.stageCount = 2;
5586 gp_ci.pStages = shaderStages;
5587 gp_ci.pVertexInputState = &vi_ci;
5588 gp_ci.pInputAssemblyState = &ia_ci;
5589 gp_ci.pViewportState = &vp_state_ci;
5590 gp_ci.pRasterizationState = &rs_ci;
5591 gp_ci.pColorBlendState = &cb_ci;
Tobin Ehlis24130d92016-07-08 15:50:53 -06005592 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
5593 gp_ci.layout = pipeline_layout;
5594 gp_ci.renderPass = renderPass();
5595
5596 VkPipelineCacheCreateInfo pc_ci = {};
5597 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
5598
5599 VkPipeline pipeline;
5600 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005601 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis24130d92016-07-08 15:50:53 -06005602 ASSERT_VK_SUCCESS(err);
5603
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005604 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06005605 ASSERT_VK_SUCCESS(err);
5606
5607 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005608 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06005609 m_commandBuffer->EndCommandBuffer();
5610 // Now destroy pipeline in order to cause error when submitting
5611 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
5612
Mark Lobodzinski33826372017-04-13 11:10:11 -06005613 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound Pipeline ");
Tobin Ehlis24130d92016-07-08 15:50:53 -06005614
5615 VkSubmitInfo submit_info = {};
5616 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5617 submit_info.commandBufferCount = 1;
5618 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5619 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5620
5621 m_errorMonitor->VerifyFound();
5622 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
5623 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5624}
5625
Tobin Ehlis31289162016-08-17 14:57:58 -06005626TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetBufferDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005627 TEST_DESCRIPTION(
5628 "Attempt to draw with a command buffer that is invalid "
5629 "due to a bound descriptor set with a buffer dependency "
5630 "being destroyed.");
Tony Barbour1fa09702017-03-16 12:09:08 -06005631 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis31289162016-08-17 14:57:58 -06005632 ASSERT_NO_FATAL_FAILURE(InitViewport());
5633 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5634
5635 VkDescriptorPoolSize ds_type_count = {};
5636 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5637 ds_type_count.descriptorCount = 1;
5638
5639 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5640 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5641 ds_pool_ci.pNext = NULL;
5642 ds_pool_ci.maxSets = 1;
5643 ds_pool_ci.poolSizeCount = 1;
5644 ds_pool_ci.pPoolSizes = &ds_type_count;
5645
5646 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005647 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis31289162016-08-17 14:57:58 -06005648 ASSERT_VK_SUCCESS(err);
5649
5650 VkDescriptorSetLayoutBinding dsl_binding = {};
5651 dsl_binding.binding = 0;
5652 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5653 dsl_binding.descriptorCount = 1;
5654 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5655 dsl_binding.pImmutableSamplers = NULL;
5656
5657 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5658 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5659 ds_layout_ci.pNext = NULL;
5660 ds_layout_ci.bindingCount = 1;
5661 ds_layout_ci.pBindings = &dsl_binding;
5662 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005663 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06005664 ASSERT_VK_SUCCESS(err);
5665
5666 VkDescriptorSet descriptorSet;
5667 VkDescriptorSetAllocateInfo alloc_info = {};
5668 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5669 alloc_info.descriptorSetCount = 1;
5670 alloc_info.descriptorPool = ds_pool;
5671 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005672 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis31289162016-08-17 14:57:58 -06005673 ASSERT_VK_SUCCESS(err);
5674
5675 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5676 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5677 pipeline_layout_ci.pNext = NULL;
5678 pipeline_layout_ci.setLayoutCount = 1;
5679 pipeline_layout_ci.pSetLayouts = &ds_layout;
5680
5681 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005682 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06005683 ASSERT_VK_SUCCESS(err);
5684
5685 // Create a buffer to update the descriptor with
5686 uint32_t qfi = 0;
5687 VkBufferCreateInfo buffCI = {};
5688 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
5689 buffCI.size = 1024;
5690 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
5691 buffCI.queueFamilyIndexCount = 1;
5692 buffCI.pQueueFamilyIndices = &qfi;
5693
5694 VkBuffer buffer;
5695 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &buffer);
5696 ASSERT_VK_SUCCESS(err);
5697 // Allocate memory and bind to buffer so we can make it to the appropriate
5698 // error
5699 VkMemoryAllocateInfo mem_alloc = {};
5700 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5701 mem_alloc.pNext = NULL;
5702 mem_alloc.allocationSize = 1024;
5703 mem_alloc.memoryTypeIndex = 0;
5704
5705 VkMemoryRequirements memReqs;
5706 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005707 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis31289162016-08-17 14:57:58 -06005708 if (!pass) {
5709 vkDestroyBuffer(m_device->device(), buffer, NULL);
5710 return;
5711 }
5712
5713 VkDeviceMemory mem;
5714 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
5715 ASSERT_VK_SUCCESS(err);
5716 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
5717 ASSERT_VK_SUCCESS(err);
5718 // Correctly update descriptor to avoid "NOT_UPDATED" error
5719 VkDescriptorBufferInfo buffInfo = {};
5720 buffInfo.buffer = buffer;
5721 buffInfo.offset = 0;
5722 buffInfo.range = 1024;
5723
5724 VkWriteDescriptorSet descriptor_write;
5725 memset(&descriptor_write, 0, sizeof(descriptor_write));
5726 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5727 descriptor_write.dstSet = descriptorSet;
5728 descriptor_write.dstBinding = 0;
5729 descriptor_write.descriptorCount = 1;
5730 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5731 descriptor_write.pBufferInfo = &buffInfo;
5732
5733 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5734
5735 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005736 char const *vsSource =
5737 "#version 450\n"
5738 "\n"
5739 "out gl_PerVertex { \n"
5740 " vec4 gl_Position;\n"
5741 "};\n"
5742 "void main(){\n"
5743 " gl_Position = vec4(1);\n"
5744 "}\n";
5745 char const *fsSource =
5746 "#version 450\n"
5747 "\n"
5748 "layout(location=0) out vec4 x;\n"
5749 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
5750 "void main(){\n"
5751 " x = vec4(bar.y);\n"
5752 "}\n";
Tobin Ehlis31289162016-08-17 14:57:58 -06005753 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5754 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5755 VkPipelineObj pipe(m_device);
5756 pipe.AddShader(&vs);
5757 pipe.AddShader(&fs);
5758 pipe.AddColorAttachment();
5759 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5760
Tony Barbour552f6c02016-12-21 14:34:07 -07005761 m_commandBuffer->BeginCommandBuffer();
5762 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005763 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5764 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5765 &descriptorSet, 0, NULL);
Rene Lindsay0583ac92017-01-16 14:29:10 -07005766
5767 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &m_viewports[0]);
5768 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &m_scissors[0]);
5769
Tobin Ehlis31289162016-08-17 14:57:58 -06005770 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005771 m_commandBuffer->EndRenderPass();
5772 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski33826372017-04-13 11:10:11 -06005773 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound Buffer ");
Tobin Ehlis31289162016-08-17 14:57:58 -06005774 // Destroy buffer should invalidate the cmd buffer, causing error on submit
5775 vkDestroyBuffer(m_device->device(), buffer, NULL);
5776 // Attempt to submit cmd buffer
5777 VkSubmitInfo submit_info = {};
5778 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5779 submit_info.commandBufferCount = 1;
5780 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5781 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5782 m_errorMonitor->VerifyFound();
5783 // Cleanup
5784 vkFreeMemory(m_device->device(), mem, NULL);
5785
5786 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5787 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5788 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5789}
5790
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005791TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetImageSamplerDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005792 TEST_DESCRIPTION(
5793 "Attempt to draw with a command buffer that is invalid "
5794 "due to a bound descriptor sets with a combined image "
5795 "sampler having their image, sampler, and descriptor set "
5796 "each respectively destroyed and then attempting to "
5797 "submit associated cmd buffers. Attempt to destroy a "
5798 "DescriptorSet that is in use.");
Tony Barbour1fa09702017-03-16 12:09:08 -06005799 ASSERT_NO_FATAL_FAILURE(Init(nullptr, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT));
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005800 ASSERT_NO_FATAL_FAILURE(InitViewport());
5801 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5802
5803 VkDescriptorPoolSize ds_type_count = {};
5804 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5805 ds_type_count.descriptorCount = 1;
5806
5807 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5808 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5809 ds_pool_ci.pNext = NULL;
Rene Lindsayed88b732017-01-27 15:55:29 -07005810 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005811 ds_pool_ci.maxSets = 1;
5812 ds_pool_ci.poolSizeCount = 1;
5813 ds_pool_ci.pPoolSizes = &ds_type_count;
5814
5815 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005816 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005817 ASSERT_VK_SUCCESS(err);
5818
5819 VkDescriptorSetLayoutBinding dsl_binding = {};
5820 dsl_binding.binding = 0;
5821 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5822 dsl_binding.descriptorCount = 1;
5823 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5824 dsl_binding.pImmutableSamplers = NULL;
5825
5826 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5827 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5828 ds_layout_ci.pNext = NULL;
5829 ds_layout_ci.bindingCount = 1;
5830 ds_layout_ci.pBindings = &dsl_binding;
5831 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005832 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005833 ASSERT_VK_SUCCESS(err);
5834
5835 VkDescriptorSet descriptorSet;
5836 VkDescriptorSetAllocateInfo alloc_info = {};
5837 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5838 alloc_info.descriptorSetCount = 1;
5839 alloc_info.descriptorPool = ds_pool;
5840 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005841 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005842 ASSERT_VK_SUCCESS(err);
5843
5844 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5845 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5846 pipeline_layout_ci.pNext = NULL;
5847 pipeline_layout_ci.setLayoutCount = 1;
5848 pipeline_layout_ci.pSetLayouts = &ds_layout;
5849
5850 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005851 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005852 ASSERT_VK_SUCCESS(err);
5853
5854 // Create images to update the descriptor with
5855 VkImage image;
5856 VkImage image2;
5857 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5858 const int32_t tex_width = 32;
5859 const int32_t tex_height = 32;
5860 VkImageCreateInfo image_create_info = {};
5861 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5862 image_create_info.pNext = NULL;
5863 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5864 image_create_info.format = tex_format;
5865 image_create_info.extent.width = tex_width;
5866 image_create_info.extent.height = tex_height;
5867 image_create_info.extent.depth = 1;
5868 image_create_info.mipLevels = 1;
5869 image_create_info.arrayLayers = 1;
5870 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5871 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
5872 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5873 image_create_info.flags = 0;
5874 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
5875 ASSERT_VK_SUCCESS(err);
5876 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
5877 ASSERT_VK_SUCCESS(err);
5878
5879 VkMemoryRequirements memory_reqs;
5880 VkDeviceMemory image_memory;
5881 bool pass;
5882 VkMemoryAllocateInfo memory_info = {};
5883 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5884 memory_info.pNext = NULL;
5885 memory_info.allocationSize = 0;
5886 memory_info.memoryTypeIndex = 0;
5887 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5888 // Allocate enough memory for both images
5889 memory_info.allocationSize = memory_reqs.size * 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005890 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005891 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005892 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005893 ASSERT_VK_SUCCESS(err);
5894 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5895 ASSERT_VK_SUCCESS(err);
5896 // Bind second image to memory right after first image
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005897 err = vkBindImageMemory(m_device->device(), image2, image_memory, memory_reqs.size);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005898 ASSERT_VK_SUCCESS(err);
5899
5900 VkImageViewCreateInfo image_view_create_info = {};
5901 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5902 image_view_create_info.image = image;
5903 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5904 image_view_create_info.format = tex_format;
5905 image_view_create_info.subresourceRange.layerCount = 1;
5906 image_view_create_info.subresourceRange.baseMipLevel = 0;
5907 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005908 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005909
5910 VkImageView view;
5911 VkImageView view2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005912 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005913 ASSERT_VK_SUCCESS(err);
5914 image_view_create_info.image = image2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005915 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view2);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005916 ASSERT_VK_SUCCESS(err);
5917 // Create Samplers
5918 VkSamplerCreateInfo sampler_ci = {};
5919 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5920 sampler_ci.pNext = NULL;
5921 sampler_ci.magFilter = VK_FILTER_NEAREST;
5922 sampler_ci.minFilter = VK_FILTER_NEAREST;
5923 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5924 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5925 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5926 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5927 sampler_ci.mipLodBias = 1.0;
5928 sampler_ci.anisotropyEnable = VK_FALSE;
5929 sampler_ci.maxAnisotropy = 1;
5930 sampler_ci.compareEnable = VK_FALSE;
5931 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5932 sampler_ci.minLod = 1.0;
5933 sampler_ci.maxLod = 1.0;
5934 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5935 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5936 VkSampler sampler;
5937 VkSampler sampler2;
5938 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5939 ASSERT_VK_SUCCESS(err);
5940 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler2);
5941 ASSERT_VK_SUCCESS(err);
5942 // Update descriptor with image and sampler
5943 VkDescriptorImageInfo img_info = {};
5944 img_info.sampler = sampler;
5945 img_info.imageView = view;
5946 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5947
5948 VkWriteDescriptorSet descriptor_write;
5949 memset(&descriptor_write, 0, sizeof(descriptor_write));
5950 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5951 descriptor_write.dstSet = descriptorSet;
5952 descriptor_write.dstBinding = 0;
5953 descriptor_write.descriptorCount = 1;
5954 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5955 descriptor_write.pImageInfo = &img_info;
5956
5957 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5958
5959 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005960 char const *vsSource =
5961 "#version 450\n"
5962 "\n"
5963 "out gl_PerVertex { \n"
5964 " vec4 gl_Position;\n"
5965 "};\n"
5966 "void main(){\n"
5967 " gl_Position = vec4(1);\n"
5968 "}\n";
5969 char const *fsSource =
5970 "#version 450\n"
5971 "\n"
5972 "layout(set=0, binding=0) uniform sampler2D s;\n"
5973 "layout(location=0) out vec4 x;\n"
5974 "void main(){\n"
5975 " x = texture(s, vec2(1));\n"
5976 "}\n";
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005977 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5978 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5979 VkPipelineObj pipe(m_device);
5980 pipe.AddShader(&vs);
5981 pipe.AddShader(&fs);
5982 pipe.AddColorAttachment();
5983 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5984
5985 // First error case is destroying sampler prior to cmd buffer submission
Mark Lobodzinski33826372017-04-13 11:10:11 -06005986 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is invalid because bound Sampler");
Tony Barbour552f6c02016-12-21 14:34:07 -07005987 m_commandBuffer->BeginCommandBuffer();
5988 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005989 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5990 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5991 &descriptorSet, 0, NULL);
Rene Lindsaya31285f2017-01-11 16:35:53 -07005992 VkViewport viewport = {0, 0, 16, 16, 0, 1};
5993 VkRect2D scissor = {{0, 0}, {16, 16}};
5994 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
5995 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005996 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005997 m_commandBuffer->EndRenderPass();
5998 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005999 // Destroy sampler invalidates the cmd buffer, causing error on submit
6000 vkDestroySampler(m_device->device(), sampler, NULL);
6001 // Attempt to submit cmd buffer
6002 VkSubmitInfo submit_info = {};
6003 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6004 submit_info.commandBufferCount = 1;
6005 submit_info.pCommandBuffers = &m_commandBuffer->handle();
6006 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
6007 m_errorMonitor->VerifyFound();
Rene Lindsaya31285f2017-01-11 16:35:53 -07006008
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06006009 // Now re-update descriptor with valid sampler and delete image
6010 img_info.sampler = sampler2;
6011 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Rene Lindsayed88b732017-01-27 15:55:29 -07006012
6013 VkCommandBufferBeginInfo info = {};
6014 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
6015 info.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
6016
Mark Lobodzinski33826372017-04-13 11:10:11 -06006017 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound Image ");
Rene Lindsayed88b732017-01-27 15:55:29 -07006018 m_commandBuffer->BeginCommandBuffer(&info);
Tony Barbour552f6c02016-12-21 14:34:07 -07006019 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006020 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
6021 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6022 &descriptorSet, 0, NULL);
Rene Lindsaya31285f2017-01-11 16:35:53 -07006023 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
6024 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06006025 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07006026 m_commandBuffer->EndRenderPass();
6027 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06006028 // Destroy image invalidates the cmd buffer, causing error on submit
6029 vkDestroyImage(m_device->device(), image, NULL);
6030 // Attempt to submit cmd buffer
6031 submit_info = {};
6032 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6033 submit_info.commandBufferCount = 1;
6034 submit_info.pCommandBuffers = &m_commandBuffer->handle();
6035 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
6036 m_errorMonitor->VerifyFound();
6037 // Now update descriptor to be valid, but then free descriptor
6038 img_info.imageView = view2;
6039 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Rene Lindsayed88b732017-01-27 15:55:29 -07006040 m_commandBuffer->BeginCommandBuffer(&info);
Tony Barbour552f6c02016-12-21 14:34:07 -07006041 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006042 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
6043 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6044 &descriptorSet, 0, NULL);
Rene Lindsaya31285f2017-01-11 16:35:53 -07006045 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
6046 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06006047 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07006048 m_commandBuffer->EndRenderPass();
6049 m_commandBuffer->EndCommandBuffer();
Tony Barbourc373c012017-01-26 10:53:28 -07006050 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Dave Houltonfbf52152017-01-06 12:55:29 -07006051
6052 // Immediately try to destroy the descriptor set in the active command buffer - failure expected
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006053 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call vkFreeDescriptorSets() on descriptor set 0x");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06006054 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Mark Mueller917f6bc2016-08-30 10:57:19 -06006055 m_errorMonitor->VerifyFound();
Dave Houltonfbf52152017-01-06 12:55:29 -07006056
6057 // Try again once the queue is idle - should succeed w/o error
Dave Houltond5507dd2017-01-24 15:29:02 -07006058 // 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 -07006059 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07006060 m_errorMonitor->SetUnexpectedError(
6061 "pDescriptorSets must be a pointer to an array of descriptorSetCount VkDescriptorSet handles, each element of which must "
6062 "either be a valid handle or VK_NULL_HANDLE");
Mark Lobodzinski74597792017-04-11 15:43:49 -06006063 m_errorMonitor->SetUnexpectedError("Unable to remove DescriptorSet obj");
Dave Houltonfbf52152017-01-06 12:55:29 -07006064 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
6065
6066 // Attempt to submit cmd buffer containing the freed descriptor set
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06006067 submit_info = {};
6068 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6069 submit_info.commandBufferCount = 1;
6070 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Lobodzinski33826372017-04-13 11:10:11 -06006071 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound DescriptorSet ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06006072 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
6073 m_errorMonitor->VerifyFound();
Dave Houltonfbf52152017-01-06 12:55:29 -07006074
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06006075 // Cleanup
6076 vkFreeMemory(m_device->device(), image_memory, NULL);
6077 vkDestroySampler(m_device->device(), sampler2, NULL);
6078 vkDestroyImage(m_device->device(), image2, NULL);
6079 vkDestroyImageView(m_device->device(), view, NULL);
6080 vkDestroyImageView(m_device->device(), view2, NULL);
6081 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6082 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6083 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6084}
6085
Tobin Ehlisaabbcd02017-04-13 14:15:21 -06006086TEST_F(VkLayerTest, ImageDescriptorLayoutMismatch) {
6087 TEST_DESCRIPTION("Update an image sampler with a layout that doesn't match the actual image layout at the image is used.");
6088 ASSERT_NO_FATAL_FAILURE(Init(nullptr, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT));
6089 ASSERT_NO_FATAL_FAILURE(InitViewport());
6090 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6091
6092 VkDescriptorPoolSize ds_type_count = {};
6093 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6094 ds_type_count.descriptorCount = 1;
6095
6096 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6097 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6098 ds_pool_ci.pNext = NULL;
6099 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
6100 ds_pool_ci.maxSets = 1;
6101 ds_pool_ci.poolSizeCount = 1;
6102 ds_pool_ci.pPoolSizes = &ds_type_count;
6103
6104 VkDescriptorPool ds_pool;
6105 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
6106 ASSERT_VK_SUCCESS(err);
6107
6108 VkDescriptorSetLayoutBinding dsl_binding = {};
6109 dsl_binding.binding = 0;
6110 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6111 dsl_binding.descriptorCount = 1;
6112 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6113 dsl_binding.pImmutableSamplers = NULL;
6114
6115 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6116 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6117 ds_layout_ci.pNext = NULL;
6118 ds_layout_ci.bindingCount = 1;
6119 ds_layout_ci.pBindings = &dsl_binding;
6120 VkDescriptorSetLayout ds_layout;
6121 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
6122 ASSERT_VK_SUCCESS(err);
6123
6124 VkDescriptorSet descriptorSet;
6125 VkDescriptorSetAllocateInfo alloc_info = {};
6126 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6127 alloc_info.descriptorSetCount = 1;
6128 alloc_info.descriptorPool = ds_pool;
6129 alloc_info.pSetLayouts = &ds_layout;
6130 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
6131 ASSERT_VK_SUCCESS(err);
6132
6133 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6134 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6135 pipeline_layout_ci.pNext = NULL;
6136 pipeline_layout_ci.setLayoutCount = 1;
6137 pipeline_layout_ci.pSetLayouts = &ds_layout;
6138
6139 VkPipelineLayout pipeline_layout;
6140 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
6141 ASSERT_VK_SUCCESS(err);
6142
6143 // Create images to update the descriptor with
6144 const VkFormat format = VK_FORMAT_B8G8R8A8_UNORM;
6145 VkImageObj image(m_device);
6146 image.Init(32, 32, 1, format, VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VK_IMAGE_TILING_OPTIMAL,
6147 0);
6148 ASSERT_TRUE(image.initialized());
6149
6150 VkImageViewCreateInfo image_view_create_info = {};
6151 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
6152 image_view_create_info.image = image.handle();
6153 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
6154 image_view_create_info.format = format;
6155 image_view_create_info.subresourceRange.layerCount = 1;
6156 image_view_create_info.subresourceRange.baseMipLevel = 0;
6157 image_view_create_info.subresourceRange.levelCount = 1;
6158 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
6159
6160 VkImageView view;
6161 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
6162 ASSERT_VK_SUCCESS(err);
6163 // Create Sampler
6164 VkSamplerCreateInfo sampler_ci = {};
6165 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
6166 sampler_ci.pNext = NULL;
6167 sampler_ci.magFilter = VK_FILTER_NEAREST;
6168 sampler_ci.minFilter = VK_FILTER_NEAREST;
6169 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
6170 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6171 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6172 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6173 sampler_ci.mipLodBias = 1.0;
6174 sampler_ci.anisotropyEnable = VK_FALSE;
6175 sampler_ci.maxAnisotropy = 1;
6176 sampler_ci.compareEnable = VK_FALSE;
6177 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
6178 sampler_ci.minLod = 1.0;
6179 sampler_ci.maxLod = 1.0;
6180 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
6181 sampler_ci.unnormalizedCoordinates = VK_FALSE;
6182 VkSampler sampler;
6183 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
6184 ASSERT_VK_SUCCESS(err);
6185 // Update descriptor with image and sampler
6186 VkDescriptorImageInfo img_info = {};
6187 img_info.sampler = sampler;
6188 img_info.imageView = view;
6189 // This should cause a mis-match. Actual layout at use time is SHADER_RO
6190 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
6191
6192 VkWriteDescriptorSet descriptor_write;
6193 memset(&descriptor_write, 0, sizeof(descriptor_write));
6194 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6195 descriptor_write.dstSet = descriptorSet;
6196 descriptor_write.dstBinding = 0;
6197 descriptor_write.descriptorCount = 1;
6198 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6199 descriptor_write.pImageInfo = &img_info;
6200
6201 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6202
6203 // Create PSO to be used for draw-time errors below
6204 char const *vsSource =
6205 "#version 450\n"
6206 "\n"
6207 "out gl_PerVertex { \n"
6208 " vec4 gl_Position;\n"
6209 "};\n"
6210 "void main(){\n"
6211 " gl_Position = vec4(1);\n"
6212 "}\n";
6213 char const *fsSource =
6214 "#version 450\n"
6215 "\n"
6216 "layout(set=0, binding=0) uniform sampler2D s;\n"
6217 "layout(location=0) out vec4 x;\n"
6218 "void main(){\n"
6219 " x = texture(s, vec2(1));\n"
6220 "}\n";
6221 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6222 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
6223 VkPipelineObj pipe(m_device);
6224 pipe.AddShader(&vs);
6225 pipe.AddShader(&fs);
6226 pipe.AddColorAttachment();
6227 pipe.CreateVKPipeline(pipeline_layout, renderPass());
6228
6229 VkCommandBufferObj cmd_buf(m_device, m_commandPool);
6230 cmd_buf.BeginCommandBuffer();
Tobin Ehlisaabbcd02017-04-13 14:15:21 -06006231 // record layout different than actual descriptor layout of SHADER_RO
6232 image.SetLayout(&cmd_buf, VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL);
Mark Lobodzinski95512b72017-05-10 12:21:30 -06006233 cmd_buf.BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlisaabbcd02017-04-13 14:15:21 -06006234 vkCmdBindPipeline(cmd_buf.handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
6235 vkCmdBindDescriptorSets(cmd_buf.handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &descriptorSet, 0, NULL);
6236 VkViewport viewport = {0, 0, 16, 16, 0, 1};
6237 VkRect2D scissor = {{0, 0}, {16, 16}};
6238 vkCmdSetViewport(cmd_buf.handle(), 0, 1, &viewport);
6239 vkCmdSetScissor(cmd_buf.handle(), 0, 1, &scissor);
6240 // At draw time the update layout will mis-match the actual layout
6241 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6242 " with specific layout VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL that doesn't match the "
6243 "actual current layout VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL.");
6244 m_errorMonitor->SetDesiredFailureMsg(
6245 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6246 " Image layout specified at vkUpdateDescriptorSets() time doesn't match actual image layout at time descriptor is used.");
6247 cmd_buf.Draw(1, 0, 0, 0);
6248 m_errorMonitor->VerifyFound();
6249 cmd_buf.EndRenderPass();
6250 cmd_buf.EndCommandBuffer();
6251 // Submit cmd buffer
6252 VkSubmitInfo submit_info = {};
6253 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6254 submit_info.commandBufferCount = 1;
6255 submit_info.pCommandBuffers = &cmd_buf.handle();
6256 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
6257 vkQueueWaitIdle(m_device->m_queue);
6258 // Cleanup
6259 vkDestroySampler(m_device->device(), sampler, NULL);
6260 vkDestroyImageView(m_device->device(), view, NULL);
6261 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6262 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6263 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6264}
6265
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006266TEST_F(VkLayerTest, DescriptorPoolInUseDestroyedSignaled) {
6267 TEST_DESCRIPTION("Delete a DescriptorPool with a DescriptorSet that is in use.");
Tony Barbour1fa09702017-03-16 12:09:08 -06006268 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006269 ASSERT_NO_FATAL_FAILURE(InitViewport());
6270 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6271
6272 VkDescriptorPoolSize ds_type_count = {};
6273 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6274 ds_type_count.descriptorCount = 1;
6275
6276 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6277 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6278 ds_pool_ci.pNext = NULL;
6279 ds_pool_ci.maxSets = 1;
6280 ds_pool_ci.poolSizeCount = 1;
6281 ds_pool_ci.pPoolSizes = &ds_type_count;
6282
6283 VkDescriptorPool ds_pool;
6284 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
6285 ASSERT_VK_SUCCESS(err);
6286
6287 VkDescriptorSetLayoutBinding dsl_binding = {};
6288 dsl_binding.binding = 0;
6289 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6290 dsl_binding.descriptorCount = 1;
6291 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6292 dsl_binding.pImmutableSamplers = NULL;
6293
6294 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6295 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6296 ds_layout_ci.pNext = NULL;
6297 ds_layout_ci.bindingCount = 1;
6298 ds_layout_ci.pBindings = &dsl_binding;
6299 VkDescriptorSetLayout ds_layout;
6300 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
6301 ASSERT_VK_SUCCESS(err);
6302
6303 VkDescriptorSet descriptor_set;
6304 VkDescriptorSetAllocateInfo alloc_info = {};
6305 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6306 alloc_info.descriptorSetCount = 1;
6307 alloc_info.descriptorPool = ds_pool;
6308 alloc_info.pSetLayouts = &ds_layout;
6309 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
6310 ASSERT_VK_SUCCESS(err);
6311
6312 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6313 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6314 pipeline_layout_ci.pNext = NULL;
6315 pipeline_layout_ci.setLayoutCount = 1;
6316 pipeline_layout_ci.pSetLayouts = &ds_layout;
6317
6318 VkPipelineLayout pipeline_layout;
6319 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
6320 ASSERT_VK_SUCCESS(err);
6321
6322 // Create image to update the descriptor with
6323 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06006324 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 -06006325 ASSERT_TRUE(image.initialized());
6326
6327 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
6328 // Create Sampler
6329 VkSamplerCreateInfo sampler_ci = {};
6330 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
6331 sampler_ci.pNext = NULL;
6332 sampler_ci.magFilter = VK_FILTER_NEAREST;
6333 sampler_ci.minFilter = VK_FILTER_NEAREST;
6334 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
6335 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6336 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6337 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6338 sampler_ci.mipLodBias = 1.0;
6339 sampler_ci.anisotropyEnable = VK_FALSE;
6340 sampler_ci.maxAnisotropy = 1;
6341 sampler_ci.compareEnable = VK_FALSE;
6342 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
6343 sampler_ci.minLod = 1.0;
6344 sampler_ci.maxLod = 1.0;
6345 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
6346 sampler_ci.unnormalizedCoordinates = VK_FALSE;
6347 VkSampler sampler;
6348 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
6349 ASSERT_VK_SUCCESS(err);
6350 // Update descriptor with image and sampler
6351 VkDescriptorImageInfo img_info = {};
6352 img_info.sampler = sampler;
6353 img_info.imageView = view;
6354 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
6355
6356 VkWriteDescriptorSet descriptor_write;
6357 memset(&descriptor_write, 0, sizeof(descriptor_write));
6358 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6359 descriptor_write.dstSet = descriptor_set;
6360 descriptor_write.dstBinding = 0;
6361 descriptor_write.descriptorCount = 1;
6362 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6363 descriptor_write.pImageInfo = &img_info;
6364
6365 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6366
6367 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006368 char const *vsSource =
6369 "#version 450\n"
6370 "\n"
6371 "out gl_PerVertex { \n"
6372 " vec4 gl_Position;\n"
6373 "};\n"
6374 "void main(){\n"
6375 " gl_Position = vec4(1);\n"
6376 "}\n";
6377 char const *fsSource =
6378 "#version 450\n"
6379 "\n"
6380 "layout(set=0, binding=0) uniform sampler2D s;\n"
6381 "layout(location=0) out vec4 x;\n"
6382 "void main(){\n"
6383 " x = texture(s, vec2(1));\n"
6384 "}\n";
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006385 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6386 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
6387 VkPipelineObj pipe(m_device);
6388 pipe.AddShader(&vs);
6389 pipe.AddShader(&fs);
6390 pipe.AddColorAttachment();
6391 pipe.CreateVKPipeline(pipeline_layout, renderPass());
6392
Tony Barbour552f6c02016-12-21 14:34:07 -07006393 m_commandBuffer->BeginCommandBuffer();
6394 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006395 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
6396 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6397 &descriptor_set, 0, NULL);
Rene Lindsaye353a072017-01-16 11:07:28 -07006398
6399 VkViewport viewport = {0, 0, 16, 16, 0, 1};
6400 VkRect2D scissor = {{0, 0}, {16, 16}};
6401 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
6402 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
6403
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006404 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07006405 m_commandBuffer->EndRenderPass();
6406 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006407 // Submit cmd buffer to put pool in-flight
6408 VkSubmitInfo submit_info = {};
6409 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6410 submit_info.commandBufferCount = 1;
6411 submit_info.pCommandBuffers = &m_commandBuffer->handle();
6412 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
6413 // Destroy pool while in-flight, causing error
Mark Lobodzinski33826372017-04-13 11:10:11 -06006414 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete DescriptorPool ");
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006415 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6416 m_errorMonitor->VerifyFound();
6417 vkQueueWaitIdle(m_device->m_queue);
6418 // Cleanup
6419 vkDestroySampler(m_device->device(), sampler, NULL);
6420 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6421 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07006422 m_errorMonitor->SetUnexpectedError(
6423 "If descriptorPool is not VK_NULL_HANDLE, descriptorPool must be a valid VkDescriptorPool handle");
Mark Lobodzinski74597792017-04-11 15:43:49 -06006424 m_errorMonitor->SetUnexpectedError("Unable to remove DescriptorPool obj");
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006425 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Rene Lindsaye353a072017-01-16 11:07:28 -07006426 // TODO : It seems Validation layers think ds_pool was already destroyed, even though it wasn't?
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006427}
6428
Tobin Ehlis50a095d2016-09-21 17:32:49 -06006429TEST_F(VkLayerTest, DescriptorImageUpdateNoMemoryBound) {
6430 TEST_DESCRIPTION("Attempt an image descriptor set update where image's bound memory has been freed.");
Tony Barbour1fa09702017-03-16 12:09:08 -06006431 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis50a095d2016-09-21 17:32:49 -06006432 ASSERT_NO_FATAL_FAILURE(InitViewport());
6433 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6434
6435 VkDescriptorPoolSize ds_type_count = {};
6436 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6437 ds_type_count.descriptorCount = 1;
6438
6439 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6440 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6441 ds_pool_ci.pNext = NULL;
6442 ds_pool_ci.maxSets = 1;
6443 ds_pool_ci.poolSizeCount = 1;
6444 ds_pool_ci.pPoolSizes = &ds_type_count;
6445
6446 VkDescriptorPool ds_pool;
6447 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
6448 ASSERT_VK_SUCCESS(err);
6449
6450 VkDescriptorSetLayoutBinding dsl_binding = {};
6451 dsl_binding.binding = 0;
6452 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6453 dsl_binding.descriptorCount = 1;
6454 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6455 dsl_binding.pImmutableSamplers = NULL;
6456
6457 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6458 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6459 ds_layout_ci.pNext = NULL;
6460 ds_layout_ci.bindingCount = 1;
6461 ds_layout_ci.pBindings = &dsl_binding;
6462 VkDescriptorSetLayout ds_layout;
6463 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
6464 ASSERT_VK_SUCCESS(err);
6465
6466 VkDescriptorSet descriptorSet;
6467 VkDescriptorSetAllocateInfo alloc_info = {};
6468 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6469 alloc_info.descriptorSetCount = 1;
6470 alloc_info.descriptorPool = ds_pool;
6471 alloc_info.pSetLayouts = &ds_layout;
6472 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
6473 ASSERT_VK_SUCCESS(err);
6474
6475 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6476 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6477 pipeline_layout_ci.pNext = NULL;
6478 pipeline_layout_ci.setLayoutCount = 1;
6479 pipeline_layout_ci.pSetLayouts = &ds_layout;
6480
6481 VkPipelineLayout pipeline_layout;
6482 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
6483 ASSERT_VK_SUCCESS(err);
6484
6485 // Create images to update the descriptor with
6486 VkImage image;
6487 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
6488 const int32_t tex_width = 32;
6489 const int32_t tex_height = 32;
6490 VkImageCreateInfo image_create_info = {};
6491 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6492 image_create_info.pNext = NULL;
6493 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6494 image_create_info.format = tex_format;
6495 image_create_info.extent.width = tex_width;
6496 image_create_info.extent.height = tex_height;
6497 image_create_info.extent.depth = 1;
6498 image_create_info.mipLevels = 1;
6499 image_create_info.arrayLayers = 1;
6500 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
6501 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
6502 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
6503 image_create_info.flags = 0;
6504 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
6505 ASSERT_VK_SUCCESS(err);
6506 // Initially bind memory to avoid error at bind view time. We'll break binding before update.
6507 VkMemoryRequirements memory_reqs;
6508 VkDeviceMemory image_memory;
6509 bool pass;
6510 VkMemoryAllocateInfo memory_info = {};
6511 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6512 memory_info.pNext = NULL;
6513 memory_info.allocationSize = 0;
6514 memory_info.memoryTypeIndex = 0;
6515 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
6516 // Allocate enough memory for image
6517 memory_info.allocationSize = memory_reqs.size;
6518 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
6519 ASSERT_TRUE(pass);
6520 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
6521 ASSERT_VK_SUCCESS(err);
6522 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
6523 ASSERT_VK_SUCCESS(err);
6524
6525 VkImageViewCreateInfo image_view_create_info = {};
6526 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
6527 image_view_create_info.image = image;
6528 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
6529 image_view_create_info.format = tex_format;
6530 image_view_create_info.subresourceRange.layerCount = 1;
6531 image_view_create_info.subresourceRange.baseMipLevel = 0;
6532 image_view_create_info.subresourceRange.levelCount = 1;
6533 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
6534
6535 VkImageView view;
6536 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
6537 ASSERT_VK_SUCCESS(err);
6538 // Create Samplers
6539 VkSamplerCreateInfo sampler_ci = {};
6540 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
6541 sampler_ci.pNext = NULL;
6542 sampler_ci.magFilter = VK_FILTER_NEAREST;
6543 sampler_ci.minFilter = VK_FILTER_NEAREST;
6544 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
6545 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6546 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6547 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6548 sampler_ci.mipLodBias = 1.0;
6549 sampler_ci.anisotropyEnable = VK_FALSE;
6550 sampler_ci.maxAnisotropy = 1;
6551 sampler_ci.compareEnable = VK_FALSE;
6552 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
6553 sampler_ci.minLod = 1.0;
6554 sampler_ci.maxLod = 1.0;
6555 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
6556 sampler_ci.unnormalizedCoordinates = VK_FALSE;
6557 VkSampler sampler;
6558 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
6559 ASSERT_VK_SUCCESS(err);
6560 // Update descriptor with image and sampler
6561 VkDescriptorImageInfo img_info = {};
6562 img_info.sampler = sampler;
6563 img_info.imageView = view;
6564 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
6565
6566 VkWriteDescriptorSet descriptor_write;
6567 memset(&descriptor_write, 0, sizeof(descriptor_write));
6568 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6569 descriptor_write.dstSet = descriptorSet;
6570 descriptor_write.dstBinding = 0;
6571 descriptor_write.descriptorCount = 1;
6572 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6573 descriptor_write.pImageInfo = &img_info;
6574 // Break memory binding and attempt update
6575 vkFreeMemory(m_device->device(), image_memory, nullptr);
6576 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006577 " previously bound memory was freed. Memory must not be freed prior to this operation.");
Tobin Ehlis50a095d2016-09-21 17:32:49 -06006578 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6579 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
6580 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6581 m_errorMonitor->VerifyFound();
6582 // Cleanup
6583 vkDestroyImage(m_device->device(), image, NULL);
6584 vkDestroySampler(m_device->device(), sampler, NULL);
6585 vkDestroyImageView(m_device->device(), view, NULL);
6586 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6587 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6588 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6589}
6590
Karl Schultz6addd812016-02-02 17:17:23 -07006591TEST_F(VkLayerTest, InvalidPipeline) {
Karl Schultzbdb75952016-04-19 11:36:49 -06006592 // Attempt to bind an invalid Pipeline to a valid Command Buffer
6593 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06006594 // Create a valid cmd buffer
6595 // call vkCmdBindPipeline w/ false Pipeline
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06006596 uint64_t fake_pipeline_handle = 0xbaad6001;
6597 VkPipeline bad_pipeline = reinterpret_cast<VkPipeline &>(fake_pipeline_handle);
Tony Barbour1fa09702017-03-16 12:09:08 -06006598 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes4dbf70f2016-09-16 17:58:00 +12006599 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6600
Karl Schultzf78bcdd2016-11-30 12:36:01 -07006601 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00601);
Tony Barbour552f6c02016-12-21 14:34:07 -07006602 m_commandBuffer->BeginCommandBuffer();
6603 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006604 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, bad_pipeline);
Karl Schultzbdb75952016-04-19 11:36:49 -06006605 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12006606
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06006607 // Now issue a draw call with no pipeline bound
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006608 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 -06006609 Draw(1, 0, 0, 0);
6610 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12006611
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06006612 // Finally same check once more but with Dispatch/Compute
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006613 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 -07006614 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); // must be outside renderpass
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06006615 vkCmdDispatch(m_commandBuffer->GetBufferHandle(), 0, 0, 0);
6616 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06006617}
6618
Karl Schultz6addd812016-02-02 17:17:23 -07006619TEST_F(VkLayerTest, DescriptorSetNotUpdated) {
Tobin Ehlis5a5f5ef2016-08-17 13:56:55 -06006620 TEST_DESCRIPTION("Bind a descriptor set that hasn't been updated.");
Karl Schultz6addd812016-02-02 17:17:23 -07006621 VkResult err;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006622
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006623 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " bound but it was never updated. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006624
Tony Barbour1fa09702017-03-16 12:09:08 -06006625 ASSERT_NO_FATAL_FAILURE(Init());
Mike Stroyan713b2d72015-08-04 10:49:29 -06006626 ASSERT_NO_FATAL_FAILURE(InitViewport());
6627 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006628 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006629 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6630 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06006631
6632 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006633 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6634 ds_pool_ci.pNext = NULL;
6635 ds_pool_ci.maxSets = 1;
6636 ds_pool_ci.poolSizeCount = 1;
6637 ds_pool_ci.pPoolSizes = &ds_type_count;
Mike Stroyan713b2d72015-08-04 10:49:29 -06006638
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006639 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006640 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006641 ASSERT_VK_SUCCESS(err);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006642
Tony Barboureb254902015-07-15 12:50:33 -06006643 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006644 dsl_binding.binding = 0;
6645 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6646 dsl_binding.descriptorCount = 1;
6647 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6648 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006649
Tony Barboureb254902015-07-15 12:50:33 -06006650 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006651 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6652 ds_layout_ci.pNext = NULL;
6653 ds_layout_ci.bindingCount = 1;
6654 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006655 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006656 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006657 ASSERT_VK_SUCCESS(err);
6658
6659 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006660 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006661 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006662 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006663 alloc_info.descriptorPool = ds_pool;
6664 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006665 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006666 ASSERT_VK_SUCCESS(err);
6667
Tony Barboureb254902015-07-15 12:50:33 -06006668 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006669 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6670 pipeline_layout_ci.pNext = NULL;
6671 pipeline_layout_ci.setLayoutCount = 1;
6672 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006673
6674 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006675 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006676 ASSERT_VK_SUCCESS(err);
6677
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006678 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06006679 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07006680 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006681 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006682
Tony Barbourc95e4ac2015-08-04 17:05:26 -06006683 VkPipelineObj pipe(m_device);
6684 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06006685 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06006686 pipe.AddColorAttachment();
Tony Barbourc95e4ac2015-08-04 17:05:26 -06006687 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06006688
Tony Barbour552f6c02016-12-21 14:34:07 -07006689 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006690 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
6691 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6692 &descriptorSet, 0, NULL);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006693
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006694 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06006695
Chia-I Wuf7458c52015-10-26 21:10:41 +08006696 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6697 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6698 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006699}
6700
Karl Schultz6addd812016-02-02 17:17:23 -07006701TEST_F(VkLayerTest, InvalidBufferViewObject) {
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006702 // Create a single TEXEL_BUFFER descriptor and send it an invalid bufferView
Karl Schultz6addd812016-02-02 17:17:23 -07006703 VkResult err;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006704
Karl Schultzf78bcdd2016-11-30 12:36:01 -07006705 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00940);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006706
Tony Barbour1fa09702017-03-16 12:09:08 -06006707 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006708 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006709 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
6710 ds_type_count.descriptorCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006711
6712 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006713 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6714 ds_pool_ci.pNext = NULL;
6715 ds_pool_ci.maxSets = 1;
6716 ds_pool_ci.poolSizeCount = 1;
6717 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006718
6719 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006720 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006721 ASSERT_VK_SUCCESS(err);
6722
6723 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006724 dsl_binding.binding = 0;
6725 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
6726 dsl_binding.descriptorCount = 1;
6727 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6728 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006729
6730 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006731 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6732 ds_layout_ci.pNext = NULL;
6733 ds_layout_ci.bindingCount = 1;
6734 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006735 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006736 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006737 ASSERT_VK_SUCCESS(err);
6738
6739 VkDescriptorSet descriptorSet;
6740 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006741 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006742 alloc_info.descriptorSetCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006743 alloc_info.descriptorPool = ds_pool;
6744 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006745 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006746 ASSERT_VK_SUCCESS(err);
6747
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006748 VkBufferView view = (VkBufferView)((size_t)0xbaadbeef); // invalid bufferView object
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006749 VkWriteDescriptorSet descriptor_write;
6750 memset(&descriptor_write, 0, sizeof(descriptor_write));
6751 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6752 descriptor_write.dstSet = descriptorSet;
6753 descriptor_write.dstBinding = 0;
6754 descriptor_write.descriptorCount = 1;
6755 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
6756 descriptor_write.pTexelBufferView = &view;
6757
6758 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6759
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006760 m_errorMonitor->VerifyFound();
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006761
6762 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6763 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6764}
6765
Mark Youngd339ba32016-05-30 13:28:35 -06006766TEST_F(VkLayerTest, CreateBufferViewNoMemoryBoundToBuffer) {
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006767 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 -06006768
6769 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06006770 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006771 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -06006772
Tony Barbour1fa09702017-03-16 12:09:08 -06006773 ASSERT_NO_FATAL_FAILURE(Init());
Mark Youngd339ba32016-05-30 13:28:35 -06006774
6775 // Create a buffer with no bound memory and then attempt to create
6776 // a buffer view.
6777 VkBufferCreateInfo buff_ci = {};
6778 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes4538d242016-09-13 18:13:58 +12006779 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -06006780 buff_ci.size = 256;
6781 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
6782 VkBuffer buffer;
6783 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
6784 ASSERT_VK_SUCCESS(err);
6785
6786 VkBufferViewCreateInfo buff_view_ci = {};
6787 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
6788 buff_view_ci.buffer = buffer;
6789 buff_view_ci.format = VK_FORMAT_R8_UNORM;
6790 buff_view_ci.range = VK_WHOLE_SIZE;
6791 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006792 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Mark Youngd339ba32016-05-30 13:28:35 -06006793
6794 m_errorMonitor->VerifyFound();
6795 vkDestroyBuffer(m_device->device(), buffer, NULL);
6796 // If last error is success, it still created the view, so delete it.
6797 if (err == VK_SUCCESS) {
6798 vkDestroyBufferView(m_device->device(), buff_view, NULL);
6799 }
6800}
6801
Karl Schultz6addd812016-02-02 17:17:23 -07006802TEST_F(VkLayerTest, InvalidDynamicOffsetCases) {
6803 // Create a descriptorSet w/ dynamic descriptor and then hit 3 offset error
6804 // cases:
Tobin Ehlisf6585052015-12-17 11:48:42 -07006805 // 1. No dynamicOffset supplied
6806 // 2. Too many dynamicOffsets supplied
6807 // 3. Dynamic offset oversteps buffer being updated
Karl Schultz6addd812016-02-02 17:17:23 -07006808 VkResult err;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006809 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6810 " requires 1 dynamicOffsets, but only "
6811 "0 dynamicOffsets are left in "
6812 "pDynamicOffsets ");
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006813
Tony Barbour1fa09702017-03-16 12:09:08 -06006814 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006815 ASSERT_NO_FATAL_FAILURE(InitViewport());
6816 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6817
6818 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006819 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6820 ds_type_count.descriptorCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006821
6822 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006823 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6824 ds_pool_ci.pNext = NULL;
6825 ds_pool_ci.maxSets = 1;
6826 ds_pool_ci.poolSizeCount = 1;
6827 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006828
6829 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006830 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006831 ASSERT_VK_SUCCESS(err);
6832
6833 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006834 dsl_binding.binding = 0;
6835 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6836 dsl_binding.descriptorCount = 1;
6837 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6838 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006839
6840 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006841 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6842 ds_layout_ci.pNext = NULL;
6843 ds_layout_ci.bindingCount = 1;
6844 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006845 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006846 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006847 ASSERT_VK_SUCCESS(err);
6848
6849 VkDescriptorSet descriptorSet;
6850 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006851 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006852 alloc_info.descriptorSetCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006853 alloc_info.descriptorPool = ds_pool;
6854 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006855 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006856 ASSERT_VK_SUCCESS(err);
6857
6858 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006859 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6860 pipeline_layout_ci.pNext = NULL;
6861 pipeline_layout_ci.setLayoutCount = 1;
6862 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006863
6864 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006865 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006866 ASSERT_VK_SUCCESS(err);
6867
6868 // Create a buffer to update the descriptor with
6869 uint32_t qfi = 0;
6870 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006871 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6872 buffCI.size = 1024;
6873 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6874 buffCI.queueFamilyIndexCount = 1;
6875 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006876
6877 VkBuffer dyub;
6878 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6879 ASSERT_VK_SUCCESS(err);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006880 // Allocate memory and bind to buffer so we can make it to the appropriate
6881 // error
6882 VkMemoryAllocateInfo mem_alloc = {};
6883 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6884 mem_alloc.pNext = NULL;
6885 mem_alloc.allocationSize = 1024;
Chris Forbesb6116cc2016-05-08 11:39:59 +12006886 mem_alloc.memoryTypeIndex = 0;
6887
6888 VkMemoryRequirements memReqs;
6889 vkGetBufferMemoryRequirements(m_device->device(), dyub, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006890 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Chris Forbesb6116cc2016-05-08 11:39:59 +12006891 if (!pass) {
6892 vkDestroyBuffer(m_device->device(), dyub, NULL);
6893 return;
6894 }
6895
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006896 VkDeviceMemory mem;
6897 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
6898 ASSERT_VK_SUCCESS(err);
6899 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
6900 ASSERT_VK_SUCCESS(err);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006901 // Correctly update descriptor to avoid "NOT_UPDATED" error
6902 VkDescriptorBufferInfo buffInfo = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006903 buffInfo.buffer = dyub;
6904 buffInfo.offset = 0;
6905 buffInfo.range = 1024;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006906
6907 VkWriteDescriptorSet descriptor_write;
6908 memset(&descriptor_write, 0, sizeof(descriptor_write));
6909 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6910 descriptor_write.dstSet = descriptorSet;
6911 descriptor_write.dstBinding = 0;
6912 descriptor_write.descriptorCount = 1;
6913 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6914 descriptor_write.pBufferInfo = &buffInfo;
6915
6916 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6917
Tony Barbour552f6c02016-12-21 14:34:07 -07006918 m_commandBuffer->BeginCommandBuffer();
6919 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006920 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6921 &descriptorSet, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006922 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07006923 uint32_t pDynOff[2] = {512, 756};
6924 // Now cause error b/c too many dynOffsets in array for # of dyn descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006925 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6926 "Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but ");
6927 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6928 &descriptorSet, 2, pDynOff);
Chris Forbes7b342802016-04-07 13:20:10 +12006929 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07006930 // Finally cause error due to dynamicOffset being too big
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006931 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6932 " dynamic offset 512 combined with "
6933 "offset 0 and range 1024 that "
6934 "oversteps the buffer size of 1024");
Tobin Ehlisf6585052015-12-17 11:48:42 -07006935 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006936 char const *vsSource =
6937 "#version 450\n"
6938 "\n"
6939 "out gl_PerVertex { \n"
6940 " vec4 gl_Position;\n"
6941 "};\n"
6942 "void main(){\n"
6943 " gl_Position = vec4(1);\n"
6944 "}\n";
6945 char const *fsSource =
6946 "#version 450\n"
6947 "\n"
6948 "layout(location=0) out vec4 x;\n"
6949 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
6950 "void main(){\n"
6951 " x = vec4(bar.y);\n"
6952 "}\n";
Tobin Ehlisf6585052015-12-17 11:48:42 -07006953 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6954 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
6955 VkPipelineObj pipe(m_device);
6956 pipe.AddShader(&vs);
6957 pipe.AddShader(&fs);
6958 pipe.AddColorAttachment();
6959 pipe.CreateVKPipeline(pipeline_layout, renderPass());
6960
Rene Lindsayacbf5e62016-12-15 18:47:11 -07006961 VkViewport viewport = {0, 0, 16, 16, 0, 1};
6962 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
6963 VkRect2D scissor = {{0, 0}, {16, 16}};
6964 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
6965
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006966 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07006967 // This update should succeed, but offset size of 512 will overstep buffer
6968 // /w range 1024 & size 1024
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006969 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6970 &descriptorSet, 1, pDynOff);
Tobin Ehlisf6585052015-12-17 11:48:42 -07006971 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006972 m_errorMonitor->VerifyFound();
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006973
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006974 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis512098e2016-05-05 09:06:12 -06006975 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006976
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006977 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06006978 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006979 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6980}
6981
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006982TEST_F(VkLayerTest, DescriptorBufferUpdateNoMemoryBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006983 TEST_DESCRIPTION(
6984 "Attempt to update a descriptor with a non-sparse buffer "
6985 "that doesn't have memory bound");
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006986 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06006987 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006988 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Tobin Ehlisfed999f2016-09-21 15:09:45 -06006989 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6990 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006991
Tony Barbour1fa09702017-03-16 12:09:08 -06006992 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006993 ASSERT_NO_FATAL_FAILURE(InitViewport());
6994 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6995
6996 VkDescriptorPoolSize ds_type_count = {};
6997 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6998 ds_type_count.descriptorCount = 1;
6999
7000 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7001 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7002 ds_pool_ci.pNext = NULL;
7003 ds_pool_ci.maxSets = 1;
7004 ds_pool_ci.poolSizeCount = 1;
7005 ds_pool_ci.pPoolSizes = &ds_type_count;
7006
7007 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007008 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06007009 ASSERT_VK_SUCCESS(err);
7010
7011 VkDescriptorSetLayoutBinding dsl_binding = {};
7012 dsl_binding.binding = 0;
7013 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
7014 dsl_binding.descriptorCount = 1;
7015 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7016 dsl_binding.pImmutableSamplers = NULL;
7017
7018 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7019 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7020 ds_layout_ci.pNext = NULL;
7021 ds_layout_ci.bindingCount = 1;
7022 ds_layout_ci.pBindings = &dsl_binding;
7023 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007024 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06007025 ASSERT_VK_SUCCESS(err);
7026
7027 VkDescriptorSet descriptorSet;
7028 VkDescriptorSetAllocateInfo alloc_info = {};
7029 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7030 alloc_info.descriptorSetCount = 1;
7031 alloc_info.descriptorPool = ds_pool;
7032 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007033 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06007034 ASSERT_VK_SUCCESS(err);
7035
7036 // Create a buffer to update the descriptor with
7037 uint32_t qfi = 0;
7038 VkBufferCreateInfo buffCI = {};
7039 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
7040 buffCI.size = 1024;
7041 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
7042 buffCI.queueFamilyIndexCount = 1;
7043 buffCI.pQueueFamilyIndices = &qfi;
7044
7045 VkBuffer dyub;
7046 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
7047 ASSERT_VK_SUCCESS(err);
7048
7049 // Attempt to update descriptor without binding memory to it
7050 VkDescriptorBufferInfo buffInfo = {};
7051 buffInfo.buffer = dyub;
7052 buffInfo.offset = 0;
7053 buffInfo.range = 1024;
7054
7055 VkWriteDescriptorSet descriptor_write;
7056 memset(&descriptor_write, 0, sizeof(descriptor_write));
7057 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
7058 descriptor_write.dstSet = descriptorSet;
7059 descriptor_write.dstBinding = 0;
7060 descriptor_write.descriptorCount = 1;
7061 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
7062 descriptor_write.pBufferInfo = &buffInfo;
7063
7064 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
7065 m_errorMonitor->VerifyFound();
7066
7067 vkDestroyBuffer(m_device->device(), dyub, NULL);
7068 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7069 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
7070}
7071
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07007072TEST_F(VkLayerTest, InvalidPushConstants) {
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07007073 VkResult err;
Tony Barbour1fa09702017-03-16 12:09:08 -06007074 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07007075 ASSERT_NO_FATAL_FAILURE(InitViewport());
7076 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7077
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007078 VkPipelineLayout pipeline_layout;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07007079 VkPushConstantRange pc_range = {};
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07007080 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7081 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7082 pipeline_layout_ci.pushConstantRangeCount = 1;
7083 pipeline_layout_ci.pPushConstantRanges = &pc_range;
7084
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007085 //
7086 // Check for invalid push constant ranges in pipeline layouts.
7087 //
7088 struct PipelineLayoutTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06007089 VkPushConstantRange const range;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007090 char const *msg;
7091 };
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07007092
Karl Schultzc81037d2016-05-12 08:11:23 -06007093 const uint32_t too_big = m_device->props.limits.maxPushConstantsSize + 0x4;
7094 const std::array<PipelineLayoutTestCase, 10> range_tests = {{
7095 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0},
7096 "vkCreatePipelineLayout() call has push constants index 0 with "
7097 "size 0."},
7098 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
7099 "vkCreatePipelineLayout() call has push constants index 0 with "
7100 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06007101 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Karl Schultzc81037d2016-05-12 08:11:23 -06007102 "vkCreatePipelineLayout() call has push constants index 0 with "
7103 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06007104 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 0},
Karl Schultzc81037d2016-05-12 08:11:23 -06007105 "vkCreatePipelineLayout() call has push constants index 0 with "
7106 "size 0."},
7107 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
7108 "vkCreatePipelineLayout() call has push constants index 0 with "
7109 "offset 1. Offset must"},
7110 {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big},
7111 "vkCreatePipelineLayout() call has push constants index 0 "
7112 "with offset "},
7113 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big},
7114 "vkCreatePipelineLayout() call has push constants "
7115 "index 0 with offset "},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06007116 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06007117 "vkCreatePipelineLayout() call has push constants index 0 "
7118 "with offset "},
7119 {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020},
7120 "vkCreatePipelineLayout() call has push "
7121 "constants index 0 with offset "},
7122 {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0},
7123 "vkCreatePipelineLayout() call has push "
7124 "constants index 0 with offset "},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007125 }};
7126
7127 // Check for invalid offset and size
Karl Schultzc81037d2016-05-12 08:11:23 -06007128 for (const auto &iter : range_tests) {
7129 pc_range = iter.range;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007130 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
7131 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007132 m_errorMonitor->VerifyFound();
7133 if (VK_SUCCESS == err) {
7134 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7135 }
7136 }
7137
7138 // Check for invalid stage flag
7139 pc_range.offset = 0;
7140 pc_range.size = 16;
7141 pc_range.stageFlags = 0;
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06007142 m_errorMonitor->SetDesiredFailureMsg(
7143 VK_DEBUG_REPORT_ERROR_BIT_EXT,
7144 "vkCreatePipelineLayout: value of pCreateInfo->pPushConstantRanges[0].stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007145 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007146 m_errorMonitor->VerifyFound();
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007147 if (VK_SUCCESS == err) {
7148 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7149 }
7150
Karl Schultzc59b72d2017-02-24 15:45:05 -07007151 // Check for duplicate stage flags in a list of push constant ranges.
7152 // A shader can only have one push constant block and that block is mapped
7153 // to the push constant range that has that shader's stage flag set.
7154 // The shader's stage flag can only appear once in all the ranges, so the
7155 // implementation can find the one and only range to map it to.
Karl Schultzc81037d2016-05-12 08:11:23 -06007156 const uint32_t ranges_per_test = 5;
Karl Schultzc59b72d2017-02-24 15:45:05 -07007157 struct DuplicateStageFlagsTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06007158 VkPushConstantRange const ranges[ranges_per_test];
Jeremy Hayesde6d96c2017-02-01 15:22:32 -07007159 std::vector<char const *> const msg;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007160 };
Karl Schultzc59b72d2017-02-24 15:45:05 -07007161 // Overlapping ranges are OK, but a stage flag can appear only once.
7162 const std::array<DuplicateStageFlagsTestCase, 3> duplicate_stageFlags_tests = {
7163 {
7164 {{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
7165 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
7166 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
7167 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007168 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzc59b72d2017-02-24 15:45:05 -07007169 {
7170 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 0 and 1.",
7171 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 0 and 2.",
7172 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 0 and 3.",
7173 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 0 and 4.",
7174 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 1 and 2.",
7175 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 1 and 3.",
7176 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 1 and 4.",
7177 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 2 and 3.",
7178 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 2 and 4.",
7179 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 3 and 4.",
7180 }},
7181 {{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
7182 {VK_SHADER_STAGE_GEOMETRY_BIT, 0, 4},
7183 {VK_SHADER_STAGE_FRAGMENT_BIT, 0, 4},
7184 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
7185 {VK_SHADER_STAGE_GEOMETRY_BIT, 0, 4}},
7186 {
7187 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 0 and 3.",
7188 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 1 and 4.",
7189 }},
7190 {{{VK_SHADER_STAGE_FRAGMENT_BIT, 0, 4},
7191 {VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 4},
7192 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
7193 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
7194 {VK_SHADER_STAGE_GEOMETRY_BIT, 0, 4}},
7195 {
7196 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 2 and 3.",
7197 }},
7198 },
7199 };
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007200
Karl Schultzc59b72d2017-02-24 15:45:05 -07007201 for (const auto &iter : duplicate_stageFlags_tests) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007202 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
Karl Schultzc81037d2016-05-12 08:11:23 -06007203 pipeline_layout_ci.pushConstantRangeCount = ranges_per_test;
Karl Schultzc59b72d2017-02-24 15:45:05 -07007204 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg.begin(), iter.msg.end());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007205 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007206 m_errorMonitor->VerifyFound();
7207 if (VK_SUCCESS == err) {
7208 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7209 }
7210 }
7211
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007212 //
7213 // CmdPushConstants tests
7214 //
7215
Karl Schultzc59b72d2017-02-24 15:45:05 -07007216 // Setup a pipeline layout with ranges: [0,16) [64,80)
Karl Schultzc81037d2016-05-12 08:11:23 -06007217 const VkPushConstantRange pc_range2[] = {
Karl Schultzc59b72d2017-02-24 15:45:05 -07007218 {VK_SHADER_STAGE_VERTEX_BIT, 64, 16}, {VK_SHADER_STAGE_FRAGMENT_BIT, 0, 16},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007219 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007220 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range2) / sizeof(VkPushConstantRange);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007221 pipeline_layout_ci.pPushConstantRanges = pc_range2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007222 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07007223 ASSERT_VK_SUCCESS(err);
Karl Schultzc59b72d2017-02-24 15:45:05 -07007224
7225 const uint8_t dummy_values[100] = {};
7226
7227 m_commandBuffer->BeginCommandBuffer();
7228 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007229
7230 // Check for invalid stage flag
Karl Schultzc59b72d2017-02-24 15:45:05 -07007231 // Note that VU 00996 isn't reached due to parameter validation
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06007232 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdPushConstants: value of stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007233 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, 0, 0, 16, dummy_values);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007234 m_errorMonitor->VerifyFound();
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007235
Karl Schultzc59b72d2017-02-24 15:45:05 -07007236 m_errorMonitor->ExpectSuccess();
7237 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, VK_SHADER_STAGE_FRAGMENT_BIT, 0, 16, dummy_values);
7238 m_errorMonitor->VerifyNotFound();
7239 m_errorMonitor->ExpectSuccess();
7240 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, VK_SHADER_STAGE_VERTEX_BIT, 64, 16, dummy_values);
7241 m_errorMonitor->VerifyNotFound();
7242 const std::array<VkPushConstantRange, 6> cmd_range_tests = {{
7243 {VK_SHADER_STAGE_FRAGMENT_BIT, 64, 16},
7244 {VK_SHADER_STAGE_VERTEX_BIT, 0, 16},
7245 {VK_SHADER_STAGE_GEOMETRY_BIT, 0, 16},
7246 {VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT, 0, 16},
7247 {VK_SHADER_STAGE_VERTEX_BIT, 24, 16},
7248 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06007249 }};
Karl Schultzc59b72d2017-02-24 15:45:05 -07007250 for (const auto &iter : cmd_range_tests) {
7251 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00988);
7252 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.stageFlags, iter.offset, iter.size,
7253 dummy_values);
Karl Schultzc81037d2016-05-12 08:11:23 -06007254 m_errorMonitor->VerifyFound();
7255 }
Karl Schultzc81037d2016-05-12 08:11:23 -06007256
Tony Barbour552f6c02016-12-21 14:34:07 -07007257 m_commandBuffer->EndRenderPass();
7258 m_commandBuffer->EndCommandBuffer();
Karl Schultzc59b72d2017-02-24 15:45:05 -07007259 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07007260}
7261
Karl Schultz6addd812016-02-02 17:17:23 -07007262TEST_F(VkLayerTest, DescriptorSetCompatibility) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07007263 // Test various desriptorSet errors with bad binding combinations
Karl Schultz6addd812016-02-02 17:17:23 -07007264 VkResult err;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007265
Tony Barbour1fa09702017-03-16 12:09:08 -06007266 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis559c6382015-11-05 09:52:49 -07007267 ASSERT_NO_FATAL_FAILURE(InitViewport());
7268 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7269
7270 static const uint32_t NUM_DESCRIPTOR_TYPES = 5;
7271 VkDescriptorPoolSize ds_type_count[NUM_DESCRIPTOR_TYPES] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007272 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7273 ds_type_count[0].descriptorCount = 10;
7274 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
7275 ds_type_count[1].descriptorCount = 2;
7276 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
7277 ds_type_count[2].descriptorCount = 2;
7278 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_SAMPLER;
7279 ds_type_count[3].descriptorCount = 5;
7280 // TODO : LunarG ILO driver currently asserts in desc.c w/ INPUT_ATTACHMENT
7281 // type
7282 // ds_type_count[4].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
7283 ds_type_count[4].type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
7284 ds_type_count[4].descriptorCount = 2;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007285
7286 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007287 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7288 ds_pool_ci.pNext = NULL;
7289 ds_pool_ci.maxSets = 5;
7290 ds_pool_ci.poolSizeCount = NUM_DESCRIPTOR_TYPES;
7291 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007292
7293 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007294 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007295 ASSERT_VK_SUCCESS(err);
7296
7297 static const uint32_t MAX_DS_TYPES_IN_LAYOUT = 2;
7298 VkDescriptorSetLayoutBinding dsl_binding[MAX_DS_TYPES_IN_LAYOUT] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007299 dsl_binding[0].binding = 0;
7300 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7301 dsl_binding[0].descriptorCount = 5;
7302 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
7303 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007304
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007305 // Create layout identical to set0 layout but w/ different stageFlags
7306 VkDescriptorSetLayoutBinding dsl_fs_stage_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007307 dsl_fs_stage_only.binding = 0;
7308 dsl_fs_stage_only.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7309 dsl_fs_stage_only.descriptorCount = 5;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007310 dsl_fs_stage_only.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; // Different stageFlags to cause error at
7311 // bind time
Karl Schultz6addd812016-02-02 17:17:23 -07007312 dsl_fs_stage_only.pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007313 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007314 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7315 ds_layout_ci.pNext = NULL;
7316 ds_layout_ci.bindingCount = 1;
7317 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007318 static const uint32_t NUM_LAYOUTS = 4;
7319 VkDescriptorSetLayout ds_layout[NUM_LAYOUTS] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007320 VkDescriptorSetLayout ds_layout_fs_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007321 // Create 4 unique layouts for full pipelineLayout, and 1 special fs-only
7322 // layout for error case
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007323 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[0]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007324 ASSERT_VK_SUCCESS(err);
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07007325 ds_layout_ci.pBindings = &dsl_fs_stage_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007326 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007327 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007328 dsl_binding[0].binding = 0;
7329 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007330 dsl_binding[0].descriptorCount = 2;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07007331 dsl_binding[1].binding = 1;
7332 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
7333 dsl_binding[1].descriptorCount = 2;
7334 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
7335 dsl_binding[1].pImmutableSamplers = NULL;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07007336 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007337 ds_layout_ci.bindingCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007338 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[1]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007339 ASSERT_VK_SUCCESS(err);
7340 dsl_binding[0].binding = 0;
7341 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007342 dsl_binding[0].descriptorCount = 5;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007343 ds_layout_ci.bindingCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007344 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[2]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007345 ASSERT_VK_SUCCESS(err);
7346 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007347 dsl_binding[0].descriptorCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007348 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[3]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007349 ASSERT_VK_SUCCESS(err);
7350
7351 static const uint32_t NUM_SETS = 4;
7352 VkDescriptorSet descriptorSet[NUM_SETS] = {};
7353 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007354 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007355 alloc_info.descriptorSetCount = NUM_LAYOUTS;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007356 alloc_info.descriptorPool = ds_pool;
7357 alloc_info.pSetLayouts = ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007358 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptorSet);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007359 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007360 VkDescriptorSet ds0_fs_only = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07007361 alloc_info.descriptorSetCount = 1;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007362 alloc_info.pSetLayouts = &ds_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007363 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &ds0_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007364 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007365
7366 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007367 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7368 pipeline_layout_ci.pNext = NULL;
7369 pipeline_layout_ci.setLayoutCount = NUM_LAYOUTS;
7370 pipeline_layout_ci.pSetLayouts = ds_layout;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007371
7372 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007373 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007374 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007375 // Create pipelineLayout with only one setLayout
7376 pipeline_layout_ci.setLayoutCount = 1;
7377 VkPipelineLayout single_pipe_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007378 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &single_pipe_layout);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007379 ASSERT_VK_SUCCESS(err);
7380 // Create pipelineLayout with 2 descriptor setLayout at index 0
7381 pipeline_layout_ci.pSetLayouts = &ds_layout[3];
7382 VkPipelineLayout pipe_layout_one_desc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007383 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_one_desc);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007384 ASSERT_VK_SUCCESS(err);
7385 // Create pipelineLayout with 5 SAMPLER descriptor setLayout at index 0
7386 pipeline_layout_ci.pSetLayouts = &ds_layout[2];
7387 VkPipelineLayout pipe_layout_five_samp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007388 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_five_samp);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007389 ASSERT_VK_SUCCESS(err);
7390 // Create pipelineLayout with UB type, but stageFlags for FS only
7391 pipeline_layout_ci.pSetLayouts = &ds_layout_fs_only;
7392 VkPipelineLayout pipe_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007393 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007394 ASSERT_VK_SUCCESS(err);
7395 // Create pipelineLayout w/ incompatible set0 layout, but set1 is fine
7396 VkDescriptorSetLayout pl_bad_s0[2] = {};
7397 pl_bad_s0[0] = ds_layout_fs_only;
7398 pl_bad_s0[1] = ds_layout[1];
7399 pipeline_layout_ci.setLayoutCount = 2;
7400 pipeline_layout_ci.pSetLayouts = pl_bad_s0;
7401 VkPipelineLayout pipe_layout_bad_set0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007402 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_bad_set0);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007403 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007404
Tobin Ehlis88452832015-12-03 09:40:56 -07007405 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007406 char const *vsSource =
7407 "#version 450\n"
7408 "\n"
7409 "out gl_PerVertex {\n"
7410 " vec4 gl_Position;\n"
7411 "};\n"
7412 "void main(){\n"
7413 " gl_Position = vec4(1);\n"
7414 "}\n";
7415 char const *fsSource =
7416 "#version 450\n"
7417 "\n"
7418 "layout(location=0) out vec4 x;\n"
7419 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
7420 "void main(){\n"
7421 " x = vec4(bar.y);\n"
7422 "}\n";
Tobin Ehlis88452832015-12-03 09:40:56 -07007423 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
7424 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007425 VkPipelineObj pipe(m_device);
7426 pipe.AddShader(&vs);
7427 pipe.AddShader(&fs);
Tobin Ehlis88452832015-12-03 09:40:56 -07007428 pipe.AddColorAttachment();
7429 pipe.CreateVKPipeline(pipe_layout_fs_only, renderPass());
Tobin Ehlis559c6382015-11-05 09:52:49 -07007430
Tony Barbour552f6c02016-12-21 14:34:07 -07007431 m_commandBuffer->BeginCommandBuffer();
7432 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis88452832015-12-03 09:40:56 -07007433
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007434 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07007435 // NOTE : I believe LunarG ilo driver has bug (LX#189) that requires binding
7436 // of PSO
7437 // here before binding DSs. Otherwise we assert in cmd_copy_dset_data() of
7438 // cmd_pipeline.c
7439 // due to the fact that cmd_alloc_dset_data() has not been called in
7440 // cmd_bind_graphics_pipeline()
7441 // TODO : Want to cause various binding incompatibility issues here to test
7442 // DrawState
Tobin Ehlis559c6382015-11-05 09:52:49 -07007443 // First cause various verify_layout_compatibility() fails
7444 // Second disturb early and late sets and verify INFO msgs
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007445 // verify_set_layout_compatibility fail cases:
7446 // 1. invalid VkPipelineLayout (layout) passed into vkCmdBindDescriptorSets
Karl Schultzf78bcdd2016-11-30 12:36:01 -07007447 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00981);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007448 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
7449 (VkPipelineLayout)((size_t)0xbaadb1be), 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007450 m_errorMonitor->VerifyFound();
7451
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007452 // 2. layoutIndex exceeds # of layouts in layout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007453 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempting to bind set to index 1");
7454 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, single_pipe_layout, 0, 2,
7455 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007456 m_errorMonitor->VerifyFound();
7457
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007458 vkDestroyPipelineLayout(m_device->device(), single_pipe_layout, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07007459 // 3. Pipeline setLayout[0] has 2 descriptors, but set being bound has 5
7460 // descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007461 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has 2 descriptors, but DescriptorSetLayout ");
7462 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_one_desc, 0, 1,
7463 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007464 m_errorMonitor->VerifyFound();
7465
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007466 vkDestroyPipelineLayout(m_device->device(), pipe_layout_one_desc, NULL);
7467 // 4. same # of descriptors but mismatch in type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007468 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is type 'VK_DESCRIPTOR_TYPE_SAMPLER' but binding ");
7469 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_five_samp, 0, 1,
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(), pipe_layout_five_samp, NULL);
7474 // 5. same # of descriptors but mismatch in stageFlags
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007475 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7476 " has stageFlags 16 but binding 0 for DescriptorSetLayout ");
7477 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 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 // Cause INFO messages due to disturbing previously bound Sets
7482 // First bind sets 0 & 1
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007483 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
7484 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007485 // 1. Disturb bound set0 by re-binding set1 w/ updated pipelineLayout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007486 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " previously bound as set #0 was disturbed ");
7487 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
7488 &descriptorSet[1], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007489 m_errorMonitor->VerifyFound();
7490
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007491 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
7492 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007493 // 2. Disturb set after last bound set
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007494 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
7495 " newly bound as set #0 so set #1 and "
7496 "any subsequent sets were disturbed ");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007497 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
7498 &ds0_fs_only, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007499 m_errorMonitor->VerifyFound();
7500
Tobin Ehlis10fad692016-07-07 12:00:36 -06007501 // Now that we're done actively using the pipelineLayout that gfx pipeline
7502 // was created with, we should be able to delete it. Do that now to verify
7503 // that validation obeys pipelineLayout lifetime
7504 vkDestroyPipelineLayout(m_device->device(), pipe_layout_fs_only, NULL);
7505
Tobin Ehlis88452832015-12-03 09:40:56 -07007506 // Cause draw-time errors due to PSO incompatibilities
Karl Schultz6addd812016-02-02 17:17:23 -07007507 // 1. Error due to not binding required set (we actually use same code as
7508 // above to disturb set0)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007509 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
7510 &descriptorSet[0], 0, NULL);
7511 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
7512 &descriptorSet[1], 0, NULL);
7513 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 -07007514
7515 VkViewport viewport = {0, 0, 16, 16, 0, 1};
7516 VkRect2D scissor = {{0, 0}, {16, 16}};
7517 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
7518 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
7519
Tobin Ehlis88452832015-12-03 09:40:56 -07007520 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007521 m_errorMonitor->VerifyFound();
7522
Tobin Ehlis991d45a2016-01-06 08:48:41 -07007523 vkDestroyPipelineLayout(m_device->device(), pipe_layout_bad_set0, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07007524 // 2. Error due to bound set not being compatible with PSO's
7525 // VkPipelineLayout (diff stageFlags in this case)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007526 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
7527 &descriptorSet[0], 0, NULL);
7528 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " bound as set #0 is not compatible with ");
Tobin Ehlis88452832015-12-03 09:40:56 -07007529 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007530 m_errorMonitor->VerifyFound();
7531
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007532 // Remaining clean-up
Karl Schultz6addd812016-02-02 17:17:23 -07007533 for (uint32_t i = 0; i < NUM_LAYOUTS; ++i) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007534 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout[i], NULL);
7535 }
7536 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_fs_only, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007537 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7538 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
7539}
Tobin Ehlis559c6382015-11-05 09:52:49 -07007540
Karl Schultz6addd812016-02-02 17:17:23 -07007541TEST_F(VkLayerTest, NoBeginCommandBuffer) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007542 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7543 "You must call vkBeginCommandBuffer() before this call to ");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007544
Tony Barbour1fa09702017-03-16 12:09:08 -06007545 ASSERT_NO_FATAL_FAILURE(Init());
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007546 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007547 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007548 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007549
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007550 m_errorMonitor->VerifyFound();
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007551}
7552
Karl Schultz6addd812016-02-02 17:17:23 -07007553TEST_F(VkLayerTest, SecondaryCommandBufferNullRenderpass) {
7554 VkResult err;
7555 VkCommandBuffer draw_cmd;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007556
Karl Schultzf78bcdd2016-11-30 12:36:01 -07007557 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00110);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007558
Tony Barbour1fa09702017-03-16 12:09:08 -06007559 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06007560
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007561 VkCommandBufferAllocateInfo cmd = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007562 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06007563 cmd.pNext = NULL;
Mike Schuchardt06304c22017-03-01 17:09:09 -07007564 cmd.commandPool = m_commandPool->handle();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007565 cmd.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007566 cmd.commandBufferCount = 1;
Cody Northropb4569702015-08-04 17:35:57 -06007567
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007568 err = vkAllocateCommandBuffers(m_device->device(), &cmd, &draw_cmd);
Mike Stroyand1c84a52015-08-18 14:40:24 -06007569 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06007570
7571 // Force the failure by not setting the Renderpass and Framebuffer fields
Jon Ashburnf19916e2016-01-11 13:12:43 -07007572 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Rene Lindsay65072a92017-01-23 11:38:10 -07007573 cmd_buf_hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
7574
7575 VkCommandBufferBeginInfo cmd_buf_info = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007576 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06007577 cmd_buf_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007578 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 -07007579 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06007580
7581 // The error should be caught by validation of the BeginCommandBuffer call
7582 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
7583
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007584 m_errorMonitor->VerifyFound();
Mike Schuchardt06304c22017-03-01 17:09:09 -07007585 vkFreeCommandBuffers(m_device->device(), m_commandPool->handle(), 1, &draw_cmd);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06007586}
7587
Chris Forbes5b3725e2017-05-18 16:01:20 -07007588TEST_F(VkLayerTest, SecondaryCommandBufferRerecordedExplicitReset) {
Chris Forbes9480ae92017-05-17 17:14:34 -07007589 ASSERT_NO_FATAL_FAILURE(Init());
7590
Chris Forbes5b3725e2017-05-18 16:01:20 -07007591 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was destroyed or rerecorded");
Chris Forbes9480ae92017-05-17 17:14:34 -07007592
7593 // A pool we can reset in.
7594 VkCommandPoolObj pool(m_device, m_device->graphics_queue_node_index_,
7595 VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT);
7596 VkCommandBufferObj secondary(m_device, &pool,
7597 VK_COMMAND_BUFFER_LEVEL_SECONDARY);
7598
7599 secondary.begin();
7600 secondary.end();
7601
7602 m_commandBuffer->begin();
7603 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary.handle());
7604
7605 // rerecording of secondary
Chris Forbes5b3725e2017-05-18 16:01:20 -07007606 secondary.reset(); // explicit reset here.
Chris Forbes9480ae92017-05-17 17:14:34 -07007607 secondary.begin();
7608 secondary.end();
7609
7610 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary.handle());
Chris Forbes5b3725e2017-05-18 16:01:20 -07007611 m_errorMonitor->VerifyFound();
7612}
Chris Forbes9480ae92017-05-17 17:14:34 -07007613
Chris Forbes5b3725e2017-05-18 16:01:20 -07007614TEST_F(VkLayerTest, SecondaryCommandBufferRerecordedNoReset) {
7615 ASSERT_NO_FATAL_FAILURE(Init());
7616
7617 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was destroyed or rerecorded");
7618
7619 // A pool we can reset in.
7620 VkCommandPoolObj pool(m_device, m_device->graphics_queue_node_index_,
7621 VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT);
7622 VkCommandBufferObj secondary(m_device, &pool,
7623 VK_COMMAND_BUFFER_LEVEL_SECONDARY);
7624
7625 secondary.begin();
7626 secondary.end();
7627
7628 m_commandBuffer->begin();
7629 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary.handle());
7630
7631 // rerecording of secondary
7632 secondary.begin(); // implicit reset in begin
7633 secondary.end();
7634
7635 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary.handle());
Chris Forbes9480ae92017-05-17 17:14:34 -07007636 m_errorMonitor->VerifyFound();
7637}
7638
Chris Forbes42bbfe22017-05-18 16:20:53 -07007639TEST_F(VkLayerTest, CascadedInvalidation) {
7640 ASSERT_NO_FATAL_FAILURE(Init());
7641
7642 VkEventCreateInfo eci = { VK_STRUCTURE_TYPE_EVENT_CREATE_INFO, nullptr, 0 };
7643 VkEvent event;
7644 vkCreateEvent(m_device->device(), &eci, nullptr, &event);
7645
7646 VkCommandBufferObj secondary(m_device, m_commandPool, VK_COMMAND_BUFFER_LEVEL_SECONDARY);
7647 secondary.begin();
7648 vkCmdSetEvent(secondary.handle(), event, VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT);
7649 secondary.end();
7650
7651 m_commandBuffer->begin();
7652 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary.handle());
7653 m_commandBuffer->end();
7654
7655 // destroying the event should invalidate both primary and secondary CB
7656 vkDestroyEvent(m_device->device(), event, nullptr);
7657
7658 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "invalid because bound Event");
7659 m_commandBuffer->QueueCommandBuffer(false);
7660 m_errorMonitor->VerifyFound();
7661}
7662
Karl Schultz6addd812016-02-02 17:17:23 -07007663TEST_F(VkLayerTest, CommandBufferResetErrors) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007664 // Cause error due to Begin while recording CB
7665 // Then cause 2 errors for attempting to reset CB w/o having
7666 // VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT set for the pool from
7667 // which CBs were allocated. Note that this bit is off by default.
Mike Weiblencce7ec72016-10-17 19:33:05 -06007668 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call Begin on command buffer");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007669
Tony Barbour1fa09702017-03-16 12:09:08 -06007670 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007671
7672 // Calls AllocateCommandBuffers
7673 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
7674
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07007675 // Force the failure by setting the Renderpass and Framebuffer fields with (fake) data
Jon Ashburnf19916e2016-01-11 13:12:43 -07007676 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07007677 cmd_buf_hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
7678 VkCommandBufferBeginInfo cmd_buf_info = {};
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007679 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
7680 cmd_buf_info.pNext = NULL;
7681 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007682 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007683
7684 // Begin CB to transition to recording state
7685 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
7686 // Can't re-begin. This should trigger error
7687 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007688 m_errorMonitor->VerifyFound();
7689
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07007690 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00093);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007691 VkCommandBufferResetFlags flags = 0; // Don't care about flags for this test
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007692 // Reset attempt will trigger error due to incorrect CommandPool state
7693 vkResetCommandBuffer(commandBuffer.GetBufferHandle(), flags);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007694 m_errorMonitor->VerifyFound();
7695
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07007696 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00105);
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007697 // Transition CB to RECORDED state
7698 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
7699 // Now attempting to Begin will implicitly reset, which triggers error
7700 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007701 m_errorMonitor->VerifyFound();
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007702}
7703
Karl Schultz6addd812016-02-02 17:17:23 -07007704TEST_F(VkLayerTest, InvalidPipelineCreateState) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007705 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07007706 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007707
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07007708 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7709 "Invalid Pipeline CreateInfo State: Vertex Shader required");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007710
Tony Barbour1fa09702017-03-16 12:09:08 -06007711 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06007712 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06007713
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007714 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007715 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7716 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06007717
7718 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007719 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7720 ds_pool_ci.pNext = NULL;
7721 ds_pool_ci.maxSets = 1;
7722 ds_pool_ci.poolSizeCount = 1;
7723 ds_pool_ci.pPoolSizes = &ds_type_count;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06007724
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007725 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007726 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007727 ASSERT_VK_SUCCESS(err);
7728
Tony Barboureb254902015-07-15 12:50:33 -06007729 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007730 dsl_binding.binding = 0;
7731 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7732 dsl_binding.descriptorCount = 1;
7733 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7734 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007735
Tony Barboureb254902015-07-15 12:50:33 -06007736 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007737 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7738 ds_layout_ci.pNext = NULL;
7739 ds_layout_ci.bindingCount = 1;
7740 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06007741
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007742 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007743 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007744 ASSERT_VK_SUCCESS(err);
7745
7746 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007747 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007748 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007749 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007750 alloc_info.descriptorPool = ds_pool;
7751 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007752 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007753 ASSERT_VK_SUCCESS(err);
7754
Tony Barboureb254902015-07-15 12:50:33 -06007755 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007756 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7757 pipeline_layout_ci.setLayoutCount = 1;
7758 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007759
7760 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007761 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007762 ASSERT_VK_SUCCESS(err);
7763
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007764 VkViewport vp = {}; // Just need dummy vp to point to
7765 VkRect2D sc = {}; // dummy scissor to point to
Tobin Ehlise68360f2015-10-01 11:15:13 -06007766
7767 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007768 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7769 vp_state_ci.scissorCount = 1;
7770 vp_state_ci.pScissors = &sc;
7771 vp_state_ci.viewportCount = 1;
7772 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007773
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007774 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7775 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7776 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7777 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7778 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7779 rs_state_ci.depthClampEnable = VK_FALSE;
Rene Lindsayae4977b2017-01-23 14:55:54 -07007780 rs_state_ci.rasterizerDiscardEnable = VK_TRUE;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007781 rs_state_ci.depthBiasEnable = VK_FALSE;
Rene Lindsayae4977b2017-01-23 14:55:54 -07007782 rs_state_ci.lineWidth = 1.0f;
7783
7784 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7785 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7786 vi_ci.pNext = nullptr;
7787 vi_ci.vertexBindingDescriptionCount = 0;
7788 vi_ci.pVertexBindingDescriptions = nullptr;
7789 vi_ci.vertexAttributeDescriptionCount = 0;
7790 vi_ci.pVertexAttributeDescriptions = nullptr;
7791
7792 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7793 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7794 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7795
7796 VkPipelineShaderStageCreateInfo shaderStages[2];
7797 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7798
7799 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7800 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Dave Houlton59a20702017-02-02 17:26:23 -07007801 shaderStages[0] = fs.GetStageCreateInfo(); // should be: vs.GetStageCreateInfo();
Rene Lindsayae4977b2017-01-23 14:55:54 -07007802 shaderStages[1] = fs.GetStageCreateInfo();
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007803
Tony Barboureb254902015-07-15 12:50:33 -06007804 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007805 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7806 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007807 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007808 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7809 gp_ci.layout = pipeline_layout;
7810 gp_ci.renderPass = renderPass();
Rene Lindsayae4977b2017-01-23 14:55:54 -07007811 gp_ci.pVertexInputState = &vi_ci;
7812 gp_ci.pInputAssemblyState = &ia_ci;
7813
7814 gp_ci.stageCount = 1;
7815 gp_ci.pStages = shaderStages;
Tony Barboureb254902015-07-15 12:50:33 -06007816
7817 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007818 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7819 pc_ci.initialDataSize = 0;
7820 pc_ci.pInitialData = 0;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007821
7822 VkPipeline pipeline;
Jon Ashburnc669cc62015-07-09 15:02:25 -06007823 VkPipelineCache pipelineCache;
7824
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007825 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Jon Ashburnc669cc62015-07-09 15:02:25 -06007826 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007827 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007828 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007829
Chia-I Wuf7458c52015-10-26 21:10:41 +08007830 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7831 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7832 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7833 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007834}
Rene Lindsayae4977b2017-01-23 14:55:54 -07007835
Tobin Ehlis912df022015-09-17 08:46:18 -06007836/*// TODO : This test should be good, but needs Tess support in compiler to run
7837TEST_F(VkLayerTest, InvalidPatchControlPoints)
7838{
7839 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis912df022015-09-17 08:46:18 -06007840 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007841
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07007842 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07007843 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH
7844primitive ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007845
Tony Barbour1fa09702017-03-16 12:09:08 -06007846 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis912df022015-09-17 08:46:18 -06007847 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis912df022015-09-17 08:46:18 -06007848
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007849 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis912df022015-09-17 08:46:18 -06007850 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007851 ds_type_count.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007852
7853 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7854 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7855 ds_pool_ci.pNext = NULL;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007856 ds_pool_ci.poolSizeCount = 1;
7857 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis912df022015-09-17 08:46:18 -06007858
7859 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07007860 err = vkCreateDescriptorPool(m_device->device(),
7861VK_DESCRIPTOR_POOL_USAGE_NON_FREE, 1, &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis912df022015-09-17 08:46:18 -06007862 ASSERT_VK_SUCCESS(err);
7863
7864 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08007865 dsl_binding.binding = 0;
Tobin Ehlis912df022015-09-17 08:46:18 -06007866 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08007867 dsl_binding.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007868 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7869 dsl_binding.pImmutableSamplers = NULL;
7870
7871 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007872 ds_layout_ci.sType =
7873VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06007874 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007875 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07007876 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis912df022015-09-17 08:46:18 -06007877
7878 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007879 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
7880&ds_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06007881 ASSERT_VK_SUCCESS(err);
7882
7883 VkDescriptorSet descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07007884 err = vkAllocateDescriptorSets(m_device->device(), ds_pool,
7885VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet);
Tobin Ehlis912df022015-09-17 08:46:18 -06007886 ASSERT_VK_SUCCESS(err);
7887
7888 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007889 pipeline_layout_ci.sType =
7890VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06007891 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007892 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007893 pipeline_layout_ci.pSetLayouts = &ds_layout;
7894
7895 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007896 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
7897&pipeline_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06007898 ASSERT_VK_SUCCESS(err);
7899
7900 VkPipelineShaderStageCreateInfo shaderStages[3];
7901 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
7902
Karl Schultz6addd812016-02-02 17:17:23 -07007903 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT,
7904this);
Tobin Ehlis912df022015-09-17 08:46:18 -06007905 // Just using VS txt for Tess shaders as we don't care about functionality
Karl Schultz6addd812016-02-02 17:17:23 -07007906 VkShaderObj
7907tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
7908this);
7909 VkShaderObj
7910te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT,
7911this);
Tobin Ehlis912df022015-09-17 08:46:18 -06007912
Karl Schultz6addd812016-02-02 17:17:23 -07007913 shaderStages[0].sType =
7914VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007915 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007916 shaderStages[0].shader = vs.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07007917 shaderStages[1].sType =
7918VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007919 shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007920 shaderStages[1].shader = tc.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07007921 shaderStages[2].sType =
7922VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007923 shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007924 shaderStages[2].shader = te.handle();
7925
7926 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007927 iaCI.sType =
7928VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Chia-I Wu515eb8f2015-10-31 00:31:16 +08007929 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST;
Tobin Ehlis912df022015-09-17 08:46:18 -06007930
7931 VkPipelineTessellationStateCreateInfo tsCI = {};
7932 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
7933 tsCI.patchControlPoints = 0; // This will cause an error
7934
7935 VkGraphicsPipelineCreateInfo gp_ci = {};
7936 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7937 gp_ci.pNext = NULL;
7938 gp_ci.stageCount = 3;
7939 gp_ci.pStages = shaderStages;
7940 gp_ci.pVertexInputState = NULL;
7941 gp_ci.pInputAssemblyState = &iaCI;
7942 gp_ci.pTessellationState = &tsCI;
7943 gp_ci.pViewportState = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007944 gp_ci.pRasterizationState = NULL;
Tobin Ehlis912df022015-09-17 08:46:18 -06007945 gp_ci.pMultisampleState = NULL;
7946 gp_ci.pDepthStencilState = NULL;
7947 gp_ci.pColorBlendState = NULL;
7948 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7949 gp_ci.layout = pipeline_layout;
7950 gp_ci.renderPass = renderPass();
7951
7952 VkPipelineCacheCreateInfo pc_ci = {};
7953 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7954 pc_ci.pNext = NULL;
7955 pc_ci.initialSize = 0;
7956 pc_ci.initialData = 0;
7957 pc_ci.maxSize = 0;
7958
7959 VkPipeline pipeline;
7960 VkPipelineCache pipelineCache;
7961
Karl Schultz6addd812016-02-02 17:17:23 -07007962 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL,
7963&pipelineCache);
Tobin Ehlis912df022015-09-17 08:46:18 -06007964 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07007965 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
7966&gp_ci, NULL, &pipeline);
Tobin Ehlis912df022015-09-17 08:46:18 -06007967
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007968 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007969
Chia-I Wuf7458c52015-10-26 21:10:41 +08007970 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7971 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7972 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7973 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis912df022015-09-17 08:46:18 -06007974}
7975*/
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007976
Mark Lobodzinski510aa5c2016-12-19 07:59:10 -07007977TEST_F(VkLayerTest, PSOViewportScissorCountTests) {
Karl Schultz6addd812016-02-02 17:17:23 -07007978 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007979
Mark Lobodzinski510aa5c2016-12-19 07:59:10 -07007980 TEST_DESCRIPTION("Test various cases of viewport and scissor count validation");
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007981
Tony Barbour1fa09702017-03-16 12:09:08 -06007982 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007983 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007984
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007985 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007986 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7987 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007988
7989 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007990 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7991 ds_pool_ci.maxSets = 1;
7992 ds_pool_ci.poolSizeCount = 1;
7993 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007994
7995 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007996 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007997 ASSERT_VK_SUCCESS(err);
7998
7999 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008000 dsl_binding.binding = 0;
8001 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8002 dsl_binding.descriptorCount = 1;
8003 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008004
8005 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008006 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8007 ds_layout_ci.bindingCount = 1;
8008 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008009
8010 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008011 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008012 ASSERT_VK_SUCCESS(err);
8013
8014 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008015 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008016 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008017 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008018 alloc_info.descriptorPool = ds_pool;
8019 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008020 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008021 ASSERT_VK_SUCCESS(err);
8022
8023 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008024 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8025 pipeline_layout_ci.setLayoutCount = 1;
8026 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008027
8028 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008029 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008030 ASSERT_VK_SUCCESS(err);
8031
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07008032 VkViewport vp = {};
Tobin Ehlise68360f2015-10-01 11:15:13 -06008033 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008034 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
Mark Lobodzinski510aa5c2016-12-19 07:59:10 -07008035 vp_state_ci.scissorCount = 1;
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07008036 vp_state_ci.viewportCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -07008037 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008038
Karl Schultzdfdb8d42016-03-08 10:30:21 -07008039 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
8040 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
8041 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
8042 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
8043 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
8044 rs_state_ci.depthClampEnable = VK_FALSE;
8045 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
8046 rs_state_ci.depthBiasEnable = VK_FALSE;
8047
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07008048 VkPipelineVertexInputStateCreateInfo vi_ci = {};
8049 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
8050 vi_ci.pNext = nullptr;
8051 vi_ci.vertexBindingDescriptionCount = 0;
8052 vi_ci.pVertexBindingDescriptions = nullptr;
8053 vi_ci.vertexAttributeDescriptionCount = 0;
8054 vi_ci.pVertexAttributeDescriptions = nullptr;
8055
8056 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
8057 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
8058 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
8059
8060 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
8061 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
8062 pipe_ms_state_ci.pNext = NULL;
8063 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
8064 pipe_ms_state_ci.sampleShadingEnable = 0;
8065 pipe_ms_state_ci.minSampleShading = 1.0;
8066 pipe_ms_state_ci.pSampleMask = NULL;
8067
Cody Northropeb3a6c12015-10-05 14:44:45 -06008068 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07008069 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06008070
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008071 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07008072 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chia-I Wu28e06912015-10-31 00:31:16 +08008073 shaderStages[0] = vs.GetStageCreateInfo();
8074 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06008075
8076 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008077 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8078 gp_ci.stageCount = 2;
8079 gp_ci.pStages = shaderStages;
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07008080 gp_ci.pVertexInputState = &vi_ci;
8081 gp_ci.pInputAssemblyState = &ia_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07008082 gp_ci.pViewportState = &vp_state_ci;
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07008083 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07008084 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07008085 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
8086 gp_ci.layout = pipeline_layout;
8087 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06008088
8089 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008090 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008091
8092 VkPipeline pipeline;
8093 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008094 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008095 ASSERT_VK_SUCCESS(err);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008096
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07008097 if (!m_device->phy().features().multiViewport) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07008098 printf(" MultiViewport feature is disabled -- skipping enabled-state checks.\n");
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07008099
8100 // Check case where multiViewport is disabled and viewport count is not 1
8101 // We check scissor/viewport simultaneously since separating them would trigger the mismatch error, 1434.
8102 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01430);
8103 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01431);
8104 vp_state_ci.scissorCount = 0;
8105 vp_state_ci.viewportCount = 0;
8106 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
8107 m_errorMonitor->VerifyFound();
8108 } else {
8109 if (m_device->props.limits.maxViewports == 1) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07008110 printf(" Device limit maxViewports is 1, skipping tests that require higher limits.\n");
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07008111 } else {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07008112 printf(" MultiViewport feature is enabled -- skipping disabled-state checks.\n");
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07008113
8114 // Check is that viewportcount and scissorcount match
8115 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01434);
8116 vp_state_ci.scissorCount = 1;
8117 vp_state_ci.viewportCount = m_device->props.limits.maxViewports;
8118 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
8119 m_errorMonitor->VerifyFound();
8120
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07008121 // Check case where multiViewport is enabled and viewport count is greater than max
8122 // We check scissor/viewport simultaneously since separating them would trigger the mismatch error, 1434.
8123 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01432);
8124 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01433);
8125 vp_state_ci.scissorCount = m_device->props.limits.maxViewports + 1;
8126 vp_state_ci.viewportCount = m_device->props.limits.maxViewports + 1;
8127 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
8128 m_errorMonitor->VerifyFound();
8129 }
8130 }
Tobin Ehlise68360f2015-10-01 11:15:13 -06008131
Chia-I Wuf7458c52015-10-26 21:10:41 +08008132 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
8133 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8134 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8135 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008136}
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07008137
8138// 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
8139// set dynamically.
Karl Schultz6addd812016-02-02 17:17:23 -07008140TEST_F(VkLayerTest, PSOViewportStateNotSet) {
Karl Schultz6addd812016-02-02 17:17:23 -07008141 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008142
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07008143 TEST_DESCRIPTION("Create a graphics pipeline with rasterization enabled but no viewport state.");
8144
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07008145 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02113);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008146
Tony Barbour1fa09702017-03-16 12:09:08 -06008147 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlise68360f2015-10-01 11:15:13 -06008148 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06008149
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008150 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008151 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8152 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008153
8154 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008155 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8156 ds_pool_ci.maxSets = 1;
8157 ds_pool_ci.poolSizeCount = 1;
8158 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008159
8160 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008161 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008162 ASSERT_VK_SUCCESS(err);
8163
8164 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008165 dsl_binding.binding = 0;
8166 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8167 dsl_binding.descriptorCount = 1;
8168 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008169
8170 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008171 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8172 ds_layout_ci.bindingCount = 1;
8173 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008174
8175 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008176 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008177 ASSERT_VK_SUCCESS(err);
8178
8179 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008180 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008181 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008182 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008183 alloc_info.descriptorPool = ds_pool;
8184 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008185 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008186 ASSERT_VK_SUCCESS(err);
8187
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07008188 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
8189 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
8190 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
8191
8192 VkPipelineVertexInputStateCreateInfo vi_ci = {};
8193 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
8194 vi_ci.pNext = nullptr;
8195 vi_ci.vertexBindingDescriptionCount = 0;
8196 vi_ci.pVertexBindingDescriptions = nullptr;
8197 vi_ci.vertexAttributeDescriptionCount = 0;
8198 vi_ci.pVertexAttributeDescriptions = nullptr;
8199
8200 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
8201 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
8202 pipe_ms_state_ci.pNext = NULL;
8203 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
8204 pipe_ms_state_ci.sampleShadingEnable = 0;
8205 pipe_ms_state_ci.minSampleShading = 1.0;
8206 pipe_ms_state_ci.pSampleMask = NULL;
8207
Tobin Ehlise68360f2015-10-01 11:15:13 -06008208 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008209 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8210 pipeline_layout_ci.setLayoutCount = 1;
8211 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008212
8213 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008214 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008215 ASSERT_VK_SUCCESS(err);
8216
8217 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
8218 // Set scissor as dynamic to avoid second error
8219 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008220 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
8221 dyn_state_ci.dynamicStateCount = 1;
8222 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008223
Cody Northropeb3a6c12015-10-05 14:44:45 -06008224 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07008225 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06008226
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008227 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07008228 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
8229 // 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 +08008230 shaderStages[0] = vs.GetStageCreateInfo();
8231 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06008232
Karl Schultzdfdb8d42016-03-08 10:30:21 -07008233 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
8234 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
8235 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
8236 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
8237 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
8238 rs_state_ci.depthClampEnable = VK_FALSE;
8239 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
8240 rs_state_ci.depthBiasEnable = VK_FALSE;
8241
Tobin Ehlise68360f2015-10-01 11:15:13 -06008242 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008243 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8244 gp_ci.stageCount = 2;
8245 gp_ci.pStages = shaderStages;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07008246 gp_ci.pRasterizationState = &rs_state_ci;
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07008247 // Not setting VP state w/o dynamic vp state should cause validation error
8248 gp_ci.pViewportState = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -07008249 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07008250 gp_ci.pVertexInputState = &vi_ci;
8251 gp_ci.pInputAssemblyState = &ia_ci;
8252 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07008253 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
8254 gp_ci.layout = pipeline_layout;
8255 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06008256
8257 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008258 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008259
8260 VkPipeline pipeline;
8261 VkPipelineCache pipelineCache;
8262
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008263 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008264 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008265 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008266
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008267 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06008268
Chia-I Wuf7458c52015-10-26 21:10:41 +08008269 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
8270 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8271 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8272 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008273}
Mark Lobodzinski73169e22016-12-16 14:01:17 -07008274
8275// Create PSO w/o non-zero viewportCount but no viewport data, then run second test where dynamic scissor count doesn't match PSO
8276// scissor count
Karl Schultz6addd812016-02-02 17:17:23 -07008277TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch) {
8278 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008279
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07008280 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02110);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008281
Tony Barbour1fa09702017-03-16 12:09:08 -06008282 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12008283
8284 if (!m_device->phy().features().multiViewport) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07008285 printf(" Device does not support multiple viewports/scissors; skipped.\n");
Chris Forbesc08a6ca2016-07-28 14:14:07 +12008286 return;
8287 }
8288
Tobin Ehlise68360f2015-10-01 11:15:13 -06008289 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06008290
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008291 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008292 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8293 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008294
8295 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008296 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8297 ds_pool_ci.maxSets = 1;
8298 ds_pool_ci.poolSizeCount = 1;
8299 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008300
8301 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008302 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008303 ASSERT_VK_SUCCESS(err);
8304
8305 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008306 dsl_binding.binding = 0;
8307 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8308 dsl_binding.descriptorCount = 1;
8309 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008310
8311 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008312 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8313 ds_layout_ci.bindingCount = 1;
8314 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008315
8316 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008317 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008318 ASSERT_VK_SUCCESS(err);
8319
8320 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008321 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008322 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008323 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008324 alloc_info.descriptorPool = ds_pool;
8325 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008326 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008327 ASSERT_VK_SUCCESS(err);
8328
8329 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008330 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8331 pipeline_layout_ci.setLayoutCount = 1;
8332 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008333
8334 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008335 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008336 ASSERT_VK_SUCCESS(err);
8337
8338 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008339 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
8340 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008341 vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error
Karl Schultz6addd812016-02-02 17:17:23 -07008342 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008343 vp_state_ci.pScissors = NULL; // Scissor is dynamic (below) so this won't cause error
Tobin Ehlise68360f2015-10-01 11:15:13 -06008344
8345 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
8346 // Set scissor as dynamic to avoid that error
8347 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008348 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
8349 dyn_state_ci.dynamicStateCount = 1;
8350 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008351
Mark Lobodzinski73169e22016-12-16 14:01:17 -07008352 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
8353 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
8354 pipe_ms_state_ci.pNext = NULL;
8355 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
8356 pipe_ms_state_ci.sampleShadingEnable = 0;
8357 pipe_ms_state_ci.minSampleShading = 1.0;
8358 pipe_ms_state_ci.pSampleMask = NULL;
8359
Cody Northropeb3a6c12015-10-05 14:44:45 -06008360 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07008361 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06008362
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008363 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski73169e22016-12-16 14:01:17 -07008364 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
8365 // 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 +08008366 shaderStages[0] = vs.GetStageCreateInfo();
8367 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06008368
Cody Northropf6622dc2015-10-06 10:33:21 -06008369 VkPipelineVertexInputStateCreateInfo vi_ci = {};
8370 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
8371 vi_ci.pNext = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008372 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06008373 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008374 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06008375 vi_ci.pVertexAttributeDescriptions = nullptr;
8376
8377 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
8378 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
8379 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
8380
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008381 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008382 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Mark Lobodzinski73169e22016-12-16 14:01:17 -07008383 rs_ci.lineWidth = m_device->props.limits.lineWidthRange[0];
Cody Northropf6622dc2015-10-06 10:33:21 -06008384 rs_ci.pNext = nullptr;
8385
Mark Youngc89c6312016-03-31 16:03:20 -06008386 VkPipelineColorBlendAttachmentState att = {};
8387 att.blendEnable = VK_FALSE;
8388 att.colorWriteMask = 0xf;
8389
Cody Northropf6622dc2015-10-06 10:33:21 -06008390 VkPipelineColorBlendStateCreateInfo cb_ci = {};
8391 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
8392 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06008393 cb_ci.attachmentCount = 1;
8394 cb_ci.pAttachments = &att;
Cody Northropf6622dc2015-10-06 10:33:21 -06008395
Tobin Ehlise68360f2015-10-01 11:15:13 -06008396 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008397 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8398 gp_ci.stageCount = 2;
8399 gp_ci.pStages = shaderStages;
8400 gp_ci.pVertexInputState = &vi_ci;
8401 gp_ci.pInputAssemblyState = &ia_ci;
8402 gp_ci.pViewportState = &vp_state_ci;
8403 gp_ci.pRasterizationState = &rs_ci;
8404 gp_ci.pColorBlendState = &cb_ci;
8405 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski73169e22016-12-16 14:01:17 -07008406 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07008407 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
8408 gp_ci.layout = pipeline_layout;
8409 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06008410
8411 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008412 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008413
8414 VkPipeline pipeline;
8415 VkPipelineCache pipelineCache;
8416
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008417 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008418 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008419 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008420
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008421 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008422
Tobin Ehlisd332f282015-10-02 11:00:56 -06008423 // Now hit second fail case where we set scissor w/ different count than PSO
Karl Schultz6addd812016-02-02 17:17:23 -07008424 // First need to successfully create the PSO from above by setting
8425 // pViewports
Mike Weiblen95dd0f92016-10-19 12:28:27 -06008426 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 -07008427
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008428 VkViewport vp = {}; // Just need dummy vp to point to
Karl Schultz6addd812016-02-02 17:17:23 -07008429 vp_state_ci.pViewports = &vp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008430 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07008431 ASSERT_VK_SUCCESS(err);
Tony Barbour552f6c02016-12-21 14:34:07 -07008432 m_commandBuffer->BeginCommandBuffer();
8433 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008434 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008435 VkRect2D scissors[1] = {}; // don't care about data
Karl Schultz6addd812016-02-02 17:17:23 -07008436 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12008437 vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 1, 1, scissors);
Karl Schultz6addd812016-02-02 17:17:23 -07008438 Draw(1, 0, 0, 0);
8439
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008440 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07008441
8442 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
8443 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8444 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8445 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008446 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07008447}
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008448
8449// 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 -07008450// viewportCount
8451TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch) {
8452 VkResult err;
8453
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07008454 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02111);
Karl Schultz6addd812016-02-02 17:17:23 -07008455
Tony Barbour1fa09702017-03-16 12:09:08 -06008456 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12008457
8458 if (!m_device->phy().features().multiViewport) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07008459 printf(" Device does not support multiple viewports/scissors; skipped.\n");
Chris Forbesc08a6ca2016-07-28 14:14:07 +12008460 return;
8461 }
8462
Karl Schultz6addd812016-02-02 17:17:23 -07008463 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8464
8465 VkDescriptorPoolSize ds_type_count = {};
8466 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8467 ds_type_count.descriptorCount = 1;
8468
8469 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8470 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8471 ds_pool_ci.maxSets = 1;
8472 ds_pool_ci.poolSizeCount = 1;
8473 ds_pool_ci.pPoolSizes = &ds_type_count;
8474
8475 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008476 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Karl Schultz6addd812016-02-02 17:17:23 -07008477 ASSERT_VK_SUCCESS(err);
8478
8479 VkDescriptorSetLayoutBinding dsl_binding = {};
8480 dsl_binding.binding = 0;
8481 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8482 dsl_binding.descriptorCount = 1;
8483 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8484
8485 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8486 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8487 ds_layout_ci.bindingCount = 1;
8488 ds_layout_ci.pBindings = &dsl_binding;
8489
8490 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008491 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07008492 ASSERT_VK_SUCCESS(err);
8493
8494 VkDescriptorSet descriptorSet;
8495 VkDescriptorSetAllocateInfo alloc_info = {};
8496 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8497 alloc_info.descriptorSetCount = 1;
8498 alloc_info.descriptorPool = ds_pool;
8499 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008500 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Karl Schultz6addd812016-02-02 17:17:23 -07008501 ASSERT_VK_SUCCESS(err);
8502
8503 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
8504 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8505 pipeline_layout_ci.setLayoutCount = 1;
8506 pipeline_layout_ci.pSetLayouts = &ds_layout;
8507
8508 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008509 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07008510 ASSERT_VK_SUCCESS(err);
8511
8512 VkPipelineViewportStateCreateInfo vp_state_ci = {};
8513 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
8514 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008515 vp_state_ci.pScissors = NULL; // Null scissor w/ count of 1 should cause error
Karl Schultz6addd812016-02-02 17:17:23 -07008516 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008517 vp_state_ci.pViewports = NULL; // vp is dynamic (below) so this won't cause error
Karl Schultz6addd812016-02-02 17:17:23 -07008518
8519 VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT;
8520 // Set scissor as dynamic to avoid that error
8521 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
8522 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
8523 dyn_state_ci.dynamicStateCount = 1;
8524 dyn_state_ci.pDynamicStates = &vp_state;
8525
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008526 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
8527 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
8528 pipe_ms_state_ci.pNext = NULL;
8529 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
8530 pipe_ms_state_ci.sampleShadingEnable = 0;
8531 pipe_ms_state_ci.minSampleShading = 1.0;
8532 pipe_ms_state_ci.pSampleMask = NULL;
8533
Karl Schultz6addd812016-02-02 17:17:23 -07008534 VkPipelineShaderStageCreateInfo shaderStages[2];
8535 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
8536
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008537 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008538 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
8539 // 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 -07008540 shaderStages[0] = vs.GetStageCreateInfo();
8541 shaderStages[1] = fs.GetStageCreateInfo();
8542
8543 VkPipelineVertexInputStateCreateInfo vi_ci = {};
8544 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
8545 vi_ci.pNext = nullptr;
8546 vi_ci.vertexBindingDescriptionCount = 0;
8547 vi_ci.pVertexBindingDescriptions = nullptr;
8548 vi_ci.vertexAttributeDescriptionCount = 0;
8549 vi_ci.pVertexAttributeDescriptions = nullptr;
8550
8551 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
8552 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
8553 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
8554
8555 VkPipelineRasterizationStateCreateInfo rs_ci = {};
8556 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008557 rs_ci.lineWidth = m_device->props.limits.lineWidthRange[0];
Karl Schultz6addd812016-02-02 17:17:23 -07008558 rs_ci.pNext = nullptr;
8559
Mark Youngc89c6312016-03-31 16:03:20 -06008560 VkPipelineColorBlendAttachmentState att = {};
8561 att.blendEnable = VK_FALSE;
8562 att.colorWriteMask = 0xf;
8563
Karl Schultz6addd812016-02-02 17:17:23 -07008564 VkPipelineColorBlendStateCreateInfo cb_ci = {};
8565 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
8566 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06008567 cb_ci.attachmentCount = 1;
8568 cb_ci.pAttachments = &att;
Karl Schultz6addd812016-02-02 17:17:23 -07008569
8570 VkGraphicsPipelineCreateInfo gp_ci = {};
8571 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8572 gp_ci.stageCount = 2;
8573 gp_ci.pStages = shaderStages;
8574 gp_ci.pVertexInputState = &vi_ci;
8575 gp_ci.pInputAssemblyState = &ia_ci;
8576 gp_ci.pViewportState = &vp_state_ci;
8577 gp_ci.pRasterizationState = &rs_ci;
8578 gp_ci.pColorBlendState = &cb_ci;
8579 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008580 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07008581 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
8582 gp_ci.layout = pipeline_layout;
8583 gp_ci.renderPass = renderPass();
8584
8585 VkPipelineCacheCreateInfo pc_ci = {};
8586 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
8587
8588 VkPipeline pipeline;
8589 VkPipelineCache pipelineCache;
8590
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008591 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Karl Schultz6addd812016-02-02 17:17:23 -07008592 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008593 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07008594
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008595 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07008596
8597 // Now hit second fail case where we set scissor w/ different count than PSO
8598 // First need to successfully create the PSO from above by setting
8599 // pViewports
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07008600 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8601 "Dynamic viewport(s) 0 are used by pipeline state object, ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008602
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008603 VkRect2D sc = {}; // Just need dummy vp to point to
Tobin Ehlisd332f282015-10-02 11:00:56 -06008604 vp_state_ci.pScissors = &sc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008605 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06008606 ASSERT_VK_SUCCESS(err);
Tony Barbour552f6c02016-12-21 14:34:07 -07008607 m_commandBuffer->BeginCommandBuffer();
8608 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008609 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008610 VkViewport viewports[1] = {};
8611 viewports[0].width = 8;
8612 viewports[0].height = 8;
Tobin Ehlisd332f282015-10-02 11:00:56 -06008613 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12008614 vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 1, 1, viewports);
Tobin Ehlisd332f282015-10-02 11:00:56 -06008615 Draw(1, 0, 0, 0);
8616
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008617 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06008618
Chia-I Wuf7458c52015-10-26 21:10:41 +08008619 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
8620 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8621 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8622 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008623 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008624}
8625
Mark Young7394fdd2016-03-31 14:56:43 -06008626TEST_F(VkLayerTest, PSOLineWidthInvalid) {
8627 VkResult err;
8628
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008629 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06008630
Tony Barbour1fa09702017-03-16 12:09:08 -06008631 ASSERT_NO_FATAL_FAILURE(Init());
Mark Young7394fdd2016-03-31 14:56:43 -06008632 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8633
8634 VkDescriptorPoolSize ds_type_count = {};
8635 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8636 ds_type_count.descriptorCount = 1;
8637
8638 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8639 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8640 ds_pool_ci.maxSets = 1;
8641 ds_pool_ci.poolSizeCount = 1;
8642 ds_pool_ci.pPoolSizes = &ds_type_count;
8643
8644 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008645 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Young7394fdd2016-03-31 14:56:43 -06008646 ASSERT_VK_SUCCESS(err);
8647
8648 VkDescriptorSetLayoutBinding dsl_binding = {};
8649 dsl_binding.binding = 0;
8650 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8651 dsl_binding.descriptorCount = 1;
8652 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8653
8654 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8655 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8656 ds_layout_ci.bindingCount = 1;
8657 ds_layout_ci.pBindings = &dsl_binding;
8658
8659 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008660 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06008661 ASSERT_VK_SUCCESS(err);
8662
8663 VkDescriptorSet descriptorSet;
8664 VkDescriptorSetAllocateInfo alloc_info = {};
8665 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8666 alloc_info.descriptorSetCount = 1;
8667 alloc_info.descriptorPool = ds_pool;
8668 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008669 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Young7394fdd2016-03-31 14:56:43 -06008670 ASSERT_VK_SUCCESS(err);
8671
8672 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
8673 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8674 pipeline_layout_ci.setLayoutCount = 1;
8675 pipeline_layout_ci.pSetLayouts = &ds_layout;
8676
8677 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008678 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06008679 ASSERT_VK_SUCCESS(err);
8680
8681 VkPipelineViewportStateCreateInfo vp_state_ci = {};
8682 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
8683 vp_state_ci.scissorCount = 1;
8684 vp_state_ci.pScissors = NULL;
8685 vp_state_ci.viewportCount = 1;
8686 vp_state_ci.pViewports = NULL;
8687
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008688 VkDynamicState dynamic_states[3] = {VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR, VK_DYNAMIC_STATE_LINE_WIDTH};
Mark Young7394fdd2016-03-31 14:56:43 -06008689 // Set scissor as dynamic to avoid that error
8690 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
8691 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
8692 dyn_state_ci.dynamicStateCount = 2;
8693 dyn_state_ci.pDynamicStates = dynamic_states;
8694
8695 VkPipelineShaderStageCreateInfo shaderStages[2];
8696 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
8697
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008698 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
8699 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT,
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008700 this); // TODO - We shouldn't need a fragment shader
8701 // but add it to be able to run on more devices
Mark Young7394fdd2016-03-31 14:56:43 -06008702 shaderStages[0] = vs.GetStageCreateInfo();
8703 shaderStages[1] = fs.GetStageCreateInfo();
8704
8705 VkPipelineVertexInputStateCreateInfo vi_ci = {};
8706 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
8707 vi_ci.pNext = nullptr;
8708 vi_ci.vertexBindingDescriptionCount = 0;
8709 vi_ci.pVertexBindingDescriptions = nullptr;
8710 vi_ci.vertexAttributeDescriptionCount = 0;
8711 vi_ci.pVertexAttributeDescriptions = nullptr;
8712
8713 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
8714 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
8715 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
8716
8717 VkPipelineRasterizationStateCreateInfo rs_ci = {};
8718 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
8719 rs_ci.pNext = nullptr;
Rene Lindsay144e4842017-01-20 14:27:15 -07008720 rs_ci.rasterizerDiscardEnable = VK_TRUE;
Mark Young7394fdd2016-03-31 14:56:43 -06008721
Mark Young47107952016-05-02 15:59:55 -06008722 // Check too low (line width of -1.0f).
8723 rs_ci.lineWidth = -1.0f;
Mark Young7394fdd2016-03-31 14:56:43 -06008724
8725 VkPipelineColorBlendAttachmentState att = {};
8726 att.blendEnable = VK_FALSE;
8727 att.colorWriteMask = 0xf;
8728
8729 VkPipelineColorBlendStateCreateInfo cb_ci = {};
8730 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
8731 cb_ci.pNext = nullptr;
8732 cb_ci.attachmentCount = 1;
8733 cb_ci.pAttachments = &att;
8734
8735 VkGraphicsPipelineCreateInfo gp_ci = {};
8736 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8737 gp_ci.stageCount = 2;
8738 gp_ci.pStages = shaderStages;
8739 gp_ci.pVertexInputState = &vi_ci;
8740 gp_ci.pInputAssemblyState = &ia_ci;
8741 gp_ci.pViewportState = &vp_state_ci;
8742 gp_ci.pRasterizationState = &rs_ci;
8743 gp_ci.pColorBlendState = &cb_ci;
8744 gp_ci.pDynamicState = &dyn_state_ci;
8745 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
8746 gp_ci.layout = pipeline_layout;
8747 gp_ci.renderPass = renderPass();
8748
8749 VkPipelineCacheCreateInfo pc_ci = {};
8750 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
8751
8752 VkPipeline pipeline;
8753 VkPipelineCache pipelineCache;
8754
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008755 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06008756 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008757 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06008758
8759 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06008760 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06008761
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008762 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06008763
8764 // Check too high (line width of 65536.0f).
8765 rs_ci.lineWidth = 65536.0f;
8766
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008767 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06008768 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008769 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06008770
8771 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06008772 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06008773
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008774 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06008775
8776 dyn_state_ci.dynamicStateCount = 3;
8777
8778 rs_ci.lineWidth = 1.0f;
8779
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008780 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06008781 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008782 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tony Barbour552f6c02016-12-21 14:34:07 -07008783 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008784 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06008785
8786 // Check too low with dynamic setting.
Mark Young47107952016-05-02 15:59:55 -06008787 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), -1.0f);
Mark Young7394fdd2016-03-31 14:56:43 -06008788 m_errorMonitor->VerifyFound();
8789
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008790 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06008791
8792 // Check too high with dynamic setting.
8793 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), 65536.0f);
8794 m_errorMonitor->VerifyFound();
Tony Barbour552f6c02016-12-21 14:34:07 -07008795 m_commandBuffer->EndCommandBuffer();
Mark Young7394fdd2016-03-31 14:56:43 -06008796
8797 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
8798 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8799 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8800 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008801 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06008802}
8803
Jeremy Hayes37f0cdd2017-05-04 18:08:49 -06008804TEST_F(VkLayerTest, VALIDATION_ERROR_01407) {
8805 TEST_DESCRIPTION("Test VALIDATION_ERROR_01407: binding must be less than VkPhysicalDeviceLimits::maxVertexInputBindings");
8806
8807 ASSERT_NO_FATAL_FAILURE(Init());
8808 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8809
8810 VkPipelineCache pipeline_cache;
8811 {
8812 VkPipelineCacheCreateInfo create_info{};
8813 create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
8814
8815 VkResult err = vkCreatePipelineCache(m_device->device(), &create_info, nullptr, &pipeline_cache);
8816 ASSERT_VK_SUCCESS(err);
8817 }
8818
8819 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
8820 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
8821
8822 VkPipelineShaderStageCreateInfo stages[2]{{}};
8823 stages[0] = vs.GetStageCreateInfo();
8824 stages[1] = fs.GetStageCreateInfo();
8825
8826 // Test when binding is greater than or equal to VkPhysicalDeviceLimits::maxVertexInputBindings.
8827 VkVertexInputBindingDescription vertex_input_binding_description{};
8828 vertex_input_binding_description.binding = m_device->props.limits.maxVertexInputBindings;
8829
8830 VkPipelineVertexInputStateCreateInfo vertex_input_state{};
8831 vertex_input_state.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
8832 vertex_input_state.pNext = nullptr;
8833 vertex_input_state.vertexBindingDescriptionCount = 1;
8834 vertex_input_state.pVertexBindingDescriptions = &vertex_input_binding_description;
8835 vertex_input_state.vertexAttributeDescriptionCount = 0;
8836 vertex_input_state.pVertexAttributeDescriptions = nullptr;
8837
8838 VkPipelineInputAssemblyStateCreateInfo input_assembly_state{};
8839 input_assembly_state.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
8840 input_assembly_state.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
8841
8842 VkViewport viewport{};
8843 VkPipelineViewportStateCreateInfo viewport_state{};
8844 viewport_state.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
8845 viewport_state.scissorCount = 1;
8846 viewport_state.viewportCount = 1;
8847 viewport_state.pViewports = &viewport;
8848
8849 VkPipelineMultisampleStateCreateInfo multisample_state{};
8850 multisample_state.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
8851 multisample_state.pNext = nullptr;
8852 multisample_state.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
8853 multisample_state.sampleShadingEnable = 0;
8854 multisample_state.minSampleShading = 1.0;
8855 multisample_state.pSampleMask = nullptr;
8856
8857 VkPipelineRasterizationStateCreateInfo rasterization_state{};
8858 rasterization_state.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
8859 rasterization_state.polygonMode = VK_POLYGON_MODE_FILL;
8860 rasterization_state.cullMode = VK_CULL_MODE_BACK_BIT;
8861 rasterization_state.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
8862 rasterization_state.depthClampEnable = VK_FALSE;
8863 rasterization_state.rasterizerDiscardEnable = VK_FALSE;
8864 rasterization_state.depthBiasEnable = VK_FALSE;
8865
8866 VkPipelineLayout pipeline_layout;
8867 {
8868 VkPipelineLayoutCreateInfo create_info{};
8869 create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8870 create_info.setLayoutCount = 0;
8871 create_info.pSetLayouts = nullptr;
8872
8873 VkResult err = vkCreatePipelineLayout(m_device->device(), &create_info, nullptr, &pipeline_layout);
8874 ASSERT_VK_SUCCESS(err);
8875 }
8876
8877 {
8878 VkGraphicsPipelineCreateInfo create_info{};
8879 create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8880 create_info.stageCount = 2;
8881 create_info.pStages = stages;
8882 create_info.pVertexInputState = &vertex_input_state;
8883 create_info.pInputAssemblyState = &input_assembly_state;
8884 create_info.pViewportState = &viewport_state;
8885 create_info.pMultisampleState = &multisample_state;
8886 create_info.pRasterizationState = &rasterization_state;
8887 create_info.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
8888 create_info.layout = pipeline_layout;
8889 create_info.renderPass = renderPass();
8890
8891 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01407);
8892 VkPipeline pipeline;
8893 vkCreateGraphicsPipelines(m_device->device(), pipeline_cache, 1, &create_info, nullptr, &pipeline);
8894 m_errorMonitor->VerifyFound();
8895 }
8896
8897 vkDestroyPipelineCache(m_device->device(), pipeline_cache, nullptr);
8898 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
8899}
8900
8901TEST_F(VkLayerTest, VALIDATION_ERROR_01408) {
8902 TEST_DESCRIPTION(
8903 "Test VALIDATION_ERROR_01408: stride must be less than or equal to VkPhysicalDeviceLimits::maxVertexInputBindingStride");
8904
8905 ASSERT_NO_FATAL_FAILURE(Init());
8906 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8907
8908 VkPipelineCache pipeline_cache;
8909 {
8910 VkPipelineCacheCreateInfo create_info{};
8911 create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
8912
8913 VkResult err = vkCreatePipelineCache(m_device->device(), &create_info, nullptr, &pipeline_cache);
8914 ASSERT_VK_SUCCESS(err);
8915 }
8916
8917 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
8918 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
8919
8920 VkPipelineShaderStageCreateInfo stages[2]{{}};
8921 stages[0] = vs.GetStageCreateInfo();
8922 stages[1] = fs.GetStageCreateInfo();
8923
8924 // Test when stride is greater than VkPhysicalDeviceLimits::maxVertexInputBindingStride.
8925 VkVertexInputBindingDescription vertex_input_binding_description{};
8926 vertex_input_binding_description.stride = m_device->props.limits.maxVertexInputBindingStride + 1;
8927
8928 VkPipelineVertexInputStateCreateInfo vertex_input_state{};
8929 vertex_input_state.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
8930 vertex_input_state.pNext = nullptr;
8931 vertex_input_state.vertexBindingDescriptionCount = 1;
8932 vertex_input_state.pVertexBindingDescriptions = &vertex_input_binding_description;
8933 vertex_input_state.vertexAttributeDescriptionCount = 0;
8934 vertex_input_state.pVertexAttributeDescriptions = nullptr;
8935
8936 VkPipelineInputAssemblyStateCreateInfo input_assembly_state{};
8937 input_assembly_state.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
8938 input_assembly_state.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
8939
8940 VkViewport viewport{};
8941 VkPipelineViewportStateCreateInfo viewport_state{};
8942 viewport_state.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
8943 viewport_state.scissorCount = 1;
8944 viewport_state.viewportCount = 1;
8945 viewport_state.pViewports = &viewport;
8946
8947 VkPipelineMultisampleStateCreateInfo multisample_state{};
8948 multisample_state.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
8949 multisample_state.pNext = nullptr;
8950 multisample_state.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
8951 multisample_state.sampleShadingEnable = 0;
8952 multisample_state.minSampleShading = 1.0;
8953 multisample_state.pSampleMask = nullptr;
8954
8955 VkPipelineRasterizationStateCreateInfo rasterization_state{};
8956 rasterization_state.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
8957 rasterization_state.polygonMode = VK_POLYGON_MODE_FILL;
8958 rasterization_state.cullMode = VK_CULL_MODE_BACK_BIT;
8959 rasterization_state.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
8960 rasterization_state.depthClampEnable = VK_FALSE;
8961 rasterization_state.rasterizerDiscardEnable = VK_FALSE;
8962 rasterization_state.depthBiasEnable = VK_FALSE;
8963
8964 VkPipelineLayout pipeline_layout;
8965 {
8966 VkPipelineLayoutCreateInfo create_info{};
8967 create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8968 create_info.setLayoutCount = 0;
8969 create_info.pSetLayouts = nullptr;
8970
8971 VkResult err = vkCreatePipelineLayout(m_device->device(), &create_info, nullptr, &pipeline_layout);
8972 ASSERT_VK_SUCCESS(err);
8973 }
8974
8975 {
8976 VkGraphicsPipelineCreateInfo create_info{};
8977 create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8978 create_info.stageCount = 2;
8979 create_info.pStages = stages;
8980 create_info.pVertexInputState = &vertex_input_state;
8981 create_info.pInputAssemblyState = &input_assembly_state;
8982 create_info.pViewportState = &viewport_state;
8983 create_info.pMultisampleState = &multisample_state;
8984 create_info.pRasterizationState = &rasterization_state;
8985 create_info.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
8986 create_info.layout = pipeline_layout;
8987 create_info.renderPass = renderPass();
8988
8989 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01408);
8990 VkPipeline pipeline;
8991 vkCreateGraphicsPipelines(m_device->device(), pipeline_cache, 1, &create_info, nullptr, &pipeline);
8992 m_errorMonitor->VerifyFound();
8993 }
8994
8995 vkDestroyPipelineCache(m_device->device(), pipeline_cache, nullptr);
8996 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
8997}
8998
Jeremy Hayes091e1ab2017-05-04 18:10:28 -06008999TEST_F(VkLayerTest, VALIDATION_ERROR_01410) {
9000 TEST_DESCRIPTION("Test VALIDATION_ERROR_01410: location must be less than VkPhysicalDeviceLimits::maxVertexInputAttributes");
9001
9002 ASSERT_NO_FATAL_FAILURE(Init());
9003 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9004
9005 VkPipelineCache pipeline_cache;
9006 {
9007 VkPipelineCacheCreateInfo create_info{};
9008 create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
9009
9010 VkResult err = vkCreatePipelineCache(m_device->device(), &create_info, nullptr, &pipeline_cache);
9011 ASSERT_VK_SUCCESS(err);
9012 }
9013
9014 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9015 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
9016
9017 VkPipelineShaderStageCreateInfo stages[2]{{}};
9018 stages[0] = vs.GetStageCreateInfo();
9019 stages[1] = fs.GetStageCreateInfo();
9020
9021 // Test when location is greater than or equal to VkPhysicalDeviceLimits::maxVertexInputAttributes.
9022 VkVertexInputAttributeDescription vertex_input_attribute_description{};
9023 vertex_input_attribute_description.location = m_device->props.limits.maxVertexInputAttributes;
9024
9025 VkPipelineVertexInputStateCreateInfo vertex_input_state{};
9026 vertex_input_state.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
9027 vertex_input_state.pNext = nullptr;
9028 vertex_input_state.vertexBindingDescriptionCount = 0;
9029 vertex_input_state.pVertexBindingDescriptions = nullptr;
9030 vertex_input_state.vertexAttributeDescriptionCount = 1;
9031 vertex_input_state.pVertexAttributeDescriptions = &vertex_input_attribute_description;
9032
9033 VkPipelineInputAssemblyStateCreateInfo input_assembly_state{};
9034 input_assembly_state.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
9035 input_assembly_state.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
9036
9037 VkViewport viewport{};
9038 VkPipelineViewportStateCreateInfo viewport_state{};
9039 viewport_state.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
9040 viewport_state.scissorCount = 1;
9041 viewport_state.viewportCount = 1;
9042 viewport_state.pViewports = &viewport;
9043
9044 VkPipelineMultisampleStateCreateInfo multisample_state{};
9045 multisample_state.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
9046 multisample_state.pNext = nullptr;
9047 multisample_state.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
9048 multisample_state.sampleShadingEnable = 0;
9049 multisample_state.minSampleShading = 1.0;
9050 multisample_state.pSampleMask = nullptr;
9051
9052 VkPipelineRasterizationStateCreateInfo rasterization_state{};
9053 rasterization_state.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
9054 rasterization_state.polygonMode = VK_POLYGON_MODE_FILL;
9055 rasterization_state.cullMode = VK_CULL_MODE_BACK_BIT;
9056 rasterization_state.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
9057 rasterization_state.depthClampEnable = VK_FALSE;
9058 rasterization_state.rasterizerDiscardEnable = VK_FALSE;
9059 rasterization_state.depthBiasEnable = VK_FALSE;
9060
9061 VkPipelineLayout pipeline_layout;
9062 {
9063 VkPipelineLayoutCreateInfo create_info{};
9064 create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9065 create_info.setLayoutCount = 0;
9066 create_info.pSetLayouts = nullptr;
9067
9068 VkResult err = vkCreatePipelineLayout(m_device->device(), &create_info, nullptr, &pipeline_layout);
9069 ASSERT_VK_SUCCESS(err);
9070 }
9071
9072 {
9073 VkGraphicsPipelineCreateInfo create_info{};
9074 create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
9075 create_info.stageCount = 2;
9076 create_info.pStages = stages;
9077 create_info.pVertexInputState = &vertex_input_state;
9078 create_info.pInputAssemblyState = &input_assembly_state;
9079 create_info.pViewportState = &viewport_state;
9080 create_info.pMultisampleState = &multisample_state;
9081 create_info.pRasterizationState = &rasterization_state;
9082 create_info.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
9083 create_info.layout = pipeline_layout;
9084 create_info.renderPass = renderPass();
9085
9086 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01410);
9087 VkPipeline pipeline;
9088 vkCreateGraphicsPipelines(m_device->device(), pipeline_cache, 1, &create_info, nullptr, &pipeline);
9089 m_errorMonitor->VerifyFound();
9090 }
9091
9092 vkDestroyPipelineCache(m_device->device(), pipeline_cache, nullptr);
9093 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
9094}
9095
9096TEST_F(VkLayerTest, VALIDATION_ERROR_01411) {
9097 TEST_DESCRIPTION("Test VALIDATION_ERROR_01411: binding must be less than VkPhysicalDeviceLimits::maxVertexInputBindings");
9098
9099 ASSERT_NO_FATAL_FAILURE(Init());
9100 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9101
9102 VkPipelineCache pipeline_cache;
9103 {
9104 VkPipelineCacheCreateInfo create_info{};
9105 create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
9106
9107 VkResult err = vkCreatePipelineCache(m_device->device(), &create_info, nullptr, &pipeline_cache);
9108 ASSERT_VK_SUCCESS(err);
9109 }
9110
9111 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9112 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
9113
9114 VkPipelineShaderStageCreateInfo stages[2]{{}};
9115 stages[0] = vs.GetStageCreateInfo();
9116 stages[1] = fs.GetStageCreateInfo();
9117
9118 // Test when binding is greater than or equal to VkPhysicalDeviceLimits::maxVertexInputBindings.
9119 VkVertexInputAttributeDescription vertex_input_attribute_description{};
9120 vertex_input_attribute_description.binding = m_device->props.limits.maxVertexInputBindings;
9121
9122 VkPipelineVertexInputStateCreateInfo vertex_input_state{};
9123 vertex_input_state.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
9124 vertex_input_state.pNext = nullptr;
9125 vertex_input_state.vertexBindingDescriptionCount = 0;
9126 vertex_input_state.pVertexBindingDescriptions = nullptr;
9127 vertex_input_state.vertexAttributeDescriptionCount = 1;
9128 vertex_input_state.pVertexAttributeDescriptions = &vertex_input_attribute_description;
9129
9130 VkPipelineInputAssemblyStateCreateInfo input_assembly_state{};
9131 input_assembly_state.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
9132 input_assembly_state.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
9133
9134 VkViewport viewport{};
9135 VkPipelineViewportStateCreateInfo viewport_state{};
9136 viewport_state.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
9137 viewport_state.scissorCount = 1;
9138 viewport_state.viewportCount = 1;
9139 viewport_state.pViewports = &viewport;
9140
9141 VkPipelineMultisampleStateCreateInfo multisample_state{};
9142 multisample_state.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
9143 multisample_state.pNext = nullptr;
9144 multisample_state.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
9145 multisample_state.sampleShadingEnable = 0;
9146 multisample_state.minSampleShading = 1.0;
9147 multisample_state.pSampleMask = nullptr;
9148
9149 VkPipelineRasterizationStateCreateInfo rasterization_state{};
9150 rasterization_state.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
9151 rasterization_state.polygonMode = VK_POLYGON_MODE_FILL;
9152 rasterization_state.cullMode = VK_CULL_MODE_BACK_BIT;
9153 rasterization_state.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
9154 rasterization_state.depthClampEnable = VK_FALSE;
9155 rasterization_state.rasterizerDiscardEnable = VK_FALSE;
9156 rasterization_state.depthBiasEnable = VK_FALSE;
9157
9158 VkPipelineLayout pipeline_layout;
9159 {
9160 VkPipelineLayoutCreateInfo create_info{};
9161 create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9162 create_info.setLayoutCount = 0;
9163 create_info.pSetLayouts = nullptr;
9164
9165 VkResult err = vkCreatePipelineLayout(m_device->device(), &create_info, nullptr, &pipeline_layout);
9166 ASSERT_VK_SUCCESS(err);
9167 }
9168
9169 {
9170 VkGraphicsPipelineCreateInfo create_info{};
9171 create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
9172 create_info.stageCount = 2;
9173 create_info.pStages = stages;
9174 create_info.pVertexInputState = &vertex_input_state;
9175 create_info.pInputAssemblyState = &input_assembly_state;
9176 create_info.pViewportState = &viewport_state;
9177 create_info.pMultisampleState = &multisample_state;
9178 create_info.pRasterizationState = &rasterization_state;
9179 create_info.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
9180 create_info.layout = pipeline_layout;
9181 create_info.renderPass = renderPass();
9182
9183 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01411);
9184 VkPipeline pipeline;
9185 vkCreateGraphicsPipelines(m_device->device(), pipeline_cache, 1, &create_info, nullptr, &pipeline);
9186 m_errorMonitor->VerifyFound();
9187 }
9188
9189 vkDestroyPipelineCache(m_device->device(), pipeline_cache, nullptr);
9190 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
9191}
9192
9193TEST_F(VkLayerTest, VALIDATION_ERROR_01412) {
9194 TEST_DESCRIPTION(
9195 "Test VALIDATION_ERROR_01412: offset must be less than or equal to VkPhysicalDeviceLimits::maxVertexInputAttributeOffset");
9196
9197 ASSERT_NO_FATAL_FAILURE(Init());
9198 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9199
9200 VkPipelineCache pipeline_cache;
9201 {
9202 VkPipelineCacheCreateInfo create_info{};
9203 create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
9204
9205 VkResult err = vkCreatePipelineCache(m_device->device(), &create_info, nullptr, &pipeline_cache);
9206 ASSERT_VK_SUCCESS(err);
9207 }
9208
9209 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9210 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
9211
9212 VkPipelineShaderStageCreateInfo stages[2]{{}};
9213 stages[0] = vs.GetStageCreateInfo();
9214 stages[1] = fs.GetStageCreateInfo();
9215
9216 // Test when offset is greater than maximum.
9217 VkVertexInputAttributeDescription vertex_input_attribute_description{};
9218 vertex_input_attribute_description.offset = m_device->props.limits.maxVertexInputAttributeOffset + 1;
9219
9220 VkPipelineVertexInputStateCreateInfo vertex_input_state{};
9221 vertex_input_state.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
9222 vertex_input_state.pNext = nullptr;
9223 vertex_input_state.vertexBindingDescriptionCount = 0;
9224 vertex_input_state.pVertexBindingDescriptions = nullptr;
9225 vertex_input_state.vertexAttributeDescriptionCount = 1;
9226 vertex_input_state.pVertexAttributeDescriptions = &vertex_input_attribute_description;
9227
9228 VkPipelineInputAssemblyStateCreateInfo input_assembly_state{};
9229 input_assembly_state.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
9230 input_assembly_state.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
9231
9232 VkViewport viewport{};
9233 VkPipelineViewportStateCreateInfo viewport_state{};
9234 viewport_state.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
9235 viewport_state.scissorCount = 1;
9236 viewport_state.viewportCount = 1;
9237 viewport_state.pViewports = &viewport;
9238
9239 VkPipelineMultisampleStateCreateInfo multisample_state{};
9240 multisample_state.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
9241 multisample_state.pNext = nullptr;
9242 multisample_state.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
9243 multisample_state.sampleShadingEnable = 0;
9244 multisample_state.minSampleShading = 1.0;
9245 multisample_state.pSampleMask = nullptr;
9246
9247 VkPipelineRasterizationStateCreateInfo rasterization_state{};
9248 rasterization_state.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
9249 rasterization_state.polygonMode = VK_POLYGON_MODE_FILL;
9250 rasterization_state.cullMode = VK_CULL_MODE_BACK_BIT;
9251 rasterization_state.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
9252 rasterization_state.depthClampEnable = VK_FALSE;
9253 rasterization_state.rasterizerDiscardEnable = VK_FALSE;
9254 rasterization_state.depthBiasEnable = VK_FALSE;
9255
9256 VkPipelineLayout pipeline_layout;
9257 {
9258 VkPipelineLayoutCreateInfo create_info{};
9259 create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9260 create_info.setLayoutCount = 0;
9261 create_info.pSetLayouts = nullptr;
9262
9263 VkResult err = vkCreatePipelineLayout(m_device->device(), &create_info, nullptr, &pipeline_layout);
9264 ASSERT_VK_SUCCESS(err);
9265 }
9266
9267 {
9268 VkGraphicsPipelineCreateInfo create_info{};
9269 create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
9270 create_info.stageCount = 2;
9271 create_info.pStages = stages;
9272 create_info.pVertexInputState = &vertex_input_state;
9273 create_info.pInputAssemblyState = &input_assembly_state;
9274 create_info.pViewportState = &viewport_state;
9275 create_info.pMultisampleState = &multisample_state;
9276 create_info.pRasterizationState = &rasterization_state;
9277 create_info.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
9278 create_info.layout = pipeline_layout;
9279 create_info.renderPass = renderPass();
9280
9281 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01412);
9282 VkPipeline pipeline;
9283 vkCreateGraphicsPipelines(m_device->device(), pipeline_cache, 1, &create_info, nullptr, &pipeline);
9284 m_errorMonitor->VerifyFound();
9285 }
9286
9287 vkDestroyPipelineCache(m_device->device(), pipeline_cache, nullptr);
9288 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
9289}
9290
Karl Schultz6addd812016-02-02 17:17:23 -07009291TEST_F(VkLayerTest, NullRenderPass) {
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06009292 // Bind a NULL RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009293 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mike Schuchardt0b1f2f82016-12-28 15:11:20 -07009294 "vkCmdBeginRenderPass: required parameter pRenderPassBegin specified as NULL");
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06009295
Tony Barbour1fa09702017-03-16 12:09:08 -06009296 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06009297 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06009298
Tony Barbour552f6c02016-12-21 14:34:07 -07009299 m_commandBuffer->BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07009300 // Don't care about RenderPass handle b/c error should be flagged before
9301 // that
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009302 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06009303
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009304 m_errorMonitor->VerifyFound();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06009305}
9306
Karl Schultz6addd812016-02-02 17:17:23 -07009307TEST_F(VkLayerTest, RenderPassWithinRenderPass) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009308 // Bind a BeginRenderPass within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009309 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9310 "It is invalid to issue this call inside an active render pass");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009311
Tony Barbour1fa09702017-03-16 12:09:08 -06009312 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009313 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009314
Tony Barbour552f6c02016-12-21 14:34:07 -07009315 m_commandBuffer->BeginCommandBuffer();
9316 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Karl Schultz6addd812016-02-02 17:17:23 -07009317 // Just create a dummy Renderpass that's non-NULL so we can get to the
9318 // proper error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009319 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009320
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009321 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009322}
9323
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06009324TEST_F(VkLayerTest, RenderPassClearOpMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009325 TEST_DESCRIPTION(
9326 "Begin a renderPass where clearValueCount is less than"
9327 "the number of renderPass attachments that use loadOp"
9328 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06009329
Tony Barbour1fa09702017-03-16 12:09:08 -06009330 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06009331 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9332
9333 // Create a renderPass with a single attachment that uses loadOp CLEAR
9334 VkAttachmentReference attach = {};
9335 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
9336 VkSubpassDescription subpass = {};
Cort Stratton7547f772017-05-04 15:18:52 -07009337 subpass.colorAttachmentCount = 1;
9338 subpass.pColorAttachments = &attach;
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06009339 VkRenderPassCreateInfo rpci = {};
9340 rpci.subpassCount = 1;
9341 rpci.pSubpasses = &subpass;
9342 rpci.attachmentCount = 1;
9343 VkAttachmentDescription attach_desc = {};
Rene Lindsay4bf0e4c2017-01-31 14:20:34 -07009344 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06009345 // Set loadOp to CLEAR
9346 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
9347 rpci.pAttachments = &attach_desc;
9348 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
9349 VkRenderPass rp;
9350 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
9351
9352 VkCommandBufferInheritanceInfo hinfo = {};
9353 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
9354 hinfo.renderPass = VK_NULL_HANDLE;
9355 hinfo.subpass = 0;
9356 hinfo.framebuffer = VK_NULL_HANDLE;
9357 hinfo.occlusionQueryEnable = VK_FALSE;
9358 hinfo.queryFlags = 0;
9359 hinfo.pipelineStatistics = 0;
9360 VkCommandBufferBeginInfo info = {};
9361 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
9362 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
9363 info.pInheritanceInfo = &hinfo;
9364
9365 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
9366 VkRenderPassBeginInfo rp_begin = {};
9367 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
9368 rp_begin.pNext = NULL;
9369 rp_begin.renderPass = renderPass();
9370 rp_begin.framebuffer = framebuffer();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009371 rp_begin.clearValueCount = 0; // Should be 1
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06009372
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07009373 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00442);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06009374
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009375 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06009376
9377 m_errorMonitor->VerifyFound();
Mark Lobodzinski5c70ebd2016-06-09 13:45:00 -06009378
9379 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06009380}
9381
Cody Northrop3bb4d962016-05-09 16:15:57 -06009382TEST_F(VkLayerTest, EndCommandBufferWithinRenderPass) {
Cody Northrop3bb4d962016-05-09 16:15:57 -06009383 TEST_DESCRIPTION("End a command buffer with an active render pass");
9384
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009385 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9386 "It is invalid to issue this call inside an active render pass");
Cody Northrop3bb4d962016-05-09 16:15:57 -06009387
Tony Barbour1fa09702017-03-16 12:09:08 -06009388 ASSERT_NO_FATAL_FAILURE(Init());
Cody Northrop3bb4d962016-05-09 16:15:57 -06009389 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9390
Tony Barbour552f6c02016-12-21 14:34:07 -07009391 m_commandBuffer->BeginCommandBuffer();
9392 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
9393 vkEndCommandBuffer(m_commandBuffer->handle());
Cody Northrop3bb4d962016-05-09 16:15:57 -06009394
9395 m_errorMonitor->VerifyFound();
9396
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009397 // TODO: Add test for VK_COMMAND_BUFFER_LEVEL_SECONDARY
9398 // TODO: Add test for VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT
Cody Northrop3bb4d962016-05-09 16:15:57 -06009399}
9400
Karl Schultz6addd812016-02-02 17:17:23 -07009401TEST_F(VkLayerTest, FillBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009402 // Call CmdFillBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009403 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9404 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009405
Tony Barbour1fa09702017-03-16 12:09:08 -06009406 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009407 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009408
Tony Barbour552f6c02016-12-21 14:34:07 -07009409 m_commandBuffer->BeginCommandBuffer();
9410 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009411
9412 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009413 vk_testing::Buffer dstBuffer;
9414 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009415
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009416 m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009417
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009418 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009419}
9420
Karl Schultz6addd812016-02-02 17:17:23 -07009421TEST_F(VkLayerTest, UpdateBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009422 // Call CmdUpdateBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009423 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9424 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009425
Tony Barbour1fa09702017-03-16 12:09:08 -06009426 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009427 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009428
Tony Barbour552f6c02016-12-21 14:34:07 -07009429 m_commandBuffer->BeginCommandBuffer();
9430 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009431
9432 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009433 vk_testing::Buffer dstBuffer;
9434 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009435
Karl Schultz6addd812016-02-02 17:17:23 -07009436 VkDeviceSize dstOffset = 0;
Rene Lindsay32d26902017-02-02 16:49:24 -07009437 uint32_t Data[] = {1, 2, 3, 4, 5, 6, 7, 8};
9438 VkDeviceSize dataSize = sizeof(Data) / sizeof(uint32_t);
9439 vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(), dstOffset, dataSize, &Data);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009440
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009441 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009442}
9443
Petr Kraus4d718682017-05-18 03:38:41 +02009444TEST_F(VkLayerTest, ClearColorImageWithBadRange) {
9445 TEST_DESCRIPTION("Record clear color with an invalid VkImageSubresourceRange");
9446
9447 ASSERT_NO_FATAL_FAILURE(Init());
9448 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9449
9450 VkImageObj image(m_device);
9451 image.Init(32, 32, 1, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_OPTIMAL);
9452 ASSERT_TRUE(image.create_info().arrayLayers == 1);
9453 ASSERT_TRUE(image.initialized());
9454 image.SetLayout(VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
9455
9456 const VkClearColorValue clear_color = {{0.0f, 0.0f, 0.0f, 1.0f}};
9457
9458 m_commandBuffer->BeginCommandBuffer();
9459 const auto cb_handle = m_commandBuffer->GetBufferHandle();
9460
9461 // Try levelCount = 0
9462 {
9463 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
9464 const VkImageSubresourceRange range = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 0, 1};
9465 vkCmdClearColorImage(cb_handle, image.handle(), image.Layout(), &clear_color, 1, &range);
9466 m_errorMonitor->VerifyFound();
9467 }
9468
9469 // Try baseLevel + levelCount > image.mipLevels
9470 {
9471 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
9472 const VkImageSubresourceRange range = {VK_IMAGE_ASPECT_COLOR_BIT, 1, 1, 0, 1};
9473 vkCmdClearColorImage(cb_handle, image.handle(), image.Layout(), &clear_color, 1, &range);
9474 m_errorMonitor->VerifyFound();
9475 }
9476
9477 // Try baseLevel >= image.mipLevels with VK_REMAINING_MIP_LEVELS
9478 {
9479 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9480 "vkCmdClearColorImage: pRanges[0].baseMipLevel (= 1) is greater or equal to the mip "
9481 "level count of the image (i.e. greater or equal to 1).");
9482 const VkImageSubresourceRange range = {VK_IMAGE_ASPECT_COLOR_BIT, 1, VK_REMAINING_MIP_LEVELS, 0, 1};
9483 vkCmdClearColorImage(cb_handle, image.handle(), image.Layout(), &clear_color, 1, &range);
9484 m_errorMonitor->VerifyFound();
9485 }
9486
9487 // Try layerCount = 0
9488 {
9489 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02931);
9490 const VkImageSubresourceRange range = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 0};
9491 vkCmdClearColorImage(cb_handle, image.handle(), image.Layout(), &clear_color, 1, &range);
9492 m_errorMonitor->VerifyFound();
9493 }
9494
9495 // Try baseLayer + layerCount > image.arrayLayers
9496 {
9497 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02931);
9498 const VkImageSubresourceRange range = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 1, 1};
9499 vkCmdClearColorImage(cb_handle, image.handle(), image.Layout(), &clear_color, 1, &range);
9500 m_errorMonitor->VerifyFound();
9501 }
9502
9503 // Try baseLevel >= image.mipLevels with VK_REMAINING_ARRAY_LAYERS
9504 {
9505 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9506 "vkCmdClearColorImage: pRanges[0].baseArrayLayer (= 1) is greater or equal to the "
9507 "arrayLayers of the image when it was created (i.e. greater or equal to 1).");
9508 const VkImageSubresourceRange range = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 1, VK_REMAINING_ARRAY_LAYERS};
9509 vkCmdClearColorImage(cb_handle, image.handle(), image.Layout(), &clear_color, 1, &range);
9510 m_errorMonitor->VerifyFound();
9511 }
9512}
9513
9514TEST_F(VkLayerTest, ClearDepthStencilWithBadRange) {
9515 TEST_DESCRIPTION("Record clear depth with an invalid VkImageSubresourceRange");
9516
9517 ASSERT_NO_FATAL_FAILURE(Init());
9518 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9519
9520 const auto depth_format = FindSupportedDepthStencilFormat(gpu());
9521 if (!depth_format) {
9522 printf(" No Depth + Stencil format found. Skipped.\n");
9523 return;
9524 }
9525
9526 VkImageObj image(m_device);
9527 image.Init(32, 32, 1, depth_format, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_OPTIMAL);
9528 ASSERT_TRUE(image.create_info().arrayLayers == 1);
9529 ASSERT_TRUE(image.initialized());
9530 const VkImageAspectFlags ds_aspect = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
9531 image.SetLayout(ds_aspect, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
9532
9533 const VkClearDepthStencilValue clear_value = {};
9534
9535 m_commandBuffer->BeginCommandBuffer();
9536 const auto cb_handle = m_commandBuffer->GetBufferHandle();
9537
9538 // Try levelCount = 0
9539 {
9540 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
9541 const VkImageSubresourceRange range = {ds_aspect, 0, 0, 0, 1};
9542 vkCmdClearDepthStencilImage(cb_handle, image.handle(), image.Layout(), &clear_value, 1, &range);
9543 m_errorMonitor->VerifyFound();
9544 }
9545
9546 // Try baseLevel + levelCount > image.mipLevels
9547 {
9548 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
9549 const VkImageSubresourceRange range = {ds_aspect, 1, 1, 0, 1};
9550 vkCmdClearDepthStencilImage(cb_handle, image.handle(), image.Layout(), &clear_value, 1, &range);
9551 m_errorMonitor->VerifyFound();
9552 }
9553
9554 // Try baseLevel >= image.mipLevels with VK_REMAINING_MIP_LEVELS
9555 {
9556 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9557 "vkCmdClearDepthStencilImage: pRanges[0].baseMipLevel (= 1) is greater or equal to "
9558 "the mip level count of the image (i.e. greater or equal to 1).");
9559 const VkImageSubresourceRange range = {ds_aspect, 1, VK_REMAINING_MIP_LEVELS, 0, 1};
9560 vkCmdClearDepthStencilImage(cb_handle, image.handle(), image.Layout(), &clear_value, 1, &range);
9561 m_errorMonitor->VerifyFound();
9562 }
9563
9564 // Try layerCount = 0
9565 {
9566 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02931);
9567 const VkImageSubresourceRange range = {ds_aspect, 0, 1, 0, 0};
9568 vkCmdClearDepthStencilImage(cb_handle, image.handle(), image.Layout(), &clear_value, 1, &range);
9569 m_errorMonitor->VerifyFound();
9570 }
9571
9572 // Try baseLayer + layerCount > image.arrayLayers
9573 {
9574 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02931);
9575 const VkImageSubresourceRange range = {ds_aspect, 0, 1, 1, 1};
9576 vkCmdClearDepthStencilImage(cb_handle, image.handle(), image.Layout(), &clear_value, 1, &range);
9577 m_errorMonitor->VerifyFound();
9578 }
9579
9580 // Try baseLevel >= image.mipLevels with VK_REMAINING_ARRAY_LAYERS
9581 {
9582 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9583 "vkCmdClearDepthStencilImage: pRanges[0].baseArrayLayer (= 1) is greater or equal to "
9584 "the arrayLayers of the image when it was created (i.e. greater or equal to 1).");
9585 const VkImageSubresourceRange range = {ds_aspect, 0, 1, 1, VK_REMAINING_ARRAY_LAYERS};
9586 vkCmdClearDepthStencilImage(cb_handle, image.handle(), image.Layout(), &clear_value, 1, &range);
9587 m_errorMonitor->VerifyFound();
9588 }
9589}
9590
Karl Schultz6addd812016-02-02 17:17:23 -07009591TEST_F(VkLayerTest, ClearColorImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009592 // Call CmdClearColorImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009593 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9594 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009595
Tony Barbour1fa09702017-03-16 12:09:08 -06009596 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009597 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009598
Tony Barbour552f6c02016-12-21 14:34:07 -07009599 m_commandBuffer->BeginCommandBuffer();
9600 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009601
Michael Lentine0a369f62016-02-03 16:51:46 -06009602 VkClearColorValue clear_color;
9603 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
Karl Schultz6addd812016-02-02 17:17:23 -07009604 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
9605 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
9606 const int32_t tex_width = 32;
9607 const int32_t tex_height = 32;
9608 VkImageCreateInfo image_create_info = {};
9609 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
9610 image_create_info.pNext = NULL;
9611 image_create_info.imageType = VK_IMAGE_TYPE_2D;
9612 image_create_info.format = tex_format;
9613 image_create_info.extent.width = tex_width;
9614 image_create_info.extent.height = tex_height;
9615 image_create_info.extent.depth = 1;
9616 image_create_info.mipLevels = 1;
9617 image_create_info.arrayLayers = 1;
9618 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
9619 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
Jeremy Hayesa3d5c7b2017-03-07 16:01:52 -07009620 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009621
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009622 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009623 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009624
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009625 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009626
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009627 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009628
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009629 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009630}
9631
Karl Schultz6addd812016-02-02 17:17:23 -07009632TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009633 // Call CmdClearDepthStencilImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009634 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9635 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009636
Tony Barbour1fa09702017-03-16 12:09:08 -06009637 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009638 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009639
Dave Houlton1d2022c2017-03-29 11:43:58 -06009640 auto depth_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbourf887b162017-03-09 10:06:46 -07009641 if (!depth_format) {
9642 printf(" No Depth + Stencil format found. Skipped.\n");
9643 return;
9644 }
9645
Tony Barbour552f6c02016-12-21 14:34:07 -07009646 m_commandBuffer->BeginCommandBuffer();
9647 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009648
9649 VkClearDepthStencilValue clear_value = {0};
Dustin Gravesa2e5c942016-02-11 18:28:06 -07009650 VkMemoryPropertyFlags reqs = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07009651 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
9652 image_create_info.imageType = VK_IMAGE_TYPE_2D;
Tony Barbourf887b162017-03-09 10:06:46 -07009653 image_create_info.format = depth_format;
Karl Schultz6addd812016-02-02 17:17:23 -07009654 image_create_info.extent.width = 64;
9655 image_create_info.extent.height = 64;
9656 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
9657 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009658
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009659 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009660 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009661
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009662 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009663
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07009664 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_value, 1,
9665 &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009666
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009667 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009668}
9669
Karl Schultz6addd812016-02-02 17:17:23 -07009670TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass) {
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06009671 // Call CmdClearAttachmentss outside of an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07009672 VkResult err;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009673
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009674 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9675 "vkCmdClearAttachments(): This call "
9676 "must be issued inside an active "
9677 "render pass");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009678
Tony Barbour1fa09702017-03-16 12:09:08 -06009679 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009680 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009681
9682 // Start no RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009683 err = m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009684 ASSERT_VK_SUCCESS(err);
9685
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06009686 VkClearAttachment color_attachment;
9687 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9688 color_attachment.clearValue.color.float32[0] = 0;
9689 color_attachment.clearValue.color.float32[1] = 0;
9690 color_attachment.clearValue.color.float32[2] = 0;
9691 color_attachment.clearValue.color.float32[3] = 0;
9692 color_attachment.colorAttachment = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07009693 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009694 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009695
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009696 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009697}
9698
Chris Forbes3b97e932016-09-07 11:29:24 +12009699TEST_F(VkLayerTest, RenderPassExcessiveNextSubpass) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009700 TEST_DESCRIPTION(
9701 "Test that an error is produced when CmdNextSubpass is "
9702 "called too many times in a renderpass instance");
Chris Forbes3b97e932016-09-07 11:29:24 +12009703
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009704 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9705 "vkCmdNextSubpass(): Attempted to advance "
9706 "beyond final subpass");
Chris Forbes3b97e932016-09-07 11:29:24 +12009707
Tony Barbour1fa09702017-03-16 12:09:08 -06009708 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes3b97e932016-09-07 11:29:24 +12009709 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9710
Tony Barbour552f6c02016-12-21 14:34:07 -07009711 m_commandBuffer->BeginCommandBuffer();
9712 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes3b97e932016-09-07 11:29:24 +12009713
9714 // error here.
9715 vkCmdNextSubpass(m_commandBuffer->GetBufferHandle(), VK_SUBPASS_CONTENTS_INLINE);
9716 m_errorMonitor->VerifyFound();
9717
Tony Barbour552f6c02016-12-21 14:34:07 -07009718 m_commandBuffer->EndRenderPass();
9719 m_commandBuffer->EndCommandBuffer();
Chris Forbes3b97e932016-09-07 11:29:24 +12009720}
9721
Chris Forbes6d624702016-09-07 13:57:05 +12009722TEST_F(VkLayerTest, RenderPassEndedBeforeFinalSubpass) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009723 TEST_DESCRIPTION(
9724 "Test that an error is produced when CmdEndRenderPass is "
9725 "called before the final subpass has been reached");
Chris Forbes6d624702016-09-07 13:57:05 +12009726
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009727 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9728 "vkCmdEndRenderPass(): Called before reaching "
9729 "final subpass");
Chris Forbes6d624702016-09-07 13:57:05 +12009730
Tony Barbour1fa09702017-03-16 12:09:08 -06009731 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009732 VkSubpassDescription sd[2] = {{0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr},
9733 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr}};
Chris Forbes6d624702016-09-07 13:57:05 +12009734
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009735 VkRenderPassCreateInfo rcpi = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 2, sd, 0, nullptr};
Chris Forbes6d624702016-09-07 13:57:05 +12009736
9737 VkRenderPass rp;
9738 VkResult err = vkCreateRenderPass(m_device->device(), &rcpi, nullptr, &rp);
9739 ASSERT_VK_SUCCESS(err);
9740
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009741 VkFramebufferCreateInfo fbci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 16, 16, 1};
Chris Forbes6d624702016-09-07 13:57:05 +12009742
9743 VkFramebuffer fb;
9744 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
9745 ASSERT_VK_SUCCESS(err);
9746
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009747 m_commandBuffer->BeginCommandBuffer(); // no implicit RP begin
Chris Forbes6d624702016-09-07 13:57:05 +12009748
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009749 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 +12009750
9751 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
9752
9753 // Error here.
9754 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
9755 m_errorMonitor->VerifyFound();
9756
9757 // Clean up.
9758 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
9759 vkDestroyRenderPass(m_device->device(), rp, nullptr);
9760}
9761
Karl Schultz9e66a292016-04-21 15:57:51 -06009762TEST_F(VkLayerTest, BufferMemoryBarrierNoBuffer) {
9763 // Try to add a buffer memory barrier with no buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009764 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9765 "required parameter pBufferMemoryBarriers[0].buffer specified as VK_NULL_HANDLE");
Karl Schultz9e66a292016-04-21 15:57:51 -06009766
Tony Barbour1fa09702017-03-16 12:09:08 -06009767 ASSERT_NO_FATAL_FAILURE(Init());
Tony Barbour552f6c02016-12-21 14:34:07 -07009768 m_commandBuffer->BeginCommandBuffer();
Karl Schultz9e66a292016-04-21 15:57:51 -06009769
9770 VkBufferMemoryBarrier buf_barrier = {};
9771 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
9772 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
9773 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
9774 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
9775 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
9776 buf_barrier.buffer = VK_NULL_HANDLE;
9777 buf_barrier.offset = 0;
9778 buf_barrier.size = VK_WHOLE_SIZE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009779 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9780 nullptr, 1, &buf_barrier, 0, nullptr);
Karl Schultz9e66a292016-04-21 15:57:51 -06009781
9782 m_errorMonitor->VerifyFound();
9783}
9784
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009785TEST_F(VkLayerTest, InvalidBarriers) {
9786 TEST_DESCRIPTION("A variety of ways to get VK_INVALID_BARRIER ");
9787
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009788 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Barriers cannot be set during subpass");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009789
Tony Barbour1fa09702017-03-16 12:09:08 -06009790 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -06009791 auto depth_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbourf887b162017-03-09 10:06:46 -07009792 if (!depth_format) {
9793 printf(" No Depth + Stencil format found. Skipped.\n");
9794 return;
9795 }
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009796 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9797
9798 VkMemoryBarrier mem_barrier = {};
9799 mem_barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER;
9800 mem_barrier.pNext = NULL;
9801 mem_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
9802 mem_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
Tony Barbour552f6c02016-12-21 14:34:07 -07009803 m_commandBuffer->BeginCommandBuffer();
9804 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009805 // BeginCommandBuffer() starts a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009806 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 1,
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009807 &mem_barrier, 0, nullptr, 0, nullptr);
9808 m_errorMonitor->VerifyFound();
9809
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009810 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image Layout cannot be transitioned to UNDEFINED");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009811 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06009812 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 -06009813 ASSERT_TRUE(image.initialized());
9814 VkImageMemoryBarrier img_barrier = {};
9815 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
9816 img_barrier.pNext = NULL;
9817 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
9818 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
Mark Lobodzinski95512b72017-05-10 12:21:30 -06009819 img_barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009820 // New layout can't be UNDEFINED
9821 img_barrier.newLayout = VK_IMAGE_LAYOUT_UNDEFINED;
9822 img_barrier.image = image.handle();
9823 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
9824 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
9825 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9826 img_barrier.subresourceRange.baseArrayLayer = 0;
9827 img_barrier.subresourceRange.baseMipLevel = 0;
9828 img_barrier.subresourceRange.layerCount = 1;
9829 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009830 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9831 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009832 m_errorMonitor->VerifyFound();
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009833
Mark Lobodzinski95512b72017-05-10 12:21:30 -06009834 // Transition image to color attachment optimal
9835 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
9836 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
9837 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9838 nullptr, 0, nullptr, 1, &img_barrier);
9839 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinski95512b72017-05-10 12:21:30 -06009840
Mark Lobodzinski45daf6e2017-05-10 13:19:02 -06009841 // Try to change layout in a renderpass
9842 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02080);
9843 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9844 nullptr, 0, nullptr, 1, &img_barrier);
9845 m_errorMonitor->VerifyFound();
9846
9847 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
Petr Kraus4d718682017-05-18 03:38:41 +02009848 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02931);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009849 // baseArrayLayer + layerCount must be <= image's arrayLayers
9850 img_barrier.subresourceRange.baseArrayLayer = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009851 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9852 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009853 m_errorMonitor->VerifyFound();
9854 img_barrier.subresourceRange.baseArrayLayer = 0;
9855
Petr Kraus4d718682017-05-18 03:38:41 +02009856 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009857 // baseMipLevel + levelCount must be <= image's mipLevels
9858 img_barrier.subresourceRange.baseMipLevel = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009859 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9860 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009861 m_errorMonitor->VerifyFound();
9862 img_barrier.subresourceRange.baseMipLevel = 0;
9863
Mike Weiblen7053aa32017-01-25 15:21:10 -07009864 // levelCount must be non-zero.
9865 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
9866 img_barrier.subresourceRange.levelCount = 0;
9867 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9868 nullptr, 0, nullptr, 1, &img_barrier);
9869 m_errorMonitor->VerifyFound();
9870 img_barrier.subresourceRange.levelCount = 1;
9871
9872 // layerCount must be non-zero.
Petr Kraus4d718682017-05-18 03:38:41 +02009873 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02931);
Mike Weiblen7053aa32017-01-25 15:21:10 -07009874 img_barrier.subresourceRange.layerCount = 0;
9875 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9876 nullptr, 0, nullptr, 1, &img_barrier);
9877 m_errorMonitor->VerifyFound();
9878 img_barrier.subresourceRange.layerCount = 1;
9879
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009880 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 -06009881 vk_testing::Buffer buffer;
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07009882 VkMemoryPropertyFlags mem_reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
9883 buffer.init_as_src_and_dst(*m_device, 256, mem_reqs);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009884 VkBufferMemoryBarrier buf_barrier = {};
9885 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
9886 buf_barrier.pNext = NULL;
9887 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
9888 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
9889 buf_barrier.buffer = buffer.handle();
9890 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
9891 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
9892 buf_barrier.offset = 0;
9893 buf_barrier.size = VK_WHOLE_SIZE;
9894 // Can't send buffer barrier during a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009895 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9896 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009897 m_errorMonitor->VerifyFound();
9898 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
9899
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009900 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which is not less than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009901 buf_barrier.offset = 257;
9902 // Offset greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009903 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9904 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009905 m_errorMonitor->VerifyFound();
9906 buf_barrier.offset = 0;
9907
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009908 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "whose sum is greater than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009909 buf_barrier.size = 257;
9910 // Size greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009911 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9912 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009913 m_errorMonitor->VerifyFound();
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009914
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009915 // Now exercise barrier aspect bit errors, first DS
Tobin Ehlis99ab0d22017-04-26 16:53:52 -06009916 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00741);
9917 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00302);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009918 VkDepthStencilObj ds_image(m_device);
Tony Barbourf887b162017-03-09 10:06:46 -07009919 ds_image.Init(m_device, 128, 128, depth_format);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009920 ASSERT_TRUE(ds_image.initialized());
Tobin Ehlis15684a02016-07-21 14:55:26 -06009921 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
9922 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009923 img_barrier.image = ds_image.handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07009924
9925 // Not having DEPTH or STENCIL set is an error
Rene Lindsay4834cba2017-02-02 17:18:56 -07009926 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009927 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9928 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009929 m_errorMonitor->VerifyFound();
Dave Houltonfbf52152017-01-06 12:55:29 -07009930
Tobin Ehlis99ab0d22017-04-26 16:53:52 -06009931 // Having only one of depth or stencil set for DS image is an error
9932 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00302);
9933 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT;
9934 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9935 nullptr, 0, nullptr, 1, &img_barrier);
9936 m_errorMonitor->VerifyFound();
9937
9938 // Having anything other than DEPTH and STENCIL is an error
9939 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00741);
Dave Houltonfbf52152017-01-06 12:55:29 -07009940 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT | VK_IMAGE_ASPECT_COLOR_BIT;
9941 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9942 nullptr, 0, nullptr, 1, &img_barrier);
9943 m_errorMonitor->VerifyFound();
9944
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009945 // Now test depth-only
9946 VkFormatProperties format_props;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009947 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D16_UNORM, &format_props);
9948 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009949 VkDepthStencilObj d_image(m_device);
9950 d_image.Init(m_device, 128, 128, VK_FORMAT_D16_UNORM);
9951 ASSERT_TRUE(d_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009952 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06009953 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009954 img_barrier.image = d_image.handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07009955
9956 // DEPTH bit must be set
9957 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9958 "Depth-only image formats must have the VK_IMAGE_ASPECT_DEPTH_BIT set.");
Rene Lindsay4834cba2017-02-02 17:18:56 -07009959 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Dave Houltonfbf52152017-01-06 12:55:29 -07009960 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
9961 0, nullptr, 0, nullptr, 1, &img_barrier);
9962 m_errorMonitor->VerifyFound();
9963
9964 // No bits other than DEPTH may be set
9965 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9966 "Depth-only image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT set.");
9967 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009968 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
9969 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009970 m_errorMonitor->VerifyFound();
9971 }
Dave Houltonfbf52152017-01-06 12:55:29 -07009972
9973 // Now test stencil-only
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009974 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_S8_UINT, &format_props);
9975 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009976 VkDepthStencilObj s_image(m_device);
9977 s_image.Init(m_device, 128, 128, VK_FORMAT_S8_UINT);
9978 ASSERT_TRUE(s_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009979 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06009980 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009981 img_barrier.image = s_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06009982 // Use of COLOR aspect on depth image is error
Dave Houltonf3229d52017-02-21 15:59:08 -07009983 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9984 "Stencil-only image formats must have the VK_IMAGE_ASPECT_STENCIL_BIT set.");
Tobin Ehlis15684a02016-07-21 14:55:26 -06009985 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009986 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
9987 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009988 m_errorMonitor->VerifyFound();
9989 }
Dave Houltonfbf52152017-01-06 12:55:29 -07009990
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009991 // Finally test color
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009992 VkImageObj c_image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06009993 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 -06009994 ASSERT_TRUE(c_image.initialized());
9995 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
9996 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
9997 img_barrier.image = c_image.handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07009998
9999 // COLOR bit must be set
10000 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10001 "Color image formats must have the VK_IMAGE_ASPECT_COLOR_BIT set.");
Rene Lindsay4834cba2017-02-02 17:18:56 -070010002 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Dave Houltonfbf52152017-01-06 12:55:29 -070010003 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10004 nullptr, 0, nullptr, 1, &img_barrier);
10005 m_errorMonitor->VerifyFound();
10006
10007 // No bits other than COLOR may be set
10008 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10009 "Color image formats must have ONLY the VK_IMAGE_ASPECT_COLOR_BIT set.");
10010 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010011 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10012 nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010013 m_errorMonitor->VerifyFound();
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -070010014
Mike Weiblene6e01172017-03-07 22:18:40 -070010015 // A barrier's new and old VkImageLayout must be compatible with an image's VkImageUsageFlags.
10016 {
10017 VkImageObj img_color(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060010018 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 -070010019 ASSERT_TRUE(img_color.initialized());
10020
10021 VkImageObj img_ds(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060010022 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 -070010023 ASSERT_TRUE(img_ds.initialized());
10024
10025 VkImageObj img_xfer_src(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060010026 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 -070010027 ASSERT_TRUE(img_xfer_src.initialized());
10028
10029 VkImageObj img_xfer_dst(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060010030 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 -070010031 ASSERT_TRUE(img_xfer_dst.initialized());
10032
10033 VkImageObj img_sampled(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060010034 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 -070010035 ASSERT_TRUE(img_sampled.initialized());
10036
10037 VkImageObj img_input(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060010038 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 -070010039 ASSERT_TRUE(img_input.initialized());
10040
10041 const struct {
10042 VkImageObj &image_obj;
10043 VkImageLayout bad_layout;
10044 UNIQUE_VALIDATION_ERROR_CODE msg_code;
10045 } bad_buffer_layouts[] = {
10046 // clang-format off
10047 // images _without_ VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT
10048 {img_ds, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VALIDATION_ERROR_00303},
10049 {img_xfer_src, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VALIDATION_ERROR_00303},
10050 {img_xfer_dst, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VALIDATION_ERROR_00303},
10051 {img_sampled, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VALIDATION_ERROR_00303},
10052 {img_input, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VALIDATION_ERROR_00303},
10053 // images _without_ VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT
10054 {img_color, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, VALIDATION_ERROR_00304},
10055 {img_xfer_src, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, VALIDATION_ERROR_00304},
10056 {img_xfer_dst, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, VALIDATION_ERROR_00304},
10057 {img_sampled, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, VALIDATION_ERROR_00304},
10058 {img_input, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, VALIDATION_ERROR_00304},
10059 {img_color, VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL, VALIDATION_ERROR_00305},
10060 {img_xfer_src, VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL, VALIDATION_ERROR_00305},
10061 {img_xfer_dst, VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL, VALIDATION_ERROR_00305},
10062 {img_sampled, VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL, VALIDATION_ERROR_00305},
10063 {img_input, VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL, VALIDATION_ERROR_00305},
10064 // images _without_ VK_IMAGE_USAGE_SAMPLED_BIT or VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT
10065 {img_color, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VALIDATION_ERROR_00306},
10066 {img_ds, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VALIDATION_ERROR_00306},
10067 {img_xfer_src, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VALIDATION_ERROR_00306},
10068 {img_xfer_dst, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VALIDATION_ERROR_00306},
10069 // images _without_ VK_IMAGE_USAGE_TRANSFER_SRC_BIT
10070 {img_color, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VALIDATION_ERROR_00307},
10071 {img_ds, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VALIDATION_ERROR_00307},
10072 {img_xfer_dst, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VALIDATION_ERROR_00307},
10073 {img_sampled, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VALIDATION_ERROR_00307},
10074 {img_input, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VALIDATION_ERROR_00307},
10075 // images _without_ VK_IMAGE_USAGE_TRANSFER_DST_BIT
10076 {img_color, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VALIDATION_ERROR_00308},
10077 {img_ds, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VALIDATION_ERROR_00308},
10078 {img_xfer_src, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VALIDATION_ERROR_00308},
10079 {img_sampled, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VALIDATION_ERROR_00308},
10080 {img_input, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VALIDATION_ERROR_00308},
10081 // clang-format on
10082 };
10083 const uint32_t layout_count = sizeof(bad_buffer_layouts) / sizeof(bad_buffer_layouts[0]);
10084
10085 for (uint32_t i = 0; i < layout_count; ++i) {
10086 img_barrier.image = bad_buffer_layouts[i].image_obj.handle();
10087 const VkImageUsageFlags usage = bad_buffer_layouts[i].image_obj.usage();
10088 img_barrier.subresourceRange.aspectMask = (usage == VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT)
10089 ? (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)
10090 : VK_IMAGE_ASPECT_COLOR_BIT;
10091
10092 img_barrier.oldLayout = bad_buffer_layouts[i].bad_layout;
10093 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
10094 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_buffer_layouts[i].msg_code);
10095 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT,
10096 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0, nullptr, 1, &img_barrier);
10097 m_errorMonitor->VerifyFound();
10098
10099 img_barrier.oldLayout = VK_IMAGE_LAYOUT_GENERAL;
10100 img_barrier.newLayout = bad_buffer_layouts[i].bad_layout;
10101 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_buffer_layouts[i].msg_code);
10102 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT,
10103 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0, nullptr, 1, &img_barrier);
10104 m_errorMonitor->VerifyFound();
10105 }
10106
10107 img_barrier.oldLayout = VK_IMAGE_LAYOUT_GENERAL;
10108 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
10109 }
10110
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -070010111 // Attempt to mismatch barriers/waitEvents calls with incompatible queues
10112
10113 // Create command pool with incompatible queueflags
10114 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
Mike Schuchardt06304c22017-03-01 17:09:09 -070010115 uint32_t queue_family_index = m_device->QueueFamilyWithoutCapabilities(VK_QUEUE_COMPUTE_BIT);
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -070010116 if (queue_family_index == UINT32_MAX) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070010117 printf(" No non-compute queue found; skipped.\n");
Mike Weiblene6e01172017-03-07 22:18:40 -070010118 return; // NOTE: this exits the test function!
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -070010119 }
10120 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02513);
10121
10122 VkCommandPool command_pool;
10123 VkCommandPoolCreateInfo pool_create_info{};
10124 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
10125 pool_create_info.queueFamilyIndex = queue_family_index;
10126 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
10127 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
10128
10129 // Allocate a command buffer
10130 VkCommandBuffer bad_command_buffer;
10131 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
10132 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
10133 command_buffer_allocate_info.commandPool = command_pool;
10134 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
10135 command_buffer_allocate_info.commandBufferCount = 1;
10136 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &bad_command_buffer));
10137
10138 VkCommandBufferBeginInfo cbbi = {};
10139 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
10140 vkBeginCommandBuffer(bad_command_buffer, &cbbi);
10141 buf_barrier.offset = 0;
10142 buf_barrier.size = VK_WHOLE_SIZE;
10143 vkCmdPipelineBarrier(bad_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1,
10144 &buf_barrier, 0, nullptr);
10145 m_errorMonitor->VerifyFound();
10146
10147 if ((queue_props[queue_family_index].queueFlags & VK_QUEUE_GRAPHICS_BIT) == 0) {
10148 vkEndCommandBuffer(bad_command_buffer);
10149 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070010150 printf(" The non-compute queue does not support graphics; skipped.\n");
Mike Weiblene6e01172017-03-07 22:18:40 -070010151 return; // NOTE: this exits the test function!
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -070010152 }
10153 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02510);
10154 VkEvent event;
10155 VkEventCreateInfo event_create_info{};
10156 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
10157 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
10158 vkCmdWaitEvents(bad_command_buffer, 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, nullptr, 0,
10159 nullptr, 0, nullptr);
10160 m_errorMonitor->VerifyFound();
10161
10162 vkEndCommandBuffer(bad_command_buffer);
10163 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010164}
10165
Chris Forbes50223732017-05-01 09:43:35 -070010166TEST_F(VkPositiveLayerTest, LayoutFromPresentWithoutAccessMemoryRead) {
10167 // Transition an image away from PRESENT_SRC_KHR without ACCESS_MEMORY_READ
10168 // in srcAccessMask.
Tony Barbour18ba25c2016-09-29 13:42:40 -060010169
Chris Forbes50223732017-05-01 09:43:35 -070010170 // The required behavior here was a bit unclear in earlier versions of the
10171 // spec, but there is no memory dependency required here, so this should
10172 // work without warnings.
10173
10174 m_errorMonitor->ExpectSuccess();
Tony Barbour1fa09702017-03-16 12:09:08 -060010175 ASSERT_NO_FATAL_FAILURE(Init());
Tony Barbour18ba25c2016-09-29 13:42:40 -060010176 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060010177 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 -070010178 VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbour18ba25c2016-09-29 13:42:40 -060010179 ASSERT_TRUE(image.initialized());
10180
10181 VkImageMemoryBarrier barrier = {};
10182 VkImageSubresourceRange range;
10183 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
Tony Barbour18ba25c2016-09-29 13:42:40 -060010184 barrier.srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
Chris Forbes50223732017-05-01 09:43:35 -070010185 barrier.dstAccessMask = 0;
Tony Barbour18ba25c2016-09-29 13:42:40 -060010186 barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10187 barrier.newLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
10188 barrier.image = image.handle();
10189 range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10190 range.baseMipLevel = 0;
10191 range.levelCount = 1;
10192 range.baseArrayLayer = 0;
10193 range.layerCount = 1;
10194 barrier.subresourceRange = range;
10195 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
10196 cmdbuf.BeginCommandBuffer();
10197 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
10198 &barrier);
10199 barrier.oldLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
10200 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
10201 barrier.srcAccessMask = 0;
10202 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
10203 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
10204 &barrier);
10205
Chris Forbes50223732017-05-01 09:43:35 -070010206 m_errorMonitor->VerifyNotFound();
Tony Barbour18ba25c2016-09-29 13:42:40 -060010207}
10208
Karl Schultz6addd812016-02-02 17:17:23 -070010209TEST_F(VkLayerTest, IdxBufferAlignmentError) {
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010210 // Bind a BeginRenderPass within an active RenderPass
Tony Barbour1fa09702017-03-16 12:09:08 -060010211 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010212 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010213
Jeremy Hayes483d95d2017-03-08 11:03:01 -070010214 uint32_t const indices[] = {0};
10215 VkBufferCreateInfo buf_info = {};
10216 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
10217 buf_info.size = 1024;
10218 buf_info.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
10219 buf_info.queueFamilyIndexCount = 1;
10220 buf_info.pQueueFamilyIndices = indices;
10221
10222 VkBuffer buffer;
10223 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
10224 ASSERT_VK_SUCCESS(err);
10225
10226 VkMemoryRequirements requirements;
10227 vkGetBufferMemoryRequirements(m_device->device(), buffer, &requirements);
10228
10229 VkMemoryAllocateInfo alloc_info{};
10230 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10231 alloc_info.pNext = NULL;
10232 alloc_info.memoryTypeIndex = 0;
10233 alloc_info.allocationSize = requirements.size;
10234 bool pass = m_device->phy().set_memory_type(requirements.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
10235 ASSERT_TRUE(pass);
10236
10237 VkDeviceMemory memory;
10238 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &memory);
10239 ASSERT_VK_SUCCESS(err);
10240
10241 err = vkBindBufferMemory(m_device->device(), buffer, memory, 0);
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010242 ASSERT_VK_SUCCESS(err);
10243
Tony Barbour552f6c02016-12-21 14:34:07 -070010244 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010245 ASSERT_VK_SUCCESS(err);
Jeremy Hayes483d95d2017-03-08 11:03:01 -070010246
Karl Schultz6addd812016-02-02 17:17:23 -070010247 // vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
10248 // VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010249 // Should error before calling to driver so don't care about actual data
Jeremy Hayes483d95d2017-03-08 11:03:01 -070010250 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdBindIndexBuffer() offset (0x7) does not fall on ");
10251 vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), buffer, 7, VK_INDEX_TYPE_UINT16);
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010252 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010253
Jeremy Hayes483d95d2017-03-08 11:03:01 -070010254 vkFreeMemory(m_device->device(), memory, NULL);
10255 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010256}
10257
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -070010258TEST_F(VkLayerTest, InvalidQueueFamilyIndex) {
10259 // Create an out-of-range queueFamilyIndex
Tony Barbour1fa09702017-03-16 12:09:08 -060010260 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -070010261 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10262 VkBufferCreateInfo buffCI = {};
10263 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
10264 buffCI.size = 1024;
Mark Lobodzinski4761d212017-02-28 13:12:44 -070010265 buffCI.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
Jeremy Hayes8a43a0d2017-03-09 11:27:52 -070010266 buffCI.queueFamilyIndexCount = 2;
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -070010267 // Introduce failure by specifying invalid queue_family_index
Mark Lobodzinski4761d212017-02-28 13:12:44 -070010268 uint32_t qfi[2];
10269 qfi[0] = 777;
Jeremy Hayes8a43a0d2017-03-09 11:27:52 -070010270 qfi[1] = 0;
Mark Lobodzinski4761d212017-02-28 13:12:44 -070010271
10272 buffCI.pQueueFamilyIndices = qfi;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010273 buffCI.sharingMode = VK_SHARING_MODE_CONCURRENT; // qfi only matters in CONCURRENT mode
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -070010274
10275 VkBuffer ib;
Jeremy Hayes8a43a0d2017-03-09 11:27:52 -070010276 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Petr Kraus97291752017-05-11 01:05:16 +020010277 "vkCreateBuffer: pCreateInfo->pQueueFamilyIndices[0] (= 777) is not one of the queue "
10278 "families given via VkDeviceQueueCreateInfo structures when the device was created.");
Mark Lobodzinski1f9ebb72017-05-11 15:25:51 -060010279 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010280 m_errorMonitor->VerifyFound();
Mark Lobodzinski4761d212017-02-28 13:12:44 -070010281
10282 if (m_device->queue_props.size() > 2) {
Tony Barbour75db7402017-03-09 14:51:36 -070010283 VkBuffer ib2;
Mark Lobodzinski4761d212017-02-28 13:12:44 -070010284 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which was not created allowing concurrent");
10285
10286 // Create buffer shared to queue families 1 and 2, but submitted on queue family 0
10287 buffCI.queueFamilyIndexCount = 2;
10288 qfi[0] = 1;
10289 qfi[1] = 2;
Tony Barbour75db7402017-03-09 14:51:36 -070010290 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib2);
Mark Lobodzinski4761d212017-02-28 13:12:44 -070010291 VkDeviceMemory mem;
10292 VkMemoryRequirements mem_reqs;
Tony Barbour75db7402017-03-09 14:51:36 -070010293 vkGetBufferMemoryRequirements(m_device->device(), ib2, &mem_reqs);
Mark Lobodzinski4761d212017-02-28 13:12:44 -070010294
10295 VkMemoryAllocateInfo alloc_info = {};
10296 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10297 alloc_info.allocationSize = 1024;
10298 bool pass = false;
10299 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
10300 if (!pass) {
Tony Barbour75db7402017-03-09 14:51:36 -070010301 vkDestroyBuffer(m_device->device(), ib2, NULL);
Mark Lobodzinski4761d212017-02-28 13:12:44 -070010302 return;
10303 }
10304 vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
Tony Barbour75db7402017-03-09 14:51:36 -070010305 vkBindBufferMemory(m_device->device(), ib2, mem, 0);
Mark Lobodzinski4761d212017-02-28 13:12:44 -070010306
10307 m_commandBuffer->begin();
Tony Barbour75db7402017-03-09 14:51:36 -070010308 vkCmdFillBuffer(m_commandBuffer->handle(), ib2, 0, 16, 5);
Mark Lobodzinski4761d212017-02-28 13:12:44 -070010309 m_commandBuffer->end();
10310 QueueCommandBuffer(false);
10311 m_errorMonitor->VerifyFound();
Tony Barbour75db7402017-03-09 14:51:36 -070010312 vkDestroyBuffer(m_device->device(), ib2, NULL);
10313 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski4761d212017-02-28 13:12:44 -070010314 }
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -070010315}
10316
Karl Schultz6addd812016-02-02 17:17:23 -070010317TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010318 TEST_DESCRIPTION(
10319 "Attempt vkCmdExecuteCommands with a primary command buffer"
10320 " (should only be secondary)");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010321
Tony Barbour1fa09702017-03-16 12:09:08 -060010322 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -060010323 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -060010324
Chris Forbesf29a84f2016-10-06 18:39:28 +130010325 // An empty primary command buffer
10326 VkCommandBufferObj cb(m_device, m_commandPool);
10327 cb.BeginCommandBuffer();
10328 cb.EndCommandBuffer();
Tobin Ehlis0c94db02016-07-19 10:49:32 -060010329
Chris Forbesf29a84f2016-10-06 18:39:28 +130010330 m_commandBuffer->BeginCommandBuffer();
10331 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
10332 VkCommandBuffer handle = cb.handle();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -060010333
Chris Forbesf29a84f2016-10-06 18:39:28 +130010334 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdExecuteCommands() called w/ Primary Cmd Buffer ");
10335 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &handle);
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010336 m_errorMonitor->VerifyFound();
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070010337
Tobin Ehlis6d4d1d52017-04-05 12:06:10 -060010338 m_errorMonitor->SetUnexpectedError("All elements of pCommandBuffers must not be in the pending state");
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -060010339}
10340
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010341TEST_F(VkLayerTest, DSUsageBitsErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010342 TEST_DESCRIPTION(
10343 "Attempt to update descriptor sets for images and buffers "
10344 "that do not have correct usage bits sets.");
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010345 VkResult err;
10346
Tony Barbour1fa09702017-03-16 12:09:08 -060010347 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010348 VkDescriptorPoolSize ds_type_count[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
10349 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
10350 ds_type_count[i].type = VkDescriptorType(i);
10351 ds_type_count[i].descriptorCount = 1;
10352 }
10353 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10354 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10355 ds_pool_ci.pNext = NULL;
10356 ds_pool_ci.maxSets = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
10357 ds_pool_ci.poolSizeCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
10358 ds_pool_ci.pPoolSizes = ds_type_count;
10359
10360 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010361 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010362 ASSERT_VK_SUCCESS(err);
10363
10364 // Create 10 layouts where each has a single descriptor of different type
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010365 VkDescriptorSetLayoutBinding dsl_binding[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010366 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
10367 dsl_binding[i].binding = 0;
10368 dsl_binding[i].descriptorType = VkDescriptorType(i);
10369 dsl_binding[i].descriptorCount = 1;
10370 dsl_binding[i].stageFlags = VK_SHADER_STAGE_ALL;
10371 dsl_binding[i].pImmutableSamplers = NULL;
10372 }
10373
10374 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10375 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10376 ds_layout_ci.pNext = NULL;
10377 ds_layout_ci.bindingCount = 1;
10378 VkDescriptorSetLayout ds_layouts[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
10379 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
10380 ds_layout_ci.pBindings = dsl_binding + i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010381 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, ds_layouts + i);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010382 ASSERT_VK_SUCCESS(err);
10383 }
10384 VkDescriptorSet descriptor_sets[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
10385 VkDescriptorSetAllocateInfo alloc_info = {};
10386 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10387 alloc_info.descriptorSetCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
10388 alloc_info.descriptorPool = ds_pool;
10389 alloc_info.pSetLayouts = ds_layouts;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010390 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010391 ASSERT_VK_SUCCESS(err);
10392
10393 // Create a buffer & bufferView to be used for invalid updates
10394 VkBufferCreateInfo buff_ci = {};
10395 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Tony Barbour415497c2017-01-24 10:06:09 -070010396 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010397 buff_ci.size = 256;
10398 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
Tony Barbour415497c2017-01-24 10:06:09 -070010399 VkBuffer buffer, storage_texel_buffer;
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010400 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
10401 ASSERT_VK_SUCCESS(err);
Tony Barbour415497c2017-01-24 10:06:09 -070010402
10403 // Create another buffer to use in testing the UNIFORM_TEXEL_BUFFER case
10404 buff_ci.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
10405 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &storage_texel_buffer);
10406 ASSERT_VK_SUCCESS(err);
10407
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -070010408 VkMemoryRequirements mem_reqs;
10409 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
10410 VkMemoryAllocateInfo mem_alloc_info = {};
10411 mem_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10412 mem_alloc_info.pNext = NULL;
10413 mem_alloc_info.memoryTypeIndex = 0;
10414 mem_alloc_info.allocationSize = mem_reqs.size;
10415 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc_info, 0);
10416 if (!pass) {
10417 vkDestroyBuffer(m_device->device(), buffer, NULL);
10418 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10419 return;
10420 }
10421 VkDeviceMemory mem;
10422 err = vkAllocateMemory(m_device->device(), &mem_alloc_info, NULL, &mem);
10423 ASSERT_VK_SUCCESS(err);
10424 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
10425 ASSERT_VK_SUCCESS(err);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010426
10427 VkBufferViewCreateInfo buff_view_ci = {};
10428 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
10429 buff_view_ci.buffer = buffer;
10430 buff_view_ci.format = VK_FORMAT_R8_UNORM;
10431 buff_view_ci.range = VK_WHOLE_SIZE;
10432 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010433 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010434 ASSERT_VK_SUCCESS(err);
10435
Tony Barbour415497c2017-01-24 10:06:09 -070010436 // Now get resources / view for storage_texel_buffer
10437 vkGetBufferMemoryRequirements(m_device->device(), storage_texel_buffer, &mem_reqs);
10438 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc_info, 0);
10439 if (!pass) {
10440 vkDestroyBuffer(m_device->device(), buffer, NULL);
10441 vkDestroyBufferView(m_device->device(), buff_view, NULL);
10442 vkFreeMemory(m_device->device(), mem, NULL);
10443 vkDestroyBuffer(m_device->device(), storage_texel_buffer, NULL);
10444 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10445 return;
10446 }
10447 VkDeviceMemory storage_texel_buffer_mem;
10448 VkBufferView storage_texel_buffer_view;
10449 err = vkAllocateMemory(m_device->device(), &mem_alloc_info, NULL, &storage_texel_buffer_mem);
10450 ASSERT_VK_SUCCESS(err);
10451 err = vkBindBufferMemory(m_device->device(), storage_texel_buffer, storage_texel_buffer_mem, 0);
10452 ASSERT_VK_SUCCESS(err);
10453 buff_view_ci.buffer = storage_texel_buffer;
10454 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &storage_texel_buffer_view);
10455 ASSERT_VK_SUCCESS(err);
10456
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010457 // Create an image to be used for invalid updates
Tony Barbour4b4a4222017-01-24 11:46:34 -070010458 // Find a format / tiling for COLOR_ATTACHMENT
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010459 VkImageCreateInfo image_ci = {};
Tony Barbour4b4a4222017-01-24 11:46:34 -070010460 image_ci.format = VK_FORMAT_UNDEFINED;
10461 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
10462 VkFormat format = static_cast<VkFormat>(f);
10463 VkFormatProperties fProps = m_device->format_properties(format);
10464 if (fProps.linearTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) {
10465 image_ci.format = format;
10466 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
10467 break;
10468 } else if (fProps.optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) {
10469 image_ci.format = format;
10470 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
10471 break;
10472 }
10473 }
10474 if (image_ci.format == VK_FORMAT_UNDEFINED) {
10475 return;
10476 }
10477
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010478 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10479 image_ci.imageType = VK_IMAGE_TYPE_2D;
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010480 image_ci.extent.width = 64;
10481 image_ci.extent.height = 64;
10482 image_ci.extent.depth = 1;
10483 image_ci.mipLevels = 1;
10484 image_ci.arrayLayers = 1;
10485 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010486 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
Tony Barbour4b4a4222017-01-24 11:46:34 -070010487 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010488 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
10489 VkImage image;
10490 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
10491 ASSERT_VK_SUCCESS(err);
10492 // Bind memory to image
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010493 VkDeviceMemory image_mem;
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -070010494
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010495 VkMemoryAllocateInfo mem_alloc = {};
10496 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10497 mem_alloc.pNext = NULL;
10498 mem_alloc.allocationSize = 0;
10499 mem_alloc.memoryTypeIndex = 0;
10500 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
10501 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010502 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010503 ASSERT_TRUE(pass);
10504 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
10505 ASSERT_VK_SUCCESS(err);
10506 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
10507 ASSERT_VK_SUCCESS(err);
10508 // Now create view for image
10509 VkImageViewCreateInfo image_view_ci = {};
10510 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
10511 image_view_ci.image = image;
Tony Barbour4b4a4222017-01-24 11:46:34 -070010512 image_view_ci.format = image_ci.format;
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010513 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
10514 image_view_ci.subresourceRange.layerCount = 1;
10515 image_view_ci.subresourceRange.baseArrayLayer = 0;
10516 image_view_ci.subresourceRange.levelCount = 1;
10517 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10518 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010519 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010520 ASSERT_VK_SUCCESS(err);
10521
10522 VkDescriptorBufferInfo buff_info = {};
10523 buff_info.buffer = buffer;
10524 VkDescriptorImageInfo img_info = {};
10525 img_info.imageView = image_view;
10526 VkWriteDescriptorSet descriptor_write = {};
10527 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10528 descriptor_write.dstBinding = 0;
10529 descriptor_write.descriptorCount = 1;
10530 descriptor_write.pTexelBufferView = &buff_view;
10531 descriptor_write.pBufferInfo = &buff_info;
10532 descriptor_write.pImageInfo = &img_info;
10533
10534 // These error messages align with VkDescriptorType struct
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -070010535 UNIQUE_VALIDATION_ERROR_CODE error_codes[] = {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010536 VALIDATION_ERROR_00943, // placeholder, no error for SAMPLER descriptor
10537 VALIDATION_ERROR_00943, // COMBINED_IMAGE_SAMPLER
10538 VALIDATION_ERROR_00943, // SAMPLED_IMAGE
10539 VALIDATION_ERROR_00943, // STORAGE_IMAGE
10540 VALIDATION_ERROR_00950, // UNIFORM_TEXEL_BUFFER
10541 VALIDATION_ERROR_00951, // STORAGE_TEXEL_BUFFER
10542 VALIDATION_ERROR_00946, // UNIFORM_BUFFER
10543 VALIDATION_ERROR_00947, // STORAGE_BUFFER
10544 VALIDATION_ERROR_00946, // UNIFORM_BUFFER_DYNAMIC
10545 VALIDATION_ERROR_00947, // STORAGE_BUFFER_DYNAMIC
10546 VALIDATION_ERROR_00943 // INPUT_ATTACHMENT
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -070010547 };
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010548 // Start loop at 1 as SAMPLER desc type has no usage bit error
10549 for (uint32_t i = 1; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
Tony Barbour415497c2017-01-24 10:06:09 -070010550 if (VkDescriptorType(i) == VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER) {
10551 // Now check for UNIFORM_TEXEL_BUFFER using storage_texel_buffer_view
10552 descriptor_write.pTexelBufferView = &storage_texel_buffer_view;
10553 }
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010554 descriptor_write.descriptorType = VkDescriptorType(i);
10555 descriptor_write.dstSet = descriptor_sets[i];
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -070010556 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_codes[i]);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010557
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010558 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010559
10560 m_errorMonitor->VerifyFound();
10561 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[i], NULL);
Tony Barbour415497c2017-01-24 10:06:09 -070010562 if (VkDescriptorType(i) == VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER) {
10563 descriptor_write.pTexelBufferView = &buff_view;
10564 }
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010565 }
Tony Barbour415497c2017-01-24 10:06:09 -070010566
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010567 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[0], NULL);
10568 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -060010569 vkFreeMemory(m_device->device(), image_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010570 vkDestroyImageView(m_device->device(), image_view, NULL);
10571 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tony Barbour415497c2017-01-24 10:06:09 -070010572 vkDestroyBuffer(m_device->device(), storage_texel_buffer, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010573 vkDestroyBufferView(m_device->device(), buff_view, NULL);
Tony Barbour415497c2017-01-24 10:06:09 -070010574 vkDestroyBufferView(m_device->device(), storage_texel_buffer_view, NULL);
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -070010575 vkFreeMemory(m_device->device(), mem, NULL);
Tony Barbour415497c2017-01-24 10:06:09 -070010576 vkFreeMemory(m_device->device(), storage_texel_buffer_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010577 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10578}
10579
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010580TEST_F(VkLayerTest, DSBufferInfoErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010581 TEST_DESCRIPTION(
10582 "Attempt to update buffer descriptor set that has incorrect "
10583 "parameters in VkDescriptorBufferInfo struct. This includes:\n"
Jeremy Hayesd1a6a822017-03-09 14:39:45 -070010584 "1. offset value greater than or equal to buffer size\n"
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010585 "2. range value of 0\n"
10586 "3. range value greater than buffer (size - offset)");
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010587 VkResult err;
10588
Tony Barbour1fa09702017-03-16 12:09:08 -060010589 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010590 VkDescriptorPoolSize ds_type_count = {};
10591 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10592 ds_type_count.descriptorCount = 1;
10593
10594 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10595 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10596 ds_pool_ci.pNext = NULL;
Jeremy Hayesd1a6a822017-03-09 14:39:45 -070010597 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010598 ds_pool_ci.maxSets = 1;
10599 ds_pool_ci.poolSizeCount = 1;
10600 ds_pool_ci.pPoolSizes = &ds_type_count;
10601
10602 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010603 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010604 ASSERT_VK_SUCCESS(err);
10605
10606 // Create layout with single uniform buffer descriptor
10607 VkDescriptorSetLayoutBinding dsl_binding = {};
10608 dsl_binding.binding = 0;
10609 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10610 dsl_binding.descriptorCount = 1;
10611 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10612 dsl_binding.pImmutableSamplers = NULL;
10613
10614 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10615 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10616 ds_layout_ci.pNext = NULL;
10617 ds_layout_ci.bindingCount = 1;
10618 ds_layout_ci.pBindings = &dsl_binding;
10619 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010620 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010621 ASSERT_VK_SUCCESS(err);
10622
10623 VkDescriptorSet descriptor_set = {};
10624 VkDescriptorSetAllocateInfo alloc_info = {};
10625 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10626 alloc_info.descriptorSetCount = 1;
10627 alloc_info.descriptorPool = ds_pool;
10628 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010629 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010630 ASSERT_VK_SUCCESS(err);
10631
10632 // Create a buffer to be used for invalid updates
10633 VkBufferCreateInfo buff_ci = {};
10634 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
10635 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
Jeremy Hayesd1a6a822017-03-09 14:39:45 -070010636 buff_ci.size = m_device->props.limits.minUniformBufferOffsetAlignment;
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010637 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
10638 VkBuffer buffer;
10639 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
10640 ASSERT_VK_SUCCESS(err);
Jeremy Hayesd1a6a822017-03-09 14:39:45 -070010641
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010642 // Have to bind memory to buffer before descriptor update
10643 VkMemoryAllocateInfo mem_alloc = {};
10644 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10645 mem_alloc.pNext = NULL;
Jeremy Hayesd1a6a822017-03-09 14:39:45 -070010646 mem_alloc.allocationSize = buff_ci.size;
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010647 mem_alloc.memoryTypeIndex = 0;
10648
10649 VkMemoryRequirements mem_reqs;
10650 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010651 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010652 if (!pass) {
10653 vkDestroyBuffer(m_device->device(), buffer, NULL);
10654 return;
10655 }
10656
10657 VkDeviceMemory mem;
10658 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
10659 ASSERT_VK_SUCCESS(err);
10660 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
10661 ASSERT_VK_SUCCESS(err);
10662
10663 VkDescriptorBufferInfo buff_info = {};
10664 buff_info.buffer = buffer;
Jeremy Hayesd1a6a822017-03-09 14:39:45 -070010665 // Cause error due to offset out of range
10666 buff_info.offset = buff_ci.size;
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010667 buff_info.range = VK_WHOLE_SIZE;
10668 VkWriteDescriptorSet descriptor_write = {};
10669 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10670 descriptor_write.dstBinding = 0;
10671 descriptor_write.descriptorCount = 1;
10672 descriptor_write.pTexelBufferView = nullptr;
10673 descriptor_write.pBufferInfo = &buff_info;
10674 descriptor_write.pImageInfo = nullptr;
10675
10676 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10677 descriptor_write.dstSet = descriptor_set;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070010678 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00959);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010679
10680 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10681
10682 m_errorMonitor->VerifyFound();
10683 // Now cause error due to range of 0
10684 buff_info.offset = 0;
10685 buff_info.range = 0;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070010686 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00960);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010687
10688 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10689
10690 m_errorMonitor->VerifyFound();
10691 // Now cause error due to range exceeding buffer size - offset
Jeremy Hayesd1a6a822017-03-09 14:39:45 -070010692 buff_info.offset = 0;
10693 buff_info.range = buff_ci.size + 1;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070010694 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00961);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010695
10696 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10697
10698 m_errorMonitor->VerifyFound();
Mark Lobodzinski4bb54092016-07-06 14:27:19 -060010699 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010700 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10701 vkDestroyBuffer(m_device->device(), buffer, NULL);
10702 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
10703 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10704}
10705
Tobin Ehlis845887e2017-02-02 19:01:44 -070010706TEST_F(VkLayerTest, DSBufferLimitErrors) {
10707 TEST_DESCRIPTION(
10708 "Attempt to update buffer descriptor set that has VkDescriptorBufferInfo values that violate device limits.\n"
10709 "Test cases include:\n"
10710 "1. range of uniform buffer update exceeds maxUniformBufferRange\n"
10711 "2. offset of uniform buffer update is not multiple of minUniformBufferOffsetAlignment\n"
10712 "3. range of storage buffer update exceeds maxStorageBufferRange\n"
10713 "4. offset of storage buffer update is not multiple of minStorageBufferOffsetAlignment");
10714 VkResult err;
10715
Tony Barbour1fa09702017-03-16 12:09:08 -060010716 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis845887e2017-02-02 19:01:44 -070010717 VkDescriptorPoolSize ds_type_count[2] = {};
10718 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10719 ds_type_count[0].descriptorCount = 1;
10720 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
10721 ds_type_count[1].descriptorCount = 1;
10722
10723 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10724 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10725 ds_pool_ci.pNext = NULL;
10726 ds_pool_ci.maxSets = 1;
10727 ds_pool_ci.poolSizeCount = 2;
10728 ds_pool_ci.pPoolSizes = ds_type_count;
10729
10730 VkDescriptorPool ds_pool;
10731 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
10732 ASSERT_VK_SUCCESS(err);
10733
10734 // Create layout with single uniform buffer & single storage buffer descriptor
10735 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
10736 dsl_binding[0].binding = 0;
10737 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10738 dsl_binding[0].descriptorCount = 1;
10739 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
10740 dsl_binding[0].pImmutableSamplers = NULL;
10741 dsl_binding[1].binding = 1;
10742 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
10743 dsl_binding[1].descriptorCount = 1;
10744 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
10745 dsl_binding[1].pImmutableSamplers = NULL;
10746
10747 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10748 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10749 ds_layout_ci.pNext = NULL;
10750 ds_layout_ci.bindingCount = 2;
10751 ds_layout_ci.pBindings = dsl_binding;
10752 VkDescriptorSetLayout ds_layout;
10753 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
10754 ASSERT_VK_SUCCESS(err);
10755
10756 VkDescriptorSet descriptor_set = {};
10757 VkDescriptorSetAllocateInfo alloc_info = {};
10758 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10759 alloc_info.descriptorSetCount = 1;
10760 alloc_info.descriptorPool = ds_pool;
10761 alloc_info.pSetLayouts = &ds_layout;
10762 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
10763 ASSERT_VK_SUCCESS(err);
10764
10765 // Create a buffer to be used for invalid updates
10766 auto max_ub_range = m_device->props.limits.maxUniformBufferRange;
10767 auto min_ub_align = m_device->props.limits.minUniformBufferOffsetAlignment;
10768 auto max_sb_range = m_device->props.limits.maxStorageBufferRange;
10769 auto min_sb_align = m_device->props.limits.minStorageBufferOffsetAlignment;
10770 VkBufferCreateInfo ub_ci = {};
10771 ub_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
10772 ub_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
10773 ub_ci.size = max_ub_range + 128; // Make buffer bigger than range limit
10774 ub_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
10775 VkBuffer uniform_buffer;
10776 err = vkCreateBuffer(m_device->device(), &ub_ci, NULL, &uniform_buffer);
10777 ASSERT_VK_SUCCESS(err);
10778 VkBufferCreateInfo sb_ci = {};
10779 sb_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
10780 sb_ci.usage = VK_BUFFER_USAGE_STORAGE_BUFFER_BIT;
10781 sb_ci.size = max_sb_range + 128; // Make buffer bigger than range limit
10782 sb_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
10783 VkBuffer storage_buffer;
10784 err = vkCreateBuffer(m_device->device(), &sb_ci, NULL, &storage_buffer);
10785 ASSERT_VK_SUCCESS(err);
10786 // Have to bind memory to buffer before descriptor update
10787 VkMemoryAllocateInfo mem_alloc = {};
10788 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10789 mem_alloc.pNext = NULL;
10790 mem_alloc.allocationSize = ub_ci.size + sb_ci.size + 1024; // additional buffer for offset
10791 mem_alloc.memoryTypeIndex = 0;
10792
Cort Stratton77a0d592017-02-17 13:14:13 -080010793 VkMemoryRequirements ub_mem_reqs, sb_mem_reqs;
10794 vkGetBufferMemoryRequirements(m_device->device(), uniform_buffer, &ub_mem_reqs);
10795 bool pass = m_device->phy().set_memory_type(ub_mem_reqs.memoryTypeBits, &mem_alloc, 0);
10796 vkGetBufferMemoryRequirements(m_device->device(), storage_buffer, &sb_mem_reqs);
10797 pass &= m_device->phy().set_memory_type(sb_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis845887e2017-02-02 19:01:44 -070010798 if (!pass) {
Tobin Ehlis15c83792017-02-07 10:09:33 -070010799 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Tobin Ehlis845887e2017-02-02 19:01:44 -070010800 vkDestroyBuffer(m_device->device(), uniform_buffer, NULL);
Tobin Ehlis15c83792017-02-07 10:09:33 -070010801 vkDestroyBuffer(m_device->device(), storage_buffer, NULL);
10802 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis845887e2017-02-02 19:01:44 -070010803 return;
10804 }
10805
10806 VkDeviceMemory mem;
10807 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlis15c83792017-02-07 10:09:33 -070010808 if (VK_SUCCESS != err) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070010809 printf(" Failed to allocate memory in DSBufferLimitErrors; skipped.\n");
Tobin Ehlis15c83792017-02-07 10:09:33 -070010810 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10811 vkDestroyBuffer(m_device->device(), uniform_buffer, NULL);
10812 vkDestroyBuffer(m_device->device(), storage_buffer, NULL);
10813 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10814 return;
10815 }
Tobin Ehlis845887e2017-02-02 19:01:44 -070010816 ASSERT_VK_SUCCESS(err);
10817 err = vkBindBufferMemory(m_device->device(), uniform_buffer, mem, 0);
10818 ASSERT_VK_SUCCESS(err);
Cort Stratton77a0d592017-02-17 13:14:13 -080010819 auto sb_offset = (ub_ci.size + sb_mem_reqs.alignment - 1) & ~(sb_mem_reqs.alignment - 1);
Tobin Ehlis845887e2017-02-02 19:01:44 -070010820 err = vkBindBufferMemory(m_device->device(), storage_buffer, mem, sb_offset);
10821 ASSERT_VK_SUCCESS(err);
10822
10823 VkDescriptorBufferInfo buff_info = {};
10824 buff_info.buffer = uniform_buffer;
10825 buff_info.range = ub_ci.size; // This will exceed limit
10826 VkWriteDescriptorSet descriptor_write = {};
10827 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10828 descriptor_write.dstBinding = 0;
10829 descriptor_write.descriptorCount = 1;
10830 descriptor_write.pTexelBufferView = nullptr;
10831 descriptor_write.pBufferInfo = &buff_info;
10832 descriptor_write.pImageInfo = nullptr;
10833
10834 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10835 descriptor_write.dstSet = descriptor_set;
Tony Barbour02d08552017-03-24 16:36:01 -060010836 if (max_ub_range != UINT32_MAX) {
10837 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00948);
10838 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10839 m_errorMonitor->VerifyFound();
10840 }
Tobin Ehlis845887e2017-02-02 19:01:44 -070010841 // Reduce size of range to acceptable limit & cause offset error
10842 buff_info.range = max_ub_range;
10843 buff_info.offset = min_ub_align - 1;
10844 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00944);
10845 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10846 m_errorMonitor->VerifyFound();
10847
10848 // Now break storage updates
10849 buff_info.buffer = storage_buffer;
10850 buff_info.range = sb_ci.size; // This will exceed limit
10851 buff_info.offset = 0; // Reset offset for this update
10852
10853 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
10854 descriptor_write.dstBinding = 1;
Tony Barbour02d08552017-03-24 16:36:01 -060010855 if (max_ub_range != UINT32_MAX) {
10856 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00949);
10857 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10858 m_errorMonitor->VerifyFound();
10859 }
Tobin Ehlis845887e2017-02-02 19:01:44 -070010860
10861 // Reduce size of range to acceptable limit & cause offset error
10862 buff_info.range = max_sb_range;
10863 buff_info.offset = min_sb_align - 1;
10864 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00945);
10865 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10866 m_errorMonitor->VerifyFound();
10867
10868 vkFreeMemory(m_device->device(), mem, NULL);
10869 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10870 vkDestroyBuffer(m_device->device(), uniform_buffer, NULL);
10871 vkDestroyBuffer(m_device->device(), storage_buffer, NULL);
10872 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10873}
10874
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010875TEST_F(VkLayerTest, DSAspectBitsErrors) {
10876 // TODO : Initially only catching case where DEPTH & STENCIL aspect bits
10877 // are set, but could expand this test to hit more cases.
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010878 TEST_DESCRIPTION(
10879 "Attempt to update descriptor sets for images "
10880 "that do not have correct aspect bits sets.");
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010881 VkResult err;
10882
Tony Barbour1fa09702017-03-16 12:09:08 -060010883 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -060010884 auto depth_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbourf887b162017-03-09 10:06:46 -070010885 if (!depth_format) {
10886 printf(" No Depth + Stencil format found. Skipped.\n");
10887 return;
10888 }
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010889 VkDescriptorPoolSize ds_type_count = {};
10890 ds_type_count.type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
10891 ds_type_count.descriptorCount = 1;
10892
10893 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10894 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10895 ds_pool_ci.pNext = NULL;
Jeremy Hayes293c7ed2017-03-09 14:47:07 -070010896 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010897 ds_pool_ci.maxSets = 5;
10898 ds_pool_ci.poolSizeCount = 1;
10899 ds_pool_ci.pPoolSizes = &ds_type_count;
10900
10901 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010902 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010903 ASSERT_VK_SUCCESS(err);
10904
10905 VkDescriptorSetLayoutBinding dsl_binding = {};
10906 dsl_binding.binding = 0;
10907 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
10908 dsl_binding.descriptorCount = 1;
10909 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10910 dsl_binding.pImmutableSamplers = NULL;
10911
10912 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10913 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10914 ds_layout_ci.pNext = NULL;
10915 ds_layout_ci.bindingCount = 1;
10916 ds_layout_ci.pBindings = &dsl_binding;
10917 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010918 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010919 ASSERT_VK_SUCCESS(err);
10920
10921 VkDescriptorSet descriptor_set = {};
10922 VkDescriptorSetAllocateInfo alloc_info = {};
10923 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10924 alloc_info.descriptorSetCount = 1;
10925 alloc_info.descriptorPool = ds_pool;
10926 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010927 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010928 ASSERT_VK_SUCCESS(err);
10929
10930 // Create an image to be used for invalid updates
10931 VkImageCreateInfo image_ci = {};
10932 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10933 image_ci.imageType = VK_IMAGE_TYPE_2D;
Tony Barbourf887b162017-03-09 10:06:46 -070010934 image_ci.format = depth_format;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010935 image_ci.extent.width = 64;
10936 image_ci.extent.height = 64;
10937 image_ci.extent.depth = 1;
10938 image_ci.mipLevels = 1;
10939 image_ci.arrayLayers = 1;
10940 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Young2d1fa302017-03-02 10:13:09 -070010941 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010942 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
10943 image_ci.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
10944 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
10945 VkImage image;
10946 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
10947 ASSERT_VK_SUCCESS(err);
10948 // Bind memory to image
10949 VkMemoryRequirements mem_reqs;
10950 VkDeviceMemory image_mem;
10951 bool pass;
10952 VkMemoryAllocateInfo mem_alloc = {};
10953 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10954 mem_alloc.pNext = NULL;
10955 mem_alloc.allocationSize = 0;
10956 mem_alloc.memoryTypeIndex = 0;
10957 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
10958 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010959 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010960 ASSERT_TRUE(pass);
10961 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
10962 ASSERT_VK_SUCCESS(err);
10963 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
10964 ASSERT_VK_SUCCESS(err);
10965 // Now create view for image
10966 VkImageViewCreateInfo image_view_ci = {};
10967 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
10968 image_view_ci.image = image;
Tony Barbourf887b162017-03-09 10:06:46 -070010969 image_view_ci.format = depth_format;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010970 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
10971 image_view_ci.subresourceRange.layerCount = 1;
10972 image_view_ci.subresourceRange.baseArrayLayer = 0;
10973 image_view_ci.subresourceRange.levelCount = 1;
10974 // Setting both depth & stencil aspect bits is illegal for descriptor
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010975 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010976
10977 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010978 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010979 ASSERT_VK_SUCCESS(err);
10980
10981 VkDescriptorImageInfo img_info = {};
10982 img_info.imageView = image_view;
10983 VkWriteDescriptorSet descriptor_write = {};
10984 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10985 descriptor_write.dstBinding = 0;
10986 descriptor_write.descriptorCount = 1;
10987 descriptor_write.pTexelBufferView = NULL;
10988 descriptor_write.pBufferInfo = NULL;
10989 descriptor_write.pImageInfo = &img_info;
10990 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
10991 descriptor_write.dstSet = descriptor_set;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010992 const char *error_msg =
10993 " please only set either VK_IMAGE_ASPECT_DEPTH_BIT "
10994 "or VK_IMAGE_ASPECT_STENCIL_BIT ";
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010995 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msg);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010996
10997 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10998
10999 m_errorMonitor->VerifyFound();
11000 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11001 vkDestroyImage(m_device->device(), image, NULL);
11002 vkFreeMemory(m_device->device(), image_mem, NULL);
11003 vkDestroyImageView(m_device->device(), image_view, NULL);
11004 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
11005 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11006}
11007
Karl Schultz6addd812016-02-02 17:17:23 -070011008TEST_F(VkLayerTest, DSTypeMismatch) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060011009 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Karl Schultz6addd812016-02-02 17:17:23 -070011010 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011011
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011012 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11013 " binding #0 with type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER but update "
11014 "type is VK_DESCRIPTOR_TYPE_SAMPLER");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011015
Tony Barbour1fa09702017-03-16 12:09:08 -060011016 ASSERT_NO_FATAL_FAILURE(Init());
Karl Schultz6addd812016-02-02 17:17:23 -070011017 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011018 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011019 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11020 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011021
11022 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011023 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11024 ds_pool_ci.pNext = NULL;
11025 ds_pool_ci.maxSets = 1;
11026 ds_pool_ci.poolSizeCount = 1;
11027 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060011028
Tobin Ehlis3b780662015-05-28 12:11:26 -060011029 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011030 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011031 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -060011032 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011033 dsl_binding.binding = 0;
11034 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11035 dsl_binding.descriptorCount = 1;
11036 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11037 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011038
Tony Barboureb254902015-07-15 12:50:33 -060011039 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011040 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11041 ds_layout_ci.pNext = NULL;
11042 ds_layout_ci.bindingCount = 1;
11043 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060011044
Tobin Ehlis3b780662015-05-28 12:11:26 -060011045 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011046 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011047 ASSERT_VK_SUCCESS(err);
11048
11049 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011050 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011051 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011052 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011053 alloc_info.descriptorPool = ds_pool;
11054 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011055 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011056 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011057
Tobin Ehlis30db8f82016-05-05 08:19:48 -060011058 VkSamplerCreateInfo sampler_ci = {};
11059 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11060 sampler_ci.pNext = NULL;
11061 sampler_ci.magFilter = VK_FILTER_NEAREST;
11062 sampler_ci.minFilter = VK_FILTER_NEAREST;
11063 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11064 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11065 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11066 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11067 sampler_ci.mipLodBias = 1.0;
11068 sampler_ci.anisotropyEnable = VK_FALSE;
11069 sampler_ci.maxAnisotropy = 1;
11070 sampler_ci.compareEnable = VK_FALSE;
11071 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11072 sampler_ci.minLod = 1.0;
11073 sampler_ci.maxLod = 1.0;
11074 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11075 sampler_ci.unnormalizedCoordinates = VK_FALSE;
11076 VkSampler sampler;
11077 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
11078 ASSERT_VK_SUCCESS(err);
11079
11080 VkDescriptorImageInfo info = {};
11081 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011082
11083 VkWriteDescriptorSet descriptor_write;
11084 memset(&descriptor_write, 0, sizeof(descriptor_write));
11085 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011086 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011087 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011088 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011089 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060011090 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011091
11092 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11093
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011094 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011095
Chia-I Wuf7458c52015-10-26 21:10:41 +080011096 vkDestroySampler(m_device->device(), sampler, NULL);
11097 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11098 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060011099}
11100
Karl Schultz6addd812016-02-02 17:17:23 -070011101TEST_F(VkLayerTest, DSUpdateOutOfBounds) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060011102 // For overlapping Update, have arrayIndex exceed that of layout
Karl Schultz6addd812016-02-02 17:17:23 -070011103 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011104
Tobin Ehlisf922ef82016-11-30 10:19:14 -070011105 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00938);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011106
Tony Barbour1fa09702017-03-16 12:09:08 -060011107 ASSERT_NO_FATAL_FAILURE(Init());
Karl Schultz6addd812016-02-02 17:17:23 -070011108 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011109 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011110 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11111 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011112
11113 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011114 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11115 ds_pool_ci.pNext = NULL;
11116 ds_pool_ci.maxSets = 1;
11117 ds_pool_ci.poolSizeCount = 1;
11118 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060011119
Tobin Ehlis3b780662015-05-28 12:11:26 -060011120 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011121 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011122 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011123
Tony Barboureb254902015-07-15 12:50:33 -060011124 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011125 dsl_binding.binding = 0;
11126 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11127 dsl_binding.descriptorCount = 1;
11128 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11129 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -060011130
11131 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011132 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11133 ds_layout_ci.pNext = NULL;
11134 ds_layout_ci.bindingCount = 1;
11135 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060011136
Tobin Ehlis3b780662015-05-28 12:11:26 -060011137 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011138 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011139 ASSERT_VK_SUCCESS(err);
11140
11141 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011142 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011143 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011144 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011145 alloc_info.descriptorPool = ds_pool;
11146 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011147 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011148 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011149
Jeremy Hayesd5b95db2017-03-09 15:24:24 -070011150 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
11151
Tobin Ehlis30db8f82016-05-05 08:19:48 -060011152 // Correctly update descriptor to avoid "NOT_UPDATED" error
11153 VkDescriptorBufferInfo buff_info = {};
Jeremy Hayesd5b95db2017-03-09 15:24:24 -070011154 buff_info.buffer = buffer_test.GetBuffer();
Tobin Ehlis30db8f82016-05-05 08:19:48 -060011155 buff_info.offset = 0;
11156 buff_info.range = 1024;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011157
11158 VkWriteDescriptorSet descriptor_write;
11159 memset(&descriptor_write, 0, sizeof(descriptor_write));
11160 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011161 descriptor_write.dstSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011162 descriptor_write.dstArrayElement = 1; /* This index out of bounds for the update */
Chia-I Wud50a7d72015-10-26 20:48:51 +080011163 descriptor_write.descriptorCount = 1;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -060011164 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11165 descriptor_write.pBufferInfo = &buff_info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011166
11167 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11168
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011169 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011170
Chia-I Wuf7458c52015-10-26 21:10:41 +080011171 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11172 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060011173}
11174
Karl Schultz6addd812016-02-02 17:17:23 -070011175TEST_F(VkLayerTest, InvalidDSUpdateIndex) {
Tobin Ehlisc8d352d2016-11-21 10:33:40 -070011176 // Create layout w/ count of 1 and attempt update to that layout w/ binding index 2
Karl Schultz6addd812016-02-02 17:17:23 -070011177 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011178
Tobin Ehlisc8d352d2016-11-21 10:33:40 -070011179 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00936);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011180
Tony Barbour1fa09702017-03-16 12:09:08 -060011181 ASSERT_NO_FATAL_FAILURE(Init());
Karl Schultz6addd812016-02-02 17:17:23 -070011182 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011183 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011184 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11185 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011186
11187 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011188 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11189 ds_pool_ci.pNext = NULL;
11190 ds_pool_ci.maxSets = 1;
11191 ds_pool_ci.poolSizeCount = 1;
11192 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060011193
Tobin Ehlis3b780662015-05-28 12:11:26 -060011194 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011195 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011196 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011197
Tony Barboureb254902015-07-15 12:50:33 -060011198 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011199 dsl_binding.binding = 0;
11200 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11201 dsl_binding.descriptorCount = 1;
11202 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11203 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -060011204
11205 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011206 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11207 ds_layout_ci.pNext = NULL;
11208 ds_layout_ci.bindingCount = 1;
11209 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011210 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011211 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011212 ASSERT_VK_SUCCESS(err);
11213
11214 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011215 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011216 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011217 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011218 alloc_info.descriptorPool = ds_pool;
11219 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011220 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011221 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011222
Tony Barboureb254902015-07-15 12:50:33 -060011223 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011224 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11225 sampler_ci.pNext = NULL;
11226 sampler_ci.magFilter = VK_FILTER_NEAREST;
11227 sampler_ci.minFilter = VK_FILTER_NEAREST;
11228 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11229 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11230 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11231 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11232 sampler_ci.mipLodBias = 1.0;
11233 sampler_ci.anisotropyEnable = VK_FALSE;
11234 sampler_ci.maxAnisotropy = 1;
11235 sampler_ci.compareEnable = VK_FALSE;
11236 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11237 sampler_ci.minLod = 1.0;
11238 sampler_ci.maxLod = 1.0;
11239 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11240 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -060011241
Tobin Ehlis3b780662015-05-28 12:11:26 -060011242 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011243 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011244 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011245
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060011246 VkDescriptorImageInfo info = {};
11247 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011248
11249 VkWriteDescriptorSet descriptor_write;
11250 memset(&descriptor_write, 0, sizeof(descriptor_write));
11251 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011252 descriptor_write.dstSet = descriptorSet;
11253 descriptor_write.dstBinding = 2;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011254 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011255 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011256 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060011257 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011258
11259 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11260
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011261 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011262
Chia-I Wuf7458c52015-10-26 21:10:41 +080011263 vkDestroySampler(m_device->device(), sampler, NULL);
11264 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11265 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060011266}
11267
Tobin Ehlise202b2d2016-11-21 10:36:16 -070011268TEST_F(VkLayerTest, DSUpdateEmptyBinding) {
11269 // Create layout w/ empty binding and attempt to update it
11270 VkResult err;
11271
Tony Barbour1fa09702017-03-16 12:09:08 -060011272 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlise202b2d2016-11-21 10:36:16 -070011273
11274 VkDescriptorPoolSize ds_type_count = {};
11275 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
11276 ds_type_count.descriptorCount = 1;
11277
11278 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11279 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11280 ds_pool_ci.pNext = NULL;
11281 ds_pool_ci.maxSets = 1;
11282 ds_pool_ci.poolSizeCount = 1;
11283 ds_pool_ci.pPoolSizes = &ds_type_count;
11284
11285 VkDescriptorPool ds_pool;
11286 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
11287 ASSERT_VK_SUCCESS(err);
11288
11289 VkDescriptorSetLayoutBinding dsl_binding = {};
11290 dsl_binding.binding = 0;
11291 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
11292 dsl_binding.descriptorCount = 0;
11293 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11294 dsl_binding.pImmutableSamplers = NULL;
11295
11296 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11297 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11298 ds_layout_ci.pNext = NULL;
11299 ds_layout_ci.bindingCount = 1;
11300 ds_layout_ci.pBindings = &dsl_binding;
11301 VkDescriptorSetLayout ds_layout;
11302 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
11303 ASSERT_VK_SUCCESS(err);
11304
11305 VkDescriptorSet descriptor_set;
11306 VkDescriptorSetAllocateInfo alloc_info = {};
11307 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11308 alloc_info.descriptorSetCount = 1;
11309 alloc_info.descriptorPool = ds_pool;
11310 alloc_info.pSetLayouts = &ds_layout;
11311 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
11312 ASSERT_VK_SUCCESS(err);
11313
11314 VkSamplerCreateInfo sampler_ci = {};
11315 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11316 sampler_ci.magFilter = VK_FILTER_NEAREST;
11317 sampler_ci.minFilter = VK_FILTER_NEAREST;
11318 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11319 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11320 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11321 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11322 sampler_ci.mipLodBias = 1.0;
11323 sampler_ci.maxAnisotropy = 1;
11324 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11325 sampler_ci.minLod = 1.0;
11326 sampler_ci.maxLod = 1.0;
11327 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11328
11329 VkSampler sampler;
11330 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
11331 ASSERT_VK_SUCCESS(err);
11332
11333 VkDescriptorImageInfo info = {};
11334 info.sampler = sampler;
11335
11336 VkWriteDescriptorSet descriptor_write;
11337 memset(&descriptor_write, 0, sizeof(descriptor_write));
11338 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11339 descriptor_write.dstSet = descriptor_set;
11340 descriptor_write.dstBinding = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011341 descriptor_write.descriptorCount = 1; // Lie here to avoid parameter_validation error
Tobin Ehlise202b2d2016-11-21 10:36:16 -070011342 // This is the wrong type, but empty binding error will be flagged first
11343 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
11344 descriptor_write.pImageInfo = &info;
11345
11346 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02348);
11347 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11348 m_errorMonitor->VerifyFound();
11349
11350 vkDestroySampler(m_device->device(), sampler, NULL);
11351 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11352 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11353}
11354
Karl Schultz6addd812016-02-02 17:17:23 -070011355TEST_F(VkLayerTest, InvalidDSUpdateStruct) {
11356 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_*
11357 // types
11358 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011359
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011360 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 -060011361
Tony Barbour1fa09702017-03-16 12:09:08 -060011362 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011363
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011364 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011365 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11366 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011367
11368 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011369 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11370 ds_pool_ci.pNext = NULL;
11371 ds_pool_ci.maxSets = 1;
11372 ds_pool_ci.poolSizeCount = 1;
11373 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060011374
Tobin Ehlis3b780662015-05-28 12:11:26 -060011375 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011376 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011377 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -060011378 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011379 dsl_binding.binding = 0;
11380 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11381 dsl_binding.descriptorCount = 1;
11382 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11383 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011384
Tony Barboureb254902015-07-15 12:50:33 -060011385 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011386 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11387 ds_layout_ci.pNext = NULL;
11388 ds_layout_ci.bindingCount = 1;
11389 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060011390
Tobin Ehlis3b780662015-05-28 12:11:26 -060011391 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011392 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011393 ASSERT_VK_SUCCESS(err);
11394
11395 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011396 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011397 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011398 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011399 alloc_info.descriptorPool = ds_pool;
11400 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011401 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011402 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011403
Tony Barboureb254902015-07-15 12:50:33 -060011404 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011405 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11406 sampler_ci.pNext = NULL;
11407 sampler_ci.magFilter = VK_FILTER_NEAREST;
11408 sampler_ci.minFilter = VK_FILTER_NEAREST;
11409 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11410 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11411 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11412 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11413 sampler_ci.mipLodBias = 1.0;
11414 sampler_ci.anisotropyEnable = VK_FALSE;
11415 sampler_ci.maxAnisotropy = 1;
11416 sampler_ci.compareEnable = VK_FALSE;
11417 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11418 sampler_ci.minLod = 1.0;
11419 sampler_ci.maxLod = 1.0;
11420 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11421 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011422 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011423 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011424 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011425
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060011426 VkDescriptorImageInfo info = {};
11427 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011428
11429 VkWriteDescriptorSet descriptor_write;
11430 memset(&descriptor_write, 0, sizeof(descriptor_write));
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011431 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011432 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011433 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011434 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011435 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060011436 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011437
11438 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11439
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011440 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011441
Chia-I Wuf7458c52015-10-26 21:10:41 +080011442 vkDestroySampler(m_device->device(), sampler, NULL);
11443 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11444 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060011445}
11446
Karl Schultz6addd812016-02-02 17:17:23 -070011447TEST_F(VkLayerTest, SampleDescriptorUpdateError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011448 // Create a single Sampler descriptor and send it an invalid Sampler
Karl Schultz6addd812016-02-02 17:17:23 -070011449 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011450
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070011451 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00942);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011452
Tony Barbour1fa09702017-03-16 12:09:08 -060011453 ASSERT_NO_FATAL_FAILURE(Init());
Karl Schultz6addd812016-02-02 17:17:23 -070011454 // TODO : Farm Descriptor setup code to helper function(s) to reduce copied
11455 // code
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011456 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011457 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
11458 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011459
11460 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011461 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11462 ds_pool_ci.pNext = NULL;
11463 ds_pool_ci.maxSets = 1;
11464 ds_pool_ci.poolSizeCount = 1;
11465 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011466
11467 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011468 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011469 ASSERT_VK_SUCCESS(err);
11470
11471 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011472 dsl_binding.binding = 0;
11473 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
11474 dsl_binding.descriptorCount = 1;
11475 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11476 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011477
11478 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011479 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11480 ds_layout_ci.pNext = NULL;
11481 ds_layout_ci.bindingCount = 1;
11482 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011483 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011484 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011485 ASSERT_VK_SUCCESS(err);
11486
11487 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011488 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011489 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011490 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011491 alloc_info.descriptorPool = ds_pool;
11492 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011493 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011494 ASSERT_VK_SUCCESS(err);
11495
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011496 VkSampler sampler = (VkSampler)((size_t)0xbaadbeef); // Sampler with invalid handle
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011497
11498 VkDescriptorImageInfo descriptor_info;
11499 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
11500 descriptor_info.sampler = sampler;
11501
11502 VkWriteDescriptorSet descriptor_write;
11503 memset(&descriptor_write, 0, sizeof(descriptor_write));
11504 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011505 descriptor_write.dstSet = descriptorSet;
11506 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011507 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011508 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
11509 descriptor_write.pImageInfo = &descriptor_info;
11510
11511 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11512
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011513 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011514
Chia-I Wuf7458c52015-10-26 21:10:41 +080011515 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11516 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011517}
11518
Karl Schultz6addd812016-02-02 17:17:23 -070011519TEST_F(VkLayerTest, ImageViewDescriptorUpdateError) {
11520 // Create a single combined Image/Sampler descriptor and send it an invalid
11521 // imageView
11522 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011523
Karl Schultzf78bcdd2016-11-30 12:36:01 -070011524 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00943);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011525
Tony Barbour1fa09702017-03-16 12:09:08 -060011526 ASSERT_NO_FATAL_FAILURE(Init());
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011527 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011528 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11529 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011530
11531 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011532 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11533 ds_pool_ci.pNext = NULL;
11534 ds_pool_ci.maxSets = 1;
11535 ds_pool_ci.poolSizeCount = 1;
11536 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011537
11538 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011539 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011540 ASSERT_VK_SUCCESS(err);
11541
11542 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011543 dsl_binding.binding = 0;
11544 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11545 dsl_binding.descriptorCount = 1;
11546 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11547 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011548
11549 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011550 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11551 ds_layout_ci.pNext = NULL;
11552 ds_layout_ci.bindingCount = 1;
11553 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011554 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011555 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011556 ASSERT_VK_SUCCESS(err);
11557
11558 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011559 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011560 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011561 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011562 alloc_info.descriptorPool = ds_pool;
11563 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011564 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011565 ASSERT_VK_SUCCESS(err);
11566
11567 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011568 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11569 sampler_ci.pNext = NULL;
11570 sampler_ci.magFilter = VK_FILTER_NEAREST;
11571 sampler_ci.minFilter = VK_FILTER_NEAREST;
11572 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11573 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11574 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11575 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11576 sampler_ci.mipLodBias = 1.0;
11577 sampler_ci.anisotropyEnable = VK_FALSE;
11578 sampler_ci.maxAnisotropy = 1;
11579 sampler_ci.compareEnable = VK_FALSE;
11580 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11581 sampler_ci.minLod = 1.0;
11582 sampler_ci.maxLod = 1.0;
11583 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11584 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011585
11586 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011587 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011588 ASSERT_VK_SUCCESS(err);
11589
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011590 VkImageView view = (VkImageView)((size_t)0xbaadbeef); // invalid imageView object
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011591
11592 VkDescriptorImageInfo descriptor_info;
11593 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
11594 descriptor_info.sampler = sampler;
11595 descriptor_info.imageView = view;
11596
11597 VkWriteDescriptorSet descriptor_write;
11598 memset(&descriptor_write, 0, sizeof(descriptor_write));
11599 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011600 descriptor_write.dstSet = descriptorSet;
11601 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011602 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011603 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11604 descriptor_write.pImageInfo = &descriptor_info;
11605
11606 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11607
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011608 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011609
Chia-I Wuf7458c52015-10-26 21:10:41 +080011610 vkDestroySampler(m_device->device(), sampler, NULL);
11611 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11612 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011613}
11614
Karl Schultz6addd812016-02-02 17:17:23 -070011615TEST_F(VkLayerTest, CopyDescriptorUpdateErrors) {
11616 // Create DS w/ layout of 2 types, write update 1 and attempt to copy-update
11617 // into the other
11618 VkResult err;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011619
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011620 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11621 " binding #1 with type "
11622 "VK_DESCRIPTOR_TYPE_SAMPLER. Types do "
11623 "not match.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011624
Tony Barbour1fa09702017-03-16 12:09:08 -060011625 ASSERT_NO_FATAL_FAILURE(Init());
Karl Schultz6addd812016-02-02 17:17:23 -070011626 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011627 VkDescriptorPoolSize ds_type_count[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011628 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11629 ds_type_count[0].descriptorCount = 1;
11630 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
11631 ds_type_count[1].descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011632
11633 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011634 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11635 ds_pool_ci.pNext = NULL;
11636 ds_pool_ci.maxSets = 1;
11637 ds_pool_ci.poolSizeCount = 2;
11638 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011639
11640 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011641 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis04356f92015-10-27 16:35:27 -060011642 ASSERT_VK_SUCCESS(err);
11643 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011644 dsl_binding[0].binding = 0;
11645 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11646 dsl_binding[0].descriptorCount = 1;
11647 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
11648 dsl_binding[0].pImmutableSamplers = NULL;
11649 dsl_binding[1].binding = 1;
11650 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
11651 dsl_binding[1].descriptorCount = 1;
11652 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
11653 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011654
11655 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011656 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11657 ds_layout_ci.pNext = NULL;
11658 ds_layout_ci.bindingCount = 2;
11659 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011660
11661 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011662 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis04356f92015-10-27 16:35:27 -060011663 ASSERT_VK_SUCCESS(err);
11664
11665 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011666 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011667 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011668 alloc_info.descriptorSetCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011669 alloc_info.descriptorPool = ds_pool;
11670 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011671 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis04356f92015-10-27 16:35:27 -060011672 ASSERT_VK_SUCCESS(err);
11673
11674 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011675 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11676 sampler_ci.pNext = NULL;
11677 sampler_ci.magFilter = VK_FILTER_NEAREST;
11678 sampler_ci.minFilter = VK_FILTER_NEAREST;
11679 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11680 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11681 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11682 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11683 sampler_ci.mipLodBias = 1.0;
11684 sampler_ci.anisotropyEnable = VK_FALSE;
11685 sampler_ci.maxAnisotropy = 1;
11686 sampler_ci.compareEnable = VK_FALSE;
11687 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11688 sampler_ci.minLod = 1.0;
11689 sampler_ci.maxLod = 1.0;
11690 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11691 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011692
11693 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011694 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis04356f92015-10-27 16:35:27 -060011695 ASSERT_VK_SUCCESS(err);
11696
11697 VkDescriptorImageInfo info = {};
11698 info.sampler = sampler;
11699
11700 VkWriteDescriptorSet descriptor_write;
11701 memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet));
11702 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011703 descriptor_write.dstSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011704 descriptor_write.dstBinding = 1; // SAMPLER binding from layout above
Chia-I Wud50a7d72015-10-26 20:48:51 +080011705 descriptor_write.descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011706 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
11707 descriptor_write.pImageInfo = &info;
11708 // This write update should succeed
11709 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11710 // Now perform a copy update that fails due to type mismatch
11711 VkCopyDescriptorSet copy_ds_update;
11712 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
11713 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
11714 copy_ds_update.srcSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011715 copy_ds_update.srcBinding = 1; // Copy from SAMPLER binding
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011716 copy_ds_update.dstSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011717 copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding
11718 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -060011719 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
11720
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011721 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -060011722 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011723 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 -060011724 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
11725 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
11726 copy_ds_update.srcSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011727 copy_ds_update.srcBinding = 3; // ERROR : Invalid binding for matching layout
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011728 copy_ds_update.dstSet = descriptorSet;
11729 copy_ds_update.dstBinding = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011730 copy_ds_update.descriptorCount = 1; // Copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -060011731 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
11732
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011733 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011734
Tobin Ehlis04356f92015-10-27 16:35:27 -060011735 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011736 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11737 " binding#1 with offset index of 1 plus "
11738 "update array offset of 0 and update of "
11739 "5 descriptors oversteps total number "
11740 "of descriptors in set: 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011741
Tobin Ehlis04356f92015-10-27 16:35:27 -060011742 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
11743 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
11744 copy_ds_update.srcSet = descriptorSet;
11745 copy_ds_update.srcBinding = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011746 copy_ds_update.dstSet = descriptorSet;
11747 copy_ds_update.dstBinding = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011748 copy_ds_update.descriptorCount = 5; // ERROR copy 5 descriptors (out of bounds for layout)
Tobin Ehlis04356f92015-10-27 16:35:27 -060011749 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
11750
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011751 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -060011752
Chia-I Wuf7458c52015-10-26 21:10:41 +080011753 vkDestroySampler(m_device->device(), sampler, NULL);
11754 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11755 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis04356f92015-10-27 16:35:27 -060011756}
11757
Karl Schultz6addd812016-02-02 17:17:23 -070011758TEST_F(VkLayerTest, NumSamplesMismatch) {
11759 // Create CommandBuffer where MSAA samples doesn't match RenderPass
11760 // sampleCount
11761 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011762
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011763 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Num samples mismatch! ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011764
Tony Barbour1fa09702017-03-16 12:09:08 -060011765 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis3b780662015-05-28 12:11:26 -060011766 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011767 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -060011768 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011769 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011770
11771 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011772 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11773 ds_pool_ci.pNext = NULL;
11774 ds_pool_ci.maxSets = 1;
11775 ds_pool_ci.poolSizeCount = 1;
11776 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060011777
Tobin Ehlis3b780662015-05-28 12:11:26 -060011778 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011779 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011780 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011781
Tony Barboureb254902015-07-15 12:50:33 -060011782 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +080011783 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -060011784 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +080011785 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011786 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11787 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011788
Tony Barboureb254902015-07-15 12:50:33 -060011789 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11790 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11791 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011792 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -070011793 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060011794
Tobin Ehlis3b780662015-05-28 12:11:26 -060011795 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011796 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011797 ASSERT_VK_SUCCESS(err);
11798
11799 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011800 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011801 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011802 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011803 alloc_info.descriptorPool = ds_pool;
11804 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011805 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011806 ASSERT_VK_SUCCESS(err);
11807
Tony Barboureb254902015-07-15 12:50:33 -060011808 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011809 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070011810 pipe_ms_state_ci.pNext = NULL;
11811 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
11812 pipe_ms_state_ci.sampleShadingEnable = 0;
11813 pipe_ms_state_ci.minSampleShading = 1.0;
11814 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011815
Tony Barboureb254902015-07-15 12:50:33 -060011816 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011817 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11818 pipeline_layout_ci.pNext = NULL;
11819 pipeline_layout_ci.setLayoutCount = 1;
11820 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011821
11822 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011823 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011824 ASSERT_VK_SUCCESS(err);
11825
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011826 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011827 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 -060011828 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011829 VkPipelineObj pipe(m_device);
11830 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060011831 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -060011832 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011833 pipe.SetMSAA(&pipe_ms_state_ci);
11834 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis3b780662015-05-28 12:11:26 -060011835
Tony Barbour552f6c02016-12-21 14:34:07 -070011836 m_commandBuffer->BeginCommandBuffer();
11837 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011838 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis3b780662015-05-28 12:11:26 -060011839
Rene Lindsay3bdc7a42017-01-06 13:20:15 -070011840 VkViewport viewport = {0, 0, 16, 16, 0, 1};
11841 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
11842 VkRect2D scissor = {{0, 0}, {16, 16}};
11843 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
11844
Mark Young29927482016-05-04 14:38:51 -060011845 // Render triangle (the error should trigger on the attempt to draw).
11846 Draw(3, 1, 0, 0);
11847
11848 // Finalize recording of the command buffer
Tony Barbour552f6c02016-12-21 14:34:07 -070011849 m_commandBuffer->EndRenderPass();
11850 m_commandBuffer->EndCommandBuffer();
Mark Young29927482016-05-04 14:38:51 -060011851
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011852 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011853
Chia-I Wuf7458c52015-10-26 21:10:41 +080011854 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11855 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11856 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060011857}
Mark Young29927482016-05-04 14:38:51 -060011858
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011859TEST_F(VkLayerTest, RenderPassIncompatible) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011860 TEST_DESCRIPTION(
11861 "Hit RenderPass incompatible cases. "
11862 "Initial case is drawing with an active renderpass that's "
11863 "not compatible with the bound pipeline state object's creation renderpass");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011864 VkResult err;
11865
Tony Barbour1fa09702017-03-16 12:09:08 -060011866 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011867 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11868
11869 VkDescriptorSetLayoutBinding dsl_binding = {};
11870 dsl_binding.binding = 0;
11871 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11872 dsl_binding.descriptorCount = 1;
11873 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11874 dsl_binding.pImmutableSamplers = NULL;
11875
11876 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11877 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11878 ds_layout_ci.pNext = NULL;
11879 ds_layout_ci.bindingCount = 1;
11880 ds_layout_ci.pBindings = &dsl_binding;
11881
11882 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011883 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011884 ASSERT_VK_SUCCESS(err);
11885
11886 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11887 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11888 pipeline_layout_ci.pNext = NULL;
11889 pipeline_layout_ci.setLayoutCount = 1;
11890 pipeline_layout_ci.pSetLayouts = &ds_layout;
11891
11892 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011893 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011894 ASSERT_VK_SUCCESS(err);
11895
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011896 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011897 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 -060011898 // but add it to be able to run on more devices
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011899 // Create a renderpass that will be incompatible with default renderpass
11900 VkAttachmentReference attach = {};
Cort Stratton7547f772017-05-04 15:18:52 -070011901 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011902 VkAttachmentReference color_att = {};
Cort Stratton7547f772017-05-04 15:18:52 -070011903 color_att.layout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011904 VkSubpassDescription subpass = {};
11905 subpass.inputAttachmentCount = 1;
11906 subpass.pInputAttachments = &attach;
11907 subpass.colorAttachmentCount = 1;
11908 subpass.pColorAttachments = &color_att;
11909 VkRenderPassCreateInfo rpci = {};
11910 rpci.subpassCount = 1;
11911 rpci.pSubpasses = &subpass;
11912 rpci.attachmentCount = 1;
11913 VkAttachmentDescription attach_desc = {};
11914 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Cody Northropbd16af12016-06-21 09:25:48 -060011915 // Format incompatible with PSO RP color attach format B8G8R8A8_UNORM
11916 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011917 rpci.pAttachments = &attach_desc;
11918 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
11919 VkRenderPass rp;
11920 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11921 VkPipelineObj pipe(m_device);
11922 pipe.AddShader(&vs);
11923 pipe.AddShader(&fs);
11924 pipe.AddColorAttachment();
11925 VkViewport view_port = {};
11926 m_viewports.push_back(view_port);
11927 pipe.SetViewport(m_viewports);
11928 VkRect2D rect = {};
11929 m_scissors.push_back(rect);
11930 pipe.SetScissor(m_scissors);
11931 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11932
11933 VkCommandBufferInheritanceInfo cbii = {};
11934 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
11935 cbii.renderPass = rp;
11936 cbii.subpass = 0;
11937 VkCommandBufferBeginInfo cbbi = {};
11938 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
11939 cbbi.pInheritanceInfo = &cbii;
11940 vkBeginCommandBuffer(m_commandBuffer->handle(), &cbbi);
11941 VkRenderPassBeginInfo rpbi = {};
11942 rpbi.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
11943 rpbi.framebuffer = m_framebuffer;
11944 rpbi.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011945 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
11946 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011947
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011948 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is incompatible w/ gfx pipeline ");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011949 // Render triangle (the error should trigger on the attempt to draw).
11950 Draw(3, 1, 0, 0);
11951
11952 // Finalize recording of the command buffer
Tony Barbour552f6c02016-12-21 14:34:07 -070011953 m_commandBuffer->EndRenderPass();
11954 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011955
11956 m_errorMonitor->VerifyFound();
11957
11958 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11959 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11960 vkDestroyRenderPass(m_device->device(), rp, NULL);
11961}
11962
Mark Youngc89c6312016-03-31 16:03:20 -060011963TEST_F(VkLayerTest, NumBlendAttachMismatch) {
11964 // Create Pipeline where the number of blend attachments doesn't match the
11965 // number of color attachments. In this case, we don't add any color
11966 // blend attachments even though we have a color attachment.
11967 VkResult err;
11968
Tobin Ehlis974c0d92017-02-01 13:31:22 -070011969 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02109);
Mark Youngc89c6312016-03-31 16:03:20 -060011970
Tony Barbour1fa09702017-03-16 12:09:08 -060011971 ASSERT_NO_FATAL_FAILURE(Init());
Mark Youngc89c6312016-03-31 16:03:20 -060011972 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11973 VkDescriptorPoolSize ds_type_count = {};
11974 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11975 ds_type_count.descriptorCount = 1;
11976
11977 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11978 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11979 ds_pool_ci.pNext = NULL;
11980 ds_pool_ci.maxSets = 1;
11981 ds_pool_ci.poolSizeCount = 1;
11982 ds_pool_ci.pPoolSizes = &ds_type_count;
11983
11984 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011985 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Youngc89c6312016-03-31 16:03:20 -060011986 ASSERT_VK_SUCCESS(err);
11987
11988 VkDescriptorSetLayoutBinding dsl_binding = {};
11989 dsl_binding.binding = 0;
11990 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11991 dsl_binding.descriptorCount = 1;
11992 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11993 dsl_binding.pImmutableSamplers = NULL;
11994
11995 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11996 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11997 ds_layout_ci.pNext = NULL;
11998 ds_layout_ci.bindingCount = 1;
11999 ds_layout_ci.pBindings = &dsl_binding;
12000
12001 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012002 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Youngc89c6312016-03-31 16:03:20 -060012003 ASSERT_VK_SUCCESS(err);
12004
12005 VkDescriptorSet descriptorSet;
12006 VkDescriptorSetAllocateInfo alloc_info = {};
12007 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12008 alloc_info.descriptorSetCount = 1;
12009 alloc_info.descriptorPool = ds_pool;
12010 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012011 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Youngc89c6312016-03-31 16:03:20 -060012012 ASSERT_VK_SUCCESS(err);
12013
12014 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012015 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Youngc89c6312016-03-31 16:03:20 -060012016 pipe_ms_state_ci.pNext = NULL;
12017 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
12018 pipe_ms_state_ci.sampleShadingEnable = 0;
12019 pipe_ms_state_ci.minSampleShading = 1.0;
12020 pipe_ms_state_ci.pSampleMask = NULL;
12021
12022 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12023 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12024 pipeline_layout_ci.pNext = NULL;
12025 pipeline_layout_ci.setLayoutCount = 1;
12026 pipeline_layout_ci.pSetLayouts = &ds_layout;
12027
12028 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012029 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Youngc89c6312016-03-31 16:03:20 -060012030 ASSERT_VK_SUCCESS(err);
12031
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012032 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012033 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012034 // but add it to be able to run on more devices
Mark Youngc89c6312016-03-31 16:03:20 -060012035 VkPipelineObj pipe(m_device);
12036 pipe.AddShader(&vs);
12037 pipe.AddShader(&fs);
12038 pipe.SetMSAA(&pipe_ms_state_ci);
12039 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012040 m_errorMonitor->VerifyFound();
Mark Youngc89c6312016-03-31 16:03:20 -060012041
12042 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12043 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12044 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
12045}
Mark Young29927482016-05-04 14:38:51 -060012046
Mark Muellerd4914412016-06-13 17:52:06 -060012047TEST_F(VkLayerTest, MissingClearAttachment) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012048 TEST_DESCRIPTION(
12049 "Points to a wrong colorAttachment index in a VkClearAttachment "
12050 "structure passed to vkCmdClearAttachments");
Tony Barbour1fa09702017-03-16 12:09:08 -060012051 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012052 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01114);
Mark Muellerd4914412016-06-13 17:52:06 -060012053
12054 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailCmdClearAttachments);
12055 m_errorMonitor->VerifyFound();
12056}
12057
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070012058TEST_F(VkLayerTest, CmdClearAttachmentTests) {
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070012059 TEST_DESCRIPTION("Various tests for validating usage of vkCmdClearAttachments");
12060 VkResult err;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012061
Tony Barbour1fa09702017-03-16 12:09:08 -060012062 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis53eddda2015-07-01 16:46:13 -060012063 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060012064
Chia-I Wu1b99bb22015-10-27 19:25:11 +080012065 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012066 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12067 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060012068
12069 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012070 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12071 ds_pool_ci.pNext = NULL;
12072 ds_pool_ci.maxSets = 1;
12073 ds_pool_ci.poolSizeCount = 1;
12074 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060012075
Tobin Ehlis53eddda2015-07-01 16:46:13 -060012076 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012077 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060012078 ASSERT_VK_SUCCESS(err);
12079
Tony Barboureb254902015-07-15 12:50:33 -060012080 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012081 dsl_binding.binding = 0;
12082 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12083 dsl_binding.descriptorCount = 1;
12084 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
12085 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060012086
Tony Barboureb254902015-07-15 12:50:33 -060012087 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012088 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12089 ds_layout_ci.pNext = NULL;
12090 ds_layout_ci.bindingCount = 1;
12091 ds_layout_ci.pBindings = &dsl_binding;
Mark Lobodzinski209b5292015-09-17 09:44:05 -060012092
Tobin Ehlis53eddda2015-07-01 16:46:13 -060012093 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012094 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060012095 ASSERT_VK_SUCCESS(err);
12096
12097 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012098 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080012099 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070012100 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060012101 alloc_info.descriptorPool = ds_pool;
12102 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012103 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060012104 ASSERT_VK_SUCCESS(err);
12105
Tony Barboureb254902015-07-15 12:50:33 -060012106 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012107 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070012108 pipe_ms_state_ci.pNext = NULL;
12109 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
12110 pipe_ms_state_ci.sampleShadingEnable = 0;
12111 pipe_ms_state_ci.minSampleShading = 1.0;
12112 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060012113
Tony Barboureb254902015-07-15 12:50:33 -060012114 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012115 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12116 pipeline_layout_ci.pNext = NULL;
12117 pipeline_layout_ci.setLayoutCount = 1;
12118 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060012119
12120 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012121 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060012122 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski209b5292015-09-17 09:44:05 -060012123
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012124 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -060012125 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -070012126 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012127 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012128
Tony Barbour62e1a5b2015-08-06 10:16:07 -060012129 VkPipelineObj pipe(m_device);
12130 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060012131 pipe.AddShader(&fs);
Jeremy Hayes7332f342017-03-09 15:54:12 -070012132 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060012133 pipe.SetMSAA(&pipe_ms_state_ci);
12134 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060012135
Tony Barbour552f6c02016-12-21 14:34:07 -070012136 m_commandBuffer->BeginCommandBuffer();
12137 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060012138
Karl Schultz6addd812016-02-02 17:17:23 -070012139 // Main thing we care about for this test is that the VkImage obj we're
12140 // clearing matches Color Attachment of FB
Tobin Ehlis53eddda2015-07-01 16:46:13 -060012141 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -060012142 VkClearAttachment color_attachment;
12143 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12144 color_attachment.clearValue.color.float32[0] = 1.0;
12145 color_attachment.clearValue.color.float32[1] = 1.0;
12146 color_attachment.clearValue.color.float32[2] = 1.0;
12147 color_attachment.clearValue.color.float32[3] = 1.0;
12148 color_attachment.colorAttachment = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012149 VkClearRect clear_rect = {{{0, 0}, {(uint32_t)m_width, (uint32_t)m_height}}};
Tobin Ehlis53eddda2015-07-01 16:46:13 -060012150
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070012151 // Call for full-sized FB Color attachment prior to issuing a Draw
12152 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070012153 "vkCmdClearAttachments() issued on command buffer object ");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012154 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070012155 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012156
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070012157 clear_rect.rect.extent.width = renderPassBeginInfo().renderArea.extent.width + 4;
12158 clear_rect.rect.extent.height = clear_rect.rect.extent.height / 2;
12159 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01115);
12160 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
12161 m_errorMonitor->VerifyFound();
12162
12163 clear_rect.rect.extent.width = (uint32_t)m_width / 2;
12164 clear_rect.layerCount = 2;
12165 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01116);
12166 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012167 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060012168
Chia-I Wuf7458c52015-10-26 21:10:41 +080012169 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12170 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12171 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060012172}
12173
Karl Schultz6addd812016-02-02 17:17:23 -070012174TEST_F(VkLayerTest, VtxBufferBadIndex) {
12175 VkResult err;
Tobin Ehlis502480b2015-06-24 15:53:07 -060012176
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012177 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
12178 "but no vertex buffers are attached to this Pipeline State Object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012179
Tony Barbour1fa09702017-03-16 12:09:08 -060012180 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisd332f282015-10-02 11:00:56 -060012181 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlis502480b2015-06-24 15:53:07 -060012182 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060012183
Chia-I Wu1b99bb22015-10-27 19:25:11 +080012184 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012185 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12186 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060012187
12188 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012189 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12190 ds_pool_ci.pNext = NULL;
12191 ds_pool_ci.maxSets = 1;
12192 ds_pool_ci.poolSizeCount = 1;
12193 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060012194
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060012195 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012196 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis502480b2015-06-24 15:53:07 -060012197 ASSERT_VK_SUCCESS(err);
12198
Tony Barboureb254902015-07-15 12:50:33 -060012199 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012200 dsl_binding.binding = 0;
12201 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12202 dsl_binding.descriptorCount = 1;
12203 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
12204 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060012205
Tony Barboureb254902015-07-15 12:50:33 -060012206 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012207 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12208 ds_layout_ci.pNext = NULL;
12209 ds_layout_ci.bindingCount = 1;
12210 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060012211
Tobin Ehlis502480b2015-06-24 15:53:07 -060012212 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012213 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060012214 ASSERT_VK_SUCCESS(err);
12215
12216 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012217 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080012218 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070012219 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060012220 alloc_info.descriptorPool = ds_pool;
12221 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012222 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis502480b2015-06-24 15:53:07 -060012223 ASSERT_VK_SUCCESS(err);
12224
Tony Barboureb254902015-07-15 12:50:33 -060012225 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012226 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070012227 pipe_ms_state_ci.pNext = NULL;
12228 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
12229 pipe_ms_state_ci.sampleShadingEnable = 0;
12230 pipe_ms_state_ci.minSampleShading = 1.0;
12231 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060012232
Tony Barboureb254902015-07-15 12:50:33 -060012233 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012234 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12235 pipeline_layout_ci.pNext = NULL;
12236 pipeline_layout_ci.setLayoutCount = 1;
12237 pipeline_layout_ci.pSetLayouts = &ds_layout;
12238 VkPipelineLayout pipeline_layout;
Tobin Ehlis502480b2015-06-24 15:53:07 -060012239
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012240 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060012241 ASSERT_VK_SUCCESS(err);
12242
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012243 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012244 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 -060012245 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -060012246 VkPipelineObj pipe(m_device);
12247 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060012248 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -060012249 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060012250 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -060012251 pipe.SetViewport(m_viewports);
12252 pipe.SetScissor(m_scissors);
Tony Barbour62e1a5b2015-08-06 10:16:07 -060012253 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060012254
Tony Barbour552f6c02016-12-21 14:34:07 -070012255 m_commandBuffer->BeginCommandBuffer();
12256 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012257 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisf7bf4502015-09-09 15:12:35 -060012258 // Don't care about actual data, just need to get to draw to flag error
12259 static const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012260 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), (const void *)&vbo_data);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012261 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -060012262 Draw(1, 0, 0, 0);
Tobin Ehlis502480b2015-06-24 15:53:07 -060012263
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012264 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060012265
Chia-I Wuf7458c52015-10-26 21:10:41 +080012266 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12267 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12268 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis502480b2015-06-24 15:53:07 -060012269}
Mark Muellerdfe37552016-07-07 14:47:42 -060012270
Mark Mueller2ee294f2016-08-04 12:59:48 -060012271TEST_F(VkLayerTest, MismatchCountQueueCreateRequestedFeature) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012272 TEST_DESCRIPTION(
12273 "Use an invalid count in a vkEnumeratePhysicalDevices call."
12274 "Use invalid Queue Family Index in vkCreateDevice");
Tony Barbour1fa09702017-03-16 12:09:08 -060012275 ASSERT_NO_FATAL_FAILURE(Init());
Mark Mueller2ee294f2016-08-04 12:59:48 -060012276
Mark Mueller880fce52016-08-17 15:23:23 -060012277 // The following test fails with recent NVidia drivers.
12278 // By the time core_validation is reached, the NVidia
12279 // driver has sanitized the invalid condition and core_validation
12280 // is not introduced to the failure condition. This is not the case
12281 // with AMD and Mesa drivers. Futher investigation is required
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012282 // uint32_t count = static_cast<uint32_t>(~0);
12283 // VkPhysicalDevice physical_device;
12284 // vkEnumeratePhysicalDevices(instance(), &count, &physical_device);
12285 // m_errorMonitor->VerifyFound();
Mark Mueller2ee294f2016-08-04 12:59:48 -060012286
Mark Mueller2ee294f2016-08-04 12:59:48 -060012287 float queue_priority = 0.0;
Mark Mueller2ee294f2016-08-04 12:59:48 -060012288 VkDeviceQueueCreateInfo queue_create_info = {};
12289 queue_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
12290 queue_create_info.queueCount = 1;
12291 queue_create_info.pQueuePriorities = &queue_priority;
12292 queue_create_info.queueFamilyIndex = static_cast<uint32_t>(~0);
12293
12294 VkPhysicalDeviceFeatures features = m_device->phy().features();
12295 VkDevice testDevice;
12296 VkDeviceCreateInfo device_create_info = {};
12297 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
12298 device_create_info.queueCreateInfoCount = 1;
12299 device_create_info.pQueueCreateInfos = &queue_create_info;
12300 device_create_info.pEnabledFeatures = &features;
Jeremy Hayesb26fd042017-03-10 09:13:22 -070012301
Petr Kraus56ed9192017-05-08 23:45:36 +020012302 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00054);
Jeremy Hayes17fd3662017-03-17 11:51:11 -060012303 // The following unexpected error is coming from the LunarG loader. Do not make it a desired message because platforms that do
12304 // not use the LunarG loader (e.g. Android) will not see the message and the test will fail.
12305 m_errorMonitor->SetUnexpectedError("Failed to create device chain.");
Mark Mueller2ee294f2016-08-04 12:59:48 -060012306 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
12307 m_errorMonitor->VerifyFound();
12308
12309 queue_create_info.queueFamilyIndex = 1;
12310
12311 unsigned feature_count = sizeof(VkPhysicalDeviceFeatures) / sizeof(VkBool32);
12312 VkBool32 *feature_array = reinterpret_cast<VkBool32 *>(&features);
12313 for (unsigned i = 0; i < feature_count; i++) {
12314 if (VK_FALSE == feature_array[i]) {
12315 feature_array[i] = VK_TRUE;
Mark Mueller2ee294f2016-08-04 12:59:48 -060012316 device_create_info.pEnabledFeatures = &features;
Jeremy Hayesb26fd042017-03-10 09:13:22 -070012317 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12318 "While calling vkCreateDevice(), requesting feature #");
Jeremy Hayes17fd3662017-03-17 11:51:11 -060012319 // The following unexpected error is coming from the LunarG loader. Do not make it a desired message because platforms
12320 // that do not use the LunarG loader (e.g. Android) will not see the message and the test will fail.
12321 m_errorMonitor->SetUnexpectedError("Failed to create device chain.");
Jeremy Hayesb26fd042017-03-10 09:13:22 -070012322 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12323 "You requested features that are unavailable on this device. You should first "
12324 "query feature availability by calling vkGetPhysicalDeviceFeatures().");
Mark Mueller2ee294f2016-08-04 12:59:48 -060012325 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
12326 m_errorMonitor->VerifyFound();
12327 break;
12328 }
12329 }
12330}
12331
Tobin Ehlis16edf082016-11-21 12:33:49 -070012332TEST_F(VkLayerTest, InvalidQueryPoolCreate) {
12333 TEST_DESCRIPTION("Attempt to create a query pool for PIPELINE_STATISTICS without enabling pipeline stats for the device.");
12334
Tony Barbour1fa09702017-03-16 12:09:08 -060012335 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis16edf082016-11-21 12:33:49 -070012336
12337 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
12338 std::vector<VkDeviceQueueCreateInfo> queue_info;
12339 queue_info.reserve(queue_props.size());
12340 std::vector<std::vector<float>> queue_priorities;
12341 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
12342 VkDeviceQueueCreateInfo qi{};
12343 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
12344 qi.queueFamilyIndex = i;
12345 qi.queueCount = queue_props[i].queueCount;
12346 queue_priorities.emplace_back(qi.queueCount, 0.0f);
12347 qi.pQueuePriorities = queue_priorities[i].data();
12348 queue_info.push_back(qi);
12349 }
12350
12351 std::vector<const char *> device_extension_names;
12352
12353 VkDevice local_device;
12354 VkDeviceCreateInfo device_create_info = {};
12355 auto features = m_device->phy().features();
12356 // Intentionally disable pipeline stats
12357 features.pipelineStatisticsQuery = VK_FALSE;
12358 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
12359 device_create_info.pNext = NULL;
12360 device_create_info.queueCreateInfoCount = queue_info.size();
12361 device_create_info.pQueueCreateInfos = queue_info.data();
12362 device_create_info.enabledLayerCount = 0;
12363 device_create_info.ppEnabledLayerNames = NULL;
12364 device_create_info.pEnabledFeatures = &features;
12365 VkResult err = vkCreateDevice(gpu(), &device_create_info, nullptr, &local_device);
12366 ASSERT_VK_SUCCESS(err);
12367
12368 VkQueryPoolCreateInfo qpci{};
12369 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
12370 qpci.queryType = VK_QUERY_TYPE_PIPELINE_STATISTICS;
12371 qpci.queryCount = 1;
12372 VkQueryPool query_pool;
12373
12374 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01006);
12375 vkCreateQueryPool(local_device, &qpci, nullptr, &query_pool);
12376 m_errorMonitor->VerifyFound();
12377
12378 vkDestroyDevice(local_device, nullptr);
12379}
12380
Mark Mueller2ee294f2016-08-04 12:59:48 -060012381TEST_F(VkLayerTest, InvalidQueueIndexInvalidQuery) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012382 TEST_DESCRIPTION(
12383 "Use an invalid queue index in a vkCmdWaitEvents call."
12384 "End a command buffer with a query still in progress.");
Mark Mueller2ee294f2016-08-04 12:59:48 -060012385
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012386 const char *invalid_queue_index =
12387 "was created with sharingMode of VK_SHARING_MODE_EXCLUSIVE. If one "
12388 "of src- or dstQueueFamilyIndex is VK_QUEUE_FAMILY_IGNORED, both "
12389 "must be.";
Mark Mueller2ee294f2016-08-04 12:59:48 -060012390
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012391 const char *invalid_query = "Ending command buffer with in progress query: queryPool 0x";
Mark Mueller2ee294f2016-08-04 12:59:48 -060012392
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012393 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queue_index);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012394
Tony Barbour1fa09702017-03-16 12:09:08 -060012395 ASSERT_NO_FATAL_FAILURE(Init());
Mark Mueller2ee294f2016-08-04 12:59:48 -060012396
12397 VkEvent event;
12398 VkEventCreateInfo event_create_info{};
12399 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
12400 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
12401
Mark Mueller2ee294f2016-08-04 12:59:48 -060012402 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012403 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012404
Tony Barbour552f6c02016-12-21 14:34:07 -070012405 m_commandBuffer->BeginCommandBuffer();
Mark Mueller2ee294f2016-08-04 12:59:48 -060012406
12407 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060012408 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 -060012409 ASSERT_TRUE(image.initialized());
12410 VkImageMemoryBarrier img_barrier = {};
12411 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
12412 img_barrier.pNext = NULL;
12413 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
12414 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
12415 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
12416 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
12417 img_barrier.image = image.handle();
12418 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
Mark Lobodzinski2a74c5c2016-08-17 13:26:28 -060012419
12420 // QueueFamilyIndex must be VK_QUEUE_FAMILY_IGNORED, this verifies
12421 // that layer validation catches the case when it is not.
12422 img_barrier.dstQueueFamilyIndex = 0;
Mark Mueller2ee294f2016-08-04 12:59:48 -060012423 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12424 img_barrier.subresourceRange.baseArrayLayer = 0;
12425 img_barrier.subresourceRange.baseMipLevel = 0;
12426 img_barrier.subresourceRange.layerCount = 1;
12427 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012428 vkCmdWaitEvents(m_commandBuffer->handle(), 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0,
12429 nullptr, 0, nullptr, 1, &img_barrier);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012430 m_errorMonitor->VerifyFound();
12431
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012432 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_query);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012433
12434 VkQueryPool query_pool;
12435 VkQueryPoolCreateInfo query_pool_create_info = {};
12436 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
12437 query_pool_create_info.queryType = VK_QUERY_TYPE_OCCLUSION;
12438 query_pool_create_info.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012439 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012440
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012441 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0 /*startQuery*/, 1 /*queryCount*/);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012442 vkCmdBeginQuery(m_commandBuffer->handle(), query_pool, 0, 0);
12443
12444 vkEndCommandBuffer(m_commandBuffer->handle());
12445 m_errorMonitor->VerifyFound();
12446
12447 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
12448 vkDestroyEvent(m_device->device(), event, nullptr);
12449}
12450
Mark Muellerdfe37552016-07-07 14:47:42 -060012451TEST_F(VkLayerTest, VertexBufferInvalid) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012452 TEST_DESCRIPTION(
12453 "Submit a command buffer using deleted vertex buffer, "
12454 "delete a buffer twice, use an invalid offset for each "
12455 "buffer type, and attempt to bind a null buffer");
Mark Muellerdfe37552016-07-07 14:47:42 -060012456
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012457 const char *deleted_buffer_in_command_buffer =
12458 "Cannot submit cmd buffer "
12459 "using deleted buffer ";
12460 const char *invalid_offset_message =
12461 "vkBindBufferMemory(): "
12462 "memoryOffset is 0x";
12463 const char *invalid_storage_buffer_offset_message =
12464 "vkBindBufferMemory(): "
12465 "storage memoryOffset "
12466 "is 0x";
12467 const char *invalid_texel_buffer_offset_message =
12468 "vkBindBufferMemory(): "
12469 "texel memoryOffset "
12470 "is 0x";
12471 const char *invalid_uniform_buffer_offset_message =
12472 "vkBindBufferMemory(): "
12473 "uniform memoryOffset "
12474 "is 0x";
Mark Muellerdfe37552016-07-07 14:47:42 -060012475
Tony Barbour1fa09702017-03-16 12:09:08 -060012476 ASSERT_NO_FATAL_FAILURE(Init());
Mark Muellerdfe37552016-07-07 14:47:42 -060012477 ASSERT_NO_FATAL_FAILURE(InitViewport());
12478 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12479
12480 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012481 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -060012482 pipe_ms_state_ci.pNext = NULL;
12483 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
12484 pipe_ms_state_ci.sampleShadingEnable = 0;
12485 pipe_ms_state_ci.minSampleShading = 1.0;
12486 pipe_ms_state_ci.pSampleMask = nullptr;
12487
12488 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12489 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12490 VkPipelineLayout pipeline_layout;
12491
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012492 VkResult err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, nullptr, &pipeline_layout);
Mark Muellerdfe37552016-07-07 14:47:42 -060012493 ASSERT_VK_SUCCESS(err);
12494
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012495 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
12496 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Muellerdfe37552016-07-07 14:47:42 -060012497 VkPipelineObj pipe(m_device);
12498 pipe.AddShader(&vs);
12499 pipe.AddShader(&fs);
12500 pipe.AddColorAttachment();
12501 pipe.SetMSAA(&pipe_ms_state_ci);
12502 pipe.SetViewport(m_viewports);
12503 pipe.SetScissor(m_scissors);
12504 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12505
Tony Barbour552f6c02016-12-21 14:34:07 -070012506 m_commandBuffer->BeginCommandBuffer();
12507 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012508 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Muellerdfe37552016-07-07 14:47:42 -060012509
12510 {
12511 // Create and bind a vertex buffer in a reduced scope, which will cause
12512 // it to be deleted upon leaving this scope
12513 const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012514 VkVerticesObj draw_verticies(m_device, 1, 1, sizeof(vbo_data), 3, vbo_data);
Mark Muellerdfe37552016-07-07 14:47:42 -060012515 draw_verticies.BindVertexBuffers(m_commandBuffer->handle());
12516 draw_verticies.AddVertexInputToPipe(pipe);
12517 }
12518
12519 Draw(1, 0, 0, 0);
12520
Tony Barbour552f6c02016-12-21 14:34:07 -070012521 m_commandBuffer->EndRenderPass();
12522 m_commandBuffer->EndCommandBuffer();
Mark Muellerdfe37552016-07-07 14:47:42 -060012523
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012524 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, deleted_buffer_in_command_buffer);
Mark Muellerdfe37552016-07-07 14:47:42 -060012525 QueueCommandBuffer(false);
12526 m_errorMonitor->VerifyFound();
12527
12528 {
12529 // Create and bind a vertex buffer in a reduced scope, and delete it
12530 // twice, the second through the destructor
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012531 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eDoubleDelete);
Karl Schultzf78bcdd2016-11-30 12:36:01 -070012532 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00680);
Mark Muellerdfe37552016-07-07 14:47:42 -060012533 buffer_test.TestDoubleDestroy();
12534 }
12535 m_errorMonitor->VerifyFound();
12536
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012537 m_errorMonitor->SetUnexpectedError("value of pCreateInfo->usage must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012538 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidMemoryOffset)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060012539 // Create and bind a memory buffer with an invalid offset.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012540 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_offset_message);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012541 m_errorMonitor->SetUnexpectedError(
12542 "If buffer was created with the VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT or VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT, "
12543 "memoryOffset must be a multiple of VkPhysicalDeviceLimits::minTexelBufferOffsetAlignment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012544 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidMemoryOffset);
12545 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012546 m_errorMonitor->VerifyFound();
12547 }
12548
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012549 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset,
12550 VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060012551 // Create and bind a memory buffer with an invalid offset again,
12552 // but look for a texel buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012553 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_texel_buffer_offset_message);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012554 m_errorMonitor->SetUnexpectedError(
12555 "memoryOffset must be an integer multiple of the alignment member of the VkMemoryRequirements structure returned from "
12556 "a call to vkGetBufferMemoryRequirements with buffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012557 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
12558 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012559 m_errorMonitor->VerifyFound();
12560 }
12561
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012562 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060012563 // Create and bind a memory buffer with an invalid offset again, but
12564 // look for a uniform buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012565 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_uniform_buffer_offset_message);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012566 m_errorMonitor->SetUnexpectedError(
12567 "memoryOffset must be an integer multiple of the alignment member of the VkMemoryRequirements structure returned from "
12568 "a call to vkGetBufferMemoryRequirements with buffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012569 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
12570 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012571 m_errorMonitor->VerifyFound();
12572 }
12573
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012574 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060012575 // Create and bind a memory buffer with an invalid offset again, but
12576 // look for a storage buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012577 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_storage_buffer_offset_message);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012578 m_errorMonitor->SetUnexpectedError(
12579 "memoryOffset must be an integer multiple of the alignment member of the VkMemoryRequirements structure returned from "
12580 "a call to vkGetBufferMemoryRequirements with buffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012581 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
12582 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012583 m_errorMonitor->VerifyFound();
12584 }
12585
12586 {
12587 // Attempt to bind a null buffer.
Karl Schultzf78bcdd2016-11-30 12:36:01 -070012588 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00799);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012589 m_errorMonitor->SetUnexpectedError("required parameter memory specified as VK_NULL_HANDLE");
12590 m_errorMonitor->SetUnexpectedError("memory must be a valid VkDeviceMemory handle");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012591 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eBindNullBuffer);
12592 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012593 m_errorMonitor->VerifyFound();
12594 }
12595
12596 {
12597 // Attempt to use an invalid handle to delete a buffer.
Karl Schultzf78bcdd2016-11-30 12:36:01 -070012598 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00622);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012599 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eFreeInvalidHandle);
12600 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012601 }
12602 m_errorMonitor->VerifyFound();
12603
12604 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12605}
12606
Tony Barbourff1351e2017-05-10 11:14:03 -060012607TEST_F(VkLayerTest, BadVertexBufferOffset) {
12608 TEST_DESCRIPTION("Submit an offset past the end of a vertex buffer");
12609
12610 ASSERT_NO_FATAL_FAILURE(Init());
12611 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12612 static const float vbo_data[3] = {1.f, 0.f, 1.f};
Tony Barboure94224e2017-05-11 15:22:43 -060012613 VkConstantBufferObj vbo(m_device, 3, sizeof(float), (const void *)&vbo_data);
Tony Barbourff1351e2017-05-10 11:14:03 -060012614 m_commandBuffer->BeginCommandBuffer();
12615 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
12616 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01417);
Tony Barboure94224e2017-05-11 15:22:43 -060012617 BindVertexBuffer(&vbo, (VkDeviceSize)(3 * sizeof(float)), 1); // Offset at the end of the buffer
Tony Barbourff1351e2017-05-10 11:14:03 -060012618 m_errorMonitor->VerifyFound();
12619}
12620
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012621// INVALID_IMAGE_LAYOUT tests (one other case is hit by MapMemWithoutHostVisibleBit and not here)
12622TEST_F(VkLayerTest, InvalidImageLayout) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012623 TEST_DESCRIPTION(
12624 "Hit all possible validation checks associated with the "
12625 "DRAWSTATE_INVALID_IMAGE_LAYOUT enum. Generally these involve having"
12626 "images in the wrong layout when they're copied or transitioned.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012627 // 3 in ValidateCmdBufImageLayouts
12628 // * -1 Attempt to submit cmd buf w/ deleted image
12629 // * -2 Cmd buf submit of image w/ layout not matching first use w/ subresource
12630 // * -3 Cmd buf submit of image w/ layout not matching first use w/o subresource
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012631
Tony Barbour1fa09702017-03-16 12:09:08 -060012632 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -060012633 auto depth_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbourf887b162017-03-09 10:06:46 -070012634 if (!depth_format) {
12635 printf(" No Depth + Stencil format found. Skipped.\n");
12636 return;
12637 }
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012638 // Create src & dst images to use for copy operations
12639 VkImage src_image;
12640 VkImage dst_image;
Cort3b021012016-12-07 12:00:57 -080012641 VkImage depth_image;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012642
12643 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
12644 const int32_t tex_width = 32;
12645 const int32_t tex_height = 32;
12646
12647 VkImageCreateInfo image_create_info = {};
12648 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
12649 image_create_info.pNext = NULL;
12650 image_create_info.imageType = VK_IMAGE_TYPE_2D;
12651 image_create_info.format = tex_format;
12652 image_create_info.extent.width = tex_width;
12653 image_create_info.extent.height = tex_height;
12654 image_create_info.extent.depth = 1;
12655 image_create_info.mipLevels = 1;
12656 image_create_info.arrayLayers = 4;
12657 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
12658 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
12659 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Cort3b021012016-12-07 12:00:57 -080012660 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012661 image_create_info.flags = 0;
12662
12663 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &src_image);
12664 ASSERT_VK_SUCCESS(err);
Cort3b021012016-12-07 12:00:57 -080012665 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012666 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dst_image);
12667 ASSERT_VK_SUCCESS(err);
Cort3b021012016-12-07 12:00:57 -080012668 image_create_info.format = VK_FORMAT_D32_SFLOAT;
12669 image_create_info.usage |= VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
12670 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &depth_image);
12671 ASSERT_VK_SUCCESS(err);
12672
12673 // Allocate memory
12674 VkMemoryRequirements img_mem_reqs = {};
Cort530cf382016-12-08 09:59:47 -080012675 VkMemoryAllocateInfo mem_alloc = {};
Cort3b021012016-12-07 12:00:57 -080012676 VkDeviceMemory src_image_mem, dst_image_mem, depth_image_mem;
Cort530cf382016-12-08 09:59:47 -080012677 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
12678 mem_alloc.pNext = NULL;
12679 mem_alloc.allocationSize = 0;
12680 mem_alloc.memoryTypeIndex = 0;
Cort3b021012016-12-07 12:00:57 -080012681
12682 vkGetImageMemoryRequirements(m_device->device(), src_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080012683 mem_alloc.allocationSize = img_mem_reqs.size;
12684 bool pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080012685 ASSERT_TRUE(pass);
Cort530cf382016-12-08 09:59:47 -080012686 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &src_image_mem);
Cort3b021012016-12-07 12:00:57 -080012687 ASSERT_VK_SUCCESS(err);
12688
12689 vkGetImageMemoryRequirements(m_device->device(), dst_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080012690 mem_alloc.allocationSize = img_mem_reqs.size;
12691 pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080012692 ASSERT_VK_SUCCESS(err);
Cort530cf382016-12-08 09:59:47 -080012693 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &dst_image_mem);
Cort3b021012016-12-07 12:00:57 -080012694 ASSERT_VK_SUCCESS(err);
12695
12696 vkGetImageMemoryRequirements(m_device->device(), depth_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080012697 mem_alloc.allocationSize = img_mem_reqs.size;
12698 pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080012699 ASSERT_VK_SUCCESS(err);
Cort530cf382016-12-08 09:59:47 -080012700 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &depth_image_mem);
Cort3b021012016-12-07 12:00:57 -080012701 ASSERT_VK_SUCCESS(err);
12702
12703 err = vkBindImageMemory(m_device->device(), src_image, src_image_mem, 0);
12704 ASSERT_VK_SUCCESS(err);
12705 err = vkBindImageMemory(m_device->device(), dst_image, dst_image_mem, 0);
12706 ASSERT_VK_SUCCESS(err);
12707 err = vkBindImageMemory(m_device->device(), depth_image, depth_image_mem, 0);
12708 ASSERT_VK_SUCCESS(err);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012709
Tony Barbour552f6c02016-12-21 14:34:07 -070012710 m_commandBuffer->BeginCommandBuffer();
Cort530cf382016-12-08 09:59:47 -080012711 VkImageCopy copy_region;
12712 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12713 copy_region.srcSubresource.mipLevel = 0;
12714 copy_region.srcSubresource.baseArrayLayer = 0;
12715 copy_region.srcSubresource.layerCount = 1;
12716 copy_region.srcOffset.x = 0;
12717 copy_region.srcOffset.y = 0;
12718 copy_region.srcOffset.z = 0;
12719 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12720 copy_region.dstSubresource.mipLevel = 0;
12721 copy_region.dstSubresource.baseArrayLayer = 0;
12722 copy_region.dstSubresource.layerCount = 1;
12723 copy_region.dstOffset.x = 0;
12724 copy_region.dstOffset.y = 0;
12725 copy_region.dstOffset.z = 0;
12726 copy_region.extent.width = 1;
12727 copy_region.extent.height = 1;
12728 copy_region.extent.depth = 1;
12729
Mark Lobodzinski91c28262017-03-22 13:06:12 -060012730 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
12731 "layout should be VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL instead of GENERAL.");
12732 m_errorMonitor->SetUnexpectedError("layout should be VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL instead of GENERAL.");
Tobin Ehlis74cc6822017-03-14 16:16:51 -060012733
Cort530cf382016-12-08 09:59:47 -080012734 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 -060012735 m_errorMonitor->VerifyFound();
Tobin Ehlise35b66a2017-03-15 12:18:31 -060012736 // The first call hits the expected WARNING and skips the call down the chain, so call a second time to call down chain and
12737 // update layer state
Mark Lobodzinski91c28262017-03-22 13:06:12 -060012738 m_errorMonitor->SetUnexpectedError("layout should be VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL instead of GENERAL.");
12739 m_errorMonitor->SetUnexpectedError("layout should be VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL instead of GENERAL.");
Tobin Ehlise35b66a2017-03-15 12:18:31 -060012740 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 -060012741 // Now cause error due to src image layout changing
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012742 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski91c28262017-03-22 13:06:12 -060012743 "with specific layout VK_IMAGE_LAYOUT_UNDEFINED that "
12744 "doesn't match the actual current layout VK_IMAGE_LAYOUT_GENERAL.");
Mark Lobodzinskic61e1da2017-05-15 16:18:13 -060012745 m_errorMonitor->SetUnexpectedError("is VK_IMAGE_LAYOUT_UNDEFINED but can only be VK_IMAGE_LAYOUT");
Cort530cf382016-12-08 09:59:47 -080012746 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 -060012747 m_errorMonitor->VerifyFound();
12748 // Final src error is due to bad layout type
Tobin Ehlis74cc6822017-03-14 16:16:51 -060012749 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski91c28262017-03-22 13:06:12 -060012750 "is VK_IMAGE_LAYOUT_UNDEFINED but can only be "
Tobin Ehlis74cc6822017-03-14 16:16:51 -060012751 "VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL or VK_IMAGE_LAYOUT_GENERAL.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012752 m_errorMonitor->SetUnexpectedError(
Mark Lobodzinski91c28262017-03-22 13:06:12 -060012753 "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 -080012754 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 -060012755 m_errorMonitor->VerifyFound();
12756 // Now verify same checks for dst
Mark Lobodzinski91c28262017-03-22 13:06:12 -060012757 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
12758 "layout should be VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL instead of GENERAL.");
12759 m_errorMonitor->SetUnexpectedError("layout should be VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL instead of GENERAL.");
Cort530cf382016-12-08 09:59:47 -080012760 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 -060012761 m_errorMonitor->VerifyFound();
12762 // Now cause error due to src image layout changing
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012763 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski91c28262017-03-22 13:06:12 -060012764 "with specific layout VK_IMAGE_LAYOUT_UNDEFINED that doesn't match "
Tobin Ehlis74cc6822017-03-14 16:16:51 -060012765 "the actual current layout VK_IMAGE_LAYOUT_GENERAL.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012766 m_errorMonitor->SetUnexpectedError(
Mark Lobodzinski91c28262017-03-22 13:06:12 -060012767 "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 -080012768 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 -060012769 m_errorMonitor->VerifyFound();
Tobin Ehlis74cc6822017-03-14 16:16:51 -060012770 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski91c28262017-03-22 13:06:12 -060012771 "is VK_IMAGE_LAYOUT_UNDEFINED but can only be VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL "
12772 "or VK_IMAGE_LAYOUT_GENERAL.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012773 m_errorMonitor->SetUnexpectedError(
Mark Lobodzinski91c28262017-03-22 13:06:12 -060012774 "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 -080012775 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 -060012776 m_errorMonitor->VerifyFound();
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010012777
Cort3b021012016-12-07 12:00:57 -080012778 // Convert dst and depth images to TRANSFER_DST for subsequent tests
12779 VkImageMemoryBarrier transfer_dst_image_barrier[1] = {};
12780 transfer_dst_image_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
12781 transfer_dst_image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
12782 transfer_dst_image_barrier[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
12783 transfer_dst_image_barrier[0].srcAccessMask = 0;
12784 transfer_dst_image_barrier[0].dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
12785 transfer_dst_image_barrier[0].image = dst_image;
12786 transfer_dst_image_barrier[0].subresourceRange.layerCount = image_create_info.arrayLayers;
12787 transfer_dst_image_barrier[0].subresourceRange.levelCount = image_create_info.mipLevels;
12788 transfer_dst_image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12789 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
12790 NULL, 0, NULL, 1, transfer_dst_image_barrier);
12791 transfer_dst_image_barrier[0].image = depth_image;
12792 transfer_dst_image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
12793 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
12794 NULL, 0, NULL, 1, transfer_dst_image_barrier);
12795
12796 // Cause errors due to clearing with invalid image layouts
Cort530cf382016-12-08 09:59:47 -080012797 VkClearColorValue color_clear_value = {};
12798 VkImageSubresourceRange clear_range;
12799 clear_range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12800 clear_range.baseMipLevel = 0;
12801 clear_range.baseArrayLayer = 0;
12802 clear_range.layerCount = 1;
12803 clear_range.levelCount = 1;
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010012804
Cort3b021012016-12-07 12:00:57 -080012805 // Fail due to explicitly prohibited layout for color clear (only GENERAL and TRANSFER_DST are permitted).
12806 // Since the image is currently not in UNDEFINED layout, this will emit two errors.
12807 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01086);
12808 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01085);
Cort530cf382016-12-08 09:59:47 -080012809 m_commandBuffer->ClearColorImage(dst_image, VK_IMAGE_LAYOUT_UNDEFINED, &color_clear_value, 1, &clear_range);
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010012810 m_errorMonitor->VerifyFound();
Cort3b021012016-12-07 12:00:57 -080012811 // Fail due to provided layout not matching actual current layout for color clear.
12812 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01085);
Cort530cf382016-12-08 09:59:47 -080012813 m_commandBuffer->ClearColorImage(dst_image, VK_IMAGE_LAYOUT_GENERAL, &color_clear_value, 1, &clear_range);
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010012814 m_errorMonitor->VerifyFound();
Cort3b021012016-12-07 12:00:57 -080012815
Cort530cf382016-12-08 09:59:47 -080012816 VkClearDepthStencilValue depth_clear_value = {};
12817 clear_range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Cort3b021012016-12-07 12:00:57 -080012818
12819 // Fail due to explicitly prohibited layout for depth clear (only GENERAL and TRANSFER_DST are permitted).
12820 // Since the image is currently not in UNDEFINED layout, this will emit two errors.
12821 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01101);
12822 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01100);
Cort530cf382016-12-08 09:59:47 -080012823 m_commandBuffer->ClearDepthStencilImage(depth_image, VK_IMAGE_LAYOUT_UNDEFINED, &depth_clear_value, 1, &clear_range);
Cort3b021012016-12-07 12:00:57 -080012824 m_errorMonitor->VerifyFound();
12825 // Fail due to provided layout not matching actual current layout for depth clear.
12826 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01100);
Cort530cf382016-12-08 09:59:47 -080012827 m_commandBuffer->ClearDepthStencilImage(depth_image, VK_IMAGE_LAYOUT_GENERAL, &depth_clear_value, 1, &clear_range);
Cort3b021012016-12-07 12:00:57 -080012828 m_errorMonitor->VerifyFound();
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010012829
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012830 // Now cause error due to bad image layout transition in PipelineBarrier
12831 VkImageMemoryBarrier image_barrier[1] = {};
Cort3b021012016-12-07 12:00:57 -080012832 image_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012833 image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
Cort3b021012016-12-07 12:00:57 -080012834 image_barrier[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012835 image_barrier[0].image = src_image;
Cort3b021012016-12-07 12:00:57 -080012836 image_barrier[0].subresourceRange.layerCount = image_create_info.arrayLayers;
12837 image_barrier[0].subresourceRange.levelCount = image_create_info.mipLevels;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012838 image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012839 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski91c28262017-03-22 13:06:12 -060012840 "you cannot transition the layout of aspect 1 from "
12841 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL when current layout is "
12842 "VK_IMAGE_LAYOUT_GENERAL.");
Mike Weiblen62d08a32017-03-07 22:18:27 -070012843 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00305);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012844 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
12845 NULL, 0, NULL, 1, image_barrier);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012846 m_errorMonitor->VerifyFound();
12847
12848 // Finally some layout errors at RenderPass create time
12849 // Just hacking in specific state to get to the errors we want so don't copy this unless you know what you're doing.
12850 VkAttachmentReference attach = {};
12851 // perf warning for GENERAL layout w/ non-DS input attachment
12852 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
12853 VkSubpassDescription subpass = {};
12854 subpass.inputAttachmentCount = 1;
12855 subpass.pInputAttachments = &attach;
12856 VkRenderPassCreateInfo rpci = {};
12857 rpci.subpassCount = 1;
12858 rpci.pSubpasses = &subpass;
12859 rpci.attachmentCount = 1;
12860 VkAttachmentDescription attach_desc = {};
12861 attach_desc.format = VK_FORMAT_UNDEFINED;
12862 rpci.pAttachments = &attach_desc;
Tobin Ehlis1efce022016-05-11 10:40:34 -060012863 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012864 VkRenderPass rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012865 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
12866 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012867 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12868 m_errorMonitor->VerifyFound();
12869 // error w/ non-general layout
12870 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
12871
12872 m_errorMonitor->SetDesiredFailureMsg(
12873 VK_DEBUG_REPORT_ERROR_BIT_EXT,
12874 "Layout for input attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be READ_ONLY_OPTIMAL or GENERAL.");
12875 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12876 m_errorMonitor->VerifyFound();
12877 subpass.inputAttachmentCount = 0;
12878 subpass.colorAttachmentCount = 1;
12879 subpass.pColorAttachments = &attach;
12880 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
12881 // perf warning for GENERAL layout on color attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012882 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
12883 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012884 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12885 m_errorMonitor->VerifyFound();
12886 // error w/ non-color opt or GENERAL layout for color attachment
12887 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
12888 m_errorMonitor->SetDesiredFailureMsg(
12889 VK_DEBUG_REPORT_ERROR_BIT_EXT,
12890 "Layout for color attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.");
12891 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12892 m_errorMonitor->VerifyFound();
12893 subpass.colorAttachmentCount = 0;
12894 subpass.pDepthStencilAttachment = &attach;
12895 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
12896 // perf warning for GENERAL layout on DS attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012897 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
12898 "GENERAL layout for depth attachment may not give optimal performance.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012899 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12900 m_errorMonitor->VerifyFound();
12901 // error w/ non-ds opt or GENERAL layout for color attachment
12902 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012903 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12904 "Layout for depth attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be "
12905 "DEPTH_STENCIL_ATTACHMENT_OPTIMAL, DEPTH_STENCIL_READ_ONLY_OPTIMAL or GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012906 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12907 m_errorMonitor->VerifyFound();
Tobin Ehlis1efce022016-05-11 10:40:34 -060012908 // For this error we need a valid renderpass so create default one
12909 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
12910 attach.attachment = 0;
Tony Barbourf887b162017-03-09 10:06:46 -070012911 attach_desc.format = depth_format;
Tobin Ehlis1efce022016-05-11 10:40:34 -060012912 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
12913 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
12914 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
12915 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
12916 // Can't do a CLEAR load on READ_ONLY initialLayout
12917 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
12918 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
12919 attach_desc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012920 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski91c28262017-03-22 13:06:12 -060012921 "with invalid first layout VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL");
Tobin Ehlis1efce022016-05-11 10:40:34 -060012922 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12923 m_errorMonitor->VerifyFound();
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012924
Cort3b021012016-12-07 12:00:57 -080012925 vkFreeMemory(m_device->device(), src_image_mem, NULL);
12926 vkFreeMemory(m_device->device(), dst_image_mem, NULL);
12927 vkFreeMemory(m_device->device(), depth_image_mem, NULL);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012928 vkDestroyImage(m_device->device(), src_image, NULL);
12929 vkDestroyImage(m_device->device(), dst_image, NULL);
Cort3b021012016-12-07 12:00:57 -080012930 vkDestroyImage(m_device->device(), depth_image, NULL);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012931}
Tobin Ehlisd8d89182016-07-18 20:13:11 -060012932
Tobin Ehlise0936662016-10-11 08:10:51 -060012933TEST_F(VkLayerTest, InvalidStorageImageLayout) {
12934 TEST_DESCRIPTION("Attempt to update a STORAGE_IMAGE descriptor w/o GENERAL layout.");
12935 VkResult err;
12936
Tony Barbour1fa09702017-03-16 12:09:08 -060012937 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlise0936662016-10-11 08:10:51 -060012938
12939 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
12940 VkImageTiling tiling;
12941 VkFormatProperties format_properties;
12942 vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties);
12943 if (format_properties.linearTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
12944 tiling = VK_IMAGE_TILING_LINEAR;
12945 } else if (format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
12946 tiling = VK_IMAGE_TILING_OPTIMAL;
12947 } else {
Dave Houlton584d51e2017-02-16 12:52:54 -070012948 printf(" Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; skipped.\n");
Tobin Ehlise0936662016-10-11 08:10:51 -060012949 return;
12950 }
12951
12952 VkDescriptorPoolSize ds_type = {};
12953 ds_type.type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
12954 ds_type.descriptorCount = 1;
12955
12956 VkDescriptorPoolCreateInfo ds_pool_ci = {};
12957 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12958 ds_pool_ci.maxSets = 1;
12959 ds_pool_ci.poolSizeCount = 1;
12960 ds_pool_ci.pPoolSizes = &ds_type;
12961 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
12962
12963 VkDescriptorPool ds_pool;
12964 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
12965 ASSERT_VK_SUCCESS(err);
12966
12967 VkDescriptorSetLayoutBinding dsl_binding = {};
12968 dsl_binding.binding = 0;
12969 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
12970 dsl_binding.descriptorCount = 1;
12971 dsl_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12972 dsl_binding.pImmutableSamplers = NULL;
12973
12974 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
12975 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12976 ds_layout_ci.pNext = NULL;
12977 ds_layout_ci.bindingCount = 1;
12978 ds_layout_ci.pBindings = &dsl_binding;
12979
12980 VkDescriptorSetLayout ds_layout;
12981 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
12982 ASSERT_VK_SUCCESS(err);
12983
12984 VkDescriptorSetAllocateInfo alloc_info = {};
12985 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12986 alloc_info.descriptorSetCount = 1;
12987 alloc_info.descriptorPool = ds_pool;
12988 alloc_info.pSetLayouts = &ds_layout;
12989 VkDescriptorSet descriptor_set;
12990 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
12991 ASSERT_VK_SUCCESS(err);
12992
12993 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12994 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12995 pipeline_layout_ci.pNext = NULL;
12996 pipeline_layout_ci.setLayoutCount = 1;
12997 pipeline_layout_ci.pSetLayouts = &ds_layout;
12998 VkPipelineLayout pipeline_layout;
12999 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
13000 ASSERT_VK_SUCCESS(err);
13001
13002 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060013003 image.Init(32, 32, 1, tex_format, VK_IMAGE_USAGE_STORAGE_BIT, tiling, 0);
Tobin Ehlise0936662016-10-11 08:10:51 -060013004 ASSERT_TRUE(image.initialized());
13005 VkImageView view = image.targetView(tex_format);
13006
13007 VkDescriptorImageInfo image_info = {};
13008 image_info.imageView = view;
13009 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
13010
13011 VkWriteDescriptorSet descriptor_write = {};
13012 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
13013 descriptor_write.dstSet = descriptor_set;
13014 descriptor_write.dstBinding = 0;
13015 descriptor_write.descriptorCount = 1;
13016 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
13017 descriptor_write.pImageInfo = &image_info;
13018
13019 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13020 " of VK_DESCRIPTOR_TYPE_STORAGE_IMAGE type is being updated with layout "
13021 "VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL but according to spec ");
13022 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
13023 m_errorMonitor->VerifyFound();
13024
13025 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
13026 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
13027 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
13028 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
13029}
13030
Chris Forbes3fa68552017-05-18 14:34:05 -070013031TEST_F(VkLayerTest, NonSimultaneousSecondaryMarksPrimary) {
Tony Barbour1fa09702017-03-16 12:09:08 -060013032 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes3fa68552017-05-18 14:34:05 -070013033 const char *simultaneous_use_message =
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013034 "does not have VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set and "
13035 "will cause primary command buffer";
Mark Mueller93b938f2016-08-18 10:27:40 -060013036
Chris Forbes3fa68552017-05-18 14:34:05 -070013037 VkCommandBufferObj secondary(m_device, m_commandPool, VK_COMMAND_BUFFER_LEVEL_SECONDARY);
Mark Mueller93b938f2016-08-18 10:27:40 -060013038
Chris Forbes3fa68552017-05-18 14:34:05 -070013039 secondary.begin();
13040 secondary.end();
Rene Lindsay24cf6c52017-01-04 12:06:59 -070013041
Chris Forbes3fa68552017-05-18 14:34:05 -070013042 VkCommandBufferBeginInfo cbbi = {
13043 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
13044 VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT, nullptr,
13045 };
Mark Mueller93b938f2016-08-18 10:27:40 -060013046
Chris Forbes3fa68552017-05-18 14:34:05 -070013047 m_commandBuffer->begin(&cbbi);
13048 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, simultaneous_use_message);
13049 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary.handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060013050 m_errorMonitor->VerifyFound();
Chris Forbes3fa68552017-05-18 14:34:05 -070013051 m_commandBuffer->end();
13052}
Mark Mueller93b938f2016-08-18 10:27:40 -060013053
Chris Forbes3fa68552017-05-18 14:34:05 -070013054TEST_F(VkLayerTest, SimultaneousUseSecondaryTwoExecutes) {
13055 ASSERT_NO_FATAL_FAILURE(Init());
Mark Mueller93b938f2016-08-18 10:27:40 -060013056
Chris Forbes3fa68552017-05-18 14:34:05 -070013057 const char *simultaneous_use_message = "without VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set!";
Mark Mueller4042b652016-09-05 22:52:21 -060013058
Chris Forbes3fa68552017-05-18 14:34:05 -070013059 VkCommandBufferObj secondary(m_device, m_commandPool, VK_COMMAND_BUFFER_LEVEL_SECONDARY);
13060
13061 VkCommandBufferInheritanceInfo inh = {
13062 VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO, nullptr,
13063 };
13064 VkCommandBufferBeginInfo cbbi = {
13065 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
13066 0, &inh
13067 };
13068
13069 secondary.begin(&cbbi);
13070 secondary.end();
13071
13072 m_commandBuffer->begin();
13073 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary.handle());
13074 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, simultaneous_use_message);
13075 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary.handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060013076 m_errorMonitor->VerifyFound();
Chris Forbes3fa68552017-05-18 14:34:05 -070013077 m_commandBuffer->end();
13078}
Rene Lindsay24cf6c52017-01-04 12:06:59 -070013079
Chris Forbes3fa68552017-05-18 14:34:05 -070013080TEST_F(VkLayerTest, SimultaneousUseSecondarySingleExecute) {
13081 ASSERT_NO_FATAL_FAILURE(Init());
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070013082
Chris Forbes3fa68552017-05-18 14:34:05 -070013083 // variation on previous test executing the same CB twice in the same
13084 // CmdExecuteCommands call
13085
13086 const char *simultaneous_use_message = "without VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set!";
13087
13088 VkCommandBufferObj secondary(m_device, m_commandPool, VK_COMMAND_BUFFER_LEVEL_SECONDARY);
13089
13090 VkCommandBufferInheritanceInfo inh = {
13091 VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO, nullptr,
13092 };
13093 VkCommandBufferBeginInfo cbbi = {
13094 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
13095 0, &inh
13096 };
13097
13098 secondary.begin(&cbbi);
13099 secondary.end();
13100
13101 m_commandBuffer->begin();
13102 VkCommandBuffer cbs[] = { secondary.handle(), secondary.handle() };
13103 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, simultaneous_use_message);
13104 vkCmdExecuteCommands(m_commandBuffer->handle(), 2, cbs);
13105 m_errorMonitor->VerifyFound();
13106 m_commandBuffer->end();
Mark Mueller93b938f2016-08-18 10:27:40 -060013107}
13108
Tony Barbour626994c2017-02-08 15:29:37 -070013109TEST_F(VkLayerTest, SimultaneousUseOneShot) {
13110 TEST_DESCRIPTION(
13111 "Submit the same command buffer twice in one submit looking for simultaneous use and one time submit"
13112 "errors");
13113 const char *simultaneous_use_message = "is already in use and is not marked for simultaneous use";
13114 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 -060013115 ASSERT_NO_FATAL_FAILURE(Init());
Tony Barbour626994c2017-02-08 15:29:37 -070013116
13117 VkCommandBuffer cmd_bufs[2];
13118 VkCommandBufferAllocateInfo alloc_info;
13119 alloc_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
13120 alloc_info.pNext = NULL;
13121 alloc_info.commandBufferCount = 2;
Mike Schuchardt06304c22017-03-01 17:09:09 -070013122 alloc_info.commandPool = m_commandPool->handle();
Tony Barbour626994c2017-02-08 15:29:37 -070013123 alloc_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
13124 vkAllocateCommandBuffers(m_device->device(), &alloc_info, cmd_bufs);
13125
13126 VkCommandBufferBeginInfo cb_binfo;
13127 cb_binfo.pNext = NULL;
13128 cb_binfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
13129 cb_binfo.pInheritanceInfo = VK_NULL_HANDLE;
13130 cb_binfo.flags = 0;
13131 vkBeginCommandBuffer(cmd_bufs[0], &cb_binfo);
13132 VkViewport viewport = {0, 0, 16, 16, 0, 1};
13133 vkCmdSetViewport(cmd_bufs[0], 0, 1, &viewport);
13134 vkEndCommandBuffer(cmd_bufs[0]);
13135 VkCommandBuffer duplicates[2] = {cmd_bufs[0], cmd_bufs[0]};
13136
13137 VkSubmitInfo submit_info = {};
13138 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
13139 submit_info.commandBufferCount = 2;
13140 submit_info.pCommandBuffers = duplicates;
13141 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, simultaneous_use_message);
13142 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
13143 m_errorMonitor->VerifyFound();
13144 vkQueueWaitIdle(m_device->m_queue);
13145
13146 // Set one time use and now look for one time submit
13147 duplicates[0] = duplicates[1] = cmd_bufs[1];
13148 cb_binfo.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT | VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
13149 vkBeginCommandBuffer(cmd_bufs[1], &cb_binfo);
13150 vkCmdSetViewport(cmd_bufs[1], 0, 1, &viewport);
13151 vkEndCommandBuffer(cmd_bufs[1]);
13152 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, one_shot_message);
13153 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
13154 m_errorMonitor->VerifyFound();
13155 vkQueueWaitIdle(m_device->m_queue);
13156}
13157
Tobin Ehlisb093da82017-01-19 12:05:27 -070013158TEST_F(VkLayerTest, StageMaskGsTsEnabled) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013159 TEST_DESCRIPTION(
13160 "Attempt to use a stageMask w/ geometry shader and tesselation shader bits enabled when those features are "
13161 "disabled on the device.");
Tobin Ehlisb093da82017-01-19 12:05:27 -070013162
Tony Barbour1fa09702017-03-16 12:09:08 -060013163 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisb093da82017-01-19 12:05:27 -070013164 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13165
13166 std::vector<const char *> device_extension_names;
13167 auto features = m_device->phy().features();
13168 // Make sure gs & ts are disabled
13169 features.geometryShader = false;
13170 features.tessellationShader = false;
13171 // The sacrificial device object
13172 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
13173
13174 VkCommandPoolCreateInfo pool_create_info{};
13175 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
13176 pool_create_info.queueFamilyIndex = test_device.graphics_queue_node_index_;
13177
13178 VkCommandPool command_pool;
13179 vkCreateCommandPool(test_device.handle(), &pool_create_info, nullptr, &command_pool);
13180
13181 VkCommandBufferAllocateInfo cmd = {};
13182 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
13183 cmd.pNext = NULL;
13184 cmd.commandPool = command_pool;
13185 cmd.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
13186 cmd.commandBufferCount = 1;
13187
13188 VkCommandBuffer cmd_buffer;
13189 VkResult err = vkAllocateCommandBuffers(test_device.handle(), &cmd, &cmd_buffer);
13190 ASSERT_VK_SUCCESS(err);
13191
13192 VkEvent event;
13193 VkEventCreateInfo evci = {};
13194 evci.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
13195 VkResult result = vkCreateEvent(test_device.handle(), &evci, NULL, &event);
13196 ASSERT_VK_SUCCESS(result);
13197
13198 VkCommandBufferBeginInfo cbbi = {};
13199 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
13200 vkBeginCommandBuffer(cmd_buffer, &cbbi);
13201 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00230);
13202 vkCmdSetEvent(cmd_buffer, event, VK_PIPELINE_STAGE_GEOMETRY_SHADER_BIT);
13203 m_errorMonitor->VerifyFound();
13204
13205 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00231);
13206 vkCmdSetEvent(cmd_buffer, event, VK_PIPELINE_STAGE_TESSELLATION_CONTROL_SHADER_BIT);
13207 m_errorMonitor->VerifyFound();
13208
13209 vkDestroyEvent(test_device.handle(), event, NULL);
13210 vkDestroyCommandPool(test_device.handle(), command_pool, NULL);
13211}
13212
Chris Forbesd70103a2017-04-13 11:34:09 -070013213TEST_F(VkLayerTest, EventInUseDestroyedSignaled) {
Tony Barbour1fa09702017-03-16 12:09:08 -060013214 ASSERT_NO_FATAL_FAILURE(Init());
Mark Mueller917f6bc2016-08-30 10:57:19 -060013215 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13216
Tony Barbour552f6c02016-12-21 14:34:07 -070013217 m_commandBuffer->BeginCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060013218
13219 VkEvent event;
13220 VkEventCreateInfo event_create_info = {};
13221 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
13222 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013223 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Mueller917f6bc2016-08-30 10:57:19 -060013224
Tony Barbour552f6c02016-12-21 14:34:07 -070013225 m_commandBuffer->EndCommandBuffer();
Mark Muellerc8d441e2016-08-23 17:36:00 -060013226 vkDestroyEvent(m_device->device(), event, nullptr);
13227
13228 VkSubmitInfo submit_info = {};
13229 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
13230 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013231 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Lobodzinskife4be302017-02-14 13:08:15 -070013232 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is invalid because bound");
Mark Muellerc8d441e2016-08-23 17:36:00 -060013233 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
13234 m_errorMonitor->VerifyFound();
Chris Forbesd70103a2017-04-13 11:34:09 -070013235}
Mark Muellerc8d441e2016-08-23 17:36:00 -060013236
Chris Forbesd70103a2017-04-13 11:34:09 -070013237TEST_F(VkLayerTest, InUseDestroyedSignaled) {
13238 TEST_DESCRIPTION(
13239 "Use vkCmdExecuteCommands with invalid state "
13240 "in primary and secondary command buffers. "
13241 "Delete objects that are inuse. Call VkQueueSubmit "
13242 "with an event that has been deleted.");
Mark Muellerc8d441e2016-08-23 17:36:00 -060013243
Chris Forbesd70103a2017-04-13 11:34:09 -070013244 ASSERT_NO_FATAL_FAILURE(Init());
13245 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13246
13247 m_errorMonitor->ExpectSuccess();
Mark Muellerc8d441e2016-08-23 17:36:00 -060013248
Mark Mueller917f6bc2016-08-30 10:57:19 -060013249 VkSemaphoreCreateInfo semaphore_create_info = {};
13250 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
13251 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013252 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller917f6bc2016-08-30 10:57:19 -060013253 VkFenceCreateInfo fence_create_info = {};
13254 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
13255 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013256 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller917f6bc2016-08-30 10:57:19 -060013257
13258 VkDescriptorPoolSize descriptor_pool_type_count = {};
Mark Mueller4042b652016-09-05 22:52:21 -060013259 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060013260 descriptor_pool_type_count.descriptorCount = 1;
13261
13262 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
13263 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
13264 descriptor_pool_create_info.maxSets = 1;
13265 descriptor_pool_create_info.poolSizeCount = 1;
13266 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013267 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Mark Mueller917f6bc2016-08-30 10:57:19 -060013268
13269 VkDescriptorPool descriptorset_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013270 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
Mark Mueller917f6bc2016-08-30 10:57:19 -060013271
13272 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
Mark Mueller4042b652016-09-05 22:52:21 -060013273 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060013274 descriptorset_layout_binding.descriptorCount = 1;
13275 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
13276
13277 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013278 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060013279 descriptorset_layout_create_info.bindingCount = 1;
13280 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
13281
13282 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013283 ASSERT_VK_SUCCESS(
13284 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060013285
13286 VkDescriptorSet descriptorset;
13287 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013288 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060013289 descriptorset_allocate_info.descriptorSetCount = 1;
13290 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
13291 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013292 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
Mark Mueller917f6bc2016-08-30 10:57:19 -060013293
Mark Mueller4042b652016-09-05 22:52:21 -060013294 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
13295
13296 VkDescriptorBufferInfo buffer_info = {};
13297 buffer_info.buffer = buffer_test.GetBuffer();
13298 buffer_info.offset = 0;
13299 buffer_info.range = 1024;
13300
13301 VkWriteDescriptorSet write_descriptor_set = {};
13302 write_descriptor_set.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
13303 write_descriptor_set.dstSet = descriptorset;
13304 write_descriptor_set.descriptorCount = 1;
13305 write_descriptor_set.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
13306 write_descriptor_set.pBufferInfo = &buffer_info;
13307
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013308 vkUpdateDescriptorSets(m_device->device(), 1, &write_descriptor_set, 0, nullptr);
Mark Mueller4042b652016-09-05 22:52:21 -060013309
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013310 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
13311 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Mueller917f6bc2016-08-30 10:57:19 -060013312
13313 VkPipelineObj pipe(m_device);
13314 pipe.AddColorAttachment();
13315 pipe.AddShader(&vs);
13316 pipe.AddShader(&fs);
13317
13318 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013319 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060013320 pipeline_layout_create_info.setLayoutCount = 1;
13321 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
13322
13323 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013324 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060013325
13326 pipe.CreateVKPipeline(pipeline_layout, m_renderPass);
13327
Chris Forbesd70103a2017-04-13 11:34:09 -070013328 VkEvent event;
13329 VkEventCreateInfo event_create_info = {};
13330 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
13331 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
13332
Tony Barbour552f6c02016-12-21 14:34:07 -070013333 m_commandBuffer->BeginCommandBuffer();
Chris Forbesd70103a2017-04-13 11:34:09 -070013334
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013335 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Muellerc8d441e2016-08-23 17:36:00 -060013336
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013337 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
13338 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
13339 &descriptorset, 0, NULL);
Mark Mueller917f6bc2016-08-30 10:57:19 -060013340
Tony Barbour552f6c02016-12-21 14:34:07 -070013341 m_commandBuffer->EndCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060013342
Chris Forbesd70103a2017-04-13 11:34:09 -070013343 VkSubmitInfo submit_info = {};
13344 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
13345 submit_info.commandBufferCount = 1;
13346 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller917f6bc2016-08-30 10:57:19 -060013347 submit_info.signalSemaphoreCount = 1;
13348 submit_info.pSignalSemaphores = &semaphore;
13349 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013350 m_errorMonitor->Reset(); // resume logmsg processing
Mark Muellerc8d441e2016-08-23 17:36:00 -060013351
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070013352 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00213);
Mark Mueller917f6bc2016-08-30 10:57:19 -060013353 vkDestroyEvent(m_device->device(), event, nullptr);
13354 m_errorMonitor->VerifyFound();
13355
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070013356 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00199);
Mark Mueller917f6bc2016-08-30 10:57:19 -060013357 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
13358 m_errorMonitor->VerifyFound();
13359
Jeremy Hayes08369882017-02-02 10:31:06 -070013360 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Fence 0x");
Mark Mueller917f6bc2016-08-30 10:57:19 -060013361 vkDestroyFence(m_device->device(), fence, nullptr);
13362 m_errorMonitor->VerifyFound();
13363
Tobin Ehlis122207b2016-09-01 08:50:06 -070013364 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070013365 m_errorMonitor->SetUnexpectedError("If semaphore is not VK_NULL_HANDLE, semaphore must be a valid VkSemaphore handle");
13366 m_errorMonitor->SetUnexpectedError("Unable to remove Semaphore obj");
Mark Mueller917f6bc2016-08-30 10:57:19 -060013367 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070013368 m_errorMonitor->SetUnexpectedError("If fence is not VK_NULL_HANDLE, fence must be a valid VkFence handle");
13369 m_errorMonitor->SetUnexpectedError("Unable to remove Fence obj");
Mark Mueller917f6bc2016-08-30 10:57:19 -060013370 vkDestroyFence(m_device->device(), fence, nullptr);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070013371 m_errorMonitor->SetUnexpectedError("If event is not VK_NULL_HANDLE, event must be a valid VkEvent handle");
13372 m_errorMonitor->SetUnexpectedError("Unable to remove Event obj");
Mark Mueller917f6bc2016-08-30 10:57:19 -060013373 vkDestroyEvent(m_device->device(), event, nullptr);
13374 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013375 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
Mark Mueller917f6bc2016-08-30 10:57:19 -060013376 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13377}
13378
Tobin Ehlis2adda372016-09-01 08:51:06 -070013379TEST_F(VkLayerTest, QueryPoolInUseDestroyedSignaled) {
13380 TEST_DESCRIPTION("Delete in-use query pool.");
13381
Tony Barbour1fa09702017-03-16 12:09:08 -060013382 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis2adda372016-09-01 08:51:06 -070013383 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13384
13385 VkQueryPool query_pool;
13386 VkQueryPoolCreateInfo query_pool_ci{};
13387 query_pool_ci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
13388 query_pool_ci.queryType = VK_QUERY_TYPE_TIMESTAMP;
13389 query_pool_ci.queryCount = 1;
13390 vkCreateQueryPool(m_device->device(), &query_pool_ci, nullptr, &query_pool);
Tony Barbour552f6c02016-12-21 14:34:07 -070013391 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis2adda372016-09-01 08:51:06 -070013392 // Reset query pool to create binding with cmd buffer
13393 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0, 1);
13394
Tony Barbour552f6c02016-12-21 14:34:07 -070013395 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis2adda372016-09-01 08:51:06 -070013396
13397 VkSubmitInfo submit_info = {};
13398 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
13399 submit_info.commandBufferCount = 1;
13400 submit_info.pCommandBuffers = &m_commandBuffer->handle();
13401 // Submit cmd buffer and then destroy query pool while in-flight
13402 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
13403
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070013404 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01012);
Tobin Ehlis2adda372016-09-01 08:51:06 -070013405 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
13406 m_errorMonitor->VerifyFound();
13407
13408 vkQueueWaitIdle(m_device->m_queue);
13409 // Now that cmd buffer done we can safely destroy query_pool
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070013410 m_errorMonitor->SetUnexpectedError("If queryPool is not VK_NULL_HANDLE, queryPool must be a valid VkQueryPool handle");
Mark Lobodzinski74597792017-04-11 15:43:49 -060013411 m_errorMonitor->SetUnexpectedError("Unable to remove QueryPool obj");
Tobin Ehlis2adda372016-09-01 08:51:06 -070013412 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
13413}
13414
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060013415TEST_F(VkLayerTest, PipelineInUseDestroyedSignaled) {
13416 TEST_DESCRIPTION("Delete in-use pipeline.");
13417
Tony Barbour1fa09702017-03-16 12:09:08 -060013418 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060013419 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13420
13421 // Empty pipeline layout used for binding PSO
13422 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
13423 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13424 pipeline_layout_ci.setLayoutCount = 0;
13425 pipeline_layout_ci.pSetLayouts = NULL;
13426
13427 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013428 VkResult err = vkCreatePipelineLayout(m_device->handle(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060013429 ASSERT_VK_SUCCESS(err);
13430
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070013431 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00555);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060013432 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013433 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
13434 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060013435 // Store pipeline handle so we can actually delete it before test finishes
13436 VkPipeline delete_this_pipeline;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013437 { // Scope pipeline so it will be auto-deleted
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060013438 VkPipelineObj pipe(m_device);
13439 pipe.AddShader(&vs);
13440 pipe.AddShader(&fs);
13441 pipe.AddColorAttachment();
13442 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13443 delete_this_pipeline = pipe.handle();
13444
Tony Barbour552f6c02016-12-21 14:34:07 -070013445 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060013446 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013447 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060013448
Tony Barbour552f6c02016-12-21 14:34:07 -070013449 m_commandBuffer->EndCommandBuffer();
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060013450
13451 VkSubmitInfo submit_info = {};
13452 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
13453 submit_info.commandBufferCount = 1;
13454 submit_info.pCommandBuffers = &m_commandBuffer->handle();
13455 // Submit cmd buffer and then pipeline destroyed while in-flight
13456 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013457 } // Pipeline deletion triggered here
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060013458 m_errorMonitor->VerifyFound();
13459 // Make sure queue finished and then actually delete pipeline
13460 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070013461 m_errorMonitor->SetUnexpectedError("If pipeline is not VK_NULL_HANDLE, pipeline must be a valid VkPipeline handle");
13462 m_errorMonitor->SetUnexpectedError("Unable to remove Pipeline obj");
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060013463 vkDestroyPipeline(m_device->handle(), delete_this_pipeline, nullptr);
13464 vkDestroyPipelineLayout(m_device->handle(), pipeline_layout, nullptr);
13465}
13466
Tobin Ehlis7d965da2016-09-19 16:15:45 -060013467TEST_F(VkLayerTest, ImageViewInUseDestroyedSignaled) {
13468 TEST_DESCRIPTION("Delete in-use imageView.");
13469
Tony Barbour1fa09702017-03-16 12:09:08 -060013470 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis7d965da2016-09-19 16:15:45 -060013471 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13472
13473 VkDescriptorPoolSize ds_type_count;
13474 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
13475 ds_type_count.descriptorCount = 1;
13476
13477 VkDescriptorPoolCreateInfo ds_pool_ci = {};
13478 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
13479 ds_pool_ci.maxSets = 1;
13480 ds_pool_ci.poolSizeCount = 1;
13481 ds_pool_ci.pPoolSizes = &ds_type_count;
13482
13483 VkDescriptorPool ds_pool;
13484 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
13485 ASSERT_VK_SUCCESS(err);
13486
13487 VkSamplerCreateInfo sampler_ci = {};
13488 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
13489 sampler_ci.pNext = NULL;
13490 sampler_ci.magFilter = VK_FILTER_NEAREST;
13491 sampler_ci.minFilter = VK_FILTER_NEAREST;
13492 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
13493 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
13494 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
13495 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
13496 sampler_ci.mipLodBias = 1.0;
13497 sampler_ci.anisotropyEnable = VK_FALSE;
13498 sampler_ci.maxAnisotropy = 1;
13499 sampler_ci.compareEnable = VK_FALSE;
13500 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
13501 sampler_ci.minLod = 1.0;
13502 sampler_ci.maxLod = 1.0;
13503 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
13504 sampler_ci.unnormalizedCoordinates = VK_FALSE;
13505 VkSampler sampler;
13506
13507 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
13508 ASSERT_VK_SUCCESS(err);
13509
13510 VkDescriptorSetLayoutBinding layout_binding;
13511 layout_binding.binding = 0;
13512 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
13513 layout_binding.descriptorCount = 1;
13514 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
13515 layout_binding.pImmutableSamplers = NULL;
13516
13517 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
13518 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
13519 ds_layout_ci.bindingCount = 1;
13520 ds_layout_ci.pBindings = &layout_binding;
13521 VkDescriptorSetLayout ds_layout;
13522 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
13523 ASSERT_VK_SUCCESS(err);
13524
13525 VkDescriptorSetAllocateInfo alloc_info = {};
13526 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
13527 alloc_info.descriptorSetCount = 1;
13528 alloc_info.descriptorPool = ds_pool;
13529 alloc_info.pSetLayouts = &ds_layout;
13530 VkDescriptorSet descriptor_set;
13531 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
13532 ASSERT_VK_SUCCESS(err);
13533
13534 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
13535 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13536 pipeline_layout_ci.pNext = NULL;
13537 pipeline_layout_ci.setLayoutCount = 1;
13538 pipeline_layout_ci.pSetLayouts = &ds_layout;
13539
13540 VkPipelineLayout pipeline_layout;
13541 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
13542 ASSERT_VK_SUCCESS(err);
13543
13544 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060013545 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 -060013546 ASSERT_TRUE(image.initialized());
13547
13548 VkImageView view;
13549 VkImageViewCreateInfo ivci = {};
13550 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
13551 ivci.image = image.handle();
13552 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
13553 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
13554 ivci.subresourceRange.layerCount = 1;
13555 ivci.subresourceRange.baseMipLevel = 0;
13556 ivci.subresourceRange.levelCount = 1;
13557 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
13558
13559 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
13560 ASSERT_VK_SUCCESS(err);
13561
13562 VkDescriptorImageInfo image_info{};
13563 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
13564 image_info.imageView = view;
13565 image_info.sampler = sampler;
13566
13567 VkWriteDescriptorSet descriptor_write = {};
13568 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
13569 descriptor_write.dstSet = descriptor_set;
13570 descriptor_write.dstBinding = 0;
13571 descriptor_write.descriptorCount = 1;
13572 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
13573 descriptor_write.pImageInfo = &image_info;
13574
13575 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
13576
13577 // Create PSO to use the sampler
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013578 char const *vsSource =
13579 "#version 450\n"
13580 "\n"
13581 "out gl_PerVertex { \n"
13582 " vec4 gl_Position;\n"
13583 "};\n"
13584 "void main(){\n"
13585 " gl_Position = vec4(1);\n"
13586 "}\n";
13587 char const *fsSource =
13588 "#version 450\n"
13589 "\n"
13590 "layout(set=0, binding=0) uniform sampler2D s;\n"
13591 "layout(location=0) out vec4 x;\n"
13592 "void main(){\n"
13593 " x = texture(s, vec2(1));\n"
13594 "}\n";
Tobin Ehlis7d965da2016-09-19 16:15:45 -060013595 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13596 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13597 VkPipelineObj pipe(m_device);
13598 pipe.AddShader(&vs);
13599 pipe.AddShader(&fs);
13600 pipe.AddColorAttachment();
13601 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13602
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070013603 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00776);
Tobin Ehlis7d965da2016-09-19 16:15:45 -060013604
Tony Barbour552f6c02016-12-21 14:34:07 -070013605 m_commandBuffer->BeginCommandBuffer();
13606 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis7d965da2016-09-19 16:15:45 -060013607 // Bind pipeline to cmd buffer
13608 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
13609 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
13610 &descriptor_set, 0, nullptr);
Rene Lindsaya8880622017-01-18 13:12:59 -070013611
13612 VkViewport viewport = {0, 0, 16, 16, 0, 1};
13613 VkRect2D scissor = {{0, 0}, {16, 16}};
13614 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
13615 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
13616
Tobin Ehlis7d965da2016-09-19 16:15:45 -060013617 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070013618 m_commandBuffer->EndRenderPass();
13619 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis7d965da2016-09-19 16:15:45 -060013620 // Submit cmd buffer then destroy sampler
13621 VkSubmitInfo submit_info = {};
13622 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
13623 submit_info.commandBufferCount = 1;
13624 submit_info.pCommandBuffers = &m_commandBuffer->handle();
13625 // Submit cmd buffer and then destroy imageView while in-flight
13626 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
13627
13628 vkDestroyImageView(m_device->device(), view, nullptr);
13629 m_errorMonitor->VerifyFound();
13630 vkQueueWaitIdle(m_device->m_queue);
13631 // Now we can actually destroy imageView
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070013632 m_errorMonitor->SetUnexpectedError("If imageView is not VK_NULL_HANDLE, imageView must be a valid VkImageView handle");
Mark Lobodzinski74597792017-04-11 15:43:49 -060013633 m_errorMonitor->SetUnexpectedError("Unable to remove ImageView obj");
Tobin Ehlis7d965da2016-09-19 16:15:45 -060013634 vkDestroyImageView(m_device->device(), view, NULL);
13635 vkDestroySampler(m_device->device(), sampler, nullptr);
13636 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
13637 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
13638 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
13639}
13640
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060013641TEST_F(VkLayerTest, BufferViewInUseDestroyedSignaled) {
13642 TEST_DESCRIPTION("Delete in-use bufferView.");
13643
Tony Barbour1fa09702017-03-16 12:09:08 -060013644 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060013645 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13646
13647 VkDescriptorPoolSize ds_type_count;
13648 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
13649 ds_type_count.descriptorCount = 1;
13650
13651 VkDescriptorPoolCreateInfo ds_pool_ci = {};
13652 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
13653 ds_pool_ci.maxSets = 1;
13654 ds_pool_ci.poolSizeCount = 1;
13655 ds_pool_ci.pPoolSizes = &ds_type_count;
13656
13657 VkDescriptorPool ds_pool;
13658 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
13659 ASSERT_VK_SUCCESS(err);
13660
13661 VkDescriptorSetLayoutBinding layout_binding;
13662 layout_binding.binding = 0;
13663 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
13664 layout_binding.descriptorCount = 1;
13665 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
13666 layout_binding.pImmutableSamplers = NULL;
13667
13668 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
13669 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
13670 ds_layout_ci.bindingCount = 1;
13671 ds_layout_ci.pBindings = &layout_binding;
13672 VkDescriptorSetLayout ds_layout;
13673 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
13674 ASSERT_VK_SUCCESS(err);
13675
13676 VkDescriptorSetAllocateInfo alloc_info = {};
13677 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
13678 alloc_info.descriptorSetCount = 1;
13679 alloc_info.descriptorPool = ds_pool;
13680 alloc_info.pSetLayouts = &ds_layout;
13681 VkDescriptorSet descriptor_set;
13682 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
13683 ASSERT_VK_SUCCESS(err);
13684
13685 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
13686 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13687 pipeline_layout_ci.pNext = NULL;
13688 pipeline_layout_ci.setLayoutCount = 1;
13689 pipeline_layout_ci.pSetLayouts = &ds_layout;
13690
13691 VkPipelineLayout pipeline_layout;
13692 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
13693 ASSERT_VK_SUCCESS(err);
13694
13695 VkBuffer buffer;
13696 uint32_t queue_family_index = 0;
13697 VkBufferCreateInfo buffer_create_info = {};
13698 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
13699 buffer_create_info.size = 1024;
13700 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
13701 buffer_create_info.queueFamilyIndexCount = 1;
13702 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
13703
13704 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
13705 ASSERT_VK_SUCCESS(err);
13706
13707 VkMemoryRequirements memory_reqs;
13708 VkDeviceMemory buffer_memory;
13709
13710 VkMemoryAllocateInfo memory_info = {};
13711 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
13712 memory_info.allocationSize = 0;
13713 memory_info.memoryTypeIndex = 0;
13714
13715 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
13716 memory_info.allocationSize = memory_reqs.size;
13717 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
13718 ASSERT_TRUE(pass);
13719
13720 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
13721 ASSERT_VK_SUCCESS(err);
13722 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
13723 ASSERT_VK_SUCCESS(err);
13724
13725 VkBufferView view;
13726 VkBufferViewCreateInfo bvci = {};
13727 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
13728 bvci.buffer = buffer;
13729 bvci.format = VK_FORMAT_R8_UNORM;
13730 bvci.range = VK_WHOLE_SIZE;
13731
13732 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
13733 ASSERT_VK_SUCCESS(err);
13734
13735 VkWriteDescriptorSet descriptor_write = {};
13736 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
13737 descriptor_write.dstSet = descriptor_set;
13738 descriptor_write.dstBinding = 0;
13739 descriptor_write.descriptorCount = 1;
13740 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
13741 descriptor_write.pTexelBufferView = &view;
13742
13743 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
13744
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013745 char const *vsSource =
13746 "#version 450\n"
13747 "\n"
13748 "out gl_PerVertex { \n"
13749 " vec4 gl_Position;\n"
13750 "};\n"
13751 "void main(){\n"
13752 " gl_Position = vec4(1);\n"
13753 "}\n";
13754 char const *fsSource =
13755 "#version 450\n"
13756 "\n"
13757 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
13758 "layout(location=0) out vec4 x;\n"
13759 "void main(){\n"
13760 " x = imageLoad(s, 0);\n"
13761 "}\n";
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060013762 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13763 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13764 VkPipelineObj pipe(m_device);
13765 pipe.AddShader(&vs);
13766 pipe.AddShader(&fs);
13767 pipe.AddColorAttachment();
13768 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13769
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070013770 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00701);
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060013771
Tony Barbour552f6c02016-12-21 14:34:07 -070013772 m_commandBuffer->BeginCommandBuffer();
13773 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060013774 VkViewport viewport = {0, 0, 16, 16, 0, 1};
13775 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
13776 VkRect2D scissor = {{0, 0}, {16, 16}};
13777 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
13778 // Bind pipeline to cmd buffer
13779 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
13780 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
13781 &descriptor_set, 0, nullptr);
13782 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070013783 m_commandBuffer->EndRenderPass();
13784 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060013785
13786 VkSubmitInfo submit_info = {};
13787 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
13788 submit_info.commandBufferCount = 1;
13789 submit_info.pCommandBuffers = &m_commandBuffer->handle();
13790 // Submit cmd buffer and then destroy bufferView while in-flight
13791 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
13792
13793 vkDestroyBufferView(m_device->device(), view, nullptr);
13794 m_errorMonitor->VerifyFound();
13795 vkQueueWaitIdle(m_device->m_queue);
13796 // Now we can actually destroy bufferView
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070013797 m_errorMonitor->SetUnexpectedError("If bufferView is not VK_NULL_HANDLE, bufferView must be a valid VkBufferView handle");
Mark Lobodzinski74597792017-04-11 15:43:49 -060013798 m_errorMonitor->SetUnexpectedError("Unable to remove BufferView obj");
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060013799 vkDestroyBufferView(m_device->device(), view, NULL);
13800 vkDestroyBuffer(m_device->device(), buffer, NULL);
13801 vkFreeMemory(m_device->device(), buffer_memory, NULL);
13802 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
13803 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
13804 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
13805}
13806
Tobin Ehlis209532e2016-09-07 13:52:18 -060013807TEST_F(VkLayerTest, SamplerInUseDestroyedSignaled) {
13808 TEST_DESCRIPTION("Delete in-use sampler.");
13809
Tony Barbour1fa09702017-03-16 12:09:08 -060013810 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis209532e2016-09-07 13:52:18 -060013811 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13812
13813 VkDescriptorPoolSize ds_type_count;
13814 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
13815 ds_type_count.descriptorCount = 1;
13816
13817 VkDescriptorPoolCreateInfo ds_pool_ci = {};
13818 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
13819 ds_pool_ci.maxSets = 1;
13820 ds_pool_ci.poolSizeCount = 1;
13821 ds_pool_ci.pPoolSizes = &ds_type_count;
13822
13823 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013824 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis209532e2016-09-07 13:52:18 -060013825 ASSERT_VK_SUCCESS(err);
13826
13827 VkSamplerCreateInfo sampler_ci = {};
13828 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
13829 sampler_ci.pNext = NULL;
13830 sampler_ci.magFilter = VK_FILTER_NEAREST;
13831 sampler_ci.minFilter = VK_FILTER_NEAREST;
13832 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
13833 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
13834 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
13835 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
13836 sampler_ci.mipLodBias = 1.0;
13837 sampler_ci.anisotropyEnable = VK_FALSE;
13838 sampler_ci.maxAnisotropy = 1;
13839 sampler_ci.compareEnable = VK_FALSE;
13840 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
13841 sampler_ci.minLod = 1.0;
13842 sampler_ci.maxLod = 1.0;
13843 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
13844 sampler_ci.unnormalizedCoordinates = VK_FALSE;
13845 VkSampler sampler;
13846
13847 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
13848 ASSERT_VK_SUCCESS(err);
13849
13850 VkDescriptorSetLayoutBinding layout_binding;
13851 layout_binding.binding = 0;
Tobin Ehlis94fc0ad2016-09-19 16:23:01 -060013852 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
Tobin Ehlis209532e2016-09-07 13:52:18 -060013853 layout_binding.descriptorCount = 1;
13854 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
13855 layout_binding.pImmutableSamplers = NULL;
13856
13857 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
13858 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
13859 ds_layout_ci.bindingCount = 1;
13860 ds_layout_ci.pBindings = &layout_binding;
13861 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013862 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060013863 ASSERT_VK_SUCCESS(err);
13864
13865 VkDescriptorSetAllocateInfo alloc_info = {};
13866 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
13867 alloc_info.descriptorSetCount = 1;
13868 alloc_info.descriptorPool = ds_pool;
13869 alloc_info.pSetLayouts = &ds_layout;
13870 VkDescriptorSet descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013871 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis209532e2016-09-07 13:52:18 -060013872 ASSERT_VK_SUCCESS(err);
13873
13874 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
13875 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13876 pipeline_layout_ci.pNext = NULL;
13877 pipeline_layout_ci.setLayoutCount = 1;
13878 pipeline_layout_ci.pSetLayouts = &ds_layout;
13879
13880 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013881 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060013882 ASSERT_VK_SUCCESS(err);
13883
13884 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060013885 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 -060013886 ASSERT_TRUE(image.initialized());
13887
13888 VkImageView view;
13889 VkImageViewCreateInfo ivci = {};
13890 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
13891 ivci.image = image.handle();
13892 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
13893 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
13894 ivci.subresourceRange.layerCount = 1;
13895 ivci.subresourceRange.baseMipLevel = 0;
13896 ivci.subresourceRange.levelCount = 1;
13897 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
13898
13899 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
13900 ASSERT_VK_SUCCESS(err);
13901
13902 VkDescriptorImageInfo image_info{};
13903 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
13904 image_info.imageView = view;
13905 image_info.sampler = sampler;
13906
13907 VkWriteDescriptorSet descriptor_write = {};
13908 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
13909 descriptor_write.dstSet = descriptor_set;
13910 descriptor_write.dstBinding = 0;
13911 descriptor_write.descriptorCount = 1;
13912 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
13913 descriptor_write.pImageInfo = &image_info;
13914
13915 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
13916
13917 // Create PSO to use the sampler
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013918 char const *vsSource =
13919 "#version 450\n"
13920 "\n"
13921 "out gl_PerVertex { \n"
13922 " vec4 gl_Position;\n"
13923 "};\n"
13924 "void main(){\n"
13925 " gl_Position = vec4(1);\n"
13926 "}\n";
13927 char const *fsSource =
13928 "#version 450\n"
13929 "\n"
13930 "layout(set=0, binding=0) uniform sampler2D s;\n"
13931 "layout(location=0) out vec4 x;\n"
13932 "void main(){\n"
13933 " x = texture(s, vec2(1));\n"
13934 "}\n";
Tobin Ehlis209532e2016-09-07 13:52:18 -060013935 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13936 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13937 VkPipelineObj pipe(m_device);
13938 pipe.AddShader(&vs);
13939 pipe.AddShader(&fs);
13940 pipe.AddColorAttachment();
13941 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13942
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070013943 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00837);
Tobin Ehlis209532e2016-09-07 13:52:18 -060013944
Tony Barbour552f6c02016-12-21 14:34:07 -070013945 m_commandBuffer->BeginCommandBuffer();
13946 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis209532e2016-09-07 13:52:18 -060013947 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013948 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
13949 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
13950 &descriptor_set, 0, nullptr);
Rene Lindsay4da11732017-01-13 14:42:10 -070013951
13952 VkViewport viewport = {0, 0, 16, 16, 0, 1};
13953 VkRect2D scissor = {{0, 0}, {16, 16}};
13954 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
13955 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
13956
Tobin Ehlis209532e2016-09-07 13:52:18 -060013957 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070013958 m_commandBuffer->EndRenderPass();
13959 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis209532e2016-09-07 13:52:18 -060013960 // Submit cmd buffer then destroy sampler
13961 VkSubmitInfo submit_info = {};
13962 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
13963 submit_info.commandBufferCount = 1;
13964 submit_info.pCommandBuffers = &m_commandBuffer->handle();
13965 // Submit cmd buffer and then destroy sampler while in-flight
13966 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
13967
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013968 vkDestroySampler(m_device->device(), sampler, nullptr); // Destroyed too soon
Tobin Ehlis209532e2016-09-07 13:52:18 -060013969 m_errorMonitor->VerifyFound();
13970 vkQueueWaitIdle(m_device->m_queue);
Rene Lindsay4da11732017-01-13 14:42:10 -070013971
Tobin Ehlis209532e2016-09-07 13:52:18 -060013972 // Now we can actually destroy sampler
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070013973 m_errorMonitor->SetUnexpectedError("If sampler is not VK_NULL_HANDLE, sampler must be a valid VkSampler handle");
13974 m_errorMonitor->SetUnexpectedError("Unable to remove Sampler obj");
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013975 vkDestroySampler(m_device->device(), sampler, NULL); // Destroyed for real
Tobin Ehlis209532e2016-09-07 13:52:18 -060013976 vkDestroyImageView(m_device->device(), view, NULL);
13977 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
13978 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
13979 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
13980}
13981
Mark Mueller1cd9f412016-08-25 13:23:52 -060013982TEST_F(VkLayerTest, QueueForwardProgressFenceWait) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013983 TEST_DESCRIPTION(
13984 "Call VkQueueSubmit with a semaphore that is already "
13985 "signaled but not waited on by the queue. Wait on a "
13986 "fence that has not yet been submitted to a queue.");
Mark Mueller96a56d52016-08-24 10:28:05 -060013987
Tony Barbour1fa09702017-03-16 12:09:08 -060013988 ASSERT_NO_FATAL_FAILURE(Init());
Mark Mueller96a56d52016-08-24 10:28:05 -060013989 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13990
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013991 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 -070013992 const char *invalid_fence_wait_message =
13993 " which has not been submitted on a Queue or during "
13994 "acquire next image.";
Mark Mueller96a56d52016-08-24 10:28:05 -060013995
Chris Forbese98aec12017-05-18 12:50:14 -070013996 VkCommandBufferObj cb1(m_device, m_commandPool);
13997 cb1.begin();
13998 cb1.end();
Mark Mueller96a56d52016-08-24 10:28:05 -060013999
14000 VkSemaphoreCreateInfo semaphore_create_info = {};
14001 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
14002 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014003 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller96a56d52016-08-24 10:28:05 -060014004 VkSubmitInfo submit_info = {};
14005 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
14006 submit_info.commandBufferCount = 1;
Chris Forbese98aec12017-05-18 12:50:14 -070014007 submit_info.pCommandBuffers = &cb1.handle();
Mark Mueller96a56d52016-08-24 10:28:05 -060014008 submit_info.signalSemaphoreCount = 1;
14009 submit_info.pSignalSemaphores = &semaphore;
14010 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Chris Forbese98aec12017-05-18 12:50:14 -070014011
Tony Barbour552f6c02016-12-21 14:34:07 -070014012 m_commandBuffer->BeginCommandBuffer();
14013 m_commandBuffer->EndCommandBuffer();
Chris Forbese98aec12017-05-18 12:50:14 -070014014 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014015 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, queue_forward_progress_message);
Mark Mueller96a56d52016-08-24 10:28:05 -060014016 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
14017 m_errorMonitor->VerifyFound();
14018
Mark Mueller1cd9f412016-08-25 13:23:52 -060014019 VkFenceCreateInfo fence_create_info = {};
14020 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
14021 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014022 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller1cd9f412016-08-25 13:23:52 -060014023
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014024 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, invalid_fence_wait_message);
Mark Mueller1cd9f412016-08-25 13:23:52 -060014025 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
14026 m_errorMonitor->VerifyFound();
14027
Mark Mueller4042b652016-09-05 22:52:21 -060014028 vkDeviceWaitIdle(m_device->device());
Mark Mueller1cd9f412016-08-25 13:23:52 -060014029 vkDestroyFence(m_device->device(), fence, nullptr);
Mark Mueller96a56d52016-08-24 10:28:05 -060014030 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
14031}
14032
Tobin Ehlis4af23302016-07-19 10:50:30 -060014033TEST_F(VkLayerTest, FramebufferIncompatible) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014034 TEST_DESCRIPTION(
14035 "Bind a secondary command buffer with with a framebuffer "
14036 "that does not match the framebuffer for the active "
14037 "renderpass.");
Tony Barbour1fa09702017-03-16 12:09:08 -060014038 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis4af23302016-07-19 10:50:30 -060014039 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14040
14041 // A renderpass with one color attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014042 VkAttachmentDescription attachment = {0,
14043 VK_FORMAT_B8G8R8A8_UNORM,
14044 VK_SAMPLE_COUNT_1_BIT,
14045 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
14046 VK_ATTACHMENT_STORE_OP_STORE,
14047 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
14048 VK_ATTACHMENT_STORE_OP_DONT_CARE,
14049 VK_IMAGE_LAYOUT_UNDEFINED,
14050 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060014051
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014052 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060014053
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014054 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060014055
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014056 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060014057
14058 VkRenderPass rp;
14059 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
14060 ASSERT_VK_SUCCESS(err);
14061
14062 // A compatible framebuffer.
14063 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060014064 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 -060014065 ASSERT_TRUE(image.initialized());
14066
14067 VkImageViewCreateInfo ivci = {
14068 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
14069 nullptr,
14070 0,
14071 image.handle(),
14072 VK_IMAGE_VIEW_TYPE_2D,
14073 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014074 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
14075 VK_COMPONENT_SWIZZLE_IDENTITY},
Tobin Ehlis4af23302016-07-19 10:50:30 -060014076 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
14077 };
14078 VkImageView view;
14079 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
14080 ASSERT_VK_SUCCESS(err);
14081
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014082 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Tobin Ehlis4af23302016-07-19 10:50:30 -060014083 VkFramebuffer fb;
14084 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
14085 ASSERT_VK_SUCCESS(err);
14086
14087 VkCommandBufferAllocateInfo cbai = {};
14088 cbai.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mike Schuchardt06304c22017-03-01 17:09:09 -070014089 cbai.commandPool = m_commandPool->handle();
Tobin Ehlis4af23302016-07-19 10:50:30 -060014090 cbai.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
14091 cbai.commandBufferCount = 1;
14092
14093 VkCommandBuffer sec_cb;
14094 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &sec_cb);
14095 ASSERT_VK_SUCCESS(err);
14096 VkCommandBufferBeginInfo cbbi = {};
14097 VkCommandBufferInheritanceInfo cbii = {};
Chris Forbes98420382016-11-28 17:56:51 +130014098 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Tobin Ehlis4af23302016-07-19 10:50:30 -060014099 cbii.renderPass = renderPass();
14100 cbii.framebuffer = fb;
14101 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
14102 cbbi.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014103 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 -060014104 cbbi.pInheritanceInfo = &cbii;
14105 vkBeginCommandBuffer(sec_cb, &cbbi);
14106 vkEndCommandBuffer(sec_cb);
14107
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014108 VkCommandBufferBeginInfo cbbi2 = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, 0, nullptr};
Chris Forbes3400bc52016-09-13 18:10:34 +120014109 vkBeginCommandBuffer(m_commandBuffer->GetBufferHandle(), &cbbi2);
14110 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Tobin Ehlis4af23302016-07-19 10:50:30 -060014111
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014112 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060014113 " that is not the same as the primary command buffer's current active framebuffer ");
Tobin Ehlis4af23302016-07-19 10:50:30 -060014114 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &sec_cb);
14115 m_errorMonitor->VerifyFound();
14116 // Cleanup
14117 vkDestroyImageView(m_device->device(), view, NULL);
14118 vkDestroyRenderPass(m_device->device(), rp, NULL);
14119 vkDestroyFramebuffer(m_device->device(), fb, NULL);
14120}
Tobin Ehlis52b504f2016-07-19 13:25:12 -060014121
14122TEST_F(VkLayerTest, ColorBlendLogicOpTests) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014123 TEST_DESCRIPTION(
14124 "If logicOp is available on the device, set it to an "
14125 "invalid value. If logicOp is not available, attempt to "
14126 "use it and verify that we see the correct error.");
Tony Barbour1fa09702017-03-16 12:09:08 -060014127 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis52b504f2016-07-19 13:25:12 -060014128 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14129
14130 auto features = m_device->phy().features();
14131 // Set the expected error depending on whether or not logicOp available
14132 if (VK_FALSE == features.logicOp) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014133 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14134 "If logic operations feature not "
14135 "enabled, logicOpEnable must be "
14136 "VK_FALSE");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060014137 } else {
Chris Forbes34797bc2016-10-03 15:28:49 +130014138 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "pColorBlendState->logicOp (16)");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060014139 }
14140 // Create a pipeline using logicOp
14141 VkResult err;
14142
14143 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
14144 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
14145
14146 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014147 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060014148 ASSERT_VK_SUCCESS(err);
14149
14150 VkPipelineViewportStateCreateInfo vp_state_ci = {};
14151 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
14152 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014153 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060014154 vp_state_ci.pViewports = &vp;
14155 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014156 VkRect2D scissors = {}; // Dummy scissors to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060014157 vp_state_ci.pScissors = &scissors;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060014158
14159 VkPipelineShaderStageCreateInfo shaderStages[2];
14160 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
14161
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014162 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
14163 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060014164 shaderStages[0] = vs.GetStageCreateInfo();
14165 shaderStages[1] = fs.GetStageCreateInfo();
14166
14167 VkPipelineVertexInputStateCreateInfo vi_ci = {};
14168 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
14169
14170 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
14171 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
14172 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
14173
14174 VkPipelineRasterizationStateCreateInfo rs_ci = {};
14175 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbes14088512016-10-03 14:28:00 +130014176 rs_ci.lineWidth = 1.0f;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060014177
14178 VkPipelineColorBlendAttachmentState att = {};
14179 att.blendEnable = VK_FALSE;
14180 att.colorWriteMask = 0xf;
14181
14182 VkPipelineColorBlendStateCreateInfo cb_ci = {};
14183 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
14184 // Enable logicOp & set logicOp to value 1 beyond allowed entries
14185 cb_ci.logicOpEnable = VK_TRUE;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014186 cb_ci.logicOp = VK_LOGIC_OP_RANGE_SIZE; // This should cause an error
Tobin Ehlis52b504f2016-07-19 13:25:12 -060014187 cb_ci.attachmentCount = 1;
14188 cb_ci.pAttachments = &att;
14189
Chris Forbes8aeacbf2016-10-03 14:25:08 +130014190 VkPipelineMultisampleStateCreateInfo ms_ci = {};
14191 ms_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
14192 ms_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
14193
Tobin Ehlis52b504f2016-07-19 13:25:12 -060014194 VkGraphicsPipelineCreateInfo gp_ci = {};
14195 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
14196 gp_ci.stageCount = 2;
14197 gp_ci.pStages = shaderStages;
14198 gp_ci.pVertexInputState = &vi_ci;
14199 gp_ci.pInputAssemblyState = &ia_ci;
14200 gp_ci.pViewportState = &vp_state_ci;
14201 gp_ci.pRasterizationState = &rs_ci;
14202 gp_ci.pColorBlendState = &cb_ci;
Chris Forbes8aeacbf2016-10-03 14:25:08 +130014203 gp_ci.pMultisampleState = &ms_ci;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060014204 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
14205 gp_ci.layout = pipeline_layout;
14206 gp_ci.renderPass = renderPass();
14207
14208 VkPipelineCacheCreateInfo pc_ci = {};
14209 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
14210
14211 VkPipeline pipeline;
14212 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014213 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060014214 ASSERT_VK_SUCCESS(err);
14215
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014216 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060014217 m_errorMonitor->VerifyFound();
14218 if (VK_SUCCESS == err) {
14219 vkDestroyPipeline(m_device->device(), pipeline, NULL);
14220 }
Tobin Ehlis52b504f2016-07-19 13:25:12 -060014221 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
14222 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
14223}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060014224
Mike Stroyanaccf7692015-05-12 16:00:45 -060014225#if GTEST_IS_THREADSAFE
14226struct thread_data_struct {
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014227 VkCommandBuffer commandBuffer;
Mike Stroyanca855662017-05-02 11:06:27 -060014228 VkDevice device;
Mike Stroyanaccf7692015-05-12 16:00:45 -060014229 VkEvent event;
14230 bool bailout;
14231};
14232
Karl Schultz6addd812016-02-02 17:17:23 -070014233extern "C" void *AddToCommandBuffer(void *arg) {
14234 struct thread_data_struct *data = (struct thread_data_struct *)arg;
Mike Stroyanaccf7692015-05-12 16:00:45 -060014235
Mike Stroyana6d14942016-07-13 15:10:05 -060014236 for (int i = 0; i < 80000; i++) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014237 vkCmdSetEvent(data->commandBuffer, data->event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mike Stroyanaccf7692015-05-12 16:00:45 -060014238 if (data->bailout) {
14239 break;
14240 }
14241 }
14242 return NULL;
14243}
14244
Karl Schultz6addd812016-02-02 17:17:23 -070014245TEST_F(VkLayerTest, ThreadCommandBufferCollision) {
Mike Stroyan4268d1f2015-07-13 14:45:35 -060014246 test_platform_thread thread;
Mike Stroyanaccf7692015-05-12 16:00:45 -060014247
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014248 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "THREADING ERROR");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014249
Tony Barbour1fa09702017-03-16 12:09:08 -060014250 ASSERT_NO_FATAL_FAILURE(Init());
Mike Stroyanaccf7692015-05-12 16:00:45 -060014251 ASSERT_NO_FATAL_FAILURE(InitViewport());
14252 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14253
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014254 // Calls AllocateCommandBuffers
14255 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060014256
14257 // Avoid creating RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014258 commandBuffer.BeginCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060014259
14260 VkEventCreateInfo event_info;
14261 VkEvent event;
Mike Stroyanaccf7692015-05-12 16:00:45 -060014262 VkResult err;
14263
14264 memset(&event_info, 0, sizeof(event_info));
14265 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
14266
Chia-I Wuf7458c52015-10-26 21:10:41 +080014267 err = vkCreateEvent(device(), &event_info, NULL, &event);
Mike Stroyanaccf7692015-05-12 16:00:45 -060014268 ASSERT_VK_SUCCESS(err);
14269
Mike Stroyanaccf7692015-05-12 16:00:45 -060014270 err = vkResetEvent(device(), event);
14271 ASSERT_VK_SUCCESS(err);
14272
14273 struct thread_data_struct data;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014274 data.commandBuffer = commandBuffer.GetBufferHandle();
Mike Stroyanaccf7692015-05-12 16:00:45 -060014275 data.event = event;
14276 data.bailout = false;
14277 m_errorMonitor->SetBailout(&data.bailout);
Mike Stroyana6d14942016-07-13 15:10:05 -060014278
14279 // First do some correct operations using multiple threads.
14280 // Add many entries to command buffer from another thread.
14281 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
14282 // Make non-conflicting calls from this thread at the same time.
14283 for (int i = 0; i < 80000; i++) {
Mike Stroyand6343902016-07-14 08:56:16 -060014284 uint32_t count;
14285 vkEnumeratePhysicalDevices(instance(), &count, NULL);
Mike Stroyana6d14942016-07-13 15:10:05 -060014286 }
14287 test_platform_thread_join(thread, NULL);
14288
14289 // Then do some incorrect operations using multiple threads.
Mike Stroyanaccf7692015-05-12 16:00:45 -060014290 // Add many entries to command buffer from another thread.
Mike Stroyan4268d1f2015-07-13 14:45:35 -060014291 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyanaccf7692015-05-12 16:00:45 -060014292 // Add many entries to command buffer from this thread at the same time.
14293 AddToCommandBuffer(&data);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060014294
Mike Stroyan4268d1f2015-07-13 14:45:35 -060014295 test_platform_thread_join(thread, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014296 commandBuffer.EndCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060014297
Mike Stroyan10b8cb72016-01-22 15:22:03 -070014298 m_errorMonitor->SetBailout(NULL);
14299
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014300 m_errorMonitor->VerifyFound();
Mike Stroyanaccf7692015-05-12 16:00:45 -060014301
Chia-I Wuf7458c52015-10-26 21:10:41 +080014302 vkDestroyEvent(device(), event, NULL);
Mike Stroyanaccf7692015-05-12 16:00:45 -060014303}
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014304#endif // GTEST_IS_THREADSAFE
Mark Lobodzinski209b5292015-09-17 09:44:05 -060014305
Karl Schultz6addd812016-02-02 17:17:23 -070014306TEST_F(VkLayerTest, InvalidSPIRVCodeSize) {
Mark Lobodzinskid742b312017-05-09 16:26:27 -060014307 TEST_DESCRIPTION("Test that errors are produced for a spirv modules with invalid code sizes");
Chris Forbes1cc79542016-07-20 11:13:44 +120014308
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014309 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014310
Tony Barbour1fa09702017-03-16 12:09:08 -060014311 ASSERT_NO_FATAL_FAILURE(Init());
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014312 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14313
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014314 VkShaderModule module;
14315 VkShaderModuleCreateInfo moduleCreateInfo;
14316 struct icd_spv_header spv;
14317
14318 spv.magic = ICD_SPV_MAGIC;
14319 spv.version = ICD_SPV_VERSION;
14320 spv.gen_magic = 0;
14321
14322 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
14323 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070014324 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014325 moduleCreateInfo.codeSize = 4;
14326 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080014327 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014328
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014329 m_errorMonitor->VerifyFound();
Mark Lobodzinskid742b312017-05-09 16:26:27 -060014330
14331 char const *vsSource =
14332 "#version 450\n"
14333 "\n"
14334 "layout(location=0) out float x;\n"
14335 "out gl_PerVertex {\n"
14336 " vec4 gl_Position;\n"
14337 "};\n"
14338 "void main(){\n"
14339 " gl_Position = vec4(1);\n"
14340 " x = 0;\n"
14341 "}\n";
14342
14343 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02816);
14344 std::vector<unsigned int> shader;
14345 VkShaderModuleCreateInfo module_create_info;
14346 VkShaderModule shader_module;
14347 module_create_info.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
14348 module_create_info.pNext = NULL;
14349 this->GLSLtoSPV(VK_SHADER_STAGE_VERTEX_BIT, vsSource, shader);
14350 module_create_info.pCode = shader.data();
14351 // Introduce failure by making codeSize a non-multiple of 4
14352 module_create_info.codeSize = shader.size() * sizeof(unsigned int) - 1;
14353 module_create_info.flags = 0;
14354 vkCreateShaderModule(m_device->handle(), &module_create_info, NULL, &shader_module);
14355
14356 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014357}
14358
Karl Schultz6addd812016-02-02 17:17:23 -070014359TEST_F(VkLayerTest, InvalidSPIRVMagic) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014360 TEST_DESCRIPTION(
14361 "Test that an error is produced for a spirv module "
14362 "with a bad magic number");
Chris Forbes1cc79542016-07-20 11:13:44 +120014363
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014364 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V magic number");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014365
Tony Barbour1fa09702017-03-16 12:09:08 -060014366 ASSERT_NO_FATAL_FAILURE(Init());
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014367 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14368
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014369 VkShaderModule module;
14370 VkShaderModuleCreateInfo moduleCreateInfo;
14371 struct icd_spv_header spv;
14372
14373 spv.magic = ~ICD_SPV_MAGIC;
14374 spv.version = ICD_SPV_VERSION;
14375 spv.gen_magic = 0;
14376
14377 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
14378 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070014379 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Mark Lobodzinskid742b312017-05-09 16:26:27 -060014380 moduleCreateInfo.codeSize = sizeof(spv) + 16;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014381 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080014382 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014383
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014384 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014385}
14386
Chris Forbesb4afd0f2016-04-04 10:48:35 +120014387#if 0
14388// Not currently covered by SPIRV-Tools validator
Karl Schultz6addd812016-02-02 17:17:23 -070014389TEST_F(VkLayerTest, InvalidSPIRVVersion) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070014390 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +120014391 "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014392
Tony Barbour1fa09702017-03-16 12:09:08 -060014393 ASSERT_NO_FATAL_FAILURE(Init());
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014394 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14395
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014396 VkShaderModule module;
14397 VkShaderModuleCreateInfo moduleCreateInfo;
14398 struct icd_spv_header spv;
14399
14400 spv.magic = ICD_SPV_MAGIC;
14401 spv.version = ~ICD_SPV_VERSION;
14402 spv.gen_magic = 0;
14403
14404 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
14405 moduleCreateInfo.pNext = NULL;
14406
Karl Schultz6addd812016-02-02 17:17:23 -070014407 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014408 moduleCreateInfo.codeSize = sizeof(spv) + 10;
14409 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080014410 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014411
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014412 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014413}
Chris Forbesb4afd0f2016-04-04 10:48:35 +120014414#endif
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014415
Karl Schultz6addd812016-02-02 17:17:23 -070014416TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014417 TEST_DESCRIPTION(
14418 "Test that a warning is produced for a vertex output that "
14419 "is not consumed by the fragment stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014420 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "not consumed by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014421
Tony Barbour1fa09702017-03-16 12:09:08 -060014422 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014423 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes9f7ff632015-05-25 11:13:08 +120014424
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014425 char const *vsSource =
14426 "#version 450\n"
14427 "\n"
14428 "layout(location=0) out float x;\n"
14429 "out gl_PerVertex {\n"
14430 " vec4 gl_Position;\n"
14431 "};\n"
14432 "void main(){\n"
14433 " gl_Position = vec4(1);\n"
14434 " x = 0;\n"
14435 "}\n";
14436 char const *fsSource =
14437 "#version 450\n"
14438 "\n"
14439 "layout(location=0) out vec4 color;\n"
14440 "void main(){\n"
14441 " color = vec4(1);\n"
14442 "}\n";
Chris Forbes9f7ff632015-05-25 11:13:08 +120014443
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014444 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14445 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes9f7ff632015-05-25 11:13:08 +120014446
14447 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014448 pipe.AddColorAttachment();
Chris Forbes9f7ff632015-05-25 11:13:08 +120014449 pipe.AddShader(&vs);
14450 pipe.AddShader(&fs);
14451
Chris Forbes9f7ff632015-05-25 11:13:08 +120014452 VkDescriptorSetObj descriptorSet(m_device);
14453 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014454 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes9f7ff632015-05-25 11:13:08 +120014455
Tony Barbour5781e8f2015-08-04 16:23:11 -060014456 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes9f7ff632015-05-25 11:13:08 +120014457
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014458 m_errorMonitor->VerifyFound();
Chris Forbes9f7ff632015-05-25 11:13:08 +120014459}
Chris Forbes9f7ff632015-05-25 11:13:08 +120014460
Mark Mueller098c9cb2016-09-08 09:01:57 -060014461TEST_F(VkLayerTest, CreatePipelineCheckShaderBadSpecialization) {
14462 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
14463
Tony Barbour1fa09702017-03-16 12:09:08 -060014464 ASSERT_NO_FATAL_FAILURE(Init());
Mark Mueller098c9cb2016-09-08 09:01:57 -060014465 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14466
14467 const char *bad_specialization_message =
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014468 "Specialization entry 0 (for constant id 0) references memory outside provided specialization data ";
Mark Mueller098c9cb2016-09-08 09:01:57 -060014469
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014470 char const *vsSource =
14471 "#version 450\n"
14472 "\n"
14473 "out gl_PerVertex {\n"
14474 " vec4 gl_Position;\n"
14475 "};\n"
14476 "void main(){\n"
14477 " gl_Position = vec4(1);\n"
14478 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060014479
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014480 char const *fsSource =
14481 "#version 450\n"
14482 "\n"
14483 "layout (constant_id = 0) const float r = 0.0f;\n"
14484 "layout(location = 0) out vec4 uFragColor;\n"
14485 "void main(){\n"
14486 " uFragColor = vec4(r,1,0,1);\n"
14487 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060014488
14489 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14490 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14491
14492 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
14493 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
14494
14495 VkPipelineLayout pipeline_layout;
14496 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
14497
14498 VkPipelineViewportStateCreateInfo vp_state_create_info = {};
14499 vp_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
14500 vp_state_create_info.viewportCount = 1;
14501 VkViewport viewport = {};
14502 vp_state_create_info.pViewports = &viewport;
14503 vp_state_create_info.scissorCount = 1;
14504 VkRect2D scissors = {};
14505 vp_state_create_info.pScissors = &scissors;
14506
14507 VkDynamicState scissor_state = VK_DYNAMIC_STATE_SCISSOR;
14508
14509 VkPipelineDynamicStateCreateInfo pipeline_dynamic_state_create_info = {};
14510 pipeline_dynamic_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
14511 pipeline_dynamic_state_create_info.dynamicStateCount = 1;
14512 pipeline_dynamic_state_create_info.pDynamicStates = &scissor_state;
14513
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014514 VkPipelineShaderStageCreateInfo shader_stage_create_info[2] = {vs.GetStageCreateInfo(), fs.GetStageCreateInfo()};
Mark Mueller098c9cb2016-09-08 09:01:57 -060014515
14516 VkPipelineVertexInputStateCreateInfo vertex_input_create_info = {};
14517 vertex_input_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
14518
14519 VkPipelineInputAssemblyStateCreateInfo input_assembly_create_info = {};
14520 input_assembly_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
14521 input_assembly_create_info.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
14522
14523 VkPipelineRasterizationStateCreateInfo rasterization_state_create_info = {};
14524 rasterization_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
14525 rasterization_state_create_info.pNext = nullptr;
14526 rasterization_state_create_info.lineWidth = 1.0f;
14527 rasterization_state_create_info.rasterizerDiscardEnable = true;
14528
14529 VkPipelineColorBlendAttachmentState color_blend_attachment_state = {};
14530 color_blend_attachment_state.blendEnable = VK_FALSE;
14531 color_blend_attachment_state.colorWriteMask = 0xf;
14532
14533 VkPipelineColorBlendStateCreateInfo color_blend_state_create_info = {};
14534 color_blend_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
14535 color_blend_state_create_info.attachmentCount = 1;
14536 color_blend_state_create_info.pAttachments = &color_blend_attachment_state;
14537
14538 VkGraphicsPipelineCreateInfo graphicspipe_create_info = {};
14539 graphicspipe_create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
14540 graphicspipe_create_info.stageCount = 2;
14541 graphicspipe_create_info.pStages = shader_stage_create_info;
14542 graphicspipe_create_info.pVertexInputState = &vertex_input_create_info;
14543 graphicspipe_create_info.pInputAssemblyState = &input_assembly_create_info;
14544 graphicspipe_create_info.pViewportState = &vp_state_create_info;
14545 graphicspipe_create_info.pRasterizationState = &rasterization_state_create_info;
14546 graphicspipe_create_info.pColorBlendState = &color_blend_state_create_info;
14547 graphicspipe_create_info.pDynamicState = &pipeline_dynamic_state_create_info;
14548 graphicspipe_create_info.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
14549 graphicspipe_create_info.layout = pipeline_layout;
14550 graphicspipe_create_info.renderPass = renderPass();
14551
14552 VkPipelineCacheCreateInfo pipeline_cache_create_info = {};
14553 pipeline_cache_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
14554
14555 VkPipelineCache pipelineCache;
14556 ASSERT_VK_SUCCESS(vkCreatePipelineCache(m_device->device(), &pipeline_cache_create_info, nullptr, &pipelineCache));
14557
14558 // This structure maps constant ids to data locations.
14559 const VkSpecializationMapEntry entry =
14560 // id, offset, size
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014561 {0, 4, sizeof(uint32_t)}; // Challenge core validation by using a bogus offset.
Mark Mueller098c9cb2016-09-08 09:01:57 -060014562
14563 uint32_t data = 1;
14564
14565 // Set up the info describing spec map and data
14566 const VkSpecializationInfo specialization_info = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014567 1, &entry, 1 * sizeof(float), &data,
Mark Mueller098c9cb2016-09-08 09:01:57 -060014568 };
14569 shader_stage_create_info[0].pSpecializationInfo = &specialization_info;
14570
14571 VkPipeline pipeline;
14572 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_specialization_message);
14573 vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &graphicspipe_create_info, nullptr, &pipeline);
14574 m_errorMonitor->VerifyFound();
14575
14576 vkDestroyPipelineCache(m_device->device(), pipelineCache, nullptr);
14577 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
14578}
14579
14580TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorTypeMismatch) {
14581 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
14582
Tony Barbour1fa09702017-03-16 12:09:08 -060014583 ASSERT_NO_FATAL_FAILURE(Init());
Mark Mueller098c9cb2016-09-08 09:01:57 -060014584 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14585
14586 const char *descriptor_type_mismatch_message = "Type mismatch on descriptor slot 0.0 (used as type ";
14587
14588 VkDescriptorPoolSize descriptor_pool_type_count[2] = {};
14589 descriptor_pool_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
14590 descriptor_pool_type_count[0].descriptorCount = 1;
14591 descriptor_pool_type_count[1].type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
14592 descriptor_pool_type_count[1].descriptorCount = 1;
14593
14594 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
14595 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
14596 descriptor_pool_create_info.maxSets = 1;
14597 descriptor_pool_create_info.poolSizeCount = 2;
14598 descriptor_pool_create_info.pPoolSizes = descriptor_pool_type_count;
14599 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
14600
14601 VkDescriptorPool descriptorset_pool;
14602 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
14603
14604 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
14605 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
14606 descriptorset_layout_binding.descriptorCount = 1;
14607 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
Cody Northropa6484fd2017-03-10 14:13:49 -070014608 descriptorset_layout_binding.pImmutableSamplers = nullptr;
Mark Mueller098c9cb2016-09-08 09:01:57 -060014609
14610 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
14611 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
14612 descriptorset_layout_create_info.bindingCount = 1;
14613 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
14614
14615 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014616 ASSERT_VK_SUCCESS(
14617 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller098c9cb2016-09-08 09:01:57 -060014618
14619 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
14620 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
14621 descriptorset_allocate_info.descriptorSetCount = 1;
14622 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
14623 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
14624 VkDescriptorSet descriptorset;
14625 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
14626
14627 // Challenge core_validation with a non uniform buffer type.
14628 VkBufferTest storage_buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT);
14629
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014630 char const *vsSource =
14631 "#version 450\n"
14632 "\n"
14633 "layout (std140, set = 0, binding = 0) uniform buf {\n"
14634 " mat4 mvp;\n"
14635 "} ubuf;\n"
14636 "out gl_PerVertex {\n"
14637 " vec4 gl_Position;\n"
14638 "};\n"
14639 "void main(){\n"
14640 " gl_Position = ubuf.mvp * vec4(1);\n"
14641 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060014642
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014643 char const *fsSource =
14644 "#version 450\n"
14645 "\n"
14646 "layout(location = 0) out vec4 uFragColor;\n"
14647 "void main(){\n"
14648 " uFragColor = vec4(0,1,0,1);\n"
14649 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060014650
14651 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14652 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14653
14654 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
14655 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
14656 pipeline_layout_create_info.setLayoutCount = 1;
14657 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
14658
14659 VkPipelineLayout pipeline_layout;
14660 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
14661
14662 VkPipelineObj pipe(m_device);
14663 pipe.AddColorAttachment();
14664 pipe.AddShader(&vs);
14665 pipe.AddShader(&fs);
14666
14667 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_type_mismatch_message);
14668 pipe.CreateVKPipeline(pipeline_layout, renderPass());
14669 m_errorMonitor->VerifyFound();
14670
14671 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
14672 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
14673 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
14674}
14675
14676TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorNotAccessible) {
14677 TEST_DESCRIPTION(
14678 "Create a pipeline in which a descriptor used by a shader stage does not include that stage in its stageFlags.");
14679
Tony Barbour1fa09702017-03-16 12:09:08 -060014680 ASSERT_NO_FATAL_FAILURE(Init());
Mark Mueller098c9cb2016-09-08 09:01:57 -060014681 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14682
14683 const char *descriptor_not_accessible_message = "Shader uses descriptor slot 0.0 (used as type ";
14684
14685 VkDescriptorPoolSize descriptor_pool_type_count = {};
14686 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
14687 descriptor_pool_type_count.descriptorCount = 1;
14688
14689 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
14690 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
14691 descriptor_pool_create_info.maxSets = 1;
14692 descriptor_pool_create_info.poolSizeCount = 1;
14693 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
14694 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
14695
14696 VkDescriptorPool descriptorset_pool;
14697 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
14698
14699 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
14700 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
14701 descriptorset_layout_binding.descriptorCount = 1;
14702 // Intentionally make the uniform buffer inaccessible to the vertex shader to challenge core_validation
14703 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
Cody Northropa6484fd2017-03-10 14:13:49 -070014704 descriptorset_layout_binding.pImmutableSamplers = nullptr;
Mark Mueller098c9cb2016-09-08 09:01:57 -060014705
14706 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
14707 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
14708 descriptorset_layout_create_info.bindingCount = 1;
14709 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
14710
14711 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014712 ASSERT_VK_SUCCESS(
14713 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller098c9cb2016-09-08 09:01:57 -060014714
14715 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
14716 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
14717 descriptorset_allocate_info.descriptorSetCount = 1;
14718 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
14719 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
14720 VkDescriptorSet descriptorset;
14721 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
14722
14723 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
14724
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014725 char const *vsSource =
14726 "#version 450\n"
14727 "\n"
14728 "layout (std140, set = 0, binding = 0) uniform buf {\n"
14729 " mat4 mvp;\n"
14730 "} ubuf;\n"
14731 "out gl_PerVertex {\n"
14732 " vec4 gl_Position;\n"
14733 "};\n"
14734 "void main(){\n"
14735 " gl_Position = ubuf.mvp * vec4(1);\n"
14736 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060014737
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014738 char const *fsSource =
14739 "#version 450\n"
14740 "\n"
14741 "layout(location = 0) out vec4 uFragColor;\n"
14742 "void main(){\n"
14743 " uFragColor = vec4(0,1,0,1);\n"
14744 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060014745
14746 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14747 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14748
14749 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
14750 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
14751 pipeline_layout_create_info.setLayoutCount = 1;
14752 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
14753
14754 VkPipelineLayout pipeline_layout;
14755 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
14756
14757 VkPipelineObj pipe(m_device);
14758 pipe.AddColorAttachment();
14759 pipe.AddShader(&vs);
14760 pipe.AddShader(&fs);
14761
14762 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_not_accessible_message);
14763 pipe.CreateVKPipeline(pipeline_layout, renderPass());
14764 m_errorMonitor->VerifyFound();
14765
14766 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
14767 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
14768 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
14769}
14770
14771TEST_F(VkLayerTest, CreatePipelineCheckShaderPushConstantNotAccessible) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014772 TEST_DESCRIPTION(
14773 "Create a graphics pipleine in which a push constant range containing a push constant block member is not "
14774 "accessible from the current shader stage.");
Mark Mueller098c9cb2016-09-08 09:01:57 -060014775
Tony Barbour1fa09702017-03-16 12:09:08 -060014776 ASSERT_NO_FATAL_FAILURE(Init());
Mark Mueller098c9cb2016-09-08 09:01:57 -060014777 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14778
14779 const char *push_constant_not_accessible_message =
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014780 "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 -060014781
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014782 char const *vsSource =
14783 "#version 450\n"
14784 "\n"
14785 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
14786 "out gl_PerVertex {\n"
14787 " vec4 gl_Position;\n"
14788 "};\n"
14789 "void main(){\n"
14790 " gl_Position = vec4(consts.x);\n"
14791 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060014792
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014793 char const *fsSource =
14794 "#version 450\n"
14795 "\n"
14796 "layout(location = 0) out vec4 uFragColor;\n"
14797 "void main(){\n"
14798 " uFragColor = vec4(0,1,0,1);\n"
14799 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060014800
14801 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14802 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14803
14804 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
14805 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
14806
14807 // Set up a push constant range
14808 VkPushConstantRange push_constant_ranges = {};
14809 // Set to the wrong stage to challenge core_validation
14810 push_constant_ranges.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
14811 push_constant_ranges.size = 4;
14812
14813 pipeline_layout_create_info.pPushConstantRanges = &push_constant_ranges;
14814 pipeline_layout_create_info.pushConstantRangeCount = 1;
14815
14816 VkPipelineLayout pipeline_layout;
14817 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
14818
14819 VkPipelineObj pipe(m_device);
14820 pipe.AddColorAttachment();
14821 pipe.AddShader(&vs);
14822 pipe.AddShader(&fs);
14823
14824 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, push_constant_not_accessible_message);
14825 pipe.CreateVKPipeline(pipeline_layout, renderPass());
14826 m_errorMonitor->VerifyFound();
14827
14828 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
14829}
14830
14831TEST_F(VkLayerTest, CreatePipelineCheckShaderNotEnabled) {
14832 TEST_DESCRIPTION(
14833 "Create a graphics pipeline in which a capability declared by the shader requires a feature not enabled on the device.");
14834
Tony Barbour1fa09702017-03-16 12:09:08 -060014835 ASSERT_NO_FATAL_FAILURE(Init());
Mark Mueller098c9cb2016-09-08 09:01:57 -060014836 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14837
14838 const char *feature_not_enabled_message =
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014839 "Shader requires VkPhysicalDeviceFeatures::shaderFloat64 but is not enabled on the device";
Mark Mueller098c9cb2016-09-08 09:01:57 -060014840
14841 // Some awkward steps are required to test with custom device features.
14842 std::vector<const char *> device_extension_names;
14843 auto features = m_device->phy().features();
14844 // Disable support for 64 bit floats
14845 features.shaderFloat64 = false;
14846 // The sacrificial device object
14847 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
14848
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014849 char const *vsSource =
14850 "#version 450\n"
14851 "\n"
14852 "out gl_PerVertex {\n"
14853 " vec4 gl_Position;\n"
14854 "};\n"
14855 "void main(){\n"
14856 " gl_Position = vec4(1);\n"
14857 "}\n";
14858 char const *fsSource =
14859 "#version 450\n"
14860 "\n"
14861 "layout(location=0) out vec4 color;\n"
14862 "void main(){\n"
14863 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
14864 " color = vec4(green);\n"
14865 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060014866
14867 VkShaderObj vs(&test_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14868 VkShaderObj fs(&test_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14869
14870 VkRenderpassObj render_pass(&test_device);
Mark Mueller098c9cb2016-09-08 09:01:57 -060014871
14872 VkPipelineObj pipe(&test_device);
14873 pipe.AddColorAttachment();
14874 pipe.AddShader(&vs);
14875 pipe.AddShader(&fs);
14876
14877 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
14878 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
14879 VkPipelineLayout pipeline_layout;
14880 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(test_device.device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
14881
14882 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, feature_not_enabled_message);
14883 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
14884 m_errorMonitor->VerifyFound();
14885
14886 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, nullptr);
14887}
14888
Mark Lobodzinski20832822017-03-24 14:49:45 -060014889TEST_F(VkLayerTest, CreateShaderModuleCheckBadCapability) {
14890 TEST_DESCRIPTION("Create a shader in which a capability declared by the shader is not supported.");
14891 // Note that this failure message comes from spirv-tools, specifically the validator.
Mark Mueller098c9cb2016-09-08 09:01:57 -060014892
Tony Barbour1fa09702017-03-16 12:09:08 -060014893 ASSERT_NO_FATAL_FAILURE(Init());
Mark Mueller098c9cb2016-09-08 09:01:57 -060014894 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14895
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014896 char const *vsSource =
14897 "#version 450\n"
14898 "\n"
14899 "out gl_PerVertex {\n"
14900 " vec4 gl_Position;\n"
14901 "};\n"
14902 "layout(xfb_buffer = 1) out;"
14903 "void main(){\n"
14904 " gl_Position = vec4(1);\n"
14905 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060014906
Mark Lobodzinski20832822017-03-24 14:49:45 -060014907 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Capability value 53 is not allowed by Vulkan");
Mark Mueller098c9cb2016-09-08 09:01:57 -060014908
Mark Lobodzinski20832822017-03-24 14:49:45 -060014909 std::vector<unsigned int> spv;
14910 VkShaderModuleCreateInfo module_create_info;
14911 VkShaderModule shader_module;
14912 module_create_info.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
14913 module_create_info.pNext = NULL;
14914 this->GLSLtoSPV(VK_SHADER_STAGE_VERTEX_BIT, vsSource, spv);
14915 module_create_info.pCode = spv.data();
14916 module_create_info.codeSize = spv.size() * sizeof(unsigned int);
14917 module_create_info.flags = 0;
Mark Mueller098c9cb2016-09-08 09:01:57 -060014918
Mark Lobodzinski20832822017-03-24 14:49:45 -060014919 vkCreateShaderModule(m_device->handle(), &module_create_info, NULL, &shader_module);
Mark Mueller098c9cb2016-09-08 09:01:57 -060014920
Mark Lobodzinski20832822017-03-24 14:49:45 -060014921 m_errorMonitor->VerifyFound();
Mark Mueller098c9cb2016-09-08 09:01:57 -060014922}
14923
Karl Schultz6addd812016-02-02 17:17:23 -070014924TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014925 TEST_DESCRIPTION(
14926 "Test that an error is produced for a fragment shader input "
14927 "which is not present in the outputs of the previous stage");
Chris Forbes1cc79542016-07-20 11:13:44 +120014928
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014929 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014930
Tony Barbour1fa09702017-03-16 12:09:08 -060014931 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014932 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes59cb88d2015-05-25 11:13:13 +120014933
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014934 char const *vsSource =
14935 "#version 450\n"
14936 "\n"
14937 "out gl_PerVertex {\n"
14938 " vec4 gl_Position;\n"
14939 "};\n"
14940 "void main(){\n"
14941 " gl_Position = vec4(1);\n"
14942 "}\n";
14943 char const *fsSource =
14944 "#version 450\n"
14945 "\n"
14946 "layout(location=0) in float x;\n"
14947 "layout(location=0) out vec4 color;\n"
14948 "void main(){\n"
14949 " color = vec4(x);\n"
14950 "}\n";
Chris Forbes59cb88d2015-05-25 11:13:13 +120014951
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014952 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14953 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes59cb88d2015-05-25 11:13:13 +120014954
14955 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014956 pipe.AddColorAttachment();
Chris Forbes59cb88d2015-05-25 11:13:13 +120014957 pipe.AddShader(&vs);
14958 pipe.AddShader(&fs);
14959
Chris Forbes59cb88d2015-05-25 11:13:13 +120014960 VkDescriptorSetObj descriptorSet(m_device);
14961 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014962 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes59cb88d2015-05-25 11:13:13 +120014963
Tony Barbour5781e8f2015-08-04 16:23:11 -060014964 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes59cb88d2015-05-25 11:13:13 +120014965
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014966 m_errorMonitor->VerifyFound();
Chris Forbes59cb88d2015-05-25 11:13:13 +120014967}
14968
Karl Schultz6addd812016-02-02 17:17:23 -070014969TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvidedInBlock) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014970 TEST_DESCRIPTION(
14971 "Test that an error is produced for a fragment shader input "
14972 "within an interace block, which is not present in the outputs "
14973 "of the previous stage.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014974 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Chris Forbesa3e85f62016-01-15 14:53:11 +130014975
Tony Barbour1fa09702017-03-16 12:09:08 -060014976 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbesa3e85f62016-01-15 14:53:11 +130014977 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14978
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014979 char const *vsSource =
14980 "#version 450\n"
14981 "\n"
14982 "out gl_PerVertex {\n"
14983 " vec4 gl_Position;\n"
14984 "};\n"
14985 "void main(){\n"
14986 " gl_Position = vec4(1);\n"
14987 "}\n";
14988 char const *fsSource =
14989 "#version 450\n"
14990 "\n"
14991 "in block { layout(location=0) float x; } ins;\n"
14992 "layout(location=0) out vec4 color;\n"
14993 "void main(){\n"
14994 " color = vec4(ins.x);\n"
14995 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130014996
14997 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14998 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14999
15000 VkPipelineObj pipe(m_device);
15001 pipe.AddColorAttachment();
15002 pipe.AddShader(&vs);
15003 pipe.AddShader(&fs);
15004
15005 VkDescriptorSetObj descriptorSet(m_device);
15006 descriptorSet.AppendDummy();
15007 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15008
15009 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15010
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015011 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130015012}
15013
Karl Schultz6addd812016-02-02 17:17:23 -070015014TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchArraySize) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015015 TEST_DESCRIPTION(
15016 "Test that an error is produced for mismatched array sizes "
15017 "across the vertex->fragment shader interface");
15018 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15019 "Type mismatch on location 0.0: 'ptr to "
15020 "output arr[2] of float32' vs 'ptr to "
15021 "input arr[1] of float32'");
Chris Forbes0036fd12016-01-26 14:19:49 +130015022
Tony Barbour1fa09702017-03-16 12:09:08 -060015023 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes0036fd12016-01-26 14:19:49 +130015024 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15025
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015026 char const *vsSource =
15027 "#version 450\n"
15028 "\n"
15029 "layout(location=0) out float x[2];\n"
15030 "out gl_PerVertex {\n"
15031 " vec4 gl_Position;\n"
15032 "};\n"
15033 "void main(){\n"
15034 " x[0] = 0; x[1] = 0;\n"
15035 " gl_Position = vec4(1);\n"
15036 "}\n";
15037 char const *fsSource =
15038 "#version 450\n"
15039 "\n"
15040 "layout(location=0) in float x[1];\n"
15041 "layout(location=0) out vec4 color;\n"
15042 "void main(){\n"
15043 " color = vec4(x[0]);\n"
15044 "}\n";
Chris Forbes0036fd12016-01-26 14:19:49 +130015045
15046 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15047 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15048
15049 VkPipelineObj pipe(m_device);
15050 pipe.AddColorAttachment();
15051 pipe.AddShader(&vs);
15052 pipe.AddShader(&fs);
15053
15054 VkDescriptorSetObj descriptorSet(m_device);
15055 descriptorSet.AppendDummy();
15056 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15057
15058 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15059
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015060 m_errorMonitor->VerifyFound();
Chris Forbes0036fd12016-01-26 14:19:49 +130015061}
15062
Karl Schultz6addd812016-02-02 17:17:23 -070015063TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015064 TEST_DESCRIPTION(
15065 "Test that an error is produced for mismatched types across "
15066 "the vertex->fragment shader interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015067 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015068
Tony Barbour1fa09702017-03-16 12:09:08 -060015069 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060015070 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesb56af562015-05-25 11:13:17 +120015071
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015072 char const *vsSource =
15073 "#version 450\n"
15074 "\n"
15075 "layout(location=0) out int x;\n"
15076 "out gl_PerVertex {\n"
15077 " vec4 gl_Position;\n"
15078 "};\n"
15079 "void main(){\n"
15080 " x = 0;\n"
15081 " gl_Position = vec4(1);\n"
15082 "}\n";
15083 char const *fsSource =
15084 "#version 450\n"
15085 "\n"
15086 "layout(location=0) in float x;\n" /* VS writes int */
15087 "layout(location=0) out vec4 color;\n"
15088 "void main(){\n"
15089 " color = vec4(x);\n"
15090 "}\n";
Chris Forbesb56af562015-05-25 11:13:17 +120015091
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060015092 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15093 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesb56af562015-05-25 11:13:17 +120015094
15095 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080015096 pipe.AddColorAttachment();
Chris Forbesb56af562015-05-25 11:13:17 +120015097 pipe.AddShader(&vs);
15098 pipe.AddShader(&fs);
15099
Chris Forbesb56af562015-05-25 11:13:17 +120015100 VkDescriptorSetObj descriptorSet(m_device);
15101 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015102 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesb56af562015-05-25 11:13:17 +120015103
Tony Barbour5781e8f2015-08-04 16:23:11 -060015104 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesb56af562015-05-25 11:13:17 +120015105
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015106 m_errorMonitor->VerifyFound();
Chris Forbesb56af562015-05-25 11:13:17 +120015107}
15108
Karl Schultz6addd812016-02-02 17:17:23 -070015109TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchInBlock) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015110 TEST_DESCRIPTION(
15111 "Test that an error is produced for mismatched types across "
15112 "the vertex->fragment shader interface, when the variable is contained within "
15113 "an interface block");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015114 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Chris Forbesa3e85f62016-01-15 14:53:11 +130015115
Tony Barbour1fa09702017-03-16 12:09:08 -060015116 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbesa3e85f62016-01-15 14:53:11 +130015117 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15118
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015119 char const *vsSource =
15120 "#version 450\n"
15121 "\n"
15122 "out block { layout(location=0) int x; } outs;\n"
15123 "out gl_PerVertex {\n"
15124 " vec4 gl_Position;\n"
15125 "};\n"
15126 "void main(){\n"
15127 " outs.x = 0;\n"
15128 " gl_Position = vec4(1);\n"
15129 "}\n";
15130 char const *fsSource =
15131 "#version 450\n"
15132 "\n"
15133 "in block { layout(location=0) float x; } ins;\n" /* VS writes int */
15134 "layout(location=0) out vec4 color;\n"
15135 "void main(){\n"
15136 " color = vec4(ins.x);\n"
15137 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130015138
15139 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15140 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15141
15142 VkPipelineObj pipe(m_device);
15143 pipe.AddColorAttachment();
15144 pipe.AddShader(&vs);
15145 pipe.AddShader(&fs);
15146
15147 VkDescriptorSetObj descriptorSet(m_device);
15148 descriptorSet.AppendDummy();
15149 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15150
15151 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15152
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015153 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130015154}
15155
15156TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByLocation) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015157 TEST_DESCRIPTION(
15158 "Test that an error is produced for location mismatches across "
15159 "the vertex->fragment shader interface; This should manifest as a not-written/not-consumed "
15160 "pair, but flushes out broken walking of the interfaces");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015161 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 +130015162
Tony Barbour1fa09702017-03-16 12:09:08 -060015163 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbese9928822016-02-17 14:44:52 +130015164 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15165
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015166 char const *vsSource =
15167 "#version 450\n"
15168 "\n"
15169 "out block { layout(location=1) float x; } outs;\n"
15170 "out gl_PerVertex {\n"
15171 " vec4 gl_Position;\n"
15172 "};\n"
15173 "void main(){\n"
15174 " outs.x = 0;\n"
15175 " gl_Position = vec4(1);\n"
15176 "}\n";
15177 char const *fsSource =
15178 "#version 450\n"
15179 "\n"
15180 "in block { layout(location=0) float x; } ins;\n"
15181 "layout(location=0) out vec4 color;\n"
15182 "void main(){\n"
15183 " color = vec4(ins.x);\n"
15184 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130015185
15186 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15187 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15188
15189 VkPipelineObj pipe(m_device);
15190 pipe.AddColorAttachment();
15191 pipe.AddShader(&vs);
15192 pipe.AddShader(&fs);
15193
15194 VkDescriptorSetObj descriptorSet(m_device);
15195 descriptorSet.AppendDummy();
15196 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15197
15198 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15199
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015200 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130015201}
15202
15203TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByComponent) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015204 TEST_DESCRIPTION(
15205 "Test that an error is produced for component mismatches across the "
15206 "vertex->fragment shader interface. It's not enough to have the same set of locations in "
15207 "use; matching is defined in terms of spirv variables.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015208 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 +130015209
Tony Barbour1fa09702017-03-16 12:09:08 -060015210 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbese9928822016-02-17 14:44:52 +130015211 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15212
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015213 char const *vsSource =
15214 "#version 450\n"
15215 "\n"
15216 "out block { layout(location=0, component=0) float x; } outs;\n"
15217 "out gl_PerVertex {\n"
15218 " vec4 gl_Position;\n"
15219 "};\n"
15220 "void main(){\n"
15221 " outs.x = 0;\n"
15222 " gl_Position = vec4(1);\n"
15223 "}\n";
15224 char const *fsSource =
15225 "#version 450\n"
15226 "\n"
15227 "in block { layout(location=0, component=1) float x; } ins;\n"
15228 "layout(location=0) out vec4 color;\n"
15229 "void main(){\n"
15230 " color = vec4(ins.x);\n"
15231 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130015232
15233 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15234 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15235
15236 VkPipelineObj pipe(m_device);
15237 pipe.AddColorAttachment();
15238 pipe.AddShader(&vs);
15239 pipe.AddShader(&fs);
15240
15241 VkDescriptorSetObj descriptorSet(m_device);
15242 descriptorSet.AppendDummy();
15243 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15244
15245 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15246
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015247 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130015248}
15249
Chris Forbes1f3b0152016-11-30 12:48:40 +130015250TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByPrecision) {
15251 TEST_DESCRIPTION("Test that the RelaxedPrecision decoration is validated to match");
15252
Tony Barbour1fa09702017-03-16 12:09:08 -060015253 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes1f3b0152016-11-30 12:48:40 +130015254 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15255
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015256 char const *vsSource =
15257 "#version 450\n"
15258 "layout(location=0) out mediump float x;\n"
15259 "void main() { gl_Position = vec4(0); x = 1.0; }\n";
15260 char const *fsSource =
15261 "#version 450\n"
15262 "layout(location=0) in highp float x;\n"
15263 "layout(location=0) out vec4 color;\n"
15264 "void main() { color = vec4(x); }\n";
Chris Forbes1f3b0152016-11-30 12:48:40 +130015265
15266 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15267 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15268
15269 VkPipelineObj pipe(m_device);
15270 pipe.AddColorAttachment();
15271 pipe.AddShader(&vs);
15272 pipe.AddShader(&fs);
15273
15274 VkDescriptorSetObj descriptorSet(m_device);
15275 descriptorSet.AppendDummy();
15276 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15277
15278 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "differ in precision");
15279
15280 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15281
15282 m_errorMonitor->VerifyFound();
15283}
15284
Chris Forbes870a39e2016-11-30 12:55:56 +130015285TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByPrecisionBlock) {
15286 TEST_DESCRIPTION("Test that the RelaxedPrecision decoration is validated to match");
15287
Tony Barbour1fa09702017-03-16 12:09:08 -060015288 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes870a39e2016-11-30 12:55:56 +130015289 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15290
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015291 char const *vsSource =
15292 "#version 450\n"
15293 "out block { layout(location=0) mediump float x; };\n"
15294 "void main() { gl_Position = vec4(0); x = 1.0; }\n";
15295 char const *fsSource =
15296 "#version 450\n"
15297 "in block { layout(location=0) highp float x; };\n"
15298 "layout(location=0) out vec4 color;\n"
15299 "void main() { color = vec4(x); }\n";
Chris Forbes870a39e2016-11-30 12:55:56 +130015300
15301 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15302 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15303
15304 VkPipelineObj pipe(m_device);
15305 pipe.AddColorAttachment();
15306 pipe.AddShader(&vs);
15307 pipe.AddShader(&fs);
15308
15309 VkDescriptorSetObj descriptorSet(m_device);
15310 descriptorSet.AppendDummy();
15311 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15312
15313 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "differ in precision");
15314
15315 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15316
15317 m_errorMonitor->VerifyFound();
15318}
15319
Karl Schultz6addd812016-02-02 17:17:23 -070015320TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015321 TEST_DESCRIPTION(
15322 "Test that a warning is produced for a vertex attribute which is "
15323 "not consumed by the vertex shader");
Mike Weiblencce7ec72016-10-17 19:33:05 -060015324 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015325
Tony Barbour1fa09702017-03-16 12:09:08 -060015326 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060015327 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesde136e02015-05-25 11:13:28 +120015328
15329 VkVertexInputBindingDescription input_binding;
15330 memset(&input_binding, 0, sizeof(input_binding));
15331
15332 VkVertexInputAttributeDescription input_attrib;
15333 memset(&input_attrib, 0, sizeof(input_attrib));
15334 input_attrib.format = VK_FORMAT_R32_SFLOAT;
15335
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015336 char const *vsSource =
15337 "#version 450\n"
15338 "\n"
15339 "out gl_PerVertex {\n"
15340 " vec4 gl_Position;\n"
15341 "};\n"
15342 "void main(){\n"
15343 " gl_Position = vec4(1);\n"
15344 "}\n";
15345 char const *fsSource =
15346 "#version 450\n"
15347 "\n"
15348 "layout(location=0) out vec4 color;\n"
15349 "void main(){\n"
15350 " color = vec4(1);\n"
15351 "}\n";
Chris Forbesde136e02015-05-25 11:13:28 +120015352
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060015353 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15354 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesde136e02015-05-25 11:13:28 +120015355
15356 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080015357 pipe.AddColorAttachment();
Chris Forbesde136e02015-05-25 11:13:28 +120015358 pipe.AddShader(&vs);
15359 pipe.AddShader(&fs);
15360
15361 pipe.AddVertexInputBindings(&input_binding, 1);
15362 pipe.AddVertexInputAttribs(&input_attrib, 1);
15363
Chris Forbesde136e02015-05-25 11:13:28 +120015364 VkDescriptorSetObj descriptorSet(m_device);
15365 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015366 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesde136e02015-05-25 11:13:28 +120015367
Tony Barbour5781e8f2015-08-04 16:23:11 -060015368 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesde136e02015-05-25 11:13:28 +120015369
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015370 m_errorMonitor->VerifyFound();
Chris Forbesde136e02015-05-25 11:13:28 +120015371}
15372
Karl Schultz6addd812016-02-02 17:17:23 -070015373TEST_F(VkLayerTest, CreatePipelineAttribLocationMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015374 TEST_DESCRIPTION(
15375 "Test that a warning is produced for a location mismatch on "
15376 "vertex attributes. This flushes out bad behavior in the interface walker");
Mike Weiblencce7ec72016-10-17 19:33:05 -060015377 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Chris Forbes7d83cd52016-01-15 11:32:03 +130015378
Tony Barbour1fa09702017-03-16 12:09:08 -060015379 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes7d83cd52016-01-15 11:32:03 +130015380 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15381
15382 VkVertexInputBindingDescription input_binding;
15383 memset(&input_binding, 0, sizeof(input_binding));
15384
15385 VkVertexInputAttributeDescription input_attrib;
15386 memset(&input_attrib, 0, sizeof(input_attrib));
15387 input_attrib.format = VK_FORMAT_R32_SFLOAT;
15388
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015389 char const *vsSource =
15390 "#version 450\n"
15391 "\n"
15392 "layout(location=1) in float x;\n"
15393 "out gl_PerVertex {\n"
15394 " vec4 gl_Position;\n"
15395 "};\n"
15396 "void main(){\n"
15397 " gl_Position = vec4(x);\n"
15398 "}\n";
15399 char const *fsSource =
15400 "#version 450\n"
15401 "\n"
15402 "layout(location=0) out vec4 color;\n"
15403 "void main(){\n"
15404 " color = vec4(1);\n"
15405 "}\n";
Chris Forbes7d83cd52016-01-15 11:32:03 +130015406
15407 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15408 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15409
15410 VkPipelineObj pipe(m_device);
15411 pipe.AddColorAttachment();
15412 pipe.AddShader(&vs);
15413 pipe.AddShader(&fs);
15414
15415 pipe.AddVertexInputBindings(&input_binding, 1);
15416 pipe.AddVertexInputAttribs(&input_attrib, 1);
15417
15418 VkDescriptorSetObj descriptorSet(m_device);
15419 descriptorSet.AppendDummy();
15420 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15421
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070015422 m_errorMonitor->SetUnexpectedError("Vertex shader consumes input at location 1 but not provided");
Chris Forbes7d83cd52016-01-15 11:32:03 +130015423 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15424
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015425 m_errorMonitor->VerifyFound();
Chris Forbes7d83cd52016-01-15 11:32:03 +130015426}
15427
Karl Schultz6addd812016-02-02 17:17:23 -070015428TEST_F(VkLayerTest, CreatePipelineAttribNotProvided) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015429 TEST_DESCRIPTION(
15430 "Test that an error is produced for a vertex shader input which is not "
15431 "provided by a vertex attribute");
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070015432 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15433 "Vertex shader consumes input at location 0 but not provided");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015434
Tony Barbour1fa09702017-03-16 12:09:08 -060015435 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060015436 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes62e8e502015-05-25 11:13:29 +120015437
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015438 char const *vsSource =
15439 "#version 450\n"
15440 "\n"
15441 "layout(location=0) in vec4 x;\n" /* not provided */
15442 "out gl_PerVertex {\n"
15443 " vec4 gl_Position;\n"
15444 "};\n"
15445 "void main(){\n"
15446 " gl_Position = x;\n"
15447 "}\n";
15448 char const *fsSource =
15449 "#version 450\n"
15450 "\n"
15451 "layout(location=0) out vec4 color;\n"
15452 "void main(){\n"
15453 " color = vec4(1);\n"
15454 "}\n";
Chris Forbes62e8e502015-05-25 11:13:29 +120015455
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060015456 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15457 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes62e8e502015-05-25 11:13:29 +120015458
15459 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080015460 pipe.AddColorAttachment();
Chris Forbes62e8e502015-05-25 11:13:29 +120015461 pipe.AddShader(&vs);
15462 pipe.AddShader(&fs);
15463
Chris Forbes62e8e502015-05-25 11:13:29 +120015464 VkDescriptorSetObj descriptorSet(m_device);
15465 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015466 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes62e8e502015-05-25 11:13:29 +120015467
Tony Barbour5781e8f2015-08-04 16:23:11 -060015468 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes62e8e502015-05-25 11:13:29 +120015469
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015470 m_errorMonitor->VerifyFound();
Chris Forbes62e8e502015-05-25 11:13:29 +120015471}
15472
Karl Schultz6addd812016-02-02 17:17:23 -070015473TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015474 TEST_DESCRIPTION(
15475 "Test that an error is produced for a mismatch between the "
15476 "fundamental type (float/int/uint) of an attribute and the "
15477 "vertex shader input that consumes it");
Mike Weiblen15bd38e2016-10-03 19:19:41 -060015478 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 -060015479
Tony Barbour1fa09702017-03-16 12:09:08 -060015480 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060015481 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc97d98e2015-05-25 11:13:31 +120015482
15483 VkVertexInputBindingDescription input_binding;
15484 memset(&input_binding, 0, sizeof(input_binding));
15485
15486 VkVertexInputAttributeDescription input_attrib;
15487 memset(&input_attrib, 0, sizeof(input_attrib));
15488 input_attrib.format = VK_FORMAT_R32_SFLOAT;
15489
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015490 char const *vsSource =
15491 "#version 450\n"
15492 "\n"
15493 "layout(location=0) in int x;\n" /* attrib provided float */
15494 "out gl_PerVertex {\n"
15495 " vec4 gl_Position;\n"
15496 "};\n"
15497 "void main(){\n"
15498 " gl_Position = vec4(x);\n"
15499 "}\n";
15500 char const *fsSource =
15501 "#version 450\n"
15502 "\n"
15503 "layout(location=0) out vec4 color;\n"
15504 "void main(){\n"
15505 " color = vec4(1);\n"
15506 "}\n";
Chris Forbesc97d98e2015-05-25 11:13:31 +120015507
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060015508 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15509 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc97d98e2015-05-25 11:13:31 +120015510
15511 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080015512 pipe.AddColorAttachment();
Chris Forbesc97d98e2015-05-25 11:13:31 +120015513 pipe.AddShader(&vs);
15514 pipe.AddShader(&fs);
15515
15516 pipe.AddVertexInputBindings(&input_binding, 1);
15517 pipe.AddVertexInputAttribs(&input_attrib, 1);
15518
Chris Forbesc97d98e2015-05-25 11:13:31 +120015519 VkDescriptorSetObj descriptorSet(m_device);
15520 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015521 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesc97d98e2015-05-25 11:13:31 +120015522
Tony Barbour5781e8f2015-08-04 16:23:11 -060015523 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc97d98e2015-05-25 11:13:31 +120015524
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015525 m_errorMonitor->VerifyFound();
Chris Forbesc97d98e2015-05-25 11:13:31 +120015526}
15527
Chris Forbesc68b43c2016-04-06 11:18:47 +120015528TEST_F(VkLayerTest, CreatePipelineDuplicateStage) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015529 TEST_DESCRIPTION(
15530 "Test that an error is produced for a pipeline containing multiple "
15531 "shaders for the same stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015532 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15533 "Multiple shaders provided for stage VK_SHADER_STAGE_VERTEX_BIT");
Chris Forbesc68b43c2016-04-06 11:18:47 +120015534
Tony Barbour1fa09702017-03-16 12:09:08 -060015535 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbesc68b43c2016-04-06 11:18:47 +120015536 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15537
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015538 char const *vsSource =
15539 "#version 450\n"
15540 "\n"
15541 "out gl_PerVertex {\n"
15542 " vec4 gl_Position;\n"
15543 "};\n"
15544 "void main(){\n"
15545 " gl_Position = vec4(1);\n"
15546 "}\n";
15547 char const *fsSource =
15548 "#version 450\n"
15549 "\n"
15550 "layout(location=0) out vec4 color;\n"
15551 "void main(){\n"
15552 " color = vec4(1);\n"
15553 "}\n";
Chris Forbesc68b43c2016-04-06 11:18:47 +120015554
15555 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15556 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15557
15558 VkPipelineObj pipe(m_device);
15559 pipe.AddColorAttachment();
15560 pipe.AddShader(&vs);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015561 pipe.AddShader(&vs); // intentionally duplicate vertex shader attachment
Chris Forbesc68b43c2016-04-06 11:18:47 +120015562 pipe.AddShader(&fs);
15563
15564 VkDescriptorSetObj descriptorSet(m_device);
15565 descriptorSet.AppendDummy();
15566 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15567
15568 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15569
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015570 m_errorMonitor->VerifyFound();
Chris Forbesc68b43c2016-04-06 11:18:47 +120015571}
15572
Chris Forbes82ff92a2016-09-09 10:50:24 +120015573TEST_F(VkLayerTest, CreatePipelineMissingEntrypoint) {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070015574 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "No entrypoint found named `foo`");
Chris Forbes82ff92a2016-09-09 10:50:24 +120015575
Tony Barbour1fa09702017-03-16 12:09:08 -060015576 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes82ff92a2016-09-09 10:50:24 +120015577 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15578
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015579 char const *vsSource =
15580 "#version 450\n"
15581 "out gl_PerVertex {\n"
15582 " vec4 gl_Position;\n"
15583 "};\n"
15584 "void main(){\n"
15585 " gl_Position = vec4(0);\n"
15586 "}\n";
15587 char const *fsSource =
15588 "#version 450\n"
15589 "\n"
15590 "layout(location=0) out vec4 color;\n"
15591 "void main(){\n"
15592 " color = vec4(1);\n"
15593 "}\n";
Chris Forbes82ff92a2016-09-09 10:50:24 +120015594
15595 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15596 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this, "foo");
15597
15598 VkPipelineObj pipe(m_device);
15599 pipe.AddColorAttachment();
15600 pipe.AddShader(&vs);
15601 pipe.AddShader(&fs);
15602
15603 VkDescriptorSetObj descriptorSet(m_device);
15604 descriptorSet.AppendDummy();
15605 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15606
15607 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15608
15609 m_errorMonitor->VerifyFound();
15610}
15611
Chris Forbesae9d8cd2016-09-13 16:32:57 +120015612TEST_F(VkLayerTest, CreatePipelineDepthStencilRequired) {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070015613 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15614 "pDepthStencilState is NULL when rasterization is enabled and subpass "
15615 "uses a depth/stencil attachment");
Chris Forbesae9d8cd2016-09-13 16:32:57 +120015616
Tony Barbour1fa09702017-03-16 12:09:08 -060015617 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbesae9d8cd2016-09-13 16:32:57 +120015618 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15619
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015620 char const *vsSource =
15621 "#version 450\n"
15622 "void main(){ gl_Position = vec4(0); }\n";
15623 char const *fsSource =
15624 "#version 450\n"
15625 "\n"
15626 "layout(location=0) out vec4 color;\n"
15627 "void main(){\n"
15628 " color = vec4(1);\n"
15629 "}\n";
Chris Forbesae9d8cd2016-09-13 16:32:57 +120015630
15631 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15632 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15633
15634 VkPipelineObj pipe(m_device);
15635 pipe.AddColorAttachment();
15636 pipe.AddShader(&vs);
15637 pipe.AddShader(&fs);
15638
15639 VkDescriptorSetObj descriptorSet(m_device);
15640 descriptorSet.AppendDummy();
15641 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15642
15643 VkAttachmentDescription attachments[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070015644 {
15645 0, VK_FORMAT_B8G8R8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
15646 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_UNDEFINED,
15647 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
Chris Forbesae9d8cd2016-09-13 16:32:57 +120015648 },
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070015649 {
15650 0, VK_FORMAT_D16_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
15651 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_UNDEFINED,
15652 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
Chris Forbesae9d8cd2016-09-13 16:32:57 +120015653 },
15654 };
15655 VkAttachmentReference refs[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070015656 {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL}, {1, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL},
Chris Forbesae9d8cd2016-09-13 16:32:57 +120015657 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070015658 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &refs[0], nullptr, &refs[1], 0, nullptr};
15659 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesae9d8cd2016-09-13 16:32:57 +120015660 VkRenderPass rp;
15661 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
15662 ASSERT_VK_SUCCESS(err);
15663
15664 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), rp);
15665
15666 m_errorMonitor->VerifyFound();
15667
15668 vkDestroyRenderPass(m_device->device(), rp, nullptr);
15669}
15670
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015671TEST_F(VkLayerTest, CreatePipelineTessPatchDecorationMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015672 TEST_DESCRIPTION(
15673 "Test that an error is produced for a variable output from "
15674 "the TCS without the patch decoration, but consumed in the TES "
15675 "with the decoration.");
15676 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15677 "is per-vertex in tessellation control shader stage "
15678 "but per-patch in tessellation evaluation shader stage");
Chris Forbesa0193bc2016-04-04 19:19:47 +120015679
Tony Barbour1fa09702017-03-16 12:09:08 -060015680 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbesa0193bc2016-04-04 19:19:47 +120015681 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15682
Chris Forbesc1e852d2016-04-04 19:26:42 +120015683 if (!m_device->phy().features().tessellationShader) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070015684 printf(" Device does not support tessellation shaders; skipped.\n");
Chris Forbesc1e852d2016-04-04 19:26:42 +120015685 return;
15686 }
15687
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015688 char const *vsSource =
15689 "#version 450\n"
15690 "void main(){}\n";
15691 char const *tcsSource =
15692 "#version 450\n"
15693 "layout(location=0) out int x[];\n"
15694 "layout(vertices=3) out;\n"
15695 "void main(){\n"
15696 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
15697 " gl_TessLevelInner[0] = 1;\n"
15698 " x[gl_InvocationID] = gl_InvocationID;\n"
15699 "}\n";
15700 char const *tesSource =
15701 "#version 450\n"
15702 "layout(triangles, equal_spacing, cw) in;\n"
15703 "layout(location=0) patch in int x;\n"
15704 "out gl_PerVertex { vec4 gl_Position; };\n"
15705 "void main(){\n"
15706 " gl_Position.xyz = gl_TessCoord;\n"
15707 " gl_Position.w = x;\n"
15708 "}\n";
15709 char const *fsSource =
15710 "#version 450\n"
15711 "layout(location=0) out vec4 color;\n"
15712 "void main(){\n"
15713 " color = vec4(1);\n"
15714 "}\n";
Chris Forbesa0193bc2016-04-04 19:19:47 +120015715
15716 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15717 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
15718 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
15719 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15720
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015721 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
15722 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Chris Forbesa0193bc2016-04-04 19:19:47 +120015723
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015724 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Chris Forbesa0193bc2016-04-04 19:19:47 +120015725
15726 VkPipelineObj pipe(m_device);
15727 pipe.SetInputAssembly(&iasci);
15728 pipe.SetTessellation(&tsci);
15729 pipe.AddColorAttachment();
15730 pipe.AddShader(&vs);
15731 pipe.AddShader(&tcs);
15732 pipe.AddShader(&tes);
15733 pipe.AddShader(&fs);
15734
15735 VkDescriptorSetObj descriptorSet(m_device);
15736 descriptorSet.AppendDummy();
15737 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15738
15739 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15740
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015741 m_errorMonitor->VerifyFound();
Chris Forbesa0193bc2016-04-04 19:19:47 +120015742}
15743
Cort Stratton2bcca1b2017-05-05 16:02:35 -070015744TEST_F(VkLayerTest, CreatePipelineTessErrors) {
15745 TEST_DESCRIPTION("Test various errors when creating a graphics pipeline with tessellation stages active.");
15746
15747 ASSERT_NO_FATAL_FAILURE(Init());
15748 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15749
15750 if (!m_device->phy().features().tessellationShader) {
15751 printf(" Device does not support tessellation shaders; skipped.\n");
15752 return;
15753 }
15754
15755 char const *vsSource =
15756 "#version 450\n"
15757 "void main(){}\n";
15758 char const *tcsSource =
15759 "#version 450\n"
15760 "layout(vertices=3) out;\n"
15761 "void main(){\n"
15762 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
15763 " gl_TessLevelInner[0] = 1;\n"
15764 "}\n";
15765 char const *tesSource =
15766 "#version 450\n"
15767 "layout(triangles, equal_spacing, cw) in;\n"
15768 "out gl_PerVertex { vec4 gl_Position; };\n"
15769 "void main(){\n"
15770 " gl_Position.xyz = gl_TessCoord;\n"
15771 " gl_Position.w = 0;\n"
15772 "}\n";
15773 char const *fsSource =
15774 "#version 450\n"
15775 "layout(location=0) out vec4 color;\n"
15776 "void main(){\n"
15777 " color = vec4(1);\n"
15778 "}\n";
15779
15780 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15781 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
15782 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
15783 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15784
15785 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
15786 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
15787
15788 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
15789
15790 VkDescriptorSetObj descriptorSet(m_device);
15791 descriptorSet.AppendDummy();
15792 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15793
15794 {
15795 VkPipelineObj pipe(m_device);
15796 VkPipelineInputAssemblyStateCreateInfo iasci_bad = iasci;
15797 iasci_bad.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST; // otherwise we get a failure about invalid topology
15798 pipe.SetInputAssembly(&iasci_bad);
15799 pipe.AddColorAttachment();
15800 pipe.AddShader(&vs);
15801 pipe.AddShader(&fs);
15802
15803 // Pass a tess control shader without a tess eval shader
15804 pipe.AddShader(&tcs);
15805 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00534);
15806 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15807 m_errorMonitor->VerifyFound();
15808 }
15809
15810 {
15811 VkPipelineObj pipe(m_device);
15812 VkPipelineInputAssemblyStateCreateInfo iasci_bad = iasci;
15813 iasci_bad.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST; // otherwise we get a failure about invalid topology
15814 pipe.SetInputAssembly(&iasci_bad);
15815 pipe.AddColorAttachment();
15816 pipe.AddShader(&vs);
15817 pipe.AddShader(&fs);
15818
15819 // Pass a tess eval shader without a tess control shader
15820 pipe.AddShader(&tes);
15821 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00535);
15822 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15823 m_errorMonitor->VerifyFound();
15824 }
15825
15826 {
15827 VkPipelineObj pipe(m_device);
15828 pipe.SetInputAssembly(&iasci);
15829 pipe.AddColorAttachment();
15830 pipe.AddShader(&vs);
15831 pipe.AddShader(&fs);
15832
15833 // Pass patch topology without tessellation shaders
15834 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02100);
15835 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15836 m_errorMonitor->VerifyFound();
15837
15838 pipe.AddShader(&tcs);
15839 pipe.AddShader(&tes);
15840 // Pass a NULL pTessellationState (with active tessellation shader stages)
15841 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00536);
15842 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15843 m_errorMonitor->VerifyFound();
15844
15845 // Pass an invalid pTessellationState (bad sType)
15846 VkPipelineTessellationStateCreateInfo tsci_bad = tsci;
15847 tsci_bad.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
15848 pipe.SetTessellation(&tsci_bad);
15849 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01427);
15850 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15851 m_errorMonitor->VerifyFound();
15852 // Pass out-of-range patchControlPoints
15853 tsci_bad = tsci;
15854 tsci_bad.patchControlPoints = 0;
15855 pipe.SetTessellation(&tsci);
15856 pipe.SetTessellation(&tsci_bad);
15857 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01426);
15858 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15859 m_errorMonitor->VerifyFound();
15860 tsci_bad.patchControlPoints = m_device->props.limits.maxTessellationPatchSize + 1;
15861 pipe.SetTessellation(&tsci_bad);
15862 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01426);
15863 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15864 m_errorMonitor->VerifyFound();
15865 pipe.SetTessellation(&tsci);
15866
15867 // Pass an invalid primitive topology
15868 VkPipelineInputAssemblyStateCreateInfo iasci_bad = iasci;
15869 iasci_bad.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
15870 pipe.SetInputAssembly(&iasci_bad);
15871 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02099);
15872 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15873 m_errorMonitor->VerifyFound();
15874 pipe.SetInputAssembly(&iasci);
15875 }
15876}
15877
Karl Schultz6addd812016-02-02 17:17:23 -070015878TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015879 TEST_DESCRIPTION(
15880 "Test that an error is produced for a vertex attribute setup where multiple "
15881 "bindings provide the same location");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015882 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15883 "Duplicate vertex input binding descriptions for binding 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015884
Tony Barbour1fa09702017-03-16 12:09:08 -060015885 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060015886 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes280ba2c2015-06-12 11:16:41 +120015887
15888 /* Two binding descriptions for binding 0 */
15889 VkVertexInputBindingDescription input_bindings[2];
15890 memset(input_bindings, 0, sizeof(input_bindings));
15891
15892 VkVertexInputAttributeDescription input_attrib;
15893 memset(&input_attrib, 0, sizeof(input_attrib));
15894 input_attrib.format = VK_FORMAT_R32_SFLOAT;
15895
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015896 char const *vsSource =
15897 "#version 450\n"
15898 "\n"
15899 "layout(location=0) in float x;\n" /* attrib provided float */
15900 "out gl_PerVertex {\n"
15901 " vec4 gl_Position;\n"
15902 "};\n"
15903 "void main(){\n"
15904 " gl_Position = vec4(x);\n"
15905 "}\n";
15906 char const *fsSource =
15907 "#version 450\n"
15908 "\n"
15909 "layout(location=0) out vec4 color;\n"
15910 "void main(){\n"
15911 " color = vec4(1);\n"
15912 "}\n";
Chris Forbes280ba2c2015-06-12 11:16:41 +120015913
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060015914 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15915 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes280ba2c2015-06-12 11:16:41 +120015916
15917 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080015918 pipe.AddColorAttachment();
Chris Forbes280ba2c2015-06-12 11:16:41 +120015919 pipe.AddShader(&vs);
15920 pipe.AddShader(&fs);
15921
15922 pipe.AddVertexInputBindings(input_bindings, 2);
15923 pipe.AddVertexInputAttribs(&input_attrib, 1);
15924
Chris Forbes280ba2c2015-06-12 11:16:41 +120015925 VkDescriptorSetObj descriptorSet(m_device);
15926 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015927 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes280ba2c2015-06-12 11:16:41 +120015928
Tony Barbour5781e8f2015-08-04 16:23:11 -060015929 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes280ba2c2015-06-12 11:16:41 +120015930
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015931 m_errorMonitor->VerifyFound();
Chris Forbes280ba2c2015-06-12 11:16:41 +120015932}
Chris Forbes8f68b562015-05-25 11:13:32 +120015933
Karl Schultz6addd812016-02-02 17:17:23 -070015934TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015935 TEST_DESCRIPTION(
15936 "Test that an error is produced for a fragment shader which does not "
15937 "provide an output for one of the pipeline's color attachments");
Mike Weiblencce7ec72016-10-17 19:33:05 -060015938 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attachment 0 not written by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015939
Tony Barbour1fa09702017-03-16 12:09:08 -060015940 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120015941
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015942 char const *vsSource =
15943 "#version 450\n"
15944 "\n"
15945 "out gl_PerVertex {\n"
15946 " vec4 gl_Position;\n"
15947 "};\n"
15948 "void main(){\n"
15949 " gl_Position = vec4(1);\n"
15950 "}\n";
15951 char const *fsSource =
15952 "#version 450\n"
15953 "\n"
15954 "void main(){\n"
15955 "}\n";
Chris Forbes4d6d1e52015-05-25 11:13:40 +120015956
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060015957 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15958 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120015959
15960 VkPipelineObj pipe(m_device);
15961 pipe.AddShader(&vs);
15962 pipe.AddShader(&fs);
15963
Chia-I Wu08accc62015-07-07 11:50:03 +080015964 /* set up CB 0, not written */
15965 pipe.AddColorAttachment();
15966 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120015967
Chris Forbes4d6d1e52015-05-25 11:13:40 +120015968 VkDescriptorSetObj descriptorSet(m_device);
15969 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015970 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120015971
Tony Barbour5781e8f2015-08-04 16:23:11 -060015972 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120015973
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015974 m_errorMonitor->VerifyFound();
Chris Forbes4d6d1e52015-05-25 11:13:40 +120015975}
15976
Karl Schultz6addd812016-02-02 17:17:23 -070015977TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015978 TEST_DESCRIPTION(
15979 "Test that a warning is produced for a fragment shader which provides a spurious "
15980 "output with no matching attachment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015981 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060015982 "fragment shader writes to output location 1 with no matching attachment");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015983
Tony Barbour1fa09702017-03-16 12:09:08 -060015984 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120015985
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015986 char const *vsSource =
15987 "#version 450\n"
15988 "\n"
15989 "out gl_PerVertex {\n"
15990 " vec4 gl_Position;\n"
15991 "};\n"
15992 "void main(){\n"
15993 " gl_Position = vec4(1);\n"
15994 "}\n";
15995 char const *fsSource =
15996 "#version 450\n"
15997 "\n"
15998 "layout(location=0) out vec4 x;\n"
15999 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
16000 "void main(){\n"
16001 " x = vec4(1);\n"
16002 " y = vec4(1);\n"
16003 "}\n";
Chris Forbesf3fffaa2015-05-25 11:13:43 +120016004
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060016005 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
16006 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120016007
16008 VkPipelineObj pipe(m_device);
16009 pipe.AddShader(&vs);
16010 pipe.AddShader(&fs);
16011
Chia-I Wu08accc62015-07-07 11:50:03 +080016012 /* set up CB 0, not written */
16013 pipe.AddColorAttachment();
16014 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120016015 /* FS writes CB 1, but we don't configure it */
16016
Chris Forbesf3fffaa2015-05-25 11:13:43 +120016017 VkDescriptorSetObj descriptorSet(m_device);
16018 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016019 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120016020
Tony Barbour5781e8f2015-08-04 16:23:11 -060016021 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120016022
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016023 m_errorMonitor->VerifyFound();
Chris Forbesf3fffaa2015-05-25 11:13:43 +120016024}
16025
Karl Schultz6addd812016-02-02 17:17:23 -070016026TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016027 TEST_DESCRIPTION(
16028 "Test that an error is produced for a mismatch between the fundamental "
16029 "type of an fragment shader output variable, and the format of the corresponding attachment");
Mike Weiblencce7ec72016-10-17 19:33:05 -060016030 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "does not match fragment shader output type");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016031
Tony Barbour1fa09702017-03-16 12:09:08 -060016032 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbesa36d69e2015-05-25 11:13:44 +120016033
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016034 char const *vsSource =
16035 "#version 450\n"
16036 "\n"
16037 "out gl_PerVertex {\n"
16038 " vec4 gl_Position;\n"
16039 "};\n"
16040 "void main(){\n"
16041 " gl_Position = vec4(1);\n"
16042 "}\n";
16043 char const *fsSource =
16044 "#version 450\n"
16045 "\n"
16046 "layout(location=0) out ivec4 x;\n" /* not UNORM */
16047 "void main(){\n"
16048 " x = ivec4(1);\n"
16049 "}\n";
Chris Forbesa36d69e2015-05-25 11:13:44 +120016050
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060016051 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
16052 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa36d69e2015-05-25 11:13:44 +120016053
16054 VkPipelineObj pipe(m_device);
16055 pipe.AddShader(&vs);
16056 pipe.AddShader(&fs);
16057
Chia-I Wu08accc62015-07-07 11:50:03 +080016058 /* set up CB 0; type is UNORM by default */
16059 pipe.AddColorAttachment();
16060 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa36d69e2015-05-25 11:13:44 +120016061
Chris Forbesa36d69e2015-05-25 11:13:44 +120016062 VkDescriptorSetObj descriptorSet(m_device);
16063 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016064 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesa36d69e2015-05-25 11:13:44 +120016065
Tony Barbour5781e8f2015-08-04 16:23:11 -060016066 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa36d69e2015-05-25 11:13:44 +120016067
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016068 m_errorMonitor->VerifyFound();
Chris Forbesa36d69e2015-05-25 11:13:44 +120016069}
Chris Forbes7b1b8932015-06-05 14:43:36 +120016070
Karl Schultz6addd812016-02-02 17:17:23 -070016071TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016072 TEST_DESCRIPTION(
16073 "Test that an error is produced for a shader consuming a uniform "
16074 "block which has no corresponding binding in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016075 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in pipeline layout");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016076
Tony Barbour1fa09702017-03-16 12:09:08 -060016077 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes556c76c2015-08-14 12:04:59 +120016078
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016079 char const *vsSource =
16080 "#version 450\n"
16081 "\n"
16082 "out gl_PerVertex {\n"
16083 " vec4 gl_Position;\n"
16084 "};\n"
16085 "void main(){\n"
16086 " gl_Position = vec4(1);\n"
16087 "}\n";
16088 char const *fsSource =
16089 "#version 450\n"
16090 "\n"
16091 "layout(location=0) out vec4 x;\n"
16092 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
16093 "void main(){\n"
16094 " x = vec4(bar.y);\n"
16095 "}\n";
Chris Forbes556c76c2015-08-14 12:04:59 +120016096
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060016097 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
16098 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes556c76c2015-08-14 12:04:59 +120016099
Chris Forbes556c76c2015-08-14 12:04:59 +120016100 VkPipelineObj pipe(m_device);
16101 pipe.AddShader(&vs);
16102 pipe.AddShader(&fs);
16103
16104 /* set up CB 0; type is UNORM by default */
16105 pipe.AddColorAttachment();
16106 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16107
16108 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016109 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes556c76c2015-08-14 12:04:59 +120016110
16111 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
16112
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016113 m_errorMonitor->VerifyFound();
Chris Forbes556c76c2015-08-14 12:04:59 +120016114}
16115
Chris Forbes5c59e902016-02-26 16:56:09 +130016116TEST_F(VkLayerTest, CreatePipelinePushConstantsNotInLayout) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016117 TEST_DESCRIPTION(
16118 "Test that an error is produced for a shader consuming push constants "
16119 "which are not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016120 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in layout");
Chris Forbes5c59e902016-02-26 16:56:09 +130016121
Tony Barbour1fa09702017-03-16 12:09:08 -060016122 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes5c59e902016-02-26 16:56:09 +130016123
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016124 char const *vsSource =
16125 "#version 450\n"
16126 "\n"
16127 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
16128 "out gl_PerVertex {\n"
16129 " vec4 gl_Position;\n"
16130 "};\n"
16131 "void main(){\n"
16132 " gl_Position = vec4(consts.x);\n"
16133 "}\n";
16134 char const *fsSource =
16135 "#version 450\n"
16136 "\n"
16137 "layout(location=0) out vec4 x;\n"
16138 "void main(){\n"
16139 " x = vec4(1);\n"
16140 "}\n";
Chris Forbes5c59e902016-02-26 16:56:09 +130016141
16142 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
16143 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
16144
16145 VkPipelineObj pipe(m_device);
16146 pipe.AddShader(&vs);
16147 pipe.AddShader(&fs);
16148
16149 /* set up CB 0; type is UNORM by default */
16150 pipe.AddColorAttachment();
16151 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16152
16153 VkDescriptorSetObj descriptorSet(m_device);
16154 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
16155
16156 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
16157
16158 /* should have generated an error -- no push constant ranges provided! */
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016159 m_errorMonitor->VerifyFound();
Chris Forbes5c59e902016-02-26 16:56:09 +130016160}
16161
Chris Forbes3fb17902016-08-22 14:57:55 +120016162TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissing) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016163 TEST_DESCRIPTION(
16164 "Test that an error is produced for a shader consuming an input attachment "
16165 "which is not included in the subpass description");
Chris Forbes3fb17902016-08-22 14:57:55 +120016166 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16167 "consumes input attachment index 0 but not provided in subpass");
16168
Tony Barbour1fa09702017-03-16 12:09:08 -060016169 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes3fb17902016-08-22 14:57:55 +120016170
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016171 char const *vsSource =
16172 "#version 450\n"
16173 "\n"
16174 "out gl_PerVertex {\n"
16175 " vec4 gl_Position;\n"
16176 "};\n"
16177 "void main(){\n"
16178 " gl_Position = vec4(1);\n"
16179 "}\n";
16180 char const *fsSource =
16181 "#version 450\n"
16182 "\n"
16183 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
16184 "layout(location=0) out vec4 color;\n"
16185 "void main() {\n"
16186 " color = subpassLoad(x);\n"
16187 "}\n";
Chris Forbes3fb17902016-08-22 14:57:55 +120016188
16189 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
16190 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
16191
16192 VkPipelineObj pipe(m_device);
16193 pipe.AddShader(&vs);
16194 pipe.AddShader(&fs);
16195 pipe.AddColorAttachment();
16196 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16197
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016198 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
16199 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes3fb17902016-08-22 14:57:55 +120016200 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016201 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes3fb17902016-08-22 14:57:55 +120016202 ASSERT_VK_SUCCESS(err);
16203
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016204 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes3fb17902016-08-22 14:57:55 +120016205 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016206 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes3fb17902016-08-22 14:57:55 +120016207 ASSERT_VK_SUCCESS(err);
16208
16209 // error here.
16210 pipe.CreateVKPipeline(pl, renderPass());
16211
16212 m_errorMonitor->VerifyFound();
16213
16214 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
16215 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
16216}
16217
Chris Forbes5a9a0472016-08-22 16:02:09 +120016218TEST_F(VkLayerTest, CreatePipelineInputAttachmentTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016219 TEST_DESCRIPTION(
16220 "Test that an error is produced for a shader consuming an input attachment "
16221 "with a format having a different fundamental type");
Chris Forbes5a9a0472016-08-22 16:02:09 +120016222 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16223 "input attachment 0 format of VK_FORMAT_R8G8B8A8_UINT does not match");
16224
Tony Barbour1fa09702017-03-16 12:09:08 -060016225 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes5a9a0472016-08-22 16:02:09 +120016226
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016227 char const *vsSource =
16228 "#version 450\n"
16229 "\n"
16230 "out gl_PerVertex {\n"
16231 " vec4 gl_Position;\n"
16232 "};\n"
16233 "void main(){\n"
16234 " gl_Position = vec4(1);\n"
16235 "}\n";
16236 char const *fsSource =
16237 "#version 450\n"
16238 "\n"
16239 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
16240 "layout(location=0) out vec4 color;\n"
16241 "void main() {\n"
16242 " color = subpassLoad(x);\n"
16243 "}\n";
Chris Forbes5a9a0472016-08-22 16:02:09 +120016244
16245 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
16246 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
16247
16248 VkPipelineObj pipe(m_device);
16249 pipe.AddShader(&vs);
16250 pipe.AddShader(&fs);
16251 pipe.AddColorAttachment();
16252 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16253
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016254 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
16255 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes5a9a0472016-08-22 16:02:09 +120016256 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016257 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120016258 ASSERT_VK_SUCCESS(err);
16259
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016260 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120016261 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016262 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120016263 ASSERT_VK_SUCCESS(err);
16264
16265 VkAttachmentDescription descs[2] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016266 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
16267 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
16268 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
16269 {0, VK_FORMAT_R8G8B8A8_UINT, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
16270 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 +120016271 };
16272 VkAttachmentReference color = {
16273 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
16274 };
16275 VkAttachmentReference input = {
16276 1, VK_IMAGE_LAYOUT_GENERAL,
16277 };
16278
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016279 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120016280
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016281 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120016282 VkRenderPass rp;
16283 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
16284 ASSERT_VK_SUCCESS(err);
16285
16286 // error here.
16287 pipe.CreateVKPipeline(pl, rp);
16288
16289 m_errorMonitor->VerifyFound();
16290
16291 vkDestroyRenderPass(m_device->device(), rp, nullptr);
16292 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
16293 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
16294}
16295
Chris Forbes541f7b02016-08-22 15:30:27 +120016296TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissingArray) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016297 TEST_DESCRIPTION(
16298 "Test that an error is produced for a shader consuming an input attachment "
16299 "which is not included in the subpass description -- array case");
Chris Forbes541f7b02016-08-22 15:30:27 +120016300 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Rene Lindsay07b60af2017-01-10 15:57:55 -070016301 "consumes input attachment index 0 but not provided in subpass");
Chris Forbes541f7b02016-08-22 15:30:27 +120016302
Tony Barbour1fa09702017-03-16 12:09:08 -060016303 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes541f7b02016-08-22 15:30:27 +120016304
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016305 char const *vsSource =
16306 "#version 450\n"
16307 "\n"
16308 "out gl_PerVertex {\n"
16309 " vec4 gl_Position;\n"
16310 "};\n"
16311 "void main(){\n"
16312 " gl_Position = vec4(1);\n"
16313 "}\n";
16314 char const *fsSource =
16315 "#version 450\n"
16316 "\n"
16317 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput xs[1];\n"
16318 "layout(location=0) out vec4 color;\n"
16319 "void main() {\n"
16320 " color = subpassLoad(xs[0]);\n"
16321 "}\n";
Chris Forbes541f7b02016-08-22 15:30:27 +120016322
16323 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
16324 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
16325
16326 VkPipelineObj pipe(m_device);
16327 pipe.AddShader(&vs);
16328 pipe.AddShader(&fs);
16329 pipe.AddColorAttachment();
16330 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16331
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016332 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 2, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
16333 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes541f7b02016-08-22 15:30:27 +120016334 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016335 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes541f7b02016-08-22 15:30:27 +120016336 ASSERT_VK_SUCCESS(err);
16337
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016338 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes541f7b02016-08-22 15:30:27 +120016339 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016340 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes541f7b02016-08-22 15:30:27 +120016341 ASSERT_VK_SUCCESS(err);
16342
16343 // error here.
16344 pipe.CreateVKPipeline(pl, renderPass());
16345
16346 m_errorMonitor->VerifyFound();
16347
16348 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
16349 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
16350}
16351
Chris Forbes10eb9ae2016-05-31 16:09:42 +120016352TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptor) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016353 TEST_DESCRIPTION(
16354 "Test that an error is produced for a compute pipeline consuming a "
16355 "descriptor which is not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016356 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Shader uses descriptor slot 0.0");
Chris Forbes10eb9ae2016-05-31 16:09:42 +120016357
Tony Barbour1fa09702017-03-16 12:09:08 -060016358 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes10eb9ae2016-05-31 16:09:42 +120016359
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016360 char const *csSource =
16361 "#version 450\n"
16362 "\n"
16363 "layout(local_size_x=1) in;\n"
16364 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
16365 "void main(){\n"
16366 " x = vec4(1);\n"
16367 "}\n";
Chris Forbes10eb9ae2016-05-31 16:09:42 +120016368
16369 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
16370
16371 VkDescriptorSetObj descriptorSet(m_device);
16372 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
16373
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016374 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
16375 nullptr,
16376 0,
16377 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
16378 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
16379 descriptorSet.GetPipelineLayout(),
16380 VK_NULL_HANDLE,
16381 -1};
Chris Forbes10eb9ae2016-05-31 16:09:42 +120016382
16383 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016384 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes10eb9ae2016-05-31 16:09:42 +120016385
16386 m_errorMonitor->VerifyFound();
16387
16388 if (err == VK_SUCCESS) {
16389 vkDestroyPipeline(m_device->device(), pipe, nullptr);
16390 }
16391}
16392
Chris Forbes22a9b092016-07-19 14:34:05 +120016393TEST_F(VkLayerTest, CreateComputePipelineDescriptorTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016394 TEST_DESCRIPTION(
16395 "Test that an error is produced for a pipeline consuming a "
16396 "descriptor-backed resource of a mismatched type");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016397 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16398 "but descriptor of type VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER");
Chris Forbes22a9b092016-07-19 14:34:05 +120016399
Tony Barbour1fa09702017-03-16 12:09:08 -060016400 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes22a9b092016-07-19 14:34:05 +120016401
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016402 VkDescriptorSetLayoutBinding binding = {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr};
16403 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &binding};
Chris Forbes22a9b092016-07-19 14:34:05 +120016404 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016405 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes22a9b092016-07-19 14:34:05 +120016406 ASSERT_VK_SUCCESS(err);
16407
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016408 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes22a9b092016-07-19 14:34:05 +120016409 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016410 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes22a9b092016-07-19 14:34:05 +120016411 ASSERT_VK_SUCCESS(err);
16412
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016413 char const *csSource =
16414 "#version 450\n"
16415 "\n"
16416 "layout(local_size_x=1) in;\n"
16417 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
16418 "void main() {\n"
16419 " x.x = 1.0f;\n"
16420 "}\n";
Chris Forbes22a9b092016-07-19 14:34:05 +120016421 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
16422
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016423 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
16424 nullptr,
16425 0,
16426 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
16427 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
16428 pl,
16429 VK_NULL_HANDLE,
16430 -1};
Chris Forbes22a9b092016-07-19 14:34:05 +120016431
16432 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016433 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes22a9b092016-07-19 14:34:05 +120016434
16435 m_errorMonitor->VerifyFound();
16436
16437 if (err == VK_SUCCESS) {
16438 vkDestroyPipeline(m_device->device(), pipe, nullptr);
16439 }
16440
16441 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
16442 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
16443}
16444
Chris Forbes50020592016-07-27 13:52:41 +120016445TEST_F(VkLayerTest, DrawTimeImageViewTypeMismatchWithPipeline) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016446 TEST_DESCRIPTION(
16447 "Test that an error is produced when an image view type "
16448 "does not match the dimensionality declared in the shader");
Chris Forbes50020592016-07-27 13:52:41 +120016449
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016450 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 +120016451
Tony Barbour1fa09702017-03-16 12:09:08 -060016452 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes50020592016-07-27 13:52:41 +120016453 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16454
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016455 char const *vsSource =
16456 "#version 450\n"
16457 "\n"
16458 "out gl_PerVertex { vec4 gl_Position; };\n"
16459 "void main() { gl_Position = vec4(0); }\n";
16460 char const *fsSource =
16461 "#version 450\n"
16462 "\n"
16463 "layout(set=0, binding=0) uniform sampler3D s;\n"
16464 "layout(location=0) out vec4 color;\n"
16465 "void main() {\n"
16466 " color = texture(s, vec3(0));\n"
16467 "}\n";
Chris Forbes50020592016-07-27 13:52:41 +120016468 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
16469 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
16470
16471 VkPipelineObj pipe(m_device);
16472 pipe.AddShader(&vs);
16473 pipe.AddShader(&fs);
16474 pipe.AddColorAttachment();
16475
16476 VkTextureObj texture(m_device, nullptr);
16477 VkSamplerObj sampler(m_device);
16478
16479 VkDescriptorSetObj descriptorSet(m_device);
16480 descriptorSet.AppendSamplerTexture(&sampler, &texture);
16481 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
16482
16483 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
16484 ASSERT_VK_SUCCESS(err);
16485
Tony Barbour552f6c02016-12-21 14:34:07 -070016486 m_commandBuffer->BeginCommandBuffer();
16487 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes50020592016-07-27 13:52:41 +120016488
16489 m_commandBuffer->BindPipeline(pipe);
16490 m_commandBuffer->BindDescriptorSet(descriptorSet);
16491
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016492 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes50020592016-07-27 13:52:41 +120016493 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016494 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes50020592016-07-27 13:52:41 +120016495 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16496
16497 // error produced here.
16498 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
16499
16500 m_errorMonitor->VerifyFound();
16501
Tony Barbour552f6c02016-12-21 14:34:07 -070016502 m_commandBuffer->EndRenderPass();
16503 m_commandBuffer->EndCommandBuffer();
Chris Forbes50020592016-07-27 13:52:41 +120016504}
16505
Chris Forbes5533bfc2016-07-27 14:12:34 +120016506TEST_F(VkLayerTest, DrawTimeImageMultisampleMismatchWithPipeline) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016507 TEST_DESCRIPTION(
16508 "Test that an error is produced when a multisampled images "
16509 "are consumed via singlesample images types in the shader, or vice versa.");
Chris Forbes5533bfc2016-07-27 14:12:34 +120016510
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016511 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "requires bound image to have multiple samples");
Chris Forbes5533bfc2016-07-27 14:12:34 +120016512
Tony Barbour1fa09702017-03-16 12:09:08 -060016513 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes5533bfc2016-07-27 14:12:34 +120016514 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16515
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016516 char const *vsSource =
16517 "#version 450\n"
16518 "\n"
16519 "out gl_PerVertex { vec4 gl_Position; };\n"
16520 "void main() { gl_Position = vec4(0); }\n";
16521 char const *fsSource =
16522 "#version 450\n"
16523 "\n"
16524 "layout(set=0, binding=0) uniform sampler2DMS s;\n"
16525 "layout(location=0) out vec4 color;\n"
16526 "void main() {\n"
16527 " color = texelFetch(s, ivec2(0), 0);\n"
16528 "}\n";
Chris Forbes5533bfc2016-07-27 14:12:34 +120016529 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
16530 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
16531
16532 VkPipelineObj pipe(m_device);
16533 pipe.AddShader(&vs);
16534 pipe.AddShader(&fs);
16535 pipe.AddColorAttachment();
16536
16537 VkTextureObj texture(m_device, nullptr);
16538 VkSamplerObj sampler(m_device);
16539
16540 VkDescriptorSetObj descriptorSet(m_device);
16541 descriptorSet.AppendSamplerTexture(&sampler, &texture);
16542 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
16543
16544 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
16545 ASSERT_VK_SUCCESS(err);
16546
Tony Barbour552f6c02016-12-21 14:34:07 -070016547 m_commandBuffer->BeginCommandBuffer();
16548 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes5533bfc2016-07-27 14:12:34 +120016549
16550 m_commandBuffer->BindPipeline(pipe);
16551 m_commandBuffer->BindDescriptorSet(descriptorSet);
16552
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016553 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes5533bfc2016-07-27 14:12:34 +120016554 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016555 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes5533bfc2016-07-27 14:12:34 +120016556 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16557
16558 // error produced here.
16559 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
16560
16561 m_errorMonitor->VerifyFound();
16562
Tony Barbour552f6c02016-12-21 14:34:07 -070016563 m_commandBuffer->EndRenderPass();
16564 m_commandBuffer->EndCommandBuffer();
Chris Forbes5533bfc2016-07-27 14:12:34 +120016565}
16566
Mark Youngc48c4c12016-04-11 14:26:49 -060016567TEST_F(VkLayerTest, CreateImageLimitsViolationMaxWidth) {
Tony Barbour1fa09702017-03-16 12:09:08 -060016568 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060016569
Jeremy Hayesbb63cc12017-03-20 15:33:01 -060016570 VkFormat const format = VK_FORMAT_B8G8R8A8_UNORM;
16571 {
16572 VkFormatProperties properties;
16573 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), format, &properties);
16574 if (properties.optimalTilingFeatures == 0) {
16575 printf(" Image format not supported; skipped.\n");
16576 return;
16577 }
16578 }
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060016579
Jeremy Hayesbb63cc12017-03-20 15:33:01 -060016580 VkImageCreateInfo info = {};
16581 info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16582 info.pNext = NULL;
16583 info.imageType = VK_IMAGE_TYPE_2D;
16584 info.format = format;
16585 info.extent.height = 32;
16586 info.extent.depth = 1;
16587 info.mipLevels = 1;
16588 info.arrayLayers = 1;
16589 info.samples = VK_SAMPLE_COUNT_1_BIT;
16590 info.tiling = VK_IMAGE_TILING_OPTIMAL;
16591 info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
16592 info.flags = 0;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060016593
16594 // Introduce error by sending down a bogus width extent
Jeremy Hayesbb63cc12017-03-20 15:33:01 -060016595 {
16596 VkImageFormatProperties properties;
16597 auto const result = vkGetPhysicalDeviceImageFormatProperties(m_device->phy().handle(), info.format, info.imageType,
16598 info.tiling, info.usage, info.flags, &properties);
16599 ASSERT_VK_SUCCESS(result);
16600 info.extent.width = properties.maxExtent.width + 1;
16601 }
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060016602
Jeremy Hayesbb63cc12017-03-20 15:33:01 -060016603 VkImage image;
16604 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
16605 vkCreateImage(m_device->device(), &info, NULL, &image);
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016606 m_errorMonitor->VerifyFound();
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060016607}
16608
Mark Youngc48c4c12016-04-11 14:26:49 -060016609TEST_F(VkLayerTest, CreateImageLimitsViolationMinWidth) {
Tony Barbour1fa09702017-03-16 12:09:08 -060016610 ASSERT_NO_FATAL_FAILURE(Init());
Mark Youngc48c4c12016-04-11 14:26:49 -060016611
Jeremy Hayesbb63cc12017-03-20 15:33:01 -060016612 VkFormat const format = VK_FORMAT_B8G8R8A8_UNORM;
16613 {
16614 VkFormatProperties properties;
16615 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), format, &properties);
16616 if (properties.optimalTilingFeatures == 0) {
16617 printf(" Image format not supported; skipped.\n");
16618 return;
16619 }
16620 }
Mark Youngc48c4c12016-04-11 14:26:49 -060016621
Jeremy Hayesbb63cc12017-03-20 15:33:01 -060016622 VkImageCreateInfo info = {};
16623 info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16624 info.pNext = NULL;
16625 info.imageType = VK_IMAGE_TYPE_2D;
16626 info.format = format;
16627 info.extent.height = 32;
16628 info.extent.depth = 1;
16629 info.mipLevels = 1;
16630 info.arrayLayers = 1;
16631 info.samples = VK_SAMPLE_COUNT_1_BIT;
16632 info.tiling = VK_IMAGE_TILING_OPTIMAL;
16633 info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
16634 info.flags = 0;
Mark Youngc48c4c12016-04-11 14:26:49 -060016635
16636 // Introduce error by sending down a bogus width extent
Jeremy Hayesbb63cc12017-03-20 15:33:01 -060016637 info.extent.width = 0;
Mark Youngc48c4c12016-04-11 14:26:49 -060016638
Jeremy Hayesbb63cc12017-03-20 15:33:01 -060016639 VkImage image;
Tobin Ehlisa55b1d42017-04-04 12:23:48 -060016640 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02917);
Jeremy Hayesbb63cc12017-03-20 15:33:01 -060016641 m_errorMonitor->SetUnexpectedError("parameter pCreateInfo->extent.width must be greater than 0");
16642 vkCreateImage(m_device->device(), &info, NULL, &image);
Mark Youngc48c4c12016-04-11 14:26:49 -060016643 m_errorMonitor->VerifyFound();
16644}
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -070016645
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060016646TEST_F(VkLayerTest, AttachmentDescriptionUndefinedFormat) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016647 TEST_DESCRIPTION(
16648 "Create a render pass with an attachment description "
16649 "format set to VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060016650
Tony Barbour1fa09702017-03-16 12:09:08 -060016651 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060016652 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16653
Jeremy Hayes632e0ab2017-02-09 13:32:28 -070016654 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "format is VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060016655
16656 VkAttachmentReference color_attach = {};
16657 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
16658 color_attach.attachment = 0;
16659 VkSubpassDescription subpass = {};
16660 subpass.colorAttachmentCount = 1;
16661 subpass.pColorAttachments = &color_attach;
16662
16663 VkRenderPassCreateInfo rpci = {};
16664 rpci.subpassCount = 1;
16665 rpci.pSubpasses = &subpass;
16666 rpci.attachmentCount = 1;
16667 VkAttachmentDescription attach_desc = {};
16668 attach_desc.format = VK_FORMAT_UNDEFINED;
16669 rpci.pAttachments = &attach_desc;
16670 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
16671 VkRenderPass rp;
16672 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
16673
16674 m_errorMonitor->VerifyFound();
16675
16676 if (result == VK_SUCCESS) {
16677 vkDestroyRenderPass(m_device->device(), rp, NULL);
16678 }
16679}
16680
Mark Youngd339ba32016-05-30 13:28:35 -060016681TEST_F(VkLayerTest, CreateImageViewNoMemoryBoundToImage) {
16682 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -060016683 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -060016684 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -060016685
Tony Barbour1fa09702017-03-16 12:09:08 -060016686 ASSERT_NO_FATAL_FAILURE(Init());
Mark Youngd339ba32016-05-30 13:28:35 -060016687
16688 // Create an image and try to create a view with no memory backing the image
16689 VkImage image;
16690
16691 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
16692 const int32_t tex_width = 32;
16693 const int32_t tex_height = 32;
16694
16695 VkImageCreateInfo image_create_info = {};
16696 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16697 image_create_info.pNext = NULL;
16698 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16699 image_create_info.format = tex_format;
16700 image_create_info.extent.width = tex_width;
16701 image_create_info.extent.height = tex_height;
16702 image_create_info.extent.depth = 1;
16703 image_create_info.mipLevels = 1;
16704 image_create_info.arrayLayers = 1;
16705 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16706 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16707 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
16708 image_create_info.flags = 0;
16709
16710 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
16711 ASSERT_VK_SUCCESS(err);
16712
16713 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130016714 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Mark Youngd339ba32016-05-30 13:28:35 -060016715 image_view_create_info.image = image;
16716 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
16717 image_view_create_info.format = tex_format;
16718 image_view_create_info.subresourceRange.layerCount = 1;
16719 image_view_create_info.subresourceRange.baseMipLevel = 0;
16720 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016721 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -060016722
16723 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016724 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Youngd339ba32016-05-30 13:28:35 -060016725
16726 m_errorMonitor->VerifyFound();
16727 vkDestroyImage(m_device->device(), image, NULL);
16728 // If last error is success, it still created the view, so delete it.
16729 if (err == VK_SUCCESS) {
16730 vkDestroyImageView(m_device->device(), view, NULL);
16731 }
Mark Youngd339ba32016-05-30 13:28:35 -060016732}
16733
Karl Schultz6addd812016-02-02 17:17:23 -070016734TEST_F(VkLayerTest, InvalidImageViewAspect) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016735 TEST_DESCRIPTION("Create an image and try to create a view with an invalid aspectMask");
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070016736 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00741);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016737
Tony Barbour1fa09702017-03-16 12:09:08 -060016738 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060016739
Karl Schultz6addd812016-02-02 17:17:23 -070016740 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060016741 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060016742 image.Init(32, 32, 1, tex_format, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_LINEAR, 0);
Tobin Ehlis1f567a22016-05-25 16:15:18 -060016743 ASSERT_TRUE(image.initialized());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060016744
16745 VkImageViewCreateInfo image_view_create_info = {};
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060016746 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060016747 image_view_create_info.image = image.handle();
Karl Schultz6addd812016-02-02 17:17:23 -070016748 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
16749 image_view_create_info.format = tex_format;
16750 image_view_create_info.subresourceRange.baseMipLevel = 0;
16751 image_view_create_info.subresourceRange.levelCount = 1;
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060016752 image_view_create_info.subresourceRange.layerCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070016753 // Cause an error by setting an invalid image aspect
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016754 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060016755
16756 VkImageView view;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060016757 vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060016758
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016759 m_errorMonitor->VerifyFound();
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060016760}
16761
Mike Weiblena1e13f42017-02-09 21:25:59 -070016762TEST_F(VkLayerTest, ExerciseGetImageSubresourceLayout) {
16763 TEST_DESCRIPTION("Test vkGetImageSubresourceLayout() valid usages");
16764
Tony Barbour1fa09702017-03-16 12:09:08 -060016765 ASSERT_NO_FATAL_FAILURE(Init());
Mike Weiblena1e13f42017-02-09 21:25:59 -070016766 VkSubresourceLayout subres_layout = {};
16767
16768 // VU 00732: image must have been created with tiling equal to VK_IMAGE_TILING_LINEAR
16769 {
16770 const VkImageTiling tiling = VK_IMAGE_TILING_OPTIMAL; // ERROR: violates VU 00732
16771 VkImageObj img(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060016772 img.InitNoLayout(32, 32, 1, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, tiling);
Mike Weiblena1e13f42017-02-09 21:25:59 -070016773 ASSERT_TRUE(img.initialized());
16774
16775 VkImageSubresource subres = {};
16776 subres.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16777 subres.mipLevel = 0;
16778 subres.arrayLayer = 0;
16779
16780 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00732);
16781 vkGetImageSubresourceLayout(m_device->device(), img.image(), &subres, &subres_layout);
16782 m_errorMonitor->VerifyFound();
16783 }
16784
16785 // VU 00733: The aspectMask member of pSubresource must only have a single bit set
16786 {
16787 VkImageObj img(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060016788 img.InitNoLayout(32, 32, 1, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
Mike Weiblena1e13f42017-02-09 21:25:59 -070016789 ASSERT_TRUE(img.initialized());
16790
16791 VkImageSubresource subres = {};
16792 subres.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_METADATA_BIT; // ERROR: triggers VU 00733
16793 subres.mipLevel = 0;
16794 subres.arrayLayer = 0;
16795
16796 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00733);
16797 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00741);
16798 vkGetImageSubresourceLayout(m_device->device(), img.image(), &subres, &subres_layout);
16799 m_errorMonitor->VerifyFound();
16800 }
16801
16802 // 00739 mipLevel must be less than the mipLevels specified in VkImageCreateInfo when the image was created
16803 {
16804 VkImageObj img(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060016805 img.InitNoLayout(32, 32, 1, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
Mike Weiblena1e13f42017-02-09 21:25:59 -070016806 ASSERT_TRUE(img.initialized());
16807
16808 VkImageSubresource subres = {};
16809 subres.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16810 subres.mipLevel = 1; // ERROR: triggers VU 00739
16811 subres.arrayLayer = 0;
16812
16813 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00739);
16814 vkGetImageSubresourceLayout(m_device->device(), img.image(), &subres, &subres_layout);
16815 m_errorMonitor->VerifyFound();
16816 }
16817
16818 // 00740 arrayLayer must be less than the arrayLayers specified in VkImageCreateInfo when the image was created
16819 {
16820 VkImageObj img(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060016821 img.InitNoLayout(32, 32, 1, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
Mike Weiblena1e13f42017-02-09 21:25:59 -070016822 ASSERT_TRUE(img.initialized());
16823
16824 VkImageSubresource subres = {};
16825 subres.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16826 subres.mipLevel = 0;
16827 subres.arrayLayer = 1; // ERROR: triggers VU 00740
16828
16829 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00740);
16830 vkGetImageSubresourceLayout(m_device->device(), img.image(), &subres, &subres_layout);
16831 m_errorMonitor->VerifyFound();
16832 }
16833}
16834
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016835TEST_F(VkLayerTest, CopyImageLayerCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -070016836 VkResult err;
16837 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016838
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070016839 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01198);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016840
Tony Barbour1fa09702017-03-16 12:09:08 -060016841 ASSERT_NO_FATAL_FAILURE(Init());
Mike Stroyana3082432015-09-25 13:39:21 -060016842
16843 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070016844 VkImage srcImage;
16845 VkImage dstImage;
16846 VkDeviceMemory srcMem;
16847 VkDeviceMemory destMem;
16848 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016849
16850 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016851 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16852 image_create_info.pNext = NULL;
16853 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16854 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16855 image_create_info.extent.width = 32;
16856 image_create_info.extent.height = 32;
16857 image_create_info.extent.depth = 1;
16858 image_create_info.mipLevels = 1;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016859 image_create_info.arrayLayers = 4;
Karl Schultz6addd812016-02-02 17:17:23 -070016860 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16861 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16862 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16863 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016864
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016865 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016866 ASSERT_VK_SUCCESS(err);
16867
Mark Lobodzinski867787a2016-10-14 11:49:55 -060016868 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016869 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016870 ASSERT_VK_SUCCESS(err);
16871
16872 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016873 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016874 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16875 memAlloc.pNext = NULL;
16876 memAlloc.allocationSize = 0;
16877 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016878
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060016879 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016880 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016881 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016882 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016883 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016884 ASSERT_VK_SUCCESS(err);
16885
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016886 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016887 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016888 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016889 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016890 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016891 ASSERT_VK_SUCCESS(err);
16892
16893 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16894 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016895 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016896 ASSERT_VK_SUCCESS(err);
16897
Tony Barbour552f6c02016-12-21 14:34:07 -070016898 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060016899 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016900 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016901 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060016902 copyRegion.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016903 copyRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060016904 copyRegion.srcOffset.x = 0;
16905 copyRegion.srcOffset.y = 0;
16906 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016907 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016908 copyRegion.dstSubresource.mipLevel = 0;
16909 copyRegion.dstSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016910 // Introduce failure by forcing the dst layerCount to differ from src
16911 copyRegion.dstSubresource.layerCount = 3;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016912 copyRegion.dstOffset.x = 0;
16913 copyRegion.dstOffset.y = 0;
16914 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016915 copyRegion.extent.width = 1;
16916 copyRegion.extent.height = 1;
16917 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016918 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070016919 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060016920
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016921 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060016922
Chia-I Wuf7458c52015-10-26 21:10:41 +080016923 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016924 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016925 vkFreeMemory(m_device->device(), srcMem, NULL);
16926 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016927}
16928
Tony Barbourd6673642016-05-05 14:46:39 -060016929TEST_F(VkLayerTest, ImageLayerUnsupportedFormat) {
Tony Barbourd6673642016-05-05 14:46:39 -060016930 TEST_DESCRIPTION("Creating images with unsuported formats ");
16931
Tony Barbour1fa09702017-03-16 12:09:08 -060016932 ASSERT_NO_FATAL_FAILURE(Init());
Tony Barbourd6673642016-05-05 14:46:39 -060016933 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourd6673642016-05-05 14:46:39 -060016934
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060016935 // Create image with unsupported format - Expect FORMAT_UNSUPPORTED
Chris Forbesf4d8e332016-11-28 17:51:10 +130016936 VkImageCreateInfo image_create_info = {};
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060016937 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060016938 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16939 image_create_info.format = VK_FORMAT_UNDEFINED;
16940 image_create_info.extent.width = 32;
16941 image_create_info.extent.height = 32;
16942 image_create_info.extent.depth = 1;
16943 image_create_info.mipLevels = 1;
16944 image_create_info.arrayLayers = 1;
16945 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16946 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16947 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060016948
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016949 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16950 "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED");
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060016951
Jeremy Hayes96dcd812017-03-14 14:04:19 -060016952 VkImage image;
16953 vkCreateImage(m_device->handle(), &image_create_info, NULL, &image);
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060016954 m_errorMonitor->VerifyFound();
16955
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060016956 // Look for a format that is COMPLETELY unsupported with this hardware
Jeremy Hayes96dcd812017-03-14 14:04:19 -060016957 VkFormat unsupported = VK_FORMAT_UNDEFINED;
Tony Barbourd6673642016-05-05 14:46:39 -060016958 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
16959 VkFormat format = static_cast<VkFormat>(f);
16960 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016961 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Tony Barbourd6673642016-05-05 14:46:39 -060016962 unsupported = format;
16963 break;
16964 }
16965 }
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060016966
Tony Barbourd6673642016-05-05 14:46:39 -060016967 if (unsupported != VK_FORMAT_UNDEFINED) {
Tony Barbourd6673642016-05-05 14:46:39 -060016968 image_create_info.format = unsupported;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016969 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is an unsupported format");
Tony Barbourd6673642016-05-05 14:46:39 -060016970
Jeremy Hayes96dcd812017-03-14 14:04:19 -060016971 vkCreateImage(m_device->handle(), &image_create_info, NULL, &image);
Tony Barbourd6673642016-05-05 14:46:39 -060016972 m_errorMonitor->VerifyFound();
16973 }
16974}
16975
16976TEST_F(VkLayerTest, ImageLayerViewTests) {
Tony Barbourd6673642016-05-05 14:46:39 -060016977 TEST_DESCRIPTION("Passing bad parameters to CreateImageView");
16978
Tony Barbour1fa09702017-03-16 12:09:08 -060016979 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -060016980 auto depth_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbourf887b162017-03-09 10:06:46 -070016981 if (!depth_format) {
16982 return;
16983 }
Tony Barbourd6673642016-05-05 14:46:39 -060016984
16985 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060016986 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 -060016987 VK_IMAGE_TILING_OPTIMAL, 0);
16988 ASSERT_TRUE(image.initialized());
16989
16990 VkImageView imgView;
16991 VkImageViewCreateInfo imgViewInfo = {};
16992 imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
16993 imgViewInfo.image = image.handle();
16994 imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
16995 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
16996 imgViewInfo.subresourceRange.layerCount = 1;
16997 imgViewInfo.subresourceRange.baseMipLevel = 0;
16998 imgViewInfo.subresourceRange.levelCount = 1;
16999 imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17000
Tony Barbourd6673642016-05-05 14:46:39 -060017001
Tony Barbourd6673642016-05-05 14:46:39 -060017002 // Can't use depth format for view into color image - Expect INVALID_FORMAT
Tony Barbourf887b162017-03-09 10:06:46 -070017003 imgViewInfo.format = depth_format;
Jeremy Hayes2ffbaa72017-03-14 17:05:50 -060017004 m_errorMonitor->SetDesiredFailureMsg(
17005 VK_DEBUG_REPORT_ERROR_BIT_EXT,
17006 "Formats MUST be IDENTICAL unless VK_IMAGE_CREATE_MUTABLE_FORMAT BIT was set on image creation.");
Tony Barbourd6673642016-05-05 14:46:39 -060017007 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
17008 m_errorMonitor->VerifyFound();
17009 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
17010
Tony Barbourd6673642016-05-05 14:46:39 -060017011 // Same compatibility class but no MUTABLE_FORMAT bit - Expect
17012 // VIEW_CREATE_ERROR
17013 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UINT;
Jeremy Hayes2ffbaa72017-03-14 17:05:50 -060017014 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02172);
Tony Barbourd6673642016-05-05 14:46:39 -060017015 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
17016 m_errorMonitor->VerifyFound();
17017 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
17018
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060017019 // TODO: Update framework to easily passing mutable flag into ImageObj init
17020 // For now just allowing image for this one test to not have memory bound
Jeremy Hayes5a7cf2e2017-01-06 15:23:27 -070017021 // TODO: The following line is preventing the intended validation from occurring because of the way the error monitor works.
17022 // m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17023 // " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Tony Barbourd6673642016-05-05 14:46:39 -060017024 // Have MUTABLE_FORMAT bit but not in same compatibility class - Expect
17025 // VIEW_CREATE_ERROR
17026 VkImageCreateInfo mutImgInfo = image.create_info();
17027 VkImage mutImage;
17028 mutImgInfo.format = VK_FORMAT_R8_UINT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017029 assert(m_device->format_properties(VK_FORMAT_R8_UINT).optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
Tony Barbourd6673642016-05-05 14:46:39 -060017030 mutImgInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
17031 mutImgInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Jeremy Hayes2ffbaa72017-03-14 17:05:50 -060017032 VkResult ret = vkCreateImage(m_device->handle(), &mutImgInfo, NULL, &mutImage);
Tony Barbourd6673642016-05-05 14:46:39 -060017033 ASSERT_VK_SUCCESS(ret);
Jeremy Hayes2ffbaa72017-03-14 17:05:50 -060017034
17035 VkMemoryRequirements requirements;
17036 vkGetImageMemoryRequirements(m_device->device(), mutImage, &requirements);
17037
17038 VkMemoryAllocateInfo alloc_info{};
17039 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17040 alloc_info.pNext = NULL;
17041 alloc_info.memoryTypeIndex = 0;
17042 alloc_info.allocationSize = requirements.size;
17043 bool pass = m_device->phy().set_memory_type(requirements.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
17044 ASSERT_TRUE(pass);
17045
17046 VkDeviceMemory memory;
17047 ret = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &memory);
17048 ASSERT_VK_SUCCESS(ret);
17049
17050 ret = vkBindImageMemory(m_device->device(), mutImage, memory, 0);
17051 ASSERT_VK_SUCCESS(ret);
17052
Tony Barbourd6673642016-05-05 14:46:39 -060017053 imgViewInfo.image = mutImage;
Jeremy Hayes2ffbaa72017-03-14 17:05:50 -060017054 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02171);
Tony Barbourd6673642016-05-05 14:46:39 -060017055 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
17056 m_errorMonitor->VerifyFound();
17057 imgViewInfo.image = image.handle();
Jeremy Hayes2ffbaa72017-03-14 17:05:50 -060017058
17059 vkFreeMemory(m_device->device(), memory, NULL);
Tony Barbourd6673642016-05-05 14:46:39 -060017060 vkDestroyImage(m_device->handle(), mutImage, NULL);
17061}
17062
Petr Kraus4d718682017-05-18 03:38:41 +020017063TEST_F(VkLayerTest, ImageViewSubresourceRangeTests) {
17064 TEST_DESCRIPTION("Passing bad image subrange to CreateImageView");
17065
17066 ASSERT_NO_FATAL_FAILURE(Init());
17067 auto depth_format = FindSupportedDepthStencilFormat(gpu());
17068 if (!depth_format) {
17069 return;
17070 }
17071
17072 VkImageObj image(m_device);
17073 image.Init(128, 128, 1, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
17074 VK_IMAGE_TILING_OPTIMAL, 0);
17075 ASSERT_TRUE(image.initialized());
17076
17077 VkImageView imgView;
17078 VkImageViewCreateInfo imgViewInfo = {};
17079 imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
17080 imgViewInfo.image = image.handle();
17081 imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
17082 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
17083 imgViewInfo.subresourceRange.layerCount = 1;
17084 imgViewInfo.subresourceRange.baseMipLevel = 0;
17085 imgViewInfo.subresourceRange.levelCount = 1;
17086 imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17087
17088 // View's levelCount can't be 0
17089 imgViewInfo.subresourceRange.levelCount = 0;
17090 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
17091 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
17092 m_errorMonitor->VerifyFound();
17093 imgViewInfo.subresourceRange.levelCount = 1;
17094
17095 // View can't have baseMipLevel >= image's mipLevels
17096 imgViewInfo.subresourceRange.baseMipLevel = 1;
17097 imgViewInfo.subresourceRange.levelCount = VK_REMAINING_MIP_LEVELS;
17098 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17099 "vkCreateImageView: pCreateInfo->subresourceRange.baseMipLevel (= 1) is greater or equal "
17100 "to the mip level count of the image (i.e. greater or equal to 1).");
17101 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
17102 m_errorMonitor->VerifyFound();
17103 imgViewInfo.subresourceRange.baseMipLevel = 0;
17104 imgViewInfo.subresourceRange.levelCount = 1;
17105
17106 // View can't have baseMipLevel >= image's mipLevels
17107 imgViewInfo.subresourceRange.baseMipLevel = 1;
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.baseMipLevel = 0;
17112
17113 // View's baseMipLevel + levelCount can't be > image's mipLevels
17114 imgViewInfo.subresourceRange.levelCount = 2;
17115 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
17116 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
17117 m_errorMonitor->VerifyFound();
17118 imgViewInfo.subresourceRange.levelCount = 1;
17119
17120 // View's layerCount can't be 0
17121 imgViewInfo.subresourceRange.layerCount = 0;
17122 m_errorMonitor->SetDesiredFailureMsg(
17123 VK_DEBUG_REPORT_ERROR_BIT_EXT,
17124 "if pCreateInfo->viewType is VK_IMAGE_TYPE_2D, pCreateInfo->subresourceRange.layerCount must be 1");
17125 // m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02931); // overlap with param_validation
17126 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
17127 m_errorMonitor->VerifyFound();
17128 imgViewInfo.subresourceRange.layerCount = 1;
17129
17130 // View can't have baseArrayLayer >= image's arraySize
17131 imgViewInfo.subresourceRange.baseArrayLayer = 1;
17132 imgViewInfo.subresourceRange.layerCount = VK_REMAINING_ARRAY_LAYERS;
17133 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17134 "vkCreateImageView: pCreateInfo->subresourceRange.baseArrayLayer (= 1) is greater or "
17135 "equal to the arrayLayers of the image when it was created (i.e. greater or equal to 1).");
17136 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
17137 m_errorMonitor->VerifyFound();
17138 imgViewInfo.subresourceRange.baseArrayLayer = 0;
17139 imgViewInfo.subresourceRange.layerCount = 1;
17140
17141 // View can't have baseArrayLayer >= image's arraySize
17142 imgViewInfo.subresourceRange.baseArrayLayer = 1;
17143 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02931);
17144 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
17145 m_errorMonitor->VerifyFound();
17146 imgViewInfo.subresourceRange.baseArrayLayer = 0;
17147
17148 // View's baseArrayLayer + layerCount can't be > image's arrayLayers
17149 imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D_ARRAY;
17150 imgViewInfo.subresourceRange.layerCount = 2;
17151 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02931);
17152 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
17153 m_errorMonitor->VerifyFound();
17154 imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
17155 imgViewInfo.subresourceRange.layerCount = 1;
17156
17157 // View's layerCount of 2D view has to be 1
17158 imgViewInfo.subresourceRange.layerCount = 2;
17159 m_errorMonitor->SetDesiredFailureMsg(
17160 VK_DEBUG_REPORT_ERROR_BIT_EXT,
17161 "if pCreateInfo->viewType is VK_IMAGE_TYPE_2D, pCreateInfo->subresourceRange.layerCount must be 1");
17162 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
17163 m_errorMonitor->VerifyFound();
17164 imgViewInfo.subresourceRange.layerCount = 1;
17165
17166 // TODO: should test maitenance1 3D -> 2D array view feature
17167}
17168
Dave Houlton75967fc2017-03-06 17:21:16 -070017169TEST_F(VkLayerTest, CompressedImageMipCopyTests) {
17170 TEST_DESCRIPTION("Image/Buffer copies for higher mip levels");
17171
Tony Barbour1fa09702017-03-16 12:09:08 -060017172 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton75967fc2017-03-06 17:21:16 -070017173
Jamie Madill35127872017-03-15 16:17:46 -040017174 VkPhysicalDeviceFeatures device_features = {};
Dave Houlton75967fc2017-03-06 17:21:16 -070017175 ASSERT_NO_FATAL_FAILURE(GetPhysicalDeviceFeatures(&device_features));
17176 VkFormat compressed_format = VK_FORMAT_UNDEFINED;
17177 if (device_features.textureCompressionBC) {
17178 compressed_format = VK_FORMAT_BC3_SRGB_BLOCK;
17179 } else if (device_features.textureCompressionETC2) {
17180 compressed_format = VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK;
17181 } else if (device_features.textureCompressionASTC_LDR) {
17182 compressed_format = VK_FORMAT_ASTC_4x4_UNORM_BLOCK;
17183 } else {
17184 printf(" No compressed formats supported - CompressedImageMipCopyTests skipped.\n");
17185 return;
17186 }
17187
17188 VkImageCreateInfo ci;
17189 ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17190 ci.pNext = NULL;
17191 ci.flags = 0;
17192 ci.imageType = VK_IMAGE_TYPE_2D;
17193 ci.format = compressed_format;
17194 ci.extent = {32, 32, 1};
17195 ci.mipLevels = 6;
17196 ci.arrayLayers = 1;
17197 ci.samples = VK_SAMPLE_COUNT_1_BIT;
17198 ci.tiling = VK_IMAGE_TILING_OPTIMAL;
17199 ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
17200 ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
17201 ci.queueFamilyIndexCount = 0;
17202 ci.pQueueFamilyIndices = NULL;
17203 ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
17204
17205 VkImageObj image(m_device);
17206 image.init(&ci);
17207 ASSERT_TRUE(image.initialized());
17208
17209 VkImageObj odd_image(m_device);
17210 ci.extent = {31, 32, 1}; // Mips are [31,32] [15,16] [7,8] [3,4], [1,2] [1,1]
17211 odd_image.init(&ci);
17212 ASSERT_TRUE(odd_image.initialized());
17213
17214 // Allocate buffers
17215 VkMemoryPropertyFlags reqs = 0;
17216 vk_testing::Buffer buffer_1024, buffer_64, buffer_16, buffer_8;
17217 buffer_1024.init_as_src_and_dst(*m_device, 1024, reqs);
17218 buffer_64.init_as_src_and_dst(*m_device, 64, reqs);
17219 buffer_16.init_as_src_and_dst(*m_device, 16, reqs);
17220 buffer_8.init_as_src_and_dst(*m_device, 8, reqs);
17221
17222 VkBufferImageCopy region = {};
17223 region.bufferRowLength = 0;
17224 region.bufferImageHeight = 0;
17225 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17226 region.imageSubresource.layerCount = 1;
17227 region.imageOffset = {0, 0, 0};
17228 region.bufferOffset = 0;
17229
17230 // start recording
17231 m_commandBuffer->BeginCommandBuffer();
17232
17233 // Mip level copies that work - 5 levels
17234 m_errorMonitor->ExpectSuccess();
17235
17236 // Mip 0 should fit in 1k buffer - 1k texels @ 1b each
17237 region.imageExtent = {32, 32, 1};
17238 region.imageSubresource.mipLevel = 0;
17239 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_1024.handle(), 1,
17240 &region);
17241 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_1024.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17242 &region);
17243
17244 // Mip 2 should fit in 64b buffer - 64 texels @ 1b each
17245 region.imageExtent = {8, 8, 1};
17246 region.imageSubresource.mipLevel = 2;
17247 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_64.handle(), 1,
17248 &region);
17249 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17250 &region);
17251
17252 // Mip 3 should fit in 16b buffer - 16 texels @ 1b each
17253 region.imageExtent = {4, 4, 1};
17254 region.imageSubresource.mipLevel = 3;
17255 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
17256 &region);
17257 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17258 &region);
17259
17260 // Mip 4&5 should fit in 16b buffer with no complaint - 4 & 1 texels @ 1b each
17261 region.imageExtent = {2, 2, 1};
17262 region.imageSubresource.mipLevel = 4;
17263 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
17264 &region);
17265 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17266 &region);
17267
17268 region.imageExtent = {1, 1, 1};
17269 region.imageSubresource.mipLevel = 5;
17270 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
17271 &region);
17272 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17273 &region);
17274 m_errorMonitor->VerifyNotFound();
17275
17276 // Buffer must accomodate a full compressed block, regardless of texel count
17277 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01246);
17278 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_8.handle(), 1,
17279 &region);
17280 m_errorMonitor->VerifyFound();
17281 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01227);
17282 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_8.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17283 &region);
17284 m_errorMonitor->VerifyFound();
17285
17286 // Copy width < compressed block size, but not the full mip width
17287 region.imageExtent = {1, 2, 1};
17288 region.imageSubresource.mipLevel = 4;
17289 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01275);
17290 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
17291 &region);
17292 m_errorMonitor->VerifyFound();
17293 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01275);
17294 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17295 &region);
17296 m_errorMonitor->VerifyFound();
17297
17298 // Copy height < compressed block size but not the full mip height
17299 region.imageExtent = {2, 1, 1};
17300 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01276);
17301 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
17302 &region);
17303 m_errorMonitor->VerifyFound();
17304 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01276);
17305 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17306 &region);
17307 m_errorMonitor->VerifyFound();
17308
17309 // Offsets must be multiple of compressed block size
17310 region.imageOffset = {1, 1, 0};
17311 region.imageExtent = {1, 1, 1};
17312 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01273);
17313 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
17314 &region);
17315 m_errorMonitor->VerifyFound();
17316 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01273);
17317 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17318 &region);
17319 m_errorMonitor->VerifyFound();
17320
17321 // Offset + extent width = mip width - should succeed
17322 region.imageOffset = {4, 4, 0};
17323 region.imageExtent = {3, 4, 1};
17324 region.imageSubresource.mipLevel = 2;
17325 m_errorMonitor->ExpectSuccess();
17326 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), odd_image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
17327 &region);
17328 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), odd_image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17329 &region);
17330 m_errorMonitor->VerifyNotFound();
17331
17332 // Offset + extent width > mip width, but still within the final compressed block - should succeed
17333 region.imageExtent = {4, 4, 1};
17334 m_errorMonitor->ExpectSuccess();
17335 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), odd_image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
17336 &region);
17337 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), odd_image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17338 &region);
17339 m_errorMonitor->VerifyNotFound();
17340
17341 // Offset + extent width < mip width and not a multiple of block width - should fail
17342 region.imageExtent = {3, 3, 1};
17343 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01276);
17344 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), odd_image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
17345 &region);
17346 m_errorMonitor->VerifyFound();
17347 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01276);
17348 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), odd_image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17349 &region);
17350 m_errorMonitor->VerifyFound();
17351}
17352
Dave Houlton59a20702017-02-02 17:26:23 -070017353TEST_F(VkLayerTest, ImageBufferCopyTests) {
17354 TEST_DESCRIPTION("Image to buffer and buffer to image tests");
17355
Tony Barbour1fa09702017-03-16 12:09:08 -060017356 ASSERT_NO_FATAL_FAILURE(Init());
Tony Barbourf887b162017-03-09 10:06:46 -070017357 VkFormatProperties format_props = m_device->format_properties(VK_FORMAT_D24_UNORM_S8_UINT);
17358 if (!(format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT)) {
17359 printf(" VK_FORMAT_D24_UNORM_S8_UINT not supported. Skipped.\n");
17360 return;
17361 }
Dave Houlton584d51e2017-02-16 12:52:54 -070017362
17363 // Bail if any dimension of transfer granularity is 0.
17364 auto index = m_device->graphics_queue_node_index_;
17365 auto queue_family_properties = m_device->phy().queue_properties();
17366 if ((queue_family_properties[index].minImageTransferGranularity.depth == 0) ||
17367 (queue_family_properties[index].minImageTransferGranularity.width == 0) ||
17368 (queue_family_properties[index].minImageTransferGranularity.height == 0)) {
17369 printf(" Subresource copies are disallowed when xfer granularity (x|y|z) is 0. Skipped.\n");
17370 return;
17371 }
17372
Dave Houlton59a20702017-02-02 17:26:23 -070017373 VkImageObj image_64k(m_device); // 128^2 texels, 64k
17374 VkImageObj image_16k(m_device); // 64^2 texels, 16k
17375 VkImageObj image_16k_depth(m_device); // 64^2 texels, depth, 16k
Dave Houltonf3229d52017-02-21 15:59:08 -070017376 VkImageObj ds_image_4D_1S(m_device); // 256^2 texels, 512kb (256k depth, 64k stencil, 192k pack)
17377 VkImageObj ds_image_3D_1S(m_device); // 256^2 texels, 256kb (192k depth, 64k stencil)
17378 VkImageObj ds_image_2D(m_device); // 256^2 texels, 128k (128k depth)
17379 VkImageObj ds_image_1S(m_device); // 256^2 texels, 64k (64k stencil)
17380
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017381 image_64k.Init(128, 128, 1, VK_FORMAT_R8G8B8A8_UINT,
Dave Houlton59a20702017-02-02 17:26:23 -070017382 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
17383 VK_IMAGE_TILING_OPTIMAL, 0);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017384 image_16k.Init(64, 64, 1, VK_FORMAT_R8G8B8A8_UINT,
Dave Houlton59a20702017-02-02 17:26:23 -070017385 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
17386 VK_IMAGE_TILING_OPTIMAL, 0);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017387 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 -070017388 VK_IMAGE_TILING_OPTIMAL, 0);
Dave Houlton59a20702017-02-02 17:26:23 -070017389 ASSERT_TRUE(image_64k.initialized());
17390 ASSERT_TRUE(image_16k.initialized());
17391 ASSERT_TRUE(image_16k_depth.initialized());
Dave Houlton59a20702017-02-02 17:26:23 -070017392
Dave Houltonf3229d52017-02-21 15:59:08 -070017393 // Verify all needed Depth/Stencil formats are supported
17394 bool missing_ds_support = false;
17395 VkFormatProperties props = {0, 0, 0};
17396 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D32_SFLOAT_S8_UINT, &props);
17397 missing_ds_support |= (props.bufferFeatures == 0 && props.linearTilingFeatures == 0 && props.optimalTilingFeatures == 0);
17398 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D24_UNORM_S8_UINT, &props);
17399 missing_ds_support |= (props.bufferFeatures == 0 && props.linearTilingFeatures == 0 && props.optimalTilingFeatures == 0);
17400 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D16_UNORM, &props);
17401 missing_ds_support |= (props.bufferFeatures == 0 && props.linearTilingFeatures == 0 && props.optimalTilingFeatures == 0);
17402 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_S8_UINT, &props);
17403 missing_ds_support |= (props.bufferFeatures == 0 && props.linearTilingFeatures == 0 && props.optimalTilingFeatures == 0);
17404
17405 if (!missing_ds_support) {
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017406 ds_image_4D_1S.Init(
17407 256, 256, 1, VK_FORMAT_D32_SFLOAT_S8_UINT,
Dave Houltonf3229d52017-02-21 15:59:08 -070017408 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
17409 VK_IMAGE_TILING_OPTIMAL, 0);
17410 ASSERT_TRUE(ds_image_4D_1S.initialized());
17411
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017412 ds_image_3D_1S.Init(
17413 256, 256, 1, VK_FORMAT_D24_UNORM_S8_UINT,
Dave Houltonf3229d52017-02-21 15:59:08 -070017414 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
17415 VK_IMAGE_TILING_OPTIMAL, 0);
17416 ASSERT_TRUE(ds_image_3D_1S.initialized());
17417
Dave Houlton11dcd5e2017-04-25 16:00:10 -060017418 ds_image_2D.Init(
17419 256, 256, 1, VK_FORMAT_D16_UNORM,
17420 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
17421 VK_IMAGE_TILING_OPTIMAL, 0);
Dave Houltonf3229d52017-02-21 15:59:08 -070017422 ASSERT_TRUE(ds_image_2D.initialized());
17423
Dave Houlton11dcd5e2017-04-25 16:00:10 -060017424 ds_image_1S.Init(
17425 256, 256, 1, VK_FORMAT_S8_UINT,
17426 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);
Dave Houltonf3229d52017-02-21 15:59:08 -070017428 ASSERT_TRUE(ds_image_1S.initialized());
17429 }
17430
17431 // Allocate buffers
17432 vk_testing::Buffer buffer_256k, buffer_128k, buffer_64k, buffer_16k;
Dave Houlton59a20702017-02-02 17:26:23 -070017433 VkMemoryPropertyFlags reqs = 0;
Dave Houltonf3229d52017-02-21 15:59:08 -070017434 buffer_256k.init_as_src_and_dst(*m_device, 262144, reqs); // 256k
17435 buffer_128k.init_as_src_and_dst(*m_device, 131072, reqs); // 128k
17436 buffer_64k.init_as_src_and_dst(*m_device, 65536, reqs); // 64k
17437 buffer_16k.init_as_src_and_dst(*m_device, 16384, reqs); // 16k
Dave Houlton59a20702017-02-02 17:26:23 -070017438
17439 VkBufferImageCopy region = {};
17440 region.bufferRowLength = 0;
17441 region.bufferImageHeight = 0;
17442 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17443 region.imageSubresource.layerCount = 1;
17444 region.imageOffset = {0, 0, 0};
17445 region.imageExtent = {64, 64, 1};
17446 region.bufferOffset = 0;
17447
17448 // attempt copies before putting command buffer in recording state
17449 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01240);
17450 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64k.handle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17451 &region);
17452 m_errorMonitor->VerifyFound();
17453
17454 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01258);
17455 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_64k.handle(), 1,
17456 &region);
17457 m_errorMonitor->VerifyFound();
17458
17459 // start recording
17460 m_commandBuffer->BeginCommandBuffer();
17461
17462 // successful copies
17463 m_errorMonitor->ExpectSuccess();
17464 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
17465 &region);
17466 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16k.handle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17467 &region);
17468 region.imageOffset.x = 16; // 16k copy, offset requires larger image
17469 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
17470 &region);
17471 region.imageExtent.height = 78; // > 16k copy requires larger buffer & image
17472 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64k.handle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17473 &region);
17474 region.imageOffset.x = 0;
17475 region.imageExtent.height = 64;
17476 region.bufferOffset = 256; // 16k copy with buffer offset, requires larger buffer
17477 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_64k.handle(), 1,
17478 &region);
17479 m_errorMonitor->VerifyNotFound();
17480
Dave Houlton9dae7ec2017-03-01 16:23:25 -070017481 // image/buffer too small (extent too large) on copy to image
Dave Houlton59a20702017-02-02 17:26:23 -070017482 region.imageExtent = {65, 64, 1};
17483 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01227); // buffer too small
17484 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16k.handle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17485 &region);
17486 m_errorMonitor->VerifyFound();
17487
17488 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01228); // image too small
17489 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64k.handle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17490 &region);
17491 m_errorMonitor->VerifyFound();
17492
17493 // image/buffer too small (offset) on copy to image
17494 region.imageExtent = {64, 64, 1};
17495 region.imageOffset = {0, 4, 0};
17496 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01227); // buffer too small
17497 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16k.handle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17498 &region);
17499 m_errorMonitor->VerifyFound();
17500
17501 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01228); // image too small
17502 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64k.handle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17503 &region);
17504 m_errorMonitor->VerifyFound();
17505
17506 // image/buffer too small on copy to buffer
17507 region.imageExtent = {64, 64, 1};
17508 region.imageOffset = {0, 0, 0};
Mark Lobodzinski80871462017-02-16 10:37:27 -070017509 region.bufferOffset = 4;
Dave Houlton59a20702017-02-02 17:26:23 -070017510 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01246); // buffer too small
17511 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
17512 &region);
17513 m_errorMonitor->VerifyFound();
17514
17515 region.imageExtent = {64, 65, 1};
17516 region.bufferOffset = 0;
17517 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01245); // image too small
17518 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_64k.handle(), 1,
17519 &region);
17520 m_errorMonitor->VerifyFound();
17521
17522 // buffer size ok but rowlength causes loose packing
17523 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01246);
17524 region.imageExtent = {64, 64, 1};
17525 region.bufferRowLength = 68;
17526 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
17527 &region);
17528 m_errorMonitor->VerifyFound();
17529
Dave Houlton9dae7ec2017-03-01 16:23:25 -070017530 // An extent with zero area should produce a warning, but no error
17531 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT | VK_DEBUG_REPORT_ERROR_BIT_EXT, "} has zero area");
17532 region.imageExtent.width = 0;
17533 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
17534 &region);
17535 m_errorMonitor->VerifyFound();
17536
Dave Houlton59a20702017-02-02 17:26:23 -070017537 // aspect bits
17538 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01280); // more than 1 aspect bit set
17539 region.imageExtent = {64, 64, 1};
17540 region.bufferRowLength = 0;
17541 region.bufferImageHeight = 0;
17542 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
17543 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_depth.handle(), VK_IMAGE_LAYOUT_GENERAL,
17544 buffer_16k.handle(), 1, &region);
17545 m_errorMonitor->VerifyFound();
17546
17547 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01279); // mis-matched aspect
17548 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
17549 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
17550 &region);
17551 m_errorMonitor->VerifyFound();
17552
17553 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01279); // different mis-matched aspect
17554 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17555 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_depth.handle(), VK_IMAGE_LAYOUT_GENERAL,
17556 buffer_16k.handle(), 1, &region);
17557 m_errorMonitor->VerifyFound();
17558
Dave Houltonf3229d52017-02-21 15:59:08 -070017559 // Test Depth/Stencil copies
17560 if (missing_ds_support) {
17561 printf(" Depth / Stencil formats unsupported - skipping D/S tests.\n");
17562 } else {
17563 VkBufferImageCopy ds_region = {};
17564 ds_region.bufferOffset = 0;
17565 ds_region.bufferRowLength = 0;
17566 ds_region.bufferImageHeight = 0;
17567 ds_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
17568 ds_region.imageSubresource.mipLevel = 0;
17569 ds_region.imageSubresource.baseArrayLayer = 0;
17570 ds_region.imageSubresource.layerCount = 1;
17571 ds_region.imageOffset = {0, 0, 0};
17572 ds_region.imageExtent = {256, 256, 1};
17573
17574 // Depth copies that should succeed
17575 m_errorMonitor->ExpectSuccess(); // Extract 4b depth per texel, pack into 256k buffer
17576 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_4D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
17577 buffer_256k.handle(), 1, &ds_region);
17578 m_errorMonitor->VerifyNotFound();
17579
17580 m_errorMonitor->ExpectSuccess(); // Extract 3b depth per texel, pack (loose) into 256k buffer
17581 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_3D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
17582 buffer_256k.handle(), 1, &ds_region);
17583 m_errorMonitor->VerifyNotFound();
17584
17585 m_errorMonitor->ExpectSuccess(); // Copy 2b depth per texel, into 128k buffer
17586 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_2D.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
17587 buffer_128k.handle(), 1, &ds_region);
17588 m_errorMonitor->VerifyNotFound();
17589
17590 // Depth copies that should fail
17591 ds_region.bufferOffset = 4;
17592 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17593 VALIDATION_ERROR_01246); // 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->VerifyFound();
17597
17598 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17599 VALIDATION_ERROR_01246); // Extract 3b depth per texel, pack (loose) into 256k buffer
17600 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_3D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
17601 buffer_256k.handle(), 1, &ds_region);
17602 m_errorMonitor->VerifyFound();
17603
17604 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17605 VALIDATION_ERROR_01246); // Copy 2b depth per texel, into 128k buffer
17606 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_2D.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
17607 buffer_128k.handle(), 1, &ds_region);
17608 m_errorMonitor->VerifyFound();
17609
17610 // Stencil copies that should succeed
17611 ds_region.bufferOffset = 0;
17612 ds_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT;
17613 m_errorMonitor->ExpectSuccess(); // Extract 1b stencil per texel, pack into 64k buffer
17614 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_4D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
17615 buffer_64k.handle(), 1, &ds_region);
17616 m_errorMonitor->VerifyNotFound();
17617
17618 m_errorMonitor->ExpectSuccess(); // Extract 1b stencil per texel, pack into 64k buffer
17619 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_3D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
17620 buffer_64k.handle(), 1, &ds_region);
17621 m_errorMonitor->VerifyNotFound();
17622
17623 m_errorMonitor->ExpectSuccess(); // Copy 1b depth per texel, into 64k buffer
17624 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
17625 buffer_64k.handle(), 1, &ds_region);
17626 m_errorMonitor->VerifyNotFound();
17627
17628 // Stencil copies that should fail
17629 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17630 VALIDATION_ERROR_01246); // Extract 1b stencil per texel, pack into 64k buffer
17631 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_4D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
17632 buffer_16k.handle(), 1, &ds_region);
17633 m_errorMonitor->VerifyFound();
17634
17635 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17636 VALIDATION_ERROR_01246); // Extract 1b stencil per texel, pack into 64k buffer
17637 ds_region.bufferRowLength = 260;
17638 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_3D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
17639 buffer_64k.handle(), 1, &ds_region);
17640 m_errorMonitor->VerifyFound();
17641
17642 ds_region.bufferRowLength = 0;
17643 ds_region.bufferOffset = 4;
17644 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17645 VALIDATION_ERROR_01246); // Copy 1b depth per texel, into 64k buffer
17646 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
17647 buffer_64k.handle(), 1, &ds_region);
17648 m_errorMonitor->VerifyFound();
17649 }
17650
Dave Houlton584d51e2017-02-16 12:52:54 -070017651 // Test compressed formats, if supported
Jamie Madill35127872017-03-15 16:17:46 -040017652 VkPhysicalDeviceFeatures device_features = {};
Dave Houlton584d51e2017-02-16 12:52:54 -070017653 ASSERT_NO_FATAL_FAILURE(GetPhysicalDeviceFeatures(&device_features));
Dave Houltonf3229d52017-02-21 15:59:08 -070017654 if (!(device_features.textureCompressionBC || device_features.textureCompressionETC2 ||
17655 device_features.textureCompressionASTC_LDR)) {
17656 printf(" No compressed formats supported - block compression tests skipped.\n");
17657 } else {
Dave Houlton67e9b532017-03-02 17:00:10 -070017658 VkImageObj image_16k_4x4comp(m_device); // 128^2 texels as 32^2 compressed (4x4) blocks, 16k
17659 VkImageObj image_NPOT_4x4comp(m_device); // 130^2 texels as 33^2 compressed (4x4) blocks
Dave Houlton584d51e2017-02-16 12:52:54 -070017660 if (device_features.textureCompressionBC) {
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017661 image_16k_4x4comp.Init(128, 128, 1, VK_FORMAT_BC3_SRGB_BLOCK, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_OPTIMAL,
17662 0);
17663 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 -070017664 0);
Dave Houlton584d51e2017-02-16 12:52:54 -070017665 } else if (device_features.textureCompressionETC2) {
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017666 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 -070017667 VK_IMAGE_TILING_OPTIMAL, 0);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017668 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 -070017669 VK_IMAGE_TILING_OPTIMAL, 0);
Dave Houlton584d51e2017-02-16 12:52:54 -070017670 } else {
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017671 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 -070017672 VK_IMAGE_TILING_OPTIMAL, 0);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017673 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 -070017674 VK_IMAGE_TILING_OPTIMAL, 0);
Dave Houlton584d51e2017-02-16 12:52:54 -070017675 }
17676 ASSERT_TRUE(image_16k_4x4comp.initialized());
Dave Houlton59a20702017-02-02 17:26:23 -070017677
Dave Houlton584d51e2017-02-16 12:52:54 -070017678 // Just fits
17679 m_errorMonitor->ExpectSuccess();
17680 region.imageExtent = {128, 128, 1};
17681 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
17682 buffer_16k.handle(), 1, &region);
17683 m_errorMonitor->VerifyNotFound();
Dave Houlton59a20702017-02-02 17:26:23 -070017684
Dave Houlton584d51e2017-02-16 12:52:54 -070017685 // with offset, too big for buffer
17686 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01246);
17687 region.bufferOffset = 16;
17688 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
17689 buffer_16k.handle(), 1, &region);
17690 m_errorMonitor->VerifyFound();
Dave Houlton67e9b532017-03-02 17:00:10 -070017691 region.bufferOffset = 0;
Dave Houlton59a20702017-02-02 17:26:23 -070017692
Dave Houlton67e9b532017-03-02 17:00:10 -070017693 // extents that are not a multiple of compressed block size
17694 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01275);
17695 region.imageExtent.width = 66;
17696 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_NPOT_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
17697 buffer_16k.handle(), 1, &region);
17698 m_errorMonitor->VerifyFound();
17699 region.imageExtent.width = 128;
17700
17701 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01276);
Dave Houlton9dae7ec2017-03-01 16:23:25 -070017702 region.imageExtent.height = 2;
Dave Houlton67e9b532017-03-02 17:00:10 -070017703 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_NPOT_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
17704 buffer_16k.handle(), 1, &region);
17705 m_errorMonitor->VerifyFound();
17706 region.imageExtent.height = 128;
17707
17708 // TODO: All available compressed formats are 2D, with block depth of 1. Unable to provoke VU_01277.
17709
17710 // non-multiple extents are allowed if at the far edge of a non-block-multiple image - these should pass
17711 m_errorMonitor->ExpectSuccess();
17712 region.imageExtent.width = 66;
17713 region.imageOffset.x = 64;
17714 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_NPOT_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
17715 buffer_16k.handle(), 1, &region);
17716 region.imageExtent.width = 16;
17717 region.imageOffset.x = 0;
17718 region.imageExtent.height = 2;
17719 region.imageOffset.y = 128;
17720 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_NPOT_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
Dave Houlton9dae7ec2017-03-01 16:23:25 -070017721 buffer_16k.handle(), 1, &region);
17722 m_errorMonitor->VerifyNotFound();
Dave Houlton67e9b532017-03-02 17:00:10 -070017723 region.imageOffset = {0, 0, 0};
Dave Houlton9dae7ec2017-03-01 16:23:25 -070017724
Dave Houlton584d51e2017-02-16 12:52:54 -070017725 // buffer offset must be a multiple of texel block size (16)
17726 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01274);
17727 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01263);
17728 region.imageExtent = {64, 64, 1};
17729 region.bufferOffset = 24;
17730 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
17731 buffer_16k.handle(), 1, &region);
17732 m_errorMonitor->VerifyFound();
Dave Houlton59a20702017-02-02 17:26:23 -070017733
Dave Houlton584d51e2017-02-16 12:52:54 -070017734 // rowlength not a multiple of block width (4)
17735 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01271);
17736 region.bufferOffset = 0;
17737 region.bufferRowLength = 130;
17738 region.bufferImageHeight = 0;
17739 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
17740 buffer_64k.handle(), 1, &region);
17741 m_errorMonitor->VerifyFound();
Dave Houlton59a20702017-02-02 17:26:23 -070017742
Dave Houlton584d51e2017-02-16 12:52:54 -070017743 // imageheight not a multiple of block height (4)
17744 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01272);
17745 region.bufferRowLength = 0;
17746 region.bufferImageHeight = 130;
17747 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
17748 buffer_64k.handle(), 1, &region);
17749 m_errorMonitor->VerifyFound();
Dave Houlton584d51e2017-02-16 12:52:54 -070017750 }
Dave Houlton59a20702017-02-02 17:26:23 -070017751}
17752
Tony Barbourd6673642016-05-05 14:46:39 -060017753TEST_F(VkLayerTest, MiscImageLayerTests) {
Mark Lobodzinskie6911292017-02-15 14:38:51 -070017754 TEST_DESCRIPTION("Image-related tests that don't belong elsewhare");
Tony Barbourd6673642016-05-05 14:46:39 -060017755
Tony Barbour1fa09702017-03-16 12:09:08 -060017756 ASSERT_NO_FATAL_FAILURE(Init());
Tony Barbourd6673642016-05-05 14:46:39 -060017757
Rene Lindsay135204f2016-12-22 17:11:09 -070017758 // TODO: Ideally we should check if a format is supported, before using it.
Tony Barbourd6673642016-05-05 14:46:39 -060017759 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017760 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 -070017761 VK_IMAGE_TILING_OPTIMAL, 0); // 64bpp
Tony Barbourd6673642016-05-05 14:46:39 -060017762 ASSERT_TRUE(image.initialized());
Tony Barbourd6673642016-05-05 14:46:39 -060017763 vk_testing::Buffer buffer;
17764 VkMemoryPropertyFlags reqs = 0;
Rene Lindsay135204f2016-12-22 17:11:09 -070017765 buffer.init_as_src(*m_device, 128 * 128 * 8, reqs);
Tony Barbourd6673642016-05-05 14:46:39 -060017766 VkBufferImageCopy region = {};
17767 region.bufferRowLength = 128;
17768 region.bufferImageHeight = 128;
17769 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17770 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
Mark Lobodzinski3702e932016-11-22 11:40:48 -070017771 region.imageSubresource.layerCount = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060017772 region.imageExtent.height = 4;
17773 region.imageExtent.width = 4;
17774 region.imageExtent.depth = 1;
Rene Lindsay135204f2016-12-22 17:11:09 -070017775
17776 VkImageObj image2(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017777 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 -070017778 VK_IMAGE_TILING_OPTIMAL, 0); // 16bpp
Rene Lindsay135204f2016-12-22 17:11:09 -070017779 ASSERT_TRUE(image2.initialized());
17780 vk_testing::Buffer buffer2;
17781 VkMemoryPropertyFlags reqs2 = 0;
17782 buffer2.init_as_src(*m_device, 128 * 128 * 2, reqs2);
17783 VkBufferImageCopy region2 = {};
17784 region2.bufferRowLength = 128;
17785 region2.bufferImageHeight = 128;
17786 region2.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17787 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
17788 region2.imageSubresource.layerCount = 1;
17789 region2.imageExtent.height = 4;
17790 region2.imageExtent.width = 4;
17791 region2.imageExtent.depth = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060017792 m_commandBuffer->BeginCommandBuffer();
Tony Barbourd6673642016-05-05 14:46:39 -060017793
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070017794 // Image must have offset.z of 0 and extent.depth of 1
17795 // Introduce failure by setting imageExtent.depth to 0
17796 region.imageExtent.depth = 0;
Dave Houlton59a20702017-02-02 17:26:23 -070017797 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01747);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070017798 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017799 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070017800 m_errorMonitor->VerifyFound();
17801
17802 region.imageExtent.depth = 1;
17803
17804 // Image must have offset.z of 0 and extent.depth of 1
17805 // Introduce failure by setting imageOffset.z to 4
Dave Houlton9dae7ec2017-03-01 16:23:25 -070017806 // Note: Also (unavoidably) triggers 'region exceeds image' #1228
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070017807 region.imageOffset.z = 4;
Dave Houlton59a20702017-02-02 17:26:23 -070017808 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01747);
Dave Houlton9dae7ec2017-03-01 16:23:25 -070017809 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01228);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070017810 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017811 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070017812 m_errorMonitor->VerifyFound();
17813
17814 region.imageOffset.z = 0;
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060017815 // BufferOffset must be a multiple of the calling command's VkImage parameter's texel size
17816 // Introduce failure by setting bufferOffset to 1 and 1/2 texels
Rene Lindsay135204f2016-12-22 17:11:09 -070017817 region.bufferOffset = 4;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070017818 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01263);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017819 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
17820 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060017821 m_errorMonitor->VerifyFound();
17822
17823 // BufferOffset must be a multiple of 4
17824 // Introduce failure by setting bufferOffset to a value not divisible by 4
Rene Lindsay135204f2016-12-22 17:11:09 -070017825 region2.bufferOffset = 6;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070017826 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01264);
Rene Lindsay135204f2016-12-22 17:11:09 -070017827 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer2.handle(), image2.handle(),
17828 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region2);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060017829 m_errorMonitor->VerifyFound();
17830
17831 // BufferRowLength must be 0, or greater than or equal to the width member of imageExtent
17832 region.bufferOffset = 0;
17833 region.imageExtent.height = 128;
17834 region.imageExtent.width = 128;
17835 // Introduce failure by setting bufferRowLength > 0 but less than width
17836 region.bufferRowLength = 64;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070017837 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01265);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017838 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
17839 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060017840 m_errorMonitor->VerifyFound();
17841
17842 // BufferImageHeight must be 0, or greater than or equal to the height member of imageExtent
17843 region.bufferRowLength = 128;
17844 // Introduce failure by setting bufferRowHeight > 0 but less than height
17845 region.bufferImageHeight = 64;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070017846 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01266);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017847 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
17848 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060017849 m_errorMonitor->VerifyFound();
17850
17851 region.bufferImageHeight = 128;
Tony Barbourd6673642016-05-05 14:46:39 -060017852 VkImageObj intImage1(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017853 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 -070017854 VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbourd6673642016-05-05 14:46:39 -060017855 VkImageObj intImage2(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017856 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 -070017857 VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbourd6673642016-05-05 14:46:39 -060017858 VkImageBlit blitRegion = {};
17859 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17860 blitRegion.srcSubresource.baseArrayLayer = 0;
17861 blitRegion.srcSubresource.layerCount = 1;
17862 blitRegion.srcSubresource.mipLevel = 0;
17863 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17864 blitRegion.dstSubresource.baseArrayLayer = 0;
17865 blitRegion.dstSubresource.layerCount = 1;
17866 blitRegion.dstSubresource.mipLevel = 0;
17867
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060017868 // Look for NULL-blit warning
Jeremy Hayesf8e749f2017-03-15 09:40:27 -060017869 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
17870 "vkCmdBlitImage: pRegions[0].srcOffsets specify a zero-volume area.");
17871 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
17872 "vkCmdBlitImage: pRegions[0].dstOffsets specify a zero-volume area.");
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017873 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.Layout(), intImage2.handle(),
17874 intImage2.Layout(), 1, &blitRegion, VK_FILTER_LINEAR);
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060017875 m_errorMonitor->VerifyFound();
17876
Petr Kraus4d718682017-05-18 03:38:41 +020017877 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02931);
Tony Barbourd6673642016-05-05 14:46:39 -060017878 VkImageMemoryBarrier img_barrier;
17879 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
17880 img_barrier.pNext = NULL;
17881 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
17882 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
17883 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
17884 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
17885 img_barrier.image = image.handle();
17886 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
17887 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
17888 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17889 img_barrier.subresourceRange.baseArrayLayer = 0;
17890 img_barrier.subresourceRange.baseMipLevel = 0;
Tony Barbourd6673642016-05-05 14:46:39 -060017891 img_barrier.subresourceRange.layerCount = 0;
17892 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017893 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
17894 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbourd6673642016-05-05 14:46:39 -060017895 m_errorMonitor->VerifyFound();
17896 img_barrier.subresourceRange.layerCount = 1;
17897}
17898
17899TEST_F(VkLayerTest, ImageFormatLimits) {
Tony Barbourd6673642016-05-05 14:46:39 -060017900 TEST_DESCRIPTION("Exceed the limits of image format ");
17901
Tony Barbour1fa09702017-03-16 12:09:08 -060017902 ASSERT_NO_FATAL_FAILURE(Init());
Jeremy Hayesbb63cc12017-03-20 15:33:01 -060017903
17904 VkFormat const format = VK_FORMAT_B8G8R8A8_UNORM;
17905 {
17906 VkFormatProperties properties;
17907 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), format, &properties);
17908 if (properties.linearTilingFeatures == 0) {
17909 printf(" Image format not supported; skipped.\n");
17910 return;
17911 }
17912 }
17913
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017914 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Tony Barbourd6673642016-05-05 14:46:39 -060017915 VkImageCreateInfo image_create_info = {};
17916 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17917 image_create_info.pNext = NULL;
17918 image_create_info.imageType = VK_IMAGE_TYPE_2D;
Jeremy Hayesbb63cc12017-03-20 15:33:01 -060017919 image_create_info.format = format;
Tony Barbourd6673642016-05-05 14:46:39 -060017920 image_create_info.extent.width = 32;
17921 image_create_info.extent.height = 32;
17922 image_create_info.extent.depth = 1;
17923 image_create_info.mipLevels = 1;
17924 image_create_info.arrayLayers = 1;
17925 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
17926 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
17927 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
17928 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
17929 image_create_info.flags = 0;
17930
17931 VkImage nullImg;
17932 VkImageFormatProperties imgFmtProps;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017933 vkGetPhysicalDeviceImageFormatProperties(gpu(), image_create_info.format, image_create_info.imageType, image_create_info.tiling,
17934 image_create_info.usage, image_create_info.flags, &imgFmtProps);
Rene Lindsayef5bc012017-01-06 15:38:00 -070017935 image_create_info.extent.width = imgFmtProps.maxExtent.width + 1;
Tony Barbourd6673642016-05-05 14:46:39 -060017936 // Expect INVALID_FORMAT_LIMITS_VIOLATION
17937 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
17938 m_errorMonitor->VerifyFound();
Rene Lindsayef5bc012017-01-06 15:38:00 -070017939 image_create_info.extent.width = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060017940
Tony Barbour0907e362017-03-09 15:05:30 -070017941 uint32_t maxDim =
17942 std::max(std::max(image_create_info.extent.width, image_create_info.extent.height), image_create_info.extent.depth);
17943 // If max mip levels exceeds image extents, skip the max mip levels test
17944 if ((imgFmtProps.maxMipLevels + 1) <= (floor(log2(maxDim)) + 1)) {
17945 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
17946 image_create_info.mipLevels = imgFmtProps.maxMipLevels + 1;
17947 // Expect INVALID_FORMAT_LIMITS_VIOLATION
17948 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
17949 m_errorMonitor->VerifyFound();
17950 image_create_info.mipLevels = 1;
17951 }
Tony Barbourd6673642016-05-05 14:46:39 -060017952
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017953 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060017954 image_create_info.arrayLayers = imgFmtProps.maxArrayLayers + 1;
17955 // Expect INVALID_FORMAT_LIMITS_VIOLATION
17956 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
17957 m_errorMonitor->VerifyFound();
17958 image_create_info.arrayLayers = 1;
17959
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017960 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is not supported by format");
Tony Barbourd6673642016-05-05 14:46:39 -060017961 int samples = imgFmtProps.sampleCounts >> 1;
17962 image_create_info.samples = (VkSampleCountFlagBits)samples;
17963 // Expect INVALID_FORMAT_LIMITS_VIOLATION
17964 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
17965 m_errorMonitor->VerifyFound();
17966 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
17967
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017968 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17969 "pCreateInfo->initialLayout, must be "
17970 "VK_IMAGE_LAYOUT_UNDEFINED or "
17971 "VK_IMAGE_LAYOUT_PREINITIALIZED");
Tony Barbourd6673642016-05-05 14:46:39 -060017972 image_create_info.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
17973 // Expect INVALID_LAYOUT
17974 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
17975 m_errorMonitor->VerifyFound();
17976 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
17977}
17978
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017979TEST_F(VkLayerTest, CopyImageSrcSizeExceeded) {
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017980 // Image copy with source region specified greater than src image size
Tony Barbour1fa09702017-03-16 12:09:08 -060017981 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017982
Dave Houltonfc1a4052017-04-27 14:32:45 -060017983 // Create images with full mip chain
17984 VkImageCreateInfo ci;
17985 ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17986 ci.pNext = NULL;
17987 ci.flags = 0;
17988 ci.imageType = VK_IMAGE_TYPE_3D;
17989 ci.format = VK_FORMAT_R8G8B8A8_UNORM;
17990 ci.extent = {32, 32, 8};
17991 ci.mipLevels = 6;
17992 ci.arrayLayers = 1;
17993 ci.samples = VK_SAMPLE_COUNT_1_BIT;
17994 ci.tiling = VK_IMAGE_TILING_OPTIMAL;
17995 ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
17996 ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
17997 ci.queueFamilyIndexCount = 0;
17998 ci.pQueueFamilyIndices = NULL;
17999 ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
18000
Mark Lobodzinskicea14992016-10-14 10:59:42 -060018001 VkImageObj src_image(m_device);
Dave Houltonfc1a4052017-04-27 14:32:45 -060018002 src_image.init(&ci);
18003 ASSERT_TRUE(src_image.initialized());
18004
18005 // Dest image with one more mip level
18006 ci.extent = {64, 64, 16};
18007 ci.mipLevels = 7;
18008 ci.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskicea14992016-10-14 10:59:42 -060018009 VkImageObj dst_image(m_device);
Dave Houltonfc1a4052017-04-27 14:32:45 -060018010 dst_image.init(&ci);
18011 ASSERT_TRUE(dst_image.initialized());
Mark Lobodzinskicea14992016-10-14 10:59:42 -060018012
Tony Barbour552f6c02016-12-21 14:34:07 -070018013 m_commandBuffer->BeginCommandBuffer();
Dave Houltonfc1a4052017-04-27 14:32:45 -060018014
Mark Lobodzinskicea14992016-10-14 10:59:42 -060018015 VkImageCopy copy_region;
Dave Houltonfc1a4052017-04-27 14:32:45 -060018016 copy_region.extent = {32, 32, 8};
Mark Lobodzinskicea14992016-10-14 10:59:42 -060018017 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskicea14992016-10-14 10:59:42 -060018018 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Dave Houltoncee81d02017-05-02 11:00:10 -060018019 copy_region.srcSubresource.mipLevel = 0;
18020 copy_region.dstSubresource.mipLevel = 0;
Dave Houltonfc1a4052017-04-27 14:32:45 -060018021 copy_region.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinskicea14992016-10-14 10:59:42 -060018022 copy_region.dstSubresource.baseArrayLayer = 0;
Dave Houltonfc1a4052017-04-27 14:32:45 -060018023 copy_region.srcSubresource.layerCount = 1;
18024 copy_region.dstSubresource.layerCount = 1;
18025 copy_region.srcOffset = {0, 0, 0};
18026 copy_region.dstOffset = {0, 0, 0};
18027
18028 m_errorMonitor->ExpectSuccess();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060018029 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
18030 &copy_region);
Dave Houltonfc1a4052017-04-27 14:32:45 -060018031 m_errorMonitor->VerifyNotFound();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060018032
Dave Houltonfc1a4052017-04-27 14:32:45 -060018033 // Source exceeded in x-dim, VU 01202
18034 copy_region.srcOffset.x = 4;
18035 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01175); // General "contained within" VU
18036 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01202);
18037 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
18038 &copy_region);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060018039 m_errorMonitor->VerifyFound();
Dave Houltonfc1a4052017-04-27 14:32:45 -060018040
18041 // Source exceeded in y-dim, VU 01203
18042 copy_region.srcOffset.x = 0;
18043 copy_region.extent.height = 48;
18044 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01175);
18045 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01203);
18046 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
18047 &copy_region);
18048 m_errorMonitor->VerifyFound();
18049
18050 // Source exceeded in z-dim, VU 01204
18051 copy_region.extent = {4, 4, 4};
18052 copy_region.srcSubresource.mipLevel = 2;
18053 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01175);
18054 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01204);
18055 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
18056 &copy_region);
18057 m_errorMonitor->VerifyFound();
18058
18059 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060018060}
18061
18062TEST_F(VkLayerTest, CopyImageDstSizeExceeded) {
Mark Lobodzinskicea14992016-10-14 10:59:42 -060018063 // Image copy with dest region specified greater than dest image size
Tony Barbour1fa09702017-03-16 12:09:08 -060018064 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskicea14992016-10-14 10:59:42 -060018065
Dave Houltonfc1a4052017-04-27 14:32:45 -060018066 // Create images with full mip chain
18067 VkImageCreateInfo ci;
18068 ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
18069 ci.pNext = NULL;
18070 ci.flags = 0;
18071 ci.imageType = VK_IMAGE_TYPE_3D;
18072 ci.format = VK_FORMAT_R8G8B8A8_UNORM;
18073 ci.extent = {32, 32, 8};
18074 ci.mipLevels = 6;
18075 ci.arrayLayers = 1;
18076 ci.samples = VK_SAMPLE_COUNT_1_BIT;
18077 ci.tiling = VK_IMAGE_TILING_OPTIMAL;
18078 ci.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
18079 ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
18080 ci.queueFamilyIndexCount = 0;
18081 ci.pQueueFamilyIndices = NULL;
18082 ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
18083
Mark Lobodzinskicea14992016-10-14 10:59:42 -060018084 VkImageObj dst_image(m_device);
Dave Houltonfc1a4052017-04-27 14:32:45 -060018085 dst_image.init(&ci);
18086 ASSERT_TRUE(dst_image.initialized());
18087
18088 // Src image with one more mip level
18089 ci.extent = {64, 64, 16};
18090 ci.mipLevels = 7;
18091 ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
18092 VkImageObj src_image(m_device);
18093 src_image.init(&ci);
18094 ASSERT_TRUE(src_image.initialized());
Mark Lobodzinskicea14992016-10-14 10:59:42 -060018095
Tony Barbour552f6c02016-12-21 14:34:07 -070018096 m_commandBuffer->BeginCommandBuffer();
Dave Houltonfc1a4052017-04-27 14:32:45 -060018097
Mark Lobodzinskicea14992016-10-14 10:59:42 -060018098 VkImageCopy copy_region;
Dave Houltonfc1a4052017-04-27 14:32:45 -060018099 copy_region.extent = {32, 32, 8};
Mark Lobodzinskicea14992016-10-14 10:59:42 -060018100 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskicea14992016-10-14 10:59:42 -060018101 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Dave Houltoncee81d02017-05-02 11:00:10 -060018102 copy_region.srcSubresource.mipLevel = 0;
18103 copy_region.dstSubresource.mipLevel = 0;
Dave Houltonfc1a4052017-04-27 14:32:45 -060018104 copy_region.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinskicea14992016-10-14 10:59:42 -060018105 copy_region.dstSubresource.baseArrayLayer = 0;
Dave Houltonfc1a4052017-04-27 14:32:45 -060018106 copy_region.srcSubresource.layerCount = 1;
18107 copy_region.dstSubresource.layerCount = 1;
18108 copy_region.srcOffset = {0, 0, 0};
18109 copy_region.dstOffset = {0, 0, 0};
18110
18111 m_errorMonitor->ExpectSuccess();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060018112 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
18113 &copy_region);
Dave Houltonfc1a4052017-04-27 14:32:45 -060018114 m_errorMonitor->VerifyNotFound();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060018115
Dave Houltonfc1a4052017-04-27 14:32:45 -060018116 // Dest exceeded in x-dim, VU 01205
18117 copy_region.dstOffset.x = 4;
18118 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01176); // General "contained within" VU
18119 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01205);
18120 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
18121 &copy_region);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060018122 m_errorMonitor->VerifyFound();
Dave Houltonfc1a4052017-04-27 14:32:45 -060018123
18124 // Dest exceeded in y-dim, VU 01206
18125 copy_region.dstOffset.x = 0;
18126 copy_region.extent.height = 48;
18127 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01176);
18128 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01206);
18129 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
18130 &copy_region);
18131 m_errorMonitor->VerifyFound();
18132
18133 // Dest exceeded in z-dim, VU 01207
18134 copy_region.extent = {4, 4, 4};
18135 copy_region.dstSubresource.mipLevel = 2;
18136 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01176);
18137 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01207);
18138 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
18139 &copy_region);
18140 m_errorMonitor->VerifyFound();
18141
18142 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060018143}
18144
Karl Schultz6addd812016-02-02 17:17:23 -070018145TEST_F(VkLayerTest, CopyImageFormatSizeMismatch) {
Karl Schultzbdb75952016-04-19 11:36:49 -060018146 VkResult err;
18147 bool pass;
18148
18149 // Create color images with different format sizes and try to copy between them
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070018150 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01184);
Karl Schultzbdb75952016-04-19 11:36:49 -060018151
Tony Barbour1fa09702017-03-16 12:09:08 -060018152 ASSERT_NO_FATAL_FAILURE(Init());
Karl Schultzbdb75952016-04-19 11:36:49 -060018153
18154 // Create two images of different types and try to copy between them
18155 VkImage srcImage;
18156 VkImage dstImage;
18157 VkDeviceMemory srcMem;
18158 VkDeviceMemory destMem;
18159 VkMemoryRequirements memReqs;
18160
18161 VkImageCreateInfo image_create_info = {};
18162 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
18163 image_create_info.pNext = NULL;
18164 image_create_info.imageType = VK_IMAGE_TYPE_2D;
18165 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
18166 image_create_info.extent.width = 32;
18167 image_create_info.extent.height = 32;
18168 image_create_info.extent.depth = 1;
18169 image_create_info.mipLevels = 1;
18170 image_create_info.arrayLayers = 1;
18171 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
18172 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
18173 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
18174 image_create_info.flags = 0;
18175
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018176 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060018177 ASSERT_VK_SUCCESS(err);
18178
18179 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
18180 // Introduce failure by creating second image with a different-sized format.
18181 image_create_info.format = VK_FORMAT_R5G5B5A1_UNORM_PACK16;
Tobin Ehlis6d4d1d52017-04-05 12:06:10 -060018182 VkFormatProperties properties;
18183 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), image_create_info.format, &properties);
18184 if (properties.optimalTilingFeatures == 0) {
18185 printf(" Image format not supported; skipped.\n");
18186 return;
18187 }
Karl Schultzbdb75952016-04-19 11:36:49 -060018188
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018189 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060018190 ASSERT_VK_SUCCESS(err);
18191
18192 // Allocate memory
18193 VkMemoryAllocateInfo memAlloc = {};
18194 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18195 memAlloc.pNext = NULL;
18196 memAlloc.allocationSize = 0;
18197 memAlloc.memoryTypeIndex = 0;
18198
18199 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
18200 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018201 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060018202 ASSERT_TRUE(pass);
18203 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
18204 ASSERT_VK_SUCCESS(err);
18205
18206 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
18207 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018208 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060018209 ASSERT_TRUE(pass);
18210 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
18211 ASSERT_VK_SUCCESS(err);
18212
18213 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
18214 ASSERT_VK_SUCCESS(err);
18215 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
18216 ASSERT_VK_SUCCESS(err);
18217
Tony Barbour552f6c02016-12-21 14:34:07 -070018218 m_commandBuffer->BeginCommandBuffer();
Karl Schultzbdb75952016-04-19 11:36:49 -060018219 VkImageCopy copyRegion;
18220 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
18221 copyRegion.srcSubresource.mipLevel = 0;
18222 copyRegion.srcSubresource.baseArrayLayer = 0;
18223 copyRegion.srcSubresource.layerCount = 0;
18224 copyRegion.srcOffset.x = 0;
18225 copyRegion.srcOffset.y = 0;
18226 copyRegion.srcOffset.z = 0;
18227 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
18228 copyRegion.dstSubresource.mipLevel = 0;
18229 copyRegion.dstSubresource.baseArrayLayer = 0;
18230 copyRegion.dstSubresource.layerCount = 0;
18231 copyRegion.dstOffset.x = 0;
18232 copyRegion.dstOffset.y = 0;
18233 copyRegion.dstOffset.z = 0;
18234 copyRegion.extent.width = 1;
18235 copyRegion.extent.height = 1;
18236 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018237 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070018238 m_commandBuffer->EndCommandBuffer();
Karl Schultzbdb75952016-04-19 11:36:49 -060018239
18240 m_errorMonitor->VerifyFound();
18241
18242 vkDestroyImage(m_device->device(), srcImage, NULL);
18243 vkDestroyImage(m_device->device(), dstImage, NULL);
18244 vkFreeMemory(m_device->device(), srcMem, NULL);
18245 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060018246}
18247
Karl Schultz6addd812016-02-02 17:17:23 -070018248TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch) {
18249 VkResult err;
18250 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060018251
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018252 // Create a depth image and a depth/stencil image and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018253 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
18254 "vkCmdCopyImage called with unmatched source and dest image depth");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060018255
Tony Barbour1fa09702017-03-16 12:09:08 -060018256 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -060018257 auto depth_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbourf887b162017-03-09 10:06:46 -070018258 if (!depth_format) {
18259 return;
18260 }
Mike Stroyana3082432015-09-25 13:39:21 -060018261
18262 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070018263 VkImage srcImage;
18264 VkImage dstImage;
18265 VkDeviceMemory srcMem;
18266 VkDeviceMemory destMem;
18267 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060018268
18269 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070018270 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
18271 image_create_info.pNext = NULL;
18272 image_create_info.imageType = VK_IMAGE_TYPE_2D;
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018273 image_create_info.format = VK_FORMAT_D32_SFLOAT;
Karl Schultz6addd812016-02-02 17:17:23 -070018274 image_create_info.extent.width = 32;
18275 image_create_info.extent.height = 32;
18276 image_create_info.extent.depth = 1;
18277 image_create_info.mipLevels = 1;
18278 image_create_info.arrayLayers = 1;
18279 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Youngad61f4b2017-04-07 08:59:56 -060018280 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Karl Schultz6addd812016-02-02 17:17:23 -070018281 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
18282 image_create_info.flags = 0;
Tobin Ehlis6d4d1d52017-04-05 12:06:10 -060018283 VkFormatProperties properties;
18284 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), image_create_info.format, &properties);
18285 if (properties.optimalTilingFeatures == 0) {
18286 printf(" Image format not supported; skipped.\n");
18287 return;
18288 }
Mike Stroyana3082432015-09-25 13:39:21 -060018289
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018290 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060018291 ASSERT_VK_SUCCESS(err);
18292
Karl Schultzbdb75952016-04-19 11:36:49 -060018293 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
18294
Mark Lobodzinskidb117632016-03-31 10:45:56 -060018295 // Introduce failure by creating second image with a depth/stencil format
Karl Schultz6addd812016-02-02 17:17:23 -070018296 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Tony Barbourf887b162017-03-09 10:06:46 -070018297 image_create_info.format = depth_format;
Mark Lobodzinski867787a2016-10-14 11:49:55 -060018298 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060018299
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018300 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060018301 ASSERT_VK_SUCCESS(err);
18302
18303 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018304 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070018305 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18306 memAlloc.pNext = NULL;
18307 memAlloc.allocationSize = 0;
18308 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018309
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060018310 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060018311 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018312 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060018313 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018314 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060018315 ASSERT_VK_SUCCESS(err);
18316
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018317 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060018318 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018319 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060018320 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018321 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060018322 ASSERT_VK_SUCCESS(err);
18323
18324 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
18325 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018326 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060018327 ASSERT_VK_SUCCESS(err);
18328
Tony Barbour552f6c02016-12-21 14:34:07 -070018329 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060018330 VkImageCopy copyRegion;
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018331 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060018332 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060018333 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018334 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018335 copyRegion.srcOffset.x = 0;
18336 copyRegion.srcOffset.y = 0;
18337 copyRegion.srcOffset.z = 0;
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018338 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018339 copyRegion.dstSubresource.mipLevel = 0;
18340 copyRegion.dstSubresource.baseArrayLayer = 0;
18341 copyRegion.dstSubresource.layerCount = 0;
18342 copyRegion.dstOffset.x = 0;
18343 copyRegion.dstOffset.y = 0;
18344 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018345 copyRegion.extent.width = 1;
18346 copyRegion.extent.height = 1;
18347 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018348 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070018349 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060018350
Chris Forbes8f36a8a2016-04-07 13:21:07 +120018351 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060018352
Chia-I Wuf7458c52015-10-26 21:10:41 +080018353 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018354 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080018355 vkFreeMemory(m_device->device(), srcMem, NULL);
18356 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060018357}
18358
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018359TEST_F(VkLayerTest, CopyImageSampleCountMismatch) {
18360 TEST_DESCRIPTION("Image copies with sample count mis-matches");
Dave Houlton33c22b72017-02-28 13:16:02 -070018361
Mark Lobodzinski77e590c2017-03-17 12:05:16 -060018362 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton33c22b72017-02-28 13:16:02 -070018363
18364 VkImageFormatProperties image_format_properties;
18365 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
18366 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT, 0,
18367 &image_format_properties);
18368
18369 if ((0 == (VK_SAMPLE_COUNT_2_BIT & image_format_properties.sampleCounts)) ||
18370 (0 == (VK_SAMPLE_COUNT_4_BIT & image_format_properties.sampleCounts))) {
18371 printf(" Image multi-sample support not found; skipped.\n");
18372 return;
18373 }
18374
18375 VkImageCreateInfo ci;
18376 ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
18377 ci.pNext = NULL;
18378 ci.flags = 0;
18379 ci.imageType = VK_IMAGE_TYPE_2D;
18380 ci.format = VK_FORMAT_R8G8B8A8_UNORM;
18381 ci.extent = {128, 128, 1};
18382 ci.mipLevels = 1;
18383 ci.arrayLayers = 1;
18384 ci.samples = VK_SAMPLE_COUNT_1_BIT;
18385 ci.tiling = VK_IMAGE_TILING_OPTIMAL;
18386 ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
18387 ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
18388 ci.queueFamilyIndexCount = 0;
18389 ci.pQueueFamilyIndices = NULL;
18390 ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
18391
18392 VkImageObj image1(m_device);
18393 image1.init(&ci);
18394 ASSERT_TRUE(image1.initialized());
18395
18396 ci.samples = VK_SAMPLE_COUNT_2_BIT;
18397 VkImageObj image2(m_device);
18398 image2.init(&ci);
18399 ASSERT_TRUE(image2.initialized());
18400
18401 ci.samples = VK_SAMPLE_COUNT_4_BIT;
18402 VkImageObj image4(m_device);
18403 image4.init(&ci);
18404 ASSERT_TRUE(image4.initialized());
18405
18406 m_commandBuffer->BeginCommandBuffer();
18407
18408 VkImageCopy copyRegion;
18409 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
18410 copyRegion.srcSubresource.mipLevel = 0;
18411 copyRegion.srcSubresource.baseArrayLayer = 0;
18412 copyRegion.srcSubresource.layerCount = 1;
18413 copyRegion.srcOffset = {0, 0, 0};
18414 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
18415 copyRegion.dstSubresource.mipLevel = 0;
18416 copyRegion.dstSubresource.baseArrayLayer = 0;
18417 copyRegion.dstSubresource.layerCount = 1;
18418 copyRegion.dstOffset = {0, 0, 0};
18419 copyRegion.extent = {128, 128, 1};
18420
18421 // Copy a single sample image to/from a multi-sample image
18422 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01185);
18423 vkCmdCopyImage(m_commandBuffer->GetBufferHandle(), image1.handle(), VK_IMAGE_LAYOUT_GENERAL, image4.handle(),
18424 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
18425 m_errorMonitor->VerifyFound();
18426
18427 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01185);
18428 vkCmdCopyImage(m_commandBuffer->GetBufferHandle(), image2.handle(), VK_IMAGE_LAYOUT_GENERAL, image1.handle(),
18429 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
18430 m_errorMonitor->VerifyFound();
18431
18432 // Copy between multi-sample images with different sample counts
18433 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01185);
18434 vkCmdCopyImage(m_commandBuffer->GetBufferHandle(), image2.handle(), VK_IMAGE_LAYOUT_GENERAL, image4.handle(),
18435 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
18436 m_errorMonitor->VerifyFound();
18437
18438 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01185);
18439 vkCmdCopyImage(m_commandBuffer->GetBufferHandle(), image4.handle(), VK_IMAGE_LAYOUT_GENERAL, image2.handle(),
18440 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
18441 m_errorMonitor->VerifyFound();
18442
18443 m_commandBuffer->EndCommandBuffer();
18444}
18445
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018446TEST_F(VkLayerTest, CopyImageAspectMismatch) {
18447 TEST_DESCRIPTION("Image copies with aspect mask errors");
Mark Lobodzinski77e590c2017-03-17 12:05:16 -060018448 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -060018449 auto ds_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbour9357d542017-03-24 15:42:21 -060018450 if (!ds_format) {
18451 return;
18452 }
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018453
Tobin Ehlis6d4d1d52017-04-05 12:06:10 -060018454 VkFormatProperties properties;
18455 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D32_SFLOAT, &properties);
18456 if (properties.optimalTilingFeatures == 0) {
18457 printf(" Image format VK_FORMAT_D32_SFLOAT not supported; skipped.\n");
18458 return;
18459 }
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018460 VkImageObj color_image(m_device), ds_image(m_device), depth_image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060018461 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 -060018462 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 -060018463 VK_IMAGE_TILING_OPTIMAL, 0);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060018464 ds_image.Init(128, 128, 1, ds_format, VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
18465 VK_IMAGE_TILING_OPTIMAL, 0);
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018466 ASSERT_TRUE(color_image.initialized());
18467 ASSERT_TRUE(depth_image.initialized());
18468 ASSERT_TRUE(ds_image.initialized());
18469
18470 VkImageCopy copyRegion;
18471 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
18472 copyRegion.srcSubresource.mipLevel = 0;
18473 copyRegion.srcSubresource.baseArrayLayer = 0;
18474 copyRegion.srcSubresource.layerCount = 1;
18475 copyRegion.srcOffset = {0, 0, 0};
18476 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
18477 copyRegion.dstSubresource.mipLevel = 0;
18478 copyRegion.dstSubresource.baseArrayLayer = 0;
18479 copyRegion.dstSubresource.layerCount = 1;
18480 copyRegion.dstOffset = {64, 0, 0};
18481 copyRegion.extent = {64, 128, 1};
18482
18483 // Submitting command before command buffer is in recording state
Dave Houlton3c9fca72017-03-27 17:25:54 -060018484 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
18485 "You must call vkBeginCommandBuffer"); // VALIDATION_ERROR_01192);
18486 vkCmdCopyImage(m_commandBuffer->GetBufferHandle(), depth_image.handle(), VK_IMAGE_LAYOUT_GENERAL, depth_image.handle(),
18487 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018488 m_errorMonitor->VerifyFound();
18489
18490 m_commandBuffer->BeginCommandBuffer();
18491
18492 // Src and dest aspect masks don't match
18493 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT;
18494 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01197);
Dave Houlton3c9fca72017-03-27 17:25:54 -060018495 vkCmdCopyImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, ds_image.handle(),
18496 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018497 m_errorMonitor->VerifyFound();
18498 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
18499
18500 // Illegal combinations of aspect bits - VU 01221
Dave Houlton3c9fca72017-03-27 17:25:54 -060018501 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT; // color must be alone
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018502 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT;
18503 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01221);
18504 // These aspect/format mismatches are redundant but unavoidable here
18505 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01200);
18506 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01201);
Dave Houlton3c9fca72017-03-27 17:25:54 -060018507 vkCmdCopyImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_GENERAL, color_image.handle(),
18508 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018509 m_errorMonitor->VerifyFound();
18510 // Metadata aspect is illegal - VU 01222
18511 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
18512 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
18513 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01222);
18514 // These aspect/format mismatches are redundant but unavoidable here
Dave Houlton3c9fca72017-03-27 17:25:54 -060018515 vkCmdCopyImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_GENERAL, color_image.handle(),
18516 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018517 m_errorMonitor->VerifyFound();
18518
18519 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
18520 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
18521
18522 // Aspect mask doesn't match source image format - VU 01200
18523 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01200);
18524 // Again redundant but unavoidable when provoking vu01200 w/o vu01201
18525 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "unmatched source and dest image depth/stencil formats");
18526 vkCmdCopyImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_GENERAL, depth_image.handle(),
18527 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
18528 m_errorMonitor->VerifyFound();
18529
18530 // Aspect mask doesn't match dest image format - VU 01201
18531 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
18532 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
18533 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01201);
18534 // Again redundant but unavoidable when provoking vu01201 w/o vu01200
18535 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "unmatched source and dest image depth/stencil formats");
18536 vkCmdCopyImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_GENERAL, depth_image.handle(),
18537 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
18538 m_errorMonitor->VerifyFound();
18539
18540 m_commandBuffer->EndCommandBuffer();
18541}
18542
Karl Schultz6addd812016-02-02 17:17:23 -070018543TEST_F(VkLayerTest, ResolveImageLowSampleCount) {
18544 VkResult err;
18545 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060018546
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018547 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
18548 "vkCmdResolveImage called with source sample count less than 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060018549
Tony Barbour1fa09702017-03-16 12:09:08 -060018550 ASSERT_NO_FATAL_FAILURE(Init());
Mike Stroyana3082432015-09-25 13:39:21 -060018551
18552 // Create two images of sample count 1 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070018553 VkImage srcImage;
18554 VkImage dstImage;
18555 VkDeviceMemory srcMem;
18556 VkDeviceMemory destMem;
18557 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060018558
18559 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070018560 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
18561 image_create_info.pNext = NULL;
18562 image_create_info.imageType = VK_IMAGE_TYPE_2D;
18563 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
18564 image_create_info.extent.width = 32;
18565 image_create_info.extent.height = 1;
18566 image_create_info.extent.depth = 1;
18567 image_create_info.mipLevels = 1;
18568 image_create_info.arrayLayers = 1;
18569 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
18570 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
18571 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
18572 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018573
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018574 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060018575 ASSERT_VK_SUCCESS(err);
18576
Karl Schultz6addd812016-02-02 17:17:23 -070018577 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060018578
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018579 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060018580 ASSERT_VK_SUCCESS(err);
18581
18582 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018583 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070018584 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18585 memAlloc.pNext = NULL;
18586 memAlloc.allocationSize = 0;
18587 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018588
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060018589 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060018590 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018591 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060018592 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018593 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060018594 ASSERT_VK_SUCCESS(err);
18595
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018596 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060018597 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018598 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060018599 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018600 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060018601 ASSERT_VK_SUCCESS(err);
18602
18603 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
18604 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018605 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060018606 ASSERT_VK_SUCCESS(err);
18607
Tony Barbour552f6c02016-12-21 14:34:07 -070018608 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060018609 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070018610 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
18611 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060018612 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080018613 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060018614 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060018615 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130018616 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060018617 resolveRegion.srcOffset.x = 0;
18618 resolveRegion.srcOffset.y = 0;
18619 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080018620 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018621 resolveRegion.dstSubresource.mipLevel = 0;
18622 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130018623 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018624 resolveRegion.dstOffset.x = 0;
18625 resolveRegion.dstOffset.y = 0;
18626 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018627 resolveRegion.extent.width = 1;
18628 resolveRegion.extent.height = 1;
18629 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018630 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070018631 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060018632
Chris Forbes8f36a8a2016-04-07 13:21:07 +120018633 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060018634
Chia-I Wuf7458c52015-10-26 21:10:41 +080018635 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018636 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080018637 vkFreeMemory(m_device->device(), srcMem, NULL);
18638 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060018639}
18640
Karl Schultz6addd812016-02-02 17:17:23 -070018641TEST_F(VkLayerTest, ResolveImageHighSampleCount) {
18642 VkResult err;
18643 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060018644
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018645 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
18646 "vkCmdResolveImage called with dest sample count greater than 1.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060018647
Tony Barbour1fa09702017-03-16 12:09:08 -060018648 ASSERT_NO_FATAL_FAILURE(Init());
Mike Stroyana3082432015-09-25 13:39:21 -060018649
Chris Forbesa7530692016-05-08 12:35:39 +120018650 // Create two images of sample count 4 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070018651 VkImage srcImage;
18652 VkImage dstImage;
18653 VkDeviceMemory srcMem;
18654 VkDeviceMemory destMem;
18655 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060018656
18657 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070018658 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
18659 image_create_info.pNext = NULL;
18660 image_create_info.imageType = VK_IMAGE_TYPE_2D;
18661 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
18662 image_create_info.extent.width = 32;
18663 image_create_info.extent.height = 1;
18664 image_create_info.extent.depth = 1;
18665 image_create_info.mipLevels = 1;
18666 image_create_info.arrayLayers = 1;
Chris Forbesa7530692016-05-08 12:35:39 +120018667 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070018668 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
18669 // Note: Some implementations expect color attachment usage for any
18670 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018671 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070018672 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018673
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018674 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060018675 ASSERT_VK_SUCCESS(err);
18676
Karl Schultz6addd812016-02-02 17:17:23 -070018677 // Note: Some implementations expect color attachment usage for any
18678 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018679 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060018680
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018681 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060018682 ASSERT_VK_SUCCESS(err);
18683
18684 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018685 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070018686 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18687 memAlloc.pNext = NULL;
18688 memAlloc.allocationSize = 0;
18689 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018690
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060018691 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060018692 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018693 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060018694 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018695 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060018696 ASSERT_VK_SUCCESS(err);
18697
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018698 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060018699 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018700 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060018701 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018702 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060018703 ASSERT_VK_SUCCESS(err);
18704
18705 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
18706 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018707 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060018708 ASSERT_VK_SUCCESS(err);
18709
Tony Barbour552f6c02016-12-21 14:34:07 -070018710 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060018711 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070018712 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
18713 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060018714 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080018715 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060018716 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060018717 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130018718 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060018719 resolveRegion.srcOffset.x = 0;
18720 resolveRegion.srcOffset.y = 0;
18721 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080018722 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018723 resolveRegion.dstSubresource.mipLevel = 0;
18724 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130018725 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018726 resolveRegion.dstOffset.x = 0;
18727 resolveRegion.dstOffset.y = 0;
18728 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018729 resolveRegion.extent.width = 1;
18730 resolveRegion.extent.height = 1;
18731 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018732 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070018733 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060018734
Chris Forbes8f36a8a2016-04-07 13:21:07 +120018735 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060018736
Chia-I Wuf7458c52015-10-26 21:10:41 +080018737 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018738 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080018739 vkFreeMemory(m_device->device(), srcMem, NULL);
18740 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060018741}
18742
Karl Schultz6addd812016-02-02 17:17:23 -070018743TEST_F(VkLayerTest, ResolveImageFormatMismatch) {
18744 VkResult err;
18745 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060018746
Mark Lobodzinski50fbef12017-02-06 15:31:33 -070018747 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018748 "vkCmdResolveImage called with unmatched source and dest formats.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060018749
Tony Barbour1fa09702017-03-16 12:09:08 -060018750 ASSERT_NO_FATAL_FAILURE(Init());
Mike Stroyana3082432015-09-25 13:39:21 -060018751
18752 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070018753 VkImage srcImage;
18754 VkImage dstImage;
18755 VkDeviceMemory srcMem;
18756 VkDeviceMemory destMem;
18757 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060018758
18759 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070018760 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
18761 image_create_info.pNext = NULL;
18762 image_create_info.imageType = VK_IMAGE_TYPE_2D;
18763 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
18764 image_create_info.extent.width = 32;
18765 image_create_info.extent.height = 1;
18766 image_create_info.extent.depth = 1;
18767 image_create_info.mipLevels = 1;
18768 image_create_info.arrayLayers = 1;
18769 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
18770 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
18771 // Note: Some implementations expect color attachment usage for any
18772 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018773 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070018774 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018775
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018776 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060018777 ASSERT_VK_SUCCESS(err);
18778
Karl Schultz6addd812016-02-02 17:17:23 -070018779 // Set format to something other than source image
18780 image_create_info.format = VK_FORMAT_R32_SFLOAT;
18781 // Note: Some implementations expect color attachment usage for any
18782 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018783 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070018784 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060018785
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018786 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060018787 ASSERT_VK_SUCCESS(err);
18788
18789 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018790 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070018791 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18792 memAlloc.pNext = NULL;
18793 memAlloc.allocationSize = 0;
18794 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018795
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060018796 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060018797 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018798 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060018799 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018800 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060018801 ASSERT_VK_SUCCESS(err);
18802
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018803 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060018804 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018805 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060018806 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018807 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060018808 ASSERT_VK_SUCCESS(err);
18809
18810 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
18811 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018812 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060018813 ASSERT_VK_SUCCESS(err);
18814
Tony Barbour552f6c02016-12-21 14:34:07 -070018815 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060018816 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070018817 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
18818 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060018819 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080018820 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060018821 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060018822 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130018823 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060018824 resolveRegion.srcOffset.x = 0;
18825 resolveRegion.srcOffset.y = 0;
18826 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080018827 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018828 resolveRegion.dstSubresource.mipLevel = 0;
18829 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130018830 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018831 resolveRegion.dstOffset.x = 0;
18832 resolveRegion.dstOffset.y = 0;
18833 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018834 resolveRegion.extent.width = 1;
18835 resolveRegion.extent.height = 1;
18836 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018837 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070018838 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060018839
Chris Forbes8f36a8a2016-04-07 13:21:07 +120018840 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060018841
Chia-I Wuf7458c52015-10-26 21:10:41 +080018842 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018843 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080018844 vkFreeMemory(m_device->device(), srcMem, NULL);
18845 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060018846}
18847
Karl Schultz6addd812016-02-02 17:17:23 -070018848TEST_F(VkLayerTest, ResolveImageTypeMismatch) {
18849 VkResult err;
18850 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060018851
Mark Lobodzinski50fbef12017-02-06 15:31:33 -070018852 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018853 "vkCmdResolveImage called with unmatched source and dest image types.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060018854
Tony Barbour1fa09702017-03-16 12:09:08 -060018855 ASSERT_NO_FATAL_FAILURE(Init());
Mike Stroyana3082432015-09-25 13:39:21 -060018856
18857 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070018858 VkImage srcImage;
18859 VkImage dstImage;
18860 VkDeviceMemory srcMem;
18861 VkDeviceMemory destMem;
18862 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060018863
18864 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070018865 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
18866 image_create_info.pNext = NULL;
18867 image_create_info.imageType = VK_IMAGE_TYPE_2D;
18868 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
18869 image_create_info.extent.width = 32;
18870 image_create_info.extent.height = 1;
18871 image_create_info.extent.depth = 1;
18872 image_create_info.mipLevels = 1;
18873 image_create_info.arrayLayers = 1;
18874 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
18875 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
18876 // Note: Some implementations expect color attachment usage for any
18877 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018878 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070018879 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018880
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018881 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060018882 ASSERT_VK_SUCCESS(err);
18883
Karl Schultz6addd812016-02-02 17:17:23 -070018884 image_create_info.imageType = VK_IMAGE_TYPE_1D;
18885 // Note: Some implementations expect color attachment usage for any
18886 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018887 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070018888 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060018889
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018890 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060018891 ASSERT_VK_SUCCESS(err);
18892
18893 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018894 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070018895 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18896 memAlloc.pNext = NULL;
18897 memAlloc.allocationSize = 0;
18898 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018899
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060018900 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060018901 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018902 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060018903 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018904 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060018905 ASSERT_VK_SUCCESS(err);
18906
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018907 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060018908 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018909 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060018910 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018911 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060018912 ASSERT_VK_SUCCESS(err);
18913
18914 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
18915 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018916 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060018917 ASSERT_VK_SUCCESS(err);
18918
Tony Barbour552f6c02016-12-21 14:34:07 -070018919 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060018920 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070018921 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
18922 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060018923 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080018924 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060018925 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060018926 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130018927 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060018928 resolveRegion.srcOffset.x = 0;
18929 resolveRegion.srcOffset.y = 0;
18930 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080018931 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018932 resolveRegion.dstSubresource.mipLevel = 0;
18933 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130018934 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018935 resolveRegion.dstOffset.x = 0;
18936 resolveRegion.dstOffset.y = 0;
18937 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018938 resolveRegion.extent.width = 1;
18939 resolveRegion.extent.height = 1;
18940 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018941 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070018942 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060018943
Chris Forbes8f36a8a2016-04-07 13:21:07 +120018944 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060018945
Chia-I Wuf7458c52015-10-26 21:10:41 +080018946 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018947 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080018948 vkFreeMemory(m_device->device(), srcMem, NULL);
18949 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060018950}
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018951
Karl Schultz6addd812016-02-02 17:17:23 -070018952TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018953 // Create a single Image descriptor and cause it to first hit an error due
Karl Schultz6addd812016-02-02 17:17:23 -070018954 // to using a DS format, then cause it to hit error due to COLOR_BIT not
18955 // set in aspect
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018956 // The image format check comes 2nd in validation so we trigger it first,
18957 // then when we cause aspect fail next, bad format check will be preempted
Karl Schultz6addd812016-02-02 17:17:23 -070018958 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018959
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018960 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
18961 "Combination depth/stencil image formats can have only the ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060018962
Tony Barbour1fa09702017-03-16 12:09:08 -060018963 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -060018964 auto depth_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbourf887b162017-03-09 10:06:46 -070018965 if (!depth_format) {
18966 return;
18967 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060018968
Chia-I Wu1b99bb22015-10-27 19:25:11 +080018969 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070018970 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
18971 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018972
18973 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070018974 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
18975 ds_pool_ci.pNext = NULL;
18976 ds_pool_ci.maxSets = 1;
18977 ds_pool_ci.poolSizeCount = 1;
18978 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018979
18980 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018981 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018982 ASSERT_VK_SUCCESS(err);
18983
18984 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070018985 dsl_binding.binding = 0;
18986 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
18987 dsl_binding.descriptorCount = 1;
18988 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
18989 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018990
18991 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070018992 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
18993 ds_layout_ci.pNext = NULL;
18994 ds_layout_ci.bindingCount = 1;
18995 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018996 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018997 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018998 ASSERT_VK_SUCCESS(err);
18999
19000 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080019001 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080019002 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070019003 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060019004 alloc_info.descriptorPool = ds_pool;
19005 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019006 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060019007 ASSERT_VK_SUCCESS(err);
19008
Karl Schultz6addd812016-02-02 17:17:23 -070019009 VkImage image_bad;
19010 VkImage image_good;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060019011 // One bad format and one good format for Color attachment
Tony Barbourf887b162017-03-09 10:06:46 -070019012 const VkFormat tex_format_bad = depth_format;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060019013 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
Karl Schultz6addd812016-02-02 17:17:23 -070019014 const int32_t tex_width = 32;
19015 const int32_t tex_height = 32;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060019016
19017 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070019018 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
19019 image_create_info.pNext = NULL;
19020 image_create_info.imageType = VK_IMAGE_TYPE_2D;
19021 image_create_info.format = tex_format_bad;
19022 image_create_info.extent.width = tex_width;
19023 image_create_info.extent.height = tex_height;
19024 image_create_info.extent.depth = 1;
19025 image_create_info.mipLevels = 1;
19026 image_create_info.arrayLayers = 1;
19027 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
19028 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019029 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070019030 image_create_info.flags = 0;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060019031
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019032 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060019033 ASSERT_VK_SUCCESS(err);
19034 image_create_info.format = tex_format_good;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019035 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
19036 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_good);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060019037 ASSERT_VK_SUCCESS(err);
19038
Rene Lindsayf1e89c82016-12-28 13:18:31 -070019039 // ---Bind image memory---
19040 VkMemoryRequirements img_mem_reqs;
19041 vkGetImageMemoryRequirements(m_device->device(), image_bad, &img_mem_reqs);
19042 VkMemoryAllocateInfo image_alloc_info = {};
19043 image_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
19044 image_alloc_info.pNext = NULL;
19045 image_alloc_info.memoryTypeIndex = 0;
19046 image_alloc_info.allocationSize = img_mem_reqs.size;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019047 bool pass =
19048 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 -070019049 ASSERT_TRUE(pass);
19050 VkDeviceMemory mem;
19051 err = vkAllocateMemory(m_device->device(), &image_alloc_info, NULL, &mem);
19052 ASSERT_VK_SUCCESS(err);
19053 err = vkBindImageMemory(m_device->device(), image_bad, mem, 0);
19054 ASSERT_VK_SUCCESS(err);
19055 // -----------------------
19056
Tobin Ehlisa1c28562015-10-23 16:00:08 -060019057 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130019058 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070019059 image_view_create_info.image = image_bad;
19060 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
19061 image_view_create_info.format = tex_format_bad;
19062 image_view_create_info.subresourceRange.baseArrayLayer = 0;
19063 image_view_create_info.subresourceRange.baseMipLevel = 0;
19064 image_view_create_info.subresourceRange.layerCount = 1;
19065 image_view_create_info.subresourceRange.levelCount = 1;
Rene Lindsayf1e89c82016-12-28 13:18:31 -070019066 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060019067
19068 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019069 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060019070
Chris Forbes8f36a8a2016-04-07 13:21:07 +120019071 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060019072
Chia-I Wuf7458c52015-10-26 21:10:41 +080019073 vkDestroyImage(m_device->device(), image_bad, NULL);
19074 vkDestroyImage(m_device->device(), image_good, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080019075 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
19076 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Rene Lindsayf1e89c82016-12-28 13:18:31 -070019077
19078 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060019079}
Tobin Ehlis6e23d772016-05-19 11:08:34 -060019080
19081TEST_F(VkLayerTest, ClearImageErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019082 TEST_DESCRIPTION(
19083 "Call ClearColorImage w/ a depth|stencil image and "
19084 "ClearDepthStencilImage with a color image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060019085
Tony Barbour1fa09702017-03-16 12:09:08 -060019086 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -060019087 auto depth_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbourf887b162017-03-09 10:06:46 -070019088 if (!depth_format) {
19089 return;
19090 }
Tobin Ehlis6e23d772016-05-19 11:08:34 -060019091 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19092
Tony Barbour552f6c02016-12-21 14:34:07 -070019093 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis6e23d772016-05-19 11:08:34 -060019094
19095 // Color image
19096 VkClearColorValue clear_color;
19097 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
19098 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
19099 const VkFormat color_format = VK_FORMAT_B8G8R8A8_UNORM;
19100 const int32_t img_width = 32;
19101 const int32_t img_height = 32;
19102 VkImageCreateInfo image_create_info = {};
19103 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
19104 image_create_info.pNext = NULL;
19105 image_create_info.imageType = VK_IMAGE_TYPE_2D;
19106 image_create_info.format = color_format;
19107 image_create_info.extent.width = img_width;
19108 image_create_info.extent.height = img_height;
19109 image_create_info.extent.depth = 1;
19110 image_create_info.mipLevels = 1;
19111 image_create_info.arrayLayers = 1;
19112 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
19113 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
19114 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
19115
19116 vk_testing::Image color_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019117 color_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060019118
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019119 const VkImageSubresourceRange color_range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060019120
19121 // Depth/Stencil image
19122 VkClearDepthStencilValue clear_value = {0};
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019123 reqs = 0; // don't need HOST_VISIBLE DS image
Tobin Ehlis6e23d772016-05-19 11:08:34 -060019124 VkImageCreateInfo ds_image_create_info = vk_testing::Image::create_info();
19125 ds_image_create_info.imageType = VK_IMAGE_TYPE_2D;
Tony Barbourf887b162017-03-09 10:06:46 -070019126 ds_image_create_info.format = depth_format;
Tobin Ehlis6e23d772016-05-19 11:08:34 -060019127 ds_image_create_info.extent.width = 64;
19128 ds_image_create_info.extent.height = 64;
19129 ds_image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Rene Lindsaya1fc64a2016-12-27 15:18:54 -070019130 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 -060019131
19132 vk_testing::Image ds_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019133 ds_image.init(*m_device, (const VkImageCreateInfo &)ds_image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060019134
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019135 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 -060019136
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019137 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060019138
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019139 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tobin Ehlis6e23d772016-05-19 11:08:34 -060019140 &color_range);
19141
19142 m_errorMonitor->VerifyFound();
19143
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019144 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
19145 "vkCmdClearColorImage called with "
19146 "image created without "
19147 "VK_IMAGE_USAGE_TRANSFER_DST_BIT");
Tony Barbour26434b92016-06-02 09:43:50 -060019148
Rene Lindsaya1fc64a2016-12-27 15:18:54 -070019149 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tony Barbour26434b92016-06-02 09:43:50 -060019150 &color_range);
19151
19152 m_errorMonitor->VerifyFound();
19153
Tobin Ehlis6e23d772016-05-19 11:08:34 -060019154 // Call CmdClearDepthStencilImage with color image
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019155 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
19156 "vkCmdClearDepthStencilImage called without a depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060019157
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019158 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
19159 &clear_value, 1, &ds_range);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060019160
19161 m_errorMonitor->VerifyFound();
19162}
Tobin Ehliscde08892015-09-22 10:11:37 -060019163
Mike Schuchardt35fece12017-03-07 14:40:28 -070019164TEST_F(VkLayerTest, CommandQueueFlags) {
19165 TEST_DESCRIPTION(
19166 "Allocate a command buffer on a queue that does not support graphics and try to issue a "
19167 "graphics-only command");
19168
19169 ASSERT_NO_FATAL_FAILURE(Init());
19170
19171 uint32_t queueFamilyIndex = m_device->QueueFamilyWithoutCapabilities(VK_QUEUE_GRAPHICS_BIT);
Dave Houlton3c9fca72017-03-27 17:25:54 -060019172 if (queueFamilyIndex == UINT32_MAX) {
Mike Schuchardt35fece12017-03-07 14:40:28 -070019173 printf(" Non-graphics queue family not found; skipped.\n");
19174 return;
19175 } else {
19176 // Create command pool on a non-graphics queue
19177 VkCommandPoolObj command_pool(m_device, queueFamilyIndex);
19178
19179 // Setup command buffer on pool
19180 VkCommandBufferObj command_buffer(m_device, &command_pool);
19181 command_buffer.BeginCommandBuffer();
19182
19183 // Issue a graphics only command
19184 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01446);
19185 VkViewport viewport = {0, 0, 16, 16, 0, 1};
19186 command_buffer.SetViewport(0, 1, &viewport);
19187 m_errorMonitor->VerifyFound();
19188 }
19189}
19190
Mark Lobodzinskib8359282017-05-16 09:17:51 -060019191TEST_F(VkLayerTest, ExecuteUnrecordedCBs) {
19192 TEST_DESCRIPTION(
19193 "Attempt vkCmdExecuteCommands and then QueueSubmit with an unrecorded secondary and primary command buffer, respectively");
19194
19195 ASSERT_NO_FATAL_FAILURE(Init());
19196 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19197 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00155);
19198 // Allocate a secondary command buffer
19199 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
19200 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19201 command_buffer_allocate_info.commandPool = m_commandPool->handle();
19202 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
19203 command_buffer_allocate_info.commandBufferCount = 1;
19204 VkCommandBuffer secondary_command_buffer;
19205 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
19206 VkCommandBufferBeginInfo command_buffer_begin_info = {};
19207 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19208 command_buffer_begin_info.flags =
19209 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
19210 command_buffer_begin_info.pInheritanceInfo = nullptr;
19211
19212 // Now update primary cmd buffer to execute unrecorded secondary
19213 VkResult err = vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
19214 ASSERT_VK_SUCCESS(err);
19215 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
19216 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
19217 vkCmdEndRenderPass(m_commandBuffer->handle());
19218 err = vkEndCommandBuffer(m_commandBuffer->handle());
19219 ASSERT_VK_SUCCESS(err);
19220 m_errorMonitor->VerifyFound();
19221
19222 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00134);
19223 // Allocate a primary command buffer
19224 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19225 command_buffer_allocate_info.commandBufferCount = 1;
19226 VkCommandBuffer primary_command_buffer;
19227 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &primary_command_buffer));
19228
19229 // And submit the unrecorded command buffer
19230 VkSubmitInfo submit_info = {};
19231 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19232 submit_info.commandBufferCount = 1;
19233 submit_info.pCommandBuffers = &primary_command_buffer;
19234 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
19235 m_errorMonitor->VerifyFound();
19236}
19237
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019238// WSI Enabled Tests
19239//
Chris Forbes09368e42016-10-13 11:59:22 +130019240#if 0
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019241TEST_F(VkWsiEnabledLayerTest, TestEnabledWsi) {
19242
19243#if defined(VK_USE_PLATFORM_XCB_KHR)
19244 VkSurfaceKHR surface = VK_NULL_HANDLE;
19245
19246 VkResult err;
19247 bool pass;
19248 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
19249 VkSwapchainCreateInfoKHR swapchain_create_info = {};
19250 // uint32_t swapchain_image_count = 0;
19251 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
19252 // uint32_t image_index = 0;
19253 // VkPresentInfoKHR present_info = {};
19254
Tony Barbour1fa09702017-03-16 12:09:08 -060019255 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019256
19257 // Use the create function from one of the VK_KHR_*_surface extension in
19258 // order to create a surface, testing all known errors in the process,
19259 // before successfully creating a surface:
19260 // First, try to create a surface without a VkXcbSurfaceCreateInfoKHR:
19261 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo specified as NULL");
19262 err = vkCreateXcbSurfaceKHR(instance(), NULL, NULL, &surface);
19263 pass = (err != VK_SUCCESS);
19264 ASSERT_TRUE(pass);
19265 m_errorMonitor->VerifyFound();
19266
19267 // Next, try to create a surface with the wrong
19268 // VkXcbSurfaceCreateInfoKHR::sType:
19269 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
19270 xcb_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
19271 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
19272 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
19273 pass = (err != VK_SUCCESS);
19274 ASSERT_TRUE(pass);
19275 m_errorMonitor->VerifyFound();
19276
19277 // Create a native window, and then correctly create a surface:
19278 xcb_connection_t *connection;
19279 xcb_screen_t *screen;
19280 xcb_window_t xcb_window;
19281 xcb_intern_atom_reply_t *atom_wm_delete_window;
19282
19283 const xcb_setup_t *setup;
19284 xcb_screen_iterator_t iter;
19285 int scr;
19286 uint32_t value_mask, value_list[32];
19287 int width = 1;
19288 int height = 1;
19289
19290 connection = xcb_connect(NULL, &scr);
19291 ASSERT_TRUE(connection != NULL);
19292 setup = xcb_get_setup(connection);
19293 iter = xcb_setup_roots_iterator(setup);
19294 while (scr-- > 0)
19295 xcb_screen_next(&iter);
19296 screen = iter.data;
19297
19298 xcb_window = xcb_generate_id(connection);
19299
19300 value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
19301 value_list[0] = screen->black_pixel;
19302 value_list[1] = XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_STRUCTURE_NOTIFY;
19303
19304 xcb_create_window(connection, XCB_COPY_FROM_PARENT, xcb_window, screen->root, 0, 0, width, height, 0,
19305 XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual, value_mask, value_list);
19306
19307 /* Magic code that will send notification when window is destroyed */
19308 xcb_intern_atom_cookie_t cookie = xcb_intern_atom(connection, 1, 12, "WM_PROTOCOLS");
19309 xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply(connection, cookie, 0);
19310
19311 xcb_intern_atom_cookie_t cookie2 = xcb_intern_atom(connection, 0, 16, "WM_DELETE_WINDOW");
19312 atom_wm_delete_window = xcb_intern_atom_reply(connection, cookie2, 0);
19313 xcb_change_property(connection, XCB_PROP_MODE_REPLACE, xcb_window, (*reply).atom, 4, 32, 1, &(*atom_wm_delete_window).atom);
19314 free(reply);
19315
19316 xcb_map_window(connection, xcb_window);
19317
19318 // Force the x/y coordinates to 100,100 results are identical in consecutive
19319 // runs
19320 const uint32_t coords[] = { 100, 100 };
19321 xcb_configure_window(connection, xcb_window, XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, coords);
19322
19323 // Finally, try to correctly create a surface:
19324 xcb_create_info.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
19325 xcb_create_info.pNext = NULL;
19326 xcb_create_info.flags = 0;
19327 xcb_create_info.connection = connection;
19328 xcb_create_info.window = xcb_window;
19329 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
19330 pass = (err == VK_SUCCESS);
19331 ASSERT_TRUE(pass);
19332
19333 // Check if surface supports presentation:
19334
19335 // 1st, do so without having queried the queue families:
19336 VkBool32 supported = false;
19337 // TODO: Get the following error to come out:
19338 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
19339 "called before calling the vkGetPhysicalDeviceQueueFamilyProperties "
19340 "function");
19341 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
19342 pass = (err != VK_SUCCESS);
19343 // ASSERT_TRUE(pass);
19344 // m_errorMonitor->VerifyFound();
19345
19346 // Next, query a queue family index that's too large:
19347 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
19348 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 100000, surface, &supported);
19349 pass = (err != VK_SUCCESS);
19350 ASSERT_TRUE(pass);
19351 m_errorMonitor->VerifyFound();
19352
19353 // Finally, do so correctly:
19354 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
19355 // SUPPORTED
19356 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
19357 pass = (err == VK_SUCCESS);
19358 ASSERT_TRUE(pass);
19359
19360 // Before proceeding, try to create a swapchain without having called
19361 // vkGetPhysicalDeviceSurfaceCapabilitiesKHR():
19362 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
19363 swapchain_create_info.pNext = NULL;
19364 swapchain_create_info.flags = 0;
19365 swapchain_create_info.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
19366 swapchain_create_info.surface = surface;
19367 swapchain_create_info.imageArrayLayers = 1;
19368 swapchain_create_info.preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
19369 swapchain_create_info.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
19370 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
19371 "called before calling vkGetPhysicalDeviceSurfaceCapabilitiesKHR().");
19372 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
19373 pass = (err != VK_SUCCESS);
19374 ASSERT_TRUE(pass);
19375 m_errorMonitor->VerifyFound();
19376
19377 // Get the surface capabilities:
19378 VkSurfaceCapabilitiesKHR surface_capabilities;
19379
19380 // Do so correctly (only error logged by this entrypoint is if the
19381 // extension isn't enabled):
19382 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &surface_capabilities);
19383 pass = (err == VK_SUCCESS);
19384 ASSERT_TRUE(pass);
19385
19386 // Get the surface formats:
19387 uint32_t surface_format_count;
19388
19389 // First, try without a pointer to surface_format_count:
19390 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSurfaceFormatCount "
19391 "specified as NULL");
19392 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, NULL, NULL);
19393 pass = (err == VK_SUCCESS);
19394 ASSERT_TRUE(pass);
19395 m_errorMonitor->VerifyFound();
19396
19397 // Next, call with a non-NULL pSurfaceFormats, even though we haven't
19398 // correctly done a 1st try (to get the count):
19399 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
19400 surface_format_count = 0;
19401 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, (VkSurfaceFormatKHR *)&surface_format_count);
19402 pass = (err == VK_SUCCESS);
19403 ASSERT_TRUE(pass);
19404 m_errorMonitor->VerifyFound();
19405
19406 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
19407 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
19408 pass = (err == VK_SUCCESS);
19409 ASSERT_TRUE(pass);
19410
19411 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
19412 VkSurfaceFormatKHR *surface_formats = (VkSurfaceFormatKHR *)malloc(surface_format_count * sizeof(VkSurfaceFormatKHR));
19413
19414 // Next, do a 2nd try with surface_format_count being set too high:
19415 surface_format_count += 5;
19416 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
19417 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
19418 pass = (err == VK_SUCCESS);
19419 ASSERT_TRUE(pass);
19420 m_errorMonitor->VerifyFound();
19421
19422 // Finally, do a correct 1st and 2nd try:
19423 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
19424 pass = (err == VK_SUCCESS);
19425 ASSERT_TRUE(pass);
19426 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
19427 pass = (err == VK_SUCCESS);
19428 ASSERT_TRUE(pass);
19429
19430 // Get the surface present modes:
19431 uint32_t surface_present_mode_count;
19432
19433 // First, try without a pointer to surface_format_count:
19434 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pPresentModeCount "
19435 "specified as NULL");
19436
19437 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, NULL, NULL);
19438 pass = (err == VK_SUCCESS);
19439 ASSERT_TRUE(pass);
19440 m_errorMonitor->VerifyFound();
19441
19442 // Next, call with a non-NULL VkPresentModeKHR, even though we haven't
19443 // correctly done a 1st try (to get the count):
19444 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
19445 surface_present_mode_count = 0;
19446 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count,
19447 (VkPresentModeKHR *)&surface_present_mode_count);
19448 pass = (err == VK_SUCCESS);
19449 ASSERT_TRUE(pass);
19450 m_errorMonitor->VerifyFound();
19451
19452 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
19453 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
19454 pass = (err == VK_SUCCESS);
19455 ASSERT_TRUE(pass);
19456
19457 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
19458 VkPresentModeKHR *surface_present_modes = (VkPresentModeKHR *)malloc(surface_present_mode_count * sizeof(VkPresentModeKHR));
19459
19460 // Next, do a 2nd try with surface_format_count being set too high:
19461 surface_present_mode_count += 5;
19462 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
19463 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
19464 pass = (err == VK_SUCCESS);
19465 ASSERT_TRUE(pass);
19466 m_errorMonitor->VerifyFound();
19467
19468 // Finally, do a correct 1st and 2nd try:
19469 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
19470 pass = (err == VK_SUCCESS);
19471 ASSERT_TRUE(pass);
19472 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
19473 pass = (err == VK_SUCCESS);
19474 ASSERT_TRUE(pass);
19475
19476 // Create a swapchain:
19477
19478 // First, try without a pointer to swapchain_create_info:
19479 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo "
19480 "specified as NULL");
19481
19482 err = vkCreateSwapchainKHR(m_device->device(), NULL, NULL, &swapchain);
19483 pass = (err != VK_SUCCESS);
19484 ASSERT_TRUE(pass);
19485 m_errorMonitor->VerifyFound();
19486
19487 // Next, call with a non-NULL swapchain_create_info, that has the wrong
19488 // sType:
19489 swapchain_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
19490 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
19491
19492 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
19493 pass = (err != VK_SUCCESS);
19494 ASSERT_TRUE(pass);
19495 m_errorMonitor->VerifyFound();
19496
19497 // Next, call with a NULL swapchain pointer:
19498 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
19499 swapchain_create_info.pNext = NULL;
19500 swapchain_create_info.flags = 0;
19501 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSwapchain "
19502 "specified as NULL");
19503
19504 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, NULL);
19505 pass = (err != VK_SUCCESS);
19506 ASSERT_TRUE(pass);
19507 m_errorMonitor->VerifyFound();
19508
19509 // TODO: Enhance swapchain layer so that
19510 // swapchain_create_info.queueFamilyIndexCount is checked against something?
19511
19512 // Next, call with a queue family index that's too large:
19513 uint32_t queueFamilyIndex[2] = { 100000, 0 };
19514 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
19515 swapchain_create_info.queueFamilyIndexCount = 2;
19516 swapchain_create_info.pQueueFamilyIndices = queueFamilyIndex;
19517 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
19518 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
19519 pass = (err != VK_SUCCESS);
19520 ASSERT_TRUE(pass);
19521 m_errorMonitor->VerifyFound();
19522
19523 // Next, call a queueFamilyIndexCount that's too small for CONCURRENT:
19524 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
19525 swapchain_create_info.queueFamilyIndexCount = 1;
19526 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
19527 "but with a bad value(s) for pCreateInfo->queueFamilyIndexCount or "
19528 "pCreateInfo->pQueueFamilyIndices).");
19529 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
19530 pass = (err != VK_SUCCESS);
19531 ASSERT_TRUE(pass);
19532 m_errorMonitor->VerifyFound();
19533
19534 // Next, call with an invalid imageSharingMode:
19535 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_MAX_ENUM;
19536 swapchain_create_info.queueFamilyIndexCount = 1;
19537 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
19538 "called with a non-supported pCreateInfo->imageSharingMode (i.e.");
19539 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
19540 pass = (err != VK_SUCCESS);
19541 ASSERT_TRUE(pass);
19542 m_errorMonitor->VerifyFound();
19543 // Fix for the future:
19544 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
19545 // SUPPORTED
19546 swapchain_create_info.queueFamilyIndexCount = 0;
19547 queueFamilyIndex[0] = 0;
19548 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
19549
19550 // TODO: CONTINUE TESTING VALIDATION OF vkCreateSwapchainKHR() ...
19551 // Get the images from a swapchain:
19552 // Acquire an image from a swapchain:
19553 // Present an image to a swapchain:
19554 // Destroy the swapchain:
19555
19556 // TODOs:
19557 //
19558 // - Try destroying the device without first destroying the swapchain
19559 //
19560 // - Try destroying the device without first destroying the surface
19561 //
19562 // - Try destroying the surface without first destroying the swapchain
19563
19564 // Destroy the surface:
19565 vkDestroySurfaceKHR(instance(), surface, NULL);
19566
19567 // Tear down the window:
19568 xcb_destroy_window(connection, xcb_window);
19569 xcb_disconnect(connection);
19570
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019571#else // VK_USE_PLATFORM_XCB_KHR
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019572 return;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019573#endif // VK_USE_PLATFORM_XCB_KHR
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019574}
Chris Forbes09368e42016-10-13 11:59:22 +130019575#endif
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019576
19577//
19578// POSITIVE VALIDATION TESTS
19579//
19580// These tests do not expect to encounter ANY validation errors pass only if this is true
19581
Mark Lobodzinski781aeb52017-02-22 10:57:53 -070019582TEST_F(VkPositiveLayerTest, SecondaryCommandBufferClearColorAttachments) {
19583 TEST_DESCRIPTION("Create a secondary command buffer and record a CmdClearAttachments call into it");
Tony Barbour1fa09702017-03-16 12:09:08 -060019584 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski781aeb52017-02-22 10:57:53 -070019585 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19586
19587 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
19588 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mike Schuchardt06304c22017-03-01 17:09:09 -070019589 command_buffer_allocate_info.commandPool = m_commandPool->handle();
Mark Lobodzinski781aeb52017-02-22 10:57:53 -070019590 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
19591 command_buffer_allocate_info.commandBufferCount = 1;
19592
19593 VkCommandBuffer secondary_command_buffer;
19594 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
19595 VkCommandBufferBeginInfo command_buffer_begin_info = {};
19596 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
19597 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
19598 command_buffer_inheritance_info.renderPass = m_renderPass;
19599 command_buffer_inheritance_info.framebuffer = m_framebuffer;
19600
19601 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19602 command_buffer_begin_info.flags =
19603 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
19604 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
19605
19606 vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
19607 VkClearAttachment color_attachment;
19608 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
19609 color_attachment.clearValue.color.float32[0] = 0;
19610 color_attachment.clearValue.color.float32[1] = 0;
19611 color_attachment.clearValue.color.float32[2] = 0;
19612 color_attachment.clearValue.color.float32[3] = 0;
19613 color_attachment.colorAttachment = 0;
19614 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
19615 vkCmdClearAttachments(secondary_command_buffer, 1, &color_attachment, 1, &clear_rect);
19616}
19617
Tobin Ehlise0006882016-11-03 10:14:28 -060019618TEST_F(VkPositiveLayerTest, SecondaryCommandBufferImageLayoutTransitions) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019619 TEST_DESCRIPTION(
19620 "Perform an image layout transition in a secondary command buffer followed "
19621 "by a transition in the primary.");
Tobin Ehlise0006882016-11-03 10:14:28 -060019622 VkResult err;
19623 m_errorMonitor->ExpectSuccess();
Tony Barbour1fa09702017-03-16 12:09:08 -060019624 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -060019625 auto depth_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbourf887b162017-03-09 10:06:46 -070019626 if (!depth_format) {
19627 return;
19628 }
Tobin Ehlise0006882016-11-03 10:14:28 -060019629 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19630 // Allocate a secondary and primary cmd buffer
19631 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
19632 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mike Schuchardt06304c22017-03-01 17:09:09 -070019633 command_buffer_allocate_info.commandPool = m_commandPool->handle();
Tobin Ehlise0006882016-11-03 10:14:28 -060019634 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
19635 command_buffer_allocate_info.commandBufferCount = 1;
19636
19637 VkCommandBuffer secondary_command_buffer;
19638 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
19639 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19640 VkCommandBuffer primary_command_buffer;
19641 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &primary_command_buffer));
19642 VkCommandBufferBeginInfo command_buffer_begin_info = {};
19643 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
19644 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
19645 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19646 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
19647 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
19648
19649 err = vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
19650 ASSERT_VK_SUCCESS(err);
19651 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060019652 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 -060019653 ASSERT_TRUE(image.initialized());
19654 VkImageMemoryBarrier img_barrier = {};
19655 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
19656 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
19657 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
19658 img_barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
19659 img_barrier.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19660 img_barrier.image = image.handle();
19661 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
19662 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
19663 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
19664 img_barrier.subresourceRange.baseArrayLayer = 0;
19665 img_barrier.subresourceRange.baseMipLevel = 0;
19666 img_barrier.subresourceRange.layerCount = 1;
19667 img_barrier.subresourceRange.levelCount = 1;
19668 vkCmdPipelineBarrier(secondary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr,
19669 0, nullptr, 1, &img_barrier);
19670 err = vkEndCommandBuffer(secondary_command_buffer);
19671 ASSERT_VK_SUCCESS(err);
19672
19673 // Now update primary cmd buffer to execute secondary and transitions image
19674 command_buffer_begin_info.pInheritanceInfo = nullptr;
19675 err = vkBeginCommandBuffer(primary_command_buffer, &command_buffer_begin_info);
19676 ASSERT_VK_SUCCESS(err);
19677 vkCmdExecuteCommands(primary_command_buffer, 1, &secondary_command_buffer);
19678 VkImageMemoryBarrier img_barrier2 = {};
19679 img_barrier2.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
19680 img_barrier2.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
19681 img_barrier2.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
19682 img_barrier2.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19683 img_barrier2.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19684 img_barrier2.image = image.handle();
19685 img_barrier2.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
19686 img_barrier2.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
19687 img_barrier2.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
19688 img_barrier2.subresourceRange.baseArrayLayer = 0;
19689 img_barrier2.subresourceRange.baseMipLevel = 0;
19690 img_barrier2.subresourceRange.layerCount = 1;
19691 img_barrier2.subresourceRange.levelCount = 1;
19692 vkCmdPipelineBarrier(primary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
19693 nullptr, 1, &img_barrier2);
19694 err = vkEndCommandBuffer(primary_command_buffer);
19695 ASSERT_VK_SUCCESS(err);
19696 VkSubmitInfo submit_info = {};
19697 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19698 submit_info.commandBufferCount = 1;
19699 submit_info.pCommandBuffers = &primary_command_buffer;
19700 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
19701 ASSERT_VK_SUCCESS(err);
19702 m_errorMonitor->VerifyNotFound();
19703 err = vkDeviceWaitIdle(m_device->device());
19704 ASSERT_VK_SUCCESS(err);
Mike Schuchardt06304c22017-03-01 17:09:09 -070019705 vkFreeCommandBuffers(m_device->device(), m_commandPool->handle(), 1, &secondary_command_buffer);
19706 vkFreeCommandBuffers(m_device->device(), m_commandPool->handle(), 1, &primary_command_buffer);
Tobin Ehlise0006882016-11-03 10:14:28 -060019707}
19708
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019709// This is a positive test. No failures are expected.
19710TEST_F(VkPositiveLayerTest, IgnoreUnrelatedDescriptor) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019711 TEST_DESCRIPTION(
19712 "Ensure that the vkUpdateDescriptorSets validation code "
19713 "is ignoring VkWriteDescriptorSet members that are not "
19714 "related to the descriptor type specified by "
19715 "VkWriteDescriptorSet::descriptorType. Correct "
19716 "validation behavior will result in the test running to "
19717 "completion without validation errors.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019718
19719 const uintptr_t invalid_ptr = 0xcdcdcdcd;
19720
Tony Barbour1fa09702017-03-16 12:09:08 -060019721 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019722
19723 // Image Case
19724 {
19725 m_errorMonitor->ExpectSuccess();
19726
19727 VkImage image;
19728 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
19729 const int32_t tex_width = 32;
19730 const int32_t tex_height = 32;
19731 VkImageCreateInfo image_create_info = {};
19732 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
19733 image_create_info.pNext = NULL;
19734 image_create_info.imageType = VK_IMAGE_TYPE_2D;
19735 image_create_info.format = tex_format;
19736 image_create_info.extent.width = tex_width;
19737 image_create_info.extent.height = tex_height;
19738 image_create_info.extent.depth = 1;
19739 image_create_info.mipLevels = 1;
19740 image_create_info.arrayLayers = 1;
19741 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
19742 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
19743 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
19744 image_create_info.flags = 0;
19745 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
19746 ASSERT_VK_SUCCESS(err);
19747
19748 VkMemoryRequirements memory_reqs;
19749 VkDeviceMemory image_memory;
19750 bool pass;
19751 VkMemoryAllocateInfo memory_info = {};
19752 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
19753 memory_info.pNext = NULL;
19754 memory_info.allocationSize = 0;
19755 memory_info.memoryTypeIndex = 0;
19756 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
19757 memory_info.allocationSize = memory_reqs.size;
19758 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
19759 ASSERT_TRUE(pass);
19760 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
19761 ASSERT_VK_SUCCESS(err);
19762 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
19763 ASSERT_VK_SUCCESS(err);
19764
19765 VkImageViewCreateInfo image_view_create_info = {};
19766 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
19767 image_view_create_info.image = image;
19768 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
19769 image_view_create_info.format = tex_format;
19770 image_view_create_info.subresourceRange.layerCount = 1;
19771 image_view_create_info.subresourceRange.baseMipLevel = 0;
19772 image_view_create_info.subresourceRange.levelCount = 1;
19773 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
19774
19775 VkImageView view;
19776 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
19777 ASSERT_VK_SUCCESS(err);
19778
19779 VkDescriptorPoolSize ds_type_count = {};
19780 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
19781 ds_type_count.descriptorCount = 1;
19782
19783 VkDescriptorPoolCreateInfo ds_pool_ci = {};
19784 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
19785 ds_pool_ci.pNext = NULL;
19786 ds_pool_ci.maxSets = 1;
19787 ds_pool_ci.poolSizeCount = 1;
19788 ds_pool_ci.pPoolSizes = &ds_type_count;
19789
19790 VkDescriptorPool ds_pool;
19791 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
19792 ASSERT_VK_SUCCESS(err);
19793
19794 VkDescriptorSetLayoutBinding dsl_binding = {};
19795 dsl_binding.binding = 0;
19796 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
19797 dsl_binding.descriptorCount = 1;
19798 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
19799 dsl_binding.pImmutableSamplers = NULL;
19800
19801 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
19802 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
19803 ds_layout_ci.pNext = NULL;
19804 ds_layout_ci.bindingCount = 1;
19805 ds_layout_ci.pBindings = &dsl_binding;
19806 VkDescriptorSetLayout ds_layout;
19807 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
19808 ASSERT_VK_SUCCESS(err);
19809
19810 VkDescriptorSet descriptor_set;
19811 VkDescriptorSetAllocateInfo alloc_info = {};
19812 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
19813 alloc_info.descriptorSetCount = 1;
19814 alloc_info.descriptorPool = ds_pool;
19815 alloc_info.pSetLayouts = &ds_layout;
19816 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
19817 ASSERT_VK_SUCCESS(err);
19818
19819 VkDescriptorImageInfo image_info = {};
19820 image_info.imageView = view;
19821 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
19822
19823 VkWriteDescriptorSet descriptor_write;
19824 memset(&descriptor_write, 0, sizeof(descriptor_write));
19825 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
19826 descriptor_write.dstSet = descriptor_set;
19827 descriptor_write.dstBinding = 0;
19828 descriptor_write.descriptorCount = 1;
19829 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
19830 descriptor_write.pImageInfo = &image_info;
19831
19832 // Set pBufferInfo and pTexelBufferView to invalid values, which should
19833 // be
19834 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE.
19835 // This will most likely produce a crash if the parameter_validation
19836 // layer
19837 // does not correctly ignore pBufferInfo.
19838 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
19839 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
19840
19841 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
19842
19843 m_errorMonitor->VerifyNotFound();
19844
19845 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
19846 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
19847 vkDestroyImageView(m_device->device(), view, NULL);
19848 vkDestroyImage(m_device->device(), image, NULL);
19849 vkFreeMemory(m_device->device(), image_memory, NULL);
19850 }
19851
19852 // Buffer Case
19853 {
19854 m_errorMonitor->ExpectSuccess();
19855
19856 VkBuffer buffer;
19857 uint32_t queue_family_index = 0;
19858 VkBufferCreateInfo buffer_create_info = {};
19859 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
19860 buffer_create_info.size = 1024;
19861 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
19862 buffer_create_info.queueFamilyIndexCount = 1;
19863 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
19864
19865 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
19866 ASSERT_VK_SUCCESS(err);
19867
19868 VkMemoryRequirements memory_reqs;
19869 VkDeviceMemory buffer_memory;
19870 bool pass;
19871 VkMemoryAllocateInfo memory_info = {};
19872 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
19873 memory_info.pNext = NULL;
19874 memory_info.allocationSize = 0;
19875 memory_info.memoryTypeIndex = 0;
19876
19877 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
19878 memory_info.allocationSize = memory_reqs.size;
19879 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
19880 ASSERT_TRUE(pass);
19881
19882 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
19883 ASSERT_VK_SUCCESS(err);
19884 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
19885 ASSERT_VK_SUCCESS(err);
19886
19887 VkDescriptorPoolSize ds_type_count = {};
19888 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
19889 ds_type_count.descriptorCount = 1;
19890
19891 VkDescriptorPoolCreateInfo ds_pool_ci = {};
19892 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
19893 ds_pool_ci.pNext = NULL;
19894 ds_pool_ci.maxSets = 1;
19895 ds_pool_ci.poolSizeCount = 1;
19896 ds_pool_ci.pPoolSizes = &ds_type_count;
19897
19898 VkDescriptorPool ds_pool;
19899 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
19900 ASSERT_VK_SUCCESS(err);
19901
19902 VkDescriptorSetLayoutBinding dsl_binding = {};
19903 dsl_binding.binding = 0;
19904 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
19905 dsl_binding.descriptorCount = 1;
19906 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
19907 dsl_binding.pImmutableSamplers = NULL;
19908
19909 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
19910 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
19911 ds_layout_ci.pNext = NULL;
19912 ds_layout_ci.bindingCount = 1;
19913 ds_layout_ci.pBindings = &dsl_binding;
19914 VkDescriptorSetLayout ds_layout;
19915 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
19916 ASSERT_VK_SUCCESS(err);
19917
19918 VkDescriptorSet descriptor_set;
19919 VkDescriptorSetAllocateInfo alloc_info = {};
19920 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
19921 alloc_info.descriptorSetCount = 1;
19922 alloc_info.descriptorPool = ds_pool;
19923 alloc_info.pSetLayouts = &ds_layout;
19924 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
19925 ASSERT_VK_SUCCESS(err);
19926
19927 VkDescriptorBufferInfo buffer_info = {};
19928 buffer_info.buffer = buffer;
19929 buffer_info.offset = 0;
19930 buffer_info.range = 1024;
19931
19932 VkWriteDescriptorSet descriptor_write;
19933 memset(&descriptor_write, 0, sizeof(descriptor_write));
19934 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
19935 descriptor_write.dstSet = descriptor_set;
19936 descriptor_write.dstBinding = 0;
19937 descriptor_write.descriptorCount = 1;
19938 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
19939 descriptor_write.pBufferInfo = &buffer_info;
19940
19941 // Set pImageInfo and pTexelBufferView to invalid values, which should
19942 // be
19943 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER.
19944 // This will most likely produce a crash if the parameter_validation
19945 // layer
19946 // does not correctly ignore pImageInfo.
19947 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
19948 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
19949
19950 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
19951
19952 m_errorMonitor->VerifyNotFound();
19953
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019954 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
19955 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
19956 vkDestroyBuffer(m_device->device(), buffer, NULL);
19957 vkFreeMemory(m_device->device(), buffer_memory, NULL);
19958 }
19959
19960 // Texel Buffer Case
19961 {
19962 m_errorMonitor->ExpectSuccess();
19963
19964 VkBuffer buffer;
19965 uint32_t queue_family_index = 0;
19966 VkBufferCreateInfo buffer_create_info = {};
19967 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
19968 buffer_create_info.size = 1024;
19969 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
19970 buffer_create_info.queueFamilyIndexCount = 1;
19971 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
19972
19973 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
19974 ASSERT_VK_SUCCESS(err);
19975
19976 VkMemoryRequirements memory_reqs;
19977 VkDeviceMemory buffer_memory;
19978 bool pass;
19979 VkMemoryAllocateInfo memory_info = {};
19980 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
19981 memory_info.pNext = NULL;
19982 memory_info.allocationSize = 0;
19983 memory_info.memoryTypeIndex = 0;
19984
19985 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
19986 memory_info.allocationSize = memory_reqs.size;
19987 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
19988 ASSERT_TRUE(pass);
19989
19990 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
19991 ASSERT_VK_SUCCESS(err);
19992 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
19993 ASSERT_VK_SUCCESS(err);
19994
19995 VkBufferViewCreateInfo buff_view_ci = {};
19996 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
19997 buff_view_ci.buffer = buffer;
19998 buff_view_ci.format = VK_FORMAT_R8_UNORM;
19999 buff_view_ci.range = VK_WHOLE_SIZE;
20000 VkBufferView buffer_view;
20001 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buffer_view);
20002
20003 VkDescriptorPoolSize ds_type_count = {};
20004 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
20005 ds_type_count.descriptorCount = 1;
20006
20007 VkDescriptorPoolCreateInfo ds_pool_ci = {};
20008 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
20009 ds_pool_ci.pNext = NULL;
20010 ds_pool_ci.maxSets = 1;
20011 ds_pool_ci.poolSizeCount = 1;
20012 ds_pool_ci.pPoolSizes = &ds_type_count;
20013
20014 VkDescriptorPool ds_pool;
20015 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
20016 ASSERT_VK_SUCCESS(err);
20017
20018 VkDescriptorSetLayoutBinding dsl_binding = {};
20019 dsl_binding.binding = 0;
20020 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
20021 dsl_binding.descriptorCount = 1;
20022 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
20023 dsl_binding.pImmutableSamplers = NULL;
20024
20025 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
20026 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
20027 ds_layout_ci.pNext = NULL;
20028 ds_layout_ci.bindingCount = 1;
20029 ds_layout_ci.pBindings = &dsl_binding;
20030 VkDescriptorSetLayout ds_layout;
20031 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
20032 ASSERT_VK_SUCCESS(err);
20033
20034 VkDescriptorSet descriptor_set;
20035 VkDescriptorSetAllocateInfo alloc_info = {};
20036 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
20037 alloc_info.descriptorSetCount = 1;
20038 alloc_info.descriptorPool = ds_pool;
20039 alloc_info.pSetLayouts = &ds_layout;
20040 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
20041 ASSERT_VK_SUCCESS(err);
20042
20043 VkWriteDescriptorSet descriptor_write;
20044 memset(&descriptor_write, 0, sizeof(descriptor_write));
20045 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
20046 descriptor_write.dstSet = descriptor_set;
20047 descriptor_write.dstBinding = 0;
20048 descriptor_write.descriptorCount = 1;
20049 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
20050 descriptor_write.pTexelBufferView = &buffer_view;
20051
20052 // Set pImageInfo and pBufferInfo to invalid values, which should be
20053 // ignored for descriptorType ==
20054 // VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER.
20055 // This will most likely produce a crash if the parameter_validation
20056 // layer
20057 // does not correctly ignore pImageInfo and pBufferInfo.
20058 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
20059 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
20060
20061 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
20062
20063 m_errorMonitor->VerifyNotFound();
20064
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020065 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
20066 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
20067 vkDestroyBufferView(m_device->device(), buffer_view, NULL);
20068 vkDestroyBuffer(m_device->device(), buffer, NULL);
20069 vkFreeMemory(m_device->device(), buffer_memory, NULL);
20070 }
20071}
20072
Tobin Ehlis8893af82017-05-08 12:52:25 -060020073TEST_F(VkPositiveLayerTest, ImmutableSamplerOnlyDescriptor) {
20074 TEST_DESCRIPTION(
20075 "Bind a DescriptorSet with only an immutable sampler"
20076 "and make sure that we don't warn for no update.");
20077
20078 ASSERT_NO_FATAL_FAILURE(Init());
20079 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20080
20081 VkDescriptorPoolSize ds_type_count = {};
20082 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
20083 ds_type_count.descriptorCount = 1;
20084
20085 VkDescriptorPoolCreateInfo ds_pool_ci = {};
20086 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
20087 ds_pool_ci.maxSets = 1;
20088 ds_pool_ci.poolSizeCount = 1;
20089 ds_pool_ci.pPoolSizes = &ds_type_count;
20090
20091 VkDescriptorPool ds_pool;
20092 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
20093 ASSERT_VK_SUCCESS(err);
20094
20095 VkSamplerCreateInfo sampler_ci = {};
20096 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
20097 sampler_ci.pNext = NULL;
20098 sampler_ci.magFilter = VK_FILTER_NEAREST;
20099 sampler_ci.minFilter = VK_FILTER_NEAREST;
20100 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
20101 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
20102 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
20103 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
20104 sampler_ci.mipLodBias = 1.0;
20105 sampler_ci.anisotropyEnable = VK_FALSE;
20106 sampler_ci.maxAnisotropy = 1;
20107 sampler_ci.compareEnable = VK_FALSE;
20108 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
20109 sampler_ci.minLod = 1.0;
20110 sampler_ci.maxLod = 1.0;
20111 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
20112 sampler_ci.unnormalizedCoordinates = VK_FALSE;
20113 VkSampler sampler;
20114
20115 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
20116 ASSERT_VK_SUCCESS(err);
20117
20118 VkDescriptorSetLayoutBinding layout_binding = {};
20119 layout_binding.binding = 0;
20120 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
20121 layout_binding.descriptorCount = 1;
20122 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
20123 layout_binding.pImmutableSamplers = static_cast<VkSampler *>(&sampler);
20124
20125 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
20126 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
20127 ds_layout_ci.bindingCount = 1;
20128 ds_layout_ci.pBindings = &layout_binding;
20129 VkDescriptorSetLayout ds_layout;
20130 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
20131 ASSERT_VK_SUCCESS(err);
20132
20133 VkDescriptorSetAllocateInfo alloc_info = {};
20134 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
20135 alloc_info.descriptorSetCount = 1;
20136 alloc_info.descriptorPool = ds_pool;
20137 alloc_info.pSetLayouts = &ds_layout;
20138 VkDescriptorSet descriptor_set;
20139 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
20140 ASSERT_VK_SUCCESS(err);
20141
20142 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
20143 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
20144 pipeline_layout_ci.pNext = NULL;
20145 pipeline_layout_ci.setLayoutCount = 1;
20146 pipeline_layout_ci.pSetLayouts = &ds_layout;
20147
20148 VkPipelineLayout pipeline_layout;
20149 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
20150 ASSERT_VK_SUCCESS(err);
20151
20152 m_errorMonitor->ExpectSuccess();
20153 m_commandBuffer->BeginCommandBuffer();
20154 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
20155
20156 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
20157 &descriptor_set, 0, nullptr);
20158 m_errorMonitor->VerifyNotFound();
20159
20160 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
20161 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
20162 vkDestroySampler(m_device->device(), sampler, NULL);
20163 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
20164}
20165
Tobin Ehlisf7428442016-10-25 07:58:24 -060020166TEST_F(VkLayerTest, DuplicateDescriptorBinding) {
20167 TEST_DESCRIPTION("Create a descriptor set layout with a duplicate binding number.");
20168
Tony Barbour1fa09702017-03-16 12:09:08 -060020169 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisf7428442016-10-25 07:58:24 -060020170 // Create layout where two binding #s are "1"
20171 static const uint32_t NUM_BINDINGS = 3;
20172 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
20173 dsl_binding[0].binding = 1;
20174 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
20175 dsl_binding[0].descriptorCount = 1;
20176 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
20177 dsl_binding[0].pImmutableSamplers = NULL;
20178 dsl_binding[1].binding = 0;
20179 dsl_binding[1].descriptorCount = 1;
20180 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
20181 dsl_binding[1].descriptorCount = 1;
20182 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
20183 dsl_binding[1].pImmutableSamplers = NULL;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020184 dsl_binding[2].binding = 1; // Duplicate binding should cause error
Tobin Ehlisf7428442016-10-25 07:58:24 -060020185 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
20186 dsl_binding[2].descriptorCount = 1;
20187 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
20188 dsl_binding[2].pImmutableSamplers = NULL;
20189
20190 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
20191 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
20192 ds_layout_ci.pNext = NULL;
20193 ds_layout_ci.bindingCount = NUM_BINDINGS;
20194 ds_layout_ci.pBindings = dsl_binding;
20195 VkDescriptorSetLayout ds_layout;
20196 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02345);
20197 vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
20198 m_errorMonitor->VerifyFound();
20199}
20200
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060020201TEST_F(VkLayerTest, ViewportAndScissorBoundsChecking) {
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060020202 TEST_DESCRIPTION("Verify errors are detected on misuse of SetViewport and SetScissor.");
20203
Tony Barbour1fa09702017-03-16 12:09:08 -060020204 ASSERT_NO_FATAL_FAILURE(Init());
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060020205
Tony Barbour552f6c02016-12-21 14:34:07 -070020206 m_commandBuffer->BeginCommandBuffer();
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060020207
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060020208 const VkPhysicalDeviceLimits &limits = m_device->props.limits;
20209
20210 {
20211 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01448);
20212 VkViewport viewport = {0, 0, static_cast<float>(limits.maxViewportDimensions[0] + 1), 16, 0, 1};
20213 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
20214 m_errorMonitor->VerifyFound();
20215 }
20216
20217 {
20218 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01449);
20219 VkViewport viewport = {0, 0, 16, static_cast<float>(limits.maxViewportDimensions[1] + 1), 0, 1};
20220 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
20221 m_errorMonitor->VerifyFound();
20222 }
20223
20224 {
20225 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
20226 VkViewport viewport = {limits.viewportBoundsRange[0] - 1, 0, 16, 16, 0, 1};
20227 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
20228 m_errorMonitor->VerifyFound();
20229 }
20230
20231 {
20232 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
20233 VkViewport viewport = {0, limits.viewportBoundsRange[0] - 1, 16, 16, 0, 1};
20234 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
20235 m_errorMonitor->VerifyFound();
20236 }
20237
20238 {
20239 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01451);
20240 VkViewport viewport = {limits.viewportBoundsRange[1], 0, 16, 16, 0, 1};
20241 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
20242 m_errorMonitor->VerifyFound();
20243 }
20244
20245 {
20246 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01452);
20247 VkViewport viewport = {0, limits.viewportBoundsRange[1], 16, 16, 0, 1};
20248 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
20249 m_errorMonitor->VerifyFound();
20250 }
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060020251
20252 {
20253 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
20254 VkRect2D scissor = {{-1, 0}, {16, 16}};
20255 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
20256 m_errorMonitor->VerifyFound();
20257 }
20258
20259 {
20260 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
20261 VkRect2D scissor = {{0, -2}, {16, 16}};
20262 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
20263 m_errorMonitor->VerifyFound();
20264 }
20265
20266 {
20267 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01490);
20268 VkRect2D scissor = {{100, 100}, {INT_MAX, 16}};
20269 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
20270 m_errorMonitor->VerifyFound();
20271 }
20272
20273 {
20274 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01491);
20275 VkRect2D scissor = {{100, 100}, {16, INT_MAX}};
20276 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
20277 m_errorMonitor->VerifyFound();
20278 }
20279
Tony Barbour552f6c02016-12-21 14:34:07 -070020280 m_commandBuffer->EndCommandBuffer();
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060020281}
20282
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020283// This is a positive test. No failures are expected.
20284TEST_F(VkPositiveLayerTest, EmptyDescriptorUpdateTest) {
20285 TEST_DESCRIPTION("Update last descriptor in a set that includes an empty binding");
20286 VkResult err;
20287
Tony Barbour1fa09702017-03-16 12:09:08 -060020288 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020289 m_errorMonitor->ExpectSuccess();
20290 VkDescriptorPoolSize ds_type_count = {};
20291 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
20292 ds_type_count.descriptorCount = 2;
20293
20294 VkDescriptorPoolCreateInfo ds_pool_ci = {};
20295 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
20296 ds_pool_ci.pNext = NULL;
20297 ds_pool_ci.maxSets = 1;
20298 ds_pool_ci.poolSizeCount = 1;
20299 ds_pool_ci.pPoolSizes = &ds_type_count;
20300
20301 VkDescriptorPool ds_pool;
20302 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
20303 ASSERT_VK_SUCCESS(err);
20304
20305 // Create layout with two uniform buffer descriptors w/ empty binding between them
20306 static const uint32_t NUM_BINDINGS = 3;
20307 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
20308 dsl_binding[0].binding = 0;
20309 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
20310 dsl_binding[0].descriptorCount = 1;
20311 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
20312 dsl_binding[0].pImmutableSamplers = NULL;
20313 dsl_binding[1].binding = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020314 dsl_binding[1].descriptorCount = 0; // empty binding
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020315 dsl_binding[2].binding = 2;
20316 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
20317 dsl_binding[2].descriptorCount = 1;
20318 dsl_binding[2].stageFlags = VK_SHADER_STAGE_ALL;
20319 dsl_binding[2].pImmutableSamplers = NULL;
20320
20321 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
20322 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
20323 ds_layout_ci.pNext = NULL;
20324 ds_layout_ci.bindingCount = NUM_BINDINGS;
20325 ds_layout_ci.pBindings = dsl_binding;
20326 VkDescriptorSetLayout ds_layout;
20327 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
20328 ASSERT_VK_SUCCESS(err);
20329
20330 VkDescriptorSet descriptor_set = {};
20331 VkDescriptorSetAllocateInfo alloc_info = {};
20332 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
20333 alloc_info.descriptorSetCount = 1;
20334 alloc_info.descriptorPool = ds_pool;
20335 alloc_info.pSetLayouts = &ds_layout;
20336 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
20337 ASSERT_VK_SUCCESS(err);
20338
20339 // Create a buffer to be used for update
20340 VkBufferCreateInfo buff_ci = {};
20341 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
20342 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
20343 buff_ci.size = 256;
20344 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
20345 VkBuffer buffer;
20346 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
20347 ASSERT_VK_SUCCESS(err);
20348 // Have to bind memory to buffer before descriptor update
20349 VkMemoryAllocateInfo mem_alloc = {};
20350 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
20351 mem_alloc.pNext = NULL;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020352 mem_alloc.allocationSize = 512; // one allocation for both buffers
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020353 mem_alloc.memoryTypeIndex = 0;
20354
20355 VkMemoryRequirements mem_reqs;
20356 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
20357 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
20358 if (!pass) {
20359 vkDestroyBuffer(m_device->device(), buffer, NULL);
20360 return;
20361 }
20362
20363 VkDeviceMemory mem;
20364 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
20365 ASSERT_VK_SUCCESS(err);
20366 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
20367 ASSERT_VK_SUCCESS(err);
20368
20369 // Only update the descriptor at binding 2
20370 VkDescriptorBufferInfo buff_info = {};
20371 buff_info.buffer = buffer;
20372 buff_info.offset = 0;
20373 buff_info.range = VK_WHOLE_SIZE;
20374 VkWriteDescriptorSet descriptor_write = {};
20375 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
20376 descriptor_write.dstBinding = 2;
20377 descriptor_write.descriptorCount = 1;
20378 descriptor_write.pTexelBufferView = nullptr;
20379 descriptor_write.pBufferInfo = &buff_info;
20380 descriptor_write.pImageInfo = nullptr;
20381 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
20382 descriptor_write.dstSet = descriptor_set;
20383
20384 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
20385
20386 m_errorMonitor->VerifyNotFound();
20387 // Cleanup
20388 vkFreeMemory(m_device->device(), mem, NULL);
20389 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
20390 vkDestroyBuffer(m_device->device(), buffer, NULL);
20391 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
20392}
20393
20394// This is a positive test. No failures are expected.
20395TEST_F(VkPositiveLayerTest, TestAliasedMemoryTracking) {
20396 VkResult err;
20397 bool pass;
20398
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020399 TEST_DESCRIPTION(
20400 "Create a buffer, allocate memory, bind memory, destroy "
20401 "the buffer, create an image, and bind the same memory to "
20402 "it");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020403
20404 m_errorMonitor->ExpectSuccess();
20405
Tony Barbour1fa09702017-03-16 12:09:08 -060020406 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020407
20408 VkBuffer buffer;
20409 VkImage image;
20410 VkDeviceMemory mem;
20411 VkMemoryRequirements mem_reqs;
20412
20413 VkBufferCreateInfo buf_info = {};
20414 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
20415 buf_info.pNext = NULL;
20416 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
20417 buf_info.size = 256;
20418 buf_info.queueFamilyIndexCount = 0;
20419 buf_info.pQueueFamilyIndices = NULL;
20420 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
20421 buf_info.flags = 0;
20422 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
20423 ASSERT_VK_SUCCESS(err);
20424
20425 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
20426
20427 VkMemoryAllocateInfo alloc_info = {};
20428 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
20429 alloc_info.pNext = NULL;
20430 alloc_info.memoryTypeIndex = 0;
Dave Houlton9dae7ec2017-03-01 16:23:25 -070020431
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020432 // Ensure memory is big enough for both bindings
20433 alloc_info.allocationSize = 0x10000;
20434
20435 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
20436 if (!pass) {
20437 vkDestroyBuffer(m_device->device(), buffer, NULL);
20438 return;
20439 }
20440
20441 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
20442 ASSERT_VK_SUCCESS(err);
20443
20444 uint8_t *pData;
20445 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
20446 ASSERT_VK_SUCCESS(err);
20447
20448 memset(pData, 0xCADECADE, static_cast<size_t>(mem_reqs.size));
20449
20450 vkUnmapMemory(m_device->device(), mem);
20451
20452 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
20453 ASSERT_VK_SUCCESS(err);
20454
20455 // NOW, destroy the buffer. Obviously, the resource no longer occupies this
20456 // memory. In fact, it was never used by the GPU.
20457 // Just be be sure, wait for idle.
20458 vkDestroyBuffer(m_device->device(), buffer, NULL);
20459 vkDeviceWaitIdle(m_device->device());
20460
Tobin Ehlis6a005702016-12-28 15:25:56 -070020461 // Use optimal as some platforms report linear support but then fail image creation
20462 VkImageTiling image_tiling = VK_IMAGE_TILING_OPTIMAL;
20463 VkImageFormatProperties image_format_properties;
20464 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D, image_tiling,
20465 VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0, &image_format_properties);
20466 if (image_format_properties.maxExtent.width == 0) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070020467 printf(" Image format not supported; skipped.\n");
Tobin Ehlis6a005702016-12-28 15:25:56 -070020468 vkFreeMemory(m_device->device(), mem, NULL);
20469 return;
20470 }
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020471 VkImageCreateInfo image_create_info = {};
20472 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
20473 image_create_info.pNext = NULL;
20474 image_create_info.imageType = VK_IMAGE_TYPE_2D;
20475 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
20476 image_create_info.extent.width = 64;
20477 image_create_info.extent.height = 64;
20478 image_create_info.extent.depth = 1;
20479 image_create_info.mipLevels = 1;
20480 image_create_info.arrayLayers = 1;
20481 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis6a005702016-12-28 15:25:56 -070020482 image_create_info.tiling = image_tiling;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020483 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
20484 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
20485 image_create_info.queueFamilyIndexCount = 0;
20486 image_create_info.pQueueFamilyIndices = NULL;
20487 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
20488 image_create_info.flags = 0;
20489
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020490 /* Create a mappable image. It will be the texture if linear images are ok
Dave Houlton9dae7ec2017-03-01 16:23:25 -070020491 * to be textures or it will be the staging image if they are not.
20492 */
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020493 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
20494 ASSERT_VK_SUCCESS(err);
20495
20496 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
20497
Tobin Ehlis6a005702016-12-28 15:25:56 -070020498 VkMemoryAllocateInfo mem_alloc = {};
20499 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
20500 mem_alloc.pNext = NULL;
20501 mem_alloc.allocationSize = 0;
20502 mem_alloc.memoryTypeIndex = 0;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020503 mem_alloc.allocationSize = mem_reqs.size;
20504
20505 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
20506 if (!pass) {
Tobin Ehlis6a005702016-12-28 15:25:56 -070020507 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020508 vkDestroyImage(m_device->device(), image, NULL);
20509 return;
20510 }
20511
20512 // VALIDATION FAILURE:
20513 err = vkBindImageMemory(m_device->device(), image, mem, 0);
20514 ASSERT_VK_SUCCESS(err);
20515
20516 m_errorMonitor->VerifyNotFound();
20517
20518 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020519 vkDestroyImage(m_device->device(), image, NULL);
20520}
20521
Tony Barbourab713912017-02-02 14:17:35 -070020522// This is a positive test. No failures are expected.
20523TEST_F(VkPositiveLayerTest, TestDestroyFreeNullHandles) {
20524 VkResult err;
20525
20526 TEST_DESCRIPTION(
20527 "Call all applicable destroy and free routines with NULL"
20528 "handles, expecting no validation errors");
20529
20530 m_errorMonitor->ExpectSuccess();
20531
Tony Barbour1fa09702017-03-16 12:09:08 -060020532 ASSERT_NO_FATAL_FAILURE(Init());
Tony Barbourab713912017-02-02 14:17:35 -070020533 vkDestroyBuffer(m_device->device(), VK_NULL_HANDLE, NULL);
20534 vkDestroyBufferView(m_device->device(), VK_NULL_HANDLE, NULL);
20535 vkDestroyCommandPool(m_device->device(), VK_NULL_HANDLE, NULL);
20536 vkDestroyDescriptorPool(m_device->device(), VK_NULL_HANDLE, NULL);
20537 vkDestroyDescriptorSetLayout(m_device->device(), VK_NULL_HANDLE, NULL);
20538 vkDestroyDevice(VK_NULL_HANDLE, NULL);
20539 vkDestroyEvent(m_device->device(), VK_NULL_HANDLE, NULL);
20540 vkDestroyFence(m_device->device(), VK_NULL_HANDLE, NULL);
20541 vkDestroyFramebuffer(m_device->device(), VK_NULL_HANDLE, NULL);
20542 vkDestroyImage(m_device->device(), VK_NULL_HANDLE, NULL);
20543 vkDestroyImageView(m_device->device(), VK_NULL_HANDLE, NULL);
20544 vkDestroyInstance(VK_NULL_HANDLE, NULL);
20545 vkDestroyPipeline(m_device->device(), VK_NULL_HANDLE, NULL);
20546 vkDestroyPipelineCache(m_device->device(), VK_NULL_HANDLE, NULL);
20547 vkDestroyPipelineLayout(m_device->device(), VK_NULL_HANDLE, NULL);
20548 vkDestroyQueryPool(m_device->device(), VK_NULL_HANDLE, NULL);
20549 vkDestroyRenderPass(m_device->device(), VK_NULL_HANDLE, NULL);
20550 vkDestroySampler(m_device->device(), VK_NULL_HANDLE, NULL);
20551 vkDestroySemaphore(m_device->device(), VK_NULL_HANDLE, NULL);
20552 vkDestroyShaderModule(m_device->device(), VK_NULL_HANDLE, NULL);
20553
20554 VkCommandPool command_pool;
20555 VkCommandPoolCreateInfo pool_create_info{};
20556 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20557 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20558 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20559 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20560 VkCommandBuffer command_buffers[3] = {};
20561 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20562 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20563 command_buffer_allocate_info.commandPool = command_pool;
20564 command_buffer_allocate_info.commandBufferCount = 1;
20565 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20566 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffers[1]);
20567 vkFreeCommandBuffers(m_device->device(), command_pool, 3, command_buffers);
20568 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20569
20570 VkDescriptorPoolSize ds_type_count = {};
20571 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
20572 ds_type_count.descriptorCount = 1;
20573
20574 VkDescriptorPoolCreateInfo ds_pool_ci = {};
20575 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
20576 ds_pool_ci.pNext = NULL;
20577 ds_pool_ci.maxSets = 1;
20578 ds_pool_ci.poolSizeCount = 1;
20579 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
20580 ds_pool_ci.pPoolSizes = &ds_type_count;
20581
20582 VkDescriptorPool ds_pool;
20583 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
20584 ASSERT_VK_SUCCESS(err);
20585
20586 VkDescriptorSetLayoutBinding dsl_binding = {};
20587 dsl_binding.binding = 2;
20588 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
20589 dsl_binding.descriptorCount = 1;
20590 dsl_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
20591 dsl_binding.pImmutableSamplers = NULL;
20592 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
20593 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
20594 ds_layout_ci.pNext = NULL;
20595 ds_layout_ci.bindingCount = 1;
20596 ds_layout_ci.pBindings = &dsl_binding;
20597 VkDescriptorSetLayout ds_layout;
20598 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
20599 ASSERT_VK_SUCCESS(err);
20600
20601 VkDescriptorSet descriptor_sets[3] = {};
20602 VkDescriptorSetAllocateInfo alloc_info = {};
20603 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
20604 alloc_info.descriptorSetCount = 1;
20605 alloc_info.descriptorPool = ds_pool;
20606 alloc_info.pSetLayouts = &ds_layout;
20607 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_sets[1]);
20608 ASSERT_VK_SUCCESS(err);
20609 vkFreeDescriptorSets(m_device->device(), ds_pool, 3, descriptor_sets);
20610 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
20611 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
20612
20613 vkFreeMemory(m_device->device(), VK_NULL_HANDLE, NULL);
20614
20615 m_errorMonitor->VerifyNotFound();
20616}
20617
Tony Barbour626994c2017-02-08 15:29:37 -070020618TEST_F(VkPositiveLayerTest, QueueSubmitSemaphoresAndLayoutTracking) {
Tony Barboure0c5cc92017-02-08 13:53:39 -070020619 TEST_DESCRIPTION("Submit multiple command buffers with chained semaphore signals and layout transitions");
Tony Barbour626994c2017-02-08 15:29:37 -070020620
20621 m_errorMonitor->ExpectSuccess();
20622
Tony Barbour1fa09702017-03-16 12:09:08 -060020623 ASSERT_NO_FATAL_FAILURE(Init());
Tony Barbour626994c2017-02-08 15:29:37 -070020624 VkCommandBuffer cmd_bufs[4];
20625 VkCommandBufferAllocateInfo alloc_info;
20626 alloc_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20627 alloc_info.pNext = NULL;
20628 alloc_info.commandBufferCount = 4;
Mike Schuchardt06304c22017-03-01 17:09:09 -070020629 alloc_info.commandPool = m_commandPool->handle();
Tony Barbour626994c2017-02-08 15:29:37 -070020630 alloc_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20631 vkAllocateCommandBuffers(m_device->device(), &alloc_info, cmd_bufs);
20632 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060020633 image.Init(128, 128, 1, VK_FORMAT_B8G8R8A8_UNORM,
Mike Weiblen62d08a32017-03-07 22:18:27 -070020634 (VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT),
20635 VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbour626994c2017-02-08 15:29:37 -070020636 ASSERT_TRUE(image.initialized());
20637 VkCommandBufferBeginInfo cb_binfo;
20638 cb_binfo.pNext = NULL;
20639 cb_binfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20640 cb_binfo.pInheritanceInfo = VK_NULL_HANDLE;
20641 cb_binfo.flags = 0;
20642 // Use 4 command buffers, each with an image layout transition, ColorAO->General->ColorAO->TransferSrc->TransferDst
20643 vkBeginCommandBuffer(cmd_bufs[0], &cb_binfo);
20644 VkImageMemoryBarrier img_barrier = {};
20645 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
20646 img_barrier.pNext = NULL;
20647 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
20648 img_barrier.dstAccessMask = VK_ACCESS_HOST_WRITE_BIT;
20649 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
20650 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
20651 img_barrier.image = image.handle();
20652 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
20653 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
20654 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
20655 img_barrier.subresourceRange.baseArrayLayer = 0;
20656 img_barrier.subresourceRange.baseMipLevel = 0;
20657 img_barrier.subresourceRange.layerCount = 1;
20658 img_barrier.subresourceRange.levelCount = 1;
20659 vkCmdPipelineBarrier(cmd_bufs[0], VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 0, nullptr, 0, nullptr, 1,
20660 &img_barrier);
20661 vkEndCommandBuffer(cmd_bufs[0]);
20662 vkBeginCommandBuffer(cmd_bufs[1], &cb_binfo);
20663 img_barrier.oldLayout = VK_IMAGE_LAYOUT_GENERAL;
20664 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
20665 vkCmdPipelineBarrier(cmd_bufs[1], VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 0, nullptr, 0, nullptr, 1,
20666 &img_barrier);
20667 vkEndCommandBuffer(cmd_bufs[1]);
20668 vkBeginCommandBuffer(cmd_bufs[2], &cb_binfo);
20669 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
20670 img_barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
20671 vkCmdPipelineBarrier(cmd_bufs[2], VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 0, nullptr, 0, nullptr, 1,
20672 &img_barrier);
20673 vkEndCommandBuffer(cmd_bufs[2]);
20674 vkBeginCommandBuffer(cmd_bufs[3], &cb_binfo);
20675 img_barrier.oldLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
20676 img_barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
20677 vkCmdPipelineBarrier(cmd_bufs[3], VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 0, nullptr, 0, nullptr, 1,
20678 &img_barrier);
20679 vkEndCommandBuffer(cmd_bufs[3]);
20680
20681 // Submit 4 command buffers in 3 submits, with submits 2 and 3 waiting for semaphores from submits 1 and 2
20682 VkSemaphore semaphore1, semaphore2;
20683 VkSemaphoreCreateInfo semaphore_create_info{};
20684 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
20685 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore1);
20686 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore2);
20687 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
20688 VkSubmitInfo submit_info[3];
20689 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20690 submit_info[0].pNext = nullptr;
20691 submit_info[0].commandBufferCount = 1;
20692 submit_info[0].pCommandBuffers = &cmd_bufs[0];
20693 submit_info[0].signalSemaphoreCount = 1;
20694 submit_info[0].pSignalSemaphores = &semaphore1;
20695 submit_info[0].waitSemaphoreCount = 0;
20696 submit_info[0].pWaitDstStageMask = nullptr;
20697 submit_info[0].pWaitDstStageMask = flags;
20698 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20699 submit_info[1].pNext = nullptr;
20700 submit_info[1].commandBufferCount = 1;
20701 submit_info[1].pCommandBuffers = &cmd_bufs[1];
20702 submit_info[1].waitSemaphoreCount = 1;
20703 submit_info[1].pWaitSemaphores = &semaphore1;
20704 submit_info[1].signalSemaphoreCount = 1;
20705 submit_info[1].pSignalSemaphores = &semaphore2;
20706 submit_info[1].pWaitDstStageMask = flags;
20707 submit_info[2].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20708 submit_info[2].pNext = nullptr;
20709 submit_info[2].commandBufferCount = 2;
20710 submit_info[2].pCommandBuffers = &cmd_bufs[2];
20711 submit_info[2].waitSemaphoreCount = 1;
20712 submit_info[2].pWaitSemaphores = &semaphore2;
20713 submit_info[2].signalSemaphoreCount = 0;
20714 submit_info[2].pSignalSemaphores = nullptr;
20715 submit_info[2].pWaitDstStageMask = flags;
20716 vkQueueSubmit(m_device->m_queue, 3, submit_info, VK_NULL_HANDLE);
20717 vkQueueWaitIdle(m_device->m_queue);
20718
20719 vkDestroySemaphore(m_device->device(), semaphore1, NULL);
20720 vkDestroySemaphore(m_device->device(), semaphore2, NULL);
20721 m_errorMonitor->VerifyNotFound();
20722}
20723
Tobin Ehlis953e8392016-11-17 10:54:13 -070020724TEST_F(VkPositiveLayerTest, DynamicOffsetWithInactiveBinding) {
20725 // Create a descriptorSet w/ dynamic descriptors where 1 binding is inactive
20726 // We previously had a bug where dynamic offset of inactive bindings was still being used
20727 VkResult err;
20728 m_errorMonitor->ExpectSuccess();
20729
Tony Barbour1fa09702017-03-16 12:09:08 -060020730 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis953e8392016-11-17 10:54:13 -070020731 ASSERT_NO_FATAL_FAILURE(InitViewport());
20732 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20733
20734 VkDescriptorPoolSize ds_type_count = {};
20735 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
20736 ds_type_count.descriptorCount = 3;
20737
20738 VkDescriptorPoolCreateInfo ds_pool_ci = {};
20739 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
20740 ds_pool_ci.pNext = NULL;
20741 ds_pool_ci.maxSets = 1;
20742 ds_pool_ci.poolSizeCount = 1;
20743 ds_pool_ci.pPoolSizes = &ds_type_count;
20744
20745 VkDescriptorPool ds_pool;
20746 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
20747 ASSERT_VK_SUCCESS(err);
20748
20749 const uint32_t BINDING_COUNT = 3;
20750 VkDescriptorSetLayoutBinding dsl_binding[BINDING_COUNT] = {};
Tobin Ehlis0050fba2016-11-30 10:22:02 -070020751 dsl_binding[0].binding = 2;
Tobin Ehlis953e8392016-11-17 10:54:13 -070020752 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
20753 dsl_binding[0].descriptorCount = 1;
20754 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
20755 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis0050fba2016-11-30 10:22:02 -070020756 dsl_binding[1].binding = 0;
Tobin Ehlis953e8392016-11-17 10:54:13 -070020757 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
20758 dsl_binding[1].descriptorCount = 1;
20759 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
20760 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis0050fba2016-11-30 10:22:02 -070020761 dsl_binding[2].binding = 1;
Tobin Ehlis953e8392016-11-17 10:54:13 -070020762 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
20763 dsl_binding[2].descriptorCount = 1;
20764 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
20765 dsl_binding[2].pImmutableSamplers = NULL;
20766
20767 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
20768 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
20769 ds_layout_ci.pNext = NULL;
20770 ds_layout_ci.bindingCount = BINDING_COUNT;
20771 ds_layout_ci.pBindings = dsl_binding;
20772 VkDescriptorSetLayout ds_layout;
20773 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
20774 ASSERT_VK_SUCCESS(err);
20775
20776 VkDescriptorSet descriptor_set;
20777 VkDescriptorSetAllocateInfo alloc_info = {};
20778 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
20779 alloc_info.descriptorSetCount = 1;
20780 alloc_info.descriptorPool = ds_pool;
20781 alloc_info.pSetLayouts = &ds_layout;
20782 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
20783 ASSERT_VK_SUCCESS(err);
20784
20785 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
20786 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
20787 pipeline_layout_ci.pNext = NULL;
20788 pipeline_layout_ci.setLayoutCount = 1;
20789 pipeline_layout_ci.pSetLayouts = &ds_layout;
20790
20791 VkPipelineLayout pipeline_layout;
20792 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
20793 ASSERT_VK_SUCCESS(err);
20794
20795 // Create two buffers to update the descriptors with
20796 // The first will be 2k and used for bindings 0 & 1, the second is 1k for binding 2
20797 uint32_t qfi = 0;
20798 VkBufferCreateInfo buffCI = {};
20799 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
20800 buffCI.size = 2048;
20801 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
20802 buffCI.queueFamilyIndexCount = 1;
20803 buffCI.pQueueFamilyIndices = &qfi;
20804
20805 VkBuffer dyub1;
20806 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub1);
20807 ASSERT_VK_SUCCESS(err);
20808 // buffer2
20809 buffCI.size = 1024;
20810 VkBuffer dyub2;
20811 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub2);
20812 ASSERT_VK_SUCCESS(err);
20813 // Allocate memory and bind to buffers
20814 VkMemoryAllocateInfo mem_alloc[2] = {};
20815 mem_alloc[0].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
20816 mem_alloc[0].pNext = NULL;
20817 mem_alloc[0].memoryTypeIndex = 0;
20818 mem_alloc[1].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
20819 mem_alloc[1].pNext = NULL;
20820 mem_alloc[1].memoryTypeIndex = 0;
20821
20822 VkMemoryRequirements mem_reqs1;
20823 vkGetBufferMemoryRequirements(m_device->device(), dyub1, &mem_reqs1);
20824 VkMemoryRequirements mem_reqs2;
20825 vkGetBufferMemoryRequirements(m_device->device(), dyub2, &mem_reqs2);
20826 mem_alloc[0].allocationSize = mem_reqs1.size;
20827 bool pass = m_device->phy().set_memory_type(mem_reqs1.memoryTypeBits, &mem_alloc[0], 0);
20828 mem_alloc[1].allocationSize = mem_reqs2.size;
20829 pass &= m_device->phy().set_memory_type(mem_reqs2.memoryTypeBits, &mem_alloc[1], 0);
20830 if (!pass) {
20831 vkDestroyBuffer(m_device->device(), dyub1, NULL);
20832 vkDestroyBuffer(m_device->device(), dyub2, NULL);
20833 return;
20834 }
20835
20836 VkDeviceMemory mem1;
20837 err = vkAllocateMemory(m_device->device(), &mem_alloc[0], NULL, &mem1);
20838 ASSERT_VK_SUCCESS(err);
20839 err = vkBindBufferMemory(m_device->device(), dyub1, mem1, 0);
20840 ASSERT_VK_SUCCESS(err);
20841 VkDeviceMemory mem2;
20842 err = vkAllocateMemory(m_device->device(), &mem_alloc[1], NULL, &mem2);
20843 ASSERT_VK_SUCCESS(err);
20844 err = vkBindBufferMemory(m_device->device(), dyub2, mem2, 0);
20845 ASSERT_VK_SUCCESS(err);
20846 // Update descriptors
20847 VkDescriptorBufferInfo buff_info[BINDING_COUNT] = {};
20848 buff_info[0].buffer = dyub1;
20849 buff_info[0].offset = 0;
20850 buff_info[0].range = 256;
20851 buff_info[1].buffer = dyub1;
20852 buff_info[1].offset = 256;
20853 buff_info[1].range = 512;
20854 buff_info[2].buffer = dyub2;
20855 buff_info[2].offset = 0;
20856 buff_info[2].range = 512;
20857
20858 VkWriteDescriptorSet descriptor_write;
20859 memset(&descriptor_write, 0, sizeof(descriptor_write));
20860 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
20861 descriptor_write.dstSet = descriptor_set;
20862 descriptor_write.dstBinding = 0;
20863 descriptor_write.descriptorCount = BINDING_COUNT;
20864 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
20865 descriptor_write.pBufferInfo = buff_info;
20866
20867 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
20868
Tony Barbour552f6c02016-12-21 14:34:07 -070020869 m_commandBuffer->BeginCommandBuffer();
20870 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis953e8392016-11-17 10:54:13 -070020871
20872 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020873 char const *vsSource =
20874 "#version 450\n"
20875 "\n"
20876 "out gl_PerVertex { \n"
20877 " vec4 gl_Position;\n"
20878 "};\n"
20879 "void main(){\n"
20880 " gl_Position = vec4(1);\n"
20881 "}\n";
20882 char const *fsSource =
20883 "#version 450\n"
20884 "\n"
20885 "layout(location=0) out vec4 x;\n"
20886 "layout(set=0) layout(binding=0) uniform foo1 { int x; int y; } bar1;\n"
20887 "layout(set=0) layout(binding=2) uniform foo2 { int x; int y; } bar2;\n"
20888 "void main(){\n"
20889 " x = vec4(bar1.y) + vec4(bar2.y);\n"
20890 "}\n";
Tobin Ehlis953e8392016-11-17 10:54:13 -070020891 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
20892 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
20893 VkPipelineObj pipe(m_device);
20894 pipe.SetViewport(m_viewports);
20895 pipe.SetScissor(m_scissors);
20896 pipe.AddShader(&vs);
20897 pipe.AddShader(&fs);
20898 pipe.AddColorAttachment();
20899 pipe.CreateVKPipeline(pipeline_layout, renderPass());
20900
20901 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
20902 // This update should succeed, but offset of inactive binding 1 oversteps binding 2 buffer size
20903 // we used to have a bug in this case.
20904 uint32_t dyn_off[BINDING_COUNT] = {0, 1024, 256};
20905 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
20906 &descriptor_set, BINDING_COUNT, dyn_off);
20907 Draw(1, 0, 0, 0);
20908 m_errorMonitor->VerifyNotFound();
20909
20910 vkDestroyBuffer(m_device->device(), dyub1, NULL);
20911 vkDestroyBuffer(m_device->device(), dyub2, NULL);
20912 vkFreeMemory(m_device->device(), mem1, NULL);
20913 vkFreeMemory(m_device->device(), mem2, NULL);
20914
20915 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
20916 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
20917 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
20918}
20919
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020920TEST_F(VkPositiveLayerTest, NonCoherentMemoryMapping) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020921 TEST_DESCRIPTION(
20922 "Ensure that validations handling of non-coherent memory "
20923 "mapping while using VK_WHOLE_SIZE does not cause access "
20924 "violations");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020925 VkResult err;
20926 uint8_t *pData;
Tony Barbour1fa09702017-03-16 12:09:08 -060020927 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020928
20929 VkDeviceMemory mem;
20930 VkMemoryRequirements mem_reqs;
20931 mem_reqs.memoryTypeBits = 0xFFFFFFFF;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070020932 const VkDeviceSize atom_size = m_device->props.limits.nonCoherentAtomSize;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020933 VkMemoryAllocateInfo alloc_info = {};
20934 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
20935 alloc_info.pNext = NULL;
20936 alloc_info.memoryTypeIndex = 0;
20937
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070020938 static const VkDeviceSize allocation_size = 32 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020939 alloc_info.allocationSize = allocation_size;
20940
20941 // Find a memory configurations WITHOUT a COHERENT bit, otherwise exit
20942 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 -070020943 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020944 if (!pass) {
20945 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020946 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
20947 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020948 if (!pass) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020949 pass = m_device->phy().set_memory_type(
20950 mem_reqs.memoryTypeBits, &alloc_info,
20951 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT | VK_MEMORY_PROPERTY_HOST_CACHED_BIT,
20952 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020953 if (!pass) {
20954 return;
20955 }
20956 }
20957 }
20958
20959 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
20960 ASSERT_VK_SUCCESS(err);
20961
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070020962 // Map/Flush/Invalidate using WHOLE_SIZE and zero offsets and entire mapped range
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020963 m_errorMonitor->ExpectSuccess();
20964 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
20965 ASSERT_VK_SUCCESS(err);
20966 VkMappedMemoryRange mmr = {};
20967 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
20968 mmr.memory = mem;
20969 mmr.offset = 0;
20970 mmr.size = VK_WHOLE_SIZE;
20971 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
20972 ASSERT_VK_SUCCESS(err);
20973 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
20974 ASSERT_VK_SUCCESS(err);
20975 m_errorMonitor->VerifyNotFound();
20976 vkUnmapMemory(m_device->device(), mem);
20977
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070020978 // Map/Flush/Invalidate using WHOLE_SIZE and an offset and entire mapped range
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020979 m_errorMonitor->ExpectSuccess();
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070020980 err = vkMapMemory(m_device->device(), mem, 5 * atom_size, VK_WHOLE_SIZE, 0, (void **)&pData);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020981 ASSERT_VK_SUCCESS(err);
20982 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
20983 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070020984 mmr.offset = 6 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020985 mmr.size = VK_WHOLE_SIZE;
20986 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
20987 ASSERT_VK_SUCCESS(err);
20988 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
20989 ASSERT_VK_SUCCESS(err);
20990 m_errorMonitor->VerifyNotFound();
20991 vkUnmapMemory(m_device->device(), mem);
20992
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070020993 // Map with offset and size
20994 // Flush/Invalidate subrange of mapped area with offset and size
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020995 m_errorMonitor->ExpectSuccess();
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070020996 err = vkMapMemory(m_device->device(), mem, 3 * atom_size, 9 * atom_size, 0, (void **)&pData);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020997 ASSERT_VK_SUCCESS(err);
20998 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
20999 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070021000 mmr.offset = 4 * atom_size;
21001 mmr.size = 2 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021002 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
21003 ASSERT_VK_SUCCESS(err);
21004 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
21005 ASSERT_VK_SUCCESS(err);
21006 m_errorMonitor->VerifyNotFound();
21007 vkUnmapMemory(m_device->device(), mem);
21008
21009 // Map without offset and flush WHOLE_SIZE with two separate offsets
21010 m_errorMonitor->ExpectSuccess();
21011 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
21012 ASSERT_VK_SUCCESS(err);
21013 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
21014 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070021015 mmr.offset = allocation_size - (4 * atom_size);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021016 mmr.size = VK_WHOLE_SIZE;
21017 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
21018 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070021019 mmr.offset = allocation_size - (6 * atom_size);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021020 mmr.size = VK_WHOLE_SIZE;
21021 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
21022 ASSERT_VK_SUCCESS(err);
21023 m_errorMonitor->VerifyNotFound();
21024 vkUnmapMemory(m_device->device(), mem);
21025
21026 vkFreeMemory(m_device->device(), mem, NULL);
21027}
21028
21029// This is a positive test. We used to expect error in this case but spec now allows it
21030TEST_F(VkPositiveLayerTest, ResetUnsignaledFence) {
21031 m_errorMonitor->ExpectSuccess();
21032 vk_testing::Fence testFence;
21033 VkFenceCreateInfo fenceInfo = {};
21034 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
21035 fenceInfo.pNext = NULL;
21036
Tony Barbour1fa09702017-03-16 12:09:08 -060021037 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021038 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021039 VkFence fences[1] = {testFence.handle()};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021040 VkResult result = vkResetFences(m_device->device(), 1, fences);
21041 ASSERT_VK_SUCCESS(result);
21042
21043 m_errorMonitor->VerifyNotFound();
21044}
21045
21046TEST_F(VkPositiveLayerTest, CommandBufferSimultaneousUseSync) {
21047 m_errorMonitor->ExpectSuccess();
21048
Tony Barbour1fa09702017-03-16 12:09:08 -060021049 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021050 VkResult err;
21051
21052 // Record (empty!) command buffer that can be submitted multiple times
21053 // simultaneously.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021054 VkCommandBufferBeginInfo cbbi = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
21055 VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021056 m_commandBuffer->BeginCommandBuffer(&cbbi);
21057 m_commandBuffer->EndCommandBuffer();
21058
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021059 VkFenceCreateInfo fci = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021060 VkFence fence;
21061 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
21062 ASSERT_VK_SUCCESS(err);
21063
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021064 VkSemaphoreCreateInfo sci = {VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021065 VkSemaphore s1, s2;
21066 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s1);
21067 ASSERT_VK_SUCCESS(err);
21068 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s2);
21069 ASSERT_VK_SUCCESS(err);
21070
21071 // Submit CB once signaling s1, with fence so we can roll forward to its retirement.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021072 VkSubmitInfo si = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &m_commandBuffer->handle(), 1, &s1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021073 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
21074 ASSERT_VK_SUCCESS(err);
21075
21076 // Submit CB again, signaling s2.
21077 si.pSignalSemaphores = &s2;
21078 err = vkQueueSubmit(m_device->m_queue, 1, &si, VK_NULL_HANDLE);
21079 ASSERT_VK_SUCCESS(err);
21080
21081 // Wait for fence.
21082 err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
21083 ASSERT_VK_SUCCESS(err);
21084
21085 // CB is still in flight from second submission, but semaphore s1 is no
21086 // longer in flight. delete it.
21087 vkDestroySemaphore(m_device->device(), s1, nullptr);
21088
21089 m_errorMonitor->VerifyNotFound();
21090
21091 // Force device idle and clean up remaining objects
21092 vkDeviceWaitIdle(m_device->device());
21093 vkDestroySemaphore(m_device->device(), s2, nullptr);
21094 vkDestroyFence(m_device->device(), fence, nullptr);
21095}
21096
21097TEST_F(VkPositiveLayerTest, FenceCreateSignaledWaitHandling) {
21098 m_errorMonitor->ExpectSuccess();
21099
Tony Barbour1fa09702017-03-16 12:09:08 -060021100 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021101 VkResult err;
21102
21103 // A fence created signaled
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021104 VkFenceCreateInfo fci1 = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, VK_FENCE_CREATE_SIGNALED_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021105 VkFence f1;
21106 err = vkCreateFence(m_device->device(), &fci1, nullptr, &f1);
21107 ASSERT_VK_SUCCESS(err);
21108
21109 // A fence created not
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021110 VkFenceCreateInfo fci2 = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021111 VkFence f2;
21112 err = vkCreateFence(m_device->device(), &fci2, nullptr, &f2);
21113 ASSERT_VK_SUCCESS(err);
21114
21115 // Submit the unsignaled fence
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021116 VkSubmitInfo si = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 0, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021117 err = vkQueueSubmit(m_device->m_queue, 1, &si, f2);
21118
21119 // Wait on both fences, with signaled first.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021120 VkFence fences[] = {f1, f2};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021121 vkWaitForFences(m_device->device(), 2, fences, VK_TRUE, UINT64_MAX);
21122
21123 // Should have both retired!
21124 vkDestroyFence(m_device->device(), f1, nullptr);
21125 vkDestroyFence(m_device->device(), f2, nullptr);
21126
21127 m_errorMonitor->VerifyNotFound();
21128}
21129
21130TEST_F(VkPositiveLayerTest, ValidUsage) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021131 TEST_DESCRIPTION(
21132 "Verify that creating an image view from an image with valid usage "
21133 "doesn't generate validation errors");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021134
Tony Barbour1fa09702017-03-16 12:09:08 -060021135 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021136
21137 m_errorMonitor->ExpectSuccess();
21138 // Verify that we can create a view with usage INPUT_ATTACHMENT
21139 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060021140 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 -060021141 ASSERT_TRUE(image.initialized());
21142 VkImageView imageView;
21143 VkImageViewCreateInfo ivci = {};
21144 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
21145 ivci.image = image.handle();
21146 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
21147 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
21148 ivci.subresourceRange.layerCount = 1;
21149 ivci.subresourceRange.baseMipLevel = 0;
21150 ivci.subresourceRange.levelCount = 1;
21151 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
21152
21153 vkCreateImageView(m_device->device(), &ivci, NULL, &imageView);
21154 m_errorMonitor->VerifyNotFound();
21155 vkDestroyImageView(m_device->device(), imageView, NULL);
21156}
21157
21158// This is a positive test. No failures are expected.
21159TEST_F(VkPositiveLayerTest, BindSparse) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021160 TEST_DESCRIPTION(
21161 "Bind 2 memory ranges to one image using vkQueueBindSparse, destroy the image"
21162 "and then free the memory");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021163
Tony Barbour1fa09702017-03-16 12:09:08 -060021164 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021165
21166 auto index = m_device->graphics_queue_node_index_;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021167 if (!(m_device->queue_props[index].queueFlags & VK_QUEUE_SPARSE_BINDING_BIT)) return;
Tony Barbour623721f2017-03-24 15:00:21 -060021168 if (!m_device->phy().features().sparseBinding) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021169
21170 m_errorMonitor->ExpectSuccess();
21171
21172 VkImage image;
21173 VkImageCreateInfo image_create_info = {};
21174 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
21175 image_create_info.pNext = NULL;
21176 image_create_info.imageType = VK_IMAGE_TYPE_2D;
21177 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
21178 image_create_info.extent.width = 64;
21179 image_create_info.extent.height = 64;
21180 image_create_info.extent.depth = 1;
21181 image_create_info.mipLevels = 1;
21182 image_create_info.arrayLayers = 1;
21183 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
21184 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
21185 image_create_info.usage = VK_IMAGE_USAGE_STORAGE_BIT;
21186 image_create_info.flags = VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
21187 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
21188 ASSERT_VK_SUCCESS(err);
21189
21190 VkMemoryRequirements memory_reqs;
21191 VkDeviceMemory memory_one, memory_two;
21192 bool pass;
21193 VkMemoryAllocateInfo memory_info = {};
21194 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
21195 memory_info.pNext = NULL;
21196 memory_info.allocationSize = 0;
21197 memory_info.memoryTypeIndex = 0;
21198 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
21199 // Find an image big enough to allow sparse mapping of 2 memory regions
21200 // Increase the image size until it is at least twice the
21201 // size of the required alignment, to ensure we can bind both
21202 // allocated memory blocks to the image on aligned offsets.
21203 while (memory_reqs.size < (memory_reqs.alignment * 2)) {
21204 vkDestroyImage(m_device->device(), image, nullptr);
21205 image_create_info.extent.width *= 2;
21206 image_create_info.extent.height *= 2;
21207 err = vkCreateImage(m_device->device(), &image_create_info, nullptr, &image);
21208 ASSERT_VK_SUCCESS(err);
21209 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
21210 }
21211 // Allocate 2 memory regions of minimum alignment size, bind one at 0, the other
21212 // at the end of the first
21213 memory_info.allocationSize = memory_reqs.alignment;
21214 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
21215 ASSERT_TRUE(pass);
21216 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_one);
21217 ASSERT_VK_SUCCESS(err);
21218 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_two);
21219 ASSERT_VK_SUCCESS(err);
21220 VkSparseMemoryBind binds[2];
21221 binds[0].flags = 0;
21222 binds[0].memory = memory_one;
21223 binds[0].memoryOffset = 0;
21224 binds[0].resourceOffset = 0;
21225 binds[0].size = memory_info.allocationSize;
21226 binds[1].flags = 0;
21227 binds[1].memory = memory_two;
21228 binds[1].memoryOffset = 0;
21229 binds[1].resourceOffset = memory_info.allocationSize;
21230 binds[1].size = memory_info.allocationSize;
21231
21232 VkSparseImageOpaqueMemoryBindInfo opaqueBindInfo;
21233 opaqueBindInfo.image = image;
21234 opaqueBindInfo.bindCount = 2;
21235 opaqueBindInfo.pBinds = binds;
21236
21237 VkFence fence = VK_NULL_HANDLE;
21238 VkBindSparseInfo bindSparseInfo = {};
21239 bindSparseInfo.sType = VK_STRUCTURE_TYPE_BIND_SPARSE_INFO;
21240 bindSparseInfo.imageOpaqueBindCount = 1;
21241 bindSparseInfo.pImageOpaqueBinds = &opaqueBindInfo;
21242
21243 vkQueueBindSparse(m_device->m_queue, 1, &bindSparseInfo, fence);
21244 vkQueueWaitIdle(m_device->m_queue);
21245 vkDestroyImage(m_device->device(), image, NULL);
21246 vkFreeMemory(m_device->device(), memory_one, NULL);
21247 vkFreeMemory(m_device->device(), memory_two, NULL);
21248 m_errorMonitor->VerifyNotFound();
21249}
21250
21251TEST_F(VkPositiveLayerTest, RenderPassInitialLayoutUndefined) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021252 TEST_DESCRIPTION(
21253 "Ensure that CmdBeginRenderPass with an attachment's "
21254 "initialLayout of VK_IMAGE_LAYOUT_UNDEFINED works when "
21255 "the command buffer has prior knowledge of that "
21256 "attachment's layout.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021257
21258 m_errorMonitor->ExpectSuccess();
21259
Tony Barbour1fa09702017-03-16 12:09:08 -060021260 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021261
21262 // A renderpass with one color attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021263 VkAttachmentDescription attachment = {0,
21264 VK_FORMAT_R8G8B8A8_UNORM,
21265 VK_SAMPLE_COUNT_1_BIT,
21266 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
21267 VK_ATTACHMENT_STORE_OP_STORE,
21268 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
21269 VK_ATTACHMENT_STORE_OP_DONT_CARE,
21270 VK_IMAGE_LAYOUT_UNDEFINED,
21271 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021272
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021273 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021274
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021275 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021276
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021277 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021278
21279 VkRenderPass rp;
21280 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
21281 ASSERT_VK_SUCCESS(err);
21282
21283 // A compatible framebuffer.
21284 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060021285 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 -060021286 ASSERT_TRUE(image.initialized());
21287
21288 VkImageViewCreateInfo ivci = {
21289 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
21290 nullptr,
21291 0,
21292 image.handle(),
21293 VK_IMAGE_VIEW_TYPE_2D,
21294 VK_FORMAT_R8G8B8A8_UNORM,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021295 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
21296 VK_COMPONENT_SWIZZLE_IDENTITY},
21297 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021298 };
21299 VkImageView view;
21300 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
21301 ASSERT_VK_SUCCESS(err);
21302
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021303 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021304 VkFramebuffer fb;
21305 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
21306 ASSERT_VK_SUCCESS(err);
21307
21308 // Record a single command buffer which uses this renderpass twice. The
21309 // bug is triggered at the beginning of the second renderpass, when the
21310 // command buffer already has a layout recorded for the attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021311 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 -070021312 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021313 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
21314 vkCmdEndRenderPass(m_commandBuffer->handle());
21315 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
21316
21317 m_errorMonitor->VerifyNotFound();
21318
21319 vkCmdEndRenderPass(m_commandBuffer->handle());
Tony Barbour552f6c02016-12-21 14:34:07 -070021320 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021321
21322 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
21323 vkDestroyRenderPass(m_device->device(), rp, nullptr);
21324 vkDestroyImageView(m_device->device(), view, nullptr);
21325}
21326
21327TEST_F(VkPositiveLayerTest, FramebufferBindingDestroyCommandPool) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021328 TEST_DESCRIPTION(
21329 "This test should pass. Create a Framebuffer and "
21330 "command buffer, bind them together, then destroy "
21331 "command pool and framebuffer and verify there are no "
21332 "errors.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021333
21334 m_errorMonitor->ExpectSuccess();
21335
Tony Barbour1fa09702017-03-16 12:09:08 -060021336 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021337
21338 // A renderpass with one color attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021339 VkAttachmentDescription attachment = {0,
21340 VK_FORMAT_R8G8B8A8_UNORM,
21341 VK_SAMPLE_COUNT_1_BIT,
21342 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
21343 VK_ATTACHMENT_STORE_OP_STORE,
21344 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
21345 VK_ATTACHMENT_STORE_OP_DONT_CARE,
21346 VK_IMAGE_LAYOUT_UNDEFINED,
21347 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021348
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021349 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021350
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021351 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021352
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021353 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021354
21355 VkRenderPass rp;
21356 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
21357 ASSERT_VK_SUCCESS(err);
21358
21359 // A compatible framebuffer.
21360 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060021361 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 -060021362 ASSERT_TRUE(image.initialized());
21363
21364 VkImageViewCreateInfo ivci = {
21365 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
21366 nullptr,
21367 0,
21368 image.handle(),
21369 VK_IMAGE_VIEW_TYPE_2D,
21370 VK_FORMAT_R8G8B8A8_UNORM,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021371 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
21372 VK_COMPONENT_SWIZZLE_IDENTITY},
21373 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021374 };
21375 VkImageView view;
21376 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
21377 ASSERT_VK_SUCCESS(err);
21378
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021379 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021380 VkFramebuffer fb;
21381 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
21382 ASSERT_VK_SUCCESS(err);
21383
21384 // Explicitly create a command buffer to bind the FB to so that we can then
21385 // destroy the command pool in order to implicitly free command buffer
21386 VkCommandPool command_pool;
21387 VkCommandPoolCreateInfo pool_create_info{};
21388 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
21389 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
21390 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
21391 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
21392
21393 VkCommandBuffer command_buffer;
21394 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
21395 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
21396 command_buffer_allocate_info.commandPool = command_pool;
21397 command_buffer_allocate_info.commandBufferCount = 1;
21398 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
21399 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
21400
21401 // Begin our cmd buffer with renderpass using our framebuffer
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021402 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 -060021403 VkCommandBufferBeginInfo begin_info{};
21404 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21405 vkBeginCommandBuffer(command_buffer, &begin_info);
21406
21407 vkCmdBeginRenderPass(command_buffer, &rpbi, VK_SUBPASS_CONTENTS_INLINE);
21408 vkCmdEndRenderPass(command_buffer);
21409 vkEndCommandBuffer(command_buffer);
21410 vkDestroyImageView(m_device->device(), view, nullptr);
21411 // Destroy command pool to implicitly free command buffer
21412 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
21413 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
21414 vkDestroyRenderPass(m_device->device(), rp, nullptr);
21415 m_errorMonitor->VerifyNotFound();
21416}
21417
21418TEST_F(VkPositiveLayerTest, RenderPassSubpassZeroTransitionsApplied) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021419 TEST_DESCRIPTION(
21420 "Ensure that CmdBeginRenderPass applies the layout "
21421 "transitions for the first subpass");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021422
21423 m_errorMonitor->ExpectSuccess();
21424
Tony Barbour1fa09702017-03-16 12:09:08 -060021425 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021426
21427 // A renderpass with one color attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021428 VkAttachmentDescription attachment = {0,
21429 VK_FORMAT_R8G8B8A8_UNORM,
21430 VK_SAMPLE_COUNT_1_BIT,
21431 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
21432 VK_ATTACHMENT_STORE_OP_STORE,
21433 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
21434 VK_ATTACHMENT_STORE_OP_DONT_CARE,
21435 VK_IMAGE_LAYOUT_UNDEFINED,
21436 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021437
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021438 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021439
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021440 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021441
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021442 VkSubpassDependency dep = {0,
21443 0,
21444 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
21445 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
21446 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
21447 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
21448 VK_DEPENDENCY_BY_REGION_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021449
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021450 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021451
21452 VkResult err;
21453 VkRenderPass rp;
21454 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
21455 ASSERT_VK_SUCCESS(err);
21456
21457 // A compatible framebuffer.
21458 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060021459 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 -060021460 ASSERT_TRUE(image.initialized());
21461
21462 VkImageViewCreateInfo ivci = {
21463 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
21464 nullptr,
21465 0,
21466 image.handle(),
21467 VK_IMAGE_VIEW_TYPE_2D,
21468 VK_FORMAT_R8G8B8A8_UNORM,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021469 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
21470 VK_COMPONENT_SWIZZLE_IDENTITY},
21471 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021472 };
21473 VkImageView view;
21474 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
21475 ASSERT_VK_SUCCESS(err);
21476
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021477 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021478 VkFramebuffer fb;
21479 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
21480 ASSERT_VK_SUCCESS(err);
21481
21482 // Record a single command buffer which issues a pipeline barrier w/
21483 // image memory barrier for the attachment. This detects the previously
21484 // missing tracking of the subpass layout by throwing a validation error
21485 // if it doesn't occur.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021486 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 -070021487 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021488 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
21489
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021490 VkImageMemoryBarrier imb = {VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
21491 nullptr,
21492 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
21493 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
21494 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
21495 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
21496 VK_QUEUE_FAMILY_IGNORED,
21497 VK_QUEUE_FAMILY_IGNORED,
21498 image.handle(),
21499 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1}};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021500 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021501 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
21502 &imb);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021503
21504 vkCmdEndRenderPass(m_commandBuffer->handle());
21505 m_errorMonitor->VerifyNotFound();
Tony Barbour552f6c02016-12-21 14:34:07 -070021506 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021507
21508 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
21509 vkDestroyRenderPass(m_device->device(), rp, nullptr);
21510 vkDestroyImageView(m_device->device(), view, nullptr);
21511}
21512
21513TEST_F(VkPositiveLayerTest, DepthStencilLayoutTransitionForDepthOnlyImageview) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021514 TEST_DESCRIPTION(
21515 "Validate that when an imageView of a depth/stencil image "
21516 "is used as a depth/stencil framebuffer attachment, the "
21517 "aspectMask is ignored and both depth and stencil image "
21518 "subresources are used.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021519
Tony Barbour1fa09702017-03-16 12:09:08 -060021520 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021521 VkFormatProperties format_properties;
21522 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_D32_SFLOAT_S8_UINT, &format_properties);
21523 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
21524 return;
21525 }
21526
21527 m_errorMonitor->ExpectSuccess();
21528
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021529 VkAttachmentDescription attachment = {0,
21530 VK_FORMAT_D32_SFLOAT_S8_UINT,
21531 VK_SAMPLE_COUNT_1_BIT,
21532 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
21533 VK_ATTACHMENT_STORE_OP_STORE,
21534 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
21535 VK_ATTACHMENT_STORE_OP_DONT_CARE,
21536 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
21537 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021538
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021539 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021540
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021541 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, &att_ref, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021542
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021543 VkSubpassDependency dep = {0,
21544 0,
21545 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
21546 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
21547 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
21548 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
21549 VK_DEPENDENCY_BY_REGION_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021550
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021551 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021552
21553 VkResult err;
21554 VkRenderPass rp;
21555 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
21556 ASSERT_VK_SUCCESS(err);
21557
21558 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060021559 image.InitNoLayout(32, 32, 1, VK_FORMAT_D32_SFLOAT_S8_UINT,
21560 0x26, // usage
21561 VK_IMAGE_TILING_OPTIMAL, 0);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021562 ASSERT_TRUE(image.initialized());
21563 image.SetLayout(0x6, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
21564
21565 VkImageViewCreateInfo ivci = {
21566 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
21567 nullptr,
21568 0,
21569 image.handle(),
21570 VK_IMAGE_VIEW_TYPE_2D,
21571 VK_FORMAT_D32_SFLOAT_S8_UINT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021572 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
21573 {0x2, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021574 };
21575 VkImageView view;
21576 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
21577 ASSERT_VK_SUCCESS(err);
21578
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021579 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021580 VkFramebuffer fb;
21581 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
21582 ASSERT_VK_SUCCESS(err);
21583
Tony Barbour552f6c02016-12-21 14:34:07 -070021584 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021585
21586 VkImageMemoryBarrier imb = {};
21587 imb.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
21588 imb.pNext = nullptr;
21589 imb.srcAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
21590 imb.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
21591 imb.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
21592 imb.newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
21593 imb.srcQueueFamilyIndex = 0;
21594 imb.dstQueueFamilyIndex = 0;
21595 imb.image = image.handle();
21596 imb.subresourceRange.aspectMask = 0x6;
21597 imb.subresourceRange.baseMipLevel = 0;
21598 imb.subresourceRange.levelCount = 0x1;
21599 imb.subresourceRange.baseArrayLayer = 0;
21600 imb.subresourceRange.layerCount = 0x1;
21601
21602 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021603 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
21604 &imb);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021605
Tony Barbour552f6c02016-12-21 14:34:07 -070021606 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021607 QueueCommandBuffer(false);
21608 m_errorMonitor->VerifyNotFound();
21609
21610 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
21611 vkDestroyRenderPass(m_device->device(), rp, nullptr);
21612 vkDestroyImageView(m_device->device(), view, nullptr);
21613}
21614
21615TEST_F(VkPositiveLayerTest, RenderPassTransitionsAttachmentUnused) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021616 TEST_DESCRIPTION(
21617 "Ensure that layout transitions work correctly without "
21618 "errors, when an attachment reference is "
21619 "VK_ATTACHMENT_UNUSED");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021620
21621 m_errorMonitor->ExpectSuccess();
21622
Tony Barbour1fa09702017-03-16 12:09:08 -060021623 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021624
21625 // A renderpass with no attachments
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021626 VkAttachmentReference att_ref = {VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021627
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021628 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021629
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021630 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 1, &subpass, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021631
21632 VkRenderPass rp;
21633 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
21634 ASSERT_VK_SUCCESS(err);
21635
21636 // A compatible framebuffer.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021637 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021638 VkFramebuffer fb;
21639 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
21640 ASSERT_VK_SUCCESS(err);
21641
21642 // Record a command buffer which just begins and ends the renderpass. The
21643 // bug manifests in BeginRenderPass.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021644 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 -070021645 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021646 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
21647 vkCmdEndRenderPass(m_commandBuffer->handle());
21648 m_errorMonitor->VerifyNotFound();
Tony Barbour552f6c02016-12-21 14:34:07 -070021649 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021650
21651 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
21652 vkDestroyRenderPass(m_device->device(), rp, nullptr);
21653}
21654
21655// This is a positive test. No errors are expected.
21656TEST_F(VkPositiveLayerTest, StencilLoadOp) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021657 TEST_DESCRIPTION(
21658 "Create a stencil-only attachment with a LOAD_OP set to "
21659 "CLEAR. stencil[Load|Store]Op used to be ignored.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021660 VkResult result = VK_SUCCESS;
Tony Barbour1fa09702017-03-16 12:09:08 -060021661 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -060021662 auto depth_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbourf887b162017-03-09 10:06:46 -070021663 if (!depth_format) {
21664 printf(" No Depth + Stencil format found. Skipped.\n");
21665 return;
21666 }
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021667 VkImageFormatProperties formatProps;
Tony Barbourf887b162017-03-09 10:06:46 -070021668 vkGetPhysicalDeviceImageFormatProperties(gpu(), depth_format, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021669 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0,
21670 &formatProps);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021671 if (formatProps.maxExtent.width < 100 || formatProps.maxExtent.height < 100) {
21672 return;
21673 }
21674
Tony Barbourf887b162017-03-09 10:06:46 -070021675 VkFormat depth_stencil_fmt = depth_format;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021676 m_depthStencil->Init(m_device, 100, 100, depth_stencil_fmt,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021677 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021678 VkAttachmentDescription att = {};
21679 VkAttachmentReference ref = {};
21680 att.format = depth_stencil_fmt;
21681 att.samples = VK_SAMPLE_COUNT_1_BIT;
21682 att.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
21683 att.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
21684 att.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
21685 att.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE;
21686 att.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
21687 att.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
21688
21689 VkClearValue clear;
21690 clear.depthStencil.depth = 1.0;
21691 clear.depthStencil.stencil = 0;
21692 ref.attachment = 0;
21693 ref.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
21694
21695 VkSubpassDescription subpass = {};
21696 subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
21697 subpass.flags = 0;
21698 subpass.inputAttachmentCount = 0;
21699 subpass.pInputAttachments = NULL;
21700 subpass.colorAttachmentCount = 0;
21701 subpass.pColorAttachments = NULL;
21702 subpass.pResolveAttachments = NULL;
21703 subpass.pDepthStencilAttachment = &ref;
21704 subpass.preserveAttachmentCount = 0;
21705 subpass.pPreserveAttachments = NULL;
21706
21707 VkRenderPass rp;
21708 VkRenderPassCreateInfo rp_info = {};
21709 rp_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
21710 rp_info.attachmentCount = 1;
21711 rp_info.pAttachments = &att;
21712 rp_info.subpassCount = 1;
21713 rp_info.pSubpasses = &subpass;
21714 result = vkCreateRenderPass(device(), &rp_info, NULL, &rp);
21715 ASSERT_VK_SUCCESS(result);
21716
21717 VkImageView *depthView = m_depthStencil->BindInfo();
21718 VkFramebufferCreateInfo fb_info = {};
21719 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
21720 fb_info.pNext = NULL;
21721 fb_info.renderPass = rp;
21722 fb_info.attachmentCount = 1;
21723 fb_info.pAttachments = depthView;
21724 fb_info.width = 100;
21725 fb_info.height = 100;
21726 fb_info.layers = 1;
21727 VkFramebuffer fb;
21728 result = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
21729 ASSERT_VK_SUCCESS(result);
21730
21731 VkRenderPassBeginInfo rpbinfo = {};
21732 rpbinfo.clearValueCount = 1;
21733 rpbinfo.pClearValues = &clear;
21734 rpbinfo.pNext = NULL;
21735 rpbinfo.renderPass = rp;
21736 rpbinfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
21737 rpbinfo.renderArea.extent.width = 100;
21738 rpbinfo.renderArea.extent.height = 100;
21739 rpbinfo.renderArea.offset.x = 0;
21740 rpbinfo.renderArea.offset.y = 0;
21741 rpbinfo.framebuffer = fb;
21742
21743 VkFence fence = {};
21744 VkFenceCreateInfo fence_ci = {};
21745 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
21746 fence_ci.pNext = nullptr;
21747 fence_ci.flags = 0;
21748 result = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fence);
21749 ASSERT_VK_SUCCESS(result);
21750
21751 m_commandBuffer->BeginCommandBuffer();
21752 m_commandBuffer->BeginRenderPass(rpbinfo);
21753 m_commandBuffer->EndRenderPass();
21754 m_commandBuffer->EndCommandBuffer();
21755 m_commandBuffer->QueueCommandBuffer(fence);
21756
21757 VkImageObj destImage(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060021758 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 -070021759 VK_IMAGE_TILING_OPTIMAL, 0);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021760 VkImageMemoryBarrier barrier = {};
21761 VkImageSubresourceRange range;
21762 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
21763 barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
21764 barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT;
21765 barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
21766 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
21767 barrier.image = m_depthStencil->handle();
21768 range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
21769 range.baseMipLevel = 0;
21770 range.levelCount = 1;
21771 range.baseArrayLayer = 0;
21772 range.layerCount = 1;
21773 barrier.subresourceRange = range;
21774 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
21775 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
21776 cmdbuf.BeginCommandBuffer();
21777 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 -070021778 &barrier);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021779 barrier.srcAccessMask = 0;
21780 barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
21781 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
21782 barrier.image = destImage.handle();
21783 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
21784 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 -070021785 &barrier);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021786 VkImageCopy cregion;
21787 cregion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
21788 cregion.srcSubresource.mipLevel = 0;
21789 cregion.srcSubresource.baseArrayLayer = 0;
21790 cregion.srcSubresource.layerCount = 1;
21791 cregion.srcOffset.x = 0;
21792 cregion.srcOffset.y = 0;
21793 cregion.srcOffset.z = 0;
21794 cregion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
21795 cregion.dstSubresource.mipLevel = 0;
21796 cregion.dstSubresource.baseArrayLayer = 0;
21797 cregion.dstSubresource.layerCount = 1;
21798 cregion.dstOffset.x = 0;
21799 cregion.dstOffset.y = 0;
21800 cregion.dstOffset.z = 0;
21801 cregion.extent.width = 100;
21802 cregion.extent.height = 100;
21803 cregion.extent.depth = 1;
21804 cmdbuf.CopyImage(m_depthStencil->handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, destImage.handle(),
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021805 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &cregion);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021806 cmdbuf.EndCommandBuffer();
21807
21808 VkSubmitInfo submit_info;
21809 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21810 submit_info.pNext = NULL;
21811 submit_info.waitSemaphoreCount = 0;
21812 submit_info.pWaitSemaphores = NULL;
21813 submit_info.pWaitDstStageMask = NULL;
21814 submit_info.commandBufferCount = 1;
21815 submit_info.pCommandBuffers = &cmdbuf.handle();
21816 submit_info.signalSemaphoreCount = 0;
21817 submit_info.pSignalSemaphores = NULL;
21818
21819 m_errorMonitor->ExpectSuccess();
21820 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
21821 m_errorMonitor->VerifyNotFound();
21822
21823 vkQueueWaitIdle(m_device->m_queue);
21824 vkDestroyFence(m_device->device(), fence, nullptr);
21825 vkDestroyRenderPass(m_device->device(), rp, nullptr);
21826 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
21827}
21828
21829// This is a positive test. No errors should be generated.
Mike Weiblene4e225d2017-03-07 23:15:43 -070021830TEST_F(VkPositiveLayerTest, BarrierLayoutToImageUsage) {
21831 TEST_DESCRIPTION("Ensure barriers' new and old VkImageLayout are compatible with their images' VkImageUsageFlags");
21832
21833 m_errorMonitor->ExpectSuccess();
21834
Tony Barbour1fa09702017-03-16 12:09:08 -060021835 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -060021836 auto depth_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbour9357d542017-03-24 15:42:21 -060021837 if (!depth_format) {
21838 printf(" No Depth + Stencil format found. Skipped.\n");
21839 return;
21840 }
Mike Weiblene4e225d2017-03-07 23:15:43 -070021841 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21842
21843 VkImageMemoryBarrier img_barrier = {};
21844 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
21845 img_barrier.pNext = NULL;
21846 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
21847 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
21848 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
21849 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
21850 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
21851 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
21852 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
21853 img_barrier.subresourceRange.baseArrayLayer = 0;
21854 img_barrier.subresourceRange.baseMipLevel = 0;
21855 img_barrier.subresourceRange.layerCount = 1;
21856 img_barrier.subresourceRange.levelCount = 1;
21857
21858 {
21859 VkImageObj img_color(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060021860 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 -070021861 ASSERT_TRUE(img_color.initialized());
21862
21863 VkImageObj img_ds1(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060021864 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 -070021865 ASSERT_TRUE(img_ds1.initialized());
21866
21867 VkImageObj img_ds2(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060021868 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 -070021869 ASSERT_TRUE(img_ds2.initialized());
21870
21871 VkImageObj img_xfer_src(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060021872 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 -070021873 ASSERT_TRUE(img_xfer_src.initialized());
21874
21875 VkImageObj img_xfer_dst(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060021876 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 -070021877 ASSERT_TRUE(img_xfer_dst.initialized());
21878
21879 VkImageObj img_sampled(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060021880 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 -070021881 ASSERT_TRUE(img_sampled.initialized());
21882
21883 VkImageObj img_input(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060021884 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 -070021885 ASSERT_TRUE(img_input.initialized());
21886
21887 const struct {
21888 VkImageObj &image_obj;
21889 VkImageLayout old_layout;
21890 VkImageLayout new_layout;
21891 } buffer_layouts[] = {
21892 // clang-format off
21893 {img_color, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL},
21894 {img_ds1, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL},
21895 {img_ds2, VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL},
21896 {img_sampled, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL},
21897 {img_input, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL},
21898 {img_xfer_src, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL},
21899 {img_xfer_dst, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL},
21900 // clang-format on
21901 };
21902 const uint32_t layout_count = sizeof(buffer_layouts) / sizeof(buffer_layouts[0]);
21903
21904 m_commandBuffer->BeginCommandBuffer();
21905 for (uint32_t i = 0; i < layout_count; ++i) {
21906 img_barrier.image = buffer_layouts[i].image_obj.handle();
21907 const VkImageUsageFlags usage = buffer_layouts[i].image_obj.usage();
21908 img_barrier.subresourceRange.aspectMask = (usage == VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT)
21909 ? (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)
21910 : VK_IMAGE_ASPECT_COLOR_BIT;
21911
21912 img_barrier.oldLayout = buffer_layouts[i].old_layout;
21913 img_barrier.newLayout = buffer_layouts[i].new_layout;
21914 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT,
21915 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0, nullptr, 1, &img_barrier);
21916
21917 img_barrier.oldLayout = buffer_layouts[i].new_layout;
21918 img_barrier.newLayout = buffer_layouts[i].old_layout;
21919 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT,
21920 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0, nullptr, 1, &img_barrier);
21921 }
21922 m_commandBuffer->EndCommandBuffer();
21923
21924 img_barrier.oldLayout = VK_IMAGE_LAYOUT_GENERAL;
21925 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
21926 }
21927 m_errorMonitor->VerifyNotFound();
21928}
21929
21930// This is a positive test. No errors should be generated.
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021931TEST_F(VkPositiveLayerTest, WaitEventThenSet) {
21932 TEST_DESCRIPTION("Wait on a event then set it after the wait has been submitted.");
21933
21934 m_errorMonitor->ExpectSuccess();
Tony Barbour1fa09702017-03-16 12:09:08 -060021935 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021936
21937 VkEvent event;
21938 VkEventCreateInfo event_create_info{};
21939 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
21940 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
21941
21942 VkCommandPool command_pool;
21943 VkCommandPoolCreateInfo pool_create_info{};
21944 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
21945 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
21946 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
21947 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
21948
21949 VkCommandBuffer command_buffer;
21950 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
21951 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
21952 command_buffer_allocate_info.commandPool = command_pool;
21953 command_buffer_allocate_info.commandBufferCount = 1;
21954 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
21955 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
21956
21957 VkQueue queue = VK_NULL_HANDLE;
21958 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
21959
21960 {
21961 VkCommandBufferBeginInfo begin_info{};
21962 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21963 vkBeginCommandBuffer(command_buffer, &begin_info);
21964
21965 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 -070021966 nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021967 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
21968 vkEndCommandBuffer(command_buffer);
21969 }
21970 {
21971 VkSubmitInfo submit_info{};
21972 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21973 submit_info.commandBufferCount = 1;
21974 submit_info.pCommandBuffers = &command_buffer;
21975 submit_info.signalSemaphoreCount = 0;
21976 submit_info.pSignalSemaphores = nullptr;
21977 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
21978 }
21979 { vkSetEvent(m_device->device(), event); }
21980
21981 vkQueueWaitIdle(queue);
21982
21983 vkDestroyEvent(m_device->device(), event, nullptr);
21984 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
21985 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
21986
21987 m_errorMonitor->VerifyNotFound();
21988}
21989// This is a positive test. No errors should be generated.
21990TEST_F(VkPositiveLayerTest, QueryAndCopySecondaryCommandBuffers) {
21991 TEST_DESCRIPTION("Issue a query on a secondary command buffery and copy it on a primary.");
21992
Tony Barbour1fa09702017-03-16 12:09:08 -060021993 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021994 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021995
21996 m_errorMonitor->ExpectSuccess();
21997
21998 VkQueryPool query_pool;
21999 VkQueryPoolCreateInfo query_pool_create_info{};
22000 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
22001 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
22002 query_pool_create_info.queryCount = 1;
22003 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
22004
22005 VkCommandPool command_pool;
22006 VkCommandPoolCreateInfo pool_create_info{};
22007 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
22008 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
22009 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
22010 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
22011
22012 VkCommandBuffer command_buffer;
22013 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
22014 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
22015 command_buffer_allocate_info.commandPool = command_pool;
22016 command_buffer_allocate_info.commandBufferCount = 1;
22017 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
22018 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
22019
22020 VkCommandBuffer secondary_command_buffer;
22021 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
22022 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer);
22023
22024 VkQueue queue = VK_NULL_HANDLE;
22025 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
22026
22027 uint32_t qfi = 0;
22028 VkBufferCreateInfo buff_create_info = {};
22029 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
22030 buff_create_info.size = 1024;
22031 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
22032 buff_create_info.queueFamilyIndexCount = 1;
22033 buff_create_info.pQueueFamilyIndices = &qfi;
22034
22035 VkResult err;
22036 VkBuffer buffer;
22037 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
22038 ASSERT_VK_SUCCESS(err);
22039 VkMemoryAllocateInfo mem_alloc = {};
22040 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
22041 mem_alloc.pNext = NULL;
22042 mem_alloc.allocationSize = 1024;
22043 mem_alloc.memoryTypeIndex = 0;
22044
22045 VkMemoryRequirements memReqs;
22046 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
22047 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
22048 if (!pass) {
22049 vkDestroyBuffer(m_device->device(), buffer, NULL);
22050 return;
22051 }
22052
22053 VkDeviceMemory mem;
22054 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
22055 ASSERT_VK_SUCCESS(err);
22056 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
22057 ASSERT_VK_SUCCESS(err);
22058
22059 VkCommandBufferInheritanceInfo hinfo = {};
22060 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
22061 hinfo.renderPass = VK_NULL_HANDLE;
22062 hinfo.subpass = 0;
22063 hinfo.framebuffer = VK_NULL_HANDLE;
22064 hinfo.occlusionQueryEnable = VK_FALSE;
22065 hinfo.queryFlags = 0;
22066 hinfo.pipelineStatistics = 0;
22067
22068 {
22069 VkCommandBufferBeginInfo begin_info{};
22070 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22071 begin_info.pInheritanceInfo = &hinfo;
22072 vkBeginCommandBuffer(secondary_command_buffer, &begin_info);
22073
22074 vkCmdResetQueryPool(secondary_command_buffer, query_pool, 0, 1);
22075 vkCmdWriteTimestamp(secondary_command_buffer, VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
22076
22077 vkEndCommandBuffer(secondary_command_buffer);
22078
22079 begin_info.pInheritanceInfo = nullptr;
22080 vkBeginCommandBuffer(command_buffer, &begin_info);
22081
22082 vkCmdExecuteCommands(command_buffer, 1, &secondary_command_buffer);
22083 vkCmdCopyQueryPoolResults(command_buffer, query_pool, 0, 1, buffer, 0, 0, 0);
22084
22085 vkEndCommandBuffer(command_buffer);
22086 }
22087 {
22088 VkSubmitInfo submit_info{};
22089 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22090 submit_info.commandBufferCount = 1;
22091 submit_info.pCommandBuffers = &command_buffer;
22092 submit_info.signalSemaphoreCount = 0;
22093 submit_info.pSignalSemaphores = nullptr;
22094 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
22095 }
22096
22097 vkQueueWaitIdle(queue);
22098
22099 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
22100 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
22101 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &secondary_command_buffer);
22102 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
22103 vkDestroyBuffer(m_device->device(), buffer, NULL);
22104 vkFreeMemory(m_device->device(), mem, NULL);
22105
22106 m_errorMonitor->VerifyNotFound();
22107}
22108
22109// This is a positive test. No errors should be generated.
22110TEST_F(VkPositiveLayerTest, QueryAndCopyMultipleCommandBuffers) {
22111 TEST_DESCRIPTION("Issue a query and copy from it on a second command buffer.");
22112
Tony Barbour1fa09702017-03-16 12:09:08 -060022113 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022114 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022115
22116 m_errorMonitor->ExpectSuccess();
22117
22118 VkQueryPool query_pool;
22119 VkQueryPoolCreateInfo query_pool_create_info{};
22120 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
22121 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
22122 query_pool_create_info.queryCount = 1;
22123 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
22124
22125 VkCommandPool command_pool;
22126 VkCommandPoolCreateInfo pool_create_info{};
22127 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
22128 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
22129 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
22130 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
22131
22132 VkCommandBuffer command_buffer[2];
22133 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
22134 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
22135 command_buffer_allocate_info.commandPool = command_pool;
22136 command_buffer_allocate_info.commandBufferCount = 2;
22137 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
22138 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
22139
22140 VkQueue queue = VK_NULL_HANDLE;
22141 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
22142
22143 uint32_t qfi = 0;
22144 VkBufferCreateInfo buff_create_info = {};
22145 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
22146 buff_create_info.size = 1024;
22147 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
22148 buff_create_info.queueFamilyIndexCount = 1;
22149 buff_create_info.pQueueFamilyIndices = &qfi;
22150
22151 VkResult err;
22152 VkBuffer buffer;
22153 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
22154 ASSERT_VK_SUCCESS(err);
22155 VkMemoryAllocateInfo mem_alloc = {};
22156 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
22157 mem_alloc.pNext = NULL;
22158 mem_alloc.allocationSize = 1024;
22159 mem_alloc.memoryTypeIndex = 0;
22160
22161 VkMemoryRequirements memReqs;
22162 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
22163 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
22164 if (!pass) {
22165 vkDestroyBuffer(m_device->device(), buffer, NULL);
22166 return;
22167 }
22168
22169 VkDeviceMemory mem;
22170 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
22171 ASSERT_VK_SUCCESS(err);
22172 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
22173 ASSERT_VK_SUCCESS(err);
22174
22175 {
22176 VkCommandBufferBeginInfo begin_info{};
22177 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22178 vkBeginCommandBuffer(command_buffer[0], &begin_info);
22179
22180 vkCmdResetQueryPool(command_buffer[0], query_pool, 0, 1);
22181 vkCmdWriteTimestamp(command_buffer[0], VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
22182
22183 vkEndCommandBuffer(command_buffer[0]);
22184
22185 vkBeginCommandBuffer(command_buffer[1], &begin_info);
22186
22187 vkCmdCopyQueryPoolResults(command_buffer[1], query_pool, 0, 1, buffer, 0, 0, 0);
22188
22189 vkEndCommandBuffer(command_buffer[1]);
22190 }
22191 {
22192 VkSubmitInfo submit_info{};
22193 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22194 submit_info.commandBufferCount = 2;
22195 submit_info.pCommandBuffers = command_buffer;
22196 submit_info.signalSemaphoreCount = 0;
22197 submit_info.pSignalSemaphores = nullptr;
22198 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
22199 }
22200
22201 vkQueueWaitIdle(queue);
22202
22203 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
22204 vkFreeCommandBuffers(m_device->device(), command_pool, 2, command_buffer);
22205 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
22206 vkDestroyBuffer(m_device->device(), buffer, NULL);
22207 vkFreeMemory(m_device->device(), mem, NULL);
22208
22209 m_errorMonitor->VerifyNotFound();
22210}
22211
Tony Barbourc46924f2016-11-04 11:49:52 -060022212TEST_F(VkLayerTest, ResetEventThenSet) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022213 TEST_DESCRIPTION("Reset an event then set it after the reset has been submitted.");
22214
Tony Barbour1fa09702017-03-16 12:09:08 -060022215 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022216 VkEvent event;
22217 VkEventCreateInfo event_create_info{};
22218 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
22219 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
22220
22221 VkCommandPool command_pool;
22222 VkCommandPoolCreateInfo pool_create_info{};
22223 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
22224 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
22225 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
22226 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
22227
22228 VkCommandBuffer command_buffer;
22229 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
22230 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
22231 command_buffer_allocate_info.commandPool = command_pool;
22232 command_buffer_allocate_info.commandBufferCount = 1;
22233 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
22234 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
22235
22236 VkQueue queue = VK_NULL_HANDLE;
22237 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
22238
22239 {
22240 VkCommandBufferBeginInfo begin_info{};
22241 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22242 vkBeginCommandBuffer(command_buffer, &begin_info);
22243
22244 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022245 vkEndCommandBuffer(command_buffer);
22246 }
22247 {
22248 VkSubmitInfo submit_info{};
22249 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22250 submit_info.commandBufferCount = 1;
22251 submit_info.pCommandBuffers = &command_buffer;
22252 submit_info.signalSemaphoreCount = 0;
22253 submit_info.pSignalSemaphores = nullptr;
22254 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
22255 }
22256 {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022257 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
22258 "that is already in use by a "
22259 "command buffer.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022260 vkSetEvent(m_device->device(), event);
22261 m_errorMonitor->VerifyFound();
22262 }
22263
22264 vkQueueWaitIdle(queue);
22265
22266 vkDestroyEvent(m_device->device(), event, nullptr);
22267 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
22268 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
22269}
22270
22271// This is a positive test. No errors should be generated.
22272TEST_F(VkPositiveLayerTest, TwoFencesThreeFrames) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022273 TEST_DESCRIPTION(
22274 "Two command buffers with two separate fences are each "
22275 "run through a Submit & WaitForFences cycle 3 times. This "
22276 "previously revealed a bug so running this positive test "
22277 "to prevent a regression.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022278 m_errorMonitor->ExpectSuccess();
22279
Tony Barbour1fa09702017-03-16 12:09:08 -060022280 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022281 VkQueue queue = VK_NULL_HANDLE;
22282 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
22283
22284 static const uint32_t NUM_OBJECTS = 2;
22285 static const uint32_t NUM_FRAMES = 3;
22286 VkCommandBuffer cmd_buffers[NUM_OBJECTS] = {};
22287 VkFence fences[NUM_OBJECTS] = {};
22288
22289 VkCommandPool cmd_pool;
22290 VkCommandPoolCreateInfo cmd_pool_ci = {};
22291 cmd_pool_ci.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
22292 cmd_pool_ci.queueFamilyIndex = m_device->graphics_queue_node_index_;
22293 cmd_pool_ci.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
22294 VkResult err = vkCreateCommandPool(m_device->device(), &cmd_pool_ci, nullptr, &cmd_pool);
22295 ASSERT_VK_SUCCESS(err);
22296
22297 VkCommandBufferAllocateInfo cmd_buf_info = {};
22298 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
22299 cmd_buf_info.commandPool = cmd_pool;
22300 cmd_buf_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
22301 cmd_buf_info.commandBufferCount = 1;
22302
22303 VkFenceCreateInfo fence_ci = {};
22304 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
22305 fence_ci.pNext = nullptr;
22306 fence_ci.flags = 0;
22307
22308 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
22309 err = vkAllocateCommandBuffers(m_device->device(), &cmd_buf_info, &cmd_buffers[i]);
22310 ASSERT_VK_SUCCESS(err);
22311 err = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fences[i]);
22312 ASSERT_VK_SUCCESS(err);
22313 }
22314
22315 for (uint32_t frame = 0; frame < NUM_FRAMES; ++frame) {
22316 for (uint32_t obj = 0; obj < NUM_OBJECTS; ++obj) {
22317 // Create empty cmd buffer
22318 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
22319 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22320
22321 err = vkBeginCommandBuffer(cmd_buffers[obj], &cmdBufBeginDesc);
22322 ASSERT_VK_SUCCESS(err);
22323 err = vkEndCommandBuffer(cmd_buffers[obj]);
22324 ASSERT_VK_SUCCESS(err);
22325
22326 VkSubmitInfo submit_info = {};
22327 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22328 submit_info.commandBufferCount = 1;
22329 submit_info.pCommandBuffers = &cmd_buffers[obj];
22330 // Submit cmd buffer and wait for fence
22331 err = vkQueueSubmit(queue, 1, &submit_info, fences[obj]);
22332 ASSERT_VK_SUCCESS(err);
22333 err = vkWaitForFences(m_device->device(), 1, &fences[obj], VK_TRUE, UINT64_MAX);
22334 ASSERT_VK_SUCCESS(err);
22335 err = vkResetFences(m_device->device(), 1, &fences[obj]);
22336 ASSERT_VK_SUCCESS(err);
22337 }
22338 }
22339 m_errorMonitor->VerifyNotFound();
22340 vkDestroyCommandPool(m_device->device(), cmd_pool, NULL);
22341 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
22342 vkDestroyFence(m_device->device(), fences[i], nullptr);
22343 }
22344}
22345// This is a positive test. No errors should be generated.
22346TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWI) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022347 TEST_DESCRIPTION(
22348 "Two command buffers, each in a separate QueueSubmit call "
22349 "submitted on separate queues followed by a QueueWaitIdle.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022350
Tony Barbour1fa09702017-03-16 12:09:08 -060022351 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022352 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022353
22354 m_errorMonitor->ExpectSuccess();
22355
22356 VkSemaphore semaphore;
22357 VkSemaphoreCreateInfo semaphore_create_info{};
22358 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
22359 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
22360
22361 VkCommandPool command_pool;
22362 VkCommandPoolCreateInfo pool_create_info{};
22363 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
22364 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
22365 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
22366 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
22367
22368 VkCommandBuffer command_buffer[2];
22369 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
22370 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
22371 command_buffer_allocate_info.commandPool = command_pool;
22372 command_buffer_allocate_info.commandBufferCount = 2;
22373 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
22374 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
22375
22376 VkQueue queue = VK_NULL_HANDLE;
22377 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
22378
22379 {
22380 VkCommandBufferBeginInfo begin_info{};
22381 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22382 vkBeginCommandBuffer(command_buffer[0], &begin_info);
22383
22384 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 -070022385 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022386
22387 VkViewport viewport{};
22388 viewport.maxDepth = 1.0f;
22389 viewport.minDepth = 0.0f;
22390 viewport.width = 512;
22391 viewport.height = 512;
22392 viewport.x = 0;
22393 viewport.y = 0;
22394 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
22395 vkEndCommandBuffer(command_buffer[0]);
22396 }
22397 {
22398 VkCommandBufferBeginInfo begin_info{};
22399 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22400 vkBeginCommandBuffer(command_buffer[1], &begin_info);
22401
22402 VkViewport viewport{};
22403 viewport.maxDepth = 1.0f;
22404 viewport.minDepth = 0.0f;
22405 viewport.width = 512;
22406 viewport.height = 512;
22407 viewport.x = 0;
22408 viewport.y = 0;
22409 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
22410 vkEndCommandBuffer(command_buffer[1]);
22411 }
22412 {
22413 VkSubmitInfo submit_info{};
22414 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22415 submit_info.commandBufferCount = 1;
22416 submit_info.pCommandBuffers = &command_buffer[0];
22417 submit_info.signalSemaphoreCount = 1;
22418 submit_info.pSignalSemaphores = &semaphore;
22419 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
22420 }
22421 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022422 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022423 VkSubmitInfo submit_info{};
22424 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22425 submit_info.commandBufferCount = 1;
22426 submit_info.pCommandBuffers = &command_buffer[1];
22427 submit_info.waitSemaphoreCount = 1;
22428 submit_info.pWaitSemaphores = &semaphore;
22429 submit_info.pWaitDstStageMask = flags;
22430 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
22431 }
22432
22433 vkQueueWaitIdle(m_device->m_queue);
22434
22435 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
22436 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
22437 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
22438
22439 m_errorMonitor->VerifyNotFound();
22440}
22441
22442// This is a positive test. No errors should be generated.
22443TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWIFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022444 TEST_DESCRIPTION(
22445 "Two command buffers, each in a separate QueueSubmit call "
22446 "submitted on separate queues, the second having a fence"
22447 "followed by a QueueWaitIdle.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022448
Tony Barbour1fa09702017-03-16 12:09:08 -060022449 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022450 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022451
22452 m_errorMonitor->ExpectSuccess();
22453
22454 VkFence fence;
22455 VkFenceCreateInfo fence_create_info{};
22456 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
22457 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
22458
22459 VkSemaphore semaphore;
22460 VkSemaphoreCreateInfo semaphore_create_info{};
22461 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
22462 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
22463
22464 VkCommandPool command_pool;
22465 VkCommandPoolCreateInfo pool_create_info{};
22466 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
22467 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
22468 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
22469 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
22470
22471 VkCommandBuffer command_buffer[2];
22472 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
22473 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
22474 command_buffer_allocate_info.commandPool = command_pool;
22475 command_buffer_allocate_info.commandBufferCount = 2;
22476 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
22477 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
22478
22479 VkQueue queue = VK_NULL_HANDLE;
22480 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
22481
22482 {
22483 VkCommandBufferBeginInfo begin_info{};
22484 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22485 vkBeginCommandBuffer(command_buffer[0], &begin_info);
22486
22487 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 -070022488 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022489
22490 VkViewport viewport{};
22491 viewport.maxDepth = 1.0f;
22492 viewport.minDepth = 0.0f;
22493 viewport.width = 512;
22494 viewport.height = 512;
22495 viewport.x = 0;
22496 viewport.y = 0;
22497 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
22498 vkEndCommandBuffer(command_buffer[0]);
22499 }
22500 {
22501 VkCommandBufferBeginInfo begin_info{};
22502 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22503 vkBeginCommandBuffer(command_buffer[1], &begin_info);
22504
22505 VkViewport viewport{};
22506 viewport.maxDepth = 1.0f;
22507 viewport.minDepth = 0.0f;
22508 viewport.width = 512;
22509 viewport.height = 512;
22510 viewport.x = 0;
22511 viewport.y = 0;
22512 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
22513 vkEndCommandBuffer(command_buffer[1]);
22514 }
22515 {
22516 VkSubmitInfo submit_info{};
22517 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22518 submit_info.commandBufferCount = 1;
22519 submit_info.pCommandBuffers = &command_buffer[0];
22520 submit_info.signalSemaphoreCount = 1;
22521 submit_info.pSignalSemaphores = &semaphore;
22522 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
22523 }
22524 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022525 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022526 VkSubmitInfo submit_info{};
22527 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22528 submit_info.commandBufferCount = 1;
22529 submit_info.pCommandBuffers = &command_buffer[1];
22530 submit_info.waitSemaphoreCount = 1;
22531 submit_info.pWaitSemaphores = &semaphore;
22532 submit_info.pWaitDstStageMask = flags;
22533 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
22534 }
22535
22536 vkQueueWaitIdle(m_device->m_queue);
22537
22538 vkDestroyFence(m_device->device(), fence, nullptr);
22539 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
22540 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
22541 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
22542
22543 m_errorMonitor->VerifyNotFound();
22544}
22545
22546// This is a positive test. No errors should be generated.
22547TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceTwoWFF) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022548 TEST_DESCRIPTION(
22549 "Two command buffers, each in a separate QueueSubmit call "
22550 "submitted on separate queues, the second having a fence"
22551 "followed by two consecutive WaitForFences calls on the same fence.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022552
Tony Barbour1fa09702017-03-16 12:09:08 -060022553 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022554 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022555
22556 m_errorMonitor->ExpectSuccess();
22557
22558 VkFence fence;
22559 VkFenceCreateInfo fence_create_info{};
22560 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
22561 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
22562
22563 VkSemaphore semaphore;
22564 VkSemaphoreCreateInfo semaphore_create_info{};
22565 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
22566 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
22567
22568 VkCommandPool command_pool;
22569 VkCommandPoolCreateInfo pool_create_info{};
22570 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
22571 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
22572 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
22573 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
22574
22575 VkCommandBuffer command_buffer[2];
22576 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
22577 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
22578 command_buffer_allocate_info.commandPool = command_pool;
22579 command_buffer_allocate_info.commandBufferCount = 2;
22580 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
22581 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
22582
22583 VkQueue queue = VK_NULL_HANDLE;
22584 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
22585
22586 {
22587 VkCommandBufferBeginInfo begin_info{};
22588 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22589 vkBeginCommandBuffer(command_buffer[0], &begin_info);
22590
22591 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 -070022592 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022593
22594 VkViewport viewport{};
22595 viewport.maxDepth = 1.0f;
22596 viewport.minDepth = 0.0f;
22597 viewport.width = 512;
22598 viewport.height = 512;
22599 viewport.x = 0;
22600 viewport.y = 0;
22601 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
22602 vkEndCommandBuffer(command_buffer[0]);
22603 }
22604 {
22605 VkCommandBufferBeginInfo begin_info{};
22606 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22607 vkBeginCommandBuffer(command_buffer[1], &begin_info);
22608
22609 VkViewport viewport{};
22610 viewport.maxDepth = 1.0f;
22611 viewport.minDepth = 0.0f;
22612 viewport.width = 512;
22613 viewport.height = 512;
22614 viewport.x = 0;
22615 viewport.y = 0;
22616 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
22617 vkEndCommandBuffer(command_buffer[1]);
22618 }
22619 {
22620 VkSubmitInfo submit_info{};
22621 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22622 submit_info.commandBufferCount = 1;
22623 submit_info.pCommandBuffers = &command_buffer[0];
22624 submit_info.signalSemaphoreCount = 1;
22625 submit_info.pSignalSemaphores = &semaphore;
22626 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
22627 }
22628 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022629 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022630 VkSubmitInfo submit_info{};
22631 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22632 submit_info.commandBufferCount = 1;
22633 submit_info.pCommandBuffers = &command_buffer[1];
22634 submit_info.waitSemaphoreCount = 1;
22635 submit_info.pWaitSemaphores = &semaphore;
22636 submit_info.pWaitDstStageMask = flags;
22637 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
22638 }
22639
22640 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
22641 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
22642
22643 vkDestroyFence(m_device->device(), fence, nullptr);
22644 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
22645 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
22646 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
22647
22648 m_errorMonitor->VerifyNotFound();
22649}
22650
22651TEST_F(VkPositiveLayerTest, TwoQueuesEnsureCorrectRetirementWithWorkStolen) {
Tony Barbour1fa09702017-03-16 12:09:08 -060022652 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022653 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070022654 printf(" Test requires two queues, skipping\n");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022655 return;
22656 }
22657
22658 VkResult err;
22659
22660 m_errorMonitor->ExpectSuccess();
22661
22662 VkQueue q0 = m_device->m_queue;
22663 VkQueue q1 = nullptr;
22664 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &q1);
22665 ASSERT_NE(q1, nullptr);
22666
22667 // An (empty) command buffer. We must have work in the first submission --
22668 // the layer treats unfenced work differently from fenced work.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022669 VkCommandPoolCreateInfo cpci = {VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, nullptr, 0, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022670 VkCommandPool pool;
22671 err = vkCreateCommandPool(m_device->device(), &cpci, nullptr, &pool);
22672 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022673 VkCommandBufferAllocateInfo cbai = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, nullptr, pool,
22674 VK_COMMAND_BUFFER_LEVEL_PRIMARY, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022675 VkCommandBuffer cb;
22676 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &cb);
22677 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022678 VkCommandBufferBeginInfo cbbi = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022679 err = vkBeginCommandBuffer(cb, &cbbi);
22680 ASSERT_VK_SUCCESS(err);
22681 err = vkEndCommandBuffer(cb);
22682 ASSERT_VK_SUCCESS(err);
22683
22684 // A semaphore
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022685 VkSemaphoreCreateInfo sci = {VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022686 VkSemaphore s;
22687 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s);
22688 ASSERT_VK_SUCCESS(err);
22689
22690 // First submission, to q0
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022691 VkSubmitInfo s0 = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &cb, 1, &s};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022692
22693 err = vkQueueSubmit(q0, 1, &s0, VK_NULL_HANDLE);
22694 ASSERT_VK_SUCCESS(err);
22695
22696 // Second submission, to q1, waiting on s
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022697 VkFlags waitmask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; // doesn't really matter what this value is.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022698 VkSubmitInfo s1 = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 1, &s, &waitmask, 0, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022699
22700 err = vkQueueSubmit(q1, 1, &s1, VK_NULL_HANDLE);
22701 ASSERT_VK_SUCCESS(err);
22702
22703 // Wait for q0 idle
22704 err = vkQueueWaitIdle(q0);
22705 ASSERT_VK_SUCCESS(err);
22706
22707 // Command buffer should have been completed (it was on q0); reset the pool.
22708 vkFreeCommandBuffers(m_device->device(), pool, 1, &cb);
22709
22710 m_errorMonitor->VerifyNotFound();
22711
22712 // Force device completely idle and clean up resources
22713 vkDeviceWaitIdle(m_device->device());
22714 vkDestroyCommandPool(m_device->device(), pool, nullptr);
22715 vkDestroySemaphore(m_device->device(), s, nullptr);
22716}
22717
22718// This is a positive test. No errors should be generated.
22719TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022720 TEST_DESCRIPTION(
22721 "Two command buffers, each in a separate QueueSubmit call "
22722 "submitted on separate queues, the second having a fence, "
22723 "followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022724
Tony Barbour1fa09702017-03-16 12:09:08 -060022725 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022726 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022727
22728 m_errorMonitor->ExpectSuccess();
22729
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022730 VkFence fence;
22731 VkFenceCreateInfo fence_create_info{};
22732 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
22733 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
22734
22735 VkSemaphore semaphore;
22736 VkSemaphoreCreateInfo semaphore_create_info{};
22737 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
22738 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
22739
22740 VkCommandPool command_pool;
22741 VkCommandPoolCreateInfo pool_create_info{};
22742 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
22743 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
22744 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
22745 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
22746
22747 VkCommandBuffer command_buffer[2];
22748 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
22749 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
22750 command_buffer_allocate_info.commandPool = command_pool;
22751 command_buffer_allocate_info.commandBufferCount = 2;
22752 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
22753 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
22754
22755 VkQueue queue = VK_NULL_HANDLE;
22756 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
22757
22758 {
22759 VkCommandBufferBeginInfo begin_info{};
22760 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22761 vkBeginCommandBuffer(command_buffer[0], &begin_info);
22762
22763 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 -070022764 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022765
22766 VkViewport viewport{};
22767 viewport.maxDepth = 1.0f;
22768 viewport.minDepth = 0.0f;
22769 viewport.width = 512;
22770 viewport.height = 512;
22771 viewport.x = 0;
22772 viewport.y = 0;
22773 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
22774 vkEndCommandBuffer(command_buffer[0]);
22775 }
22776 {
22777 VkCommandBufferBeginInfo begin_info{};
22778 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22779 vkBeginCommandBuffer(command_buffer[1], &begin_info);
22780
22781 VkViewport viewport{};
22782 viewport.maxDepth = 1.0f;
22783 viewport.minDepth = 0.0f;
22784 viewport.width = 512;
22785 viewport.height = 512;
22786 viewport.x = 0;
22787 viewport.y = 0;
22788 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
22789 vkEndCommandBuffer(command_buffer[1]);
22790 }
22791 {
22792 VkSubmitInfo submit_info{};
22793 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22794 submit_info.commandBufferCount = 1;
22795 submit_info.pCommandBuffers = &command_buffer[0];
22796 submit_info.signalSemaphoreCount = 1;
22797 submit_info.pSignalSemaphores = &semaphore;
22798 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
22799 }
22800 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022801 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022802 VkSubmitInfo submit_info{};
22803 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22804 submit_info.commandBufferCount = 1;
22805 submit_info.pCommandBuffers = &command_buffer[1];
22806 submit_info.waitSemaphoreCount = 1;
22807 submit_info.pWaitSemaphores = &semaphore;
22808 submit_info.pWaitDstStageMask = flags;
22809 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
22810 }
22811
22812 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
22813
22814 vkDestroyFence(m_device->device(), fence, nullptr);
22815 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
22816 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
22817 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
22818
22819 m_errorMonitor->VerifyNotFound();
22820}
22821
22822// This is a positive test. No errors should be generated.
22823TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueWithSemaphoreAndOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022824 TEST_DESCRIPTION(
22825 "Two command buffers, each in a separate QueueSubmit call "
22826 "on the same queue, sharing a signal/wait semaphore, the "
22827 "second having a fence, "
22828 "followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022829
22830 m_errorMonitor->ExpectSuccess();
22831
Tony Barbour1fa09702017-03-16 12:09:08 -060022832 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022833 VkFence fence;
22834 VkFenceCreateInfo fence_create_info{};
22835 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
22836 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
22837
22838 VkSemaphore semaphore;
22839 VkSemaphoreCreateInfo semaphore_create_info{};
22840 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
22841 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
22842
22843 VkCommandPool command_pool;
22844 VkCommandPoolCreateInfo pool_create_info{};
22845 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
22846 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
22847 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
22848 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
22849
22850 VkCommandBuffer command_buffer[2];
22851 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
22852 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
22853 command_buffer_allocate_info.commandPool = command_pool;
22854 command_buffer_allocate_info.commandBufferCount = 2;
22855 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
22856 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
22857
22858 {
22859 VkCommandBufferBeginInfo begin_info{};
22860 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22861 vkBeginCommandBuffer(command_buffer[0], &begin_info);
22862
22863 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022864 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022865
22866 VkViewport viewport{};
22867 viewport.maxDepth = 1.0f;
22868 viewport.minDepth = 0.0f;
22869 viewport.width = 512;
22870 viewport.height = 512;
22871 viewport.x = 0;
22872 viewport.y = 0;
22873 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
22874 vkEndCommandBuffer(command_buffer[0]);
22875 }
22876 {
22877 VkCommandBufferBeginInfo begin_info{};
22878 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22879 vkBeginCommandBuffer(command_buffer[1], &begin_info);
22880
22881 VkViewport viewport{};
22882 viewport.maxDepth = 1.0f;
22883 viewport.minDepth = 0.0f;
22884 viewport.width = 512;
22885 viewport.height = 512;
22886 viewport.x = 0;
22887 viewport.y = 0;
22888 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
22889 vkEndCommandBuffer(command_buffer[1]);
22890 }
22891 {
22892 VkSubmitInfo submit_info{};
22893 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22894 submit_info.commandBufferCount = 1;
22895 submit_info.pCommandBuffers = &command_buffer[0];
22896 submit_info.signalSemaphoreCount = 1;
22897 submit_info.pSignalSemaphores = &semaphore;
22898 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
22899 }
22900 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022901 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022902 VkSubmitInfo submit_info{};
22903 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22904 submit_info.commandBufferCount = 1;
22905 submit_info.pCommandBuffers = &command_buffer[1];
22906 submit_info.waitSemaphoreCount = 1;
22907 submit_info.pWaitSemaphores = &semaphore;
22908 submit_info.pWaitDstStageMask = flags;
22909 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
22910 }
22911
22912 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
22913
22914 vkDestroyFence(m_device->device(), fence, nullptr);
22915 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
22916 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
22917 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
22918
22919 m_errorMonitor->VerifyNotFound();
22920}
22921
22922// This is a positive test. No errors should be generated.
22923TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueNullQueueSubmitWithFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022924 TEST_DESCRIPTION(
22925 "Two command buffers, each in a separate QueueSubmit call "
22926 "on the same queue, no fences, followed by a third QueueSubmit with NO "
22927 "SubmitInfos but with a fence, followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022928
22929 m_errorMonitor->ExpectSuccess();
22930
Tony Barbour1fa09702017-03-16 12:09:08 -060022931 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022932 VkFence fence;
22933 VkFenceCreateInfo fence_create_info{};
22934 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
22935 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
22936
22937 VkCommandPool command_pool;
22938 VkCommandPoolCreateInfo pool_create_info{};
22939 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
22940 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
22941 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
22942 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
22943
22944 VkCommandBuffer command_buffer[2];
22945 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
22946 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
22947 command_buffer_allocate_info.commandPool = command_pool;
22948 command_buffer_allocate_info.commandBufferCount = 2;
22949 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
22950 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
22951
22952 {
22953 VkCommandBufferBeginInfo begin_info{};
22954 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22955 vkBeginCommandBuffer(command_buffer[0], &begin_info);
22956
22957 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 -070022958 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022959
22960 VkViewport viewport{};
22961 viewport.maxDepth = 1.0f;
22962 viewport.minDepth = 0.0f;
22963 viewport.width = 512;
22964 viewport.height = 512;
22965 viewport.x = 0;
22966 viewport.y = 0;
22967 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
22968 vkEndCommandBuffer(command_buffer[0]);
22969 }
22970 {
22971 VkCommandBufferBeginInfo begin_info{};
22972 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22973 vkBeginCommandBuffer(command_buffer[1], &begin_info);
22974
22975 VkViewport viewport{};
22976 viewport.maxDepth = 1.0f;
22977 viewport.minDepth = 0.0f;
22978 viewport.width = 512;
22979 viewport.height = 512;
22980 viewport.x = 0;
22981 viewport.y = 0;
22982 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
22983 vkEndCommandBuffer(command_buffer[1]);
22984 }
22985 {
22986 VkSubmitInfo submit_info{};
22987 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22988 submit_info.commandBufferCount = 1;
22989 submit_info.pCommandBuffers = &command_buffer[0];
22990 submit_info.signalSemaphoreCount = 0;
22991 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
22992 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
22993 }
22994 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022995 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022996 VkSubmitInfo submit_info{};
22997 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22998 submit_info.commandBufferCount = 1;
22999 submit_info.pCommandBuffers = &command_buffer[1];
23000 submit_info.waitSemaphoreCount = 0;
23001 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
23002 submit_info.pWaitDstStageMask = flags;
23003 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
23004 }
23005
23006 vkQueueSubmit(m_device->m_queue, 0, NULL, fence);
23007
23008 VkResult err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
23009 ASSERT_VK_SUCCESS(err);
23010
23011 vkDestroyFence(m_device->device(), fence, nullptr);
23012 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
23013 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
23014
23015 m_errorMonitor->VerifyNotFound();
23016}
23017
23018// This is a positive test. No errors should be generated.
23019TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023020 TEST_DESCRIPTION(
23021 "Two command buffers, each in a separate QueueSubmit call "
23022 "on the same queue, the second having a fence, followed "
23023 "by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023024
23025 m_errorMonitor->ExpectSuccess();
23026
Tony Barbour1fa09702017-03-16 12:09:08 -060023027 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023028 VkFence fence;
23029 VkFenceCreateInfo fence_create_info{};
23030 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
23031 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
23032
23033 VkCommandPool command_pool;
23034 VkCommandPoolCreateInfo pool_create_info{};
23035 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
23036 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
23037 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
23038 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
23039
23040 VkCommandBuffer command_buffer[2];
23041 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
23042 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
23043 command_buffer_allocate_info.commandPool = command_pool;
23044 command_buffer_allocate_info.commandBufferCount = 2;
23045 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
23046 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
23047
23048 {
23049 VkCommandBufferBeginInfo begin_info{};
23050 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
23051 vkBeginCommandBuffer(command_buffer[0], &begin_info);
23052
23053 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 -070023054 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023055
23056 VkViewport viewport{};
23057 viewport.maxDepth = 1.0f;
23058 viewport.minDepth = 0.0f;
23059 viewport.width = 512;
23060 viewport.height = 512;
23061 viewport.x = 0;
23062 viewport.y = 0;
23063 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
23064 vkEndCommandBuffer(command_buffer[0]);
23065 }
23066 {
23067 VkCommandBufferBeginInfo begin_info{};
23068 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
23069 vkBeginCommandBuffer(command_buffer[1], &begin_info);
23070
23071 VkViewport viewport{};
23072 viewport.maxDepth = 1.0f;
23073 viewport.minDepth = 0.0f;
23074 viewport.width = 512;
23075 viewport.height = 512;
23076 viewport.x = 0;
23077 viewport.y = 0;
23078 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
23079 vkEndCommandBuffer(command_buffer[1]);
23080 }
23081 {
23082 VkSubmitInfo submit_info{};
23083 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
23084 submit_info.commandBufferCount = 1;
23085 submit_info.pCommandBuffers = &command_buffer[0];
23086 submit_info.signalSemaphoreCount = 0;
23087 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
23088 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
23089 }
23090 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023091 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023092 VkSubmitInfo submit_info{};
23093 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
23094 submit_info.commandBufferCount = 1;
23095 submit_info.pCommandBuffers = &command_buffer[1];
23096 submit_info.waitSemaphoreCount = 0;
23097 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
23098 submit_info.pWaitDstStageMask = flags;
23099 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
23100 }
23101
23102 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
23103
23104 vkDestroyFence(m_device->device(), fence, nullptr);
23105 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
23106 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
23107
23108 m_errorMonitor->VerifyNotFound();
23109}
23110
23111// This is a positive test. No errors should be generated.
23112TEST_F(VkPositiveLayerTest, TwoSubmitInfosWithSemaphoreOneQueueSubmitsOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023113 TEST_DESCRIPTION(
23114 "Two command buffers each in a separate SubmitInfo sent in a single "
23115 "QueueSubmit call followed by a WaitForFences call.");
Tony Barbour1fa09702017-03-16 12:09:08 -060023116 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023117
23118 m_errorMonitor->ExpectSuccess();
23119
23120 VkFence fence;
23121 VkFenceCreateInfo fence_create_info{};
23122 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
23123 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
23124
23125 VkSemaphore semaphore;
23126 VkSemaphoreCreateInfo semaphore_create_info{};
23127 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
23128 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
23129
23130 VkCommandPool command_pool;
23131 VkCommandPoolCreateInfo pool_create_info{};
23132 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
23133 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
23134 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
23135 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
23136
23137 VkCommandBuffer command_buffer[2];
23138 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
23139 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
23140 command_buffer_allocate_info.commandPool = command_pool;
23141 command_buffer_allocate_info.commandBufferCount = 2;
23142 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
23143 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
23144
23145 {
23146 VkCommandBufferBeginInfo begin_info{};
23147 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
23148 vkBeginCommandBuffer(command_buffer[0], &begin_info);
23149
23150 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 -070023151 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023152
23153 VkViewport viewport{};
23154 viewport.maxDepth = 1.0f;
23155 viewport.minDepth = 0.0f;
23156 viewport.width = 512;
23157 viewport.height = 512;
23158 viewport.x = 0;
23159 viewport.y = 0;
23160 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
23161 vkEndCommandBuffer(command_buffer[0]);
23162 }
23163 {
23164 VkCommandBufferBeginInfo begin_info{};
23165 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
23166 vkBeginCommandBuffer(command_buffer[1], &begin_info);
23167
23168 VkViewport viewport{};
23169 viewport.maxDepth = 1.0f;
23170 viewport.minDepth = 0.0f;
23171 viewport.width = 512;
23172 viewport.height = 512;
23173 viewport.x = 0;
23174 viewport.y = 0;
23175 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
23176 vkEndCommandBuffer(command_buffer[1]);
23177 }
23178 {
23179 VkSubmitInfo submit_info[2];
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023180 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023181
23182 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
23183 submit_info[0].pNext = NULL;
23184 submit_info[0].commandBufferCount = 1;
23185 submit_info[0].pCommandBuffers = &command_buffer[0];
23186 submit_info[0].signalSemaphoreCount = 1;
23187 submit_info[0].pSignalSemaphores = &semaphore;
23188 submit_info[0].waitSemaphoreCount = 0;
23189 submit_info[0].pWaitSemaphores = NULL;
23190 submit_info[0].pWaitDstStageMask = 0;
23191
23192 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
23193 submit_info[1].pNext = NULL;
23194 submit_info[1].commandBufferCount = 1;
23195 submit_info[1].pCommandBuffers = &command_buffer[1];
23196 submit_info[1].waitSemaphoreCount = 1;
23197 submit_info[1].pWaitSemaphores = &semaphore;
23198 submit_info[1].pWaitDstStageMask = flags;
23199 submit_info[1].signalSemaphoreCount = 0;
23200 submit_info[1].pSignalSemaphores = NULL;
23201 vkQueueSubmit(m_device->m_queue, 2, &submit_info[0], fence);
23202 }
23203
23204 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
23205
23206 vkDestroyFence(m_device->device(), fence, nullptr);
23207 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
23208 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
23209 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
23210
23211 m_errorMonitor->VerifyNotFound();
23212}
23213
23214TEST_F(VkPositiveLayerTest, RenderPassSecondaryCommandBuffersMultipleTimes) {
23215 m_errorMonitor->ExpectSuccess();
23216
Tony Barbour1fa09702017-03-16 12:09:08 -060023217 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023218 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
23219
Tony Barbour552f6c02016-12-21 14:34:07 -070023220 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023221
23222 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
23223 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
23224 m_errorMonitor->VerifyNotFound();
23225 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
23226 m_errorMonitor->VerifyNotFound();
23227 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
23228 m_errorMonitor->VerifyNotFound();
23229
23230 m_commandBuffer->EndCommandBuffer();
23231 m_errorMonitor->VerifyNotFound();
23232}
23233
23234TEST_F(VkPositiveLayerTest, ValidRenderPassAttachmentLayoutWithLoadOp) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023235 TEST_DESCRIPTION(
23236 "Positive test where we create a renderpass with an "
23237 "attachment that uses LOAD_OP_CLEAR, the first subpass "
23238 "has a valid layout, and a second subpass then uses a "
23239 "valid *READ_ONLY* layout.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023240 m_errorMonitor->ExpectSuccess();
Tony Barbour1fa09702017-03-16 12:09:08 -060023241 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -060023242 auto depth_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbourf887b162017-03-09 10:06:46 -070023243 if (!depth_format) {
23244 printf(" No Depth + Stencil format found. Skipped.\n");
23245 return;
23246 }
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023247
23248 VkAttachmentReference attach[2] = {};
23249 attach[0].attachment = 0;
23250 attach[0].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
23251 attach[1].attachment = 0;
23252 attach[1].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
23253 VkSubpassDescription subpasses[2] = {};
23254 // First subpass clears DS attach on load
23255 subpasses[0].pDepthStencilAttachment = &attach[0];
23256 // 2nd subpass reads in DS as input attachment
23257 subpasses[1].inputAttachmentCount = 1;
23258 subpasses[1].pInputAttachments = &attach[1];
23259 VkAttachmentDescription attach_desc = {};
Tony Barbourf887b162017-03-09 10:06:46 -070023260 attach_desc.format = depth_format;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023261 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
23262 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
23263 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
23264 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
23265 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
23266 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
23267 attach_desc.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
23268 VkRenderPassCreateInfo rpci = {};
23269 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
23270 rpci.attachmentCount = 1;
23271 rpci.pAttachments = &attach_desc;
23272 rpci.subpassCount = 2;
23273 rpci.pSubpasses = subpasses;
23274
23275 // Now create RenderPass and verify no errors
23276 VkRenderPass rp;
23277 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
23278 m_errorMonitor->VerifyNotFound();
23279
23280 vkDestroyRenderPass(m_device->device(), rp, NULL);
23281}
23282
Tobin Ehlis01103de2017-02-16 13:22:47 -070023283TEST_F(VkPositiveLayerTest, RenderPassDepthStencilLayoutTransition) {
23284 TEST_DESCRIPTION(
23285 "Create a render pass with depth-stencil attachment where layout transition "
23286 "from UNDEFINED TO DS_READ_ONLY_OPTIMAL is set by render pass and verify that "
23287 "transition has correctly occurred at queue submit time with no validation errors.");
23288
Tony Barbour1fa09702017-03-16 12:09:08 -060023289 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -060023290 auto depth_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbourf887b162017-03-09 10:06:46 -070023291 if (!depth_format) {
23292 printf(" No Depth + Stencil format found. Skipped.\n");
23293 return;
23294 }
Tobin Ehlis01103de2017-02-16 13:22:47 -070023295 VkImageFormatProperties format_props;
Tony Barbourf887b162017-03-09 10:06:46 -070023296 vkGetPhysicalDeviceImageFormatProperties(gpu(), depth_format, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
Tobin Ehlis01103de2017-02-16 13:22:47 -070023297 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, 0, &format_props);
23298 if (format_props.maxExtent.width < 32 || format_props.maxExtent.height < 32) {
Tony Barbourf887b162017-03-09 10:06:46 -070023299 printf("Depth extent too small, RenderPassDepthStencilLayoutTransition skipped.\n");
Tobin Ehlis01103de2017-02-16 13:22:47 -070023300 return;
23301 }
23302
23303 m_errorMonitor->ExpectSuccess();
Tobin Ehlis01103de2017-02-16 13:22:47 -070023304 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
23305
23306 // A renderpass with one depth/stencil attachment.
23307 VkAttachmentDescription attachment = {0,
Tony Barbourf887b162017-03-09 10:06:46 -070023308 depth_format,
Tobin Ehlis01103de2017-02-16 13:22:47 -070023309 VK_SAMPLE_COUNT_1_BIT,
23310 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
23311 VK_ATTACHMENT_STORE_OP_DONT_CARE,
23312 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
23313 VK_ATTACHMENT_STORE_OP_DONT_CARE,
23314 VK_IMAGE_LAYOUT_UNDEFINED,
23315 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
23316
23317 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
23318
23319 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, &att_ref, 0, nullptr};
23320
23321 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
23322
23323 VkRenderPass rp;
23324 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
23325 ASSERT_VK_SUCCESS(err);
23326 // A compatible ds image.
23327 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060023328 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 -070023329 ASSERT_TRUE(image.initialized());
23330
23331 VkImageViewCreateInfo ivci = {
23332 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
23333 nullptr,
23334 0,
23335 image.handle(),
23336 VK_IMAGE_VIEW_TYPE_2D,
Tony Barbourf887b162017-03-09 10:06:46 -070023337 depth_format,
Tobin Ehlis01103de2017-02-16 13:22:47 -070023338 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
23339 VK_COMPONENT_SWIZZLE_IDENTITY},
23340 {VK_IMAGE_ASPECT_DEPTH_BIT, 0, 1, 0, 1},
23341 };
23342 VkImageView view;
23343 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
23344 ASSERT_VK_SUCCESS(err);
23345
23346 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
23347 VkFramebuffer fb;
23348 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
23349 ASSERT_VK_SUCCESS(err);
23350
23351 VkRenderPassBeginInfo rpbi = {VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb, {{0, 0}, {32, 32}}, 0, nullptr};
23352 m_commandBuffer->BeginCommandBuffer();
23353 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
23354 vkCmdEndRenderPass(m_commandBuffer->handle());
23355 m_commandBuffer->EndCommandBuffer();
23356 QueueCommandBuffer(false);
23357 m_errorMonitor->VerifyNotFound();
23358
23359 // Cleanup
23360 vkDestroyImageView(m_device->device(), view, NULL);
23361 vkDestroyRenderPass(m_device->device(), rp, NULL);
23362 vkDestroyFramebuffer(m_device->device(), fb, NULL);
23363}
23364
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023365TEST_F(VkPositiveLayerTest, CreatePipelineAttribMatrixType) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023366 TEST_DESCRIPTION(
23367 "Test that pipeline validation accepts matrices passed "
23368 "as vertex attributes");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023369 m_errorMonitor->ExpectSuccess();
23370
Tony Barbour1fa09702017-03-16 12:09:08 -060023371 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023372 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
23373
23374 VkVertexInputBindingDescription input_binding;
23375 memset(&input_binding, 0, sizeof(input_binding));
23376
23377 VkVertexInputAttributeDescription input_attribs[2];
23378 memset(input_attribs, 0, sizeof(input_attribs));
23379
23380 for (int i = 0; i < 2; i++) {
23381 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
23382 input_attribs[i].location = i;
23383 }
23384
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023385 char const *vsSource =
23386 "#version 450\n"
23387 "\n"
23388 "layout(location=0) in mat2x4 x;\n"
23389 "out gl_PerVertex {\n"
23390 " vec4 gl_Position;\n"
23391 "};\n"
23392 "void main(){\n"
23393 " gl_Position = x[0] + x[1];\n"
23394 "}\n";
23395 char const *fsSource =
23396 "#version 450\n"
23397 "\n"
23398 "layout(location=0) out vec4 color;\n"
23399 "void main(){\n"
23400 " color = vec4(1);\n"
23401 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023402
23403 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
23404 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
23405
23406 VkPipelineObj pipe(m_device);
23407 pipe.AddColorAttachment();
23408 pipe.AddShader(&vs);
23409 pipe.AddShader(&fs);
23410
23411 pipe.AddVertexInputBindings(&input_binding, 1);
23412 pipe.AddVertexInputAttribs(input_attribs, 2);
23413
23414 VkDescriptorSetObj descriptorSet(m_device);
23415 descriptorSet.AppendDummy();
23416 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
23417
23418 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
23419
23420 /* expect success */
23421 m_errorMonitor->VerifyNotFound();
23422}
23423
23424TEST_F(VkPositiveLayerTest, CreatePipelineAttribArrayType) {
23425 m_errorMonitor->ExpectSuccess();
23426
Tony Barbour1fa09702017-03-16 12:09:08 -060023427 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023428 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
23429
23430 VkVertexInputBindingDescription input_binding;
23431 memset(&input_binding, 0, sizeof(input_binding));
23432
23433 VkVertexInputAttributeDescription input_attribs[2];
23434 memset(input_attribs, 0, sizeof(input_attribs));
23435
23436 for (int i = 0; i < 2; i++) {
23437 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
23438 input_attribs[i].location = i;
23439 }
23440
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023441 char const *vsSource =
23442 "#version 450\n"
23443 "\n"
23444 "layout(location=0) in vec4 x[2];\n"
23445 "out gl_PerVertex {\n"
23446 " vec4 gl_Position;\n"
23447 "};\n"
23448 "void main(){\n"
23449 " gl_Position = x[0] + x[1];\n"
23450 "}\n";
23451 char const *fsSource =
23452 "#version 450\n"
23453 "\n"
23454 "layout(location=0) out vec4 color;\n"
23455 "void main(){\n"
23456 " color = vec4(1);\n"
23457 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023458
23459 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
23460 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
23461
23462 VkPipelineObj pipe(m_device);
23463 pipe.AddColorAttachment();
23464 pipe.AddShader(&vs);
23465 pipe.AddShader(&fs);
23466
23467 pipe.AddVertexInputBindings(&input_binding, 1);
23468 pipe.AddVertexInputAttribs(input_attribs, 2);
23469
23470 VkDescriptorSetObj descriptorSet(m_device);
23471 descriptorSet.AppendDummy();
23472 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
23473
23474 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
23475
23476 m_errorMonitor->VerifyNotFound();
23477}
23478
23479TEST_F(VkPositiveLayerTest, CreatePipelineAttribComponents) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023480 TEST_DESCRIPTION(
23481 "Test that pipeline validation accepts consuming a vertex attribute "
23482 "through multiple vertex shader inputs, each consuming a different "
23483 "subset of the components.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023484 m_errorMonitor->ExpectSuccess();
23485
Tony Barbour1fa09702017-03-16 12:09:08 -060023486 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023487 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
23488
23489 VkVertexInputBindingDescription input_binding;
23490 memset(&input_binding, 0, sizeof(input_binding));
23491
23492 VkVertexInputAttributeDescription input_attribs[3];
23493 memset(input_attribs, 0, sizeof(input_attribs));
23494
23495 for (int i = 0; i < 3; i++) {
23496 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
23497 input_attribs[i].location = i;
23498 }
23499
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023500 char const *vsSource =
23501 "#version 450\n"
23502 "\n"
23503 "layout(location=0) in vec4 x;\n"
23504 "layout(location=1) in vec3 y1;\n"
23505 "layout(location=1, component=3) in float y2;\n"
23506 "layout(location=2) in vec4 z;\n"
23507 "out gl_PerVertex {\n"
23508 " vec4 gl_Position;\n"
23509 "};\n"
23510 "void main(){\n"
23511 " gl_Position = x + vec4(y1, y2) + z;\n"
23512 "}\n";
23513 char const *fsSource =
23514 "#version 450\n"
23515 "\n"
23516 "layout(location=0) out vec4 color;\n"
23517 "void main(){\n"
23518 " color = vec4(1);\n"
23519 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023520
23521 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
23522 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
23523
23524 VkPipelineObj pipe(m_device);
23525 pipe.AddColorAttachment();
23526 pipe.AddShader(&vs);
23527 pipe.AddShader(&fs);
23528
23529 pipe.AddVertexInputBindings(&input_binding, 1);
23530 pipe.AddVertexInputAttribs(input_attribs, 3);
23531
23532 VkDescriptorSetObj descriptorSet(m_device);
23533 descriptorSet.AppendDummy();
23534 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
23535
23536 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
23537
23538 m_errorMonitor->VerifyNotFound();
23539}
23540
23541TEST_F(VkPositiveLayerTest, CreatePipelineSimplePositive) {
23542 m_errorMonitor->ExpectSuccess();
23543
Tony Barbour1fa09702017-03-16 12:09:08 -060023544 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023545 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
23546
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023547 char const *vsSource =
23548 "#version 450\n"
23549 "out gl_PerVertex {\n"
23550 " vec4 gl_Position;\n"
23551 "};\n"
23552 "void main(){\n"
23553 " gl_Position = vec4(0);\n"
23554 "}\n";
23555 char const *fsSource =
23556 "#version 450\n"
23557 "\n"
23558 "layout(location=0) out vec4 color;\n"
23559 "void main(){\n"
23560 " color = vec4(1);\n"
23561 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023562
23563 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
23564 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
23565
23566 VkPipelineObj pipe(m_device);
23567 pipe.AddColorAttachment();
23568 pipe.AddShader(&vs);
23569 pipe.AddShader(&fs);
23570
23571 VkDescriptorSetObj descriptorSet(m_device);
23572 descriptorSet.AppendDummy();
23573 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
23574
23575 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
23576
23577 m_errorMonitor->VerifyNotFound();
23578}
23579
23580TEST_F(VkPositiveLayerTest, CreatePipelineRelaxedTypeMatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023581 TEST_DESCRIPTION(
23582 "Test that pipeline validation accepts the relaxed type matching rules "
23583 "set out in 14.1.3: fundamental type must match, and producer side must "
23584 "have at least as many components");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023585 m_errorMonitor->ExpectSuccess();
23586
23587 // VK 1.0.8 Specification, 14.1.3 "Additionally,..." block
23588
Tony Barbour1fa09702017-03-16 12:09:08 -060023589 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023590 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
23591
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023592 char const *vsSource =
23593 "#version 450\n"
23594 "out gl_PerVertex {\n"
23595 " vec4 gl_Position;\n"
23596 "};\n"
23597 "layout(location=0) out vec3 x;\n"
23598 "layout(location=1) out ivec3 y;\n"
23599 "layout(location=2) out vec3 z;\n"
23600 "void main(){\n"
23601 " gl_Position = vec4(0);\n"
23602 " x = vec3(0); y = ivec3(0); z = vec3(0);\n"
23603 "}\n";
23604 char const *fsSource =
23605 "#version 450\n"
23606 "\n"
23607 "layout(location=0) out vec4 color;\n"
23608 "layout(location=0) in float x;\n"
23609 "layout(location=1) flat in int y;\n"
23610 "layout(location=2) in vec2 z;\n"
23611 "void main(){\n"
23612 " color = vec4(1 + x + y + z.x);\n"
23613 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023614
23615 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
23616 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
23617
23618 VkPipelineObj pipe(m_device);
23619 pipe.AddColorAttachment();
23620 pipe.AddShader(&vs);
23621 pipe.AddShader(&fs);
23622
23623 VkDescriptorSetObj descriptorSet(m_device);
23624 descriptorSet.AppendDummy();
23625 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
23626
23627 VkResult err = VK_SUCCESS;
23628 err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
23629 ASSERT_VK_SUCCESS(err);
23630
23631 m_errorMonitor->VerifyNotFound();
23632}
23633
23634TEST_F(VkPositiveLayerTest, CreatePipelineTessPerVertex) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023635 TEST_DESCRIPTION(
23636 "Test that pipeline validation accepts per-vertex variables "
23637 "passed between the TCS and TES stages");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023638 m_errorMonitor->ExpectSuccess();
23639
Tony Barbour1fa09702017-03-16 12:09:08 -060023640 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023641 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
23642
23643 if (!m_device->phy().features().tessellationShader) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070023644 printf(" Device does not support tessellation shaders; skipped.\n");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023645 return;
23646 }
23647
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023648 char const *vsSource =
23649 "#version 450\n"
23650 "void main(){}\n";
23651 char const *tcsSource =
23652 "#version 450\n"
23653 "layout(location=0) out int x[];\n"
23654 "layout(vertices=3) out;\n"
23655 "void main(){\n"
23656 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
23657 " gl_TessLevelInner[0] = 1;\n"
23658 " x[gl_InvocationID] = gl_InvocationID;\n"
23659 "}\n";
23660 char const *tesSource =
23661 "#version 450\n"
23662 "layout(triangles, equal_spacing, cw) in;\n"
23663 "layout(location=0) in int x[];\n"
23664 "out gl_PerVertex { vec4 gl_Position; };\n"
23665 "void main(){\n"
23666 " gl_Position.xyz = gl_TessCoord;\n"
23667 " gl_Position.w = x[0] + x[1] + x[2];\n"
23668 "}\n";
23669 char const *fsSource =
23670 "#version 450\n"
23671 "layout(location=0) out vec4 color;\n"
23672 "void main(){\n"
23673 " color = vec4(1);\n"
23674 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023675
23676 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
23677 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
23678 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
23679 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
23680
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023681 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
23682 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023683
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023684 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023685
23686 VkPipelineObj pipe(m_device);
23687 pipe.SetInputAssembly(&iasci);
23688 pipe.SetTessellation(&tsci);
23689 pipe.AddColorAttachment();
23690 pipe.AddShader(&vs);
23691 pipe.AddShader(&tcs);
23692 pipe.AddShader(&tes);
23693 pipe.AddShader(&fs);
23694
23695 VkDescriptorSetObj descriptorSet(m_device);
23696 descriptorSet.AppendDummy();
23697 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
23698
23699 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
23700
23701 m_errorMonitor->VerifyNotFound();
23702}
23703
23704TEST_F(VkPositiveLayerTest, CreatePipelineGeometryInputBlockPositive) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023705 TEST_DESCRIPTION(
23706 "Test that pipeline validation accepts a user-defined "
23707 "interface block passed into the geometry shader. This "
23708 "is interesting because the 'extra' array level is not "
23709 "present on the member type, but on the block instance.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023710 m_errorMonitor->ExpectSuccess();
23711
Tony Barbour1fa09702017-03-16 12:09:08 -060023712 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023713 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
23714
23715 if (!m_device->phy().features().geometryShader) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070023716 printf(" Device does not support geometry shaders; skipped.\n");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023717 return;
23718 }
23719
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023720 char const *vsSource =
23721 "#version 450\n"
23722 "layout(location=0) out VertexData { vec4 x; } vs_out;\n"
23723 "void main(){\n"
23724 " vs_out.x = vec4(1);\n"
23725 "}\n";
23726 char const *gsSource =
23727 "#version 450\n"
23728 "layout(triangles) in;\n"
23729 "layout(triangle_strip, max_vertices=3) out;\n"
23730 "layout(location=0) in VertexData { vec4 x; } gs_in[];\n"
23731 "out gl_PerVertex { vec4 gl_Position; };\n"
23732 "void main() {\n"
23733 " gl_Position = gs_in[0].x;\n"
23734 " EmitVertex();\n"
23735 "}\n";
23736 char const *fsSource =
23737 "#version 450\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 gs(m_device, gsSource, VK_SHADER_STAGE_GEOMETRY_BIT, this);
23745 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
23746
23747 VkPipelineObj pipe(m_device);
23748 pipe.AddColorAttachment();
23749 pipe.AddShader(&vs);
23750 pipe.AddShader(&gs);
23751 pipe.AddShader(&fs);
23752
23753 VkDescriptorSetObj descriptorSet(m_device);
23754 descriptorSet.AppendDummy();
23755 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
23756
23757 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
23758
23759 m_errorMonitor->VerifyNotFound();
23760}
23761
23762TEST_F(VkPositiveLayerTest, CreatePipeline64BitAttributesPositive) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023763 TEST_DESCRIPTION(
23764 "Test that pipeline validation accepts basic use of 64bit vertex "
23765 "attributes. This is interesting because they consume multiple "
23766 "locations.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023767 m_errorMonitor->ExpectSuccess();
23768
Tony Barbour1fa09702017-03-16 12:09:08 -060023769 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023770 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
23771
23772 if (!m_device->phy().features().shaderFloat64) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070023773 printf(" Device does not support 64bit vertex attributes; skipped.\n");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023774 return;
23775 }
23776
23777 VkVertexInputBindingDescription input_bindings[1];
23778 memset(input_bindings, 0, sizeof(input_bindings));
23779
23780 VkVertexInputAttributeDescription input_attribs[4];
23781 memset(input_attribs, 0, sizeof(input_attribs));
23782 input_attribs[0].location = 0;
23783 input_attribs[0].offset = 0;
23784 input_attribs[0].format = VK_FORMAT_R64G64B64A64_SFLOAT;
23785 input_attribs[1].location = 2;
23786 input_attribs[1].offset = 32;
23787 input_attribs[1].format = VK_FORMAT_R64G64B64A64_SFLOAT;
23788 input_attribs[2].location = 4;
23789 input_attribs[2].offset = 64;
23790 input_attribs[2].format = VK_FORMAT_R64G64B64A64_SFLOAT;
23791 input_attribs[3].location = 6;
23792 input_attribs[3].offset = 96;
23793 input_attribs[3].format = VK_FORMAT_R64G64B64A64_SFLOAT;
23794
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023795 char const *vsSource =
23796 "#version 450\n"
23797 "\n"
23798 "layout(location=0) in dmat4 x;\n"
23799 "out gl_PerVertex {\n"
23800 " vec4 gl_Position;\n"
23801 "};\n"
23802 "void main(){\n"
23803 " gl_Position = vec4(x[0][0]);\n"
23804 "}\n";
23805 char const *fsSource =
23806 "#version 450\n"
23807 "\n"
23808 "layout(location=0) out vec4 color;\n"
23809 "void main(){\n"
23810 " color = vec4(1);\n"
23811 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023812
23813 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
23814 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
23815
23816 VkPipelineObj pipe(m_device);
23817 pipe.AddColorAttachment();
23818 pipe.AddShader(&vs);
23819 pipe.AddShader(&fs);
23820
23821 pipe.AddVertexInputBindings(input_bindings, 1);
23822 pipe.AddVertexInputAttribs(input_attribs, 4);
23823
23824 VkDescriptorSetObj descriptorSet(m_device);
23825 descriptorSet.AppendDummy();
23826 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
23827
23828 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
23829
23830 m_errorMonitor->VerifyNotFound();
23831}
23832
23833TEST_F(VkPositiveLayerTest, CreatePipelineInputAttachmentPositive) {
23834 TEST_DESCRIPTION("Positive test for a correctly matched input attachment");
23835 m_errorMonitor->ExpectSuccess();
23836
Tony Barbour1fa09702017-03-16 12:09:08 -060023837 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023838
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023839 char const *vsSource =
23840 "#version 450\n"
23841 "\n"
23842 "out gl_PerVertex {\n"
23843 " vec4 gl_Position;\n"
23844 "};\n"
23845 "void main(){\n"
23846 " gl_Position = vec4(1);\n"
23847 "}\n";
23848 char const *fsSource =
23849 "#version 450\n"
23850 "\n"
23851 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
23852 "layout(location=0) out vec4 color;\n"
23853 "void main() {\n"
23854 " color = subpassLoad(x);\n"
23855 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023856
23857 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
23858 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
23859
23860 VkPipelineObj pipe(m_device);
23861 pipe.AddShader(&vs);
23862 pipe.AddShader(&fs);
23863 pipe.AddColorAttachment();
23864 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
23865
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023866 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
23867 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023868 VkDescriptorSetLayout dsl;
23869 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
23870 ASSERT_VK_SUCCESS(err);
23871
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023872 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023873 VkPipelineLayout pl;
23874 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
23875 ASSERT_VK_SUCCESS(err);
23876
23877 VkAttachmentDescription descs[2] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023878 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
23879 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
23880 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
23881 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
23882 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 -060023883 };
23884 VkAttachmentReference color = {
23885 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
23886 };
23887 VkAttachmentReference input = {
23888 1, VK_IMAGE_LAYOUT_GENERAL,
23889 };
23890
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023891 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023892
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023893 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023894 VkRenderPass rp;
23895 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
23896 ASSERT_VK_SUCCESS(err);
23897
23898 // should be OK. would go wrong here if it's going to...
23899 pipe.CreateVKPipeline(pl, rp);
23900
23901 m_errorMonitor->VerifyNotFound();
23902
23903 vkDestroyRenderPass(m_device->device(), rp, nullptr);
23904 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
23905 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
23906}
23907
23908TEST_F(VkPositiveLayerTest, CreateComputePipelineMissingDescriptorUnusedPositive) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023909 TEST_DESCRIPTION(
23910 "Test that pipeline validation accepts a compute pipeline which declares a "
23911 "descriptor-backed resource which is not provided, but the shader does not "
23912 "statically use it. This is interesting because it requires compute pipelines "
23913 "to have a proper descriptor use walk, which they didn't for some time.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023914 m_errorMonitor->ExpectSuccess();
23915
Tony Barbour1fa09702017-03-16 12:09:08 -060023916 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023917
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023918 char const *csSource =
23919 "#version 450\n"
23920 "\n"
23921 "layout(local_size_x=1) in;\n"
23922 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
23923 "void main(){\n"
23924 " // x is not used.\n"
23925 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023926
23927 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
23928
23929 VkDescriptorSetObj descriptorSet(m_device);
23930 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
23931
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023932 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
23933 nullptr,
23934 0,
23935 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
23936 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
23937 descriptorSet.GetPipelineLayout(),
23938 VK_NULL_HANDLE,
23939 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023940
23941 VkPipeline pipe;
23942 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
23943
23944 m_errorMonitor->VerifyNotFound();
23945
23946 if (err == VK_SUCCESS) {
23947 vkDestroyPipeline(m_device->device(), pipe, nullptr);
23948 }
23949}
23950
23951TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsSampler) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023952 TEST_DESCRIPTION(
23953 "Test that pipeline validation accepts a shader consuming only the "
23954 "sampler portion of a combined image + sampler");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023955 m_errorMonitor->ExpectSuccess();
23956
Tony Barbour1fa09702017-03-16 12:09:08 -060023957 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023958
23959 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023960 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
23961 {1, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
23962 {2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023963 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023964 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023965 VkDescriptorSetLayout dsl;
23966 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
23967 ASSERT_VK_SUCCESS(err);
23968
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023969 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023970 VkPipelineLayout pl;
23971 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
23972 ASSERT_VK_SUCCESS(err);
23973
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023974 char const *csSource =
23975 "#version 450\n"
23976 "\n"
23977 "layout(local_size_x=1) in;\n"
23978 "layout(set=0, binding=0) uniform sampler s;\n"
23979 "layout(set=0, binding=1) uniform texture2D t;\n"
23980 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
23981 "void main() {\n"
23982 " x = texture(sampler2D(t, s), vec2(0));\n"
23983 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023984 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
23985
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023986 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
23987 nullptr,
23988 0,
23989 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
23990 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
23991 pl,
23992 VK_NULL_HANDLE,
23993 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023994
23995 VkPipeline pipe;
23996 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
23997
23998 m_errorMonitor->VerifyNotFound();
23999
24000 if (err == VK_SUCCESS) {
24001 vkDestroyPipeline(m_device->device(), pipe, nullptr);
24002 }
24003
24004 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
24005 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
24006}
24007
24008TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsImage) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070024009 TEST_DESCRIPTION(
24010 "Test that pipeline validation accepts a shader consuming only the "
24011 "image portion of a combined image + sampler");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024012 m_errorMonitor->ExpectSuccess();
24013
Tony Barbour1fa09702017-03-16 12:09:08 -060024014 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024015
24016 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070024017 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
24018 {1, VK_DESCRIPTOR_TYPE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
24019 {2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024020 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070024021 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024022 VkDescriptorSetLayout dsl;
24023 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
24024 ASSERT_VK_SUCCESS(err);
24025
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070024026 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024027 VkPipelineLayout pl;
24028 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
24029 ASSERT_VK_SUCCESS(err);
24030
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070024031 char const *csSource =
24032 "#version 450\n"
24033 "\n"
24034 "layout(local_size_x=1) in;\n"
24035 "layout(set=0, binding=0) uniform texture2D t;\n"
24036 "layout(set=0, binding=1) uniform sampler s;\n"
24037 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
24038 "void main() {\n"
24039 " x = texture(sampler2D(t, s), vec2(0));\n"
24040 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024041 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
24042
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070024043 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
24044 nullptr,
24045 0,
24046 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
24047 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
24048 pl,
24049 VK_NULL_HANDLE,
24050 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024051
24052 VkPipeline pipe;
24053 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
24054
24055 m_errorMonitor->VerifyNotFound();
24056
24057 if (err == VK_SUCCESS) {
24058 vkDestroyPipeline(m_device->device(), pipe, nullptr);
24059 }
24060
24061 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
24062 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
24063}
24064
24065TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsBoth) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070024066 TEST_DESCRIPTION(
24067 "Test that pipeline validation accepts a shader consuming "
24068 "both the sampler and the image of a combined image+sampler "
24069 "but via separate variables");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024070 m_errorMonitor->ExpectSuccess();
24071
Tony Barbour1fa09702017-03-16 12:09:08 -060024072 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024073
24074 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070024075 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
24076 {1, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024077 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070024078 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 2, bindings};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024079 VkDescriptorSetLayout dsl;
24080 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
24081 ASSERT_VK_SUCCESS(err);
24082
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070024083 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024084 VkPipelineLayout pl;
24085 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
24086 ASSERT_VK_SUCCESS(err);
24087
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070024088 char const *csSource =
24089 "#version 450\n"
24090 "\n"
24091 "layout(local_size_x=1) in;\n"
24092 "layout(set=0, binding=0) uniform texture2D t;\n"
24093 "layout(set=0, binding=0) uniform sampler s; // both binding 0!\n"
24094 "layout(set=0, binding=1) buffer block { vec4 x; };\n"
24095 "void main() {\n"
24096 " x = texture(sampler2D(t, s), vec2(0));\n"
24097 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024098 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
24099
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070024100 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
24101 nullptr,
24102 0,
24103 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
24104 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
24105 pl,
24106 VK_NULL_HANDLE,
24107 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024108
24109 VkPipeline pipe;
24110 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
24111
24112 m_errorMonitor->VerifyNotFound();
24113
24114 if (err == VK_SUCCESS) {
24115 vkDestroyPipeline(m_device->device(), pipe, nullptr);
24116 }
24117
24118 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
24119 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
24120}
24121
Tony Barbour3ed87a02017-03-15 16:19:02 -060024122TEST_F(VkPositiveLayerTest, Maintenance1Tests) {
Mark Lobodzinskidf784fc2017-03-14 09:18:40 -060024123 TEST_DESCRIPTION("Validate various special cases for the Maintenance1_KHR extension");
24124
Tony Barbour3ed87a02017-03-15 16:19:02 -060024125 device_extension_names.push_back(VK_KHR_MAINTENANCE1_EXTENSION_NAME);
Tony Barbour73c0f352017-03-16 15:55:38 -060024126 InitFramework(instance_layer_names, instance_extension_names, device_extension_names, myDbgFunc, m_errorMonitor);
Tony Barbour3ed87a02017-03-15 16:19:02 -060024127
Mark Lobodzinskidf784fc2017-03-14 09:18:40 -060024128 // Ensure that extension is available and enabled.
24129 uint32_t extension_count = 0;
24130 bool supports_maintenance1_extension = false;
24131 VkResult err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, nullptr);
24132 ASSERT_VK_SUCCESS(err);
24133 if (extension_count > 0) {
24134 std::vector<VkExtensionProperties> available_extensions(extension_count);
24135
24136 err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, &available_extensions[0]);
24137 ASSERT_VK_SUCCESS(err);
24138 for (const auto &extension_props : available_extensions) {
24139 if (strcmp(extension_props.extensionName, VK_KHR_MAINTENANCE1_EXTENSION_NAME) == 0) {
24140 supports_maintenance1_extension = true;
24141 }
24142 }
24143 }
24144
24145 // Proceed if extension is supported by hardware
24146 if (!supports_maintenance1_extension) {
24147 printf(" Maintenance1 Extension not supported, skipping tests\n");
24148 return;
24149 }
Mark Lobodzinskidf784fc2017-03-14 09:18:40 -060024150
24151 m_errorMonitor->ExpectSuccess();
Dave Houlton8e0fe7a2017-03-30 10:32:10 -060024152 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskidf784fc2017-03-14 09:18:40 -060024153 VkCommandBuffer cmd_buf;
24154 VkCommandBufferAllocateInfo alloc_info;
24155 alloc_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
24156 alloc_info.pNext = NULL;
24157 alloc_info.commandBufferCount = 1;
Mike Schuchardt06304c22017-03-01 17:09:09 -070024158 alloc_info.commandPool = m_commandPool->handle();
Mark Lobodzinskidf784fc2017-03-14 09:18:40 -060024159 alloc_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
24160 vkAllocateCommandBuffers(m_device->device(), &alloc_info, &cmd_buf);
24161
24162 VkCommandBufferBeginInfo cb_binfo;
24163 cb_binfo.pNext = NULL;
24164 cb_binfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
24165 cb_binfo.pInheritanceInfo = VK_NULL_HANDLE;
24166 cb_binfo.flags = 0;
24167 vkBeginCommandBuffer(cmd_buf, &cb_binfo);
24168 // Set Negative height, should give error if Maintenance 1 is not enabled
24169 VkViewport viewport = {0, 0, 16, -16, 0, 1};
24170 vkCmdSetViewport(cmd_buf, 0, 1, &viewport);
24171 vkEndCommandBuffer(cmd_buf);
24172
24173 m_errorMonitor->VerifyNotFound();
24174}
24175
Mark Lobodzinski35ecad32017-03-27 13:09:07 -060024176TEST_F(VkLayerTest, DuplicateValidPNextStructures) {
24177 TEST_DESCRIPTION("Create a pNext chain containing valid strutures, but with a duplicate structure type");
24178
24179 ASSERT_NO_FATAL_FAILURE(Init());
24180
24181 uint32_t extension_count = 0;
24182 VkResult err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, nullptr);
24183 ASSERT_VK_SUCCESS(err);
24184
24185 if (extension_count > 0) {
24186 std::vector<VkExtensionProperties> available_extensions(extension_count);
24187 err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, &available_extensions[0]);
24188 ASSERT_VK_SUCCESS(err);
24189
24190 for (const auto &extension_props : available_extensions) {
24191 if (strcmp(extension_props.extensionName, VK_NV_DEDICATED_ALLOCATION_EXTENSION_NAME) == 0) {
24192 // Create two pNext structures which by themselves would be valid
24193 VkDedicatedAllocationBufferCreateInfoNV dedicated_buffer_create_info = {};
24194 VkDedicatedAllocationBufferCreateInfoNV dedicated_buffer_create_info_2 = {};
24195 dedicated_buffer_create_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_BUFFER_CREATE_INFO_NV;
24196 dedicated_buffer_create_info.pNext = &dedicated_buffer_create_info_2;
24197 dedicated_buffer_create_info.dedicatedAllocation = VK_TRUE;
24198
24199 dedicated_buffer_create_info_2.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_BUFFER_CREATE_INFO_NV;
24200 dedicated_buffer_create_info_2.pNext = nullptr;
24201 dedicated_buffer_create_info_2.dedicatedAllocation = VK_TRUE;
24202
24203 uint32_t queue_family_index = 0;
24204 VkBufferCreateInfo buffer_create_info = {};
24205 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
24206 buffer_create_info.pNext = &dedicated_buffer_create_info;
24207 buffer_create_info.size = 1024;
24208 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
24209 buffer_create_info.queueFamilyIndexCount = 1;
24210 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
24211
24212 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "chain contains duplicate structure types");
24213 VkBuffer buffer;
24214 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
24215 m_errorMonitor->VerifyFound();
24216 }
24217 }
24218 }
24219}
24220
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024221TEST_F(VkPositiveLayerTest, ValidStructPNext) {
24222 TEST_DESCRIPTION("Verify that a valid pNext value is handled correctly");
24223
Tony Barbour1fa09702017-03-16 12:09:08 -060024224 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024225
24226 // Positive test to check parameter_validation and unique_objects support
24227 // for NV_dedicated_allocation
24228 uint32_t extension_count = 0;
24229 bool supports_nv_dedicated_allocation = false;
24230 VkResult err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, nullptr);
24231 ASSERT_VK_SUCCESS(err);
24232
24233 if (extension_count > 0) {
24234 std::vector<VkExtensionProperties> available_extensions(extension_count);
24235
24236 err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, &available_extensions[0]);
24237 ASSERT_VK_SUCCESS(err);
24238
24239 for (const auto &extension_props : available_extensions) {
24240 if (strcmp(extension_props.extensionName, VK_NV_DEDICATED_ALLOCATION_EXTENSION_NAME) == 0) {
24241 supports_nv_dedicated_allocation = true;
24242 }
24243 }
24244 }
24245
24246 if (supports_nv_dedicated_allocation) {
24247 m_errorMonitor->ExpectSuccess();
24248
24249 VkDedicatedAllocationBufferCreateInfoNV dedicated_buffer_create_info = {};
24250 dedicated_buffer_create_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_BUFFER_CREATE_INFO_NV;
24251 dedicated_buffer_create_info.pNext = nullptr;
24252 dedicated_buffer_create_info.dedicatedAllocation = VK_TRUE;
24253
24254 uint32_t queue_family_index = 0;
24255 VkBufferCreateInfo buffer_create_info = {};
24256 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
24257 buffer_create_info.pNext = &dedicated_buffer_create_info;
24258 buffer_create_info.size = 1024;
24259 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
24260 buffer_create_info.queueFamilyIndexCount = 1;
24261 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
24262
24263 VkBuffer buffer;
Karl Schultz47dd59d2017-01-20 13:19:20 -070024264 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024265 ASSERT_VK_SUCCESS(err);
24266
24267 VkMemoryRequirements memory_reqs;
24268 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
24269
24270 VkDedicatedAllocationMemoryAllocateInfoNV dedicated_memory_info = {};
24271 dedicated_memory_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_MEMORY_ALLOCATE_INFO_NV;
24272 dedicated_memory_info.pNext = nullptr;
24273 dedicated_memory_info.buffer = buffer;
24274 dedicated_memory_info.image = VK_NULL_HANDLE;
24275
24276 VkMemoryAllocateInfo memory_info = {};
24277 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
24278 memory_info.pNext = &dedicated_memory_info;
24279 memory_info.allocationSize = memory_reqs.size;
24280
24281 bool pass;
24282 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
24283 ASSERT_TRUE(pass);
24284
24285 VkDeviceMemory buffer_memory;
24286 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
24287 ASSERT_VK_SUCCESS(err);
24288
24289 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
24290 ASSERT_VK_SUCCESS(err);
24291
24292 vkDestroyBuffer(m_device->device(), buffer, NULL);
24293 vkFreeMemory(m_device->device(), buffer_memory, NULL);
24294
24295 m_errorMonitor->VerifyNotFound();
24296 }
24297}
24298
24299TEST_F(VkPositiveLayerTest, PSOPolygonModeValid) {
24300 VkResult err;
24301
24302 TEST_DESCRIPTION("Verify that using a solid polygon fill mode works correctly.");
24303
Tony Barbour1fa09702017-03-16 12:09:08 -060024304 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024305 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
24306
24307 std::vector<const char *> device_extension_names;
24308 auto features = m_device->phy().features();
24309 // Artificially disable support for non-solid fill modes
24310 features.fillModeNonSolid = false;
24311 // The sacrificial device object
24312 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
24313
24314 VkRenderpassObj render_pass(&test_device);
24315
24316 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
24317 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
24318 pipeline_layout_ci.setLayoutCount = 0;
24319 pipeline_layout_ci.pSetLayouts = NULL;
24320
24321 VkPipelineLayout pipeline_layout;
24322 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
24323 ASSERT_VK_SUCCESS(err);
24324
24325 VkPipelineRasterizationStateCreateInfo rs_ci = {};
24326 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
24327 rs_ci.pNext = nullptr;
24328 rs_ci.lineWidth = 1.0f;
24329 rs_ci.rasterizerDiscardEnable = true;
24330
24331 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
24332 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
24333
24334 // Set polygonMode=FILL. No error is expected
24335 m_errorMonitor->ExpectSuccess();
24336 {
24337 VkPipelineObj pipe(&test_device);
24338 pipe.AddShader(&vs);
24339 pipe.AddShader(&fs);
24340 pipe.AddColorAttachment();
24341 // Set polygonMode to a good value
24342 rs_ci.polygonMode = VK_POLYGON_MODE_FILL;
24343 pipe.SetRasterization(&rs_ci);
24344 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
24345 }
24346 m_errorMonitor->VerifyNotFound();
24347
24348 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
24349}
24350
Dave Houlton1150cf52017-04-27 14:38:11 -060024351TEST_F(VkPositiveLayerTest, LongSemaphoreChain) {
Chris Forbes94196952017-04-06 16:30:59 -070024352 m_errorMonitor->ExpectSuccess();
24353
24354 ASSERT_NO_FATAL_FAILURE(Init());
24355 VkResult err;
24356
24357 std::vector<VkSemaphore> semaphores;
24358
24359 const int chainLength = 32768;
24360 VkPipelineStageFlags flags = VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT;
24361
24362 for (int i = 0; i < chainLength; i++) {
Dave Houlton1150cf52017-04-27 14:38:11 -060024363 VkSemaphoreCreateInfo sci = {VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0};
Chris Forbes94196952017-04-06 16:30:59 -070024364 VkSemaphore semaphore;
24365 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &semaphore);
24366 ASSERT_VK_SUCCESS(err);
24367
24368 semaphores.push_back(semaphore);
24369
Chris Forbesfc50aaa2017-05-01 10:20:17 -070024370 VkSubmitInfo si = {VK_STRUCTURE_TYPE_SUBMIT_INFO,
24371 nullptr,
24372 semaphores.size() > 1 ? 1u : 0u,
24373 semaphores.size() > 1 ? &semaphores[semaphores.size() - 2] : nullptr,
24374 &flags,
24375 0,
24376 nullptr,
24377 1,
24378 &semaphores[semaphores.size() - 1]};
Chris Forbes94196952017-04-06 16:30:59 -070024379 err = vkQueueSubmit(m_device->m_queue, 1, &si, VK_NULL_HANDLE);
24380 ASSERT_VK_SUCCESS(err);
24381 }
24382
Dave Houlton1150cf52017-04-27 14:38:11 -060024383 VkFenceCreateInfo fci = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0};
Chris Forbes94196952017-04-06 16:30:59 -070024384 VkFence fence;
24385 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
24386 ASSERT_VK_SUCCESS(err);
Dave Houlton1150cf52017-04-27 14:38:11 -060024387 VkSubmitInfo si = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 1, &semaphores.back(), &flags, 0, nullptr, 0, nullptr};
Chris Forbes94196952017-04-06 16:30:59 -070024388 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
24389 ASSERT_VK_SUCCESS(err);
24390
24391 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
24392
Dave Houlton1150cf52017-04-27 14:38:11 -060024393 for (auto semaphore : semaphores) vkDestroySemaphore(m_device->device(), semaphore, nullptr);
Chris Forbes94196952017-04-06 16:30:59 -070024394
24395 vkDestroyFence(m_device->device(), fence, nullptr);
24396
24397 m_errorMonitor->VerifyNotFound();
24398}
24399
Mike Stroyanca855662017-05-02 11:06:27 -060024400extern "C" void *ReleaseNullFence(void *arg) {
24401 struct thread_data_struct *data = (struct thread_data_struct *)arg;
24402
24403 for (int i = 0; i < 40000; i++) {
24404 vkDestroyFence(data->device, VK_NULL_HANDLE, NULL);
24405 if (data->bailout) {
24406 break;
24407 }
24408 }
24409 return NULL;
24410}
24411
24412TEST_F(VkPositiveLayerTest, ThreadNullFenceCollision) {
24413 test_platform_thread thread;
24414
24415 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "THREADING ERROR");
24416
24417 ASSERT_NO_FATAL_FAILURE(Init());
24418
24419 struct thread_data_struct data;
24420 data.device = m_device->device();
24421 data.bailout = false;
24422 m_errorMonitor->SetBailout(&data.bailout);
24423
24424 // Call vkDestroyFence of VK_NULL_HANDLE repeatedly using multiple threads.
24425 // There should be no validation error from collision of that non-object.
24426 test_platform_thread_create(&thread, ReleaseNullFence, (void *)&data);
24427 for (int i = 0; i < 40000; i++) {
24428 vkDestroyFence(m_device->device(), VK_NULL_HANDLE, NULL);
24429 }
24430 test_platform_thread_join(thread, NULL);
24431
24432 m_errorMonitor->SetBailout(NULL);
24433
24434 m_errorMonitor->VerifyNotFound();
24435}
24436
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070024437#if 0 // A few devices have issues with this test so disabling for now
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024438TEST_F(VkPositiveLayerTest, LongFenceChain)
24439{
24440 m_errorMonitor->ExpectSuccess();
24441
Tony Barbour1fa09702017-03-16 12:09:08 -060024442 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024443 VkResult err;
24444
24445 std::vector<VkFence> fences;
24446
24447 const int chainLength = 32768;
24448
24449 for (int i = 0; i < chainLength; i++) {
24450 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
24451 VkFence fence;
24452 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
24453 ASSERT_VK_SUCCESS(err);
24454
24455 fences.push_back(fence);
24456
24457 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr,
24458 0, nullptr, 0, nullptr };
24459 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
24460 ASSERT_VK_SUCCESS(err);
24461
24462 }
24463
24464 // BOOM, stack overflow.
24465 vkWaitForFences(m_device->device(), 1, &fences.back(), VK_TRUE, UINT64_MAX);
24466
24467 for (auto fence : fences)
24468 vkDestroyFence(m_device->device(), fence, nullptr);
24469
24470 m_errorMonitor->VerifyNotFound();
24471}
24472#endif
24473
Petr Kraus4d718682017-05-18 03:38:41 +020024474TEST_F(VkPositiveLayerTest, ClearColorImageWithValidRange) {
24475 TEST_DESCRIPTION("Record clear color with a valid VkImageSubresourceRange");
24476
24477 ASSERT_NO_FATAL_FAILURE(Init());
24478 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
24479
24480 VkImageObj image(m_device);
24481 image.Init(32, 32, 1, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_OPTIMAL);
24482 ASSERT_TRUE(image.create_info().arrayLayers == 1);
24483 ASSERT_TRUE(image.initialized());
24484 image.SetLayout(VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
24485
24486 const VkClearColorValue clear_color = {{0.0f, 0.0f, 0.0f, 1.0f}};
24487
24488 m_commandBuffer->BeginCommandBuffer();
24489 const auto cb_handle = m_commandBuffer->GetBufferHandle();
24490
24491 // Try good case
24492 {
24493 m_errorMonitor->ExpectSuccess();
24494 VkImageSubresourceRange range = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1};
24495 vkCmdClearColorImage(cb_handle, image.handle(), image.Layout(), &clear_color, 1, &range);
24496 m_errorMonitor->VerifyNotFound();
24497 }
24498
24499 // Try good case with VK_REMAINING
24500 {
24501 m_errorMonitor->ExpectSuccess();
24502 VkImageSubresourceRange range = {VK_IMAGE_ASPECT_COLOR_BIT, 0, VK_REMAINING_MIP_LEVELS, 0, VK_REMAINING_ARRAY_LAYERS};
24503 vkCmdClearColorImage(cb_handle, image.handle(), image.Layout(), &clear_color, 1, &range);
24504 m_errorMonitor->VerifyNotFound();
24505 }
24506}
24507
24508TEST_F(VkPositiveLayerTest, ClearDepthStencilWithValidRange) {
24509 TEST_DESCRIPTION("Record clear depth with a valid VkImageSubresourceRange");
24510
24511 ASSERT_NO_FATAL_FAILURE(Init());
24512 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
24513
24514 auto depth_format = FindSupportedDepthStencilFormat(gpu());
24515 if (!depth_format) {
24516 printf(" No Depth + Stencil format found. Skipped.\n");
24517 return;
24518 }
24519
24520 VkImageObj image(m_device);
24521 image.Init(32, 32, 1, depth_format, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_OPTIMAL);
24522 ASSERT_TRUE(image.create_info().arrayLayers == 1);
24523 ASSERT_TRUE(image.initialized());
24524 const VkImageAspectFlags ds_aspect = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
24525 image.SetLayout(ds_aspect, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
24526
24527 const VkClearDepthStencilValue clear_value = {};
24528
24529 m_commandBuffer->BeginCommandBuffer();
24530 const auto cb_handle = m_commandBuffer->GetBufferHandle();
24531
24532 // Try good case
24533 {
24534 m_errorMonitor->ExpectSuccess();
24535 VkImageSubresourceRange range = {ds_aspect, 0, 1, 0, 1};
24536 vkCmdClearDepthStencilImage(cb_handle, image.handle(), image.Layout(), &clear_value, 1, &range);
24537 m_errorMonitor->VerifyNotFound();
24538 }
24539
24540 // Try good case with VK_REMAINING
24541 {
24542 m_errorMonitor->ExpectSuccess();
24543 VkImageSubresourceRange range = {ds_aspect, 0, VK_REMAINING_MIP_LEVELS, 0, VK_REMAINING_ARRAY_LAYERS};
24544 vkCmdClearDepthStencilImage(cb_handle, image.handle(), image.Layout(), &clear_value, 1, &range);
24545 m_errorMonitor->VerifyNotFound();
24546 }
24547}
24548
Cody Northrop1242dfd2016-07-13 17:24:59 -060024549#if defined(ANDROID) && defined(VALIDATION_APK)
Cody Northropb94529f2017-04-05 13:05:51 -060024550const char *appTag = "VulkanLayerValidationTests";
Cody Northrop1242dfd2016-07-13 17:24:59 -060024551static bool initialized = false;
24552static bool active = false;
24553
24554// Convert Intents to argv
24555// Ported from Hologram sample, only difference is flexible key
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024556std::vector<std::string> get_args(android_app &app, const char *intent_extra_data_key) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060024557 std::vector<std::string> args;
24558 JavaVM &vm = *app.activity->vm;
24559 JNIEnv *p_env;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070024560 if (vm.AttachCurrentThread(&p_env, nullptr) != JNI_OK) return args;
Cody Northrop1242dfd2016-07-13 17:24:59 -060024561
24562 JNIEnv &env = *p_env;
24563 jobject activity = app.activity->clazz;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024564 jmethodID get_intent_method = env.GetMethodID(env.GetObjectClass(activity), "getIntent", "()Landroid/content/Intent;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060024565 jobject intent = env.CallObjectMethod(activity, get_intent_method);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024566 jmethodID get_string_extra_method =
24567 env.GetMethodID(env.GetObjectClass(intent), "getStringExtra", "(Ljava/lang/String;)Ljava/lang/String;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060024568 jvalue get_string_extra_args;
24569 get_string_extra_args.l = env.NewStringUTF(intent_extra_data_key);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024570 jstring extra_str = static_cast<jstring>(env.CallObjectMethodA(intent, get_string_extra_method, &get_string_extra_args));
Cody Northrop1242dfd2016-07-13 17:24:59 -060024571
24572 std::string args_str;
24573 if (extra_str) {
24574 const char *extra_utf = env.GetStringUTFChars(extra_str, nullptr);
24575 args_str = extra_utf;
24576 env.ReleaseStringUTFChars(extra_str, extra_utf);
24577 env.DeleteLocalRef(extra_str);
24578 }
24579
24580 env.DeleteLocalRef(get_string_extra_args.l);
24581 env.DeleteLocalRef(intent);
24582 vm.DetachCurrentThread();
24583
24584 // split args_str
24585 std::stringstream ss(args_str);
24586 std::string arg;
24587 while (std::getline(ss, arg, ' ')) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070024588 if (!arg.empty()) args.push_back(arg);
Cody Northrop1242dfd2016-07-13 17:24:59 -060024589 }
24590
24591 return args;
24592}
24593
Dave Houlton11dcd5e2017-04-25 16:00:10 -060024594void addFullTestCommentIfPresent(const ::testing::TestInfo &test_info, std::string &error_message) {
24595 const char *const type_param = test_info.type_param();
24596 const char *const value_param = test_info.value_param();
Cody Northropb94529f2017-04-05 13:05:51 -060024597
24598 if (type_param != NULL || value_param != NULL) {
24599 error_message.append(", where ");
24600 if (type_param != NULL) {
Dave Houlton11dcd5e2017-04-25 16:00:10 -060024601 error_message.append("TypeParam = ").append(type_param);
24602 if (value_param != NULL) error_message.append(" and ");
Cody Northropb94529f2017-04-05 13:05:51 -060024603 }
24604 if (value_param != NULL) {
24605 error_message.append("GetParam() = ").append(value_param);
24606 }
24607 }
24608}
24609
24610// Inspired by https://github.com/google/googletest/blob/master/googletest/docs/AdvancedGuide.md
24611class LogcatPrinter : public ::testing::EmptyTestEventListener {
24612 // Called before a test starts.
Dave Houlton11dcd5e2017-04-25 16:00:10 -060024613 virtual void OnTestStart(const ::testing::TestInfo &test_info) {
Cody Northropb94529f2017-04-05 13:05:51 -060024614 __android_log_print(ANDROID_LOG_INFO, appTag, "[ RUN ] %s.%s", test_info.test_case_name(), test_info.name());
24615 }
24616
24617 // Called after a failed assertion or a SUCCEED() invocation.
Dave Houlton11dcd5e2017-04-25 16:00:10 -060024618 virtual void OnTestPartResult(const ::testing::TestPartResult &result) {
Cody Northropb94529f2017-04-05 13:05:51 -060024619 // If the test part succeeded, we don't need to do anything.
Dave Houlton11dcd5e2017-04-25 16:00:10 -060024620 if (result.type() == ::testing::TestPartResult::kSuccess) return;
Cody Northropb94529f2017-04-05 13:05:51 -060024621
Dave Houlton11dcd5e2017-04-25 16:00:10 -060024622 __android_log_print(ANDROID_LOG_INFO, appTag, "%s in %s:%d %s", result.failed() ? "*** Failure" : "Success",
24623 result.file_name(), result.line_number(), result.summary());
Cody Northropb94529f2017-04-05 13:05:51 -060024624 }
24625
24626 // Called after a test ends.
Dave Houlton11dcd5e2017-04-25 16:00:10 -060024627 virtual void OnTestEnd(const ::testing::TestInfo &info) {
Cody Northropb94529f2017-04-05 13:05:51 -060024628 std::string result;
24629 if (info.result()->Passed()) {
24630 result.append("[ OK ]");
24631 } else {
24632 result.append("[ FAILED ]");
24633 }
24634 result.append(info.test_case_name()).append(".").append(info.name());
Dave Houlton11dcd5e2017-04-25 16:00:10 -060024635 if (info.result()->Failed()) addFullTestCommentIfPresent(info, result);
Cody Northropb94529f2017-04-05 13:05:51 -060024636
24637 if (::testing::GTEST_FLAG(print_time)) {
24638 std::ostringstream os;
24639 os << info.result()->elapsed_time();
24640 result.append(" (").append(os.str()).append(" ms)");
24641 }
24642
24643 __android_log_print(ANDROID_LOG_INFO, appTag, "%s", result.c_str());
24644 };
24645};
24646
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024647static int32_t processInput(struct android_app *app, AInputEvent *event) { return 0; }
Cody Northrop1242dfd2016-07-13 17:24:59 -060024648
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024649static void processCommand(struct android_app *app, int32_t cmd) {
24650 switch (cmd) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070024651 case APP_CMD_INIT_WINDOW: {
24652 if (app->window) {
24653 initialized = true;
24654 }
24655 break;
Cody Northrop1242dfd2016-07-13 17:24:59 -060024656 }
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070024657 case APP_CMD_GAINED_FOCUS: {
24658 active = true;
24659 break;
24660 }
24661 case APP_CMD_LOST_FOCUS: {
24662 active = false;
24663 break;
24664 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060024665 }
24666}
24667
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024668void android_main(struct android_app *app) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060024669 app_dummy();
24670
Cody Northrop1242dfd2016-07-13 17:24:59 -060024671 int vulkanSupport = InitVulkan();
24672 if (vulkanSupport == 0) {
24673 __android_log_print(ANDROID_LOG_INFO, appTag, "==== FAILED ==== No Vulkan support found");
24674 return;
24675 }
24676
24677 app->onAppCmd = processCommand;
24678 app->onInputEvent = processInput;
24679
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024680 while (1) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060024681 int events;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024682 struct android_poll_source *source;
24683 while (ALooper_pollAll(active ? 0 : -1, NULL, &events, (void **)&source) >= 0) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060024684 if (source) {
24685 source->process(app, source);
24686 }
24687
24688 if (app->destroyRequested != 0) {
24689 VkTestFramework::Finish();
24690 return;
24691 }
24692 }
24693
24694 if (initialized && active) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024695 // Use the following key to send arguments to gtest, i.e.
24696 // --es args "--gtest_filter=-VkLayerTest.foo"
24697 const char key[] = "args";
24698 std::vector<std::string> args = get_args(*app, key);
Cody Northrop1242dfd2016-07-13 17:24:59 -060024699
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024700 std::string filter = "";
24701 if (args.size() > 0) {
24702 __android_log_print(ANDROID_LOG_INFO, appTag, "Intent args = %s", args[0].c_str());
24703 filter += args[0];
24704 } else {
24705 __android_log_print(ANDROID_LOG_INFO, appTag, "No Intent args detected");
24706 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060024707
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024708 int argc = 2;
24709 char *argv[] = {(char *)"foo", (char *)filter.c_str()};
24710 __android_log_print(ANDROID_LOG_DEBUG, appTag, "filter = %s", argv[1]);
Cody Northrop1242dfd2016-07-13 17:24:59 -060024711
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024712 // Route output to files until we can override the gtest output
24713 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/out.txt", "w", stdout);
24714 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/err.txt", "w", stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060024715
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024716 ::testing::InitGoogleTest(&argc, argv);
Cody Northropb94529f2017-04-05 13:05:51 -060024717
Dave Houlton11dcd5e2017-04-25 16:00:10 -060024718 ::testing::TestEventListeners &listeners = ::testing::UnitTest::GetInstance()->listeners();
Cody Northropb94529f2017-04-05 13:05:51 -060024719 listeners.Append(new LogcatPrinter);
24720
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024721 VkTestFramework::InitArgs(&argc, argv);
24722 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Cody Northrop1242dfd2016-07-13 17:24:59 -060024723
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024724 int result = RUN_ALL_TESTS();
Cody Northrop1242dfd2016-07-13 17:24:59 -060024725
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024726 if (result != 0) {
24727 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests FAILED ====");
24728 } else {
24729 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests PASSED ====");
24730 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060024731
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024732 VkTestFramework::Finish();
Cody Northrop1242dfd2016-07-13 17:24:59 -060024733
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024734 fclose(stdout);
24735 fclose(stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060024736
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024737 ANativeActivity_finish(app->activity);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024738 return;
Cody Northrop1242dfd2016-07-13 17:24:59 -060024739 }
24740 }
24741}
24742#endif
24743
Tony Barbour300a6082015-04-07 13:44:53 -060024744int main(int argc, char **argv) {
24745 int result;
24746
Cody Northrop8e54a402016-03-08 22:25:52 -070024747#ifdef ANDROID
24748 int vulkanSupport = InitVulkan();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070024749 if (vulkanSupport == 0) return 1;
Cody Northrop8e54a402016-03-08 22:25:52 -070024750#endif
24751
Tony Barbour300a6082015-04-07 13:44:53 -060024752 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -060024753 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour300a6082015-04-07 13:44:53 -060024754
24755 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
24756
24757 result = RUN_ALL_TESTS();
24758
Tony Barbour6918cd52015-04-09 12:58:51 -060024759 VkTestFramework::Finish();
Tony Barbour300a6082015-04-07 13:44:53 -060024760 return result;
24761}